LYGIA Shader Library

triTile (lygia/space/triTile)

make some triangular tiles. XY provide coords inside of the tile. ZW provides tile coords

Use:

<vec4> triTile(<vec2> st [, <float> scale])

Check it on Github


#ifndef FNC_TRITILE
#define FNC_TRITILE
vec4 triTile(vec2 st) {
    st *= mat2(1., -1. / 1.7320508, 0., 2. / 1.7320508);
    vec4 f = vec4(st, -st);
    vec4 i = floor(f);
    f = fract(f);
    return dot(f.xy, f.xy) < dot(f.zw, f.zw)
                ? vec4(f.xy, vec2(2., 1.) * i.xy)
                : vec4(f.zw, -(vec2(2., 1.) * i.zw + 1.));
}

vec4 triTile(vec2 st, float scale) { return triTile(st * scale); }
#endif

Use:

<float4> triTile(<float2> st [, <float> scale])

Check it on Github


#ifndef FNC_TRITILE
#define FNC_TRITILE
float4 triTile(float2 st) {
    st = mult(float2x2( 1.0, -1.0 / 1.7320508, 
                        0.0, 2.0 / 1.7320508), st);
    float4 f = float4(st, -st);
    float4 i = floor(f);
    f = frac(f);
    return dot(f.xy, f.xy) < dot(f.zw, f.zw)
                ? float4(f.xy, float2(2., 1.) * i.xy)
                : float4(f.zw, -(float2(2., 1.) * i.zw + 1.));
}

float4 triTile(float2 st, float scale) { return triTile(st * scale); }
#endif

Use:

<float4> triTile(<float2> st [, <float> scale])

Check it on Github


#ifndef FNC_TRITILE
#define FNC_TRITILE
float4 triTile(float2 st) {
    st *= mat2(1., -1. / 1.7320508, 0., 2. / 1.7320508);
    float4 f = float4(st, -st);
    float4 i = floor(f);
    f = fract(f);
    return dot(f.xy, f.xy) < dot(f.zw, f.zw)
                ? float4(f.xy, float2(2., 1.) * i.xy)
                : float4(f.zw, -(float2(2., 1.) * i.zw + 1.));
}

float4 triTile(float2 st, float scale) { return triTile(st * scale); }
#endif

Examples

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