Skip to content

Commit 76153aa

Browse files
committed
NRD updated to v3.9.0:
- added support for NRD validation layer - added support for 2.5D motion vectors - UI: exposed MV types - 2D, 2.5D, 3D - max number of accumulated frames should not be treated as "history reset" - updated tests - updated dependencies
1 parent e63496f commit 76153aa

15 files changed

+128
-55
lines changed

.args

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
{
5959
"Command": "--debugNRI"
6060
},
61+
{
62+
"Command": "--debugNRD"
63+
},
6164
{
6265
"Command": "--ignoreDPI"
6366
},

3-Run NRD sample.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,6 @@ echo 4 - Zero day
144144
goto CHOOSE_SCENE
145145

146146
:RUN
147-
start "NRD sample" "%DIR_BIN%\NRDSample.exe" --width=%WIDTH% --height=%HEIGHT% --api=%API% --vsyncInterval=%VSYNC% --scene=%SCENE% --dlssQuality=%DLSS%
147+
start "NRD sample" "%DIR_BIN%\NRDSample.exe" --width=%WIDTH% --height=%HEIGHT% --api=%API% --vsyncInterval=%VSYNC% --scene=%SCENE% --dlssQuality=%DLSS% --debugNRD
148148

149149
exit /b

External/NRD

Submodule NRD updated from d08a0e1 to bb0f733

External/NRIFramework

Shaders/AfterDlss.cs.hlsl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
1111
#include "Shared.hlsli"
1212

1313
NRI_RESOURCE( Texture2D<float3>, gIn_Image, t, 0, 1 );
14+
NRI_RESOURCE( Texture2D<float4>, gIn_Validation, t, 1, 1 );
1415

15-
NRI_RESOURCE( RWTexture2D<float3>, gOut_Image, u, 1, 1 );
16+
NRI_RESOURCE( RWTexture2D<float3>, gOut_Image, u, 0, 1 );
1617

1718
[numthreads( 16, 16, 1 )]
1819
void main( uint2 pixelPos : SV_DispatchThreadId )
@@ -30,5 +31,12 @@ void main( uint2 pixelPos : SV_DispatchThreadId )
3031
if( gOnScreen == SHOW_FINAL || gOnScreen == SHOW_BASE_COLOR )
3132
upsampled = STL::Color::LinearToSrgb( upsampled );
3233

34+
// Validation layer
35+
if( gValidation )
36+
{
37+
float4 validation = gIn_Validation.SampleLevel( gLinearSampler, pixelUv, 0 );
38+
upsampled = lerp( upsampled, validation.xyz, validation.w );
39+
}
40+
3341
gOut_Image[ pixelPos ] = upsampled;
3442
}

Shaders/Include/Shared.hlsli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ NRI_RESOURCE( cbuffer, globalConstants, b, 0, 0 )
100100
uint gBounceNum;
101101
uint gTaa;
102102
uint gSH;
103+
uint gValidation;
103104

104105
// NIS
105106
float gNisDetectRatio;

Shaders/PreDlss.cs.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
1010

1111
#include "Shared.hlsli"
1212

13-
NRI_RESOURCE( Texture2D<float3>, gIn_ObjectMotion, t, 0, 1 );
13+
NRI_RESOURCE( Texture2D<float3>, gIn_Mv, t, 0, 1 );
1414
NRI_RESOURCE( Texture2D<float4>, gIn_ComposedLighting_ViewZ, t, 1, 1 );
1515

1616
NRI_RESOURCE( RWTexture2D<float>, gOut_ViewZ, u, 0, 1 );
@@ -30,7 +30,7 @@ void main( uint2 pixelPos : SV_DispatchThreadId )
3030

3131
// Object to surface motion
3232
float3 X = STL::Geometry::AffineTransform( gViewToWorld, Xv );
33-
float3 motionVector = gIn_ObjectMotion[ pixelPos ] * ( gIsWorldSpaceMotionEnabled ? 1.0 : gInvRenderSize.xyy );
33+
float3 motionVector = gIn_Mv[ pixelPos ] * ( gIsWorldSpaceMotionEnabled ? 1.0 : gInvRenderSize.xyy );
3434
float2 pixelUvPrev = STL::Geometry::GetPrevUvFromMotion( pixelUv, X, gWorldToClipPrev, motionVector, gIsWorldSpaceMotionEnabled );
3535
float2 pixelMotion = ( pixelUvPrev - pixelUv ) * gRenderSize;
3636
gOut_SurfaceMotion[ pixelPos ] = pixelMotion;

