Search Unity

MotionVector texture outputs in pixel domain

Discussion in 'Shaders' started by liangyw, Mar 15, 2019.

  1. liangyw

    liangyw

    Joined:
    Sep 29, 2016
    Posts:
    7
    Dear all

    I am new to Unity development. I have a question regarding the _CameraMotionVectorsTexture outputs. For example, partial of my shader fragment code to sample and convert the motion vector texture:
    Code (CSharp):
    1. float2 motion = tex2D(_CameraMotionVectorsTexture, i.uv).rg;
    2. motion = motion * _CameraMotionVectorsTexture_TexelSize.zw
    From Unity documentation, e.g. https://docs.unity3d.com/ScriptReference/DepthTextureMode.MotionVectors.html, the output should be the object movement on the projected image in pixel domain from frame t to frame t+1. However, the result does not seem right after I manually check the pixel movements (see below)

    For example, I have a ball moving from right to left, and the ball's x coordinates change from 1088 to 1047, and the difference is 41 pixels. However, on my motion vector map, I have a result of 101.6 pixels instead. there is a huge differences.

    projected image frame t:
    upload_2019-3-15_10-56-8.png


    projected image frame t+1:
    upload_2019-3-15_10-53-3.png


    motionvector map at frame t+1:
    upload_2019-3-15_10-54-30.png


    I am wondering if my conversion is right? Or am I missing something here?

    If needed, I can post all the codes here.

    Thank you everyone!
     
  2. liangyw

    liangyw

    Joined:
    Sep 29, 2016
    Posts:
    7
    I resolved the issue. During set up, both depth and motionvectors for camera depth needs to be enabled. Thank you!
     
    yonng666 likes this.