1 uniform sampler2D sceneTex;
2 uniform float textureWidth;
3 uniform float textureHeight;
9 #define DEG2RAD (6.2832/360.0)
12 // Converts pixel coordinates to texture coordinates
13 vec2 pix2tex(vec2 pix)
15 return vec2(pix.x / textureWidth, 1.0 - pix.y / textureHeight);
18 float wave(vec2 pos, vec2 wave_dir, float wave_length, float wave_speed)
20 return sin(((pos.x * wave_dir.x) + (pos.y * wave_dir.y)) * 6.2832 / wave_length +
21 time * wave_speed * 6.2832 / wave_length);
24 vec2 displacement(float wave_angle, float wave_length, float wave_speed, float wave_height)
26 vec2 wave_dir = vec2(cos(wave_angle * DEG2RAD), sin(wave_angle * DEG2RAD));
27 return wave_dir * (wave(pos, wave_dir, wave_length, wave_speed) * wave_height);
31 float wave_color(float wave_angle, float wave_length, float wave_speed, float wave_height)
33 vec2 wave_dir = vec2(cos(wave_angle * DEG2RAD), sin(wave_angle * DEG2RAD));
34 return wave(pos, wave_dir, wave_length, wave_speed) * 0.5 + 0.5;
40 texpos += displacement( 20.0, 250.0, 120.0, 4.0);
41 texpos += displacement(-40.0, 350.0, 100.0, 4.0);
42 texpos += displacement(240.0, 1000.0, 100.0, 12.0);
43 texpos += displacement(160.0, 50.0, 30.0, 2.0);
45 vec3 tex = texture2D(sceneTex, pix2tex(texpos)).rgb;
46 //tex.r = wave_color( 20, 250, 150, 4); // debug
48 gl_FragColor = vec4(tex, 1.0);