You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 line
886 B

  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 PI = 3.1415926535;
  11. void main()
  12. {
  13. float aperture = 178.0f;
  14. float apertureHalf = 0.5 * aperture * (PI / 180.0);
  15. float maxFactor = sin(apertureHalf);
  16. vec2 uv = vec2(0);
  17. vec2 xy = 2.0 * fragTexCoord.xy - 1.0;
  18. float d = length(xy);
  19. if (d < (2.0 - maxFactor))
  20. {
  21. d = length(xy * maxFactor);
  22. float z = sqrt(1.0 - d * d);
  23. float r = atan(d, z) / PI;
  24. float phi = atan(xy.y, xy.x);
  25. uv.x = r * cos(phi) + 0.5;
  26. uv.y = r * sin(phi) + 0.5;
  27. }
  28. else
  29. {
  30. uv = fragTexCoord.xy;
  31. }
  32. gl_FragColor = texture2D(texture0, uv);
  33. }