Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
21cffb4
Early Stages
Sep 25, 2019
44cef5c
Early Stages
Sep 25, 2019
865f12a
Changes made for part1
Sep 25, 2019
3db9797
Changes in part1
Sep 26, 2019
b63a059
Part1
Sep 26, 2019
ac8e3ad
Changes for part2
Sep 27, 2019
9cc0c19
Chnages to be taken
Sep 28, 2019
64fecbd
Changes for Part 2 with Work Efficient Stream Compaction
Sep 29, 2019
7af5d3f
Update README.md
somanshu25 Sep 29, 2019
f5f4e21
Update README.md
somanshu25 Sep 30, 2019
6ecd419
Update README.md
somanshu25 Sep 30, 2019
fc16e09
Update README.md
somanshu25 Sep 30, 2019
441806e
Add files via upload
somanshu25 Sep 30, 2019
a80288b
Update README.md
somanshu25 Sep 30, 2019
e197b52
Update README.md
somanshu25 Sep 30, 2019
2a69bf0
Update README.md
somanshu25 Sep 30, 2019
61772f1
Update README.md
somanshu25 Sep 30, 2019
d1a12df
Add files via upload
somanshu25 Oct 1, 2019
2bccf12
Update README.md
somanshu25 Oct 1, 2019
bd1d8f8
Add files via upload
somanshu25 Oct 1, 2019
0188212
Update README.md
somanshu25 Oct 1, 2019
03ecbcd
Update README.md
somanshu25 Oct 1, 2019
e29ac9f
Add files via upload
somanshu25 Oct 1, 2019
9ffbb63
Update README.md
somanshu25 Oct 1, 2019
df18d99
Update README.md
somanshu25 Oct 1, 2019
bb63145
Update README.md
somanshu25 Oct 1, 2019
8f24272
Add files via upload
somanshu25 Oct 1, 2019
8d8bac7
Update README.md
somanshu25 Oct 1, 2019
1a1b489
Update README.md
somanshu25 Oct 1, 2019
06b3840
Update README.md
somanshu25 Oct 1, 2019
6253e6a
Add files via upload
somanshu25 Oct 1, 2019
260d270
Update README.md
somanshu25 Oct 1, 2019
635f236
Update README.md
somanshu25 Oct 1, 2019
f273e5b
Update README.md
somanshu25 Oct 1, 2019
fc26565
Update README.md
somanshu25 Oct 1, 2019
ba0084e
Update README.md
somanshu25 Oct 1, 2019
3c9bd70
Update README.md
somanshu25 Oct 1, 2019
b438629
Final commit for the Project
Oct 1, 2019
e63e721
Merge branch 'master' of https://github.com/somanshu25/Project3-CUDA-…
Oct 1, 2019
bdd58b5
Add files via upload
somanshu25 Oct 1, 2019
3035397
Update README.md
somanshu25 Oct 1, 2019
df4b133
Merge branch 'master' of https://github.com/somanshu25/Project3-CUDA-…
Oct 1, 2019
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
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ set(headers
src/sceneStructs.h
src/preview.h
src/utilities.h
src/efficient.h
src/common.h
)

