------------------------------------------------------------------------
r4235 | acceptthis | 2013-03-03 19:10:27 +0000 (Sun, 03 Mar 2013) | 5 lines fix missing q2 surface water warp. fix missing q2 underwater warp. tweak altwater shader+rendering to be capable of depth info too. Not enabling that yet. fix q2 conchar colour issue. fix rtlights in water. attempt to remove borders of shadowmap lights. implement support for dynamic resolution shadowmaps. still needs to choose the resolution properly. ------------------------------------------------------------------------ git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4231 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
eba3f5d4d1
commit
de4a7409b2
18 changed files with 585 additions and 406 deletions
|
@ -20,6 +20,9 @@ uniform float cvar_r_glsl_turbscale;
|
|||
#ifndef TINT
|
||||
#define TINT vec3(0.7, 0.8, 0.7)
|
||||
#endif
|
||||
#ifndef FOGTINT
|
||||
#define FOGTINT vec3(0.2, 0.3, 0.2)
|
||||
#endif
|
||||
|
||||
varying vec2 tc;
|
||||
varying vec4 tf;
|
||||
|
@ -42,17 +45,27 @@ void main (void)
|
|||
uniform sampler2D s_t0; //refract
|
||||
uniform sampler2D s_t1; //normalmap
|
||||
uniform sampler2D s_t2; //diffuse/reflection
|
||||
#ifdef DEPTH
|
||||
uniform sampler2D s_t3; //refraction depth
|
||||
#ifdef RIPPLEMAP
|
||||
uniform sampler2D s_t4; //ripplemap
|
||||
#endif
|
||||
#else
|
||||
#ifdef RIPPLEMAP
|
||||
uniform sampler2D s_t3; //ripplemap
|
||||
#endif
|
||||
#endif
|
||||
|
||||
uniform float e_time;
|
||||
void main (void)
|
||||
{
|
||||
vec2 stc, ntc;
|
||||
vec3 n, refr, refl, fres;
|
||||
float f;
|
||||
vec3 n, refr, refl;
|
||||
float fres;
|
||||
float depth;
|
||||
stc = (1.0 + (tf.xy / tf.w)) * 0.5;
|
||||
//hack the texture coords slightly so that there are no obvious gaps
|
||||
stc.t -= 1.5*norm.z/1080.0;
|
||||
|
||||
//apply q1-style warp, just for kicks
|
||||
ntc.s = tc.s + sin(tc.t+e_time)*0.125;
|
||||
|
@ -64,24 +77,60 @@ void main (void)
|
|||
n -= 1.0 - 4.0/256.0;
|
||||
|
||||
#ifdef RIPPLEMAP
|
||||
n += texture2D(s_t3, stc).rgb*3.0;
|
||||
n += texture2D(s_t4, stc).rgb*3.0;
|
||||
#endif
|
||||
|
||||
//the fresnel term decides how transparent the water should be
|
||||
f = pow(1.0-abs(dot(normalize(n), normalize(eye))), float(FRESNEL));
|
||||
fres = pow(1.0-abs(dot(normalize(n), normalize(eye))), float(FRESNEL));
|
||||
|
||||
#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.
|
||||
float gdepth = texture2D(s_t3, stc).x;
|
||||
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;
|
||||
}
|
||||
|
||||
//reduce the normals in shallow water (near walls, reduces the pain of linear sampling)
|
||||
if (depth < 100)
|
||||
n *= depth/100.0;
|
||||
#else
|
||||
depth = 1;
|
||||
#endif
|
||||
|
||||
|
||||
//refraction image (and water fog, if possible)
|
||||
refr = texture2D(s_t0, stc + n.st*STRENGTH*cvar_r_glsl_turbscale).rgb * TINT;
|
||||
#ifdef DEPTH
|
||||
refr = mix(refr, FOGTINT, min(depth/4096, 1));
|
||||
#endif
|
||||
|
||||
//reflection/diffuse
|
||||
#ifdef REFLECT
|
||||
refl = texture2D(s_t2, stc - n.st*STRENGTH*cvar_r_glsl_turbscale).rgb;
|
||||
#else
|
||||
refl = texture2D(s_t2, ntc).xyz;
|
||||
#endif
|
||||
// refl += 0.1*pow(dot(n, vec3(0.0,0.0,1.0)), 64.0);
|
||||
//FIXME: add specular
|
||||
|
||||
fres = refr * (1.0-f) + refl*f;
|
||||
//interplate by fresnel
|
||||
refr = mix(refr, refl, fres);
|
||||
|
||||
// fres = texture2D(s_t2, stc).xyz;
|
||||
|
||||
gl_FragColor = vec4(fres, 1.0);
|
||||
//done
|
||||
gl_FragColor = vec4(refr, 1.0);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -17,13 +17,18 @@ void main ()
|
|||
#ifdef FRAGMENT_SHADER
|
||||
uniform sampler2D s_t0;
|
||||
uniform float e_time;
|
||||
#ifndef ALPHA
|
||||
uniform float cvar_r_wateralpha;
|
||||
#define USEALPHA cvar_r_wateralpha
|
||||
#else
|
||||
#define USEALPHA float(ALPHA)
|
||||
#endif
|
||||
void main ()
|
||||
{
|
||||
vec2 ntc;
|
||||
ntc.s = tc.s + sin(tc.t+e_time)*0.125;
|
||||
ntc.t = tc.t + sin(tc.s+e_time)*0.125;
|
||||
vec3 ts = vec3(texture2D(s_t0, ntc));
|
||||
gl_FragColor = fog4(vec4(ts, cvar_r_wateralpha));
|
||||
gl_FragColor = fog4(vec4(ts, USEALPHA));
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -106,6 +106,9 @@ uniform vec3 e_uppercolour;
|
|||
uniform float l_lightradius;
|
||||
uniform vec3 l_lightcolour;
|
||||
uniform vec3 l_lightcolourscale;
|
||||
#ifdef PCF
|
||||
uniform vec4 l_shadowmapinfo; //xy are the texture scale, z is 1, w is the scale.
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
@ -115,12 +118,6 @@ uniform vec3 l_lightcolourscale;
|
|||
|
||||
float ShadowmapFilter(void)
|
||||
{
|
||||
#ifdef SPOT
|
||||
const vec3 texscale = vec3(1.0/512.0, 1.0/512.0, 1.0);
|
||||
#else
|
||||
const vec3 texscale = vec3(1.0/(512.0*3.0), 1.0/(512.0*2.0), 1.0);
|
||||
#endif
|
||||
|
||||
//dehomogonize input
|
||||
vec3 shadowcoord = (vtexprojcoord.xyz / vtexprojcoord.w);
|
||||
|
||||
|
@ -166,6 +163,9 @@ float ShadowmapFilter(void)
|
|||
vec4 nsc =l_projmatrix*vec4(t, 1.0);
|
||||
shadowcoord = (nsc.xyz / nsc.w);
|
||||
|
||||
//scale to match the light's precision and pinch inwards, so we never sample over the edge
|
||||
shadowcoord.st *= l_shadowmapinfo.w * (1.0-l_shadowmapinfo.st);
|
||||
|
||||
//now bias and relocate it
|
||||
shadowcoord = (shadowcoord + axis.xyz) * vec3(0.5/3.0, 0.5/2.0, 0.5);
|
||||
#endif
|
||||
|
@ -185,7 +185,7 @@ float ShadowmapFilter(void)
|
|||
return dot(mix(col.rgb, col.agb, fpart.x), vec3(1.0/9.0)); //blend r+a, gb are mixed because its pretty much free and gives a nicer dot instruction instead of lots of adds.
|
||||
|
||||
#else
|
||||
#define dosamp(x,y) shadow2D(s_t4, shadowcoord.xyz + (vec3(x,y,0.0)*texscale.xyz)).r
|
||||
#define dosamp(x,y) shadow2D(s_t4, shadowcoord.xyz + (vec3(x,y,0.0)*l_shadowmapinfo.xyz)).r
|
||||
float s = 0.0;
|
||||
s += dosamp(-1.0, -1.0);
|
||||
s += dosamp(-1.0, 0.0);
|
||||
|
|
|
@ -29,17 +29,9 @@ uniform vec4 e_rendertexturescale;
|
|||
uniform float cvar_r_waterwarp;
|
||||
void main ()
|
||||
{
|
||||
float amptemp;
|
||||
vec3 edge;
|
||||
edge = texture2D( s_t2, v_edge ).rgb;
|
||||
amptemp = (0.010 / 0.625) * cvar_r_waterwarp * edge.x;
|
||||
vec3 offset;
|
||||
offset = texture2D( s_t1, v_warp ).rgb;
|
||||
offset.x = (offset.x - 0.5) * 2.0;
|
||||
offset.y = (offset.y - 0.5) * 2.0;
|
||||
vec2 temp;
|
||||
temp.x = v_stc.x + offset.x * amptemp;
|
||||
temp.y = v_stc.y + offset.y * amptemp;
|
||||
gl_FragColor = texture2D( s_t0, temp*e_rendertexturescale.st );
|
||||
vec2 amp = (0.010 / 0.625) * cvar_r_waterwarp * texture2D(s_t2, v_edge).rg;
|
||||
vec3 offset = (texture2D(s_t1, v_warp).rgb - 0.5) * 2.0;
|
||||
vec2 temp = v_stc + offset.xy * amp;
|
||||
gl_FragColor = texture2D(s_t0, temp*e_rendertexturescale.st);
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue