If we have multiple materials in the same cube, we need to seperate the render proxy into mesh batches
Materials in one Static Mesh
Now it’s time to look at the FStaticMeshSceneProxy
more.
Let's consider another example, this mesh:
Is it possible to render a mesh in one draw call if it has three different materials?
No, it is not possible because we need to switch shaders between those materials.
Mesh Batch
So this means we need another structure to deal with this problem, it’s FMeshBatch
.
So our story becomes:
- The render thread takes the rendering data, both the runtime data (render proxies from components) and the common data (render datas from assets), and render the image.
- For each
FStaticMeshSceneProxy
- Get many
FMeshBatch
- For each
FMeshBatch
- Render this mesh batch
By the way, our simple cube is so simple, that only have one mesh batch.
Question for the Next Step
Even if we focus on a Cube with only 1 Mesh Batch, we still cannot convert it directly into a single Draw Call. This is because we need to render this Cube in multiple different Passes: the ZPrePass for depth culling, the BasePass for filling the GBuffer, the Shadow Pass for drawing shadows...
Therefore, it is necessary to split the Mesh Batch according to Passes, which introduces our next level: MeshDrawCommand.