2012-05-14 01:41:08 +00:00
|
|
|
//modifier: REFLECT (s_t2 is a reflection instead of diffusemap)
|
|
|
|
//modifier: STRENGTH (0.1 = fairly gentle, 0.2 = big waves)
|
2012-05-11 01:57:00 +00:00
|
|
|
//modifier: FRESNEL (5=water)
|
2012-05-14 01:41:08 +00:00
|
|
|
//modifier: TXSCALE (0.2 - wave strength)
|
|
|
|
//modifier: RIPPLEMAP (s_t3 contains a ripplemap
|
|
|
|
//modifier: TINT (some colour value)
|
|
|
|
|
|
|
|
#ifndef FRESNEL
|
|
|
|
#define FRESNEL 5.0
|
|
|
|
#endif
|
|
|
|
#ifndef STRENGTH
|
|
|
|
#define STRENGTH 0.1
|
|
|
|
#endif
|
|
|
|
#ifndef TXSCALE
|
|
|
|
#define TXSCALE 0.2
|
|
|
|
#endif
|
|
|
|
#ifndef TINT
|
|
|
|
#define TINT vec3(0.7, 0.8, 0.7)
|
|
|
|
#endif
|
2012-05-11 01:57:00 +00:00
|
|
|
|
|
|
|
varying vec2 tc;
|
|
|
|
varying vec4 tf;
|
|
|
|
varying vec3 norm;
|
|
|
|
varying vec3 eye;
|
|
|
|
#ifdef VERTEX_SHADER
|
|
|
|
attribute vec2 v_texcoord;
|
|
|
|
attribute vec3 v_normal;
|
|
|
|
uniform vec3 e_eyepos;
|
|
|
|
void main (void)
|
|
|
|
{
|
|
|
|
tc = v_texcoord.st;
|
|
|
|
tf = ftetransform();
|
|
|
|
norm = v_normal;
|
|
|
|
eye = e_eyepos - v_position.xyz;
|
|
|
|
gl_Position = tf;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef FRAGMENT_SHADER
|
|
|
|
uniform sampler2D s_t0; //refract
|
|
|
|
uniform sampler2D s_t1; //normalmap
|
2012-05-14 01:41:08 +00:00
|
|
|
uniform sampler2D s_t2; //diffuse/reflection
|
|
|
|
#ifdef RIPPLEMAP
|
|
|
|
uniform sampler2D s_t3; //ripplemap
|
2012-05-11 01:57:00 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
uniform float e_time;
|
|
|
|
void main (void)
|
|
|
|
{
|
|
|
|
vec2 stc, ntc;
|
|
|
|
vec3 n, refr, refl, fres;
|
|
|
|
float f;
|
|
|
|
stc = (1.0 + (tf.xy / tf.w)) * 0.5;
|
|
|
|
|
|
|
|
//apply q1-style warp, just for kicks
|
|
|
|
ntc.s = tc.s + sin(tc.t+e_time)*0.125;
|
|
|
|
ntc.t = tc.t + sin(tc.s+e_time)*0.125;
|
|
|
|
|
|
|
|
//generate the two wave patterns from the normalmap
|
2012-07-21 23:34:48 +00:00
|
|
|
n = (texture2D(s_t1, TXSCALE*tc + vec2(e_time*0.1, 0.0)).xyz);
|
2012-05-14 01:41:08 +00:00
|
|
|
n += (texture2D(s_t1, TXSCALE*tc - vec2(0, e_time*0.097)).xyz);
|
2012-05-11 01:57:00 +00:00
|
|
|
n -= 1.0 - 4.0/256.0;
|
|
|
|
|
2012-05-14 01:41:08 +00:00
|
|
|
#ifdef RIPPLEMAP
|
|
|
|
n += texture2D(s_t3, stc)*3;
|
2012-05-11 01:57:00 +00:00
|
|
|
#endif
|
2012-05-14 01:41:08 +00:00
|
|
|
|
|
|
|
//the fresnel term decides how transparent the water should be
|
|
|
|
f = pow(1.0-abs(dot(normalize(n), normalize(eye))), float(FRESNEL));
|
|
|
|
|
|
|
|
refr = texture2D(s_t0, stc + n.st*STRENGTH).rgb * TINT;
|
2012-05-11 01:57:00 +00:00
|
|
|
#ifdef REFLECT
|
2012-05-14 01:41:08 +00:00
|
|
|
refl = texture2D(s_t2, stc - n.st*STRENGTH).rgb;
|
2012-05-11 01:57:00 +00:00
|
|
|
#else
|
|
|
|
refl = texture2D(s_t2, ntc).xyz;
|
|
|
|
#endif
|
2012-05-14 01:41:08 +00:00
|
|
|
// refl += 0.1*pow(dot(n, vec3(0.0,0.0,1.0)), 64.0);
|
2012-05-11 01:57:00 +00:00
|
|
|
|
|
|
|
fres = refr * (1.0-f) + refl*f;
|
|
|
|
|
2012-05-14 01:41:08 +00:00
|
|
|
// fres = texture2D(s_t2, stc).xyz;
|
|
|
|
|
2012-05-11 01:57:00 +00:00
|
|
|
gl_FragColor = vec4(fres, 1.0);
|
|
|
|
}
|
|
|
|
#endif
|