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
54 changes: 49 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,55 @@ 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)
* Alexander Perry
* Tested on: Windows 10, i5-2410M @ 2.30GHz 8GB, NVS 4200M (personal computer)

### (TODO: Your README)
![](./build/.2017-10-01_22-05-47z.325samp.png)

*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.
This is my most representative image of the ray tracer. It includes antialiasing and path compression. It took a couple minutes to render.
Due to the low stats of my GPU I was unable to get high occupancy on many of the kernels. Several take a couple dozen registers to run with not much room to optimization. This limited the occupancy in the long running kernels to 33-46% and limited the overall performance of the renderer.

## Depth of field

![](./build/.2017-10-02_19-39-46z.622samp.png)

![](./build/.2017-10-02_19-45-37z.709samp.png)

These images showcase the depth of field effect. The first image has the focal distance set to near the center sphere while the second has the focal distance set to the distance of the rear wall. In the second image, it is clear to see the out-of-focusness increase along the wall toward the camera as the bleed-over increases between the walls and the floor/ceiling.

Depth of field was implemented by jittering ray origins in a disc.

![](./build/.2017-10-02_19-35-20z.20samp.png)

![](./build/.2017-10-02_19-35-49z.40samp.png)

![](./build/.2017-10-02_19-36-23z.120samp.png)

This is a series of images with reducing lensRadius. The focal distance is closer than everything in the scene but one can see how the radius of the lens affects the blur.

## Antialias

![](./img/no_aa.png)
![](./img/with_aa.png)

These images were created with no antialias for the first image and with antialiasing on the second. Both images were approximately 325 samples. Through the noise, it is possible to tell that the image on the left is a bit blockier along the edge.

Antialiasing was accomplished by jittering rays in a pixel. This is possible to run at the same time as depth of field. Antialiasing runs first, followed by depth of field in that case.

## Direct lighting

Direct lighting was accomplished by sending a feeler ray to a random light source of all rays still alive at the end of the iterations. This helps the image converge faster as more pixels have a light source in them at the end.

## Bloopers

![](./build/.2017-09-29_00-13-42z.22samp.png)

This was caused by drawing all pixels at the end rather than only valid pixels. Due to stream compaction, pixels at the end of the array (at the bottom of the screen) showed up multiple times in the array and were significantly brighter.

![](./build/.2017-09-29_01-50-03z.494samp.png)

This is standard "shadow acne". Due to floating point error, intersections were occuring in the wall rather than in front of it.

![](./build/.2017-10-01_03-30-23z.1samp.png)

