How glTF Manages Texture Wrapping Modes

The glTF (GL Transmission Format) specification handles texture wrapping modes by defining sampler configurations directly within its JSON structure, dictating how a runtime engine samples texture coordinates (UVs) that fall outside the standard [0.0, 1.0] range. Using dedicated properties for both horizontal and vertical UV axes, glTF maps OpenGL/WebGL-compatible integer constants to determine whether textures repeat continuously, clamp tightly to edge pixels, or flip back and forth in an alternating pattern.

The Sampler Object Architecture

In a glTF file, textures are decoupled into three core concepts: the image source (images), the material reference (textures), and the sampling behavior (samplers). A texture references a sampler index. This sampler object contains two explicit integer properties dedicated to wrapping behavior:

  • wrapS: Dictates texture wrapping along the horizontal UV axis (S/U coordinate).
  • wrapT: Dictates texture wrapping along the vertical UV axis (T/V coordinate).

Because wrapS and wrapT are configured independently, a glTF asset can use different wrapping modes on each axis simultaneously, such as repeating horizontally while clamping vertically.

Supported Wrapping Modes and Enumeration Values

glTF utilizes OpenGL and WebGL integer constants to represent wrapping modes. The specification supports three standard behaviors:

  • CLAMP_TO_EDGE (Value: 33071): Coordinates outside the [0.0, 1.0] range take the color of the closest edge pixel on the texture boundary. This prevents seam artifacts or visible tiling when mapping discrete decals, UI elements, or textures mapped to non-repeating geometry.
  • REPEAT (Value: 10497): The integer component of the texture coordinate is ignored, causing the texture pattern to loop indefinitely across the surface. This is standard for repeating patterns like brick walls, terrain, or fabrics.
  • MIRRORED_REPEAT (Value: 33648): The texture repeats continuously, but every odd repetition mirrors the image along the respective axis. This creates seamless tiling for textures that do not inherently align cleanly at their edges.

Default Behaviors and Fallbacks

If a glTF file defines a texture without referencing a sampler, or if the referenced sampler omits the wrapS or wrapT keys, glTF specifies that both axes default to REPEAT (10497). This design guarantees consistent behavior across engines like Three.js, Babylon.js, and Unreal Engine without requiring explicit definitions in every asset file.

Implementation in the glTF JSON Schema

A typical glTF implementation defining wrapping modes appears as follows:

{
  "samplers": [
    {
      "magFilter": 9729,
      "minFilter": 9987,
      "wrapS": 10497,
      "wrapT": 33071
    }
  ],
  "textures": [
    {
      "sampler": 0,
      "source": 0
    }
  ]
}

In this configuration, the engine evaluates the texture at index 0 using sampler 0, resulting in a texture that loops infinitely along its horizontal axis (wrapS: 10497) and stretches its edge boundary pixels along its vertical axis (wrapT: 33071).