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

Submission: Guan Sun #9

Open
wants to merge 9 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
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CUDA_PROPAGATE_HOST_FLAGS OFF)
endif()

#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}
Expand All @@ -77,7 +77,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 # TODO: uncomment if using your stream compaction
${CORELIBS}
)

Expand Down
275 changes: 40 additions & 235 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,48 @@ CUDA Path Tracer

**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)
* Guan Sun
* Tested on: Mac OS X Yosemite 10.10.5, Intel Core i7 @ 2.3GHz 8GB, GeForce GT 650M 1024MB (Personal Laptop)

### (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.
In this project, a CUDA-based path tracer capable of rendering globally-illuminated images is implemented. The features include,
* Diffuse surfaces rendering
* Perfectly specular-reflective (mirrored) surfaces rendering
* Non-perfect specular surfaces rendering
* Antialiasing
* Motion blur
* Work-efficient stream compaction using shared memory

Instructions (delete me)
========================
### Diffuse surface

This is **NOW** due ~~Thursday, September 24~~ **Tuesday, September 29** evening at midnight.
![](img/diffuse.png)

**Summary:**
In this project, you'll implement a CUDA-based path tracer capable of rendering
globally-illuminated images very quickly.
Since in this class we are concerned with working in GPU programming,
performance, and the generation of actual beautiful images (and not with
mundane programming tasks like I/O), this project includes base code for
loading a scene description file, described below, and various other things
that generally make up a framework for previewing and saving images.
### Perfectly specular-reflective surface

The core renderer is left for you to implement. Finally, note that, while this
base code is meant to serve as a strong starting point for a CUDA path tracer,
you are not required to use it if you don't want to. You may also change any
part of the base code as you please. **This is YOUR project.**
![](img/specular.png)

**Recommendation:** Every image you save should automatically get a different
filename. Don't delete all of them! For the benefit of your README, keep a
bunch of them around so you can pick a few to document your progress at the
end.
### Non-perfect specular surface

### Contents
![](img/nonperfect.png)

