glTF Vertex Color Encoding and Interpretation

This article provides an overview of how raw vertex colors are defined, stored, and rendered according to the glTF 2.0 specification. It covers the required attribute naming conventions, supported data formats, component normalization, linear color space requirements, and how these values integrate into the glTF physically based rendering (PBR) pipeline.

Attribute Naming and Accessors

In the glTF 2.0 specification, vertex colors are stored as mesh primitive attributes using the semantic name COLOR_0 (or COLOR_n for additional color sets). Each color attribute points to an accessor object, which defines how to read the underlying binary buffer data.

Supported Data Types and Layouts

Vertex colors must be defined as either three-component vectors (VEC3) representing RGB or four-component vectors (VEC4) representing RGBA. The component types allowed for vertex colors are:

  • 5121 (UNSIGNED_BYTE): 8-bit unsigned integers. When used, the accessor's normalized property must explicitly be set to true, mapping the range [0, 255] to the floating-point range [0.0, 1.0].
  • 5123 (UNSIGNED_SHORT): 16-bit unsigned integers. The accessor's normalized property must also be set to true, mapping the range [0, 65535] to the floating-point range [0.0, 1.0].
  • 5126 (FLOAT): 32-bit floating-point values representing colors directly within the standard range [0.0, 1.0].

If a primitive uses a VEC3 format, the alpha component is implicitly assumed to be 1.0.

Color Space Interpretation

A critical requirement of the glTF specification is that vertex colors are interpreted in Linear sRGB color space.

Unlike color textures (such as baseColorTexture), which are typically encoded in non-linear sRGB and require conversion in the shader, raw vertex color data must already represent linear values. Client implementations must not apply an sRGB-to-linear transfer function (gamma expansion) to normalized or floating-point vertex colors.

Integration in the PBR Material Pipeline

Once decoded into linear RGBA values, vertex colors directly modify the surface base color in the metallic-roughness and specular-glossiness material workflows.

The glTF shading model specifies that vertex colors are applied via component-wise multiplication with the material's base color properties:

\[\text{Final Base Color} = \text{COLOR\_0} \times \text{baseColorFactor} \times \text{baseColorTexture}\]

If no base color texture is assigned, the vertex color multiplies only the baseColorFactor. If no vertex color is present on the mesh, the vertex color term defaults to a neutral (1.0, 1.0, 1.0, 1.0).