Solution (source code)

= Solution

A <bidirectional reflectance distribution function>, or <BRDF>, describes how a surface scatters incident illumination into each outgoing direction. At a fixed surface <point> $p$ and <wavelength>, its inputs are two directions above the surface, $\omega_i$ toward the incident source and $\omega_o$ toward the observer; equivalently these are two pairs of angular coordinates. Its output is the ratio of differential reflected <radiance> to differential incident <irradiance>:
$$
\boxed{f_r(p,\omega_i,\omega_o)=\frac{dL_o(p,\omega_o)}{dE_i(p,\omega_i)},\qquad [f_r]=\mathrm{sr}^{-1}.}
$$
Position and <wavelength> may be additional arguments when material properties vary. A colour implementation can return one value per colour channel. The <BRDF> is a material response, not the final outgoing light value: it must be combined with the incident illumination and the projected-angle factor.<Physically Based Rendering: From Theory to Implementation (4th edition) by Matt Pharr and others>[§4.3.1, definition of the BRDF as differential outgoing radiance divided by differential incident irradiance]{ref}

For incident <radiance> $L_i$, the reflection part of the <rendering equation> is
$$
L_o(p,\omega_o)=\int_{\Omega^+}f_r(p,\omega_i,\omega_o)L_i(p,\omega_i)(\hat N\cdot\omega_i)\,d\omega_i.
$$
Emission is added separately if the surface itself emits. This integral explains how a <BRDF> replaces the assumed material response of a local lighting model. For <Lambertian reflectance>, $f_r=\rho_d/\pi$, so the cosine factor yields the diffuse term from part (a). A directional specular lobe supplies a highlight. The empirical <Phong reflection model> is an approximate angular-response model of this kind; its original direct specular term is not automatically a normalized, energy-conserving <BRDF>. The ambient term approximates missing illumination and is not itself a third direction-independent material scattering mechanism. More general <BRDFs> can reproduce measured surface behaviour, while illumination from other surfaces supplies indirect light in the <rendering equation>.