April 25, 2009

Tri-Planar Texturing

Texture distortion occurs when images are stretched across surfaces. This can be caused by non-uniformly spaced texture coordinates or verticies. This doesn't happen very often with relatively small models like characters, vehicles or objects in a game. Such art assets are usually maintained by artists and have correct texture wraps. The real challenge lies with terrain.

Terrain is large, sometimes infinite and would be unreasonable to create texture coordinates by hand. It's best to construct texture coordinates based on world coordinates. Common practice involves projecting textures along one plane on top of the terrain. When there are steep surfaces this causes texture distortion.

Tri-planar texturing solves this problem by projecting textures along all three planes and then blending appropriately between the textures. Three sets of texture coordinates are created based on the xy, yz and zx planes. These coordinates are then used to sample from the various textures. The blend weights are computed based on the normal of the surface where the texture is to be applied.

My junior game project included very large terrains. We chose to apply rock texture to the steep cliff surfaces and grass and dirt elsewhere in the levels. To avoid stretching the rock texture I adapted the tri-planar technique on the cliffs. The image on the left shows the stretching that can happen. The image on the right shows the rock texture applied to the cliff faces without stretching.

Highslide JS
Highslide JS

Additional information can be found in the NVIDIA Cascades Demo.

1 comment:

  1. Good stuff Justin. This is the exact same technique I use for the terrain texturing on my procedural universe project:

    http://johnwhigham.blogspot.com/

    ReplyDelete