Skip to content
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 @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Removed the material pass probe volumes evaluation mode.
- Unifying the history validation pass so that it is only done once for the whole frame and not per effect.
- Updated the tooltip for the Decal Angle Fade property (requires to enable Decal Layers in both HDRP asset and Frame settings) (case 1308048).
- The RTAO's history is now discarded if the occlusion caster was moving (case 1303418).

## [11.0.0] - 2020-10-21

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ TextureHandle DenoiseRTSSS(RenderGraph renderGraph, HDCamera hdCamera, TextureHa
HDTemporalFilter temporalFilter = GetTemporalFilter();
TemporalFilterParameters tfParameters = temporalFilter.PrepareTemporalFilterParameters(hdCamera, false, historyValidity);
TextureHandle historyBuffer = renderGraph.ImportTexture(RequestRayTracedSSSHistoryTexture(hdCamera));
return temporalFilter.Denoise(renderGraph, hdCamera, tfParameters, rayTracedSSS, historyBuffer, depthPyramid, normalBuffer, motionVectorBuffer, historyValidationTexture);
return temporalFilter.Denoise(renderGraph, hdCamera, tfParameters, rayTracedSSS, renderGraph.defaultResources.blackTextureXR, historyBuffer, depthPyramid, normalBuffer, motionVectorBuffer, historyValidationTexture);
}

class ComposeRTSSSPassData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ namespace UnityEngine.Rendering.HighDefinition
{
partial class HDRaytracingAmbientOcclusion
{
struct TraceAmbientOcclusionResult
{
public TextureHandle signalBuffer;
public TextureHandle velocityBuffer;
}

public TextureHandle RenderRTAO(RenderGraph renderGraph, HDCamera hdCamera,
TextureHandle depthBuffer, TextureHandle normalBuffer, TextureHandle motionVectors, TextureHandle historyValidationBuffer,
TextureHandle rayCountTexture, ShaderVariablesRaytracing shaderVariablesRaytracing)
Expand All @@ -15,12 +21,14 @@ public TextureHandle RenderRTAO(RenderGraph renderGraph, HDCamera hdCamera,

if (m_RenderPipeline.GetRayTracingState())
{
// Trace the signal
// Evaluate the parameters
AmbientOcclusionTraceParameters aoParameters = PrepareAmbientOcclusionTraceParameters(hdCamera, shaderVariablesRaytracing);
result = TraceAO(renderGraph, aoParameters, depthBuffer, normalBuffer, rayCountTexture);

// Trace the signal
TraceAmbientOcclusionResult traceResult = TraceAO(renderGraph, aoParameters, depthBuffer, normalBuffer, rayCountTexture);

// Denoise if required
result = DenoiseAO(renderGraph, hdCamera, result, depthBuffer, normalBuffer, motionVectors, historyValidationBuffer);
result = DenoiseAO(renderGraph, hdCamera, traceResult, depthBuffer, normalBuffer, motionVectors, historyValidationBuffer);

// Compose the result to be done
AmbientOcclusionComposeParameters aoComposeParameters = PrepareAmbientOcclusionComposeParameters(hdCamera, shaderVariablesRaytracing);
Expand All @@ -40,12 +48,15 @@ class TraceRTAOPassData
public TextureHandle normalBuffer;
public TextureHandle rayCountTexture;
public TextureHandle outputTexture;
public TextureHandle velocityBuffer;
}

TextureHandle TraceAO(RenderGraph renderGraph, in AmbientOcclusionTraceParameters parameters, TextureHandle depthBuffer, TextureHandle normalBuffer, TextureHandle rayCountTexture)
TraceAmbientOcclusionResult TraceAO(RenderGraph renderGraph, in AmbientOcclusionTraceParameters parameters, TextureHandle depthBuffer, TextureHandle normalBuffer, TextureHandle rayCountTexture)
{
using (var builder = renderGraph.AddRenderPass<TraceRTAOPassData>("Tracing the rays for RTAO", out var passData, ProfilingSampler.Get(HDProfileId.RaytracingAmbientOcclusion)))
{
TraceAmbientOcclusionResult traceOutput;

builder.EnableAsyncCompute(false);

passData.parameters = parameters;
Expand All @@ -55,6 +66,8 @@ TextureHandle TraceAO(RenderGraph renderGraph, in AmbientOcclusionTraceParameter
// Depending of if we will have to denoise (or not), we need to allocate the final format, or a bigger texture
passData.outputTexture = builder.WriteTexture(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true)
{ colorFormat = GraphicsFormat.R8_UNorm, enableRandomWrite = true, name = "Ray Traced Ambient Occlusion" }));
passData.velocityBuffer = builder.ReadWriteTexture(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true)
{ colorFormat = GraphicsFormat.R8_SNorm, enableRandomWrite = true, name = "Velocity Buffer" }));

builder.SetRenderFunc(
(TraceRTAOPassData data, RenderGraphContext ctx) =>
Expand All @@ -65,16 +78,19 @@ TextureHandle TraceAO(RenderGraph renderGraph, in AmbientOcclusionTraceParameter
aotResources.normalBuffer = data.normalBuffer;
aotResources.rayCountTexture = data.rayCountTexture;
aotResources.outputTexture = data.outputTexture;
aotResources.velocityBuffer = data.velocityBuffer;

TraceAO(ctx.cmd, data.parameters, aotResources);
});

return passData.outputTexture;
traceOutput.signalBuffer = passData.outputTexture;
traceOutput.velocityBuffer = passData.velocityBuffer;
return traceOutput;
}
}

