Search Unity

Resolved What is the best way to render groups of Entities in multiple layers with Dots?

Discussion in 'Graphics for ECS' started by MNNoxMortem, May 23, 2022.

  1. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    What is the best way to render groups in Entities in layers? I am currently on Entities 0.17 but I have seen 0.50 adds support for RenderLayer. However, I could not find any examples or explanation on what is exactly supported.

    I would like to be able to render a large amount of Entities with MeshRenderer (not SpriteRenderer and sortingLayers) and triangles in multiple groups/batches:
    • Group A
    • (Depth clear?)
    • Group B, Depth write & test: true
    • (Depth clear?)
    • Group C, Depth write & test: true
    • (Depth clear?)
    • Group D, etc..
    • ...
    • Render UI, etc

    I am sure this could be achieved with CameraStacking regardless the renderer, but are there better alternatives? Are there any easier or more performant alternatives? What are the limitations of each approach?

    The problem with CameraStacking is, that it requires the manual setup of the layers. I would favor a more dynamic approach (just using a numeric priority), but could fallback to the static setup if really necessary.

    0.50
    upload_2022-5-23_16-23-10.png
    0.11 - HybridRenderer v1
    upload_2022-5-23_16-25-21.png


    What does the documentation exactly refer to with the RenderLayer? Layered rendering via CameraStacks works in v1, but it means we are limited to a total of 32 layers and need to set them up before. Also the layers are also relevant for UnityEngine.Raycast (and I assume it translates 1:1 to Unity.Physics.Raycast):
    upload_2022-5-23_18-29-41.png
     
    Last edited: May 23, 2022
  2. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    351
    RenderLayer means supporting the GameObject.layer and Renderer.renderingLayerMask features of the MeshRenderer that the entity was converted from. I think what it does in practice is that the SRP can mask out some gameobjects and entities when it does DrawRenderers commands, using the FilteringSettings parameter.

    As for your actual use case, the rendering of different object groups with different settings is for the SRP (in this case URP) to decide, so the question is how to best accomplish that with URP. I think URP supports some kind of custom rendering passes which could be useful for this purpose, or using camera stacks like you wrote might also work.
     
    MNNoxMortem likes this.