CS 655 Advanced Computer Graphics - PowerPoint PPT Presentation

1 / 62
About This Presentation
Title:

CS 655 Advanced Computer Graphics

Description:

Many objects can be represented as implicit surfaces: ... Light bend computed by Snell's law: Medium 2. n. I. Medium 1. T. Refraction Indices ... – PowerPoint PPT presentation

Number of Views:50
Avg rating:3.0/5.0
Slides: 63
Provided by: cs6
Category:

less

Transcript and Presenter's Notes

Title: CS 655 Advanced Computer Graphics


1
CS 655 Advanced Computer Graphics
  • Ray-Object Intersections

2
Ray-Object Intersections
  • Many objects can be represented as implicit
    surfaces
  • Sphere (with center at c and radius R)
    fsphere(p) p c2 - R2 0
  • Plane (with normal n and distance to origin d)
    fplane(p) p n D 0
  • To determine where a ray intersects an object
  • Need to find the intersection point p of the ray
    and the object
  • The ray is represented explicitly in parametric
    form
  • R(t) Ro Rdt
  • Plug the ray equation into the surface equation
    and solve for t
  • f(R(t)) 0
  • Substitute t back into ray equation to find
    intersection point p
  • p R(t) Ro Rdt

3
Recall Ray Representation
  • A ray can be represented explicitly (in
    parametric form) as an origin (point) and a
    direction (vector)
  • Origin
  • Direction
  • The ray consists of all points
  • R(t) Ro Rdt

R(3)
R(2)
Ro Rd R(1)
Ro R(0)
R(1)
4
Ray-Sphere Intersections
  • To find the intersection points of a ray with a
    sphere
  • Sphere is represented as
  • center (point) Sc (xc, yc, zc)
  • and a radius (float) r
  • The surface of the sphere is the set of all
    points (x, y, z) such that
  • (x-xc)2 (y - yc)2 (z - zc)2 r2
  • In this form (implicit form), it is difficult to
    directly generate surface points
  • However, given a point, it is easy to see if the
    point lies on the surface
  • To solve the ray-surface intersection, substitute
    the ray equation into the sphere equation.

5
Ray-Sphere Intersections
  • First, split the ray into its component
    equations
  • x xo xdt
  • y yo ydt
  • z zo zdt
  • Next substitute the ray equation into the sphere
    equation
  • (x-xc)2 (y - yc)2 (z - zc)2 r2
  • Giving
  • (xo xdt - xc)2 (yo ydt - yc)2 (zo zdt
    - zc)2 r2

6
Ray-Sphere Intersections
  • Next, simplify the equation
  • (x0 xdt - xc)2 (y0 ydt - yc)2 (z0 zdt
    - zc)2 r2
  • Þ (xd2 yd2 zd2)t2
  • 2(xdxo - xdxc ydyo - ydyc zdzo - zdzc)t
  • (xo2- 2xoxc xc2 yo2- 2yoyc yc2 zo2-2zozc
    zc2)
  • r2

7
Ray-Sphere Intersections
  • Let
  • A xd2 yd2 zd2 1
  • B 2(xdxo - xdxc ydyo - ydyc zdzo - zdzc)
  • C xo2- 2xoxc xc2 yo2- 2yoyc yc2 zo2-2zozc
    zc2 - r2
  • Then solve using the quadratic equation

8
Ray-Sphere Intersections
  • If the discriminant is negative, the ray misses
    the sphere
  • The smaller positive root (if one exists) is the
    closer intersection point
  • We can save some computation time by computing
    the smaller root first, then only computing the
    second root if necessary

9
Ray-Sphere Intersections Algorithm
  • Algorithm for ray-sphere intersection
  • 1. Calculate B and C of the quadratic
  • 2. Calculate the discriminant D B2 4C
  • 3. If D ? 0 return false (no intersection point)
  • 4. Calculate smaller intersection parameter t0
  • 5. If t0 ? 0 then calculate larger t-value t1
  • 6. If t1 ? 0 return false (intersection point
    behind ray)
  • 7. else set t t1
  • 8. else set t t0
  • 9. Return intersection point p r(t) ro rdt

10
Ray-Sphere Intersections Normal
  • The normal n at an intersection point p on a
    sphere is

n
p
r
c
11
Ray-Sphere Intersections
  • Computation time
  • 17 adds/subtracts
  • 17 multiplies
  • 1 square root
  • for each ray/sphere test
  • Can we reduce the number of intersection
    calculations?
  • use a geometric approach

