<script id="shader-fs" type="x-shader/x-fragment">
precision highp float;
uniform sampler2D samp;
varying vec2 tc;
const float h = 1./512.;
void main(void) {
vec2 t = texture2D(samp, tc).xy;
vec2 D = -3.*t, Df = floor(D), Dd = D - Df;
vec2 tc1 = tc + Df*h;
float new = // bilinear interpolation of the 4 closest texels
(texture2D(samp, tc1).z*(1. - Dd.y) +
texture2D(samp, vec2(tc1.x, tc1.y + h)).z*Dd.y)*(1. - Dd.x) +
(texture2D(samp, vec2(tc1.x + h, tc1.y)).z*(1. - Dd.y) +
texture2D(samp, vec2(tc1.x + h, tc1.y + h)).z*Dd.y)*Dd.x;
gl_FragColor = vec4(t, new, 1. );
}
</script>
[1] Jos Stam
Real-Time
Fluid Dynamics for Games
[2] Mark J. Harris
Fast Fluid Dynamics Simulation on the GPU
GPU Gems:
Chapter 38