1
0
forked from 0ad/0ad

Updated water shaders to support darkening when out of LOS.

This was SVN commit r4269.
This commit is contained in:
Matei 2006-08-31 23:55:39 +00:00
parent c4d478a690
commit 4a45724ef2
2 changed files with 33 additions and 29 deletions

View File

@ -1,23 +1,24 @@
uniform vec3 ambient;
uniform vec3 sunDir;
uniform vec3 sunColor;
uniform vec3 cameraPos;
uniform sampler2D normalMap;
uniform sampler2D reflectionMap;
uniform sampler2D refractionMap;
uniform vec3 cameraPos;
uniform sampler2D normalMap;
uniform sampler2D reflectionMap;
uniform sampler2D refractionMap;
uniform float shininess;
uniform float waviness;
uniform float waviness;
uniform vec3 tint;
uniform float murkiness;
uniform float fullDepth;
varying vec3 worldPos;
varying float waterDepth;
varying float w;
uniform float fullDepth;
const vec3 specularColor = vec3(0.15, 0.15, 0.15);
void main()
varying vec3 worldPos;
varying float w;
varying float waterDepth;
varying float losMod;
const vec3 specularColor = vec3(0.15, 0.15, 0.15);
void main()
{
vec3 n, l, h, v; // Normal, light vector, half-vector and view vector (vector to eye)
float ndotl, ndoth, ndotv;
@ -26,18 +27,18 @@ void main()
vec3 myTint;
float t;
vec2 reflCoords, refrCoords;
vec3 reflColor, refrColor, specular;
n = normalize(texture2D(normalMap, gl_TexCoord[0].st).xzy - vec3(0.5, 0.5, 0.5));
l = -sunDir;
v = normalize(cameraPos - worldPos);
h = normalize(l + v);
ndotl = dot(n, l);
vec3 reflColor, refrColor, specular;
n = normalize(texture2D(normalMap, gl_TexCoord[0].st).xzy - vec3(0.5, 0.5, 0.5));
l = -sunDir;
v = normalize(cameraPos - worldPos);
h = normalize(l + v);
ndotl = dot(n, l);
ndoth = dot(n, h);
ndotv = dot(n, v);
fresnel = pow(1.0 - ndotv, 0.8); // A rather random Fresnel approximation
fresnel = pow(1.0 - ndotv, 0.8); // A rather random Fresnel approximation
reflCoords = 0.5 * (gl_TexCoord[1].xy / gl_TexCoord[1].w) + 0.5; // Unbias texture coords
reflCoords += waviness * n.xz / w;
@ -53,10 +54,10 @@ void main()
specular = pow(max(0.0, ndoth), shininess) * sunColor * specularColor;
gl_FragColor.rgb = mix(refrColor + 0.3*specular, reflColor + specular, fresnel);
gl_FragColor.rgb = mix(refrColor + 0.3*specular, reflColor + specular, fresnel) * losMod;
// Make alpha vary based on both depth (so it blends with the shore) and view angle (make it
// become opaque faster at lower view angles so we can't look "underneath" the water plane)
t = 18.0 * max(0.0, 0.7 - v.y);
gl_FragColor.a = 0.15 * waterDepth * (1.2 + t + fresnel);
}
gl_FragColor.a = 0.15 * waterDepth * (1.2 + t + fresnel);
}

View File

@ -2,18 +2,21 @@ uniform mat4 reflectionMatrix;
uniform mat4 refractionMatrix;
attribute float vertexDepth;
attribute float losMultiplier;
varying vec3 worldPos;
varying float waterDepth;
varying float w;
varying float waterDepth;
varying float losMod;
void main()
{
worldPos = gl_Vertex.xyz;
waterDepth = vertexDepth;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = reflectionMatrix * gl_Vertex; // projective texturing
gl_TexCoord[2] = reflectionMatrix * gl_Vertex;
losMod = losMultiplier;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = reflectionMatrix * gl_Vertex; // projective texturing
gl_TexCoord[2] = reflectionMatrix * gl_Vertex;
w = gl_TexCoord[1].w;
gl_Position = ftransform();
}