Optimizing a big map (Shadows,Lights,GI ...)

Hello Everyone,

i have a scene with a map ~1.4KM² and around 400K GameObjects.

!im totally new to Scene optimization!

im trying to bake my whole scene lights and shadows, but each time the Unity Editor crashes in the midle of the baking process, i think i certainly did something wrong.

i have few Questions about scene optimization.

  1. 99% of my GameObjects are static, some of them are big gameobjects other are small ones.
    what is the best approach to bake their Shadows ?

  2. i read on some forums that it’s not good to always combine close GOs by marking them as Static sometimes it’s better to use the Dynamic Batching instead.
    in which case should i use Dynamic Batching or Static Batching?
    how can i do it ?

Thank you!

[Edit] my game is a TopDown style.

try dividing the scene into multiple scenes and load them async at runtime only when needed

1 Like

Another thing to consider is whether or not static lighting is even appropriate for your scene to begin with. You’ll find that lightmaps tend to eat up space quite quickly on large maps (assuming you’re baking with enough resolution that it looks decent) and are generally better suited to interior scenes where the bounds of the level tend to be smaller.

In this case, you may actually find that mostly/fully dynamic lighting is worth the tradeoff here, though obviously global illumination (or the lack thereof) will likely be one of the hardest compromises. Unity promised a new GI solution coming around 2021 which should hopefully alleviate this issue, but that’s a ways off still. In the meantime, you may see if you can get away with baked GI at a really low resolution + dynamic shadows to at least cut down on bake time and some storage cost.

That being said, mesh batching/combining is still important for performance regardless of lighting technique, so your 2nd question is still valid. In general, the main drawback to combining meshes is the ability to cull them separately and use LODs (since it’s now one big object). If you think the meshes will nearly always be rendered together and it makes sense to combine them, then combine away. However, it may actually be better to leave them separate so that you can use LODs to reduce the amount of polygons you have to render overall (in addition to allowing them to be culled). A great addition to this technique is to use an impostor as the final LOD level (I personally have gotten good results with Amplify Impostors on the asset store, though it’s $60 at the time of writing) which lets you cut objects down to just a billboard with a bit of fancy trickery going on to fake depth/rotation.

If you do leave them separate, I believe static batching is generally preferred for runtime performance and dynamic is better for less memory usage (see here: Unity - Manual: Draw call batching). Even better though, is if you are using the same material for many of them and they can be GPU instanced. The standard shader has a checkbox to enable instancing, so if you’re just using the standard shader, I’d say give that a shot fist since it’s easy and see how much it helps. If it’s not enough (or the materials are can’t be shared), batching the objects probably would be a good idea.

Hope that helps answer your questions.

3 Likes

Thanks @GuitarBro
I forgot to specify that my game is a top down game so i don’t need LODs.
I’m using unity 2019.3 and I’m facing a little problem I can’t bake shadows I marked all my gameobjects as static and after the baking process all shadows still dynamic.
Also I have another question:
is it possible to use GPU instancing and bake shadows at the same time ?

For more infos, most of my objects are small props with same material and casting shadows.(grass…)

1 Like

Ah, top down is even better because you can easily figure out what’s offscreen and hide it. In that case, @GuardHei_1 's suggestion of splitting the scene would be good on a large scale (don’t want to make it too granular or you’ll be constantly loading/unloading stuff as you move) but for smaller scale stuff, simply making sure that culling is enabled should help.

As for the shadows, I’m not 100% sure, but I don’t believe Unity allows baked shadows and GPU instancing. In that case, you’d probably want to use static batching for as much as possible and let dynamic objects be dynamically batched (as possible). If you split the scene, you could at least bake them individually which should be much faster to update if only one scene changes.

1 Like

@GuitarBro do you have any idea why shadows still dynamic even for static GameObjects ?

Do you have baked lighting enabled in your lighting settings and the light casting the shadows has them set to “baked”?

ScreenShot1 :

ScreenShot2:

Seems fine, but what about the Light itself?

I’d suggest baking nothing at all for those scales. Use realtime shadows, control reflection probe / shader for a better bounce lighting look.

You’ll bake forever at those dimensions or you will be reducing the resolution so much it doesn’t make sense. You have hit an AAA wall.

2 Likes

Shadows are really changing the game visuals and makes it much better but using the real-time makes it unplayable for Low end devices.
For examples in a Oneplus2 in certain regions the game goes under 20fps when still 60fps for SamsungS8 ( high drawcalls ).

Mixed light.

I believe that should work allow for some baking, assuming the objects are static. There may be something else for baking that I’m not remembering needs to be set (I almost never bake lights these days for the reasons @hippocoder mentioned).

As for performance of realtime shadows though, have you made sure your shadowmap distance is set appropriately in the quality settings? You want to run it with the smallest distance and lowest resolution that looks acceptable. Realtime shadows get very costly the bigger they are.

1 Like

@GuitarBro my problem is im having a lot of small props concentrated in certain areas, so the realtime Shodows are creating high draw calls numbers (~250 ), which slows the rendering in mobile devices.
this is why im trying to bake as much a possible.

Those sound like they may be good candidates for combining the meshes. Another option is to disable casting shadows for those objects since they’re small. Using a screenspace contact shadow solution might help make that more bearable, but you’d pay the cost of screenspace shadows then which may or may not be acceptable.

As for why it’s still using realtime shadows, did you make sure your Shadowmask mode is set to “Shadowmask” not “Distance Shadowmask” in the quality settings? If it’s using “Distance Shadowmask” it chooses to use realtime shadows up to the shadow distance and falls back to baked only after that distance.

yes i just verified and still not baking the Shadows.
Note: the baking time is very low arround 30 seconds.

Hm. The only other thing I can think of is that the objects are not marked as lightmap static. If they are, then I’ve got no clue. :face_with_spiral_eyes:

i dont see any lightmap static option.

Oh apparently in 2019.2 they removed “Lightmap Static” and replaced it with the “Contribute GI” flag. Check that one and see if it that does it.

Here’s the article I saw that in, for reference:
https://blogs.unity3d.com/2019/08/28/static-lighting-with-light-probes/