summaryrefslogtreecommitdiff
path: root/shaders
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2011-06-01 11:23:46 -0700
committerEric Anholt <eric@anholt.net>2011-06-01 11:32:07 -0700
commitf363c1467d745847b181f7ad24e59fcba055b5b5 (patch)
treed4aa6acaf2bc2fc90919c1f271c3eadccf644c4d /shaders
parent030dfc844d7671eed6d6e5c76e4ee6b502571a06 (diff)
Add 0 A.D. shaders.
They appear to have only one linked program so far.
Diffstat (limited to 'shaders')
-rw-r--r--shaders/0ad/water_high.frag68
-rw-r--r--shaders/0ad/water_high.vert22
2 files changed, 90 insertions, 0 deletions
diff --git a/shaders/0ad/water_high.frag b/shaders/0ad/water_high.frag
new file mode 100644
index 0000000..865ff68
--- /dev/null
+++ b/shaders/0ad/water_high.frag
@@ -0,0 +1,68 @@
+uniform vec3 ambient;
+uniform vec3 sunDir;
+uniform vec3 sunColor;
+uniform vec3 cameraPos;
+uniform sampler2D normalMap;
+uniform sampler2D reflectionMap;
+uniform sampler2D refractionMap;
+uniform sampler2D losMap;
+uniform float shininess; // Blinn-Phong specular strength
+uniform float specularStrength; // Scaling for specular reflection (specular color is (this,this,this))
+uniform float waviness; // "Wildness" of the reflections and refractions; choose based on texture
+uniform vec3 tint; // Tint for refraction (used to simulate particles in water)
+uniform float murkiness; // Amount of tint to blend in with the refracted colour
+uniform float fullDepth; // Depth at which to use full murkiness (shallower water will be clearer)
+uniform vec3 reflectionTint; // Tint for reflection (used for really muddy water)
+uniform float reflectionTintStrength; // Strength of reflection tint (how much of it to mix in)
+
+varying vec3 worldPos;
+varying float w;
+varying float waterDepth;
+
+void main()
+{
+ vec3 n, l, h, v; // Normal, light vector, half-vector and view vector (vector to eye)
+ float ndotl, ndoth, ndotv;
+ float fresnel;
+ float myMurkiness; // Murkiness and tint at this pixel (tweaked based on lighting and depth)
+ float t; // Temporary variable
+ vec2 reflCoords, refrCoords;
+ vec3 reflColor, refrColor, specular;
+ float losMod;
+
+ 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);
+
+ myMurkiness = murkiness * min(waterDepth / fullDepth, 1.0);
+
+ fresnel = pow(1.0 - ndotv, 0.8); // A rather random Fresnel approximation
+
+ refrCoords = 0.5 * (gl_TexCoord[2].xy / gl_TexCoord[2].w) + 0.5; // Unbias texture coords
+ refrCoords -= 0.8 * waviness * n.xz / w; // Refractions can be slightly less wavy
+
+ reflCoords = 0.5 * (gl_TexCoord[1].xy / gl_TexCoord[1].w) + 0.5; // Unbias texture coords
+ reflCoords += waviness * n.xz / w;
+
+ reflColor = mix(texture2D(reflectionMap, reflCoords).rgb, sunColor * reflectionTint,
+ reflectionTintStrength);
+
+ refrColor = (0.5 + 0.5*ndotl) * mix(texture2D(refractionMap, refrCoords).rgb, sunColor * tint,
+ myMurkiness);
+
+ specular = pow(max(0.0, ndoth), shininess) * sunColor * specularStrength;
+
+ losMod = texture2D(losMap, gl_TexCoord[3].st).a;
+
+ 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);
+}
diff --git a/shaders/0ad/water_high.vert b/shaders/0ad/water_high.vert
new file mode 100644
index 0000000..ec972f2
--- /dev/null
+++ b/shaders/0ad/water_high.vert
@@ -0,0 +1,22 @@
+uniform mat4 reflectionMatrix;
+uniform mat4 refractionMatrix;
+uniform mat4 losMatrix;
+uniform vec4 translation;
+
+attribute float vertexDepth;
+
+varying vec3 worldPos;
+varying float w;
+varying float waterDepth;
+
+void main()
+{
+ worldPos = gl_Vertex.xyz;
+ waterDepth = vertexDepth;
+ gl_TexCoord[0] = gl_MultiTexCoord0 + translation;
+ gl_TexCoord[1] = reflectionMatrix * gl_Vertex; // projective texturing
+ gl_TexCoord[2] = reflectionMatrix * gl_Vertex;
+ gl_TexCoord[3] = losMatrix * gl_Vertex;
+ w = gl_TexCoord[1].w;
+ gl_Position = ftransform();
+}