tonemapping reorder and another example render

This commit is contained in:
Ben Kyd
2019-09-16 15:34:46 +01:00
parent 8ba434e906
commit 1d9407a046
8 changed files with 66 additions and 64 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

View File

@@ -34,9 +34,9 @@ enum RenderMode {
};
enum ToneMapMode {
MODE_TONEMAP_CLAMP,
MODE_TONEMAP_REINHARD,
MODE_TONEMAP_EXP,
MODE_TONEMAP_CLAMP,
MODE_TONEMAP_BASIC
};

View File

@@ -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];

View File

@@ -76,7 +76,7 @@ public:
uint32_t* RenderData;
int XRes, YRes;
float Gamma = 1.0f / 2.3f;
float Gamma;
~FrameBuffer();

View File

@@ -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);

View File

@@ -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";

View File

@@ -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);

View File

@@ -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<Triangle*> tris = LoadTrianglesBasic("//home//ben//programming//inferno//resources//dragon-normals.obj", "//home//ben//programming//inferno//resources//resources");
std::vector<Triangle*> 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();