diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index f26bc0fb3ad..19ccfc215da 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -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 diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/SubsurfaceScattering/SubsurfaceScatteringManagerRT.cs b/com.unity.render-pipelines.high-definition/Runtime/Material/SubsurfaceScattering/SubsurfaceScatteringManagerRT.cs index 1e21f69edb2..a88b899457f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/SubsurfaceScattering/SubsurfaceScatteringManagerRT.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/SubsurfaceScattering/SubsurfaceScatteringManagerRT.cs @@ -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 diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingAmbientOcclusion.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingAmbientOcclusion.RenderGraph.cs index 3c2f543e057..c635856d362 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingAmbientOcclusion.RenderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingAmbientOcclusion.RenderGraph.cs @@ -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) @@ -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); @@ -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("Tracing the rays for RTAO", out var passData, ProfilingSampler.Get(HDProfileId.RaytracingAmbientOcclusion))) { + TraceAmbientOcclusionResult traceOutput; + builder.EnableAsyncCompute(false); passData.parameters = parameters; @@ -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) => @@ -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(); @@ -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 diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingAmbientOcclusion.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingAmbientOcclusion.cs index 84525a3125a..6629e540bf6 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingAmbientOcclusion.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingAmbientOcclusion.cs @@ -72,6 +72,7 @@ public struct AmbientOcclusionTraceResources // Output Buffer public RTHandle outputTexture; + public RTHandle velocityBuffer; } AmbientOcclusionTraceParameters PrepareAmbientOcclusionTraceParameters(HDCamera hdCamera, ShaderVariablesRaytracing raytracingCB) @@ -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); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingIndirectDiffuse.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingIndirectDiffuse.RenderGraph.cs index c5bdc37a58d..17abee3f05c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingIndirectDiffuse.RenderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingIndirectDiffuse.RenderGraph.cs @@ -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); @@ -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); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDTemporalFilter.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDTemporalFilter.RenderGraph.cs index 684f0d76e49..14d7d5cf3b5 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDTemporalFilter.RenderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDTemporalFilter.RenderGraph.cs @@ -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("TemporalDenoiser", out var passData, ProfilingSampler.Get(HDProfileId.TemporalFilter))) @@ -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); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingAmbientOcclusion.raytrace b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingAmbientOcclusion.raytrace index f1be448e6e9..15a66abcd10 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingAmbientOcclusion.raytrace +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingAmbientOcclusion.raytrace @@ -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) @@ -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) { @@ -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; } @@ -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