## Table of Contents

# Introduction

During my Master’s 2016 winter term, I took Derek Nowrouzezahrai class called *Realistic and interactive rendering in digital medias*.

The main goal of this class was to implement multiples “tasks” in our own software to produce high quality rendering, studying different algorithms and techniques to achieve this goal.

You’ll find on this page a summary of my work, on sampling techniques, rendering algorithms, and BRDFs.

# Rendering equation and Monte Carlo integration

## Rendering equation

In computer rendering, we use a lot of differents equations, to take into account a multitude of differents effects and phenomena. But the most important one is the so-called *Rendering Equation* ^{1} :

$$ \begin{equation} L\left(x,\omega_o\right) = L_e\left(x,\omega_o\right) + \int _{\Omega} L\left(x’,-\omega_i\right) f_r\left(x,\omega_i,\omega_o\right) \left(\vec{n} \cdot \omega_i\right) d\omega_i \end{equation} $$

With each terms meaning:

- $L\left(x,\omega_o\right)$ is the total incoming light in the direction $\omega_o$ from the point $x$
- $L\left(x’,-\omega_i\right)$ is the incoming light from every direction $\omega_i$ in the integration domain $\Omega$, at point $x$
- $f_r\left(x,\omega_i,\omega_o\right)$ is the function describing the appearance of the surface at point $x$, looking in the direction $\omega_o$ with incoming light from $\omega_i$ : usually it’s a
*BRDF*(bidirectionnal reflectance distribution function). - $\left(\vec{n} \cdot \omega_i\right)$ is the cosine term weigthing the contribution of the light according to the surface normal and the $\omega_i$ direction.

## Monte Carlo integration

To solve the rendering equation, we use a mathematical tool called a Monte Carlo integration : it’s a schocastic approximation used to compute integrals.

The theory is :

Let’s assume we have an integral $F$ in any dimensions:
$$ F = \int _X f(x) dx$$
A *Monte Carlo* estimator of this integral will be:
$$\bar{F} = \frac{1}{N}\sum ^{N-1} _{i=0} \frac{f(X_i)}{pdf(X_i)} \approx \int _x f(x) dx $$

(And it’s easy to prove that the $E\left[\bar{F}\right] = F$)

It means that with $N$ numbers of *samples*, with $N$ approaches infinity, the estimator will yield the exact result.

The trickiest part is to find a proper probability density function (pdf), to approximate the $F$, which will define how we sample our random samples $X$.

So, with these tools in hand, a simple Monte Carlo algorithm to approximate an integral will look like:

- Find a good pdf to generate our random samples $X_i$
- Generate $N$ random samples
- Evaluate $\bar{F} = \frac{1}{N}\sum _{i=0}^{N-1}\frac{f(X_i)}{pdf(X_i)}$

In the context of the rendering equation, it means that we can build a Monte Carlo estimator of the rendering equation to numerically approximate its result.

Let’s quickly take a simple example : the case of ambient occlusion.

When we talk about ambient occlusion in a scene, we talk about how each points of the scene is exposed to the *skylight* : we assume that our scene is englobed in an hemisphere, and we want to know the proportion of it accessible from the surface.

The simplified version of the rendering equation to render AO (Ambient Occlusion) is:

$$ L_{ao}(x) = \int _{\Omega} \frac{max(\vec{n_x}\cdot \omega,0)}{\pi}V(x,\omega) d\omega $$

With $V(x,\omega)$ is the visibility term, a function yelding $1$ with we see the sky light or $0$.

A Monte-Carlo estimator of this equation is: $$ \bar{L_{ao}(x)} = \frac{1}{N}\sum _{i=0}^{N - 1} \frac{max(\vec{n_x}\cdot\omega,0) V(x,\omega)}{\pi pdf(\omega)} $$

So to compute the ambient occlusion with this Monte Carlo estimator, we just need to find a good pdf : one acceptable pdf is to sample the random directions $\omega$ on an hemisphere : we pick a random point on an unit hemisphere aligned on the normal of $x$, and we evaluate our estimator with this direction.

# Path tracing

So with the rendering equation in our head and a basic idea on how Monte Carlo integration is working, let’s talk about rendering real images !

The path tracing algorithm has been introduced at the same time than the rendering equation in 1986 by James Kajiya ^{2}.