Skip to content

Commit

Permalink
v4.8.0:
Browse files Browse the repository at this point in the history
HIGHLIGHTS:
- NRD: improved FP16 viewZ support
- SIGMA: made more friendly to per light shadow denoising (multi-light scenario)
- removed unused (non-denoisers) "SPECULAR_REFLECTION_MV" & "SPECULAR_DELTA_MV"

DETAILS:
- NRD: exposed "CommonSettings::viewZScale", which should help to improve FP16 support
- SIGMA: "IN_SHADOWDATA" => "IN_PENUMBRA", "IN_SHADOW_TRANSLUCENCY" => "IN_TRANSLUCENCY"
- SIGMA: massaged front-end functions
- SIGMA: switched to use common "IN_VIEWZ" input instead of a custom one (it eliminates a need to clone ViewZ in case of multiple lights)
- REBLUR: minor tweaks
- SPECULAR_REFLECTION_MV: deprecated and removed
- SPECULAR_DELTA_MV: deprecated and removed
- updated docs
  • Loading branch information
dzhdanNV committed May 9, 2024
1 parent f20158d commit 8d3c245
Show file tree
Hide file tree
Showing 58 changed files with 330 additions and 970 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ if (NOT NRD_DISABLE_SHADER_COMPILATION)

if (NRD_EMBEDS_SPIRV_SHADERS)
set (SHADERMAKE_COMMANDS ${SHADERMAKE_COMMANDS} COMMAND ShaderMake -p SPIRV --compiler "${DXC_SPIRV_PATH}" ${SHADERMAKE_GENERAL_ARGS}
-D VULKAN
--sRegShift 100
--tRegShift 200
--bRegShift 300
Expand Down
2 changes: 1 addition & 1 deletion External/MathLib
Submodule MathLib updated 1 files
+1 −1 External/sse2neon
4 changes: 2 additions & 2 deletions Include/NRD.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#include <cstddef>

#define NRD_VERSION_MAJOR 4
#define NRD_VERSION_MINOR 7
#define NRD_VERSION_MINOR 8
#define NRD_VERSION_BUILD 0
#define NRD_VERSION_DATE "17 April 2024"
#define NRD_VERSION_DATE "9 May 2024"

#if defined(_MSC_VER)
#define NRD_CALL __fastcall
Expand Down
76 changes: 28 additions & 48 deletions Include/NRDDescs.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#pragma once

#define NRD_DESCS_VERSION_MAJOR 4
#define NRD_DESCS_VERSION_MINOR 7
#define NRD_DESCS_VERSION_MINOR 8

static_assert(NRD_VERSION_MAJOR == NRD_DESCS_VERSION_MAJOR && NRD_VERSION_MINOR == NRD_DESCS_VERSION_MINOR, "Please, update all NRD SDK files");

Expand Down Expand Up @@ -92,10 +92,11 @@ namespace nrd
IN_SPEC_SH0,
IN_SPEC_SH1,

// Shadow data and optional translucency (RG16f+ and RGBA8+ for translucency)
// SIGMA: use "SIGMA_FrontEnd_PackShadow" for encoding
IN_SHADOWDATA,
IN_SHADOW_TRANSLUCENCY,
// Penumbra and optional translucency (R16f+ and RGBA8+ for translucency)
// SIGMA: use "SIGMA_FrontEnd_PackPenumbra" for penumbra properties encoding
// SIGMA: use "SIGMA_FrontEnd_PackTranslucency" for translucency encoding
IN_PENUMBRA,
IN_TRANSLUCENCY,

// Some signal (R8+)
IN_SIGNAL,
Expand All @@ -108,44 +109,37 @@ namespace nrd
// OUTPUTS
//=============================================================================================================================

// IMPORTANT: These textures can be potentially used as history buffers!
// IMPORTANT: Most of denoisers do not write into output pixels outside of "CommonSettings::denoisingRange"!

// Radiance and hit distance
// REBLUR: use "REBLUR_BackEnd_UnpackRadianceAndNormHitDist" for decoding (RGBA16f+)
// RELAX: use "RELAX_BackEnd_UnpackRadiance" for decoding (R11G11B10f+)
OUT_DIFF_RADIANCE_HITDIST,
OUT_SPEC_RADIANCE_HITDIST,
OUT_DIFF_RADIANCE_HITDIST, // IMPORTANT: used as history if "stabilizationStrength != 0"
OUT_SPEC_RADIANCE_HITDIST, // IMPORTANT: used as history if "stabilizationStrength != 0"

// SH data
// REBLUR: use "REBLUR_BackEnd_UnpackSh" for decoding (2x RGBA16f+)
// RELAX: use "RELAX_BackEnd_UnpackSh" for decoding (2x RGBA16f+)
OUT_DIFF_SH0,
OUT_DIFF_SH1,
OUT_SPEC_SH0,
OUT_SPEC_SH1,
OUT_DIFF_SH0, // IMPORTANT: used as history if "stabilizationStrength != 0"
OUT_DIFF_SH1, // IMPORTANT: used as history if "stabilizationStrength != 0"
OUT_SPEC_SH0, // IMPORTANT: used as history if "stabilizationStrength != 0"
OUT_SPEC_SH1, // IMPORTANT: used as history if "stabilizationStrength != 0"

// Normalized hit distance (R8+)
OUT_DIFF_HITDIST,
OUT_SPEC_HITDIST,

// Bent normal and normalized hit distance (RGBA8+)
// REBLUR: use "REBLUR_BackEnd_UnpackDirectionalOcclusion" for decoding
OUT_DIFF_DIRECTION_HITDIST,
OUT_DIFF_DIRECTION_HITDIST, // IMPORTANT: used as history if "stabilizationStrength != 0"

// Shadow and optional transcluceny (R8+ or RGBA8+)
// SIGMA: use "SIGMA_BackEnd_UnpackShadow" for decoding
OUT_SHADOW_TRANSLUCENCY,
OUT_SHADOW_TRANSLUCENCY, // IMPORTANT: used as history if "stabilizationStrength != 0"

// Denoised signal (R8+)
OUT_SIGNAL,

// 2D screen-space specular motion (RG16f+), MV = previous - current
OUT_REFLECTION_MV,

// 2D screen-space refraction motion (RG16f+), MV = previous - current
OUT_DELTA_MV,

// (Optional) Debug output (RGBA8+), .w = transparency
// Used if "CommonSettings::enableValidation = true"
OUT_VALIDATION,
Expand All @@ -168,10 +162,8 @@ namespace nrd
/*
IMPORTANT: IN_MV, IN_NORMAL_ROUGHNESS, IN_VIEWZ are used by any denoiser
These denoisers DON'T use:
SIGMA_SHADOW - IN_VIEWZ
SIGMA_SHADOW_TRANSLUCENCY - IN_VIEWZ
SIGMA_SHADOW & SIGMA_SHADOW_TRANSLUCENCY - IN_MV, if "stabilizationStrength = 0"
REFERENCE - IN_MV, IN_NORMAL_ROUGHNESS, IN_VIEWZ
SPECULAR_DELTA_MV - IN_NORMAL_ROUGHNESS, IN_VIEWZ
*/

// =============================================================================================================================
Expand Down Expand Up @@ -225,18 +217,6 @@ namespace nrd
// OUTPUTS - OUT_DIFF_DIRECTION_HITDIST
REBLUR_DIFFUSE_DIRECTIONAL_OCCLUSION,

// =============================================================================================================================
// SIGMA
// =============================================================================================================================

// INPUTS - IN_SHADOWDATA, OUT_SHADOW_TRANSLUCENCY (used as history)
// OUTPUTS - OUT_SHADOW_TRANSLUCENCY
SIGMA_SHADOW,

// INPUTS - IN_SHADOWDATA, IN_SHADOW_TRANSLUCENCY, OUT_SHADOW_TRANSLUCENCY (used as history)
// OUTPUTS - OUT_SHADOW_TRANSLUCENCY
SIGMA_SHADOW_TRANSLUCENCY,

// =============================================================================================================================
// RELAX
// =============================================================================================================================
Expand Down Expand Up @@ -272,24 +252,24 @@ namespace nrd
RELAX_DIFFUSE_SPECULAR_SH,

// =============================================================================================================================
// REFERENCE
// SIGMA
// =============================================================================================================================

// INPUTS - IN_SIGNAL
// OUTPUTS - OUT_SIGNAL
REFERENCE,
// INPUTS - IN_PENUMBRA, OUT_SHADOW_TRANSLUCENCY
// OUTPUTS - OUT_SHADOW_TRANSLUCENCY
SIGMA_SHADOW,

// INPUTS - IN_PENUMBRA, IN_TRANSLUCENCY, OUT_SHADOW_TRANSLUCENCY
// OUTPUTS - OUT_SHADOW_TRANSLUCENCY
SIGMA_SHADOW_TRANSLUCENCY,

// =============================================================================================================================
// MOTION VECTORS
// REFERENCE
// =============================================================================================================================

// INPUTS - IN_SPEC_HITDIST
// OUTPUTS - OUT_REFLECTION_MV
SPECULAR_REFLECTION_MV,

// INPUTS - IN_DELTA_PRIMARY_POS, IN_DELTA_SECONDARY_POS
// OUTPUT - OUT_DELTA_MV
SPECULAR_DELTA_MV,
// INPUTS - IN_SIGNAL
// OUTPUTS - OUT_SIGNAL
REFERENCE,

MAX_NUM
};
Expand Down Expand Up @@ -479,7 +459,7 @@ namespace nrd
ComputeShaderDesc computeShaderSPIRV;
const char* shaderFileName;
const char* shaderEntryPointName;
const ResourceRangeDesc* resourceRanges; // up to 2 ranges: "TEXTURE" inputs (optional) and "TEXTURE_STORAGE" outputs
const ResourceRangeDesc* resourceRanges; // up to 2 ranges: "TEXTURE" inputs (optional) and "TEXTURE_STORAGE" outputs
uint32_t resourceRangesNum;

