Urho3D Wiki

Tri-Planar Texturing

69pages on
this wiki
Add New Page
Comments0 Share

This is a bit based on this article:

Tri-Planar Texturing is a method of projecting a texture on a mesh without having texture seams or stretched textures. The texture is projected from each axis (local or world) and then blended together. This is especially useful for (dynamically created) terrain or other procedural generated meshes. There's no UV mapping needed with this technique.

Triplanar texturing2
Triplanar texturing1

The result in Urho3D. Left is with lighting (colored light) and right without.


#include "Transform.glsl"     // defines some variables we need
varying vec4 vLocalPos;       // local position (object space)
varying vec3 vLocalNormal; // local normal (object space) uniform sampler2D sTexture0; // a texture ... void VS() { vLocalNormal = iNormal; // fill local normal vLocalPos = iPos; // fill local position ... }

void PS() { ... vec3 weights=abs(vLocalNormal); // calculate the weights of the three projected textures
float sum=weights.x+weights.y+weights.z; // let all three axes/weights add up to 1.0 weights.x/=sum;
weights.z/=sum; vec4 diffColor=texture2D(sTexture0,vLocalPos.xy)*weights.z+ // project each of the three planes and blend together with the weights texture2D(sTexture0,vLocalPos.yz)*weights.x+ texture2D(sTexture0,vLocalPos.xz)*weights.y; diffColor*=cMatDiffColor; // optional, you may want to mix with the diffuse color parameter of the material ...

The same technique can be used for normal/specular maps as well.

[TODO: make ready to use materials and maybe new images]

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.