Skip to content

Instantly share code, notes, and snippets.

@raedatoui
Forked from alco/ripple.frag
Created August 14, 2016 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raedatoui/a3eb2ad001e6305010f9b52d1665db01 to your computer and use it in GitHub Desktop.
Save raedatoui/a3eb2ad001e6305010f9b52d1665db01 to your computer and use it in GitHub Desktop.
Ripple effect for GLSL
// simple fragment shader
// 'time' contains seconds since the program was linked.
uniform float time;
uniform sampler2D tex;
uniform sampler2D tex2;
float radius = .5;
void main()
{
float t = clamp(time / 6., 0., 1.);
vec2 coords = gl_TexCoord[0].st;
vec2 dir = coords - vec2(.5);
float dist = distance(coords, vec2(.5));
vec2 offset = dir * (sin(dist * 80. - time*15.) + .5) / 30.;
vec2 texCoord = coords + offset;
vec4 diffuse = texture2D(tex, texCoord);
vec4 mixin = texture2D(tex2, texCoord);
gl_FragColor = mixin * t + diffuse * (1. - t);
}
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