Skip to content

Commit

Permalink
improved readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mattelser committed Oct 12, 2021
1 parent 3795f34 commit 6a9b5cd
Show file tree
Hide file tree
Showing 20 changed files with 385 additions and 192 deletions.
100 changes: 72 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,40 @@ CUDA Path Tracer
* Tested on: Tested on: Windows 10, i3-10100F @ 3.6GHz 16GB, GeForce 1660 Super 6GB

### Features
![nice image or two showing off some features]()
![Stanford tryranosaurus](img/trex.png)
![DOF example](img/DOF.png)

This is a GPU based forward path tracer, which renders scenes by calculating "camera rays" bouncing around the scene,
simulating individual light rays. The renderer supports the following features:
- Arbitrary mesh loading using .obj file format
- Multiple shader BSDFs, including refraction
- Anti-aliasing
- Depth of Field
- Minor optimizations
- Several optimizations
- Adaptive Sampling* (not fully implemented)
- Bloopers

### Arbitrary mesh loading
The renderer supports loading arbitrary meshes via .obj files.
The renderer supports loading arbitrary meshes via .obj files using
(`tinyobjloader`)[https://github.com/tinyobjloader/tinyobjloader].

One issue discovered was that the triangle intersection detection function
initially used (`glm::intersectRayTriangle()`) does not compute intersections
with the "back" of faces. This caused problems for open meshes like the Newell Teapot
or for meshes assigned a refraction shader, as can be seen here:
![newell teapot hole image]()
![incomplete refraction image]()
A bounding box is calculated at load time and used to optimize ray intersection
detection. The bounding box is a mesh itself, consisting of tris. Each ray in
the scene is initially tested for intersection with these tris, and only if an
intersection is found will the ray be checked against the mesh's tris.

One issue discovered was that the triangle intersection detection function
initially used (`glm::intersectRayTriangle()`) does not compute intersections
with the "back" of faces. This caused problems for open meshes like the Newell Teapot
or for meshes assigned a refraction shader, as can be seen here:
![newell teapot hole image](img/back_face_cull_issue.png)
Also somewhat visible through the noise is a secondary effect of this back face
issue: collisions with the bounding box are not detected from within the
bounding box. Notice the sharp lines on the floor cutting off the diffuse
bounce close to the teapot. This is from rays on the floor near the teapot
casting outward and missing the teapot bounding box, and therefore not
checking for collisions with any of the teapots actual tris.

Performance impacts:
- no spatial optimizations are made (other than the bounding box), so each
ray that hits the bounding box is checked against every triangle in the mesh.
Expand All @@ -48,25 +56,27 @@ inherit whatever memory value the normals were initialized to.
BSDFs are implemented to allow for pure diffuse objects, objects with diffuse
and reflections, as well as objects with both reflection and refraction. The
Fresnel effect is calculated using Schlick's approximation
![image showing off different materials]()

Since physically correct models do not always provide the preferred result, the
Fresnel effect is tuneable via a user parameter. Note this is separate from the
index of refraction (also tuneable), this is an additional parameter which controls
the power used in Schlick's approximation.
![image showing different Fresnel powers]()

Performance impacts:
- TODO: compare scene performance with/without some shader types
![Fresnel power comparison](img/fresnel_comparison.png)
The sphere on the right has a Fresnel power of 1, which dramatically changes
the reflect/refract ratio in favor of reflection. The sphere in the middle has
a Fresnel power of 3, which is only a subltle change from the (standard)
Fresnel power of 5 on the rightmost sphere.

Known limitations:
- objects with refractions are assumed to have reflection. An object can be reflective without
refraction, but not vice-versa.

### Anti-aliasing
anti-aliasing was accomplished by jittering the origin of camera rays for the initial bounce.
![image without anti-aliasing]()
![image with anti-aliasing]()
![image without anti-aliasing](img/antialias_off.png)
![image with anti-aliasing](img/antialias_on.png)
The first image has no antialiasing and has jagged pixelated edges along
horizontal lines. The second image has cleaner lines with no notable "jaggies".

Performance impacts:
- An unnoticeable impact to the time it takes each pixel to converge as a result of adding some small randomness.
Expand All @@ -76,15 +86,19 @@ slightly varied camera ray origins each iteration.
### Depth of Field
Depth of field can optionally be simulated, with tuneable parameters for aperture size, lens radius,
and focal distance.
![image showing off depth of field]()
![DOF example](img/DOFOFF.png)
![DOF example](img/DOF.png)
The first image shows a scene with no simulated depth of field. The second
image has depth of field turned on, simulating the blur according to distance
in the same way a physical camera lens would.

Performance impacts:
- Using DOF requires a greater number of iterations to produce a clean image. The blur is a result
of a stochastic process, and as a result the greater the blur the larger the variance of each blurred pixel
Known limitations:
- This can not be combined with the "first bounce cache" optimization as it depends on
slightly varied camera rays each iteration.
### Minor optimizations
### Optimizations
- first bounce cache
An option is provided to cache the first bounce of each camera ray from iteration 1, and use that cache
for each subsequent iteration (until the camera is moved, generating a new iteration 1 and a new cache).
Expand All @@ -94,13 +108,25 @@ different code paths as a result of conditionals), rays can optionally be
sorted by their material id. This manimizes the number of warps with different
materials, which may take different amounts of time as a result of calculated
differing BSDFs.
- cull dead bounces
- use stream compaction to cull dead bounces
Bounces that do not hit an object (i.e. which go off into space) are culled every iteration.

