Computer Graphics from Scratch Cover

Computer Graphics from Scratch

A Programmer's Introduction to 3D Rendering
by Gabriel Gambetta
April 2021, 248 pp.

Look Inside!

Computer Graphics ScratchComputer Graphics from Scratch pg 67Computer Graphics from Scratch pg 143Computer Graphics from Scratch page 166Computer Graphics from Scratch page 177 Computer Graphics from Scratch Image

Download Chapter 3: LIGHT

Computer graphics are at work everywhere today, adding eye-popping details to video games, hyper-realistic CGI to major blockbusters, and life-like imagery to computer-animated films. This beginners book will introduce you to a core slice of this ever-expanding field, 3D rendering, with a focus on two popular algorithmic methods: raytracing and rasterization.

Written to be easily understood by high-school students but rigorous enough for professional engineers, you’ll build each of these surprisingly simple algorithms into complete, fully functional renderers as you build your knowledge base. The first half covers raytracing, which simulates rays of light as they bounce off of objects in a scene; the second half breaks down rasterization, the real-time process for converting 3D graphics into a screen-compatible array of 2D pixels. Every chapter gives you something visually new and exciting to add to your works-in-progress, from creating reflections and shadows that make objects look more realistic, to rendering a scene from any directional point of view.

You’ll learn how to:

  • Represent objects in a scene, and use perspective projection to draw them in
  • Compute the illumination for light sources (point, directional, and ambient)
  • Render mirror-like reflections on surfaces, and cast shadows for depth
  • Use clipping algorithms to render a scene from any camera position
  • Implement flat shading, Gouraud shading, and Phong shading algorithms
  • "Paint” textures that fake surface details and turn shapes into everyday objects

The book uses informal pseudocode throughout the text, so you can write your renderers in any language. In addition, the author provides links to live working versions of his algorithms.

Author Bio 

Gabriel Gambetta has been coding games since the age of 5 on a ZX Spectrum. After studying CS and starting his career as a company man, he gave it all up to start a game development company, where he worked for over a decade while teaching Computer Graphics at a local university. Most recently, Gambetta has worked at Google in Zürich since 2011, except for a stint as an early engineer in London-based multiplayer game tech unicorn Improbable.

Table of contents 

Chapter 1: Introductory Concepts
Chapter 2: Basic Raytracing
Chapter 3: Light
Chapter 4: Shadows and Reflections
Chapter 5: Extending the Raytracer
Chapter 6: Lines
Chapter 7: Filled Triangles
Chapter 8: Shaded Triangles
Chapter 9: Perspective Projection
Chapter 10: Describing and Rendering a Scene
Chapter 11: Clipping
Chapter 12: Hidden Surface Removal
Chapter 13: Shading
Chapter 14: Textures
Chapter 15: Extending the Rasterizer

View the detailed Table of Contents
View the Index


"If you've ever wanted to peek behind the curtain and understand how [computer graphics] work, here you've got it in a step-by-step process. . . . A nice resource to have to learn about the basics of computer graphics. . . . If you want to jump in and learn about computer graphics or get an understanding of how ray tracing works, this is a good choice."
Game From Scratch

"There's enough information in his book for a university course. In fact, the book is based on the course Gambetta taught before he became a senior engineer at Google."
—Joy Schwabach, Arkansas Democrat Gazette's On Computers

"One of the best textbooks I have ever seen! . . . I am in awe of the simplicity of the math and science involved. It feels a lot like I am wielding magical powers that I've always thought were beyond my reach. [Gabriel Gambetta has] absolutely managed to demystify the process. I guess it's a sort of 'the power was within you the whole time' kind of moment."
/u/Grakkam, Reddit

Book announcement featured in GameDev Digest and GamaSutra


Page 210: in the batch of three equations in the top half of the page, the second equation that currently reads:
Ry = Vx・Wz – Vz・ Wx

Should now read:

Ry = Vz・Wx – Vx・Wz