Getting Started

Okay. You are officially awesome. You’re one of those programmers, the ones who actively seek out new ways to apply their craft and tackle challenges for the thrill of it. You’re in good company!

With this book, you’re going to build a 3D renderer from scratch. Specifically, you’ll build a ray tracer, casting rays of light backward into a scene and following their paths as they bounce around toward a light source. It’s generally not a very fast technique (and so isn’t well-suited for real-time rendering) but it can produce very realistic results. By the end of this book, you’ll be able to render scenes like this one:

images/intro/jacks.png

And you don’t have to be a mathematician or computer scientist to do it!

Beginning at the bottom, you’ll build a foundation of basic routines and tools. You’ll use those to bootstrap other routines, making light rays, shapes, and functions to predict how they’ll interact. Then things start moving quickly, and within a few chapters you’ll be producing realistic images of 3D spheres. You’ll add shadows and visual effects like geometric patterns, mirror reflections, and glass. Other shapes follow—planes, cubes, cylinders, and more. By the end of the book, you’ll be taking these primitive shapes and combining them in complex ways using set operations. There’ll be no stopping you!

The specific algorithm you’ll implement is called Whitted ray tracing,[1] named for Turner Whitted, the researcher who described it in 1979. It’s often referred to as recursive ray tracing, because it works by recursively spawning rays (lines representing rays of light) and bouncing them around the scene to discover what color each pixel of the final image should be. In a nutshell, the algorithm works like this for each of the image’s pixels:

  1. Cast a ray into the scene, and find where it strikes a surface.
  2. Cast a ray from that point toward each light source to determine which lights illuminate that point.
  3. If the surface is reflective, cast a new ray in the direction of reflection and recursively determine what color is reflected there.
  4. If the surface is transparent, do the same thing in the direction of refraction.
  5. Combine all colors that contribute to the point (the color of the surface, the reflection, and refraction) and return that as the color of the pixel.

Over the course of this book, you’ll implement each of those steps, learning how to compute reflection vectors, how to approximate refraction, how to intersect rays with various primitive shapes, and more. Sooner than you might think, you’ll be rendering awesome 3D scenes!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.218.215