Skip to content

Instantly share code, notes, and snippets.

@alco
Created July 8, 2012 11:23
Show Gist options
  • Save alco/3070585 to your computer and use it in GitHub Desktop.
Save alco/3070585 to your computer and use it in GitHub Desktop.
A whirl effect in GLSL
// simple fragment shader
// 'time' contains seconds since the program was linked.
uniform float time;
uniform sampler2D tex;
float radius = .5;
void main()
{
vec2 coords = gl_TexCoord[0].st;
float dist = distance(coords, vec2(.5));
mat2 rotmat;
if (dist < radius) {
float percent = (radius - dist) / radius;
float angle = percent * percent * sin(time) * 4.;
float sina = sin(angle);
float cosa = cos(angle);
rotmat = mat2(cosa, sina, -sina, cosa);
} else {
rotmat = mat2(1, 0, 0, 1);
}
vec2 texCoord = rotmat * (coords - vec2(.5)) + vec2(.5);
vec4 diffuse = texture2D(tex, texCoord);
gl_FragColor = diffuse;
}
uniform float time;
// simple vertex shader
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_FrontColor = gl_Color;
gl_TexCoord[0] = gl_MultiTexCoord0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment