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 SAMPLETRIPLANAR_TYPE
#define SAMPLETRIPLANAR_TYPE vec4
#endif

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

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

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

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

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

Dependencies:

Use:

<float4> sample2DCube(in <SAMPLER_TYPE> lut, in <float3> xyz)

Check it on Github




#ifndef SAMPLETRIPLANAR_TYPE
#define SAMPLETRIPLANAR_TYPE float4
#endif

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

#ifndef FNC_SAMPLETRIPLANAR
#define FNC_SAMPLETRIPLANAR
SAMPLETRIPLANAR_TYPE sampleTriplanar(SAMPLER_TYPE tex, in float3 d) {
    SAMPLETRIPLANAR_TYPE colx = SAMPLETRIPLANAR_FNC(tex, d.yz);
    SAMPLETRIPLANAR_TYPE coly = SAMPLETRIPLANAR_FNC(tex, d.zx);
    SAMPLETRIPLANAR_TYPE colz = SAMPLETRIPLANAR_FNC(tex, d.xy);

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

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

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

Licenses

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