diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 08b3bc385dd..460ca19a630 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -805,6 +805,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Increased path tracing BSDFs roughness range from [0.001, 0.999] to [0.00001, 0.99999]. - Changing the default SSGI radius for the all configurations. - Changed the default parameters for quality RTGI to match expected behavior. +- Add color clear pass while rendering XR occlusion mesh to avoid leaks. ## [7.1.1] - 2019-09-05 diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Prepass.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Prepass.cs index 240e0087e09..ebaed2ee4da 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Prepass.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Prepass.cs @@ -115,7 +115,8 @@ PrepassOutput RenderPrepass(RenderGraph renderGraph, TextureHandle sssBuffer, Cu result.motionVectorsBuffer = CreateMotionVectorBuffer(renderGraph, msaa, clearMotionVectors); result.depthBuffer = CreateDepthBuffer(renderGraph, msaa); - RenderXROcclusionMeshes(renderGraph, hdCamera, result.depthBuffer); + // TODO RENDERGRAPH : XR occlusion mesh also need to write to color buffer + //RenderXROcclusionMeshes(renderGraph, hdCamera, result.depthBuffer); using (new XRSinglePassScope(renderGraph, hdCamera)) { diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraphUtils.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraphUtils.cs index 1b351d1df5b..61d7461365c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraphUtils.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraphUtils.cs @@ -143,7 +143,8 @@ void RenderXROcclusionMeshes(RenderGraph renderGraph, HDCamera hdCamera, Texture builder.SetRenderFunc( (RenderOcclusionMeshesPassData data, RenderGraphContext ctx) => { - data.hdCamera.xr.RenderOcclusionMeshes(ctx.cmd, ctx.resources.GetTexture(data.depthBuffer)); + // TODO RENDERGRAPH : XR occlusion mesh also need to write to color buffer + //data.hdCamera.xr.RenderOcclusionMeshes(ctx.cmd, ctx.resources.GetTexture(data.depthBuffer)); }); } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index ab1480b7f54..4f56015b84c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -2351,8 +2351,11 @@ AOVRequestData aovRequest // Render XR occlusion mesh to depth buffer early in the frame to improve performance if (hdCamera.xr.enabled && m_Asset.currentPlatformRenderPipelineSettings.xrSettings.occlusionMesh) { + bool msaa = hdCamera.frameSettings.IsEnabled(FrameSettingsField.MSAA); + Color clearColor = GetColorBufferClearColor(hdCamera); + hdCamera.xr.StopSinglePass(cmd); - hdCamera.xr.RenderOcclusionMeshes(cmd, m_SharedRTManager.GetDepthStencilBuffer(hdCamera.frameSettings.IsEnabled(FrameSettingsField.MSAA))); + hdCamera.xr.RenderOcclusionMeshes(cmd, clearColor, msaa ? m_CameraColorMSAABuffer : m_CameraColorBuffer, m_SharedRTManager.GetDepthStencilBuffer(msaa)); hdCamera.xr.StartSinglePass(cmd); } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs index f0e646378ac..368fc11c7ea 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs @@ -186,6 +186,7 @@ static class HDShaderIDs public static readonly int _InputDepth = Shader.PropertyToID("_InputDepthTexture"); + public static readonly int _ClearColor = Shader.PropertyToID("_ClearColor"); public static readonly int _SrcBlend = Shader.PropertyToID("_SrcBlend"); public static readonly int _DstBlend = Shader.PropertyToID("_DstBlend"); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/XR/XRPass.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/XR/XRPass.cs index 40a635b4a39..c6d53e39e57 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/XR/XRPass.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/XR/XRPass.cs @@ -255,7 +255,7 @@ internal void EndCamera(CommandBuffer cmd, HDCamera hdCamera) } } - internal void RenderOcclusionMeshes(CommandBuffer cmd, RTHandle depthBuffer) + internal void RenderOcclusionMeshes(CommandBuffer cmd, Color clearColor, RTHandle colorBuffer, RTHandle depthBuffer) { if (enabled && xrSdkEnabled && occlusionMeshMaterial != null) { @@ -267,7 +267,8 @@ internal void RenderOcclusionMeshes(CommandBuffer cmd, RTHandle depthBuffer) { if (views[viewId].occlusionMesh != null) { - CoreUtils.SetRenderTarget(cmd, depthBuffer, ClearFlag.None, 0, CubemapFace.Unknown, viewId); + CoreUtils.SetRenderTarget(cmd, colorBuffer, depthBuffer, ClearFlag.None, clearColor, 0, CubemapFace.Unknown, viewId); + cmd.SetGlobalVector(HDShaderIDs._ClearColor, clearColor); cmd.DrawMesh(views[viewId].occlusionMesh, m, occlusionMeshMaterial); } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/XROcclusionMesh.shader b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/XROcclusionMesh.shader index 05730dc8889..e6f68e75096 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/XROcclusionMesh.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/XROcclusionMesh.shader @@ -23,8 +23,11 @@ Shader "Hidden/HDRP/XROcclusionMesh" return output; } - void Frag(out float outputDepth : SV_Depth) + float4 _ClearColor; + + void Frag(out float4 outputColor : SV_Target, out float outputDepth : SV_Depth) { + outputColor = _ClearColor; outputDepth = UNITY_NEAR_CLIP_VALUE; } ENDHLSL @@ -36,7 +39,6 @@ Shader "Hidden/HDRP/XROcclusionMesh" Pass { ZWrite On ZTest Always Blend Off Cull Off - ColorMask 0 HLSLPROGRAM #pragma vertex Vert