]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
reduced number of varying variables required in a certain case in
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 13 Mar 2011 10:43:03 +0000 (10:43 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 13 Mar 2011 10:43:03 +0000 (10:43 +0000)
steelstorm by 1, to bring the shader within limits of older cards

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10917 d7cf8633-e32d-0410-b094-e92efae38249

shader_glsl.h

index a6fef691f0d5e2833026ed4b7620a7e12736a24c..20be4e6e630c77fdd84e5f917a09966c9c068e82 100644 (file)
 "attribute vec3 Attrib_TexCoord3; // normal\n"
 "attribute vec4 Attrib_TexCoord4; // lightmap texcoords\n"
 "#endif\n"
-"varying lowp vec4 VertexColor;\n"
+"varying mediump vec4 VertexColor;\n"
 "\n"
 "#if defined(USEFOGINSIDE) || defined(USEFOGOUTSIDE) || defined(USEFOGHEIGHTTEXTURE)\n"
 "# define USEFOG\n"
 "#endif\n"
 "#if defined(MODE_LIGHTMAP) || defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_LIGHTDIRECTIONMAP_TANGENTSPACE)\n"
-"#define USELIGHTMAP\n"
+"# define USELIGHTMAP\n"
 "#endif\n"
-"#if defined(USESPECULAR) || defined(USEOFFSETMAPPING) || defined(USEREFLECTCUBE) || defined(MODE_FAKELIGHT)\n"
-"#define USEEYEVECTOR\n"
+"#if defined(USESPECULAR) || defined(USEOFFSETMAPPING) || defined(USEREFLECTCUBE) || defined(MODE_FAKELIGHT) || defined(USEFOG)\n"
+"# define USEEYEVECTOR\n"
 "#endif\n"
 "\n"
 "#ifdef USESHADOWMAP2D\n"
 "uniform sampler2D Texture_First;\n"
 "#ifdef USEBLOOM\n"
 "uniform sampler2D Texture_Second;\n"
-"uniform lowp vec4 BloomColorSubtract;\n"
+"uniform mediump vec4 BloomColorSubtract;\n"
 "#endif\n"
 "#ifdef USEGAMMARAMPS\n"
 "uniform sampler2D Texture_GammaRamps;\n"
 "#endif\n"
 "#ifdef USESATURATION\n"
-"uniform lowp float Saturation;\n"
+"uniform mediump float Saturation;\n"
 "#endif\n"
 "#ifdef USEVIEWTINT\n"
-"uniform lowp vec4 ViewTintColor;\n"
+"uniform mediump vec4 ViewTintColor;\n"
 "#endif\n"
 "//uncomment these if you want to use them:\n"
 "uniform mediump vec4 UserVec1;\n"
 "uniform mediump vec4 DistortScaleRefractReflect;\n"
 "uniform mediump vec4 ScreenScaleRefractReflect;\n"
 "uniform mediump vec4 ScreenCenterRefractReflect;\n"
-"uniform lowp vec4 RefractColor;\n"
-"uniform lowp vec4 ReflectColor;\n"
+"uniform mediump vec4 RefractColor;\n"
+"uniform mediump vec4 ReflectColor;\n"
 "uniform mediump float ReflectFactor;\n"
 "uniform mediump float ReflectOffset;\n"
 "\n"
 "void main(void)\n"
 "{\n"
 "      TexCoord = vec2(TexMatrix * Attrib_TexCoord0);\n"
-"      vec3 EyeVectorModelSpace = EyePosition - Attrib_Position.xyz;\n"
-"      EyeVector.x = dot(EyeVectorModelSpace, Attrib_TexCoord1.xyz);\n"
-"      EyeVector.y = dot(EyeVectorModelSpace, Attrib_TexCoord2.xyz);\n"
-"      EyeVector.z = dot(EyeVectorModelSpace, Attrib_TexCoord3.xyz);\n"
+"      vec3 EyeRelative = EyePosition - Attrib_Position.xyz;\n"
+"      EyeVector.x = dot(EyeRelative, Attrib_TexCoord1.xyz);\n"
+"      EyeVector.y = dot(EyeRelative, Attrib_TexCoord2.xyz);\n"
+"      EyeVector.z = dot(EyeRelative, Attrib_TexCoord3.xyz);\n"
 "      gl_Position = ModelViewProjectionMatrix * Attrib_Position;\n"
 "      ModelViewProjectionPosition = gl_Position;\n"
 "}\n"
 "uniform mediump vec4 DistortScaleRefractReflect;\n"
 "uniform mediump vec4 ScreenScaleRefractReflect;\n"
 "uniform mediump vec4 ScreenCenterRefractReflect;\n"
-"uniform lowp vec4 RefractColor;\n"
-"uniform lowp vec4 ReflectColor;\n"
+"uniform mediump vec4 RefractColor;\n"
+"uniform mediump vec4 ReflectColor;\n"
 "uniform mediump float ReflectFactor;\n"
 "uniform mediump float ReflectOffset;\n"
 "uniform highp float ClientTime;\n"
 "#endif\n"
 "\n"
 "#ifdef USEEYEVECTOR\n"
-"varying highp vec3 EyeVector;\n"
-"#endif\n"
-"#ifdef USEFOG\n"
-"varying highp vec4 EyeVectorModelSpaceFogPlaneVertexDist;\n"
+"varying highp vec4 EyeVectorFogDepth;\n"
 "#endif\n"
 "\n"
 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_DEFERREDGEOMETRY) || defined(USEREFLECTCUBE)\n"
