Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Discussion Tips on how to optimize modular 3D models

Discussion in 'General Discussion' started by Tom-Kazansky, Jul 9, 2022.

  1. Tom-Kazansky

    Tom-Kazansky

    Joined:
    Mar 9, 2015
    Posts:
    58
    Hi,
    I'm working on a Chess-based game, in which I use models bought from here: Mech Constructor: Spiders and Tanks

    currently, my game has:
    - a background
    - some UI elements
    - controllable units (using the models mentioned above), up to 10 in total
    - the camera is able to see the whole board (which consists of 8x13 cells)

    I built this and play on my Android device, which is Xiaomi Redmi 11 Pro 5G.
    The framerate is rather poor, only about 40fps or so, so I'm finding a way to improve this.

    my questions:
    1) are these models too much for mobile devices?

    2) is there anything I can do to improve the performance of my game?
    I'm not well versed in optimization, I only know some basic stuffs, I can understand a few things in the Profiler.
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,511
    First step: analysis. Check the profiler manual and try to find out what your bottleneck is. Focus on determining whether you are CPU or GPU bound. Feel free to post screenshots of profiler while game runs on device if you can‘t make heads or tails of it.

    As for the asset, I just glanced over the description. Polycounts seem fine but 4k atlas sounds like way too much for mobile especially when this 4k atlas is per model rather than one for all of them. 4k texture equals 64 MB video memory if not compressed.
     
    Tom-Kazansky likes this.
  3. Tom-Kazansky

    Tom-Kazansky

    Joined:
    Mar 9, 2015
    Posts:
    58
    thank you for the reply,
    I will first try scaling the texture down and see if there is any improvements.
     
  4. Tom-Kazansky

    Tom-Kazansky

    Joined:
    Mar 9, 2015
    Posts:
    58
    Hi,
    I tried analyzing the performance using the Profiler (with Deep Profile enabled)

    There is some regular spikes from "ProfilingScope..", I guess this is from the Profiler's script, and I can safely ignore it, right?
    I also attached some screenshots while in gameplay (which have 10 units)

    the GPU time seems to be always --ms, did I miss a settings somewhere?

    "Rendering", is there any problems in this data
    take5.png

    "Memory", is there any problems in this data
    take6.png

    if you want to take a look at the profiling data, its here:android-profiler1.data (it's 464MB, though)
     

    Attached Files:

  5. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,082
    It looks like half of your performance is being eaten up by scripts and garbage collection, as well as your rendering taking up much more than it should, given the description of your game. Generally speaking, you want every operation to take up no more than a total of 16ms, otherwise you're taking too long to process a single frame to hit 60fps.
     
  6. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    1,181
    The profiler is giving you a clear answer on some code that is taking way too long, and it looks like it has to do with the render pipeline. Do a google search for the specific methods that have a huge time listed under the "Self ms" column.
     
    Last edited: Jul 11, 2022
  7. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    1,726
    4k atlas is WAY too much for mobile devices. Your target platform is mobile, even though gilley033 is correct, i also think that setup and optimization for mobile is a key factor. When deving a game for mobile "less is better" theory is true (lower res textures, model import settings, material settings, compression, camera settings, too many to list).

    IMHO, learn to optimize for mobile (tons of tutorials and info out there). Ive seen bad coding/scripts, garbage collection, un-optimization, and many more causes of this...
     
    Ryiah and Tom-Kazansky like this.
  8. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,967
    The following are points that can be applied to any mobile 3d game for performance benefits, however profiling will enable you to tell which of these (if any) are most relevant for you / highest impact:

    - Reduce texture sizes
    - Atlas textures
    - Use lower-density geometry models, ideally with details baked into normal maps where possible
    - Use GPU instancing where possible
    - Async is your friend, use it wisely but use it where possible
    - Dont do things continiously in updates if they dont need to be
    - Try and minimise the number of monobehaviours and gameobjects in your scene (use normal classes etc where possible)
    - Use pooling instead of destroying and instantiating all the time
    - Avoid doing anything physics related if possible, and use physics collision layers if you absolutely must use physics
    - Avoid / minimise use of render textures
    - Use lower quality settings for your render pipeline
    - Remove or turn down any post FX
    - Use the job system and burst compiler for all tasks that are suited to it
     
    Kokowolo, spiney199, Ryiah and 2 others like this.
  9. Ukounu

    Ukounu

    Joined:
    Nov 2, 2019
    Posts:
    209
    Are you guys talking about 2005 mobile devices, or about modern ones? 4k textures and scenes with millions of vertices is perfectly fine for high-end mobile devices since many years ago... The OP said he tested the project on Xiaomi Mi 11 Pro. There is no feasible way how a few 4k textures for each chess piece could degrade performance of a device like that. The problem apparently is elsewhere.
     
    Last edited: Jul 11, 2022
  10. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    1,726
    I agree, and thats why i posted "Ive seen bad coding/scripts, garbage collection, un-optimization, and many more causes of this...". Im not a mobile dev, BUT i do know optimization, and the lower res you use for textures, the better, but certainly not the root cause of this senario, gut feeling is scripting...

    Please learn to take the whole statement into consideration, and the fact that we all try to help on the info thats givin...
     
  11. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,967
    What? I work with mobile for many clients and 4k textures absolutely will degrade performance on 95%+ of mobile devices.

    Its also completely unnecessary, why do you need 4k textures when you are playing on a device with an incredibly small screen? The increase from 2k to 4k will not be that percieveable anyway at that screen size, compared to other things that could be done instead to increase fidelity
     
    Ryiah likes this.
  12. Tom-Kazansky

    Tom-Kazansky

    Joined:
    Mar 9, 2015
    Posts:
    58
    the 4k textures are just the default stuffs from the asset provider, I agree that 4k textures are unnecessary for mobile.

    though I have tried down-scale the texture to 1k (25% of the original texture) but there is no significant improvements. (or somehow the texture didn't update)
    I guess I need to dive deeper.
     
  13. BIGTIMEMASTER

    BIGTIMEMASTER

    Joined:
    Jun 1, 2017
    Posts:
    5,181
    i think you could use 512 or lower textures, not see a big visual difference, but see a big performance gain. This is true for desktop, how could it not be for mobile? Reduce texture size is the easiest and probably biggest performance gain you get. After that probably look into needless shadow casters, and shader complexity.
     
    MadeFromPolygons likes this.
  14. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,967
    Well as already said from looking at the profiler, you also need to optimize your scripts which are taking up the majority of the ms

    For a simple thing like this, having this much script overhead points to some seriously unoptimized scripts running

    I can see from your profiler you are also using post processing such as bloom etc. Did you completely disable post processing like I suggested? that will reduce the big blit spikes you have having from URP.

    Its best to start simple and slowly add things to ensure you are always performant, rather than add a bunch of stuff and then start removing until it runs okay. Disable PostFX and any other "nice to have" things that are not integral to your project. Only add them once you actually know you have the frame budget for it.
     
    Ryiah and Tom-Kazansky like this.
  15. Ukounu

    Ukounu

    Joined:
    Nov 2, 2019
    Posts:
    209
    If you read the first post again, maybe you will notice that the OP says he experienced performance issues on a modern high-end device (Xiaomi Mi 11 Pro) - which belongs to top 5% of most powerful mobile devices as of 2022, and not on 95% of all mobile devices. Devices like that can run all the modern graphics-heavy games like Genshin Impact, COD Mobile, etc. There is no feasible way for a few dozens 4k textures to make any noticeable performance impact on a device like that.
     
  16. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,967
    I honestly dont think you understand just what the difference in perf hit a 4k is vs a 2k etc. Yes those games run on those and other phones, no those games absolutely do not use 4k textures. Genshin uses 512 in many places on mobile.

    Please dont just assume that because it runs a nice looking game, 4k textures on mobile (which has never been recommended practise for mobile in unity, ever) are okay. They simply are not, and more importantly they are absolutely a waste of time on a small screen, you will see virtually no difference from a 4k, 2k or 1k texture to most eyes on a phone sized screen at regular viewing distance.

    Having larger textures will impact shader computation significantly, some forms of post FX etc which all take signifcantly more ms the higher the texture resolution is. So yes, it absolutely can cause issues if OP has added all sorts of post FX etc (which you can clearly see they have from their profiler). Dont just assume it wont be this, when there have been plenty of modern mobile devices having issues with 4k textures.

    And yes, I use a pixel 6 and latest iphone for projects, I am well aware of what a modern high end mobile phone can and cannot do. Hence the above suggestions. I also recommended this in addition to a variety of other things, and clearly stated its up to OP to profile to see which has an impact. But assuming an optimization wont work before actually testing it is really bad practise - you attempt an optimisation, you test and profile, you see if it has a good impact, if not you roll back. Not all projects are the same, regardless of device - as always your mileage may vary.
     
    Last edited: Jul 12, 2022
    Ryiah likes this.
  17. Tom-Kazansky

    Tom-Kazansky

    Joined:
    Mar 9, 2015
    Posts:
    58
    Hi, thanks for the tip,
    I didn't know what "PostFX" mean at first, now I figured it out that it means "Post Processing",

    I use the lowest possible Render pipeline settings, disable the Post Processing, HDR, Bloom... => I'm getting close to 60fps :D
     
    warthos3399 and MadeFromPolygons like this.
  18. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    1,726
    Have you checked your camera settings (clipping far plane/rendering distance, etc.)?. Your creating a chess board type game. Your far clipping plane should be very low (100 or less, depending on scene). Dial it back and watch your fps increase.
     
  19. Tom-Kazansky

    Tom-Kazansky

    Joined:
    Mar 9, 2015
    Posts:
    58
    my camera Clipping Planes are 1 (near) and 100 (far),

    here is my camera settings:
    camera settings.png

    the size of the models is pretty big, the board also need to be big, so I need to put the camera on a high position,
    is there any impacts if I reduce model size (with transform-scale)?
     
  20. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,553
    It won't make any difference when there are no objects to be clipped.
     
    MadeFromPolygons and warthos3399 like this.
  21. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    1,726
    100 far is very good, nice job. The realistic, only thing left to gain fps/ms is script based functions. So i think its time to check your C# scripts and optimize them. Otherwise, your pretty much on point. If your currently getting at least 60 fps, thats not bad at all.

    If you reduce scale/model size, i really dont think you will gain much, but you stated "the size of the models is pretty big", Scale the models to what would be "realistic", you will gain some. But remember that model/texture/material import settings also effect this. I have seen bad settings cause alot of havok.

    Example, this is just a piece of my Unity Bible of optimization. Maybe something in it might help. But remember, everyones project is different, so keep that in mind, but i still feel script functionality is your answer:

    ====OPTIMIZATION====
    --All assets, should have LODS, and adjusted correctly, (per project).
    -Adjusting the far/near clipping planes on the camera.
    -Increase the pixel error (for terrain). This results in more significant height-popping of terrain subsections.
    -Increase the detail distance (the distance that grass and detail meshes are visible).
    -Decrease the tree distance (the distance beyond which trees aren't drawn at all).
    -Decrease the billboard start (the distance at which tree meshes are replaced with billboards).
    -Reduce the Max Mesh Trees (the maximum number of trees which are displayed as meshes at any one time - any others will be displayed as billboards regardless of their proximity).
    -Remove reflection probes, if not needed/used.
    -Use texture atlas's.
    -If Minimap: use texture/screenshot of the world instead of camera, if possible.
    -Bake occlusion culling.
    -Reduce models polygons/tris.
    -Bake lightmaps, static/baked lightmaps.
    -Delete parts of models not needed.
    -Reduce number of textures per model.
    -Take off shadows on objects not needed.
    -Scale down textures, if needed - 2048 for high detail, 1024 for mid detail, 512 for low detail, etc.
    -Directional light - should be yellow-ish tint.
    -Color Space: linear.
    -Ambient light (if used): blue tint
    -Adjust light intensity.
    -Chunk/split up terrain and stream terrain tiles, if large/open world senarios.
    Texture Import Settings:
    Gen Mipmaps: true
    Max Size: 1024
    Compression: low quality (Lower Disc Size)
    Max Size: minimum
    Atlas textures:
    Remove Alpha Channel
    Disable: Read/Write Enabled
    16bit Over 32bit color
    Disable Mipmaps for UI
    Disable Streaming Mipmaps On: decal projector textures, refection probes textures, terrain textures
    Mesh Import Settings:
    Mesh Compression: use agressive compression
    Disable: read/write enabled
    Rig: if not using animation, disable Rig
    Blendshapes: disable if not using
    Normals And Tangents: if material is not using, disable
    ====Graphics====
    Batching: batch objects that have the same material/texture
    Use Static Batching Over Dynamic
    Disable Cast Shadow: shut off cast shadow on objects that dont need to cast a shadow
    Limit Use Of Reflection Probes, Shadows, and Lights
    Reflection Probe Settings: lower resolution, and area of effect
     
  22. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,967
    Well done, thats a great improvement :) With some more tweaks to other areas such as scripts you will be at 60fps+ solidly :)
     
    warthos3399 and Tom-Kazansky like this.