3
$\begingroup$

In Cg tuts, Diffuse Section

Surfaces that face away from the light will produce negative dot-product values, so the max(N · L, 0) in the equation ensures that these surfaces show no diffuse lighting.

My question is why not just leave it be negative? IMO, both the negative and zero will make the color be black.

$\endgroup$

3 Answers 3

10
$\begingroup$

If lighting with multiple lights, they add together to make the final lighting value. A negative light would darken other lights, which is incorrect. This is also true if you add in specular reflections, emissive lighting, or other sources of lighting. The negative lighting from one source of lighting would darken some other source of non negative lighting.

$\endgroup$
3
  • $\begingroup$ If only one direction light is taken into account, no further processing such as half-lambert, is there any need to use the max func? $\endgroup$
    – AlexWei
    Jan 7, 2019 at 7:54
  • 3
    $\begingroup$ If your application does indeed not rely on this value not being negative (only a single light source, just rendering straight to a color target in a way that will lead to the output being clamped to black anyways, etc.) then, by all means, go ahead and skip the max() if it makes you feel better. But do so, knowing that this will merely produce a result indistinguishable from the correct result in the most narrow circumstances and incorrect results in any other case. Meanwhile, any useful explanation of how shading works will continue to present the formula that is correct in general… 😉 $\endgroup$ Jan 7, 2019 at 10:00
  • $\begingroup$ @MichaelKenzel Actually, it will makes me feel better :) knowing it could be safely skipped. Because I am afraid there is sth beyond my knowledge happens under the hood. Thanks. $\endgroup$
    – AlexWei
    Jan 7, 2019 at 11:46
2
$\begingroup$

Because negative shading values are undefined and don't play well with tonemapping. It is preferable to use values in $[0,1]$ for low-dynamic-range or $[0,+\infty)$ for high-dynamic-range images.

$\endgroup$
2
$\begingroup$

$N \cdot L < 0$ implies that the light is directed in the direction opposite the normal to the visible surface of the polygon. This means that the light is coming from behind and striking the back face of the polygon. In the analogous situation in real life, light striking one face of an opaque surface does not affect the illumination of a second face. Shining light on the back of a book (or other opaque object) does make the front of the book darker (that is it does not apply negative lighting): it simply has no effect on the front face of the book. This is the reason for the max() function.

Applying negative illumination to a surface where $N \cdot L < 0$ doesn't make sense physically. In geometric optics with incoherent light sources there is no such thing as negative illumination.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.