Search Unity

Implementing MeshInstanceRendererSystem frustum-culling and LOD with spatial hashing

Discussion in 'Graphics for ECS' started by The5, May 12, 2018.

  1. The5

    The5

    Joined:
    May 26, 2017
    Posts:
    19
    I am currently trying to implement frustum-culling and LOD on a spatial hash grid.
    It appears to me like I would have to implement my own MeshInstanceRendererSystem to handle which entities will be drawn and at what LOD detail they are.
    Removing or modifying the entire MeshInstanceRenderer SharedComponent per entity feels like the wrong approach, though I might be wrong here.

    Any suggestions as to how one would implement this with the currently available system?
    Or is building a custom MeshInstanceRenderer the right way?

    On that note, the ECS documentation https://github.com/Unity-Technologi...master/Documentation/content/ecs_in_detail.md got a link to the "MeshInstanceRendererSystem.cs", however that link is broken:
    https://github.com/Unity-Technologi...endering.Hybrid/MeshInstanceRendererSystem.cs

    So, it appears the c# implementation of MeshInstanceRendererSystem was available at some point. Is it still?
    Or, can I somehow inspect its source in the ECS package?

    P.S.:
    Is there a go-to hash function for 3D/2D spatial hashing for games?
    For collision detection, selection, neighbor queries, culling and such that is.
    I was not able to find some "industry standard", some papers mentioned XOR or DJB2 for their speed and claimed collisions do not matter much for the typical use-cases named above.
    Does anything speak against using "infinite size" (I lack the proper term here) hash functions rather than simply calculating the 1D index of a fixed size 2D grid or fixed size hash table? (NativeMultiHashMapis not required to be fixed to begin with.)
     
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Open any of the examples of ECS, well suited spellsouls demo, and look at the implementation of MeshInstanceRender, I think you'll find something there.
     
  3. The5

    The5

    Joined:
    May 26, 2017
    Posts:
    19
    The spellsouls demo´s ArrowRenderSystem is a good, relatively simple example indeed.
    At the time it was created the builtin MeshInstanceRendererSystem was not available yet it seems.

    All other ECS examples that I am aware of use the now builtin MeshInstanceRenderer.
    They do not perform any LOD or culling though, they do not even pass any per-entity MaterialPropertyBlocks.

    I am still unsure if one could utilize the existing system, or if it is necessary to re-implement a custom MeshInstanceRendererSystem and drop the builtin one.
    But looking at things like MaterialPropertyBlocks it sure looks like one needs to write their your own.

    Mind you, I am aware that ECS is currently just in preview stage and we likely get a more sophisticated MeshInstanceRendererSystem. But then again I wonder how a generic MeshInstanceRendererSystem would be designed.