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

Project3: Nuofan Xu #26

Open
wants to merge 3 commits into
base: main
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
86 changes: 81 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,87 @@ 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)
Nuofan Xu, Windows 10, AMD Ryzen 3800X, RTX2080 Super

### (TODO: Your README)
A CUDA-accelerated path tracer: a global-illumination renderer.

*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.
![](imgs/941.PNG)

*(The walls are implemented as diffusing surface, and the ball is implemented as perfect specular surface.)*
**

## Features
-Basic pathtracer
-Refractive, Reflective, and Diffused surfaces
-Antialiasing
-Depth of Field
-Direct Lighting
-Steam Compaction

### Material Surfaces

The pathtracer supports the following material surfaces:

* diffuse: light scatters uniformly from the surface
* specular/reflective (perfect): light reflects perfectly off the surface.
* refractive (using [Schlick's Approximation][wiki-schlick] of the Fresnel
effect to blend reflective and refractive light bounces).

[wiki-schlick]: https://en.wikipedia.org/wiki/Schlick%27s_approximation

### Triangle checking ###
![](imgs/triang.PNG)

### Refractive Ball ###
![](imgs/refractive.PNG)
*(The ball is implemented with 1.5 refraction rate)*

### Direct Light ###
To get a direct lighting effect in our images we want to make the last bounce of each ray hit a light source. We do this by randomly selecting a point on a randomly selected light and setting the direction of the ray to that point. The first image is without direct lighting, and the second one we can see is overall brighter with the direct lighting enabled.
![](imgs/direct_light.PNG)
![](imgs/941.PNG)

### Depth of Field

Depth of field simulates a physical aperture by varying the origin and direction
of rays shot from the camera. DOF is defined with a focal distance from the
camera, at which objects are perfectly in focus, and an aperture radius,
defining the amount of variance added to each ray.

![](imgs/blur.PNG)
![](imgs/941.PNG)

*(no DOF; DOF with distance 5.5, aperture 0.4; around 1000 iterations each)*

### Antialiasing

Camera rays are shot from the camera's position in the direction of a pixel.
Antialiasing jitters the target of the ray within a pixel. This is a brief
computation that happens once per pixel per iteration; it has little impact on
performance.

![](imgs/antialiasing.PNG)

*(Enlargement of antialiasing along wall corners (right) vs no antialiasing (left))*


### Stream compaction.

This pathtracer uses `thrust::stable_partition` to perform stream compaction on dead
rays. Reference: https://pbr-book.org/. The performance gain using stream compaction is analyzed using open scenes (room that has the front wall removed) vs closed scenes (room enclosed by walls as shown in previous images) and strong ceiling lighting (10x10, entire ceiling) and normal lighting (6x6).

![](imgs/stream_compact.PNG)

As we can see from the graph, the type of scene has a large effect on the number of rays alive in a scene, as expected. The type of scene (closed/open) tends to define the trend line for how many rays terminate at each bounce (by leaving the scene). The type of light defines how many rays terminate on the very first ray shoot, but only has a small effect on the trend line on rays terminating. The effect of stream compaction, however, becomes obvious as the bounce depth increases regardless of the scenes, and at a depth of 14, we can at least expect a performance increase of 50% assuming the calculation of "dying rays" cost similar to that of normal rays.

## Run

To build: `make`

To run: `build/cis565_path_tracer SCENE_FILE.txt`.

Some sample scene files are found in `scenes/`.

## Feedback

Any feedback regarding the correctness of code or the pathtracer in general is welcome.
Binary file added imgs/941.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 imgs/antialiased.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 imgs/antialiasing.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 imgs/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 imgs/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 imgs/cornell317.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 imgs/cornell663.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 imgs/depth_aliasing.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 imgs/direct_light.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 imgs/refractive.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 imgs/stream_compact.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 imgs/triang.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions scenes/cornell.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ MATERIAL 4
RGB .98 .98 .98
SPECEX 0
SPECRGB .98 .98 .98
REFL 1
REFR 0
REFRIOR 0
REFL 0
REFR 1
REFRIOR 1.5
EMITTANCE 0

// Camera
Expand Down
171 changes: 171 additions & 0 deletions scenes/diff.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
// Emissive material (light)
MATERIAL 0
RGB 1 1 1
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 5

// Diffuse white
MATERIAL 1
RGB .98 .98 .98
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0

// Diffuse red
MATERIAL 2
RGB .85 .35 .35
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0

// Diffuse green
MATERIAL 3
RGB .35 .85 .35
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0

// Specular white
MATERIAL 4
RGB .98 .98 .98
SPECEX 0
SPECRGB .98 .98 .98
REFL 1
REFR 0
REFRIOR 0
EMITTANCE 0

// Glass
MATERIAL 5
RGB 1.0 1.0 1.0
SPECEX 0
SPECRGB 1.0 1.0 1.0
REFL 0
REFR 1
REFRIOR 1.5
EMITTANCE 0

// Blue Glass
MATERIAL 6
RGB .98 .98 .98
SPECEX 0
SPECRGB .85 .85 .98
REFL 0
REFR 1
REFRIOR 1.65
EMITTANCE 0

// Diffuse Blue
MATERIAL 7
RGB .35 .85 .85
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0

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


// Ceiling light
OBJECT 0
cube
material 0
TRANS 0 10 0
ROTAT 0 0 0
SCALE 3 .3 3

// Floor
OBJECT 1
cube
material 1
TRANS 0 0 0
ROTAT 0 0 0
SCALE 16 .01 16

// Ceiling
OBJECT 2
cube
material 1
TRANS 0 10 0
ROTAT 0 0 90
SCALE .01 16 16

// Back wall
OBJECT 3
cube
material 1
TRANS 0 5 -5
ROTAT 0 90 0
SCALE .01 16 16

// Left wall
OBJECT 4
cube
material 2
TRANS -8 5 0
ROTAT 0 0 0
SCALE .01 16 16

// Right wall
OBJECT 5
cube
material 3
TRANS 8 5 0
ROTAT 0 0 0
SCALE .01 16 16

// Sphere
//OBJECT 6
//sphere
//material 6
//TRANS 0 5 5
//ROTAT 0 0 0
//SCALE 3 3 3

// Sphere 2
//OBJECT 7
//sphere
//material 7
//TRANS -3 2 -1
//ROTAT 0 0 0
//SCALE 3 3 3

// Sphere 3
//OBJECT 8
//sphere
//material 6
//TRANS 2 3 6
//ROTAT 0 0 0
//SCALE 3 3 3

//outside light
OBJECT 6
cube
material 0
TRANS 0 4 12
ROTAT 90 0 0
SCALE 3 .3 3
14 changes: 12 additions & 2 deletions scenes/sphere.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Emissive material (light)
MATERIAL 0
RGB 1 1 1
RGB 0 1 0
SPECEX 0
SPECRGB 0 0 0
REFL 0
Expand All @@ -25,4 +25,14 @@ sphere
material 0
TRANS 0 0 0
ROTAT 0 0 0
SCALE 3 3 3
SCALE 1 1 1

// mesh
OBJECT 7
cube.obj
material 0
FILENAME cube.obj
TRANS 2 2 1
ROTAT 0 0 0
SCALE 3 3 3

30 changes: 15 additions & 15 deletions src/glslUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ namespace glslUtility {

// embedded passthrough shaders so that default passthrough shaders don't need to be loaded
static std::string passthroughVS =
" attribute vec4 Position; \n"
" attribute vec2 Texcoords; \n"
" varying vec2 v_Texcoords; \n"
" \n"
" void main(void){ \n"
" v_Texcoords = Texcoords; \n"
" gl_Position = Position; \n"
" }";
" attribute vec4 Position; \n"
" attribute vec2 Texcoords; \n"
" varying vec2 v_Texcoords; \n"
" \n"
" void main(void){ \n"
" v_Texcoords = Texcoords; \n"
" gl_Position = Position; \n"
" }";
static std::string passthroughFS =
" varying vec2 v_Texcoords; \n"
" \n"
" uniform sampler2D u_image; \n"
" \n"
" void main(void){ \n"
" gl_FragColor = texture2D(u_image, v_Texcoords); \n"
" }";
" varying vec2 v_Texcoords; \n"
" \n"
" uniform sampler2D u_image; \n"
" \n"
" void main(void){ \n"
" gl_FragColor = texture2D(u_image, v_Texcoords); \n"
" }";

typedef struct {
GLuint vertex;
Expand Down
4 changes: 2 additions & 2 deletions src/glslUtility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace glslUtility {

GLuint createDefaultProgram(const char *attributeLocations[], GLuint numberOfLocations);
GLuint createProgram(const char *vertexShaderPath, const char *fragmentShaderPath,
const char *attributeLocations[], GLuint numberOfLocations);
const char *attributeLocations[], GLuint numberOfLocations);
}

#endif
#endif
Loading