Search Unity

Bug Custom Motion Vectors not working with Indirect Rendering after 2022.2.0b3

Discussion in 'High Definition Render Pipeline' started by MattCarr, Dec 30, 2022.

  1. MattCarr

    MattCarr

    Joined:
    Jul 5, 2009
    Posts:
    339
    Edit (6 March 2023): I resubmitted the bug and found out that the original was indeed mishandled in the backend. This time it has a working Issue Tracker link here: https://issuetracker.unity3d.com/is...k-when-rendering-a-custom-shader-procedurally

    Ever since 2022.2.0b4 I found that when rendering with Graphics.RenderMeshIndirect, Graphics.RenderPrimitivesIndexedIndirect or any of the similar methods, I couldn't use custom motion vectors which had previously worked fine in 2022.2.0b3 and earlier.

    I submitted a bug about this a few months ago but nothing has happened with that (internal bug ID UUM-14912. Issue tracker link is supposed to be https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-14912 but it doesn't work).

    I've created a basic project demonstrating the issue. In the project I've made a Shader Graph shader that takes a custom motion vector and I had motion blur on to make it easy to see. I have a standard MeshFilter/MeshRenderer cube rendered with a material using that shader that has the correct motion vectors in Unity 2022.2.0b3 and in the latest version 2022.2.1f1, and then I render another cube below it with the same material using Graphics.RenderMeshIndirect which has the correct motion vectors in 2022.2.0b3 but no motion vectors in 2022.2.1f1.

    Here is an image showing the results from both versions and the Shader Graph shader.
    MotionVectorBug.png

    Here is the code used to draw the cube using Graphics.RenderMeshIndirect.
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Rendering;
    3.  
    4. public class BasicRenderCube : MonoBehaviour
    5. {
    6.     public Material material;
    7.     public Mesh mesh;
    8.  
    9.     GraphicsBuffer commandBuf;
    10.     GraphicsBuffer.IndirectDrawIndexedArgs[] commandData;
    11.     const int commandCount = 1;
    12.  
    13.     void Start()
    14.     {
    15.         commandBuf = new GraphicsBuffer(GraphicsBuffer.Target.IndirectArguments, commandCount, GraphicsBuffer.IndirectDrawIndexedArgs.size);
    16.         commandData = new GraphicsBuffer.IndirectDrawIndexedArgs[commandCount];
    17.     }
    18.  
    19.     void OnDestroy()
    20.     {
    21.         commandBuf?.Release();
    22.         commandBuf = null;
    23.     }
    24.  
    25.     void Update()
    26.     {
    27.         RenderParams rp = new RenderParams(material);
    28.         rp.worldBounds = new Bounds(Vector3.zero, 10000*Vector3.one);
    29.         rp.matProps = new MaterialPropertyBlock();
    30.         rp.matProps.SetMatrix("_ObjectToWorld", Matrix4x4.Translate(new Vector3(0.0f, -2.0f, 0)));
    31.         rp.motionVectorMode = MotionVectorGenerationMode.Object;
    32.         rp.shadowCastingMode = ShadowCastingMode.On;
    33.         commandData[0].indexCountPerInstance = mesh.GetIndexCount(0);
    34.         commandData[0].instanceCount = 1;
    35.         commandBuf.SetData(commandData);
    36.         Graphics.RenderMeshIndirect(rp, mesh, commandBuf, commandCount);
    37.     }
    38. }
    I have tried variations of different options for the shader and material related to motion vectors with no change.

    My expectation is that
    Code (CSharp):
    1. rp.motionVectorMode = MotionVectorGenerationMode.Object;
    is no longer working correctly or hopefully I've missed some new hidden setting that wasn't in the update notes.

    I can provide the project or additional information if needed. This is preventing us from getting off of 2022.2.0b3 so I'm hoping to get some eyes on the issue so it can be fixed if there's a problem.

    Edit (6 March 2023): I resubmitted the bug and found out that the original was indeed mishandled in the backend. This time it has a working Issue Tracker link here: https://issuetracker.unity3d.com/is...k-when-rendering-a-custom-shader-procedurally
     
    Last edited: Mar 17, 2023
  2. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    Unfortunately, I don't have a solution, but worth pointing out that unity's own terrain uses indirect instancing, and they don't have motion vector support. (Even though unity themselves recently added an API to do just that).

    Hopefully both issues are resolved. TAA struggles without motion vectors.

    Have you received no reply at all? Getting bugs through QA is a struggle, but it shouldn't usually take months for a review.
     
  3. MattCarr

    MattCarr

    Joined:
    Jul 5, 2009
    Posts:
    339
    I don't think it's a technical issue as they've supported it and included the object votion vector support options in the Graphics.RenderXIndirect methods for this purpose, but there were some changes between Beta 3 and Beta 4 that I think accidentally caused this bug.

    I submitted 2 similar bugs around the same time and both were approved and one was reviewed and resolved relatively quickly but this bug seems to have maybe had some error in their system because the issue tracker URL doesn't work. It's in a confirmed state from QA and passed on, but I don't think anything further has happened with it since the 22nd of August.

    I don't really want to assume the bug report is bugged and submit the same bug again so I was hoping by posting here a Unity dev could see this here and look into the existing bug. I guess I'll wait a little longer and then just submit the bug again if nothing happens...
     
    Last edited: Jan 4, 2023
  4. Kasperrr

    Kasperrr

    Joined:
    Feb 23, 2019
    Posts:
    13
    Hey, @MattCarr

    Did you manage to solve it? I have the same problem on 2022.3.12f1
     
  5. MattCarr

    MattCarr

    Joined:
    Jul 5, 2009
    Posts:
    339
  6. Kasperrr

    Kasperrr

    Joined:
    Feb 23, 2019
    Posts:
    13
    Thanks. Actually just test it with Graphics.RenderMeshIndirect() and works well. Idk why thought that they may fix or somehow adapt it also for:
    Graphics.DrawMeshInstancedIndirect()
     
  7. MattCarr

    MattCarr

    Joined:
    Jul 5, 2009
    Posts:
    339
    I'm using Graphics.RenderPrimitivesIndexedIndirect and it was working once the bug was fixed. You'll need to use Graphics.RenderMeshIndirect instead of Graphics.DrawMeshInstancedIndirect because the Graphics.Render* methods are the newer versions of Graphics.Draw* methods that give more options like taking the RenderParams struct that has the motionVectorMode you can set to Object.
     
    Kasperrr likes this.