This was early in setting up direct lighting.
Binary file added build/.2017-09-28_20-54-46z.1036samp.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 build/.2017-09-28_21-07-32z.13samp.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 build/.2017-09-28_21-29-26z.129samp.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 build/.2017-09-28_21-38-06z.174samp.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 build/.2017-09-28_21-43-39z.32samp.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 build/.2017-09-28_21-57-59z.6samp.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 build/.2017-09-28_22-00-02z.3samp.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 build/.2017-09-28_22-01-21z.3samp.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 build/.2017-09-28_22-06-03z.37samp.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 build/.2017-09-28_22-11-11z.33samp.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 build/.2017-09-28_22-14-23z.35samp.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 build/.2017-09-28_22-18-07z.12samp.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 build/.2017-09-28_22-19-07z.7samp.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 build/.2017-09-28_22-19-53z.80samp.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 build/.2017-09-28_22-32-12z.3samp.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 build/.2017-09-28_22-45-19z.95samp.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 build/.2017-09-29_00-03-20z.12samp.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 build/.2017-09-29_00-13-42z.22samp.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 build/.2017-09-29_00-21-30z.636samp.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 build/.2017-09-29_00-28-33z.397samp.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 build/.2017-09-29_00-28-33z.566samp.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 build/.2017-09-29_01-47-02z.34samp.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 build/.2017-09-29_01-47-02z.78samp.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 build/.2017-09-29_01-50-03z.160samp.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 build/.2017-09-29_01-50-03z.491samp.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 build/.2017-09-29_01-50-03z.494samp.png
Binary file added build/.2017-09-29_01-57-48z.675samp.png
Binary file added build/.2017-09-30_18-52-05z.341samp.png
Binary file added build/.2017-09-30_19-03-03z.40samp.png
Binary file added build/.2017-09-30_19-04-35z.11samp.png
Binary file added build/.2017-09-30_20-56-25z.11samp.png
Binary file added build/.2017-09-30_21-23-11z.11samp.png
Binary file added build/.2017-09-30_21-29-44z.7samp.png
Binary file added build/.2017-09-30_21-30-26z.3samp.png
Binary file added build/.2017-09-30_21-36-36z.4samp.png
Binary file added build/.2017-09-30_21-39-00z.6samp.png
Binary file added build/.2017-09-30_21-55-40z.41samp.png
Binary file added build/.2017-09-30_21-58-09z.15samp.png
Binary file added build/.2017-09-30_23-58-31z.12samp.png
Binary file added build/.2017-10-01_00-01-19z.8samp.png
Binary file added build/.2017-10-01_00-03-11z.5samp.png
Binary file added build/.2017-10-01_00-07-24z.4samp.png
Binary file added build/.2017-10-01_01-04-33z.2samp.png
Binary file added build/.2017-10-01_01-06-13z.1samp.png
Binary file added build/.2017-10-01_01-39-47z.9samp.png
Binary file added build/.2017-10-01_01-40-53z.5samp.png
Binary file added build/.2017-10-01_01-41-35z.2samp.png
Binary file added build/.2017-10-01_02-44-12z.7samp.png
Binary file added build/.2017-10-01_02-47-22z.7samp.png
Binary file added build/.2017-10-01_02-48-08z.466samp.png
Binary file added build/.2017-10-01_03-30-23z.1samp.png
Binary file added build/.2017-10-01_03-32-11z.9samp.png
Binary file added build/.2017-10-01_04-29-01z.8samp.png
Binary file added build/.2017-10-01_04-30-08z.3samp.png
Binary file added build/.2017-10-01_04-41-49z.6samp.png
Binary file added build/.2017-10-01_18-33-45z.85samp.png
Binary file added build/.2017-10-01_18-37-35z.39samp.png
Binary file added build/.2017-10-01_19-14-06z.50samp.png
Binary file added build/.2017-10-01_20-03-51z.8samp.png
Binary file added build/.2017-10-01_20-41-04z.146samp.png
Binary file added build/.2017-10-01_21-08-32z.120samp.png
Binary file added build/.2017-10-01_21-10-21z.30samp.png
Binary file added build/.2017-10-01_21-11-26z.217samp.png
Binary file added build/.2017-10-01_21-25-23z.45samp.png
Binary file added build/.2017-10-01_21-25-23z.568samp.png
Binary file added build/.2017-10-01_21-32-18z.70samp.png
Binary file added build/.2017-10-01_21-59-34z.147samp.png
Binary file added build/.2017-10-01_22-01-28z.404samp.png
Binary file added build/.2017-10-01_22-05-47z.325samp.png
Binary file added build/.2017-10-01_22-25-30z.1samp.png
Binary file added build/.2017-10-02_19-35-20z.20samp.png
Binary file added build/.2017-10-02_19-35-49z.40samp.png
Binary file added build/.2017-10-02_19-36-23z.120samp.png
Binary file added build/.2017-10-02_19-38-17z.138samp.png
Binary file added build/.2017-10-02_19-39-46z.622samp.png
Binary file added build/.2017-10-02_19-45-37z.709samp.png
Binary file added build/.2017-10-02_19-45-37z.901samp.png
Binary file added build/.2017-10-02_19-54-33z.102samp.png
Binary file added build/.2017-10-02_19-54-33z.57samp.png
Binary file added build/.2017-10-03_01-18-22z.325samp.png
Binary file added build/.2017-10-03_01-21-45z.324samp.png
Binary file added build/Release/.2017-10-01_04-01-15z.2samp.png
Binary file added build/Release/.2017-10-01_04-01-28z.2samp.png
Binary file added build/Release/.2017-10-01_04-04-59z.2samp.png
Binary file added img/no_aa.png
Binary file added img/with_aa.png
3 changes: 3 additions & 0 deletions scenes/cornell.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@ EMITTANCE 0
// Camera
CAMERA
RES 800 800
//RES 200 200
FOVY 45
ITERATIONS 5000
DEPTH 8
FILE cornell
EYE 0.0 5 10.5
LOOKAT 0 5 0
UP 0 1 0
FOCALLENGTH 15.5
LENSRADIUS 1.5


// Ceiling light
Expand Down
7 changes: 4 additions & 3 deletions scenes/sphere.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ EMITTANCE 5

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

