Skip to content

SemperParatusGithub/MandelbrotSet

Repository files navigation

Mandelbrot Set

General

A simple C++ OpenGL realtime Mandelbrot set renderer. Everything is rendered on the GPU
using shaders and the OpenGL-Shading-Language (GLSL).

How does it work?
The Mandelbrot Set is defined as a set of points in the complex plain.
Each pixel value is calculated iteratively with a function defined as:

fc(z) = z2 + c

When iteratively processing this function we want to find out if the value of the function converges to some
constant or diverges to infinity

When taking a closer look at the fragment shader when can see that we first retrieve the pixels
position using gl_FragCoord. After taking the zoom and offset in account we then pass the
coordinates to the mandelbrot function which returns the appropriate pixel value.
After that the final colour is retrieved by the function MapToColor.

float Mandelbrot(dvec2 fragCoord)
{
	int n = 0;
	dvec2 z = vec2(0.0, 0.0);
	for (n = 0; n < u_MaxIterations; n++)
	{
		dvec2 znew;
		znew.x = (z.x * z.x) - (z.y * z.y) + fragCoord.x;
		znew.y = (2.0 * z.x * z.y) + fragCoord.y;
		z = znew;
		if ((z.x * z.x) + (z.y * z.y) > 16.0)
			break;
	}
	return n / float(u_MaxIterations);
}

The full source code of the shader is available here
If you want to know more about the Mandelbrot set: https://en.wikipedia.org/wiki/Mandelbrot_set

Screenshots

Screenshot1
Screenshot2
Screenshot3
Screenshot4
Screenshot5
Screenshot6
Screenshot7

License

This project is under the MIT license. For full license text see LICENCE.txt

Third Party Libraries