diff --git a/progress/25 dragon oustisde, rinehard tonemap.png b/progress/25 dragon oustisde, rinehard tonemap.png new file mode 100644 index 0000000..6672e9d Binary files /dev/null and b/progress/25 dragon oustisde, rinehard tonemap.png differ diff --git a/src/common.hpp b/src/common.hpp index 9bc81d0..3cce325 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -34,9 +34,9 @@ enum RenderMode { }; enum ToneMapMode { - MODE_TONEMAP_CLAMP, MODE_TONEMAP_REINHARD, MODE_TONEMAP_EXP, + MODE_TONEMAP_CLAMP, MODE_TONEMAP_BASIC }; diff --git a/src/display/framebuffer.cpp b/src/display/framebuffer.cpp index 92fb0b3..a9a4529 100644 --- a/src/display/framebuffer.cpp +++ b/src/display/framebuffer.cpp @@ -63,50 +63,60 @@ void FrameBuffer::PostProcess(ToneMapMode mode) { memset((void*)m_swapBuffer, 0, (XRes * YRes) * sizeof(glm::vec3)); // reinhard - if (mode == MODE_TONEMAP_BASIC) { - - float max = 0.0f; - for (int x = 0; x < XRes; x++) - for (int y = 0; y < YRes; y++) { - if (RenderPostProcess[y * this->XRes + x].r > max) max = RenderPostProcess[y * this->XRes + x].r; - if (RenderPostProcess[y * this->XRes + x].g > max) max = RenderPostProcess[y * this->XRes + x].g; - if (RenderPostProcess[y * this->XRes + x].b > max) max = RenderPostProcess[y * this->XRes + x].b; - } + switch (mode) { + case MODE_TONEMAP_REINHARD: + { + for (int x = 0; x < XRes; x++) + for (int y = 0; y < YRes; y++) { + m_swapBuffer[y * this->XRes + x] = RenderPostProcess[y * this->XRes + x] / + (RenderPostProcess[y * this->XRes + x] + 1.0f); + } - for (int x = 0; x < XRes; x++) - for (int y = 0; y < YRes; y++) { - m_swapBuffer[y * this->XRes + x] = RenderPostProcess[y * this->XRes + x] / max; - } - - } else if (mode == MODE_TONEMAP_CLAMP) { + break; + } + case MODE_TONEMAP_EXP: + { + for (int x = 0; x < XRes; x++) + for (int y = 0; y < YRes; y++) { + m_swapBuffer[y * this->XRes + x] = 1.0f - exp2(RenderPostProcess[y * this->XRes + x] * 1.0f); + } - for (int x = 0; x < XRes; x++) - for (int y = 0; y < YRes; y++) { - m_swapBuffer[y * this->XRes + x] = Clamp(RenderPostProcess[y * this->XRes + x], 1.0f, 0.0f); - } - - } else if (mode == MODE_TONEMAP_REINHARD) { + break; + } + case MODE_TONEMAP_CLAMP: + { + for (int x = 0; x < XRes; x++) + for (int y = 0; y < YRes; y++) { + m_swapBuffer[y * this->XRes + x] = Clamp(RenderPostProcess[y * this->XRes + x], 1.0f, 0.0f); + } - for (int x = 0; x < XRes; x++) - for (int y = 0; y < YRes; y++) { - m_swapBuffer[y * this->XRes + x] = RenderPostProcess[y * this->XRes + x] / (RenderPostProcess[y * this->XRes + x] + 1.0f); - } + break; + } + case MODE_TONEMAP_BASIC: + { + float max = 0.0f; - } else if (mode == MODE_TONEMAP_EXP) { + for (int x = 0; x < XRes; x++) + for (int y = 0; y < YRes; y++) { + if (RenderPostProcess[y * this->XRes + x].r > max) max = RenderPostProcess[y * this->XRes + x].r; + if (RenderPostProcess[y * this->XRes + x].g > max) max = RenderPostProcess[y * this->XRes + x].g; + if (RenderPostProcess[y * this->XRes + x].b > max) max = RenderPostProcess[y * this->XRes + x].b; + } - for (int x = 0; x < XRes; x++) - for (int y = 0; y < YRes; y++) { - m_swapBuffer[y * this->XRes + x] = 1.0f - exp(RenderPostProcess[y * this->XRes + x] * 1.0f); - } - - } else { - for (int x = 0; x < XRes; x++) - for (int y = 0; y < YRes; y++) { - m_swapBuffer[y * this->XRes + x] = Clamp(RenderPostProcess[y * this->XRes + x], 1.0f, 0.0f); - } + for (int x = 0; x < XRes; x++) + for (int y = 0; y < YRes; y++) { + m_swapBuffer[y * this->XRes + x] = RenderPostProcess[y * this->XRes + x] / max; + } + + break; + } + default: + { + break; + } } - + for (int x = 0; x < XRes; x++) for (int y = 0; y < YRes; y++) { RenderPostProcess[y * this->XRes + x] = m_swapBuffer[y * this->XRes + x]; diff --git a/src/display/framebuffer.hpp b/src/display/framebuffer.hpp index b21118b..6ef9a08 100644 --- a/src/display/framebuffer.hpp +++ b/src/display/framebuffer.hpp @@ -76,7 +76,7 @@ public: uint32_t* RenderData; int XRes, YRes; - float Gamma = 1.0f / 2.3f; + float Gamma; ~FrameBuffer(); diff --git a/src/engine/progressiverenderer.cpp b/src/engine/progressiverenderer.cpp index 16dfdd5..9b55a66 100644 --- a/src/engine/progressiverenderer.cpp +++ b/src/engine/progressiverenderer.cpp @@ -84,7 +84,7 @@ void ProgressiveRenderer::Input() { ImGui::Combo("Render Mode", &m_renderModeSelected, renderItems, IM_ARRAYSIZE(renderItems)); m_mode = (RenderMode)m_renderModeSelected; - const char* toneMapItems[] = { "Clamp", "Reinhard Tonamap", "Exponential Tonemap", "Basic Tonemap" }; + const char* toneMapItems[] = { "Reinhard Tonamap", "Exponential Tonemap", "Clamp", "Basic Tonemap" }; ImGui::Combo("ToneMap Mode", &m_toneMapModeSelected, toneMapItems, IM_ARRAYSIZE(toneMapItems)); ImGui::SliderFloat("Gamma", &m_gamma, 1.0f, 4.0f); @@ -117,7 +117,7 @@ void ProgressiveRenderer::Render() { m_engine->Mode = m_mode; m_engine->PostProcess(m_threadPool->ThreadFrameBuffer->RenderTarget, m_threadPool->ThreadFrameBuffer->RenderPostProcess, m_scene->w, m_scene->h); - // Denoise + // Denoise in HDR space m_threadPool->ThreadFrameBuffer->PostProcess((ToneMapMode)m_toneMapModeSelected); diff --git a/src/engine/progressiverenderer.hpp b/src/engine/progressiverenderer.hpp index 868120d..04bc3c7 100644 --- a/src/engine/progressiverenderer.hpp +++ b/src/engine/progressiverenderer.hpp @@ -75,7 +75,7 @@ private: int m_framesRendererd = 0; // Gamma to pass to the framebuffer - float m_gamma = 2.3f; + float m_gamma = 2.2f; // Image save path to pass to the framebuffer std::string m_imageSavePath = "image.png"; diff --git a/src/engine/renderengine.hpp b/src/engine/renderengine.hpp index a1f7be8..18a9774 100644 --- a/src/engine/renderengine.hpp +++ b/src/engine/renderengine.hpp @@ -10,9 +10,13 @@ class Ray; class RenderEngine { public: + // Default constructor RenderEngine(); + // Sets the active rendering scene for the engine void SetScene(Scene* scene); + + // Recursive getcolour glm::vec3 GetColour(Ray ray, int& depth); void PostProcess(glm::vec3* src, glm::vec3* dst, int w, int h); diff --git a/test/main.cpp b/test/main.cpp index eab9584..0cfc9ba 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -2,8 +2,8 @@ #include "../src/inferno.hpp" -static const int width = 1000; -static const int height = 1000; +static const int width = 1080; +static const int height = 720; int main(int argc, char** argv) { InfernoEngine inferno; @@ -26,31 +26,19 @@ int main(int argc, char** argv) { //Sphere sphere1({ 1.3f, -0.8f, -5.0f }, 0.2f, new Material({ 0.817f, 0.374, 0.574 })); //scene->objects.push_back(&sphere1); - //Sphere sphere({ 0.0f, 0.0f, -5.0f }, 1.0f, new Material({ 0.817f, 0.374, 0.574 })); + Sphere sphere({ 0.0f, 0.0f, -5.0f }, 1.0f, new Material({ 0.817f, 0.374, 0.574 })); // sphere.material->NormalTexture = new Texture("E:/Projects/Inferno/resources/textures/dirt-normal.jpg"); - // sphere.material->NormalTexture = new Texture("/home/ben/programming/inferno/resources/textures/dirt-normal.jpg"); - //scene->objects.push_back(&sphere); + sphere.material->NormalTexture = new Texture("/home/ben/programming/inferno/resources/textures/dirt-normal.jpg"); + scene->objects.push_back(&sphere); - //Sphere light({ 35.0f, 50.0f, 25.0f }, 25.0f, new Material({ 1.0f, 1.0f, 1.0f }, 0.0f, 200.0f)); - //scene->objects.push_back(&light); + Sphere light({ 35.0f, 50.0f, 25.0f }, 25.0f, new Material({ 1.0f, 1.0f, 1.0f }, 0.0f, 200.0f)); + scene->objects.push_back(&light); - //Plane plane({ 0.0f,-1.0f, 0.0f }, { 0.0f, -1.0f, 0.0f }, new Material({ 0.2f, 0.2f, 0.2f })); + Plane plane({ 0.0f,-1.0f, 0.0f }, { 0.0f, -1.0f, 0.0f }, new Material({ 0.2f, 0.2f, 0.2f })); // plane.material->NormalTexture = new Texture("E:/Projects/Inferno/resources/textures/normals.png"); - // plane.material->NormalTexture = new Texture("/home/ben/programming/inferno/resources/textures/normals.png"); - //scene->objects.push_back(&plane); + plane.material->NormalTexture = new Texture("/home/ben/programming/inferno/resources/textures/normals.png"); + scene->objects.push_back(&plane); - scene->objects.push_back(new Sphere({ 35.0f, 26.0f, 25.0f }, 15.0f, new Material({ 1.0f, 1.0f, 1.0f }, 0.0f, 50.0f))); - scene->objects.push_back(new Sphere({-0.457001f, 0.19f, -3.53899f}, 0.02f, new Material({ 1.0f, 0.9f, 0.8f }, 0.0f, 5000.0f))); - scene->objects.push_back(new Plane( { 0.0f, -1.0f, 0.0f }, { 0.0f, -1.0f, 0.0f }, new Material({ 0.847f, 0.792f, 0.658f }, 0.2f))); - - //std::vector tris = LoadTrianglesBasic("//home//ben//programming//inferno//resources//dragon-normals.obj", "//home//ben//programming//inferno//resources//resources"); - std::vector tris = LoadTrianglesBasic("E://Projects//Inferno//resources//models//dragon-normals.obj", "E://Projects//Inferno//resources//models"); - - Mesh* mesh = new Mesh(tris); - mesh->Translate({ 0.2f, -1.04, -3.8f }); - //mesh->Translate({ 0.0f, -1.0, -4.0f }); - mesh->Optimise(); - scene->meshs.push_back(mesh); inferno.SetScene(scene); inferno.Ready();