Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

how to draw entities with different meshes efficiently ?

Discussion in 'Entity Component System' started by Robber33, Nov 18, 2019.

  1. Robber33

    Robber33

    Joined:
    Feb 22, 2015
    Posts:
    52
    I'm working on a terrain generator, it's a tile based system, right now i'm using gameobjects with meshrenderer, i use the job system extensively here for generating terrain.

    I would like to transition to DOTS for this, mostly because i also want to integrate the new physics systems.
    but i see that using RenderMesh, as its a sharedcomponent, when my terrain-slabs have different meshes they end up in different chunks. Since each terrain-piece will have a different mesh, i end up with a chunk for every terrain piece, which seems to be counter productive

    Will there be any benefit for using RenderMesh component and Hybrid Renderer for this ? Or would i be better of skipping RenderMesh and use Graphics.Drawmesh to draw each piece myself, allowing terrain-pieces to be nicely chuncked together for other components and systems ?

    Even when using gameobjects with a meshrenderer, using MeshRenderer performs faster than using Graphics.DrawMesh for each tile, because of caching ? will I see a comparible optimisations using Hybrid Render over Graphics.Drawmesh ? or is performance mainly geared towards instance rendering ?

    kind regards,
    Rob Bothof
     
  2. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    RenderMesh might give you some advantages like the culling and just generally fitting in with the DOTS ecosystem better.

    What you need to do if you want something comparable to Unity's instanced terrain renderer is to just use flat tiles with the procedural api's with height data in the compute shader, or even just a height texture sampler in the shader. You reuse a small set of tiles everywhere. That small set being enough to account for LOD transitions, the edge quads needing different triangles so edge seems match.

    Even then you need to sort out colliders and how to make it render in the editor.

    What is your reason for using mesh terrains?
     
  3. Robber33

    Robber33

    Joined:
    Feb 22, 2015
    Posts:
    52
    thanx SnackTime,

    I think i didn't mention the terrain is completely procedural.
    my edges don't need different triangulation, I overlay my tiles and use a shadercrossfading technique to match the edges. The main reason is I need to calculate meshcolliders aswell and it more as less started as an experiment to work with jobs. I'm already happy with performance and would like to transition this to DOTS, for compatibility with unity.physics and perhaps other DOTS related techniques.

    Apart from whats the best approach for making a terrain, i think it is still a valid question ?
    there can be other designs where instance rendering is not the solution and i like to know how to this efficiently with DOTS
     
  4. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Ya I got that your terrain is procedural.

    Grouping things that can be batched together, shared components are what that type of scenario was designed for. Where you have a lot of batches for a specific feature like yours, DOTS rendering isn't really going to help you performance wise. That the data is in different chunks isn't really an issue. It's the main thread overhead of how DOTS rendering processes batches that will perform worse then just using DrawMesh.
     
  5. Robber33

    Robber33

    Joined:
    Feb 22, 2015
    Posts:
    52
    Thanx for your response snacktime!

    i got DrawMesh times down a lot by optimizing the vertexcount of my tiles, so the amount of tiles is lower and vertexcount is highter, that way there isn't a batching benefit,so right now i'm not even using gameobjects for this just DrawMesh.

    I can seperate the meshcolliders from the meshrendering, so i'm gonna try to put those in entities with the physics system.
     
  6. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    DrawMesh is rarely better then just having a renderer on a GameObject. It's when your meshes change constantly that it's a win.
     
  7. Robber33

    Robber33

    Joined:
    Feb 22, 2015
    Posts:
    52
    good to know, thanx!