vec3 SphereSponge()

in src/elm_src/Algorithm/fractals.c [133:158]


vec3 SphereSponge(vec3 w)
{
    w *= objectRotation;
    float k = scale;
    float d = -10000.0;
    float d1, r, md = 100000.0, cd = 0.0;

    for (int i = 0; i < int(maxIterations); i++) {
        vec3 zz = mod(w * k, sphereHoles) - vec3(0.5 * sphereHoles) + offset;
        r = length(zz);

        // distance to the edge of the sphere (positive inside)
        d1 = (sphereScale - r) / k;
        k *= scale;

        // intersection
        d = max(d, d1);

        if (i < colorIterations) {
            md = min(md, d);
            cd = r;
        }
    }

    return vec3(d, cd, md);
}