Skip to content

Add color clear pass while rendering XR occlusion mesh to avoid leaks #688

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 2 commits into from
Jun 11, 2020
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 @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,7 +39,6 @@ Shader "Hidden/HDRP/XROcclusionMesh"
Pass
{
ZWrite On ZTest Always Blend Off Cull Off
ColorMask 0

HLSLPROGRAM
#pragma vertex Vert
Expand Down