Skip to content

Commit

Permalink
NRD v3.4.2:
Browse files Browse the repository at this point in the history
HIGHLIGHTS:
- bug fixes & improvements

DETAILS:
- REBLUR: fixed broken resource bindings in REBLUR_DIRECTIONAL_OCCLUSION denoiser
- REBLUR: tweaked plane distance sensitivity after history reset to minimize overblur
- REBLUR: tuned blur radius in spatial passes if number of accumulated frames is low (gives IQ and performance)
- REBLUR: switched anti-firefly to 3x3 instead of 5x5
- REBLUR: anti-firefly and fast history clamping improvements
  • Loading branch information
dzhdanNV committed Aug 18, 2022
1 parent 692da5e commit a393821
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 55 deletions.
4 changes: 2 additions & 2 deletions Include/NRD.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# NVIDIA Real-time Denoisers v3.4.1 (NRD)
# NVIDIA Real-time Denoisers v3.4.2 (NRD)

## SAMPLE APP

Expand Down
2 changes: 1 addition & 1 deletion Resources/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 3 additions & 2 deletions Shaders/Include/Common.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
13 changes: 8 additions & 5 deletions Shaders/Include/REBLUR/REBLUR_Common.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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

Expand All @@ -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 )
Expand Down
10 changes: 5 additions & 5 deletions Shaders/Include/REBLUR/REBLUR_Common_DiffuseSpatialFilter.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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;
Expand All @@ -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 );

Expand Down
11 changes: 6 additions & 5 deletions Shaders/Include/REBLUR/REBLUR_Common_SpecularSpatialFilter.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

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

Expand All @@ -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 );
Expand All @@ -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 ) );
Expand Down
5 changes: 2 additions & 3 deletions Shaders/Include/REBLUR/REBLUR_Config.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand Down
3 changes: 3 additions & 0 deletions Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_Blur.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
42 changes: 26 additions & 16 deletions Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_HistoryFix.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -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

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

Expand Down
3 changes: 3 additions & 0 deletions Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_PostBlur.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_PrePass.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion Shaders/Include/SIGMA/SIGMA_Config.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Shaders/Include/SIGMA/SIGMA_Shadow_Blur.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -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++ )
Expand Down
Loading

0 comments on commit a393821

Please sign in to comment.