Skip to content
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.gif filter=lfs diff=lfs merge=lfs -text
17 changes: 13 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ cmake_minimum_required(VERSION 3.0)

project(cis565_path_tracer)

# Crucial magic for CUDA linking
find_package(Threads REQUIRED)
find_package(CUDA 8.0 REQUIRED)

## Because screw life
## set(CUDACC_DEFINE -D__CUDACC__)

## Because fuck nvcc
## add_definitions(-D__CUDACC__)

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})

# Set up include and lib paths
Expand Down Expand Up @@ -60,17 +70,16 @@ if (WIN32)
list(APPEND CORELIBS legacy_stdio_definitions.lib)
endif()

# Crucial magic for CUDA linking
find_package(Threads REQUIRED)
find_package(CUDA 8.0 REQUIRED)

set(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE ON)
set(CUDA_SEPARABLE_COMPILATION ON)

if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CUDA_PROPAGATE_HOST_FLAGS OFF)
endif()

## Because screw life
set(CUDACC_DEFINE -D__CUDACC__)

include_directories(.)
#add_subdirectory(stream_compaction) # TODO: uncomment if using your stream compaction
add_subdirectory(src)
Expand Down
156 changes: 148 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,153 @@
CUDA Path Tracer
================
# **University of Pennsylvania, CIS 565: GPU Programming and Architecture, Project 3:**

**University of Pennsylvania, CIS 565: GPU Programming and Architecture, Project 3**
# **CUDA Path Real Time Path Tracer**

* (TODO) YOUR NAME HERE
* Tested on: (TODO) Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab)

### (TODO: Your README)

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


Tested on: Windows 10, Intel Core i7-7700HQ CPU @ 2.80 GHz, 8GB RAM, NVidia GeForce GTX 1050