Shaders/PrimaryRays.cs.hlsl

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,35 +78,40 @@ void main( uint2 pixelPos : SV_DispatchThreadId )
7878
GeometryProps geometryProps0 = CastRay( cameraRayOrigin, cameraRayDirection, 0.0, INF, GetConeAngleFromRoughness( 0.0, 0.0 ), gWorldTlas, ( gOnScreen == SHOW_MESH || gOnScreen == SHOW_NORMAL ) ? GEOMETRY_ALL : GEOMETRY_IGNORE_TRANSPARENT, 0 );
7979
MaterialProps materialProps0 = GetMaterialProps( geometryProps0 );
8080

81+
// ViewZ
82+
float viewZ = STL::Geometry::AffineTransform( gWorldToView, geometryProps0.X ).z;
83+
gOut_ViewZ[ pixelPos ] = geometryProps0.IsSky( ) ? STL::Math::Sign( viewZ ) * INF : viewZ;
8184

82-
// Early out - sky
83-
if( geometryProps0.IsSky( ) )
85+
// Motion
86+
float3 Xprev = geometryProps0.X;
87+
if( !geometryProps0.IsSky( ) )
88+
{
89+
InstanceData instanceData = gIn_InstanceData[ geometryProps0.instanceIndex ];
90+
Xprev = STL::Geometry::AffineTransform( instanceData.mWorldToWorldPrev, geometryProps0.X );
91+
}
92+
93+
float3 motion = Xprev - geometryProps0.X;
94+
if( !gIsWorldSpaceMotionEnabled )
8495
{
85-
float4 clipPrev = STL::Geometry::ProjectiveTransform( gWorldToClipPrev, geometryProps0.X );
96+
float4 clipPrev = STL::Geometry::ProjectiveTransform( gWorldToClipPrev, Xprev );
8697
float2 sampleUvPrev = ( clipPrev.xy / clipPrev.w ) * float2( 0.5, -0.5 ) + 0.5;
87-
float2 surfaceMotion = ( sampleUvPrev - sampleUv ) * gRectSize;
88-
float3 motion = gIsWorldSpaceMotionEnabled ? 0 : surfaceMotion.xyy;
8998

90-
gOut_Motion[ pixelPos ] = motion * STL::Math::LinearStep( 0.0, 0.0000005, abs( motion ) ); // TODO: move LinearStep to NRD?
91-
gOut_ViewZ[ pixelPos ] = INF * STL::Math::Sign( gNearZ );
99+
motion.xy = ( sampleUvPrev - sampleUv ) * gRectSize;
100+
motion.z = STL::Math::Sign( viewZ ) * clipPrev.w - viewZ;
101+
}
102+
103+
gOut_Motion[ pixelPos ] = motion * STL::Math::LinearStep( 0.0, 0.0000005, abs( motion ) ); // TODO: move LinearStep to NRD?
104+
105+
// Early out - sky
106+
if( geometryProps0.IsSky( ) )
107+
{
92108
gOut_DirectEmission[ pixelPos ] = materialProps0.Lemi;
93109
gOut_DirectLighting[ pixelPos ] = 0;
94110

95111
return;
96112
}
97113

98-
// Motion
99-
InstanceData instanceData = gIn_InstanceData[ geometryProps0.instanceIndex ];
100-
float3 Xprev = STL::Geometry::AffineTransform( instanceData.mWorldToWorldPrev, geometryProps0.X );
101-
float4 clipPrev = STL::Geometry::ProjectiveTransform( gWorldToClipPrev, Xprev );
102-
float2 sampleUvPrev = ( clipPrev.xy / clipPrev.w ) * float2( 0.5, -0.5 ) + 0.5;
103-
float2 surfaceMotion = ( sampleUvPrev - sampleUv ) * gRectSize;
104-
float3 motion = gIsWorldSpaceMotionEnabled ? ( Xprev - geometryProps0.X ) : surfaceMotion.xyy;
105-
106-
gOut_Motion[ pixelPos ] = motion * STL::Math::LinearStep( 0.0, 0.0000005, abs( motion ) ); // TODO: move LinearStep to NRD?
107-
108114
// G-buffer
109-
float viewZ = STL::Geometry::AffineTransform( gWorldToView, geometryProps0.X ).z;
110115
float mipNorm = STL::Math::Sqrt01( geometryProps0.mip / MAX_MIP_LEVEL );
111116