-"varying lowp vec3 VectorS; // direction of S texcoord (sometimes crudely called tangent)\n"
-"varying lowp vec3 VectorT; // direction of T texcoord (sometimes crudely called binormal)\n"
-"varying lowp vec3 VectorR; // direction of R texcoord (surface normal)\n"
+"varying highp vec4 VectorS; // direction of S texcoord (sometimes crudely called tangent)\n"
+"varying highp vec4 VectorT; // direction of T texcoord (sometimes crudely called binormal)\n"
+"varying highp vec4 VectorR; // direction of R texcoord (surface normal)\n"
+"#else\n"
+"# ifdef USEFOG\n"
+"varying highp vec3 EyeVectorModelSpace;\n"
+"# endif\n"
 "#endif\n"
 "\n"
 "#ifdef USEREFLECTION\n"
 "uniform highp vec4 FogPlane;\n"
 "\n"
 "#ifdef USESHADOWMAPORTHO\n"
-"varying mediump vec3 ShadowMapTC;\n"
+"varying highp vec3 ShadowMapTC;\n"
 "#endif\n"
 "\n"
 "#ifdef USEBOUNCEGRID\n"
-"varying mediump vec3 BounceGridTexCoord;\n"
+"varying highp vec3 BounceGridTexCoord;\n"
 "#endif\n"
 "\n"
 "\n"
 "uniform sampler2D Texture_ScreenSpecular;\n"
 "#endif\n"
 "\n"
-"uniform lowp vec3 Color_Pants;\n"
-"uniform lowp vec3 Color_Shirt;\n"
-"uniform lowp vec3 FogColor;\n"
+"uniform mediump vec3 Color_Pants;\n"
+"uniform mediump vec3 Color_Shirt;\n"
+"uniform mediump vec3 FogColor;\n"
 "\n"
 "#ifdef USEFOG\n"
 "uniform highp float FogRangeRecip;\n"
 "uniform highp float FogHeightFade;\n"
 "vec3 FogVertex(vec4 surfacecolor)\n"
 "{\n"
-"      vec3 EyeVectorModelSpace = EyeVectorModelSpaceFogPlaneVertexDist.xyz;\n"
-"      float FogPlaneVertexDist = EyeVectorModelSpaceFogPlaneVertexDist.w;\n"
+"#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_DEFERREDGEOMETRY) || defined(USEREFLECTCUBE)\n"
+"      vec3 EyeVectorModelSpace = vec3(VectorS.w, VectorT.w, VectorR.w);\n"
+"#endif\n"
+"      float FogPlaneVertexDist = EyeVectorFogDepth.w;\n"
 "      float fogfrac;\n"
 "       vec3 fc = FogColor;\n"
 "#ifdef USEFOGALPHAHACK\n"
 "      // this basically steps forward a small amount repeatedly until it finds\n"
 "      // itself inside solid, then jitters forward and back using decreasing\n"
 "      // amounts to find the impact\n"
-"      //vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMapping_Scale) * vec2(-1, 1), -1);\n"
-"      //vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMapping_Scale * vec2(-1, 1), -1);\n"
-"      vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMapping_Scale * vec2(-1, 1), -1);\n"
+"      //vec3 OffsetVector = vec3(EyeVectorFogDepth.xy * ((1.0 / EyeVectorFogDepth.z) * OffsetMapping_Scale) * vec2(-1, 1), -1);\n"
+"      //vec3 OffsetVector = vec3(normalize(EyeVectorFogDepth.xy) * OffsetMapping_Scale * vec2(-1, 1), -1);\n"
+"      vec3 OffsetVector = vec3(normalize(EyeVectorFogDepth.xyz).xy * OffsetMapping_Scale * vec2(-1, 1), -1);\n"
 "      vec3 RT = vec3(TexCoord, 1);\n"
 "      OffsetVector *= 0.1;\n"
 "      RT += OffsetVector *  step(textureGrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z);\n"
 "      return RT.xy;\n"
 "#else\n"
 "      // 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits)\n"
