Triplanar color and displacement mapping

calendar_today

04.03.2023

label

Modeling, Texturing

mouse

Houdini 19.5

Description

Blending texture maps from top, front and side for coloring and displacing a mesh.

1 Code

function vector triplanar(vector uvw, nml; string tex; float blend){
    vector x = set(uvw.y, uvw.z, 0.0);
    vector y = set(uvw.z, uvw.x, 0.0);
    vector z = set(uvw.x, uvw.y, 0.0);
    
    x = colormap(tex, x);
    y = colormap(tex, y);
    z = colormap(tex, z);
    
    vector m = pow(abs(nml), blend);
    vector c = (x*m.x + y*m.y + z*m.z) / (m.x + m.y + m.z);
    return c;
}

float blend = chf('blend');
string tex_diff = chs('diffuse');
string tex_disp = chs('displace');
float amount = chf('amount');

vector bb = relbbox(0, v@P);

v@Cd = triplanar(bb, v@N, tex_diff, blend);
v@P += v@N * triplanar(bb, v@N, tex_disp, blend) * amount;

2 Article

A nice read to take this further:
https://iquilezles.org/articles/biplanar/

download

Downloads