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: Anantha Srinivas #16

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0ef715a
SM Upgrade; Added initial code setup
ananthaks Sep 28, 2018
645b59d
Added coreBSDFs, warp functions and some common utilities
ananthaks Sep 28, 2018
97e8b59
Updates: Added coord conv matrices, simplified APIs, completed bsdf c…
ananthaks Sep 29, 2018
0367e31
Testing indentation
ananthaks Sep 29, 2018
a7a29c9
fix intersection logic; naive 1 iteration workimg
ananthaks Sep 29, 2018
7a40021
Naive working to an extent
ananthaks Sep 29, 2018
4d3edc1
Got basic Naive working; Some bug with screen being split
ananthaks Sep 29, 2018
c91a1f9
Full Naive working; Bug fix in bsdf
ananthaks Sep 30, 2018
04a5930
Added reflective material
ananthaks Sep 30, 2018
4b2a3bd
Update to stream compaction
ananthaks Sep 30, 2018
36f2ab0
Tried AA
ananthaks Sep 30, 2018
047c0a7
Corrected AntiAliasing
ananthaks Sep 30, 2018
583f27b
code refactor; stream compaction; refractive materials
ananthaks Oct 1, 2018
62c5096
Refactor for Direct Lighting
ananthaks Oct 1, 2018
aa7830e
Added Square plane geometry for area lights
ananthaks Oct 1, 2018
a8057e1
Added Plane sampling; fixed bug: sending obj by value instead of addres
ananthaks Oct 1, 2018
5ebafe5
Changed material loading; added glass mat; inifite mirrors
ananthaks Oct 1, 2018
bed0dcb
Sorting materials to ensure best warp utilization
ananthaks Oct 1, 2018
ca280ff
added intersection caching
ananthaks Oct 1, 2018
3630f5b
More work on Direct Lighting
ananthaks Oct 1, 2018
c608441
Small warnings
ananthaks Oct 1, 2018
d83b407
Code rehaul: to fix recursion issue
ananthaks Oct 2, 2018
00c84ba
Update readme
ananthaks Oct 2, 2018
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
77 changes: 71 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,78 @@
CUDA Path Tracer
================

**University of Pennsylvania, CIS 565: GPU Programming and Architecture, Project 3**
**University of Pennsylvania, CIS 565: GPU Programming and Architecture**

