lygia
/sdf
/mandelbulbSDF
)Returns the mandelbulb SDF For more information about the mandlebulb, check this article
Dependencies:
lygia
/space
/cart2polar
.glsl
Use:
mandelbulbSDF(<vec2> st)
#ifndef FNC_MANDELBULBSDF
#define FNC_MANDELBULBSDF
vec2 mandelbulbSDF( in vec3 st ) {
vec3 zeta = st;
float m = dot(st,st);
float dz = 1.0;
float n = 8.0;
const int maxiterations = 20;
float iterations = 0.0;
float r = 0.0;
float dr = 1.0;
for (int i = 0; i < maxiterations; i+=1) {
dz = n*pow(m, 3.5)*dz + 1.0;
vec3 sphericalZ = cart2polar( zeta );
float newx = pow(sphericalZ.x, n) * sin(sphericalZ.y*n) * cos(sphericalZ.z*n);
float newy = pow(sphericalZ.x, n) * sin(sphericalZ.y*n) * sin(sphericalZ.z*n);
float newz = pow(sphericalZ.x, n) * cos(sphericalZ.y*n);
zeta.x = newx + st.x;
zeta.y = newy + st.y;
zeta.z = newz + st.z;
m = dot(zeta, zeta);
if ( m > 2.0 )
break;
}
// distance estimation through the Hubbard-Douady potential from Inigo Quilez
return vec2(0.25*log(m) * sqrt(m) / dz, iterations);
}
#endif
Dependencies:
lygia
/space
/cart2polar
.glsl
Use:
mandelbulbSDF(<vec2> st)
#ifndef FNC_MANDELBULBSDF
#define FNC_MANDELBULBSDF
float2 mandelbulbSDF( float3 st ) {
float3 zeta = st;
float m = dot(st,st);
float dz = 1.0;
float n = 8.0;
const int maxiterations = 20;
float iterations = 0.0;
float r = 0.0;
float dr = 1.0;
for (int i = 0; i < maxiterations; i+=1) {
dz = n*pow(m, 3.5)*dz + 1.0;
float3 sphericalZ = cart2polar( zeta );
float newx = pow(sphericalZ.x, n) * sin(sphericalZ.y*n) * cos(sphericalZ.z*n);
float newy = pow(sphericalZ.x, n) * sin(sphericalZ.y*n) * sin(sphericalZ.z*n);
float newz = pow(sphericalZ.x, n) * cos(sphericalZ.y*n);
zeta.x = newx + st.x;
zeta.y = newy + st.y;
zeta.z = newz + st.z;
m = dot(zeta, zeta);
if ( m > 2.0 )
break;
}
// distance estimation through the Hubbard-Douady potential from Inigo Quilez
return float2(0.25*log(m) * sqrt(m) / dz, iterations);
}
#endif
Dependencies:
lygia
/space
/cart2polar
.glsl
Use:
mandelbulbSDF(<float2> st)
#ifndef FNC_MANDELBULBSDF
#define FNC_MANDELBULBSDF
float2 mandelbulbSDF( float3 st ) {
float3 zeta = st;
float m = dot(st,st);
float dz = 1.0;
float n = 8.0;
const int maxiterations = 20;
float iterations = 0.0;
float r = 0.0;
float dr = 1.0;
for (int i = 0; i < maxiterations; i+=1) {
dz = n*pow(m, 3.5)*dz + 1.0;
float3 sphericalZ = cart2polar( zeta );
float newx = pow(sphericalZ.x, n) * sin(sphericalZ.y*n) * cos(sphericalZ.z*n);
float newy = pow(sphericalZ.x, n) * sin(sphericalZ.y*n) * sin(sphericalZ.z*n);
float newz = pow(sphericalZ.x, n) * cos(sphericalZ.y*n);
zeta.x = newx + st.x;
zeta.y = newy + st.y;
zeta.z = newz + st.z;
m = dot(zeta, zeta);
if ( m > 2.0 )
break;
}
// distance estimation through the Hubbard-Douady potential from Inigo Quilez
return float2(0.25*log(m) * sqrt(m) / dz, iterations);
}
#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.
Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository