LYGIA Shader Library

hexTile (lygia/space/hexTile)

make some hexagonal tiles. XY provide coordenates of the tile. While Z provides the distance to the center of the tile

Use:

<vec4> hexTile(<vec2> st)

Check it on Github


#ifndef FNC_HEXTILE
#define FNC_HEXTILE

vec4 hexTile(vec2 st) {
    vec2 s = vec2(1., 1.7320508);
    vec2 o = vec2(.5, 1.);
    st = st.yx;

    vec4 i = floor(vec4(st,st-o)/s.xyxy)+.5;
    vec4 f = vec4(st-i.xy*s, st-(i.zw+.5)*s);

    return dot(f.xy,f.xy) < dot(f.zw,f.zw) ? 
            vec4(f.yx+.5, i.xy):
            vec4(f.wz+.5, i.zw+o);
}
#endif

Use:

<float4> hexTile(<float2> st)

Check it on Github


#ifndef FNC_HEXTILE
#define FNC_HEXTILE

float4 hexTile(float2 st) {
    float2 s = float2(1., 1.7320508);
    float2 o = float2(.5, 1.);
    st = st.yx;

    float4 i = floor(float4(st,st-o)/s.xyxy)+.5;
    float4 f = float4(st-i.xy*s, st-(i.zw+.5)*s);

    return dot(f.xy,f.xy) < dot(f.zw,f.zw) ? 
            float4(f.yx+.5, i.xy):
            float4(f.wz+.5, i.zw+o);
}

#endif

Examples

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