Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void main() {
  2. #define iterations 256
  3.  
  4.    
  5.     vec2 position = v_tex_coord; // gets the location of the current pixel in the intervals [0..1] [0..1]
  6.     vec3 color = vec3(0.0,0.0,0.0); // initialize color to black
  7.    
  8.     vec2 z = position; // z.x is the real component z.y is the imaginary component
  9.    
  10.     //
  11.     // Rescale the position to the intervals [-2,1] [-1,1]
  12.     z *= vec2(3.0,2.0);
  13.     z -= vec2(2.0,1.0);
  14.    
  15.     vec2 c = vec2(-0.7 + cos(u_time) / 3.0,0.4 + sin(u_time) / 3.0);
  16.    
  17.     float it = 0.0; // Keep track of what iteration we reached
  18.     for (int i = 0;i < iterations; ++i) {
  19.         // zn = zn-1 ^ 2 + c
  20.        
  21.         // (x + yi) ^ 2 = x ^ 2 - y ^ 2 + 2xyi
  22.         z = vec2(z.x * z.x - z.y * z.y, 2.0 * z.x * z.y);
  23.         z += c;
  24.        
  25.         if (dot(z,z) > 4.0) { // dot(z,z) == length(z) ^ 2 only faster to compute
  26.             break;
  27.         }
  28.        
  29.         it += 1.0;
  30.     }
  31.    
  32.     if (it < float(iterations)) {
  33.         color.x = sin(it / 3.0);
  34.         color.y = cos(it / 6.0);
  35.         color.z = cos(it / 12.0 + 3.14 / 4.0);
  36.     }
  37.     gl_FragColor = vec4(color,1.0);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement