From 56fd91b04f13a1dc31e36113683dda6a72795632 Mon Sep 17 00:00:00 2001 From: divverent Date: Mon, 20 Oct 2008 13:20:06 +0000 Subject: [PATCH] q3map2 is too stupid to calculate proper surface normals when q3map_nonplanar is used (the lightmap and deluxemap coords correspond to virtually random coordinates on that luxel, and NOT to its center, because recursive triangle subdivision is used to map the luxels to coordinates on the draw surfaces), which also causes deluxemaps to be wrong because light contributions from the wrong side of the surface are added up. To prevent divisions by zero or strong exaggerations, a max() nudge is done here at expense of some additional fps. This is ONLY needed for deluxemaps, tangentspace deluxemap avoid this problem by design. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8535 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_rmain.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/gl_rmain.c b/gl_rmain.c index d1ee2700..14a1c3f4 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -950,7 +950,16 @@ static const char *builtinshaderstring = " diffusenormal.y = dot(diffusenormal_modelspace, myhalf3(VectorT));\n" " diffusenormal.z = dot(diffusenormal_modelspace, myhalf3(VectorR));\n" " // calculate directional shading (and undoing the existing angle attenuation on the lightmap by the division)\n" -" myhalf3 tempcolor = color.rgb * (DiffuseScale * myhalf(max(float(dot(surfacenormal, diffusenormal) / diffusenormal.z), 0.0)));\n" +" // note that q3map2 is too stupid to calculate proper surface normals when q3map_nonplanar\n" +" // is used (the lightmap and deluxemap coords correspond to virtually random coordinates\n" +" // on that luxel, and NOT to its center, because recursive triangle subdivision is used\n" +" // to map the luxels to coordinates on the draw surfaces), which also causes\n" +" // deluxemaps to be wrong because light contributions from the wrong side of the surface\n" +" // are added up. To prevent divisions by zero or strong exaggerations, a max()\n" +" // nudge is done here at expense of some additional fps. This is ONLY needed for\n" +" // deluxemaps, tangentspace deluxemap avoid this problem by design.\n" +" myhalf3 tempcolor = color.rgb * (DiffuseScale * myhalf(max(float(dot(surfacenormal, diffusenormal) / max(0.25, diffusenormal.z)), 0.0)));\n" +" // 0.25 supports up to 75.5 degrees normal/deluxe angle\n" "# ifdef USESPECULAR\n" "# ifdef USEEXACTSPECULARMATH\n" " tempcolor += myhalf3(texture2D(Texture_Gloss, TexCoord)) * SpecularScale * pow(myhalf(max(float(dot(reflect(diffusenormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), SpecularPower);\n" -- 2.39.2