Commit 0ede5ba7 authored by unknown's avatar unknown
Browse files

Fixed #19 by resetting the IDs

parent eb3b9cc8
......@@ -92,7 +92,7 @@ bool traverseObjects(const in Ray ray, const in bool use_first, const in float m
for (int i = start; i <= end; i++)
{
float current_t = t_min;
const Mesh mesh = b_meshes[b_object_ids[i]];
const Mesh mesh = b_meshes[i];
if(force_bvh)
{
if(mesh.traverseBVH(ray.makeMeshLocal(mesh), use_first, current_t, false, hit, unused, t_min)){
......
......@@ -2,7 +2,7 @@
<!-- Splash screen settings -->
<item name="splash_image">/textures/splash.png</item>
<item name="splash_sound">/audio/swoosh.wav</item>
<item name="splash_background">0.1 0.4 0.7 1.0</item>
<item name="splash_background">#0277BD</item>
<item name="splash_duration">200</item>
<!-- General settings -->
......
......@@ -185,6 +185,7 @@ namespace glare
drawDebugWindow();
drawSceneSelector();
drawLinespaceControls();
ImGui::Render();
core::LightManager::getInstance().clear();
......@@ -284,120 +285,141 @@ namespace glare
static int render_state = 0;
render_state = int(m_render_state);
ImGui::Title("Render Mode");
ImGui::RadioButton("[OpenGL] Lines", &render_state, 0);
ImGui::RadioButton("[OpenGL] Shaded", &render_state, 1);
ImGui::RadioButton("Pathtracer", &render_state, 2);
ImGui::PushID("id_render_mode");
ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth());
ImGui::Combo("", &render_state, { "OpenGl Wireframe", "OpenGL Deferred", "Pathtracing" });
ImGui::PopItemWidth();
ImGui::PopID();
if (m_render_state != AppRenderState(render_state)) {
glFinish();
m_render_state = AppRenderState(render_state);
}
ImGui::EndGroup();
ImGui::SameLine();
ImGui::BeginGroup();
static int raygenstate = 0;
raygenstate = int(m_ray_gen_state);
ImGui::Title("Ray Generator");
ImGui::RadioButton("Default", &raygenstate, 1);
ImGui::RadioButton("GBuffer", &raygenstate, 0);
if (raygenstate != int(m_ray_gen_state)) {
m_ray_gen_state = AppRayGenState(raygenstate);
switch (m_ray_gen_state)
{
case AppRayGenState::eDefault:
m_raytracer->setGenerator(std::make_shared<advanced::RayGeneratorDefault>());
break;
case AppRayGenState::eGBuffer:
m_raytracer->setGenerator(std::make_shared<advanced::RayGeneratorGBuffer>());
break;
default:
break;
if (m_render_state == AppRenderState::ePathtracer) {
ImGui::Spacing();
ImGui::Title("Scene Settings");
ImGui::TextWrapped("By default, a transformation or mesh update will trigger a pathtracer sample count reset. If you want to limit this to explicit settings changes and camera movements, uncheck the following option.");
bool collector_active = m_collector->isActive();
ImGui::Checkbox("Reset on scene update", &collector_active);
if (collector_active != m_collector->isActive())
m_collector->setActive(collector_active);
ImGui::Spacing();
ImGui::BeginGroup();
static int raygenstate = 0;
raygenstate = int(m_ray_gen_state);
ImGui::Title("Ray Generator");
ImGui::PushID("id_ray_generator");
ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth());
ImGui::Combo("", &raygenstate, { "GBuffer", "Default (BVH)" });
ImGui::PopItemWidth();
ImGui::PopID();
if (raygenstate != int(m_ray_gen_state)) {
m_ray_gen_state = AppRayGenState(raygenstate);
switch (m_ray_gen_state)
{
case AppRayGenState::eDefault:
m_raytracer->setGenerator(std::make_shared<advanced::RayGeneratorDefault>());
break;
case AppRayGenState::eGBuffer:
m_raytracer->setGenerator(std::make_shared<advanced::RayGeneratorGBuffer>());
break;
default:
break;
}
}
}
ImGui::EndGroup();
ImGui::Value("Current Sample", m_raytracer->currentSamples());
int bounces = m_raytracer->bounces();
ImGui::DragInt("Bounces", &bounces, 1, 0, 30);
if (bounces != m_raytracer->bounces())
m_raytracer->setBounces(bounces);
auto ft = &advanced::Raytracer::maxSamples;
int max_samples = m_raytracer->maxSamples();
ImGui::DragInt("Max. Samples", &max_samples, 1, 1, 50000);
if (max_samples != m_raytracer->maxSamples())
m_raytracer->setMaxSamples(max_samples);
int spfr = m_raytracer->samplesPerFrame();
ImGui::DragInt("Samples per Frame", &spfr, 1, 1, 10);
if (spfr != m_raytracer->samplesPerFrame())
m_raytracer->setSamplesPerFrame(spfr);
bool collector_active = m_collector->isActive();
ImGui::Checkbox("Collector active", &collector_active);
if (collector_active != m_collector->isActive())
m_collector->setActive(collector_active);
float clamp_direct = m_raytracer->getClampDirect();
ImGui::DragFloat("Clamp Direct", &clamp_direct, 0.1f, 0.0f, 100.f);
if (clamp_direct != m_raytracer->getClampDirect())
m_raytracer->setClampDirect(clamp_direct);
float clamp_indirect = m_raytracer->getClampIndirect();
ImGui::DragFloat("Clamp Indirect", &clamp_indirect, 0.1f, 0.0f, 100.f);
if (clamp_indirect != m_raytracer->getClampIndirect())
m_raytracer->setClampIndirect(clamp_indirect);
float acc = m_raytracer->getAccuracyThreshold();
ImGui::DragFloat("Accuracy Quality", &acc, 0.001f, 0.0f, 1.f);
if (acc != m_raytracer->getAccuracyThreshold())
m_raytracer->setAccuracyThreshold(acc);
float shd = m_raytracer->getShadowThreshold();
ImGui::DragFloat("Shadow Quality", &shd, 0.001f, 0.0f, 1.f);
if (shd != m_raytracer->getShadowThreshold())
m_raytracer->setShadowThreshold(shd);
struct qpres {
float acc;
float shd;
};
std::vector<qpres> presets
{
{ 0.f, 1.0f },
{ 0.f, 0.75f },
{ 0.f, 0.5f },
{ 0.f, 0.25f },
{ 0.f, 0.001f },
{ 1.0f, 0.f },
{ 0.75f, 0.f },
{ 0.5f, 0.f },
{ 0.25f, 0.f },
{ 0.001f, 0.f },
{ 0.f, 0.f },
};
int i = 0;
for (qpres &preset : presets) {
if (ImGui::Button(("Preset " + std::to_string(i++)).c_str())) {
m_raytracer->setAccuracyThreshold(preset.acc);
m_raytracer->setShadowThreshold(preset.shd);
ImGui::EndGroup();
ImGui::Spacing();
ImGui::PushID("id_samples");
ImGui::Title("Samples");
ImGui::ProgressBar(m_raytracer->currentSamples() / float(m_raytracer->maxSamples()), ImVec2(-1, 0), ("Current: " + std::to_string(m_raytracer->currentSamples()) + " of " + std::to_string(m_raytracer->maxSamples())).c_str());
ImGui::Spacing();
int max_samples = m_raytracer->maxSamples();
ImGui::DragInt("Maximum", &max_samples, 1, 1, 50000);
if (max_samples != m_raytracer->maxSamples())
m_raytracer->setMaxSamples(max_samples);
int spfr = m_raytracer->samplesPerFrame();
ImGui::DragInt("per frame", &spfr, 1, 1, 10);
if (spfr != m_raytracer->samplesPerFrame())
m_raytracer->setSamplesPerFrame(spfr);
ImGui::PopID();
ImGui::Spacing();
ImGui::Title("Bounces");
ImGui::PushID("id_bounces");
ImGui::TextWrapped("The global bounce limit clamps down all effect-dependant bounce limits to a unified maximum value.");
int bounces = m_raytracer->bounces();
ImGui::DragInt("Global Limit", &bounces, 1, 0, 15);
if (bounces != m_raytracer->bounces())
m_raytracer->setBounces(bounces);
if (ImGui::CollapsingHeader("Bounce Thresholds"))
{
drawEffectBounceControl("Diffuse", advanced::EffectType::eDiffuse);
drawEffectBounceControl("Translucent", advanced::EffectType::eTranslucent);
drawEffectBounceControl("Reflective", advanced::EffectType::eReflection);
drawEffectBounceControl("Refractive", advanced::EffectType::eRefraction);
drawEffectBounceControl("Transparence", advanced::EffectType::eTransparent);
drawEffectBounceControl("Emissive", advanced::EffectType::eEmissive);
}
if ((i) % 4 != 0) {
ImGui::SameLine();
ImGui::Spacing();
ImGui::TextWrapped("The direct clamp setting will lead to the primary ray result color being clamped down to a set maximum. That means each color component will be clamped. The same applies to the \"clamp indirect\" setting for non-primary bounces.");
float clamp_direct = m_raytracer->getClampDirect();
ImGui::DragFloat("Clamp Direct", &clamp_direct, 0.1f, 0.0f, 100.f);
if (clamp_direct != m_raytracer->getClampDirect())
m_raytracer->setClampDirect(clamp_direct);
float clamp_indirect = m_raytracer->getClampIndirect();
ImGui::DragFloat("Clamp Indirect", &clamp_indirect, 0.1f, 0.0f, 100.f);
if (clamp_indirect != m_raytracer->getClampIndirect())
m_raytracer->setClampIndirect(clamp_indirect);
ImGui::PopID();
auto &&style = ImGui::GetStyle();
auto col_bt = style.Colors[ImGuiCol_Button];
auto col_bt_h = style.Colors[ImGuiCol_ButtonHovered];
auto col_bt_a = style.Colors[ImGuiCol_ButtonActive];
auto color_bt = color::hex<color::rgba32f>("#4CAF50");
auto color_bt_h = color::hex<color::rgba32f>("#81C784");
auto color_bt_a = color::hex<color::rgba32f>("#2E7D32");
style.Colors[ImGuiCol_Button] = ImVec4(color_bt.r, color_bt.g, color_bt.b, color_bt.a);
style.Colors[ImGuiCol_ButtonHovered] = ImVec4(color_bt_h.r, color_bt_h.g, color_bt_h.b, color_bt_h.a);
style.Colors[ImGuiCol_ButtonActive] = ImVec4(color_bt_a.r, color_bt_a.g, color_bt_a.b, color_bt_a.a);
ImGui::Spacing();
ImGui::Title("Save Render as...");
ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth()/2 );
if (ImGui::Button("32bit HDR"))
{
m_raytracer->saveRenderHDR(core::asset("/screenshots/render.hdr"));
}
}
if (ImGui::Button("Save Render as HDR"))
{
m_raytracer->saveRenderHDR(core::asset("/screenshots/render.hdr"));
}
if (ImGui::Button("Save Render as PNG"))
{
m_raytracer->saveRender(core::asset("/screenshots/render.png"));
ImGui::SameLine();
if (ImGui::Button("8bit PNG"))
{
m_raytracer->saveRender(core::asset("/screenshots/render.png"));
}
ImGui::PopItemWidth();
style.Colors[ImGuiCol_Button] = col_bt;
style.Colors[ImGuiCol_ButtonHovered] = col_bt_h;
style.Colors[ImGuiCol_ButtonActive] = col_bt_a;
}
ImGui::Separator();
......@@ -456,8 +478,55 @@ namespace glare
ImGui::End();
}
void Application::drawLSBounceControl(const std::string &label, advanced::EffectType effect)
{
int val = m_raytracer->getLinespaceBounceThreshold(effect);
ImGui::DragInt(label.c_str(), &val, 1.f, 0, m_raytracer->getEffectBounces(effect));
if (val != m_raytracer->getLinespaceBounceThreshold(effect))
{
m_raytracer->setLinespaceBounceThresholds(effect, uint8_t(val));
}
}
void Application::drawEffectBounceControl(const std::string &label, advanced::EffectType effect)
{
int val = m_raytracer->getEffectBounces(effect);
ImGui::DragInt(label.c_str(), &val, 1.f, 0, 15);
if (val != m_raytracer->getEffectBounces(effect))
{
m_raytracer->setEffectBounces(effect, uint8_t(val));
}
}
void Application::drawLinespaceControls()
{
ImGui::Begin("Linespace Settings", nullptr, ImVec2(200, 300));
ImGui::Title("PDF Thresholds");
ImGui::TextWrapped("The following threshold values will determine as of which accumulated PDF value the Line Space should be used instead of the BVH.");
{
float acc = m_raytracer->getAccuracyThreshold();
ImGui::DragFloat("Direct", &acc, 0.001f, 0.0f, 1.f);
if (acc != m_raytracer->getAccuracyThreshold())
m_raytracer->setAccuracyThreshold(acc);
float shd = m_raytracer->getShadowThreshold();
ImGui::DragFloat("Shadow", &shd, 0.001f, 0.0f, 1.f);
if (shd != m_raytracer->getShadowThreshold())
m_raytracer->setShadowThreshold(shd);
}
ImGui::Title("Bounce Thresholds");
ImGui::TextWrapped("The following threshold values will determine as of which bounce the Line Space should be used instead of the BVH. This can vary for every kind of effect.");
{
drawLSBounceControl("Diffuse", advanced::EffectType::eDiffuse);
drawLSBounceControl("Translucent", advanced::EffectType::eTranslucent);
drawLSBounceControl("Reflective", advanced::EffectType::eReflection);
drawLSBounceControl("Refractive", advanced::EffectType::eRefraction);
drawLSBounceControl("Transparence", advanced::EffectType::eTransparent);
drawLSBounceControl("Emissive", advanced::EffectType::eEmissive);
}
ImGui::End();
}
}
......@@ -46,6 +46,8 @@ namespace glare
void drawDebugWindow();
void drawSceneSelector();
void drawLinespaceControls();
void drawLSBounceControl(const std::string &label, advanced::EffectType effect);
void drawEffectBounceControl(const std::string &label, advanced::EffectType effect);
//Scene
fs::path m_current_scene_root;
......
......@@ -275,11 +275,22 @@ namespace glare
Log_Debug << "BVH info: Construction took " << timer.time() << " microseconds";
m_meshes.resize(mesh_ids.size());
for (size_t id : mesh_ids)
for (int i = 0; i < mesh_ids.size(); ++i)
{
size_t id = mesh_ids[i];
mesh_ids[i] = i;
const auto &collector = m_mesh_collectors[id];
m_meshes[id] = (collector->makeMesh(glm::uint(m_material_filter[collector->materialID()])));
m_meshes[i] = (collector->makeMesh(glm::uint(m_material_filter[collector->materialID()])));
m_meshes[i].id = i;
}
//size_t target_index = 0;
//for (size_t id : mesh_ids)
//{
// const auto &collector = m_mesh_collectors[id];
// m_meshes[id] = (collector->makeMesh(glm::uint(m_material_filter[collector->materialID()])));
//}
}
bool shouldSplit(const math::Bounds &centroid)
......
......@@ -64,6 +64,12 @@ namespace glare
}
m_bounce_count_thresholds[unsigned(type)] = clamped;
reset();
}
uint8_t Raytracer::getEffectBounces(EffectType type)
{
return m_bounce_count_thresholds[unsigned(type)];
}
void Raytracer::setLinespaceBounceThresholds(EffectType type, uint8_t bounces)
......@@ -76,6 +82,12 @@ namespace glare
}
m_ls_bounce_count_thresholds[unsigned(type)] = clamped;
reset();
}
uint8_t Raytracer::getLinespaceBounceThreshold(EffectType type)
{
return m_ls_bounce_count_thresholds[unsigned(type)];
}
void Raytracer::reset()
......
......@@ -41,7 +41,9 @@ namespace glare
void saveRender(fs::path target) const;
void setEffectBounces(EffectType type, uint8_t bounces);
uint8_t getEffectBounces(EffectType type);
void setLinespaceBounceThresholds(EffectType type, uint8_t bounces);
uint8_t getLinespaceBounceThreshold(EffectType type);
//template<typename DataStruct>
void setGenerator(std::shared_ptr<RayGeneratorBase> generator);
......
#include "Shader.h"
#include <regex>
#include <map>
#include <engine/EngineState.h>
#include <engine/Console.h>
#include <fstream>
#include <cctype>
......
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