From: havoc Date: Tue, 22 Nov 2005 00:55:26 +0000 (+0000) Subject: fixed backwards q3bsp model lighting and backwards rtlighting X-Git-Tag: xonotic-v0.1.0preview~4469 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=7f6fffa3d33fa7821a34e58259f0511b62c530d2;p=xonotic%2Fdarkplaces.git fixed backwards q3bsp model lighting and backwards rtlighting git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5815 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/r_light.c b/r_light.c index 5c69018b..69b5097e 100644 --- a/r_light.c +++ b/r_light.c @@ -387,9 +387,11 @@ void R_LightModel_CalcVertexColors(const float *ambientcolor4f, const float *dif // silly directional diffuse shading if (usediffuse) { + // we have to negate this result because it is the incoming light + // direction, not simply the normal to dotproduct with. dot = DotProduct(normal3f, dnormal); - if (dot > 0) - VectorMA(color, dot, diffusecolor, color); + if (dot < 0) + VectorMA(color, -dot, diffusecolor, color); } // pretty good lighting diff --git a/r_shadow.c b/r_shadow.c index a929ff5b..1b5a8600 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -319,16 +319,16 @@ const char *builtinshader_light_vert = " // (we use unnormalized to ensure that it interpolates correctly and then\n" " // normalize it per pixel)\n" " vec3 lightminusvertex = LightPosition - gl_Vertex.xyz;\n" -" LightVector.x = -dot(lightminusvertex, gl_MultiTexCoord1.xyz);\n" -" LightVector.y = -dot(lightminusvertex, gl_MultiTexCoord2.xyz);\n" -" LightVector.z = -dot(lightminusvertex, gl_MultiTexCoord3.xyz);\n" +" LightVector.x = dot(lightminusvertex, gl_MultiTexCoord1.xyz);\n" +" LightVector.y = dot(lightminusvertex, gl_MultiTexCoord2.xyz);\n" +" LightVector.z = dot(lightminusvertex, gl_MultiTexCoord3.xyz);\n" "\n" "#if defined(USESPECULAR) || defined(USEFOG) || defined(USEOFFSETMAPPING)\n" " // transform unnormalized eye direction into tangent space\n" " vec3 eyeminusvertex = EyePosition - gl_Vertex.xyz;\n" -" EyeVector.x = -dot(eyeminusvertex, gl_MultiTexCoord1.xyz);\n" -" EyeVector.y = -dot(eyeminusvertex, gl_MultiTexCoord2.xyz);\n" -" EyeVector.z = -dot(eyeminusvertex, gl_MultiTexCoord3.xyz);\n" +" EyeVector.x = dot(eyeminusvertex, gl_MultiTexCoord1.xyz);\n" +" EyeVector.y = dot(eyeminusvertex, gl_MultiTexCoord2.xyz);\n" +" EyeVector.z = dot(eyeminusvertex, gl_MultiTexCoord3.xyz);\n" "#endif\n" "\n" " // transform vertex to camera space, using ftransform to match non-VS\n" @@ -1444,9 +1444,9 @@ static void R_Shadow_RenderSurfacesLighting_Light_Vertex_Shading(const msurface_ { Matrix4x4_Transform(&r_shadow_entitytolight, vertex3f, v); Matrix4x4_Transform3x3(&r_shadow_entitytolight, normal3f, n); - if ((dot = DotProduct(n, v)) > 0) + if ((dot = DotProduct(n, v)) < 0) { - shadeintensity = dot / sqrt(VectorLength2(v) * VectorLength2(n)); + shadeintensity = -dot / sqrt(VectorLength2(v) * VectorLength2(n)); color4f[0] = (ambientcolor[0] + shadeintensity * diffusecolor[0]) - reduce; color4f[1] = (ambientcolor[1] + shadeintensity * diffusecolor[1]) - reduce; color4f[2] = (ambientcolor[2] + shadeintensity * diffusecolor[2]) - reduce; @@ -1470,9 +1470,9 @@ static void R_Shadow_RenderSurfacesLighting_Light_Vertex_Shading(const msurface_ { distintensity = pow(1 - dist, r_shadow_attenpower) * r_shadow_attenscale; Matrix4x4_Transform3x3(&r_shadow_entitytolight, normal3f, n); - if ((dot = DotProduct(n, v)) > 0) + if ((dot = DotProduct(n, v)) < 0) { - shadeintensity = dot / sqrt(VectorLength2(v) * VectorLength2(n)); + shadeintensity = -dot / sqrt(VectorLength2(v) * VectorLength2(n)); color4f[0] = (ambientcolor[0] + shadeintensity * diffusecolor[0]) * distintensity - reduce; color4f[1] = (ambientcolor[1] + shadeintensity * diffusecolor[1]) * distintensity - reduce; color4f[2] = (ambientcolor[2] + shadeintensity * diffusecolor[2]) * distintensity - reduce; @@ -1504,9 +1504,9 @@ static void R_Shadow_RenderSurfacesLighting_Light_Vertex_Shading(const msurface_ dist = sqrt(dist); distintensity = pow(1 - dist, r_shadow_attenpower) * r_shadow_attenscale; Matrix4x4_Transform3x3(&r_shadow_entitytolight, normal3f, n); - if ((dot = DotProduct(n, v)) > 0) + if ((dot = DotProduct(n, v)) < 0) { - shadeintensity = dot / sqrt(VectorLength2(v) * VectorLength2(n)); + shadeintensity = -dot / sqrt(VectorLength2(v) * VectorLength2(n)); color4f[0] = (ambientcolor[0] + shadeintensity * diffusecolor[0]) * distintensity - reduce; color4f[1] = (ambientcolor[1] + shadeintensity * diffusecolor[1]) * distintensity - reduce; color4f[2] = (ambientcolor[2] + shadeintensity * diffusecolor[2]) * distintensity - reduce; @@ -1568,7 +1568,7 @@ static void R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(float *out3f, int numver float lightdir[3]; for (i = 0;i < numverts;i++, vertex3f += 3, svector3f += 3, tvector3f += 3, normal3f += 3, out3f += 3) { - VectorSubtract(vertex3f, relativelightorigin, lightdir); + VectorSubtract(relativelightorigin, vertex3f, lightdir); // the cubemap normalizes this for us out3f[0] = DotProduct(svector3f, lightdir); out3f[1] = DotProduct(tvector3f, lightdir); @@ -1582,9 +1582,9 @@ static void R_Shadow_GenTexCoords_Specular_NormalCubeMap(float *out3f, int numve float lightdir[3], eyedir[3], halfdir[3]; for (i = 0;i < numverts;i++, vertex3f += 3, svector3f += 3, tvector3f += 3, normal3f += 3, out3f += 3) { - VectorSubtract(vertex3f, relativelightorigin, lightdir); + VectorSubtract(relativelightorigin, vertex3f, lightdir); VectorNormalize(lightdir); - VectorSubtract(vertex3f, relativeeyeorigin, eyedir); + VectorSubtract(relativeeyeorigin, vertex3f, eyedir); VectorNormalize(eyedir); VectorAdd(lightdir, eyedir, halfdir); // the cubemap normalizes this for us