Skip to content

Fix regression that was introduced in a previous PR on the diffuse denoiser #6119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class HDDiffuseDenoiser
{
// Resources used for the de-noiser
ComputeShader m_DiffuseDenoiser;
Texture m_OwenScrambleRGBA;

HDRenderPipeline m_RenderPipeline;

Expand All @@ -18,20 +17,11 @@ 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)
{
// Keep track of the resources
m_DiffuseDenoiser = rpResources.shaders.diffuseDenoiserCS;
m_OwenScrambleRGBA = rpResources.textures.owenScrambledRGBATex;

m_RenderPipeline = renderPipeline;

Expand All @@ -40,8 +30,13 @@ 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.SetTexture(m_GeneratePointDistributionKernel, HDShaderIDs._OwenScrambledRGTexture, rpResources.textures.owenScrambledRGBATex);
m_DiffuseDenoiser.SetBuffer(m_GeneratePointDistributionKernel, "_PointDistributionRW", m_PointDistribution);
m_DiffuseDenoiser.Dispatch(m_GeneratePointDistributionKernel, 1, 1, 1);
}

public void Release()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma kernel GeneratePointDistribution

#pragma kernel BilateralFilterSingle BILATERAL_FILTER=BilateralFilterSingle SINGLE_CHANNEL
#pragma kernel BilateralFilterColor BILATERAL_FILTER=BilateralFilterColor

Expand All @@ -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"
Expand All @@ -32,6 +35,7 @@
// Noisy Input Buffer
TEXTURE2D_X(_DenoiseInputTexture);
// Buffer used for point sampling
RWStructuredBuffer<float2> _PointDistributionRW;
StructuredBuffer<float2> _PointDistribution;
// Filtered Output buffer (depends on the singel or color variant of the denoiser)
#if SINGLE_CHANNEL
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down