-"      //vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMapping_Scale) * vec2(-1, 1));\n"
-"      //vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMapping_Scale * vec2(-1, 1));\n"
-"      vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMapping_Scale * vec2(-1, 1));\n"
+"      //vec2 OffsetVector = vec2(EyeVectorFogDepth.xy * ((1.0 / EyeVectorFogDepth.z) * OffsetMapping_Scale) * vec2(-1, 1));\n"
+"      //vec2 OffsetVector = vec2(normalize(EyeVectorFogDepth.xy) * OffsetMapping_Scale * vec2(-1, 1));\n"
+"      vec2 OffsetVector = vec2(normalize(EyeVectorFogDepth.xyz).xy * OffsetMapping_Scale * vec2(-1, 1));\n"
 "      OffsetVector *= 0.5;\n"
 "      TexCoord += OffsetVector * (1.0 - textureGrad(Texture_Normal, TexCoord, dPdx, dPdy).a);\n"
 "      TexCoord += OffsetVector * (1.0 - textureGrad(Texture_Normal, TexCoord, dPdx, dPdy).a);\n"
 "\n"
 "      // transform unnormalized eye direction into tangent space\n"
 "#ifdef USEOFFSETMAPPING\n"
-"      vec3 EyeVectorModelSpace = EyePosition - Attrib_Position.xyz;\n"
-"      EyeVector.x = dot(EyeVectorModelSpace, Attrib_TexCoord1.xyz);\n"
-"      EyeVector.y = dot(EyeVectorModelSpace, Attrib_TexCoord2.xyz);\n"
-"      EyeVector.z = dot(EyeVectorModelSpace, Attrib_TexCoord3.xyz);\n"
+"      vec3 EyeRelative = EyePosition - Attrib_Position.xyz;\n"
+"      EyeVectorFogDepth.x = dot(EyeRelative, Attrib_TexCoord1.xyz);\n"
+"      EyeVectorFogDepth.y = dot(EyeRelative, Attrib_TexCoord2.xyz);\n"
+"      EyeVectorFogDepth.z = dot(EyeRelative, Attrib_TexCoord3.xyz);\n"
+"      EyeVectorFogDepth.w = 0.0;\n"
 "#endif\n"
 "\n"
 "      VectorS = (ModelViewMatrix * vec4(Attrib_TexCoord1.xyz, 0)).xyz;\n"
 "\n"
 "      // transform unnormalized eye direction into tangent space\n"
 "#ifdef USEEYEVECTOR\n"
-"      vec3 EyeVectorModelSpace = EyePosition - Attrib_Position.xyz;\n"
-"      EyeVector.x = dot(EyeVectorModelSpace, Attrib_TexCoord1.xyz);\n"
-"      EyeVector.y = dot(EyeVectorModelSpace, Attrib_TexCoord2.xyz);\n"
-"      EyeVector.z = dot(EyeVectorModelSpace, Attrib_TexCoord3.xyz);\n"
-"#endif\n"
-"\n"
+"      vec3 EyeRelative = EyePosition - Attrib_Position.xyz;\n"
+"      EyeVectorFogDepth.x = dot(EyeRelative, Attrib_TexCoord1.xyz);\n"
+"      EyeVectorFogDepth.y = dot(EyeRelative, Attrib_TexCoord2.xyz);\n"
+"      EyeVectorFogDepth.z = dot(EyeRelative, Attrib_TexCoord3.xyz);\n"
 "#ifdef USEFOG\n"
-"      EyeVectorModelSpaceFogPlaneVertexDist.xyz = EyePosition - Attrib_Position.xyz;\n"
-"      EyeVectorModelSpaceFogPlaneVertexDist.w = dot(FogPlane, Attrib_Position);\n"
+"      EyeVectorFogDepth.w = dot(FogPlane, Attrib_Position);\n"
+"#else\n"
+"      EyeVectorFogDepth.w = 0.0;\n"
 "#endif\n"
+"#endif\n"
+"\n"
 "\n"
 "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(USEREFLECTCUBE)\n"
