Search Unity

Bug Motion Vectors not working with Graphics.RenderMeshInstanced?

Discussion in 'Universal Render Pipeline' started by bluescrn, Nov 15, 2022.

  1. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    In older version of 2021.3, it was silently failing to render object motion vectors for RenderMeshInstanced() objects, but in 2021.3.12f1, I'm seeing an error:

    "DrawMeshInstanced does not support the shader 'Universal Render Pipeline/Lit' because it does not read any instanced properties. Try switching to DrawMeshInstancedProcedural if the shader is doing procedural instancing."

    Is there any workaround for this? - It looks like it's supposed to be using a separate shader (Hidden/kMotion/ObjectMotionVectors) for the motion vector pass, not a pass within the lit shader - is that correct?

    (I need the motion vectors to be there as I'm using a 3rd-party TAA solution, and my rotating instanced meshes look very smeared without them)

    A related issue/bug - When looking in Frame Debugger, I can't see any object motion vectors being rendered, only one draw call for the camera motion vectors? (To see what's going on, I'm having to render the motion vectors texture to the screen, or use RenderDoc)
     
  2. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    Hmm, I think I've got it working now by adding a "LightMode"="MotionVectors" pass to the shader (now a custom shader based on the URP Lit shader), with that pass essentially containing the contents of ObjectMotionVectors.shader. Setting that shader as a fallback didn't seem to work.

    I'd have expected the standard URP lit shader to work 'out of the box' though, as it works with motion vectors in other cases, just not this RenderMeshInstanced case.

    With that pass in, the frame debugger does now show up the instanced draw calls in the motion vectors pass

    Also noticed that that specific error pops up a few times when the shader is compiling in the Unity version I'd been using, (I'm also using RenderMeshInstanced in edit mode), which added to the confusion while investigating this.