diff options
Diffstat (limited to 'shaders/warzone2100/1.shader_test')
-rw-r--r-- | shaders/warzone2100/1.shader_test | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/shaders/warzone2100/1.shader_test b/shaders/warzone2100/1.shader_test new file mode 100644 index 0000000..c7b7d72 --- /dev/null +++ b/shaders/warzone2100/1.shader_test @@ -0,0 +1,103 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#version 120 +#pragma debug(on) + +varying float vertexDistance; +varying vec3 normal, lightDir, eyeVec; + +uniform sampler2D Texture0; +uniform sampler2D Texture1; +uniform sampler2D Texture2; +uniform vec4 teamcolour; +uniform int tcmask, normalmap; +uniform int fogEnabled; +uniform bool ecmEffect; +uniform float graphicsCycle; + +void main(void) +{ + vec4 mask, colour; + vec4 light = (gl_FrontLightModelProduct.sceneColor * gl_FrontMaterial.ambient) + (gl_LightSource[0].ambient * gl_FrontMaterial.ambient); + vec3 N = normalize(normal); + vec3 L = normalize(lightDir); + float lambertTerm = dot(N, L); + if (lambertTerm > 0.0) + { + light += gl_LightSource[0].diffuse * gl_FrontMaterial.diffuse * lambertTerm; + vec3 E = normalize(eyeVec); + vec3 R = reflect(-L, N); + float specular = pow(max(dot(R, E), 0.0), gl_FrontMaterial.shininess); + light += gl_LightSource[0].specular * gl_FrontMaterial.specular * specular; + } + + // Get color from texture unit 0, merge with lighting + colour = texture2D(Texture0, gl_TexCoord[0].st) * light; + + if (tcmask == 1) + { + // Get tcmask information from texture unit 1 + mask = texture2D(Texture1, gl_TexCoord[0].st); + + // Apply color using grain merge with tcmask + gl_FragColor = (colour + (teamcolour - 0.5) * mask.a) * gl_Color; + } + else + { + gl_FragColor = colour * gl_Color; + } + + if (ecmEffect) + { + gl_FragColor.a = 0.45 + 0.225 * graphicsCycle; + } + + if (fogEnabled > 0) + { + // Calculate linear fog + float fogFactor = (gl_Fog.end - vertexDistance) / (gl_Fog.end - gl_Fog.start); + fogFactor = clamp(fogFactor, 0.0, 1.0); + + // Return fragment color + gl_FragColor = mix(gl_Fog.color, gl_FragColor, fogFactor); + } +} + +[vertex shader] +#version 120 +#pragma debug(on) + +uniform float stretch; + +varying float vertexDistance; +varying vec3 normal, lightDir, eyeVec; + +void main(void) +{ + vec3 vVertex = vec3(gl_ModelViewMatrix * gl_Vertex); + vec4 position = gl_Vertex; + + // Pass texture coordinates to fragment shader + gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; + + // Lighting -- we pass these to the fragment shader + normal = gl_NormalMatrix * gl_Normal; + lightDir = vec3(gl_LightSource[0].position.xyz - vVertex); + eyeVec = -vVertex; + gl_FrontColor = gl_Color; + + // Implement building stretching to accomodate terrain + if (position.y <= 0.0) + { + position.y -= stretch; + } + + // Translate every vertex according to the Model View and Projection Matrix + gl_Position = gl_ModelViewProjectionMatrix * position; + + // Remember vertex distance + vertexDistance = gl_Position.z; +} + |