]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
make sure gloss never calculates 0^0
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 29 Aug 2011 14:02:58 +0000 (14:02 +0000)
committerRudolf Polzer <divVerent@xonotic.org>
Mon, 29 Aug 2011 15:48:45 +0000 (17:48 +0200)
as that is undefined and leads to black stuff

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11305 d7cf8633-e32d-0410-b094-e92efae38249
::stable-branch::merge=2924a0a6e6f62043eb92c77db28434ef76b86461

dpsoftrast.c
shader_glsl.h
shader_hlsl.h

index 2c101fc2d79888cf7ac73133e9d6e0a48d1b16a0..d1cde7a915720f724a12d8f4bc72495a6b879f4b 100644 (file)
@@ -107,6 +107,8 @@ static void *MM_CALLOC(size_t nmemb, size_t size)
 #define MM_FREE free
 #endif
 
+#define DPSOFTRAST_FLT_MIN 0.000000000000000001f
+
 typedef enum DPSOFTRAST_ARRAY_e
 {
        DPSOFTRAST_ARRAY_POSITION,
@@ -3855,7 +3857,7 @@ void DPSOFTRAST_PixelShader_LightDirection(DPSOFTRAST_State_Thread *thread, cons
                                specularnormal[2] = lightnormal[2] + eyenormal[2];
                                DPSOFTRAST_Vector3Normalize(specularnormal);
 
-                               specular = DPSOFTRAST_Vector3Dot(surfacenormal, specularnormal);if (specular < 0.0f) specular = 0.0f;
+                               specular = DPSOFTRAST_Vector3Dot(surfacenormal, specularnormal);if (specular < DPSOFTRAST_FLT_MIN) specular = DPSOFTRAST_FLT_MIN;
                        }
 
                        specular = pow(specular, SpecularPower * glosstex[3]);
@@ -4264,7 +4266,7 @@ void DPSOFTRAST_PixelShader_LightSource(DPSOFTRAST_State_Thread *thread, const D
                                specularnormal[2] = lightnormal[2] + eyenormal[2];
                                DPSOFTRAST_Vector3Normalize(specularnormal);
 
-                               specular = DPSOFTRAST_Vector3Dot(surfacenormal, specularnormal);if (specular < 0.0f) specular = 0.0f;
+                               specular = DPSOFTRAST_Vector3Dot(surfacenormal, specularnormal);if (specular < DPSOFTRAST_FLT_MIN) specular = DPSOFTRAST_FLT_MIN;
                        }
                        specular = pow(specular, SpecularPower * glosstex[3]);
 
index 5a00e7a7acd2c791a5ac30e923696f9a2d2603e6..57ce3d5d26df36c10ac735c621b87c5d31b3fcc1 100644 (file)
@@ -43,6 +43,9 @@
 "#define highp\n"
 "#endif\n"
 "\n"
+"// not REALLY the smallest value (2^-62 would be correct), but short and any compiler failing at parsing this is broken\n"
+"#define FLT_MIN 0.000000000000000001\n"
+"\n"
 "#ifdef VERTEX_SHADER\n"
 "dp_attribute vec4 Attrib_Position;  // vertex\n"
 "dp_attribute vec4 Attrib_Color;     // color\n"
 "      // calculate directional shading\n"
 "      vec3 eyevector = position * -1.0;\n"
 "#  ifdef USEEXACTSPECULARMATH\n"
-"      myhalf specular = pow(cast_myhalf(max(float(dot(reflect(lightnormal, surfacenormal), normalize(eyevector)))*-1.0, 0.0)), SpecularPower * normalmap.a);\n"
+"      myhalf specular = pow(cast_myhalf(max(float(dot(reflect(lightnormal, surfacenormal), normalize(eyevector)))*-1.0, FLT_MIN)), SpecularPower * normalmap.a);\n"
 "#  else\n"
 "      myhalf3 specularnormal = normalize(lightnormal + cast_myhalf3(normalize(eyevector)));\n"
-"      myhalf specular = pow(cast_myhalf(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower * normalmap.a);\n"
+"      myhalf specular = pow(cast_myhalf(max(float(dot(surfacenormal, specularnormal)), FLT_MIN)), SpecularPower * normalmap.a);\n"
 "#  endif\n"
 "#endif\n"
 "\n"
 "      color.rgb = diffusetex * (Color_Ambient + diffuse * Color_Diffuse);\n"
 "#ifdef USESPECULAR\n"
 "#ifdef USEEXACTSPECULARMATH\n"
-"      myhalf specular = pow(cast_myhalf(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVectorFogDepth.xyz)))*-1.0, 0.0)), SpecularPower * glosstex.a);\n"
+"      myhalf specular = pow(cast_myhalf(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVectorFogDepth.xyz)))*-1.0, FLT_MIN)), SpecularPower * glosstex.a);\n"
 "#else\n"
 "      myhalf3 specularnormal = normalize(lightnormal + cast_myhalf3(normalize(EyeVectorFogDepth.xyz)));\n"
-"      myhalf specular = pow(cast_myhalf(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower * glosstex.a);\n"
+"      myhalf specular = pow(cast_myhalf(max(float(dot(surfacenormal, specularnormal)), FLT_MIN)), SpecularPower * glosstex.a);\n"
 "#endif\n"
 "      color.rgb += glosstex.rgb * (specular * Color_Specular);\n"
 "#endif\n"
 "      myhalf diffuse = cast_myhalf(max(float(dot(surfacenormal, lightnormal)), 0.0));\n"
 "#  ifdef USESPECULAR\n"
 "#   ifdef USEEXACTSPECULARMATH\n"
-"      myhalf specular = pow(cast_myhalf(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVectorFogDepth.xyz)))*-1.0, 0.0)), SpecularPower * glosstex.a);\n"
+"      myhalf specular = pow(cast_myhalf(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVectorFogDepth.xyz)))*-1.0, FLT_MIN)), SpecularPower * glosstex.a);\n"
 "#   else\n"
 "      myhalf3 specularnormal = normalize(lightnormal + cast_myhalf3(normalize(EyeVectorFogDepth.xyz)));\n"
-"      myhalf specular = pow(cast_myhalf(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower * glosstex.a);\n"
+"      myhalf specular = pow(cast_myhalf(max(float(dot(surfacenormal, specularnormal)), FLT_MIN)), SpecularPower * glosstex.a);\n"
 "#   endif\n"
 "      color.rgb = diffusetex * Color_Ambient + (diffusetex * Color_Diffuse * diffuse + glosstex.rgb * Color_Specular * specular) * lightcolor;\n"
 "#  else\n"
index 1296711385ed4c8770000b70bfa2f8e9475d46e9..2fa3e6d7c0f89f5f46308896444a29a53a6b8fce 100644 (file)
@@ -2,6 +2,9 @@
 "// written by Forest 'LordHavoc' Hale\n"
 "// shadowmapping enhancements by Lee 'eihrul' Salzman\n"
 "\n"
+"// not REALLY the smallest value (2^-62 would be correct), but short and any compiler failing at parsing this is broken\n"
+"#define FLT_MIN 0.000000000000000001\n"
+"\n"
 "// FIXME: we need to get rid of ModelViewProjectionPosition to make room for the texcoord for this\n"
 "#if defined(USEREFLECTION)\n"
 "#undef USESHADOWMAPORTHO\n"
 "      // calculate directional shading\n"
 "      float3 eyevector = position * -1.0;\n"
 "#  ifdef USEEXACTSPECULARMATH\n"
-"      half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(eyevector)))*-1.0, 0.0)), SpecularPower * normalmap.a));\n"
+"      half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(eyevector)))*-1.0, FLT_MIN)), SpecularPower * normalmap.a));\n"
 "#  else\n"
 "      half3 specularnormal = half3(normalize(lightnormal + half3(normalize(eyevector))));\n"
-"      half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower * normalmap.a));\n"
+"      half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), FLT_MIN)), SpecularPower * normalmap.a));\n"
 "#  endif\n"
 "#endif\n"
 "\n"
 "      color.rgb = diffusetex * (Color_Ambient + diffuse * Color_Diffuse);\n"
 "#ifdef USESPECULAR\n"
 "#ifdef USEEXACTSPECULARMATH\n"
-"      half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), SpecularPower * glosstex.a));\n"
+"      half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, FLT_MIN)), SpecularPower * glosstex.a));\n"
 "#else\n"
 "      half3 specularnormal = half3(normalize(lightnormal + half3(normalize(EyeVector))));\n"
-"      half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower * glosstex.a));\n"
+"      half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), FLT_MIN)), SpecularPower * glosstex.a));\n"
 "#endif\n"
 "      color.rgb += glosstex.rgb * (specular * Color_Specular);\n"
 "#endif\n"
 "      half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n"
 "#  ifdef USESPECULAR\n"
 "#   ifdef USEEXACTSPECULARMATH\n"
-"      half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), SpecularPower * glosstex.a));\n"
+"      half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, FLT_MIN)), SpecularPower * glosstex.a));\n"
 "#   else\n"
 "      half3 specularnormal = half3(normalize(lightnormal + half3(normalize(EyeVector))));\n"
-"      half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower * glosstex.a));\n"
+"      half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), FLT_MIN)), SpecularPower * glosstex.a));\n"
 "#   endif\n"
 "      color.rgb = diffusetex * Color_Ambient + (diffusetex * Color_Diffuse * diffuse + glosstex.rgb * Color_Specular * specular) * lightcolor;\n"
 "#  else\n"