Search Unity

ECS and Motion Vectors

Discussion in 'Entity Component System' started by Nothke, Sep 29, 2019.

  1. Nothke

    Nothke

    Joined:
    Dec 2, 2012
    Posts:
    112
    It seems that rendered entities don't get written into a motion vector map. Which means that they are not affected by motion blur. I tested with both built-in and HDRP pipelines (UWP does not support per-object motion blur).

    Here's a direct test in HDRP between moving an Entity by the Translation component (red, top) and a GameObject (blue, bottom)

    motioncubes.gif

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class MoveSine : MonoBehaviour
    4. {
    5.     public float gain = 10;
    6.     public float frequency = 10;
    7.  
    8.     void Update()
    9.     {
    10.         transform.position = new Vector3(
    11.             Mathf.Sin(Time.time * frequency) * gain, 0, 0);
    12.     }
    13. }
    14.  
    Code (CSharp):
    1. using UnityEngine;
    2. using Unity.Jobs;
    3. using Unity.Collections;
    4. using Unity.Mathematics;
    5. using static Unity.Mathematics.math;
    6. using Unity.Burst;
    7. using Unity.Entities;
    8. using Unity.Transforms;
    9. using Unity.Rendering;
    10.  
    11. public class MoveSineSystem : JobComponentSystem
    12. {
    13.     [BurstCompile]
    14.     struct MoveSineSystemJob : IJobForEach<Translation>
    15.     {
    16.         public float time;
    17.         public float gain;
    18.         public float frequency;
    19.  
    20.         public void Execute(ref Translation c0)
    21.         {
    22.             float x = sin(time * frequency) * gain;
    23.             c0.Value = float3(x, c0.Value.y, 0);
    24.         }
    25.     }
    26.  
    27.     protected override JobHandle OnUpdate(JobHandle inputDeps)
    28.     {
    29.         return new MoveSineSystemJob()
    30.         {
    31.             time = Time.time,
    32.             gain = 10,
    33.             frequency = 10
    34.         }.Schedule(this, inputDeps);
    35.     }
    36. }

    Here is also an example I also posted on the physics discussion thread, running with built-in renderer comparison between GameObject-based physics (PhysX) and DOTS (Havok) with motion vectors debug view:

    ecs.jpg

    Is there something I'm missing or is it something that's not possible yet?
     
  2. DJSourceTech

    DJSourceTech

    Joined:
    Feb 26, 2020
    Posts:
    5
    I am suffering from this annoying bug too.:mad:
    Seems there is nothing like motion inside Unity.Rendering.RenderMesh. If u find a solution, please tell me;)
     
  3. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Motion vectors are currently not support the next version of Hybrid Renderer which will require Unity 2020.1 fully support motion vectors. Keep an eye out on the release notes the next couple of weeks.
     
  4. DJSourceTech

    DJSourceTech

    Joined:
    Feb 26, 2020
    Posts:
    5
    GREAT!!!!!