set(sources
Expand All @@ -84,6 +86,8 @@ set(sources
src/scene.cpp
src/preview.cpp
src/utilities.cpp
src/common.cu
src/efficient.cu
)

list(SORT headers)
Expand All @@ -92,10 +96,10 @@ list(SORT sources)
source_group(Headers FILES ${headers})
source_group(Sources FILES ${sources})

#add_subdirectory(stream_compaction) # TODO: uncomment if using your stream compaction
add_subdirectory(stream_compaction) # TODO: uncomment if using your stream compaction

cuda_add_executable(${CMAKE_PROJECT_NAME} ${sources} ${headers})
target_link_libraries(${CMAKE_PROJECT_NAME}
${LIBRARIES}
#stream_compaction # TODO: uncomment if using your stream compaction
stream_compaction # TODO: uncomment if using your stream compaction
)
120 changes: 115 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,123 @@
CUDA Path Tracer
================

<img src="https://github.com/somanshu25/Project3-CUDA-Path-Tracer/blob/master/img/scene_from_front.png" width="400"/><img src="https://github.com/somanshu25/Project3-CUDA-Path-Tracer/blob/master/img/scene_side.png" width="400"/>

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

* (TODO) YOUR NAME HERE
* Tested on: (TODO) Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab)
* SOMANSHU AGARWAL
* [LinkedIn](https://www.linkedin.com/in/somanshu25)
* Tested on: Windows 10, i7-6700 @ 3.4GHz 16GB, Quadro P1000 4GB (Moore 100B Lab)


### What is Path Tracer and how it is different from Ray Tracing?

Path tracing is a realistic lighting algorithm that simulates light bouncing around a scene. it is based on Monte-Carlo based sampling technique and simulate realistic images through rendering. The path tracer is continually rendering, so the scene will start off grainy and become smoother over time. Path tracing is a similar rendering technique as ray tracing except the fact that path tracing uses random sampling to incrementally compute a final image. The side by side comparision below shows the importance of rendering the scene in iterations which removed the blurring of the image and noise.

<p align="center">
After 200 iterations | After 1500 iterations
</p>
<p align="center">
<img src="img/img_diffuion_500_iter.png" width="300" alt="After 200 iteration" />
<img src="img/image_diffusion.png" width="300" alt="After 1500 iterations"/>
</p>

The following features are enabled in the path tracer:

* Basic Features:
* BSDF evaluation for Diffusion and Perfectly Specular Surfaces
* Sort the rays after intersection with material ID type it intersected
* Stream Compaction using Thrust
* Cache First Bounce

* Adanced Features:
* BSDF evaluation including Refraction, Fresnel Effect using Schlick's approximation
* BSDF evaluation for Different Percentage Comnibations for Refraction and Reflection
* Anit-aliasing
* Work-Efficient Stream Compaction using Shared Memory
* Motion Blur (attempted)

### BSDF Evaluation for Perfectly Specular, Diffusion Sufraces and Refraction Surfaces:
BSDF evaluation has been done for perfectly specular, diffusion and refractive surfaces. The evaluation was also done for specular surfaces where random combinations of reflection and refraction takes place. For reflection, I have used `glm::reflect` while for refraction, I have calculated the the value of index of refraction by assuming that one of the two medium will be air, caclulating the normal and using `glm::refract` function for caclulating the refracted ray. I'm also taking care of total internal reflection scenario. Also, the Fresnel effect is added into the shading using [Schlick's approximation](https://en.wikipedia.org/wiki/Schlick%27s_approximation).

<p align="center">
Perfectly Specular | Perfect Refraction | Diffusion
</p>

<p align="center">
<img src="img/img_perfect_specular.png" width="250" alt="Perfectly Specular" />
<img src="img/img_prefect_refraction.png" width="250" alt="Perfect Refraction"/>
<img src="img/image_diffusion.png" width="250" alt="Diffusion"/>
</p>


For diffusing, I have used the already defined cosign weighted distribution function for evaluating the new ray, which is the ransom permutation of the hemisphere. The images showing the effects of all these are:

For different combinations of relective and refractive probabilies, here are the effects shown in the images:

<p align="center">
Reflection:70%, Refract:30% | Reflection:30%, Refract:70%
</p>
<p align="center">
<img src="img/less_refrac_more_reflect.png" width="300" alt="Reflection:70%, Refract:30%" />
<img src="img/more_refrac_less_reflect.png" width="300" alt="Reflection:30%, Refract:70%"/>
</p>

In above, we can see for the material with more refract probabilty than reflect, the light is passing through and there is light in place of shadow.
### Sorting the rays by material ID

The rays after bouncing from the objects are sprted on the basis of the material ID, sicne, there is high chance that all these rays might strike the same object again and we have the rays at contigous memeory allocation in the memory which would quicken up the effect. In our cornell scene, we mostly observe that the sorting does not improve the performance that greatly because of lack of different materials in the scenes.

<p align="center"><img src="https://github.com/somanshu25/Project3-CUDA-Path-Tracer/blob/master/img/ray_sorting_graph.png" width="700"/></p>

### Stream Compaction by using Thrust Library and Work Efficient using Shared memory

The stream compaction has benn done in the path tracer using Thrust library initially so that the basic working of the path tracer could be verified. After designing the basic path tracer, I worked on performing Stream Compaction using Shared Memory. The algorithm uses two stages of scanning where the first scanning happens using Shared Memory. The performace as shown in the graphs below. After performing the Work Efficient usign Shared memory algorithm across the blocks, we are getting the last element of each of the block and adding the last element in the original array in the block and performing again scan operation on the new array. Referred for the following reference for writing the code [GPU Gem Ch 39 ](https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch39.html)

The graph below shows the runtime for Work Efficient Shared memory vs Thrust library. It clearly indicated that the work efficent implementation with Shared Memory is much faster than Thrust.

<p align="center"><img src="https://github.com/somanshu25/Project3-CUDA-Path-Tracer/blob/master/img/graph_stream_compaction_comparision.png" width="700"/></p>


### Caching the First Bounce

For each iteration, the rays are generated from the camera are likely to hit the same intersection material. Thus, computing the intersections every iteration would be costly and we can preserve that time by caching the first bounces that takes place in the first iteration and then later on just load those intersections for next iterations and prcess for the shading. The performance analysis for the caching and non-cahing as the function of depth in the first and second iteration is given below:

<p align="center"><img src="https://github.com/somanshu25/Project3-CUDA-Path-Tracer/blob/master/img/graph_cache_first_bounce_difference.png" width="700"/></p>

We can observe that for `depth = 0`, the runtime has increased drastically as we are not computing the intersections again.

### Anti-Aliasing

Anti-aliasing is the way of remove the jaggering happening during the rendering by sending out the rays from the camera and adding on the noise a little bit so that the smoothning effect could be seen the image. The effect of the anti-aliasing could be seen at the interections of the wall and the floor where the lines are more smoother as compared to the normal ones. The comparision of the effect is shown below:

<p align="center">
Without Anti-Aliasing | With Aliasing
</p>
<p align="center">
<img src="https://github.com/somanshu25/Project3-CUDA-Path-Tracer/blob/master/img/Image_before_aliasing_zoomin.png"="300" alt="Without Antialiasing" />
<img src="https://github.com/somanshu25/Project3-CUDA-Path-Tracer/blob/master/img//Image_after_aliasing_zoomin.png" width="300" alt="With Antialiasing"/>
</p>

Here, we can see that some of the jaggered lines in the left hand side which are not in the right hand side.

### Motion Blur

I have attemmpted to do motion blur n the path tracer and was going through lot of issues as the image is getting dark and lot of other stuff. The code for motion blur is in the code file "pathrace.cu".

### Bloopers

Some of the bloopers across all the experiments and features:

<p align="center"><img src="https://github.com/somanshu25/Project3-CUDA-Path-Tracer/blob/master/img/blooper%201.png" width="500"/></p>
On the above blooper, my refraction was wrong as I was always refractive and then checking the condtiino for reflection.

<p align="center"><img src="https://github.com/somanshu25/Project3-CUDA-Path-Tracer/blob/master/img/cornell.2019-09-26_03-37-21z.49samp.png" width="500"/></p>

When my stream cpoompaction Implementation was wrong with Work Efficient. I was not sorting in the last stage.

<p align="center"><img src="https://github.com/somanshu25/Project3-CUDA-Path-Tracer/blob/master/img/cornell.2019-09-27_00-14-50z.5000samp.png" width="500"/></p>

### (TODO: Your README)
This when I didn't invert the normal vector for checking the refraction.

*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.

Binary file added img/Image_after_aliasing.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/Image_after_aliasing_zoomin.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/Image_before_aliasing.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/Image_before_aliasing_zoomin.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/blooper 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/cornell.2019-09-26_03-37-21z.49samp.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.2019-09-26_03-37-47z.1500samp.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.2019-09-26_03-37-47z.95samp.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.2019-09-26_03-48-32z.5000samp.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.2019-09-27_00-14-50z.5000samp.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.2019-09-27_00-37-23z.5000samp.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.2019-09-27_01-48-07z.5000samp.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.2019-09-27_02-03-18z.2509samp.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.2019-09-27_02-08-58z.873samp.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.2019-09-27_02-37-04z.838samp.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.2019-09-27_02-54-34z.3518samp.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.2019-09-27_03-01-55z.5000samp.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/graph_cache_first_bounce_difference.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/graph_stream_compaction_comparision.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/image_diffusion.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/img_diffuion_500_iter.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/img_emissive.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/img_open_scene.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/img_perfect_specular.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/img_prefect_refraction.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/img_specular_less_refraction.png
Binary file added img/less_refrac_more_reflect.png
Binary file added img/live_rays_open_closed.png
Binary file added img/more_refrac_less_reflect.png
Binary file added img/ray_sorting_graph.png
Binary file added img/scene_from_front.png
Binary file added img/scene_side.png
10 changes: 5 additions & 5 deletions scenes/cornell.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ MATERIAL 4
RGB .98 .98 .98
SPECEX 0
SPECRGB .98 .98 .98
REFL 1
REFR 0
REFRIOR 0
REFL 0.7
REFR 0.3
REFRIOR 1.52
EMITTANCE 0

// Camera
CAMERA
RES 800 800
RES 720 720
FOVY 45
ITERATIONS 5000
DEPTH 8
Expand Down Expand Up @@ -114,4 +114,4 @@ sphere
material 4
TRANS -1 4 -1
ROTAT 0 0 0
SCALE 3 3 3
SCALE 3 3 3
117 changes: 117 additions & 0 deletions scenes/cornell2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Emissive material (light)
MATERIAL 0
RGB 1 1 1
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 5

// Diffuse white
MATERIAL 1
RGB .98 .98 .98
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0

// Diffuse red
MATERIAL 2
RGB .85 .35 .35
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0

// Diffuse green
MATERIAL 3
RGB .35 .85 .35
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0

// Specular white
MATERIAL 4
RGB .98 .98 .98
SPECEX 0
SPECRGB .98 .98 .98
REFL 1
REFR 0
REFRIOR 0
EMITTANCE 0

// Camera
CAMERA
RES 720 720
FOVY 45
ITERATIONS 5000
DEPTH 8
FILE cornell
EYE 0.0 5 10.5
LOOKAT 0 5 0
UP 0 1 0


// Ceiling light
OBJECT 0
cube
material 0
TRANS 0 10 0
ROTAT 0 0 0
SCALE 3 .3 3

// Floor
OBJECT 1
cube
material 1
TRANS 0 0 0
ROTAT 0 0 0
SCALE 10 .01 10

// Ceiling
OBJECT 2
cube
material 1
TRANS 0 10 0
ROTAT 0 0 90
SCALE .01 10 10

// Back wall
OBJECT 3
cube
material 1
TRANS 0 5 -5
ROTAT 0 90 0
SCALE .01 10 10

// Left wall
OBJECT 4
cube
material 2
TRANS -5 5 0
ROTAT 0 0 0
SCALE .01 10 10

// Right wall
OBJECT 5
cube
material 3
TRANS 5 5 0
ROTAT 0 0 0
SCALE .01 10 10

// Sphere
OBJECT 6
sphere
material 4
TRANS -1 4 -1
ROTAT 0 0 0
SCALE 3 3 3
Loading