Ray Tracing II - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Ray Tracing II

Description:

Observation: We are only interested in rays that cross the eye point. ... inside the sphere, N should be negated so that it points back toward the center. ... – PowerPoint PPT presentation

Number of Views:54
Avg rating:3.0/5.0
Slides: 19
Provided by: drewke9
Category:
Tags: negated | ray | tracing

less

Transcript and Presenter's Notes

Title: Ray Tracing II


1
Ray Tracing II
2
Ray Tracing
  • Observation We are only interested in rays that
    cross the eye point.
  • Idea Start at eye point and trace backwards.

Light Source
Shadow Ray
Eye
Object
Eye Ray
Shadow Ray
Object
Light Source
3
Visible Surface Determination
  • Ray tracing can be used as a visible surface
    determination algorithm
  • Often called ray casting.
  • (A ray is a uni-directional line segment).
  • The algorithm
  • For each pixel
  • Determine the world coordinates of the pixels
    center.
  • Cast a ray from the eye through the pixels
    center.
  • Check for intersection of this ray with any
    object.
  • For closest intersection, determine color of
    object at that point.

4
Color Determination
  • To determine the color at the intersection of an
    eye ray with an object, we can
  • Simply assign the color of the object (no
    shading).
  • Determine the shading of the object.
  • Calculate the contribution of a texture at that
    point.
  • Some combination of the above
  • Shading
  • Cast ray from intersection point to each light
    source.
  • The shadow ray.
  • Light contributes to shading only if the shadow
    ray does not intersect an object in the scene.

5
Intersections
  • Ray tracing algorithms are dominated by
    intersection testing and determination
  • Need efficient methods to test for intersection
  • Does the eye ray or shadow ray intersect an
    object?
  • Need efficient method to calculate intersection
    points and normal vectors (for lighting
    calculations).
  • Ray/Sphere
  • Ray/Plane
  • Ray/Polygon

6
Ray/Sphere Intersection (Algebraic
Solution)
  • Ray is defined by R(t) Ro Rdt where t gt 0.
  • Ro Origin of ray at (xo, yo, zo)
  • Rd Direction of ray xd, yd, zd (unit vector)
  • Sphere's surface is defined by the set of points
    (xs, ys, zs) satisfying the equation
  • (xs - xc)2 (ys - yc)2 (zs - zc)2 - rs2
    0
  • Center of sphere (xc, yc, zc)
  • Radius of sphere rs

7
Possible Cases of Ray/Sphere Intersection
1. Ray intersects sphere twice with tgt0 2. Ray
tangent to sphere 3. Ray intersects sphere with
tlt0 4. Ray originates inside sphere 5. Ray does
not intersect sphere
1
2
3
4
5
8
Solving For t
  • Substitute the basic ray equation
  • x xo xdt
  • y yo ydt
  • z zo zdt
  • into the equation of the sphere
  • (x0 xdt - xc)2 (y0 ydt - yc)2 (z0 zdt -
    zc)2 - rs2 0
  • This is a quadratic equation in t At2 Bt C
    0, where
  • A xd2 yd2 zd2
  • B 2xd(x0 - xc) yd(y0 - yc) zd(z0 - zc)
  • C (x0 - xc)2 (y0 - yc)2 (z0 - zc)2 - rs2
  • Note A1

9
Relation of t to Intersection
  • We want the smallest positive t - call it ti

t0
Discriminant 0
t1
t0
t0
t1
t1
Discriminant lt 0
10
Actual Intersection
  • Intersection point, (xi, yi, zi) (xoxdti,
    yoydti, zozdti)
  • Unit vector normal to the surface at this point
    is
  • N (xi - xc) / rs, (yi - yc) / rs, (zi - zc) /
    rs
  • If the ray originates inside the sphere, N should
    be negated so that it points back toward the
    center.

N
N
11
Summary (Algebraic Solution)
  • Calculate A, B and C of the quadratic
  • Calculate discriminant (If lt 0, then no
    intersection)
  • Calculate t0
  • If t0 lt 0, then calculate t1 (If t1 lt 0, no
    intersection point on ray)
  • Calculate intersection point
  • Calculate normal vector at point
  • Helpful pointers
  • Precompute rs2
  • Precompute 1/rs
  • If computed t is very small then, due to rounding
    error, you may not have a valid intersection

12
Ray/Plane Intersection
  • Ray is defined by R(t) Ro Rdt where t gt 0
  • Ro Origin of ray at (xo, yo, zo)
  • Rd Direction of ray xd, yd, zd (unit
    vector)
  • Plane is defined by A, B, C, D
  • Ax By Cz D 0 for a point in the plane
  • Normal Vector, N A, B, C (unit vector)
  • A2 B2 C2 1

13
Ray/Plane (cont.)
  • Substitute the ray equation into the plane
    equation
  • A(xo xdt) B(yo ydt) C(zo zdt) D 0
  • Solve for t
  • t -(Axo Byo Czo D) / (Axd Byd Czd)
  • t -(N Ro D) / (N Rd)

14
What Can Happen?
15
Ray/Plane Summary
  • Intersection point
  • (xi, yi, zi) (xo xdti, yo ydti, zo zdti)
  • Calculate N Rd and compare it to zero.
  • Calculate ti and compare it to zero.
  • Compute intersection point.

16
Ray/Polygon Intersection
  • A polygon is defined by a set of p points Gn
    (xn, yn, zn) n 0, 1, ..., (p-1)
  • The polygon is in a plane, Ax By Cz D 0,
    Normal N A, B, C
  • Find the intersection of the ray with the plane
    of the polygon.
  • Throw away the coordinate of each point for which
    the corresponding normal component is of the
    greatest magnitude (dominant coordinate).
  • You now have a 2-D polygon defined by the set of
    points
  • (un, vn) n 0, 1, .., p-1
  • Translate the polygon so that the intersection
    point of the ray with the plane of the polygon
    goes to the origin of the u,v system. Call these
    translated points
  • (un, vn) n 0, 1, .., p-1
  • Determine whether the origin is within the 2D
    polygon.

17
Ray/Polygon (cont.)
18
Ray/Polygon Algorithm
  • To determine whether the origin is within a 2D
    polygon, we only need to count the number of
    times the polygons edges cross the positive
    u-axis as we walk around the polygon. Odd number
    crossings origin is within.
  • num_crossings 0
  • sign_holder sign(v0)
  • for(a0 a lt p a)
  • b (a1) p
  • next_sign_holder sign(vb)
  • if (sign_holder ! next_sign_holder)
  • if (ua gt 0 and ub gt 0)
  • num_crossings num_crossings 1
  • else if (ua gt 0 or ub gt 0)
  • int ua - va(ub - ua) / (vb - va)
  • if(int gt 0)
  • num_crossings num_crossings 1
  • sign_holder next_sign_holder
  • if(num_crossings 2 1) ray intersects polygon
Write a Comment
User Comments (0)
About PowerShow.com