Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project 4: Yu-Chia Shen #21

Open
wants to merge 5 commits into
base: base-code
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 96 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,102 @@ CUDA Denoiser For CUDA Path Tracer

**University of Pennsylvania, CIS 565: GPU Programming and Architecture, Project 4**

* (TODO) YOUR NAME HERE
* Tested on: (TODO) Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab)
* Yu-Chia Shen
* [LinkedIn](https://www.linkedin.com/in/ycshen0831/)
* Tested on: Windows 10, i5-11400F @ 4.3GHz 16GB, GTX 3060 12GB (personal)

### (TODO: Your README)
# Overview
This project is to build a denoiser using colors and 2 geometry buffer: normals, and positions. The effect of the denoiser can smooth the image while not blur the edges between objects. The technique is based on the paper "Edge-Avoiding A-Trous Wavelet Transform for fast Global Illumination Filtering". You can find the paper here: https://jo.dreggn.org/home/2010_atrous.pdf

*DO NOT* leave the README to the last minute! It is a crucial part of the
project, and we will not be able to grade you without a good README.
![](./img/Laterns.png)

# Result

## **Before & After Comparison**
| Raw Image | After Denoise |
| :--------------------------: | :-------------------: |
| ![](./img/before.png) | ![](./img/after.png) |

| Blur Image | After Denoise |
| :--------------------------: | :-------------------: |
| ![](./img/beforeBlur.jpg) | ![](./img/after.png) |

## **GBuffer**
| Normal Buffer | Position Buffer |
| :--------------------------: | :-------------------: |
| ![](./img/normals_img.png) | ![](./img/positions_img.png) |

# Performance Analysis

## Time Analysis for Denoiser

The following chart shows that the Denoiser time is approximately the same as the ray tracer in one iteration. Also, since denoise only needed to be applied in the final iteration, it doesn't not affect the whole render too much. It only count as one iteration of the ray tracer.

![](./img/Resolution%20(pixel)%20vs%20Run%20Time%20(ms)%20vs%20iter.png)

## Visual Effect Analysis

### Visual Effect
| Iteration 1000 without Denoiser | Iteration 6000 without Denoiser | Denoised Image 100 iteration
| :--------------------------: | :-------------------: | :-------------------: |
| ![](./img/iteration/a1000.png) | ![](./img/iteration/a6000.png) | ![](./img/iteration/aResult.png) |

We can see that the image needed 6000 iteration to achieve the effect of the denoiser. Even go throught 1000 iteration, the image is still noisy when zoom in. Therefore, the denoiser can greatly improve the visual effect with very less iteration.

### Image Difference Using tools
| Iteration 500 without Denoiser | Difference | Denoised Image 100 iteration
| :--------------------------: | :-------------------: | :-------------------: |
| ![](./img/iteration/cornell.2022-10-22_23-16-51z.500.0samp.png) | ![](./img/vs/vs500.png) | ![](./img/denoiseResult.png) |

| Iteration 1000 without Denoiser | Difference | Denoised Image 100 iteration
| :--------------------------: | :-------------------: | :-------------------: |
| ![](./img/iteration/cornell.2022-10-22_19-24-22z.1000.0samp.png) | ![](./img/vs/vs1000.png) | ![](./img/denoiseResult.png) |

| Iteration 6000 without Denoiser | Difference | Denoised Image 100 iteration
| :--------------------------: | :-------------------: | :-------------------: |
| ![](./img/iteration/cornell.2022-10-22_19-24-22z.6000.5samp.png) | ![](./img/vs/vs6000.png) | ![](./img/denoiseResult.png) |

## **Resolution vs Execute Time**
![](./img/chart/Resolution%20(pixel)%20vs%20Run%20Time%20(ms).png)

## **Filter Size vs Execute Time**
![](./img/chart/Filter%20Size%20(pixel)%20vs%20Run%20Time%20(ms).png)

## **Visual Effect with different Iteration**
| Denoised Image 5 iteration| Denoised Image 10 iteration | Denoised Image 20 iteration
| :--------------------------: | :-------------------: | :-------------------: |
| ![](./img/denoiseIter/cornell.2022-10-22_23-28-04z.5.5samp.png) | ![](./img/denoiseIter/cornell.2022-10-22_23-28-04z.10.4samp.png) | ![](./img/denoiseIter/cornell.2022-10-22_23-28-04z.20.3samp.png) |

| Denoised Image 40 iteration| Denoised Image 80 iteration | Denoised Image 100 iteration
| :--------------------------: | :-------------------: | :-------------------: |
| ![](./img/denoiseIter/cornell.2022-10-22_23-28-04z.40.2samp.png) | ![](./img/denoiseIter/cornell.2022-10-22_23-28-04z.80.1samp.png) | ![](./img/denoiseIter/cornell.2022-10-22_23-28-04z.100.0samp.png) |

We can see that the visual quality improve when we use more iterations. However, there is a limit for high iteration. The images with 80 iteration and 100 iteration seems the same.

## **Visual Effect with different Filter Size**
| 8 x 8 | 20 x 20 | 40 x 40 |
| :--------------------------: | :-------------------: | :-------------------: |
| ![](./img/visual_filter_size/f8.png) | ![](./img/visual_filter_size/f20.png) | ![](./img/visual_filter_size/f40.png) |

| 80 x 80 | 200 x 200 | 400 x 400|
| :--------------------------: | :-------------------: | :-------------------: |
| ![](./img/visual_filter_size/f80.png) | ![](./img/visual_filter_size/f200.png) | ![](./img/visual_filter_size/f400.png) |

You can see that the visual quality improve while increasing the filter size. The surface of the objects are smoother when filter size is larger. However, there is a limit for the filter size. When the filter size is larger than 80 x 80, the visual improvement is no longer exist. That means the visual quality does not scale uniformly with the filter size.

## Visual Effect with Different Material

| Material Type | Before | After |
| :--------------------------: | :-------------------: | :-------------------: |
| Diffuse | ![](./img/material/diffuse.png) | ![](./img/material/diffuseDenoise.png) |
| Specular | ![](./img/before.png) | ![](./img/after.png) |

We can see that the denoise effect is better on diffuse object than specular objects. The contour of the specular is blured after denoise.

## Visual Effect with Different Scenes
| Light Source | 100 iteration | 1000 iteration |
| :--------------------------: | :-------------------: | :-------------------: |
| Small Light Source | ![](./img/NewScene/cornell.2022-10-22_23-49-30z.101.1samp.png) | ![](./img/NewScene/cornell.2022-10-22_23-49-30z.1026.3samp.png) |
| Large Light Source | ![](./img/after.png) | ![](./img/NewScene/Large.png) |

We can see that for 100 iteration, large light source has better denoised result. This is because before denoise, small light source has a more noisy image. Therefore, too many noise in the image result in a poor denoiser effect. However, when the image converge after 1000 iteration, the denoiser effect become better.
Binary file added img/Filter Size (pixel) vs Run Time (ms) (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 img/Filter Size (pixel) vs Run Time (ms).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 img/NewScene/Large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 img/after.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 img/before.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 img/beforeBlur.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 img/chart/Resolution (pixel) vs Run Time (ms).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 img/cornell.2022-10-22_04-08-05z.0samp.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 img/cornell.2022-10-22_04-08-05z.100samp.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 img/cornell.2022-10-22_04-08-05z.25samp.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 img/cornell.2022-10-22_04-08-05z.50samp.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 img/cornell.2022-10-22_04-08-05z.75samp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 img/denoiseResult.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 img/iteration/a1000.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 img/iteration/a6000.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 img/iteration/aResult.png
Binary file added img/material/diffuse.png
Binary file added img/material/diffuseDenoise.png
Binary file added img/normals_img.png
Binary file added img/positions_img.png
Binary file added img/visual_filter_size/0.png
Binary file added img/visual_filter_size/f20.png
Binary file added img/visual_filter_size/f200.png
Binary file added img/visual_filter_size/f40.png
Binary file added img/visual_filter_size/f400.png
Binary file added img/visual_filter_size/f8.png
Binary file added img/visual_filter_size/f80.png
Binary file added img/vs/vs1000.png
Binary file added img/vs/vs500.png
Binary file added img/vs/vs6000.png
8 changes: 7 additions & 1 deletion scenes/cornell_ceiling_light.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ EMITTANCE 0
CAMERA
RES 800 800
FOVY 45
ITERATIONS 10
ITERATIONS 1000
DEPTH 8
FILE cornell
EYE 0.0 5 10.5
Expand Down Expand Up @@ -115,3 +115,9 @@ material 4
TRANS -1 4 -1
ROTAT 0 0 0
SCALE 3 3 3






22 changes: 18 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ static double lastY;
int ui_iterations = 0;
int startupIterations = 0;
int lastLoopIterations = 0;
int lastPosWeight = 0;
int lastNormalWeight = 0;
int lastColorWeight = 0;
bool ui_showGbuffer = false;
bool ui_denoise = false;
int ui_filterSize = 80;
float ui_colorWeight = 0.45f;
float ui_normalWeight = 0.35f;
float ui_positionWeight = 0.2f;
bool ui_saveAndExit = false;
extern int ui_typeGbuffer = 0;

static bool camchanged = true;
static float dtheta = 0, dphi = 0;
Expand All @@ -45,6 +49,8 @@ int iteration;
int width;
int height;

int num_pic = 0;

//-------------------------------
//-------------MAIN--------------
//-------------------------------
Expand Down Expand Up @@ -112,7 +118,7 @@ void saveImage() {

std::string filename = renderState->imageName;
std::ostringstream ss;
ss << filename << "." << startTimeString << "." << samples << "samp";
ss << filename << "." << startTimeString << "." << samples << "." << num_pic++ << "samp";
filename = ss.str();

// CHECKITOUT
Expand Down Expand Up @@ -162,18 +168,26 @@ void runCuda() {

// execute the kernel
int frame = 0;
pathtrace(frame, iteration);
pathtrace(frame, iteration, ui_iterations == iteration);
}

if (ui_showGbuffer) {
showGBuffer(pbo_dptr);
} else {
showGBuffer(pbo_dptr, iteration, ui_typeGbuffer);
}
else if (ui_denoise) {
showImageDenoise(pbo_dptr, iteration);
}
else {
showImage(pbo_dptr, iteration);
}

// unmap buffer object
cudaGLUnmapBufferObject(pbo);

if (iteration != 0 && iteration % 1000 == 0 && iteration != ui_iterations) {
saveImage();
}

if (ui_saveAndExit) {
saveImage();
pathtraceFree();
Expand Down
1 change: 1 addition & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ extern float ui_colorWeight;
extern float ui_normalWeight;
extern float ui_positionWeight;
extern bool ui_saveAndExit;
extern int ui_typeGbuffer;

void runCuda();
void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods);
Expand Down
Loading