// Hint that pipeline has a constant buffer with shared parameters from "InstanceDesc"
Expand Down
47 changes: 18 additions & 29 deletions Include/NRDSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license agreement from NVIDIA CORPORATION is strictly prohibited.
#pragma once

#define NRD_SETTINGS_VERSION_MAJOR 4
#define NRD_SETTINGS_VERSION_MINOR 7
#define NRD_SETTINGS_VERSION_MINOR 8

static_assert(NRD_VERSION_MAJOR == NRD_SETTINGS_VERSION_MAJOR && NRD_VERSION_MINOR == NRD_SETTINGS_VERSION_MINOR, "Please, update all NRD SDK files");

Expand Down Expand Up @@ -109,6 +109,9 @@ namespace nrd
uint16_t rectSize[2] = {};
uint16_t rectSizePrev[2] = {};

// (>0) - viewZ = IN_VIEWZ * viewZScale (mostly for FP16 viewZ)
float viewZScale = 1.0f;

// (ms) - user provided if > 0, otherwise - tracked internally
float timeDeltaBetweenFrames = 0.0f;

Expand Down Expand Up @@ -257,22 +260,6 @@ namespace nrd
bool usePrepassOnlyForSpecularMotionEstimation = false;
};

// SIGMA

struct SigmaSettings
{
// Direction to the light source
// IMPORTANT: it is needed only for directional light sources (sun)
float lightDirection[3] = {0.0f, 0.0f, 0.0f};

// (normalized %) - represents maximum allowed deviation from local tangent plane
float planeDistanceSensitivity = 0.005f;

// (normalized %) - stabilizes output, more stabilization improves antilag (clean signals can use lower values)
// 0 - disables the stabilization pass and makes denoising spatial only (no history)
float stabilizationStrength = 1.0f;
};

