Introduction & Background

In this note, we're going to talk about integration - and integral calculus! In the last few notes, we started looking at ray tracing, intersecting rays with 3D rays, and how to speed that up - and last note, we looked at systems of measuring light. We're going to use ray tracing to simulate the flow of light in modeled worlds, where we have light sources & materials, and light is bouncing around a scene until it hits a camera. In order to do that, we're going to do a lot of integration!

Reminder: Quadrature-Based Numeric Integration

As a quick reminder, one way to estimate simple integrals like the one below is to sample $f(x)$ values at different $x$ positions to estimate the area under the curve (e.g. trapezoid rule, Reimann sums, etc.). The more samples of $f(x)$ that we take, the better our estimate gets.

We can think of this as even, uniform sampling - a discretized estimation of this integral. This is not what we'll be doing today.

We can think of this as even, uniform sampling - a discretized estimation of this integral. This is not what we'll be doing today.

Before we get into the specifics, let's look at a few examples of where we use integration in graphics.

We can interpret what we did with regards to antialiasing as estimating the integral of a triangle over the area of a pixel.

We can interpret what we did with regards to antialiasing as estimating the integral of a triangle over the area of a pixel.

We also used an integral when calculating the irradiance from the environment. We integrate over all directions in the hemisphere.

We also used an integral when calculating the irradiance from the environment. We integrate over all directions in the hemisphere.

In order to calculate motion blur, we integrate over the area of pixel as well as over exposure time.

In order to calculate motion blur, we integrate over the area of pixel as well as over exposure time.

Here's a five-dimensional integral - we integrate over the 2D lens pupil (opening of the lens), 2D pixel area, and exposure over time.

Here's a five-dimensional integral - we integrate over the 2D lens pupil (opening of the lens), 2D pixel area, and exposure over time.

We'll be doing integrals that are much higher than five dimensions in order to render photorealistic images!

The Curse of Dimensionality

In high-dimensional integration, if we want a complete set of samples in our high dimension, we'll need to take a lot of samples that scale to the power $d$. If we wanted to take $N$ samples in $5$ dimensions, we'd have to take $N^5$ samples in order to estimate an integral.

![If we use the randomized approach, the error is going to be **less than that if we use numerical integration.

The punchline:** global illumination (the algorithm that we use to sample the space of rays populating the 3D world) involves infinite-dimension integrals, so we'll be strongly motivated to pursue the randomized approach.](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/403e94a8-a0ec-4d04-95f6-eb58c9160213/Untitled.png)

If we use the randomized approach, the error is going to be **less than that if we use numerical integration.

The punchline:** global illumination (the algorithm that we use to sample the space of rays populating the 3D world) involves infinite-dimension integrals, so we'll be strongly motivated to pursue the randomized approach.

Example: Discrete vs. Monte Carlo Integration

Let's look at a simple shadow example. In this scene, there's a little rectangular light source floating in the world, and a little polygon (square) blocking light from reaching the ground, which casts a shadow onto the ground.

If we were to do a discrete approach, we'd take one sample per pixel over the light source. This'll be a ray-tracing approach, where we look for every point in the final scene & ray-trace from the light source to the point and see whether it's blocked or not.

![On the left, we sample every single pixel and perform a ray-trace from the pixel to the light. But the edge being sharp doesn't really seem like accurate graphics; that's because there's an area light source at the top, where we can't capture the entire light source in a single ray from pixel → light.

In the middle, we get a soft (but noisy) shadow. Instead of tracing a ray to the center of the light source, we trace it to a random position on the light source, which gives us an estimate of the integral over that lighting.

On the right, we have what we'd get if we did this precisely. ](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/a08aa780-5d1e-4b3a-8102-e0fd0e88dcd3/Untitled.png)

On the left, we sample every single pixel and perform a ray-trace from the pixel to the light. But the edge being sharp doesn't really seem like accurate graphics; that's because there's an area light source at the top, where we can't capture the entire light source in a single ray from pixel → light.

In the middle, we get a soft (but noisy) shadow. Instead of tracing a ray to the center of the light source, we trace it to a random position on the light source, which gives us an estimate of the integral over that lighting.

On the right, we have what we'd get if we did this precisely.

Overview of Monte Carlo Integration