From a2d234ec3038a927adb4a11cfddce859565add8b Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Thu, 16 Apr 2020 19:26:37 +0200 Subject: [PATCH] always use lightmap lightColor restoration, even with lightgrid direction, ref #299, #306 The feature discussed in #299 and #306 to restore original light color to feed the normal-based light computation was only applied on surface using deluxe maps, leading to anomalous dark lighting with maps without deluxemaps, or when deluxe mapping is disabled. It's not related to deluxe maps but to light maps any way --- .../renderer/glsl_source/lightMapping_fp.glsl | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/engine/renderer/glsl_source/lightMapping_fp.glsl b/src/engine/renderer/glsl_source/lightMapping_fp.glsl index 3aa2d234f5..ca9e255a09 100644 --- a/src/engine/renderer/glsl_source/lightMapping_fp.glsl +++ b/src/engine/renderer/glsl_source/lightMapping_fp.glsl @@ -118,32 +118,6 @@ void main() // Compute light color from space lightmap. vec3 lightColor = texture2D(u_LightMap, var_TexLight).rgb; - #if defined(USE_DELUXE_MAPPING) - /* Lightmaps generated by q3map2 don't store the raw light value, but - they store light premultiplied with the dot product of the light - direction and surface normal. The line is just an attempt to reverse - that and get the original light values. - - The lightmap stores the light in this way because for the diffuse - lighting formula the outgoing light is equal to the incoming light - multiplied by the above dot product multiplied by the surface albedo. - So this premultiplication means that the diffuse lighting value can - be calculated with a single multiply operation. - - But specular lighting and/or normal mapping formulas are more complex, - and so you need the true light value to get correct lighting. - Obviously the data is not good enough to recover the original color - in all cases. The lower bound was an arbitrary chose factor to - prevent too small divisors resulting in too bright lights. - - Increasing the value should reduce these artifacts. -- gimhael - https://github.com/DaemonEngine/Daemon/issues/299#issuecomment-606186347 - */ - - // divide by cosine term to restore original light color - lightColor /= clamp(dot(normalize(var_Normal), lightDir), 0.3, 1.0); - #endif - color.rgb = vec3(0.0); #else // Compute light color from lightgrid. @@ -153,6 +127,32 @@ void main() color.rgb = ambientColor * r_AmbientScale * diffuse.rgb; #endif + #if defined(USE_LIGHT_MAPPING) + /* Lightmaps generated by q3map2 don't store the raw light value, but + they store light premultiplied with the dot product of the light + direction and surface normal. The line is just an attempt to reverse + that and get the original light values. + + The lightmap stores the light in this way because for the diffuse + lighting formula the outgoing light is equal to the incoming light + multiplied by the above dot product multiplied by the surface albedo. + So this premultiplication means that the diffuse lighting value can + be calculated with a single multiply operation. + + But specular lighting and/or normal mapping formulas are more complex, + and so you need the true light value to get correct lighting. + Obviously the data is not good enough to recover the original color + in all cases. The lower bound was an arbitrary chose factor to + prevent too small divisors resulting in too bright lights. + + Increasing the value should reduce these artifacts. -- gimhael + https://github.com/DaemonEngine/Daemon/issues/299#issuecomment-606186347 + */ + + // divide by cosine term to restore original light color + lightColor /= clamp(dot(normalize(var_Normal), lightDir), 0.3, 1.0); + #endif + // Blend static light. computeLight(lightDir, normal, viewDir, lightColor, diffuse, material, color);