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
270 changes: 81 additions & 189 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,85 @@
CIS 565 Project3 : CUDA Pathtracer
===================

Fall 2014

Due Wed, 10/8 (submit without penalty until Sun, 10/12)

## INTRODUCTION
In this project, you will implement a CUDA based pathtracer capable of
generating pathtraced rendered images extremely quickly. Building a pathtracer can be viewed as a generalization of building a raytracer, so for those of you who have taken 460/560, the basic concept should not be very new to you. For those of you that have not taken
CIS460/560, raytracing is a technique for generating images by tracing rays of
light through pixels in an image plane out into a scene and following the way
the rays of light bounce and interact with objects in the scene. More
information can be found here:
http://en.wikipedia.org/wiki/Ray_tracing_(graphics). Pathtracing is a generalization of this technique by considering more than just the contribution of direct lighting to a surface.

Since in this class we are concerned with working in generating actual images
and less so with mundane tasks like file I/O, this project includes basecode
for loading a scene description file format, described below, and various other
things that generally make up the render "harness" that takes care of
everything up to the rendering itself. The core renderer is left for you to
implement. Finally, note that while this basecode is meant to serve as a
strong starting point for a CUDA pathtracer, you are not required to use this
basecode if you wish, and you may also change any part of the basecode
specification as you please, so long as the final rendered result is correct.

## CONTENTS
The Project3 root directory contains the following subdirectories:
Radium Yang's Pathtracer

