Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. vec2 x=tc - vec2(0.5,0.5);
  2. float radius=length(x);
  3. float angle=atan(x.y, x.x);
  4.  
  5. #version ...
  6. precision ...
  7.  
  8. varying vec2 tc; // texcoords from vertex shader
  9. uniform sampler2D tex;
  10.  
  11. #define PI 3.14159265358979323844
  12.  
  13. void main ()
  14. {
  15. const float r_inner=0.25;
  16. const float t_outer=0.5;
  17.  
  18. vec2 x = v_tex - vec2(0.5);
  19. float radius = length(x);
  20. float angle = atan(x.y, x.x);
  21.  
  22. vec2 tc_polar; // the new polar texcoords
  23. // map radius so that for r=r_inner -> 0 and r=r_outer -> 1
  24. tc_polar.s = ( radius - r_inner) / (r_outer - r_inner);
  25.  
  26. // map angle from [-PI,PI] to [0,1]
  27. tc_polar.t = angle * 0.5 / PI + 0.5;
  28.  
  29. // texture mapping
  30. gl_FragColor = texture2D(tex, tc_polar);
  31. }
  32.  
  33. uniform float Angle; // range 2pi / 100000.0 to 1.0 (rounded down), exponential
  34. uniform float AngleMin; // range -3.2 to 3.2
  35. uniform float AngleWidth; // range 0.0 to 6.4
  36. uniform float Radius; // range -10000.0 to 1.0
  37. uniform float RadiusMin; // range 0.0 to 2.0
  38. uniform float RadiusWidth; // range 0.0 to 2.0
  39. uniform vec2 Center; // range: -1.0 to 3.0
  40.  
  41. uniform sampler2D Texture;
  42.  
  43. void main()
  44. {
  45. // Normalised texture coords
  46. vec2 texCoord = gl_TexCoord[0].xy;
  47. // Shift origin to texture centre (with offset)
  48. vec2 normCoord;
  49. normCoord.x = 2.0 * texCoord.x – Center.x;
  50. normCoord.y = 2.0 * texCoord.y – Center.y;
  51. // Convert Cartesian to Polar coords
  52. float r = length(normCoord);
  53. float theta = atan(normCoord.y, normCoord.x);
  54.  
  55. // The actual effect
  56. r = (r < RadiusMin) ? r : (r > RadiusMin + RadiusWidth) ? r : ceil(r / Radius) * Radius;
  57. theta = (theta < AngleMin) ? theta : (theta > AngleMin + AngleWidth) ? theta : floor(theta / Angle) * Angle;
  58.  
  59. // Convert Polar back to Cartesian coords
  60. normCoord.x = r * cos(theta);
  61. normCoord.y = r * sin(theta);
  62. // Shift origin back to bottom-left (taking offset into account)
  63. texCoord.x = normCoord.x / 2.0 + (Center.x / 2.0);
  64. texCoord.y = normCoord.y / 2.0 + (Center.y / 2.0);
  65.  
  66. // Output
  67. gl_FragColor = texture2D(Texture, texCoord);
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement