Guest User

Untitled

a guest
Jan 19th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. const float PI = 3.1415926535;
  2.  
  3. vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords)
  4. {
  5. float aperture = 178.0;
  6. float apertureHalf = 0.5 * aperture * (PI / 180.0);
  7. float maxFactor = sin(apertureHalf);
  8.  
  9. vec2 uv;
  10. vec2 xy = 2.0 * texture_coords.xy - 1.0;
  11. float d = length(xy);
  12. if (d < (2.0-maxFactor))
  13. {
  14. d = length(xy * maxFactor);
  15. float z = sqrt(1.0 - d * d);
  16. float r = atan(d, z) / PI;
  17. float phi = atan(xy.y, xy.x);
  18.  
  19. uv.x = r * cos(phi) + 0.5;
  20. uv.y = r * sin(phi) + 0.5;
  21. }
  22. else
  23. {
  24. uv = texture_coords.xy;
  25. }
  26. vec4 c = texture2D(texture, uv);
  27. return c;
  28. }
Add Comment
Please, Sign In to add comment