Let’s say I have three nearby static meshes that share the same textures and the same material. I could merge them together into a single mesh in my 3D modeling tool to enforce them being rendered with a single drawcall, but I like the convenience of being able to reposition them individually in Unity3D and as far as I understand it static batching should achieve exactly the same - upon compilation these meshes will be merged together. Is this correct so far?
How will static batching be affected once occlusion culling is introduced (and how will static batching affect occlusion culling?). Will the meshes not be merged together? or will the merging avoid occlusion culling to work (let’s assume my whole scene shares the same material)? is it possible to somehow define groups of static meshes that shall be statically batched together, so that they can act as a single occluder/ocludee?
There are a few questions with distinct answers in your question, so please let me answer them piece by piece:
-
In case you would decide to go without static batching, there are still 2 more productive ways going forward than merging the meshes in your modelling app. Thats the Static Combine Functionality in Unity Pros or the Combine Children script of the ‘Scripts’ package installed along unity, which both allow you to combine the meshes in Unity
-
Static batching works along these lines but still different becuase it is not a ‘draw all or nothing’ scenario. It will draw the distinct meshes if their bounding boxes are within the visible area of your camera (or your main camera in case of OC)
-
The occlusion culling will work with either setup. To the occlusion culling it does not matter if its 1 mesh or 20 though as it operates on PVS (Potentially Visible Sets) and not the actual geometry once calculated, so you can replace the geometry or even throw it out the game completely if thats what you want to do (it hence makes sense to have simple and complete objects as occluders instead of using over detailed objects which require extremely dense pvs settings that take hours to days to calculate)
-
Static batching unlike the mesh merges from 1 will respond to occlusion culling properly and on an object to object base. Mesh merging can be extremely tricky (unless its a Quake style games with dedicated rooms and corridors connecting them) to do right when combined with occlusion culling because Unitys occlusion in general is mesh / object based and not triangle based. That means that if the bounding box of your mesh / combined mesh is in the view of the camera and not occluded, then the whole mesh will be rendered even if there is not a single triangle visible at the time. Also desktop graphic cards are incapable of properly handling this situation either, processing the whole invisible mesh and sending it to the gpu - on mobile GPUS from Imagination technology or Qualcomm (but not NVIDIA) all this hidden geometry is discarded in the first step already which reduces the dependence on PVS for this purpose at least (occlussion culling has other powerfull uses related to object activation and deactivation that are important though like animation that can stop updating the skeleton while out of view, a quite costly operation with complex skeletons)