Advertisement
Guest User

Untitled

a guest
Aug 10th, 2015
1,034
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. [FRAGMENT SHADER]
  2. precision mediump float;
  3.  
  4. varying vec2 texCoords;
  5.  
  6. uniform sampler2D render_texture;
  7.  
  8. uniform vec2 screen_size;
  9.  
  10. uniform vec2 swirl_center;
  11.  
  12. uniform float swirl_radius;
  13. uniform float swirl_amount;
  14. uniform float swirl_strength;
  15.  
  16. vec2 swirl(vec2 coords)
  17. {
  18.     //Convert to poolar coordinates
  19.     //Get the relative position to the swirl_center
  20.     coords = coords - swirl_center;
  21.     float r = length(coords);
  22.     if(r <= swirl_radius)
  23.     {
  24.         float phi = atan(coords.y, coords.x);
  25.         float distortion = pow(swirl_amount * ((swirl_radius - r) / swirl_radius), 2);
  26.        
  27.         if(swirl_amount >= 0)
  28.             phi = phi + distortion;
  29.         else
  30.             phi = phi - distortion;
  31.        
  32.         coords.x = r * cos(phi);
  33.         coords.y = r * sin(phi);
  34.     }
  35.     //Convert it back to global space
  36.     return coords + swirl_center;
  37. }
  38.  
  39. void main()
  40. {
  41.     vec2 coords = texCoords * screen_size;
  42.     coords = swirl(coords);
  43.     coords /= screen_size;
  44.    
  45.     gl_FragColor = texture2D(render_texture, coords);
  46. }
  47.  
  48. [VERTEX SHADER]
  49. layout(location = 0) in vec3 vertexPos;
  50. layout(location = 1) in vec2 vertexUV;
  51.  
  52. varying vec2 texCoords;
  53.  
  54. void main()
  55. {
  56.     gl_Position = vec4(vertexPos, 1.f);
  57.    
  58.     texCoords = vertexUV;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement