Search Unity

Any advice to optimize our game.

Discussion in 'General Graphics' started by warmanw, Jul 17, 2019.

  1. warmanw

    warmanw

    Joined:
    Feb 2, 2015
    Posts:
    32
    Hi Guys sorry to bother you with a standard issue. But we are really new in optimizing a game. If you have any particular suggestions to our case that would be awesome. Since googling brought me to a lot of cases which just confused me more and more.

    • So here is the deal.. We have a room with low poly(~2000vert) decors(20 decors in each room), each decor has one texture(512x512)
    • we also have 8 cats walking there with skinned mesh(6000vert) and one texture(512x512)
    • we use very basic diffuse shader.
    • no lights sources in the game.. ambient
    • Since cats move and decorations can be moved as well, we cannot have any static object in the room..
    • mipmaps are disabled for all textures.

    for now all works fine on all devices..
    upload_2019-7-17_9-14-10.png

    but we want to develop feature where camera goes up and shows several rooms, each with its own decorations and cats. Something like this
    upload_2019-7-17_9-22-23.png

    So please help us... what are the best practice for optimizing this mode.

    this mode is for navigation only and is not the main view of the game, so we can disable moving decorations, maybe can set to static.
     
  2. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,980
    Well first off, turn mipmaps on. Im not sure why you would want to turn it off because it will save you memory and applies to stuff like you zooming out the camera. Also make sure to turn GPU instancing on on materials that are going to be in more than one place such as walls etc.

    Secondly, I would use some sort of LOD. If you are zooming out , there is no reason not to have some LOD levels otherwise you are going from rendering 1 room at full res, to X rooms at full res. You need to render lower and lower density geometry as you zoom out, and the lod component in unity + generating some lods for your models will do just that.

    Finally, combine your materials, you said you have 512x512 texture per decoration? Merge them into texture atlases so that they end up drawing in fewer draw calls.

    Try all 3 of those and come back and let us know if it helped and by how much.

    A tip:

    Profile your game. Its hard to tell you what to actually optimise without seeing your profiler results, as it could be nothing to do with rendering at all and all to do with some scripts that are running, or audio, or UI, or physics etc etc. Profiler will shed light on this.

    Also use the frame debugger to work out exactly how many draw calls are happening and why things are not GPU instanced/batching, and then fix that by making the things batchable or instanceable such as combining materials and meshes.
     
    richardkettlewell likes this.
  3. warmanw

    warmanw

    Joined:
    Feb 2, 2015
    Posts:
    32
    Thank you very much. We know how to easy create LOD For decorations. but for skinned cats not sure that we can easily generate them without breaking skinning or animation.. do you have any experience of creating LOD for characters?

    also you said to combine the textures in one atlas.. which is the best practice to do that? at runtime or just create batch of decorations that use same texture?(and if we have all combined into 4096x4096 texture. with mipmap enabled it will become bigger? or mipmaps are actually generated into different textures? so we will endup having 4 textures

    4096, 2048,1024,512
    or one bigger
    8192 with all mipmaps included?
     
    MadeFromPolygons likes this.
  4. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,980
    So for combining materials I would use something like this: https://assetstore.unity.com/packages/tools/modeling/mesh-baker-5017

    As it will redo the UVs for you so you dont need to go back into your modelling program, and means you can keep adjusting the settings until you have correct performance.

    Just try and combine everything into one big texture, then test, and then adjust based on performance, Its hard to tell there is not 1 setting so try 8k, 4k, 2k etc until you find what works best for you. You may want to for instance have all decorations as one texture, all cats as another etc.

    As for LOD, you cant really do LOD properly with skinned meshes so those you will leave out, but do LOD for everything else.

    For your skinned meshes, you can look at skinned mesh instancing such as: https://blogs.unity3d.com/2018/04/16/animation-instancing-instancing-for-skinnedmeshrenderer/

    Although that is probably overkill.

    But again, post your profiler results here as I doubt with that screenshot that it is the graphics that are causing you to have framerate problems, its likely the code you are running in your scripts. If you post a picture of your profiler results we can better determine what is going on. Running the profiler is the only way to truly test performance issues.
     
  5. ph_

    ph_

    Joined:
    Sep 5, 2013
    Posts:
    232
    +1 with mesh baker, it worked really well in my project and if you think about the time it'll save you ... it pay back itself in no time!
     
    MadeFromPolygons likes this.
  6. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,980
    I just really like the fact that you can run it on a mega-sized and complex scene and it will automatically work out what should be combined with what based on some easy to set settings, makes optimising after-the-fact very easy indeed! (for graphics optimisations, CPU side you will still need to adjust any scripts to be better optimised if they are taking up valuable time in the profiler)

    And yes I agree it pays itself back in value very quickly
     
    ph_ likes this.
  7. warmanw

    warmanw

    Joined:
    Feb 2, 2015
    Posts:
    32
    Thanks for your help . really I think now we are on right track.. first of all profiler.
     
    MadeFromPolygons likes this.
  8. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,980
    Absolutely :) You can always come back here and comment if you have more problems or any issues implementing any of this.

    Also, dont worry optimisation is difficult and therefore sometimes a pain at first.

    A thing I forgot to mention is:

    Bake lightmaps and use baked lighting (if possible to not have realtime lighting) and also use occlusion culling (also can bake this) to stop it rendering anything outside of camera view :)

    Those 2 will get you many FPS back! Good luck! :D
     
  9. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    Performance characteristics often vary depending on target hardware and the project itself. If you target different hardware, something that boosts performance on platform A, does not necessarily have the same effect on platform B.

    The basic principle of optimizing a game often boils down to:
    1. Run build on target hardware
    2. Use Profiler to find bottleneck, note how much time is spent there
    3. Optimize bottleneck
    4. Run build on the very same hardware you used earlier
    5. Use Profiler to find earlier bottleneck, check how much time is spent there now
    6. If "time spent" is still unacceptable, goto 3
    It's important that you use the same setup during an optimization sessions always. For example, do not "git pull" while you're in the middle of optimizing and profiling, as it might affect the test.

    Here are a few links to optimization talks held by Unity Technologies. These are great resources to get a general idea where one can apply optimizations. However, always profile before and after doing optimizations. Optimizing blindly can go in the wrong direction.