Skip to content

Commit

Permalink
Added in matt's stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
noah-ku committed Mar 18, 2024
1 parent 061907a commit 537b43e
Show file tree
Hide file tree
Showing 38 changed files with 166 additions and 22 deletions.
Binary file added assets/images/hw3/part2/CBlucy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part2/beast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part2/cow1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part2/cow2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part2/cow3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part2/maxplanck.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part2/peter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part2/raySlide.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part2/withBVH.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part2/withoutBVH.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part3and4/bunny0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part3and4/bunny1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part3and4/bunny2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part3and4/bunny3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part3and4/bunny4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part3and4/bunny5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part3and4/bunnyFalse1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part3and4/bunnyFalse2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part3and4/bunnyFalse3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part3and4/bunnyFalse4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part3and4/bunnyFalse5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part3and4/part3-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part3and4/part3-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part3and4/part3-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part3and4/part3-64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/hw3/part3and4/part3C-4.png
Binary file added assets/images/hw3/part3and4/part3CH4.png
Binary file added assets/images/hw3/part3and4/part3H1.png
Binary file added assets/images/hw3/part3and4/part3H16.png
Binary file added assets/images/hw3/part3and4/part3H4.png
Binary file added assets/images/hw3/part3and4/part3H64.png
Binary file added assets/images/hw3/part3and4/part4R0.png
Binary file added assets/images/hw3/part3and4/part4R1.png
Binary file added assets/images/hw3/part3and4/part4R100.png
Binary file added assets/images/hw3/part3and4/part4R2.png
Binary file added assets/images/hw3/part3and4/part4R3.png
Binary file added assets/images/hw3/part3and4/part4R4.png
188 changes: 166 additions & 22 deletions homework3.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,60 +82,204 @@ there can be either 0, 1, or 2 intersections when a ray passes a circle. This wa
![Spheres](./assets/images/hw3/part1/CBspheres.png)

# Part 2: Bounding Volume Hierarchy
## Task 0: Timing Experiment
## Task 1: Constructing the BVH

PLACEHOLDER
Rendering a lot of these scenes that have many triangles will take very long, so we had to switch to a faster algorithm. By switching to a BVH (Bounding Volume Hierarchy) algorithm, we can reduce the runtime from O(N) to O(log N). To do this, we had to first construct the BVH tree. To construct a tree, we had to think about how we wanted to implement a base case. As seen from the instructions, we want to
keep splitting boundaries until the number of objects in our boundary is less than or equal to `max_leaf_size`. Next, we had to figure out when to recursively call and what heuristic to use.

## Task 1: Constructing the BVH
The main heuristic we used to determine where to split was to take the spatial median. What this means is that we would look for the axis with the greatest extent and try to partition it in a way that splits as evenly as possible. To do this, we determined the axis with the highest spread (either X, Y, Z). Afterwards, we sort the primitives based on their centroid's positions. This
makes it very easy to know where to split since you can determine the "middle" of all the primitives. Finally, we partition from the median by calling `construct_bvh` recursively on one side (from `start` to `middle`) and recursively on the other (`middle` to `end`). After assigning these recursive calls to variables called `leftNode` and `rightNode`, we set the node's variables such as `l`
and `r` to be those nodes, and also set `node->bb` to be the bounding box we set earlier. We decided to go with the spatial median heuristic since it was relatively simple and was also easier to debug.

<br>

*Cow (Root)*
![Cow 1](./assets/images/hw3/part2/cow1.png)

*Cow (Root->Right)*
![Cow 2](./assets/images/hw3/part2/cow2.png)

*Cow (Root->Right->Right)*
![Cow 3](./assets/images/hw3/part2/cow3.png)

PLACEHOLDER

## Task 2: Intersecting the Bounding Box

PLACEHOLDER
The next part that we had to implement was the function `BBox::intersect`. For each axis, we had to do a series of steps. First, we had to check to see if the axis on `r.d` was equal to 0. If it is, that means it's parallel. We also check to see if that same axis for `r.o` is between the limits. If it isn't, we don't have to continue further; we can just return false.
Next, we can solve for `tmin` and `tmax` of the axis. We set the highest of `t0` and `tmin` as `t0` and the lowest of `t1` and `tmax` as `t1`. If `t0` is greater than `t1`, we return false since there was no intersection.

We repeat these for all the axes, so we need to keep restricting the bounds for x, y, and z. All these steps were derived from the lecture slide given to us in class.

<br>

*Lecture Slide on Bounding Boxes*
![Ray Slide](./assets/images/hw3/part2/raySlide.jpg)

## Task 3: Intersecting the BVH

