From: havoc Date: Fri, 23 Sep 2005 06:04:17 +0000 (+0000) Subject: make glsl work on ATI's newer drivers (which don't like #define on keywords) X-Git-Tag: xonotic-v0.1.0preview~4555 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=8cc17cdcecde0702ac21c2bc4a55b84de8fa9b98;p=xonotic%2Fdarkplaces.git make glsl work on ATI's newer drivers (which don't like #define on keywords) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5726 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/r_shadow.c b/r_shadow.c index 392d1f49..1946a32a 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -329,28 +329,33 @@ const char *builtinshader_light_frag = "// written by Forest 'LordHavoc' Hale\n" "\n" "// use half floats if available for math performance\n" -"#ifndef GEFORCEFX\n" -"#define half float\n" -"#define hvec2 vec2\n" -"#define hvec3 vec3\n" -"#define hvec4 vec4\n" +"#ifdef GEFORCEFX\n" +"#define myhalf half\n" +"#define myhvec2 hvec2\n" +"#define myhvec3 hvec3\n" +"#define myhvec4 hvec4\n" +"#else\n" +"#define myhalf float\n" +"#define myhvec2 vec2\n" +"#define myhvec3 vec3\n" +"#define myhvec4 vec4\n" "#endif\n" "\n" -"uniform hvec3 LightColor;\n" +"uniform myhvec3 LightColor;\n" "#ifdef USEOFFSETMAPPING\n" -"uniform half OffsetMapping_Scale;\n" -"uniform half OffsetMapping_Bias;\n" +"uniform myhalf OffsetMapping_Scale;\n" +"uniform myhalf OffsetMapping_Bias;\n" "#endif\n" "#ifdef USESPECULAR\n" -"uniform half SpecularPower;\n" +"uniform myhalf SpecularPower;\n" "#endif\n" "#ifdef USEFOG\n" -"uniform half FogRangeRecip;\n" +"uniform myhalf FogRangeRecip;\n" "#endif\n" -"uniform half AmbientScale;\n" -"uniform half DiffuseScale;\n" +"uniform myhalf AmbientScale;\n" +"uniform myhalf DiffuseScale;\n" "#ifdef USESPECULAR\n" -"uniform half SpecularScale;\n" +"uniform myhalf SpecularScale;\n" "#endif\n" "\n" "uniform sampler2D Texture_Normal;\n" @@ -382,17 +387,17 @@ const char *builtinshader_light_frag = " //\n" " // pow(1-(x*x+y*y+z*z), 4) is far more realistic but needs large lights to\n" " // provide significant illumination, large = slow = pain.\n" -" half colorscale = max(1.0 - dot(CubeVector, CubeVector), 0.0);\n" +" myhalf colorscale = max(1.0 - dot(CubeVector, CubeVector), 0.0);\n" "\n" "#ifdef USEFOG\n" " // apply fog\n" -" colorscale *= texture2D(Texture_FogMask, hvec2(length(EyeVector)*FogRangeRecip, 0)).x;\n" +" colorscale *= texture2D(Texture_FogMask, myhvec2(length(EyeVector)*FogRangeRecip, 0)).x;\n" "#endif\n" "\n" "#ifdef USEOFFSETMAPPING\n" " // this is 3 sample because of ATI Radeon 9500-9800/X300 limits\n" -" hvec2 OffsetVector = normalize(EyeVector).xy * vec2(-0.333, 0.333);\n" -" hvec2 TexCoordOffset = TexCoord + OffsetVector * (OffsetMapping_Bias + OffsetMapping_Scale * texture2D(Texture_Normal, TexCoord).w);\n" +" myhvec2 OffsetVector = normalize(EyeVector).xy * vec2(-0.333, 0.333);\n" +" myhvec2 TexCoordOffset = TexCoord + OffsetVector * (OffsetMapping_Bias + OffsetMapping_Scale * texture2D(Texture_Normal, TexCoord).w);\n" " TexCoordOffset += OffsetVector * (OffsetMapping_Bias + OffsetMapping_Scale * texture2D(Texture_Normal, TexCoordOffset).w);\n" " TexCoordOffset += OffsetVector * (OffsetMapping_Bias + OffsetMapping_Scale * texture2D(Texture_Normal, TexCoordOffset).w);\n" "#define TexCoord TexCoordOffset\n" @@ -400,26 +405,26 @@ const char *builtinshader_light_frag = "\n" " // get the surface normal\n" "#ifdef SURFACENORMALIZE\n" -" hvec3 surfacenormal = normalize(hvec3(texture2D(Texture_Normal, TexCoord)) - 0.5);\n" +" myhvec3 surfacenormal = normalize(myhvec3(texture2D(Texture_Normal, TexCoord)) - 0.5);\n" "#else\n" -" hvec3 surfacenormal = -1.0 + 2.0 * hvec3(texture2D(Texture_Normal, TexCoord));\n" +" myhvec3 surfacenormal = -1.0 + 2.0 * myhvec3(texture2D(Texture_Normal, TexCoord));\n" "#endif\n" "\n" " // calculate shading\n" -" hvec3 diffusenormal = hvec3(normalize(LightVector));\n" -" hvec3 color = hvec3(texture2D(Texture_Color, TexCoord)) * (AmbientScale + DiffuseScale * max(dot(surfacenormal, diffusenormal), 0.0));\n" +" myhvec3 diffusenormal = myhvec3(normalize(LightVector));\n" +" myhvec3 color = myhvec3(texture2D(Texture_Color, TexCoord)) * (AmbientScale + DiffuseScale * max(dot(surfacenormal, diffusenormal), 0.0));\n" "#ifdef USESPECULAR\n" -" hvec3 specularnormal = hvec3(normalize(diffusenormal + hvec3(normalize(EyeVector))));\n" -" color += hvec3(texture2D(Texture_Gloss, TexCoord)) * (SpecularScale * pow(max(dot(surfacenormal, specularnormal), 0.0), SpecularPower));\n" +" myhvec3 specularnormal = myhvec3(normalize(diffusenormal + myhvec3(normalize(EyeVector))));\n" +" color += myhvec3(texture2D(Texture_Gloss, TexCoord)) * (SpecularScale * pow(max(dot(surfacenormal, specularnormal), 0.0), SpecularPower));\n" "#endif\n" "\n" "#ifdef USECUBEFILTER\n" " // apply light cubemap filter\n" -" color *= hvec3(textureCube(Texture_Cube, CubeVector));\n" +" color *= myhvec3(textureCube(Texture_Cube, CubeVector));\n" "#endif\n" "\n" " // calculate fragment color (apply light color and attenuation/fog scaling)\n" -" gl_FragColor = hvec4(color * LightColor * colorscale, 1);\n" +" gl_FragColor = myhvec4(color * LightColor * colorscale, 1);\n" "}\n" ;