Search Unity

  1. Unity 2019.4 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  3. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Assets Cluster Mesh Rendering (rendering acceleration technique)

Discussion in 'Works In Progress' started by CodeRoadOne, Jun 20, 2020.

  1. CodeRoadOne

    CodeRoadOne

    Joined:
    Mar 9, 2014
    Posts:
    18
    Hi all,

    We are working on a new optimization technique for Unity, called Cluster Mesh. The idea is simple: reduce the number of batches/draw calls as much as possible. The best usage is when you use an atlas texture and you have different meshes that have one or more instances. All of this will be reduced to one batch/draw call.

    We have the best example in this scene (the demo scene from Simple Fantasy - Cartoon Assets):
    CRO_IndirectRendering_01.png

    As you can see there are 3338 batches/draw calls. The scene has 3466 objects that need to be rendered using 4 different materials.

    When we activate Cluster Mesh rendering, we end up with this:
    CRO_IndirectRendering_02.png

    19 batches/draw calls, but not all of them are from the cluster rendering. As we said there are 4 different materials so we need 4 draw calls for the main rendering and 2 draw calls for every shadow cascade (as we have 2 materials with transparency). You can see this looking at the frame debug:
    CRO_IndirectRendering_03.png

    The next thing that needs to be implemented is the culling system
    . At this point, everything is sent to the GPU but it can reduce the number of polygons sent by using GPU culling.

    The above technique works in Unity standard as well. The screenshots were done using Unity Universal Rendering Pipeline.

    You may be wondering how easy it is to add this to your project. At this moment as this tool is still in progress you need to follow a few steps:

    1. Add to the camera the rendering script: CRO Indirect Rendering Renderer (name might change in the future)
    CRO_IndirectRendering_04.png

    2. Add an empty object in the scene and attach the CRO Indirect Rendering Geometry Collector
    CRO_IndirectRendering_05.png

    3. Press the collect materials button and it will provide you a list with all materials in the scene. For every material that you want to be part of the acceleration provide a replacement material for indirect rendering (for the moment we added only the standard lit material, but if you follow the steps that will be provided you can change any material to cluster with some easy modifications to the shader.

    4. Next step is to press the Collect geometry. This is where all the magic will happen.

    5. Done! Now you can run the game with the new rendering path. Enjoy!



    Watch this thread for updates as we will be posting more stuff as we go ahead with the tool.
     
    GarbageCat, Firlefanz73 and Mark_01 like this.
  2. CodeRoadOne

    CodeRoadOne

    Joined:
    Mar 9, 2014
    Posts:
    18
    We added a short video to show you how this tool is working at this moment inside Unity:
     
    zmaxz and Mark_01 like this.
  3. CodeRoadOne

    CodeRoadOne

    Joined:
    Mar 9, 2014
    Posts:
    18
    Hi all,

    Here is our latest addition to the Mesh Cluster tool – Frustum Culling!

    It seems that there are some confusions about this tool. This is NOT a mesh combiner that will create one giant mesh and render that combined mesh with one draw call. Even if this technique is working in some situations, it is not very efficient, as you are sending a lot of triangles to the GPU that are not actually visible on screen. Even if the GPU is fast in detecting polygons that are out of screen, it will still cost time (everything depends on the number of triangles that are out of the view frustum).

    Here is a small video showing a single mesh rendered using this system. On the right side of the screen you will see what we actually send to the GPU for rendering. On the right side you see what the game camera is rendering.



    The second video is showing the Frustum Culling on the entire map.
    On the left, you see what we’re sending to the GPU, and on the right is what the player camera is seeing.

     
    zmaxz and Firlefanz73 like this.
  4. GarbageCat

    GarbageCat

    Joined:
    Jul 31, 2012
    Posts:
    224
    looks amazing, can this also work on WebGL 2.0? are there any limitation for mobile?
     
  5. CodeRoadOne

    CodeRoadOne

    Joined:
    Mar 9, 2014
    Posts:
    18
    Hi, so I'm afraid this tool can only work on targets that allow ComputeBuffers as input to the Vertex Shaders. I didn't try WebGL 2.0 yet so I cannot tell you this now.
    The tool is not ready yet as I need to add a lot more features to it and then I'll sort out the compatibility list for you guys. For sure this code will work on PC (DX11 and above), new mobiles (probably IPhone 8 and above, and the equivalent on Android using Vulkan), and on all consoles (including Switch using Vulkan).
    Thanks for the appreciation : )
     
  6. CodeRoadOne

    CodeRoadOne

    Joined:
    Mar 9, 2014
    Posts:
    18
    Hi all,

    Here’s a new demo and some more explanations about the Mesh Clustering.
    In the video you will see the current system that we intend to simplify (there are still too many steps before you can use the system and we know we can do better to make your life easier : )

    So, in this demo we start by creating a standard Unity sphere and assign a pre-created red material (it is using Universal Render Pipeline\Lit).

    Then, we collect all materials in the scene and assign the pre-created material for the Cluster Mesh Rendering. The creation of the material is simple, just duplicate the original material and replace the Universal Render Pipeline\Lit with CRO\URP_Lit.

    Collect the geometry and poof!, everything is done! You can now play the game : )

    As you will see, we send to the GPU only the parts of the sphere that are visible, not the entire object. This will make the rendering a lot more efficient. Of course, this is still use one single draw call. As a bonus, in case you are wondering, this will work also for instanced geometry. For every instance we will send only what is visible from that instance.

    Hope you like it and let me know what will make it more useful for your particular case, or what demo video should we add.

     
    zmaxz likes this.
  7. CodeRoadOne

    CodeRoadOne

    Joined:
    Mar 9, 2014
    Posts:
    18
    We just wanted to test the current performances of the system. Please note that the system is not yet fully optimized, we need to work a little more to get better performances, but it's not so bad even now. Take a look and leave a comment.
    Enjoy!
     
    Last edited: Jun 24, 2020
    zmaxz likes this.
  8. CodeRoadOne

    CodeRoadOne

    Joined:
    Mar 9, 2014
    Posts:
    18
    Hi all,

    We added a new feature to the Mesh Cluster: Screen size percentage culling.

    In general, when an object is too small it doesn’t impact the visible scene anymore and it’s best to not render it. For this reason, we added a new option for you where you can control the threshold that establishes when an object is too small and it can be removed from screen.
    Be aware that an object for us is a Cluster Mesh, not the entire object as it is exported from your favorite 3D modeling tool. We will explain this in detail in a future video demonstration.

    Take a look at the demo and let us know what other features will be useful to add for your project.

     
    zmaxz likes this.
  9. Mark_01

    Mark_01

    Joined:
    Mar 31, 2016
    Posts:
    463
    Am curious to know if this can work for/on VR oculus quest ?
     
  10. CodeRoadOne

    CodeRoadOne

    Joined:
    Mar 9, 2014
    Posts:
    18
    Hi, Mark! In theory it should work, I don't see why it wouldn't work. The biggest problem would be what rendering pipeline you want to use. For the moment I tested it with Universal Render Pipeline and Standard Unity (deferred rendering). As there are too many variations I'll concentrate only on one pipeline (Universal Render Pipeline) and later I'll try to add support for others.
     
    Mark_01 likes this.
  11. Mark_01

    Mark_01

    Joined:
    Mar 31, 2016
    Posts:
    463
    Thanks so much for your reply. Once I get the cable for the quest in the mail and start
    playing around with making my own levels for vr quest , I will come back here :)
    I think for vr you use the Universal Render Pipeline.

    I think this could be a very good, well liked asset once you have it on the store.
    AFAIK there is not to many assets that does this well. ;-)
     
  12. CodeRoadOne

    CodeRoadOne

    Joined:
    Mar 9, 2014
    Posts:
    18
    Thank you for the kind words. Check back here from time to time for updates!
     
    Mark_01 likes this.
  13. CodeRoadOne

    CodeRoadOne

    Joined:
    Mar 9, 2014
    Posts:
    18
    Hello all,

    We added a free checkup tool on GitHub – MeshClusterCompatibility (https://github.com/CodeRoadOne/MeshClusterCompatibility) for Unity 2019.4.1f1. This tool will allow you to know in advance if Mesh Cluster is compatible with the minimum device that you want to support. Just download the code, do a build for that platform and run it on that machine. As soon as the application is starting you will see a screen telling you if the current implementation of the Mesh Cluster is compatible with that platform.
    CRO_MeshClusterCompatibility.png
    If all the current fields are green you have maximum compatibility. If some fields are yellow, the tool will work, but there will be a speed penalty.

    Let us know if your targeted device is not compatible and where it is failing. We will decide if we try to increase the compatibility to include your target device.

    The Compatibility Test Scene can be found in: CodeRoadOne/MeshCluster/DemoScene/CompatibilityTest/CRO_CompatibilityTest

    Send us your feedback!
     
    Mark_01 and JBR-games like this.
unityunity