12
Ray-Sphere Intersections - Geometric
tca
thc
d
Sc
OC
  • R0

13
Ray-Sphere Intersections - Geometric
  • Determine whether the rays origin is outside
    the sphere
  • if R0 - Sc lt r, then the point is inside the
    sphere
  • Call the vector between R0 and Sc OC
  • Find the closest approach of the ray to the
    spheres center.
  • let d distance from Sc to the ray
  • let tca distance from R0 to closest approach of
    ray to Sc
  • tca Rd OC

tca
thc
d
Sc
OC
R0
14
Ray-Sphere Intersections - Geometric
  • If tca lt 0 and R0 lies outside the sphere, the
    ray does not intersect the sphere
  • Otherwise, compute thc, the distance from the
    closest approach to the spheres surface
  • thc2 r2 - d2
  • d2 OC2 - tca2, so
  • thc2 r2 - OC2 tca2

tca
thc
d
Sc
OC
R0
15
Ray-Sphere Intersections - Geometric
  • If thc2 lt 0 the ray does not intersect the sphere
  • Otherwise, calculate the intersection distance
  • If R0 is outside the sphere
  • t tca - thc
  • If R0 is inside the sphere
  • t tca thc

tca
thc
d
Sc
OC
R0
16
Ray-Sphere Intersections - Geometric
  • Calculate the intersection point
  • (xi, yi, zi)
  • (xo xdt, yo ydt, zo zdt)
  • Calculate the normal at the intersection point
  • This reduces the computation (worst case) by 4
    multiplies and 1 add
  • Even fewer computations if the ray misses the
    sphere

tca
thc
d
Sc
OC
R0
17
Example
  • Find the intersection point of the ray
  • and the sphere

18
Example
1. Check ray origin inside/outside
sphere Compute OC 2. Find closest approach to
spheres center. 3. Check for non intersection 4.
Compute thc 5. Check thc2 lt 0 6. Calculate the
intersection distance 7. Calculate
intersection point 8. Calculate normal
First Normalize ray
1. Compute OC
Since gt r, Ro is outside the sphere
19
Example
1. Check ray origin inside/outside
sphere Compute OC 2. Find closest approach to
spheres center. 3. Check for non intersection 4.
Compute thc 5. Check thc2 lt 0 6. Calculate the
intersection distance 7. Calculate
intersection point 8. Calculate normal
2. Find the closest approach of the ray to the
spheres center.
20
Example
1. Check ray origin inside/outside
sphere Compute OC 2. Find closest approach to
spheres center. 3. Check for non intersection 4.
Compute thc 5. Check thc2 lt 0 6. Calculate the
intersection distance 7. Calculate
intersection point 8. Calculate normal
3. If tca lt 0 and R0 lies outside the sphere,
the ray does not intersect the sphere
R0 does lie outside the sphere, but tca gt 0,
so continue
21
Example
1. Check ray origin inside/outside
sphere Compute OC 2. Find closest approach to
spheres center. 3. Check for non intersection 4.
Compute thc 5. Check thc2 lt 0 6. Calculate the
intersection distance 7. Calculate
intersection point 8. Calculate normal
4. Compute thc, the distance from the closest
approach to the spheres surface
22
Example
1. Check ray origin inside/outside
sphere Compute OC 2. Find closest approach to
spheres center. 3. Check for non intersection 4.
Compute thc 5. Check thc2 lt 0 6. Calculate the
intersection distance 7. Calculate
intersection point 8. Calculate normal
5. See if thc2 lt 0
thc2 gt 0, so the ray must hit the sphere
23
Example
1. Check ray origin inside/outside
sphere Compute OC 2. Find closest approach to
spheres center. 3. Check for non intersection 4.
Compute thc 5. Check thc2 lt 0 6. Calculate the
intersection distance 7. Calculate
intersection point 8. Calculate normal
  • 6. Calculate the intersection distance
  • Since R0 is outside the sphere

so the ray intersects the sphere at t 3.744
24
Example
1. Check ray origin inside/outside
sphere Compute OC 2. Find closest approach to
spheres center. 3. Check for non intersection 4.
Compute thc 5. Check thc2 lt 0 6. Calculate the
intersection distance 7. Calculate
intersection point 8. Calculate normal
7. Calculate the intersection point
25
Example
1. Check ray origin inside/outside
sphere Compute OC 2. Find closest approach to
spheres center. 3. Check for non intersection 4.
Compute thc 5. Check thc2 lt 0 6. Calculate the
intersection distance 7. Calculate
intersection point 8. Calculate normal
8. Calculate the normal at the intersection
point
Done!
26
Computing the Reflection Ray
  • Angle of incidence angle of reflection

