Skip to content

Commit

Permalink
NRD updated to v4.2.0:
Browse files Browse the repository at this point in the history
- PT: better hitT accumulation on emissives
- PT: improved PSR
- PT: improved curvature heuristic for PSR
- PT: added geometry curvature correction by scale
- PT: added optional Russian Roulette usage
- PT: added curvature visualization
- PT: added PSR throughput visualization
- PT: fixed bias in Important Sampling
- PT: fixed glass in ortho mode
- PT: fixed / tuned ambient usage
- PT: fixed / adjusted throughput
- PT: fixed previous frame reuse for specular for low roughness
- PT: fixed MV of dynamic objects in PSR
- PT: fixed prev transform of scaled glass objects
- NRD: anti-firefly enabled in DLSS mode for REBLUR (good cleaner, minimizes confusion cases for DLSS, doesn't add bias)
- UI: highlighted preferred settings
- dropped AssImp
- added Kitchen scene and removed ZeroDay scene
- all assets converted to GLTF
- optimized memory usage a bit
- performance optimizations
- more accurate curvature calculations
- updated README
- updated dependencies
- refactoring
  • Loading branch information
dzhdanNV committed May 23, 2023
1 parent 0dafd53 commit f229533
Show file tree
Hide file tree
Showing 16 changed files with 640 additions and 556 deletions.
8 changes: 4 additions & 4 deletions .args
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@
"Command": "SCENES",
"Items": [
{
"Command": "--scene=ShaderBalls/ShaderBalls.obj"
"Command": "--scene=ShaderBalls/ShaderBalls.gltf"
},
{
"Command": "--scene=Bistro/BistroInterior.fbx"
"Command": "--scene=Bistro/BistroInterior.gltf"
},
{
"Command": "--scene=Bistro/BistroExterior.fbx"
"Command": "--scene=Bistro/BistroExterior.gltf"
},
{
"Command": "--scene=ZeroDay/MEASURE_SEVEN/MEASURE_SEVEN.fbx"
"Command": "--scene=Kitchen/Kitchen.gltf"
}
]
},
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ compile_commands.json
*.manifest

# external packages
External/Assimp/
External/Detex/
External/Glfw/
External/ImGui/
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ endif ()
message ("Packman platform: ${PACKMAN_PLATFORM}")

if (USE_MINIMAL_DATA)
set (NRI_DATA_VERSION 2.0_minimal)
set (NRI_DATA_VERSION 2.3_minimal)
message ("Using minimal '_Data'")
else ()
set (NRI_DATA_VERSION 2.1)
set (NRI_DATA_VERSION 2.3)
endif ()

