LYGIA Shader Library

starSDF (lygia/v1.1.4/sdf/starSDF)

Returns a star-shaped sdf with V branches

Dependencies:

Use:

starSDF(<vec2> st, <int> V, <float> scale)

Check it on Github



#ifndef FNC_STARSDF
#define FNC_STARSDF
float starSDF(in vec2 st, in int V, in float s) {
    st = st * 4. - 2.;
    float a = atan(st.y, st.x) / TAU;
    float seg = a * float(V);
    a = ((floor(seg) + .5) / float(V) +
        mix(s, -s, step(.5, fract(seg))))
        * TAU;
    return abs(dot(vec2(cos(a), sin(a)),
                   st));
}
#endif

Dependencies:

Use:

starSDF(<float2> st, <int> V, <float> scale)

Check it on Github



#ifndef FNC_STARSDF
#define FNC_STARSDF
float starSDF(in float2 st, in int V, in float s) {
    st = st * 4. - 2.;
    float a = atan2(st.y, st.x) / TAU;
    float seg = a * float(V);
    a = ((floor(seg) + .5) / float(V) +
        lerp(s, -s, step(.5, frac(seg))))
        * TAU;
    return abs(dot(float2(cos(a), sin(a)),
                   st));
}
#endif

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 or follow the Github repository