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: Daniel Krupka #26

Open
wants to merge 4 commits into
base: master
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
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ set(CORELIBS
"${GLFW_LIBRARY}"
"${OPENGL_LIBRARY}"
"${GLEW_LIBRARY}"
pthread
)

# Enable C++11 for host code
Expand Down Expand Up @@ -68,17 +69,16 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
endif()

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

cuda_add_executable(${CMAKE_PROJECT_NAME}
"src/main.h"
"src/main.cpp"
)

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

Expand Down
57 changes: 49 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,54 @@
CUDA Path Tracer
================
CUDA Stream Compaction
======================

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

* (TODO) YOUR NAME HERE
* Tested on: (TODO) Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab)
* Daniel Krupka
* Tested on: Debian testing (stretch), Intel(R) Core(TM) i7-4710HQ CPU @ 2.50GHz 8GB, GTX 850M

### (TODO: Your README)
# Project 3 - GPU Path Tracing
My goal for this project was to extend my existing path tracer to use CUDA. All code is hand-written or
adapted from given CIS 565 code -- no external libraries used.

*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.
# Features
The primary performance features implemented are
1. Stream Compaction - Rays that are no longer alive (e.g. have hit lights, escaped the scene)
are culled.
2. Bounce Caching - Rays' first intersection are constant between iterations, and thus can be cached for some time savings.
3. Sort-by-material - As objects with similar materials can be expected to take similar code paths during shading, it may be
advantageous to sort rays by the material they've hit prior to shading.

Additionally, I implemented some extra features and improvements.
1. Fresnel scattering - The exact Fresnel equations for reflection/refraction are solved.
2. Depth of field - Physically accurate depth of field.
3. Arbitrary meshes - .obj files can be loaded, with optional AABB culling.

# Results

![Cornell Box](img/cornell.png "Cornell Box")

## Base features
The CUDA-accelerated path tracer performed much faster than the CPU version, as expected. Though I did not run CPU tests,
similar scenes generally took minutes where the GPU version takes seconds.


![First-Bounce caching comparison](img/cache.png "First-Bounce caching comparison")

As expected, caching the first ray intersection did produce a performance gain, but this diminished as the maximum
number of bounces increased. These tests were conducted on the Cornell box seen above.

## Extra features
![DOF](img/dof.png "Depth of Field")

Depth of field is physically realistic, and achieved by a "DENSITY N" and "APERTURE R" parameters in the CAMERA section, which
causes the ray origins to be jittered N^2 times within an aperture of radius R. This leads to a slow-down equivalent to
having N^2 times as many rays.

![Cow](img/cow.png "Arbitrary meshes")
![Teapot](img/teapot.png "Arbitrary meshes")

The tracer supports loading arbitrary meshes from a standard .obj file, by setting "SHAPE mesh"
and FILE file.obj" in an OBJECT section. AABB culling can be enabled/disabled by "BBCULL 1/0".
For the teapot, the non-culled render took 118 seconds, the culled 102 seconds The cow, a more complex model,
took 635 seconds non-culled, but only 593 seconds culled.

Binary file removed img/REFERENCE_cornell.5000samp.png
Binary file not shown.
Binary file added img/cache.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.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/cow.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/dof.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/glitch1.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/glitch2.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/glitch3.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 removed img/stacked_bar_graph.png
Binary file not shown.
Binary file added img/teapot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 31 additions & 16 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
set(SOURCE_FILES
"stb.cpp"
"image.cpp"
"image.h"
"interactions.h"
"intersections.h"
"glslUtility.hpp"
"glslUtility.cpp"
"pathtrace.cu"
"pathtrace.h"
"camera.cpp"
"camera.hpp"
"scene.hpp"
"scene.cpp"
"scene.h"
"sceneStructs.h"
"preview.h"
"preview.cpp"
"utilities.cpp"
"utilities.h"
"conf.hpp"
"conf.cpp"
"util.hpp"
"kdtree.cpp"
"kdtree.hpp"
"light.hpp"
"node.cpp"
"node.hpp"
"shader.cpp"
"shader.hpp"
"texture.hpp"
"texture.cpp"
"mesh/intersection.hpp"
"mesh/intersection.cu"
"mesh/object.cpp"
"mesh/object.hpp"
"mesh/cube.cpp"
"mesh/cube.hpp"
"mesh/sphere.cpp"
"mesh/sphere.hpp"
"mesh/cylinder.cpp"
"mesh/cylinder.hpp"
"mesh/mesh.cpp"
"mesh/mesh.hpp"
"cuda_camera.cu"
"util_cuda.cu"
"stb.cpp"
)

cuda_add_library(src
${SOURCE_FILES}
OPTIONS -arch=sm_20
OPTIONS -arch=sm_50 -std=c++11
)
Loading