Professional Documents
Culture Documents
Part 2 Rendering
Today: Intro to Rendering, Ray Casting
NVIDIA
Animation
quaternions, skinning, ODEs, masses and springs
10/27/2011
Today
What does rendering mean? Basics of ray casting
Scene
7 8
Camera Scene
9
Pixels
Scene
10
Pixels
Pixels
Scene
Each pixel corresponds to one ray. We need to figure out which scene point each one hits. 12
10/27/2011
Rendering
Image
Rendering
Image
Pixels
Scene
Pixels
Scene
Rendering
Rendering refers to the entire process that produces color values for pixels, given a 3D representation of the scene Pixels correspond to rays; need to figure out the visible scene point along each ray
Called hidden surface problem in older texts Visibility is a more modern term Also, we assume (for now) a single ray per pixel
Rendering
Rendering refers to the entire process that produces color values for pixels Pixels correspond to rays; need to figure out the visible scene point along each ray
Called hidden surface problem in older texts Visibility is a more modern term Also, we assume (for now) a single ray per pixel
Major algorithms: Ray casting and rasterization Note: We are assuming a pinhole camera (for now)
15 16
Questions?
Ray Casting
Ray Casting Basics Camera and Ray Generation Ray-Plane Intersection Ray-Sphere Intersection
17
18
10/27/2011
Ray Casting
For every pixel Construct a ray from the eye For every object in the scene Find intersection with the ray Keep if closest
Shading
For every pixel Construct a ray from the eye For every object in the scene Find intersection with the ray Keep if closest Shade
19
20
Material Properties
Diffuse (matte) Specular (shiny)
Light properties
Position Intensity, ... Diffuse sphere Specular spheres
21 22
Much more!
X ?
camera rays are rays from the camera to the scene
23
24
10/27/2011
Secondary Rays
Indirect illumination
Reflections
Henrik Wann Jensen
Refractions
Shadows
6.837 Durand
Caustics
26
26
Ray Tracing
Reflections
Questions?
Ray Casting
For every pixel Construct a ray from the eye For every object in the scene Find intersection with the ray Keep if closest Shade depending on light and normal vector
N
Ray Representation
Two vectors:
Origin Direction (normalized is better)
Parametric line
P(t) = origin + t * direction
Finding the intersection point and normal is the central part of ray casting
P(t) direction
origin
29
30
10/27/2011
Ray Representation
Two vectors:
Origin Direction (normalized is better)
Another way to put the ray casting problem statement: Find smallest t > 0 such that P(t) lies on a surface in the scene
Parametric line
P(t) = origin + t * direction
P(t) direction
origin
31
32
Ray Casting
Ray Casting Basics Camera and Ray Generation Ray-Plane Intersection Ray-Sphere Intersection
33
34
Cameras
For every pixel Construct a ray from the eye For every object in the scene Find intersection with ray Keep if closest
Pinhole Camera
Box with a tiny hole Inverted image Similar triangles Perfect image if hole infinitely small Pure geometric optics No depth of field issue (everything in focus)
35
36
10/27/2011
Oldest Illustration
From Gemma Frisius, 1545
37
38
39
40
Camera Description?
Camera Description?
Eye point e (center) Orthobasis u, v, w (horizontal, up, direction)
w u
41
42
10/27/2011
Camera Description?
Eye point e (center) Orthobasis u, v, w (horizontal, up, direction) Field of view angle Image rectangle aspect ratio
v
Questions?
w u
43
44
Image Coordinates
Image plane
-1 y 1
Convenient to define normalized image coordinates such that the x, y coordinates run from -1 to 1 regardless of the dimensions and aspect ratio of the image rectangle.
Ray Generation in 2D
p is point on image plane at coordinate x, we want to know the direction of the ray r
r?
view direction w
Camera
-1 x 1
45
field of view
eye point e
right u
46
Ray Generation in 2D
Ray Generation in 2D
D
field of view
view direction w
field of view
right u
47
right u
48
10/27/2011
Ray Generation in 2D
r = p-e = (x*u, D*w)
x
Ray Generation in 2D
r = p-e = (x*u, D*w)
x
then we just normalize r to get the ray
r
D
field of view
r
D
field of view eye point e
right u
49
view direction w
eye point e
right u
50
perspective
orthographic
The point of the exercise with computing D was to allow us to use the [-1,1] image coordinate system regardless of field of view.
51
Orthographic Camera
Ray Generation?
Origin = e + x*size*u + y*size*v Direction is constant: w
53
54
10/27/2011
Questions?
Even Funkier Multiperspective Imaging
Ray Casting
Ray Casting Basics Camera and Ray Generation Ray-Plane Intersection Ray-Sphere Intersection
55
56
Ray Casting
For every pixel Construct a ray from the eye For every object in the scene Find intersection with the ray Keep if closest
direction
Rd
57
origin
Ro
58
3D Plane Representation?
H(p) = d > 0
3D Plane Representation?
H(p) = d > 0 normal
normal
Po
Po
H(P) = Ax+By+Cz+D = 0 = nP + D = 0
59
60
10
10/27/2011
3D Plane Representation?
H(p) = d > 0
3D Plane Representation?
H(p) > 0 normal
normal
Po
Po
Point-Plane distance?
If n is normalized, distance to plane is H(P) it is a signed distance!
61 62
Ray-Plane Intersection
Intersection means both are satisfied So, insert explicit equation of ray into implicit equation of plane & solve for t
P(t) = Ro + t * Rd H(P) = nP + D = 0 n(Ro + t * Rd) + D = 0 t = -(D + nRo) / nRd
H(P) = nP + D = 0
P(t)
Solution of an equation Does not generate points Verifies that a point is on the plane
Done!
Ray-Plane Intersection
Intersection means both are satisfied So, insert explicit equation of ray into implicit equation of plane & solve for t
P(t) = Ro + t * Rd H(P) = nP + D = 0 n(Ro + t * Rd) + D = 0 t = -(D + nRo) / nRd
Additional Bookkeeping
Verify that intersection is closer than previous
t < tcurrent t > tmin
P(t)
P(t)
11
10/27/2011
Normal
Also need surface normal for shading
(Diffuse: dot product between light direction and normal, clamp to zero)
Questions?
Math Digression
Duality: points and planes are dual when you use homogeneous coordinates Point (x, y, z, 1) Plane (A, B, C, D) Plane equation dot product You can map planes to points and points to planes in a dual space. Lots of cool equivalences
intersection of 3 planes define a point 3 points define a plane!
69
Questions?
70
Ray Casting
Ray Casting Basics Camera and Ray Generation Ray-Plane Intersection Ray-Sphere Intersection
Sphere Representation?
Implicit sphere equation
Assume centered at origin (easy to translate) H(P) = ||P||2 - r2 = PP - r2 = 0
Rd
Ro
71
72
12
10/27/2011
Ray-Sphere Intersection
Insert explicit equation of ray into implicit equation of sphere & solve for t ; H(P) = PP - r2 = 0 P(t) = Ro + t*Rd (Ro + tRd) (Ro + tRd) - r2 = 0 RdRdt2 + 2RdRot + RoRo - r2 = 0
Ray-Sphere Intersection
Quadratic: at2 + bt + c = 0
a = 1 (remember, ||Rd|| = 1) b = 2RdRo c = RoRo r2
Rd
Ro
73
74
Ray-Sphere Intersection
3 cases, depending on the sign of b2 4ac What do these cases correspond to? Which root (t+ or t-) should you choose?
Closest positive!
Ray-Sphere Intersection
It's so easy that all ray-tracing images have spheres!
:-)
Turner Whitted
75
76
Sphere Normal
Simply Q/||Q||
Q = P(t), intersection point (for spheres centered at origin)
Questions?
Rd
Ro
normal
77 78
13
10/27/2011
NVIDIA
NVIDIA
79
80
Quiz
Grades are available in Stellar today after class If you have issues with grading, voice up latest next Tuesday(Nov 1st) Statistics
Mean 56.93 Stdev 12.61
81
14