PLACEHOLDER
Finally, we have to implement intersection detection for BVHs. We followed a pretty similar algorithm to `construct_bvh`, where the only difference is that we are using traversal. When a ray is cast, it either hits the left bounding box or the right bounding box. We keep recursively calling this function to explore the region that the ray is located in until we reach the
smallest box possible that has `max_leaf_size` or fewer primitives. When we reach this bounding box, we iterate through all primitives located in this targeted bounding box and start checking to see if there were any intersections with the actual primitives instead of just the box. We return true if there was an intersection with one of these primitives, and false if none were
hit. For `has_intersection`, we just have to check if any have an intersection, but for `intersect`, we had to keep track of the number of intersections and find the nearest one as well.

Here are some of our renders with the new O(log N) BVH implementation.

<br>

*Lucy*
![Ray Slide](./assets/images/hw3/part2/CBlucy.png)

*Beast*
![Ray Slide](./assets/images/hw3/part2/beast.png)

*Max Planck*
![Ray Slide](./assets/images/hw3/part2/maxPlanck.png)

*Peter*
![Ray Slide](./assets/images/hw3/part2/peter.png)

## Speed Analysis

We see a very noticeable difference when rendering with and without the BVH implementation. The default implementation loops through triangles one by one, which will be very slow if you reach thousands of primitives. As seen from the screenshots, rendering the `maxplanck.dae` with the naive implementation takes around 99 seconds to complete. On the other hand, the BVH implementation
only takes 0.05 seconds to complete. This is because a O(log N) implementation is much faster than an O(N), even if you scale N to be very high.

<br>

*Rendering Speed* ***Without*** *BVH*
![Without BVH](./assets/images/hw3/part2/withoutBVH.png)

*Rendering Speed* ***With*** *BVH*
![With BVH](./assets/images/hw3/part2/withBVH.png)


# Part 3: Direct Illumination
## Task 1: Diffuse BSDF
## Tasks 1-4

PLACEHOLDER
In our `estimate_direct_lighting_hemisphere`, we have a number of samples and we want to iterate by that amount. Using `w_out` that was provided and `w_i` and `pdf` that we created, we pass that into the `sample_f` function to get the Lambertian BSDF value. Then, using the Monte Carlo Estimator, we calculate the light for the next ray and interact using the `bvh->intersect` function, summing all the light and dividing by the number of samples.

## Task 2: Zero-bounce Illumination
For `estimate_direct_lighting_importance`, it's similar to the previous function, which is hemisphere, but with a bit of difference. We account for the number of lights in the scene and sample using the `sample_L` function that's in `scene->light`. Based on this, we have an inner for loop that iterates `ns_area_light` times. In the inner loop, we create a next ray that intersects, and using variables we got from `sample_L`, we calculate the amount and sum them up. Additionally, we also want to check if the light is a delta light, and if so, we want to stop the for loop. After the inner loop, we divide the sum of the light amount by the number of iterations and add to the total light sum.

PLACEHOLDER
We also have `zero_bounce_radiance` that simply returns `isect.bsdf->get_emission()`.

## Task 3: Direct Lighting with Uniform Hemisphere Sampling
Both of these function is called by one_bounce_radiance. Depends on the value of `direct_hemisphere` that was defined in the command line. Also, before calling this one_bounce radiance, we want to make sure that we call render the the light source by calling `zero_bounce_radiance` as well.

PLACEHOLDER
*Hemisphere 1 sample per pixel*
<br>
CBbunny with light 1
![Part 3 Bunny light 1 with H](./assets/images/hw3/part3and4/part3H1.png)
<br>
CBbunny with light 4
![Part 3 Bunny light 4 with H](./assets/images/hw3/part3and4/part3H4.png)
<br>
CBbunny with light 16
![Part 3 Bunny light 16 with H](./assets/images/hw3/part3and4/part3H16.png)
<br>
CBbunny with light 64
![Part 3 Bunny light 64 with H](./assets/images/hw3/part3and4/part3H64.png)

## Task 4: Direct Lighting by Importance Sampling Lights
<br>

PLACEHOLDER
*Importance 1 sample per pixel*
<br>
CBbunny light 1 without H
![Part 3 Bunny light 1 without H](./assets/images/hw3/part3and4/part3-1.png)
<br>
CBbunny light 4 without H
![Part 3 Bunny light 4 without H](./assets/images/hw3/part3and4/part3-4.png)
<br>
CBbunny light 16 without H
![Part 3 Bunny light 16 without H](./assets/images/hw3/part3and4/part3-16.png)
<br>
CBbunny light 64 without H
![Part 3 Bunny light 64 without H](./assets/images/hw3/part3and4/part3-64.png)

<br>

### Comparison Analysis
*Hemisphere*
<br>
![Part 3 sphere light 4 with H](./assets/images/hw3/part3and4/part3CH4.png)
<br>
*Importance*
<br>
![Part 3 sphere light 4 without H](./assets/images/hw3/part3and4/part3C-4.png)
<br>

Looking at these two pictures, we noticed that importance sampling is less noisy and has better quality of shadows. This is because the light sources on surfaces are more precisely simulated. On the other hand, for our Hemisphere sampling, we noticed that the lighting is more uniform and has higher noise in shadow.



