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: Spencer Webster-Bass #33

Open
wants to merge 13 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 @@ -92,10 +92,10 @@ list(SORT sources)
source_group(Headers FILES ${headers})
source_group(Sources FILES ${sources})

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

cuda_add_executable(${CMAKE_PROJECT_NAME} ${sources} ${headers})
target_link_libraries(${CMAKE_PROJECT_NAME}
${LIBRARIES}
#stream_compaction # TODO: uncomment if using your stream compaction
# stream_compaction # TODO: uncomment if using your stream compaction
)
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,30 @@ 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)
* SPENCER WEBSTER-BASS
* [LinkedIn](https://www.linkedin.com/in/spencer-webster-bass/)
* Tested on: Windows 10, i7-6700 @ 3.40GHz 16GB, Quadro P1000 222MB (MOR100B-19)

### (TODO: Your README)
### 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.
Path tracers are programs that have th eability to simulate the physics of light to create photorealistic images. Path tracers are computationally expensive, but embarrasingly parallel; this quality lends them to implementations on the GPU to speed up run times. This project is a GPU implementation of a path tracer using CUDA and C++.

Features:
* Diffuse and specular shaders
* Path culling using stream compaction

### BLOOPERS

![Render 1](img/renders/cornell.2020-10-01_03-19-56z.9samp.png)

![Render 2](img/renders/cornell.2020-10-01_03-22-37z.2samp.png)

![Render 3](img/renders/cornell.2020-10-01_03-24-32z.18samp.png)

![Render 4](img/renders/cornell.2020-10-01_03-24-32z.2samp.png)

![Render 5](img/renders/cornell.2020-10-01_03-29-14z.8samp.png)

### REFERENCES

* Specular Highlight Formula: http://ogldev.org/www/tutorial19/tutorial19.html#:~:text=Let's%20finalize%20the%20formula%20of,the%20material%20('M').
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
126 changes: 120 additions & 6 deletions src/interactions.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ glm::vec3 calculateRandomDirectionInHemisphere(
*
* The visual effect you want is to straight-up add the diffuse and specular
* components. You can do this in a few ways. This logic also applies to
* combining other types of materias (such as refractive).
* combining other types of materials (such as refractive).
*
* - Always take an even (50/50) split between a each effect (a diffuse bounce
* and a specular bounce), but divide the resulting color of either branch
Expand All @@ -68,12 +68,126 @@ glm::vec3 calculateRandomDirectionInHemisphere(
*/
__host__ __device__
void scatterRay(
PathSegment & pathSegment,
glm::vec3 intersect,
glm::vec3 normal,
const Material &m,
thrust::default_random_engine &rng) {
const Camera& cam,
thrust::default_random_engine& rng,
PathSegment& pathSegment,
ShadeableIntersection& intersection,
Material& mat,
const int* lights,
int lightsNum,
const Geom* geoms,
Material* materials)
{
// TODO: implement this.
// A basic implementation of pure-diffuse shading will just call the
// calculateRandomDirectionInHemisphere defined above.
glm::vec3 color;
glm::vec3 normal = intersection.surfaceNormal;
glm::vec3 wi = -pathSegment.ray.direction;
pathSegment.ray.origin = intersection.intersectPos;

thrust::uniform_real_distribution<float> u01(0, 1);
float randMat = u01(rng);

// computing which light to sample from
// and its relevant features
float rL = u01(rng) * lightsNum;
int randLight = (int)rL;
glm::vec3 L = geoms[lights[randLight]].translation - pathSegment.ray.origin;
L = glm::normalize(L);

// used 2nd suggestion for determining which material to sample
if (randMat <= mat.hasReflective) {
// specular calculation
glm::vec3 r = glm::reflect(pathSegment.ray.direction, normal);
glm::vec3 v = glm::normalize(intersection.intersectPos);
color = glm::vec3(1.f) * mat.specular.color * mat.hasReflective * glm::pow(glm::dot(r, v), mat.specular.exponent) / mat.hasReflective;
// glm::vec3 v = glm::normalize(cam.position - intersection.intersectPos);
// color = glm::vec3(1.f) * mat.specular.color * mat.hasReflective * glm::pow(glm::dot(r, v), mat.specular.exponent) / mat.hasReflective;
color = mat.specular.color;
pathSegment.ray.direction = r;
}
else {
// diffuse calculation
float diffuse = glm::dot(normal, L);
float ambient = 0.2;
float lux = diffuse + ambient;
color = pathSegment.throughput * mat.color * lux / (1.f - mat.hasReflective);
// color = mat.color * pathSegment.throughput;
color = mat.color;

// update throughput
pathSegment.throughput *= color * glm::abs(glm::dot(pathSegment.ray.direction, normal)) / TWO_PI;
// update light bounce direction
pathSegment.ray.direction = calculateRandomDirectionInHemisphere(normal, rng);
}

pathSegment.color = color;
pathSegment.remainingBounces--;
// pathSegment.remainingBounces = 0;
}


// Ray Tracer Code...
// Also make sure to uncomment Option 1 in shadeFakeMaterial
/*
__host__ __device__
void scatterRay(
const Camera& cam,
thrust::default_random_engine& rng,
PathSegment& pathSegment,
ShadeableIntersection& intersection,
Material& mat,
const int* lights,
int lightsNum,
const Geom* geoms,
Material* materials)
{
// TODO: implement this.
// A basic implementation of pure-diffuse shading will just call the
// calculateRandomDirectionInHemisphere defined above.
glm::vec3 color;
glm::vec3 normal = intersection.surfaceNormal;
glm::vec3 wi = -pathSegment.ray.direction;
pathSegment.ray.origin = intersection.intersectPos;

thrust::uniform_real_distribution<float> u01(0, 1);
float randMat = u01(rng);

// computing which light to sample from
// and its relevant features
float rL = u01(rng) * lightsNum;
int randLight = (int)rL;
glm::vec3 L = geoms[lights[randLight]].translation - pathSegment.ray.origin;
L = glm::normalize(L);

// used 2nd suggestion for determining which material to sample
if (randMat <= mat.hasReflective) {
// specular calculation
glm::vec3 r = glm::reflect(pathSegment.ray.direction, normal);
glm::vec3 v = glm::normalize(intersection.intersectPos);
color = glm::vec3(1.f) * mat.specular.color * mat.hasReflective * glm::pow(glm::dot(r, v), mat.specular.exponent) / mat.hasReflective;
// glm::vec3 v = glm::normalize(cam.position - intersection.intersectPos);
// color = glm::vec3(1.f) * mat.specular.color * mat.hasReflective * glm::pow(glm::dot(r, v), mat.specular.exponent) / mat.hasReflective;
color = mat.specular.color;
pathSegment.ray.direction = r;
}
else {
// diffuse calculation
float diffuse = glm::dot(normal, L);
float ambient = 0.2;
float lux = diffuse + ambient;
color = pathSegment.throughput * mat.color * lux / (1.f - mat.hasReflective);
// color = mat.color * pathSegment.throughput;

// update throughput
pathSegment.throughput *= color * glm::abs(glm::dot(pathSegment.ray.direction, normal)) / TWO_PI;
// update light bounce direction
pathSegment.ray.direction = calculateRandomDirectionInHemisphere(normal, rng);
}

pathSegment.color = color;
pathSegment.remainingBounces--;
pathSegment.remainingBounces = 0;
}
*/
Loading