-"      VectorS = Attrib_TexCoord1.xyz;\n"
-"      VectorT = Attrib_TexCoord2.xyz;\n"
-"      VectorR = Attrib_TexCoord3.xyz;\n"
+"# ifdef USEFOG\n"
+"      VectorS = vec4(Attrib_TexCoord1.xyz, EyePosition.x - Attrib_Position.x);\n"
+"      VectorT = vec4(Attrib_TexCoord2.xyz, EyePosition.y - Attrib_Position.y);\n"
+"      VectorR = vec4(Attrib_TexCoord3.xyz, EyePosition.z - Attrib_Position.z);\n"
+"# else\n"
+"      VectorS = Attrib_TexCoord1;\n"
+"      VectorT = Attrib_TexCoord2;\n"
+"      VectorR = Attrib_TexCoord3;\n"
+"# endif\n"
+"#else\n"
+"# ifdef USEFOG\n"
+"      EyeVectorModelSpace = EyePosition - Attrib_Position.xyz;\n"
+"# endif\n"
 "#endif\n"
 "\n"
 "      // transform vertex to camera space, using ftransform to match non-VS rendering\n"
 "uniform mediump vec4 DistortScaleRefractReflect;\n"
 "uniform mediump vec4 ScreenScaleRefractReflect;\n"
 "uniform mediump vec4 ScreenCenterRefractReflect;\n"
-"uniform lowp vec4 ReflectColor;\n"
+"uniform mediump vec4 ReflectColor;\n"
 "#endif\n"
 "#ifdef USEREFLECTCUBE\n"
 "uniform highp mat4 ModelToReflectCube;\n"
 "#endif\n"
 "\n"
 "#ifdef USEREFLECTCUBE\n"
-"      vec3 TangentReflectVector = reflect(-EyeVector, surfacenormal);\n"
+"      vec3 TangentReflectVector = reflect(-EyeVectorFogDepth.xyz, surfacenormal);\n"
 "      vec3 ModelReflectVector = TangentReflectVector.x * VectorS + TangentReflectVector.y * VectorT + TangentReflectVector.z * VectorR;\n"
 "      vec3 ReflectCubeTexCoord = vec3(ModelToReflectCube * vec4(ModelReflectVector, 0));\n"
 "      diffusetex += myhalf3(offsetMappedTexture2D(Texture_ReflectMask)) * myhalf3(textureCube(Texture_ReflectCube, ReflectCubeTexCoord));\n"
 "      color.rgb = diffusetex * (Color_Ambient + diffuse * Color_Diffuse);\n"
 "#ifdef USESPECULAR\n"
 "#ifdef USEEXACTSPECULARMATH\n"
-"      myhalf specular = pow(myhalf(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), SpecularPower * glosstex.a);\n"
+"      myhalf specular = pow(myhalf(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVectorFogDepth.xyz)))*-1.0, 0.0)), SpecularPower * glosstex.a);\n"
 "#else\n"
-"      myhalf3 specularnormal = normalize(lightnormal + myhalf3(normalize(EyeVector)));\n"
+"      myhalf3 specularnormal = normalize(lightnormal + myhalf3(normalize(EyeVectorFogDepth.xyz)));\n"
 "      myhalf specular = pow(myhalf(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower * glosstex.a);\n"
 "#endif\n"
 "      color.rgb += glosstex.rgb * (specular * Color_Specular);\n"
 "\n"
 "#ifdef MODE_FAKELIGHT\n"
 "#define SHADING\n"
-"myhalf3 lightnormal = myhalf3(normalize(EyeVector));\n"
+"myhalf3 lightnormal = myhalf3(normalize(EyeVectorFogDepth.xyz));\n"
 "myhalf3 lightcolor = myhalf3(1.0);\n"
 "#endif // MODE_FAKELIGHT\n"
 "\n"
 "      myhalf diffuse = myhalf(max(float(dot(surfacenormal, lightnormal)), 0.0));\n"
 "#  ifdef USESPECULAR\n"
 "#   ifdef USEEXACTSPECULARMATH\n"
-"      myhalf specular = pow(myhalf(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), SpecularPower * glosstex.a);\n"
+"      myhalf specular = pow(myhalf(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVectorFogDepth.xyz)))*-1.0, 0.0)), SpecularPower * glosstex.a);\n"
 "#   else\n"
-"      myhalf3 specularnormal = normalize(lightnormal + myhalf3(normalize(EyeVector)));\n"
+"      myhalf3 specularnormal = normalize(lightnormal + myhalf3(normalize(EyeVectorFogDepth.xyz)));\n"
 "      myhalf specular = pow(myhalf(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower * glosstex.a);\n"
 "#   endif\n"
 "      color.rgb = diffusetex * Color_Ambient + (diffusetex * Color_Diffuse * diffuse + glosstex.rgb * Color_Specular * specular) * lightcolor;\n"