From bec6b387c06064afb0cd55b42cc028c3783fc9ff Mon Sep 17 00:00:00 2001 From: SomeNvidiaGuy <107078408+SomeNvidiaGuy@users.noreply.github.com> Date: Sat, 8 Feb 2025 18:20:57 -0800 Subject: [PATCH 01/12] Updated links in README.md --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 66b1508..6beeee2 100644 --- a/README.md +++ b/README.md @@ -9,43 +9,43 @@ Version 2.3.0. **RTX** **D**ynamic **I**llumination is a framework that originally facilitated implementation of efficient direct light sampling in real-time renderers. It is based on the **ReSTIR** algorithm published in the paper called "Spatiotemporal reservoir resampling for real-time ray tracing with dynamic direct lighting" by B. Bitterli et al. -Starting with version 2.0, RTXDI also includes **ReSTIR GI** functionality, which allows applications to apply importance resampling to indirect illumination rendered using path tracing. For more information about the indirect illumination algorithm, see the paper called "ReSTIR GI: Path Resampling for Real-Time Path Tracing" by Y. Ouyang et al. The feature is described in more detail in [this document](doc/RestirGI.md). +Starting with version 2.0, RTXDI also includes **ReSTIR GI** functionality, which allows applications to apply importance resampling to indirect illumination rendered using path tracing. For more information about the indirect illumination algorithm, see the paper called "ReSTIR GI: Path Resampling for Real-Time Path Tracing" by Y. Ouyang et al. The feature is described in more detail in [this document](Doc/RestirGI.md). For more information about RTXDI, see the [NVIDIA Developer Page](https://developer.nvidia.com/rtxdi). ## Package Contents -[`Libraries/Rtxdi`](https://github.com/NVIDIAGameWorks/rtxdi-runtime) is a submodule that contains the integrable runtime sources that are meant to be included in the application build: +[`Libraries/Rtxdi`](https://github.com/NVIDIA-RTX/RTXDI-Library) is a submodule that contains the integrable runtime sources that are meant to be included in the application build: -- [`Rtxdi/Include/Rtxdi`](https://github.com/NVIDIAGameWorks/rtxdi-runtime/tree/main/include/rtxdi) has the include files, both for host code and for shaders. -- [`Rtxdi/Include/Rtxdi/DI/`](https://github.com/NVIDIAGameWorks/rtxdi-runtime/tree/main/Include/Rtxdi/DI/) and [`Rtxdi/Include/Rtxdi/GI/`](https://github.com/NVIDIAGameWorks/rtxdi-runtime/tree/main/Include/Rtxdi/GI/) are the main shader include folders that contain the resampling implementations for their respective algorithms. -- [`Rtxdi/Source`](https://github.com/NVIDIAGameWorks/rtxdi-runtime/tree/main/Source) has the host code with various utility functions for setting up the parameters and resources for resampling. +- [`Rtxdi/Include/Rtxdi`](https://github.com/NVIDIA-RTX/RTXDI-Library/tree/main/Include/Rtxdi) has the include files, both for host code and for shaders. +- [`Rtxdi/Include/Rtxdi/DI/`](https://github.com/NVIDIA-RTX/RTXDI-Library/tree/main/Include/Rtxdi/DI) and [`Rtxdi/Include/Rtxdi/GI/`](https://github.com/NVIDIA-RTX/RTXDI-Library/tree/main/Include/Rtxdi/GI) are the main shader include folders that contain the resampling implementations for their respective algorithms. +- [`Rtxdi/Source`](https://github.com/NVIDIA-RTX/RTXDI-Library/tree/main/Source) has the host code with various utility functions for setting up the parameters and resources for resampling. [`Samples`](Samples) contains two sample projects, [`MinimalSample`](Samples/MinimalSample) and [`FullSample`](Samples/FullSample). The [`MinimalSample/Source`](Samples/MinimalSample/Source) project implements ReSTIR DI in a single combined pass to show a minimum viable implementation. The [`FullSample/Source`](Samples/FullSample/Source) project implements ReSTIR DI in several passes integrated into a broader rendering pipeline to show a more standard implementation. The shaders for each project live in their respective [`MinimalSample/Shaders`](Samples/MinimalSample/Shaders) and [`FullSample/Shaders`](Samples/FullSample/Shaders) folders. [`External`](External) contains project dependencies both from Nvidia and third parties: -- [`External/donut`](External/donut) is a Git submodule structure with the ["Donut" rendering framework](https://github.com/NVIDIAGameWorks/donut) used to build the sample apps. +- `External/donut` is a Git submodule structure with the ["Donut" rendering framework](https://github.com/NVIDIA-RTX/Donut) used to build the sample apps. -- [`External/NRD`](External/NRD) is a Git submodule with the ["NRD" denoiser library](https://github.com/NVIDIAGameWorks/RayTracingDenoiser). +- `External/NRD` is a Git submodule with the ["NRD" denoiser library](https://github.com/NVIDIA-RTX/NRD). -- [`External/DLSS`](External/DLSS) is a Git submodule with the [Deep Learning Super-Sampling SDK](https://github.com/NVIDIA/DLSS). +- `External/DLSS` is a Git submodule with the [Deep Learning Super-Sampling SDK](https://github.com/NVIDIA/DLSS). - `External/dxc` is a recent version of DirectX Shader Compiler. However, unlike the other dependencies, it is not a Git submodule but is instead fetched by CMake at project configuration time. -[`Assets/Media`](https://github.com/NVIDIAGameWorks/rtxdi-assets) is a Git submodule containing the [RTXDI SDK Sample Assets](https://github.com/NVIDIAGameWorks/rtxdi-assets). +`Assets/Media` is a Git submodule containing the [RTXDI SDK Sample Assets](https://github.com/NVIDIA-RTX/RTXDI-Assets). ## Building and Running the Sample Apps -**Note** that because the [`rtxdi-assets`](https://github.com/NVIDIAGameWorks/rtxdi-assets) submodule that is cloned into `Assets/Media` uses LFS, cloning it without [LFS](https://git-lfs.com) installed will result in files containing LFS pointers instead of the actual assets. +**Note** that because the [`rtxdi-assets`](https://github.com/NVIDIA-RTX/RTXDI-Assets) submodule that is cloned into `Assets/Media` uses LFS, cloning it without [LFS](https://git-lfs.com) installed will result in files containing LFS pointers instead of the actual assets. ### Windows 1. Install LFS support by following the instructions on [git-lfs.com](https://git-lfs.com) 2. Clone the repository with all submodules: - - `git clone --recursive https://github.com/NVIDIAGameWorks/RTXDI.git` + - `git clone --recursive https://github.com/NVIDIA-RTX/RTXDI.git` If the clone was made non-recursively and the submodules are missing, clone them separately: @@ -74,7 +74,7 @@ For more information about RTXDI, see the [NVIDIA Developer Page](https://develo - `sudo apt install git-lfs` 3. Clone the repository with all submodules: - - `git clone --recursive https://github.com/NVIDIAGameWorks/RTXDI.git` + - `git clone --recursive https://github.com/NVIDIA-RTX/RTXDI.git` If the clone was made non-recursively and the submodules are missing, clone them separately: @@ -94,7 +94,7 @@ For more information about RTXDI, see the [NVIDIA Developer Page](https://develo ### Vulkan support -The RTXDI sample applications can run using D3D12 or Vulkan, which is achieved through the [NVRHI](https://github.com/NVIDIAGameWorks/nvrhi) rendering API abstraction layer and HLSL shader compilation to SPIR-V through DXC (DirectX Shader Compiler). We deliver a compatible version of DXC through packman. If you wish to use a different (e.g. newer) version of DXC, it can be obtained from [Microsoft/DirectXShaderCompiler](https://github.com/Microsoft/DirectXShaderCompiler) on GitHub. The path to a custom version of DXC can be configured using the `DXC_PATH` and `DXC_SPIRV_PATH` CMake variables. +The RTXDI sample applications can run using D3D12 or Vulkan, which is achieved through the [NVRHI](https://github.com/NVIDIA-RTX/NVRHI) rendering API abstraction layer and HLSL shader compilation to SPIR-V through DXC (DirectX Shader Compiler). We deliver a compatible version of DXC through packman. If you wish to use a different (e.g. newer) version of DXC, it can be obtained from [Microsoft/DirectXShaderCompiler](https://github.com/Microsoft/DirectXShaderCompiler) on GitHub. The path to a custom version of DXC can be configured using the `DXC_PATH` and `DXC_SPIRV_PATH` CMake variables. By default, the sample apps will run using D3D12 on Windows. To start them in Vulkan mode, add `--vk` to the command line. To compile the sample apps without Vulkan support, set the CMake variable `DONUT_WITH_VULKAN` to `OFF` and re-generate the project. @@ -102,4 +102,4 @@ To enable SPIV-V compileation tests, set the `GLSLANG_PATH` variable in CMake to ## Integration -See the [Integration Guide](doc/Integration.md). +See the [Integration Guide](Doc/Integration.md). From 04012e22e68e59a622c51a7773c5921223cefbc0 Mon Sep 17 00:00:00 2001 From: dzhdan Date: Mon, 24 Feb 2025 12:45:48 +0800 Subject: [PATCH 02/12] Code cleanup (no functional changes): - removed dummy defines - reduced code entropy around "WITH_NRD" macro --- Samples/FullSample/Shaders/CMakeLists.txt | 6 ++--- .../FullSample/Shaders/CompositingPass.hlsl | 5 ++-- .../DenoisingPasses/ComputeGradients.hlsl | 12 ++++------ .../LightingPasses/BrdfRayTracing.hlsl | 24 +++++++------------ .../LightingPasses/DI/FusedResampling.hlsl | 10 ++------ .../LightingPasses/DI/ShadeSamples.hlsl | 14 ++++------- .../LightingPasses/GI/FinalShading.hlsl | 18 +++++--------- .../ShadeSecondarySurfaces.hlsl | 10 ++------ .../LightingPasses/ShadingHelpers.hlsli | 12 ++++++---- 9 files changed, 40 insertions(+), 71 deletions(-) diff --git a/Samples/FullSample/Shaders/CMakeLists.txt b/Samples/FullSample/Shaders/CMakeLists.txt index ad93179..a2db48a 100644 --- a/Samples/FullSample/Shaders/CMakeLists.txt +++ b/Samples/FullSample/Shaders/CMakeLists.txt @@ -73,7 +73,7 @@ add_custom_target(${shaders_target} SOURCES ${shaders} Shaders.cfg) if(TARGET NRD) - set(NRD_OPTIONS -I "${CMAKE_CURRENT_SOURCE_DIR}/../../../external/NRD/Shaders/Include" -D WITH_NRD -D NRD_USE_OCT_NORMAL_ENCODING=0 -D NRD_USE_MATERIAL_ID=0) + set(NRD_OPTIONS -I "${CMAKE_CURRENT_SOURCE_DIR}/../../../external/NRD/Shaders/Include" -D WITH_NRD) else() set(NRD_OPTIONS --relaxedInclude NRD.hlsli) endif() @@ -87,7 +87,7 @@ set (OUTPUT_PATH_BASE "${CMAKE_BINARY_DIR}/bin/shaders/full-sample") endif() if (DONUT_WITH_DX12) - set(DX12_COMPILER_OPTIONS + set(DX12_COMPILER_OPTIONS --platform DXIL --shaderModel 6_5 --binaryBlob @@ -130,4 +130,4 @@ if (DONUT_WITH_VULKAN) endif() set_target_properties(${shaders_target} PROPERTIES FOLDER ${folder}) -set_source_files_properties(${shaders} PROPERTIES VS_TOOL_OVERRIDE "None") +set_source_files_properties(${shaders} PROPERTIES VS_TOOL_OVERRIDE "None") diff --git a/Samples/FullSample/Shaders/CompositingPass.hlsl b/Samples/FullSample/Shaders/CompositingPass.hlsl index 9972e79..85c7b20 100644 --- a/Samples/FullSample/Shaders/CompositingPass.hlsl +++ b/Samples/FullSample/Shaders/CompositingPass.hlsl @@ -15,7 +15,6 @@ #include "GBufferHelpers.hlsli" #ifdef WITH_NRD -#define NRD_HEADER_ONLY #include #include #endif @@ -71,7 +70,7 @@ void main(uint2 globalIdx : SV_DispatchThreadID) { denoised_diffuse = REBLUR_BackEnd_UnpackRadianceAndNormHitDist(denoised_diffuse); denoised_specular = REBLUR_BackEnd_UnpackRadianceAndNormHitDist(denoised_specular); - + diffuse_illumination = REBLUR_BackEnd_UnpackRadianceAndNormHitDist(diffuse_illumination); specular_illumination = REBLUR_BackEnd_UnpackRadianceAndNormHitDist(specular_illumination); } @@ -97,7 +96,7 @@ void main(uint2 globalIdx : SV_DispatchThreadID) compositedColor += emissive.rgb; } else - { + { RayDesc primaryRay = setupPrimaryRay(globalIdx, g_Const.view); if (g_Const.enableEnvironmentMap) diff --git a/Samples/FullSample/Shaders/DenoisingPasses/ComputeGradients.hlsl b/Samples/FullSample/Shaders/DenoisingPasses/ComputeGradients.hlsl index da891b1..fcbbe54 100644 --- a/Samples/FullSample/Shaders/DenoisingPasses/ComputeGradients.hlsl +++ b/Samples/FullSample/Shaders/DenoisingPasses/ComputeGradients.hlsl @@ -14,9 +14,7 @@ #include "Rtxdi/DI/Reservoir.hlsli" -#ifdef WITH_NRD #undef WITH_NRD -#endif #include "../LightingPasses/ShadingHelpers.hlsli" @@ -42,7 +40,7 @@ void RayGen() int2 selectedPixelPos = -1; int2 selectedPrevPixelPos = -1; float2 selectedDiffSpecLum = 0; - + // Iterate over all the pixels in the stratum, find one that is likely to produce // the brightest gradient. That means the pixel that has the brightest color coming // purely from light sampling in either the current or the previous frame. @@ -64,10 +62,10 @@ void RayGen() // Load the previous frame sampled lighting luminance. // For invalid gradients, temporalPixelPos is negative, and prevLuminance will be 0 float2 prevLuminance = t_PrevRestirLuminance[temporalReservoirPos]; - + // Load the current frame sampled lighting luminance. float2 currLuminance = u_RestirLuminance[srcReservoirPos]; - + float currMaxLuminance = max(currLuminance.x, currLuminance.y); float prevMaxLuminance = max(prevLuminance.x, prevLuminance.y); float selectedMaxLuminance = max(selectedDiffSpecLum.x, selectedDiffSpecLum.y); @@ -107,7 +105,7 @@ void RayGen() // Map the reservoir's light index into the other frame (previous or current) int selectedMappedLightIndex = RAB_TranslateLightIndex(RTXDI_GetDIReservoirLightIndex(selectedReservoir), !usePrevSample); - + if (selectedMappedLightIndex >= 0) { // If the mapping was successful, compare the lighting. @@ -154,7 +152,7 @@ void RayGen() // Calculate the sampled lighting luminance for the other surface float2 newDiffSpecLum = float2(calcLuminance(diffuse * surface.material.diffuseAlbedo), calcLuminance(specular)); - // Convert to FP16 and back to avoid false-positive gradients due to precision loss in the + // Convert to FP16 and back to avoid false-positive gradients due to precision loss in the // u_RestirLuminance and t_PrevRestirLuminance textures where selectedDiffSpecLum comes from. newDiffSpecLum = f16tof32(f32tof16(newDiffSpecLum)); diff --git a/Samples/FullSample/Shaders/LightingPasses/BrdfRayTracing.hlsl b/Samples/FullSample/Shaders/LightingPasses/BrdfRayTracing.hlsl index e130567..9708a64 100644 --- a/Samples/FullSample/Shaders/LightingPasses/BrdfRayTracing.hlsl +++ b/Samples/FullSample/Shaders/LightingPasses/BrdfRayTracing.hlsl @@ -14,12 +14,6 @@ #include -#ifdef WITH_NRD -#define NRD_HEADER_ONLY -#include -#include -#endif - #include "ShadingHelpers.hlsli" static const float c_MaxIndirectRadiance = 10; @@ -43,7 +37,7 @@ void RayGen() return; RAB_RandomSamplerState rng = RAB_InitRandomSampler(GlobalIndex, 5); - + float3 tangent, bitangent; branchlessONB(surface.normal, tangent, bitangent); @@ -122,13 +116,13 @@ void RayGen() ray.Origin = surface.worldPos; float3 radiance = 0; - + RayPayload payload = (RayPayload)0; payload.instanceID = ~0u; payload.throughput = 1.0; uint instanceMask = INSTANCE_MASK_OPAQUE; - + if (g_Const.sceneConstants.enableAlphaTestedGeometry) instanceMask |= INSTANCE_MASK_ALPHA_TESTED; @@ -137,7 +131,7 @@ void RayGen() #if USE_RAY_QUERY RayQuery rayQuery; - + rayQuery.TraceRayInline(SceneBVH, RAY_FLAG_NONE, instanceMask, ray); while (rayQuery.Proceed()) @@ -174,8 +168,8 @@ void RayGen() } uint gbufferIndex = RTXDI_ReservoirPositionToPointer(g_Const.restirGI.reservoirBufferParams, GlobalIndex, 0); - - struct + + struct { float3 position; float3 normal; @@ -204,7 +198,7 @@ void RayGen() payload.barycentrics, GeomAttr_Normal | GeomAttr_TexCoord | GeomAttr_Position, t_InstanceData, t_GeometryData, t_MaterialConstants); - + MaterialSample ms = sampleGeometryMaterial(gs, 0, 0, 0, MatAttr_BaseColor | MatAttr_Emissive | MatAttr_MetalRough, s_MaterialSampler); @@ -273,10 +267,10 @@ void RayGen() // GI reservoir sample in ShadeSecondarySurface.hlsl. It need to be stored separately. secondaryGBufferData.emission = radiance; radiance = 0; - + secondaryGBufferData.pdf = overall_PDF; } - + uint flags = 0; if (isSpecularRay) flags |= kSecondaryGBuffer_IsSpecularRay; if (isDeltaSurface) flags |= kSecondaryGBuffer_IsDeltaSurface; diff --git a/Samples/FullSample/Shaders/LightingPasses/DI/FusedResampling.hlsl b/Samples/FullSample/Shaders/LightingPasses/DI/FusedResampling.hlsl index 7d7b673..7474967 100644 --- a/Samples/FullSample/Shaders/LightingPasses/DI/FusedResampling.hlsl +++ b/Samples/FullSample/Shaders/LightingPasses/DI/FusedResampling.hlsl @@ -24,12 +24,6 @@ #include "Rtxdi/ReGIR/ReGIRSampling.hlsli" #endif -#ifdef WITH_NRD -#define NRD_HEADER_ONLY -#include -#include -#endif - #include "../ShadingHelpers.hlsli" #if USE_RAY_QUERY @@ -132,7 +126,7 @@ void RayGen() /* previousFrameTLAS = */ false, /* enableVisibilityReuse = */ true, diffuse, specular, lightDistance); currLuminance = float2(calcLuminance(diffuse * surface.material.diffuseAlbedo), calcLuminance(specular)); - + specular = DemodulateSpecular(surface.material.specularF0, specular); } @@ -149,6 +143,6 @@ void RayGen() } #endif - StoreShadingOutput(GlobalIndex, pixelPosition, + StoreShadingOutput(GlobalIndex, pixelPosition, surface.viewDepth, surface.material.roughness, diffuse, specular, lightDistance, true, g_Const.restirDI.shadingParams.enableDenoiserInputPacking); } \ No newline at end of file diff --git a/Samples/FullSample/Shaders/LightingPasses/DI/ShadeSamples.hlsl b/Samples/FullSample/Shaders/LightingPasses/DI/ShadeSamples.hlsl index db23e7b..b67c6d1 100644 --- a/Samples/FullSample/Shaders/LightingPasses/DI/ShadeSamples.hlsl +++ b/Samples/FullSample/Shaders/LightingPasses/DI/ShadeSamples.hlsl @@ -18,12 +18,6 @@ #include "Rtxdi/ReGIR/ReGIRSampling.hlsli" #endif -#ifdef WITH_NRD -#define NRD_HEADER_ONLY -#include -#include -#endif - #include "../ShadingHelpers.hlsli" #if USE_RAY_QUERY @@ -60,9 +54,9 @@ void RayGen() bool needToStore = ShadeSurfaceWithLightSample(reservoir, surface, lightSample, /* previousFrameTLAS = */ false, /* enableVisibilityReuse = */ true, diffuse, specular, lightDistance); - + currLuminance = float2(calcLuminance(diffuse * surface.material.diffuseAlbedo), calcLuminance(specular)); - + specular = DemodulateSpecular(surface.material.specularF0, specular); if (needToStore) @@ -74,7 +68,7 @@ void RayGen() // Store the sampled lighting luminance for the gradient pass. // Discard the pixels where the visibility was reused, as gradients need actual visibility. u_RestirLuminance[GlobalIndex] = currLuminance * (reservoir.age > 0 ? 0 : 1); - + #if RTXDI_REGIR_MODE != RTXDI_REGIR_DISABLED if (g_Const.visualizeRegirCells) { @@ -82,6 +76,6 @@ void RayGen() } #endif - StoreShadingOutput(GlobalIndex, pixelPosition, + StoreShadingOutput(GlobalIndex, pixelPosition, surface.viewDepth, surface.material.roughness, diffuse, specular, lightDistance, true, g_Const.restirDI.shadingParams.enableDenoiserInputPacking); } diff --git a/Samples/FullSample/Shaders/LightingPasses/GI/FinalShading.hlsl b/Samples/FullSample/Shaders/LightingPasses/GI/FinalShading.hlsl index bde6d5a..75d6f7f 100644 --- a/Samples/FullSample/Shaders/LightingPasses/GI/FinalShading.hlsl +++ b/Samples/FullSample/Shaders/LightingPasses/GI/FinalShading.hlsl @@ -16,12 +16,6 @@ #include #include -#ifdef WITH_NRD -#define NRD_HEADER_ONLY -#include -#include -#endif - #include "../ShadingHelpers.hlsli" static const float kMaxBrdfValue = 1e4; @@ -47,7 +41,7 @@ RTXDI_GIReservoir LoadInitialSampleReservoir(int2 reservoirPosition, RAB_Surface const float3 normal = octToNdirUnorm32(secondaryGBufferData.normal); const float3 throughput = Unpack_R16G16B16A16_FLOAT(secondaryGBufferData.throughputAndFlags).rgb; - // Note: the secondaryGBufferData.emission field contains the sampled radiance saved in ShadeSecondarySurfaces + // Note: the secondaryGBufferData.emission field contains the sampled radiance saved in ShadeSecondarySurfaces return RTXDI_MakeGIReservoir(secondaryGBufferData.worldPos, normal, secondaryGBufferData.emission * throughput, secondaryGBufferData.pdf); } @@ -69,10 +63,10 @@ void RayGen() return; const RAB_Surface primarySurface = RAB_GetGBufferSurface(pixelPosition, false); - + const uint2 reservoirPosition = RTXDI_PixelPosToReservoirPos(pixelPosition, g_Const.runtimeParams.activeCheckerboardField); const RTXDI_GIReservoir reservoir = RTXDI_LoadGIReservoir(g_Const.restirGI.reservoirBufferParams, reservoirPosition, g_Const.restirGI.bufferIndices.secondarySurfaceReSTIRDIOutputBufferIndex); - + float3 diffuse = 0; float3 specular = 0; @@ -106,10 +100,10 @@ void RayGen() const float3 initialRadiance = initialReservoir.radiance * initialReservoir.weightSum; - diffuse = brdf.demodulatedDiffuse * radiance * finalWeight + diffuse = brdf.demodulatedDiffuse * radiance * finalWeight + brdf0.demodulatedDiffuse * initialRadiance * initialWeight; - specular = brdf.specular * radiance * finalWeight + specular = brdf.specular * radiance * finalWeight + brdf0.specular * initialRadiance * initialWeight; } else @@ -122,6 +116,6 @@ void RayGen() specular = DemodulateSpecular(primarySurface.material.specularF0, specular); } - StoreShadingOutput(GlobalIndex, pixelPosition, + StoreShadingOutput(GlobalIndex, pixelPosition, primarySurface.viewDepth, primarySurface.material.roughness, diffuse, specular, 0, false, true); } diff --git a/Samples/FullSample/Shaders/LightingPasses/ShadeSecondarySurfaces.hlsl b/Samples/FullSample/Shaders/LightingPasses/ShadeSecondarySurfaces.hlsl index 8f3e944..f56863c 100644 --- a/Samples/FullSample/Shaders/LightingPasses/ShadeSecondarySurfaces.hlsl +++ b/Samples/FullSample/Shaders/LightingPasses/ShadeSecondarySurfaces.hlsl @@ -20,12 +20,6 @@ #include #include -#ifdef WITH_NRD -#define NRD_HEADER_ONLY -#include -#include -#endif - #include "ShadingHelpers.hlsli" static const float c_MaxIndirectRadiance = 10; @@ -86,7 +80,7 @@ void RayGen() g_Const.brdfPT.secondarySurfaceReSTIRDIParams.initialSamplingParams.numPrimaryInfiniteLightSamples, g_Const.brdfPT.secondarySurfaceReSTIRDIParams.initialSamplingParams.numPrimaryEnvironmentSamples, 0, // numBrdfSamples - 0.f, // brdfCutoff + 0.f, // brdfCutoff 0.f); // brdfMinRayT RAB_LightSample lightSample; @@ -174,7 +168,7 @@ void RayGen() specular = DemodulateSpecular(primarySurface.material.specularF0, specular); - StoreShadingOutput(GlobalIndex, pixelPosition, + StoreShadingOutput(GlobalIndex, pixelPosition, primarySurface.viewDepth, primarySurface.material.roughness, diffuse, specular, 0, false, true); } } diff --git a/Samples/FullSample/Shaders/LightingPasses/ShadingHelpers.hlsli b/Samples/FullSample/Shaders/LightingPasses/ShadingHelpers.hlsli index 1e26fd1..f979f71 100644 --- a/Samples/FullSample/Shaders/LightingPasses/ShadingHelpers.hlsli +++ b/Samples/FullSample/Shaders/LightingPasses/ShadingHelpers.hlsli @@ -11,8 +11,10 @@ #ifndef SHADING_HELPERS_HLSLI #define SHADING_HELPERS_HLSLI -#include "NRDEncoding.hlsli" -#include "NRD.hlsli" +#ifdef WITH_NRD +#include +#include +#endif struct SplitBrdf { @@ -133,7 +135,7 @@ void StoreShadingOutput( if (calcLuminance(specular) > calcLuminance(priorSpecular.rgb) || lightDistance == 0) specularHitT = priorSpecular.w; - + diffuse += priorDiffuse.rgb; specular += priorSpecular.rgb; } @@ -164,7 +166,7 @@ void StoreShadingOutput( { const bool useReLAX = (g_Const.denoiserMode == DENOISER_MODE_RELAX); const bool sanitize = true; - + if (useReLAX) { u_DiffuseLighting[lightingTexturePos] = RELAX_FrontEnd_PackRadianceAndHitDist(diffuse, diffuseHitT, sanitize); @@ -174,7 +176,7 @@ void StoreShadingOutput( { float diffNormDist = REBLUR_FrontEnd_GetNormHitDist(diffuseHitT, viewDepth, g_Const.reblurDiffHitDistParams, 1.0); u_DiffuseLighting[lightingTexturePos] = REBLUR_FrontEnd_PackRadianceAndNormHitDist(diffuse, diffNormDist, sanitize); - + float specNormDist = REBLUR_FrontEnd_GetNormHitDist(specularHitT, viewDepth, g_Const.reblurSpecHitDistParams, roughness); u_SpecularLighting[lightingTexturePos] = REBLUR_FrontEnd_PackRadianceAndNormHitDist(specular, specNormDist, sanitize); } From 67e18d7c7ef78236e847ff453d0b8c4a9dd88b57 Mon Sep 17 00:00:00 2001 From: dzhdan Date: Mon, 24 Feb 2025 13:20:55 +0800 Subject: [PATCH 03/12] Reduced code entropy --- .../FullSample/Shaders/LightingPasses/ShadingHelpers.hlsli | 4 ++-- Samples/FullSample/Shaders/ShaderParameters.h | 3 +-- Samples/FullSample/Source/RenderPasses/LightingPasses.cpp | 5 +---- Samples/FullSample/Source/RenderPasses/LightingPasses.h | 3 +-- Samples/FullSample/Source/main.cpp | 3 +-- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/Samples/FullSample/Shaders/LightingPasses/ShadingHelpers.hlsli b/Samples/FullSample/Shaders/LightingPasses/ShadingHelpers.hlsli index f979f71..e202f2b 100644 --- a/Samples/FullSample/Shaders/LightingPasses/ShadingHelpers.hlsli +++ b/Samples/FullSample/Shaders/LightingPasses/ShadingHelpers.hlsli @@ -174,10 +174,10 @@ void StoreShadingOutput( } else { - float diffNormDist = REBLUR_FrontEnd_GetNormHitDist(diffuseHitT, viewDepth, g_Const.reblurDiffHitDistParams, 1.0); + float diffNormDist = REBLUR_FrontEnd_GetNormHitDist(diffuseHitT, viewDepth, g_Const.reblurHitDistParams, 1.0); u_DiffuseLighting[lightingTexturePos] = REBLUR_FrontEnd_PackRadianceAndNormHitDist(diffuse, diffNormDist, sanitize); - float specNormDist = REBLUR_FrontEnd_GetNormHitDist(specularHitT, viewDepth, g_Const.reblurSpecHitDistParams, roughness); + float specNormDist = REBLUR_FrontEnd_GetNormHitDist(specularHitT, viewDepth, g_Const.reblurHitDistParams, roughness); u_SpecularLighting[lightingTexturePos] = REBLUR_FrontEnd_PackRadianceAndNormHitDist(specular, specNormDist, sanitize); } } diff --git a/Samples/FullSample/Shaders/ShaderParameters.h b/Samples/FullSample/Shaders/ShaderParameters.h index e029771..31fc868 100644 --- a/Samples/FullSample/Shaders/ShaderParameters.h +++ b/Samples/FullSample/Shaders/ShaderParameters.h @@ -211,8 +211,7 @@ struct ResamplingConstants PlanarViewConstants prevView; RTXDI_RuntimeParameters runtimeParams; - float4 reblurDiffHitDistParams; - float4 reblurSpecHitDistParams; + float4 reblurHitDistParams; uint frameIndex; uint enablePreviousTLAS; diff --git a/Samples/FullSample/Source/RenderPasses/LightingPasses.cpp b/Samples/FullSample/Source/RenderPasses/LightingPasses.cpp index 48672cf..9519dc5 100644 --- a/Samples/FullSample/Source/RenderPasses/LightingPasses.cpp +++ b/Samples/FullSample/Source/RenderPasses/LightingPasses.cpp @@ -442,10 +442,7 @@ void LightingPasses::FillResamplingConstants( constants.visualizeRegirCells = lightingSettings.visualizeRegirCells; #if WITH_NRD if (lightingSettings.denoiserMode != DENOISER_MODE_OFF) - { - NrdHitDistanceParamsToFloat4(lightingSettings.reblurDiffHitDistanceParams, constants.reblurDiffHitDistParams); - NrdHitDistanceParamsToFloat4(lightingSettings.reblurSpecHitDistanceParams, constants.reblurSpecHitDistParams); - } + NrdHitDistanceParamsToFloat4(lightingSettings.reblurHitDistanceParams, constants.reblurHitDistParams); #endif constants.lightBufferParams = isContext.GetLightBufferParameters(); diff --git a/Samples/FullSample/Source/RenderPasses/LightingPasses.h b/Samples/FullSample/Source/RenderPasses/LightingPasses.h index 73c624d..fd04d55 100644 --- a/Samples/FullSample/Source/RenderPasses/LightingPasses.h +++ b/Samples/FullSample/Source/RenderPasses/LightingPasses.h @@ -77,8 +77,7 @@ class LightingPasses BRDFPathTracing_Parameters brdfptParams = GetDefaultBRDFPathTracingParams(); #if WITH_NRD - const nrd::HitDistanceParameters* reblurDiffHitDistanceParams = nullptr; - const nrd::HitDistanceParameters* reblurSpecHitDistanceParams = nullptr; + const nrd::HitDistanceParameters* reblurHitDistanceParams = nullptr; #endif }; diff --git a/Samples/FullSample/Source/main.cpp b/Samples/FullSample/Source/main.cpp index 36b5846..722d4ab 100644 --- a/Samples/FullSample/Source/main.cpp +++ b/Samples/FullSample/Source/main.cpp @@ -1114,8 +1114,7 @@ class SceneRenderer : public app::ApplicationBase lightingSettings.enableAlphaTestedGeometry = m_ui.gbufferSettings.enableAlphaTestedGeometry; lightingSettings.enableTransparentGeometry = m_ui.gbufferSettings.enableTransparentGeometry; #if WITH_NRD - lightingSettings.reblurDiffHitDistanceParams = &m_ui.reblurSettings.hitDistanceParameters; - lightingSettings.reblurSpecHitDistanceParams = &m_ui.reblurSettings.hitDistanceParameters; + lightingSettings.reblurHitDistanceParams = &m_ui.reblurSettings.hitDistanceParameters; lightingSettings.denoiserMode = denoiserMode; #else lightingSettings.denoiserMode = DENOISER_MODE_OFF; From db8d765d941adbab48269c3ebd4de6d6cc2b9121 Mon Sep 17 00:00:00 2001 From: dzhdan Date: Mon, 24 Feb 2025 13:32:50 +0800 Subject: [PATCH 04/12] Updated NRD (submodule only, WIP) --- External/NRD | 2 +- External/NRD.cmake | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/External/NRD b/External/NRD index 248e69e..a4cbf7c 160000 --- a/External/NRD +++ b/External/NRD @@ -1 +1 @@ -Subproject commit 248e69e425a747d232c45599663297fd861705a8 +Subproject commit a4cbf7c0ea4965698dd4ef68ffa50a6c719e024e diff --git a/External/NRD.cmake b/External/NRD.cmake index 35d6c84..4c0e868 100644 --- a/External/NRD.cmake +++ b/External/NRD.cmake @@ -9,7 +9,4 @@ if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/NRD/CMakeLists.txt") option(NRD_STATIC_LIBRARY "" ON) add_subdirectory(external/NRD) - - set_target_properties(NRD PROPERTIES FOLDER NRD) - set_target_properties(NRD_Shaders PROPERTIES FOLDER NRD) endif() From 92c5ee77e883348149bdd182be5c34854cce0802 Mon Sep 17 00:00:00 2001 From: dzhdan Date: Mon, 24 Feb 2025 15:45:36 +0800 Subject: [PATCH 05/12] Updated NRD --- External/NRD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/External/NRD b/External/NRD index a4cbf7c..b3801ac 160000 --- a/External/NRD +++ b/External/NRD @@ -1 +1 @@ -Subproject commit a4cbf7c0ea4965698dd4ef68ffa50a6c719e024e +Subproject commit b3801acfd639727cf8231ededa4916726bec6739 From 53a2f24e876c283537ea01cee694d6f9edc3d0bd Mon Sep 17 00:00:00 2001 From: dzhdan Date: Mon, 24 Feb 2025 16:51:57 +0800 Subject: [PATCH 06/12] NRD updated to v4.14: - UI: reworked NRD related settings (WIP) - "frame based" accumulation replaced with "time based" accumulation - adjusted default settings for RESTIR --- Samples/FullSample/Source/NrdIntegration.cpp | 8 +- Samples/FullSample/Source/UserInterface.cpp | 112 +++++++++++-------- Samples/FullSample/Source/UserInterface.h | 3 +- 3 files changed, 71 insertions(+), 52 deletions(-) diff --git a/Samples/FullSample/Source/NrdIntegration.cpp b/Samples/FullSample/Source/NrdIntegration.cpp index 96d9529..38e27b5 100644 --- a/Samples/FullSample/Source/NrdIntegration.cpp +++ b/Samples/FullSample/Source/NrdIntegration.cpp @@ -110,9 +110,9 @@ bool NrdIntegration::Initialize(uint32_t width, uint32_t height) }; nrd::InstanceCreationDesc instanceCreationDesc; - instanceCreationDesc.memoryAllocatorInterface.Allocate = NrdAllocate; - instanceCreationDesc.memoryAllocatorInterface.Reallocate = NrdReallocate; - instanceCreationDesc.memoryAllocatorInterface.Free = NrdFree; + instanceCreationDesc.allocationCallbacks.Allocate = NrdAllocate; + instanceCreationDesc.allocationCallbacks.Reallocate = NrdReallocate; + instanceCreationDesc.allocationCallbacks.Free = NrdFree; instanceCreationDesc.denoisersNum = dim(denoisers); instanceCreationDesc.denoisers = denoisers; @@ -423,7 +423,7 @@ void NrdIntegration::RunDenoiserPasses( assert(resourceIndex < dispatchDesc.resourcesNum); const nrd::ResourceDesc& resource = dispatchDesc.resources[resourceIndex]; - assert(resource.stateNeeded == nrdDescriptorRange.descriptorType); + assert(resource.descriptorType == nrdDescriptorRange.descriptorType); nvrhi::TextureHandle texture; switch (resource.type) diff --git a/Samples/FullSample/Source/UserInterface.cpp b/Samples/FullSample/Source/UserInterface.cpp index 780460b..bb7199e 100644 --- a/Samples/FullSample/Source/UserInterface.cpp +++ b/Samples/FullSample/Source/UserInterface.cpp @@ -50,7 +50,7 @@ UIData::UIData() taaParams.newFrameWeight = 0.04f; taaParams.maxRadiance = 200.f; taaParams.clampingFactor = 1.3f; - + restirDI.resamplingMode = rtxdi::ReSTIRDI_ResamplingMode::TemporalAndSpatial; restirDI.initialSamplingParams = rtxdi::GetDefaultReSTIRDIInitialSamplingParams(); restirDI.temporalResamplingParams = rtxdi::GetDefaultReSTIRDITemporalResamplingParams(); @@ -211,10 +211,10 @@ void UIData::SetDefaultDenoiserSettings() reblurSettings.enableAntiFirefly = true; reblurSettings.diffusePrepassBlurRadius = 30.0f; reblurSettings.specularPrepassBlurRadius = 30.0f; - + reblurSettings.antilagSettings.luminanceSigmaScale = 2.0f; + reblurSettings.antilagSettings.luminanceSensitivity = 2.0f; + relaxSettings = nrd::RelaxSettings(); - relaxSettings.diffuseMaxFastAccumulatedFrameNum = 1; - relaxSettings.specularMaxFastAccumulatedFrameNum = 1; relaxSettings.diffusePhiLuminance = 1.0f; relaxSettings.spatialVarianceEstimationHistoryThreshold = 1; relaxSettings.enableAntiFirefly = true; @@ -391,7 +391,7 @@ void UserInterface::SamplingSettings() ImGui::TreePop(); } ImGui::Separator(); - + if (ImGui_ColoredTreeNode("Direct Lighting", c_ColorAttentionHeader)) { bool samplingSettingsChanged = false; @@ -426,9 +426,9 @@ void UserInterface::SamplingSettings() } ImGui::Checkbox("Show Advanced Settings", &m_showAdvancedSamplingSettings); - + bool isUsingReStir = m_ui.directLightingMode == DirectLightingMode::ReStir; - + if (isUsingReStir) { ImGui::PushItemWidth(180.f); @@ -501,7 +501,7 @@ void UserInterface::SamplingSettings() static const char* regirFallbackOptions[] = { "Uniform Sampling", "Power RIS" }; const char* currentFallbackOption = regirFallbackOptions[static_cast(m_ui.regirDynamicParameters.fallbackSamplingMode)]; if (ImGui::BeginCombo("ReGIR RIS Fallback Sampling Mode", currentFallbackOption)) - { + { for (int i = 0; i < sizeof(regirFallbackOptions) / sizeof(regirFallbackOptions[0]); i++) { bool is_selected = (i == static_cast(m_ui.regirDynamicParameters.fallbackSamplingMode)); @@ -519,7 +519,7 @@ void UserInterface::SamplingSettings() ImGui::TreePop(); } - + samplingSettingsChanged |= ImGui::SliderInt("Initial BRDF Samples", (int*)&m_ui.restirDI.initialSamplingParams.numPrimaryBrdfSamples, 0, 8); ShowHelpMarker( @@ -718,7 +718,7 @@ void UserInterface::SamplingSettings() ImGui::TreePop(); } - + if (m_ui.indirectLightingMode == IndirectLightingMode::ReStirGI) { ImGui::PushItemWidth(180.f); @@ -730,7 +730,7 @@ void UserInterface::SamplingSettings() "Fused Spatiotemporal\0"); ImGui::PopItemWidth(); ImGui::Separator(); - + if ((m_ui.restirGI.resamplingMode == rtxdi::ReSTIRGI_ResamplingMode::Temporal || m_ui.restirGI.resamplingMode == rtxdi::ReSTIRGI_ResamplingMode::TemporalAndSpatial || m_ui.restirGI.resamplingMode == rtxdi::ReSTIRGI_ResamplingMode::FusedSpatiotemporal) && @@ -896,7 +896,7 @@ void UserInterface::PostProcessSettings() } #endif m_ui.resetAccumulation |= ImGui::Checkbox("Apply Textures in Compositing", (bool*)&m_ui.enableTextures); - + ImGui::Checkbox("Tone mapping", (bool*)&m_ui.enableToneMapping); ImGui::SameLine(160.f); ImGui::SliderFloat("Exposure bias", &m_ui.exposureBias, -4.f, 2.f); @@ -974,7 +974,7 @@ void UserInterface::DenoiserSettings() int useReLAX = (m_ui.denoisingMethod == nrd::Denoiser::RELAX_DIFFUSE_SPECULAR) ? 1 : 0; ImGui::Combo("Denoiser", &useReLAX, "ReBLUR\0ReLAX\0"); m_ui.denoisingMethod = useReLAX ? nrd::Denoiser::RELAX_DIFFUSE_SPECULAR : nrd::Denoiser::REBLUR_DIFFUSE_SPECULAR; - + ImGui::SameLine(); if (ImGui::Button("Reset Settings")) m_ui.SetDefaultDenoiserSettings(); @@ -1002,60 +1002,78 @@ void UserInterface::DenoiserSettings() { ImGui::Separator(); ImGui::PushItemWidth(160.f); + + ImGui::SliderFloat("Accumulation time (sec)", &m_ui.accumulationTime, 0.0f, 1.0f, "%.2f"); + double fps = 1.0 / GetDeviceManager()->GetAverageFrameTimeSeconds(); + + // Better use "accumulation time" instead of "accumulated frames", since the former is FPS independent + uint32_t maxAccumulatedFrameNum = nrd::GetMaxAccumulatedFrameNum(m_ui.accumulationTime, (float)fps); + + // ReSTIR produces ~clean signals, but using 0-1 accumulated frames for fast history is unrecommended because of disocclusions (at least) + uint32_t maxFastAccumulatedFrameNum = maxAccumulatedFrameNum / 10; // 10x faster "fast" history + if (useReLAX) { - ImGui::SliderInt("History length (frames)", (int*)&m_ui.relaxSettings.diffuseMaxAccumulatedFrameNum, 0, nrd::RELAX_MAX_HISTORY_FRAME_NUM); - ImGui::SliderInt("Fast history length (frames)", (int*)&m_ui.relaxSettings.diffuseMaxFastAccumulatedFrameNum, 0, nrd::RELAX_MAX_HISTORY_FRAME_NUM); + m_ui.relaxSettings.diffuseMaxAccumulatedFrameNum = maxAccumulatedFrameNum; + m_ui.relaxSettings.specularMaxAccumulatedFrameNum = maxAccumulatedFrameNum; + m_ui.relaxSettings.diffuseMaxFastAccumulatedFrameNum = maxFastAccumulatedFrameNum; + m_ui.relaxSettings.specularMaxFastAccumulatedFrameNum = maxFastAccumulatedFrameNum; + ImGui::Checkbox("Anti-firefly", &m_ui.relaxSettings.enableAntiFirefly); ImGui::SameLine(); ImGui::Checkbox("Roughness edge stopping", &m_ui.relaxSettings.enableRoughnessEdgeStopping); - ImGui::Text("Reprojection:"); + ImGui::SliderFloat2("Pre-pass radius (px)", &m_ui.relaxSettings.diffusePrepassBlurRadius, 0.0f, 50.0f, "%.1f"); + ImGui::SliderInt("A-trous iterations", (int*)&m_ui.relaxSettings.atrousIterationNum, 2, 8); + ImGui::SliderFloat2("Diff-Spec luma weight", &m_ui.relaxSettings.diffusePhiLuminance, 0.0f, 10.0f, "%.1f"); + ImGui::SliderFloat2("Min luma weight", &m_ui.relaxSettings.diffuseMinLuminanceWeight, 0.0f, 1.0f, "%.2f"); + ImGui::SliderFloat("Depth threshold", &m_ui.relaxSettings.depthThreshold, 0.0f, 1.0f, "%.3f", ImGuiSliderFlags_Logarithmic); + ImGui::SliderFloat("Lobe fraction", &m_ui.relaxSettings.lobeAngleFraction, 0.0f, 1.0f, "%.2f"); + ImGui::SliderFloat("Roughness fraction", &m_ui.relaxSettings.roughnessFraction, 0.0f, 1.0f, "%.2f"); + ImGui::SliderFloat("Min hitT weight", &m_ui.relaxSettings.minHitDistanceWeight, 0.01f, 0.2f, "%.2f"); ImGui::SliderFloat("Spec variance boost", &m_ui.relaxSettings.specularVarianceBoost, 0.0f, 8.0f, "%.2f"); ImGui::SliderFloat("Clamping sigma scale", &m_ui.relaxSettings.historyClampingColorBoxSigmaScale, 0.0f, 10.0f, "%.1f"); + ImGui::SliderInt("History threshold", (int*)&m_ui.relaxSettings.spatialVarianceEstimationHistoryThreshold, 0, 10); + ImGui::Text("Luminance / Normal / Roughness:"); + ImGui::SliderFloat3("Relaxation", &m_ui.relaxSettings.luminanceEdgeStoppingRelaxation, 0.0f, 1.0f, "%.2f"); - ImGui::Text("Spatial filering:"); - ImGui::SliderFloat2("Pre-pass blur radius (px)", &m_ui.relaxSettings.diffusePrepassBlurRadius, 0.0f, 50.0f, "%.1f"); - ImGui::SliderInt("A-trous iterations", (int32_t*)&m_ui.relaxSettings.atrousIterationNum, 2, 8); - ImGui::SliderFloat2("Diff-Spec luma weight", &m_ui.relaxSettings.diffusePhiLuminance, 0.0f, 10.0f, "%.1f"); - ImGui::SetNextItemWidth( ImGui::CalcItemWidth() * 0.9f ); - ImGui::SliderFloat3("Diff-Spec-Rough fraction", &m_ui.relaxSettings.diffuseLobeAngleFraction, 0.0f, 1.0f, "%.2f"); - ImGui::SetNextItemWidth( ImGui::CalcItemWidth() * 0.9f ); - ImGui::SliderFloat3("Luma-Normal-Rough relaxation", &m_ui.relaxSettings.luminanceEdgeStoppingRelaxation, 0.0f, 1.0f, "%.2f"); - ImGui::SliderFloat("Spec lobe angle slack", &m_ui.relaxSettings.specularLobeAngleSlack, 0.0f, 89.0f, "%.3f", ImGuiSliderFlags_Logarithmic); - ImGui::SliderFloat2("Diff-Spec min luma weight", &m_ui.relaxSettings.diffuseMinLuminanceWeight, 0.0f, 1.0f, "%.2f"); - ImGui::SliderFloat("Depth threshold", &m_ui.relaxSettings.depthThreshold, 0.0f, 1.0f, "%.3f", ImGuiSliderFlags_Logarithmic); - - ImGui::Text("Spatial variance estimation:"); - ImGui::SliderInt("History threshold", (int32_t*)&m_ui.relaxSettings.spatialVarianceEstimationHistoryThreshold, 0, 10); + ImGui::Text("HISTORY FIX:"); + ImGui::SliderFloat("Normal weight power", &m_ui.relaxSettings.historyFixEdgeStoppingNormalPower, 0.0f, 128.0f, "%.1f"); + ImGui::SliderInt("Frames", (int*)&m_ui.relaxSettings.historyFixFrameNum, 0, 5); + ImGui::SliderInt("Stride", (int*)&m_ui.relaxSettings.historyFixBasePixelStride, 1, 20); - ImGui::Text("Anti-lag:"); + ImGui::Text("ANTI-LAG:"); ImGui::SliderFloat("Acceleration amount", &m_ui.relaxSettings.antilagSettings.accelerationAmount, 0.0f, 1.0f, "%.2f"); - ImGui::SliderFloat("Spatial sigma scale", &m_ui.relaxSettings.antilagSettings.spatialSigmaScale, 0.0f, 10.0f, "%.1f"); - ImGui::SliderFloat("Temporal sigma scale", &m_ui.relaxSettings.antilagSettings.temporalSigmaScale, 0.0f, 10.0f, "%.1f"); + ImGui::SliderFloat2("S/T sigma scales", &m_ui.relaxSettings.antilagSettings.spatialSigmaScale, 0.0f, 10.0f, "%.1f"); ImGui::SliderFloat("Reset amount", &m_ui.relaxSettings.antilagSettings.resetAmount, 0.0f, 1.0f, "%.2f"); } else { - ImGui::SliderInt("History length (frames)", (int*)&m_ui.reblurSettings.maxAccumulatedFrameNum, 0, nrd::REBLUR_MAX_HISTORY_FRAME_NUM); + m_ui.reblurSettings.maxAccumulatedFrameNum = maxAccumulatedFrameNum; + m_ui.reblurSettings.maxFastAccumulatedFrameNum = maxFastAccumulatedFrameNum; + + // Temporal stabilization is optional for ReSTIR + m_ui.reblurSettings.maxStabilizedFrameNum = std::min(m_ui.reblurSettings.maxStabilizedFrameNum, maxAccumulatedFrameNum); + ImGui::SliderInt("Stabilization (frames)", (int*)&m_ui.reblurSettings.maxStabilizedFrameNum, 0, maxAccumulatedFrameNum, "%d"); + ImGui::Checkbox("Anti-firefly", &m_ui.reblurSettings.enableAntiFirefly); ImGui::SameLine(); ImGui::Checkbox("Performance mode", &m_ui.reblurSettings.enablePerformanceMode); - ImGui::Text("Spatial filering:"); - ImGui::SliderFloat2("Pre-pass blur radius (px)", &m_ui.reblurSettings.diffusePrepassBlurRadius, 0.0f, 50.0f, "%.1f"); - ImGui::SliderFloat("Blur base radius (px)", &m_ui.reblurSettings.blurRadius, 0.0f, 60.0f, "%.1f"); + ImGui::SliderFloat2("Pre-pass radius (px)", &m_ui.reblurSettings.diffusePrepassBlurRadius, 0.0f, 50.0f, "%.1f"); + ImGui::SliderFloat("Min blur radius (px)", &m_ui.reblurSettings.minBlurRadius, 0.0f, 5.0f, "%.1f"); + ImGui::SliderFloat("Max blur radius (px)", &m_ui.reblurSettings.maxBlurRadius, 0.0f, 30.0f, "%.1f"); ImGui::SliderFloat("Lobe fraction", &m_ui.reblurSettings.lobeAngleFraction, 0.0f, 1.0f, "%.2f"); ImGui::SliderFloat("Roughness fraction", &m_ui.reblurSettings.roughnessFraction, 0.0f, 1.0f, "%.2f"); - ImGui::SliderFloat("Stabilization strength", &m_ui.reblurSettings.stabilizationStrength, 0.0f, 1.0f, "%.2f"); - ImGui::SetNextItemWidth( ImGui::CalcItemWidth() * 0.6f ); - ImGui::SliderFloat("Responsive accum roughness threshold", &m_ui.reblurSettings.responsiveAccumulationRoughnessThreshold, 0.0f, 1.0f, "%.2f"); + ImGui::SliderFloat("Min hitT weight", &m_ui.reblurSettings.minHitDistanceWeight, 0.01f, 0.2f, "%.2f"); + ImGui::SliderInt("History fix frames", (int*)&m_ui.reblurSettings.historyFixFrameNum, 0, 5); + ImGui::SliderInt("History fix stride", (int*)&m_ui.reblurSettings.historyFixBasePixelStride, 1, 20); - if (m_ui.reblurSettings.stabilizationStrength != 0.0f) + if (m_ui.reblurSettings.maxAccumulatedFrameNum && m_ui.reblurSettings.maxStabilizedFrameNum) { - ImGui::Text("Anti-lag:"); - ImGui::SliderFloat2("Sigma scale", &m_ui.reblurSettings.antilagSettings.luminanceSigmaScale, 1.0f, 3.0f, "%.1f"); - ImGui::SliderFloat2("Power", &m_ui.reblurSettings.antilagSettings.luminanceAntilagPower, 0.01f, 1.0f, "%.2f"); + ImGui::Text("ANTI-LAG:"); + ImGui::SliderFloat("Sigma scale", &m_ui.reblurSettings.antilagSettings.luminanceSigmaScale, 1.0f, 5.0f, "%.1f"); + ImGui::SliderFloat("Sensitivity", &m_ui.reblurSettings.antilagSettings.luminanceSensitivity, 1.0f, 5.0f, "%.1f"); } } @@ -1183,7 +1201,7 @@ void UserInterface::SceneSettings() } ImGui::Separator(); - + if (ImGui_ColoredTreeNode("Material Editor", c_ColorRegularHeader)) { ImGui::Checkbox("##enableRoughnessOverride", &m_ui.gbufferSettings.enableRoughnessOverride); @@ -1227,7 +1245,7 @@ void UserInterface::SceneSettings() ImGui::TreePop(); } - + ImGui::Separator(); if (ImGui_ColoredTreeNode("Light Editor", c_ColorRegularHeader)) @@ -1440,7 +1458,7 @@ void UserInterface::buildUI() { if (!m_ui.showUI) return; - + int width, height; GetDeviceManager()->GetWindowDimensions(width, height); diff --git a/Samples/FullSample/Source/UserInterface.h b/Samples/FullSample/Source/UserInterface.h index 0eed2df..cc7afd5 100644 --- a/Samples/FullSample/Source/UserInterface.h +++ b/Samples/FullSample/Source/UserInterface.h @@ -145,10 +145,11 @@ struct UIData bool environmentMapImportanceSampling = true; float environmentIntensityBias = 0.f; float environmentRotation = 0.f; - + bool enableDenoiser = true; #ifdef WITH_NRD float debug = 0.0f; + float accumulationTime = 0.334f; // (sec) 20 frames @ 60 FPS nrd::Denoiser denoisingMethod = nrd::Denoiser::RELAX_DIFFUSE_SPECULAR; nrd::ReblurSettings reblurSettings = {}; nrd::RelaxSettings relaxSettings = {}; From 44b28600aad7b831079d58537cd6c7ee3d7e3275 Mon Sep 17 00:00:00 2001 From: dzhdan Date: Tue, 25 Feb 2025 09:14:24 +0800 Subject: [PATCH 07/12] Updated Donut --- External/donut | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/External/donut b/External/donut index 04c9b20..5b8b5c3 160000 --- a/External/donut +++ b/External/donut @@ -1 +1 @@ -Subproject commit 04c9b20189ea59629c888f260cd3a3cef0119010 +Subproject commit 5b8b5c3ff83ba5fd90459d816314e75e17a8eb30 From 540fe01e71964c9476fab64c3052f6af5858d495 Mon Sep 17 00:00:00 2001 From: dzhdan Date: Tue, 25 Feb 2025 13:25:32 +0800 Subject: [PATCH 08/12] Updated NRD --- External/NRD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/External/NRD b/External/NRD index b3801ac..7481ed7 160000 --- a/External/NRD +++ b/External/NRD @@ -1 +1 @@ -Subproject commit b3801acfd639727cf8231ededa4916726bec6739 +Subproject commit 7481ed7e32deb36f311028d3fad6ad6277a078cc From a8d7cef05b7afb3519a5fbc7678ecc1224654347 Mon Sep 17 00:00:00 2001 From: dzhdan Date: Tue, 25 Feb 2025 14:09:26 +0800 Subject: [PATCH 09/12] Updated DLSS --- External/DLSS | 2 +- External/DLSS.cmake | 6 +++--- Samples/FullSample/Source/DLSS-DX12.cpp | 3 ++- Samples/FullSample/Source/DLSS-VK.cpp | 5 +++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/External/DLSS b/External/DLSS index 59c5860..d489595 160000 --- a/External/DLSS +++ b/External/DLSS @@ -1 +1 @@ -Subproject commit 59c586020d6892944bdd17408edf14de93e87541 +Subproject commit d489595a8c5cb19c7a8d770b0cb5bc198cc99018 diff --git a/External/DLSS.cmake b/External/DLSS.cmake index 591c6c4..3e4de9f 100644 --- a/External/DLSS.cmake +++ b/External/DLSS.cmake @@ -9,8 +9,8 @@ if (WIN32) set(dlss_lib_debug "nvsdk_ngx_s_dbg.lib") set_target_properties(DLSS PROPERTIES - IMPORTED_IMPLIB "${dlss_sdk}/lib/${dlss_platform}/x86_64/${dlss_lib_release}" - IMPORTED_IMPLIB_DEBUG "${dlss_sdk}/lib/${dlss_platform}/x86_64/${dlss_lib_debug}" + IMPORTED_IMPLIB "${dlss_sdk}/lib/${dlss_platform}/x64/${dlss_lib_release}" + IMPORTED_IMPLIB_DEBUG "${dlss_sdk}/lib/${dlss_platform}/x64/${dlss_lib_debug}" IMPORTED_LOCATION "${dlss_sdk}/lib/${dlss_platform}/rel/nvngx_dlss.dll" IMPORTED_LOCATION_DEBUG "${dlss_sdk}/lib/${dlss_platform}/dev/nvngx_dlss.dll" ) @@ -21,7 +21,7 @@ elseif (UNIX AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") add_library(DLSS STATIC IMPORTED) set(dlss_platform "Linux_x86_64") - set(dlss_lib "libnvidia-ngx-dlss.so.2.3.1") + set(dlss_lib "libnvidia-ngx-dlss.so.310.1") set_target_properties(DLSS PROPERTIES IMPORTED_LOCATION "${dlss_sdk}/lib/${dlss_platform}/libnvsdk_ngx.a" diff --git a/Samples/FullSample/Source/DLSS-DX12.cpp b/Samples/FullSample/Source/DLSS-DX12.cpp index 9dec599..2b62514 100644 --- a/Samples/FullSample/Source/DLSS-DX12.cpp +++ b/Samples/FullSample/Source/DLSS-DX12.cpp @@ -189,7 +189,8 @@ class DLSS_DX12 : public DLSS m_parameters = nullptr; } - NVSDK_NGX_D3D12_Shutdown(); + ID3D12Device* d3ddevice = m_device->getNativeObject(nvrhi::ObjectTypes::D3D12_Device); + NVSDK_NGX_D3D12_Shutdown1(d3ddevice); } }; diff --git a/Samples/FullSample/Source/DLSS-VK.cpp b/Samples/FullSample/Source/DLSS-VK.cpp index 2de8cc9..3e8aefd 100644 --- a/Samples/FullSample/Source/DLSS-VK.cpp +++ b/Samples/FullSample/Source/DLSS-VK.cpp @@ -48,7 +48,7 @@ class DLSS_VK : public DLSS featureCommonInfo.LoggingInfo.DisableOtherLoggingSinks = true; NVSDK_NGX_Result result = NVSDK_NGX_VULKAN_Init(c_applicationID, - executablePathW.c_str(), vkInstance, vkPhysicalDevice, vkDevice, &featureCommonInfo); + executablePathW.c_str(), vkInstance, vkPhysicalDevice, vkDevice, nullptr, nullptr, &featureCommonInfo); if (result != NVSDK_NGX_Result_Success) { @@ -220,7 +220,8 @@ class DLSS_VK : public DLSS m_parameters = nullptr; } - NVSDK_NGX_VULKAN_Shutdown(); + VkDevice vkDevice = m_device->getNativeObject(nvrhi::ObjectTypes::VK_Device); + NVSDK_NGX_VULKAN_Shutdown1(vkDevice); } }; From 041e88bfc0528f92270132c246638f8162a3ec5c Mon Sep 17 00:00:00 2001 From: dzhdan Date: Tue, 25 Feb 2025 14:13:03 +0800 Subject: [PATCH 10/12] Fix for the previous commit --- External/DLSS.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/External/DLSS.cmake b/External/DLSS.cmake index 3e4de9f..d763b5f 100644 --- a/External/DLSS.cmake +++ b/External/DLSS.cmake @@ -21,7 +21,7 @@ elseif (UNIX AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") add_library(DLSS STATIC IMPORTED) set(dlss_platform "Linux_x86_64") - set(dlss_lib "libnvidia-ngx-dlss.so.310.1") + set(dlss_lib "libnvidia-ngx-dlss.so.310.1.0") set_target_properties(DLSS PROPERTIES IMPORTED_LOCATION "${dlss_sdk}/lib/${dlss_platform}/libnvsdk_ngx.a" From 1eaa2f698337a6610a18b368995e6e5f2d87a268 Mon Sep 17 00:00:00 2001 From: dzhdan Date: Thu, 27 Feb 2025 10:13:28 +0800 Subject: [PATCH 11/12] UI: polishing --- Samples/FullSample/Source/UserInterface.cpp | 76 +++++++++++---------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/Samples/FullSample/Source/UserInterface.cpp b/Samples/FullSample/Source/UserInterface.cpp index bb7199e..d6a6e9c 100644 --- a/Samples/FullSample/Source/UserInterface.cpp +++ b/Samples/FullSample/Source/UserInterface.cpp @@ -208,11 +208,11 @@ void UIData::ApplyPreset() void UIData::SetDefaultDenoiserSettings() { reblurSettings = nrd::ReblurSettings(); + reblurSettings.antilagSettings.luminanceSigmaScale = 2.0f; + reblurSettings.antilagSettings.luminanceSensitivity = 2.0f; reblurSettings.enableAntiFirefly = true; reblurSettings.diffusePrepassBlurRadius = 30.0f; reblurSettings.specularPrepassBlurRadius = 30.0f; - reblurSettings.antilagSettings.luminanceSigmaScale = 2.0f; - reblurSettings.antilagSettings.luminanceSensitivity = 2.0f; relaxSettings = nrd::RelaxSettings(); relaxSettings.diffusePhiLuminance = 1.0f; @@ -964,7 +964,7 @@ void UserInterface::DenoiserSettings() if (ImGui_ColoredTreeNode(s, c_ColorAttentionHeader)) { - ImGui::Checkbox("Enable Denoiser", &m_ui.enableDenoiser); + ImGui::Checkbox("Enable", &m_ui.enableDenoiser); if (m_ui.enableDenoiser) { @@ -979,46 +979,30 @@ void UserInterface::DenoiserSettings() if (ImGui::Button("Reset Settings")) m_ui.SetDefaultDenoiserSettings(); - ImGui::Separator(); ImGui::PushItemWidth(160.f); - ImGui::SliderFloat("Noise Mix-in", &m_ui.noiseMix, 0.f, 1.f); - ImGui::PopItemWidth(); - ImGui::PushItemWidth(76.f); - ImGui::SliderFloat("##noiseClampLow", &m_ui.noiseClampLow, 0.f, 1.f); - ImGui::SameLine(); - ImGui::SliderFloat("Noise Clamp", &m_ui.noiseClampHigh, 1.f, 4.f); - ImGui::PopItemWidth(); - ImGui::Separator(); - ImGui::Checkbox("Use Confidence Input", (bool*)&m_ui.lightingSettings.enableGradients); - if (m_ui.lightingSettings.enableGradients && m_showAdvancedDenoisingSettings) - { - ImGui::SliderFloat("Gradient Sensitivity", &m_ui.lightingSettings.gradientSensitivity, 1.f, 20.f); - ImGui::SliderFloat("Darkness Bias (EV)", &m_ui.lightingSettings.gradientLogDarknessBias, -16.f, -4.f); - ImGui::SliderFloat("Confidence History Length", &m_ui.lightingSettings.confidenceHistoryLength, 0.f, 3.f); - } + ImGui::SliderFloat("Accumulation time (sec)", &m_ui.accumulationTime, 0.0f, 1.0f, "%.2f"); + double fps = 1.0 / GetDeviceManager()->GetAverageFrameTimeSeconds(); - if (m_showAdvancedDenoisingSettings) - { - ImGui::Separator(); - ImGui::PushItemWidth(160.f); + // Better use "accumulation time" instead of "accumulated frames", since the former is FPS independent + uint32_t maxAccumulatedFrameNum = nrd::GetMaxAccumulatedFrameNum(m_ui.accumulationTime, (float)fps); + maxAccumulatedFrameNum = std::min(maxAccumulatedFrameNum, 60u); - ImGui::SliderFloat("Accumulation time (sec)", &m_ui.accumulationTime, 0.0f, 1.0f, "%.2f"); - double fps = 1.0 / GetDeviceManager()->GetAverageFrameTimeSeconds(); + // ReSTIR produces ~clean signals, but using 0-1 accumulated frames for fast history is unrecommended because of disocclusions (at least) + uint32_t maxFastAccumulatedFrameNum = maxAccumulatedFrameNum / 10; // 10x faster "fast" history - // Better use "accumulation time" instead of "accumulated frames", since the former is FPS independent - uint32_t maxAccumulatedFrameNum = nrd::GetMaxAccumulatedFrameNum(m_ui.accumulationTime, (float)fps); + m_ui.relaxSettings.diffuseMaxAccumulatedFrameNum = maxAccumulatedFrameNum; + m_ui.relaxSettings.specularMaxAccumulatedFrameNum = maxAccumulatedFrameNum; + m_ui.relaxSettings.diffuseMaxFastAccumulatedFrameNum = maxFastAccumulatedFrameNum; + m_ui.relaxSettings.specularMaxFastAccumulatedFrameNum = maxFastAccumulatedFrameNum; - // ReSTIR produces ~clean signals, but using 0-1 accumulated frames for fast history is unrecommended because of disocclusions (at least) - uint32_t maxFastAccumulatedFrameNum = maxAccumulatedFrameNum / 10; // 10x faster "fast" history + m_ui.reblurSettings.maxAccumulatedFrameNum = maxAccumulatedFrameNum; + m_ui.reblurSettings.maxFastAccumulatedFrameNum = maxFastAccumulatedFrameNum; + if (m_showAdvancedDenoisingSettings) + { if (useReLAX) { - m_ui.relaxSettings.diffuseMaxAccumulatedFrameNum = maxAccumulatedFrameNum; - m_ui.relaxSettings.specularMaxAccumulatedFrameNum = maxAccumulatedFrameNum; - m_ui.relaxSettings.diffuseMaxFastAccumulatedFrameNum = maxFastAccumulatedFrameNum; - m_ui.relaxSettings.specularMaxFastAccumulatedFrameNum = maxFastAccumulatedFrameNum; - ImGui::Checkbox("Anti-firefly", &m_ui.relaxSettings.enableAntiFirefly); ImGui::SameLine(); ImGui::Checkbox("Roughness edge stopping", &m_ui.relaxSettings.enableRoughnessEdgeStopping); @@ -1049,9 +1033,6 @@ void UserInterface::DenoiserSettings() } else { - m_ui.reblurSettings.maxAccumulatedFrameNum = maxAccumulatedFrameNum; - m_ui.reblurSettings.maxFastAccumulatedFrameNum = maxFastAccumulatedFrameNum; - // Temporal stabilization is optional for ReSTIR m_ui.reblurSettings.maxStabilizedFrameNum = std::min(m_ui.reblurSettings.maxStabilizedFrameNum, maxAccumulatedFrameNum); ImGui::SliderInt("Stabilization (frames)", (int*)&m_ui.reblurSettings.maxStabilizedFrameNum, 0, maxAccumulatedFrameNum, "%d"); @@ -1079,6 +1060,27 @@ void UserInterface::DenoiserSettings() ImGui::PopItemWidth(); } + + // Noise mix in + ImGui::Separator(); + ImGui::PushItemWidth(160.f); + ImGui::SliderFloat("Noise Mix-in", &m_ui.noiseMix, 0.f, 1.f); + ImGui::PopItemWidth(); + ImGui::PushItemWidth(76.f); + ImGui::SliderFloat("##noiseClampLow", &m_ui.noiseClampLow, 0.f, 1.f); + ImGui::SameLine(); + ImGui::SliderFloat("Noise Clamp", &m_ui.noiseClampHigh, 1.f, 4.f); + ImGui::PopItemWidth(); + + // Confidence + ImGui::Separator(); + ImGui::Checkbox("Use Confidence Input", (bool*)&m_ui.lightingSettings.enableGradients); + if (m_ui.lightingSettings.enableGradients && m_showAdvancedDenoisingSettings) + { + ImGui::SliderFloat("Gradient Sensitivity", &m_ui.lightingSettings.gradientSensitivity, 1.f, 20.f); + ImGui::SliderFloat("Darkness Bias (EV)", &m_ui.lightingSettings.gradientLogDarknessBias, -16.f, -4.f); + ImGui::SliderFloat("Confidence History Length", &m_ui.lightingSettings.confidenceHistoryLength, 0.f, 3.f); + } } ImGui::TreePop(); From 116e29d381ddab58d8f80670cbb1a23c54099212 Mon Sep 17 00:00:00 2001 From: dzhdan Date: Wed, 5 Mar 2025 12:18:27 +0800 Subject: [PATCH 12/12] Updated NRD to v4.14.0 (fixed) --- External/NRD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/External/NRD b/External/NRD index 7481ed7..5779933 160000 --- a/External/NRD +++ b/External/NRD @@ -1 +1 @@ -Subproject commit 7481ed7e32deb36f311028d3fad6ad6277a078cc +Subproject commit 57799338d2642cd3d0349f7a04b9bbbca40d824f