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 3 - Xiang Deng #21

Open
wants to merge 57 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
842d770
change cmake
dengxianga Oct 3, 2016
72f2676
bullshit
dengxianga Oct 3, 2016
af68ddc
:( : ( CNM
dengxianga Oct 4, 2016
7148581
fix the stupid coloring bug,
dengxianga Oct 4, 2016
8239eea
remove unnessary branch
dengxianga Oct 4, 2016
5dab9c0
add streamcompact
dengxianga Oct 7, 2016
486b56b
efficien compaction done
dengxianga Oct 8, 2016
2054a16
add external for cuda 8 link error as suggested by ruoyu fan; add stream
dengxianga Oct 8, 2016
ef8eba2
work efficient shared mem done
dengxianga Oct 9, 2016
2142750
r
dengxianga Oct 9, 2016
0fe35f9
motion blur a
dengxianga Oct 9, 2016
e87b648
add blur example
dengxianga Oct 9, 2016
2641572
readme1
dengxianga Oct 9, 2016
a82ac0e
togglable and remove nasty lines
dengxianga Oct 10, 2016
ef972a2
sort by material done
dengxianga Oct 10, 2016
e60e52c
try
dengxianga Oct 10, 2016
1fc46dd
r
dengxianga Oct 10, 2016
4f00430
r
dengxianga Oct 10, 2016
57265bc
c
dengxianga Oct 10, 2016
0226393
cache done too
dengxianga Oct 10, 2016
0ce9095
first bounce v2
dengxianga Oct 10, 2016
d8afcb1
simplify cache
dengxianga Oct 10, 2016
e285290
AA and motion speed
dengxianga Oct 10, 2016
eac6252
cos jitter works too
dengxianga Oct 10, 2016
149f196
simple aa
dengxianga Oct 10, 2016
96cf234
motion blur v2
dengxianga Oct 10, 2016
05ebe12
looks better
dengxianga Oct 10, 2016
9d2e3d1
:)
dengxianga Oct 10, 2016
c21c1bb
blur gif
dengxianga Oct 10, 2016
bbf7ad5
img
dengxianga Oct 10, 2016
dc5b6f1
refrac done
dengxianga Oct 10, 2016
6594f1f
change img
dengxianga Oct 10, 2016
f02c856
AA noAA gif
dengxianga Oct 10, 2016
1bde381
DOF done?
dengxianga Oct 10, 2016
c7b27ac
add dofimg
dengxianga Oct 10, 2016
edecae7
readme
dengxianga Oct 11, 2016
3134ac3
a
dengxianga Oct 11, 2016
84d253b
readme
dengxianga Oct 11, 2016
aa7a649
readme
dengxianga Oct 11, 2016
890a08a
files
dengxianga Oct 11, 2016
e576b5c
bug fixed
dengxianga Oct 11, 2016
b24ba24
no dof now
dengxianga Oct 11, 2016
9c17760
refernces
dengxianga Oct 11, 2016
b6cd0f2
readme forgot to mention one feature.
dengxianga Oct 11, 2016
c86e2c5
one more image, not for grading
dengxianga Oct 11, 2016
7800750
update readme
dengxianga Oct 12, 2016
4d0cb1d
Merge branch 'master' of https://github.com/dengxianga/Project3-CUDA-…
dengxianga Oct 12, 2016
e51f71a
r
dengxianga Oct 12, 2016
b1b176f
r
dengxianga Oct 12, 2016
01ccde1
r
dengxianga Oct 12, 2016
e57f3a8
r
dengxianga Oct 12, 2016
fabfa22
r
dengxianga Oct 12, 2016
14a1690
r
dengxianga Oct 12, 2016
ea7efdd
update readme
dengxianga Oct 12, 2016
d51ad1c
yep
dengxianga Oct 24, 2016
02297ee
yep
dengxianga Oct 24, 2016
413f425
yep
dengxianga Oct 24, 2016
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
25 changes: 15 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
cmake_minimum_required(VERSION 3.0)

project(cis565_path_tracer)

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/external/cmake")

# Set up include and lib paths
set(EXTERNAL "external")
include_directories("${EXTERNAL}")
include_directories("${EXTERNAL}/include")
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(EXTERNAL_LIB_PATH "${EXTERNAL}/lib/osx")
Expand All @@ -18,13 +16,19 @@ endif()
link_directories(${EXTERNAL_LIB_PATH})
list(APPEND CMAKE_LIBRARY_PATH "${EXTERNAL_LIB_PATH}")

# Configure GLFW
set(GLFW_ROOT_DIR "${EXTERNAL}/glfw-3.2.1")
# fix for cuda 8 according to Ruoyu Fan
# We don't need documents, tests, etc..
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(GLFW_INSTALL OFF CACHE BOOL "" FORCE)
add_subdirectory(${GLFW_ROOT_DIR})
include_directories("${GLFW_ROOT_DIR}/include")
SET(GLFW_LIBRARY glfw)

# Find up and set up core dependency libs

set(GLFW_INCLUDE_DIR "${EXTERNAL}/include")
set(GLFW_LIBRARY_DIR "${CMAKE_LIBRARY_PATH}")
find_library(GLFW_LIBRARY "glfw3" HINTS "${GLFW_LIBRARY_DIR}")

set(GLEW_INCLUDE_DIR "${EXTERNAL}/include")
set(GLEW_LIBRARY_DIR "${CMAKE_LIBRARY_PATH}")
add_definitions(-DGLEW_STATIC)
Expand All @@ -43,6 +47,7 @@ set(CMAKE_CXX_STANDARD 11)

# Enable CUDA debug info in debug mode builds
list(APPEND CUDA_NVCC_FLAGS_DEBUG -G -g)
list(APPEND CUDA_NVCC_FLAGS "-std=c++11")

# OSX-specific hacks/fixes
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Expand All @@ -68,7 +73,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
endif()

include_directories(.)
#add_subdirectory(stream_compaction) # TODO: uncomment if using your stream compaction
add_subdirectory(stream_compaction) # DONE: uncomment if using your stream compaction
add_subdirectory(src)

cuda_add_executable(${CMAKE_PROJECT_NAME}
Expand All @@ -78,7 +83,7 @@ cuda_add_executable(${CMAKE_PROJECT_NAME}

target_link_libraries(${CMAKE_PROJECT_NAME}
src
#stream_compaction # TODO: uncomment if using your stream compaction
stream_compaction # DONE: uncomment if using your stream compaction
${CORELIBS}
)

Expand Down
118 changes: 112 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,119 @@
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**

* (TODO) YOUR NAME HERE
* Tested on: (TODO) Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab)
* Xiang Deng
* Tested on: Windows 10-Home, i7-6700U @ 2.6GHz 16GB, GTX 1060 6GB (Personal Computer)

### (TODO: Your README)
**Project Description:**

*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.
We assemble multiple colorful objects with diffuse surfaces, perfectly specular surfaces or refraction materials into one scene, after 'turning on' the lights which bounces and hits the objects wihtin the scene,
a beautifully illuminated image is generated.
In this project, we typically explores the development of two major components: 1. run the simulation of ray tracer with CUDA as efficient as possible 2. generate cool images with splendid visual effects.

Static scene rendering + basic shading features (reflection + diffusion + refraction)

![](img/stack3.png) | ![](img/stack4.png) | ![](img/blur4.gif)

![](img/beforeblur.png)

* Features
* BSDF shading with diffusion, reflection.
* Stream Compaction for removing inactive rays.
* Sorting rays by material id.
* First bounce caching of intersections.


* Additional features
* Work efficient shared memory compaction.
* Refractions.
* Anti-aliasing with uniform guassian spherical jitter.
* Motion blur.
* Depth of field.

Some demos we had so far:

Motion blur + basic shading features (reflection + diffusion + refraction) | Screen Shot of Motion Blur From a Differnt Angle |
:-------------------------:|:-------------------------:
![](img/blur3.gif) |![](img/coolblur.png)






Depth of field with DoFx=2, DoFy=10 |Depth of field DoFx=5, DoFy=5
:-------------------------:|:-------------------------:
![](img/DOF1.png) | ![](img/DOF2.png)



Anti-aliasing | Without-anti-aliasing
:-------------------------:|:-------------------------:
![](img/AA.gif) | ![](img/noAA.gif)

**Summary of Implementations (forgive my brevity)**

* The motion blur is essentially produced by adding Gaussian noise to time sampling of the object movements seen by the camera (technically the rays that hits the moving sphere); initial speed of objects can be set in the
scene file (cornellMove.txt for example); different inital speed setting can cause differnt blur effects.

* The refraction is essentially following the Schlick's approximation (https://en.wikipedia.org/wiki/Schlick%27s_approximation). Lights can either be reflected by the surface or enter and bounces
inside the ball, or come out again.

* Depth of field is typically based on PBRT chap 6 and chap 13, especially including the concentric disc sampling (chap 13).

* Anti-aliasing is achieved by adding uniform spherical Gaussian noises with radius of 0.005 to each rays from the camera, resource can be found here http://paulbourke.net/miscellaneous/aliasing/.

In addition, regarding optimization, a few methods were implemented, including work efficient shared memory stream compaction, organizing rays contiguous in memory by sorting, caching first bounces of ray intersections, etc.



# Analysis

Stream Compaction reduces the number of active bouncing paths within one iteration, plot below illustrates this in open scene (cornell).
The thrust implementation (removeif) performs similar to the work effcicient shared memory version implementated by the author.

![](charts/1.PNG)

Stream compaction consequently significantly reduces the time consumption on computing spatial intersections of rays on objects; yet overhead of the extra
time spending on compaction itself trememdously decreases its benefit.
In comparison between the two version of compaction, shared memory provides more benefits in terms of both computing intersections and the overall CUDA running time.


![](charts/2.PNG)

In closed scene, Stream Compaction doesn't significantly the number of active bouncing paths within one iteration, plot below illustrates this in closed scene (cornell), in this case very few
rays terminated.
The thrust implementation (removeif) performs similar to the work effcicient shared memory version implementated by the author.

![](charts/3.PNG)

In closed scene, both implementation of compaction causes delay in processing; yet the overhead of the extra
time spending on compaction itself cause further delay. Lights terminated mostly (probably) due to the collision on emissive lights.
In comparison between the two version of compaction, shared memory provides more benefits in terms of both computing intersections and the overall CUDA running time.

![](charts/4.PNG)

Sorting trememdously increases the delay in processing; whereas caching first bouncing does reduces around 10 percent of the total processing time.
However, caching does has its limitations since it's assuming the scene is static, if objects are moving, caching the first bounce intersections might causes laggy rendering.
Sorting turns out to have more overhead effects than any other optimization methods so far. It doesn't have the benefit in either open or closed scene: in open scene it is more wise to remove
terminated rays as soon as possible, making rays contiguous by sorting is not worthwhile considering its complexity and cost; in closed scene it's not likely to have a number of rays terminated,
in such case the memory isn't as sparse as open scene while sorting and making memory contiguous might not be useful in this case either.

![](charts/5.PNG)

# CMakeLists Changes

A couple changed were made, 1. Changed CUDA compatiblity sm_20 --> sm_61; 2. Added file names from stream compaction folder; 3. Adjustments of main cmakelist file
for fixing linking errors with Visual Studio 2013, CUDA 8 (see https://groups.google.com/forum/#!topic/cis-565-fall-2016/kMSmwhhdqFg , also includes the changes to the
external folder).

* Togglable parameters of modes, please see common.h.
* Parameters for motion speed, camera DOF, etc, please see cornellMove.txt for reference.

# References

* [PBRT] Physically Based Rendering, Second Edition: From Theory To Implementation. Pharr, Matt and Humphreys, Greg. 2010.
* Antialiasing and Raytracing. Chris Cooksey and Paul Bourke, http://paulbourke.net/miscellaneous/aliasing/
* [Sampling notes](http://graphics.ucsd.edu/courses/cse168_s14/) from Steve Rotenberg and Matteo Mannino, University of California, San Diego, CSE168: Rendering Algorithms
Binary file added charts/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 charts/2.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 charts/3.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 charts/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 charts/5.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
161 changes: 0 additions & 161 deletions cmake/CMakeParseArguments.cmake

This file was deleted.

11 changes: 11 additions & 0 deletions external/cmake/CMakeParseArguments.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.

#.rst:
# CMakeParseArguments
# -------------------
#
# This module once implemented the :command:`cmake_parse_arguments` command
# that is now implemented natively by CMake. It is now an empty placeholder
# for compatibility with projects that include it to get the command from
# CMake 3.4 and lower.
Loading