Download Ray Intersect - Introduction to Computer Graphics - Lecture Slides and more Slides Computer Graphics in PDF only on Docsity!
Lecture 17:
Ray Intersect
Review
โข In ray casting, there are three steps:
โ Step 1: Generating a Ray
- A. Find the ray in world coordinate system
- B. Find the ray in camera coordinate system and transform it
to world coordinate
โ Step 2: Intersection
- Intersects the ray with all objects in the world
- Return the nearest point on the nearest object
โ Step 3: Coloring the Pixel
- Direct illumination (Assignment 5: intersect)
- Indirect illumination (Assignment 6: recursive ray tracer)
Step 2: Ray-Object Intersection
(Implicit Objects)
- At what points (if any) does the ray intersect an object?
- Points on a ray have form P + t d
- t is any nonnegative real
- A surface point Q lying on an object has the property that f(Q) = 0
- Combining, we want to know โFor which values of t is f(P + t d ) = 0 ?โ
- We are solving a system of simultaneous equations in x , y (in 2D) or x , y , z (in 3D)
Step 2: Ray-Object Intersection
(Implicit Objects)
2D ray-circle intersection example
- Consider eye-point P = (-3, 1), direction vector d = (.8, -.6) and the unit circle:
f(x,y) = x^2 + y^2 โ R^2
- A typical point of the ray is:
Q = P + t d = (-3,1) + t (.8,-.6) = (-3 + .8t,1 - .6 t )
- Plugging this into the equation of the circle:
f (Q) = f (-3 + .8t,1 - .6 t ) = (-3+.8 t )^2 + (1-.6 t )^2 - 1
9 โ 4.8 t + .64 t^2 + 1 โ 1.2 t + .36 t^2 - 1
- Setting this to zero, we get:
t^2 โ 6 t + 9 = 0
Step 2: Ray-Object Intersection
2D ray-circle intersection example (continued)^ (Implicit Objects)
- Generalizing:
- we can take an arbitrary implicit surface with equation f(Q) = 0 , a ray P + t d , and plug the latter into the former:
f ( P + t d ) = 0
- The result, after some algebra, is an equation with t as unknown
- We then solve for t , analytically or numerically
Step 2: Ray-Object Intersection
- For cylindrical objects, the implicit equation^ (Implicit Objects)
๐(๐ฅ, ๐ฆ, ๐ง) = ๐ฅ^2 + ๐ง^2 โ 1 = 0
in 3-space defines an infinite cylinder of unit radius, running along the y-axis
- Usually, itโs more useful to work with finite objects
- e.g. a unit cylinder truncated with the limits: Cylinder Body: ๐ฅ^2 + ๐ง^2 โ 1 = 0, โ1 โค ๐ฆ โค 1
- But how do we implicitly define cylinder โcaps?โ
- The cap is the inside of the cylinder at the y extrema of the cylinder (a.k.a. a circle)
- cylinder caps top: ๐ฅ^2 + ๐ง^2 โ 1 โค 0, ๐ฆ = 1
bottom: ๐ฅ^2 + ๐ง^2 โ 1 โค 0, ๐ฆ = โ
Cap
Step 2: Ray-Object Intersection
(Implicit Objects)
Implicit surface strategy summary
- Substitute ray ( P + t d ) into implicit surface equations and solve for t
- smallest non-negative t -value is the closest surface you see from eye point
- For complicated objects (not defined by a single equation), write out a set of equalities and inequalities and then code individual surfaces as casesโฆ
- Latter approach can be generalized cleverly to handle all sorts of complex combinations of objects - constructive Solid Geometry (CSG), where objects are stored as a hierarchy of primitives and 3-D set operations (union, intersection, difference) - โblobby objectsโ, which are implicit surfaces defined by sums of implicit equations (F(x,y,z)= 0 )
CSG!
Cool Blob!
Step 2: Ray-Object Intersection
โข So far, we have seen how intersection works if
the object is in the world coordinate, and its
parameters are simple
โ That is, the object sits at (0, 0, 0), and has unit radius
โข In real examples, the objects have often been
translated, rotated, and scaled.
โข How would we apply the same solution to these
objects?
Step 2: Ray-Object Intersection (Object
Coord)
- Let the world-space intersection point be defined as MQ , where Q is a point in object space: ๐ + ๐ก๐
= ๐๐ ๐โ1^ โ
๐ + ๐ก๐
= ๐ ๐โ1๐ + ๐ก๐โ1๐
= ๐ Let ๐ = ๐โ1๐, ๐
= ๐โ1๐
- If ๐ ๐ฅ, ๐ฆ, ๐ง is the equation of the untransformed object, we just have to solve ๐ ๐ + ๐ก๐
= 0
- note: ๐
is probably not a unit vector
- the parameter t along this vector and its world space counterpart always have the same value.
- normalizing ๐
would alter this relationship. Do NOT normalize ๐
. Why??
(0,0,0)
MQ
P ๏ซ t d
f ( x , y , z )๏ฝ 0
d^11 d
~ ~ ๏ญ ๏ญ P ๏ซ t ๏ฝ M P ๏ซ tM
Q
f x y z ๏ฝ
Step 2: Ray-Object Intersection (Object
Coord)
- In the example, we already know the matrix M, which transforms the
object from object coordinate into world coordinate.
- Recall, M is the matrix that translate/rotate/scales a unit object into the desired location/orientation/size
- We are just finding the inverse of M, which will bring the ray from world
coordinate back to object coordinate.
- The advantage is obvious, math is easier in the object coordinate space!
- As mentioned before, you need to find the smallest t-value from the
intersection test, you can use t in two ways:
- ๐ + ๐ก๐
gives the world coordinate location of the intersection point
- ๐ + ๐ก๐
is the corresponding intersection point in object coordinate
- Note that the t value doesnโt change between the two coordinate spaces!