// RELAX

const uint32_t RELAX_MAX_HISTORY_FRAME_NUM = 255;
Expand Down Expand Up @@ -379,25 +366,27 @@ namespace nrd
bool enableMaterialTestForSpecular = false;
};

// REFERENCE
// SIGMA

struct ReferenceSettings
struct SigmaSettings
{
// (>= 0) - maximum number of linearly accumulated frames ( = FPS * "time of accumulation")
uint32_t maxAccumulatedFrameNum = 1024;
};
// Direction to the light source
// IMPORTANT: it is needed only for directional light sources (sun)
float lightDirection[3] = {0.0f, 0.0f, 0.0f};

// SPECULAR_REFLECTION_MV
// (normalized %) - represents maximum allowed deviation from local tangent plane
float planeDistanceSensitivity = 0.005f;

struct SpecularReflectionMvSettings
{
float unused;
// (normalized %) - stabilizes output, more stabilization improves antilag (clean signals can use lower values)
// 0 - disables the stabilization pass and makes denoising spatial only (no history)
float stabilizationStrength = 1.0f;
};

// SPECULAR_DELTA_MV
// REFERENCE

struct SpecularDeltaMvSettings
struct ReferenceSettings
{
float unused;
// (>= 0) - maximum number of linearly accumulated frames ( = FPS * "time of accumulation")
uint32_t maxAccumulatedFrameNum = 1024;
};
}
41 changes: 24 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# NVIDIA REAL-TIME DENOISERS v4.7.0 (NRD)
# NVIDIA REAL-TIME DENOISERS v4.8.0 (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 All @@ -18,7 +18,7 @@ For quick starting see *[NRD sample](https://github.com/NVIDIAGameWorks/NRDSampl
Performance on RTX 4080 @ 1440p (native resolution, default denoiser settings):
- `REBLUR_DIFFUSE_SPECULAR` - 2.45 ms
- `RELAX_DIFFUSE_SPECULAR` - 2.90 ms
- `SIGMA_SHADOW` - 0.30 ms (0.24 mns if temporal stabilization is off)
- `SIGMA_SHADOW` - 0.30 ms (0.24 ms if temporal stabilization is off)
- `SIGMA_SHADOW_TRANSLUCENCY` - 0.40 ms (0.30 ms if temporal stabilization is off)

