I have 6 Cameras in my world I need to grab the depth buffer from them.
I am literally only interested in the Depth buffer of the cameras, no effects, no lighting, just opaque objects that the camera can see.
What process do I need to render the cameras, and then:
a) Put it inside a Render Texture
b) Use it in shader graph to render custom view of the scene based on the Depth?
I did it this way.
Make sure your cameras are disabled
And i am not sure about right clear flags (color, depth) on custom pass
Make custom pass script and add it to your custom pass volume
class DepthToRTCustomPass : CustomPass
{
[SerializeField] private LayerMask _layerMask = ~0;
[SerializeField] private RenderTexture[] _depthRenderTextures;
[SerializeField] private Camera[] _camera;
protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
{
}
protected override void Execute(CustomPassContext ctx)
{
if (ctx.hdCamera.camera.cameraType == CameraType.SceneView)
return;
for (int i = 0; i < _camera.Length; i++)
{
if (_camera[i] == null) continue;
// Culling
_camera[i].TryGetCullingParameters(out var cullingParameters);
var cullingResults = ctx.renderContext.Cull(ref cullingParameters);
ctx.cullingResults = cullingResults;
// Depth state
var depthTestOverride = new RenderStateBlock(RenderStateMask.Depth)
{
depthState = new DepthState(true, CompareFunction.LessEqual),
};
if (_depthRenderTextures[i] != null)
{
CustomPassUtils.RenderDepthFromCamera(ctx,
_camera[i],
_depthRenderTextures[i],
clearFlags,
_layerMask,
RenderQueueType.All,
depthTestOverride);
}
}
}
}