* (TODO) YOUR NAME HERE
* Tested on: (TODO) Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab)
**Anantha Srinivas**
[LinkedIn](https://www.linkedin.com/in/anantha-srinivas-00198958/), [Twitter](https://twitter.com/an2tha)

### (TODO: Your README)
**Tested on:**
* Windows 10, i7-8700 @ 3.20GHz 16GB, GTX 1080 8097MB (Personal)
* Built for Visual Studio 2017 using the v140 toolkit
---

*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.
![Figure 0: Cover](img/infinite_area.png)

![Figure 0: mats](img/Materials.png)

Introduction
---

Path tracer is computer graphics technique using which virtual scenes are rendered. The most popular version called as Monte Carlo path tracer is similar to the traditional Ray tracer, but instead of one ray per pixel multiple ray are launched. At each point of intersection, the rays are bounced off in a random direction, based on the material the ray intersected with. The distribution of these bounces are defined by a functional called as Bi Direction scattering distribution function.

A Path tracer implemented on the CPU is highly inefficient, given that for each pixel, we will need to cast multiple rays from the camera and trace it around the scene. A GPU based implementation would speed up this process, with computation of color for each pixel being run almost simulatanously on multiple threads.

![Figure 1: Ray Intersection](img/path_trace.png)

Implemented Features
---

1. A lot of structural changes to the code to reflect the architecture as described in **Physically Based Rendering, Second Edition: From Theory To Implementation** by Pharr, Matt and Humphreys, Greg.

2. Naive Integrator.

3. The path tracer supports the following materials:
* Diffuse materials

![Figure 2: Diffuse](img/Cornell_diffuse.png)

* Refractive material
![Figure 3: Refractive](img/Cornel_refraction_reflection.png)

* Specular (Perfectly specular and glossy)
![Figure 4: Parallel Mirrors](img/Glass_ball.png)

4. Rays between each iteration are compacted to remove any dead rays. This is done to improve the performance.

5. The Path segments are sorted by material type. This ensure that almost all warps executed on the GPU have similar execution time.

6. The first intersection is cached for subsequent iterations. This saves redundant calculation on the GPU.

7. Implemented Refraction (the refractive index is assumed to be 1.52, which should be later taken as input from the scene file)

8. Stocahstic sampled AntiAliasing. This jitters the ray direction from camera by a small amount. Over multiple interations, this results in a blurred effect.


|| No Anti-Aliasing | Anti-Alias 1 | Anti-Alias 2 |
:-------------------------:|:-------------------------:|:-------------------------: |:-------------------------:
Original Image|![](img/AA_00.png) | ![](img/AA_01.png) | ![](img/AA_02.png)
Zoomed|![](img/AA_00Zoomed.png) | ![](img/AA_01Zoomed.png) | ![](img/AA_02Zoomed.png)


9. Implemented Procedural geometry or implicit surfaces. Current supported implicit surfaces include - box, sphere, torus, capped cylinder. The intersection with the geometry is determined using ray marching.

![Figure 5: Implicit Surface](img/Implicit.png)


Analysis
---
Comparison in runtimes between CPU vs GPU based Path tracer (for Naive Integrator)

When compared to GPU based Path tracer, CPU is way more slow. Even with multi-threading enabled, the number of pixels computed per thread is limited.

![Figure 6: Performance grah](img/performance.png)


References
---
[PBRT] Physically Based Rendering, Second Edition: From Theory To Implementation. Pharr, Matt and Humphreys, Greg. 2010.
Binary file added img/AA_00.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/AA_00Zoomed.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/AA_01.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/AA_01Zoomed.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/AA_02.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/AA_02Zoomed.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/Cornel_refraction_reflection.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/Cornell_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/Glass_ball.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/Implicit.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/Materials.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/Mirror_room.png
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.
Binary file added img/infinite_2.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/infinite_area.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/path_trace.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/performance.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
144 changes: 144 additions & 0 deletions scenes/infinite_room.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// 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

// Specular white mirror
MATERIAL 5
RGB .98 .98 .98
SPECEX 0
SPECRGB 1.0 1.0 1.0
REFL 1
REFR 0
REFRIOR 0
EMITTANCE 0

// Refractive glass ball
MATERIAL 6
RGB .98 .98 .98
SPECEX 0
SPECRGB 1.0 1.0 1.0
REFL 0
REFR 1
REFRIOR 0
EMITTANCE 0

// Camera
CAMERA
RES 800 800
FOVY 45
ITERATIONS 500
DEPTH 10
FILE cornell
EYE -0.5 4 2
LOOKAT -10 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 10 .01 10

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

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

// Left wall
OBJECT 4
cube
material 5
TRANS -5 5 0
ROTAT 0 0 0
SCALE .01 10 10

// Right wall
OBJECT 5
plane
material 5
TRANS 5 5 0
ROTAT 0 -90 0
SCALE 10 10 1

// Front wall
OBJECT 6
plane
material 5
TRANS 0 5 5
ROTAT 0 180 0
SCALE 10 10 1

// Sphere
OBJECT 7
sphere
material 2
TRANS 0 4 -1
ROTAT 0 0 0
SCALE 3 3 3
166 changes: 166 additions & 0 deletions scenes/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
// Emissive material (light)
MATERIAL 0
RGB 1 1 1
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 5
DIFFUSE 0

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

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

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

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

// Specular white mirror
MATERIAL 5
RGB .98 .98 .98
SPECEX 0
SPECRGB 1.0 1.0 1.0
REFL 1
REFR 0
REFRIOR 0
EMITTANCE 0
DIFFUSE 0

// Refractive glass ball
MATERIAL 6
RGB .98 .98 .98
SPECEX 0
SPECRGB 0.98 0.98 0.98
REFL 0
REFR 1
REFRIOR 0
EMITTANCE 0
DIFFUSE 0

// Diffuse yellow
MATERIAL 7
RGB 1.0 .85 .32
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0
DIFFUSE 1

// Plastic blue
MATERIAL 8
RGB 0.08 0.15 0.6
SPECEX 0
SPECRGB 0 0 0
REFL 0
REFR 0
REFRIOR 0
EMITTANCE 0
DIFFUSE 1

// Camera
CAMERA
RES 800 800
FOVY 45
ITERATIONS 100
DEPTH 10
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 10 .01 10

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

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

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

// Right wall
OBJECT 5
plane
material 3
TRANS 5 5 0
ROTAT 0 -90 0
SCALE 10 10 1

// Sphere diffuse
OBJECT 6
cube
material 7
TRANS 0 4 -1
ROTAT 45 45 0
SCALE 3 3 3

Loading