# Monte Carlo sampling

REDsdk uses sampling methods based on Monte Carlo approximation to solve complex physical problems. We'll discuss this more in depth in this chapter.

## A word on Monte Carlo sampling

The resolution of a complex physical phenomenon can rarely be achieved using direct mathematical methods. Equations to solve are just too complex. In computer graphics, it often starts with that sort of things: A typical lighting equation.

It's ugly, don't you think? So this can't be directly solved. Given the ultimate goal of producing realistic images, rendering engines have to find a way to get approximative results for these evil equations. Monte Carlo based methods offer a good way to achieve our objectives.

In a word, Monte Carlo methods rely on a repeated random sampling to obtain a numerical result (http://en.wikipedia.org/wiki/Monte_Carlo_method). The idea is to take samples, measure each of them and consolidate the sum to get an average numerical estimation of the phenomenon that we're trying to solve. In computer graphics, this has a lot of applications. If we consider the example of shadow casting from a wide source of light with blocking geometry on the path, Monte Carlo sampling methods provide these results: Monte Carlo sampling applied to shadow casting.

More samples mean a more accurate result. Hence the most visible consequence of using Monte Carlo methods for rendering is noise. More samples means less noise in the resulting image, but more samples also means more time needed to render the image. Consequently, all is about choosing the right number of samples for the right quality versus the right performance.

In REDsdk, there are several phenomena that get sampled using Monte Carlo methods: 