![Built](https://img.shields.io/appveyor/ci/gruntjs/grunt.svg) ![Issues](https://img.shields.io/github/issues-raw/badges/shields/website.svg) ![CUDA 8.0](https://img.shields.io/badge/CUDA-8.0-green.svg?style=flat) ![Platform](https://img.shields.io/badge/platform-Desktop-bcbcbc.svg) ![Developer](https://img.shields.io/badge/Developer-Youssef%20Victor-0f97ff.svg?style=flat)




- [Features](#features)



- [In-Depth](#indepth)



- [Blooper](#blooper)




____________________________________________________



The goal of this project was to run an algorithm that clears out all zeros from an array on the GPU using CUDA. This parallel reduction is done using the scan algorithm that computes the exclusive prefix sum. I also implemented a parallelized Radix Sort using the exclusive prefix sum algorithm developed.



### Things Done

#### Core Features

- [x] Shading for Ideal Diffuse Surfaces
- [x] Shading for Perfectly Specular Surfaces
- [x] Early Ray Termination Using Stream Compaction
- [x] Caching of First Bounces

#### Spicy Features
- [x] Shading for Transmissive Surfaces (maybe)
- [x] Work-efficient Stream Compaction Using Shared Memory Across Multiple Blocks
- [x] Environment Maps
- [x] Direct Lighting
- [x] Multiple Importance Sampling
- [x] Stochastic Antialiasing
- [x] Arbitrary Mesh Loading
- [ ] Kd-Tree & Stackless Kd-Tree Traversal on the GPU
- [ ] [Physically Accurate Lens Flares](https://placeholderart.wordpress.com/2015/01/19/implementation-notes-physically-based-lens-flares/)
- [ ] [Specular BRDF with Microstructure BRDF](https://people.eecs.berkeley.edu/~lingqi/publications/paper_glints2.pdf)
- [ ] Texture Mapping (maybe)
- [ ] Depth of Field/Cooler Lens Effects such as bloom

![Cornell Box](/img/cornellOBJ.png)

Multiple Importance Sampling, 7500 Samples, 1080x1080 px, OBJ dodecahedron mesh.



### In-Depth:

#### Transmissive Surfaces

This uses basic `glm::refract` so it should work. For some reason it doesn't. I should change the implementation of it, but for now, maybe I can get half-credit points. To try out a scene with it simply set a material's bsdf to 2.
`TODO: Show picture`

#### Work Efficient Scan Using Shared Memory Across Multiple Blocks

This took me like 5 days to do, I ended up simply using thrust's partition, but well, that's programming for you. The benefit to my implementation is that it works all the way up to `2^24` as opposed to some others' implementation which fails before that.
`TODO: Show performance comparison`

#### Environment Maps:

![environment-map](/img/envMap2.png)

An environment map with a purely specular sphere in the middle.

![diffuse-environment-map](/img/envMap.png)

An environment map with a purely diffuse sphere in the middle.

In the sample images above, you can clearly see the effect the environment map has with specular surfaces. With the purely specular surface it sort of looks like there is some bloom effeect showing as well. I think that is really cool.

The second image with a diffuse surface is supposed to be a 98% white sphere. But as you see, as in the real world, the environment also reflects light onto the object. The result is the beautifully shaded sphere you see.

In the following images you will see how the environment maps affect the lighting of a cornell box scene with a specular sphere in the middle:

![cornellBoxNoEnvMap](/img/cornellSpec.png)
Normal cornell box scene with no environment map.

![cornellBoxNoEnvMap](/img/cornellEnvSpec.png)
Normal cornell box scene with environment map added.

The environment map adds better lighting to the scene.


#### Direct Lighting

This took a while to get completely right, it uses a light-based sample to shade the entire scene. As such, there are no reflections on objects. The result however is a much more nicely converged scene.

`TODO: Show Pic`

#### Multiple Importance Sampling

When you combine the light based sampling and the bsdf-based sampling, you get what you saw in the representative image at the start: a completely converged. Here are some more pictures:

![mis-sample1](/img/cornellTwo.2017-10-01_21-11-00z.5000samp.png)

`TODO: Add More Images`

#### Stochastic Anti-Aliasing:

This Feature was fairly simple to implement yet took a lot to perfect. This feature does not work with first-bounce caching unless you jitter the ray direction after you generate the ray, which is possible and might be a `TODO`, but given the lack of time, it will probably remain an idea. Here is what happens when I try anti-aliasing with caching turned on:

![bad-aliasing](/img/cornell.2017-10-01_18-30-30z.5000samp.png)

With my cached first bounce, there are jagged edges surrounding everything as all the rays have been jittered, but they do not change across iterations, so the random jitterness stays and remains prominent. As such the picture looks very weird. Here's what it looks like without anti-aliasing at all:

![no-aliasing](/img/cornellTwo.2017-10-01_09-02-39z.5000samp.png)

The image here has very rough aliased edges. Here is what it looks like with everything fixed:

![aliasing](/img/cornellTwo.2017-10-01_21-11-00z.5000samp.png)

Now the image is much smoother.

#### Arbitrary Mesh Loading

Took me forever to get this to work, triangle intersection and intersection testing on the GPU caused a lot of problems. Eventually they were all resolved, but still. Here is the beautiful representative image once again with a stretched out cyan dodecahedron model:

![Cornell Box](/img/cornellOBJ.png)


### Bloopers / Lessons Learned

This is a blooper I got while trying to get MIS to work

![bnw](/img/bloopers/bnw.gif)

Another blooper I got where I was sampling the light weirdly

![the-v](/img/bloopers/v.gif)

My favorite Blooper, which also shows Direct Ligting Rays being sampled:

![starry stuff](/img/bloopers/starry.gif)

Binary file added img/MIS-1000samps.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/bloopers/bnw.gif
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/bloopers/starry.gif
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/bloopers/v.gif
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.2017-10-01_18-30-30z.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/cornellEnvSpec.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/cornellOBJ.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/cornellSpec.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/cornellTwo.2017-10-01_00-59-01z.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/cornellTwo.2017-10-01_02-07-17z.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/cornellTwo.2017-10-01_04-03-53z.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/cornellTwo.2017-10-01_04-16-37z.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/cornellTwo.2017-10-01_08-41-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/cornellTwo.2017-10-01_09-02-39z.26samp.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/cornellTwo.2017-10-01_09-02-39z.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/cornellTwo.2017-10-01_19-53-41z.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/cornellTwo.2017-10-01_21-11-00z.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/envMap.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/envMap2.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.
7 changes: 6 additions & 1 deletion scenes/cornell.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 5
EMITTANCE 3
BSDF -1

// Diffuse white
MATERIAL 1
Expand All @@ -17,6 +18,7 @@ REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0
BSDF 0

// Diffuse red
MATERIAL 2
Expand All @@ -27,6 +29,7 @@ REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0
BSDF 0

// Diffuse green
MATERIAL 3
Expand All @@ -37,6 +40,7 @@ REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0
BSDF 0

// Specular white
MATERIAL 4
Expand All @@ -47,6 +51,7 @@ REFL 1
REFR 0
REFRIOR 0
EMITTANCE 0
BSDF 0

// Camera
CAMERA
Expand Down
150 changes: 150 additions & 0 deletions scenes/cornellDraggo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
// Emissive material (light)
MATERIAL 0
RGB 0.8 1 1
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 10
BSDF -1

// Emissive material (light)
MATERIAL 1
RGB 1 1 0.8
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 10
BSDF -1

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

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

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

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

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


// Ceiling light
OBJECT 0
plane
material 0
TRANS 3 9.99 0
ROTAT 90 0 0
SCALE 3 3 1

// Ceiling light 2
OBJECT 1
plane
material 1
TRANS -3 9.99 0
ROTAT 90 0 0
SCALE 3 3 1

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

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

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

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

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

// Sphere
OBJECT 7
sphere
material 2
TRANS -1 4 -4
ROTAT 0 0 0
SCALE 0.1 0.1 0.1

// Cube Mesh
OBJECT 8
mesh
../scenes/dragon.obj
material 4
TRANS 0 2 -4
ROTAT 0 0 0
SCALE 2 2 2
Loading