Version: Unity 6.0 (6000.0)
Language : English
Output a motion vector texture in a custom shader in URP
Troubleshooting motion vectors in URP

Sample motion vectors in a shader in URP

Any ScriptableRenderPass implementation can request the motion vector texture as input. To do that, add the ScriptableRenderPassInput.Motion flag in the ScriptableRenderPass.ConfigureInput method in the AddRenderPasses callback of your custom Renderer Feature. If no other effect in the frame is using motion vectors, setting this input flag forces the URP renderer to inject the motion vector render pass into the frame.

To sample the motion vector texture in your shader pass, declare the shader resource for it in the HLSLPROGRAM section:

    TEXTURE2D_X(_MotionVectorTexture);
    SAMPLER(sampler_MotionVectorTexture);

To perform the sampling, use the following macro:

    SAMPLE_TEXTURE2D_X(_MotionVectorTexture, sampler_MotionVectorTexture, uv);

The _X postfix ensures that the texture is correctly declared and sampled when targeting XR platforms.

Output a motion vector texture in a custom shader in URP
Troubleshooting motion vectors in URP