execute_process (COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/External/Packman/packman${PACKMAN_EXT}" pull "${CMAKE_CURRENT_SOURCE_DIR}/Dependencies.xml" -p ${PACKMAN_PLATFORM} -t nri_data_version=${NRI_DATA_VERSION}
Expand Down
2 changes: 1 addition & 1 deletion External/NRD
Submodule NRD updated 91 files
+6 −5 CMakeLists.txt
+1 −1 External/MathLib
+1 −1 External/ShaderMake
+20 −9 Include/NRD.h
+20 −14 Include/NRDDescs.h
+4 −2 Include/NRDSettings.h
+19 −16 Integration/NRDIntegration.h
+76 −71 Integration/NRDIntegration.hpp
+90 −80 README.md
+3 −3 Resources/NRD.rc
+3 −4 Resources/Version.h
+2 −0 Shaders.cfg
+18 −0 Shaders/Include/Common.hlsli
+2 −2 Shaders/Include/NRD.hlsli
+6 −2 Shaders/Include/REBLUR/REBLUR_Config.hlsli
+6 −3 Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_Blur.hlsli
+5 −1 Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_CopyStabilizedHistory.hlsli
+71 −37 Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_HistoryFix.hlsli
+7 −3 Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_HitDistReconstruction.hlsli
+11 −4 Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_PostBlur.hlsli
+5 −2 Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_PrePass.hlsli
+16 −14 Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_TemporalAccumulation.hlsli
+8 −7 Shaders/Include/REBLUR/REBLUR_DiffuseSpecular_TemporalStabilization.hlsli
+1 −1 Shaders/Include/RELAX/RELAX_Config.hlsli
+6 −4 Shaders/Include/RELAX/RELAX_DiffuseSpecular_AntiFirefly.hlsli
+17 −4 Shaders/Include/RELAX/RELAX_DiffuseSpecular_Atrous.hlsli
+11 −6 Shaders/Include/RELAX/RELAX_DiffuseSpecular_AtrousSmem.hlsli
+12 −7 Shaders/Include/RELAX/RELAX_DiffuseSpecular_HistoryClamping.hlsli
+7 −4 Shaders/Include/RELAX/RELAX_DiffuseSpecular_HistoryFix.hlsli
+7 −2 Shaders/Include/RELAX/RELAX_DiffuseSpecular_HitDistReconstruction.hlsli
+5 −10 Shaders/Include/RELAX/RELAX_DiffuseSpecular_PrePass.hlsli
+23 −29 Shaders/Include/RELAX/RELAX_DiffuseSpecular_TemporalAccumulation.hlsli
+5 −21 Shaders/Include/SIGMA/SIGMA_Common.hlsli
+3 −2 Shaders/Include/SIGMA/SIGMA_Config.hlsli
+16 −9 Shaders/Include/SIGMA/SIGMA_Shadow_Blur.hlsli
+11 −6 Shaders/Include/SIGMA/SIGMA_Shadow_ClassifyTiles.hlsli
+14 −4 Shaders/Include/SIGMA/SIGMA_Shadow_TemporalStabilization.hlsli
+21 −0 Shaders/Resources/REBLUR_ClassifyTiles.resources.hlsli
+20 −17 Shaders/Resources/REBLUR_DiffuseSpecular_Blur.resources.hlsli
+11 −8 Shaders/Resources/REBLUR_DiffuseSpecular_CopyStabilizedHistory.resources.hlsli
+24 −21 Shaders/Resources/REBLUR_DiffuseSpecular_HistoryFix.resources.hlsli
+13 −10 Shaders/Resources/REBLUR_DiffuseSpecular_HitDistReconstruction.resources.hlsli
+20 −17 Shaders/Resources/REBLUR_DiffuseSpecular_PostBlur.resources.hlsli
+17 −14 Shaders/Resources/REBLUR_DiffuseSpecular_PrePass.resources.hlsli
+50 −47 Shaders/Resources/REBLUR_DiffuseSpecular_TemporalAccumulation.resources.hlsli
+35 −32 Shaders/Resources/REBLUR_DiffuseSpecular_TemporalStabilization.resources.hlsli
+21 −0 Shaders/Resources/RELAX_ClassifyTiles.resources.hlsli
+13 −10 Shaders/Resources/RELAX_DiffuseSpecular_AntiFirefly.resources.hlsli
+26 −23 Shaders/Resources/RELAX_DiffuseSpecular_Atrous.resources.hlsli
+33 −28 Shaders/Resources/RELAX_DiffuseSpecular_AtrousSmem.resources.hlsli
+22 −19 Shaders/Resources/RELAX_DiffuseSpecular_HistoryClamping.resources.hlsli
+20 −17 Shaders/Resources/RELAX_DiffuseSpecular_HistoryFix.resources.hlsli
+13 −10 Shaders/Resources/RELAX_DiffuseSpecular_HitDistReconstruction.resources.hlsli
+21 −24 Shaders/Resources/RELAX_DiffuseSpecular_PrePass.resources.hlsli
+57 −54 Shaders/Resources/RELAX_DiffuseSpecular_TemporalAccumulation.resources.hlsli
+7 −3 Shaders/Resources/SIGMA_Shadow_Blur.resources.hlsli
+1 −1 Shaders/Resources/SIGMA_Shadow_ClassifyTiles.resources.hlsli
+2 −2 Shaders/Resources/SIGMA_Shadow_SmoothTiles.resources.hlsli
+1 −1 Shaders/Resources/SIGMA_Shadow_TemporalStabilization.resources.hlsli
+48 −0 Shaders/Source/REBLUR_ClassifyTiles.cs.hlsl
+48 −0 Shaders/Source/RELAX_ClassifyTiles.cs.hlsl
+7 −6 Shaders/Source/SIGMA_Shadow_SmoothTiles.cs.hlsl
+45 −18 Source/Denoisers/Reblur_Diffuse.hpp
+45 −18 Source/Denoisers/Reblur_DiffuseDirectionalOcclusion.hpp
+39 −15 Source/Denoisers/Reblur_DiffuseOcclusion.hpp
+48 −21 Source/Denoisers/Reblur_DiffuseSh.hpp
+50 −23 Source/Denoisers/Reblur_DiffuseSpecular.hpp
+43 −19 Source/Denoisers/Reblur_DiffuseSpecularOcclusion.hpp
+56 −29 Source/Denoisers/Reblur_DiffuseSpecularSh.hpp
+45 −18 Source/Denoisers/Reblur_Specular.hpp
+39 −16 Source/Denoisers/Reblur_SpecularOcclusion.hpp
+48 −21 Source/Denoisers/Reblur_SpecularSh.hpp
+12 −12 Source/Denoisers/Reference.hpp
+107 −83 Source/Denoisers/Relax_Diffuse.hpp
+113 −92 Source/Denoisers/Relax_DiffuseSh.hpp
+125 −104 Source/Denoisers/Relax_DiffuseSpecular.hpp
+139 −122 Source/Denoisers/Relax_DiffuseSpecularSh.hpp
+110 −86 Source/Denoisers/Relax_Specular.hpp
+114 −93 Source/Denoisers/Relax_SpecularSh.hpp
+19 −18 Source/Denoisers/Sigma_Shadow.hpp
+19 −18 Source/Denoisers/Sigma_ShadowTranslucency.hpp
+11 −11 Source/Denoisers/SpecularDeltaMv.hpp
+7 −7 Source/Denoisers/SpecularReflectionMv.hpp
+466 −404 Source/InstanceImpl.cpp
+88 −84 Source/InstanceImpl.h
+4 −4 Source/Other.cpp
+88 −64 Source/Reblur.cpp
+28 −20 Source/Relax.cpp
+20 −20 Source/Sigma.cpp
+54 −46 Source/Wrapper.cpp
+19 −1 UPDATE.md
42 changes: 27 additions & 15 deletions Shaders/Composition.cs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ NRI_RESOURCE( Texture2D<float>, gIn_ViewZ, t, 0, 1 );
NRI_RESOURCE( Texture2D<float4>, gIn_Normal_Roughness, t, 1, 1 );
NRI_RESOURCE( Texture2D<float4>, gIn_BaseColor_Metalness, t, 2, 1 );
NRI_RESOURCE( Texture2D<float3>, gIn_DirectLighting, t, 3, 1 );
NRI_RESOURCE( Texture2D<float3>, gIn_Ambient, t, 4, 1 );
NRI_RESOURCE( Texture2D<float4>, gIn_Diff, t, 5, 1 );
NRI_RESOURCE( Texture2D<float4>, gIn_Spec, t, 6, 1 );
NRI_RESOURCE( Texture2D<float3>, gIn_PsrThroughput, t, 4, 1 );
NRI_RESOURCE( Texture2D<float3>, gIn_Ambient, t, 5, 1 );
NRI_RESOURCE( Texture2D<float4>, gIn_Diff, t, 6, 1 );
NRI_RESOURCE( Texture2D<float4>, gIn_Spec, t, 7, 1 );
#if( NRD_MODE == SH )
NRI_RESOURCE( Texture2D<float4>, gIn_DiffSh, t, 7, 1 );
NRI_RESOURCE( Texture2D<float4>, gIn_SpecSh, t, 8, 1 );
NRI_RESOURCE( Texture2D<float4>, gIn_DiffSh, t, 8, 1 );
NRI_RESOURCE( Texture2D<float4>, gIn_SpecSh, t, 9, 1 );
#endif

// Outputs
NRI_RESOURCE( RWTexture2D<float4>, gOut_ComposedDiff, u, 0, 1 );
NRI_RESOURCE( RWTexture2D<float4>, gOut_ComposedSpec, u, 1, 1 );
NRI_RESOURCE( RWTexture2D<float3>, gOut_ComposedDiff, u, 0, 1 );
NRI_RESOURCE( RWTexture2D<float4>, gOut_ComposedSpec_ViewZ, u, 1, 1 );

[numthreads( 16, 16, 1)]
void main( int2 pixelPos : SV_DispatchThreadId )
Expand Down Expand Up @@ -53,8 +54,8 @@ void main( int2 pixelPos : SV_DispatchThreadId )

if( abs( viewZ ) == INF )
{
gOut_ComposedDiff[ pixelPos ] = float4( Ldirect * float( gOnScreen == SHOW_FINAL ), z );
gOut_ComposedSpec[ pixelPos ] = float4( 0, 0, 0, z );
gOut_ComposedDiff[ pixelPos ] = Ldirect * float( gOnScreen == SHOW_FINAL );
gOut_ComposedSpec_ViewZ[ pixelPos ] = float4( 0, 0, 0, z );

return;
}
Expand Down Expand Up @@ -186,8 +187,8 @@ void main( int2 pixelPos : SV_DispatchThreadId )
float3 diffDemod = ( 1.0 - Fenv ) * albedo * 0.99 + 0.01;
float3 specDemod = Fenv * 0.99 + 0.01;

float3 Ldiff = diff.xyz * ( gReference ? 1.0 : diffDemod );
float3 Lspec = spec.xyz * ( gReference ? 1.0 : specDemod );
float3 Ldiff = diff.xyz * diffDemod;
float3 Lspec = spec.xyz * specDemod;

// Ambient
float3 ambient = gIn_Ambient.SampleLevel( gLinearSampler, float2( 0.5, 0.5 ), 0 );
Expand All @@ -199,8 +200,17 @@ void main( int2 pixelPos : SV_DispatchThreadId )
Ldiff += ambient * diff.w * ( 1.0 - Fenv ) * albedo;
Lspec += ambient * spec.w * Fenv * specAmbientAmount;

// IMPORTANT: we store diffuse and specular separately to be able to use reprojection trick.
// Let's assume that direct lighting can always be reprojected as diffuse
// Apply PSR throughput ( primary surface material before replacement )
#if( USE_PSR == 1 )
float3 psrThroughput = gIn_PsrThroughput[ pixelPos ];
Ldiff *= psrThroughput;
Lspec *= psrThroughput;
Ldirect *= psrThroughput;
#else
float3 psrThroughput = 1.0;
#endif

// IMPORTANT: we store diffuse and specular separately to be able to use the reprojection trick. Let's assume that direct lighting can always be reprojected as diffuse
Ldiff += Ldirect;

// Debug
Expand All @@ -222,10 +232,12 @@ void main( int2 pixelPos : SV_DispatchThreadId )
Ldiff = baseColorMetalness.w;
else if( gOnScreen == SHOW_WORLD_UNITS )
Ldiff = frac( X * gUnitToMetersMultiplier );
else if( gOnScreen == SHOW_PSR_THROUGHPUT )
Ldiff = psrThroughput;
else if( gOnScreen != SHOW_FINAL )
Ldiff = gOnScreen == SHOW_MIP_SPECULAR ? spec.xyz : Ldirect.xyz;

// Output
gOut_ComposedDiff[ pixelPos ] = float4( Ldiff, z );
gOut_ComposedSpec[ pixelPos ] = float4( Lspec, z );
gOut_ComposedDiff[ pixelPos ] = Ldiff;
gOut_ComposedSpec_ViewZ[ pixelPos ] = float4( Lspec, z );
}
40 changes: 18 additions & 22 deletions Shaders/DeltaRays.cs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.