The following data was gathered from a single test scene using multiple
shaders, across all available BRDFS. All renders were run to 100 iterations at
a resolution of 720x480. Here is the test scene at 5000 iterations:
![test scene full render](img/test_scene.png)

![optimization comparison](img/optimization_comparison.png)
Performance impacts:
- first bounce cache provides a noticeable improvement (TODO add a metric for this)
- Sorting materials is noteably worse. (TODO provide a metric)
- culling dead bounces (I think?) has a relatively neutral impact (TODO confirm and add metric)
- notably, all optimizations are slightly worse for a trace depth of 8, when
the benefit of these optimizations has not yet outweighed their overhead.
- first bounce cache provides a steady, but minor improvement.
- Stream compaction provides the most dramatic improvement, even in a scene
that is mostly filled by collideable objects.
- sorting materials provides a notable decrease in render times which increases
slightly as the trace depth increases.
- All optimizations provide a performance increase of approximately 2x!

Known limitations:
- As noted above, first bounce cache cannot be combined with DOF or anti-aliasing.
### Adaptive Sampling* (incomplete)
Expand Down Expand Up @@ -128,11 +154,29 @@ pixels of the image are always culled instead of the pixels which have
converged. This is likely due to a sorting mismatch, or using the wrong number
of paths when calling some relevant function. This has not been fixed in time.

![accurate heatmap showing incorrect sampling]()
![Disfunctional adaptive sampling](img/adaptiveSampleBug.png)
![accurate heatmap showing incorrect sampling](img/heatmap.png)
White represents pixels which required the maximum number of iterations, black
indicates immediate culling. Note the gradient in the heat map showing that
pixels are culled from the bottom up as iterations increase. This reflects what
can be seen in the render itself: the bottom is noisy and gets less noisy
towards the top.
### Bloopers
![several]()
![bloopers]()
![here]()
![with]()
![explanations]()
![stream compaction VHS](img/stream_compaction_blooper.png)
This image is the result of a stream compaction issue. The VHS-like look of it
is amplified by the banded noise at the top, which is the result of a race
condition when sorting paths.
![refraction hall of horrors](img/refraction_mesh_blooper.png)
![refraction hall of horrors](img/refraction_mesh_blooper2.png)
These works of art were created while attempting to fix the mesh back face
collision detection issue described above.

