fragment.glsl (671B)
1 #version 330 core 2 in vec2 fpos; 3 out vec4 fcol; 4 5 vec4 color(int, int); 6 7 void main() { 8 float x, y; 9 float xx, yy; 10 11 const int N = 1000; 12 const float T = 2; 13 14 x = 0; y = 0; 15 int i; 16 for (i = 0; i < N; i++) { 17 // z_n+1 = z_n^2 + c, z_0 = 0 18 // (x + yi) * (x + yi) = x*x - y*y + (y*x + x*y)*i 19 xx = x; 20 yy = y; 21 x = xx*xx - yy*yy + fpos.x; 22 y = 2*xx*yy + fpos.y; 23 if (x*x + y*y > T) { 24 fcol = color(i, N); 25 return; 26 } 27 } 28 fcol = color(i, N); 29 } 30 31 vec4 color(int i, int N) { 32 if (i < N / 3) { 33 return vec4(0, float(i)/N, 1-float(i)/N, 1); 34 } else if (i < N / 2) { 35 return vec4(float(i)/N, 1-float(i)/N, 0, 1); 36 } else { 37 return vec4(1-float(i)/N, 0, 0, 1); 38 } 39 } 40