smallpt: global illumination in 99 lines of c++ a ray tracer by kevin beason presentation by dr....
TRANSCRIPT
![Page 1: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/1.jpg)
smallpt: Global Illumination in 99 lines of C++
a ray tracer by Kevin Beasonhttp://kevinbeason.com/smallpt/
Presentation byDr. David Cline
Oklahoma State University
![Page 2: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/2.jpg)
Global Illumination
• Global Illumination = “virtual photography”– Given a scene description that specifies the
location of surfaces in a scene, the location of lights, and the location of a camera, take a virtual “photograph” of that scene.
![Page 3: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/3.jpg)
• “Headlight” rendering of a simple scene
![Page 4: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/4.jpg)
• Adding surface details
![Page 5: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/5.jpg)
• Direct lighting with hard shadows
![Page 6: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/6.jpg)
• “Ambient occlusion” = direct lighting of a cloudy day.
![Page 7: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/7.jpg)
• Ambient Occlusion and depth of field
![Page 8: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/8.jpg)
• Global illumination showing different surface types, glass surfaces, caustics (light concentrations), and depth of field.
![Page 9: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/9.jpg)
Another Example
• Ad-hoc Lighting vs. Global Illumination
![Page 10: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/10.jpg)
How to form a GI image?
![Page 11: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/11.jpg)
The Rendering Equation
![Page 12: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/12.jpg)
The Rendering Equation
The radiance (intensity of light)Coming from surface point PIn direction Dv. This is what weHave to calculate.
![Page 13: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/13.jpg)
The Rendering Equation
The self-emitted radiance from PIn direction Dv (0 unless point P Is a light source) This can be lookedUp as part of the scene description.
![Page 14: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/14.jpg)
The Rendering Equation
The reflected light term. Here we must add Up (integrate) all of the light coming in to point P from all directions, modulated by the Chance that it scatters in direction Dv (based on the BRDF function, Fs)
![Page 15: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/15.jpg)
Path Tracing Approximation
Replace the ray integral with a Monte Carlo(random) Sample that has the same Expected(average) Value. Then average a bunch of samples for each pixel to create a smooth image.
![Page 16: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/16.jpg)
Path Tracing Algorithm
![Page 17: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/17.jpg)
SmallPT• A 99 line Path Tracer by Kevin Beason • (Expanded Version has 218 lines)• Major Parts:
Vec: a vector class, used for points, normals, colorsRay: a ray class (origin and direction)Refl_t: the surface reflection typeSphere: SmallPT only supports sphere objectsspheres: the hard coded scene (some # of spheres)intersect: a routine to intersect rays with the scene of spheresradiance: recursive routine that solves the rendering equationmain: program start and main loop that goes over each pixel
![Page 18: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/18.jpg)
Squashed Code 1:
![Page 19: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/19.jpg)
Squashed Code 2:
![Page 20: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/20.jpg)
Expanded version (1)Preliminaries
![Page 21: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/21.jpg)
Expanded version (2)Vec (Points, Vectors, Colors)
![Page 22: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/22.jpg)
Normalize
• “Normalize” a vector = divide by its length
![Page 23: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/23.jpg)
Dot Product
![Page 24: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/24.jpg)
Cross Product
![Page 25: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/25.jpg)
Ray Structure
• A ray is a parametric line with an origin (o) and a direction (d). A point along the ray can be defined using a parameter, t:
• In code we have:
• The core routines of the ray tracer intersect rays with geometric objects (spheres in our case)
![Page 26: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/26.jpg)
Sphere
• SmallPT supports sphere objects only• We can define a sphere based on
– a center point, C– Radius, r
• The equation of the sphere:
• In vector form:
![Page 27: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/27.jpg)
Sphere Intersection
Start with vector equation of sphere
![Page 28: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/28.jpg)
Intersection Routine
![Page 29: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/29.jpg)
Full Sphere Code
![Page 30: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/30.jpg)
The Scene
![Page 31: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/31.jpg)
The Scene Description
![Page 32: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/32.jpg)
Convert Colors to Displayable Range
• The output of the “radiance” function is a set of unbounded colors. This has to be converted to be between 0 and 255 for display purposes. The following functions do this. The “toInt” function applies a gamma correction of 2.2.
![Page 33: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/33.jpg)
Intersect Ray with Scene• Check each sphere, one at a time. Keep the closest
intersection.
![Page 34: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/34.jpg)
End Part 1
![Page 35: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/35.jpg)
The main Function
• Set up camera coordinates• Initialize image array• Parallel directive• For each pixel
– Do 2x2 subpixels– Average a number of radiance samples– Set value in image
• Write out image file
![Page 36: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/36.jpg)
main (1)
![Page 37: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/37.jpg)
main (1a: set up image)
![Page 38: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/38.jpg)
main (1b: set up camera)
![Page 39: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/39.jpg)
Camera Setup• Look from and gaze direction:
• Horizontal (x) camera direction
(assumes upright camera)(0.5135 defines field of view angle)
• Vertical (vup) vector of the camera
(cross product gets vector perpendicular to both cx and gaze direction)
![Page 40: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/40.jpg)
Camera Setup
lookfrom
cx
cy gazedirection
![Page 41: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/41.jpg)
main (2: Create Image)
![Page 42: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/42.jpg)
main (2a: OpenMP directive)
States that each loop iteration should be runin its own thread.
![Page 43: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/43.jpg)
main (2b: Loop over image pixels)
Loop over all pixels in the image.
![Page 44: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/44.jpg)
main (2c: Subpixels & samples)
Pixels composed of 2x2 subpixels. The subpixel colors will be averaged.
![Page 45: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/45.jpg)
main (2d: Pixel Index)
Calculate array index for pixel(x,y)
![Page 46: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/46.jpg)
main (2e: Tent Filter)
r1 and r2 are random values of a tent filter(Determine location of sample within pixel)
![Page 47: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/47.jpg)
Tent Filter• From Realistic Ray Tracing (Shirley and
Morley)
![Page 48: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/48.jpg)
Tent Filter• From Realistic Ray Tracing (Shirley and Morley)
![Page 49: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/49.jpg)
main (2f: Ray direction & radiance)
Compute ray direction using cam.d, cx, cyUse radiance function to estimate radiance
![Page 50: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/50.jpg)
main (2g: Add subpixel estimate)
Add the gamma-corrected subpixel color estimate to the Pixel color c[i]
![Page 51: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/51.jpg)
main (3: Write PPM image)
PPM Format: http://netpbm.sourceforge.net/doc/ppm.html
![Page 52: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/52.jpg)
radiance (1: do intersection)
return value Vec the radiance estimater the ray we are castingdepth the ray depth Xi random number seedE whether to include emissive color
![Page 53: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/53.jpg)
radiance (2: surface properties)
Surface properties include:intersection point (x)Normal (n)Oriented normal (n1)Object color (f)
![Page 54: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/54.jpg)
Orienting Normal
• When a ray hits a glass surface, the ray tracer must determine if it is entering or exiting glass to compute the refraction ray.
• The dot product of the normal and ray direction tells this:
![Page 55: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/55.jpg)
Russian Roulette
• Stop the recursion randomly based on the surface reflectivity.– Use the maximum component (r,g,b) of the surface color.– Don’t do Russian Roulette until after depth 5
![Page 56: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/56.jpg)
Diffuse Reflection
• For diffuse (not shiny) reflection– Sample all lights (non-recursive)– Send out additional random sample (recursive)
![Page 57: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/57.jpg)
Diffuse Reflection
• Construct random ray:– Get random angle (r1)– Get random distance from center (r2s)– Use normal to create orthonormal coordinate
frame (w,u,v)
![Page 58: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/58.jpg)
Sampling Unit Disk• From Realistic Ray Tracing (Shirley and
Morley)
![Page 59: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/59.jpg)
Sampling Unit Hemisphere
w=zu=xv=y
![Page 60: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/60.jpg)
Sampling Lights
![Page 61: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/61.jpg)
Sampling Sphere by Solid Angle
• Create coordinate system for sampling: sw, su, sv
![Page 62: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/62.jpg)
Sampling Sphere by Solid Angle
• Determine max angle
amax
![Page 63: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/63.jpg)
Sampling Sphere by Solid Angle
• Calculate sample direction based on random numbers according to equation from Realistic Ray Tracing:
![Page 64: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/64.jpg)
Shadow Ray
• 145: Check for occlusion with shadow ray
• 146: Compute 1/probability with respect to solid angle
• 147: Calculate lighting and add to current value
![Page 65: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/65.jpg)
Diffuse Recursive Call
• Make recursive call with random ray direction computed earlier:
– Note that the 0 parameter at the end turns off the emissive term at the next recursion level.
![Page 66: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/66.jpg)
Ideal Specular (Mirror) Reflection
![Page 67: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/67.jpg)
Ideal Specular (Mirror) Reflection
• Reflected Ray:– Angle of incidence = Angle of reflection
![Page 68: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/68.jpg)
Glass (Dielectric)
![Page 69: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/69.jpg)
Reflected Ray & Orientation
• 159: Glass is both reflective and refractive, so we compute the reflected ray here.
• 160: Determine if ray is entering or exiting glass
• 161: IOR for glass is 1.5. nnt is either 1.5 or 1/1.5
![Page 70: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/70.jpg)
Total Internal Reflection
• Total internal reflection occurs when the light ray attempts to leave glass at too shallow an angle.
• If the angle is too shallow, all the light is reflected.
![Page 71: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/71.jpg)
Reflect or Refract using Fresnel Term
• Compute the refracted ray
![Page 72: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/72.jpg)
Refraction Ray
![Page 73: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/73.jpg)
Refractive Index• Refractive index gives the speed of light
within a medium compared to the speed of light within a vacuum:
Water: 1.33Plastic: 1.5Glass: 1.5 – 1.7Diamond: 2.5
Note that this does not account for dispersion (prisms). To account for these, vary index by wavelength.
![Page 74: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/74.jpg)
Fresnel Reflectance• Percentage of light is reflected (and
what refracted) from a glass surface based on incident angle (ϴa)
• Reflectance at “normal incidence”, where (n=na/nb)
• Reflectance at other angles:
![Page 75: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/75.jpg)
Reflect or Refract using Fresnel Term
• Fresnel Reflectance– R0 = reflectance at normal incidence based on IOR– c = 1-cos(theta)– Re = fresnel reflectance
![Page 76: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/76.jpg)
Reflect or Refract using Fresnel Term
• P = probability of reflecting• Finally, make 1 or 2 recursive calls
– Make 2 if depth is <= 2– Make 1 randomly if depth > 2
![Page 77: Smallpt: Global Illumination in 99 lines of C++ a ray tracer by Kevin Beason Presentation by Dr. David Cline Oklahoma State](https://reader036.vdocument.in/reader036/viewer/2022062304/56649e175503460f94b02f11/html5/thumbnails/77.jpg)
Convergence
From: http://kevinbeason.com/smallpt/