swirl.fs 1007 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #version 100
  2. precision mediump float;
  3. // Input vertex attributes (from vertex shader)
  4. varying vec2 fragTexCoord;
  5. varying vec4 fragColor;
  6. // Input uniform values
  7. uniform sampler2D texture0;
  8. uniform vec4 colDiffuse;
  9. // NOTE: Add here your custom variables
  10. const float renderWidth = 800.0; // HARDCODED for example!
  11. const float renderHeight = 480.0; // Use uniforms instead...
  12. float radius = 250.0;
  13. float angle = 0.8;
  14. uniform vec2 center;
  15. void main()
  16. {
  17. vec2 texSize = vec2(renderWidth, renderHeight);
  18. vec2 tc = fragTexCoord*texSize;
  19. tc -= center;
  20. float dist = length(tc);
  21. if (dist < radius)
  22. {
  23. float percent = (radius - dist)/radius;
  24. float theta = percent*percent*angle*8.0;
  25. float s = sin(theta);
  26. float c = cos(theta);
  27. tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c)));
  28. }
  29. tc += center;
  30. vec4 color = texture2D(texture0, tc/texSize)*colDiffuse*fragColor;;
  31. gl_FragColor = vec4(color.rgb, 1.0);;
  32. }