Search Unity

Question What is the efficient way to display many items (game objects) for 3d?

Discussion in 'Game Design' started by shum88, Mar 3, 2023.

  1. shum88

    shum88

    Joined:
    Dec 16, 2022
    Posts:
    23
    Hi, as the title says, what is the efficient way to display many items?
    I have many shelves that contain 3d objects such as meat, fruit, vegetables, etc.

    I have items that are just for display, and some are intractable.
    I am worried that displayed items cause bad performance.
    How do you all handle performance in this kind of situation?
    Also, what is the best way to distinct interactable items?
     
  2. dogmachris

    dogmachris

    Joined:
    Sep 15, 2014
    Posts:
    1,375
    That's a rather generic question, so there's a ton of information on that:

    Use LOD to reduce the complexity of your objects when they're not in focus. There are tons of different LOD approaches, but the basic idea is to render high detail objects at close distances and replace them by low detail objects as they are farther away.

    Occlusion culling is another technique to save resrouces, it helps hide objects that aren't visible to the camera. It can make a huge difference.

    Object Pooling - Use object pooling to keep things running smoothly and avoid performance bottlenecks. Basically preload all objects to the scene, put them some place where they won't bother anyone and recycle them as you need them. This way you can create the illusion of having a lot more objects in the scene than you actually do. - also a drastuc performance booster.

    Batching - Who wants to do extra work? Batch up objects that share the same materials and shaders, and let Unity handle the rest.

    I hope this helps.
     
  3. shum88

    shum88

    Joined:
    Dec 16, 2022
    Posts:
    23
    Thank you so much! This is very helpful! I will look up Occlusion culling, Object Pooling, and the Batching :)
     
  4. dogmachris

    dogmachris

    Joined:
    Sep 15, 2014
    Posts:
    1,375
    Glad to be of help! Don't forget about LOD! And remember, optimizing your code is like eating your veggies - it may not be the most exciting thing in the world, but it's essential for the health of your project. Keep on coding, and happy optimizing!
     
  5. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,882
    Implement. Then check the performance. Is it okay? Good, nothing else needed. ;)
    Otherwise you have a concrete example you can get help for on the forum. You didn‘t even mention target platform which matters most regarding what optimizations are most helpful.
     
    angrypenguin likes this.
  6. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,619
    I'd strongly recommend looking into "instanced rendering", first of all to see if it's applicable to your scenario. If you're rendering lots of the same thing, or things with simple variations, then this can drastically cut down the CPU work required.
     
  7. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,634
    Another thing you can do is use a custom parallax map shader. I don't think Unity has a built-in parallax mapping shader unless maybe HDRP has one. If you have something like a trough full of oranges, for example, you don't need to model any individual oranges. Instead you could just have a single quad with a texture and normal map and heightmap and it will look like 3d oranges to the player. Of course this type of shader will have it's own performance impact, so youd have to weigh which is better.

    For things that are very small, like coffee beans or nuts, you could probably just use a texture and normal map and that will already work with Unity's standard and URP lit shaders.
     
    angrypenguin likes this.
  8. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,619
    A tessellation shader would also work for the box-of-oranges scenario, assuming your target platform supports it.

    As would just sub-dividing your plane and raising / lowering some verts manually.