******************** 6000 Iterations, Ray Depth: 8, Depth of Field: focal length 13 *******************
![alt tag](https://github.com/radiumyang/Project3-Pathtracer/blob/master/windows/Project3-Pathtracer/Project3-Pathtracer/depth%2Brefract%2Bbackreflect%2B6000.bmp)

##FEATURE LIST
- Basic
* Raycasting
* Diffuse surfaces
* Perfect specular reflective surfaces
* Cube intersection testing
* Sphere surface point sampling
* Stream compaction optimization
- Extra
* Supersampling Anti-Alisasing
* Depth of field
* Refraction

###Feature Overview
For the Pathtracing Algorithm and basic features' implementations, I mainly followed the raytracing slides in CIS 560 and pathtracing slices in CIS 565.

Extra Features:
- Depth of field
* I referred to the algorithm posted here: http://ray-tracer-concept.blogspot.com/2011/12/depth-of-field.html
* Find a focal plane before the camera, the new ray direction should come from the image plane to the focal point.

* src/ contains the source code for the project. Both the Windows Visual Studio
solution and the OSX and Linux makefiles reference this folder for all
source; the base source code compiles on Linux, OSX and Windows without
modification. If you are building on OSX, be sure to uncomment lines 4 & 5 of
the CMakeLists.txt in order to make sure CMake builds against clang.
* data/scenes/ contains an example scene description file.
* renders/ contains an example render of the given example scene file.
* windows/ contains a Windows Visual Studio 2010 project and all dependencies
needed for building and running on Windows 7. If you would like to create a
Visual Studio 2012 or 2013 projects, there are static libraries that you can
use for GLFW that are in external/bin/GLFW (Visual Studio 2012 uses msvc110,
and Visual Studio 2013 uses msvc120)
* external/ contains all the header, static libraries and built binaries for
3rd party libraries (i.e. glm, GLEW, GLFW) that we use for windowing and OpenGL
extensions
- Reflection/ Refraction
* I referred to the algorithm posted here: http://ray-tracer-concept.blogspot.com/2011/12/refraction.html
* Interesting bug... when calculating the accumulated reflective/refractive factor, failed to limit the factor to be required number.
Solution:in reflection, if randomnumber < hasReflective, do reflection; else do diffuse.
in refraction, if randomnumber < refractive, do refraction; else do reflection.
* Example: iterations: 2000, trace depth: 8, hasReflect = 0.3, hasRefract = 0.8
* Before:
![alt tag](https://github.com/radiumyang/Project3-Pathtracer/blob/master/windows/Project3-Pathtracer/Project3-Pathtracer/refr_bug.bmp)
* After: (iterations: 2000, trace depth: 8)
![alt tag](https://github.com/radiumyang/Project3-Pathtracer/blob/master/windows/Project3-Pathtracer/Project3-Pathtracer/depth%2Brefract%2Bbackreflect%2B2000.bmp)

- Stream compaction
* reference: http://wiki.thrust.googlecode.com/hg-history/312700376feeadec0b1a679a259d66ff8512d5b3/html/group__stream__compaction.html#ga517b17ceafe31a9fc70ac5127bd626de
* To accelerate the performance, using thrust to do stream compaction to delete rays which have already been hit to the background or light from the raypool. Thus, after each iteration, the valid rays in the ray pool will be decreased, which will help improve the performance.

- Supersampling Anti-Alisasing
* When casting the ray, jittered the pixel position on the image plane. (use thrust random number engine)

## Performance Analysis
![alt tag](https://github.com/radiumyang/Project3-Pathtracer/blob/master/windows/Project3-Pathtracer/Project3-Pathtracer/performance_iterations.JPG)

![alt tag](https://github.com/radiumyang/Project3-Pathtracer/blob/master/windows/Project3-Pathtracer/Project3-Pathtracer/performance_tracedepth.JPG)

## Progress Screenshots

* Step 1: ray intersection + diffuse color + soft shadow (sample 20) test

///// trace depth: 8 /////
![alt tag](https://github.com/radiumyang/Project3-Pathtracer/blob/master/windows/Project3-Pathtracer/Project3-Pathtracer/tmp_2.bmp)

* Step 2: use ray pool algorithm, diffuse + reflection + specular test

///// trace depth: 8 /////
![alt tag](https://github.com/radiumyang/Project3-Pathtracer/blob/master/windows/Project3-Pathtracer/Project3-Pathtracer/spec_1.bmp)

* Step 3: add refraction & depth of field

///// trace depth: 8 /////
![alt tag](https://github.com/radiumyang/Project3-Pathtracer/blob/master/windows/Project3-Pathtracer/Project3-Pathtracer/depth_refract_1000.bmp)

* Step 4: set customized scene (reflected walls) + performance tests

////// Iterations: 4000, trace depth: 2 /////
![alt tag](https://github.com/radiumyang/Project3-Pathtracer/blob/master/windows/Project3-Pathtracer/Project3-Pathtracer/4000_depth2.bmp)

////// Iterations: 4000, trace depth: 5 /////
![alt tag](https://github.com/radiumyang/Project3-Pathtracer/blob/master/windows/Project3-Pathtracer/Project3-Pathtracer/4000_depth5.bmp)

////// Iterations: 500, trace depth: 8 /////
![alt tag](https://github.com/radiumyang/Project3-Pathtracer/blob/master/windows/Project3-Pathtracer/Project3-Pathtracer/depth%2Brefract%2Bbackreflect%2B500.bmp)

////// Iterations: 6000, trace depth: 8 /////
![alt tag](https://github.com/radiumyang/Project3-Pathtracer/blob/master/windows/Project3-Pathtracer/Project3-Pathtracer/depth%2Brefract%2Bbackreflect%2B6000.bmp)


===================

## RUNNING THE CODE
The main function requires a scene description file (that is provided in data/scenes).
Expand All @@ -51,111 +89,6 @@ The main function reads in the scene file by an argument as such :
If you are using Visual Studio, you can set this in the Debugging > Command Arguments section
in the Project properties.

## REQUIREMENTS
In this project, you are given code for:

* Loading, reading, and storing the scene scene description format
* Example functions that can run on both the CPU and GPU for generating random
numbers, spherical intersection testing, and surface point sampling on cubes
* A class for handling image operations and saving images
* Working code for CUDA-GL interop

You will need to implement the following features:

* Raycasting from a camera into a scene through a pixel grid
* Diffuse surfaces
* Perfect specular reflective surfaces
* Cube intersection testing
* Sphere surface point sampling
* Stream compaction optimization

You are also required to implement at least 2 of the following features:

* Texture mapping
* Bump mapping
* Depth of field
* Refraction, i.e. glass
* OBJ Mesh loading and rendering
* Interactive camera
* Motion blur
* Subsurface scattering

The 'extra features' list is not comprehensive. If you have a particular feature
you would like to implement (e.g. acceleration structures, etc.) please contact us
first!

For each 'extra feature' you must provide the following analysis :
* overview write up of the feature
* performance impact of the feature
* if you did something to accelerate the feature, why did you do what you did
* compare your GPU version to a CPU version of this feature (you do NOT need to
implement a CPU version)
* how can this feature be further optimized (again, not necessary to implement it, but
should give a roadmap of how to further optimize and why you believe this is the next
step)

## BASE CODE TOUR
You will be working in three files: raytraceKernel.cu, intersections.h, and
interactions.h. Within these files, areas that you need to complete are marked
with a TODO comment. Areas that are useful to and serve as hints for optional
features are marked with TODO (Optional). Functions that are useful for
reference are marked with the comment LOOK.

* raytraceKernel.cu contains the core raytracing CUDA kernel. You will need to
complete:
* cudaRaytraceCore() handles kernel launches and memory management; this
function already contains example code for launching kernels,
transferring geometry and cameras from the host to the device, and transferring
image buffers from the host to the device and back. You will have to complete
this function to support passing materials and lights to CUDA.
* raycastFromCameraKernel() is a function that you need to implement. This
function once correctly implemented should handle camera raycasting.
* raytraceRay() is the core raytracing CUDA kernel; all of your pathtracing
logic should be implemented in this CUDA kernel. raytraceRay() should
take in a camera, image buffer, geometry, materials, and lights, and should
trace a ray through the scene and write the resultant color to a pixel in the
image buffer.

* intersections.h contains functions for geometry intersection testing and
point generation. You will need to complete:
* boxIntersectionTest(), which takes in a box and a ray and performs an
intersection test. This function should work in the same way as
sphereIntersectionTest().
* getRandomPointOnSphere(), which takes in a sphere and returns a random
point on the surface of the sphere with an even probability distribution.
This function should work in the same way as getRandomPointOnCube(). You can
(although do not necessarily have to) use this to generate points on a sphere
to use a point lights, or can use this for area lighting.

* interactions.h contains functions for ray-object interactions that define how
rays behave upon hitting materials and objects. You will need to complete:
* getRandomDirectionInSphere(), which generates a random direction in a
sphere with a uniform probability. This function works in a fashion
similar to that of calculateRandomDirectionInHemisphere(), which generates a
random cosine-weighted direction in a hemisphere.
* calculateBSDF(), which takes in an incoming ray, normal, material, and
other information, and returns an outgoing ray. You can either implement
this function for ray-surface interactions, or you can replace it with your own
function(s).

You will also want to familiarize yourself with:

* sceneStructs.h, which contains definitions for how geometry, materials,
lights, cameras, and animation frames are stored in the renderer.
* utilities.h, which serves as a kitchen-sink of useful functions

## NOTES ON GLM
This project uses GLM, the GL Math library, for linear algebra. You need to
know two important points on how GLM is used in this project:

* In this project, indices in GLM vectors (such as vec3, vec4), are accessed
via swizzling. So, instead of v[0], v.x is used, and instead of v[1], v.y is
used, and so on and so forth.
* GLM Matrix operations work fine on NVIDIA Fermi cards and later, but
pre-Fermi cards do not play nice with GLM matrices. As such, in this project,
GLM matrices are replaced with a custom matrix struct, called a cudaMat4, found
in cudaMat4.h. A custom function for multiplying glm::vec4s and cudaMat4s is
provided as multiplyMV() in intersections.h.

## SCENE FORMAT
This project uses a custom scene description format.
Expand Down Expand Up @@ -219,8 +152,6 @@ Objects are defined in the following fashion:
An example scene file setting up two frames inside of a Cornell Box can be
found in the scenes/ directory.

For meshes, note that the base code will only read in .obj files. For more
information on the .obj specification see http://en.wikipedia.org/wiki/Wavefront_.obj_file.

An example of a mesh object is as follows:

Expand All @@ -232,42 +163,3 @@ TRANS 0 5 -5
ROTAT 0 90 0
SCALE .01 10 10

Check the Google group for some sample .obj files of varying complexity.

## THIRD PARTY CODE POLICY
* Use of any third-party code must be approved by asking on our Google Group.
If it is approved, all students are welcome to use it. Generally, we approve
use of third-party code that is not a core part of the project. For example,
for the ray tracer, we would approve using a third-party library for loading
models, but would not approve copying and pasting a CUDA function for doing
refraction.
* Third-party code must be credited in README.md.
* Using third-party code without its approval, including using another
student's code, is an academic integrity violation, and will result in you
receiving an F for the semester.

## SELF-GRADING
* On the submission date, email your grade, on a scale of 0 to 100, to Harmony,
[email protected], with a one paragraph explanation. Be concise and
realistic. Recall that we reserve 30 points as a sanity check to adjust your
grade. Your actual grade will be (0.7 * your grade) + (0.3 * our grade). We
hope to only use this in extreme cases when your grade does not realistically
reflect your work - it is either too high or too low. In most cases, we plan
to give you the exact grade you suggest.
* Projects are not weighted evenly, e.g., Project 0 doesn't count as much as
the path tracer. We will determine the weighting at the end of the semester
based on the size of each project.

## SUBMISSION
Please change the README to reflect the answers to the questions we have posed
above. Remember:
* this is a renderer, so include images that you've made!
* be sure to back your claims for optimization with numbers and comparisons
* if you reference any other material, please provide a link to it
* you wil not e graded on how fast your path tracer runs, but getting close to
real-time is always nice
* if you have a fast GPU renderer, it is good to show case this with a video to
show interactivity. If you do so, please include a link.

Be sure to open a pull request and to send Harmony your grade and why you
believe this is the grade you should get.
8 changes: 4 additions & 4 deletions data/scenes/sampleScene.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,23 @@ UP 0 1 0

OBJECT 0
cube
material 0
material 3
frame 0
TRANS 0 0 0
ROTAT 0 0 90
SCALE .01 10 10

OBJECT 1
cube
material 0
material 3
frame 0
TRANS 0 5 -5
ROTAT 0 90 0
SCALE .01 10 10

OBJECT 2
cube
material 0
material 3
frame 0
TRANS 0 10 0
ROTAT 0 0 90
Expand Down Expand Up @@ -183,7 +183,7 @@ SCALE 3 3 3

OBJECT 8
cube
material 8
material 3
frame 0
TRANS 0 10 0
ROTAT 0 0 90
Expand Down
Loading