// Sphere
Expand Down
35 changes: 29 additions & 6 deletions src/interactions.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,36 @@ glm::vec3 calculateRandomDirectionInHemisphere(
* You may need to change the parameter list for your purposes!
*/
__host__ __device__
void scatterRay(
PathSegment & pathSegment,
glm::vec3 intersect,
glm::vec3 normal,
const Material &m,
thrust::default_random_engine &rng) {
void scatterRayUniform(
PathSegment &pathSegment,
glm::vec3 &intersect,
glm::vec3 &normal,
const Material &m,
thrust::default_random_engine &rng) {
// TODO: implement this.
// A basic implementation of pure-diffuse shading will just call the
// calculateRandomDirectionInHemisphere defined above.
glm::vec3 dir = calculateRandomDirectionInHemisphere(normal, rng);
pathSegment.ray.direction = dir;
pathSegment.ray.origin = intersect+dir*0.00001f; // avoid shadow acne
--pathSegment.remainingBounces;
//pathSegment.color = pathSegment.remainingBounces > 0 ?
// pathSegment.color * m.color : glm::vec3(0.0f);
pathSegment.color = pathSegment.color * m.color;
}

__host__ __device__
void scatterRaySpecular(
PathSegment &pathSegment,
glm::vec3 &intersect,
glm::vec3 &normal,
const Material &m,
thrust::default_random_engine &rng) {
glm::vec3 dir = glm::reflect(pathSegment.ray.direction, normal);
pathSegment.ray.direction = dir;
pathSegment.ray.origin = intersect+dir*0.00001f; // avoid shadow acne
--pathSegment.remainingBounces;
//pathSegment.color = pathSegment.remainingBounces > 0 ?
// pathSegment.color * m.specular.color : glm::vec3(0.0f);
pathSegment.color = pathSegment.color* m.specular.color;
}
13 changes: 7 additions & 6 deletions src/intersections.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ __host__ __device__ glm::vec3 multiplyMV(glm::mat4 m, glm::vec4 v) {
* @param outside Output param for whether the ray came from outside.
* @return Ray parameter `t` value. -1 if no intersection.
*/
__host__ __device__ float boxIntersectionTest(Geom box, Ray r,
glm::vec3 &intersectionPoint, glm::vec3 &normal, bool &outside) {
__host__ __device__ float boxIntersectionTest(Geom &box, Ray &r,
glm::vec3 &intersectionPoint, glm::vec3 &normal/*, bool &outside*/) {
Ray q;
q.origin = multiplyMV(box.inverseTransform, glm::vec4(r.origin , 1.0f));
q.direction = glm::normalize(multiplyMV(box.inverseTransform, glm::vec4(r.direction, 0.0f)));
Expand Down Expand Up @@ -76,11 +76,11 @@ __host__ __device__ float boxIntersectionTest(Geom box, Ray r,
}

if (tmax >= tmin && tmax > 0) {
outside = true;
//outside = true;
if (tmin <= 0) {
tmin = tmax;
tmin_n = tmax_n;
outside = false;
//outside = false;
}
intersectionPoint = multiplyMV(box.transform, glm::vec4(getPointOnRay(q, tmin), 1.0f));
normal = glm::normalize(multiplyMV(box.transform, glm::vec4(tmin_n, 0.0f)));
Expand All @@ -99,8 +99,8 @@ __host__ __device__ float boxIntersectionTest(Geom box, Ray r,
* @param outside Output param for whether the ray came from outside.
* @return Ray parameter `t` value. -1 if no intersection.
*/
__host__ __device__ float sphereIntersectionTest(Geom sphere, Ray r,
glm::vec3 &intersectionPoint, glm::vec3 &normal, bool &outside) {
__host__ __device__ float sphereIntersectionTest(Geom &sphere, Ray &r,
glm::vec3 &intersectionPoint, glm::vec3 &normal/*, bool &outside*/) {
float radius = .5;

glm::vec3 ro = multiplyMV(sphere.inverseTransform, glm::vec4(r.origin, 1.0f));
Expand All @@ -120,6 +120,7 @@ __host__ __device__ float sphereIntersectionTest(Geom sphere, Ray r,
float firstTerm = -vDotDirection;
float t1 = firstTerm + squareRoot;
float t2 = firstTerm - squareRoot;
bool outside;

float t = 0;
if (t1 < 0 && t2 < 0) {
Expand Down
Loading