Search Unity

Feedback Hybrid Renderer filtering RenderBoundsUpdateSystem

Discussion in 'Graphics for ECS' started by GilCat, Jun 23, 2019.

  1. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    I'm experimenting on a system of massive rendering where i'm relying on the RenderBounds from the HybridRenderer Package and i found that no matter what, the bounds are always updated.
    Wouldn't it be more efficient if there was a check for change on read only chunks? Or am i missing something here.
    Something like this:
    Code (CSharp):
    1. [BurstCompile]
    2.     struct BoundsJob : IJobChunk {
    3.       [ReadOnly] public ArchetypeChunkComponentType<RenderBounds> RendererBounds;
    4.       [ReadOnly] public ArchetypeChunkComponentType<LocalToWorld> LocalToWorld;
    5.       public ArchetypeChunkComponentType<WorldRenderBounds> WorldRenderBounds;
    6.       public ArchetypeChunkComponentType<ChunkWorldRenderBounds> ChunkWorldRenderBounds;
    7.       public uint LastSystemVersion;
    8.  
    9.  
    10.       public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) {
    11.         if (!chunk.DidChange(RendererBounds, LastSystemVersion) &&
    12.           !chunk.DidChange(LocalToWorld, LastSystemVersion))
    13.           return;
    14.         //@TODO: Delta change...
    15.         var worldBounds = chunk.GetNativeArray(WorldRenderBounds);
    16.         var localBounds = chunk.GetNativeArray(RendererBounds);
    17.         var localToWorld = chunk.GetNativeArray(LocalToWorld);
    18.         MinMaxAABB combined = MinMaxAABB.Empty;
    19.         for (int i = 0; i != localBounds.Length; i++) {
    20.           var transformed = AABB.Transform(localToWorld[i].Value, localBounds[i].Value);
    21.  
    22.           worldBounds[i] = new WorldRenderBounds { Value = transformed };
    23.           combined.Encapsulate(transformed);
    24.         }
    25.  
    26.         chunk.SetChunkComponentData(ChunkWorldRenderBounds, new ChunkWorldRenderBounds { Value = combined });
    27.       }
    28.     }
    Also think that this it should also apply to the Transform System.