From 78c356f73e852a9067bdf5f01e89c78ee36e5d52 Mon Sep 17 00:00:00 2001 From: Anis Benyoub Date: Fri, 22 Oct 2021 18:10:06 +0200 Subject: [PATCH 1/4] Fix regression that was introduced in a previous PR --- .../Raytracing/HDDiffuseDenoiser.cs | 16 ++++++---------- .../Shaders/Denoising/DiffuseDenoiser.compute | 12 +++++++++++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDDiffuseDenoiser.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDDiffuseDenoiser.cs index 6c9a59503d3..f95d9232271 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDDiffuseDenoiser.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDDiffuseDenoiser.cs @@ -18,14 +18,6 @@ class HDDiffuseDenoiser int m_GatherSingleKernel; int m_GatherColorKernel; ComputeBuffer m_PointDistribution; - static internal float[] pointDistribution = new float[] { 0.647285104f, -0.534139216f, 0.201738372f, 0.260410696f, - -0.443308681f, 0.259598345f, 0.0f, 0.0f, - 0.851900041f, 0.214261428f, 0.0376310274f, -0.406103343f, - -0.357411921f, -0.525219262f, -0.00147355383f, 0.239211172f, - -0.463947058f, 0.646911025f, -0.0379408896f, -0.291660219f, - 0.405679494f, -0.473511368f, 0.0473965593f, 0.0411158539f, - -0.963973522f, -0.155723229f, -0.444706231f, 0.141471207f, - 0.0980135575f, 0.687162697f, 0.156328082f, -0.0518609099f}; public void Init(HDRenderPipelineRuntimeResources rpResources, HDRenderPipeline renderPipeline) { @@ -40,8 +32,12 @@ public void Init(HDRenderPipelineRuntimeResources rpResources, HDRenderPipeline m_BilateralFilterColorKernel = m_DiffuseDenoiser.FindKernel("BilateralFilterColor"); m_GatherSingleKernel = m_DiffuseDenoiser.FindKernel("GatherSingle"); m_GatherColorKernel = m_DiffuseDenoiser.FindKernel("GatherColor"); - m_PointDistribution = new ComputeBuffer(16 * 2, sizeof(float)); - m_PointDistribution.SetData(pointDistribution); + + // Generate the point distribution + int m_GeneratePointDistributionKernel = m_DiffuseDenoiser.FindKernel("GeneratePointDistribution"); + m_PointDistribution = new ComputeBuffer(16 * 2 * 4, sizeof(float)); + m_DiffuseDenoiser.SetBuffer(m_GeneratePointDistributionKernel, "_PointDistributionRW", m_PointDistribution); + m_DiffuseDenoiser.Dispatch(m_GeneratePointDistributionKernel, 1, 1, 1); } public void Release() diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Denoising/DiffuseDenoiser.compute b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Denoising/DiffuseDenoiser.compute index 6a1cf4e8e93..6ca84903adc 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Denoising/DiffuseDenoiser.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Denoising/DiffuseDenoiser.compute @@ -1,3 +1,5 @@ +#pragma kernel GeneratePointDistribution + #pragma kernel BilateralFilterSingle BILATERAL_FILTER=BilateralFilterSingle SINGLE_CHANNEL #pragma kernel BilateralFilterColor BILATERAL_FILTER=BilateralFilterColor @@ -21,6 +23,7 @@ #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl" // Ray Tracing includes +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingSampling.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Denoising/BilateralFilter.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Denoising/DenoisingUtils.hlsl" @@ -32,6 +35,7 @@ // Noisy Input Buffer TEXTURE2D_X(_DenoiseInputTexture); // Buffer used for point sampling +RWStructuredBuffer _PointDistributionRW; StructuredBuffer _PointDistribution; // Filtered Output buffer (depends on the singel or color variant of the denoiser) #if SINGLE_CHANNEL @@ -50,6 +54,12 @@ int _JitterFramePeriod; // Flag used to do a half resolution filter int _HalfResolutionFilter; +[numthreads(64, 1, 1)] +void GeneratePointDistribution(uint3 dispatchThreadId : SV_DispatchThreadID) +{ + _PointDistributionRW[dispatchThreadId.x] = SampleDiskCubic(GetLDSequenceSampleFloat(dispatchThreadId.x, 0), GetLDSequenceSampleFloat(dispatchThreadId.x, 1)); +} + float ComputeMaxDenoisingRadius(float3 positionRWS) { // Compute the distance to the pixel @@ -127,7 +137,7 @@ void BILATERAL_FILTER(uint3 dispatchThreadId : SV_DispatchThreadID, uint2 groupT hClip.xyz /= hClip.w; // Is the target pixel in the screen? - if (hClip.x > 1.0 || hClip.x < -1.0 || hClip.y > 1.0 || hClip.y < -1.0 ) + if (hClip.x > 1.0 || hClip.x < -1.0 || hClip.y > 1.0 || hClip.y < -1.0) continue; // Convert it to screen sample space From 0247d31c335a7e22822d8f8fcfb74f33b4f2e48e Mon Sep 17 00:00:00 2001 From: Anis Benyoub Date: Fri, 22 Oct 2021 18:16:12 +0200 Subject: [PATCH 2/4] changelog --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 4243d3cab23..139681f1f06 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed robustness issues with the stacklit material in path tracing (case 1373971). - Fixed custom pass injection point not visible in the UI when using the Camera mode. - Fixed film grain & dithering when using spatial upscaling methods for DRS. +- Fixed a regression that was introduced in the diffuse denoiser in a previous PR. ### Changed - Use RayTracingAccelerationStructure.CullInstances to filter Renderers and populate the acceleration structure with ray tracing instances for improved CPU performance on the main thread. From 70c3e17ee3a111cb535d5fbe4bba91d8cf27bddf Mon Sep 17 00:00:00 2001 From: Anis Benyoub Date: Fri, 22 Oct 2021 18:31:22 +0200 Subject: [PATCH 3/4] fix formatting --- .../Raytracing/Shaders/Denoising/DiffuseDenoiser.compute | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Denoising/DiffuseDenoiser.compute b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Denoising/DiffuseDenoiser.compute index 6ca84903adc..bd222517772 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Denoising/DiffuseDenoiser.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Denoising/DiffuseDenoiser.compute @@ -56,7 +56,7 @@ int _HalfResolutionFilter; [numthreads(64, 1, 1)] void GeneratePointDistribution(uint3 dispatchThreadId : SV_DispatchThreadID) -{ +{ _PointDistributionRW[dispatchThreadId.x] = SampleDiskCubic(GetLDSequenceSampleFloat(dispatchThreadId.x, 0), GetLDSequenceSampleFloat(dispatchThreadId.x, 1)); } From 1f63d530a44a611e8d9489b80feccd373b19b8bd Mon Sep 17 00:00:00 2001 From: Anis Benyoub Date: Fri, 22 Oct 2021 20:05:39 +0200 Subject: [PATCH 4/4] Missing bind at init --- .../Runtime/RenderPipeline/Raytracing/HDDiffuseDenoiser.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDDiffuseDenoiser.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDDiffuseDenoiser.cs index f95d9232271..b12d097a46d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDDiffuseDenoiser.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDDiffuseDenoiser.cs @@ -8,7 +8,6 @@ class HDDiffuseDenoiser { // Resources used for the de-noiser ComputeShader m_DiffuseDenoiser; - Texture m_OwenScrambleRGBA; HDRenderPipeline m_RenderPipeline; @@ -23,7 +22,6 @@ public void Init(HDRenderPipelineRuntimeResources rpResources, HDRenderPipeline { // Keep track of the resources m_DiffuseDenoiser = rpResources.shaders.diffuseDenoiserCS; - m_OwenScrambleRGBA = rpResources.textures.owenScrambledRGBATex; m_RenderPipeline = renderPipeline; @@ -36,6 +34,7 @@ public void Init(HDRenderPipelineRuntimeResources rpResources, HDRenderPipeline // Generate the point distribution int m_GeneratePointDistributionKernel = m_DiffuseDenoiser.FindKernel("GeneratePointDistribution"); m_PointDistribution = new ComputeBuffer(16 * 2 * 4, sizeof(float)); + m_DiffuseDenoiser.SetTexture(m_GeneratePointDistributionKernel, HDShaderIDs._OwenScrambledRGTexture, rpResources.textures.owenScrambledRGBATex); m_DiffuseDenoiser.SetBuffer(m_GeneratePointDistributionKernel, "_PointDistributionRW", m_PointDistribution); m_DiffuseDenoiser.Dispatch(m_GeneratePointDistributionKernel, 1, 1, 1); }