Skip to content

Commit

Permalink
NRD updated to v4.9.2:
Browse files Browse the repository at this point in the history
- utilized "NRIResourceAllocator" extension for ~ALL allocations in the app
- PT: removed incorrectly traced glass in PSR space
- PT: glass tracing uses Bayer dithering to reduce overall noise
- Linux: minor fix for DLSS in Cmake
- returned back NORMAL mode instead of OCCLUSION (regression)
- updated deps
- updated tests
  • Loading branch information
dzhdanNV committed Aug 23, 2024
1 parent b5677a7 commit df1fb9c
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 189 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ if (WIN32)
else ()
find_library (NGX_D_LIB NAMES libnvsdk_ngx.a PATHS "External/NGX/lib/Linux_x86_64")
find_library (NGX_LIB NAMES libnvsdk_ngx.a PATHS "External/NGX/lib/Linux_x86_64")
find_file (DLSS_SR_DLL NAMES libnvidia-ngx-dlss.so.3.7.0 PATHS "External/NGX/lib/Linux_x86_64/rel")
find_file (DLSS_SR_DLL NAMES libnvidia-ngx-dlss.so.3.7.10 PATHS "External/NGX/lib/Linux_x86_64/rel")
endif ()

if (NGX_D_LIB AND NGX_LIB AND DLSS_SR_DLL)
Expand Down
2 changes: 1 addition & 1 deletion External/NRD
Submodule NRD updated from 7e36d4 to a3ae12
2 changes: 1 addition & 1 deletion External/NRIFramework
2 changes: 1 addition & 1 deletion Shaders/Composition.cs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void main( int2 pixelPos : SV_DispatchThreadId )
float3 diffDemod = ( 1.0 - Fenv ) * albedo * 0.99 + 0.01;
float3 specDemod = Fenv * 0.99 + 0.01;

