Commit 35445028 authored by Johannes Braun's avatar Johannes Braun
Browse files

A little bit of cleanup.

parent a0f5455a
......@@ -12,18 +12,19 @@ namespace glare
switch (key) {
case controls::Key::e0:
{
Log_Debug << "Changed default rendering mode";
m_render_state = AppRenderState::eDefault;
m_render_state = AppRenderState::eGLLines;
} break;
case controls::Key::e1:
{
Log_Debug << "Changed voxel rendering mode";
m_render_state = AppRenderState::eVoxels;
m_render_state = AppRenderState::eGLDefault;
} break;
case controls::Key::e2:
{
Log_Debug << "Changed rt mode";
m_render_state = AppRenderState::eRaytrace;
m_render_state = AppRenderState::eLineSpace;
} break;
case controls::Key::e3:
{
m_render_state = AppRenderState::ePathtracer;
} break;
default: break;
}
......@@ -47,7 +48,7 @@ namespace glare
//Create a skybox from cube map.
m_skybox = std::make_shared<core::Skybox>(core::Skybox::collectFilesFrom(core::asset("/textures/ryfjallet/")));
initializeScene(core::asset("/meshes/scenery/bunny.dae"), 1.f);
initializeScene(m_current_scene_root / "bunny.dae", 1.f);
initializeRenderRequirements();
initializeAdvanced();
initializeGUI();
......@@ -72,14 +73,7 @@ namespace glare
int ls_resolution = 6;
ls::LineSpace linespace(*mesh_collector, ls_resolution);
std::vector<std::shared_ptr<core::Shader>> shaders = {
std::make_shared<core::Shader>(gl::ShaderType::eVertex, "/linespace/visualize/lines.vert"),
std::make_shared<core::Shader>(gl::ShaderType::eGeometry, "/linespace/visualize/lines.geom"),
std::make_shared<core::Shader>(gl::ShaderType::eFragment, "/linespace/visualize/lines.frag")
};
std::unique_ptr<core::ShaderProgram> lines_program = std::make_unique<core::ShaderProgram>(shaders);
core::VertexArray lines_vao;
ls::LineSpaceRenderer linespace_renderer(*m_collector, linespace);
#endif
/////
......@@ -96,7 +90,7 @@ namespace glare
switch (m_render_state)
{
case AppRenderState::eLines:
case AppRenderState::eGLLines:
{
gl::polygonMode(gl::Face::eFrontAndBack, gl::PolygonMode::eLine);
bool cull = gl::isEnabled(gl::EnableParameter::eCullFace);
......@@ -106,7 +100,7 @@ namespace glare
gl::polygonMode(gl::Face::eFrontAndBack, gl::PolygonMode::eFill);
}
break;
case AppRenderState::eDefault:
case AppRenderState::eGLDefault:
{
m_gbuffer->activate();
m_skybox->draw();
......@@ -115,24 +109,12 @@ namespace glare
m_gbuffer->draw();
}
break;
case AppRenderState::eVoxels:
case AppRenderState::eLineSpace:
{
m_collector->collect();
lines_program->use();
lines_program->updateStorageBuffer("mesh_buffer", m_collector->meshBuffer());
lines_program->updateStorageBuffer("line_buffer", linespace.lineBuffer());
//lines_program->updateUniformInt("u_full_ls", int(u_full_ls));
lines_program->updateUniformUInt("u_mesh", line_mesh_id);
lines_program->updateUniformUInt("u_triangle_count", unsigned(mesh_collector->triangles().size()));
lines_program->updateUniformMatrix("u_view_projection", core::EngineState::main_camera->getViewProjection());
lines_vao.draw(gl::PrimitiveType::ePoints, linespace.lines().size());
linespace_renderer.draw();
}
break;
case AppRenderState::eRaytrace:
case AppRenderState::ePathtracer:
{
auto &&rt_texture = m_raytracer->render(m_config.window_width, m_config.window_height);
m_texture_renderer_default->draw(rt_texture);
......@@ -140,25 +122,17 @@ namespace glare
break;
}
drawGUI();
//drawVoxelController();
ImGui::End();
drawDebugWindow();
drawSceneSelector();
//static bool u_full_ls = true;
ImGui::Begin("LineSpace");
//ImGui::Checkbox("Show full LS", &u_full_ls);
ImGui::DragInt("Max. Subdivision", &ls_resolution);
if (ImGui::Button("Rebuild with Settings")) {
linespace.generate(*mesh_collector, ls_resolution);
}
ImGui::End();
ImGui::Render();
core::LightManager::getInstance().clear();
});
}
......@@ -179,10 +153,6 @@ namespace glare
}
m_scene_root = m_scene_data->scenes.begin()->second;
//Set arbitrary light
auto light = std::make_shared<core::LightComponent>(Colors::White, core::Attenuation{ 1.f, 0.1f, 0.01f }, core::LightParameters::makeAmbientLight());
m_scene_root->addComponent(light);
std::shared_ptr<core::GraphNode> cam_node;
if (!m_scene_data->cameras.empty())
{
......@@ -199,8 +169,6 @@ namespace glare
cam_node->makeComponent<component::PlayerController>();
m_scene_root->makeComponent<component::FramerateCounter>();
#define DEBUG__ADD_ROTATOR
#ifdef DEBUG__ADD_ROTATOR
for (auto &&node : m_scene_root)
......@@ -262,7 +230,7 @@ namespace glare
ImGui::TextWrapped(description.c_str());
}
void Application::drawGUI()
void Application::drawDebugWindow()
{
ImGui::Begin("Debug", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
......@@ -270,10 +238,10 @@ namespace glare
static int render_state = 0;
render_state = int(m_render_state);
ImGui::Title("Render Mode");
ImGui::RadioButton("Lines", &render_state, 0);
ImGui::RadioButton("Default GBuffer", &render_state, 1);
ImGui::RadioButton("Voxels", &render_state, 2);
ImGui::RadioButton("Raytracer", &render_state, 3);
ImGui::RadioButton("[OpenGL] Lines", &render_state, 0);
ImGui::RadioButton("[OpenGL] GBuffer", &render_state, 1);
ImGui::RadioButton("Line Space", &render_state, 2);
ImGui::RadioButton("Pathtracer", &render_state, 3);
if (m_render_state != AppRenderState(render_state)) {
glFinish();
......@@ -333,7 +301,6 @@ namespace glare
ImGui::Separator();
ImGui::Title("General Settings");
//ImGui::Checkbox("FXAA", &m_config.use_fxaa);
static int bla = 0;
bla = int(m_config.vsync);
......@@ -351,6 +318,7 @@ namespace glare
drawControlItem("Tab", "Toggle Raytracing.");
drawControlItem("V", "Toggle voxel rendering.");
ImGui::End();
}
void Application::drawSceneSelector()
......@@ -387,46 +355,8 @@ namespace glare
ImGui::End();
}
void Application::drawVoxelController()
void Application::drawLinespaceControls()
{
ImGui::Begin("Voxels", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::PushID("##Voxels");
ImGui::TextColored({ 0.8f, 0.6f, 0.2f, 1.0f }, "Voxel and Line Space Settings");
ImGui::DragInt("Subdivisions", &m_voxel_parameters.subdivisions, 1, 1, 32);
ImGui::DragInt("Depth", &m_voxel_parameters.depth, 1, 1, 8);
if (m_voxel_times.update_time != -1)
{
ImGui::Value("Voxelizer Update Time (ms):", float(m_voxel_times.update_time));
}
if (m_voxel_times.update_time_render != -1)
{
ImGui::Value("Renderer Update Time (ms):", float(m_voxel_times.update_time_render));
}
if (m_voxel_times.update_linespace != -1)
{
ImGui::Value("Line Space Update Time (ms):", float(m_voxel_times.update_linespace));
}
if (ImGui::Button("Update Voxels and Line Space"))
{
//glare::core::ClockMS clock;
////Update voxelizer with new subdivisions and depth
//m_voxelizer->initialize(m_voxel_parameters.subdivisions, m_voxel_parameters.depth, m_mesh_collector);
//m_voxel_times.update_time = clock.time();
//clock.restart();
////re-upload voxels to GPU for rendering
//m_voxel_renderer->update(*m_voxelizer);
//m_voxel_times.update_time_render = clock.time();
//clock.restart();
////Update Line Space
//m_linespace->reset(m_voxelizer);
//m_voxel_times.update_linespace = clock.time();
}
ImGui::PopID();
ImGui::End();
}
}
......@@ -17,10 +17,10 @@ namespace glare
enum class AppRenderState
{
eLines = 0,
eDefault = 1,
eVoxels = 2,
eRaytrace = 3
eGLLines = 0,
eGLDefault = 1,
eLineSpace = 2,
ePathtracer = 3
};
enum class AppRayGenState
......@@ -43,10 +43,10 @@ namespace glare
void updateAdvanced();
void onKeyDown(controls::Key key, controls::KeyMods mods);
void drawGUI();
void drawControlItem(std::string title, std::string description);
void drawVoxelController();
void drawDebugWindow();
void drawSceneSelector();
void drawLinespaceControls();
//Scene
fs::path m_current_scene_root;
......@@ -67,7 +67,7 @@ namespace glare
std::shared_ptr<advanced::SceneCollector> m_collector;
std::shared_ptr<advanced::Raytracer> m_raytracer;
AppRenderState m_render_state = AppRenderState::eDefault;
AppRenderState m_render_state = AppRenderState::eGLDefault;
AppRayGenState m_ray_gen_state = AppRayGenState::eDefault;
struct
......@@ -79,17 +79,6 @@ namespace glare
unsigned sample_count;
} m_config;
struct {
int subdivisions = 2;
int depth = 1;
} m_voxel_parameters;
struct {
double update_time = -1;
double update_time_render = -1;
double update_linespace = -1;
} m_voxel_times;
};
}
......
......@@ -16,7 +16,7 @@ namespace glare
void LocalCollector::collect(const core::MeshRenderer &mesh, std::shared_ptr<LocalDatastructure> datastructure)
{
m_id = mesh.id();
m_material_id = mesh.getMaterial()->id();
m_datastructure = datastructure;
......@@ -95,5 +95,10 @@ namespace glare
{
return m_material_id;
}
size_t LocalCollector::id() const
{
return m_id;
}
}
}
......@@ -44,8 +44,9 @@ namespace glare
glm::mat4 m_transform;
size_t materialID() const;
size_t id() const;
private:
size_t m_id = 0;
size_t m_material_id = 0; //!< NOT the buffer position of this material!
std::shared_ptr<LocalDatastructure> m_datastructure;
math::Bounds m_bounds;
......
......@@ -41,6 +41,7 @@ namespace glare
m_bounds = collector.bounds();
m_bounds.max = m_bounds.min + glm::vec4(m_subdivision.size * glm::vec3(m_subdivision.subdivisions), 0);
m_lines.resize(calculateLineCount());
m_mesh_id = collector.id();
// initialize m_offsets
calculateOffsets();
......@@ -52,8 +53,6 @@ namespace glare
core::ClockMS clock;
size_t index = 0;
Log_Info << "Linespace is being generated now...";
//Loop through all possible and useful startface-endface-configurations
......@@ -188,5 +187,35 @@ namespace glare
{
return m_lines;
}
LineSpaceRenderer::LineSpaceRenderer(const advanced::SceneCollector &collector, const LineSpace &linespace)
: m_linespace(linespace), m_collector(collector)
{
std::vector<std::shared_ptr<core::Shader>> shaders = {
std::make_shared<core::Shader>(gl::ShaderType::eVertex, "/linespace/visualize/lines.vert"),
std::make_shared<core::Shader>(gl::ShaderType::eGeometry, "/linespace/visualize/lines.geom"),
std::make_shared<core::Shader>(gl::ShaderType::eFragment, "/linespace/visualize/lines.frag")
};
m_program = std::make_unique<core::ShaderProgram>(shaders);
m_vertex_array = std::make_unique<core::VertexArray>();
}
LineSpaceRenderer::~LineSpaceRenderer()
{
}
void LineSpaceRenderer::draw() const
{
m_program->use();
m_program->updateStorageBuffer("mesh_buffer", m_collector.meshBuffer());
m_program->updateStorageBuffer("line_buffer", m_linespace.lineBuffer());
m_program->updateUniformUInt("u_mesh", unsigned(m_linespace.m_mesh_id));
m_program->updateUniformUInt("u_triangle_count", unsigned(m_collector.meshCollectors().at(m_linespace.m_mesh_id)->triangles().size()));
m_program->updateUniformMatrix("u_view_projection", core::EngineState::main_camera->getViewProjection());
m_vertex_array->draw(gl::PrimitiveType::ePoints, m_linespace.lines().size());
}
}
}
......@@ -2,6 +2,7 @@
#define __LINESPACE_H
#include <array>
#include <advanced/meshlocal/SceneCollector.h>
#include <advanced/meshlocal/LocalCollector.h>
#include <advanced/meshlocal/LocalBVH.h>
#include <engine/rendering/Shader.h>
......@@ -87,8 +88,11 @@ namespace glare
size_t faceRangeIndex(Face in, Face out);
}
class LineSpaceRenderer;
class LineSpace
{
friend class LineSpaceRenderer;
public:
LineSpace();
~LineSpace();
......@@ -106,13 +110,29 @@ namespace glare
size_t calculateLineCount();
glm::vec3 patchCenter(const Patch &patch);
size_t m_mesh_id;
math::Bounds m_bounds;
std::array<size_t, 15> m_offsets;
math::UniformBoundsSubdivision m_subdivision;
std::vector<Line> m_lines;
core::Buffer<gl::BufferType::eShaderStorage> m_line_buffer;
};
class LineSpaceRenderer
{
public:
LineSpaceRenderer(const advanced::SceneCollector &collector, const LineSpace &linespace);
~LineSpaceRenderer();
void draw() const;
private:
const advanced::SceneCollector &m_collector;
const LineSpace &m_linespace;
std::unique_ptr<core::ShaderProgram> m_program;
std::unique_ptr<core::VertexArray> m_vertex_array;
};
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment