CSE168 Project 2

Direct Lighting with Monte Carlo Integration

$$
L_d(x, \omega_o) \approx L_i \frac{A}{N} \cdot
\sum_{k = 1}^{N}f\left(x, \omega_i(k), \omega_o\right)
\frac{\cos \theta_i \cdot \cos \theta_o}{\mid x - x_k’\mid^2}
V(x, x_k’)
$$

Introduction

In this project, I implemented direct light sampling of area light sources with Monte Carlo integration. The equation above represents the Monte Carlo integration of one area light source $L_i$ with $N$ samples. The final color of one pixel is essentially the sum of emission and direct lightings from all area light sources.

Below are some output results. Click them to view larger images:

Sphere Cornell Box Dragon
Sphere Cornell Box Dragon

Variance and Noise

Notice that noises can be found in the image, especially in the shadows. This is caused by the variance of Monte Carlo integration with finite number of samples. As the number of samples increases, the variance could decrease, but just at a linear rate. So, apart from randomly sampling the area light, a stratified sampling method was implemented to further reduce the variance. Stratified sampling method divides the area light into little grids, and samples from each grid. This process essentially makes samples more uniformly distributed than purely random distribution, and thus reduce the noise.

9 Random Sampling 3x3 Stratified Random Sampling
9 Random Sampling 3x3 Stratified Random Sampling

More Variance Reduction Methods

After writing the stratified sampling integrator, I also implemented two extra variance reduction methods.

Biased Center Sampling

The first one is to sample area light source at the center, and only sample randomly for visibility. This method is biased, but could completely remove noise in area without shadows. Codes are written in OptiXRenderer/DIrectBiased.cu.

The image below sampled the area light source only at the center. So, although there is no noise, the image is totally wrong and has visible bias.

9 Biased Sampling

The bias can be reduced in combination with stratified sampling such that we are not just sampling the single center of the area light, but several centers of the little grids in the area light. The image below sampled centers from 3x3 stratified grids of the area light source. It appears very similar to the physically correct result, and there is no noise at all.

3x3 Stratified Biased Sampling 3x3 Stratified Random Sampling
3x3 Stratified Biased Sampling 3x3 Stratified Random Sampling
Bias: $-0.2$, Variance: 0.3 Bias: 0.0, Variance: 3.8

As the number of grids increases, the bias can be further reduced. Below are more comparisons between this biased method sampling at center, and random sampling method.

5x5 Stratified Biased Sampling 5x5 Stratified Random Sampling
Biased Sphere Sphere
Bias: -0.1, Variance: 1.4 Bias: 0.0, Variance: 2.8
Biased Cornell Box Cornell Box
Bias: 0.0, Variance: 0.5 Bias: 0.0, Variance: 1.0
Biased Dragon Dragon
Bias: 0.0, Variance: 0.5 Bias: 0.0, Variance: 0.8

In the sphere scene and Cornell box scene, there are clearly less noise in areas without shadows. For example, the upper hemisphere is very smooth because there is no obstacle blocking it. However, this effect is not obvious in the dragon scene. In addition, because of this center sampling pattern is fixed across all pixels, some binding effects can be spotted in the left lower corner of the dragon scene. Overall, this method can significantly reduce noise in areas without shadows, but has no improvement on shadows, and may even cause banding issues in the shadows.

Low Discrepancy Sequence Sampling

While we enforce uniform distribution in stratified random sampling by cutting area light into grids, another approach is to directly generate numbers that area uniformly distributed. Formally, such numbers form a low discrepancy sequence, and Monte Carlo integration using low discrepancy sequence is called quasi Monte Carlo method. Below I will just refer this method as quasi random method for simplicity.

I searched for some low discrepancy sequences, and initially want to implement a Sobol sequence generator to use in the integrator. However, I failed to comprehend all the math behind it, and in the end chose a simpler one called Van der Corput sequence. Since the integrator need to sample at a 2D area light source, I used two Van der Corput sequences, and this multidimensional generalization is called Halton sequence. Codes are written in OptiXRenderer/lowdis.h and OptiXRenderer/DirectQuasi.cu.

9 Quasi Random Sampling 9 Random Sampling 3x3 Stratified Random Sampling
9 Quasi Random Sampling 9 Random Sampling 3x3 Stratified Random Sampling
Bias: 0.0, Variance: 3.7 Bias: 0.0, Variance: 28.9 Bias: 0.0, Variance: 3.8

Images above show how the quasi random method reduced the variance without using stratification. It does not introduce any bias, and the final result is comparable with stratified random sampling with same number of samples. This is expected as both methods enforce better uniform distribution. Below are more comparisons between quasi random method and stratified random method.

25 Quasi Random Sampling 5x5 Stratified Random Sampling
Quasi Sphere Sphere
Bias: 0.0, Variance: 3.5 Bias: 0.0, Variance: 2.8
Quasi Cornell Box Cornell Box
Bias: 0.0, Variance: 1.1 Bias: 0.0, Variance: 1.0
Quasi Dragon Dragon
Bias: 0.0, Variance: 0.9 Bias: 0.0, Variance: 0.8

Overall, this quasi random method produces similar results as stratified random method. There is no bias or binding effect, which makes it an equivalently good alternative to the stratified random method. Because of my naïve implementation of sequence generator, the quasi random method does not have obvious performance difference from stratified random method. But since no stratification is required in quasi random method, it may gain better performance from getting rid of iteration. The Sobol sequence included in the reference could be a good choice since it replaces a lot of arithmetics with efficient bit operations.

Full Reports of Submissions to UCSD Online

Here are the link to reports generated on UCSD Online:

Reference

CSE168 Final Project Proposal CSE168 Project 1
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×