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