parallel physically based path-tracing and shading part 1 of 2 · path-tracing algorithm •solves...
TRANSCRIPT
![Page 1: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/1.jpg)
Parallel Physically Based Path-tracing and ShadingPart 1 of 2
CIS565 Fall 2012University of Pennsylvaniaby Yining Karl Li
1Monday, September 24, 12
![Page 2: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/2.jpg)
Agenda
• Part 1 (Today):
• Quick introduction and theory review:
• The Rendering Equation
• Bidirectional reflection distribution functions
• Pathtracing algorithm overview
• Implementing parallel ray-tracing
• Recursion versus iteration
• Iterative ray-tracing
• Part 2 (Wednesday):
• Distributed ray-tracing/Monte-carlo integration, more on BRDFs
• Implementing parallel path-tracing
• Path versus ray parallelization, ray compaction
• Parallel computation, BRDF evaluation, and you!
• Parallel approaches to spatial acceleration structures
• Stack-less KD-tree construction and traversal
• Bounding volume hierarchies
2Monday, September 24, 12
![Page 3: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/3.jpg)
3
Path-tracing: Quick Introduction and Theory Review
Octane Render TestRefractive Software/Bertrand Benoit 2011
Monday, September 24, 12
![Page 4: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/4.jpg)
The Rendering Equation
4
•Super high level meaning: [outgoing light] = [incoming light] + [emitted light] + [absorbed light]
= Outgoing light
= Emitted light
= Integrate over a hemisphere in the direction w over the given point p
= BRDF (Bidirectional Reflectance Distribution Function
= Incoming Light
= Attenuate incoming light based on the cosine of the angle between the normal n and the incoming light direction wi
Monday, September 24, 12
![Page 5: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/5.jpg)
Bidirectional Reflectance Distribution Functions
5
•Defines how light is reflected at a given opaque surface
•Can be extended with transmittance to produce the BSDF: Bidirectional Scattering Distribution Function
•Reflectance models:•Ideal Specular (think mirrors)•Ideal Diffuse•Specular/Glossy (won’t cover
today)•Phong Model•Microfacet Models•Torrance-Sparrow Model
Monday, September 24, 12
![Page 6: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/6.jpg)
Reflectance Models: Ideal Specular
6
•Ideal specular reflection: incoming light and outgoing light make the same angle across the surface normal, so angle of incidence = angle of reflection
•Fresnel’s law: defines the behavior of light when moving between mediums with different indices of refraction.•Can be approximated with Shlick’s
approximation.Photorealizer
Peter Kutz 2012
Monday, September 24, 12
![Page 7: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/7.jpg)
Reflectance Models: Ideal Diffuse
7
•Ideal diffuse reflection: light is equally likely to be reflected in any output direction within a hemisphere oriented along the surface normal over a given point
•Think: wall paint.•Theoretical models:•Micro-facet distribution•Subsurface reflection
GPU Path TracerPeter Kutz/Yining Karl Li 2012
Monday, September 24, 12
![Page 8: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/8.jpg)
Path-tracing Algorithm
• Solves the rendering equation, which was first proposed by James Kajiya in 1986.
• Generalizes ray tracing to produce accurate, unbiased images with full global illumination. Path tracing allows for effects like soft shadows, DOF, antialiasing for free.
• Potentially extremely slow on the CPU and has only become a feasible technique in recent years due to faster and faster hardware.
8 The Third and the SeventhAlex Roman
Monday, September 24, 12
![Page 9: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/9.jpg)
Path-tracing Algorithm
•1. For each pixel, shoot a ray into the scene
•2. For each ray, trace until the ray hits a surface. Upon hitting a surface, sample the emittance and BRDF for the surface and then send the ray in a new random direction
•3. Continue bouncing each ray around until a recursion depth is reached
•4. Repeat steps 1-3 over and over and continuously accumulate the result until a final image begins to converge
9Monday, September 24, 12
![Page 10: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/10.jpg)
10
TAKUA RenderYining Karl Li 2012
The random “Monte Carlo” method that path tracers use means that they can take some time to converge to a final image
1 Iteration
Monday, September 24, 12
![Page 11: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/11.jpg)
11
The random “Monte Carlo” method that path tracers use means that they can take some time to converge to a final image
20 Iterations
TAKUA RenderYining Karl Li 2012
Monday, September 24, 12
![Page 12: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/12.jpg)
12
The random “Monte Carlo” method that path tracers use means that they can take some time to converge to a final image
250 Iterations
TAKUA RenderYining Karl Li 2012
Monday, September 24, 12
![Page 13: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/13.jpg)
Path-tracing: GPU Motivation
•Even with a naive implementation, GPU path tracing can converge fast enough to be interactive! Contrast with CPU implementations, which can take dozens of minutes to hours to converge.
•Even more performance can be extracted through the use of spatial acceleration structures such as stack-less KD-trees or BVH.
•Single biggest constraint is memory: path tracing requires keeping everything in a scene in memory at once, which is not an issue on the CPU with 16 Gb RAM available, but can become a problem on the GPU with typically <1.5 Gb RAM available
13Monday, September 24, 12
![Page 14: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/14.jpg)
14
• Brigade Render by OTOY• Arion Render by RandomControl• Octane Render by Refractive Software
Current Commercial GPU Path-tracers
Brigade RenderOTOY/Sam Lapere 2012
Arion RenderRandomControl/Kuba Dabrowski 2011
Octane RenderRefractive Software/Bertrand Benoit 2011
Monday, September 24, 12
![Page 15: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/15.jpg)
CUDA Path-tracing Demos
• Peter and Karl’s GPU Path Tracer: https://vimeo.com/41109177
• BRIGADE Renderer: http://www.youtube.com/watch?feature=player_embedded&v=FJLy-ci-RyY
15
GPU Path TracerPeter Kutz/Yining Karl Li 2012
Monday, September 24, 12
![Page 16: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/16.jpg)
16
Parallel Ray-tracing: A stepping stone to path-tracing
Pov-Ray GlassesGilles Tran 2006
Monday, September 24, 12
![Page 17: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/17.jpg)
Basic Ray-tracing Algorithm
•1. For each pixel, shoot a ray into the scene
•2. For each ray, trace until the ray hits a surface.
•3. For each intersection, cast a shadow feeler ray to each light source to see if each light source is visible and shade the current pixel accordingly
•4. If the surface is diffuse, stop. If the surface is reflective, shoot a new ray reflected across the normal from the incident ray
•5. Repeat steps 1-4 over and over until a maximum tracing depth has been reached or until the ray hits a light or a diffuse surface
17Monday, September 24, 12
![Page 18: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/18.jpg)
Recursive Ray-tracing
•The most obvious way to implement basic raytracing is through a purely recursive approach:
18
color3 rayTrace(int depth, ray r, vector<geom> objects, vector<lights> light_sources){
[determine closest intersected object j, intersection normal n, intersection point p]
color = black
if(object j is reflective){reflected_r = reflect_ray(r, normal, p);reflected_color = rayTrace(depth+1, reflected_r, objects, light_sources); color = reflected_Color;
}
for each light l in light_sources{if shadow_ray(p, l)==true{
light_contribution = calculate_light_contribution(p,l,n,j);color += light_contribution;
}}
return color;}
Monday, September 24, 12
![Page 19: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/19.jpg)
Parallelizing Ray-tracing
•Ray-tracing is an embarrassingly parallel problem!
•Tracing each pixel in the image is computationally independent from all other pixels
•Tracing a single pixel is not a terribly computationally intense task, there’s simply a lot of tracing that needs to happen
•Solution: parallelize along pixels!
•Launch one thread per pixel, trace hundreds to thousands of pixels in mass parallel!
19Monday, September 24, 12
![Page 20: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/20.jpg)
Parallelizing Ray-tracing
20
Wait, we have a problem... CUDA does not support recursion!*
*Except on Fermi and newer
Monday, September 24, 12
![Page 21: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/21.jpg)
Iterative Ray-tracing
•Iterative ray-tracing: a slightly less intuitive ray-tracing algorithm that does not need recursion!
•Analogy: think breadth first search versus depth first search
•Recursive model:
21
Trace all ray bounces in first
ray path
Monday, September 24, 12
![Page 22: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/22.jpg)
Iterative Ray-tracing
•Iterative ray-tracing: a slightly less intuitive ray-tracing algorithm that does not need recursion!
•Analogy: think breadth first search versus depth first search
•Recursive model:
22
Trace all ray bounces in
second ray path
Monday, September 24, 12
![Page 23: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/23.jpg)
Iterative Ray-tracing
•Iterative ray-tracing: a slightly less intuitive ray-tracing algorithm that does not need recursion!
•Analogy: think breadth first search versus depth first search
•Recursive model:
23
etc.
Trace all ray bounces in third
ray path
Monday, September 24, 12
![Page 24: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/24.jpg)
Iterative Ray-tracing
•Iterative ray-tracing: a slightly less intuitive ray-tracing algorithm that does not need recursion!
•Analogy: think breadth first search versus depth first search
•Iterative model:
24
Trace first ray bounce in all
ray paths
Monday, September 24, 12
![Page 25: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/25.jpg)
Iterative Ray-tracing
•Iterative ray-tracing: a slightly less intuitive ray-tracing algorithm that does not need recursion!
•Analogy: think breadth first search versus depth first search
•Iterative model:
25
Trace second ray bounce in all ray paths
Monday, September 24, 12
![Page 26: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/26.jpg)
Iterative Ray-tracing
•Iterative ray-tracing: a slightly less intuitive ray-tracing algorithm that does not need recursion!
•Analogy: think breadth first search versus depth first search
•Iterative model:
26
Trace third ray bounce in all ray paths, and so
on and so forth
Monday, September 24, 12
![Page 27: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/27.jpg)
Iterative Ray-tracing
•Implement ray-tracing as a while or for loop and cache the current ray for use in the next iteration of the loop:
27
color3 rayTrace(int depth, ray r, vector<geom> objects, vector<lights> light_sources){ray currentRay = r;color = black;
for(int i=0; i<depth; i++){
[determine closest intersected object j, intersection normal n, intersection point p]
if(object j is reflective){reflected_r = reflect_ray(r, normal, p);
}for each light l in light_sources{
if shadow_ray(p, l)==true{color += color * calculate_light_contribution(p,l,n,j);
}}
}return color;
}
Monday, September 24, 12
![Page 28: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/28.jpg)
Parallelizing Ray-tracing
28
So we can just implement that entire interative ray-tracing algorithm in a
CUDA kernal and we’re done, right?
Monday, September 24, 12
![Page 29: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/29.jpg)
Parallelizing Ray-tracing
29
So we can just implement that entire interative ray-tracing algorithm in a
CUDA kernal and we’re done, right?
Well yes, BUT...
Monday, September 24, 12
![Page 30: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/30.jpg)
Parallel Ray-Tracing Quirks: Wasted Cycles
30
Text
•How many bounces does each ray path make before terminating?
TAKUA RenderYining Karl Li 2012
Monday, September 24, 12
![Page 31: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/31.jpg)
Parallel Ray-Tracing Quirks: Wasted Cycles
31
Text
•How many bounces does each ray path make before terminating?
4 bounces?
TAKUA RenderYining Karl Li 2012
Monday, September 24, 12
![Page 32: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/32.jpg)
Parallel Ray-Tracing Quirks: Wasted Cycles
32
Text
•How many bounces does each ray path make before terminating?
3 bounces?
TAKUA RenderYining Karl Li 2012
Monday, September 24, 12
![Page 33: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/33.jpg)
Parallel Ray-Tracing Quirks: Wasted Cycles
33
Text
•How many bounces does each ray path make before terminating?
2 bounces?
TAKUA RenderYining Karl Li 2012
Monday, September 24, 12
![Page 34: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/34.jpg)
Parallel Ray-Tracing Quirks: Wasted Cycles
34
Text
•How many bounces does each ray path make before terminating?
1 bounce?
TAKUA RenderYining Karl Li 2012
Monday, September 24, 12
![Page 35: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/35.jpg)
Parallel Ray-Tracing Quirks: Wasted Cycles
35
Text
•How many bounces does each ray path make before terminating?
No bounces?
TAKUA RenderYining Karl Li 2012
Monday, September 24, 12
![Page 36: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/36.jpg)
Parallel Ray-Tracing Quirks: Wasted Cycles
36
Text
•How many bounces does each ray path make before terminating?
•We have no idea how many bounces each ray path may take!
•What does this uncertainty imply about parallelizing by pixels?
TAKUA RenderYining Karl Li 2012
Monday, September 24, 12
![Page 37: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/37.jpg)
Parallel Ray-Tracing Quirks: Wasted Cycles
37
•Remember, in CUDA, we can only launch a finite number of blocks at a time, and must wait for blocks to complete before launching more.
•If some threads need to trace more bounces than others, then potentially a large number of threads will spend the majority of the time idling.
•Conclusion: parallelizing by pixels is one possible approach, but ultimately a naive one.
Thread 1 Thread 2 Thread 3 Thread 4 Thread 5 Thread 6
Bounce 1 Bounce 1 DONE Bounce 1 Bounce 1 Bounce 1
Bounce 2 DONE Bounce 2 DONE DONE
Bounce 3 DONE
Bounce 4
DONEWASTED CYCLES
Monday, September 24, 12
![Page 38: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/38.jpg)
Ray Parallelization
38
•Solution: parallelize by rays, not pixels!
•Instead of a single kernel launch that traces an entire ray path, do multiple kernel launches that trace individual bounces!
•1. Construct pool of rays that need to be intersection tested
•2. Construct grid of colors and unaccumulated colors
•3. Launch a kernel that traces ONE bounce and records the next ray into the ray pool
•4. Remove terminated rays from the ray pool through string compaction type process
•5. Repeat
Monday, September 24, 12
![Page 39: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/39.jpg)
•With each iteration of the ray-trace, we need less threads as rays terminate! As a result, each iteration requires fewer blocks, meaning each iteration executes faster than the previous iteration.
•Well, there are a few rare edge cases where this approach does not provide a performance boost. Can you think of any?
Ray Parallelization
39
Iteration 1: 10 blocks executing in groups of 4 = 3 batches
Iteration 2: 4 blocks executing in groups of 4 = 1 batch
Monday, September 24, 12
![Page 40: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/40.jpg)
Ray Parallelization: Super Simple Example
40
First Kernel Launch
Ray Pool:Ray 1, Ray 2, Ray 3
Threads Needed:3
Result:
Terminated Rays:Ray 1
TAKUA RenderYining Karl Li 2012
Monday, September 24, 12
![Page 41: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/41.jpg)
Ray Parallelization: Super Simple Example
41
Second Kernel Launch
Ray Pool:Ray 2, Ray 3
Threads Needed:2
Result:
Terminated Rays:Ray 1
TAKUA RenderYining Karl Li 2012
Monday, September 24, 12
![Page 42: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/42.jpg)
Ray Parallelization: Super Simple Example
42
Third Kernel Launch
Ray Pool:Ray 2, Ray 3
Threads Needed:2
Result:
Terminated Rays:Ray 1, Ray 3
TAKUA RenderYining Karl Li 2012
Monday, September 24, 12
![Page 43: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/43.jpg)
Ray Parallelization: Super Simple Example
43
Fourth Kernel Launch
Ray Pool:Ray 2
Threads Needed:1
Result:
Terminated Rays:Ray 1, Ray 3, Ray 2
TAKUA RenderYining Karl Li 2012
Monday, September 24, 12
![Page 44: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/44.jpg)
Parallel Ray-Tracing Quirks: Memory Management
44
•Assume we cudaMemcpy() all of our geometry and materials and other scene assets from host memory to device global memory.
•What happens in this scene on the first bounce?
TAKUA RenderYining Karl Li 2012
Monday, September 24, 12
![Page 45: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/45.jpg)
Parallel Ray-Tracing Quirks: Memory Management
45
•Assume we cudaMemcpy() all of our geometry and materials and other scene assets from host memory to device global memory.
•What happens in this scene on the first bounce?
•A lot of rays are hitting the same objects, meaning a lot of threads are concurrently trying to access the same places in global memory!
TAKUA RenderYining Karl Li 2012
Monday, September 24, 12
![Page 46: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/46.jpg)
Parallel Ray-Tracing Quirks: Memory Management
46
•Possible Solutions:
•In distributed raytracing scenarios: since the first bounce will always involve the same raycasts from the camera, cache the result of the first bounce and recycle the result .
•“First bounce cache, second bounce thrash”
•If the scene is sufficiently small, cache geometry data in shared memory.
•Why might this be a bad idea in some cases?
Monday, September 24, 12
![Page 47: Parallel Physically Based Path-tracing and Shading Part 1 of 2 · Path-tracing Algorithm •Solves the rendering equation, which was first proposed by James Kajiya in 1986. •Generalizes](https://reader035.vdocuments.net/reader035/viewer/2022071108/5fe32f9019bad715a62abe30/html5/thumbnails/47.jpg)
47
References
• Tatarinov, Kharlamov, NVIDIA SIGGRAPH 2009 Alternative Rendering Pipelines Presentation: http://developer.download.nvidia.com/presentations/2009/SIGGRAPH/Alternative_rendering_pipelines.pdf
• [Kajiya86] Kajiya, “The Rendering Equation”: http://dl.acm.org/citation.cfm?id=15902
• Sam Lapere’s “Ray Tracey’s Blog”: http://raytracey.blogspot.de/
• [Pharr04] Matt Pharr, Greg Humphreys, “Physically Based Rendering”: http://www.pbrt.org/
• Rory Driscoll’s “CodeItNow” Blog: http://www.rorydriscoll.com/2008/08/24/lighting-the-rendering-equation/
• Stanford University's CS348B: Image Synthesis course materials: https://graphics.stanford.edu/wikis/cs348b-12
Monday, September 24, 12