LYGIA Shader Library

tbn (lygia/space/tbn)

Tangent-Bitangent-Normal Matrix

Use:

mat3 tbn(vec3 t, vec3 b, vec3 n)

Check it on Github


#ifndef FNC_TBN
#define FNC_TBN

mat3 tbn(vec3 t, vec3 b, vec3 n) {
    return mat3(t, b, n);
}

mat3 tbn(vec3 n, vec3 up) {
    vec3 t = normalize(cross(up, n));
    vec3 b = cross(n, t);
    return tbn(t, b, n);
}

#endif

Use:

float3x3 tbn(float3 t, float3 b, float3 n)

Check it on Github


#ifndef FNC_TBN
#define FNC_TBN

float3x3 tbn(float3 t, float3 b, float3 n) {
    float3x3 M;
    M._m00_m10_m20 = t;
    M._m01_m11_m21 = b;
    M._m02_m12_m22 = n;
    return M;
}

float3x3 tbn(float3 n, float3 up) {
    float3 t = normalize(cross(up, n));
    float3 b = cross(n, t);
    return tbn(t, b, n);
}

#endif

License

MIT License (MIT) Copyright (c) 2024 Shadi El Hajj

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