Supported signal types:
Expand Down Expand Up @@ -309,8 +309,8 @@ The *Persistent* column (matches *NRD Permanent pool*) indicates how much of the
| | REBLUR_DIFFUSE_SPECULAR_OCCLUSION | 72.12 | 38.12 | 34.00 |
| | REBLUR_DIFFUSE_SPECULAR_SH | 270.31 | 105.62 | 164.69 |
| | REBLUR_DIFFUSE_DIRECTIONAL_OCCLUSION | 86.69 | 42.25 | 44.44 |
| | SIGMA_SHADOW | 23.38 | 0.00 | 23.38 |
| | SIGMA_SHADOW_TRANSLUCENCY | 42.31 | 0.00 | 42.31 |
| | SIGMA_SHADOW | 15.00 | 0.00 | 15.00 |
| | SIGMA_SHADOW_TRANSLUCENCY | 33.94 | 0.00 | 33.94 |
| | RELAX_DIFFUSE | 99.25 | 63.31 | 35.94 |
| | RELAX_DIFFUSE_SH | 158.31 | 88.62 | 69.69 |
| | RELAX_SPECULAR | 101.44 | 63.38 | 38.06 |
Expand All @@ -329,8 +329,8 @@ The *Persistent* column (matches *NRD Permanent pool*) indicates how much of the
| | REBLUR_DIFFUSE_SPECULAR_OCCLUSION | 127.56 | 67.50 | 60.06 |
| | REBLUR_DIFFUSE_SPECULAR_SH | 480.06 | 187.50 | 292.56 |
| | REBLUR_DIFFUSE_DIRECTIONAL_OCCLUSION | 153.81 | 75.00 | 78.81 |
| | SIGMA_SHADOW | 41.38 | 0.00 | 41.38 |
| | SIGMA_SHADOW_TRANSLUCENCY | 75.12 | 0.00 | 75.12 |
| | SIGMA_SHADOW | 26.38 | 0.00 | 26.38 |
| | SIGMA_SHADOW_TRANSLUCENCY | 60.12 | 0.00 | 60.12 |
| | RELAX_DIFFUSE | 176.31 | 112.50 | 63.81 |
| | RELAX_DIFFUSE_SH | 281.31 | 157.50 | 123.81 |
| | RELAX_SPECULAR | 180.06 | 112.50 | 67.56 |
Expand All @@ -349,8 +349,8 @@ The *Persistent* column (matches *NRD Permanent pool*) indicates how much of the
| | REBLUR_DIFFUSE_SPECULAR_OCCLUSION | 271.00 | 143.44 | 127.56 |
| | REBLUR_DIFFUSE_SPECULAR_SH | 1020.06 | 398.44 | 621.62 |
| | REBLUR_DIFFUSE_DIRECTIONAL_OCCLUSION | 326.81 | 159.38 | 167.44 |
| | SIGMA_SHADOW | 88.06 | 0.00 | 88.06 |
| | SIGMA_SHADOW_TRANSLUCENCY | 159.69 | 0.00 | 159.69 |
| | SIGMA_SHADOW | 56.19 | 0.00 | 56.19 |
| | SIGMA_SHADOW_TRANSLUCENCY | 127.81 | 0.00 | 127.81 |
| | RELAX_DIFFUSE | 374.69 | 239.12 | 135.56 |
| | RELAX_DIFFUSE_SH | 597.81 | 334.75 | 263.06 |
| | RELAX_SPECULAR | 382.69 | 239.12 | 143.56 |
Expand Down Expand Up @@ -749,7 +749,11 @@ maxAccumulatedFrameNum > maxFastAccumulatedFrameNum > historyFixFrameNum
**[SIGMA]** Using "blue" noise can help to avoid shadow shimmering. It works best if the pattern is static on the screen.
**[SIGMA]** *SIGMA_TRANSLUCENT_SHADOW* can be used for shadow denoising from multiple light sources:
**[SIGMA]** *SIGMA* can be used for multi-light shadow denoising if applied "per light". `SigmaSettings::stabilizationStrength` can be set to `0` to disable temporal history. It provides the followinmg benefits:
- light count independent memory usage
- no need to manage history buffers for lights
**[SIGMA]** In theory *SIGMA_TRANSLUCENT_SHADOW* can be used as a "single-pass" shadow denoiser for shadows from multiple light sources:
*L[i]* - unshadowed analytical lighting from a single light source (**not noisy**)<br/>
*S[i]* - stochastically sampled light visibility for *L[i]* (**noisy**)<br/>
Expand All @@ -766,7 +770,9 @@ Or:<br/>
Input data preparation example:
```cpp
float3 Lsum = 0;
float2x3 multiLightShadowData = SIGMA_FrontEnd_MultiLightStart( );
float3 LSsum = 0.0;
float Wsum = 0.0;
float Psum = 0.0;
for( uint i = 0; i < N; i++ )
{
Expand All @@ -775,15 +781,20 @@ for( uint i = 0; i < N; i++ )
// "distanceToOccluder" should respect rules described in NRD.hlsli in "INPUT PARAMETERS" section
float distanceToOccluder = SampleShadow( i );
float shadow = !IsOccluded( distanceToOccluder );
LSsum += L * shadow;
// The weight should be zero if a pixel is not in the penumbra, but it is not trivial to compute...
float weight = ...;
weight *= Luminance( L );
Wsum += weight;
SIGMA_FrontEnd_MultiLightUpdate( L, distanceToOccluder, tanOfLightAngularRadius, weight, multiLightShadowData );
float penumbraRadius = SIGMA_FrontEnd_PackPenumbra( ... ).x;
Psum += penumbraRadius * weight;
}
float4 shadowTranslucency;
float2 shadowData = SIGMA_FrontEnd_MultiLightEnd( viewZ, multiLightShadowData, Lsum, shadowTranslucency );
float3 translucency = LSsum / max( Lsum, NRD_EPS );
float penumbraRadius = Psum / max( Wsum, NRD_EPS );
```

