Slides from 03/31/05 (Ray Tracing)

advertisement
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.
}
}
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.
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.
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.
Intersections (More)
• Ellipsoids (from wwwcourses.cs.uiuc.edu/~cs419/ray-intersection.ppt)
These eqns
should be
flipped
Local Illumination (a quick
reminder)
• Phong illumination model (not to be
confused with Phong shading)
– For each light:
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
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
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.
Download