TextureHandle DenoiseAO(RenderGraph renderGraph, HDCamera hdCamera,
TextureHandle rayTracedAO,
TraceAmbientOcclusionResult traceAOResult,
TextureHandle depthBuffer, TextureHandle normalBuffer, TextureHandle motionVectorBuffer, TextureHandle historyValidationBuffer)
{
var aoSettings = hdCamera.volumeStack.GetComponent<AmbientOcclusion>();
Expand All @@ -87,17 +103,17 @@ TextureHandle DenoiseAO(RenderGraph renderGraph, HDCamera hdCamera,
HDTemporalFilter temporalFilter = m_RenderPipeline.GetTemporalFilter();
TemporalFilterParameters tfParameters = temporalFilter.PrepareTemporalFilterParameters(hdCamera, true, historyValidity);
TextureHandle historyBuffer = renderGraph.ImportTexture(RequestAmbientOcclusionHistoryTexture(hdCamera));
TextureHandle denoisedRTAO = temporalFilter.Denoise(renderGraph, hdCamera, tfParameters, rayTracedAO, historyBuffer, depthBuffer, normalBuffer, motionVectorBuffer, historyValidationBuffer);
TextureHandle denoisedRTAO = temporalFilter.Denoise(renderGraph, hdCamera, tfParameters, traceAOResult.signalBuffer, traceAOResult.velocityBuffer, historyBuffer, depthBuffer, normalBuffer, motionVectorBuffer, historyValidationBuffer);

// Apply the diffuse denoiser
HDDiffuseDenoiser diffuseDenoiser = m_RenderPipeline.GetDiffuseDenoiser();
DiffuseDenoiserParameters ddParams = diffuseDenoiser.PrepareDiffuseDenoiserParameters(hdCamera, true, aoSettings.denoiserRadius, false, false);
rayTracedAO = diffuseDenoiser.Denoise(renderGraph, hdCamera, ddParams, denoisedRTAO, depthBuffer, normalBuffer, rayTracedAO);
traceAOResult.signalBuffer = diffuseDenoiser.Denoise(renderGraph, hdCamera, ddParams, denoisedRTAO, depthBuffer, normalBuffer, traceAOResult.signalBuffer);

return rayTracedAO;
return traceAOResult.signalBuffer;
}
else
return rayTracedAO;
return traceAOResult.signalBuffer;
}

class ComposeRTAOPassData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public struct AmbientOcclusionTraceResources

// Output Buffer
public RTHandle outputTexture;
public RTHandle velocityBuffer;
}

