1 / 9

Ray Tracing Outline

Ray Tracing Outline. For each pixel { Shoot ray r from eye to center of pixel with trace( r ) } function trace( r ) For each object { Find object with closest intersection, x. } If x exists { For each light source { For all other objects {

diep
Download Presentation

Ray Tracing Outline

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Ray Tracing Outline For each pixel { Shoot ray r from eye to center of pixel with trace( r ) } function trace( r ) For each object { Find object with closest intersection, x. } If x exists { For each light source { For all other objects { Check for intersection of ray from light to x. } If no intersection { Calculate direct illumination with Phong model. } Accumulate calculated color. } Calculate reflection ray r’, and recurse calling trace( r’ ) Accumulate reflected colors, and return. } }

  2. Leverage C++ • Using C++ will make complicated code very simple. Take advantage of it! • Abstract base class “Object”. Subclasses for spheres, triangles, etc. Store objects as array of pointers, and iterate with virtual “Intersect” function. • Common information (Kd, Ks, Ka) • Each actual object type will have its own intersection function.

  3. Data Structures • Sphere: center, radius • Ellipsoid: Just sphere with 4x4 tranformation applied to it. • Triangle: vertices, normal • Ray: start, direction • Input files: • Can use parser from As3 • Need: camera information, object information • Objects should at least have Ks, Kd, color, location, but the assignment is open-ended. E.g., can have Ka if you want, or not. Can have texture map information.

  4. Intersections • Parametric ray equation: r(t)=p+td • t>=0 • Implicit sphere equation: f(p)=||p-c||-r=0 • p is any point on sphere’s surface, c is the center, r is the radius. • Intersection (with an implicit equation) is just root finding. • Explicit triangle equation: t(u,v)=(1-u-v)v0+uv1+vv2 • Barycentric • Solve linear system of equations.

  5. Intersections (More) • Ellipsoids (from www-courses.cs.uiuc.edu/~cs419/ray-intersection.ppt) These eqns should be flipped

  6. Local Illumination (a quick reminder) • Phong illumination model (not to be confused with Phong shading) • For each light:

  7. Speeding things up • BSP trees with bounding boxes • Intersections take up most of the time. • If create BSP structure, then can check for intersection from front to back from a given starting ray location. • Octrees • Figure out which cells it intersects, and check for intersections only with objects inside those cells

  8. More features • Here are some suggestions: • Transparency with refraction • Anti-aliasing • Lens effects / depth of field • Super quadrics • Programmable shading • Texture, bump, and/or displacement mapping • Spot lights and/or area lights • Other interesting features

  9. Tips • Make sure you test your code early and often. Ray tracers are hard to debug. • Don’t try to implement everything at once. E.g., start with only spheres, 1 light source, and a constant local illumination value to test your intersection code. • Take advantage of the newsgroup. • This assignment is open-ended. However, we strongly suggest using C++. Very strongly. • Start now! You don’t know what silly problems you’ll encounter. Plus, you’ll get really into it and want to add lots of extra features.

More Related