112117
float3 albedo, Rf0;
@@ -118,7 +123,6 @@ void main( uint2 pixelPos : SV_DispatchThreadId )
118123
noDiffuseFlag = noDiffuseFlag || ( frac( geometryProps0.X ).x < 0.05 ? 1 : 0 );
119124
#endif
120125

121-
gOut_ViewZ[ pixelPos ] = viewZ;
122126
gOut_PrimaryMip[ pixelPos ] = mipNorm;
123127
gOut_Normal_Roughness[ pixelPos ] = NRD_FrontEnd_PackNormalAndRoughness( materialProps0.N, materialProps0.roughness, noDiffuseFlag );
124128
gOut_BaseColor_Metalness[ pixelPos ] = float4( STL::Color::LinearToSrgb( materialProps0.baseColor ), materialProps0.metalness );

Shaders/Temporal.cs.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
1010

1111
#include "Shared.hlsli"
1212

13-
NRI_RESOURCE( Texture2D<float3>, gIn_ObjectMotion, t, 0, 1 );
13+
NRI_RESOURCE( Texture2D<float3>, gIn_Mv, t, 0, 1 );
1414
NRI_RESOURCE( Texture2D<float4>, gIn_ComposedLighting_ViewZ, t, 1, 1 );
1515
NRI_RESOURCE( Texture2D<float3>, gIn_History, t, 2, 1 );
1616

@@ -110,7 +110,7 @@ void main( int2 threadPos : SV_GroupThreadId, int2 pixelPos : SV_DispatchThreadI
110110
float2 offset = float2( offseti ) * gInvRectSize;
111111
float3 Xvnearest = STL::Geometry::ReconstructViewPosition( pixelUv + offset, gCameraFrustum, viewZnearest, gOrthoMode );
112112
float3 Xnearest = STL::Geometry::AffineTransform( gViewToWorld, Xvnearest );
113-
float3 mvNearest = gIn_ObjectMotion[ pixelPos + offseti ] * ( gIsWorldSpaceMotionEnabled ? 1.0 : gInvRectSize.xyy );
113+
float3 mvNearest = gIn_Mv[ pixelPos + offseti ] * ( gIsWorldSpaceMotionEnabled ? 1.0 : gInvRectSize.xyy );
114114
float2 pixelUvPrev = STL::Geometry::GetPrevUvFromMotion( pixelUv + offset, Xnearest, gWorldToClipPrev, mvNearest, gIsWorldSpaceMotionEnabled );
115115
pixelUvPrev -= offset;
116116

Shaders/Upsample.cs.hlsl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
1111
#include "Shared.hlsli"
1212

1313
NRI_RESOURCE( Texture2D<float3>, gIn_Image, t, 0, 1 );
14+
NRI_RESOURCE( Texture2D<float4>, gIn_Validation, t, 1, 1 );
1415

15-
NRI_RESOURCE( RWTexture2D<float3>, gOut_Image, u, 1, 1 );
16+
NRI_RESOURCE( RWTexture2D<float3>, gOut_Image, u, 0, 1 );
1617

1718
[numthreads( 16, 16, 1 )]
1819
void main( uint2 pixelPos : SV_DispatchThreadId )
@@ -35,6 +36,13 @@ void main( uint2 pixelPos : SV_DispatchThreadId )
3536
const float3 nvColor = float3( 118.0, 185.0, 0.0 ) / 255.0;
3637
result = lerp( result, nvColor * verticalLine, verticalLine );
3738

39+
// Validation layer
40+
if( gValidation )
41+
{
42+
float4 validation = gIn_Validation.SampleLevel( gLinearSampler, pixelUv, 0 );
43+
result = lerp( result, validation.xyz, validation.w );
44+
}
45+
3846
// Output
3947
gOut_Image[ pixelPos ] = result;
4048
}

Shaders/UpsampleNis.cs.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ NRI_RESOURCE( Texture2D<float4>, gIn_Image, t, 0, 1 );
1414
NRI_RESOURCE( Texture2D<float4>, gIn_NisData1, t, 1, 1 );
1515
NRI_RESOURCE( Texture2D<float4>, gIn_NisData2, t, 2, 1 );
1616

17-
NRI_RESOURCE( RWTexture2D<float4>, gOut_Image, u, 3, 1 );
17+
NRI_RESOURCE( RWTexture2D<float4>, gOut_Image, u, 0, 1 );
1818

1919
// Strange stuff #1
2020
#define samplerLinearClamp gLinearSampler

0 commit comments

Comments
 (0)