68 lines
2.3 KiB
C#
68 lines
2.3 KiB
C#
#if ENABLE_VR && ENABLE_XR_MODULE
|
|
using UnityEngine.Experimental.Rendering.RenderGraphModule;
|
|
using UnityEngine.Experimental.Rendering;
|
|
|
|
namespace UnityEngine.Rendering.Universal
|
|
{
|
|
/// <summary>
|
|
/// Draw the XR occlusion mesh into the current depth buffer when XR is enabled.
|
|
/// </summary>
|
|
public class XROcclusionMeshPass : ScriptableRenderPass
|
|
{
|
|
PassData m_PassData;
|
|
|
|
public XROcclusionMeshPass(RenderPassEvent evt)
|
|
{
|
|
base.profilingSampler = new ProfilingSampler(nameof(XROcclusionMeshPass));
|
|
renderPassEvent = evt;
|
|
m_PassData = new PassData();
|
|
base.profilingSampler = new ProfilingSampler("XR Occlusion Pass");
|
|
}
|
|
|
|
private static void ExecutePass(ScriptableRenderContext context, ref RenderingData renderingData)
|
|
{
|
|
var cmd = renderingData.commandBuffer;
|
|
|
|
if (renderingData.cameraData.xr.hasValidOcclusionMesh)
|
|
{
|
|
renderingData.cameraData.xr.RenderOcclusionMesh(cmd);
|
|
context.ExecuteCommandBuffer(cmd);
|
|
cmd.Clear();
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
|
|
{
|
|
ExecutePass(context, ref renderingData);
|
|
}
|
|
|
|
private class PassData
|
|
{
|
|
internal RenderingData renderingData;
|
|
internal TextureHandle cameraDepthAttachment;
|
|
}
|
|
|
|
internal void Render(RenderGraph renderGraph, in TextureHandle cameraDepthAttachment, ref RenderingData renderingData)
|
|
{
|
|
using (var builder = renderGraph.AddRenderPass<PassData>("XR Occlusion Pass", out var passData, base.profilingSampler))
|
|
{
|
|
passData.renderingData = renderingData;
|
|
passData.cameraDepthAttachment = builder.UseDepthBuffer(cameraDepthAttachment, DepthAccess.Write);
|
|
|
|
// TODO RENDERGRAPH: culling? force culling off for testing
|
|
builder.AllowPassCulling(false);
|
|
|
|
builder.SetRenderFunc((PassData data, RenderGraphContext context) =>
|
|
{
|
|
ExecutePass(context.renderContext, ref data.renderingData);
|
|
});
|
|
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif
|