### Notable Sources
- As noted above,
(`tinyobjloader`)[https://github.com/tinyobjloader/tinyobjloader] was used for
mesh loading.
- As noted in the comments, Stack Exchange and Stack overflow
provided the math for two vector manipulation methods
- Matt Pharr & Grep Humphreys Physically Based Rendering Texbook provided useful context


Binary file added img/DOF.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/DOFOFF.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/adaptiveSampleBug.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/antialias_off.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/antialias_on.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/back_face_cull_issue.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/fresnel_comparison.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/heatmap.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/optimization_comparison.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/refraction_mesh_blooper.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/refraction_mesh_blooper2.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/stream_compaction_blooper.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/subpixel_sampling_blooper.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/test_scene.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/trex.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/DOF.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ EMITTANCE 0

// Camera
CAMERA
RES 720 480
RES 1080 720
FOVY 40
ITERATIONS 5000
DEPTH 8
Expand Down
123 changes: 69 additions & 54 deletions scenes/cornell.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ CACHE_BOUNCE 1
USE_DOF 0
ANTIALIAS 1
USE_BBOX 1
ADAPTIVE_SAMPLING 1
MIN_SAMPLES 2
ADAPTIVE_SAMPLING 0
MIN_SAMPLES 2000
PIX_VARIANCE 0.2


Expand All @@ -19,7 +19,7 @@ REFL 0
REFR 0
REFRIOR 0
FRESNELPOW 5
EMITTANCE 5
EMITTANCE 15

// Diffuse white
MATERIAL 1
Expand Down Expand Up @@ -111,82 +111,113 @@ EMITTANCE 0

// Camera
CAMERA
RES 800 800
RES 800 600
FOVY 45
ITERATIONS 5000
DEPTH 8
FILE cornell
FOCALDIST 8
APERTURE 0.5
LENSRAD 1
EYE 0.0 5 10.5
LOOKAT 0 5 0
EYE 0.0 9 6
LOOKAT 0 5 -5.5
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
OBJECT 0
cube
material 1
TRANS 0 0 0
ROTAT 0 0 0
SCALE 10 .01 10

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

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

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

// Right wall
OBJECT 5
OBJECT 4
cube
material 3
TRANS 5 5 0
ROTAT 0 0 0
SCALE .01 10 10

// Floor light
OBJECT 5
cube
material 0
TRANS -3 0.05 2
ROTAT 0 -25 0
SCALE 3 .1 .1

// Floor light
OBJECT 6
cube
material 0
TRANS 3 0.05 2
ROTAT 0 30 0
SCALE 3 .1 .1

// Floor light
OBJECT 7
cube
material 0
TRANS 2 0.05 1
ROTAT 0 -5 0
SCALE 3 .1 .1

// Floor light
OBJECT 8
cube
material 0
TRANS -1 0.05 1
ROTAT 0 10 0
SCALE 3 .1 .1

// t-rex
OBJECT 9
C:\Users\elser\class\gpu\pathTracer\Project3-CUDA-Path-Tracer\scenes\tyraLoPoly.obj
material 7
TRANS 0 0 -2
ROTAT 0 90 0
SCALE -2.25 2.25 2.25

// Sphere
OBJECT 10
sphere
material 4
TRANS 5 10 -5
ROTAT 0 0 0
SCALE 8 8 8

//// bunny
//OBJECT 6
//C:\Users\elser\class\gpu\pathTracer\Project3-CUDA-Path-Tracer\scenes\bunnyLoPoly.obj
//material 8
//TRANS 1 0 -2
//ROTAT 0 0 0
//SCALE 1 1 1

//// Sphere
//OBJECT 6
//sphere
//material 4
//TRANS -3 4 -2
//ROTAT 0 0 0
//SCALE 3 3 3
//
//// platform
//OBJECT 7
Expand All @@ -195,20 +226,20 @@ SCALE .01 10 10
//TRANS -3 1.25 -1
//ROTAT 0 0 0
//SCALE 3 2.5 7

//// teapot
//OBJECT 6
//C:\Users\elser\class\gpu\pathTracer\Project3-CUDA-Path-Tracer\scenes\teapotTris.obj
//material 7
//TRANS 0 0 0
//ROTAT 0 0 0
//SCALE .5 .5 .5

//
////// teapot
////OBJECT 6
////C:\Users\elser\class\gpu\pathTracer\Project3-CUDA-Path-Tracer\scenes\teapotTris.obj
////material 7
////TRANS 0 0 0
////ROTAT 0 0 0
////SCALE .5 .5 .5
//
//// glass Sphere
//OBJECT 8
//sphere
//material 6
//TRANS 0 1.5 -2
//TRANS 0 2 -2
//ROTAT 0 0 0
//SCALE 3 3 3
//
Expand Down Expand Up @@ -259,19 +290,3 @@ SCALE .01 10 10
//TRANS 0 8 0
//ROTAT 0 0 45
//SCALE 3 .1 3

//// Oren-Nayar Sphere
//OBJECT 9
//sphere
//material 6
//TRANS 3 4 -2
//ROTAT 0 0 0
//SCALE 3 3 3
//
//// Floor light
//OBJECT 10
//cube
//material 0
//TRANS 0 0 0
//ROTAT 0 0 0
//SCALE 10 1 1
Loading

0 comments on commit 6a9b5cd

Please sign in to comment.