Updates to the water shaders and a fix to stamina bar display on ships.

This was SVN commit r3903.
This commit is contained in:
Matei
2006-05-28 22:00:01 +00:00
parent 67ede785d5
commit 7ac2fc94a9
3 changed files with 27 additions and 18 deletions
@@ -25,6 +25,10 @@
<Health>
<Bar_Height>12.0</Bar_Height>
</Health>
<Stamina>
<Bar_Height>12.3</Bar_Height>
</Stamina>
</Traits>
@@ -5,21 +5,24 @@ uniform vec3 cameraPos;
uniform sampler2D normalMap;
uniform sampler2D reflectionMap;
uniform sampler2D refractionMap;
uniform float shininess;
uniform float shininess;
uniform float waviness;
varying vec3 worldPos;
varying vec3 waterColor;
varying float waterDepth;
varying float w;
varying float w;
const vec3 specularColor = vec3(0.2, 0.2, 0.2);
void main()
{
vec3 n, l, h, v; // normal, vector to light, half-vector and view vector (vector to eye)
vec3 n, l, h, v; // Normal, light vector, half-vector and view vector (vector to eye)
float ndotl, ndoth, ndotv;
float fresnel;
float temp;
float t;
vec2 reflCoords, refrCoords;
vec3 reflCol, refrCol, specular;
vec3 reflColor, refrColor, specular;
n = normalize(texture2D(normalMap, gl_TexCoord[0].st).xzy - vec3(0.5, 0.5, 0.5));
l = -sunDir;
@@ -30,22 +33,24 @@ void main()
ndoth = dot(n, h);
ndotv = dot(n, v);
fresnel = pow(1.0 - ndotv, 0.8); // A rather arbitrary 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;
reflCoords += 2.9 * n.xz / w; // The 2.9 can be tweaked to make reflections "wavier"
reflCoords = 0.5 * (gl_TexCoord[1].xy / gl_TexCoord[1].w) + 0.5; // Unbias texture coords
reflCoords += waviness * n.xz / w;
refrCoords = 0.5 * (gl_TexCoord[2].xy / gl_TexCoord[2].w) + 0.5;
refrCoords -= 2.6 * n.xz / w; // The 2.6 can be tweaked to make refractions "wavier"
refrCoords = 0.5 * (gl_TexCoord[2].xy / gl_TexCoord[2].w) + 0.5; // Unbias texture coords
refrCoords -= waviness * n.xz / w;
reflCol = (0.8 + 0.2*ndotl) * texture2D(reflectionMap, reflCoords).rgb;
reflColor = texture2D(reflectionMap, reflCoords).rgb;
refrCol = (ambient + ndotl * sunColor) * mix(texture2D(refractionMap, refrCoords).rgb, waterColor, 0.3);
refrColor = (0.5 + 0.5*ndotl) * mix(texture2D(refractionMap, refrCoords).rgb, waterColor, 0.3);
specular = pow(max(0.0, ndoth), shininess) * sunColor * vec3(0.2, 0.2, 0.2); // specular color can be changed here
specular = pow(max(0.0, ndoth), shininess) * sunColor * specularColor;
gl_FragColor.rgb = mix(refrCol + 0.3*specular, reflCol + specular, fresnel);
gl_FragColor.rgb = mix(refrColor + 0.3*specular, reflColor + specular, fresnel);
temp = 8.0 * max(0.0, 0.7-v.y);
gl_FragColor.a = 0.15 * waterDepth * (temp + mix(1.2, 2.2, fresnel));
// 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 = 8.0 * max(0.0, 0.7 - v.y);
gl_FragColor.a = 0.15 * waterDepth * (1.2 + t + fresnel);
}
@@ -11,10 +11,10 @@ varying float w;
void main()
{
worldPos = gl_Vertex.xyz;
waterColor = gl_Color.xyz;
waterColor = gl_Color.rgb;
waterDepth = vertexDepth;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = reflectionMatrix * gl_Vertex;
gl_TexCoord[1] = reflectionMatrix * gl_Vertex; // projective texturing
gl_TexCoord[2] = reflectionMatrix * gl_Vertex;
w = gl_TexCoord[1].w;
gl_Position = ftransform();