Ray Tracing - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Ray Tracing

Description:

Uses illumination models to determine color value at the intersection of a ray and an object. ... Ray Sphere Intersection. Algebraic solution ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 20
Provided by: mattc159
Category:
Tags: ray | tracing

less

Transcript and Presenter's Notes

Title: Ray Tracing


1
Ray Tracing
  • Matthew W. Campbell
  • Senior, Computer Science Dept.

2
Ray tracing overview
  • Technique for rendering 3D graphics.
  • Point sampling technique.
  • rays pixels (assuming normal sampling)
  • Models light interaction among surfaces and the
    environment.
  • Uses illumination models to determine color value
    at the intersection of a ray and an object.
  • Supports transparency, reflections, refractions,
    etc.

3
Ray tracing concept and samples
4
Ray tracing algorithm
  • Begin tracing.
  • Construct a ray through each pixel in the scene.
  • Pixel color result of tracing the ray
  • Tracing the ray
  • Find intersection of ray with closest object in
    the scene.
  • Compute intersection point and normal at the
    intersection point.
  • Shade the point.
  • Shade the point
  • For each light
  • Determine if point is in shadow relative to light
    source.
  • Using illumination model, determine color at the
    intersection point.

5
Constructing primary rays
  • Ray is defined by R(t) Ro Rdt where tgt0.
  • Ro Origin of ray at (xo, yo, zo)
  • Rd Direction of ray xd, yd, zd (unit vector).
  • Determine world location of pixel (i,j).
  • Origin (x,y,z) camera position.
  • Direction (x,y,z)
  • j (WIDTH/2)
  • i (HEIGHT/2)
  • 255.0 Fairly abitrary, just interpret as FOV.
  • Normalize direction vector.

6
Ray Plane intersection
  • Plane equation
  • Ax By Cz D 0 (point on plane)
  • (A,B,C) is normal of the plane (unit vector)

7
Ray/Plane cont.
  • Substitute ray equation into 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)

8
Ray/Plane Summary
  • Compute N Rd
  • If equals zero, ray and plane are parallel,
    therefore, no intersection.
  • Compute t
  • t -(N Ro D) / (N Rd)
  • If t lt 0, no intersection
  • Compute intersection point.
  • (x,y,z) R0 (Rd t)

9
Ray Sphere Intersection
  • Algebraic solution
  • (x0 xdt - xc)2 (y0 ydt - yc )2 (z0 zdt
    - zc)2 - rs2 0
  • 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
  • Intersection point
  • (x,y,z) (xo xdt, yo ydt, zo zdt)
  • N (x - xc) / rs, (y - yc) / rs, (z - zc) / rs

10
Ray-Sphere Cont.
  • Geometric Solution
  • Lots of ways to determine that no intersection
    exists, why does this help?
  • 6 Steps
  • 1 Find if the rays origin is inside the
    sphere.
  • Origin to center vector, OC C Ro
  • Length squared of OC OC2
  • If OC2 lt rs2 then ray origin is inside of the
    sphere. (go to step 4). Else if OC2 gt rs2
    then ray origin is outside of the sphere.

11
Ray-Sphere Cont.
  • Step 2
  • Calculate ray distance which is closest to the
    center of the sphere.
  • L OC cos ß OC Rd cos ß OCRd
  • If the ray is outside of the sphere and points
    away from the sphere, L must be lt 0, and the ray
    misses the sphere.

12
Ray-Sphere Cont.
  • Step 3
  • Calculate the squared distance from the closest
    approach along the ray to the spheres center
    to the spheres surface. (HC2 half coord
    distance squared).
  • D2 OC2 L2
  • HC2 rs2 D2
  • If HC2 lt 0, ray misses sphere.

13
Ray-Sphere Cont.
  • Step 4
  • Find t.
  • t L HC, if ray originates outside the sphere.
  • t L HC, if ray originates inside the sphere.
  • Step 5
  • Calculate the intersection point.
  • (x,y,z) Ro (tRd) I
  • Step 6
  • Calculate the normal vector.
  • N (I-Sc) / Sr, negate if ray originates inside
    of the sphere.

14
Ray-Polygon Intersection
  • We define a polygon as a list of n points
  • (x0, y0, z0), (x1, y1, z1),(xn-1, yn-1, zn-1).
  • The polygon is in a plane, i.e. we use planar
    polygons.
  • Algorithm overview
  • Intersect the ray with the plane of the polygon.
  • Project the polygon into 2D space.
  • Translate the polygon so the intersection point
    of the ray and the plane sits at the origin.
  • Determine whether the origin is within the 2D
    polygon.

15
Ray-Polygon Cont.
  • Project the polygon into 2D space.
  • Planar projection.
  • Take the polygons normal and find the dominate
    component.
  • Throw away the corresponding coordinate of each
    point in the polygon.
  • Ex Polygon normal (0,0,1) Lies on the XY
    plane.
  • Throw away the z component of each point in the
    polygon resulting in a 2D polygon.

16
Ray-Polygon Cont.
  • Translate the polygon and check to see if origin
    is inside.
  • Translate the polygon by the intersection point
    of the ray and the plane ( I).
  • For all points in the polygon, Pnew Pold I
  • 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.

17
Ray-Polygon Cont.
18
Ray tracing optimizations
  • Adaptive grid sampling
  • Instead of using one ray per pixel, use one ray
    per block of pixels if the detail in that part of
    the image is small enough.
  • Spatial Partitioning!!
  • Uniform grids.
  • Octrees, KD-trees, BSP-trees.
  • Any BVH or bounding volume hierarchy.
  • Reduce recursion depth when calculating
    reflections and refractions.

19
?
Write a Comment
User Comments (0)
About PowerShow.com