Search Unity

Question _CameraMotionVectorsTexture meaning/definition

Discussion in 'Shaders' started by alien13mars, Nov 23, 2022.

  1. alien13mars

    alien13mars

    Joined:
    Nov 2, 2022
    Posts:
    4
    Hey, does anyone know how exactly _CameraMotionVectorsTexture is defined?
    If I do
    Code (CSharp):
    1. tex2D(_CameraMotionVectorsTexture,In.uv);
    which channel decodes the motion in x-direction? Which for the y-direction?
    In which range are the numbers decoded?

    From my experiments I determined the following:
    - g-channel decode movement in x-direction
    - r-channel decodes movement in y-direction
    - they numbers probably range from -1 to 1 for each direction. However, they are very small! Without scaling them by a factor of at least 1000 they are bascially useless.

    Are those oberservation correct?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    AFAIK the built in rendering path stores the values as:
    red channel = x direction in screen UV space.
    green channel = y direction in screen UV space.
    This means a value of 1.0 (or -1.0) in either means the object moved the width or height of the screen between the previous frame and current frame.

    The SRPs appear to use the same rg = xy, but stored so you have to do rg * 2.0 - 1.0 to get the UV range, and clamped to be between -1.0 and 1.0 after decoding, where as the built in pipeline doesn't clamp the values.
     
    alien13mars likes this.
  3. alien13mars

    alien13mars

    Joined:
    Nov 2, 2022
    Posts:
    4
    Thank you for your answer! This clears it up for me!