2016-08-25 00:12:14 +00:00
|
|
|
!!cvardf r_glsl_turbscale_reflect=1 //simpler scaler
|
|
|
|
!!cvardf r_glsl_turbscale_refract=1 //simpler scaler
|
|
|
|
!!samps 4 diffuse
|
|
|
|
|
|
|
|
#include "sys/defs.h"
|
|
|
|
|
|
|
|
//modifier: REFLECT (s_t2 is a reflection instead of diffusemap)
|
|
|
|
//modifier: STRENGTH_REFL (distortion strength - 0.1 = fairly gentle, 0.2 = big waves)
|
|
|
|
//modifier: STRENGTH_REFL (distortion strength - 0.1 = fairly gentle, 0.2 = big waves)
|
|
|
|
//modifier: FRESNEL_EXP (5=water)
|
|
|
|
//modifier: TXSCALE (wave size - 0.2)
|
|
|
|
//modifier: RIPPLEMAP (s_t3 contains a ripplemap
|
|
|
|
//modifier: TINT_REFR (some colour value)
|
|
|
|
//modifier: TINT_REFL (some colour value)
|
|
|
|
//modifier: ALPHA (mix in the normal water texture over the top)
|
|
|
|
//modifier: USEMODS (use single-texture scrolling via tcmods - note, also forces the engine to actually use tcmod etc)
|
|
|
|
|
|
|
|
//a few notes on DP compat:
|
|
|
|
//'dpwater' makes numerous assumptions about DP internals
|
|
|
|
//by default there is a single pass that uses the pass's normal tcmods
|
|
|
|
//the fresnel has a user-supplied min+max rather than an exponent
|
|
|
|
//both parts are tinted individually
|
|
|
|
//if alpha is enabled, the regular water texture is blended over the top, again using the same crappy tcmods...
|
|
|
|
|
|
|
|
//legacy crap
|
2012-05-14 01:41:08 +00:00
|
|
|
#ifndef FRESNEL
|
|
|
|
#define FRESNEL 5.0
|
|
|
|
#endif
|
2016-08-25 00:12:14 +00:00
|
|
|
#ifndef TINT
|
|
|
|
#define TINT 0.7,0.8,0.7
|
|
|
|
#endif
|
2012-05-14 01:41:08 +00:00
|
|
|
#ifndef STRENGTH
|
|
|
|
#define STRENGTH 0.1
|
|
|
|
#endif
|
|
|
|
#ifndef TXSCALE
|
|
|
|
#define TXSCALE 0.2
|
|
|
|
#endif
|
2016-08-25 00:12:14 +00:00
|
|
|
|
|
|
|
//current values (referring to legacy defaults where needed)
|
|
|
|
#ifndef FRESNEL_EXP
|
|
|
|
#define FRESNEL_EXP 5.0
|
|
|
|
#endif
|
|
|
|
#ifndef FRESNEL_MIN
|
|
|
|
#define FRESNEL_MIN 0.0
|
|
|
|
#endif
|
|
|
|
#ifndef FRESNEL_RANGE
|
|
|
|
#define FRESNEL_RANGE 1.0
|
|
|
|
#endif
|
|
|
|
#ifndef STRENGTH_REFL
|
|
|
|
#define STRENGTH_REFL STRENGTH
|
|
|
|
#endif
|
|
|
|
#ifndef STRENGTH_REFR
|
|
|
|
#define STRENGTH_REFR STRENGTH
|
|
|
|
#endif
|
|
|
|
#ifndef TXSCALE1
|
|
|
|
#define TXSCALE1 TXSCALE
|
|
|
|
#endif
|
|
|
|
#ifndef TXSCALE2
|
|
|
|
#define TXSCALE2 TXSCALE
|
|
|
|
#endif
|
|
|
|
#ifndef TINT_REFR
|
|
|
|
#define TINT_REFR TINT
|
|
|
|
#endif
|
|
|
|
#ifndef TINT_REFL
|
|
|
|
#define TINT_REFL 1.0,1.0,1.0
|
2012-05-14 01:41:08 +00:00
|
|
|
#endif
|
2013-03-12 23:13:39 +00:00
|
|
|
#ifndef FOGTINT
|
2016-08-25 00:12:14 +00:00
|
|
|
#define FOGTINT 0.2,0.3,0.2
|
2013-03-12 23:13:39 +00:00
|
|
|
#endif
|
2012-05-11 01:57:00 +00:00
|
|
|
|
|
|
|
varying vec2 tc;
|
|
|
|
varying vec4 tf;
|
|
|
|
varying vec3 norm;
|
|
|
|
varying vec3 eye;
|
|
|
|
#ifdef VERTEX_SHADER
|
|
|
|
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
|
2016-08-25 00:12:14 +00:00
|
|
|
#ifdef ALPHA
|
|
|
|
#include "sys/fog.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2015-03-03 00:14:43 +00:00
|
|
|
#define s_refract s_t0
|
|
|
|
#define s_reflect s_t1
|
|
|
|
#define s_ripplemap s_t2
|
|
|
|
#define s_refractdepth s_t3
|
|
|
|
|
2012-05-11 01:57:00 +00:00
|
|
|
void main (void)
|
|
|
|
{
|
2016-08-25 00:12:14 +00:00
|
|
|
vec2 stc; //screen tex coords
|
|
|
|
vec2 ntc; //normalmap/diffuse tex coords
|
2013-03-12 23:13:39 +00:00
|
|
|
vec3 n, refr, refl;
|
|
|
|
float fres;
|
|
|
|
float depth;
|
2012-05-11 01:57:00 +00:00
|
|
|
stc = (1.0 + (tf.xy / tf.w)) * 0.5;
|
2016-08-25 00:12:14 +00:00
|
|
|
//hack the texture coords slightly so that there are less obvious gaps
|
2013-03-12 23:13:39 +00:00
|
|
|
stc.t -= 1.5*norm.z/1080.0;
|
2012-05-11 01:57:00 +00:00
|
|
|
|
2016-08-25 00:12:14 +00:00
|
|
|
#if 0//def USEMODS
|
|
|
|
ntc = tc;
|
|
|
|
n = texture2D(s_normalmap, ntc).xyz - 0.5;
|
|
|
|
#else
|
2012-05-11 01:57:00 +00:00
|
|
|
//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
|
2016-08-25 00:12:14 +00:00
|
|
|
n = (texture2D(s_normalmap, vec2(TXSCALE1)*tc + vec2(e_time*0.1, 0.0)).xyz);
|
|
|
|
n += (texture2D(s_normalmap, vec2(TXSCALE2)*tc - vec2(0, e_time*0.097)).xyz);
|
2012-05-11 01:57:00 +00:00
|
|
|
n -= 1.0 - 4.0/256.0;
|
2016-08-25 00:12:14 +00:00
|
|
|
#endif
|
2012-05-11 01:57:00 +00:00
|
|
|
|
2012-05-14 01:41:08 +00:00
|
|
|
#ifdef RIPPLEMAP
|
2013-03-17 12:11:47 +00:00
|
|
|
n += texture2D(s_ripplemap, stc).rgb*3.0;
|
2012-05-11 01:57:00 +00:00
|
|
|
#endif
|
2016-08-25 00:12:14 +00:00
|
|
|
n = normalize(n);
|
2012-05-14 01:41:08 +00:00
|
|
|
|
|
|
|
//the fresnel term decides how transparent the water should be
|
2016-08-25 00:12:14 +00:00
|
|
|
fres = pow(1.0-abs(dot(n, normalize(eye))), float(FRESNEL_EXP)) * float(FRESNEL_RANGE) + float(FRESNEL_MIN);
|
2013-03-12 23:13:39 +00:00
|
|
|
|
|
|
|
#ifdef DEPTH
|
|
|
|
float far = #include "cvar/gl_maxdist";
|
|
|
|
float near = #include "cvar/gl_mindist";
|
|
|
|
//get depth value at the surface
|
|
|
|
float sdepth = gl_FragCoord.z;
|
|
|
|
sdepth = (2.0*near) / (far + near - sdepth * (far - near));
|
|
|
|
sdepth = mix(near, far, sdepth);
|
|
|
|
|
|
|
|
//get depth value at the ground beyond the surface.
|
2015-03-03 00:14:43 +00:00
|
|
|
float gdepth = texture2D(s_refractdepth, stc).x;
|
2013-03-12 23:13:39 +00:00
|
|
|
gdepth = (2.0*near) / (far + near - gdepth * (far - near));
|
|
|
|
if (gdepth >= 0.5)
|
|
|
|
{
|
|
|
|
gdepth = sdepth;
|
|
|
|
depth = 0.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gdepth = mix(near, far, gdepth);
|
|
|
|
depth = gdepth - sdepth;
|
|
|
|
}
|
2012-05-14 01:41:08 +00:00
|
|
|
|
2013-03-12 23:13:39 +00:00
|
|
|
//reduce the normals in shallow water (near walls, reduces the pain of linear sampling)
|
2013-03-12 23:14:02 +00:00
|
|
|
if (depth < 100.0)
|
2013-03-12 23:13:39 +00:00
|
|
|
n *= depth/100.0;
|
|
|
|
#else
|
2013-03-12 23:14:02 +00:00
|
|
|
depth = 1.0;
|
2013-03-12 23:13:39 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
//refraction image (and water fog, if possible)
|
2016-08-25 00:12:14 +00:00
|
|
|
refr = texture2D(s_refract, stc + n.st*float(STRENGTH_REFR)*float(r_glsl_turbscale_refract)).rgb * vec3(TINT_REFR);
|
2013-03-12 23:13:39 +00:00
|
|
|
#ifdef DEPTH
|
2016-08-25 00:12:14 +00:00
|
|
|
refr = mix(refr, vec3(FOGTINT), min(depth/4096.0, 1.0));
|
2013-03-12 23:13:39 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//reflection/diffuse
|
2012-05-11 01:57:00 +00:00
|
|
|
#ifdef REFLECT
|
2016-08-25 00:12:14 +00:00
|
|
|
refl = texture2D(s_reflect, stc - n.st*float(STRENGTH_REFL)*float(r_glsl_turbscale_reflect)).rgb * vec3(TINT_REFL);
|
2012-05-11 01:57:00 +00:00
|
|
|
#else
|
2016-08-25 00:12:14 +00:00
|
|
|
refl = texture2D(s_diffuse, ntc).xyz * vec3(TINT_REFL);
|
2012-05-11 01:57:00 +00:00
|
|
|
#endif
|
2013-03-12 23:13:39 +00:00
|
|
|
//interplate by fresnel
|
|
|
|
refr = mix(refr, refl, fres);
|
2012-05-14 01:41:08 +00:00
|
|
|
|
2016-08-25 00:12:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ALPHA
|
|
|
|
vec4 ts = texture2D(s_diffuse, ntc);
|
|
|
|
vec4 surf = fog4blend(vec4(ts.rgb, float(ALPHA)*ts.a));
|
|
|
|
refr = mix(refr, surf.rgb, surf.a);
|
|
|
|
#endif
|
|
|
|
|
2013-03-12 23:13:39 +00:00
|
|
|
//done
|
|
|
|
gl_FragColor = vec4(refr, 1.0);
|
2012-05-11 01:57:00 +00:00
|
|
|
}
|
|
|
|
#endif
|