Wednesday, January 19, 2011

Lessons learned from Writing a RayTracer

As I promised in my post about finishing my ray-tracer, I'm publishing the math equations I used in order to save some time for other people, when doing the intersection calculations.

You can find the document here: The 3D Equation Sheet

And here is a list of ridiculously annoying bugs, that I encountered during writing the ray-tracer. Although some of these seem really trivial, I'll list them in hope that they will save you some time when you write a ray-tracer. Even though these seem trivial, I know that some of them are bugs that other teams also had.

Common Bugs:
  • When you shoot a ray from the eye and find an intersection, make sure the item is actually in front of the eye and not behind it!
  • When the ray from the eye intersects with a point, and you shoot light at the point, make sure the light is on the same side of the surface as your eye - so that you won't see light on the other side on opaque surfaces!
  • When calculating the intersection with a cylinder, which has a limited length - if the first intersection is "too far" from the origin of the cylinder, the second intersection may actually be in range! So check both...
  • Rays of light should be shot from the eye of the camera, and not from the image plane of the camera! (It matters when checking if an object is behind us or not)
  • When building the plane where x=6, the equation is x-6=0 and not x+6=0. Trivial, but not noticing this missing minus wasted an entire day for me…

No comments:

Post a Comment