]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
reworked specular lighting to use real reflection math instead of the
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 28 Aug 2008 09:38:27 +0000 (09:38 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 28 Aug 2008 09:38:27 +0000 (09:38 +0000)
averaged-directions approximation that was used before
no longer normalizes deluxemap samples, this may help with some "bright
edge near shadow" interpolation issues

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

gl_rmain.c

index bbd731e1d67eb75cc962f9baf3f822632345112a..04b376be96b933cc281dbd4da8236b5918be3b80 100644 (file)
@@ -847,7 +847,8 @@ static const char *builtinshaderstring =
 "      myhalf terrainblend = clamp(myhalf(gl_Color.a) * color.a * 2.0 - 0.5, myhalf(0.0), myhalf(1.0));\n"
 "      //myhalf terrainblend = min(myhalf(gl_Color.a) * color.a * 2.0, myhalf(1.0));\n"
 "      //myhalf terrainblend = myhalf(gl_Color.a) * color.a > 0.5;\n"
-"      color = mix(myhalf4(texture2D(Texture_SecondaryColor, TexCoord)), color, terrainblend);\n"
+"      color.rgb = mix(myhalf3(texture2D(Texture_SecondaryColor, TexCoord)), color.rgb, terrainblend);\n"
+"      color.a = 1.0;\n"
 "      //color = mix(myhalf4(1, 0, 0, 1), color, terrainblend);\n"
 "#endif\n"
 "\n"
@@ -859,7 +860,7 @@ static const char *builtinshaderstring =
 "      myhalf3 glosscolor = mix(myhalf3(texture2D(Texture_SecondaryGloss, TexCoord)), myhalf3(texture2D(Texture_Gloss, TexCoord)), terrainblend);\n"
 "#  endif\n"
 "# else\n"
-"      myhalf3 surfacenormal = normalize(myhalf3(texture2D(Texture_Normal, TexCoord)) - myhalf3(0.5));\n"
+"      myhalf3 surfacenormal = normalize(myhalf3(texture2D(Texture_Normal, TexCoord)) - myhalf3(0.5, 0.5, 0.5));\n"
 "#  ifdef USESPECULAR\n"
 "      myhalf3 glosscolor = myhalf3(texture2D(Texture_Gloss, TexCoord));\n"
 "#  endif\n"
@@ -880,10 +881,8 @@ static const char *builtinshaderstring =
 "      myhalf3 diffusenormal = myhalf3(normalize(LightVector));\n"
 "# endif\n"
 "# ifdef USESPECULAR\n"
-"      myhalf3 specularnormal = normalize(diffusenormal + myhalf3(normalize(EyeVector)));\n"
-"\n"
 "      // calculate directional shading\n"
-"      color.rgb = myhalf(texture2D(Texture_Attenuation, vec2(length(CubeVector), 0.0))) * (color.rgb * (AmbientScale + DiffuseScale * myhalf(max(float(dot(surfacenormal, diffusenormal)), 0.0))) + (SpecularScale * pow(myhalf(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower)) * glosscolor);\n"
+"      color.rgb = myhalf(texture2D(Texture_Attenuation, vec2(length(CubeVector), 0.0))) * (color.rgb * (AmbientScale + DiffuseScale * myhalf(max(float(dot(surfacenormal, diffusenormal)), 0.0))) + (SpecularScale * pow(myhalf(max(float(dot(reflect(diffusenormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), SpecularPower)) * glosscolor);\n"
 "# else\n"
 "#  ifdef USEDIFFUSE\n"
 "      // calculate directional shading\n"
@@ -913,8 +912,7 @@ static const char *builtinshaderstring =
 "# ifdef USESPECULAR\n"
 "      // calculate directional shading\n"
 "      color.rgb *= AmbientColor + DiffuseColor * myhalf(max(float(dot(surfacenormal, diffusenormal)), 0.0));\n"
-"      myhalf3 specularnormal = normalize(diffusenormal + myhalf3(normalize(EyeVector)));\n"
-"      color.rgb += myhalf3(texture2D(Texture_Gloss, TexCoord)) * SpecularColor * pow(myhalf(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower);\n"
+"      color.rgb += myhalf3(texture2D(Texture_Gloss, TexCoord)) * SpecularColor * pow(myhalf(max(float(dot(reflect(diffusenormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), SpecularPower);\n"
 "# else\n"
 "#  ifdef USEDIFFUSE\n"
 "\n"
@@ -933,13 +931,15 @@ static const char *builtinshaderstring =
 "      // deluxemap lightmapping using light vectors in modelspace (evil q3map2)\n"
 "\n"
 "      // get the light normal\n"
-"      myhalf3 diffusenormal_modelspace = myhalf3(texture2D(Texture_Deluxemap, TexCoordLightmap)) - myhalf3(0.5);\n"
-"      myhalf3 diffusenormal = normalize(myhalf3(dot(diffusenormal_modelspace, myhalf3(VectorS)), dot(diffusenormal_modelspace, myhalf3(VectorT)), dot(diffusenormal_modelspace, myhalf3(VectorR))));\n"
+"      myhalf3 diffusenormal_modelspace = myhalf3(texture2D(Texture_Deluxemap, TexCoordLightmap)) * 2.0 + myhalf3(-1.0, -1.0, -1.0);\n"
+"      myhalf3 diffusenormal;\n"
+"      diffusenormal.x = dot(diffusenormal_modelspace, myhalf3(VectorS));\n"
+"      diffusenormal.y = dot(diffusenormal_modelspace, myhalf3(VectorT));\n"
+"      diffusenormal.z = dot(diffusenormal_modelspace, myhalf3(VectorR));\n"
 "      // calculate directional shading\n"
 "      myhalf3 tempcolor = color.rgb * (DiffuseScale * myhalf(max(float(dot(surfacenormal, diffusenormal)), 0.0)));\n"
 "# ifdef USESPECULAR\n"
-"      myhalf3 specularnormal = myhalf3(normalize(diffusenormal + myhalf3(normalize(EyeVector))));\n"
-"      tempcolor += myhalf3(texture2D(Texture_Gloss, TexCoord)) * SpecularScale * pow(myhalf(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower);\n"
+"      tempcolor += myhalf3(texture2D(Texture_Gloss, TexCoord)) * SpecularScale * pow(myhalf(max(float(dot(reflect(diffusenormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), SpecularPower);\n"
 "# endif\n"
 "\n"
 "      // apply lightmap color\n"
@@ -953,12 +953,11 @@ static const char *builtinshaderstring =
 "      // deluxemap lightmapping using light vectors in tangentspace (hmap2 -light)\n"
 "\n"
 "      // get the light normal\n"
-"      myhalf3 diffusenormal = normalize(myhalf3(texture2D(Texture_Deluxemap, TexCoordLightmap)) - myhalf3(0.5));\n"
+"      myhalf3 diffusenormal = myhalf3(texture2D(Texture_Deluxemap, TexCoordLightmap)) * 2.0 + myhalf3(-1.0, -1.0, -1.0);\n"
 "      // calculate directional shading\n"
 "      myhalf3 tempcolor = color.rgb * (DiffuseScale * myhalf(max(float(dot(surfacenormal, diffusenormal)), 0.0)));\n"
 "# ifdef USESPECULAR\n"
-"      myhalf3 specularnormal = myhalf3(normalize(diffusenormal + myhalf3(normalize(EyeVector))));\n"
-"      tempcolor += myhalf3(texture2D(Texture_Gloss, TexCoord)) * SpecularScale * pow(myhalf(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower);\n"
+"      tempcolor += myhalf3(texture2D(Texture_Gloss, TexCoord)) * SpecularScale * pow(myhalf(max(float(dot(reflect(diffusenormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), SpecularPower);\n"
 "# endif\n"
 "\n"
 "      // apply lightmap color\n"