// Inputs
NRI_RESOURCE( Texture2D<float>, gIn_ViewZ, t, 0, 1 );
NRI_RESOURCE( Texture2D<float4>, gIn_Diff_ViewZ, t, 1, 1 );
NRI_RESOURCE( Texture2D<float4>, gIn_Spec_ViewZ, t, 2, 1 );
NRI_RESOURCE( Texture2D<float3>, gIn_ComposedDiff, t, 1, 1 );
NRI_RESOURCE( Texture2D<float4>, gIn_ComposedSpec_ViewZ, t, 2, 1 );
NRI_RESOURCE( Texture2D<float3>, gIn_Ambient, t, 3, 1 );

// Outputs
Expand Down Expand Up @@ -54,18 +54,18 @@ float3 TraceTransparent( TraceTransparentDesc desc )
float eta = STL::BRDF::IOR::Air / STL::BRDF::IOR::Glass;

GeometryProps geometryProps = desc.geometryProps;
float transmittance = 1.0;
float pathThroughput = 1.0;
bool isReflection = desc.isReflection;

[loop]
for( uint bounce = 1; bounce <= desc.bounceNum; bounce++ ) // TODO: stop if transmittance is low
for( uint bounce = 1; bounce <= desc.bounceNum; bounce++ ) // TODO: stop if pathThroughput is low
{
// Reflection or refraction?
float NoV = abs( dot( geometryProps.N, geometryProps.V ) );
float F = STL::BRDF::FresnelTerm_Dielectric( eta, NoV );

if( bounce == 1 )
transmittance *= isReflection ? F : 1.0 - F;
pathThroughput *= isReflection ? F : 1.0 - F;
else
isReflection = STL::Rng::Hash::GetFloat( ) < F;

Expand Down Expand Up @@ -94,7 +94,7 @@ float3 TraceTransparent( TraceTransparentDesc desc )
// TODO: glass internal extinction?
// ideally each "medium" should have "eta" and "extinction" parameters in "TraceTransparentDesc" and "TraceOpaqueDesc"
if( !isReflection )
transmittance *= 0.96;
pathThroughput *= 0.96;

// Is opaque hit found?
if( !geometryProps.IsTransparent( ) )
Expand All @@ -111,16 +111,17 @@ float3 TraceTransparent( TraceTransparentDesc desc )
// Ambient estimation at the end of the path
float3 BRDF = GetAmbientBRDF( geometryProps, materialProps );
BRDF *= 1.0 + EstimateDiffuseProbability( geometryProps, materialProps, true );

L += desc.Lamb * BRDF;

// Previous frame
float3 prevLdiff, prevLspec;
float reprojectionWeight = ReprojectRadiance( false, !isReflection, gIn_Diff_ViewZ, gIn_Spec_ViewZ, geometryProps, desc.pixelPos, prevLdiff, prevLspec );
float reprojectionWeight = ReprojectRadiance( false, !isReflection, gIn_ComposedDiff, gIn_ComposedSpec_ViewZ, geometryProps, desc.pixelPos, prevLdiff, prevLspec );

L = lerp( L, prevLdiff + prevLspec, reprojectionWeight );

// Output
return L * transmittance;
return L * pathThroughput;
}
}