I incoming ray N Surface normal R Reflected
ray (generally want to keep I and N normalized)
27
Computing the Reflection Ray
  • Knowing I and N, how do we compute R?

1. qI q R 2. I, N, and R are coplanar 3. R aI
bN 4. -I ? N cos(qI) 5. N ? R cos(q
R) 6. Using 1, 4, and 5, we get 7. -I ? N N ?
R, so 8. -I ? N N ? (aI bN) 9. -I ? N (N ?
aI) (N ? bN) 10. -I ? N a(N ? I) b (N ?
N) 11. -I ? N a(N ? I) b, since N is
normalized 12. Without loss of generality, let a
1, then 13. b -2 (N ? I), so 14. R I - 2(N
? I)N
28
Refraction (transparency)
  • When an object is transparent, it transmits light
  • Light travels through different materials at
    different speeds.
  • Thus, we get light bending.
  • E.g., pole in water

29
Refraction (transparency)
  • The manner in which light travels through a
    material is accounted for by the objects index
    of refraction
  • the ratio of the speed of light through the
    material to the speed of light in a vacuum
  • Light bend computed by Snells law

I
n
Medium 1
T
Medium 2
30
Refraction Indices
  • Index of refraction for various materials
  • Material Index
  • Vacuum 1.0
  • Air 1.0003
  • Water 1.33
  • Alcohol 1.36
  • Fused quartz 1.46
  • Crown glass 1.52
  • Flint glass 1.65
  • Sapphire 1.77
  • Heavy flint glass 1.89
  • Diamond 2.42

31
Refraction
  • How do we compute T?

1. Let nIT n1/n2 sin(f)/sin(q) 2. then nIT2
sin2(f)/sin2(q) 3. sin2(q) nIT2 sin2(f)
4. since sin2(q) cos2(q) 1, we get 5. (1 -
cos2(q)) nIT2 1 - cos2(f), so 6. (1 - cos2(q))
nIT2 - 1 - cos2(f) 7. (1 - cos2(q)) nIT2 - 1
- (-N ? T)2 8. (1 - cos2(q)) nIT2 - 1 - (-N ?
(aI bN))2 9. (1 - cos2(q)) nIT2 - 1 - (-a(N
? I) b(-N ? N))2 10. (1 - cos2(q)) nIT2 - 1
-(a(cos(f)) - b)2 11. We want T normalized, so T
? T 1, so 12. 1 (aI bN) ? (aI bN) 13. 1
a2(I ? I) 2ab(I ? N) ? b2(N ? N) 14. 1 a2
2abcos(q) ? b2
I
n
Medium 1
T
Medium 2
32
Refraction
  • How do we compute T?

I
n
15. Solve equations 10 and 14 simultaneously 16.
(1 - cos2(q)) nIT2 - 1 -(a(cos(f)) - b)2
1 a2 2abcos(q) ? b2 17. After solving, we
get 18. So,
Medium 1
T
Medium 2
33
Refraction Example
  • Compute T for

Water
Glass
T
34
Refraction Example
35
Shadows
  • The intensity of what we see at at pixel will
    depend on whether or not a light actually hits
    the object
  • The point of intersection between ray 1 and the
    object is in direct illumination
  • The point of intersection between ray 2 and the
    object is blocked from the light source (in
    shadow)
  • The final pixel intensity must be computed taking
    this into account

Light
ray 1
ray 2
Eye
Image plane
36
Shadows
  • Approach for computing shadows (hard shadows)
  • For each ray generated, find the first object
    intersected
  • From that intersection point, send a ray directly
    to each light source
  • If the ray intersects an object en route to the
    light source, the object is occluded from that
    light source
  • For shadow rays, we dont care which object the
    ray intersects, just the fact that it does
    intersect

37
Ray-Plane Intersections
  • To find the intersection points of a ray with an
    infinite plane
  • Ray equation
  • Origin ro (xo, yo, zo)
  • Direction rd (xd, yd, zd)
  • Plane equation
  • ax by cz d 0
  • with a2 b2 c2 1
  • normal vector pn (a, b, c)
  • distance from (0, 0, 0) to plane is d
  • Substitute the ray equation into the plane
    equation
  • a(x0 xdt) b(y0 ydt) c(z0 zdt) d
    0
  • Þ ax0 axdt by0 bydt cz0 czdt d
    0
  • Solving for t we get
  • t -(ax0 by0 cz0 d) / (axd byd czd)

