From 9b0edf439a9d5f5298112191c75d392a6b904121 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 9 Apr 2013 12:12:02 -0700 Subject: Add shaders from warzone2100. --- COPYING | 1 + shaders/warzone2100/1.shader_test | 103 ++++++++++++++++++++++++++++++++++++++ shaders/warzone2100/4.shader_test | 51 +++++++++++++++++++ 3 files changed, 155 insertions(+) create mode 100644 shaders/warzone2100/1.shader_test create mode 100644 shaders/warzone2100/4.shader_test diff --git a/COPYING b/COPYING index feaf090..bb72bb2 100644 --- a/COPYING +++ b/COPYING @@ -1,6 +1,7 @@ shaders/0ad/*: shaders/gst-gl-*: shaders/supertuxkart/*: +shaders/warzone2100/*: /* * GStreamer * Copyright (C) 2007 David A. Schleef 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; +} + diff --git a/shaders/warzone2100/4.shader_test b/shaders/warzone2100/4.shader_test new file mode 100644 index 0000000..64dd0c5 --- /dev/null +++ b/shaders/warzone2100/4.shader_test @@ -0,0 +1,51 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#version 120 +#pragma debug(on) + +uniform sampler2D Texture0; +uniform sampler2D Texture1; +uniform vec4 teamcolour; +uniform int tcmask; +//uniform int fogEnabled; + +void main(void) +{ + vec4 mask, colour; + + // Get color from texture unit 0 + colour = texture2D(Texture0, gl_TexCoord[0].st); + + 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; + } +} + + +[vertex shader] +#version 120 +#pragma debug(on) + +void main(void) +{ + // Pass texture coordinates to fragment shader + gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; + + // Pass glColor to fragment shader + gl_FrontColor = gl_Color; + + // Translate every vertex according to the Model View and Projection Matrix + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; +} + -- cgit v1.2.3