Skip to content

Commit

Permalink
v4.11.4:
Browse files Browse the repository at this point in the history
HIGHLIGHTS:
- improved robustness

DETAILS:
- NRD: GLSL-related replacements come into play if not already defined
- NRD: improved robustness
- RELAX: fixed touching of pixels outside of denoising range (can be garbage) in "HistoryClamping" pass
- RELAX/REBLUR: fixed touching of wrong data (can be garbage) in "checkerboard" mode on the left side of the screen
- REBLUR: pedantic IQ changes in "TemporalStabilization" pass if "split screen" mode is active
- Integration: NRI updated to v1.161
- updated docs
  • Loading branch information
dzhdanNV committed Jan 21, 2025
1 parent 33e10fa commit c559760
Show file tree
Hide file tree
Showing 24 changed files with 222 additions and 140 deletions.
2 changes: 1 addition & 1 deletion External/MathLib
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 4
#define NRD_VERSION_MINOR 11
#define NRD_VERSION_BUILD 3
#define NRD_VERSION_DATE "3 January 2024"
#define NRD_VERSION_BUILD 4
#define NRD_VERSION_DATE "20 January 2025"

#if defined(_WIN32)
#define NRD_CALL __stdcall
Expand Down
1 change: 1 addition & 0 deletions Include/NRDSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ namespace nrd
float timeDeltaBetweenFrames = 0.0f;

// (units > 0) - use TLAS or tracing range
// It's highly recommended to use "viewZ > denoisingRange" for INF (sky) pixels
float denoisingRange = 500000.0f;

// [0.01; 0.02] - two samples considered occluded if relative distance difference is greater than this slope-scaled threshold
Expand Down
8 changes: 4 additions & 4 deletions Integration/NRDIntegration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#include <alloca.h>
#endif

static_assert(NRD_VERSION_MAJOR >= 4 && NRD_VERSION_MINOR >= 10, "Unsupported NRD version!");
static_assert(NRI_VERSION_MAJOR >= 1 && NRI_VERSION_MINOR >= 158, "Unsupported NRI version!");
static_assert(NRD_VERSION_MAJOR >= 4 && NRD_VERSION_MINOR >= 11, "Unsupported NRD version!");
static_assert(NRI_VERSION_MAJOR >= 1 && NRI_VERSION_MINOR >= 161, "Unsupported NRI version!");

