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);