The Ray Tracer Challenge

Book description

Brace yourself for a fun challenge: build a photorealistic 3D renderer from scratch! It's easier than you think. In just a couple of weeks, build a ray-tracer that renders beautiful scenes with shadows, reflections, brilliant refraction effects, and subjects composed of various graphics primitives: spheres, cubes, cylinders, triangles, and more. With each chapter, implement another piece of the puzzle and move the renderer that much further forward. Do all of this in whichever language and environment you prefer, and do it entirely test-first, so you know it's correct. Recharge yourself with this project's immense potential for personal exploration, experimentation, and discovery.

The renderer is a ray tracer, which means it simulates the physics of light by tracing the path of light rays around your scene. Each exciting chapter presents a bite-sized piece of the puzzle, building on earlier chapters and setting the stage for later ones. Requirements are given in plain English, which you translate into tests and code. When the project is complete, look back and realize you've built an entire system test-first!

There's no research necessary -- all the necessary formulas and algorithms are presented and illustrated right here. Dive into intriguing topics from fundamental concepts such as vectors and matrices; to the algorithms that simulate the intersection of light rays with spheres, planes, cubes, cylinders, and triangles; to geometric patterns such as checkers and rings. Lighting and shading effects, such as shadows and reflections, make your scenes come to life, and constructive solid geometry (CSG) enables you to combine your graphics primitives in simple ways to produce complex shapes.

Play and experiment as you discover the fun of writing a ray tracer. Accept the challenge today!

What You Need:



Aside from a computer, operating system, and programming environment, you'll need a way to display PPM image files. On Windows, programs like Photoshop will work, or free programs like IrfanView. On Mac, no special software is needed, as Preview can open PPM files.

Publisher resources

View/Submit Errata

Table of contents

  1.  Acknowledgments
  2.  Foreword
  3.  Getting Started
    1. Who This Book Is For
    2. How to Read This Book
    3. Things to Watch Out For
  4. 1. Tuples, Points, and Vectors
    1. Tuples
    2. Operations
    3. Putting It Together
  5. 2. Drawing on a Canvas
    1. Representing Colors
    2. Implementing Color Operations
    3. Creating a Canvas
    4. Saving a Canvas
    5. Putting It Together
  6. 3. Matrices
    1. Creating a Matrix
    2. Multiplying Matrices
    3. The Identity Matrix
    4. Transposing Matrices
    5. Inverting Matrices
    6. Putting It Together
  7. 4. Matrix Transformations
    1. Translation
    2. Scaling
    3. Rotation
    4. Shearing
    5. Chaining Transformations
    6. Putting It Together
  8. 5. Ray-Sphere Intersections
    1. Creating Rays
    2. Intersecting Rays with Spheres
    3. Tracking Intersections
    4. Identifying Hits
    5. Transforming Rays and Spheres
    6. Putting It Together
  9. 6. Light and Shading
    1. Surface Normals
    2. Reflecting Vectors
    3. The Phong Reflection Model
    4. Putting It Together
  10. 7. Making a Scene
    1. Building a World
    2. Defining a View Transformation
    3. Implementing a Camera
    4. Putting It Together
  11. 8. Shadows
    1. Lighting in Shadows
    2. Testing for Shadows
    3. Rendering Shadows
    4. Putting It Together
  12. 9. Planes
    1. Refactoring Shapes
    2. Implementing a Plane
    3. Putting It Together
  13. 10. Patterns
    1. Making a Striped Pattern
    2. Transforming Patterns
    3. Generalizing Patterns
    4. Making a Gradient Pattern
    5. Making a Ring Pattern
    6. Making a 3D Checker Pattern
    7. Putting It Together
  14. 11. Reflection and Refraction
    1. Reflection
    2. Transparency and Refraction
    3. Fresnel Effect
    4. Putting It Together
  15. 12. Cubes
    1. Intersecting a Ray with a Cube
    2. Finding the Normal on a Cube
    3. Putting It Together
  16. 13. Cylinders
    1. Intersecting a Ray with a Cylinder
    2. Finding the Normal on a Cylinder
    3. Truncating Cylinders
    4. Capped Cylinders
    5. Cones
    6. Putting It Together
  17. 14. Groups
    1. Implementing Groups
    2. Finding the Normal on a Child Object
    3. Using Bounding Boxes to Optimize Large Scenes
    4. Putting It Together
  18. 15. Triangles
    1. Triangles
    2. Wavefront OBJ Files
    3. Smooth Triangles
    4. Smooth Triangles in OBJ Files
    5. Putting It Together
  19. 16. Constructive Solid Geometry (CSG)
    1. Implementing CSG
    2. Coloring CSG Shapes
    3. Putting It Together
  20. 17. Next Steps
    1. Area Lights and Soft Shadows
    2. Spotlights
    3. Focal Blur
    4. Motion Blur
    5. Anti-aliasing
    6. Texture Maps
    7. Normal Perturbation
    8. Torus Primitive
    9. Wrapping It Up
  21. A1. Rendering the Cover Image

Product information

  • Title: The Ray Tracer Challenge
  • Author(s): Jamis Buck
  • Release date: February 2019
  • Publisher(s): Pragmatic Bookshelf
  • ISBN: 9781680502718