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. Dismiss Notice

Question Graphic Optimization

Discussion in 'General Graphics' started by dyrwoolf, Jun 4, 2023.

  1. dyrwoolf

    dyrwoolf

    Joined:
    Oct 9, 2010
    Posts:
    18
    I dont know if this is the right place to ask this question, but I do it anyway.
    If I have a character with lets say 10 different helmets and chose to include all helmets in that characters fbx, and just enabel/disable them when i change helmet. Does the enginge compute the disabled helmets aswell as the one enabled? Whats the highest cost, this approch or to have 10 different helmet models that I at runtime instanciate and bind to the characters headbone?
     
  2. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    516
    Disabled helmets are not rendered but you'll still have them in memory which may or may not be a problem, depending on how many props you have. If you have 100 different helmets, armors, swords, etc. loading them all up front would not be a good idea. If you just have a handful, it shouldn't be a problem.

    The bigger problem is with skinned meshes, like for example different shirts. What people often do is chop the character up into different body parts (torso, legs, head, ...) and have different versions of them - just like with static props. The problem with that is that this will quickly generate a huge number of draw calls, even if you just enable one renderer for each body part:

    #drawcalls = #characters * #bodyparts * #renderpasses

    You'll also have to animate each body part separately, which is expensive.

    The way to optimize this is to merge the skinned meshes after customization at load-time and use the same material (some form of uber shader) and skeleton on each body part.
     
    Last edited: Jun 4, 2023
  3. dyrwoolf

    dyrwoolf

    Joined:
    Oct 9, 2010
    Posts:
    18
    Thank You.
     
  4. kenamis

    kenamis

    Joined:
    Feb 5, 2015
    Posts:
    386
    This is not exactly true anymore if you're using a SRP and the SRP batcher is enabled.
    https://docs.unity3d.com/Manual/SRPBatcher.html
    The costly part is no longer the draw call, but a SetShaderPass because of a new shader variant. This means you can have many different mesh and material combinations and if they all share the same shader variant, then they get batched together.
    So, depending on your goals, it's arguable whether combining meshes and materials would still be optimal or not. Combining them does create unique resources which uses memory inefficiently and need to be made sure to be cleaned up.
     
  5. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    516
    I was referring to BiRP, sorry, should have made that clear.

    I am aware of the SRPBatcher in URP and HDRP, but my experience with it is limited. I doubt that it will fix the performance problems with modular characters but you should profile it anyways. Just throw in a bunch of characters and look at the CPU and GPU cost.