38
Ray-Plane Intersections
  • In vector form we have
  • If the ray is parallel to the plane and does
    not intersect
  • If the normal of the plane is pointing away
    from the ray, and thus the plane is culled
  • If t lt 0 then intersection point is behind the
    ray, so no real intersection occurs
  • Otherwise, compute intersection point p ro
    rdt

39
Ray/Plane Intersection
  • Basic Algorithm
  • Compute vd pn rd
  • If vd gt 0 and assuming 1 sided planes then return
  • If vd 0 then return (ray parallel to plane)
  • Compute vo -(pn rd d)
  • Compute t vo / vd
  • If t lt 0 return
  • If vd gt 0 reverse the planes normal
  • Return r (xo xdt, yo ydt, zo zdt)

40
Ray/Polygon Intersection
  • Assume planar polygons
  • First perform the ray/plane intersection with the
    plane in which the polygon lies
  • Next, determine whether the intersection point
    lies within the polygon

41
Ray/Polygon Intersection
  • Idea shoot a ray from the intersection point in
    an arbitrary direction
  • if the ray crosses an even number of polygon
    edges, the point is outside the polygon
  • if the ray crosses an odd number of polygon
    edges, the point is inside the polygon

11 crossings - point inside polygon
4 crossings - point outside polygon
42
Ray/Polygon Intersection
  • Polygon
  • a set of N points Gn (xn, yn, zn), n 0, 1,
    N-1
  • Plane
  • Ax By Cz D 0, with normal Pn (A, B, C)
  • Intersection point
  • Ri (xi, yi, zi), Ri on the plane

43
Ray/Polygon Intersection Algorithm
  • Step 1
  • Project the polygon onto a 2D plane
  • one of the coordinate planes
  • simply discard one of the coordinates
  • this will project the polygon onto the plane
    defined by the other two coordinates
  • topology preserving but not area preserving
  • throw away the coordinate whose magnitude in the
    plane normal is greatest
  • e.g., if Pn (3, -1, -5) we would throw away all
    z coordinates

44
Ray/Polygon Intersection Algorithm
  • Step 2
  • Translate the polygon so that the intersection
    point is at the origin
  • apply this translation to all points in the
    polygon
  • Step 3
  • Send a ray down one of the coordinate axes and
    count the number of intersections of that ray
    with the polygon
  • This is done in practice by looking at each
    polygon edge, one at a time, to see if it crosses
    the coordinate axis

45
Ray/Polygon Intersection Algorithm
  • Problems
  • Vertices that lie exactly on the ray
  • Edges that lie exactly on the ray

46
Ray/Polygon Intersection Algorithm
  • How do we handle these cases?
  • In essence, shift the vertex or edge up by e so
    that it will lie in the plane just above the axis
  • This is done by checking for a y value gt 0
  • What about if the intersection point is exactly a
    vertex?
  • Perform a similar e shift
  • What if the intersection point lies exactly on an
    edge?
  • Specify it as either in or out - as long as we do
    the specification consistently, it will work okay
  • If the edge is shared by two polygons, the point
    will be in one polygon and out of the other.

47
Ray/Polygon Intersection Algorithm
  • The effect of doing this e shift is
  • These cases all work correctly now.

48
The Actual Algorithm - part 1
  • Determine the dominant coordinate as the largest
    magnitude component of Pn
  • For each vertex (xn, yn, zn), n 0, 1, , N-1 of
    the polygon, project the vertex onto the dominant
    coordinate axis, giving (un, vn) vertices.
  • Project the intersection point (xint, yint, zint)
    onto the same coordinate plane as the vertices.
  • Translate all polygon vertices by (-uint, -vint),
    giving (un, vn) vertices.
  • Set numCrossings 0

49
The Actual Algorithm - part 2
  • If v0 lt 0, set signHolder -1, otherwise set
    signHolder 1
  • For i 0 to N-1 (note - when i N-1, i1 should
    be 0)
  • if vi1 lt 0 set nextSignHolder -1 else set
    nextSignHolder 1
  • if (signHolder ltgt nextSignHolder)
  • if (ui gt 0 and ui1 gt 0) this edge crosses u
    so increment numCrossings
  • else if (ui gt 0 or ui1gt0) the edge might cross
    u, so compute the intersection with the u axis
  • ucross ui -vi (ui1 -ui)/(vi1 -vi)
  • if ucross gt 0 the edge crosses u so increment
    numCrossings
  • set signHolder nextSignHolder
  • If numCrossings is odd, the point is inside the
    polygon

