diff options
86 files changed, 13343 insertions, 13201 deletions
diff --git a/shaders/warsow/1.frag b/shaders/warsow/1.frag deleted file mode 100644 index dce1c71..0000000 --- a/shaders/warsow/1.frag +++ /dev/null @@ -1,342 +0,0 @@ -#define FRAGMENT_SHADER -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/1.shader_test b/shaders/warsow/1.shader_test new file mode 100644 index 0000000..f005219 --- /dev/null +++ b/shaders/warsow/1.shader_test @@ -0,0 +1,689 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + +[vertex shader] +#define VERTEX_SHADER +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/1.vert b/shaders/warsow/1.vert deleted file mode 100644 index 7cbe02c..0000000 --- a/shaders/warsow/1.vert +++ /dev/null @@ -1,342 +0,0 @@ -#define VERTEX_SHADER -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/10.frag b/shaders/warsow/10.frag deleted file mode 100644 index dce1c71..0000000 --- a/shaders/warsow/10.frag +++ /dev/null @@ -1,342 +0,0 @@ -#define FRAGMENT_SHADER -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/10.shader_test b/shaders/warsow/10.shader_test new file mode 100644 index 0000000..de4bd35 --- /dev/null +++ b/shaders/warsow/10.shader_test @@ -0,0 +1,697 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +#define APPLY_LIGHTSTYLE0 +#define APPLY_FBLIGHTMAP +#define APPLY_SPECULAR +#define APPLY_AMBIENT_COMPENSATION +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + +[vertex shader] +#define VERTEX_SHADER +#define APPLY_LIGHTSTYLE0 +#define APPLY_FBLIGHTMAP +#define APPLY_SPECULAR +#define APPLY_AMBIENT_COMPENSATION +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/10.vert b/shaders/warsow/10.vert deleted file mode 100644 index 7cbe02c..0000000 --- a/shaders/warsow/10.vert +++ /dev/null @@ -1,342 +0,0 @@ -#define VERTEX_SHADER -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/11.frag b/shaders/warsow/11.frag deleted file mode 100644 index 4b7ece2..0000000 --- a/shaders/warsow/11.frag +++ /dev/null @@ -1,344 +0,0 @@ -#define FRAGMENT_SHADER -#define APPLY_LIGHTSTYLE0 -#define APPLY_FBLIGHTMAP -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/11.vert b/shaders/warsow/11.vert deleted file mode 100644 index d34482c..0000000 --- a/shaders/warsow/11.vert +++ /dev/null @@ -1,344 +0,0 @@ -#define VERTEX_SHADER -#define APPLY_LIGHTSTYLE0 -#define APPLY_FBLIGHTMAP -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/12.frag b/shaders/warsow/12.frag deleted file mode 100644 index 00a170c..0000000 --- a/shaders/warsow/12.frag +++ /dev/null @@ -1,345 +0,0 @@ -#define FRAGMENT_SHADER -#define APPLY_LIGHTSTYLE0 -#define APPLY_FBLIGHTMAP -#define APPLY_SPECULAR -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/12.vert b/shaders/warsow/12.vert deleted file mode 100644 index 2ddc43a..0000000 --- a/shaders/warsow/12.vert +++ /dev/null @@ -1,345 +0,0 @@ -#define VERTEX_SHADER -#define APPLY_LIGHTSTYLE0 -#define APPLY_FBLIGHTMAP -#define APPLY_SPECULAR -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/13.frag b/shaders/warsow/13.frag deleted file mode 100644 index f106fbe..0000000 --- a/shaders/warsow/13.frag +++ /dev/null @@ -1,346 +0,0 @@ -#define FRAGMENT_SHADER -#define APPLY_LIGHTSTYLE0 -#define APPLY_FBLIGHTMAP -#define APPLY_SPECULAR -#define APPLY_AMBIENT_COMPENSATION -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/13.shader_test b/shaders/warsow/13.shader_test new file mode 100644 index 0000000..4a2358e --- /dev/null +++ b/shaders/warsow/13.shader_test @@ -0,0 +1,693 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +#define APPLY_DIRECTIONAL_LIGHT +#define APPLY_CELLSHADING +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + +[vertex shader] +#define VERTEX_SHADER +#define APPLY_DIRECTIONAL_LIGHT +#define APPLY_CELLSHADING +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/13.vert b/shaders/warsow/13.vert deleted file mode 100644 index 4fe15fd..0000000 --- a/shaders/warsow/13.vert +++ /dev/null @@ -1,346 +0,0 @@ -#define VERTEX_SHADER -#define APPLY_LIGHTSTYLE0 -#define APPLY_FBLIGHTMAP -#define APPLY_SPECULAR -#define APPLY_AMBIENT_COMPENSATION -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/14.frag b/shaders/warsow/14.frag deleted file mode 100644 index 4292f6c..0000000 --- a/shaders/warsow/14.frag +++ /dev/null @@ -1,344 +0,0 @@ -#define FRAGMENT_SHADER -#define APPLY_DIRECTIONAL_LIGHT -#define APPLY_CELLSHADING -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/14.vert b/shaders/warsow/14.vert deleted file mode 100644 index 78f8084..0000000 --- a/shaders/warsow/14.vert +++ /dev/null @@ -1,344 +0,0 @@ -#define VERTEX_SHADER -#define APPLY_DIRECTIONAL_LIGHT -#define APPLY_CELLSHADING -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/15.frag b/shaders/warsow/15.frag deleted file mode 100644 index af536af..0000000 --- a/shaders/warsow/15.frag +++ /dev/null @@ -1,151 +0,0 @@ -#define FRAGMENT_SHADER -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec4 TexCoord; -varying vec4 ProjVector; -#ifdef APPLY_EYEDOT -varying vec3 EyeVector; -#endif - -#ifdef VERTEX_SHADER -// Vertex shader - -#ifdef APPLY_EYEDOT -uniform vec3 EyeOrigin; -uniform float FrontPlane; -#endif - -void main(void) -{ -gl_FrontColor = gl_Color; - -mat4 textureMatrix; - -textureMatrix = gl_TextureMatrix[0]; -TexCoord.st = vec2 (textureMatrix * gl_MultiTexCoord0); - -textureMatrix = gl_TextureMatrix[0]; -textureMatrix[0] = -textureMatrix[0]; -textureMatrix[1] = -textureMatrix[1]; -TexCoord.pq = vec2 (textureMatrix * gl_MultiTexCoord0); - -#ifdef APPLY_EYEDOT -mat3 strMatrix; -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -vec3 EyeVectorWorld = (EyeOrigin - gl_Vertex.xyz) * FrontPlane; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -gl_Position = ftransform(); -ProjVector = gl_Position; -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_DUDV -uniform sampler2D DuDvMapTexture; -#endif - -#ifdef APPLY_EYEDOT -uniform sampler2D NormalmapTexture; -#endif -uniform sampler2D ReflectionTexture; -uniform sampler2D RefractionTexture; -uniform float TextureWidth, TextureHeight; - -void main(void) -{ -myhalf3 color; - -#ifdef APPLY_DUDV -vec3 displacement = vec3(texture2D(DuDvMapTexture, vec2(TexCoord.pq) * vec2(0.25))); -vec2 coord = vec2(TexCoord.st) + vec2(displacement) * vec2 (0.2); - -vec3 fdist = vec3 (normalize(vec3(texture2D(DuDvMapTexture, coord)) - vec3 (0.5))) * vec3(0.005); -#else -vec3 fdist = vec3(0.0); -#endif - -// get projective texcoords -float scale = float(1.0 / float(ProjVector.w)); -float inv2NW = 1.0 / (2.0 * float (TextureWidth)); -float inv2NH = 1.0 / (2.0 * float (TextureHeight)); -vec2 projCoord = (vec2(ProjVector.xy) * scale + vec2 (1.0)) * vec2 (0.5) + vec2(fdist.xy); -projCoord.s = float (clamp (float(projCoord.s), inv2NW, 1.0 - inv2NW)); -projCoord.t = float (clamp (float(projCoord.t), inv2NH, 1.0 - inv2NH)); - - -myhalf3 refr = myhalf3(0.0); -myhalf3 refl = myhalf3(0.0); - -#ifdef APPLY_EYEDOT -// calculate dot product between the surface normal and eye vector -// great for simulating varying water translucency based on the view angle -myhalf3 surfaceNormal = normalize(myhalf3(texture2D(NormalmapTexture, coord)) - myhalf3 (0.5)); -vec3 eyeNormal = normalize(myhalf3(EyeVector)); - -float refrdot = float(dot(surfaceNormal, eyeNormal)); -//refrdot = float (clamp (refrdot, 0.0, 1.0)); -float refldot = 1.0 - refrdot; -// get refraction and reflection - -#ifdef APPLY_REFRACTION -refr = (myhalf3(texture2D(RefractionTexture, projCoord))) * refrdot; -#endif -#ifdef APPLY_REFLECTION -refl = (myhalf3(texture2D(ReflectionTexture, projCoord))) * refldot; -#endif - -#else - -#ifdef APPLY_REFRACTION -refr = (myhalf3(texture2D(RefractionTexture, projCoord))); -#endif -#ifdef APPLY_REFLECTION -refl = (myhalf3(texture2D(ReflectionTexture, projCoord))); -#endif - -#endif - -// add reflection and refraction -#ifdef APPLY_DISTORTION_ALPHA -color = myhalf3(gl_Color.rgb) + myhalf3(mix (refr, refl, float(gl_Color.a))); -#else -color = myhalf3(gl_Color.rgb) + refr + refl; -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),1.0); -#else -gl_FragColor = vec4(vec3(color),1.0); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/15.vert b/shaders/warsow/15.vert deleted file mode 100644 index 6ee1e1e..0000000 --- a/shaders/warsow/15.vert +++ /dev/null @@ -1,151 +0,0 @@ -#define VERTEX_SHADER -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec4 TexCoord; -varying vec4 ProjVector; -#ifdef APPLY_EYEDOT -varying vec3 EyeVector; -#endif - -#ifdef VERTEX_SHADER -// Vertex shader - -#ifdef APPLY_EYEDOT -uniform vec3 EyeOrigin; -uniform float FrontPlane; -#endif - -void main(void) -{ -gl_FrontColor = gl_Color; - -mat4 textureMatrix; - -textureMatrix = gl_TextureMatrix[0]; -TexCoord.st = vec2 (textureMatrix * gl_MultiTexCoord0); - -textureMatrix = gl_TextureMatrix[0]; -textureMatrix[0] = -textureMatrix[0]; -textureMatrix[1] = -textureMatrix[1]; -TexCoord.pq = vec2 (textureMatrix * gl_MultiTexCoord0); - -#ifdef APPLY_EYEDOT -mat3 strMatrix; -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -vec3 EyeVectorWorld = (EyeOrigin - gl_Vertex.xyz) * FrontPlane; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -gl_Position = ftransform(); -ProjVector = gl_Position; -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_DUDV -uniform sampler2D DuDvMapTexture; -#endif - -#ifdef APPLY_EYEDOT -uniform sampler2D NormalmapTexture; -#endif -uniform sampler2D ReflectionTexture; -uniform sampler2D RefractionTexture; -uniform float TextureWidth, TextureHeight; - -void main(void) -{ -myhalf3 color; - -#ifdef APPLY_DUDV -vec3 displacement = vec3(texture2D(DuDvMapTexture, vec2(TexCoord.pq) * vec2(0.25))); -vec2 coord = vec2(TexCoord.st) + vec2(displacement) * vec2 (0.2); - -vec3 fdist = vec3 (normalize(vec3(texture2D(DuDvMapTexture, coord)) - vec3 (0.5))) * vec3(0.005); -#else -vec3 fdist = vec3(0.0); -#endif - -// get projective texcoords -float scale = float(1.0 / float(ProjVector.w)); -float inv2NW = 1.0 / (2.0 * float (TextureWidth)); -float inv2NH = 1.0 / (2.0 * float (TextureHeight)); -vec2 projCoord = (vec2(ProjVector.xy) * scale + vec2 (1.0)) * vec2 (0.5) + vec2(fdist.xy); -projCoord.s = float (clamp (float(projCoord.s), inv2NW, 1.0 - inv2NW)); -projCoord.t = float (clamp (float(projCoord.t), inv2NH, 1.0 - inv2NH)); - - -myhalf3 refr = myhalf3(0.0); -myhalf3 refl = myhalf3(0.0); - -#ifdef APPLY_EYEDOT -// calculate dot product between the surface normal and eye vector -// great for simulating varying water translucency based on the view angle -myhalf3 surfaceNormal = normalize(myhalf3(texture2D(NormalmapTexture, coord)) - myhalf3 (0.5)); -vec3 eyeNormal = normalize(myhalf3(EyeVector)); - -float refrdot = float(dot(surfaceNormal, eyeNormal)); -//refrdot = float (clamp (refrdot, 0.0, 1.0)); -float refldot = 1.0 - refrdot; -// get refraction and reflection - -#ifdef APPLY_REFRACTION -refr = (myhalf3(texture2D(RefractionTexture, projCoord))) * refrdot; -#endif -#ifdef APPLY_REFLECTION -refl = (myhalf3(texture2D(ReflectionTexture, projCoord))) * refldot; -#endif - -#else - -#ifdef APPLY_REFRACTION -refr = (myhalf3(texture2D(RefractionTexture, projCoord))); -#endif -#ifdef APPLY_REFLECTION -refl = (myhalf3(texture2D(ReflectionTexture, projCoord))); -#endif - -#endif - -// add reflection and refraction -#ifdef APPLY_DISTORTION_ALPHA -color = myhalf3(gl_Color.rgb) + myhalf3(mix (refr, refl, float(gl_Color.a))); -#else -color = myhalf3(gl_Color.rgb) + refr + refl; -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),1.0); -#else -gl_FragColor = vec4(vec3(color),1.0); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/16.frag b/shaders/warsow/16.frag deleted file mode 100644 index d917740..0000000 --- a/shaders/warsow/16.frag +++ /dev/null @@ -1,110 +0,0 @@ -#define FRAGMENT_SHADER -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec4 ProjVector; - -#ifdef VERTEX_SHADER -// Vertex shader - -void main(void) -{ -gl_FrontColor = gl_Color; - - -mat4 textureMatrix; - -textureMatrix = gl_TextureMatrix[0]; - -gl_Position = ftransform(); -ProjVector = textureMatrix * gl_Vertex; -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -uniform myhalf3 LightAmbient; - -uniform float TextureWidth, TextureHeight; -uniform float ProjDistance; -uniform sampler2DShadow ShadowmapTexture; - -void main(void) -{ -myhalf color = myhalf(1.0); - -if (ProjVector.w <= 0.0 || ProjVector.w >= ProjDistance) -discard; - -float dtW = 1.0 / TextureWidth; -float dtH = 1.0 / TextureHeight; - -vec3 coord = vec3 (ProjVector.xyz / ProjVector.w); -coord = (coord + vec3 (1.0)) * vec3 (0.5); -coord.s = float (clamp (float(coord.s), dtW, 1.0 - dtW)); -coord.t = float (clamp (float(coord.t), dtH, 1.0 - dtH)); -coord.r = float (clamp (float(coord.r), 0.0, 1.0)); - -myhalf shadow0 = myhalf(shadow2D(ShadowmapTexture, coord).r); -myhalf shadow = shadow0; - -#if defined(APPLY_PCF2x2) || defined(APPLY_PCF3x3) - -vec3 coord2 = coord + vec3(0.0, dtH, 0.0); -myhalf shadow1 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(dtW, dtH, 0.0); -myhalf shadow2 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(dtW, 0.0, 0.0); -myhalf shadow3 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -#if defined(APPLY_PCF3x3) -coord2 = coord + vec3(-dtW, 0.0, 0.0); -myhalf shadow4 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(-dtW, -dtH, 0.0); -myhalf shadow5 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(0.0, -dtH, 0.0); -myhalf shadow6 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(dtW, -dtH, 0.0); -myhalf shadow7 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(-dtW, dtH, 0.0); -myhalf shadow8 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -shadow = (shadow0 + shadow1 + shadow2 + shadow3 + shadow4 + shadow5 + shadow6 + shadow7 + shadow8) * myhalf(0.11); -#else -shadow = (shadow0 + shadow1 + shadow2 + shadow3) * myhalf(0.25); -#endif -#else -shadow = shadow0; -#endif - -float attenuation = float (ProjVector.w) / ProjDistance; -myhalf compensation = myhalf(0.25) - max(LightAmbient.x, max(LightAmbient.y, LightAmbient.z)) -;compensation = max (compensation, 0.0); -color = shadow + attenuation + compensation; - -gl_FragColor = vec4(vec3(color),1.0); -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/16.shader_test b/shaders/warsow/16.shader_test new file mode 100644 index 0000000..76c961a --- /dev/null +++ b/shaders/warsow/16.shader_test @@ -0,0 +1,307 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec4 TexCoord; +varying vec4 ProjVector; +#ifdef APPLY_EYEDOT +varying vec3 EyeVector; +#endif + +#ifdef VERTEX_SHADER +// Vertex shader + +#ifdef APPLY_EYEDOT +uniform vec3 EyeOrigin; +uniform float FrontPlane; +#endif + +void main(void) +{ +gl_FrontColor = gl_Color; + +mat4 textureMatrix; + +textureMatrix = gl_TextureMatrix[0]; +TexCoord.st = vec2 (textureMatrix * gl_MultiTexCoord0); + +textureMatrix = gl_TextureMatrix[0]; +textureMatrix[0] = -textureMatrix[0]; +textureMatrix[1] = -textureMatrix[1]; +TexCoord.pq = vec2 (textureMatrix * gl_MultiTexCoord0); + +#ifdef APPLY_EYEDOT +mat3 strMatrix; +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +vec3 EyeVectorWorld = (EyeOrigin - gl_Vertex.xyz) * FrontPlane; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +gl_Position = ftransform(); +ProjVector = gl_Position; +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_DUDV +uniform sampler2D DuDvMapTexture; +#endif + +#ifdef APPLY_EYEDOT +uniform sampler2D NormalmapTexture; +#endif +uniform sampler2D ReflectionTexture; +uniform sampler2D RefractionTexture; +uniform float TextureWidth, TextureHeight; + +void main(void) +{ +myhalf3 color; + +#ifdef APPLY_DUDV +vec3 displacement = vec3(texture2D(DuDvMapTexture, vec2(TexCoord.pq) * vec2(0.25))); +vec2 coord = vec2(TexCoord.st) + vec2(displacement) * vec2 (0.2); + +vec3 fdist = vec3 (normalize(vec3(texture2D(DuDvMapTexture, coord)) - vec3 (0.5))) * vec3(0.005); +#else +vec3 fdist = vec3(0.0); +#endif + +// get projective texcoords +float scale = float(1.0 / float(ProjVector.w)); +float inv2NW = 1.0 / (2.0 * float (TextureWidth)); +float inv2NH = 1.0 / (2.0 * float (TextureHeight)); +vec2 projCoord = (vec2(ProjVector.xy) * scale + vec2 (1.0)) * vec2 (0.5) + vec2(fdist.xy); +projCoord.s = float (clamp (float(projCoord.s), inv2NW, 1.0 - inv2NW)); +projCoord.t = float (clamp (float(projCoord.t), inv2NH, 1.0 - inv2NH)); + + +myhalf3 refr = myhalf3(0.0); +myhalf3 refl = myhalf3(0.0); + +#ifdef APPLY_EYEDOT +// calculate dot product between the surface normal and eye vector +// great for simulating varying water translucency based on the view angle +myhalf3 surfaceNormal = normalize(myhalf3(texture2D(NormalmapTexture, coord)) - myhalf3 (0.5)); +vec3 eyeNormal = normalize(myhalf3(EyeVector)); + +float refrdot = float(dot(surfaceNormal, eyeNormal)); +//refrdot = float (clamp (refrdot, 0.0, 1.0)); +float refldot = 1.0 - refrdot; +// get refraction and reflection + +#ifdef APPLY_REFRACTION +refr = (myhalf3(texture2D(RefractionTexture, projCoord))) * refrdot; +#endif +#ifdef APPLY_REFLECTION +refl = (myhalf3(texture2D(ReflectionTexture, projCoord))) * refldot; +#endif + +#else + +#ifdef APPLY_REFRACTION +refr = (myhalf3(texture2D(RefractionTexture, projCoord))); +#endif +#ifdef APPLY_REFLECTION +refl = (myhalf3(texture2D(ReflectionTexture, projCoord))); +#endif + +#endif + +// add reflection and refraction +#ifdef APPLY_DISTORTION_ALPHA +color = myhalf3(gl_Color.rgb) + myhalf3(mix (refr, refl, float(gl_Color.a))); +#else +color = myhalf3(gl_Color.rgb) + refr + refl; +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),1.0); +#else +gl_FragColor = vec4(vec3(color),1.0); +#endif +} + +#endif // FRAGMENT_SHADER + + +[vertex shader] +#define VERTEX_SHADER +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec4 TexCoord; +varying vec4 ProjVector; +#ifdef APPLY_EYEDOT +varying vec3 EyeVector; +#endif + +#ifdef VERTEX_SHADER +// Vertex shader + +#ifdef APPLY_EYEDOT +uniform vec3 EyeOrigin; +uniform float FrontPlane; +#endif + +void main(void) +{ +gl_FrontColor = gl_Color; + +mat4 textureMatrix; + +textureMatrix = gl_TextureMatrix[0]; +TexCoord.st = vec2 (textureMatrix * gl_MultiTexCoord0); + +textureMatrix = gl_TextureMatrix[0]; +textureMatrix[0] = -textureMatrix[0]; +textureMatrix[1] = -textureMatrix[1]; +TexCoord.pq = vec2 (textureMatrix * gl_MultiTexCoord0); + +#ifdef APPLY_EYEDOT +mat3 strMatrix; +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +vec3 EyeVectorWorld = (EyeOrigin - gl_Vertex.xyz) * FrontPlane; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +gl_Position = ftransform(); +ProjVector = gl_Position; +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_DUDV +uniform sampler2D DuDvMapTexture; +#endif + +#ifdef APPLY_EYEDOT +uniform sampler2D NormalmapTexture; +#endif +uniform sampler2D ReflectionTexture; +uniform sampler2D RefractionTexture; +uniform float TextureWidth, TextureHeight; + +void main(void) +{ +myhalf3 color; + +#ifdef APPLY_DUDV +vec3 displacement = vec3(texture2D(DuDvMapTexture, vec2(TexCoord.pq) * vec2(0.25))); +vec2 coord = vec2(TexCoord.st) + vec2(displacement) * vec2 (0.2); + +vec3 fdist = vec3 (normalize(vec3(texture2D(DuDvMapTexture, coord)) - vec3 (0.5))) * vec3(0.005); +#else +vec3 fdist = vec3(0.0); +#endif + +// get projective texcoords +float scale = float(1.0 / float(ProjVector.w)); +float inv2NW = 1.0 / (2.0 * float (TextureWidth)); +float inv2NH = 1.0 / (2.0 * float (TextureHeight)); +vec2 projCoord = (vec2(ProjVector.xy) * scale + vec2 (1.0)) * vec2 (0.5) + vec2(fdist.xy); +projCoord.s = float (clamp (float(projCoord.s), inv2NW, 1.0 - inv2NW)); +projCoord.t = float (clamp (float(projCoord.t), inv2NH, 1.0 - inv2NH)); + + +myhalf3 refr = myhalf3(0.0); +myhalf3 refl = myhalf3(0.0); + +#ifdef APPLY_EYEDOT +// calculate dot product between the surface normal and eye vector +// great for simulating varying water translucency based on the view angle +myhalf3 surfaceNormal = normalize(myhalf3(texture2D(NormalmapTexture, coord)) - myhalf3 (0.5)); +vec3 eyeNormal = normalize(myhalf3(EyeVector)); + +float refrdot = float(dot(surfaceNormal, eyeNormal)); +//refrdot = float (clamp (refrdot, 0.0, 1.0)); +float refldot = 1.0 - refrdot; +// get refraction and reflection + +#ifdef APPLY_REFRACTION +refr = (myhalf3(texture2D(RefractionTexture, projCoord))) * refrdot; +#endif +#ifdef APPLY_REFLECTION +refl = (myhalf3(texture2D(ReflectionTexture, projCoord))) * refldot; +#endif + +#else + +#ifdef APPLY_REFRACTION +refr = (myhalf3(texture2D(RefractionTexture, projCoord))); +#endif +#ifdef APPLY_REFLECTION +refl = (myhalf3(texture2D(ReflectionTexture, projCoord))); +#endif + +#endif + +// add reflection and refraction +#ifdef APPLY_DISTORTION_ALPHA +color = myhalf3(gl_Color.rgb) + myhalf3(mix (refr, refl, float(gl_Color.a))); +#else +color = myhalf3(gl_Color.rgb) + refr + refl; +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),1.0); +#else +gl_FragColor = vec4(vec3(color),1.0); +#endif +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/16.vert b/shaders/warsow/16.vert deleted file mode 100644 index f5a1571..0000000 --- a/shaders/warsow/16.vert +++ /dev/null @@ -1,110 +0,0 @@ -#define VERTEX_SHADER -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec4 ProjVector; - -#ifdef VERTEX_SHADER -// Vertex shader - -void main(void) -{ -gl_FrontColor = gl_Color; - - -mat4 textureMatrix; - -textureMatrix = gl_TextureMatrix[0]; - -gl_Position = ftransform(); -ProjVector = textureMatrix * gl_Vertex; -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -uniform myhalf3 LightAmbient; - -uniform float TextureWidth, TextureHeight; -uniform float ProjDistance; -uniform sampler2DShadow ShadowmapTexture; - -void main(void) -{ -myhalf color = myhalf(1.0); - -if (ProjVector.w <= 0.0 || ProjVector.w >= ProjDistance) -discard; - -float dtW = 1.0 / TextureWidth; -float dtH = 1.0 / TextureHeight; - -vec3 coord = vec3 (ProjVector.xyz / ProjVector.w); -coord = (coord + vec3 (1.0)) * vec3 (0.5); -coord.s = float (clamp (float(coord.s), dtW, 1.0 - dtW)); -coord.t = float (clamp (float(coord.t), dtH, 1.0 - dtH)); -coord.r = float (clamp (float(coord.r), 0.0, 1.0)); - -myhalf shadow0 = myhalf(shadow2D(ShadowmapTexture, coord).r); -myhalf shadow = shadow0; - -#if defined(APPLY_PCF2x2) || defined(APPLY_PCF3x3) - -vec3 coord2 = coord + vec3(0.0, dtH, 0.0); -myhalf shadow1 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(dtW, dtH, 0.0); -myhalf shadow2 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(dtW, 0.0, 0.0); -myhalf shadow3 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -#if defined(APPLY_PCF3x3) -coord2 = coord + vec3(-dtW, 0.0, 0.0); -myhalf shadow4 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(-dtW, -dtH, 0.0); -myhalf shadow5 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(0.0, -dtH, 0.0); -myhalf shadow6 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(dtW, -dtH, 0.0); -myhalf shadow7 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(-dtW, dtH, 0.0); -myhalf shadow8 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -shadow = (shadow0 + shadow1 + shadow2 + shadow3 + shadow4 + shadow5 + shadow6 + shadow7 + shadow8) * myhalf(0.11); -#else -shadow = (shadow0 + shadow1 + shadow2 + shadow3) * myhalf(0.25); -#endif -#else -shadow = shadow0; -#endif - -float attenuation = float (ProjVector.w) / ProjDistance; -myhalf compensation = myhalf(0.25) - max(LightAmbient.x, max(LightAmbient.y, LightAmbient.z)) -;compensation = max (compensation, 0.0); -color = shadow + attenuation + compensation; - -gl_FragColor = vec4(vec3(color),1.0); -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/17.frag b/shaders/warsow/17.frag deleted file mode 100644 index 0e60fc6..0000000 --- a/shaders/warsow/17.frag +++ /dev/null @@ -1,49 +0,0 @@ -#define FRAGMENT_SHADER -// Warsow GLSL shader - - -varying vec4 ProjVector; - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform float OutlineHeight; - -void main(void) -{ -gl_FrontColor = gl_Color; - -vec4 n = vec4(gl_Normal.xyz, 0.0); -vec4 v = vec4(gl_Vertex) + n * OutlineHeight; - -gl_Position = gl_ModelViewProjectionMatrix * v; -ProjVector = gl_Position; -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * v; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -uniform float OutlineCutOff; - -void main(void) -{ - -#ifdef APPLY_OUTLINES_CUTOFF -if (OutlineCutOff > 0.0 && (ProjVector.w > OutlineCutOff)) -discard; -#endif - -gl_FragColor = vec4 (gl_Color); -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/17.vert b/shaders/warsow/17.vert deleted file mode 100644 index 368238c..0000000 --- a/shaders/warsow/17.vert +++ /dev/null @@ -1,49 +0,0 @@ -#define VERTEX_SHADER -// Warsow GLSL shader - - -varying vec4 ProjVector; - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform float OutlineHeight; - -void main(void) -{ -gl_FrontColor = gl_Color; - -vec4 n = vec4(gl_Normal.xyz, 0.0); -vec4 v = vec4(gl_Vertex) + n * OutlineHeight; - -gl_Position = gl_ModelViewProjectionMatrix * v; -ProjVector = gl_Position; -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * v; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -uniform float OutlineCutOff; - -void main(void) -{ - -#ifdef APPLY_OUTLINES_CUTOFF -if (OutlineCutOff > 0.0 && (ProjVector.w > OutlineCutOff)) -discard; -#endif - -gl_FragColor = vec4 (gl_Color); -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/18.frag b/shaders/warsow/18.frag deleted file mode 100644 index f9d9ae2..0000000 --- a/shaders/warsow/18.frag +++ /dev/null @@ -1,63 +0,0 @@ -#define FRAGMENT_SHADER -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -#define M_TWOPI 6.28318530717958647692 - -varying vec2 TexCoord; - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform float TurbAmplitude, TurbPhase; - -void main(void) -{ -gl_FrontColor = gl_Color; - -vec4 turb; -turb = vec4(gl_MultiTexCoord0); -turb.s += TurbAmplitude * sin( ((gl_MultiTexCoord0.t / 4.0 + TurbPhase)) * M_TWOPI ); -turb.t += TurbAmplitude * sin( ((gl_MultiTexCoord0.s / 4.0 + TurbPhase)) * M_TWOPI ); -TexCoord = vec2(gl_TextureMatrix[0] * turb); - -gl_Position = ftransform(); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -uniform sampler2D BaseTexture; - -void main(void) -{ - -myhalf4 color; - -color = myhalf4(gl_Color) * myhalf4(texture2D(BaseTexture, TexCoord)); - -gl_FragColor = vec4(color); -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/18.vert b/shaders/warsow/18.vert deleted file mode 100644 index 27e76e5..0000000 --- a/shaders/warsow/18.vert +++ /dev/null @@ -1,63 +0,0 @@ -#define VERTEX_SHADER -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -#define M_TWOPI 6.28318530717958647692 - -varying vec2 TexCoord; - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform float TurbAmplitude, TurbPhase; - -void main(void) -{ -gl_FrontColor = gl_Color; - -vec4 turb; -turb = vec4(gl_MultiTexCoord0); -turb.s += TurbAmplitude * sin( ((gl_MultiTexCoord0.t / 4.0 + TurbPhase)) * M_TWOPI ); -turb.t += TurbAmplitude * sin( ((gl_MultiTexCoord0.s / 4.0 + TurbPhase)) * M_TWOPI ); -TexCoord = vec2(gl_TextureMatrix[0] * turb); - -gl_Position = ftransform(); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -uniform sampler2D BaseTexture; - -void main(void) -{ - -myhalf4 color; - -color = myhalf4(gl_Color) * myhalf4(texture2D(BaseTexture, TexCoord)); - -gl_FragColor = vec4(color); -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/19.frag b/shaders/warsow/19.frag deleted file mode 100644 index 28fd36b..0000000 --- a/shaders/warsow/19.frag +++ /dev/null @@ -1,345 +0,0 @@ -#define FRAGMENT_SHADER -#define APPLY_LIGHTSTYLE0 -#define APPLY_FBLIGHTMAP -#define APPLY_AMBIENT_COMPENSATION -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/19.shader_test b/shaders/warsow/19.shader_test new file mode 100644 index 0000000..9b644bc --- /dev/null +++ b/shaders/warsow/19.shader_test @@ -0,0 +1,225 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec4 ProjVector; + +#ifdef VERTEX_SHADER +// Vertex shader + +void main(void) +{ +gl_FrontColor = gl_Color; + + +mat4 textureMatrix; + +textureMatrix = gl_TextureMatrix[0]; + +gl_Position = ftransform(); +ProjVector = textureMatrix * gl_Vertex; +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +uniform myhalf3 LightAmbient; + +uniform float TextureWidth, TextureHeight; +uniform float ProjDistance; +uniform sampler2DShadow ShadowmapTexture; + +void main(void) +{ +myhalf color = myhalf(1.0); + +if (ProjVector.w <= 0.0 || ProjVector.w >= ProjDistance) +discard; + +float dtW = 1.0 / TextureWidth; +float dtH = 1.0 / TextureHeight; + +vec3 coord = vec3 (ProjVector.xyz / ProjVector.w); +coord = (coord + vec3 (1.0)) * vec3 (0.5); +coord.s = float (clamp (float(coord.s), dtW, 1.0 - dtW)); +coord.t = float (clamp (float(coord.t), dtH, 1.0 - dtH)); +coord.r = float (clamp (float(coord.r), 0.0, 1.0)); + +myhalf shadow0 = myhalf(shadow2D(ShadowmapTexture, coord).r); +myhalf shadow = shadow0; + +#if defined(APPLY_PCF2x2) || defined(APPLY_PCF3x3) + +vec3 coord2 = coord + vec3(0.0, dtH, 0.0); +myhalf shadow1 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(dtW, dtH, 0.0); +myhalf shadow2 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(dtW, 0.0, 0.0); +myhalf shadow3 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +#if defined(APPLY_PCF3x3) +coord2 = coord + vec3(-dtW, 0.0, 0.0); +myhalf shadow4 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(-dtW, -dtH, 0.0); +myhalf shadow5 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(0.0, -dtH, 0.0); +myhalf shadow6 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(dtW, -dtH, 0.0); +myhalf shadow7 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(-dtW, dtH, 0.0); +myhalf shadow8 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +shadow = (shadow0 + shadow1 + shadow2 + shadow3 + shadow4 + shadow5 + shadow6 + shadow7 + shadow8) * myhalf(0.11); +#else +shadow = (shadow0 + shadow1 + shadow2 + shadow3) * myhalf(0.25); +#endif +#else +shadow = shadow0; +#endif + +float attenuation = float (ProjVector.w) / ProjDistance; +myhalf compensation = myhalf(0.25) - max(LightAmbient.x, max(LightAmbient.y, LightAmbient.z)) +;compensation = max (compensation, 0.0); +color = shadow + attenuation + compensation; + +gl_FragColor = vec4(vec3(color),1.0); +} + +#endif // FRAGMENT_SHADER + + +[vertex shader] +#define VERTEX_SHADER +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec4 ProjVector; + +#ifdef VERTEX_SHADER +// Vertex shader + +void main(void) +{ +gl_FrontColor = gl_Color; + + +mat4 textureMatrix; + +textureMatrix = gl_TextureMatrix[0]; + +gl_Position = ftransform(); +ProjVector = textureMatrix * gl_Vertex; +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +uniform myhalf3 LightAmbient; + +uniform float TextureWidth, TextureHeight; +uniform float ProjDistance; +uniform sampler2DShadow ShadowmapTexture; + +void main(void) +{ +myhalf color = myhalf(1.0); + +if (ProjVector.w <= 0.0 || ProjVector.w >= ProjDistance) +discard; + +float dtW = 1.0 / TextureWidth; +float dtH = 1.0 / TextureHeight; + +vec3 coord = vec3 (ProjVector.xyz / ProjVector.w); +coord = (coord + vec3 (1.0)) * vec3 (0.5); +coord.s = float (clamp (float(coord.s), dtW, 1.0 - dtW)); +coord.t = float (clamp (float(coord.t), dtH, 1.0 - dtH)); +coord.r = float (clamp (float(coord.r), 0.0, 1.0)); + +myhalf shadow0 = myhalf(shadow2D(ShadowmapTexture, coord).r); +myhalf shadow = shadow0; + +#if defined(APPLY_PCF2x2) || defined(APPLY_PCF3x3) + +vec3 coord2 = coord + vec3(0.0, dtH, 0.0); +myhalf shadow1 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(dtW, dtH, 0.0); +myhalf shadow2 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(dtW, 0.0, 0.0); +myhalf shadow3 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +#if defined(APPLY_PCF3x3) +coord2 = coord + vec3(-dtW, 0.0, 0.0); +myhalf shadow4 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(-dtW, -dtH, 0.0); +myhalf shadow5 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(0.0, -dtH, 0.0); +myhalf shadow6 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(dtW, -dtH, 0.0); +myhalf shadow7 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(-dtW, dtH, 0.0); +myhalf shadow8 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +shadow = (shadow0 + shadow1 + shadow2 + shadow3 + shadow4 + shadow5 + shadow6 + shadow7 + shadow8) * myhalf(0.11); +#else +shadow = (shadow0 + shadow1 + shadow2 + shadow3) * myhalf(0.25); +#endif +#else +shadow = shadow0; +#endif + +float attenuation = float (ProjVector.w) / ProjDistance; +myhalf compensation = myhalf(0.25) - max(LightAmbient.x, max(LightAmbient.y, LightAmbient.z)) +;compensation = max (compensation, 0.0); +color = shadow + attenuation + compensation; + +gl_FragColor = vec4(vec3(color),1.0); +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/19.vert b/shaders/warsow/19.vert deleted file mode 100644 index 2303a5d..0000000 --- a/shaders/warsow/19.vert +++ /dev/null @@ -1,345 +0,0 @@ -#define VERTEX_SHADER -#define APPLY_LIGHTSTYLE0 -#define APPLY_FBLIGHTMAP -#define APPLY_AMBIENT_COMPENSATION -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/2.frag b/shaders/warsow/2.frag deleted file mode 100644 index 4b7ece2..0000000 --- a/shaders/warsow/2.frag +++ /dev/null @@ -1,344 +0,0 @@ -#define FRAGMENT_SHADER -#define APPLY_LIGHTSTYLE0 -#define APPLY_FBLIGHTMAP -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/2.vert b/shaders/warsow/2.vert deleted file mode 100644 index d34482c..0000000 --- a/shaders/warsow/2.vert +++ /dev/null @@ -1,344 +0,0 @@ -#define VERTEX_SHADER -#define APPLY_LIGHTSTYLE0 -#define APPLY_FBLIGHTMAP -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/20.frag b/shaders/warsow/20.frag deleted file mode 100644 index dce1c71..0000000 --- a/shaders/warsow/20.frag +++ /dev/null @@ -1,342 +0,0 @@ -#define FRAGMENT_SHADER -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/20.vert b/shaders/warsow/20.vert deleted file mode 100644 index 7cbe02c..0000000 --- a/shaders/warsow/20.vert +++ /dev/null @@ -1,342 +0,0 @@ -#define VERTEX_SHADER -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/21.frag b/shaders/warsow/21.frag deleted file mode 100644 index 4b7ece2..0000000 --- a/shaders/warsow/21.frag +++ /dev/null @@ -1,344 +0,0 @@ -#define FRAGMENT_SHADER -#define APPLY_LIGHTSTYLE0 -#define APPLY_FBLIGHTMAP -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/21.vert b/shaders/warsow/21.vert deleted file mode 100644 index d34482c..0000000 --- a/shaders/warsow/21.vert +++ /dev/null @@ -1,344 +0,0 @@ -#define VERTEX_SHADER -#define APPLY_LIGHTSTYLE0 -#define APPLY_FBLIGHTMAP -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/22.frag b/shaders/warsow/22.frag deleted file mode 100644 index 00a170c..0000000 --- a/shaders/warsow/22.frag +++ /dev/null @@ -1,345 +0,0 @@ -#define FRAGMENT_SHADER -#define APPLY_LIGHTSTYLE0 -#define APPLY_FBLIGHTMAP -#define APPLY_SPECULAR -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/22.shader_test b/shaders/warsow/22.shader_test new file mode 100644 index 0000000..b4f6f7c --- /dev/null +++ b/shaders/warsow/22.shader_test @@ -0,0 +1,103 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +// Warsow GLSL shader + + +varying vec4 ProjVector; + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform float OutlineHeight; + +void main(void) +{ +gl_FrontColor = gl_Color; + +vec4 n = vec4(gl_Normal.xyz, 0.0); +vec4 v = vec4(gl_Vertex) + n * OutlineHeight; + +gl_Position = gl_ModelViewProjectionMatrix * v; +ProjVector = gl_Position; +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * v; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +uniform float OutlineCutOff; + +void main(void) +{ + +#ifdef APPLY_OUTLINES_CUTOFF +if (OutlineCutOff > 0.0 && (ProjVector.w > OutlineCutOff)) +discard; +#endif + +gl_FragColor = vec4 (gl_Color); +} + +#endif // FRAGMENT_SHADER + + +[vertex shader] +#define VERTEX_SHADER +// Warsow GLSL shader + + +varying vec4 ProjVector; + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform float OutlineHeight; + +void main(void) +{ +gl_FrontColor = gl_Color; + +vec4 n = vec4(gl_Normal.xyz, 0.0); +vec4 v = vec4(gl_Vertex) + n * OutlineHeight; + +gl_Position = gl_ModelViewProjectionMatrix * v; +ProjVector = gl_Position; +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * v; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +uniform float OutlineCutOff; + +void main(void) +{ + +#ifdef APPLY_OUTLINES_CUTOFF +if (OutlineCutOff > 0.0 && (ProjVector.w > OutlineCutOff)) +discard; +#endif + +gl_FragColor = vec4 (gl_Color); +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/22.vert b/shaders/warsow/22.vert deleted file mode 100644 index 2ddc43a..0000000 --- a/shaders/warsow/22.vert +++ /dev/null @@ -1,345 +0,0 @@ -#define VERTEX_SHADER -#define APPLY_LIGHTSTYLE0 -#define APPLY_FBLIGHTMAP -#define APPLY_SPECULAR -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/23.frag b/shaders/warsow/23.frag deleted file mode 100644 index f106fbe..0000000 --- a/shaders/warsow/23.frag +++ /dev/null @@ -1,346 +0,0 @@ -#define FRAGMENT_SHADER -#define APPLY_LIGHTSTYLE0 -#define APPLY_FBLIGHTMAP -#define APPLY_SPECULAR -#define APPLY_AMBIENT_COMPENSATION -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/23.vert b/shaders/warsow/23.vert deleted file mode 100644 index 4fe15fd..0000000 --- a/shaders/warsow/23.vert +++ /dev/null @@ -1,346 +0,0 @@ -#define VERTEX_SHADER -#define APPLY_LIGHTSTYLE0 -#define APPLY_FBLIGHTMAP -#define APPLY_SPECULAR -#define APPLY_AMBIENT_COMPENSATION -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/24.frag b/shaders/warsow/24.frag deleted file mode 100644 index 4292f6c..0000000 --- a/shaders/warsow/24.frag +++ /dev/null @@ -1,344 +0,0 @@ -#define FRAGMENT_SHADER -#define APPLY_DIRECTIONAL_LIGHT -#define APPLY_CELLSHADING -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/24.vert b/shaders/warsow/24.vert deleted file mode 100644 index 78f8084..0000000 --- a/shaders/warsow/24.vert +++ /dev/null @@ -1,344 +0,0 @@ -#define VERTEX_SHADER -#define APPLY_DIRECTIONAL_LIGHT -#define APPLY_CELLSHADING -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/25.frag b/shaders/warsow/25.frag deleted file mode 100644 index af536af..0000000 --- a/shaders/warsow/25.frag +++ /dev/null @@ -1,151 +0,0 @@ -#define FRAGMENT_SHADER -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec4 TexCoord; -varying vec4 ProjVector; -#ifdef APPLY_EYEDOT -varying vec3 EyeVector; -#endif - -#ifdef VERTEX_SHADER -// Vertex shader - -#ifdef APPLY_EYEDOT -uniform vec3 EyeOrigin; -uniform float FrontPlane; -#endif - -void main(void) -{ -gl_FrontColor = gl_Color; - -mat4 textureMatrix; - -textureMatrix = gl_TextureMatrix[0]; -TexCoord.st = vec2 (textureMatrix * gl_MultiTexCoord0); - -textureMatrix = gl_TextureMatrix[0]; -textureMatrix[0] = -textureMatrix[0]; -textureMatrix[1] = -textureMatrix[1]; -TexCoord.pq = vec2 (textureMatrix * gl_MultiTexCoord0); - -#ifdef APPLY_EYEDOT -mat3 strMatrix; -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -vec3 EyeVectorWorld = (EyeOrigin - gl_Vertex.xyz) * FrontPlane; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -gl_Position = ftransform(); -ProjVector = gl_Position; -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_DUDV -uniform sampler2D DuDvMapTexture; -#endif - -#ifdef APPLY_EYEDOT -uniform sampler2D NormalmapTexture; -#endif -uniform sampler2D ReflectionTexture; -uniform sampler2D RefractionTexture; -uniform float TextureWidth, TextureHeight; - -void main(void) -{ -myhalf3 color; - -#ifdef APPLY_DUDV -vec3 displacement = vec3(texture2D(DuDvMapTexture, vec2(TexCoord.pq) * vec2(0.25))); -vec2 coord = vec2(TexCoord.st) + vec2(displacement) * vec2 (0.2); - -vec3 fdist = vec3 (normalize(vec3(texture2D(DuDvMapTexture, coord)) - vec3 (0.5))) * vec3(0.005); -#else -vec3 fdist = vec3(0.0); -#endif - -// get projective texcoords -float scale = float(1.0 / float(ProjVector.w)); -float inv2NW = 1.0 / (2.0 * float (TextureWidth)); -float inv2NH = 1.0 / (2.0 * float (TextureHeight)); -vec2 projCoord = (vec2(ProjVector.xy) * scale + vec2 (1.0)) * vec2 (0.5) + vec2(fdist.xy); -projCoord.s = float (clamp (float(projCoord.s), inv2NW, 1.0 - inv2NW)); -projCoord.t = float (clamp (float(projCoord.t), inv2NH, 1.0 - inv2NH)); - - -myhalf3 refr = myhalf3(0.0); -myhalf3 refl = myhalf3(0.0); - -#ifdef APPLY_EYEDOT -// calculate dot product between the surface normal and eye vector -// great for simulating varying water translucency based on the view angle -myhalf3 surfaceNormal = normalize(myhalf3(texture2D(NormalmapTexture, coord)) - myhalf3 (0.5)); -vec3 eyeNormal = normalize(myhalf3(EyeVector)); - -float refrdot = float(dot(surfaceNormal, eyeNormal)); -//refrdot = float (clamp (refrdot, 0.0, 1.0)); -float refldot = 1.0 - refrdot; -// get refraction and reflection - -#ifdef APPLY_REFRACTION -refr = (myhalf3(texture2D(RefractionTexture, projCoord))) * refrdot; -#endif -#ifdef APPLY_REFLECTION -refl = (myhalf3(texture2D(ReflectionTexture, projCoord))) * refldot; -#endif - -#else - -#ifdef APPLY_REFRACTION -refr = (myhalf3(texture2D(RefractionTexture, projCoord))); -#endif -#ifdef APPLY_REFLECTION -refl = (myhalf3(texture2D(ReflectionTexture, projCoord))); -#endif - -#endif - -// add reflection and refraction -#ifdef APPLY_DISTORTION_ALPHA -color = myhalf3(gl_Color.rgb) + myhalf3(mix (refr, refl, float(gl_Color.a))); -#else -color = myhalf3(gl_Color.rgb) + refr + refl; -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),1.0); -#else -gl_FragColor = vec4(vec3(color),1.0); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/25.shader_test b/shaders/warsow/25.shader_test new file mode 100644 index 0000000..7b223e1 --- /dev/null +++ b/shaders/warsow/25.shader_test @@ -0,0 +1,132 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +#define M_TWOPI 6.28318530717958647692 + +varying vec2 TexCoord; + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform float TurbAmplitude, TurbPhase; + +void main(void) +{ +gl_FrontColor = gl_Color; + +vec4 turb; +turb = vec4(gl_MultiTexCoord0); +turb.s += TurbAmplitude * sin( ((gl_MultiTexCoord0.t / 4.0 + TurbPhase)) * M_TWOPI ); +turb.t += TurbAmplitude * sin( ((gl_MultiTexCoord0.s / 4.0 + TurbPhase)) * M_TWOPI ); +TexCoord = vec2(gl_TextureMatrix[0] * turb); + +gl_Position = ftransform(); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +uniform sampler2D BaseTexture; + +void main(void) +{ + +myhalf4 color; + +color = myhalf4(gl_Color) * myhalf4(texture2D(BaseTexture, TexCoord)); + +gl_FragColor = vec4(color); +} + +#endif // FRAGMENT_SHADER + + + +[vertex shader] +#define VERTEX_SHADER +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +#define M_TWOPI 6.28318530717958647692 + +varying vec2 TexCoord; + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform float TurbAmplitude, TurbPhase; + +void main(void) +{ +gl_FrontColor = gl_Color; + +vec4 turb; +turb = vec4(gl_MultiTexCoord0); +turb.s += TurbAmplitude * sin( ((gl_MultiTexCoord0.t / 4.0 + TurbPhase)) * M_TWOPI ); +turb.t += TurbAmplitude * sin( ((gl_MultiTexCoord0.s / 4.0 + TurbPhase)) * M_TWOPI ); +TexCoord = vec2(gl_TextureMatrix[0] * turb); + +gl_Position = ftransform(); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +uniform sampler2D BaseTexture; + +void main(void) +{ + +myhalf4 color; + +color = myhalf4(gl_Color) * myhalf4(texture2D(BaseTexture, TexCoord)); + +gl_FragColor = vec4(color); +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/25.vert b/shaders/warsow/25.vert deleted file mode 100644 index 6ee1e1e..0000000 --- a/shaders/warsow/25.vert +++ /dev/null @@ -1,151 +0,0 @@ -#define VERTEX_SHADER -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec4 TexCoord; -varying vec4 ProjVector; -#ifdef APPLY_EYEDOT -varying vec3 EyeVector; -#endif - -#ifdef VERTEX_SHADER -// Vertex shader - -#ifdef APPLY_EYEDOT -uniform vec3 EyeOrigin; -uniform float FrontPlane; -#endif - -void main(void) -{ -gl_FrontColor = gl_Color; - -mat4 textureMatrix; - -textureMatrix = gl_TextureMatrix[0]; -TexCoord.st = vec2 (textureMatrix * gl_MultiTexCoord0); - -textureMatrix = gl_TextureMatrix[0]; -textureMatrix[0] = -textureMatrix[0]; -textureMatrix[1] = -textureMatrix[1]; -TexCoord.pq = vec2 (textureMatrix * gl_MultiTexCoord0); - -#ifdef APPLY_EYEDOT -mat3 strMatrix; -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -vec3 EyeVectorWorld = (EyeOrigin - gl_Vertex.xyz) * FrontPlane; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -gl_Position = ftransform(); -ProjVector = gl_Position; -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_DUDV -uniform sampler2D DuDvMapTexture; -#endif - -#ifdef APPLY_EYEDOT -uniform sampler2D NormalmapTexture; -#endif -uniform sampler2D ReflectionTexture; -uniform sampler2D RefractionTexture; -uniform float TextureWidth, TextureHeight; - -void main(void) -{ -myhalf3 color; - -#ifdef APPLY_DUDV -vec3 displacement = vec3(texture2D(DuDvMapTexture, vec2(TexCoord.pq) * vec2(0.25))); -vec2 coord = vec2(TexCoord.st) + vec2(displacement) * vec2 (0.2); - -vec3 fdist = vec3 (normalize(vec3(texture2D(DuDvMapTexture, coord)) - vec3 (0.5))) * vec3(0.005); -#else -vec3 fdist = vec3(0.0); -#endif - -// get projective texcoords -float scale = float(1.0 / float(ProjVector.w)); -float inv2NW = 1.0 / (2.0 * float (TextureWidth)); -float inv2NH = 1.0 / (2.0 * float (TextureHeight)); -vec2 projCoord = (vec2(ProjVector.xy) * scale + vec2 (1.0)) * vec2 (0.5) + vec2(fdist.xy); -projCoord.s = float (clamp (float(projCoord.s), inv2NW, 1.0 - inv2NW)); -projCoord.t = float (clamp (float(projCoord.t), inv2NH, 1.0 - inv2NH)); - - -myhalf3 refr = myhalf3(0.0); -myhalf3 refl = myhalf3(0.0); - -#ifdef APPLY_EYEDOT -// calculate dot product between the surface normal and eye vector -// great for simulating varying water translucency based on the view angle -myhalf3 surfaceNormal = normalize(myhalf3(texture2D(NormalmapTexture, coord)) - myhalf3 (0.5)); -vec3 eyeNormal = normalize(myhalf3(EyeVector)); - -float refrdot = float(dot(surfaceNormal, eyeNormal)); -//refrdot = float (clamp (refrdot, 0.0, 1.0)); -float refldot = 1.0 - refrdot; -// get refraction and reflection - -#ifdef APPLY_REFRACTION -refr = (myhalf3(texture2D(RefractionTexture, projCoord))) * refrdot; -#endif -#ifdef APPLY_REFLECTION -refl = (myhalf3(texture2D(ReflectionTexture, projCoord))) * refldot; -#endif - -#else - -#ifdef APPLY_REFRACTION -refr = (myhalf3(texture2D(RefractionTexture, projCoord))); -#endif -#ifdef APPLY_REFLECTION -refl = (myhalf3(texture2D(ReflectionTexture, projCoord))); -#endif - -#endif - -// add reflection and refraction -#ifdef APPLY_DISTORTION_ALPHA -color = myhalf3(gl_Color.rgb) + myhalf3(mix (refr, refl, float(gl_Color.a))); -#else -color = myhalf3(gl_Color.rgb) + refr + refl; -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),1.0); -#else -gl_FragColor = vec4(vec3(color),1.0); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/26.frag b/shaders/warsow/26.frag deleted file mode 100644 index d917740..0000000 --- a/shaders/warsow/26.frag +++ /dev/null @@ -1,110 +0,0 @@ -#define FRAGMENT_SHADER -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec4 ProjVector; - -#ifdef VERTEX_SHADER -// Vertex shader - -void main(void) -{ -gl_FrontColor = gl_Color; - - -mat4 textureMatrix; - -textureMatrix = gl_TextureMatrix[0]; - -gl_Position = ftransform(); -ProjVector = textureMatrix * gl_Vertex; -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -uniform myhalf3 LightAmbient; - -uniform float TextureWidth, TextureHeight; -uniform float ProjDistance; -uniform sampler2DShadow ShadowmapTexture; - -void main(void) -{ -myhalf color = myhalf(1.0); - -if (ProjVector.w <= 0.0 || ProjVector.w >= ProjDistance) -discard; - -float dtW = 1.0 / TextureWidth; -float dtH = 1.0 / TextureHeight; - -vec3 coord = vec3 (ProjVector.xyz / ProjVector.w); -coord = (coord + vec3 (1.0)) * vec3 (0.5); -coord.s = float (clamp (float(coord.s), dtW, 1.0 - dtW)); -coord.t = float (clamp (float(coord.t), dtH, 1.0 - dtH)); -coord.r = float (clamp (float(coord.r), 0.0, 1.0)); - -myhalf shadow0 = myhalf(shadow2D(ShadowmapTexture, coord).r); -myhalf shadow = shadow0; - -#if defined(APPLY_PCF2x2) || defined(APPLY_PCF3x3) - -vec3 coord2 = coord + vec3(0.0, dtH, 0.0); -myhalf shadow1 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(dtW, dtH, 0.0); -myhalf shadow2 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(dtW, 0.0, 0.0); -myhalf shadow3 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -#if defined(APPLY_PCF3x3) -coord2 = coord + vec3(-dtW, 0.0, 0.0); -myhalf shadow4 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(-dtW, -dtH, 0.0); -myhalf shadow5 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(0.0, -dtH, 0.0); -myhalf shadow6 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(dtW, -dtH, 0.0); -myhalf shadow7 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(-dtW, dtH, 0.0); -myhalf shadow8 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -shadow = (shadow0 + shadow1 + shadow2 + shadow3 + shadow4 + shadow5 + shadow6 + shadow7 + shadow8) * myhalf(0.11); -#else -shadow = (shadow0 + shadow1 + shadow2 + shadow3) * myhalf(0.25); -#endif -#else -shadow = shadow0; -#endif - -float attenuation = float (ProjVector.w) / ProjDistance; -myhalf compensation = myhalf(0.25) - max(LightAmbient.x, max(LightAmbient.y, LightAmbient.z)) -;compensation = max (compensation, 0.0); -color = shadow + attenuation + compensation; - -gl_FragColor = vec4(vec3(color),1.0); -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/26.vert b/shaders/warsow/26.vert deleted file mode 100644 index f5a1571..0000000 --- a/shaders/warsow/26.vert +++ /dev/null @@ -1,110 +0,0 @@ -#define VERTEX_SHADER -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec4 ProjVector; - -#ifdef VERTEX_SHADER -// Vertex shader - -void main(void) -{ -gl_FrontColor = gl_Color; - - -mat4 textureMatrix; - -textureMatrix = gl_TextureMatrix[0]; - -gl_Position = ftransform(); -ProjVector = textureMatrix * gl_Vertex; -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -uniform myhalf3 LightAmbient; - -uniform float TextureWidth, TextureHeight; -uniform float ProjDistance; -uniform sampler2DShadow ShadowmapTexture; - -void main(void) -{ -myhalf color = myhalf(1.0); - -if (ProjVector.w <= 0.0 || ProjVector.w >= ProjDistance) -discard; - -float dtW = 1.0 / TextureWidth; -float dtH = 1.0 / TextureHeight; - -vec3 coord = vec3 (ProjVector.xyz / ProjVector.w); -coord = (coord + vec3 (1.0)) * vec3 (0.5); -coord.s = float (clamp (float(coord.s), dtW, 1.0 - dtW)); -coord.t = float (clamp (float(coord.t), dtH, 1.0 - dtH)); -coord.r = float (clamp (float(coord.r), 0.0, 1.0)); - -myhalf shadow0 = myhalf(shadow2D(ShadowmapTexture, coord).r); -myhalf shadow = shadow0; - -#if defined(APPLY_PCF2x2) || defined(APPLY_PCF3x3) - -vec3 coord2 = coord + vec3(0.0, dtH, 0.0); -myhalf shadow1 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(dtW, dtH, 0.0); -myhalf shadow2 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(dtW, 0.0, 0.0); -myhalf shadow3 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -#if defined(APPLY_PCF3x3) -coord2 = coord + vec3(-dtW, 0.0, 0.0); -myhalf shadow4 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(-dtW, -dtH, 0.0); -myhalf shadow5 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(0.0, -dtH, 0.0); -myhalf shadow6 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(dtW, -dtH, 0.0); -myhalf shadow7 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(-dtW, dtH, 0.0); -myhalf shadow8 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -shadow = (shadow0 + shadow1 + shadow2 + shadow3 + shadow4 + shadow5 + shadow6 + shadow7 + shadow8) * myhalf(0.11); -#else -shadow = (shadow0 + shadow1 + shadow2 + shadow3) * myhalf(0.25); -#endif -#else -shadow = shadow0; -#endif - -float attenuation = float (ProjVector.w) / ProjDistance; -myhalf compensation = myhalf(0.25) - max(LightAmbient.x, max(LightAmbient.y, LightAmbient.z)) -;compensation = max (compensation, 0.0); -color = shadow + attenuation + compensation; - -gl_FragColor = vec4(vec3(color),1.0); -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/27.frag b/shaders/warsow/27.frag deleted file mode 100644 index 0e60fc6..0000000 --- a/shaders/warsow/27.frag +++ /dev/null @@ -1,49 +0,0 @@ -#define FRAGMENT_SHADER -// Warsow GLSL shader - - -varying vec4 ProjVector; - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform float OutlineHeight; - -void main(void) -{ -gl_FrontColor = gl_Color; - -vec4 n = vec4(gl_Normal.xyz, 0.0); -vec4 v = vec4(gl_Vertex) + n * OutlineHeight; - -gl_Position = gl_ModelViewProjectionMatrix * v; -ProjVector = gl_Position; -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * v; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -uniform float OutlineCutOff; - -void main(void) -{ - -#ifdef APPLY_OUTLINES_CUTOFF -if (OutlineCutOff > 0.0 && (ProjVector.w > OutlineCutOff)) -discard; -#endif - -gl_FragColor = vec4 (gl_Color); -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/27.vert b/shaders/warsow/27.vert deleted file mode 100644 index 368238c..0000000 --- a/shaders/warsow/27.vert +++ /dev/null @@ -1,49 +0,0 @@ -#define VERTEX_SHADER -// Warsow GLSL shader - - -varying vec4 ProjVector; - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform float OutlineHeight; - -void main(void) -{ -gl_FrontColor = gl_Color; - -vec4 n = vec4(gl_Normal.xyz, 0.0); -vec4 v = vec4(gl_Vertex) + n * OutlineHeight; - -gl_Position = gl_ModelViewProjectionMatrix * v; -ProjVector = gl_Position; -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * v; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -uniform float OutlineCutOff; - -void main(void) -{ - -#ifdef APPLY_OUTLINES_CUTOFF -if (OutlineCutOff > 0.0 && (ProjVector.w > OutlineCutOff)) -discard; -#endif - -gl_FragColor = vec4 (gl_Color); -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/28.frag b/shaders/warsow/28.frag deleted file mode 100644 index f9d9ae2..0000000 --- a/shaders/warsow/28.frag +++ /dev/null @@ -1,63 +0,0 @@ -#define FRAGMENT_SHADER -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -#define M_TWOPI 6.28318530717958647692 - -varying vec2 TexCoord; - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform float TurbAmplitude, TurbPhase; - -void main(void) -{ -gl_FrontColor = gl_Color; - -vec4 turb; -turb = vec4(gl_MultiTexCoord0); -turb.s += TurbAmplitude * sin( ((gl_MultiTexCoord0.t / 4.0 + TurbPhase)) * M_TWOPI ); -turb.t += TurbAmplitude * sin( ((gl_MultiTexCoord0.s / 4.0 + TurbPhase)) * M_TWOPI ); -TexCoord = vec2(gl_TextureMatrix[0] * turb); - -gl_Position = ftransform(); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -uniform sampler2D BaseTexture; - -void main(void) -{ - -myhalf4 color; - -color = myhalf4(gl_Color) * myhalf4(texture2D(BaseTexture, TexCoord)); - -gl_FragColor = vec4(color); -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/28.vert b/shaders/warsow/28.vert deleted file mode 100644 index 27e76e5..0000000 --- a/shaders/warsow/28.vert +++ /dev/null @@ -1,63 +0,0 @@ -#define VERTEX_SHADER -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -#define M_TWOPI 6.28318530717958647692 - -varying vec2 TexCoord; - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform float TurbAmplitude, TurbPhase; - -void main(void) -{ -gl_FrontColor = gl_Color; - -vec4 turb; -turb = vec4(gl_MultiTexCoord0); -turb.s += TurbAmplitude * sin( ((gl_MultiTexCoord0.t / 4.0 + TurbPhase)) * M_TWOPI ); -turb.t += TurbAmplitude * sin( ((gl_MultiTexCoord0.s / 4.0 + TurbPhase)) * M_TWOPI ); -TexCoord = vec2(gl_TextureMatrix[0] * turb); - -gl_Position = ftransform(); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -uniform sampler2D BaseTexture; - -void main(void) -{ - -myhalf4 color; - -color = myhalf4(gl_Color) * myhalf4(texture2D(BaseTexture, TexCoord)); - -gl_FragColor = vec4(color); -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/3.frag b/shaders/warsow/3.frag deleted file mode 100644 index 00a170c..0000000 --- a/shaders/warsow/3.frag +++ /dev/null @@ -1,345 +0,0 @@ -#define FRAGMENT_SHADER -#define APPLY_LIGHTSTYLE0 -#define APPLY_FBLIGHTMAP -#define APPLY_SPECULAR -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/3.vert b/shaders/warsow/3.vert deleted file mode 100644 index 2ddc43a..0000000 --- a/shaders/warsow/3.vert +++ /dev/null @@ -1,345 +0,0 @@ -#define VERTEX_SHADER -#define APPLY_LIGHTSTYLE0 -#define APPLY_FBLIGHTMAP -#define APPLY_SPECULAR -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/30.shader_test b/shaders/warsow/30.shader_test new file mode 100644 index 0000000..04dc676 --- /dev/null +++ b/shaders/warsow/30.shader_test @@ -0,0 +1,26 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#version 130 +uniform sampler2D texSampler; +in vec3 texCoords; +out vec4 out_color; + +void main() +{ + out_color = texture(texSampler, texCoords.xy); +} + +[vertex shader] +#version 130 +in vec2 position; +in vec3 textureCoords; +out vec3 texCoords; +void main() +{ + texCoords = textureCoords; + gl_Position = vec4(position, 0.0, 1.0); +} + + diff --git a/shaders/warsow/31.shader_test b/shaders/warsow/31.shader_test new file mode 100644 index 0000000..f005219 --- /dev/null +++ b/shaders/warsow/31.shader_test @@ -0,0 +1,689 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + +[vertex shader] +#define VERTEX_SHADER +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/34.shader_test b/shaders/warsow/34.shader_test new file mode 100644 index 0000000..62d5d00 --- /dev/null +++ b/shaders/warsow/34.shader_test @@ -0,0 +1,693 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +#define APPLY_LIGHTSTYLE0 +#define APPLY_FBLIGHTMAP +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + +[vertex shader] +#define VERTEX_SHADER +#define APPLY_LIGHTSTYLE0 +#define APPLY_FBLIGHTMAP +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/37.shader_test b/shaders/warsow/37.shader_test new file mode 100644 index 0000000..6e68fc9 --- /dev/null +++ b/shaders/warsow/37.shader_test @@ -0,0 +1,695 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +#define APPLY_LIGHTSTYLE0 +#define APPLY_FBLIGHTMAP +#define APPLY_SPECULAR +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + +[vertex shader] +#define VERTEX_SHADER +#define APPLY_LIGHTSTYLE0 +#define APPLY_FBLIGHTMAP +#define APPLY_SPECULAR +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/4.frag b/shaders/warsow/4.frag deleted file mode 100644 index f106fbe..0000000 --- a/shaders/warsow/4.frag +++ /dev/null @@ -1,346 +0,0 @@ -#define FRAGMENT_SHADER -#define APPLY_LIGHTSTYLE0 -#define APPLY_FBLIGHTMAP -#define APPLY_SPECULAR -#define APPLY_AMBIENT_COMPENSATION -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/4.shader_test b/shaders/warsow/4.shader_test new file mode 100644 index 0000000..62d5d00 --- /dev/null +++ b/shaders/warsow/4.shader_test @@ -0,0 +1,693 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +#define APPLY_LIGHTSTYLE0 +#define APPLY_FBLIGHTMAP +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + +[vertex shader] +#define VERTEX_SHADER +#define APPLY_LIGHTSTYLE0 +#define APPLY_FBLIGHTMAP +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/4.vert b/shaders/warsow/4.vert deleted file mode 100644 index 4fe15fd..0000000 --- a/shaders/warsow/4.vert +++ /dev/null @@ -1,346 +0,0 @@ -#define VERTEX_SHADER -#define APPLY_LIGHTSTYLE0 -#define APPLY_FBLIGHTMAP -#define APPLY_SPECULAR -#define APPLY_AMBIENT_COMPENSATION -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/40.shader_test b/shaders/warsow/40.shader_test new file mode 100644 index 0000000..de4bd35 --- /dev/null +++ b/shaders/warsow/40.shader_test @@ -0,0 +1,697 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +#define APPLY_LIGHTSTYLE0 +#define APPLY_FBLIGHTMAP +#define APPLY_SPECULAR +#define APPLY_AMBIENT_COMPENSATION +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + +[vertex shader] +#define VERTEX_SHADER +#define APPLY_LIGHTSTYLE0 +#define APPLY_FBLIGHTMAP +#define APPLY_SPECULAR +#define APPLY_AMBIENT_COMPENSATION +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/43.shader_test b/shaders/warsow/43.shader_test new file mode 100644 index 0000000..4a2358e --- /dev/null +++ b/shaders/warsow/43.shader_test @@ -0,0 +1,693 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +#define APPLY_DIRECTIONAL_LIGHT +#define APPLY_CELLSHADING +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + +[vertex shader] +#define VERTEX_SHADER +#define APPLY_DIRECTIONAL_LIGHT +#define APPLY_CELLSHADING +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/46.shader_test b/shaders/warsow/46.shader_test new file mode 100644 index 0000000..76c961a --- /dev/null +++ b/shaders/warsow/46.shader_test @@ -0,0 +1,307 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec4 TexCoord; +varying vec4 ProjVector; +#ifdef APPLY_EYEDOT +varying vec3 EyeVector; +#endif + +#ifdef VERTEX_SHADER +// Vertex shader + +#ifdef APPLY_EYEDOT +uniform vec3 EyeOrigin; +uniform float FrontPlane; +#endif + +void main(void) +{ +gl_FrontColor = gl_Color; + +mat4 textureMatrix; + +textureMatrix = gl_TextureMatrix[0]; +TexCoord.st = vec2 (textureMatrix * gl_MultiTexCoord0); + +textureMatrix = gl_TextureMatrix[0]; +textureMatrix[0] = -textureMatrix[0]; +textureMatrix[1] = -textureMatrix[1]; +TexCoord.pq = vec2 (textureMatrix * gl_MultiTexCoord0); + +#ifdef APPLY_EYEDOT +mat3 strMatrix; +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +vec3 EyeVectorWorld = (EyeOrigin - gl_Vertex.xyz) * FrontPlane; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +gl_Position = ftransform(); +ProjVector = gl_Position; +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_DUDV +uniform sampler2D DuDvMapTexture; +#endif + +#ifdef APPLY_EYEDOT +uniform sampler2D NormalmapTexture; +#endif +uniform sampler2D ReflectionTexture; +uniform sampler2D RefractionTexture; +uniform float TextureWidth, TextureHeight; + +void main(void) +{ +myhalf3 color; + +#ifdef APPLY_DUDV +vec3 displacement = vec3(texture2D(DuDvMapTexture, vec2(TexCoord.pq) * vec2(0.25))); +vec2 coord = vec2(TexCoord.st) + vec2(displacement) * vec2 (0.2); + +vec3 fdist = vec3 (normalize(vec3(texture2D(DuDvMapTexture, coord)) - vec3 (0.5))) * vec3(0.005); +#else +vec3 fdist = vec3(0.0); +#endif + +// get projective texcoords +float scale = float(1.0 / float(ProjVector.w)); +float inv2NW = 1.0 / (2.0 * float (TextureWidth)); +float inv2NH = 1.0 / (2.0 * float (TextureHeight)); +vec2 projCoord = (vec2(ProjVector.xy) * scale + vec2 (1.0)) * vec2 (0.5) + vec2(fdist.xy); +projCoord.s = float (clamp (float(projCoord.s), inv2NW, 1.0 - inv2NW)); +projCoord.t = float (clamp (float(projCoord.t), inv2NH, 1.0 - inv2NH)); + + +myhalf3 refr = myhalf3(0.0); +myhalf3 refl = myhalf3(0.0); + +#ifdef APPLY_EYEDOT +// calculate dot product between the surface normal and eye vector +// great for simulating varying water translucency based on the view angle +myhalf3 surfaceNormal = normalize(myhalf3(texture2D(NormalmapTexture, coord)) - myhalf3 (0.5)); +vec3 eyeNormal = normalize(myhalf3(EyeVector)); + +float refrdot = float(dot(surfaceNormal, eyeNormal)); +//refrdot = float (clamp (refrdot, 0.0, 1.0)); +float refldot = 1.0 - refrdot; +// get refraction and reflection + +#ifdef APPLY_REFRACTION +refr = (myhalf3(texture2D(RefractionTexture, projCoord))) * refrdot; +#endif +#ifdef APPLY_REFLECTION +refl = (myhalf3(texture2D(ReflectionTexture, projCoord))) * refldot; +#endif + +#else + +#ifdef APPLY_REFRACTION +refr = (myhalf3(texture2D(RefractionTexture, projCoord))); +#endif +#ifdef APPLY_REFLECTION +refl = (myhalf3(texture2D(ReflectionTexture, projCoord))); +#endif + +#endif + +// add reflection and refraction +#ifdef APPLY_DISTORTION_ALPHA +color = myhalf3(gl_Color.rgb) + myhalf3(mix (refr, refl, float(gl_Color.a))); +#else +color = myhalf3(gl_Color.rgb) + refr + refl; +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),1.0); +#else +gl_FragColor = vec4(vec3(color),1.0); +#endif +} + +#endif // FRAGMENT_SHADER + + +[vertex shader] +#define VERTEX_SHADER +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec4 TexCoord; +varying vec4 ProjVector; +#ifdef APPLY_EYEDOT +varying vec3 EyeVector; +#endif + +#ifdef VERTEX_SHADER +// Vertex shader + +#ifdef APPLY_EYEDOT +uniform vec3 EyeOrigin; +uniform float FrontPlane; +#endif + +void main(void) +{ +gl_FrontColor = gl_Color; + +mat4 textureMatrix; + +textureMatrix = gl_TextureMatrix[0]; +TexCoord.st = vec2 (textureMatrix * gl_MultiTexCoord0); + +textureMatrix = gl_TextureMatrix[0]; +textureMatrix[0] = -textureMatrix[0]; +textureMatrix[1] = -textureMatrix[1]; +TexCoord.pq = vec2 (textureMatrix * gl_MultiTexCoord0); + +#ifdef APPLY_EYEDOT +mat3 strMatrix; +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +vec3 EyeVectorWorld = (EyeOrigin - gl_Vertex.xyz) * FrontPlane; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +gl_Position = ftransform(); +ProjVector = gl_Position; +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_DUDV +uniform sampler2D DuDvMapTexture; +#endif + +#ifdef APPLY_EYEDOT +uniform sampler2D NormalmapTexture; +#endif +uniform sampler2D ReflectionTexture; +uniform sampler2D RefractionTexture; +uniform float TextureWidth, TextureHeight; + +void main(void) +{ +myhalf3 color; + +#ifdef APPLY_DUDV +vec3 displacement = vec3(texture2D(DuDvMapTexture, vec2(TexCoord.pq) * vec2(0.25))); +vec2 coord = vec2(TexCoord.st) + vec2(displacement) * vec2 (0.2); + +vec3 fdist = vec3 (normalize(vec3(texture2D(DuDvMapTexture, coord)) - vec3 (0.5))) * vec3(0.005); +#else +vec3 fdist = vec3(0.0); +#endif + +// get projective texcoords +float scale = float(1.0 / float(ProjVector.w)); +float inv2NW = 1.0 / (2.0 * float (TextureWidth)); +float inv2NH = 1.0 / (2.0 * float (TextureHeight)); +vec2 projCoord = (vec2(ProjVector.xy) * scale + vec2 (1.0)) * vec2 (0.5) + vec2(fdist.xy); +projCoord.s = float (clamp (float(projCoord.s), inv2NW, 1.0 - inv2NW)); +projCoord.t = float (clamp (float(projCoord.t), inv2NH, 1.0 - inv2NH)); + + +myhalf3 refr = myhalf3(0.0); +myhalf3 refl = myhalf3(0.0); + +#ifdef APPLY_EYEDOT +// calculate dot product between the surface normal and eye vector +// great for simulating varying water translucency based on the view angle +myhalf3 surfaceNormal = normalize(myhalf3(texture2D(NormalmapTexture, coord)) - myhalf3 (0.5)); +vec3 eyeNormal = normalize(myhalf3(EyeVector)); + +float refrdot = float(dot(surfaceNormal, eyeNormal)); +//refrdot = float (clamp (refrdot, 0.0, 1.0)); +float refldot = 1.0 - refrdot; +// get refraction and reflection + +#ifdef APPLY_REFRACTION +refr = (myhalf3(texture2D(RefractionTexture, projCoord))) * refrdot; +#endif +#ifdef APPLY_REFLECTION +refl = (myhalf3(texture2D(ReflectionTexture, projCoord))) * refldot; +#endif + +#else + +#ifdef APPLY_REFRACTION +refr = (myhalf3(texture2D(RefractionTexture, projCoord))); +#endif +#ifdef APPLY_REFLECTION +refl = (myhalf3(texture2D(ReflectionTexture, projCoord))); +#endif + +#endif + +// add reflection and refraction +#ifdef APPLY_DISTORTION_ALPHA +color = myhalf3(gl_Color.rgb) + myhalf3(mix (refr, refl, float(gl_Color.a))); +#else +color = myhalf3(gl_Color.rgb) + refr + refl; +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),1.0); +#else +gl_FragColor = vec4(vec3(color),1.0); +#endif +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/49.shader_test b/shaders/warsow/49.shader_test new file mode 100644 index 0000000..9b644bc --- /dev/null +++ b/shaders/warsow/49.shader_test @@ -0,0 +1,225 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec4 ProjVector; + +#ifdef VERTEX_SHADER +// Vertex shader + +void main(void) +{ +gl_FrontColor = gl_Color; + + +mat4 textureMatrix; + +textureMatrix = gl_TextureMatrix[0]; + +gl_Position = ftransform(); +ProjVector = textureMatrix * gl_Vertex; +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +uniform myhalf3 LightAmbient; + +uniform float TextureWidth, TextureHeight; +uniform float ProjDistance; +uniform sampler2DShadow ShadowmapTexture; + +void main(void) +{ +myhalf color = myhalf(1.0); + +if (ProjVector.w <= 0.0 || ProjVector.w >= ProjDistance) +discard; + +float dtW = 1.0 / TextureWidth; +float dtH = 1.0 / TextureHeight; + +vec3 coord = vec3 (ProjVector.xyz / ProjVector.w); +coord = (coord + vec3 (1.0)) * vec3 (0.5); +coord.s = float (clamp (float(coord.s), dtW, 1.0 - dtW)); +coord.t = float (clamp (float(coord.t), dtH, 1.0 - dtH)); +coord.r = float (clamp (float(coord.r), 0.0, 1.0)); + +myhalf shadow0 = myhalf(shadow2D(ShadowmapTexture, coord).r); +myhalf shadow = shadow0; + +#if defined(APPLY_PCF2x2) || defined(APPLY_PCF3x3) + +vec3 coord2 = coord + vec3(0.0, dtH, 0.0); +myhalf shadow1 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(dtW, dtH, 0.0); +myhalf shadow2 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(dtW, 0.0, 0.0); +myhalf shadow3 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +#if defined(APPLY_PCF3x3) +coord2 = coord + vec3(-dtW, 0.0, 0.0); +myhalf shadow4 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(-dtW, -dtH, 0.0); +myhalf shadow5 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(0.0, -dtH, 0.0); +myhalf shadow6 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(dtW, -dtH, 0.0); +myhalf shadow7 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(-dtW, dtH, 0.0); +myhalf shadow8 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +shadow = (shadow0 + shadow1 + shadow2 + shadow3 + shadow4 + shadow5 + shadow6 + shadow7 + shadow8) * myhalf(0.11); +#else +shadow = (shadow0 + shadow1 + shadow2 + shadow3) * myhalf(0.25); +#endif +#else +shadow = shadow0; +#endif + +float attenuation = float (ProjVector.w) / ProjDistance; +myhalf compensation = myhalf(0.25) - max(LightAmbient.x, max(LightAmbient.y, LightAmbient.z)) +;compensation = max (compensation, 0.0); +color = shadow + attenuation + compensation; + +gl_FragColor = vec4(vec3(color),1.0); +} + +#endif // FRAGMENT_SHADER + + +[vertex shader] +#define VERTEX_SHADER +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec4 ProjVector; + +#ifdef VERTEX_SHADER +// Vertex shader + +void main(void) +{ +gl_FrontColor = gl_Color; + + +mat4 textureMatrix; + +textureMatrix = gl_TextureMatrix[0]; + +gl_Position = ftransform(); +ProjVector = textureMatrix * gl_Vertex; +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +uniform myhalf3 LightAmbient; + +uniform float TextureWidth, TextureHeight; +uniform float ProjDistance; +uniform sampler2DShadow ShadowmapTexture; + +void main(void) +{ +myhalf color = myhalf(1.0); + +if (ProjVector.w <= 0.0 || ProjVector.w >= ProjDistance) +discard; + +float dtW = 1.0 / TextureWidth; +float dtH = 1.0 / TextureHeight; + +vec3 coord = vec3 (ProjVector.xyz / ProjVector.w); +coord = (coord + vec3 (1.0)) * vec3 (0.5); +coord.s = float (clamp (float(coord.s), dtW, 1.0 - dtW)); +coord.t = float (clamp (float(coord.t), dtH, 1.0 - dtH)); +coord.r = float (clamp (float(coord.r), 0.0, 1.0)); + +myhalf shadow0 = myhalf(shadow2D(ShadowmapTexture, coord).r); +myhalf shadow = shadow0; + +#if defined(APPLY_PCF2x2) || defined(APPLY_PCF3x3) + +vec3 coord2 = coord + vec3(0.0, dtH, 0.0); +myhalf shadow1 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(dtW, dtH, 0.0); +myhalf shadow2 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(dtW, 0.0, 0.0); +myhalf shadow3 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +#if defined(APPLY_PCF3x3) +coord2 = coord + vec3(-dtW, 0.0, 0.0); +myhalf shadow4 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(-dtW, -dtH, 0.0); +myhalf shadow5 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(0.0, -dtH, 0.0); +myhalf shadow6 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(dtW, -dtH, 0.0); +myhalf shadow7 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(-dtW, dtH, 0.0); +myhalf shadow8 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +shadow = (shadow0 + shadow1 + shadow2 + shadow3 + shadow4 + shadow5 + shadow6 + shadow7 + shadow8) * myhalf(0.11); +#else +shadow = (shadow0 + shadow1 + shadow2 + shadow3) * myhalf(0.25); +#endif +#else +shadow = shadow0; +#endif + +float attenuation = float (ProjVector.w) / ProjDistance; +myhalf compensation = myhalf(0.25) - max(LightAmbient.x, max(LightAmbient.y, LightAmbient.z)) +;compensation = max (compensation, 0.0); +color = shadow + attenuation + compensation; + +gl_FragColor = vec4(vec3(color),1.0); +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/5.frag b/shaders/warsow/5.frag deleted file mode 100644 index 4292f6c..0000000 --- a/shaders/warsow/5.frag +++ /dev/null @@ -1,344 +0,0 @@ -#define FRAGMENT_SHADER -#define APPLY_DIRECTIONAL_LIGHT -#define APPLY_CELLSHADING -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/5.vert b/shaders/warsow/5.vert deleted file mode 100644 index 78f8084..0000000 --- a/shaders/warsow/5.vert +++ /dev/null @@ -1,344 +0,0 @@ -#define VERTEX_SHADER -#define APPLY_DIRECTIONAL_LIGHT -#define APPLY_CELLSHADING -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec2 TexCoord; -#ifdef APPLY_LIGHTSTYLE0 -varying vec4 LightmapTexCoord01; -#ifdef APPLY_LIGHTSTYLE2 -varying vec4 LightmapTexCoord23; -#endif -#endif - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -varying vec3 EyeVector; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -varying vec3 LightVector; -#endif - -varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform vec3 EyeOrigin; - -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform vec3 LightDir; -#endif - -void main() -{ -gl_FrontColor = gl_Color; - -TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); - -#ifdef APPLY_LIGHTSTYLE0 -LightmapTexCoord01.st = gl_MultiTexCoord4.st; -#ifdef APPLY_LIGHTSTYLE1 -LightmapTexCoord01.pq = gl_MultiTexCoord5.st; -#ifdef APPLY_LIGHTSTYLE2 -LightmapTexCoord23.st = gl_MultiTexCoord6.st; -#ifdef APPLY_LIGHTSTYLE3 -LightmapTexCoord23.pq = gl_MultiTexCoord7.st; -#endif -#endif -#endif -#endif - -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -#ifdef APPLY_DIRECTIONAL_LIGHT -LightVector = LightDir * strMatrix; -#endif - -gl_Position = ftransform (); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_LIGHTSTYLE0 -uniform sampler2D LightmapTexture0; -uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord -uniform myhalf3 lsColor0; // lightstyle color - -#ifdef APPLY_LIGHTSTYLE1 -uniform sampler2D LightmapTexture1; -uniform float DeluxemapOffset1; -uniform myhalf3 lsColor1; - -#ifdef APPLY_LIGHTSTYLE2 -uniform sampler2D LightmapTexture2; -uniform float DeluxemapOffset2; -uniform myhalf3 lsColor2; - -#ifdef APPLY_LIGHTSTYLE3 -uniform sampler2D LightmapTexture3; -uniform float DeluxemapOffset3; -uniform myhalf3 lsColor3; - -#endif -#endif -#endif -#endif - -uniform sampler2D BaseTexture; -uniform sampler2D NormalmapTexture; -uniform sampler2D GlossTexture; -#ifdef APPLY_DECAL -uniform sampler2D DecalTexture; -#endif - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -uniform float OffsetMappingScale; -#endif - -uniform myhalf3 LightAmbient; -#ifdef APPLY_DIRECTIONAL_LIGHT -uniform myhalf3 LightDiffuse; -#endif - -uniform myhalf GlossIntensity; // gloss scaling factor -uniform myhalf GlossExponent; // gloss exponent factor - -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// The following reliefmapping and offsetmapping routine was taken from DarkPlaces -// The credit goes to LordHavoc (as always) -vec2 OffsetMapping(vec2 TexCoord) -{ -#ifdef APPLY_RELIEFMAPPING -// 14 sample relief mapping: linear search and then binary search -// this basically steps forward a small amount repeatedly until it finds -// itself inside solid, then jitters forward and back using decreasing -// amounts to find the impact -//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); -//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); -vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); -vec3 RT = vec3(TexCoord, 1); -OffsetVector *= 0.1; -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); -RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); -return RT.xy; -#else -// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) -// this basically moves forward the full distance, and then backs up based -// on height of samples -//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); -//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); -vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); -TexCoord += OffsetVector; -OffsetVector *= 0.5; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; -return TexCoord; -#endif -} -#endif - -void main() -{ -#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) -// apply offsetmapping -vec2 TexCoordOffset = OffsetMapping(TexCoord); -#define TexCoord TexCoordOffset -#endif -myhalf3 surfaceNormal; -myhalf3 diffuseNormalModelspace; -myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); -float diffuseProduct; -#ifdef APPLY_CELLSHADING -int lightcell; -float diffuseProductPositive; -float diffuseProductNegative; -float hardShadow; -#endif - -myhalf3 weightedDiffuseNormal; -myhalf3 specularNormal; -float specularProduct; - -#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) -myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); -#else -myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); -#endif - -// get the surface normal -surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); - -#ifdef APPLY_DIRECTIONAL_LIGHT -diffuseNormal = myhalf3 (LightVector); -weightedDiffuseNormal = diffuseNormal; -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -#ifdef APPLY_CELLSHADING -hardShadow = 0.0; -diffuseProductPositive = max (diffuseProduct, 0.0); -diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); - -// smooth the hard shadow edge -lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); -hardShadow += float(lightcell); - -lightcell = int(diffuseProductPositive * 2.0); -hardShadow += float(lightcell); - -color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); - -// backlight -lightcell = int (diffuseProductNegative * 2.0); -color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); -#else -color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; -#endif - -#endif - -// deluxemapping using light vectors in modelspace - -#ifdef APPLY_LIGHTSTYLE0 - -// get light normal -diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -// calculate directional shading -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); - -#ifdef APPLY_FBLIGHTMAP -weightedDiffuseNormal = diffuseNormal; -// apply lightmap color -color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); -#else - -#define NORMALIZE_DIFFUSE_NORMAL - -weightedDiffuseNormal = lsColor0 * diffuseNormal; -// apply lightmap color -color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); -#endif - -#ifdef APPLY_AMBIENT_COMPENSATION -// compensate for ambient lighting -color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; -#endif - -#ifdef APPLY_LIGHTSTYLE1 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor1 * diffuseNormal; -color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); - -#ifdef APPLY_LIGHTSTYLE2 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor2 * diffuseNormal; -color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); - -#ifdef APPLY_LIGHTSTYLE3 -diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; -diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); -diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); -weightedDiffuseNormal += lsColor3 * diffuseNormal; -color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); - -#endif -#endif -#endif -#endif - -#ifdef APPLY_SPECULAR - -#ifdef NORMALIZE_DIFFUSE_NORMAL -specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); -#else -specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); -#endif - -specularProduct = float (dot (surfaceNormal, specularNormal)); -color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); -#endif - -#ifdef APPLY_BASETEX_ALPHA_ONLY -color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); -#else -#ifdef APPLY_COLOR_CLAMPING -color = min(color, myhalf4(1.0)); -#endif -color = color * myhalf4(texture2D(BaseTexture, TexCoord)); -#endif - -#ifdef APPLY_DECAL -#ifdef APPLY_DECAL_ADD -myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb + color.rgb; -color.a = color.a * myhalf(gl_Color.a); -#else -myhalf4 decal = myhalf4(gl_Color.rgba); -if (decal.a > 0.0) -{ -decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); -color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); -} -#endif -#else -color = color * myhalf4(gl_Color.rgba); -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),color.a); -#else -gl_FragColor = vec4(color); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/52.shader_test b/shaders/warsow/52.shader_test new file mode 100644 index 0000000..b4f6f7c --- /dev/null +++ b/shaders/warsow/52.shader_test @@ -0,0 +1,103 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +// Warsow GLSL shader + + +varying vec4 ProjVector; + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform float OutlineHeight; + +void main(void) +{ +gl_FrontColor = gl_Color; + +vec4 n = vec4(gl_Normal.xyz, 0.0); +vec4 v = vec4(gl_Vertex) + n * OutlineHeight; + +gl_Position = gl_ModelViewProjectionMatrix * v; +ProjVector = gl_Position; +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * v; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +uniform float OutlineCutOff; + +void main(void) +{ + +#ifdef APPLY_OUTLINES_CUTOFF +if (OutlineCutOff > 0.0 && (ProjVector.w > OutlineCutOff)) +discard; +#endif + +gl_FragColor = vec4 (gl_Color); +} + +#endif // FRAGMENT_SHADER + + +[vertex shader] +#define VERTEX_SHADER +// Warsow GLSL shader + + +varying vec4 ProjVector; + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform float OutlineHeight; + +void main(void) +{ +gl_FrontColor = gl_Color; + +vec4 n = vec4(gl_Normal.xyz, 0.0); +vec4 v = vec4(gl_Vertex) + n * OutlineHeight; + +gl_Position = gl_ModelViewProjectionMatrix * v; +ProjVector = gl_Position; +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * v; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +uniform float OutlineCutOff; + +void main(void) +{ + +#ifdef APPLY_OUTLINES_CUTOFF +if (OutlineCutOff > 0.0 && (ProjVector.w > OutlineCutOff)) +discard; +#endif + +gl_FragColor = vec4 (gl_Color); +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/55.shader_test b/shaders/warsow/55.shader_test new file mode 100644 index 0000000..3e97234 --- /dev/null +++ b/shaders/warsow/55.shader_test @@ -0,0 +1,140 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +#define M_TWOPI 6.28318530717958647692 + +varying vec2 TexCoord; + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform float TurbAmplitude, TurbPhase; + +void main(void) +{ +gl_FrontColor = gl_Color; + +vec4 turb; +turb = vec4(gl_MultiTexCoord0); +turb.s += TurbAmplitude * sin( ((gl_MultiTexCoord0.t / 4.0 + TurbPhase)) * M_TWOPI ); +turb.t += TurbAmplitude * sin( ((gl_MultiTexCoord0.s / 4.0 + TurbPhase)) * M_TWOPI ); +TexCoord = vec2(gl_TextureMatrix[0] * turb); + +gl_Position = ftransform(); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +uniform sampler2D BaseTexture; + +void main(void) +{ + +myhalf4 color; + +color = myhalf4(gl_Color) * myhalf4(texture2D(BaseTexture, TexCoord)); + +gl_FragColor = vec4(color); +} + +#endif // FRAGMENT_SHADER + + +[0m[0m +=====================================[0m +[0mwdm16[0m +[0m +Silver[0m connected from 127.0.0.1[0m +Silver skill 50[0m +Sector[0m connected from 127.0.0.1[0m +Sector skill 50[0m + +[vertex shader] +#define VERTEX_SHADER +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +#define M_TWOPI 6.28318530717958647692 + +varying vec2 TexCoord; + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform float TurbAmplitude, TurbPhase; + +void main(void) +{ +gl_FrontColor = gl_Color; + +vec4 turb; +turb = vec4(gl_MultiTexCoord0); +turb.s += TurbAmplitude * sin( ((gl_MultiTexCoord0.t / 4.0 + TurbPhase)) * M_TWOPI ); +turb.t += TurbAmplitude * sin( ((gl_MultiTexCoord0.s / 4.0 + TurbPhase)) * M_TWOPI ); +TexCoord = vec2(gl_TextureMatrix[0] * turb); + +gl_Position = ftransform(); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +uniform sampler2D BaseTexture; + +void main(void) +{ + +myhalf4 color; + +color = myhalf4(gl_Color) * myhalf4(texture2D(BaseTexture, TexCoord)); + +gl_FragColor = vec4(color); +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/6.frag b/shaders/warsow/6.frag deleted file mode 100644 index af536af..0000000 --- a/shaders/warsow/6.frag +++ /dev/null @@ -1,151 +0,0 @@ -#define FRAGMENT_SHADER -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec4 TexCoord; -varying vec4 ProjVector; -#ifdef APPLY_EYEDOT -varying vec3 EyeVector; -#endif - -#ifdef VERTEX_SHADER -// Vertex shader - -#ifdef APPLY_EYEDOT -uniform vec3 EyeOrigin; -uniform float FrontPlane; -#endif - -void main(void) -{ -gl_FrontColor = gl_Color; - -mat4 textureMatrix; - -textureMatrix = gl_TextureMatrix[0]; -TexCoord.st = vec2 (textureMatrix * gl_MultiTexCoord0); - -textureMatrix = gl_TextureMatrix[0]; -textureMatrix[0] = -textureMatrix[0]; -textureMatrix[1] = -textureMatrix[1]; -TexCoord.pq = vec2 (textureMatrix * gl_MultiTexCoord0); - -#ifdef APPLY_EYEDOT -mat3 strMatrix; -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -vec3 EyeVectorWorld = (EyeOrigin - gl_Vertex.xyz) * FrontPlane; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -gl_Position = ftransform(); -ProjVector = gl_Position; -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_DUDV -uniform sampler2D DuDvMapTexture; -#endif - -#ifdef APPLY_EYEDOT -uniform sampler2D NormalmapTexture; -#endif -uniform sampler2D ReflectionTexture; -uniform sampler2D RefractionTexture; -uniform float TextureWidth, TextureHeight; - -void main(void) -{ -myhalf3 color; - -#ifdef APPLY_DUDV -vec3 displacement = vec3(texture2D(DuDvMapTexture, vec2(TexCoord.pq) * vec2(0.25))); -vec2 coord = vec2(TexCoord.st) + vec2(displacement) * vec2 (0.2); - -vec3 fdist = vec3 (normalize(vec3(texture2D(DuDvMapTexture, coord)) - vec3 (0.5))) * vec3(0.005); -#else -vec3 fdist = vec3(0.0); -#endif - -// get projective texcoords -float scale = float(1.0 / float(ProjVector.w)); -float inv2NW = 1.0 / (2.0 * float (TextureWidth)); -float inv2NH = 1.0 / (2.0 * float (TextureHeight)); -vec2 projCoord = (vec2(ProjVector.xy) * scale + vec2 (1.0)) * vec2 (0.5) + vec2(fdist.xy); -projCoord.s = float (clamp (float(projCoord.s), inv2NW, 1.0 - inv2NW)); -projCoord.t = float (clamp (float(projCoord.t), inv2NH, 1.0 - inv2NH)); - - -myhalf3 refr = myhalf3(0.0); -myhalf3 refl = myhalf3(0.0); - -#ifdef APPLY_EYEDOT -// calculate dot product between the surface normal and eye vector -// great for simulating varying water translucency based on the view angle -myhalf3 surfaceNormal = normalize(myhalf3(texture2D(NormalmapTexture, coord)) - myhalf3 (0.5)); -vec3 eyeNormal = normalize(myhalf3(EyeVector)); - -float refrdot = float(dot(surfaceNormal, eyeNormal)); -//refrdot = float (clamp (refrdot, 0.0, 1.0)); -float refldot = 1.0 - refrdot; -// get refraction and reflection - -#ifdef APPLY_REFRACTION -refr = (myhalf3(texture2D(RefractionTexture, projCoord))) * refrdot; -#endif -#ifdef APPLY_REFLECTION -refl = (myhalf3(texture2D(ReflectionTexture, projCoord))) * refldot; -#endif - -#else - -#ifdef APPLY_REFRACTION -refr = (myhalf3(texture2D(RefractionTexture, projCoord))); -#endif -#ifdef APPLY_REFLECTION -refl = (myhalf3(texture2D(ReflectionTexture, projCoord))); -#endif - -#endif - -// add reflection and refraction -#ifdef APPLY_DISTORTION_ALPHA -color = myhalf3(gl_Color.rgb) + myhalf3(mix (refr, refl, float(gl_Color.a))); -#else -color = myhalf3(gl_Color.rgb) + refr + refl; -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),1.0); -#else -gl_FragColor = vec4(vec3(color),1.0); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/6.vert b/shaders/warsow/6.vert deleted file mode 100644 index 6ee1e1e..0000000 --- a/shaders/warsow/6.vert +++ /dev/null @@ -1,151 +0,0 @@ -#define VERTEX_SHADER -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec4 TexCoord; -varying vec4 ProjVector; -#ifdef APPLY_EYEDOT -varying vec3 EyeVector; -#endif - -#ifdef VERTEX_SHADER -// Vertex shader - -#ifdef APPLY_EYEDOT -uniform vec3 EyeOrigin; -uniform float FrontPlane; -#endif - -void main(void) -{ -gl_FrontColor = gl_Color; - -mat4 textureMatrix; - -textureMatrix = gl_TextureMatrix[0]; -TexCoord.st = vec2 (textureMatrix * gl_MultiTexCoord0); - -textureMatrix = gl_TextureMatrix[0]; -textureMatrix[0] = -textureMatrix[0]; -textureMatrix[1] = -textureMatrix[1]; -TexCoord.pq = vec2 (textureMatrix * gl_MultiTexCoord0); - -#ifdef APPLY_EYEDOT -mat3 strMatrix; -strMatrix[0] = gl_MultiTexCoord1.xyz; -strMatrix[2] = gl_Normal.xyz; -strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); - -vec3 EyeVectorWorld = (EyeOrigin - gl_Vertex.xyz) * FrontPlane; -EyeVector = EyeVectorWorld * strMatrix; -#endif - -gl_Position = ftransform(); -ProjVector = gl_Position; -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -#ifdef APPLY_DUDV -uniform sampler2D DuDvMapTexture; -#endif - -#ifdef APPLY_EYEDOT -uniform sampler2D NormalmapTexture; -#endif -uniform sampler2D ReflectionTexture; -uniform sampler2D RefractionTexture; -uniform float TextureWidth, TextureHeight; - -void main(void) -{ -myhalf3 color; - -#ifdef APPLY_DUDV -vec3 displacement = vec3(texture2D(DuDvMapTexture, vec2(TexCoord.pq) * vec2(0.25))); -vec2 coord = vec2(TexCoord.st) + vec2(displacement) * vec2 (0.2); - -vec3 fdist = vec3 (normalize(vec3(texture2D(DuDvMapTexture, coord)) - vec3 (0.5))) * vec3(0.005); -#else -vec3 fdist = vec3(0.0); -#endif - -// get projective texcoords -float scale = float(1.0 / float(ProjVector.w)); -float inv2NW = 1.0 / (2.0 * float (TextureWidth)); -float inv2NH = 1.0 / (2.0 * float (TextureHeight)); -vec2 projCoord = (vec2(ProjVector.xy) * scale + vec2 (1.0)) * vec2 (0.5) + vec2(fdist.xy); -projCoord.s = float (clamp (float(projCoord.s), inv2NW, 1.0 - inv2NW)); -projCoord.t = float (clamp (float(projCoord.t), inv2NH, 1.0 - inv2NH)); - - -myhalf3 refr = myhalf3(0.0); -myhalf3 refl = myhalf3(0.0); - -#ifdef APPLY_EYEDOT -// calculate dot product between the surface normal and eye vector -// great for simulating varying water translucency based on the view angle -myhalf3 surfaceNormal = normalize(myhalf3(texture2D(NormalmapTexture, coord)) - myhalf3 (0.5)); -vec3 eyeNormal = normalize(myhalf3(EyeVector)); - -float refrdot = float(dot(surfaceNormal, eyeNormal)); -//refrdot = float (clamp (refrdot, 0.0, 1.0)); -float refldot = 1.0 - refrdot; -// get refraction and reflection - -#ifdef APPLY_REFRACTION -refr = (myhalf3(texture2D(RefractionTexture, projCoord))) * refrdot; -#endif -#ifdef APPLY_REFLECTION -refl = (myhalf3(texture2D(ReflectionTexture, projCoord))) * refldot; -#endif - -#else - -#ifdef APPLY_REFRACTION -refr = (myhalf3(texture2D(RefractionTexture, projCoord))); -#endif -#ifdef APPLY_REFLECTION -refl = (myhalf3(texture2D(ReflectionTexture, projCoord))); -#endif - -#endif - -// add reflection and refraction -#ifdef APPLY_DISTORTION_ALPHA -color = myhalf3(gl_Color.rgb) + myhalf3(mix (refr, refl, float(gl_Color.a))); -#else -color = myhalf3(gl_Color.rgb) + refr + refl; -#endif - -#ifdef APPLY_GRAYSCALE -float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); -gl_FragColor = vec4(vec3(grey),1.0); -#else -gl_FragColor = vec4(vec3(color),1.0); -#endif -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/60.shader_test b/shaders/warsow/60.shader_test new file mode 100644 index 0000000..30ba541 --- /dev/null +++ b/shaders/warsow/60.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/warsow/63.shader_test b/shaders/warsow/63.shader_test new file mode 100644 index 0000000..7497b6b --- /dev/null +++ b/shaders/warsow/63.shader_test @@ -0,0 +1,22 @@ +[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/warsow/64.shader_test b/shaders/warsow/64.shader_test new file mode 100644 index 0000000..b59d973 --- /dev/null +++ b/shaders/warsow/64.shader_test @@ -0,0 +1,696 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +#define APPLY_LIGHTSTYLE0 +#define APPLY_FBLIGHTMAP +#define APPLY_AMBIENT_COMPENSATION +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + + +[vertex shader] +#define VERTEX_SHADER +#define APPLY_LIGHTSTYLE0 +#define APPLY_FBLIGHTMAP +#define APPLY_AMBIENT_COMPENSATION +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/67.shader_test b/shaders/warsow/67.shader_test new file mode 100644 index 0000000..f005219 --- /dev/null +++ b/shaders/warsow/67.shader_test @@ -0,0 +1,689 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + +[vertex shader] +#define VERTEX_SHADER +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/7.frag b/shaders/warsow/7.frag deleted file mode 100644 index d917740..0000000 --- a/shaders/warsow/7.frag +++ /dev/null @@ -1,110 +0,0 @@ -#define FRAGMENT_SHADER -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec4 ProjVector; - -#ifdef VERTEX_SHADER -// Vertex shader - -void main(void) -{ -gl_FrontColor = gl_Color; - - -mat4 textureMatrix; - -textureMatrix = gl_TextureMatrix[0]; - -gl_Position = ftransform(); -ProjVector = textureMatrix * gl_Vertex; -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -uniform myhalf3 LightAmbient; - -uniform float TextureWidth, TextureHeight; -uniform float ProjDistance; -uniform sampler2DShadow ShadowmapTexture; - -void main(void) -{ -myhalf color = myhalf(1.0); - -if (ProjVector.w <= 0.0 || ProjVector.w >= ProjDistance) -discard; - -float dtW = 1.0 / TextureWidth; -float dtH = 1.0 / TextureHeight; - -vec3 coord = vec3 (ProjVector.xyz / ProjVector.w); -coord = (coord + vec3 (1.0)) * vec3 (0.5); -coord.s = float (clamp (float(coord.s), dtW, 1.0 - dtW)); -coord.t = float (clamp (float(coord.t), dtH, 1.0 - dtH)); -coord.r = float (clamp (float(coord.r), 0.0, 1.0)); - -myhalf shadow0 = myhalf(shadow2D(ShadowmapTexture, coord).r); -myhalf shadow = shadow0; - -#if defined(APPLY_PCF2x2) || defined(APPLY_PCF3x3) - -vec3 coord2 = coord + vec3(0.0, dtH, 0.0); -myhalf shadow1 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(dtW, dtH, 0.0); -myhalf shadow2 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(dtW, 0.0, 0.0); -myhalf shadow3 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -#if defined(APPLY_PCF3x3) -coord2 = coord + vec3(-dtW, 0.0, 0.0); -myhalf shadow4 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(-dtW, -dtH, 0.0); -myhalf shadow5 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(0.0, -dtH, 0.0); -myhalf shadow6 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(dtW, -dtH, 0.0); -myhalf shadow7 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(-dtW, dtH, 0.0); -myhalf shadow8 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -shadow = (shadow0 + shadow1 + shadow2 + shadow3 + shadow4 + shadow5 + shadow6 + shadow7 + shadow8) * myhalf(0.11); -#else -shadow = (shadow0 + shadow1 + shadow2 + shadow3) * myhalf(0.25); -#endif -#else -shadow = shadow0; -#endif - -float attenuation = float (ProjVector.w) / ProjDistance; -myhalf compensation = myhalf(0.25) - max(LightAmbient.x, max(LightAmbient.y, LightAmbient.z)) -;compensation = max (compensation, 0.0); -color = shadow + attenuation + compensation; - -gl_FragColor = vec4(vec3(color),1.0); -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/7.shader_test b/shaders/warsow/7.shader_test new file mode 100644 index 0000000..6e68fc9 --- /dev/null +++ b/shaders/warsow/7.shader_test @@ -0,0 +1,695 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +#define APPLY_LIGHTSTYLE0 +#define APPLY_FBLIGHTMAP +#define APPLY_SPECULAR +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + +[vertex shader] +#define VERTEX_SHADER +#define APPLY_LIGHTSTYLE0 +#define APPLY_FBLIGHTMAP +#define APPLY_SPECULAR +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/7.vert b/shaders/warsow/7.vert deleted file mode 100644 index f5a1571..0000000 --- a/shaders/warsow/7.vert +++ /dev/null @@ -1,110 +0,0 @@ -#define VERTEX_SHADER -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -varying vec4 ProjVector; - -#ifdef VERTEX_SHADER -// Vertex shader - -void main(void) -{ -gl_FrontColor = gl_Color; - - -mat4 textureMatrix; - -textureMatrix = gl_TextureMatrix[0]; - -gl_Position = ftransform(); -ProjVector = textureMatrix * gl_Vertex; -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -uniform myhalf3 LightAmbient; - -uniform float TextureWidth, TextureHeight; -uniform float ProjDistance; -uniform sampler2DShadow ShadowmapTexture; - -void main(void) -{ -myhalf color = myhalf(1.0); - -if (ProjVector.w <= 0.0 || ProjVector.w >= ProjDistance) -discard; - -float dtW = 1.0 / TextureWidth; -float dtH = 1.0 / TextureHeight; - -vec3 coord = vec3 (ProjVector.xyz / ProjVector.w); -coord = (coord + vec3 (1.0)) * vec3 (0.5); -coord.s = float (clamp (float(coord.s), dtW, 1.0 - dtW)); -coord.t = float (clamp (float(coord.t), dtH, 1.0 - dtH)); -coord.r = float (clamp (float(coord.r), 0.0, 1.0)); - -myhalf shadow0 = myhalf(shadow2D(ShadowmapTexture, coord).r); -myhalf shadow = shadow0; - -#if defined(APPLY_PCF2x2) || defined(APPLY_PCF3x3) - -vec3 coord2 = coord + vec3(0.0, dtH, 0.0); -myhalf shadow1 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(dtW, dtH, 0.0); -myhalf shadow2 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(dtW, 0.0, 0.0); -myhalf shadow3 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -#if defined(APPLY_PCF3x3) -coord2 = coord + vec3(-dtW, 0.0, 0.0); -myhalf shadow4 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(-dtW, -dtH, 0.0); -myhalf shadow5 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(0.0, -dtH, 0.0); -myhalf shadow6 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(dtW, -dtH, 0.0); -myhalf shadow7 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -coord2 = coord + vec3(-dtW, dtH, 0.0); -myhalf shadow8 = myhalf (shadow2D (ShadowmapTexture, coord2).r); - -shadow = (shadow0 + shadow1 + shadow2 + shadow3 + shadow4 + shadow5 + shadow6 + shadow7 + shadow8) * myhalf(0.11); -#else -shadow = (shadow0 + shadow1 + shadow2 + shadow3) * myhalf(0.25); -#endif -#else -shadow = shadow0; -#endif - -float attenuation = float (ProjVector.w) / ProjDistance; -myhalf compensation = myhalf(0.25) - max(LightAmbient.x, max(LightAmbient.y, LightAmbient.z)) -;compensation = max (compensation, 0.0); -color = shadow + attenuation + compensation; - -gl_FragColor = vec4(vec3(color),1.0); -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/70.shader_test b/shaders/warsow/70.shader_test new file mode 100644 index 0000000..62d5d00 --- /dev/null +++ b/shaders/warsow/70.shader_test @@ -0,0 +1,693 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +#define APPLY_LIGHTSTYLE0 +#define APPLY_FBLIGHTMAP +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + +[vertex shader] +#define VERTEX_SHADER +#define APPLY_LIGHTSTYLE0 +#define APPLY_FBLIGHTMAP +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/73.shader_test b/shaders/warsow/73.shader_test new file mode 100644 index 0000000..6e68fc9 --- /dev/null +++ b/shaders/warsow/73.shader_test @@ -0,0 +1,695 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +#define APPLY_LIGHTSTYLE0 +#define APPLY_FBLIGHTMAP +#define APPLY_SPECULAR +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + +[vertex shader] +#define VERTEX_SHADER +#define APPLY_LIGHTSTYLE0 +#define APPLY_FBLIGHTMAP +#define APPLY_SPECULAR +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/76.shader_test b/shaders/warsow/76.shader_test new file mode 100644 index 0000000..de4bd35 --- /dev/null +++ b/shaders/warsow/76.shader_test @@ -0,0 +1,697 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +#define APPLY_LIGHTSTYLE0 +#define APPLY_FBLIGHTMAP +#define APPLY_SPECULAR +#define APPLY_AMBIENT_COMPENSATION +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + +[vertex shader] +#define VERTEX_SHADER +#define APPLY_LIGHTSTYLE0 +#define APPLY_FBLIGHTMAP +#define APPLY_SPECULAR +#define APPLY_AMBIENT_COMPENSATION +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/79.shader_test b/shaders/warsow/79.shader_test new file mode 100644 index 0000000..4a2358e --- /dev/null +++ b/shaders/warsow/79.shader_test @@ -0,0 +1,693 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +#define APPLY_DIRECTIONAL_LIGHT +#define APPLY_CELLSHADING +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + +[vertex shader] +#define VERTEX_SHADER +#define APPLY_DIRECTIONAL_LIGHT +#define APPLY_CELLSHADING +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec2 TexCoord; +#ifdef APPLY_LIGHTSTYLE0 +varying vec4 LightmapTexCoord01; +#ifdef APPLY_LIGHTSTYLE2 +varying vec4 LightmapTexCoord23; +#endif +#endif + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +varying vec3 EyeVector; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +varying vec3 LightVector; +#endif + +varying mat3 strMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform vec3 EyeOrigin; + +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform vec3 LightDir; +#endif + +void main() +{ +gl_FrontColor = gl_Color; + +TexCoord = vec2 (gl_TextureMatrix[0] * gl_MultiTexCoord0); + +#ifdef APPLY_LIGHTSTYLE0 +LightmapTexCoord01.st = gl_MultiTexCoord4.st; +#ifdef APPLY_LIGHTSTYLE1 +LightmapTexCoord01.pq = gl_MultiTexCoord5.st; +#ifdef APPLY_LIGHTSTYLE2 +LightmapTexCoord23.st = gl_MultiTexCoord6.st; +#ifdef APPLY_LIGHTSTYLE3 +LightmapTexCoord23.pq = gl_MultiTexCoord7.st; +#endif +#endif +#endif +#endif + +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +#if defined(APPLY_SPECULAR) || defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +vec3 EyeVectorWorld = EyeOrigin - gl_Vertex.xyz; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +#ifdef APPLY_DIRECTIONAL_LIGHT +LightVector = LightDir * strMatrix; +#endif + +gl_Position = ftransform (); +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_LIGHTSTYLE0 +uniform sampler2D LightmapTexture0; +uniform float DeluxemapOffset0; // s-offset for LightmapTexCoord +uniform myhalf3 lsColor0; // lightstyle color + +#ifdef APPLY_LIGHTSTYLE1 +uniform sampler2D LightmapTexture1; +uniform float DeluxemapOffset1; +uniform myhalf3 lsColor1; + +#ifdef APPLY_LIGHTSTYLE2 +uniform sampler2D LightmapTexture2; +uniform float DeluxemapOffset2; +uniform myhalf3 lsColor2; + +#ifdef APPLY_LIGHTSTYLE3 +uniform sampler2D LightmapTexture3; +uniform float DeluxemapOffset3; +uniform myhalf3 lsColor3; + +#endif +#endif +#endif +#endif + +uniform sampler2D BaseTexture; +uniform sampler2D NormalmapTexture; +uniform sampler2D GlossTexture; +#ifdef APPLY_DECAL +uniform sampler2D DecalTexture; +#endif + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +uniform float OffsetMappingScale; +#endif + +uniform myhalf3 LightAmbient; +#ifdef APPLY_DIRECTIONAL_LIGHT +uniform myhalf3 LightDiffuse; +#endif + +uniform myhalf GlossIntensity; // gloss scaling factor +uniform myhalf GlossExponent; // gloss exponent factor + +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// The following reliefmapping and offsetmapping routine was taken from DarkPlaces +// The credit goes to LordHavoc (as always) +vec2 OffsetMapping(vec2 TexCoord) +{ +#ifdef APPLY_RELIEFMAPPING +// 14 sample relief mapping: linear search and then binary search +// this basically steps forward a small amount repeatedly until it finds +// itself inside solid, then jitters forward and back using decreasing +// amounts to find the impact +//vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1), -1); +//vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1), -1); +vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1), -1); +vec3 RT = vec3(TexCoord, 1); +OffsetVector *= 0.1; +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * step(texture2D(NormalmapTexture, RT.xy).a, RT.z); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) - 0.5); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.5 - 0.25); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.25 - 0.125); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.125 - 0.0625); +RT += OffsetVector * (step(texture2D(NormalmapTexture, RT.xy).a, RT.z) * 0.0625 - 0.03125); +return RT.xy; +#else +// 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits) +// this basically moves forward the full distance, and then backs up based +// on height of samples +//vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMappingScale) * vec2(-1, 1)); +//vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMappingScale * vec2(-1, 1)); +vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMappingScale * vec2(-1, 1)); +TexCoord += OffsetVector; +OffsetVector *= 0.5; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +TexCoord -= OffsetVector * texture2D(NormalmapTexture, TexCoord).a; +return TexCoord; +#endif +} +#endif + +void main() +{ +#if defined(APPLY_OFFSETMAPPING) || defined(APPLY_RELIEFMAPPING) +// apply offsetmapping +vec2 TexCoordOffset = OffsetMapping(TexCoord); +#define TexCoord TexCoordOffset +#endif +myhalf3 surfaceNormal; +myhalf3 diffuseNormalModelspace; +myhalf3 diffuseNormal = myhalf3 (0.0, 0.0, -1.0); +float diffuseProduct; +#ifdef APPLY_CELLSHADING +int lightcell; +float diffuseProductPositive; +float diffuseProductNegative; +float hardShadow; +#endif + +myhalf3 weightedDiffuseNormal; +myhalf3 specularNormal; +float specularProduct; + +#if !defined(APPLY_DIRECTIONAL_LIGHT) && !defined(APPLY_LIGHTSTYLE0) +myhalf4 color = myhalf4 (1.0, 1.0, 1.0, 1.0); +#else +myhalf4 color = myhalf4 (0.0, 0.0, 0.0, 1.0); +#endif + +// get the surface normal +surfaceNormal = normalize (myhalf3 (texture2D (NormalmapTexture, TexCoord)) - myhalf3 (0.5)); + +#ifdef APPLY_DIRECTIONAL_LIGHT +diffuseNormal = myhalf3 (LightVector); +weightedDiffuseNormal = diffuseNormal; +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +#ifdef APPLY_CELLSHADING +hardShadow = 0.0; +diffuseProductPositive = max (diffuseProduct, 0.0); +diffuseProductNegative = (-min (diffuseProduct, 0.0) - 0.3); + +// smooth the hard shadow edge +lightcell = int(max(diffuseProduct + 0.1, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(max(diffuseProduct + 0.055, 0.0) * 2.0); +hardShadow += float(lightcell); + +lightcell = int(diffuseProductPositive * 2.0); +hardShadow += float(lightcell); + +color.rgb += myhalf(0.6 + hardShadow * 0.3333333333 * 0.27 + diffuseProductPositive * 0.14); + +// backlight +lightcell = int (diffuseProductNegative * 2.0); +color.rgb += myhalf (float(lightcell) * 0.085 + diffuseProductNegative * 0.085); +#else +color.rgb += LightDiffuse.rgb * myhalf(max (diffuseProduct, 0.0)) + LightAmbient.rgb; +#endif + +#endif + +// deluxemapping using light vectors in modelspace + +#ifdef APPLY_LIGHTSTYLE0 + +// get light normal +diffuseNormalModelspace = myhalf3 (texture2D(LightmapTexture0, vec2(LightmapTexCoord01.s+DeluxemapOffset0,LightmapTexCoord01.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +// calculate directional shading +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); + +#ifdef APPLY_FBLIGHTMAP +weightedDiffuseNormal = diffuseNormal; +// apply lightmap color +color.rgb += myhalf3 (max (diffuseProduct, 0.0) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st))); +#else + +#define NORMALIZE_DIFFUSE_NORMAL + +weightedDiffuseNormal = lsColor0 * diffuseNormal; +// apply lightmap color +color.rgb += lsColor0 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture0, LightmapTexCoord01.st)); +#endif + +#ifdef APPLY_AMBIENT_COMPENSATION +// compensate for ambient lighting +color.rgb += myhalf((1.0 - max (diffuseProduct, 0.0))) * LightAmbient; +#endif + +#ifdef APPLY_LIGHTSTYLE1 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture1, vec2(LightmapTexCoord01.p+DeluxemapOffset1,LightmapTexCoord01.q))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor1 * diffuseNormal; +color.rgb += lsColor1 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture1, LightmapTexCoord01.pq)); + +#ifdef APPLY_LIGHTSTYLE2 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture2, vec2(LightmapTexCoord23.s+DeluxemapOffset2,LightmapTexCoord23.t))) - myhalf3 (0.5); +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor2 * diffuseNormal; +color.rgb += lsColor2 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture2, LightmapTexCoord23.st)); + +#ifdef APPLY_LIGHTSTYLE3 +diffuseNormalModelspace = myhalf3 (texture2D (LightmapTexture3, vec2(LightmapTexCoord23.p+DeluxemapOffset3,LightmapTexCoord23.q))) - myhalf3 (0.5);; +diffuseNormal = normalize (myhalf3(dot(diffuseNormalModelspace,myhalf3(strMatrix[0])),dot(diffuseNormalModelspace,myhalf3(strMatrix[1])),dot(diffuseNormalModelspace,myhalf3(strMatrix[2])))); +diffuseProduct = float (dot (surfaceNormal, diffuseNormal)); +weightedDiffuseNormal += lsColor3 * diffuseNormal; +color.rgb += lsColor3 * myhalf(max (diffuseProduct, 0.0)) * myhalf3 (texture2D (LightmapTexture3, LightmapTexCoord23.pq)); + +#endif +#endif +#endif +#endif + +#ifdef APPLY_SPECULAR + +#ifdef NORMALIZE_DIFFUSE_NORMAL +specularNormal = normalize (myhalf3 (normalize (weightedDiffuseNormal)) + myhalf3 (normalize (EyeVector))); +#else +specularNormal = normalize (weightedDiffuseNormal + myhalf3 (normalize (EyeVector))); +#endif + +specularProduct = float (dot (surfaceNormal, specularNormal)); +color.rgb += (myhalf3(texture2D(GlossTexture, TexCoord)) * GlossIntensity) * pow(myhalf(max(specularProduct, 0.0)), GlossExponent); +#endif + +#ifdef APPLY_BASETEX_ALPHA_ONLY +color = min(color, myhalf4(texture2D(BaseTexture, TexCoord).a)); +#else +#ifdef APPLY_COLOR_CLAMPING +color = min(color, myhalf4(1.0)); +#endif +color = color * myhalf4(texture2D(BaseTexture, TexCoord)); +#endif + +#ifdef APPLY_DECAL +#ifdef APPLY_DECAL_ADD +myhalf3 decal = myhalf3(gl_Color.rgb) * myhalf3(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb + color.rgb; +color.a = color.a * myhalf(gl_Color.a); +#else +myhalf4 decal = myhalf4(gl_Color.rgba); +if (decal.a > 0.0) +{ +decal = decal * myhalf4(texture2D(DecalTexture, TexCoord)); +color.rgb = decal.rgb * decal.a + color.rgb * (1.0-decal.a); +} +#endif +#else +color = color * myhalf4(gl_Color.rgba); +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),color.a); +#else +gl_FragColor = vec4(color); +#endif +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/8.frag b/shaders/warsow/8.frag deleted file mode 100644 index 0e60fc6..0000000 --- a/shaders/warsow/8.frag +++ /dev/null @@ -1,49 +0,0 @@ -#define FRAGMENT_SHADER -// Warsow GLSL shader - - -varying vec4 ProjVector; - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform float OutlineHeight; - -void main(void) -{ -gl_FrontColor = gl_Color; - -vec4 n = vec4(gl_Normal.xyz, 0.0); -vec4 v = vec4(gl_Vertex) + n * OutlineHeight; - -gl_Position = gl_ModelViewProjectionMatrix * v; -ProjVector = gl_Position; -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * v; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -uniform float OutlineCutOff; - -void main(void) -{ - -#ifdef APPLY_OUTLINES_CUTOFF -if (OutlineCutOff > 0.0 && (ProjVector.w > OutlineCutOff)) -discard; -#endif - -gl_FragColor = vec4 (gl_Color); -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/8.vert b/shaders/warsow/8.vert deleted file mode 100644 index 368238c..0000000 --- a/shaders/warsow/8.vert +++ /dev/null @@ -1,49 +0,0 @@ -#define VERTEX_SHADER -// Warsow GLSL shader - - -varying vec4 ProjVector; - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform float OutlineHeight; - -void main(void) -{ -gl_FrontColor = gl_Color; - -vec4 n = vec4(gl_Normal.xyz, 0.0); -vec4 v = vec4(gl_Vertex) + n * OutlineHeight; - -gl_Position = gl_ModelViewProjectionMatrix * v; -ProjVector = gl_Position; -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * v; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -uniform float OutlineCutOff; - -void main(void) -{ - -#ifdef APPLY_OUTLINES_CUTOFF -if (OutlineCutOff > 0.0 && (ProjVector.w > OutlineCutOff)) -discard; -#endif - -gl_FragColor = vec4 (gl_Color); -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/82.shader_test b/shaders/warsow/82.shader_test new file mode 100644 index 0000000..76c961a --- /dev/null +++ b/shaders/warsow/82.shader_test @@ -0,0 +1,307 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec4 TexCoord; +varying vec4 ProjVector; +#ifdef APPLY_EYEDOT +varying vec3 EyeVector; +#endif + +#ifdef VERTEX_SHADER +// Vertex shader + +#ifdef APPLY_EYEDOT +uniform vec3 EyeOrigin; +uniform float FrontPlane; +#endif + +void main(void) +{ +gl_FrontColor = gl_Color; + +mat4 textureMatrix; + +textureMatrix = gl_TextureMatrix[0]; +TexCoord.st = vec2 (textureMatrix * gl_MultiTexCoord0); + +textureMatrix = gl_TextureMatrix[0]; +textureMatrix[0] = -textureMatrix[0]; +textureMatrix[1] = -textureMatrix[1]; +TexCoord.pq = vec2 (textureMatrix * gl_MultiTexCoord0); + +#ifdef APPLY_EYEDOT +mat3 strMatrix; +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +vec3 EyeVectorWorld = (EyeOrigin - gl_Vertex.xyz) * FrontPlane; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +gl_Position = ftransform(); +ProjVector = gl_Position; +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_DUDV +uniform sampler2D DuDvMapTexture; +#endif + +#ifdef APPLY_EYEDOT +uniform sampler2D NormalmapTexture; +#endif +uniform sampler2D ReflectionTexture; +uniform sampler2D RefractionTexture; +uniform float TextureWidth, TextureHeight; + +void main(void) +{ +myhalf3 color; + +#ifdef APPLY_DUDV +vec3 displacement = vec3(texture2D(DuDvMapTexture, vec2(TexCoord.pq) * vec2(0.25))); +vec2 coord = vec2(TexCoord.st) + vec2(displacement) * vec2 (0.2); + +vec3 fdist = vec3 (normalize(vec3(texture2D(DuDvMapTexture, coord)) - vec3 (0.5))) * vec3(0.005); +#else +vec3 fdist = vec3(0.0); +#endif + +// get projective texcoords +float scale = float(1.0 / float(ProjVector.w)); +float inv2NW = 1.0 / (2.0 * float (TextureWidth)); +float inv2NH = 1.0 / (2.0 * float (TextureHeight)); +vec2 projCoord = (vec2(ProjVector.xy) * scale + vec2 (1.0)) * vec2 (0.5) + vec2(fdist.xy); +projCoord.s = float (clamp (float(projCoord.s), inv2NW, 1.0 - inv2NW)); +projCoord.t = float (clamp (float(projCoord.t), inv2NH, 1.0 - inv2NH)); + + +myhalf3 refr = myhalf3(0.0); +myhalf3 refl = myhalf3(0.0); + +#ifdef APPLY_EYEDOT +// calculate dot product between the surface normal and eye vector +// great for simulating varying water translucency based on the view angle +myhalf3 surfaceNormal = normalize(myhalf3(texture2D(NormalmapTexture, coord)) - myhalf3 (0.5)); +vec3 eyeNormal = normalize(myhalf3(EyeVector)); + +float refrdot = float(dot(surfaceNormal, eyeNormal)); +//refrdot = float (clamp (refrdot, 0.0, 1.0)); +float refldot = 1.0 - refrdot; +// get refraction and reflection + +#ifdef APPLY_REFRACTION +refr = (myhalf3(texture2D(RefractionTexture, projCoord))) * refrdot; +#endif +#ifdef APPLY_REFLECTION +refl = (myhalf3(texture2D(ReflectionTexture, projCoord))) * refldot; +#endif + +#else + +#ifdef APPLY_REFRACTION +refr = (myhalf3(texture2D(RefractionTexture, projCoord))); +#endif +#ifdef APPLY_REFLECTION +refl = (myhalf3(texture2D(ReflectionTexture, projCoord))); +#endif + +#endif + +// add reflection and refraction +#ifdef APPLY_DISTORTION_ALPHA +color = myhalf3(gl_Color.rgb) + myhalf3(mix (refr, refl, float(gl_Color.a))); +#else +color = myhalf3(gl_Color.rgb) + refr + refl; +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),1.0); +#else +gl_FragColor = vec4(vec3(color),1.0); +#endif +} + +#endif // FRAGMENT_SHADER + + +[vertex shader] +#define VERTEX_SHADER +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec4 TexCoord; +varying vec4 ProjVector; +#ifdef APPLY_EYEDOT +varying vec3 EyeVector; +#endif + +#ifdef VERTEX_SHADER +// Vertex shader + +#ifdef APPLY_EYEDOT +uniform vec3 EyeOrigin; +uniform float FrontPlane; +#endif + +void main(void) +{ +gl_FrontColor = gl_Color; + +mat4 textureMatrix; + +textureMatrix = gl_TextureMatrix[0]; +TexCoord.st = vec2 (textureMatrix * gl_MultiTexCoord0); + +textureMatrix = gl_TextureMatrix[0]; +textureMatrix[0] = -textureMatrix[0]; +textureMatrix[1] = -textureMatrix[1]; +TexCoord.pq = vec2 (textureMatrix * gl_MultiTexCoord0); + +#ifdef APPLY_EYEDOT +mat3 strMatrix; +strMatrix[0] = gl_MultiTexCoord1.xyz; +strMatrix[2] = gl_Normal.xyz; +strMatrix[1] = gl_MultiTexCoord1.w * cross (strMatrix[2], strMatrix[0]); + +vec3 EyeVectorWorld = (EyeOrigin - gl_Vertex.xyz) * FrontPlane; +EyeVector = EyeVectorWorld * strMatrix; +#endif + +gl_Position = ftransform(); +ProjVector = gl_Position; +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +#ifdef APPLY_DUDV +uniform sampler2D DuDvMapTexture; +#endif + +#ifdef APPLY_EYEDOT +uniform sampler2D NormalmapTexture; +#endif +uniform sampler2D ReflectionTexture; +uniform sampler2D RefractionTexture; +uniform float TextureWidth, TextureHeight; + +void main(void) +{ +myhalf3 color; + +#ifdef APPLY_DUDV +vec3 displacement = vec3(texture2D(DuDvMapTexture, vec2(TexCoord.pq) * vec2(0.25))); +vec2 coord = vec2(TexCoord.st) + vec2(displacement) * vec2 (0.2); + +vec3 fdist = vec3 (normalize(vec3(texture2D(DuDvMapTexture, coord)) - vec3 (0.5))) * vec3(0.005); +#else +vec3 fdist = vec3(0.0); +#endif + +// get projective texcoords +float scale = float(1.0 / float(ProjVector.w)); +float inv2NW = 1.0 / (2.0 * float (TextureWidth)); +float inv2NH = 1.0 / (2.0 * float (TextureHeight)); +vec2 projCoord = (vec2(ProjVector.xy) * scale + vec2 (1.0)) * vec2 (0.5) + vec2(fdist.xy); +projCoord.s = float (clamp (float(projCoord.s), inv2NW, 1.0 - inv2NW)); +projCoord.t = float (clamp (float(projCoord.t), inv2NH, 1.0 - inv2NH)); + + +myhalf3 refr = myhalf3(0.0); +myhalf3 refl = myhalf3(0.0); + +#ifdef APPLY_EYEDOT +// calculate dot product between the surface normal and eye vector +// great for simulating varying water translucency based on the view angle +myhalf3 surfaceNormal = normalize(myhalf3(texture2D(NormalmapTexture, coord)) - myhalf3 (0.5)); +vec3 eyeNormal = normalize(myhalf3(EyeVector)); + +float refrdot = float(dot(surfaceNormal, eyeNormal)); +//refrdot = float (clamp (refrdot, 0.0, 1.0)); +float refldot = 1.0 - refrdot; +// get refraction and reflection + +#ifdef APPLY_REFRACTION +refr = (myhalf3(texture2D(RefractionTexture, projCoord))) * refrdot; +#endif +#ifdef APPLY_REFLECTION +refl = (myhalf3(texture2D(ReflectionTexture, projCoord))) * refldot; +#endif + +#else + +#ifdef APPLY_REFRACTION +refr = (myhalf3(texture2D(RefractionTexture, projCoord))); +#endif +#ifdef APPLY_REFLECTION +refl = (myhalf3(texture2D(ReflectionTexture, projCoord))); +#endif + +#endif + +// add reflection and refraction +#ifdef APPLY_DISTORTION_ALPHA +color = myhalf3(gl_Color.rgb) + myhalf3(mix (refr, refl, float(gl_Color.a))); +#else +color = myhalf3(gl_Color.rgb) + refr + refl; +#endif + +#ifdef APPLY_GRAYSCALE +float grey = dot(color, myhalf3(0.299, 0.587, 0.114)); +gl_FragColor = vec4(vec3(grey),1.0); +#else +gl_FragColor = vec4(vec3(color),1.0); +#endif +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/85.shader_test b/shaders/warsow/85.shader_test new file mode 100644 index 0000000..9b644bc --- /dev/null +++ b/shaders/warsow/85.shader_test @@ -0,0 +1,225 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec4 ProjVector; + +#ifdef VERTEX_SHADER +// Vertex shader + +void main(void) +{ +gl_FrontColor = gl_Color; + + +mat4 textureMatrix; + +textureMatrix = gl_TextureMatrix[0]; + +gl_Position = ftransform(); +ProjVector = textureMatrix * gl_Vertex; +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +uniform myhalf3 LightAmbient; + +uniform float TextureWidth, TextureHeight; +uniform float ProjDistance; +uniform sampler2DShadow ShadowmapTexture; + +void main(void) +{ +myhalf color = myhalf(1.0); + +if (ProjVector.w <= 0.0 || ProjVector.w >= ProjDistance) +discard; + +float dtW = 1.0 / TextureWidth; +float dtH = 1.0 / TextureHeight; + +vec3 coord = vec3 (ProjVector.xyz / ProjVector.w); +coord = (coord + vec3 (1.0)) * vec3 (0.5); +coord.s = float (clamp (float(coord.s), dtW, 1.0 - dtW)); +coord.t = float (clamp (float(coord.t), dtH, 1.0 - dtH)); +coord.r = float (clamp (float(coord.r), 0.0, 1.0)); + +myhalf shadow0 = myhalf(shadow2D(ShadowmapTexture, coord).r); +myhalf shadow = shadow0; + +#if defined(APPLY_PCF2x2) || defined(APPLY_PCF3x3) + +vec3 coord2 = coord + vec3(0.0, dtH, 0.0); +myhalf shadow1 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(dtW, dtH, 0.0); +myhalf shadow2 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(dtW, 0.0, 0.0); +myhalf shadow3 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +#if defined(APPLY_PCF3x3) +coord2 = coord + vec3(-dtW, 0.0, 0.0); +myhalf shadow4 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(-dtW, -dtH, 0.0); +myhalf shadow5 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(0.0, -dtH, 0.0); +myhalf shadow6 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(dtW, -dtH, 0.0); +myhalf shadow7 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(-dtW, dtH, 0.0); +myhalf shadow8 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +shadow = (shadow0 + shadow1 + shadow2 + shadow3 + shadow4 + shadow5 + shadow6 + shadow7 + shadow8) * myhalf(0.11); +#else +shadow = (shadow0 + shadow1 + shadow2 + shadow3) * myhalf(0.25); +#endif +#else +shadow = shadow0; +#endif + +float attenuation = float (ProjVector.w) / ProjDistance; +myhalf compensation = myhalf(0.25) - max(LightAmbient.x, max(LightAmbient.y, LightAmbient.z)) +;compensation = max (compensation, 0.0); +color = shadow + attenuation + compensation; + +gl_FragColor = vec4(vec3(color),1.0); +} + +#endif // FRAGMENT_SHADER + + +[vertex shader] +#define VERTEX_SHADER +// Warsow GLSL shader + +#if !defined(__GLSL_CG_DATA_TYPES) +#define myhalf float +#define myhalf2 vec2 +#define myhalf3 vec3 +#define myhalf4 vec4 +#else +#define myhalf half +#define myhalf2 half2 +#define myhalf3 half3 +#define myhalf4 half4 +#endif + +varying vec4 ProjVector; + +#ifdef VERTEX_SHADER +// Vertex shader + +void main(void) +{ +gl_FrontColor = gl_Color; + + +mat4 textureMatrix; + +textureMatrix = gl_TextureMatrix[0]; + +gl_Position = ftransform(); +ProjVector = textureMatrix * gl_Vertex; +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +uniform myhalf3 LightAmbient; + +uniform float TextureWidth, TextureHeight; +uniform float ProjDistance; +uniform sampler2DShadow ShadowmapTexture; + +void main(void) +{ +myhalf color = myhalf(1.0); + +if (ProjVector.w <= 0.0 || ProjVector.w >= ProjDistance) +discard; + +float dtW = 1.0 / TextureWidth; +float dtH = 1.0 / TextureHeight; + +vec3 coord = vec3 (ProjVector.xyz / ProjVector.w); +coord = (coord + vec3 (1.0)) * vec3 (0.5); +coord.s = float (clamp (float(coord.s), dtW, 1.0 - dtW)); +coord.t = float (clamp (float(coord.t), dtH, 1.0 - dtH)); +coord.r = float (clamp (float(coord.r), 0.0, 1.0)); + +myhalf shadow0 = myhalf(shadow2D(ShadowmapTexture, coord).r); +myhalf shadow = shadow0; + +#if defined(APPLY_PCF2x2) || defined(APPLY_PCF3x3) + +vec3 coord2 = coord + vec3(0.0, dtH, 0.0); +myhalf shadow1 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(dtW, dtH, 0.0); +myhalf shadow2 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(dtW, 0.0, 0.0); +myhalf shadow3 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +#if defined(APPLY_PCF3x3) +coord2 = coord + vec3(-dtW, 0.0, 0.0); +myhalf shadow4 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(-dtW, -dtH, 0.0); +myhalf shadow5 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(0.0, -dtH, 0.0); +myhalf shadow6 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(dtW, -dtH, 0.0); +myhalf shadow7 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +coord2 = coord + vec3(-dtW, dtH, 0.0); +myhalf shadow8 = myhalf (shadow2D (ShadowmapTexture, coord2).r); + +shadow = (shadow0 + shadow1 + shadow2 + shadow3 + shadow4 + shadow5 + shadow6 + shadow7 + shadow8) * myhalf(0.11); +#else +shadow = (shadow0 + shadow1 + shadow2 + shadow3) * myhalf(0.25); +#endif +#else +shadow = shadow0; +#endif + +float attenuation = float (ProjVector.w) / ProjDistance; +myhalf compensation = myhalf(0.25) - max(LightAmbient.x, max(LightAmbient.y, LightAmbient.z)) +;compensation = max (compensation, 0.0); +color = shadow + attenuation + compensation; + +gl_FragColor = vec4(vec3(color),1.0); +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/88.shader_test b/shaders/warsow/88.shader_test new file mode 100644 index 0000000..b4f6f7c --- /dev/null +++ b/shaders/warsow/88.shader_test @@ -0,0 +1,103 @@ +[require] +GLSL >= 1.10 + +[fragment shader] +#define FRAGMENT_SHADER +// Warsow GLSL shader + + +varying vec4 ProjVector; + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform float OutlineHeight; + +void main(void) +{ +gl_FrontColor = gl_Color; + +vec4 n = vec4(gl_Normal.xyz, 0.0); +vec4 v = vec4(gl_Vertex) + n * OutlineHeight; + +gl_Position = gl_ModelViewProjectionMatrix * v; +ProjVector = gl_Position; +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * v; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +uniform float OutlineCutOff; + +void main(void) +{ + +#ifdef APPLY_OUTLINES_CUTOFF +if (OutlineCutOff > 0.0 && (ProjVector.w > OutlineCutOff)) +discard; +#endif + +gl_FragColor = vec4 (gl_Color); +} + +#endif // FRAGMENT_SHADER + + +[vertex shader] +#define VERTEX_SHADER +// Warsow GLSL shader + + +varying vec4 ProjVector; + +#ifdef VERTEX_SHADER +// Vertex shader + +uniform float OutlineHeight; + +void main(void) +{ +gl_FrontColor = gl_Color; + +vec4 n = vec4(gl_Normal.xyz, 0.0); +vec4 v = vec4(gl_Vertex) + n * OutlineHeight; + +gl_Position = gl_ModelViewProjectionMatrix * v; +ProjVector = gl_Position; +#ifdef APPLY_CLIPPING +#ifdef __GLSL_CG_DATA_TYPES +gl_ClipVertex = gl_ModelViewMatrix * v; +#endif +#endif +} + +#endif // VERTEX_SHADER + + +#ifdef FRAGMENT_SHADER +// Fragment shader + +uniform float OutlineCutOff; + +void main(void) +{ + +#ifdef APPLY_OUTLINES_CUTOFF +if (OutlineCutOff > 0.0 && (ProjVector.w > OutlineCutOff)) +discard; +#endif + +gl_FragColor = vec4 (gl_Color); +} + +#endif // FRAGMENT_SHADER + + diff --git a/shaders/warsow/9.frag b/shaders/warsow/9.frag deleted file mode 100644 index f9d9ae2..0000000 --- a/shaders/warsow/9.frag +++ /dev/null @@ -1,63 +0,0 @@ -#define FRAGMENT_SHADER -// Warsow GLSL shader - -#if !defined(__GLSL_CG_DATA_TYPES) -#define myhalf float -#define myhalf2 vec2 -#define myhalf3 vec3 -#define myhalf4 vec4 -#else -#define myhalf half -#define myhalf2 half2 -#define myhalf3 half3 -#define myhalf4 half4 -#endif - -#define M_TWOPI 6.28318530717958647692 - -varying vec2 TexCoord; - -#ifdef VERTEX_SHADER -// Vertex shader - -uniform float TurbAmplitude, TurbPhase; - -void main(void) -{ -gl_FrontColor = gl_Color; - -vec4 turb; -turb = vec4(gl_MultiTexCoord0); -turb.s += TurbAmplitude * sin( ((gl_MultiTexCoord0.t / 4.0 + TurbPhase)) * M_TWOPI ); -turb.t += TurbAmplitude * sin( ((gl_MultiTexCoord0.s / 4.0 + TurbPhase)) * M_TWOPI ); -TexCoord = vec2(gl_TextureMatrix[0] * turb); - -gl_Position = ftransform(); -#ifdef APPLY_CLIPPING -#ifdef __GLSL_CG_DATA_TYPES -gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; -#endif -#endif -} - -#endif // VERTEX_SHADER - - -#ifdef FRAGMENT_SHADER -// Fragment shader - -uniform sampler2D BaseTexture; - -void main(void) -{ - -myhalf4 color; - -color = myhalf4(gl_Color) * myhalf4(texture2D(BaseTexture, TexCoord)); - -gl_FragColor = vec4(color); -} - -#endif // FRAGMENT_SHADER - - diff --git a/shaders/warsow/9.vert b/shaders/warsow/91.shader_test index 27e76e5..e32eb19 100644 --- a/shaders/warsow/9.vert +++ b/shaders/warsow/91.shader_test @@ -1,3 +1,7 @@ +[require] +GLSL >= 1.10 + +[vertex shader] #define VERTEX_SHADER // Warsow GLSL shader @@ -51,13 +55,3 @@ uniform sampler2D BaseTexture; void main(void) { -myhalf4 color; - -color = myhalf4(gl_Color) * myhalf4(texture2D(BaseTexture, TexCoord)); - -gl_FragColor = vec4(color); -} - -#endif // FRAGMENT_SHADER - - |