A method of emulating [[Electromagnetic Radiation|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(\hat m \cdot \hat L, 0) \\ \nu &= \max(\vec R_L \cdot \vec v, 0)^{n_{\text{spec}}}\\ \vec R_{L} &= 2\mu\hat m - \hat 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}}}(\hat m \cdot \hat 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 - $\hat m$ is the surface [[../Math/Normal Vector|Normal]] - $\hat L$ is the [[../Math/Unit Vector|Unit Vector]] is the direction to the light source from $P$ - $\vec v$ is the [[../Math/Unit Vector|Unit 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 \hat m \vec l \rvert} \right)$ ##### [[Diffuse Illumination]] $\huge \begin{align} C_{\text{diff}}(P)&= k_{\text{diff}}(\hat m \cdot \hat 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, {{\hat m \cdot \hat L}} \right) $ Diffuse reflection is not dependent on the view direction and only depends on the surface normal and the direction to the light. The [[../Math/Dot Product|Dot Product]] is used in this context due to its property that it is equal to the [[Cosine|cosine]] of the angle between the two vectors (when both vectors are normalized). >[!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(\hat m \cdot \hat L)\hat m - \hat L $ $\vec R_{L}$ can be thought of also as the [[Wave Reflection|reflection]] [[Vector|vector]] of light. This formula assumes $\hat m$ and $\hat 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 $\hat m \cdot \hat 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). $ \huge k_\text{diff} \odot C_\text{amb} $ Where $C_\text{amb}$ is the [[Color]] of the ambient light and $k_\text{diff}$.