namespace nrd
{
Expand Down Expand Up @@ -341,15 +341,15 @@ void Integration::CreateResources(uint16_t resourceWidth, uint16_t resourceHeigh
snprintf(name, sizeof(name), "%s::P(%u)", m_Name, i);
else
snprintf(name, sizeof(name), "%s::T(%u)", m_Name, i - instanceDesc.permanentPoolSize);
m_NRI->SetTextureDebugName(*texture, name);
m_NRI->SetDebugName(texture, name);

// Construct NRD texture
nri::TextureBarrierDesc& nrdTexture = m_TexturePool[i];
nrdTexture = nri::TextureBarrierFromUnknown(texture, {nri::AccessBits::UNKNOWN, nri::Layout::UNKNOWN}, 0, 1);

// Adjust memory usage
nri::MemoryDesc memoryDesc = {};
m_NRI->GetTextureMemoryDesc(*m_Device, textureDesc, nri::MemoryLocation::DEVICE, memoryDesc);
m_NRI->GetTextureMemoryDesc(*texture, nri::MemoryLocation::DEVICE, memoryDesc);

if (i < instanceDesc.permanentPoolSize)
m_PermanentPoolSize += memoryDesc.size;
Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# NVIDIA REAL-TIME DENOISERS v4.11.3 (NRD)
# NVIDIA REAL-TIME DENOISERS v4.11.4 (NRD)

[![Build NRD SDK](https://github.com/NVIDIAGameWorks/RayTracingDenoiser/actions/workflows/build.yml/badge.svg)](https://github.com/NVIDIAGameWorks/RayTracingDenoiser/actions/workflows/build.yml)

Expand Down Expand Up @@ -98,8 +98,6 @@ NRD sample has *TESTS* section in the bottom of the UI, a new test can be added
- If nothing helps
- describe the issue, attach a video and steps to reproduce

Additionally, for any information, suggestions or general requests please feel free to contact us at NRD-SDK-Support@nvidia.com

# API

Terminology:
Expand Down Expand Up @@ -154,8 +152,6 @@ Commons inputs for primary hits (if *PSR* is not used, common use case) or for s
- project on screen using matrices passed to NRD
- `.w` component is positive view Z (or just transform world-space position to main view space and take `.z` component)

All textures should be *NaN* free at each pixel, even at pixels outside of denoising range.

The illustration below shows expected inputs for primary hits:

![Input without PSR](Images/InputsWithoutPsr.png)
Expand Down Expand Up @@ -208,6 +204,17 @@ Distance to occluder (*SIGMA*):

See `NRDDescs.h` and `NRD.hlsli` for more details and descriptions of other inputs and outputs.

# NOISY & NON-NOISY DATA REQUIREMENTS

Noisy inputs:
- garbage values are allowed outside of active viewport, i.e. `>= CommonSettings::rectSize`
- garbage values are allowed outside of denoising range, i.e. `>= CommonSettings::denoisingRange`

Non-noisy inputs (guides):
- must not contain garbage

Where "garbage" is `NAN/INF` or undesired value.

# IMPROVING OUTPUT QUALITY

The temporal part of *NRD* naturally suppresses jitter, which is essential for upscaling techniques. If an *SH* denoiser is in use, a high quality resolve can be applied to the final output to regain back macro details, micro details and per-pixel jittering. As an example, the image below demonstrates the results *after* and *before* resolve with active *DLSS* (quality mode).
Expand Down Expand Up @@ -665,13 +672,6 @@ IN_NORMAL_ROUGHNESS = GetVirtualSpaceNormalAndRoughnessAt( B );
IN_MV = GetMotionAt( B );
```
## INTERACTION WITH `INFs` AND `NANs`
- *NRD* doesn't touch pixels outside of viewport: `INFs / NANs` are allowed
- *NRD* doesn't touch pixels outside of denoising range: `INFs / NANs` are allowed
- `INFs / NANs` are not allowed for pixels inside the viewport and denoising range
- `INFs` can be used in `IN_VIEWZ`, but not recommended
## INTERACTION WITH FRAME GENERATION TECHNIQUES
Frame generation (FG) techniques boost FPS by interpolating between 2 last available frames. *NRD* works better when frame rate increases, because it gets more data per second. It's not the case for FG, because all rendering pipeline underlying passes (like, denoising) continue to work on the original non-boosted framerate. `GetMaxAccumulatedFrameNum` helper should get a real FPS, not a fake one.
Expand Down Expand Up @@ -708,7 +708,7 @@ Hair strands tangent vectors *can't* be used as "normals guide" for *NRD* due to
**[NRD]** When upgrading to the latest version keep an eye on `ResourceType` enumeration. The order of the input slots can be changed or something can be added, you need to adjust the inputs accordingly to match the mapping. Or use *NRD integration* to simplify the process.
**[NRD]** All pixels in floating point textures should be INF / NAN free to avoid propagation, because such values are used in weight calculations and accumulation of a weighted sum. Functions `XXX_FrontEnd_PackRadianceAndHitDist` perform optional NAN / INF clearing of the input signal. There is a boolean to skip these checks.
**[NRD]** Functions `XXX_FrontEnd_PackRadianceAndHitDist` perform optional `NAN/INF` clearing of the input signal. There is a boolean to skip these checks.
**[NRD]** All denoisers work with positive RGB inputs (some denoisers can change color space in *front end* functions). For better image quality, HDR color inputs need to be in a sane range [0; 250], because the internal pipeline uses FP16 and *RELAX* tracks second moments of the input signal, i.e. `x^2` must fit into FP16 range. If the color input is in a wider range, any form of non-aggressive color compression can be applied (linear scaling, pow-based or log-based methods). *REBLUR* supports wider HDR ranges, because it doesn't track second moments. Passing pre-exposured colors (i.e. `color * exposure`) is not recommended, because a significant momentary change in exposure is hard to react to in this case.
Expand Down
2 changes: 1 addition & 1 deletion Resources/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ Versioning rules:

#define VERSION_MAJOR 4
#define VERSION_MINOR 11
#define VERSION_BUILD 3
#define VERSION_BUILD 4

#define VERSION_STRING STR(VERSION_MAJOR.VERSION_MINOR.VERSION_BUILD encoding=NRD_NORMAL_ENCODING.NRD_ROUGHNESS_ENCODING)
3 changes: 2 additions & 1 deletion Shaders/Include/Common.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ float4 GetBlurKernelRotation( compiletime const uint mode, uint2 pixelPos, float

float IsInScreenNearest( float2 uv )
{
return float( all( uv >= 0.0 ) && all( uv < 1.0 ) );
return float( all( uv > 0.0 ) && all( uv < 1.0 ) );
}

// x y
Expand All @@ -296,6 +296,7 @@ float4 IsInScreenBilinear( float2 footprintOrigin, float2 rectSize )
float2 ApplyCheckerboardShift( float2 pos, uint mode, uint counter, uint frameIndex )
{
// IMPORTANT: "pos" must be snapped to the pixel center
pos += 16384.0; // apply pattern-neutral bias, to make "pos" non-negative
uint checkerboard = Sequence::CheckerBoard( uint2( pos ), frameIndex );
float shift = ( ( counter & 0x1 ) == 0 ) ? -1.0 : 1.0;

Expand Down
40 changes: 30 additions & 10 deletions Shaders/Include/NRD.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,36 @@ NOISY INPUTS:
//=================================================================================================================================

#ifdef NRD_GLSL
#define float4 vec4
#define float3 vec3
#define float2 vec2
#define float2x2 mat2x2
#define float2x3 mat2x3
#define float3x3 mat3x3
#define rsqrt inversesqrt
#define saturate( x ) clamp( x, 0.0, 1.0 )
#define lerp mix
#define mul( x, y ) ( x * y )
#ifndef float4
#define float4 vec4
#endif
#ifndef float3
#define float3 vec3
#endif
#ifndef float2
#define float2 vec2
#endif
#ifndef float2x2
#define float2x2 mat2x2
#endif
#ifndef float2x3
#define float2x3 mat2x3
#endif
#ifndef float3x3
#define float3x3 mat3x3
#endif
#ifndef rsqrt
#define rsqrt inversesqrt
#endif
#ifndef saturate
#define saturate( x ) clamp( x, 0.0, 1.0 )
#endif
#ifndef lerp
#define lerp mix
#endif
#ifndef mul
#define mul( x, y ) ( x * y )
#endif
#endif

//=================================================================================================================================
Expand Down
6 changes: 4 additions & 2 deletions Shaders/Include/REBLUR_Common_DiffuseSpatialFilter.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,16 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#endif

// Snap to the pixel center!
uv = ( floor( uv * gRectSize ) + 0.5 ) * gRectSizeInv;
uv = floor( uv * gRectSize ) + 0.5;

// Apply checkerboard shift
#if( REBLUR_SPATIAL_MODE == REBLUR_PRE_BLUR )
uv = ApplyCheckerboardShift( uv * gRectSize, gDiffCheckerboard, n, gFrameIndex ) * gRectSizeInv;
uv = ApplyCheckerboardShift( uv, gDiffCheckerboard, n, gFrameIndex );
#endif

// Texture coordinates
uv *= gRectSizeInv;

float2 uvScaled = ClampUvToViewport( uv );
float2 checkerboardUvScaled = uvScaled;
#if( REBLUR_SPATIAL_MODE == REBLUR_PRE_BLUR )
Expand Down
6 changes: 4 additions & 2 deletions Shaders/Include/REBLUR_Common_SpecularSpatialFilter.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,16 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#endif

// Snap to the pixel center!
uv = ( floor( uv * gRectSize ) + 0.5 ) * gRectSizeInv;
uv = floor( uv * gRectSize ) + 0.5;

// Apply checkerboard shift
#if( REBLUR_SPATIAL_MODE == REBLUR_PRE_BLUR )
uv = ApplyCheckerboardShift( uv * gRectSize, gSpecCheckerboard, n, gFrameIndex ) * gRectSizeInv;
uv = ApplyCheckerboardShift( uv, gSpecCheckerboard, n, gFrameIndex );
#endif

// Texture coordinates
uv *= gRectSizeInv;

float2 uvScaled = ClampUvToViewport( uv );
float2 checkerboardUvScaled = uvScaled;
#if( REBLUR_SPATIAL_MODE == REBLUR_PRE_BLUR )
Expand Down
1 change: 1 addition & 0 deletions Shaders/Include/REBLUR_Config.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
NRD_CONSTANT( float, gMinRectDimMulUnproject ) \
NRD_CONSTANT( float, gUsePrepassNotOnlyForSpecularMotionEstimation ) \
NRD_CONSTANT( float, gSplitScreen ) \
NRD_CONSTANT( float, gSplitScreenPrev ) \
NRD_CONSTANT( float, gCheckerboardResolveAccumSpeed ) \
NRD_CONSTANT( float, gViewZScale ) \
NRD_CONSTANT( float, gFireflySuppressorMinRelativeScale ) \
Expand Down
6 changes: 3 additions & 3 deletions Shaders/Include/REBLUR_TemporalStabilization.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ NRD_EXPORT void NRD_CS_MAIN( NRD_CS_MAIN_ARGS )
float diffHistoryWeight = diffTemporalAccumulationParams.x;
diffHistoryWeight *= diffAntilag; // this is important
diffHistoryWeight *= float( pixelUv.x >= gSplitScreen );
diffHistoryWeight *= float( smbPixelUv.x >= gSplitScreen );
diffHistoryWeight *= float( smbPixelUv.x >= gSplitScreenPrev );

smbDiffHistory = Color::Clamp( diffM1, diffSigma * diffTemporalAccumulationParams.y, smbDiffHistory );

Expand Down Expand Up @@ -407,8 +407,8 @@ NRD_EXPORT void NRD_CS_MAIN( NRD_CS_MAIN_ARGS )
float specHistoryWeight = specTemporalAccumulationParams.x;
specHistoryWeight *= specAntilag; // this is important
specHistoryWeight *= float( pixelUv.x >= gSplitScreen );
specHistoryWeight *= virtualHistoryAmount != 1.0 ? float( smbPixelUv.x >= gSplitScreen ) : 1.0;
specHistoryWeight *= virtualHistoryAmount != 0.0 ? float( vmbPixelUv.x >= gSplitScreen ) : 1.0;
specHistoryWeight *= virtualHistoryAmount != 1.0 ? float( smbPixelUv.x >= gSplitScreenPrev ) : 1.0;
specHistoryWeight *= virtualHistoryAmount != 0.0 ? float( vmbPixelUv.x >= gSplitScreenPrev ) : 1.0;

float responsiveFactor = RemapRoughnessToResponsiveFactor( roughness );
float smc = GetSpecMagicCurve( roughness );
Expand Down
Loading

0 comments on commit c559760

Please sign in to comment.