Skip to content

Commit

Permalink
Run denoiser everytime option is checked
Browse files Browse the repository at this point in the history
  • Loading branch information
knightcrawler25 committed Jan 1, 2022
1 parent 44c0b6d commit df26edf
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 28 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ A physically based path tracer that runs in a GLSL fragment shader.

![Jinx](./screenshots/Jinx.png)

![Slum](./screenshots/Slum.png)

Features
--------
- Unidirectional path tracer
- RadeonRays 2.0 as a BVH builder (BVH traversal doesn't use RadeonRays as it is done in a fragment shader)
- BVH builder from RadeonRays 2.0
- Disney BSDF
- Texture Mapping (Albedo, Metallic-Roughness, Normal, Emission)
- Analytic Lights (Sphere, Rect, Directional)
Expand Down
Binary file added screenshots/Slum.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ void LoadScene(std::string sceneName)
// Add a default HDR if there are no lights in the scene
if (!scene->hdrData)
{
scene->AddHDR(assetsDir + "HDR/san_giuseppe_bridge_blurred.hdr");
scene->AddHDR(assetsDir + "HDR/white_cliff_top_1k.hdr");
renderOptions.useEnvMap = scene->lights.empty() ? true : false;
renderOptions.hdrMultiplier = 1.0f;
renderOptions.hdrMultiplier = 1.5f;
}

scene->renderOptions = renderOptions;
Expand Down Expand Up @@ -374,7 +374,6 @@ void MainLoop(void* arg)
scene->camera->aperture = aperture / 1000.0f;
optionsChanged |= ImGui::SliderFloat("Focal Distance", &scene->camera->focalDist, 0.01f, 50.0f);
ImGui::Text("Pos: %.2f, %.2f, %.2f", scene->camera->position.x, scene->camera->position.y, scene->camera->position.z);
ImGui::Text("Dir: %.2f, %.2f, %.2f", scene->camera->forward.x, scene->camera->forward.y, scene->camera->forward.z);
}

scene->dirty = false;
Expand Down
2 changes: 1 addition & 1 deletion src/core/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ namespace GLSLPT
RadeonRays::bbox bounds = sceneBvh->Bounds();
Vec3 extents = bounds.extents() * 5.0f;
Vec3 center = bounds.center();
AddCamera(Vec3(extents.x, center.y, extents.z), center, 45.0f);
AddCamera(Vec3(0, center.y, extents.x), center, 45.0f);
}

initialized = true;
Expand Down
51 changes: 28 additions & 23 deletions src/core/TiledRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,37 +446,42 @@ namespace GLSLPT
Renderer::Update(secondsElapsed);

// Denoise Image
if (scene->renderOptions.enableDenoiser && !denoised || (frameCounter % (scene->renderOptions.denoiserFrameCnt * (numTiles.x * numTiles.y)) == 0))
if (scene->renderOptions.enableDenoiser && sampleCounter > 1)
{
// FIXME: Figure out a way to have transparency with denoiser
glBindTexture(GL_TEXTURE_2D, tileOutputTexture[1 - currentBuffer]);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_FLOAT, denoiserInputFramePtr);
if (!denoised || (frameCounter % (scene->renderOptions.denoiserFrameCnt * (numTiles.x * numTiles.y)) == 0))
{
// FIXME: Figure out a way to have transparency with denoiser
glBindTexture(GL_TEXTURE_2D, tileOutputTexture[1 - currentBuffer]);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_FLOAT, denoiserInputFramePtr);

// Create an Intel Open Image Denoise device
oidn::DeviceRef device = oidn::newDevice();
device.commit();
// Create an Intel Open Image Denoise device
oidn::DeviceRef device = oidn::newDevice();
device.commit();

// Create a denoising filter
oidn::FilterRef filter = device.newFilter("RT"); // generic ray tracing filter
filter.setImage("color", denoiserInputFramePtr, oidn::Format::Float3, renderSize.x, renderSize.y, 0, 0, 0);
filter.setImage("output", frameOutputPtr, oidn::Format::Float3, renderSize.x, renderSize.y, 0, 0, 0);
filter.set("hdr", false);
filter.commit();
// Create a denoising filter
oidn::FilterRef filter = device.newFilter("RT"); // generic ray tracing filter
filter.setImage("color", denoiserInputFramePtr, oidn::Format::Float3, renderSize.x, renderSize.y, 0, 0, 0);
filter.setImage("output", frameOutputPtr, oidn::Format::Float3, renderSize.x, renderSize.y, 0, 0, 0);
filter.set("hdr", false);
filter.commit();

// Filter the image
filter.execute();
// Filter the image
filter.execute();

// Check for errors
const char* errorMessage;
if (device.getError(errorMessage) != oidn::Error::None)
std::cout << "Error: " << errorMessage << std::endl;
// Check for errors
const char* errorMessage;
if (device.getError(errorMessage) != oidn::Error::None)
std::cout << "Error: " << errorMessage << std::endl;

// Copy the denoised data to denoisedTexture
glBindTexture(GL_TEXTURE_2D, denoisedTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, renderSize.x, renderSize.y, 0, GL_RGB, GL_FLOAT, frameOutputPtr);
// Copy the denoised data to denoisedTexture
glBindTexture(GL_TEXTURE_2D, denoisedTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, renderSize.x, renderSize.y, 0, GL_RGB, GL_FLOAT, frameOutputPtr);

denoised = true;
denoised = true;
}
}
else
denoised = false;

if (scene->dirty)
{
Expand Down
7 changes: 7 additions & 0 deletions src/loaders/Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ namespace GLSLPT
char transparentBackground[10] = "None";
char enableBackground[10] = "None";
char independentRenderSize[10] = "None";
char enableTonemap[10] = "None";

while (fgets(line, kMaxLineLength, file))
{
Expand All @@ -252,6 +253,7 @@ namespace GLSLPT
sscanf(line, " tileHeight %i", &renderOptions.tileHeight);
sscanf(line, " enableRR %s", enableRR);
sscanf(line, " RRDepth %i", &renderOptions.RRDepth);
sscanf(line, " enableTonemap %s", enableTonemap);
sscanf(line, " useAces %s", useAces);
sscanf(line, " texArrayWidth %i", &renderOptions.texArrayWidth);
sscanf(line, " texArrayHeight %i", &renderOptions.texArrayHeight);
Expand Down Expand Up @@ -306,6 +308,11 @@ namespace GLSLPT
else if (strcmp(independentRenderSize, "True") == 0)
renderOptions.independentRenderSize = true;

if (strcmp(enableTonemap, "False") == 0)
renderOptions.enableTonemap = false;
else if (strcmp(enableTonemap, "True") == 0)
renderOptions.enableTonemap = true;

if (!renderOptions.independentRenderSize)
renderOptions.windowResolution = renderOptions.renderResolution;
}
Expand Down

0 comments on commit df26edf

Please sign in to comment.