Expand Down Expand Up @@ -150,15 +151,19 @@ void main( int2 pixelPos : SV_DispatchThreadId )
float viewZ = gIn_ViewZ[ pixelPos ];
float3 Xv = STL::Geometry::ReconstructViewPosition( sampleUv, gCameraFrustum, viewZ, gOrthoMode );

// Composed without glass
float3 diff = gIn_ComposedDiff[ pixelPos ];
float4 spec = gIn_ComposedSpec_ViewZ[ pixelPos ];
float3 Lsum = diff + spec.xyz * float( gOnScreen == SHOW_FINAL );

// Primary ray for transparent geometry only
float3 cameraRayOriginv = STL::Geometry::ReconstructViewPosition( sampleUv, gCameraFrustum, gNearZ, gOrthoMode );
float3 cameraRayOrigin = STL::Geometry::AffineTransform( gViewToWorld, cameraRayOriginv );
float3 cameraRayDirection = gOrthoMode == 0 ? normalize( STL::Geometry::RotateVector( gViewToWorld, cameraRayOriginv ) ) : -gViewDirection;

float tmin0 = length( Xv );
float tmin0 = gOrthoMode == 0 ? length( Xv ) : abs( Xv.z );
GeometryProps geometryPropsT = CastRay( cameraRayOrigin, cameraRayDirection, 0.0, tmin0, GetConeAngleFromRoughness( 0.0, 0.0 ), gWorldTlas, gTransparent == 0.0 ? 0 : GEOMETRY_ONLY_TRANSPARENT, 0 );

