Working with Meshes in Unreal Engine

How to with Meshes in the Unreal Engine?

Static Mesh (SM) vs Instance SM (ISM)

  • Static Mesh Components
    • Every single mesh contains:
      • Transform
      • Mesh, materials
      • Physics, collision
      • Lighting
    • Rendering: at least 1 draw call per movable SM

    Result: Heavy to render

  • Single Instance
    • An instance contains:
      • Transform
    • Other properties (mesh, material, ...) are common for the whole group
    • Rendering: all instances drawn at once

    Result: Lightweight to render

Why rendering separate objects is slow?

  • GPUs are crazy fast at rendering polygons ... but it needs to be fed with data by the (slow) CPU
  • OpenGL and DirectX (Up to 11) have a global state - it points to a buffer of vertices and the material to draw with
  • Want to draw another mesh or change the material? The CPU will issue a new command, a draw call

Drawing 100 meshes

  • Single meshes
    • Apply properties - 100x
    • Set material - 100x
    • Draw - 100x.

    Draw call is slow. It goes also through the graphics driver, which isn't helping

  • Partial solution
    • Combine pieces into a single big mesh
      • + Only a few draw calls
      • - Culling hides entire object
      • - Huge weight, LODs are hard to work with

      → Worth to use only for groups of nearby objects

  • 100 instances
    • Upload an array of 100 transforms
    • Set material
    • Draw (in one call)

Instanced Static mesh

  • One template mesh for all copies
  • It does not work with Level of Detail (LoD)

Hierarhical Instanced Static mesh

Like Instanced Static Mesh, but contains multiple instances groups - one group for each LOD (Level Of Detail). The instances are then moved between the groups based on the distance.