A method of emulating lighting in a 3d scene.
Phong lighting is composed of three parts:
- [[###Diffuse Illumination|Diffuse Illumination]]
- [[#Specular Illumination|Specular Illumination]]
- [[#Ambient Illumination|Ambient Illumination]]
The equation for the model for an individual light:
$\large
C =
\underbrace{\mu k_{\text{diff}} \odot C_{\text{light}}} _{\text{Diffuse}}
+
\underbrace{k_{\text{spec}}
\nu \odot C_{\text{light}}}_{\text{Specular}}
+ \underbrace{k_\text{diff} \odot C_\text{amb}}_\text{Ambient}
$
$\large
\begin{align}
\mu &= \max(\vec m \cdot \vec L, 0) \\
\nu &= \max(\vec R_L \cdot \vec v, 0)^{n_{\text{spec}}}\\
\vec R_{L} &= 2\mu\vec m - \vec L
\end{align}
$
The combined light from multiple ight sources is the ambient factor combined with the sum of the diffuse and specular reflection from each light.
$\large
C={k_\text{diff}\odot C_{\text{amb}}}_\text{Ambient}
+ \sum_{i=1}^N C_{\text{light}}^{(i)} \odot \pa{
k_{\text{{diff}}}(\vec m \cdot \vec L_{i}) +
k_{\text{{spec}}}(\vec R_{i} \cdot \vec v)^{n_{\text{spec}}}
}
$
![[../../00 Excalidraw/Phong Lighting Model .excalidraw.dark.svg]]
%%[[../../00 Excalidraw/Phong Lighting Model .excalidraw.md|🖋 Edit in Excalidraw]], and the [[../../00 Excalidraw/Phong Lighting Model .excalidraw.light.svg|light exported image]]%%
Where:
- $P$ is the [[Point]] being lit
- $\vec m$ is the surface [[../Math/Normal Vector|Normal]]
- $\vec L$ is the [[../Math/Vector|Vector]] is the direction to the light source from $P$
- $\vec v$ is the [[../Math/Vector|Vector]] in the direction to the camera $E$ from $P$.
- $E$ is the [[../Physics/Position|Position]] of the [[../Computer Science/View Space|Camera]]
>[!note]
Note that in [[Lighting Model|Lighting Models]], the dot product $\vec a\cdot \vec b$ typically refers to the [[../Math/Clamp|clamped]] [[../Math/Dot Product|Dot Product]], $\max\left( 0, \frac{\vec a \cdot \vec{b} }{\lvert \vec m \vec l \rvert} \right)$
##### [[Diffuse Illumination]]
$\huge \begin{align}
C_{\text{diff}}(P)&= k_{\text{diff}}(\vec m \cdot \vec L) \odot C_{\text{light}}\\
&=\mu k_{\text{diff}} \odot C_{\text{light}}\\
\end{align} $
Where $k_{\text{diff}}$ is [[Albedo]] of the point, $C_{\text{light}}$ is the [[Color]] of the light, and $\mu$ is the diffuse shading factor:
$\large
\mu = \max\left( 0, \frac{{\vec m \cdot \vec L}}{\lvert \vec m \cdot \vec L \rvert } \right)
$
Diffuse reflection is not dependent on the view direction and only depends on the surface normal and the direction to the light.
>[!note] When multipling [[Color|Colors]] together ($k_\text{diff} C_{\text{light}}$) it is assumed to being using the [[Hadamard Product]]
##### [[Specular Illumination]]
Color of light due to [[Specular Illumination|Specular Reflection]].
$\huge C_{\text{spec}}= k_{\text{spec}} \pa{
\vec R_{L} \cdot \vec v
}^{n_{\text{spec}}} \odot C_{\text{light}} $
Where the surface itself has the following properties:
- $k_{\text{spec}}=$ the [[Specular Illumination|Specular Reflection]] coefficient, fraction of light specuraly reflection at normal incidence
([[RGBA Color Model|RGB]] triple)
- $n_{\text{spec}}=$ the specular exponent, meant to model how rough / smooth of the surface.
$\vec R_{L}$ is the direction of perfect specular reflection, calculated as:
$\large \vec R_{L} = 2(\vec m \cdot \vec L)\vec m - \vec L $
This formula assumes $\vec m$ and $\vec L$ are [[../Math/Vector Normalization|Normalized]], as well as that $\vec R_{L} \cdot \vec v$ is positive.
Alternatively, this can be written as
$\huge \begin{align}
C_{\text{spec}}(P) = \nu k_{\text{spec}} \odot C_{\text{light}}
\end{align}
$
Where $\nu= \pa{\vec R_{L }\cdot \vec v}^{n_{\text{spec}}}$
If $\vec m \cdot \vec L < 0$ **OR** $\vec v\cdot \vec R_{L} < 0$, then $C_{\text{spec}}=0$.
##### [[Ambient Illumination]]
A gross appoximation of [[Global Illumination]] (indirect lighting).
$
k_\text{diff} \odot C_\text{amb}
$
Where $C_\text{amb}$ is the [[Color]] of the ambient light and $k_\text{diff}$.