* `src/` C++/CUDA source files.
* `scenes/` Example scene description files.
* `img/` Renders of example scene description files.
(These probably won't match precisely with yours.)
* `external/` Includes and static libraries for 3rd party libraries.
### Antialiasing

![](img/antialias.png)

### Running the code
### Motion blur

![](img/blur.png)

### Work-efficient stream compaction

![](img/compaction.png)

Work-efficient stream compaction removes all the terminated rays to improve the rendering performance. This figure shows how the number of
active rays changing as trace depth increases in one single iteration. From the figure we can come to the conclusion that stream compaction only improves the rendering performance of open scenes since in closed scenes the rays will never terminate before reaching the maximum trace depth.


## Running the code

The main function requires a scene description file. Call the program with
one as an argument: `cis565_path_tracer scenes/sphere.txt`.
Expand All @@ -54,150 +54,13 @@ If you are using Visual Studio, you can set this in the Debugging > Command
Arguments section in the Project properties. Make sure you get the path right -
read the console for errors.

#### Controls
### Controls

* Esc to save an image and exit.
* Space to save an image. Watch the console for the output filename.
* W/A/S/D and R/F move the camera. Arrow keys rotate.

## Requirements

**Ask on the mailing list for clarifications.**

In this project, you are given code for:

* Loading and reading the scene description format
* Sphere and box intersection functions
* Support for saving images
* Working CUDA-GL interop for previewing your render while it's running
* A function which generates random screen noise (instead of an actual render).

You will need to implement the following features:

* Raycasting from the camera into the scene through an imaginary grid of pixels
(the screen).
* Implement simple antialiasing (by jittering rays within each pixel).
* Diffuse surfaces (using provided cosine-weighted scatter function) [PBRT 8.3].
* Perfectly specular-reflective (mirrored) surfaces.
* See notes on diffuse/specular in `scatterRay` and on imperfect specular below.
* Stream compaction optimization, using:
* **NEWLY ADDED:** Work-efficient stream compaction using shared memory across
multiple blocks. (See
[*GPU Gems 3*, Chapter 39](http://http.developer.nvidia.com/GPUGems3/gpugems3_ch39.html).)

You are also required to implement at least 2 of the following features. Please
ask if you need good references. If you find good references, share them!
**Extra credit**: implement more features on top of the 2 required ones,
with point value up to +20/100 atthe grader's discretion
(based on difficulty and coolness).

* **NOW REQUIRED - NOT AN EXTRA:** ~~Work-efficient stream compaction (see above).~~
* These 2 smaller features:
* Refraction (e.g. glass/water) [PBRT 8.2] with Frensel effects using
[Schlick's approximation](https://en.wikipedia.org/wiki/Schlick's_approximation)
or more accurate methods [PBRT 8.5].
* Physically-based depth-of-field (by jittering rays within an aperture)
[PBRT 6.2.3].
* Recommended but not required: non-perfect specular surfaces. (See below.)
* Texture mapping [PBRT 10.4].
* Bump mapping [PBRT 9.3].
* Direct lighting (by taking a final ray directly to a random point on an
emissive object acting as a light source). Or more advanced [PBRT 15.1.1].
* Some method of defining object motion, and motion blur by averaging samples
at different times in the animation.
* Subsurface scattering [PBRT 5.6.2, 11.6].
* Arbitrary mesh loading and rendering (e.g. `obj` files). You can find these
online or export them from your favorite 3D modeling application.
With approval, you may use a third-party OBJ loading code to bring the data
into C++.
* You can use the triangle intersection function `glm::intersectRayTriangle`.

This 'extra features' list is not comprehensive. If you have a particular idea
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, what did you do and why?
* Compare your GPU version of the feature to a HYPOTHETICAL CPU version
(you don't have to implement it!) Does it benefit or suffer from being
implemented on the GPU?
* How might this feature be optimized beyond your current implementation?

## Base Code Tour

You'll be working in the following files. Look for important parts of the code:
search for `CHECKITOUT`. You'll have to implement parts labeled with `TODO`.
(But don't let these constrain you - you have free rein!)

* `src/pathtrace.cu`: path tracing kernels, device functions, and calling code
* `pathtraceInit` initializes the path tracer state - it should copy
scene data (e.g. geometry, materials) from `Scene`.
* `pathtraceFree` frees memory allocated by `pathtraceInit`
* `pathtrace` performs one iteration of the rendering - it handles kernel
launches, memory copies, transferring some data, etc.
* See comments for a low-level path tracing recap.
* `src/intersections.h`: ray intersection functions
* `boxIntersectionTest` and `sphereIntersectionTest`, which take in a ray and
a geometry object and return various properties of the intersection.
* `src/interactions.h`: ray scattering functions
* `calculateRandomDirectionInHemisphere`: a cosine-weighted random direction
in a hemisphere. Needed for implementing diffuse surfaces.
* `scatterRay`: this function should perform all ray scattering, and will
call `calculateRandomDirectionInHemisphere`. See comments for details.
* `src/main.cpp`: you don't need to do anything here, but you can change the
program to save `.hdr` image files, if you want (for postprocessing).

### Generating random numbers

```
thrust::default_random_engine rng(hash(index));
thrust::uniform_real_distribution<float> u01(0, 1);
float result = u01(rng);
```

There is a convenience function for generating a random engine using a
combination of index, iteration, and depth as the seed:

```
thrust::default_random_engine rng = random_engine(iter, index, depth);
```

### Imperfect specular lighting

In path tracing, like diffuse materials, specular materials are
simulated using a probability distribution instead computing the
strength of a ray bounce based on angles.

Equations 7, 8, and 9 of
[*GPU Gems 3*, Chapter 20](http://http.developer.nvidia.com/GPUGems3/gpugems3_ch20.html)
give the formulas for generating a random specular ray. (Note that
there is a typographical error: χ in the text = ξ in the formulas.)

Also see the notes in `scatterRay` for probability splits between
diffuse/specular/other material types.

See also: PBRT 8.2.2.

### Handling Long-Running CUDA Threads

By default, your GPU driver will probably kill a CUDA kernel if it runs for more than 5 seconds. There's a way to disable this timeout. Just beware of infinite loops - they may lock up your computer.

> The easiest way to disable TDR for Cuda programming, assuming you have the NVIDIA Nsight tools installed, is to open the Nsight Monitor, click on "Nsight Monitor options", and under "General" set "WDDM TDR enabled" to false. This will change the registry setting for you. Close and reboot. Any change to the TDR registry setting won't take effect until you reboot. [Stack Overflow](http://stackoverflow.com/questions/497685/cuda-apps-time-out-fail-after-several-seconds-how-to-work-around-this)

### Notes on GLM

This project uses GLM for linear algebra.

On NVIDIA cards pre-Fermi (pre-DX12), you may have issues with mat4-vec4
multiplication. If you have one of these cards, be careful! If you have issues,
you might need to grab `cudamat4` and `multiplyMV` from the
[Fall 2014 project](https://github.com/CIS565-Fall-2014/Project3-Pathtracer).
Let us know if you need to do this.

### Scene File Format
## Scene File Format

This project uses a custom scene description format. Scene files are flat text
files that describe all geometry, materials, lights, cameras, and render
Expand Down Expand Up @@ -239,75 +102,17 @@ Objects are defined in the following fashion:
* TRANS (float transx) (float transy) (float transz) //translation
* ROTAT (float rotationx) (float rotationy) (float rotationz) //rotation
* SCALE (float scalex) (float scaley) (float scalez) //scale
* MOVING //define whether the object is moving or not
* TRANSGOAL (float transx) (float transy) (float transz) //translation of the movement goal
* FRAMES (int) //the frame span of the movement

Two examples are provided in the `scenes/` directory: a single emissive sphere,
Examples are provided in the `scenes/` directory: a single emissive sphere,
and a simple cornell box made using cubes for walls and lights and a sphere in
the middle.

## 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 path 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, at minimum,
result in you receiving an F for the semester.

## README

Please see: [**TIPS FOR WRITING AN AWESOME README**](https://github.com/pjcozzi/Articles/blob/master/CIS565/GitHubRepo/README.md)

* Sell your project.
* Assume the reader has a little knowledge of path tracing - don't go into
detail explaining what it is. Focus on your project.
* Don't talk about it like it's an assignment - don't say what is and isn't
"extra" or "extra credit." Talk about what you accomplished.
* Use this to document what you've done.
* *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.

In addition:

* 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 be 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 very good to show case this with a
video to show interactivity. If you do so, please include a link!

### Analysis

* Stream compaction helps most after a few bounces. Print and plot the
effects of stream compaction within a single iteration (i.e. the number of
unterminated rays after each bounce) and evaluate the benefits you get from
stream compaction.
* Compare scenes which are open (like the given cornell box) and closed
(i.e. no light can escape the scene). Again, compare the performance effects
of stream compaction! Remember, stream compaction only affects rays which
terminate, so what might you expect?


## Submit

If you have modified any of the `CMakeLists.txt` files at all (aside from the
list of `SOURCE_FILES`), you must test that your project can build in Moore
100B/C. Beware of any build issues discussed on the Google Group.

1. Open a GitHub pull request so that we can see that you have finished.
The title should be "Submission: YOUR NAME".
2. Send an email to the TA (gmail: kainino1+cis565@) with:
* **Subject**: in the form of `[CIS565] Project N: PENNKEY`.
* Direct link to your pull request on GitHub.
* Estimate the amount of time you spent on the project.
* If there were any outstanding problems, or if you did any extra
work, *briefly* explain.
* Feedback on the project itself, if any.

## References

* [PBRT] Physically Based Rendering, Second Edition: From Theory To Implementation. Pharr, Matt and Humphreys, Greg. 2010.
* Upenn CIS565 lecture slides by Patrick Cozzi
* http://http.developer.nvidia.com/GPUGems3/gpugems3_ch20.html
* http://http.developer.nvidia.com/GPUGems3/gpugems3_ch39.html
Binary file added img/antialias.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/blur.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/compaction.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/diffuse.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/nonperfect.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/specular.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion scenes/cornell.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ SCALE .01 10 10
// Sphere
OBJECT 6
sphere
material 4
material 1
TRANS -1 4 -1
ROTAT 0 0 0
SCALE 3 3 3
Loading