AmbientOcclusionTraceParameters PrepareAmbientOcclusionTraceParameters(HDCamera hdCamera, ShaderVariablesRaytracing raytracingCB)
Expand Down Expand Up @@ -153,6 +154,7 @@ static public void TraceAO(CommandBuffer cmd, AmbientOcclusionTraceParameters ao
// Set the output textures
cmd.SetRayTracingTextureParam(aoTraceParameters.aoShaderRT, HDShaderIDs._RayCountTexture, aoTraceResources.rayCountTexture);
cmd.SetRayTracingTextureParam(aoTraceParameters.aoShaderRT, HDShaderIDs._AmbientOcclusionTextureRW, aoTraceResources.outputTexture);
cmd.SetRayTracingTextureParam(aoTraceParameters.aoShaderRT, HDShaderIDs._VelocityBuffer, aoTraceResources.velocityBuffer);

// Run the computation
cmd.DispatchRays(aoTraceParameters.aoShaderRT, m_RayGenShaderName, (uint)aoTraceParameters.actualWidth, (uint)aoTraceParameters.actualHeight, (uint)aoTraceParameters.viewCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ TextureHandle DenoiseRTGI(RenderGraph renderGraph, HDCamera hdCamera, TextureHan
// Run the temporal denoiser
TemporalFilterParameters tfParameters = temporalFilter.PrepareTemporalFilterParameters(hdCamera, false, historyValidity0);
TextureHandle historyBufferHF = renderGraph.ImportTexture(RequestIndirectDiffuseHistoryTextureHF(hdCamera));
TextureHandle denoisedRTGI = temporalFilter.Denoise(renderGraph, hdCamera, tfParameters, rtGIBuffer, historyBufferHF, depthPyramid, normalBuffer, motionVectorBuffer, historyValidationTexture);
TextureHandle denoisedRTGI = temporalFilter.Denoise(renderGraph, hdCamera, tfParameters, rtGIBuffer, renderGraph.defaultResources.blackTextureXR, historyBufferHF, depthPyramid, normalBuffer, motionVectorBuffer, historyValidationTexture);

// Apply the diffuse denoiser
DiffuseDenoiserParameters ddParams = diffuseDenoiser.PrepareDiffuseDenoiserParameters(hdCamera, false, giSettings.denoiserRadius, giSettings.halfResolutionDenoiser, giSettings.secondDenoiserPass);
Expand All @@ -250,7 +250,7 @@ TextureHandle DenoiseRTGI(RenderGraph renderGraph, HDCamera hdCamera, TextureHan
// Run the temporal denoiser
tfParameters = temporalFilter.PrepareTemporalFilterParameters(hdCamera, false, historyValidity1);
TextureHandle historyBufferLF = renderGraph.ImportTexture(RequestIndirectDiffuseHistoryTextureLF(hdCamera));
denoisedRTGI = temporalFilter.Denoise(renderGraph, hdCamera, tfParameters, rtGIBuffer, historyBufferLF, depthPyramid, normalBuffer, motionVectorBuffer, historyValidationTexture);
denoisedRTGI = temporalFilter.Denoise(renderGraph, hdCamera, tfParameters, rtGIBuffer, renderGraph.defaultResources.blackTextureXR, historyBufferLF, depthPyramid, normalBuffer, motionVectorBuffer, historyValidationTexture);

// Apply the diffuse denoiser
ddParams = diffuseDenoiser.PrepareDiffuseDenoiserParameters(hdCamera, false, giSettings.denoiserRadius * 0.5f, giSettings.halfResolutionDenoiser, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class TemporalFilterPassData
}

public TextureHandle Denoise(RenderGraph renderGraph, HDCamera hdCamera, TemporalFilterParameters tfParameters,
TextureHandle noisyBuffer, TextureHandle historyBuffer,
TextureHandle noisyBuffer, TextureHandle velocityBuffer,
TextureHandle historyBuffer,
TextureHandle depthBuffer, TextureHandle normalBuffer, TextureHandle motionVectorBuffer, TextureHandle historyValidationBuffer)
{
using (var builder = renderGraph.AddRenderPass<TemporalFilterPassData>("TemporalDenoiser", out var passData, ProfilingSampler.Get(HDProfileId.TemporalFilter)))
Expand All @@ -86,7 +87,7 @@ public TextureHandle Denoise(RenderGraph renderGraph, HDCamera hdCamera, Tempora
passData.motionVectorBuffer = builder.ReadTexture(motionVectorBuffer);

// Effect buffers
passData.velocityBuffer = renderGraph.defaultResources.blackTextureXR;
passData.velocityBuffer = builder.ReadTexture(velocityBuffer);
passData.noisyBuffer = builder.ReadTexture(noisyBuffer);
passData.validationBuffer = builder.ReadTexture(historyValidationBuffer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ TEXTURE2D_X(_DepthTexture);

// Output structure of the reflection raytrace shader
RW_TEXTURE2D_X(float, _AmbientOcclusionTextureRW);
RW_TEXTURE2D_X(float, _VelocityBuffer);

[shader("miss")]
void MissShaderAmbientOcclusion(inout RayIntersection rayIntersection : SV_RayPayload)
Expand Down Expand Up @@ -66,7 +67,7 @@ void RayGenAmbientOcclusion()

// Variable that accumulate the radiance
float finalColor = 0.0;

float velocity = 0.0f;
// Let's loop through th e samples
for (int i = 0; i < numSamples; ++i)
{
Expand Down Expand Up @@ -98,8 +99,9 @@ void RayGenAmbientOcclusion()

// Evaluate the ray intersection
TraceRay(_RaytracingAccelerationStructure, RAY_FLAG_CULL_BACK_FACING_TRIANGLES, RAYTRACINGRENDERERFLAG_AMBIENT_OCCLUSION, 0, 1, 0, rayDescriptor, rayIntersection);

// Accumulate this value
velocity = max(velocity, rayIntersection.velocity);
finalColor += rayIntersection.color.x;
}

Expand All @@ -108,6 +110,7 @@ void RayGenAmbientOcclusion()

// Alright we are done
_AmbientOcclusionTextureRW[COORD_TEXTURE2D_X(currentPixelCoord)] = finalColor;
_VelocityBuffer[COORD_TEXTURE2D_X(currentPixelCoord)] = velocity;
}

// Fallback default any hit shader for this raytrace shader
Expand Down