Created
July 8, 2012 11:23
-
-
Save alco/3070585 to your computer and use it in GitHub Desktop.
A whirl effect in GLSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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