Commit 89eb2e9f authored by unknown's avatar unknown
Browse files

More refactoring and movement

parent 1f79adad
assets/screenshots/render.png

2.45 MB | W: | H:

assets/screenshots/render.png

3.21 MB | W: | H:

assets/screenshots/render.png
assets/screenshots/render.png
assets/screenshots/render.png
assets/screenshots/render.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -8,7 +8,6 @@
#include <engine/Math.h>
#include <engine/GLWrapper.h>
#include <engine/Console.h>
#include <engine/FileUtilities.h>
#include <engine/EngineState.h>
#include <engine/ComponentContainer.h>
......
#ifndef __GLARE_INCLUDE_IO
#define __GLARE_INCLUDE_IO
#include <io/ImageUtilities.h>
#include <io/Resources.h>
#include <io/ArgParser.h>
......
#include <types/integers.h>
#include <util/integers.h>
int main(int argc, char* argv[])
{
......
......@@ -8,6 +8,7 @@
#include <linespace/LineSpace.h>
#include <io/Export.h>
#include <util/files.h>
namespace glare
{
......@@ -50,7 +51,7 @@ namespace glare
m_arguments = std::make_unique<io::Arguments>(argc, argv);
pugi::xml_document preferences_file;
preferences_file.load_file(core::asset("/preferences/default.xml").c_str());
preferences_file.load_file(files::asset("/preferences/default.xml").c_str());
// BASIC CONFIG
const auto config_child = preferences_file.child("settings").find_child_by_attribute("group", "name", "config");
......@@ -64,34 +65,34 @@ namespace glare
core::Callbacks::addKeyDownCallback("main_application", std::bind(&Application::onKeyDown, this, std::placeholders::_1, std::placeholders::_2));
core::Callbacks::addFramebufferSizeCallback("main_application", std::bind(&Application::onFramebufferSize, this, std::placeholders::_1, std::placeholders::_2));
core::SplashScreen splash_screen(core::asset("/preferences/splash_01.xml"));
core::SplashScreen splash_screen(files::asset("/preferences/splash_01.xml"));
splash_screen.run();
m_current_scene_root = core::asset("/meshes/scenery/");
m_current_scene_root = files::asset("/meshes/scenery/");
//Create a skybox from cube map.
m_skybox = std::make_shared<core::Skybox>(core::Skybox::collectFilesFrom(core::asset("/textures/ryfjallet/")));
m_skybox = std::make_shared<core::Skybox>(core::Skybox::collectFilesFrom(files::asset("/textures/ryfjallet/")));
//auto cube_node = io::Resources::getInstance().getColladaSceneMeshNode("", m_current_scene_root / "benchmark_stfd_dragon_diff.dae", "dragon_vrip");
//io::Export::meshAsBinary(cube_node->getComponent<core::MeshRenderer>()->getMesh(), core::asset("dragon.mesh"), true);
//quitPromptDefault(0);
//initializeScene(m_current_scene_root / "artifact_suzanne_x2_glass_0r.dae", 1.f);
//initializeScene(m_current_scene_root / "artifact_suzanne_x2_mirror_0r.dae", 1.f);
//initializeScene(m_current_scene_root / "artifact_suzanne_x2_transparent.dae", 1.f);
initializeScene(m_current_scene_root / "benchmark_stfd_bunny_diff.dae", 1.f);
//initializeScene(m_current_scene_root / "difficult.dae", 1.f);
//initializeScene(m_current_scene_root / "benchmark_stfd_bunny_diff.dae", 1.f);
initializeScene(m_current_scene_root / "difficult.dae", 1.f);
initializeRenderRequirements();
initializeAdvanced();
initializeGUI();
m_raytracer->loadSettings(core::asset("/preferences/pathtracer_default.xml"));
m_raytracer->loadSettings(files::asset("/preferences/pathtracer_default.xml"));
gl::setEnabled(gl::EnableParameter::eMultisample, true);
auto audio_buffer = io::Resources::getInstance().getAudioBuffer(core::asset("/audio/env.wav"));
auto audio_buffer = io::Resources::getInstance().getAudioBuffer(files::asset("/audio/env.wav"));
auto environment_source = core::EngineState::graph_root->makeComponent<core::AudioSource>(audio_buffer->id());
environment_source->setLooping(true);
environment_source->play();
......@@ -356,14 +357,14 @@ namespace glare
ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth()/2 );
if (ImGui::Button("32bit HDR"))
{
m_raytracer->saveRender(core::asset("/screenshots/render.hdr"));
m_raytracer->saveRender(files::asset("/screenshots/render.hdr"));
}
ImGui::SameLine();
if (ImGui::Button("8bit PNG"))
{
m_raytracer->saveRender(core::asset("/screenshots/render.png"));
m_raytracer->saveRender(files::asset("/screenshots/render.png"));
}
ImGui::PopItemWidth();
style.Colors[ImGuiCol_Button] = col_bt;
......
#include "Game.h"
#include "Map.h"
#include <array>
#include <util/files.h>
Game::Game()
{
......@@ -35,21 +36,21 @@ void Game::onKeyDown(controls::Key key, controls::KeyMods mods)
}
void Game::initialize()
{
pugi::xml_document preferences_file;
preferences_file.load_file(core::asset("/preferences/default.xml").c_str());
// BASIC CONFIG
const auto config_child = preferences_file.child("settings").find_child_by_attribute("group", "name", "config");
m_config.window_width = config_child.find_child_by_attribute("item", "name", "window_size_x").attribute("value").as_uint(1280);
m_config.window_height = config_child.find_child_by_attribute("item", "name", "window_size_y").attribute("value").as_uint(720);
m_config.window_title = config_child.find_child_by_attribute("item", "name", "window_title").attribute("value").as_string("GLARE");
m_config.vsync = VSyncMode(config_child.find_child_by_attribute("item", "name", "vsync").attribute("value").as_uint(0));
{
pugi::xml_document preferences_file;
preferences_file.load_file(files::asset("/preferences/default.xml").c_str());
// BASIC CONFIG
const auto config_child = preferences_file.child("settings").find_child_by_attribute("group", "name", "config");
m_config.window_width = config_child.find_child_by_attribute("item", "name", "window_size_x").attribute("value").as_uint(1280);
m_config.window_height = config_child.find_child_by_attribute("item", "name", "window_size_y").attribute("value").as_uint(720);
m_config.window_title = config_child.find_child_by_attribute("item", "name", "window_title").attribute("value").as_string("GLARE");
m_config.vsync = VSyncMode(config_child.find_child_by_attribute("item", "name", "vsync").attribute("value").as_uint(0));
m_config.sample_count = config_child.find_child_by_attribute("item", "name", "msaa").attribute("value").as_uint(4);
core::EngineState::initialize(m_config.window_width, m_config.window_height, m_config.window_title);
m_skybox = std::make_shared<core::Skybox>(core::Skybox::collectFilesFrom(core::asset("/textures/sky/")));
m_skybox = std::make_shared<core::Skybox>(core::Skybox::collectFilesFrom(files::asset("/textures/sky/")));
std::vector<float> bla(2);
......@@ -84,7 +85,7 @@ void Game::initialize()
environment_node->attach(sun_node);
// Make the terrain
game::Map map(core::asset("/maps/test01/map.xml"));
game::Map map(files::asset("/maps/test01/map.xml"));
auto terrain_node = std::make_shared<core::GraphNode>("terrain");
terrain_node->addComponent(map.getMesh());
......@@ -94,7 +95,7 @@ void Game::initialize()
core::EngineState::graph_root->attach(cam_node);
//Attach plane as child in front of the camera.
auto plane = io::Resources::getInstance().getColladaMesh(core::asset("meshes/scenery/plane.dae"), "Cube");
auto plane = io::Resources::getInstance().getColladaMesh(files::asset("meshes/scenery/plane.dae"), "Cube");
cam_node->attach(plane);
plane->transform()->position = { 0, -2.f, -15 };
plane->transform()->rotate({ glm::radians(-90.f), glm::radians(90.f), 0.f });
......@@ -109,10 +110,10 @@ void Game::initialize()
ImGui::glfw3::newFrame();
glare::core::EngineState::update();
//Simulate a sun for a day and night cycle.
//Simulate a sun for a day and night cycle.
if (controls::keyState(controls::Key::eF) == controls::ButtonAction::ePress) {
sun_node->transform()->rotate({ glm::radians(80.f)*core::Time::deltaTime(), 0, 0 });
sun_node->transform()->rotate({ glm::radians(80.f)*core::Time::deltaTime(), 0, 0 });
}
/*else {
sun_node->transform()->rotate({ glm::radians(0.f)*core::Time::deltaTime(), 0, 0 });
......@@ -132,17 +133,17 @@ void Game::initialize()
m_gbuffer->draw(); //... with shadow map ;)
} break;
case 1: {
gl::viewport(0, 0, 1024, 1024);
texrend->draw(light_sun->shadowMapRenderer().framebuffer().colorAttachment(gl::Attachment::eColor0));
gl::viewport(0, 0, unsigned(core::EngineState::main_camera->getWidth()),
texrend->draw(light_sun->shadowMapRenderer().framebuffer().colorAttachment(gl::Attachment::eColor0));
gl::viewport(0, 0, unsigned(core::EngineState::main_camera->getWidth()),
unsigned(core::EngineState::main_camera->getWidth() / core::EngineState::main_camera->getAspectRatio()));
} break;
case 2: {
gl::viewport(0, 0, 1024, 1024);
texrend->draw(light_sun->shadowMapRenderer().framebuffer().depthAttachment());
gl::viewport(0, 0, unsigned(core::EngineState::main_camera->getWidth()),
texrend->draw(light_sun->shadowMapRenderer().framebuffer().depthAttachment());
gl::viewport(0, 0, unsigned(core::EngineState::main_camera->getWidth()),
unsigned(core::EngineState::main_camera->getWidth() / core::EngineState::main_camera->getAspectRatio()));
} break;
}
......
#include "Map.h"
#include "io/ImageUtilities.h"
#include <pugixml/pugixml.hpp>
#include <io/Resources.h>
#include <types/color.h>
namespace glare
{
namespace game
{
Map::Map(const fs::path &path)
#include "Map.h"
#include <pugixml/pugixml.hpp>
#include <io/Resources.h>
#include <util/color.h>
#include <util/files.h>
#include <engine/graphics/ImageTexture2D.h>
namespace glare
{
namespace game
{
Map::Map(const fs::path &path)
{
pugi::xml_document document;
document.load_file(path.c_str());
......@@ -34,7 +36,7 @@ namespace glare
m_team_to_pcolor.emplace(team_id, mapto_color);
}
auto data = io::image::loadData<core::TextureDataRGBA_32F>(m_heightmap_path);
auto data = core::textures::loadData<core::TextureDataRGBA_32F>(m_heightmap_path);
m_width = unsigned(data->width());
m_height = unsigned(data->height());
......@@ -52,18 +54,18 @@ namespace glare
m_heights[x][y] = data->get({ x, y }).r*m_height_scale;
}
}
}
}
std::shared_ptr<core::MeshRenderer> Map::getMesh(bool rebuild)
{
if (!rebuild && m_mesh_renderer)
{
return m_mesh_renderer;
}
}
std::shared_ptr<core::MeshRenderer> Map::getMesh(bool rebuild)
{
if (!rebuild && m_mesh_renderer)
{
return m_mesh_renderer;
}
std::vector<math::Vertex> m_vertices;
std::vector<unsigned> m_indices;
std::vector<unsigned> m_indices;
const int v_count = 18;
......@@ -240,32 +242,32 @@ namespace glare
}
}
auto mesh = std::make_shared<core::Mesh>(m_vertices, m_indices);
m_mesh_renderer = std::make_shared<core::MeshRenderer>(mesh, makeMaterial());
return m_mesh_renderer;
}
std::shared_ptr<core::Material> Map::makeMaterial()
{
auto mesh = std::make_shared<core::Mesh>(m_vertices, m_indices);
m_mesh_renderer = std::make_shared<core::MeshRenderer>(mesh, makeMaterial());
return m_mesh_renderer;
}
std::shared_ptr<core::Material> Map::makeMaterial()
{
std::shared_ptr<core::Material> material = std::make_shared<core::Material>("terrain");
material->color_diffuse = color::preset::white.rgb;
material->color_specular = 2 * color::preset::white.rgb;
material->specular_exponent = 80;
material->map_diffuse = io::Resources::getInstance().getTexture(core::asset("meshes/scenery/gravel_medium2048.png"));
material->map_normal = io::Resources::getInstance().getTexture(core::asset("meshes/scenery/gravel_medium2048_n.png"));
material->map_displacement = io::Resources::getInstance().getTexture(core::asset("meshes/scenery/gravel_medium2048_h.png"));
material->map_specular = io::Resources::getInstance().getTexture(core::asset("meshes/scenery/gravel_medium2048_s.png"));
return material;
}
glm::vec3 Map::getSectorCenter(unsigned x, unsigned z) const
{
float cx = x * (m_sector_size + m_sector_border) + m_sector_size / 2;
float cz = z * (m_sector_size + m_sector_border) + m_sector_size / 2;
return glm::vec3(cx, m_heights[x][z], cz);
}
}
}
material->map_diffuse = io::Resources::getInstance().getTexture(files::asset("meshes/scenery/gravel_medium2048.png"));
material->map_normal = io::Resources::getInstance().getTexture(files::asset("meshes/scenery/gravel_medium2048_n.png"));
material->map_displacement = io::Resources::getInstance().getTexture(files::asset("meshes/scenery/gravel_medium2048_h.png"));
material->map_specular = io::Resources::getInstance().getTexture(files::asset("meshes/scenery/gravel_medium2048_s.png"));
return material;
}
glm::vec3 Map::getSectorCenter(unsigned x, unsigned z) const
{
float cx = x * (m_sector_size + m_sector_border) + m_sector_size / 2;
float cz = z * (m_sector_size + m_sector_border) + m_sector_size / 2;
return glm::vec3(cx, m_heights[x][z], cz);
}
}
}
#ifndef __MAP_H
#define __MAP_H
#include <engine/rendering/MeshRenderer.h>
#include <filesystem>
#include <map>
namespace glare
{
namespace game
{
namespace fs = std::experimental::filesystem;
class Map
{
public:
Map(const fs::path &path);
std::shared_ptr<core::MeshRenderer> getMesh(bool rebuild = true);
glm::vec3 getSectorCenter(unsigned x, unsigned z) const;
private:
std::shared_ptr<core::Material> makeMaterial();
std::shared_ptr<core::MeshRenderer> m_mesh_renderer;
std::vector<std::vector<float>> m_heights;
std::string m_version;
fs::path m_heightmap_path;
#ifndef __MAP_H
#define __MAP_H
#include <engine/rendering/MeshRenderer.h>
#include <filesystem>
#include <map>
namespace glare
{
namespace game
{
namespace fs = std::experimental::filesystem;
class Map
{
public:
Map(const fs::path &path);
std::shared_ptr<core::MeshRenderer> getMesh(bool rebuild = true);
glm::vec3 getSectorCenter(unsigned x, unsigned z) const;
private:
std::shared_ptr<core::Material> makeMaterial();
std::shared_ptr<core::MeshRenderer> m_mesh_renderer;
std::vector<std::vector<float>> m_heights;
std::string m_version;
fs::path m_heightmap_path;
float m_height_scale;
float m_sector_size;
float m_sector_border;
float m_sector_uv_scale;
fs::path m_possessionmap_path;
std::map<unsigned, color::rgba8u> m_team_to_pcolor;
unsigned m_width;
unsigned m_height;
};
}
}
#endif //__MAP_H
float m_sector_uv_scale;
fs::path m_possessionmap_path;
std::map<unsigned, color::rgba8u> m_team_to_pcolor;
unsigned m_width;
unsigned m_height;
};
}
}
#endif //__MAP_H
#ifndef __GLARE_ADVANCED_INTERSECTIONTESTS_H
#define __GLARE_ADVANCED_INTERSECTIONTESTS_H
#include <log/log.h>
#include <util/log.h>
#include <glm/glm.hpp>
#include <glm/ext.hpp>
#include <engine/Math.h>
......
......@@ -27,7 +27,7 @@ namespace glare
RayGeneratorDefault::RayGeneratorDefault()
{
m_generator_shader_default = core::ShaderProgram::makeUnique("/raytracer/generators/bvh/bvh_raygenerator.compute");
m_generator_shader_default = core::ShaderProgram::makeUnique(core::shader("/raytracer/generators/bvh/bvh_raygenerator.compute").string());
}
void RayGeneratorDefault::generate(Raytracer &raytracer)
......@@ -54,12 +54,12 @@ namespace glare
RayGeneratorGBuffer::RayGeneratorGBuffer()
{
std::vector<std::shared_ptr<glare::core::Shader>> shaders = {
std::make_shared<glare::core::Shader>(gl::ShaderType::eVertex, "raytracer/generators/gbuffer/gbuffer.vert"),
std::make_shared<glare::core::Shader>(gl::ShaderType::eGeometry, "raytracer/generators/gbuffer/gbuffer.geom"),
std::make_shared<glare::core::Shader>(gl::ShaderType::eFragment, "raytracer/generators/gbuffer/gbuffer.frag")
std::make_shared<glare::core::Shader>(gl::ShaderType::eVertex, core::shader("raytracer/generators/gbuffer/gbuffer.vert")),
std::make_shared<glare::core::Shader>(gl::ShaderType::eGeometry, core::shader("raytracer/generators/gbuffer/gbuffer.geom")),
std::make_shared<glare::core::Shader>(gl::ShaderType::eFragment, core::shader("raytracer/generators/gbuffer/gbuffer.frag"))
};
m_generator_shader_gbuffer = std::make_unique<core::ShaderProgram>(shaders);
m_buffer_depthtest = core::ShaderProgram::makeUnique("raytracer/generators/gbuffer/depthtest.compute");
m_buffer_depthtest = core::ShaderProgram::makeUnique(core::shader("raytracer/generators/gbuffer/depthtest.compute").string());
m_vertex_array = std::make_unique<core::VertexArray>();
}
......
......@@ -42,7 +42,7 @@ namespace glare
m_linespace_config.distance_threshold = 8.f;
m_render_config.bounces = 16;
m_render_shader = core::ShaderProgram::makeUnique("/raytracer/pathtracer.compute");
m_render_shader = core::ShaderProgram::makeUnique(core::shader("/raytracer/pathtracer.compute").string());
m_ray_generator = ray_generator;
m_trace_buffer = std::make_unique<core::Buffer<gl::BufferType::eShaderStorage>>();
core::MessageHandler::getInstance().registerReceiver(core::GlobalMessages::c_scene_changed, *this);
......@@ -213,7 +213,7 @@ namespace glare
void Raytracer::saveRender(fs::path target) const
{
io::image::saveTexture(target, *m_render_target);
core::textures::saveTexture(target, *m_render_target);
}
void Raytracer::setGenerator(std::shared_ptr<RayGeneratorBase> generator)
......
#ifndef __RAYTRACER_H
#define __RAYTRACER_H
#include <engine/rendering/ShaderProgram.h>
#include <engine/rendering/GraphNode.h>
#include <engine/graphics/Skybox.h>
#include <filesystem>
#include <array>
#include <io/ImageUtilities.h>
#include "RayGenerator.h"
#include <advanced/meshlocal/LocalCollector.h>
#include <advanced/meshlocal/SceneCollector.h>
#include <engine/rendering/ShaderProgram.h>
#include <engine/rendering/GraphNode.h>
#include <engine/graphics/Skybox.h>
#include <util/images.h>
#include "RayGenerator.h"
namespace glare
{
......
#include <engine/Time.h>
#include <log/log.h>
#include <util/log.h>
#include "FramerateCounter.h"
#include <imgui/imgui_glfw.h>
......
#include "Console.h"
#include <iostream>
#include <log/log.h>
#include <util/log.h>
namespace glare
{
......
#include <fstream>
#include <sstream>
#include <algorithm>
#include <string>
#include "FileUtilities.h"
#include <log/log.h>
namespace glare
{
namespace core
{
fs::path asset(fs::path path)
{
return fs::path(ASSETS_PATH) / path;
}
fs::path preference(fs::path path)
{
return fs::path(PREFERENCES_PATH) / path;
}
std::string loadText(const fs::path &path)
{
std::ifstream file(path);
if (file.good())
{
Log_Debug << "File " << path << " loaded successfully.";
return std::string(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>());
}
Log_Error << "File " << path << " could not be found!";
return "";
}
void saveText(const fs::path &path, const fs::path &content)
{
std::ofstream file(path);
file << content;
}
void readFile(const fs::path &path, std::function<void(const std::vector<std::string> &)> on_read_line)
{
std::ifstream file(path);
if (!file.good())
{
Log_Error << "File not found: " << path;
}
std::string line;
std::vector<std::string> parameters;
while (getline(file, line))
{
std::istringstream line_stream(line);
std::string line_substring;
parameters.clear();
while (getline(line_stream, line_substring, ' '))
{
parameters.push_back(line_substring);
}
on_read_line(parameters);
}
}
std::string getDirectory(const fs::path& path)
{
return path.parent_path().string();
}
void saveBinary(const fs::path &path, uint8_t* data, size_t size)
{
std::ofstream output;
output.open(path, std::ios::out | std::ios::binary);
output.write(reinterpret_cast<char*>(data), size);
output.close();
}
void saveBinary(const fs::path &path, std::vector<uint8_t> data)
{
saveBinary(path, data.data(), data.size() * sizeof(uint8_t));
}
}
}
#ifndef __IOUTILITIES_H
#define __IOUTILITIES_H
#include <functional>
#include <filesystem>
#include <vector>
#include <string>
#include <memory>
<