swirl.fs 888 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #version 330
  2. in vec2 fragTexCoord;
  3. out vec4 fragColor;
  4. uniform sampler2D texture0;
  5. uniform vec4 tintColor;
  6. // NOTE: Add here your custom variables
  7. const float renderWidth = 800; // HARDCODED for example!
  8. const float renderHeight = 480; // Use uniforms instead...
  9. float radius = 250.0;
  10. float angle = 0.8;
  11. uniform vec2 center = vec2(200, 200);
  12. void main (void)
  13. {
  14. vec2 texSize = vec2(renderWidth, renderHeight);
  15. vec2 tc = fragTexCoord*texSize;
  16. tc -= center;
  17. float dist = length(tc);
  18. if (dist < radius)
  19. {
  20. float percent = (radius - dist)/radius;
  21. float theta = percent*percent*angle*8.0;
  22. float s = sin(theta);
  23. float c = cos(theta);
  24. tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c)));
  25. }
  26. tc += center;
  27. vec3 color = texture2D(texture0, tc/texSize).rgb;
  28. fragColor = vec4(color, 1.0);;
  29. }