diff options
author | Eric Anholt <eric@anholt.net> | 2013-04-09 11:24:50 -0700 |
---|---|---|
committer | Eric Anholt <eric@anholt.net> | 2013-04-09 11:24:50 -0700 |
commit | 08dc04697010faa80a949200577cae01ffb27202 (patch) | |
tree | 853f21ea7676a63723bfbd5bd160eee1e9677e6b /shaders | |
parent | 558ac050d031199864105ab7906e6cc6d62509fc (diff) |
Update 0 A.D. shaders.
Diffstat (limited to 'shaders')
-rw-r--r-- | shaders/0ad/12.shader_test | 360 | ||||
-rw-r--r-- | shaders/0ad/3.shader_test | 17 | ||||
-rw-r--r-- | shaders/0ad/6.shader_test | 21 | ||||
-rw-r--r-- | shaders/0ad/9.shader_test | 81 | ||||
-rw-r--r-- | shaders/0ad/water_high.frag | 68 | ||||
-rw-r--r-- | shaders/0ad/water_high.vert | 22 |
6 files changed, 479 insertions, 90 deletions
diff --git a/shaders/0ad/12.shader_test b/shaders/0ad/12.shader_test new file mode 100644 index 0000000..bb8ae0d --- /dev/null +++ b/shaders/0ad/12.shader_test @@ -0,0 +1,360 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#version 110 + +uniform vec3 ambient; +uniform vec3 sunDir; +uniform vec3 sunColor; +uniform vec3 cameraPos; +uniform sampler2D losMap; +uniform float shininess; +uniform float specularStrength; +uniform float waviness; +uniform vec3 tint; +uniform float murkiness; +uniform vec3 reflectionTint; +uniform float reflectionTintStrength; +uniform vec3 color; + +uniform vec3 fogColor; +uniform vec2 fogParams; + +uniform vec2 screenSize; +uniform float time; + +varying vec3 worldPos; +varying float waterDepth; + +uniform sampler2D normalMap; +uniform sampler2D normalMap2; + + + uniform sampler2D reflectionMap; + + + uniform sampler2D refractionMap; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +vec3 get_fog(vec3 color) +{ + float density = fogParams.x; + float maxFog = fogParams.y; + + const float LOG2 = 1.442695; + float z = gl_FragCoord.z / gl_FragCoord.w; + float fogFactor = exp2(-density * density * z * z * LOG2); + + fogFactor = fogFactor * (1.0 - maxFog) + maxFog; + + fogFactor = clamp(fogFactor, 0.0, 1.0); + + return mix(fogColor, color, fogFactor); +} + +void main() +{ + + + + + + + vec3 n, l, h, v; + float ndotl, ndoth, ndotv; + float fresnel; + float t; + vec2 reflCoords, refrCoords; + vec3 reflColor, refrColor, specular; + float losMod; + + float wavyFactor = waviness * 0.125; + + + vec3 ww = texture2D(normalMap, (gl_TexCoord[0].st) * mix(2.0,0.8,waviness/10.0) +gl_TexCoord[0].zw).xzy; + + + vec3 ww2 = texture2D(normalMap2, (gl_TexCoord[0].st) * mix(2.0,0.8,waviness/10.0) +gl_TexCoord[0].zw).xzy; + ww = mix(ww, ww2, mod(time * 60.0, 8.0) / 8.0); + + + + + + + n = normalize(ww - vec3(0.5, 0.5, 0.5)); + + n = mix(vec3(0.0,1.0,0.0),n,wavyFactor); + + + + + l = -sunDir; + v = normalize(cameraPos - worldPos); + h = normalize(l + v); + + ndotl = (dot(n, l) + 1.0)/2.0; + ndoth = dot(n, h); + ndotv = dot(n, v); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + float distoFactor = clamp((waterDepth/v.y)/4.0,0.0,7.0); + + + fresnel = pow(1.05 - ndotv, 1.3333); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + refrCoords = clamp( (0.5*gl_TexCoord[2].xy - n.xz * distoFactor) / gl_TexCoord[2].w + 0.5,0.0,1.0); + + float perceivedDepth = waterDepth / v.y; + vec3 refColor = texture2D(refractionMap, refrCoords).rgb; + float luminance = (1.0 - clamp((perceivedDepth/mix(300.0,1.0, pow(murkiness,0.2) )), 0.0, 1.0)); + float colorExtinction = clamp(perceivedDepth*murkiness/5.0,0.0,1.0); + refrColor = (0.5 + 0.5*ndotl) * mix(color,mix(refColor,refColor*tint,colorExtinction),luminance*luminance); + + + + + + + + + + + + + + + + + + + + reflCoords = clamp( (0.5*gl_TexCoord[1].xy + 10.0*n.xz) / gl_TexCoord[1].w + 0.5,0.0,1.0); + reflColor = mix(texture2D(reflectionMap, reflCoords).rgb, sunColor * reflectionTint, reflectionTintStrength); + + + + + + specular = pow(ndoth, shininess) * sunColor * specularStrength; + + losMod = texture2D(losMap, gl_TexCoord[3].st).a; + losMod = losMod < 0.03 ? 0.0 : losMod; + + vec3 colour; + + + + + + + + + + + + + colour = mix(refrColor + fresnel*specular, reflColor + fresnel*specular, fresnel); + + + + + + + + colour = mix(texture2D(refractionMap, (0.5*gl_TexCoord[2].xy) / gl_TexCoord[2].w + 0.5).rgb ,colour, clamp(perceivedDepth,0.0,1.0)); + + + + gl_FragColor.rgb = get_fog(colour) * losMod; + + + + + + + + + + + + + + t = 30.0 * max(0.0, 0.9 - v.y); + float alpha = clamp(0.15 * waterDepth * (1.2 + t + fresnel),0.0,1.0); + + + + gl_FragColor.a = alpha; + + +} + +TIMER| common/setup.xml: 791.83 us +TIMER| common/styles.xml: 53.064 us +TIMER| common/sprite1.xml: 2.03779 ms +TIMER| common/icon_sprites.xml: 122.018 us +TIMER| common/common_sprites.xml: 1.89583 ms +TIMER| common/common_styles.xml: 205.949 us +TIMER| session/sprites.xml: 2.32971 ms +TIMER| session/setup.xml: 82.104 us +TIMER| session/styles.xml: 207.038 us +TIMER| session/session.xml: 69.6939 ms +TIMER| common/global.xml: 1.1758 ms +GAME STARTED, ALL INIT COMPLETE +Using Xcursor to sys_cursor_create 32 x 32 cursor + +[vertex shader] +#version 110 + +uniform mat4 reflectionMatrix; +uniform mat4 refractionMatrix; +uniform mat4 losMatrix; +uniform mat4 shadowTransform; +uniform float repeatScale; +uniform vec2 translation; +uniform float waviness; + + + + + +uniform float time; +uniform float mapSize; + +varying vec3 worldPos; +varying float waterDepth; + + + +attribute vec3 a_vertex; +attribute vec4 a_encodedDepth; + +void main() +{ + worldPos = a_vertex; + waterDepth = dot(a_encodedDepth.xyz, vec3(255.0, -255.0, 1.0)); + + gl_TexCoord[0] = vec4(a_vertex.xz*repeatScale,translation); + gl_TexCoord[1] = reflectionMatrix * vec4(a_vertex, 1.0); + gl_TexCoord[2] = refractionMatrix * vec4(a_vertex, 1.0); + gl_TexCoord[3] = losMatrix * vec4(a_vertex, 1.0); + + gl_TexCoord[3].zw = vec2(a_vertex.xz)/mapSize; + + + + + + + + + gl_Position = gl_ModelViewProjectionMatrix * vec4(a_vertex, 1.0); +} + diff --git a/shaders/0ad/3.shader_test b/shaders/0ad/3.shader_test new file mode 100644 index 0000000..30ba541 --- /dev/null +++ b/shaders/0ad/3.shader_test @@ -0,0 +1,17 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +uniform vec4 color; +void main() +{ + gl_FragColor = color; +} + +[vertex shader] +attribute vec4 position; +void main() +{ + gl_Position = position; +} + diff --git a/shaders/0ad/6.shader_test b/shaders/0ad/6.shader_test new file mode 100644 index 0000000..2bdc44d --- /dev/null +++ b/shaders/0ad/6.shader_test @@ -0,0 +1,21 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#version 130 +uniform ivec4 color; +out ivec4 out_color; + +void main() +{ + out_color = color; +} + +[vertex shader] +#version 130 +in vec4 position; +void main() +{ + gl_Position = position; +} + diff --git a/shaders/0ad/9.shader_test b/shaders/0ad/9.shader_test new file mode 100644 index 0000000..b1f4165 --- /dev/null +++ b/shaders/0ad/9.shader_test @@ -0,0 +1,81 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#version 110 + +uniform sampler2D waveTex; +uniform sampler2D infoTex; + +uniform float time; +uniform float waviness; + +void main() +{ + vec3 color = texture2D(waveTex, gl_TexCoord[0].st * vec2(2.0,4.0) - vec2(0.0,0.5 + time/5.0)).rgb; + float split = abs(gl_TexCoord[0].x - 0.5); + split = 0.48 - split; + split *= 3.0; + split = min(1.0,split); + + float opac = split*min(1.0, gl_TexCoord[0].y); + opac *= 1.0 - max(0.0,gl_TexCoord[0].y-0.9)*10.0; + color = mix(vec3(0.5,0.5,1.0),color, opac); + + gl_FragColor.rgb = mix(vec3(0.5,0.5,1.0), color, clamp(texture2D(infoTex,gl_TexCoord[0].zw).r,0.4,1.0)); + + gl_FragColor.a = 1.0; +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +[vertex shader] +#version 110 + +attribute vec3 a_vertex; +attribute vec2 a_uv0; + +uniform float mapSize; + +void main() +{ + gl_Position = gl_ModelViewProjectionMatrix * vec4(a_vertex, 1.0); + gl_TexCoord[0].st = a_uv0; + gl_TexCoord[0].zw = vec2(a_vertex.xz)/mapSize; +} + diff --git a/shaders/0ad/water_high.frag b/shaders/0ad/water_high.frag deleted file mode 100644 index 865ff68..0000000 --- a/shaders/0ad/water_high.frag +++ /dev/null @@ -1,68 +0,0 @@ -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 deleted file mode 100644 index ec972f2..0000000 --- a/shaders/0ad/water_high.vert +++ /dev/null @@ -1,22 +0,0 @@ -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();
-}
|