Skip to content

CalvinRen/GAMES101-Homework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GAMES101-Homework

Homework of GAMES101: Introduction to Computer Graphics, instructed by Professor Linqi Yan.

Assignment0

Build up C++ Environment (OpenCV & Eigen)

HW1-Rotation and Translation

Rasterization of a triangle with rotation and translation.

HW2-Triangles and Z-buffering

Normal Version

MSAA Version

Implement MSAA by using supersampling to achieve anti-aliasing, and optimize the boundary, but there is a black edge at the intersection of triangles

MSAA Version with no black-edge

Remove the black edge at the intersection of triangles

Comparison

HW3-Shading

Normal Shader

Blinn-Phong Shader

Implemented Blinn-Phong Reflection model.

$$\begin{aligned} L &= L_{Ambient} + L_{Diffuse} + L_{Specular} \\ &= k_a * I_a + k_d * (I/r^2) * max(0, n \cdot l) + k_s * (I/r^2) * max(0, n \cdot h)^{p} \end{aligned}$$

Texture Shader

Add Texture Mapping to the Blinn-Phong Shader.

Bump Mapping Shader

Add Bump Mapping to the Blinn-Phong Shader.

Displacement Mapping Shader

Add Displacement Mapping to the Blinn-Phong Shader.

HW4-Bezier Curve

Naive Bezier Curves

Bernstein Form of Bezier Curve:
$$\textbf{b}^n(t) = \sum_{j=0}^{n}\textbf{b}_jB^n_j(t)$$ In this implementation, we recursively compute the control points of the Bezier curve.

Anti-Aliasing Bezier Curves

In order to achieve anti-aliasing, we use super sampling to sample the curve at a higher resolution.

Comparison

HW5-Ray Tracing and Triangle Intersection

Whitted-Style Ray Tracing.

$$Ray:\quad \textbf{r}(t)=\textbf{o}+t\textbf{d}, 0 \leq t < \infty$$ $$Sphere: \quad \textbf{p}:(\textbf{p}-\textbf{c})^2-R^2 = 0$$ When $(\textbf{o}+t\textbf{d}-\textbf{c})^2-R^2 = 0$, we have a solution for $t$: $$t = \frac{-b\pm \sqrt{b^2-4ac}}{2a} $$

Ray Intersection With Triangle

Muller Trumbore Algorithm:

$$ \begin{aligned} \overrightarrow{E_1} &= \overrightarrow{P_1} - \overrightarrow{P_0} \\ \overrightarrow{E_2} &= \overrightarrow{P_2} - \overrightarrow{P_0} \\ \overrightarrow{S} &= \textbf{O} - \overrightarrow{P_0} \\ \overrightarrow{S_1} &= \textbf{D} \times \overrightarrow{E_2} \\ \overrightarrow{S_2} &= \overrightarrow{S} \times \overrightarrow{E_1} \end{aligned} $$

$$ \begin{aligned} a &= \overrightarrow{S_1} \cdot \overrightarrow{E_1} \\ f &= \frac{1}{a} \\ t &= f * (\overrightarrow{S_2} \cdot \overrightarrow{E_2}) \\ u &= f * (\overrightarrow{S_1} \cdot \overrightarrow{S}) \\ v &= f * (\overrightarrow{S_2} \cdot \textbf{D}) \end{aligned} $$

When t > 0.0 && u > 0.0 && v > 0.0 && (1 - u - v) > 0.0, we have a solution for $t$.

HW6-Ray Bounding Box Intersection and BVH

Ray Bounding Box Intersection

Slabs perpendicular method:

$$ \begin{aligned} \textbf{t}{max} &= \frac{P{max} - \textbf{O}}{\textbf{D}} \ \textbf{t}{min} &= \frac{P{min} - \textbf{O}}{\textbf{D}} \ \textbf{t}{enter} &= max(\textbf{t}{min}) \ \textbf{t}{exit} &= min(\textbf{t}{max}) \end{aligned} $$

When $t_{enter} &lt; t_{exit}\ \land \ t_{exit} \ge0$ , ray intersects with the bounding box.

BVH

  • Find bounding box
  • Recursively split set of objects in two subsets
  • Recompute the bounding box of the subsets
  • Stop when necessary
  • Store objects in each leaf node

HW7-Path Tracing

Original Framework

  • SPP = 16
  • Render Time = 48min

Optimized Framework

  1. Multiple Thread (OpenMP)
#pragma omp parallel for
  1. Add SPP
    Set SPP = 1024.

  2. Anti-Aliasing
    Sample randomly over a range of pixels.

  3. Modify get_random_float()
    Due to the feature of random_device on Linux/Unix, the function uses the entropy pool provided by Operating System. When the entropy pool is exhausted, random_device blocks the call until there is enough entropy available, which therefore makes the function a time-consuming operation.
    In the given framework, random_device function was called frequently, resulting in an overall performance degradation.
    In order to optimize this function, we made the first three lines into static variables.

  4. Remove White Noise Point
    Since the PDF is sampled randomly, when the value of pdf closes to 0, the computed indirect light will be biased towards the limit value. Therefore, we only consider on computing the indirect light when $pdf &gt; \epsilon$.

Result

  • SPP = 1024
  • Render Time = 14min

About

GAMES101 Homework1-7

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published