LYGIA Shader Library

triplanar (lygia/sample/triplanar)

triplanar mapping

Dependencies:

Use:

<vec4> sample2DCube(in <SAMPLER_TYPE> lut, in <vec3> xyz)

Check it on Github




#ifndef SAMPLE_TRIPLANAR_FNC
#define SAMPLE_TRIPLANAR_FNC(TEX, UV) SAMPLER_FNC(TEX, UV)
#endif

#ifndef FNC_SAMPLETRIPLANAR
#define FNC_SAMPLETRIPLANAR
vec3 sampleTriplanar(SAMPLER_TYPE tex, in vec3 d) {
    vec3 colx = SAMPLE_TRIPLANAR_FNC(tex, d.yz).xyz;
    vec3 coly = SAMPLE_TRIPLANAR_FNC(tex, d.zx).xyz;
    vec3 colz = SAMPLE_TRIPLANAR_FNC(tex, d.xy).xyz;

    vec3 n = d*d;
    return (colx*n.x + coly*n.y + colz*n.z)/(n.x+n.y+n.z);
}

// iq's cubemap function
vec3 sampleTriplanar(SAMPLER_TYPE tex, in vec3 d, in float s) {
    vec3 colx = SAMPLE_TRIPLANAR_FNC(tex, 0.5 + s*d.yz/d.x).xyz;
    vec3 coly = SAMPLE_TRIPLANAR_FNC(tex, 0.5 + s*d.zx/d.y).xyz;
    vec3 colz = SAMPLE_TRIPLANAR_FNC(tex, 0.5 + s*d.xy/d.z).xyz;

    vec3 n = d*d;

    return (colx*n.x + coly*n.y + colz*n.z)/(n.x+n.y+n.z);
}
#endif

License

LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.

Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).

It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.

Get the latest news and releases

Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository