Smallpt Cline Slides
Smallpt Cline Slides
Smallpt Cline Slides
• In vector form:
Sphere Start with vector equation of sphere
Intersection
Intersection Routine
Full Sphere Code
The Scene
The Scene Description
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.
Intersect Ray with Scene
• Check each sphere, one at a time. Keep the closest
intersection.
End Part 1
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
main (1)
main (1a: set up image)
main (1b: set up camera)
Camera Setup
• Look from and gaze direction:
cy gaze
direction
cx
look
from
main (2: Create Image)
main (2a: OpenMP directive)
• The dot product of the normal and ray direction tells this:
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
Diffuse Reflection
• For diffuse (not shiny) reflection
– Sample all lights (non-recursive)
– Send out additional random sample (recursive)
Diffuse Reflection
w=z
u=x
v=y
Sampling Lights
Sampling Sphere by Solid Angle
amax
Sampling Sphere by Solid Angle
• Reflected Ray:
– Angle of incidence =
Angle of reflection
Glass (Dielectric)
Reflected Ray & Orientation
Water: 1.33
Plastic: 1.5
Glass: 1.5 – 1.7
Diamond: 2.5
• Fresnel Reflectance
– R0 = reflectance at normal incidence based on IOR
– c = 1-cos(theta)
– Re = fresnel reflectance
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
Convergence
From: http://kevinbeason.com/smallpt/