From 1908057434023af04709ba986d5affa19aec2bd9 Mon Sep 17 00:00:00 2001 From: TheRedShip Date: Sun, 12 Jan 2025 19:05:03 +0100 Subject: [PATCH] ~ | Refraction change --- imgui.ini | 2 +- includes/RT/Object.hpp | 1 + includes/RT/Scene.hpp | 1 + shaders/compute.glsl | 2 +- shaders/scatter.glsl | 4 ++-- srcs/class/Scene.cpp | 1 + srcs/class/SceneParser.cpp | 7 ++++--- srcs/class/Window.cpp | 7 ++++--- 8 files changed, 15 insertions(+), 10 deletions(-) diff --git a/imgui.ini b/imgui.ini index b0d7623..419840a 100644 --- a/imgui.ini +++ b/imgui.ini @@ -7,7 +7,7 @@ Pos=1515,93 Size=368,276 [Window][Material] -Pos=1620,199 +Pos=1601,205 Size=297,259 [Window][Camera] diff --git a/includes/RT/Object.hpp b/includes/RT/Object.hpp index edd88fb..0bff2ac 100644 --- a/includes/RT/Object.hpp +++ b/includes/RT/Object.hpp @@ -21,6 +21,7 @@ typedef struct s_Material float emission; float roughness; float metallic; + float refraction; int type; } Material; diff --git a/includes/RT/Scene.hpp b/includes/RT/Scene.hpp index 693eccb..f48eb80 100644 --- a/includes/RT/Scene.hpp +++ b/includes/RT/Scene.hpp @@ -39,6 +39,7 @@ struct GPUMaterial float emission; float roughness; float metallic; + float refraction; int type; }; diff --git a/shaders/compute.glsl b/shaders/compute.glsl index 70ce97d..db38c2a 100644 --- a/shaders/compute.glsl +++ b/shaders/compute.glsl @@ -26,8 +26,8 @@ struct GPUMaterial float emission; // 4 float roughness; // 4 float metallic; // 4 + float refraction; // 4 int type; // 4 - int texture_index; // 4 }; struct GPUCamera diff --git a/shaders/scatter.glsl b/shaders/scatter.glsl index 7b3e2b5..b33b2c6 100644 --- a/shaders/scatter.glsl +++ b/shaders/scatter.glsl @@ -17,12 +17,12 @@ Ray dieletricRay(hitInfo hit, Ray ray, GPUMaterial mat) float refraction_ratio; vec3 unit_direction; - refraction_ratio = 1.0f / mat.roughness; //mat.roughness = refraction (saving memory) + refraction_ratio = 1.0f / mat.refraction; if (dot(ray.direction, hit.normal) > 0.0f) { hit.normal = -hit.normal; - refraction_ratio = mat.roughness; + refraction_ratio = mat.refraction; } unit_direction = normalize(ray.direction); diff --git a/srcs/class/Scene.cpp b/srcs/class/Scene.cpp index 8b32490..8f476a9 100644 --- a/srcs/class/Scene.cpp +++ b/srcs/class/Scene.cpp @@ -142,6 +142,7 @@ void Scene::updateGPUData() gpu_mat.emission = material->emission; gpu_mat.roughness = material->roughness; gpu_mat.metallic = material->metallic; + gpu_mat.refraction = material->refraction; gpu_mat.type = material->type; _gpu_materials.push_back(gpu_mat); diff --git a/srcs/class/SceneParser.cpp b/srcs/class/SceneParser.cpp index aaca620..1090c85 100644 --- a/srcs/class/SceneParser.cpp +++ b/srcs/class/SceneParser.cpp @@ -61,13 +61,13 @@ void SceneParser::parseMaterial(std::stringstream &line) { float r,g,b; float emission; - float roughness; + float rough_refrac; float metallic; std::string type; Material *mat; - if (!(line >> r >> g >> b >> emission >> roughness >> metallic)) + if (!(line >> r >> g >> b >> emission >> rough_refrac >> metallic)) throw std::runtime_error("Material: Missing material properties"); if (!(line >> type)) @@ -77,8 +77,9 @@ void SceneParser::parseMaterial(std::stringstream &line) mat->color = glm::vec3(r / 255.0f, g / 255.0f, b / 255.0f); mat->emission = emission; - mat->roughness = roughness; + mat->roughness = rough_refrac; mat->metallic = metallic; + mat->refraction = rough_refrac; mat->type = 0; if (type == "LAM") diff --git a/srcs/class/Window.cpp b/srcs/class/Window.cpp index 696f69e..d16638a 100644 --- a/srcs/class/Window.cpp +++ b/srcs/class/Window.cpp @@ -200,11 +200,12 @@ void Window::imGuiRender() has_changed |= ImGui::SliderFloat("Emission", &mat.emission, 0.0f, 10.0f); if (mat.type == 1) - has_changed |= ImGui::SliderFloat("Roughness", &mat.roughness, 0.0f, 5.0f); + has_changed |= ImGui::SliderFloat("Refraction", &mat.refraction, 1.0f, 5.0f); else + { has_changed |= ImGui::SliderFloat("Roughness", &mat.roughness, 0.0f, 1.0f); - - has_changed |= ImGui::SliderFloat("Metallic", &mat.metallic, 0.0f, 1.0f); + has_changed |= ImGui::SliderFloat("Metallic", &mat.metallic, 0.0f, 1.0f); + } has_changed |= ImGui::SliderInt("Type", &mat.type, 0, 1); ImGui::PopID();