Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vec2 x=tc - vec2(0.5,0.5);
- float radius=length(x);
- float angle=atan(x.y, x.x);
- #version ...
- precision ...
- varying vec2 tc; // texcoords from vertex shader
- uniform sampler2D tex;
- #define PI 3.14159265358979323844
- void main ()
- {
- const float r_inner=0.25;
- const float t_outer=0.5;
- vec2 x = v_tex - vec2(0.5);
- float radius = length(x);
- float angle = atan(x.y, x.x);
- vec2 tc_polar; // the new polar texcoords
- // map radius so that for r=r_inner -> 0 and r=r_outer -> 1
- tc_polar.s = ( radius - r_inner) / (r_outer - r_inner);
- // map angle from [-PI,PI] to [0,1]
- tc_polar.t = angle * 0.5 / PI + 0.5;
- // texture mapping
- gl_FragColor = texture2D(tex, tc_polar);
- }
- uniform float Angle; // range 2pi / 100000.0 to 1.0 (rounded down), exponential
- uniform float AngleMin; // range -3.2 to 3.2
- uniform float AngleWidth; // range 0.0 to 6.4
- uniform float Radius; // range -10000.0 to 1.0
- uniform float RadiusMin; // range 0.0 to 2.0
- uniform float RadiusWidth; // range 0.0 to 2.0
- uniform vec2 Center; // range: -1.0 to 3.0
- uniform sampler2D Texture;
- void main()
- {
- // Normalised texture coords
- vec2 texCoord = gl_TexCoord[0].xy;
- // Shift origin to texture centre (with offset)
- vec2 normCoord;
- normCoord.x = 2.0 * texCoord.x – Center.x;
- normCoord.y = 2.0 * texCoord.y – Center.y;
- // Convert Cartesian to Polar coords
- float r = length(normCoord);
- float theta = atan(normCoord.y, normCoord.x);
- // The actual effect
- r = (r < RadiusMin) ? r : (r > RadiusMin + RadiusWidth) ? r : ceil(r / Radius) * Radius;
- theta = (theta < AngleMin) ? theta : (theta > AngleMin + AngleWidth) ? theta : floor(theta / Angle) * Angle;
- // Convert Polar back to Cartesian coords
- normCoord.x = r * cos(theta);
- normCoord.y = r * sin(theta);
- // Shift origin back to bottom-left (taking offset into account)
- texCoord.x = normCoord.x / 2.0 + (Center.x / 2.0);
- texCoord.y = normCoord.y / 2.0 + (Center.y / 2.0);
- // Output
- gl_FragColor = texture2D(Texture, texCoord);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement