Ray Tracing - PowerPoint PPT Presentation


PPT – Ray Tracing PowerPoint presentation | free to view - id: 73992-ZDc1Z


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation

Ray Tracing


Add the light ray's color intensities to the pixel. ... To determine the color at the intersection of an eye ray with an object, we can: ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 25
Provided by: drew81


Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Ray Tracing

Ray Tracing
An Ideal Ray Tracer
  • Cast light rays from all light sources.
  • Follow them to the eye point.
  • Reflect off of solid objects.
  • Pass through transparent objects (refraction).
  • Obtain color by light absorption.
  • Diffuse reflection/refraction multiplies rays.
  • For rays that hit the eye point, intersect with
    window on view plane, which corresponds to a
    screen pixel.
  • Add the light rays color intensities to the
  • Problem It could take forever to draw an image!

Ray Tracing That Works
  • 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 Ray
Shadow Ray
Light Source
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
  • Cast a ray from the eye through the pixels
  • Check for intersection of this ray with any
  • For closest intersection, determine color of
    object at that point.

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
  • Determine the shading of the object.
  • Calculate the contribution of a texture at that
  • Some combination of the above
  • Shading
  • Cast ray from intersection point to each light
  • The shadow ray.
  • Light contributes to shading only if the shadow
    ray does not intersect an object in the scene.

  • 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
  • Need efficient method to calculate intersection
    points and normal vectors (for lighting
  • Ray/Sphere
  • Ray/Plane
  • Ray/Polygon

Ray/Sphere Intersection (Algebraic
  • 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
  • Center of sphere (xc, yc, zc)
  • Radius of sphere rs

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
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

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

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

Summary (Algebraic Solution)
  • Calculate A, B and C of the quadratic
  • Calculate discriminant (If lt 0, then no
  • 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

Ray/Sphere Intersection (Geometric Solution)
  • In the case of the sphere there are a number of
    tests that we can make to determine that there is
    not an intersection. This approach allows us to
    avoid calculations and result in a faster
  • 1. Find if the ray's origin is outside the sphere.

Origin to center vector, OC C - Ro Length
squared of OC OC2 If OC2 lt rs2 then
the ray origin is inside the sphere (go to step
4) Else if OC2 gt rs2 then the ray origin is
outside the sphere
R/S Geometric Solution (cont.)
  • 2. Find the length of the ray to the point along
    the ray closest to the sphere's center.

L OC cos ß OC Rd cos ß OCRd
If the ray is outside and points away from the
sphere (L lt 0), the ray must miss the sphere.
R/S Geometric Solution (cont.)
  • 3. Else find the squared distance from the
    closest approach along the ray to the sphere's
    center to the sphere's surface (HC2 half chord
    distance squared).

D2 OC2 - L2 HC2 rs2 - D2 rs2 -
OC2 L2
If HC2 lt 0, the ray misses the sphere.
R/S Geometric Solution (cont.)
  • 4. Else find t for the intersection
  • ti L - HC for rays originating outside the
  • ti L HC for rays originating inside or on
    the sphere
  • 5. Calculate intersection point (xi, yi, zi) by
    plugging ti into Ro tRd
  • 6. Calculate normal vector
  • (xi - xc)/rs (yi - yc)/rs, (zi - zc)/rs
  • (negate if ray originates inside sphere)

Summary (Geometric Solution)
  • Find distance squared between ray origin and
    center of sphere, test for ray outside sphere.
  • Calculate ray distance which is closest to the
    center of the sphere.
  • Test if the ray points away from the sphere.
  • Find square of half chord intersection distance.
  • Test if square is negative.
  • Calculate intersection distance.
  • Find intersection point.
  • Calculate normal vector at point.
  • These techniques are no slower than the
    algebraic solution and often allow you to
    determine that there is no intersection using
    fewer calculations.

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
  • 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

Ray/Plane (cont.)
  • Substitute the ray equation into the plane
  • 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)
  • Note The normal vector of the plane should
    usually (except for backface removal) be for the
    surface facing the ray. If it isn't then it
    should be reversed before illumination is
  • If N Rd gt 0 then use N -A, B, C

What Can Happen?
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.
  • Compare N Rd to zero and reverse normal if

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
  • (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

Ray/Polygon (cont.)
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
About PowerShow.com