LYGIA Shader Library

juliaSDF (lygia/sdf/juliaSDF)

Returns the Juia set SDF For more information about the Julia set, check this article Some values for c: * vec2(−0.8, 0.156) * vec2(0.285, 0.0) * vec2(-0.8, 0.156); * vec2(0.27334, 0.00742) * vec2(−0.835, −0.2321)

Dependencies:

Use:

juliaSDF(<vec2> st, <vec2> c, <float> r)

Check it on Github



#ifndef FNC_JULIASDF
#define FNC_JULIASDF
float juliaSDF( vec2 st, vec2 center, vec2 c, float r) {
    st -= 0.5;
    st *= 2.0;
    vec2 z = vec2(0.0) - (st) * r;
    float n = 0.0;
    const int I = 500;
    for (int i = I; i > 0; i--) { 
        if ( length(z) > 4.0 ) { 
            n = float(i)/float(I); 
            break;
        } 
        z = vec2( (pow2(z.x) - pow2(z.y)) + c.x, (2.0*z.x*z.y) + c.y ); 
    } 
    return n;
}

float juliaSDF( vec2 st, vec2 c, float r) {
    #ifdef CENTER_2D
        return juliaSDF(st, CENTER_2D, c, r); 
    #else 
        return juliaSDF(st, vec2(0.5), c, r); 
    #endif
}
#endif

Dependencies:

Use:

juliaSDF(<float2> st, <float2> c, <float> r)

Check it on Github



#ifndef FNC_JULIASDF
#define FNC_JULIASDF
float juliaSDF( float2 st, float2 c, float r) {
    st = st * 2.0 - 1.0;
    float2 z = float2(0.0) - (st) * r;
    float n = 0.0;
    const int I = 500;
    for (int i = I; i > 0; i --) { 
        if ( length(z) > 4.0 ) { 
        n = float(i)/float(I); 
        break;
        } 
        z = float2( (pow2(z.x) - pow2(z.y)) + c.x, (2.0*z.x*z.y) + c.y ); 
    } 
    return n;
}
#endif

Dependencies:

Use:

juliaSDF(<float2> st, <float2> c, <float> r)

Check it on Github



#ifndef FNC_JULIASDF
#define FNC_JULIASDF
float juliaSDF( float2 st, float2 center, float2 c, float r) {
    st -= 0.5;
    st *= 2.0;
    float2 z = float2(0.0) - (st) * r;
    float n = 0.0;
    const int I = 500;
    for (int i = I; i > 0; i--) { 
        if ( length(z) > 4.0 ) { 
            n = float(i)/float(I); 
            break;
        } 
        z = float2( (pow2(z.x) - pow2(z.y)) + c.x, (2.0*z.x*z.y) + c.y ); 
    } 
    return n;
}

float juliaSDF( float2 st, float2 c, float r) {
    #ifdef CENTER_2D
        return juliaSDF(st, CENTER_2D, c, r); 
    #else 
        return juliaSDF(st, float2(0.5), c, r); 
    #endif
}
#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