@@ -88,8 +88,25 @@ void main()
8888
8989 vec3 lightDir = normalize (2.0 * deluxe.xyz - 1.0 );
9090
91+ // Lightmaps generated by q3map2 don't store the raw light value, but
92+ // they store light premultiplied with the dot product of the light
93+ // direction and surface normal. The line is just an attempt to reverse
94+ // that and get the original light values.
95+ // The lightmap stores the light in this way because for the diffuse
96+ // lighting formula the outgoing light is equal to the incoming light
97+ // multiplied by the above dot product multiplied by the surface albedo.
98+ // So this premultiplication means that the diffuse lighting value can
99+ // be calculated with a single multiply operation.
100+ // But specular lighting and/or normal mapping formulas are more complex,
101+ // and so you need the true light value to get correct lighting.
102+ // Obviously the data is not good enough to recover the original color
103+ // in all cases. The lower bound was an arbitrary chose factor to
104+ // prevent too small divisors resulting in too bright lights. Increasing
105+ // the value should reduce these artifacts.
106+ // -- gimhael https://github.com/DaemonEngine/Daemon/issues/299#issuecomment-606186347
107+
91108 // divide by cosine term to restore original light color
92- lightColor /= clamp (dot (normalize (var_Normal), lightDir), 0.004 , 1.0 );
109+ lightColor /= clamp (dot (normalize (var_Normal), lightDir), 0.3 , 1.0 );
93110
94111 computeLight(lightDir, normal, viewDir, lightColor, diffuse, material, color);
95112#else // !USE_DELUXE_MAPPING
0 commit comments