Skip to content

Instantly share code, notes, and snippets.

@alco
Created July 8, 2012 11:52
Show Gist options
  • Save alco/3070640 to your computer and use it in GitHub Desktop.
Save alco/3070640 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;
}
Copy link

ghost commented Oct 31, 2013

Hi,

I want to implement Ripple Effect using GLSL shader for iOS. In which, I want to generate ripples from the touch coordinates on screen by user.

Could you help me to implement that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment