Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

HybridRenderer tips and tricks?

Discussion in 'Graphics for ECS' started by Cell-i-Zenit, Dec 5, 2019.

  1. Cell-i-Zenit

    Cell-i-Zenit

    Joined:
    Mar 11, 2016
    Posts:
    290
    Hi,

    so currently i have like 50k Cubes in my Scene and the performance drops to 50fps.. iam not really happy with that and wonder if i can somehow increase the fps by doing some "tricks", eg caching, some settings, disabling some objects which are not seen etc.

    Anyone can point me to a ressource where stuff like that is described? I see in my systems that the HybridRenderer is basically using like 95% of the resources.

    Is there a way to "Disable" the rendering of an object by attaching an "Disable" Entity or stuff like that? I could greatly reduce the number of displayed cubes by disabled some cubes in the far distance.

    Should i implement my own version of Frustrum Culling?
     
  2. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,297
    Do you have an instancing enabled (on the material)?

    Other than that, I don't think hybrid renderer is at max optimization potential.
     
  3. Cell-i-Zenit

    Cell-i-Zenit

    Joined:
    Mar 11, 2016
    Posts:
    290
    I have it enabled, but it does nothing on the performance if i enable/disable it, so i guess iam doing something wrong here.

    What iam doing: Have 4 different RenderMeshes prepared and assign a rendermesh at random to each Cube via

    manager.SetSharedComponentData(leaf2, renderMesh);

    Each RenderMesh uses the same Mesh:

    var mesh = (Resources.Load("cube") as GameObject).GetComponent<MeshFilter>().sharedMesh;
     
  4. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    What is your batch count in the status window?
    It should be clear if there is batching or not.
    upload_2019-12-5_15-2-19.png

    I've tested with Standard and URP and it seems to be working just fine.
     
  5. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,322
    First off, jump into the timeline view and see which step is taking up so much of your time. There is a separate system that does culling compared to rendering.

    If you decide you still want a custom solution, you can write a GameObjectConversionSystem that removes the RenderMesh on your cubes and replaces it with your own custom version. You can then use Graphics.DrawMeshInstancedIndirect to dispatch everything into a handful of draw calls. Of course this is assuming your platform supports this and you know how to wire up the shader to support DrawMeshInstancedIndirect.
     
  6. Micz84

    Micz84

    Joined:
    Jul 21, 2012
    Posts:
    451
    I have a similar issue. I have a simple agent model (not animated) and map build-out of scaled meshes.
    there are 14k agents and map has 200x200 tiles that make about 54k batches.
    RenderMeshSystemV2 takes 12.53 ms.
     

    Attached Files:

  7. siggigg

    siggigg

    Joined:
    Apr 11, 2018
    Posts:
    247
    Those of you having issues, what renderer are you using? Currently Hybrid works best with HDRP and is really only supported there.
     
  8. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,690
    And built-in still works fine ;)
     
    Opeth001 likes this.
  9. siggigg

    siggigg

    Joined:
    Apr 11, 2018
    Posts:
    247
    Perhaps for some features, but I know it doesn't for the per-instance shader params (similar to material property blocks) and I know some optimizations were done with HDRP in mind.
     
  10. Micz84

    Micz84

    Joined:
    Jul 21, 2012
    Posts:
    451
    I am using URP. I will check with HDRP.
     
  11. Radu392

    Radu392

    Joined:
    Jan 6, 2016
    Posts:
    210
  12. Cell-i-Zenit

    Cell-i-Zenit

    Joined:
    Mar 11, 2016
    Posts:
    290
    Last edited: Dec 5, 2019
    siggigg likes this.
  13. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,690
    Yep, this is why we're using our own rendering system :)
     
    siggigg likes this.
  14. sngdan

    sngdan

    Joined:
    Feb 7, 2014
    Posts:
    1,154
    This is still a good thread on the subject (it is not necessarily related to sprites, despite the title).
    https://forum.unity.com/threads/200k-dynamic-animated-sprites-at-80fps.695809/

    Basically DrawMeshInstancedIndirect + various use case specific optimizations like:
    1. calculations pushed to shader - i.e. local to world calculation pushed to shader
    2. minimization of cpu to gpu data - i.e. animation index with uv lookup in shader
    3. caching of cpu to gpu data - ComputeBuffer.SetData(m_values, startIndex, startIndex, valueCount)
    4. culling

    I posted a barebone system there which implements point 3, and hence has no optimizations for 2D - you could try if this helps in your case (although you will loose culling / lod benefits unless you implement yourself)