Skip to content
FREE SHIPPING ON ALL DOMESTIC ORDERS $35+
FREE SHIPPING ON ALL US ORDERS $35+

Computer Graphics from Scratch: A Programmer's Introduction to 3D Rendering

Availability:
Only 2 left!
Save 12% Save 12%
Original price $49.99
Original price $49.99 - Original price $49.99
Original price $49.99
Current price $43.99
$43.99 - $43.99
Current price $43.99
Computer Graphics from Scratch demystifies the algorithms used in modern graphics software and guides beginners through building photorealistic 3D renders.

Computer graphics programming books are often math-heavy and intimidating for newcomers. Not this one. Computer Graphics from Scratch takes a simpler approach by keeping the math to a minimum and focusing on only one aspect of computer graphics, 3D rendering.

You’ll build two complete, fully functional renderers: a raytracer, which simulates rays of light as they bounce off objects, and a rasterizer, which converts 3D models into 2D pixels. As you progress you’ll learn how to create realistic reflections and shadows, and how to render a scene from any point of view.

Pseudocode examples throughout make it easy to write your renderers in any language, and links to live JavaScript demos of each algorithm invite you to explore further on your own.
Learn how to:
  • Use perspective projection to draw 3D objects on a 2D plane
  • Simulate the way rays of light interact with surfaces
  • Add mirror-like reflections and cast shadows to objects
  • Render a scene from any camera position using clipping planes
  • Use flat, Gouraud, and Phong shading to mimic real surface lighting
  • Paint texture details onto basic shapes to create realistic-looking objects

  • Whether you’re an aspiring graphics engineer or a novice programmer curious about how graphics algorithms work, Gabriel Gambetta’s simple, clear explanations will quickly put computer graphics concepts and rendering techniques within your reach. All you need is basic coding knowledge and high school math. Computer Graphics from Scratch will cover the rest.

    ISBN-13: 9781718500761

    Media Type: Paperback

    Publisher: No Starch Press

    Publication Date: 05-13-2021

    Pages: 248

    Product Dimensions: 6.90(w) x 9.10(h) x 0.60(d)

    Gabriel Gambetta started coding games around the age of 5 on a ZX Spectrum. After studying Computer Science and working at a respectable local company in his native Uruguay, he started a game development company and ran it for 10 years while teaching Computer Graphics at his alma mater. More recently, Gambetta has been working at Google Zürich, where he's been since 2011 except for a stint as an early engineer in the London-based multiplayer game tech unicorn Improbable.

    Table of Contents

    Acknowledge xv

    Introduction xvii

    Who This Book Is For xviii

    What This Book Covers xviii

    Why Read This Book? xix

    About This Book xx

    About the Author xxi

    1 Introduction Concepts 1

    The Canvas 1

    Coordinate Systems 2

    Color Models 3

    Subtractive Color Model 4

    Additive Color Model 6

    Forget the Details 7

    Color Depth and Representation 7

    Color Manipulation 8

    The Scene 9

    Summary 10

    Part I Raytracing

    2 Basic Raytracing

    Rendering a Swiss Landscape 13

    Basic Assumptions 15

    Canvas to Viewport 17

    Tracing Rays 18

    The Ray Equation 19

    The Sphere Equation 19

    Ray Meets Sphere 20

    Rendering our First Spheres 22

    Summary 27

    3 Light

    Simplifying Assumptions 29

    Light Sources 30

    Point Lights 30

    Directional Lights 31

    Ambient Light 32

    Illumination of a Single Point 32

    Diffuse Reflection 33

    Modeling Diffuse Reflection 34

    The Diffuse Reflection Equation 36

    Sphere Normals 36

    Rendering with Diffuse Reflection 37

    Specular Reflection 39

    Modeling Specular Reflection 42

    The Specular Reflection Term 44

    The Full Illumination Equation 45

    Rendering with Specular Reflections 45

    Summary 48

    4 Shadows and Reflections 51

    Shadows 51

    Understanding Shadows 51

    Rendering with Shadows 54

    Reflections 57

    Mirrors and Reflection 57

    Rendering with Reflections 60

    Summary 62

    5 Extending the Raytracer

    Arbitrary Camera Positioning 65

    Performance Optimizations 67

    Parallelization 67

    Caching Immutable Values 68

    Shadow Optimizations 68

    Spatial Structures 69

    Subsampling 70

    Supporting Other Primitives 70

    Constructive Solid Geometry 71

    Transparency 73

    Refraction 74

    Supersampling 75

    Summary 75

    Part II Rasterization

    6 Lines 79

    Describing Lines 80

    Drawing Lines 81

    Drawing Lines with Any Slope 86

    The Linear Interpolation Function 87

    Summary 90

    7 Filled Triangles 91

    Drawing Wireframe Triangles 91

    Drawing Filled Triangles 92

    Summary 96

    8 Shaded Triangles 97

    Defining Our Problem 97

    Computing Edge Shading 98

    Computing Interior Shading 100

    Summary 102

    9 Perspective Projection 105

    Basic Assumptions 105

    Finding P' 106

    The Projection Equation 107

    Properties of the Projection Equation 108

    Projecting Our First 3D Object 109

    Summary 111

    10 Describing and Rendering a Scene 113

    Representing a Cube 113

    Models and Instances 117

    Model Transform 119

    Camera Transform 122

    The Transform Matrix 124

    Homogeneous Coordinates 126

    Homogeneous Rotation Matrix 127

    Homogeneous Scale Matrix 127

    Homogeneous Translation Matrix 127

    Homogeneous Projection Matrix 128

    Homogeneous Viewport-to-Canvas Matrix 129

    The Transform Matrix Revisited 129

    Summary 131

    11 Clipping 133

    An Overview of the Clipping Process 134

    The Clipping Volume 134

    Clipping the Scene Against a Plane 135

    Defining the Clipping Planes 138

    Clipping Whole Objects 139

    Clipping Triangles 142

    Segment-Plane Intersection 144

    Clipping Pseudocode 145

    Clipping in the Rendering Pipeline 147

    Summary 147

    12 Hidden Surface Removal 149

    Rendering Solid Objects 149

    Painter's Algorithm 150

    Depth Buffering 151

    Using 1/Z instead of Z 154

    Back Face Culling 157

    Classifying Triangles 159

    Summary 161

    13 Shading 163

    Shading vs. Illumination 163

    Flat Shading 164

    Gouraud Shading 165

    Phong Shading 169

    Summary 173

    14 Textures 175

    Painting a Crate 175

    Bilinear Filtering 181

    Mipmapping 183

    Trilinear Filtering 187

    Summary 187

    15 Extending the Rasterizer 189

    Normal Mapping 189

    Environment Mapping 192

    Shadows 193

    Stencil Shadows 193

    Shadow Mapping 199

    Summary 200

    Afterword 201

    Appendix: Linear Algebra 203

    Points 203

    Vectors 204

    Representing Vectors 204

    Vector Magnitude 205

    Point and Vector Operations 205

    Subtracting Points 205

    Adding a Point and a Vector 206

    Adding Vectors 207

    Multiplying a Vector by a Number 207

    Multiplying Vectors 208

    Matrices 210

    Matrix Operations 210

    Adding Matrices 211

    Multiplying a Matrix by a Number 211

    Multiplying Matrices 211

    Multiplying a Matrix and a Vector 212

    Index 213