4 #define HEIGHT (1080*1)
9 layout (local_size_x = LWS_X, local_size_y = LWS_Y, local_size_z = 1 ) in;
15 layout(std140, binding = 0) buffer buf
23 In order to fit the work into workgroups, some unnecessary threads are launched.
24 We terminate those threads here.
26 if(gl_GlobalInvocationID.x >= WIDTH || gl_GlobalInvocationID.y >= HEIGHT)
29 float x = float(gl_GlobalInvocationID.x) / float(WIDTH);
30 float y = float(gl_GlobalInvocationID.y) / float(HEIGHT);
33 What follows is code for rendering the mandelbrot set.
35 vec2 uv = vec2(x, (y - 0.5) * (12.0 / 19.0) + 0.5);
37 vec2 c = vec2(-.445, 0.0) + (uv - 0.5)*(4.0);
41 for (int i = 0; i<M; i++) {
42 z = vec2(z.x*z.x - z.y*z.y, 2.*z.x*z.y) + c;
49 // we use a simple cosine palette to determine color:
50 // http://iquilezles.org/www/articles/palettes/palettes.htm
51 float t = float(n) * 500.0 / float(M);
52 vec3 d = vec3(0.5, 0.5, 0.5);
53 vec3 e = vec3(0.5, 0.5, 0.5);
54 vec3 f = vec3(1.0, 1.0, 1.0);
55 vec3 g = vec3(0.00, 0.33, 0.67);
57 vec4 color = vec4( d + e*cos( 6.28318*(f*t+g) ) ,1.0);
60 color = vec4(0, 0, 0, 1);
62 // store the rendered mandelbrot set into a storage buffer:
63 imageData[WIDTH * gl_GlobalInvocationID.y + gl_GlobalInvocationID.x].value = color;