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.
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 ?
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 ?
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.
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…)
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.
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 ).
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.
@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.