Urho3D Wiki

This is a bit based on this article: http://gamedevelopment.tutsplus.com/articles/use-tri-planar-texture-mapping-for-better-terrain--gamedev-13821

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.jpg

Triplanar texturing1.jpg

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]