diff --git a/Include/NRD.h b/Include/NRD.h index 33ad59be..3c2573d8 100644 --- a/Include/NRD.h +++ b/Include/NRD.h @@ -29,8 +29,8 @@ license agreement from NVIDIA CORPORATION is strictly prohibited. #define NRD_VERSION_MAJOR 3 #define NRD_VERSION_MINOR 4 -#define NRD_VERSION_BUILD 1 -#define NRD_VERSION_DATE "17 August 2022" +#define NRD_VERSION_BUILD 2 +#define NRD_VERSION_DATE "18 August 2022" #if defined(_MSC_VER) #define NRD_CALL __fastcall diff --git a/README.md b/README.md index 6590fe4f..55544fcd 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# NVIDIA Real-time Denoisers v3.4.1 (NRD) +# NVIDIA Real-time Denoisers v3.4.2 (NRD) ## SAMPLE APP diff --git a/Resources/Version.h b/Resources/Version.h index 39ebae71..847364b2 100644 --- a/Resources/Version.h +++ b/Resources/Version.h @@ -23,7 +23,7 @@ Versioning rules: #define VERSION_MAJOR 3 #define VERSION_MINOR 4 -#define VERSION_BUILD 1 +#define VERSION_BUILD 2 #define VERSION_REVISION 0 #define VERSION_STRING STR(VERSION_MAJOR.VERSION_MINOR.VERSION_BUILD.VERSION_REVISION) diff --git a/Shaders/Include/Common.hlsli b/Shaders/Include/Common.hlsli index b1f5bd84..999d6ca9 100644 --- a/Shaders/Include/Common.hlsli +++ b/Shaders/Include/Common.hlsli @@ -346,9 +346,10 @@ float2 GetKernelSampleCoordinates( float4x4 mToClip, float3 offset, float3 X, fl // Weight parameters -float2 GetGeometryWeightParams( float planeDistSensitivity, float frustumHeight, float3 Xv, float3 Nv, float scale = 1.0 ) +float2 GetGeometryWeightParams( float planeDistSensitivity, float frustumHeight, float3 Xv, float3 Nv, float nonLinearAccumSpeed ) { - float a = scale / ( planeDistSensitivity * frustumHeight + 1e-6 ); + float relaxation = lerp( 1.0, 0.25, nonLinearAccumSpeed ); + float a = relaxation / ( planeDistSensitivity * frustumHeight + 1e-6 ); float b = -dot( Nv, Xv ) * a; return float2( a, b ); diff --git a/Shaders/Include/REBLUR/REBLUR_Common.hlsli b/Shaders/Include/REBLUR/REBLUR_Common.hlsli index 7cd58980..6f816744 100644 --- a/Shaders/Include/REBLUR/REBLUR_Common.hlsli +++ b/Shaders/Include/REBLUR/REBLUR_Common.hlsli @@ -103,10 +103,10 @@ float4 UnpackInternalData1( float4 p ) float4 PackInternalData2( float fbits, float curvature, float virtualHistoryAmount, float hitDistScaleForTracking, float viewZ ) { // BITS: - // 0 - free + // 0 - free // TODO: can be used to store "skip HistoryFix" bit // 1 - CatRom flag // 2,3,4,5 - occlusion 2x2 - // 6 - free + // 6 - free // TODO: free! // 7 - curvature sign float pixelSize = PixelRadiusToWorld( gUnproject, gOrthoMode, 1.0, viewZ ); @@ -436,8 +436,11 @@ float GetBlurRadius( float r = lerp( gMinConvergedStateBaseRadiusScale, 1.0, nonLinearAccumSpeed ); // Avoid over-blurring on contact ( tests 76, 95, 120 ) - hitDistFactor = lerp( hitDistFactor, 1.0, nonLinearAccumSpeed ); - r *= hitDistFactor; // TODO: reduce influence if reprojection confidence is low? + // TODO: reduce "hitDistFactor" influence if reprojection confidence is low? + // TODO: if luminance stoppers are used, blur radius should depend less on "hitDistFactor" + float relaxedHitDistFactor = lerp( 1.0, hitDistFactor, roughness ); + hitDistFactor = lerp( hitDistFactor, relaxedHitDistFactor, nonLinearAccumSpeed ); + r *= hitDistFactor; // IMPORTANT: do not apply "hitDistFactor" to radiusBias because it is responsible for error compensation @@ -451,7 +454,7 @@ float GetBlurRadius( // Disable spatial filtering if radius is 0 r *= float( radius != 0 ); - return r; // TODO: if luminance stoppers are used, blur radius should depend less on hitDistFactor + return r; } float GetBlurRadiusScaleBasingOnTrimming( float roughness, float3 trimmingParams ) diff --git a/Shaders/Include/REBLUR/REBLUR_Common_DiffuseSpatialFilter.hlsli b/Shaders/Include/REBLUR/REBLUR_Common_DiffuseSpatialFilter.hlsli index f04c4b94..932c0b2d 100644 --- a/Shaders/Include/REBLUR/REBLUR_Common_DiffuseSpatialFilter.hlsli +++ b/Shaders/Include/REBLUR/REBLUR_Common_DiffuseSpatialFilter.hlsli @@ -31,9 +31,11 @@ license agreement from NVIDIA CORPORATION is strictly prohibited. #else float2 diffInternalData = float2( 1.0 / ( 1.0 + internalData1.x ), internalData1.x ); float2 sum = 1.0; + float boost = saturate( 1.0 - diffInternalData.y / REBLUR_FIXED_FRAME_NUM ); - float radius = gBlurRadius; - radius *= ( 1.0 + 2.0 * boost ) / 3.0; + boost *= NoV; + + float radius = gBlurRadius * ( 1.0 + 2.0 * boost ) / 3.0; #endif #if( REBLUR_SPATIAL_MODE == REBLUR_PRE_BLUR ) @@ -51,8 +53,6 @@ license agreement from NVIDIA CORPORATION is strictly prohibited. #endif // Blur radius - float3 Vv = GetViewVector( Xv, true ); - float frustumHeight = PixelRadiusToWorld( gUnproject, gOrthoMode, gRectSize.y, viewZ ); float hitDistScale = _REBLUR_GetHitDistanceNormalization( viewZ, gHitDistParams, 1.0 ); float hitDist = diff.w * hitDistScale; @@ -70,7 +70,7 @@ license agreement from NVIDIA CORPORATION is strictly prohibited. // Denoising float2x3 TvBv = GetKernelBasis( Nv, Nv, 1.0, worldBlurRadius ); // D = N - float2 geometryWeightParams = GetGeometryWeightParams( gPlaneDistSensitivity, frustumHeight, Xv, Nv, lerp( 1.0, REBLUR_PLANE_DIST_MIN_SENSITIVITY_SCALE, diffInternalData.x ) ); + float2 geometryWeightParams = GetGeometryWeightParams( gPlaneDistSensitivity, frustumHeight, Xv, Nv, diffInternalData.x ); float normalWeightParams = GetNormalWeightParams( diffInternalData.x, lobeAngleFractionScale ); float2 hitDistanceWeightParams = GetHitDistanceWeightParams( diff.w, diffInternalData.x ); diff --git a/Shaders/Include/REBLUR/REBLUR_Common_SpecularSpatialFilter.hlsli b/Shaders/Include/REBLUR/REBLUR_Common_SpecularSpatialFilter.hlsli index c30f1183..bf35809f 100644 --- a/Shaders/Include/REBLUR/REBLUR_Common_SpecularSpatialFilter.hlsli +++ b/Shaders/Include/REBLUR/REBLUR_Common_SpecularSpatialFilter.hlsli @@ -32,9 +32,12 @@ license agreement from NVIDIA CORPORATION is strictly prohibited. #else float2 specInternalData = float2( 1.0 / ( 1.0 + internalData1.z ), internalData1.z ); float2 sum = 1.0; + float boost = saturate( 1.0 - specInternalData.y / REBLUR_FIXED_FRAME_NUM ); - float radius = gBlurRadius; - radius *= ( 1.0 + 2.0 * boost * GetSpecMagicCurve2( roughness ) ) / 3.0; + boost *= NoV; + boost *= GetSpecMagicCurve2( roughness ); + + float radius = gBlurRadius * ( 1.0 + 2.0 * boost ) / 3.0; #endif radius *= GetBlurRadiusScaleBasingOnTrimming( roughness, gSpecLobeTrimmingParams.xyz ); @@ -57,7 +60,6 @@ license agreement from NVIDIA CORPORATION is strictly prohibited. #endif // Blur radius - float3 Vv = GetViewVector( Xv, true ); float4 Dv = STL::ImportanceSampling::GetSpecularDominantDirection( Nv, Vv, roughness, STL_SPECULAR_DOMINANT_DIRECTION_G2 ); float NoD = abs( dot( Nv, Dv.xyz ) ); @@ -84,7 +86,7 @@ license agreement from NVIDIA CORPORATION is strictly prohibited. // Denoising float2x3 TvBv = GetKernelBasis( Dv.xyz, Nv, NoD, worldBlurRadius, roughness, specInternalData.x ); - float2 geometryWeightParams = GetGeometryWeightParams( gPlaneDistSensitivity, frustumHeight, Xv, Nv, lerp( 1.0, REBLUR_PLANE_DIST_MIN_SENSITIVITY_SCALE, specInternalData.x ) ); + float2 geometryWeightParams = GetGeometryWeightParams( gPlaneDistSensitivity, frustumHeight, Xv, Nv, specInternalData.x ); float normalWeightParams = GetNormalWeightParams( specInternalData.x, lobeAngleFractionScale, roughness ); float2 hitDistanceWeightParams = GetHitDistanceWeightParams( spec.w, specInternalData.x, roughness ); float2 roughnessWeightParams = GetRoughnessWeightParams( roughness, roughnessFractionScale ); @@ -98,7 +100,6 @@ license agreement from NVIDIA CORPORATION is strictly prohibited. float3 L = dirPdf.xyz; float3 V = STL::Geometry::RotateVector( gViewToWorld, Vv ); float3 H = normalize( L + V ); - float NoV = abs( dot( N, V ) ); float NoL = saturate( dot( N, L ) ); float NoH = saturate( dot( N, H ) ); float VoH = saturate( dot( V, H ) ); diff --git a/Shaders/Include/REBLUR/REBLUR_Config.hlsli b/Shaders/Include/REBLUR/REBLUR_Config.hlsli index db7e5201..1010687c 100644 --- a/Shaders/Include/REBLUR/REBLUR_Config.hlsli +++ b/Shaders/Include/REBLUR/REBLUR_Config.hlsli @@ -18,9 +18,9 @@ license agreement from NVIDIA CORPORATION is strictly prohibited. #define REBLUR_USE_HISTORY_FIX 1 #define REBLUR_USE_YCOCG 1 #define REBLUR_USE_FAST_HISTORY 1 -#define REBLUR_USE_5X5_ANTI_FIREFLY 1 // can be 0 for clean signals // Switches ( default 0 ) +#define REBLUR_USE_5X5_ANTI_FIREFLY 0 // can be 1 for dirty signals, but will be less useful #define REBLUR_USE_SCREEN_SPACE_SAMPLING 0 #define REBLUR_USE_ANTILAG_NOT_INVOKING_HISTORY_FIX 0 #define REBLUR_USE_ACCUM_SPEED_NONLINEAR_INTERPOLATION 0 @@ -70,10 +70,9 @@ license agreement from NVIDIA CORPORATION is strictly prohibited. #define REBLUR_POST_BLUR_FRACTION_SCALE 0.5 #define REBLUR_VIRTUAL_MOTION_NORMAL_WEIGHT_ITERATION_NUM 2 -#define REBLUR_COLOR_CLAMPING_SIGMA_SCALE 2.0 +#define REBLUR_COLOR_CLAMPING_SIGMA_SCALE 1.5 // TODO: was 2.0, but we can use even 1.0 because the fast history is noisy, while the main history is denoised #define REBLUR_SPEC_ACCUM_BASE_POWER ( 0.4 + 0.2 * exp2( -gFramerateScale ) ) // bigger values = more aggressive rejection #define REBLUR_SPEC_ACCUM_CURVE ( 1.0 - exp2( -gFramerateScale ) ) // smaller values = more aggressive rejection -#define REBLUR_PLANE_DIST_MIN_SENSITIVITY_SCALE 0.05 #define REBLUR_TS_SIGMA_AMPLITUDE ( 3.0 * gFramerateScale ) #define REBLUR_TS_ACCUM_TIME ( gFramerateScale * 30.0 * 0.5 ) // = FPS * seconds #define REBLUR_PARALLAX_SCALE ( 2.0 * gFramerateScale ) // TODO: is it possible to use 1 with tweaks in other parameters? diff --git a/Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_Blur.hlsli b/Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_Blur.hlsli index 0963292d..0798efd4 100644 --- a/Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_Blur.hlsli +++ b/Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_Blur.hlsli @@ -54,6 +54,9 @@ NRD_EXPORT void NRD_CS_MAIN( int2 threadPos : SV_GroupThreadId, int2 pixelPos : float3 Xv = STL::Geometry::ReconstructViewPosition( pixelUv, gFrustum, viewZ, gOrthoMode ); float4 rotator = GetBlurKernelRotation( REBLUR_BLUR_ROTATOR_MODE, pixelPos, gRotator, gFrameIndex ); + float3 Vv = GetViewVector( Xv, true ); + float NoV = abs( dot( Nv, Vv ) ); + // Spatial filtering #define REBLUR_SPATIAL_MODE REBLUR_BLUR diff --git a/Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_HistoryFix.hlsli b/Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_HistoryFix.hlsli index cd537ef9..e11cd2e8 100644 --- a/Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_HistoryFix.hlsli +++ b/Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_HistoryFix.hlsli @@ -95,14 +95,16 @@ NRD_EXPORT void NRD_CS_MAIN( int2 threadPos : SV_GroupThreadId, int2 pixelPos : #ifndef REBLUR_PERFORMANCE_MODE #ifdef REBLUR_DIFFUSE - float diffM1 = s_DiffLuma[ smemPos.y ][ smemPos.x ]; + float diffCenter = s_DiffLuma[ smemPos.y ][ smemPos.x ]; + float diffM1 = diffCenter; float diffM2 = diffM1 * diffM1; float diffMax = -NRD_INF; float diffMin = NRD_INF; #endif #ifdef REBLUR_SPECULAR - float specM1 = s_SpecLuma[ smemPos.y ][ smemPos.x ]; + float specCenter = s_SpecLuma[ smemPos.y ][ smemPos.x ]; + float specM1 = specCenter; float specM2 = specM1 * specM1; float specMax = -NRD_INF; float specMin = NRD_INF; @@ -153,19 +155,23 @@ NRD_EXPORT void NRD_CS_MAIN( int2 threadPos : SV_GroupThreadId, int2 pixelPos : #ifdef REBLUR_DIFFUSE float diffLuma = GetLuma( diff ); + // Anti-firefly + float diffLumaClamped1 = clamp( diffLuma, diffMin, diffMax ); + diffLuma = gAntiFirefly ? diffLumaClamped1 : diffLuma; + // Fast history #if( REBLUR_USE_FAST_HISTORY == 1 && !defined( REBLUR_OCCLUSION ) ) diffM1 *= invSum; diffM2 *= invSum; float diffSigma = GetStdDev( diffM1, diffM2 ) * REBLUR_COLOR_CLAMPING_SIGMA_SCALE; - float diffLumaClamped1 = STL::Color::Clamp( diffM1, diffSigma, diffLuma ); - diffLuma = lerp( diffLumaClamped1, diffLuma, 1.0 / ( 1.0 + useFastHistory * frameNumUnclamped.x ) ); - #endif + // Seems that extending clamping range by the center helps to minimize potential bias + diffMin = min( diffM1 - diffSigma, diffCenter ); + diffMax = max( diffM1 + diffSigma, diffCenter ); - // Anti-firefly - float diffLumaClamped2 = clamp( diffLuma, diffMin, diffMax ); - diffLuma = lerp( diffLumaClamped2, diffLuma, 1.0 / ( 1.0 + gAntiFirefly * frameNumUnclamped.x ) ); + float diffLumaClamped2 = clamp( diffLuma, diffMin, diffMax ); + diffLuma = lerp( diffLumaClamped2, diffLuma, 1.0 / ( 1.0 + useFastHistory * frameNumUnclamped.x ) ); + #endif // Change luma diff = ChangeLuma( diff, diffLuma ); @@ -178,19 +184,23 @@ NRD_EXPORT void NRD_CS_MAIN( int2 threadPos : SV_GroupThreadId, int2 pixelPos : #ifdef REBLUR_SPECULAR float specLuma = GetLuma( spec ); + // Anti-firefly + float specLumaClamped1 = clamp( specLuma, specMin, specMax ); + specLuma = gAntiFirefly ? specLumaClamped1 : specLuma; + // Fast history #if( REBLUR_USE_FAST_HISTORY == 1 && !defined( REBLUR_OCCLUSION ) ) specM1 *= invSum; specM2 *= invSum; float specSigma = GetStdDev( specM1, specM2 ) * REBLUR_COLOR_CLAMPING_SIGMA_SCALE; - float specLumaClamped1 = STL::Color::Clamp( specM1, specSigma, specLuma ); - specLuma = lerp( specLumaClamped1, specLuma, 1.0 / ( 1.0 + useFastHistory * frameNumUnclamped.y ) ); - #endif + // Seems that extending clamping range by the center helps to minimize potential bias + specMin = min( specM1 - specSigma, specCenter ); + specMax = max( specM1 + specSigma, specCenter ); - // Anti-firefly - float specLumaClamped2 = clamp( specLuma, specMin, specMax ); - specLuma = lerp( specLumaClamped2, specLuma, 1.0 / ( 1.0 + gAntiFirefly * frameNumUnclamped.y ) ); + float specLumaClamped2 = clamp( specLuma, specMin, specMax ); + specLuma = lerp( specLumaClamped2, specLuma, 1.0 / ( 1.0 + useFastHistory * frameNumUnclamped.y ) ); + #endif // Change luma spec = ChangeLuma( spec, specLuma ); @@ -271,7 +281,7 @@ NRD_EXPORT void NRD_CS_MAIN( int2 threadPos : SV_GroupThreadId, int2 pixelPos : #ifdef REBLUR_DIFFUSE float diffNonLinearAccumSpeed = 1.0 / ( 1.0 + frameNumUnclamped.x ); - float2 diffGeometryWeightParams = GetGeometryWeightParams( gPlaneDistSensitivity, frustumHeight, Xv, Nv, lerp( 1.0, REBLUR_PLANE_DIST_MIN_SENSITIVITY_SCALE, diffNonLinearAccumSpeed ) ); + float2 diffGeometryWeightParams = GetGeometryWeightParams( gPlaneDistSensitivity, frustumHeight, Xv, Nv, diffNonLinearAccumSpeed ); float diffNormalWeightParam = GetNormalWeightParams( diffNonLinearAccumSpeed, 1.0 ); #endif @@ -295,7 +305,7 @@ NRD_EXPORT void NRD_CS_MAIN( int2 threadPos : SV_GroupThreadId, int2 pixelPos : #endif float specNormalWeightParam = rcp( angle * specNonLinearAccumSpeed + NRD_NORMAL_ENCODING_ERROR ); - float2 specGeometryWeightParams = GetGeometryWeightParams( gPlaneDistSensitivity, frustumHeight, Xv, Nv, lerp( 1.0, REBLUR_PLANE_DIST_MIN_SENSITIVITY_SCALE, specNonLinearAccumSpeed ) ); + float2 specGeometryWeightParams = GetGeometryWeightParams( gPlaneDistSensitivity, frustumHeight, Xv, Nv, specNonLinearAccumSpeed ); float2 specRoughnessWeightParams = GetRoughnessWeightParams( roughness, 1.0 ); float2 specHitDistanceWeightParams = GetHitDistanceWeightParams( ExtractHitDist( spec ), specNonLinearAccumSpeed, roughness ); diff --git a/Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_PostBlur.hlsli b/Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_PostBlur.hlsli index 555e8679..13469581 100644 --- a/Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_PostBlur.hlsli +++ b/Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_PostBlur.hlsli @@ -59,6 +59,9 @@ NRD_EXPORT void NRD_CS_MAIN( int2 threadPos : SV_GroupThreadId, int2 pixelPos : float3 Xv = STL::Geometry::ReconstructViewPosition( pixelUv, gFrustum, viewZ, gOrthoMode ); float4 rotator = GetBlurKernelRotation( REBLUR_POST_BLUR_ROTATOR_MODE, pixelPos, gRotator, gFrameIndex ); + float3 Vv = GetViewVector( Xv, true ); + float NoV = abs( dot( Nv, Vv ) ); + // Spatial filtering #define REBLUR_SPATIAL_MODE REBLUR_POST_BLUR diff --git a/Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_PrePass.hlsli b/Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_PrePass.hlsli index 8f086603..55e73614 100644 --- a/Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_PrePass.hlsli +++ b/Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_PrePass.hlsli @@ -46,6 +46,9 @@ NRD_EXPORT void NRD_CS_MAIN( int2 threadPos : SV_GroupThreadId, int2 pixelPos : float3 Xv = STL::Geometry::ReconstructViewPosition( pixelUv, gFrustum, viewZ, gOrthoMode ); float4 rotator = GetBlurKernelRotation( REBLUR_PRE_BLUR_ROTATOR_MODE, pixelPos, gRotator, gFrameIndex ); + float3 Vv = GetViewVector( Xv, true ); + float NoV = abs( dot( Nv, Vv ) ); + #define REBLUR_SPATIAL_MODE REBLUR_PRE_BLUR #ifdef REBLUR_DIFFUSE diff --git a/Shaders/Include/SIGMA/SIGMA_Config.hlsli b/Shaders/Include/SIGMA/SIGMA_Config.hlsli index 40313022..b441bf26 100644 --- a/Shaders/Include/SIGMA/SIGMA_Config.hlsli +++ b/Shaders/Include/SIGMA/SIGMA_Config.hlsli @@ -11,7 +11,6 @@ license agreement from NVIDIA CORPORATION is strictly prohibited. #define SIGMA_POISSON_SAMPLE_NUM 8 #define SIGMA_POISSON_SAMPLES g_Poisson8 #define SIGMA_MAX_PIXEL_RADIUS 32.0 -#define SIGMA_PLANE_DISTANCE_SCALE 0.25 #define SIGMA_MIN_HIT_DISTANCE_OUTPUT 0.0001 #define SIGMA_PENUMBRA_FIX_BLUR_RADIUS_ADDON 5.0 #define SIGMA_MAX_SIGMA_SCALE 3.5 diff --git a/Shaders/Include/SIGMA/SIGMA_Shadow_Blur.hlsli b/Shaders/Include/SIGMA/SIGMA_Shadow_Blur.hlsli index 65d99dde..489aad24 100644 --- a/Shaders/Include/SIGMA/SIGMA_Shadow_Blur.hlsli +++ b/Shaders/Include/SIGMA/SIGMA_Shadow_Blur.hlsli @@ -152,7 +152,7 @@ NRD_EXPORT void NRD_CS_MAIN( int2 threadPos : SV_GroupThreadId, int2 pixelPos : sum = 1.0; float frustumHeight = PixelRadiusToWorld( gUnproject, gOrthoMode, gRectSize.y, viewZ ); - float2 geometryWeightParams = GetGeometryWeightParams( gPlaneDistSensitivity, frustumHeight, Xv, Nv, SIGMA_PLANE_DISTANCE_SCALE ); + float2 geometryWeightParams = GetGeometryWeightParams( gPlaneDistSensitivity, frustumHeight, Xv, Nv, 1.0 ); [unroll] for( uint i = 0; i < SIGMA_POISSON_SAMPLE_NUM; i++ ) diff --git a/Source/Methods/Reblur_DiffuseDirectionalOcclusion.hpp b/Source/Methods/Reblur_DiffuseDirectionalOcclusion.hpp index 480b1abd..0424ecb5 100644 --- a/Source/Methods/Reblur_DiffuseDirectionalOcclusion.hpp +++ b/Source/Methods/Reblur_DiffuseDirectionalOcclusion.hpp @@ -11,8 +11,8 @@ license agreement from NVIDIA CORPORATION is strictly prohibited. size_t nrd::DenoiserImpl::AddMethod_ReblurDiffuseDirectionalOcclusion(uint16_t w, uint16_t h) { #define METHOD_NAME REBLUR_DirectionalOcclusion - #define DIFF_TEMP1 AsUint(Permanent::DIFF_HISTORY_STABILIZED_PONG), 0, 1, AsUint(Permanent::DIFF_HISTORY_STABILIZED_PING) - #define DIFF_TEMP2 AsUint(ResourceType::OUT_DIFF_DIRECTION_HITDIST) + #define DIFF_TEMP1 AsUint(Transient::DIFF_TMP1) + #define DIFF_TEMP2 AsUint(Transient::DIFF_TMP2) enum class Permanent { @@ -20,8 +20,6 @@ size_t nrd::DenoiserImpl::AddMethod_ReblurDiffuseDirectionalOcclusion(uint16_t w PREV_NORMAL_ROUGHNESS, PREV_ACCUMSPEEDS_MATERIALID, DIFF_HISTORY, - DIFF_HISTORY_STABILIZED_PING, - DIFF_HISTORY_STABILIZED_PONG, DIFF_FAST_HISTORY_PING, DIFF_FAST_HISTORY_PONG, }; @@ -30,8 +28,6 @@ size_t nrd::DenoiserImpl::AddMethod_ReblurDiffuseDirectionalOcclusion(uint16_t w m_PermanentPool.push_back( {Format::RGBA8_UNORM, w, h, 1} ); m_PermanentPool.push_back( {Format::R16_UINT, w, h, 1} ); m_PermanentPool.push_back( {Format::RGBA16_SFLOAT, w, h, 1} ); - m_PermanentPool.push_back( {Format::RGBA16_SFLOAT, w, h, 1} ); - m_PermanentPool.push_back( {Format::RGBA16_SFLOAT, w, h, 1} ); m_PermanentPool.push_back( {Format::R16_SFLOAT, w, h, 1} ); m_PermanentPool.push_back( {Format::R16_SFLOAT, w, h, 1} ); @@ -39,12 +35,14 @@ size_t nrd::DenoiserImpl::AddMethod_ReblurDiffuseDirectionalOcclusion(uint16_t w { DATA1 = TRANSIENT_POOL_START, DATA2, - DIFF_ACCUMULATED, + DIFF_TMP1, + DIFF_TMP2 }; m_TransientPool.push_back( {Format::RG8_UNORM, w, h, 1} ); m_TransientPool.push_back( {Format::RG8_UNORM, w, h, 1} ); m_TransientPool.push_back( {Format::RGBA16_SFLOAT, w, h, 1} ); + m_TransientPool.push_back( {Format::RGBA16_SFLOAT, w, h, 1} ); REBLUR_SET_SHARED_CONSTANTS; @@ -136,8 +134,16 @@ size_t nrd::DenoiserImpl::AddMethod_ReblurDiffuseDirectionalOcclusion(uint16_t w PushOutput( AsUint(Transient::DATA2) ); // Shaders - AddDispatch( REBLUR_Diffuse_TemporalAccumulation, REBLUR_TEMPORAL_ACCUMULATION_CONSTANT_NUM, REBLUR_TEMPORAL_ACCUMULATION_GROUP_DIM, 1 ); - AddDispatch( REBLUR_Perf_Diffuse_TemporalAccumulation, REBLUR_TEMPORAL_ACCUMULATION_CONSTANT_NUM, REBLUR_TEMPORAL_ACCUMULATION_GROUP_DIM, 1 ); + if (hasConfidenceInputs) + { + AddDispatch( REBLUR_Diffuse_TemporalAccumulation_Confidence, REBLUR_TEMPORAL_ACCUMULATION_CONSTANT_NUM, REBLUR_TEMPORAL_ACCUMULATION_GROUP_DIM, 1 ); + AddDispatch( REBLUR_Perf_Diffuse_TemporalAccumulation_Confidence, REBLUR_TEMPORAL_ACCUMULATION_CONSTANT_NUM, REBLUR_TEMPORAL_ACCUMULATION_GROUP_DIM, 1 ); + } + else + { + AddDispatch( REBLUR_Diffuse_TemporalAccumulation, REBLUR_TEMPORAL_ACCUMULATION_CONSTANT_NUM, REBLUR_TEMPORAL_ACCUMULATION_GROUP_DIM, 1 ); + AddDispatch( REBLUR_Perf_Diffuse_TemporalAccumulation, REBLUR_TEMPORAL_ACCUMULATION_CONSTANT_NUM, REBLUR_TEMPORAL_ACCUMULATION_GROUP_DIM, 1 ); + } } } @@ -153,7 +159,7 @@ size_t nrd::DenoiserImpl::AddMethod_ReblurDiffuseDirectionalOcclusion(uint16_t w PushInput( AsUint(Permanent::DIFF_FAST_HISTORY_PONG), 0, 1, AsUint(Permanent::DIFF_FAST_HISTORY_PING) ); // Outputs - PushOutput( AsUint(Transient::DIFF_ACCUMULATED) ); + PushOutput( DIFF_TEMP1 ); // Shaders AddDispatch( REBLUR_Diffuse_HistoryFix, REBLUR_HISTORY_FIX_CONSTANT_NUM, REBLUR_HISTORY_FIX_GROUP_DIM, 1 ); @@ -168,7 +174,7 @@ size_t nrd::DenoiserImpl::AddMethod_ReblurDiffuseDirectionalOcclusion(uint16_t w // Inputs PushInput( AsUint(ResourceType::IN_NORMAL_ROUGHNESS) ); PushInput( AsUint(Transient::DATA1) ); - PushInput( AsUint(Transient::DIFF_ACCUMULATED) ); + PushInput( DIFF_TEMP1 ); PushInput( AsUint(ResourceType::IN_VIEWZ) ); // Outputs @@ -218,6 +224,21 @@ size_t nrd::DenoiserImpl::AddMethod_ReblurDiffuseDirectionalOcclusion(uint16_t w } } + for (int i = 0; i < REBLUR_COPY_STABILIZED_HISTORY_PERMUTATION_NUM; i++) + { + PushPass("Copy stabilized history"); + { + // Inputs + PushInput( AsUint(ResourceType::OUT_DIFF_DIRECTION_HITDIST) ); + + // Outputs + PushOutput( DIFF_TEMP2 ); + + // Shaders + AddDispatch( REBLUR_Diffuse_CopyStabilizedHistory, REBLUR_COPY_STABILIZED_HISTORY_CONSTANT_NUM, REBLUR_COPY_STABILIZED_HISTORY_GROUP_DIM, USE_MAX_DIMS ); + } + } + for (int i = 0; i < REBLUR_TEMPORAL_STABILIZATION_PERMUTATION_NUM; i++) { PushPass("Temporal stabilization"); @@ -229,11 +250,10 @@ size_t nrd::DenoiserImpl::AddMethod_ReblurDiffuseDirectionalOcclusion(uint16_t w PushInput( AsUint(Transient::DATA1) ); PushInput( AsUint(Transient::DATA2) ); PushInput( AsUint(Permanent::DIFF_HISTORY) ); - PushInput( AsUint(Permanent::DIFF_HISTORY_STABILIZED_PING), 0, 1, AsUint(Permanent::DIFF_HISTORY_STABILIZED_PONG) ); + PushInput( DIFF_TEMP2 ); // Outputs PushOutput( AsUint(Permanent::PREV_ACCUMSPEEDS_MATERIALID) ); - PushOutput( AsUint(Permanent::DIFF_HISTORY_STABILIZED_PONG), 0, 1, AsUint(Permanent::DIFF_HISTORY_STABILIZED_PING) ); PushOutput( AsUint(ResourceType::OUT_DIFF_DIRECTION_HITDIST) ); // Shaders