I tried to implement what teodron suggested:
void main()
{
vec2 uv = gl_FragCoord.xy / resolution.xy;
float sepoffset = 0.005*cos(iGlobalTime*3.0);
if (uv.y > 0.3 + sepoffset)// is air - no reflection or effect
{
gl_FragColor = texture2D(texture, vec2(uv.x, -uv.y));
}
else
{
// Compute the mirror effect.
float xoffset = 0.005*cos(iGlobalTime*3.0+200.0*uv.y);
//float yoffset = 0.05*(1.0+cos(iGlobalTime*3.0+50.0*uv.y));
float yoffset = ((0.3 - uv.y)/0.3) * 0.05*(1.0+cos(iGlobalTime*3.0+50.0*uv.y));
vec4 color = texture2D(texture, vec2(uv.x+xoffset , -1.0*(0.6 - uv.y+ yoffset)));
//
//vec4 finalColor = vec4(mix(color.rgb, overlayColor, 0.25), 1.0);
gl_FragColor = color;
}
}
It looks pretty close (it's hard to tell without the base image) but you can tweak the parameters.
You may see it in action there: https://www.shadertoy.com/view/Xll3R7
Some remarks:
- I had to invert the y coordinate since I was getting the image upside down, but it may depend of what you pass into resolution.xy; if the result is inverted for you, just uninvert uv.y
- I changed your uniform declarations so it works with shadertoy. You can ignore those changes.
- You will need however to add a uniform providing the time and use it in place of iGlobalTime (which is the time in seconds)
- I added a tide effect since it looks like there is one on your example but it's hard to tell (see sepoffset variable). You may remove it if you don't like it
- I removed the overlay color since it was not looking good, and your example didn't had one
- To tweak the effect to your taste:
- change the factor of iGlobalTime to speedup/slowdown the effect (you can change each of them separately if you want, let's say accelerate the x movement and slow down the y movement)
- change the cos() factor to amplify/attenuate the effect
EDIT: I changed the yoffset to include the modification from @cepro
timevalue, you can shift theuv.xywith a(sin(time),cos(time))offset vector. Of course, you must figure out the amplitudes of the sine and cosine offsets. I'd start with just offsetting theuv.yfirst and see how I can adjust the effect further. \$\endgroup\$