Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. // XOR'd carpets
  2.  
  3. #ifdef GL_ES
  4. precision mediump float;
  5. #endif
  6.  
  7. uniform float time;
  8. uniform vec2 mouse;
  9. uniform vec2 resolution;
  10.  
  11. bool hit(vec2 p)
  12. {
  13. float direction = -.1; // -1.0 to zoom out
  14. ivec2 sectors;
  15. const int lim = 5;
  16. vec2 coordIter = p / pow(3.0, mod(direction*time, 1.0));
  17.  
  18. for (int i=0; i < lim; i++) {
  19. sectors = ivec2(floor(coordIter.xy * 3.0));
  20. if (sectors.x == 1 && sectors.y == 1) {
  21. // make a hole
  22. return false;
  23. } else {
  24. // map current sector to whole carpet
  25. coordIter.xy = coordIter.xy * 3.0 - vec2(sectors.xy);
  26. }
  27. }
  28.  
  29. return true;
  30. }
  31.  
  32. void main(void)
  33. {
  34. vec2 coordOrig = abs(gl_FragCoord.xy / resolution.xy-0.5);
  35. coordOrig.y *= resolution.y / resolution.x;
  36. coordOrig = mod(coordOrig, 1.0);
  37. vec4 color = vec4(1.0);
  38. for(float i = 0.; i < 4.; i++) {
  39. if (hit(i*0.1+coordOrig))
  40. color = 1.0 - color;
  41. }
  42.  
  43. gl_FragColor = color;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement