# The Rendering Equation

This is one of the most important equation for rendering:

$\displaystyle \quad L_o(p, \omega_o) = L_e(p,\omega_o) + \int_{S^2} f(p,\omega_o,\omega_i) \; L_i(p,\omega_i) \; (n \cdot \omega_i) \; d\omega_i$

The equation above requires integration of incoming radiance over all possible directions in the hemisphere. Note that this formulation is more suited for distant lighting which is why it’s weighted by the solid angle $d\omega_i$.

### Spherical Coordinates Formulation

When trying to come up with analytical solution to the rendering equation, we often do this in *spherical coordinates*. We need to take into account the change of domain of integration [wiki]:

$\quad d\omega = sin\theta \; d\theta d\phi$

Which yields:

$\displaystyle \quad L_o(p, \omega_o) = L_e(p, \omega_o) + \int_{0}^{2\pi}\int_{0}^{\pi} f(p,\omega_o,\theta,\phi) \; L_i(p,\theta,\phi) \; |cos\theta| \; sin\theta \; d\theta \; d\phi$

### Surface Formulation

In the context of patch tracing, it’s more common to formulate the rendering equation based on patches that we hit. This is done by considering all the visible hit points from rays shot from upper hemisphere of $p$.

Consider starting at point $p = x$ and casting a ray in the direction of $\omega_i$. Let $y = ray(x, \omega_i)$ be the hit-point for the raycast. Assuming there’s no participating media, radiance is constant along rays through the scene and therefore $L(y, -\omega_i) = L(p, \omega_i)$ (we can drop the suffix from $L_i$ and $L_o$ for simplicity). If we just want to consider all points above the hemisphere of $x$, we will need to introduce visibility function $V(x, y)$ between the two points $x$ and $y$. Finally, we will need to account for the change of domain of integration from differential solid angle $d\omega_i$ to differential area $dA_y$:

$\displaystyle \quad d\omega_i = \frac{|cos\theta_y|}{{r_{xy}}^2} \; dA_y$

To simplify notation, we will introduce geometric term $G(x, y)$:

$\displaystyle \quad G(x, y) = \frac{|cos \theta_x| \; |cos\theta_y|}{{r_{xy}}^2}$

Note:

- $|cos \theta_x| = max(n \cdot \omega_i, 0)$
- $|cos \theta_y| = max(n \cdot -\omega_i, 0)$

Which yields the following equation for surfaces:

$\displaystyle \quad L(x, \omega_0) = L_e(x,\omega_0) + \int_{M} f(x,\omega_o,\omega_i) \; L(y, -\omega_i) \; V(x, y) \; G(x, y) \; dA_y$

## Table of Contents

## Radiometry

In order to understand the rendering equation, it’s important to get familiar with basic radiometric quantities oftenly used in rendering: *flux*, *irradiance*, *radiant exitance*, *intensity* and *radiance*. They are basically different ways of measuring photons. A photon at wavelength $\lambda$ carries energy $Q = \frac{h c}{\lambda}$ where *h* is Planck’s constant and *c* is the speed of light. The four basic quantities can be derived from energy (J) by taking limits over time, area and directions.

Quantity | Formula | Unit | Definition |
---|---|---|---|

(Radiant) Flux | $$\displaystyle \Phi = \frac{dQ}{dt}$$ | $$W$$ | Total amount of energy passing through surface per unit time (J/s). Also known as power. |

Irradiance | $$\displaystyle E = \frac{d\Phi}{dA}$$ | $$W/m^2$$ | Area density of arriving at a surface. |

Radiant exitance | $$\displaystyle M = \frac{d\Phi}{dA}$$ | $$W/m^2$$ | Area density of flux leaving a surface. |

(Radiant) Intensity | $$\displaystyle I = \frac{d\Phi}{d\omega} $$ | $$W/sr$$ | Angular density of emitted power. Intensity describes directional distribution of light but only meaningful for point light sources. |

Radiance | $$\displaystyle L = \frac{d\Phi}{d\omega \; dA \; cos\theta}$$ | $$W/(m^2 sr)$$ | Flux density per unit area, per unit solid angle. |

## Irradiance

Irradiance is an average density of power over a finite area $\displaystyle E = \frac{\Phi}{A}$. We can compute *irradiance at point* $E(p)$ by taking the $\displaystyle \lim_{A \to 0} \frac{\Delta \Phi(p)}{\Delta A} = \frac{d\Phi}{dA}$.

Irradiance can also be computed by taking integral of radiance:

$\quad E(p,n) = \displaystyle \int_{S^2} L_i(p, \omega) \; |cos \theta| \; d\omega$

#### Irradiance via Monte Carlo

We can compute irradiance vis *Monte Carlo* estimator $\hat{E} = \frac{1}{N} \sum_{i=0}^{N-1} \frac{f(X_i)}{pdf(X_i)}$.

For *uniform hemisphere sampling*, pdf is just a constant $\frac{1}{2 \pi}$, which makes the estimator to be:

$\quad \hat{E} = \displaystyle \frac{2 \pi}{N} \sum_{i=0}^{N-1} L_i \; cos \theta$

For *cosine hemisphere sampling*, pdf becomes $\frac{cos \theta}{\pi}$, which makes the estimator to be:

$\quad \hat{E} = \displaystyle \frac{\pi}{N} \sum_{i=0}^{N-1} L_i$

## Solid Angle

Solid angle $\Omega$ is defined as:

$\displaystyle \quad \Omega = \frac{A}{r^2}$

where $A$ is the *spherical surface area* and $r$ is the radius of a sphere.

#### Differential Solid Angle

Given a unit sphere parameterized by $(\phi, \theta)$

$\quad x = sin\theta \; cos\phi \\ \quad y = sin\theta \; sin\phi \\ \quad z = cos\theta$

the differential solid angle is

$\quad d\Omega = sin(\theta) d\theta d\phi$

#### Spherical Cap

The projection of a sphere onto a surface of another sphere is *spherical cap*. Solid angle of spherical cap with apex angle $2\theta$ is given by:

$\quad \Omega = 2 \pi (1 - cos\theta)$

We can use this to approximate sphere radius $R$ at distance $d$ given solid angle $\Omega$ (only valid when $d >= R$):

$\quad sin\theta = \frac{R}{d}$

$\quad R^2 = d^2 \; (1 - (1 - \frac{\Omega}{2\pi})^2) = d^2 \; \frac{\Omega}{2\pi} (2 - \frac{\Omega}{2\pi})$

## Notation

#### Linear Operators

Sometimes the rendering equation is written in *operator equations* which tend to be more concise than the integral equation.

**K**is the*local reflection operator*that maps the field/incoming radiance function to the surface radiance function after one reflection (think BRDF).**G**is the*field radiance operator*that expressed the incident field radiance at each point in terms of the surface radiance of the surrounding environment. $$\displaystyle (\bm{G}L)(p,\omega) \equiv L(ray(p,\omega), \omega)$$ $ray(p, \omega)$ is a raycast function that returns the first hit point.

## References

- The Light Transport Equation: http://www.pbr-book.org/3ed-2018/Light_Transport_I_Surface_Reflection/The_Light_Transport_Equation.html
- Radiometry: https://pbr-book.org/3ed-2018/Color_and_Radiometry/Radiometry
- A Framework for the Analysis of error in Global Illumination Algorithms: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.114.5283&rep=rep1&type=pdf