float3 Ltransparent = 0.0;
if( !geometryPropsT.IsSky( ) && geometryPropsT.tmin < tmin0 )
{
// Initialize RNG
Expand Down Expand Up @@ -190,23 +195,14 @@ void main( int2 pixelPos : SV_DispatchThreadId )
// IMPORTANT: use 1 reflection path and 1 refraction path at the primary glass hit to significantly reduce noise
// TODO: use probabilistic split at the primary glass hit when denoising is available
desc.isReflection = true;
Ltransparent = TraceTransparent( desc );
Lsum = TraceTransparent( desc );

desc.isReflection = false;
Ltransparent += TraceTransparent( desc );
Lsum += TraceTransparent( desc );
}

// Composition
float4 diff = gIn_Diff_ViewZ[ pixelPos ];
float4 spec = gIn_Spec_ViewZ[ pixelPos ] * float( gOnScreen == SHOW_FINAL );

float3 Lsum = diff.xyz + spec.xyz;

float mask = dot( Ltransparent, 1.0 );
Lsum = mask == 0.0 ? Lsum : Ltransparent;

// Output
float z = diff.w;
float z = spec.w;

gOut_Composed[ pixelPos ] = float4( Lsum, z );
}
Loading

0 comments on commit f229533

Please sign in to comment.