# Part 4: Global Illumination
## Task 1: Sampling with Diffuse BSDF
## Tasks 1-3

PLACEHOLDER
In our `at_least_one_bounce_radiance`, we first check to see if `isAccumBounces` is false. If it is, we consider rendering the indirect lighting based only on `m`. Otherwise, we add `one_bounce_radiance` to `L_out` and proceed. For our Russian Roulette, we use 0.4 as recommended in the specification, and by using `coin_flip`, we determine whether to continue executing the code. If the function returns true, we call `sample_f` using `isect` obtained from the function parameter and pass in `wi`. Then, we check if it intersects with our newly created ray with the current depth minus one. If it does, we calculate `L_out` by calling `at_least_one_bounce_radiance` again, thereby recursively calculating one bounce at a time. In the case of `isAccumBounces` being false, we set `L_out` to equal the latest indirect light calculation.

## Task 2: Global Illumination with up to N Bounces of Light
As seen in the images, when `isAccumBounces` is set to false, we only capture indirect light. For example, at `-m 1`, we only see light that has bounced once, meaning we should not see the light source, which we don't. In contrast, when `isAccumBounces` is true, we can see the light source as well as walls/bunny that have been illuminated, because these include one-bounce lights.

PLACEHOLDER
For a high number of bounces, such as 100, we should not see a difference beyond the 10th bounce because, at 100 bounces, the radiance becomes so minimal or nonexistent that further bouncing is effectively inconsequential.

## Task 3: Global Illumination with Russian Roulette
*CBbunnies with mth-bounce with isAccumBounces True and 2048 samples*
<br>
Part 4 Bunny -m 0
![Part 4 Bunny -m 0](./assets/images/hw3/part3and4/bunny0.png)
<br>
Part 4 Bunny -m 1
![Part 4 Bunny -m 1](./assets/images/hw3/part3and4/bunny1.png)
<br>
Part 4 Bunny -m 2
![Part 4 Bunny -m 2](./assets/images/hw3/part3and4/bunny2.png)
<br>
Part 4 Bunny -m 3
![Part 4 Bunny -m 3](./assets/images/hw3/part3and4/bunny3.png)
<br>
Part 4 Bunny -m 4
![Part 4 Bunny -m 4](./assets/images/hw3/part3and4/bunny4.png)
<br>
Part 4 Bunny -m 5
![Part 4 Bunny -m 5](./assets/images/hw3/part3and4/bunny5.png)

PLACEHOLDER
<br>

## Task 4: Direct Lighting by Importance Sampling Lights
*CBbunnies with mth-bounce with isAccumBounces False and 2048 samples*
<br>
Part 4 Bunny -o 0 -m 0
![Part 4 Bunny -o 0 -m 0](./assets/images/hw3/part3and4/bunny0.png)
<br>
Part 4 Bunny -o 0 -m 1
![Part 4 Bunny -o 0 -m 1](./assets/images/hw3/part3and4/bunnyFalse1.png)
<br>
Part 4 Bunny -o 0 -m 2
![Part 4 Bunny -o 0 -m 2](./assets/images/hw3/part3and4/bunnyFalse2.png)
<br>
Part 4 Bunny -o 0 -m 3
![Part 4 Bunny -o 0 -m 3](./assets/images/hw3/part3and4/bunnyFalse3.png)
<br>
Part 4 Bunny -o 0 -m 4
![Part 4 Bunny -o 0 -m 4](./assets/images/hw3/part3and4/bunnyFalse4.png)
<br>
Part 4 Bunny -o 0 -m 5
![Part 4 Bunny -o 0 -m 5](./assets/images/hw3/part3and4/bunnyFalse5.png)

PLACEHOLDER
<br>

*Russian Roulette*
<br>
Part 4 Bunny Russian Roulette -m 0
![Part 4 Bunny Russian Roulette -m 0](./assets/images/hw3/part3and4/part4R0.png)
<br>
Part 4 Bunny Russian Roulette -m 1
![Part 4 Bunny Russian Roulette -m 1](./assets/images/hw3/part3and4/part4R1.png)
<br>
Part 4 Bunny Russian Roulette -m 2
![Part 4 Bunny Russian Roulette -m 2](./assets/images/hw3/part3and4/part4R2.png)
<br>
Part 4 Bunny Russian Roulette -m 3
![Part 4 Bunny Russian Roulette -m 3](./assets/images/hw3/part3and4/part4R3.png)
<br>
Part 4 Bunny Russian Roulette -m 4
![Part 4 Bunny Russian Roulette -m 4](./assets/images/hw3/part3and4/part4R4.png)
<br>
Part 4 Bunny Russian Roulette -m 100
![Part 4 Bunny Russian Roulette -m 100](./assets/images/hw3/part3and4/part4R100.png)


# Part 5: Adaptive Sampling
Expand Down

0 comments on commit 537b43e

Please sign in to comment.