if( normMaterialID == MATERIAL_ID_HAIR / 3.0 && NRD_NORMAL_ENCODING == NRD_NORMAL_ENCODING_R10G10B10A2_UNORM )
if( normMaterialID == MATERIAL_ID_HAIR / MATERIAL_NORM )
{
diffDemod = 1.0;
specDemod = 1.0;
Expand Down
6 changes: 3 additions & 3 deletions Shaders/DlssBefore.cs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.

#include "Include/Shared.hlsli"

NRI_RESOURCE( RWTexture2D<float>, gOut_ViewZ, u, 0, 1 );
NRI_RESOURCE( RWTexture2D<float>, gInOut_ViewZ, u, 0, 1 );
NRI_RESOURCE( RWTexture2D<float3>, gInOut_Mv, u, 1, 1 );

[numthreads( 16, 16, 1 )]
Expand All @@ -22,14 +22,14 @@ void main( uint2 pixelPos : SV_DispatchThreadId )
if( pixelUv.x > 1.0 || pixelUv.y > 1.0 )
return;

float viewZ = gOut_ViewZ[ pixelPos ];
float viewZ = gInOut_ViewZ[ pixelPos ];
float3 Xv = Geometry::ReconstructViewPosition( pixelUv, gCameraFrustum, viewZ, gOrthoMode );

// Recalculate viewZ to depth ( needed for SR )
if( gSR )
{
float4 clipPos = Geometry::ProjectiveTransform( gViewToClip, Xv );
gOut_ViewZ[ pixelPos ] = clipPos.z / clipPos.w;
gInOut_ViewZ[ pixelPos ] = clipPos.z / clipPos.w;
}

// Patch MV, because 2D MVs needed
Expand Down
5 changes: 2 additions & 3 deletions Shaders/Include/Shared.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
// SH - SH (spherical harmonics or spherical gaussian) denoisers
// OCCLUSION - OCCLUSION (ambient or specular occlusion only) denoisers
// DIRECTIONAL_OCCLUSION - DIRECTIONAL_OCCLUSION (ambient occlusion in SH mode) denoisers
#define NRD_MODE OCCLUSION // NORMAL, SH, OCCLUSION, DIRECTIONAL_OCCLUSION
#define NRD_MODE NORMAL // NORMAL, SH, OCCLUSION, DIRECTIONAL_OCCLUSION
#define SIGMA_TRANSLUCENT 1

// Default = 1
Expand Down Expand Up @@ -94,6 +94,7 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#define MATERIAL_ID_METAL 1
#define MATERIAL_ID_PSR 2
#define MATERIAL_ID_HAIR 3
#define MATERIAL_NORM 3.0

// Mip mode
#define MIP_VISIBILITY 0 // for visibility: emission, shadow and alpha mask
Expand Down Expand Up @@ -506,8 +507,6 @@ float GetCircleOfConfusion( float distance ) // diameter
#define SKY_INTENSITY 1.0
#define SUN_INTENSITY 10.0

// TODO: add dither, use USE_FP11 = true

float3 GetSunIntensity( float3 v )
{
float b = dot( v, gSunDirection.xyz );
Expand Down
13 changes: 7 additions & 6 deletions Shaders/Taa.cs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.

#include "Include/Shared.hlsli"

NRI_RESOURCE( Texture2D<float3>, gIn_Mv, t, 0, 1 );
NRI_RESOURCE( Texture2D<float4>, gIn_ComposedLighting_ViewZ, t, 1, 1 );
NRI_RESOURCE( Texture2D<float4>, gIn_History, t, 2, 1 );
NRI_RESOURCE( Texture2D<float>, gIn_ViewZ, t, 0, 1 );
NRI_RESOURCE( Texture2D<float3>, gIn_Mv, t, 1, 1 );
NRI_RESOURCE( Texture2D<float3>, gIn_Composed, t, 2, 1 );
NRI_RESOURCE( Texture2D<float4>, gIn_History, t, 3, 1 );

NRI_RESOURCE( RWTexture2D<float4>, gOut_Result, u, 0, 1 );

Expand Down Expand Up @@ -41,9 +42,9 @@ void Preload( uint2 sharedPos, int2 globalPos )
{
globalPos = clamp( globalPos, 0, gRectSize - 1.0 );

float4 color_viewZ = gIn_ComposedLighting_ViewZ[ globalPos ];
color_viewZ.xyz = ApplyTonemap( color_viewZ.xyz );
color_viewZ.w = abs( color_viewZ.w ) * Math::Sign( gNearZ ) / FP16_VIEWZ_SCALE;
float4 color_viewZ;
color_viewZ.xyz = ApplyTonemap( gIn_Composed[ globalPos ] );
color_viewZ.w = gIn_ViewZ[ globalPos ];

s_Data[ sharedPos.y ][ sharedPos.x ] = color_viewZ;
}
Expand Down
21 changes: 12 additions & 9 deletions Shaders/TraceOpaque.cs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ float2 GetBlueNoise( uint2 pixelPos, bool isCheckerboard, uint seed = 0 )
float2 dither = ( float2( d & 3, d >> 2 ) + 0.5 ) * ( 1.0 / 4.0 );
blue += ( dither.xyxy - 0.5 ) * ( 1.0 / 256.0 );

// Don't use blue noise in these cases
if( gDenoiserType == DENOISER_REFERENCE || gRR )
blue.xy = Rng::Hash::GetFloat2( );

return saturate( blue.xy );
}

Expand Down Expand Up @@ -273,7 +277,7 @@ TraceOpaqueResult TraceOpaque( TraceOpaqueDesc desc )

bool isSharcAllowed = geometryProps.tmin > voxelSize; // voxel angular size is acceptable
isSharcAllowed = isSharcAllowed && Rng::Hash::GetFloat( ) > Lcached.w; // probabilistically estimate the need
isSharcAllowed = isSharcAllowed && desc.bounceNum == 0; // for PSR allowed only for the last bounce
isSharcAllowed = isSharcAllowed && desc.bounceNum == 0; // allow only for the last bounce for PSR

float3 sharcRadiance = 0;
if( isSharcAllowed && SharcGetCachedRadiance( sharcState, sharcHitData, sharcRadiance, false ) )
Expand All @@ -299,21 +303,22 @@ TraceOpaqueResult TraceOpaque( TraceOpaqueDesc desc )
psrLsum = Lcached.xyz;

// Update materials and INF emission
float3 psrNormal = float3( 0, 0, 1 );
if( !geometryProps.IsSky( ) )
{
float3 psrNormal = Geometry::RotateVectorInverse( mirrorMatrix, materialProps.N );
psrNormal = Geometry::RotateVectorInverse( mirrorMatrix, materialProps.N );

gOut_BaseColor_Metalness[ desc.pixelPos ] = float4( Color::ToSrgb( materialProps.baseColor ), materialProps.metalness );

// IMPORTANT: use another set of materialID to avoid potential leaking, because PSR uses own de-modulation scheme
gOut_Normal_Roughness[ desc.pixelPos ] = NRD_FrontEnd_PackNormalAndRoughness( psrNormal, materialProps.roughness, MATERIAL_ID_PSR );
}
else
{
// Composition pass doesn't apply "psrThroughput" to INF pixels
gOut_DirectEmission[ desc.pixelPos ] = psrLsum * psrThroughput;
}

// IMPORTANT: use another materialID to avoid potential leaking, because PSR uses own de-modulation scheme. Also needed for tracing of transparent stuff
gOut_Normal_Roughness[ desc.pixelPos ] = NRD_FrontEnd_PackNormalAndRoughness( psrNormal, materialProps.roughness, MATERIAL_ID_PSR );

// Update viewZ
float3 Xvirtual = desc.geometryProps.X - desc.geometryProps.V * accumulatedHitDist;
viewZ = Geometry::AffineTransform( gWorldToView, Xvirtual ).z;
Expand Down Expand Up @@ -377,7 +382,7 @@ TraceOpaqueResult TraceOpaque( TraceOpaqueDesc desc )

// Clamp probability to a sane range to guarantee a sample in 3x3 ( or 5x5 ) area
float rnd = Rng::Hash::GetFloat( );
if( gTracingMode == RESOLUTION_FULL_PROBABILISTIC && bounceIndex == 1 )
if( gTracingMode == RESOLUTION_FULL_PROBABILISTIC && bounceIndex == 1 && !gRR )
{
diffuseProbability = float( diffuseProbability != 0.0 ) * clamp( diffuseProbability, gMinProbability, 1.0 - gMinProbability );
rnd = Sequence::Bayer4x4( desc.pixelPos, gFrameIndex ) + rnd / 16.0;
Expand Down Expand Up @@ -623,7 +628,7 @@ TraceOpaqueResult TraceOpaque( TraceOpaqueDesc desc )
float3 Xglobal = GetGlobalPos( geometryProps.X );
uint level = GetGridLevel( Xglobal, gridParameters );
float voxelSize = GetVoxelSize( level, gridParameters );
float smc = GetSpecMagicCurve( accumulatedDiffuseLikeMotion ); // better than "materialProps.roughness"
float smc = GetSpecMagicCurve( materialProps.roughness );

float3x3 mBasis = Geometry::GetBasis( geometryProps.N );
float2 rndScaled = ( Rng::Hash::GetFloat2( ) - 0.5 ) * voxelSize * USE_SHARC_DITHERING;
Expand Down Expand Up @@ -933,8 +938,6 @@ void main( uint2 pixelPos : SV_DispatchThreadId )

// Sun shadow
float2 rnd = GetBlueNoise( pixelPos, false );
if( gDenoiserType == DENOISER_REFERENCE )
rnd = Rng::Hash::GetFloat2( );
rnd = ImportanceSampling::Cosine::GetRay( rnd ).xy;
rnd *= gTanSunAngularRadius;

Expand Down
29 changes: 19 additions & 10 deletions Shaders/TraceTransparent.cs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.

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

// Outputs
NRI_RESOURCE( RWTexture2D<float4>, gOut_Composed, u, 0, 1 );
NRI_RESOURCE( RWTexture2D<float3>, gOut_Composed, u, 0, 1 );
NRI_RESOURCE( RWTexture2D<float3>, gInOut_Mv, u, 1, 1 );

//========================================================================================
Expand Down Expand Up @@ -66,7 +67,13 @@ float3 TraceTransparent( TraceTransparentDesc desc )
if( bounce == 1 )
pathThroughput *= isReflection ? F : 1.0 - F;
else
isReflection = Rng::Hash::GetFloat( ) < F;
{
float rnd = Sequence::Bayer4x4( desc.pixelPos, gFrameIndex + bounce );
if( gDenoiserType == DENOISER_REFERENCE || gRR )
rnd = Rng::Hash::GetFloat( );

isReflection = rnd < F;
}

// Compute ray
float3 ray = reflect( -geometryProps.V, geometryProps.N );
Expand Down Expand Up @@ -184,8 +191,8 @@ void main( int2 pixelPos : SV_DispatchThreadId )

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

// Primary ray for transparent geometry only
float3 cameraRayOrigin = ( float3 )0;
Expand All @@ -198,8 +205,12 @@ void main( int2 pixelPos : SV_DispatchThreadId )

GeometryProps geometryPropsT = CastRay( cameraRayOrigin, cameraRayDirection, 0.0, tmin0, GetConeAngleFromRoughness( 0.0, 0.0 ), gWorldTlas, gTransparent == 0.0 ? 0 : GEOMETRY_ONLY_TRANSPARENT, 0 );

// Material ID
float normMaterialID;
float4 normalAndRoughness = NRD_FrontEnd_UnpackNormalAndRoughness( gIn_Normal_Roughness[ pixelPos ], normMaterialID );

// Trace delta events
if( !geometryPropsT.IsSky( ) && geometryPropsT.tmin < tmin0 )
if( !geometryPropsT.IsSky( ) && geometryPropsT.tmin < tmin0 && normMaterialID != MATERIAL_ID_PSR / MATERIAL_NORM )
{
// Patch motion vectors replacing MV for the background with MV for the closest glass layer.
// IMPORTANT: surface-based motion can be used only if the object is curved.
Expand Down Expand Up @@ -230,7 +241,5 @@ void main( int2 pixelPos : SV_DispatchThreadId )
Lsum = ApplyExposure( Lsum );

// Output
float z = spec.w;

gOut_Composed[ pixelPos ] = float4( Lsum, z );
gOut_Composed[ pixelPos ] = Lsum;
}
6 changes: 3 additions & 3 deletions Source/DLSS/DLSSIntegration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <assert.h> // assert
#include <stdio.h> // printf

static_assert(NRI_VERSION_MAJOR >= 1 && NRI_VERSION_MINOR >= 140, "Unsupported NRI version!");
static_assert(NRI_VERSION_MAJOR >= 1 && NRI_VERSION_MINOR >= 141, "Unsupported NRI version!");

// An ugly temp workaround until DLSS fix the problem
#ifndef _WIN32
Expand Down Expand Up @@ -141,8 +141,8 @@ bool DlssIntegration::InitializeLibrary(nri::Device& device, const char* appData
else if (deviceDesc.graphicsAPI == nri::GraphicsAPI::VK)
{
VkDevice vkDevice = (VkDevice)NRI.GetDeviceNativeObject(*m_Device);
VkPhysicalDevice vkPhysicalDevice = (VkPhysicalDevice)NRI.GetVkPhysicalDevice(*m_Device);
VkInstance vkInstance = (VkInstance)NRI.GetVkInstance(*m_Device);
VkPhysicalDevice vkPhysicalDevice = (VkPhysicalDevice)NRI.GetPhysicalDeviceVK(*m_Device);
VkInstance vkInstance = (VkInstance)NRI.GetInstanceVK(*m_Device);
result = NVSDK_NGX_VULKAN_Init(m_ApplicationId, path, vkInstance, vkPhysicalDevice, vkDevice);
if (NVSDK_NGX_SUCCEED(result))
result = NVSDK_NGX_VULKAN_GetCapabilityParameters(&m_NgxParameters);
Expand Down
Loading

0 comments on commit df1fb9c

Please sign in to comment.