Decompiled: Meshes

Structure

A mesh is a data structure representing a discrete geometric surface and serves as the primary geometry format in real-time rendering systems. The following article outlines the internal structure and operational principle of meshes, progressing from the abstractions used by DCCs (Digital Content Creation software) to the memory-level representation processed by the GPU. Intermediate layers function only as conceptual aids; the final layer approximates the authoritative storage model, with exact implementation determined by the GPU architecture.

Tier 0: What the Artist sees

DCCs implement mesh abstractions with varying amounts of variation, but most converge on three fundamental concepts:

[insert image showing vertices, edges and faces]

  • Vertices: Points in space.
  • Edges: The connection between two Vertices.
  • Faces: The surface area formed between (at least) 3 Edges.

It is by manipulating these fundamental components that a 3D artists traditionally produce 3D models, whether by manually creating vertices, connecting them into edges before connecting edges together to form faces, using sculpting tools to manipulate and create vertices en-masse, or use something akin to blenders geometry nodes to generate a 3D model with other inputs, whether it’d be pure math or textures.

An Artist is not limited to simply modifying these properties, however. They can usually modify the appearance of their mesh in many other ways. The most relevant are:

Smooth/Hard shading

[Insert image of Smooth/Hard Shading]

Most DCCs allow the user to toggle between Smooth and Hard shading on a per-mesh, per-face or per-edge basis. Usually, it is also possible to set some rule, such as smooth shade any edge with an angle greater than 30 degrees.

UVs

[Insert image displaying UVs]
[Insert image displaying connected UV vs UV Island]

UVs are primarily used for displaying a texture on your model.

Vertex Color

[Insert image displaying Vertex Colors]

Tier 1: Vertices are where it’s at

While DCCs tend to tell us the lie that various attributes of our mesh has settings, this isn’t necessarily true. For example, an edge/face cannot be “hard” and vertex can’t be in 2 places on the same UV map. Now, you might be thinking to yourself “that can’t be right, I split UVs all the time!” or “what do you mean, I use hard edges all the time!” and while that’s true in DCC terms, under the hood both these scenarios actually work in the same.

The DCC simply splits the vertex into 2 vertices under the hood.

For more information about how these properties are used at runtime, see Decompiled/Mesh Series Partt 2: Rendering

Tier 2: High-Level API

A mesh consists of multiple arrays, one of each mesh attribute of the appropriate type. If a mesh does not have an attribute, the corresponding array is null.
Elements of the same index belong to the same vertex
For example, a mesh with just Normal and Color might look like this:

int[] Indices
float3[] Positions
float3[] Normals
float4[] Colors

Position and Indices are always required. Indices stores the indices of the vertices that make up a triangle and has to be a multiple of 3.

Tier 3: Low-Level API

A mesh consists of multiple arrays, one for each attribute. Each attribute will be one of any valid Format and Dimension combination (has to be multiple of 4). Not all GPUs support all formats.

Tier 4: GPU Structure

A mesh consists of multiple arrays called streams, these contain the intervowen data of all vertex attributes belonging to the appropriate stream.


Rendering

  1. Mesh exists on CPU
  2. Mesh is sent to GPU
  3. Mesh

Performance

Now that we know how meshes work, we can investigate the performance overhead of a mesh.
This cost is closely related to shaders and the GPU rendering pipeline. For this reason, the section is similarly broken up into two, one for a simple overview and one for indepth analysis requiring pre-requisite knowledge.

Tier 0: Simple Overview

  • Vertex Count: Runtime + Memory Cost
  • Polygon Count: Small Runtime + Small Memory Cost
  • Face Area: Big Runtime Cost

Tier 1: Detailed Breakdown

Runtime

  • Vertex Shader * Vertex Count
  • Attributes * Triangles