Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Camera motion vectors texture no longer accessible

Discussion in 'High Definition Render Pipeline' started by three-ms-creative, May 18, 2021.

  1. three-ms-creative

    three-ms-creative

    Joined:
    May 5, 2021
    Posts:
    10
    Hey everyone. In my asset's most recent update, I started using the camera motion vectors texture for some temporal reprojection to render volumetrics. I sample the global _CameraMotionVectorsTexture variable from a custom compute shader that's called from the custom sky "RenderSky()" function---so after the opaque geometry is rendered.

    Specifically, the sampling code looks like:

    Code (CSharp):
    1. float2 motionVector = 0;
    2.        
    3. DecodeMotionVector(LOAD_TEXTURE2D_X(_CameraMotionVectorsTexture, positionCS.xy), motionVector);

    In 2020.1.17 this worked fine. However, in 2020.3+, I get an error saying _CameraMotionVectorsTexture has not been set. This is weird, isn't this a shader global that gets set in the opaque pass? Why wouldn't it be set when rendering the sky?

    What changed---why does this work in 2020.1 but not in 2020.3? Does anyone know how to sample from the motion vectors texture from an arbitrary compute shader for 2020.3+?
     
  2. merpheus

    merpheus

    Joined:
    Mar 5, 2013
    Posts:
    198
    +1 on this post. This happens when rendergraph is enabled. Apparently, rendergraph code doesn't expose motion vector texture to custom effects.

    An alternative is to have a custom pass to calculate motion vectors. @antoinel_unity have a custom pass samples repo on github afaik. But I should ask, why can't unity patch this and give access to custom effects?
     
  3. three-ms-creative

    three-ms-creative

    Joined:
    May 5, 2021
    Posts:
    10
    Cool, glad to see that someone else ran into this issue. I ended up writing a quick regular vertex/fragment shader to copy the motion vectors into another render texture---then I use that copy in my compute shader. It's not a pretty workaround but the performance hit is like 6 microseconds and it works.
     
  4. merpheus

    merpheus

    Joined:
    Mar 5, 2013
    Posts:
    198
    Like you calculate custom motion vectors for all of your meshes, that might work but how for custom drawn stuff but what about regular meshes? For example, I was writing an SSR post effect and accessing to MotionVectors was kinda tricky
     
  5. DenizCetinalp

    DenizCetinalp

    Joined:
    Feb 8, 2014
    Posts:
    16
    Is there a comment from Unity on this? Will this be fixed?
     
  6. merpheus

    merpheus

    Joined:
    Mar 5, 2013
    Posts:
    198
    This is fixed dude, on latest 2021 beta, it should be merged to master.
     
  7. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    236