I had worked on image processing project back in my high school days and so the last memories returned recently when I wanted to implement the twirl filter in GLSL. Mathematically, it is easily given as the following function in polar coordinates,
F(r,theta)=f(r,theta+amt)
In normal world though, we are working in Cartesian coordiates so we need to add that conversion in. Other than that, it is the same function. Here is the output from my shader.
And here is the GLSL fragment shader for doing this.
uniform sampler2D textureMap; //image
F(r,theta)=f(r,theta+amt)
In normal world though, we are working in Cartesian coordiates so we need to add that conversion in. Other than that, it is the same function. Here is the output from my shader.
The Lena image filtered with the twirl filter in GLSL. |
uniform sampler2D textureMap; //image
uniform float amount; //amount of twirl
void main() {
vec2 uv = gl_TexCoord[0].st-0.5;
float angle = atan2(uv.y,uv.x);
float radius = length(uv);
angle+= radius*amount;
vec2 shifted = radius*vec2(cos(angle), sin(angle));
gl_FragColor = texture(textureMap, (shifted+0.5));
}
I hope it is useful for others too.
Enjoy!!!
No comments:
Post a Comment