GLSL shader example

Triplanar Mapping on an SDF Rock

Blend three planar projections using normal-axis weights to avoid relying on one projection for steep rock faces.

Live example

Edit the code and the preview updates as you type.

What to observe

Triplanar Mapping on an SDF Rock.

Mechanism

Blend three planar projections using normal-axis weights to avoid relying on one projection for steep rock faces.

The controlling code

return length(p)-.7-.07*sin(p.x*9.)*sin(p.y*8.)*sin(p.z*8.);

Experiment

Change the blend-weight exponent in pow(abs(normal),vec3(4.)) from 4. to 1.. The three projected image copies blend over broader regions, making their transitions easier to see on the bumpy rock.

Debugging and cost

Every surface hit adds three texture lookups after ray marching and normal estimation. Change all three projection scales *.5+.5 to *1.+.5 to increase texture frequency; the fixture clamps at its borders, so repeated image tiling will not appear automatically.

Built-in functions used

Learn it step by step