I set up a full screen Custom Post Process Volume to dump the depth and motion vectors info into a texture, but I keep getting zero values for the motion vectors.
I did activate “Motion Vectors” (and “Opaque Objects”) in the Renderer Asset (and in the “Frame” settings).
Also, in my CustomPostProcessVolumeComponent
class I test if the camera is capable of computing motion vectors:
public override void Render(CommandBuffer cmd, HDCamera camera, RTHandle source, RTHandle destination)
{
m_ColorMaterial.SetTexture("_InputTexture", source);
cmd.Blit(source.rt, colorRT, m_ColorMaterial);
if (!camera.frameSettings.IsEnabled(FrameSettingsField.ObjectMotionVectors) ||
!camera.frameSettings.IsEnabled(FrameSettingsField.OpaqueObjects))
{
Debug.LogError("Motion vectors not enabled for current camera");
return;
}
if (!camera.frameSettings.IsEnabled(FrameSettingsField.DepthOfField))
{
Debug.LogError("Depth of field not enabled for current camera.");
return;
}
m_DepthMotionMaterial.SetTexture("_InputTexture", source);
cmd.Blit(source.rt, depthMotionRT, m_DepthMotionMaterial);
}
The first Blit works like a charm and dumps the Color Texture correctly.
The second Blit dumps the correct depth values, but I keep getting (0,0) in my motion vector data.
And here is a snippet of my DepthMotion
shader:
float4 FullScreenPass(Varyings varyings) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(varyings);
float depth = LoadCameraDepth(varyings.positionCS.xy);
depth = Linear01Depth(depth, _ZBufferParams);
float2 motion = LOAD_TEXTURE2D_X_LOD(_CameraMotionVectorsTexture, varyings.positionCS.xy,0).rg;
return float4(depth,motion.x, motion.y,1);
}
What am I missing?
FYI, I’m using HDRP 10.5.0 and Unity 2020.3.9f1.