Some water shaders, with per-pixel fresnel and lighting but no reflection and refraction yet.
This was SVN commit r3892.
This commit is contained in:
parent
e02d42b746
commit
965b4c9f92
44
binaries/data/mods/official/shaders/water_high.fs
Normal file
44
binaries/data/mods/official/shaders/water_high.fs
Normal file
@ -0,0 +1,44 @@
|
||||
uniform vec3 ambient;
|
||||
uniform vec3 sunDir;
|
||||
uniform vec3 sunColor;
|
||||
uniform vec3 cameraPos;
|
||||
uniform sampler2D normalMap;
|
||||
uniform float shininess;
|
||||
|
||||
varying vec3 worldPos;
|
||||
varying vec3 waterColor; /* Water colour with LOS multiplied in */
|
||||
varying float waterDepth;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 n, l, h, v; /* normal, vector to light, half-vector and view vector (vector to eye) */
|
||||
float ndotl, ndoth, ndotv;
|
||||
float fresnel;
|
||||
float t;
|
||||
vec3 color;
|
||||
vec3 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 arbitrary Fresnel approximation */
|
||||
|
||||
color = ambient * waterColor;
|
||||
specular = vec3(0.0, 0.0, 0.0);
|
||||
if(ndotl > 0.0)
|
||||
{
|
||||
color += ndotl * sunColor * waterColor;
|
||||
specular = pow(ndoth, shininess) * sunColor * 0.6; /* Assume specular color is (.6,.6,.6) for now */
|
||||
}
|
||||
|
||||
gl_FragColor.rgb = color + specular;
|
||||
|
||||
t = 8.0 * max(0.0, 0.7-v.y);
|
||||
gl_FragColor.a = mix(0.15*waterDepth*(1.2 + t), 0.15*waterDepth*(2.0 + t), fresnel) * fresnel;
|
||||
}
|
14
binaries/data/mods/official/shaders/water_high.vs
Normal file
14
binaries/data/mods/official/shaders/water_high.vs
Normal file
@ -0,0 +1,14 @@
|
||||
attribute float vertexDepth;
|
||||
|
||||
varying vec3 worldPos;
|
||||
varying vec3 waterColor; /* Water colour with LOS multiplied in */
|
||||
varying float waterDepth;
|
||||
|
||||
void main()
|
||||
{
|
||||
worldPos = gl_Vertex.xyz;
|
||||
waterColor = gl_Color.xyz;
|
||||
waterDepth = vertexDepth;
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
gl_Position = ftransform();
|
||||
}
|
8
binaries/data/mods/official/shaders/water_high.xml
Normal file
8
binaries/data/mods/official/shaders/water_high.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
|
||||
|
||||
<Program>
|
||||
<Shaders>
|
||||
<Shader type="VERTEX_SHADER">shaders/water_high.vs</Shader>
|
||||
<Shader type="FRAGMENT_SHADER">shaders/water_high.fs</Shader>
|
||||
</Shaders>
|
||||
</Program>
|
Loading…
Reference in New Issue
Block a user