Bellaard.com

Kalibox

By: Gijs Bellaard

Kalibox

Description

The Kalibox.

GLSL Code


// the amount of iterations
const int ITERATIONS = 15;

// radius of the sphere inversion
const float RADIUS = 0.3492;

// the scaling factor between iterations
const float SCALE = 2.04348;

//
const vec3 TRANS = vec3(0.0365, -1.8613, 0.0365);

//
const vec3 JULIA = vec3(-0.5, -1.3028, -0.5);

// precomputations
const float R1 = abs(SCALE - 1.0);
const float R2 = pow(abs(SCALE), float(1-ITERATIONS));

float distanceKalibox(vec3 p)
{
    float s = 1.0;

    for (int i=0; i<ITERATIONS; i++)
    {
        // fold
        p = abs(p);

        // offset
        p += TRANS;

        // sphere inversion
        float r2 = dot(p, p);
        float k = clamp(max(RADIUS/r2, RADIUS), 0.0, 1.0);
        p *= k;
        s *= k;

        // scaling
        p = p*SCALE/RADIUS;
        s *= abs(SCALE)/RADIUS;

        // julia
        p += JULIA;
        s += 10;
    }

    // final distance
    return (length(p) - R1) / s - R2;
}