43-denoise: Style cleanup. Added screenshot.
This commit is contained in:
parent
27de3100b7
commit
cbccb2386a
@ -34,21 +34,21 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* References:
|
||||
* Reference(s):
|
||||
*
|
||||
* Spatiotemporal Variance-Guided Filtering: Real-Time Reconstruction for
|
||||
* Path-Traced Global Illumination. by Christoph Schied and more.
|
||||
* - SVGF denoising algorithm
|
||||
* SVGF denoising algorithm
|
||||
*
|
||||
* Streaming G-Buffer Compression for Multi-Sample Anti-Aliasing.
|
||||
* by E. Kerzner and M. Salvi.
|
||||
* - details about history comparison for temporal denoising filter
|
||||
* details about history comparison for temporal denoising filter
|
||||
*
|
||||
* Edge-Avoiding À-Trous Wavelet Transform for Fast Global Illumination
|
||||
* Filtering. by Holger Dammertz and more.
|
||||
* - details about a-trous algorithm for spatial denoising filter
|
||||
* details about a-trous algorithm for spatial denoising filter
|
||||
*/
|
||||
|
||||
|
||||
#include <common.h>
|
||||
#include <camera.h>
|
||||
#include <bgfx_utils.h>
|
||||
@ -56,7 +56,6 @@
|
||||
#include <bx/rng.h>
|
||||
#include <bx/os.h>
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
#define DENOISE_MAX_PASSES 6
|
||||
@ -343,6 +342,7 @@ public:
|
||||
{
|
||||
meshUnload(m_meshes[ii]);
|
||||
}
|
||||
|
||||
meshUnload(m_ground);
|
||||
|
||||
bgfx::destroy(m_normalTexture);
|
||||
@ -383,7 +383,8 @@ public:
|
||||
if (!entry::processEvents(m_width, m_height, m_debug, m_reset, &m_mouseState) )
|
||||
{
|
||||
// skip processing when minimized, otherwise crashing
|
||||
if (0 == m_width || 0 == m_height)
|
||||
if (0 == m_width
|
||||
|| 0 == m_height)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -427,7 +428,7 @@ public:
|
||||
|
||||
// Draw everything into gbuffer
|
||||
{
|
||||
bgfx::setViewName(view, "gbuffer");
|
||||
bgfx::setViewName(view, "GBuffer");
|
||||
bgfx::setViewClear(view
|
||||
, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH
|
||||
, 0
|
||||
@ -456,7 +457,7 @@ public:
|
||||
|
||||
// Shade gbuffer
|
||||
{
|
||||
bgfx::setViewName(view, "combine");
|
||||
bgfx::setViewName(view, "Combine");
|
||||
|
||||
// for some reason, previous draws texture lingering in transform stack
|
||||
// need to clear out, otherwise this copy is garbled. this used to work
|
||||
@ -468,6 +469,7 @@ public:
|
||||
bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
|
||||
bgfx::setViewTransform(view, NULL, orthoProj);
|
||||
bgfx::setViewFrameBuffer(view, m_currentColor.m_buffer);
|
||||
|
||||
bgfx::setState(0
|
||||
| BGFX_STATE_WRITE_RGB
|
||||
| BGFX_STATE_WRITE_A
|
||||
@ -475,9 +477,13 @@ public:
|
||||
);
|
||||
bgfx::setTexture(0, s_color, m_gbufferTex[GBUFFER_RT_COLOR]);
|
||||
bgfx::setTexture(1, s_normal, m_gbufferTex[GBUFFER_RT_NORMAL]);
|
||||
|
||||
m_uniforms.submit();
|
||||
|
||||
screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
|
||||
|
||||
bgfx::submit(view, m_combineProgram);
|
||||
|
||||
++view;
|
||||
}
|
||||
|
||||
@ -487,7 +493,7 @@ public:
|
||||
// denoise temporal pass
|
||||
if (m_useTemporalPass && m_havePrevious)
|
||||
{
|
||||
bgfx::setViewName(view, "denoise temporal");
|
||||
bgfx::setViewName(view, "Denoise Temporal");
|
||||
|
||||
bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
|
||||
bgfx::setViewTransform(view, NULL, orthoProj);
|
||||
@ -505,8 +511,11 @@ public:
|
||||
bgfx::setTexture(4, s_previousNormal, m_previousNormal.m_texture);
|
||||
|
||||
m_uniforms.submit();
|
||||
|
||||
screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
|
||||
|
||||
bgfx::submit(view, m_denoiseTemporalProgram);
|
||||
|
||||
++view;
|
||||
|
||||
lastTex = m_temporaryColor.m_texture;
|
||||
@ -516,46 +525,54 @@ public:
|
||||
if (0 < m_denoisePasses)
|
||||
{
|
||||
// variable number of passes for denoise, alternate between two textures/buffers
|
||||
bgfx::FrameBufferHandle destBuffer[DENOISE_MAX_PASSES] = {
|
||||
bgfx::FrameBufferHandle destBuffer[] =
|
||||
{
|
||||
m_previousDenoise.m_buffer,
|
||||
m_currentColor.m_buffer,
|
||||
m_temporaryColor.m_buffer,
|
||||
m_currentColor.m_buffer,
|
||||
m_temporaryColor.m_buffer,
|
||||
m_currentColor.m_buffer
|
||||
m_currentColor.m_buffer,
|
||||
};
|
||||
BX_STATIC_ASSERT(BX_COUNTOF(destBuffer) == DENOISE_MAX_PASSES);
|
||||
|
||||
uint32_t denoisePasses = bx::min(DENOISE_MAX_PASSES, m_denoisePasses);
|
||||
for (uint32_t i = 0; i < denoisePasses; ++i)
|
||||
const uint32_t denoisePasses = bx::min(DENOISE_MAX_PASSES, m_denoisePasses);
|
||||
|
||||
for (uint32_t ii = 0; ii < denoisePasses; ++ii)
|
||||
{
|
||||
const char buffer[] = { 'd', 'e', 'n', 'o', 'i', 's', 'e', ' ', char('0'+i), 0 };
|
||||
bgfx::setViewName(view, buffer);
|
||||
char name[64];
|
||||
bx::snprintf(name, BX_COUNTOF(name), "Denoise %d/%d", ii, denoisePasses-1);
|
||||
bgfx::setViewName(view, name);
|
||||
|
||||
bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
|
||||
bgfx::setViewTransform(view, NULL, orthoProj);
|
||||
bgfx::setViewFrameBuffer(view, destBuffer[i]);
|
||||
bgfx::setViewFrameBuffer(view, destBuffer[ii]);
|
||||
|
||||
bgfx::setState(BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_DEPTH_TEST_ALWAYS);
|
||||
bgfx::setTexture(0, s_color, lastTex);
|
||||
bgfx::setTexture(1, s_normal, m_gbufferTex[GBUFFER_RT_NORMAL]);
|
||||
bgfx::setTexture(2, s_depth, m_gbufferTex[GBUFFER_RT_DEPTH]);
|
||||
|
||||
// need to update some denoise uniforms per draw
|
||||
float denoiseStepScale = bx::pow(2.0f, float(i));
|
||||
const float denoiseStepScale = bx::pow(2.0f, float(ii) );
|
||||
m_uniforms.m_denoiseStep = denoiseStepScale;
|
||||
|
||||
m_uniforms.submit();
|
||||
|
||||
screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
|
||||
bgfx::ProgramHandle spatialProgram = (0 == m_spatialSampleType)
|
||||
|
||||
const bgfx::ProgramHandle spatialProgram = (0 == m_spatialSampleType)
|
||||
? m_denoiseSpatialProgram3x3
|
||||
: m_denoiseSpatialProgram5x5;
|
||||
: m_denoiseSpatialProgram5x5
|
||||
;
|
||||
bgfx::submit(view, spatialProgram);
|
||||
|
||||
++view;
|
||||
|
||||
if (m_previousDenoise.m_buffer.idx == destBuffer[i].idx)
|
||||
if (m_previousDenoise.m_buffer.idx == destBuffer[ii].idx)
|
||||
{
|
||||
lastTex = m_previousDenoise.m_texture;
|
||||
}
|
||||
else if (m_temporaryColor.m_buffer.idx == destBuffer[i].idx)
|
||||
else if (m_temporaryColor.m_buffer.idx == destBuffer[ii].idx)
|
||||
{
|
||||
lastTex = m_temporaryColor.m_texture;
|
||||
}
|
||||
@ -569,27 +586,30 @@ public:
|
||||
{
|
||||
// need color result for temporal denoise if not supplied by spatial pass
|
||||
// (per SVGF paper, reuse previous frame's first spatial pass output as previous color
|
||||
bgfx::setViewName(view, "copy color for temporal denoise");
|
||||
bgfx::setViewName(view, "Copy Color for Temporal Denoise");
|
||||
bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
|
||||
bgfx::setViewTransform(view, NULL, orthoProj);
|
||||
bgfx::setViewFrameBuffer(view, m_previousDenoise.m_buffer);
|
||||
bgfx::setState(BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_DEPTH_TEST_ALWAYS);
|
||||
bgfx::setTexture(0, s_color, lastTex);
|
||||
|
||||
screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
|
||||
bgfx::submit(view, m_copyProgram);
|
||||
|
||||
++view;
|
||||
}
|
||||
|
||||
// apply lighting
|
||||
{
|
||||
bgfx::setViewName(view, "apply lighting");
|
||||
bgfx::setViewName(view, "Apply Lighting");
|
||||
|
||||
bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
|
||||
bgfx::setViewTransform(view, NULL, orthoProj);
|
||||
|
||||
bgfx::FrameBufferHandle destBuffer = (lastTex.idx == m_currentColor.m_texture.idx)
|
||||
? m_temporaryColor.m_buffer
|
||||
: m_currentColor.m_buffer;
|
||||
: m_currentColor.m_buffer
|
||||
;
|
||||
bgfx::setViewFrameBuffer(view, destBuffer);
|
||||
bgfx::setState(0
|
||||
| BGFX_STATE_WRITE_RGB
|
||||
@ -599,23 +619,27 @@ public:
|
||||
bgfx::setTexture(0, s_color, lastTex);
|
||||
bgfx::setTexture(1, s_albedo, m_gbufferTex[GBUFFER_RT_COLOR]);
|
||||
m_uniforms.submit();
|
||||
|
||||
screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
|
||||
bgfx::submit(view, m_denoiseApplyLighting);
|
||||
++view;
|
||||
|
||||
lastTex = (m_temporaryColor.m_buffer.idx == destBuffer.idx)
|
||||
? m_temporaryColor.m_texture
|
||||
: m_currentColor.m_texture;
|
||||
: m_currentColor.m_texture
|
||||
;
|
||||
}
|
||||
|
||||
if (m_enableTxaa)
|
||||
{
|
||||
// Draw txaa to txaa buffer
|
||||
{
|
||||
bgfx::setViewName(view, "temporal aa");
|
||||
bgfx::setViewName(view, "Temporal AA");
|
||||
|
||||
bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
|
||||
bgfx::setViewTransform(view, NULL, orthoProj);
|
||||
bgfx::setViewFrameBuffer(view, m_txaaColor.m_buffer);
|
||||
|
||||
bgfx::setState(0
|
||||
| BGFX_STATE_WRITE_RGB
|
||||
| BGFX_STATE_WRITE_A
|
||||
@ -626,14 +650,16 @@ public:
|
||||
bgfx::setTexture(2, s_velocity, m_gbufferTex[GBUFFER_RT_VELOCITY]);
|
||||
bgfx::setTexture(3, s_depth, m_gbufferTex[GBUFFER_RT_DEPTH]);
|
||||
m_uniforms.submit();
|
||||
|
||||
screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
|
||||
bgfx::submit(view, m_txaaProgram);
|
||||
|
||||
++view;
|
||||
}
|
||||
|
||||
// Copy txaa result to previous
|
||||
{
|
||||
bgfx::setViewName(view, "copy2previous");
|
||||
bgfx::setViewName(view, "Copy to Previous");
|
||||
|
||||
bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
|
||||
bgfx::setViewTransform(view, NULL, orthoProj);
|
||||
@ -644,14 +670,16 @@ public:
|
||||
| BGFX_STATE_DEPTH_TEST_ALWAYS
|
||||
);
|
||||
bgfx::setTexture(0, s_color, m_txaaColor.m_texture);
|
||||
|
||||
screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
|
||||
bgfx::submit(view, m_copyProgram);
|
||||
|
||||
++view;
|
||||
}
|
||||
|
||||
// Copy txaa result to swap chain
|
||||
{
|
||||
bgfx::setViewName(view, "display");
|
||||
bgfx::setViewName(view, "Display");
|
||||
|
||||
bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
|
||||
bgfx::setViewTransform(view, NULL, orthoProj);
|
||||
@ -662,8 +690,10 @@ public:
|
||||
| BGFX_STATE_DEPTH_TEST_ALWAYS
|
||||
);
|
||||
bgfx::setTexture(0, s_color, m_txaaColor.m_texture);
|
||||
|
||||
screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
|
||||
bgfx::submit(view, m_copyProgram);
|
||||
|
||||
++view;
|
||||
}
|
||||
}
|
||||
@ -671,7 +701,7 @@ public:
|
||||
{
|
||||
// Copy color result to swap chain
|
||||
{
|
||||
bgfx::setViewName(view, "display");
|
||||
bgfx::setViewName(view, "Display");
|
||||
bgfx::setViewClear(view
|
||||
, BGFX_CLEAR_NONE
|
||||
, 0
|
||||
@ -687,22 +717,26 @@ public:
|
||||
| BGFX_STATE_WRITE_A
|
||||
);
|
||||
bgfx::setTexture(0, s_color, lastTex);
|
||||
|
||||
screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
|
||||
bgfx::submit(view, m_copyProgram);
|
||||
|
||||
++view;
|
||||
}
|
||||
}
|
||||
|
||||
// copy the normal buffer for next time
|
||||
{
|
||||
bgfx::setViewName(view, "copy normals");
|
||||
bgfx::setViewName(view, "Copy Normals");
|
||||
bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
|
||||
bgfx::setViewTransform(view, NULL, orthoProj);
|
||||
bgfx::setViewFrameBuffer(view, m_previousNormal.m_buffer);
|
||||
bgfx::setState(BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_DEPTH_TEST_ALWAYS);
|
||||
bgfx::setTexture(0, s_color, m_gbufferTex[GBUFFER_RT_NORMAL]);
|
||||
|
||||
screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
|
||||
bgfx::submit(view, m_copyProgram);
|
||||
|
||||
++view;
|
||||
|
||||
// update previous status
|
||||
@ -767,7 +801,10 @@ public:
|
||||
|
||||
ImGui::Checkbox("dynamic noise", &m_dynamicNoise);
|
||||
if (ImGui::IsItemHovered() )
|
||||
{
|
||||
ImGui::SetTooltip("update noise pattern each frame");
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
}
|
||||
|
||||
@ -781,19 +818,28 @@ public:
|
||||
ImGui::Text("spatial denoise pass controls:");
|
||||
ImGui::SliderInt("spatial passes", &m_denoisePasses, 0, DENOISE_MAX_PASSES);
|
||||
if (ImGui::IsItemHovered() )
|
||||
{
|
||||
ImGui::SetTooltip("set passes to 0 to turn off spatial denoise");
|
||||
}
|
||||
|
||||
ImGui::Combo("spatial sample extent", &m_spatialSampleType, "three\0five\0\0");
|
||||
if (ImGui::IsItemHovered() )
|
||||
{
|
||||
ImGui::SetTooltip("select 3x3 or 5x5 filter kernal");
|
||||
}
|
||||
|
||||
ImGui::SliderFloat("sigma z", &m_sigmaDepth, 0.0f, 0.1f, "%.5f");
|
||||
if (ImGui::IsItemHovered() )
|
||||
{
|
||||
ImGui::SetTooltip("lower sigma z, pickier blending across depth edges");
|
||||
}
|
||||
|
||||
ImGui::SliderFloat("sigma n", &m_sigmaNormal, 1.0f, 256.0f);
|
||||
if (ImGui::IsItemHovered() )
|
||||
{
|
||||
ImGui::SetTooltip("higher sigma n, pickier blending across normal edges");
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
}
|
||||
|
||||
@ -802,15 +848,21 @@ public:
|
||||
ImGui::Checkbox("use TXAA", &m_enableTxaa);
|
||||
ImGui::Checkbox("apply extra blur to current color", &m_applyMitchellFilter);
|
||||
if (ImGui::IsItemHovered() )
|
||||
{
|
||||
ImGui::SetTooltip("reduces flicker/crawl on thin features, maybe too much!");
|
||||
}
|
||||
|
||||
ImGui::SliderFloat("feedback min", &m_feedbackMin, 0.0f, 1.0f);
|
||||
if (ImGui::IsItemHovered() )
|
||||
{
|
||||
ImGui::SetTooltip("minimum amount of previous frame to blend in");
|
||||
}
|
||||
|
||||
ImGui::SliderFloat("feedback max", &m_feedbackMax, 0.0f, 1.0f);
|
||||
if (ImGui::IsItemHovered() )
|
||||
{
|
||||
ImGui::SetTooltip("maximum amount of previous frame to blend in");
|
||||
}
|
||||
|
||||
ImGui::Checkbox("debug TXAA with slow frame rate", &m_useTxaaSlow);
|
||||
if (ImGui::IsItemHovered() )
|
||||
@ -820,6 +872,7 @@ public:
|
||||
ImGui::Text("high framerate compensates for flickering, masking issues");
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
}
|
||||
|
||||
@ -941,7 +994,8 @@ public:
|
||||
{
|
||||
{
|
||||
uint32_t idx = m_currFrame % 8;
|
||||
const float offsets[] = {
|
||||
const float offsets[] =
|
||||
{
|
||||
(1.0f/ 2.0f), (1.0f/3.0f),
|
||||
(1.0f/ 4.0f), (2.0f/3.0f),
|
||||
(3.0f/ 4.0f), (1.0f/9.0f),
|
||||
@ -949,7 +1003,7 @@ public:
|
||||
(5.0f/ 8.0f), (7.0f/9.0f),
|
||||
(3.0f/ 8.0f), (2.0f/9.0f),
|
||||
(7.0f/ 8.0f), (5.0f/9.0f),
|
||||
(1.0f/16.0f), (8.0f/9.0f)
|
||||
(1.0f/16.0f), (8.0f/9.0f),
|
||||
};
|
||||
|
||||
// Strange constant for jitterX is because 8 values from halton2
|
||||
@ -975,7 +1029,8 @@ public:
|
||||
|
||||
m_uniforms.m_frameOffsetForNoise = m_dynamicNoise
|
||||
? float(m_currFrame % 8)
|
||||
: 0.0f;
|
||||
: 0.0f
|
||||
;
|
||||
m_uniforms.m_noiseType = float(m_noiseType);
|
||||
m_uniforms.m_sigmaDepth = m_sigmaDepth;
|
||||
m_uniforms.m_sigmaNormal = m_sigmaNormal;
|
||||
@ -1049,15 +1104,15 @@ public:
|
||||
|
||||
// UI parameters
|
||||
int32_t m_noiseType = 2;
|
||||
bool m_dynamicNoise = true;
|
||||
bool m_useTemporalPass = true;
|
||||
int32_t m_spatialSampleType = 1;
|
||||
int32_t m_denoisePasses = 5;
|
||||
float m_sigmaDepth = 0.05f;
|
||||
float m_sigmaNormal = 128.0f;
|
||||
bool m_enableTxaa = false;
|
||||
float m_feedbackMin = 0.8f;
|
||||
float m_feedbackMax = 0.95f;
|
||||
bool m_dynamicNoise = true;
|
||||
bool m_useTemporalPass = true;
|
||||
bool m_enableTxaa = false;
|
||||
bool m_applyMitchellFilter = true;
|
||||
bool m_useTxaaSlow = false;
|
||||
};
|
||||
|
BIN
examples/43-denoise/screenshot.png
Normal file
BIN
examples/43-denoise/screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 303 KiB |
Loading…
Reference in New Issue
Block a user