50
Example
  • Given a polygon
  • G0 (-3, -3, 7)
  • G1 (3, -4, 3)
  • G2 (4, -5, 4)
  • and intersection point
  • Ri (-2, -2, 4)
  • Does the intersection point lie within the
    polygon?

51
Example
  • Step 1 Get the plane normal, determine dominant
    coordinate
  • Pn can be computed from the cross product of two
    vectors in the plane
  • The vertices of the polygon can be used to
    compute vectors in the plane

v1 G0 - G1 (-3, -3, 7) - (3, -4, 3)
(-6, 1, 4)
v2 G2 - G1 (4, -5, 4) - (3, -4, 3) (1,
-1, 1)
52
Example
  • The plane normal is then v1 x v2 (assuming
    clockwise vertex specification)

Pn (-6, 1, 4) x (1, -1, 1) (5, 10, 5)
So the dominant coordinate is y
53
Example
  • Step 2 Project the vertices
  • Step 3 Project the intersection point

G0 proj of (-3, -3, 7) Þ (-3, 7) G1 proj of
(3, -4, 3) Þ (3, 3) G2 proj of (4, -5, 4) Þ (4,
4)
G1
Ri
G2
G0
Ri proj of (-2, -2, 4) Þ (-2, 4)
54
Example
  • Step 4 Translate the vertices

G0 (-3, 7) - (-2, 4) Þ (-1, 3) G1 (3, 3) -
(-2, 4) Þ (5, -1) G2 (4, 4) - (-2, 4) Þ (6,
0) Ri (-2, 4) - (-2, 4) Þ (0, 0)
G1
Ri
G2
G0
55
Example
  • Step 5 Set numCrossings 0
  • Step 6 v0 3, so
  • signHolder 1

56
Example
  • Step 7
  • i signHolder nextSignHolder numCrossings intersect
    ion point

u
v
1
0
0
-1
-1
1
-1-3(5-(-1))/(-1-3) 3.5
1
1
1
2
2
1
Since numCrossings is even, the point is outside
the polygon
57
Ray/Box Intersection
  • i.e., intersecting with bounding boxes
  • We will deal with the case of boxes with parallel
    sides with normals parallel to the coordinate
    axes.
  • Box
  • Minimum extent Bl (xl, yl, zl)
  • Maximum extent Bh (xh, yh, zh)
  • Ray
  • R(t) Ro Rdt
  • Ro (xo, yo, zo)
  • Rd (xd, yd, zd)

58
Ray/Box Intersection (2)
  • Algorithm
  • Set tnear -8, tfar 8
  • For the pair of X planes
  • If xd 0, the ray is parallel to the planes
  • If xo lt xl or xo gt xh then return FALSE
    (origin not between planes)
  • Else the ray is not parallel to the planes, so
    calculate intersection distances of planes
  • t1 (xl - xo) / xd (time at which the ray
    intersects the minimum x plane)
  • t2 (xh - xo) / xd (time at which the ray
    intersects the maximum x plane)
  • If t1 gt t2 swap t1 and t2
  • If t1 gt tnear , set tnear t1
  • If t2 lt tfar , set tfar t2
  • If tnear gt tfar box is missed so return FALSE
  • If tfar lt 0 box is behind ray so return FALSE
  • Repeat step 2 for Y then Z
  • All tests survived, so return TRUE

59
Ray/Box Intersection example 1
tfar
tnear
yh
yl
Ro
xl
xh
60
Ray/Box Intersection example 2
tfar
tnear
yh
yl
Ro
xl
xh
61
Ray/Box Intersection Example 3
  • Given the ray
  • Ro (0, 4, 2)
  • Rd (0.213, -0.436, 0.873)
  • And the box
  • Bl (-1, 2, 1)
  • Bh (3, 3, 3)
  • Does the ray hit the box?

62
Ray/Box Intersection Example 3
  • t1x (-1 - 0) / 0.218 -4.59
  • t2x (3 - 0) / 0.218 13.8
  • So tnear -4.59, tfar 13.8
  • t1y (2 - 4) / (-.436) 4.59
  • t2y (3 - 4) / (-.436) 2.29
  • t1y gt t2y so swap
  • Then tnear 2.29, tfar 4.59
  • t1z (1 - 2) / (0.873) -1.15
  • t2z (3 - 2) / (0.873) 1.15
  • tnear stays the same
  • tfar 1.15
  • So, tnear gt tfar so the ray misses the box
Write a Comment
User Comments (0)
About PowerShow.com