Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified shaders/comp.spv
Binary file not shown.
24 changes: 13 additions & 11 deletions shaders/shader.comp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct Pixel{

layout(std140, binding = 0) buffer buf
{
Pixel imageData[];
Pixel imageData[];
};

void main() {
Expand All @@ -28,29 +28,31 @@ void main() {
float y = float(gl_GlobalInvocationID.y) / float(HEIGHT);

/*
What follows is code for rendering the mandelbrot set.
What follows is code for rendering the mandelbrot set.
*/
vec2 uv = vec2(x,y);
uv.y -= 0.5; // center vertically
uv *= vec2(1, 0.75); // adjust for 4:3 aspect ratio
float n = 0.0;
vec2 c = vec2(-.445, 0.0) + (uv - 0.5)*(2.0+ 1.7*0.2 ),
vec2 c = uv * 3 + vec2(-2.1, 0.0),
z = vec2(0.0);
const int M =128;
const int M = 128;
for (int i = 0; i<M; i++)
{
z = vec2(z.x*z.x - z.y*z.y, 2.*z.x*z.y) + c;
if (dot(z, z) > 2) break;
if (dot(z, z) > 4) break;
n++;
}

// we use a simple cosine palette to determine color:
// http://iquilezles.org/www/articles/palettes/palettes.htm
// http://iquilezles.org/www/articles/palettes/palettes.htm
float t = float(n) / float(M);
vec3 d = vec3(0.3, 0.3 ,0.5);
vec3 e = vec3(-0.2, -0.3 ,-0.5);
vec3 d = vec3(0.3, 0.3, 0.5);
vec3 e = vec3(-0.2, -0.3, -0.5);
vec3 f = vec3(2.1, 2.0, 3.0);
vec3 g = vec3(0.0, 0.1, 0.0);
vec4 color = vec4( d + e*cos( 6.28318*(f*t+g) ) ,1.0);
vec4 color = vec4( d + e*cos( 6.28318*(f*t+g) ), 1.0);

// store the rendered mandelbrot set into a storage buffer:
imageData[WIDTH * gl_GlobalInvocationID.y + gl_GlobalInvocationID.x].value = color;
}
}