Motion Vector is broken for entities

Hello. I want TAA to be applied to things drawn as Entities.
However, I found that, unlike regular game objects, TAA is not properly applied to things drawn as entities.
(*TAA works fine with regular game objects)

9905760--1431156--capture.gif

This problem appears to be the same as the post:

As mentioned by the poster above,

I tried enabling RenderGraph, but it had no effect.
(*I don’t know if this is the right way)
9905760--1431159--enablerendergraph.png

How to reproduce:

  1. Create a new project: ‘Universal 3D’ with Unity 2022.3.21f
  2. Install packages:
    com.unity.entities: 1.3.0-exp.1 (1.2 also tried)
    com.unity.entities.graphics: 1.3.0-exp.1 (1.2 also tried)
  3. Copy the ecs sample ‘HelloCube’ folder from here:
    EntityComponentSystemSamples/EntitiesSamples/Assets/HelloCube at master · Unity-Technologies/EntityComponentSystemSamples · GitHub
  4. Open the ‘HelloCube_Prefabs’ scene in ‘4. Prefabs’ folder
  5. Turn on TAA settings (check Post Processing and select TAA on Anti-aliasing) on Main Camera
  6. Edit URP-HighFidelity.asset: Set ‘Anti Aliasing (MSAA)’ as Disable (to enable TAA)
  7. Edit the ‘OnUpdate’ function in ‘FallAndDestroySystem.cs’ in ‘4. Prefabs’ folder:
    (*This process is not necessary, but it is to make it easier to visually check)
public void OnUpdate(ref SystemState state)
{
    foreach (var (transform, speed) in
             SystemAPI.Query<RefRW<LocalTransform>, RefRO<RotationSpeed>>())
    {
        transform.ValueRW = transform.ValueRO.RotateY(0f); // Just set it without any changes
    }
}
  1. Play the game, then you can see cubes jittering and wrong motion vector texture in Frame Debugger:
    (*It seems to always draw the value of the current position regardless of movement)

What I checked:

  1. If the entity’s transform is not set (in current frame), motion vector is not drawn.
  2. Even if the set transform is exactly the same as before, when the entity’s transform is set (in current frame), motion vector is drawn.

In the project I’m currently working on, I need to draw using Entity, and TAA needs to be applied to this Entity.

Could you help me solve this problem?

It seems like ‘unity_MatrixPreviousM’ is missing(or not set properly) in motion vector shader, and I found the following in Entity Graphics.

RenderMeshUtility.cs:

#if HDRP_10_0_0_OR_NEWER
#define USE_HYBRID_MOTION_PASS
#endif

...

// Components required by objects that need to be rendered in per-object motion passes.
#if USE_HYBRID_MOTION_PASS
if (flags.HasFlagFast(EntitiesGraphicsComponentFlags.InMotionPass))
    components.Add(ComponentType.ReadWrite<BuiltinMaterialPropertyUnity_MatrixPreviousM>());
#endif

I modified USE_HYBRID_MOTION_PASS to always be declared and the problem was resolved.

Just ran into this too. Noticed motion blur was broken for object based motion vectors. Thank you for posting, enabling that code fixes motion blur as well.