First, I wanted to thank @antoinel_unity for the extremely helpful CustomPass examples repository. It’s been very useful as I’ve been learning the CustomPass and HDRP APIs.
I’m currently using 2019.3.9f1 with HDRP 7.3.1.
I’ve been trying to work on an effect extending from the repository’s depth capture example, where I’d like to capture the depth buffer and motion vectors for a separate camera that’s not being rendered to screen. I’m running into the following roadblocks:
- When a MeshRenderer is using tessellation, such as HDRP’s
LayeredLitTessellation
Material, the Frame Debug window shows that object being is being rendered during the CustomPass, using theDepthOnly
pass, but the depth texture is unchanged. TheINSTANCING_ON
keyword is set, and settings in the Frame Debug window seem similar to those in the standardDepthPrepassDeferredForDecals
pass, which of course correctly captures the depth.
Note that using aLit
override material when setting up theRendererListDesc
will cause the object to be rendered correctly, though the depth will not match that of the true tessellated version. Additionally, I can reproduce the same behaviour in the repository’s depth capture example. - I’m trying to render MotionVectors from the same camera, but calling
HDUtils.DrawRendererList
doesn’t cause any objects to be rendered (even usingLit
material, irrespective of tessellation).
MeshRenderers
haveMotion Vectors
set toPer Object Motion
.
I’ll try to summarize the relevant code snippets here.
For the camera setup, I ensure the depthTextureMode is set, though this doesn’t seem to make a difference.
_bakingCamera.depthTextureMode |= DepthTextureMode.Depth | DepthTextureMode.MotionVectors;
For the depth pass, setup is the same as the repository’s example:
_bakingCamera.TryGetCullingParameters(out ScriptableCullingParameters cullingParams);
cullingParams.cullingOptions = CullingOptions.ShadowCasters;
cullingParams.cullingMask = (uint)_layerMask.value;
cullingResult = renderContext.Cull(ref cullingParams);
The same is true to the capture during Execute
:
var heightRendererListDesc = new RendererListDesc(_depthShaderTags, cullingResult, _bakingCamera)
{
rendererConfiguration = PerObjectData.None,
renderQueueRange = RenderQueueRange.all,
sortingCriteria = SortingCriteria.BackToFront,
excludeObjectMotionVectors = false,
stateBlock = new RenderStateBlock(RenderStateMask.Raster) { rasterState = new RasterState(depthClip: false) },
};
CoreUtils.SetRenderTarget(cmd, _depthBakeBuffer, ClearFlag.Depth);
HDUtils.DrawRendererList(renderContext, cmd, RendererList.Create(heightRendererListDesc));
For the motion vectors pass, I tried to use the same GraphicsFormat (RG16) that it seems Unity normally uses:
motionVectorsBuffer = RTHandles.Alloc(_depthCaptureTexture.width, _depthCaptureTexture.height, colorFormat: GraphicsFormat.R16G16_SFloat, depthBufferBits: DepthBits.None, dimension: TextureDimension.Tex2D, name: "Motion Vectors");
_motionVectorsShaderTags = new ShaderTagId[2]
{
new ShaderTagId("MotionVectors"),
new ShaderTagId("Motion Vectors"),
};
Then, during Execute
:
var motionVectorRendererListDesc = new RendererListDesc(_motionVectorsShaderTags, cullingResult, _bakingCamera)
{
rendererConfiguration = PerObjectData.MotionVectors,
renderQueueRange = RenderQueueRange.all,
sortingCriteria = SortingCriteria.BackToFront,
excludeObjectMotionVectors = false,
};
CoreUtils.SetRenderTarget(cmd, _motionVectorsBuffer, ClearFlag.All);
RendererList motionVectorsRendererList = RendererList.Create(motionVectorRendererListDesc);
HDUtils.DrawRendererList(renderContext, cmd, motionVectorsRendererList);
The cullingResult
is the same as for the depth pass, though no objects are rendered, even the ones that appear in the depth pass.
Any help or advice would be greatly appreciated!