After denoising the final result can be computed as:
Expand All @@ -797,7 +808,3 @@ Is this a biased solution? If spatial filtering is off - no, because we just reo
- if shadows overlap, a separate pass is needed to analyze noisy input and classify pixels as *umbra* - *penumbra* (and optionally *empty space*). Raster shadow maps can be used for this if available
- it is not recommended to mix 1 cd and 100000 cd lights, since FP32 texture will be needed for a weighted sum.
In this case, it's better to process the sun and other bright light sources separately.

**[SIGMA]** *SIGMA* can be used for multi-light shadow denoising if applied "per light". `SigmaSettings::stabilizationStrength` can be set to `0` to disable temporal history. It provides the followinmg benefits:
- light count independent memory usage
- no need to manage history buffers for lights
2 changes: 1 addition & 1 deletion Resources/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Versioning rules:
*/

#define VERSION_MAJOR 4
#define VERSION_MINOR 7
#define VERSION_MINOR 8
#define VERSION_BUILD 0

#define VERSION_STRING STR(VERSION_MAJOR.VERSION_MINOR.VERSION_BUILD encoding=NRD_NORMAL_ENCODING.NRD_ROUGHNESS_ENCODING)
2 changes: 0 additions & 2 deletions Shaders.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,3 @@ SIGMA_Shadow_PostBlur.cs.hlsl -T cs
SIGMA_Shadow_SmoothTiles.cs.hlsl -T cs
SIGMA_Shadow_SplitScreen.cs.hlsl -T cs
SIGMA_Shadow_TemporalStabilization.cs.hlsl -T cs
SpecularDeltaMv_Compute.cs.hlsl -T cs
SpecularReflectionMv_Compute.cs.hlsl -T cs
7 changes: 6 additions & 1 deletion Shaders/Include/Common.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Usage:
PrintfAt( "a = %f, b = %f, c = %u", a, b, c );
#endif
*/
#if( defined( __hlsl_dx_compiler ) && defined( VULKAN ) )
#if( defined( __hlsl_dx_compiler ) && defined( __spirv__ ) )
#define PRINTF_AVAILABLE
#define PrintfAt(...) \
if( uint( pixelPos.x ) == gPrintfAt.x && uint( pixelPos.y ) == gPrintfAt.y ) \
Expand Down Expand Up @@ -198,6 +198,11 @@ static const float3 g_Special8[ 8 ] =
#define CompareMaterials( m0, m, mask ) 1.0
#endif

float UnpackViewZ( float z )
{
return abs( z * gViewZScale );
}

float PixelRadiusToWorld( float unproject, float orthoMode, float pixelRadius, float viewZ )
{
return pixelRadius * unproject * lerp( viewZ, 1.0, abs( orthoMode ) );
Expand Down
Loading

0 comments on commit 8d3c245

Please sign in to comment.