<p>I've read some tutorials about Phong and Blinn lighting models and tried to implement a rendered myself.
To my knowledge, the basic approach consists of the following steps:</p>

<ul>
<li>calculate the vector from the current fragment to the light <code>rayToLight</code> (and normalize it)</li>
<li>calculate the diffuse color intensity using <code>diffuseIntensity = max(dot(rayToLight, normal))</code></li>
<li>calculate the vector from the current fragment and the camera <code>rayToCamera</code> (and normalize it)</li>
<li>reflect <code>rayToLight</code>: <code>reflected = reflect(-rayToLight, normal)</code></li>
<li>calculate the <code>specularIntensity = pow(max(dot(reflected, rayToCamera), 0.0), shininess)</code>.</li>
</ul>

<p>The problem is that <code>specularIntensity</code> ( <code>dot(reflected, rayToCamera)</code> to be precise), can be non-zero even if the light and the camera are on the opposite sides of a surface. Take the following example
<a href="https://i.sstatic.net/4lM81.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/4lM81.png" alt="enter image description here"></a>
It is possible that the angle between <code>reflected</code> and <code>rayToCamera</code> is less than 90 deg even if the camera and the light are on the opposite sides of a surface.
This means that despite the surface is not lit by the diffuse light, it can show specular reflections which is, of course, not wanted.
I wasn't aware of this problem until it occurred when I was trying to implement a simple phong lighting model.</p>

<p>Have I done something wrong or is it just the way it should work?
Thanks</p>

CC BY-SA 4.0
2019-06-12T14:48:45.320Z
yes it's necessary to check whether `dot(light_dir, norm)` is positive or not. If negative we don't need to include specular component.
gallickgunner
CC BY-SA 4.0
2019-06-12T15:01:10.057Z
I see, I wonder why the majority of tutorials don't bring up this caveat. Thank you very much @gallickgunner . Feel free to add your comment as an answer as it is exactly what I was looking for.
Damiano Massarelli
<lighting>
Clarification about Phong lighting model
Damiano Massarelli
# Clarification about Phong lighting model

(Asked by: username_0 on 2019-06-11)

I've read some tutorials about Phong and Blinn lighting models and tried to implement a rendered myself.
To my knowledge, the basic approach consists of the following steps:

* calculate the vector from the current fragment to the light `rayToLight` (and normalize it)
* calculate the diffuse color intensity using `diffuseIntensity = max(dot(rayToLight, normal))`
* calculate the vector from the current fragment and the camera `rayToCamera` (and normalize it)
* reflect `rayToLight`: `reflected = reflect(-rayToLight, normal)`
* calculate the `specularIntensity = pow(max(dot(reflected, rayToCamera), 0.0), shininess)`.

The problem is that `specularIntensity` ( `dot(reflected, rayToCamera)` to be precise), can be non-zero even if the light and the camera are on the opposite sides of a surface. Take the following example
[![enter image description here](https://i.sstatic.net/4lM81.png)](https://i.sstatic.net/4lM81.png)
It is possible that the angle between `reflected` and `rayToCamera` is less than 90 deg even if the camera and the light are on the opposite sides of a surface.
This means that despite the surface is not lit by the diffuse light, it can show specular reflections which is, of course, not wanted.
I wasn't aware of this problem until it occurred when I was trying to implement a simple phong lighting model.

Have I done something wrong or is it just the way it should work?
Thanks

**Tags:** lighting

> **Comments:**
> **username_1**: yes it's necessary to check whether `dot(light_dir, norm)` is positive or not. If negative we don't need to include specular component.  
> **username_0**: I see, I wonder why the majority of tutorials don't bring up this caveat. Thank you very much @username_1 . Feel free to add your comment as an answer as it is exactly what I was looking for.  

---

## 0 answers

