Hello all,
I’m planning to do a simple ripple warper to an image. When the user clicks on the image, it is consider as the center of the ripple and a ripple must be created. I’m planning to create a very basic script which has nothing to do with reflection or refraction. I don’t know what kind of warping function to be used to get ripple effect. Can anyone help me? Thanks in advance.
Regards,
Gowthaman.
You’re in luck as I just happen to have one of those shaders…
Vertex Shader:
#version 120
varying vec2 texCoord0;
void main(void)
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
texCoord0.xy = gl_MultiTexCoord0.st;
}
FragmentShader:
#version 120
varying vec2 texCoord0;
/*
sceneTex (sampler2D): the final scene image.
paramv2 (vec2): mouse position (in texture coord space: [0 ; 1]).
time (float): shockwave elapsed time in second.
paramv4 (vec3): shockwave parameters
Ouputs: color buffer
*/
uniform sampler2D scenetex; // texunit #0
uniform vec2 paramv2; // Mouse position
uniform vec4 paramv4; // 10.0, 0.8, 0.1, effect elapsed time
void main()
{
vec2 uv = texCoord0.xy;
vec2 texCoord = uv;
float distancefromcenter = distance(uv, paramv2);
if ( (distancefromcenter <= (paramv4.w + paramv4.z)) &&
(distancefromcenter >= (paramv4.w - paramv4.z)) )
{
float diff = (distancefromcenter - paramv4.w);
float powDiff = 1.0 - pow(abs(diff*paramv4.x), paramv4.y);
float diffTime = diff * powDiff;
vec2 diffUV = normalize(uv - paramv2);
texCoord = uv + (diffUV * diffTime);
}
gl_FragColor = texture2D(scenetex, texCoord);
}
Thanks for your reply BionicBytes. But if you don’t mind can you explain the fragment shader part? I don’t get it.
Regards,
Gowthaman.