This repository contains all my work with fractals. An explanation can be found here.
This shader can be used as a starting point to create other fractals. It has the following features:
- Procedural color palette
- Smooth iteration count
- Supersampling
The implementation can be found below:
#define N 64.
#define B 32.
#define SS 4.
float random (in vec2 st) {
return fract(sin(dot(st.xy, vec2(12454.1,78345.2))) * 43758.5);
}
vec2 random2(in vec2 st) {
return vec2(random(st), random(st));
}
vec3 pal( in float t, in vec3 a, in vec3 b, in vec3 c, in vec3 d ) {
return a + b*cos(6.28318 * (c*t + d));
}
float iterate(vec2 p) {
vec2 z = vec2(0), c = p;
float i;
for(i=0.; i < N; i++) {
z = mat2(z, -z.y, z.x) * z + c;
if(dot(z, z) > B*B) break;
}
return i - log(log(dot(z, z)) / log(B)) / log(2.);;
}
void mainImage( out vec4 fragColor, in vec2 fragCoord ) {
vec2 R = iResolution.xy;
vec3 col = vec3(0);
for(float i=0.; i < SS; i++) {
vec2 uv = (2. * fragCoord + random2(R+i) - R) / R.y ;
float sn = iterate(uv) / N;
col += pal(fract(2.*sn + 0.5), vec3(.5), vec3(0.5),
vec3(1.0,1.0,1.0), vec3(.0, .10, .2));
}
fragColor = vec4(col / SS, 1.0);
}
This is a link to a simple fractal viewer with limited controls. It shows the burning ship fractal.
An attempt to create a short, and fast, implementation for the Mandelbrot set in GLSL. Currently it stands at 176 characters, which is a little more than half a tweet.
#define R iResolution.xy
void mainImage( out vec4 O, in vec2 I ) {
vec2 c = ( 2.*I - R ) / R.y, z = 0./R;
float i = 0.;
for(; ++i <= 64. && dot(z,z) < 4. ;)
z = mat2( z, -z.y, z.x ) * z + c;
O = vec4(vec3( i / 64. ), 1.0);
}
It can be tested at Shadertoy.
More resources can be found at the following links:
- Distance Estimation with 3D Fractals: http://blog.hvidtfeldts.net/index.php/2011/06/distance-estimated-3d-fractals-part-i/
- Building 4D Polytopes, and Stereoscopic Projection: https://syntopia.github.io/Polytopia/polytopes.html
- GUI.dat, is a lightweight GUI library: https://github.com/dataarts/dat.gui
- Path Tracing 3D Fractals, rendering equation: http://blog.hvidtfeldts.net/index.php/2015/01/path-tracing-3d-fractals/
In the screenshots
folder are high-res pictures.
Implementations of the fractals on ShaderToy: