Course contentsShow
← Unity Game Development
Lesson 619 of 8289. Rendering and VisualsFree lesson

Adding World-Space Triplanar Mapping

Implement triplanar projection to ensure textures map correctly across complex meshes without requiring manual UV unwrapping.

In this lesson, you will learn how to bypass traditional UV unwrapping by using world-space triplanar mapping to project textures onto complex meshes from three distinct directions.

The Problem with UVs

Standard UV mapping relies on a 2D "skin" unwrapped from a 3D object. If a mesh has complex geometry or is procedurally generated, creating distortion-free UVs can be time-consuming or impossible. Triplanar mapping solves this by ignoring the object's UV coordinates entirely and instead sampling textures based on the object’s position in the world.

How It Works

The concept uses the surface's Normal Vector to decide which of the three primary axes (X, Y, or Z) should influence the texture sampling. Imagine three projectors placed infinitely far away, shining onto the object from the top, the front, and the side. The shader samples all three, then blends them together based on the steepness of the surface.

In Shader Graph, you implement this by:

  1. Transforming the Object Normal to World Space.
  2. Using the Absolute node on the World Position to ensure the texture repeats correctly on both sides of the origin.
  3. Splitting the Position into XYZ components.
  4. Sampling your texture three times: using (Y, Z) for the X-axis, (X, Z) for the Y-axis, and (X, Y) for the Z-axis.

You then use the Normal vector as a mask to blend these samples. If a surface is pointing straight up (like a floor), the Y-axis projection receives the most weight, effectively masking out the "streaking" that would occur if you stretched a single texture across the sides.

// Conceptual logic for blending projections
float3 blending = abs(normal);
blending /= (blending.x + blending.y + blending.z);

float4 color = texX * blending.x + texY * blending.y + texZ * blending.z;

By calculating these weights, the texture seamlessly transitions across edges regardless of the mesh topology. This is the industry-standard technique for terrain, modular architecture, and large environmental props where you want consistent tiling without the manual labor of unwrapping.

Key Takeaway: Triplanar mapping eliminates UV distortion on complex meshes by projecting textures along the X, Y, and Z axes of world space and blending them based on surface orientation.