Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Sample motion vectors in a shader in URP

Request the motion vector texture as an input in a custom shader.
Read time 1 minuteLast updated 23 days ago

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.