Mesh Batches

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:

image

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.

Look at this image from Direct3D 11 offcial documents. It tells you that you cannot ask DX11 API to use more than one shader for the samge stage, aka. draw with more than one pixel shader.

Mesh Batch

So this means we need another structure to deal with this problem, it’s FMeshBatch.

image

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

image

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.