You are previewing Game Graphics Programming.
O'Reilly logo
Game Graphics Programming

Book Description

"Game Graphics Programming" examines the many different techniques and effects that are used to create cutting-edge graphics in today's video games and how to implement them. The book takes a detailed look at computer graphics, exploring both the theory and application of each algorithm and effect and how they are structured and executed to generate the rendered result. Detailed C++ source code and pseudocode are used as examples throughout the book to demonstrate the methods being taught, but the techniques presented can be used with any programming language or tool. You'll begin with an introduction to basic 2D and 3D game graphics tools and components including common game mathematics, colors and pixels, and computer memory, as well as ray tracing and rasterization techniques and programmable shaders. Once you've reviewed the foundations of game graphics, you'll go more in-depth with shading and surfaces, direct and global illumination, special effects, and rendering nature. After the how and why of each technique is presented, you'll also examine optimizations that can be done to improve performance and alternative methods. "Game Graphics Programming" presents you with all of the information you need to efficiently and effectively create eye-catching graphical scenes for video games.

Table of Contents

  1. Copyright
    1. Dedication
  2. Acknowledgments
  3. About the Author
  4. Introduction
    1. Overview to This Book
    2. What’s Different about This Book
    3. Who This Book Is For
    4. What You Will Need to Know for This Book
    5. How This Book Is Organized
    6. Source Code for This Book
    7. Errata
  5. 1. Introduction to Game Graphics
    1. 1. Introduction to Game Graphics
      1. Computer Graphics in Media
      2. Computer Graphics in Print
        1. Graphics in Movies and TV
      3. Computer Graphics in Video Games
        1. 2D Graphics
        2. 3D Graphics
        3. Rasterization and the Rendering Pipeline
        4. XNA
      4. About this Book
      5. Purpose of this Book
        1. Prerequisites and Prior Knowledge
        2. Tools Used in this Book
      6. Summary
      7. Chapter Questions
    2. 2. 2D and 3D Graphics
      1. Bits and Bytes
        1. Memory Bits
        2. Memory Bytes
        3. Hexadecimal Values
      2. Color Ranges
        1. Low-Dynamic-Range Colors
        2. High-Dynamic-Range Colors
        3. Additional Color Information
      3. 2D Graphics
        1. Sprites
        2. Tiled Images and Backgrounds
      4. 3D Graphics
        1. The Z Buffer
        2. Shading Surfaces
      5. Geometry and Primitives
        1. Lines
        2. Polygons
        3. Triangles
        4. Convex and Concave Polygons
        5. Spheres and Boxes
        6. Additional Geometric Objects
        7. Loading Geometry
      6. Mathematics Used in Computer Graphics
        1. Vectors, Vertices, and Points
        2. Transformations
        3. Matrices
        4. Rays
        5. Planes
          1. Line and Triangle Intersection
          2. Additional Primitive Intersections
        6. Frustums
        7. Occlusions
        8. Quaternion Rotations
          1. Rotations with Quaternions
          2. Interpolation with Quaternions
      7. Summary
      8. Chapter Questions
      9. Chapter Exercises
    3. 3. Ray Tracing
      1. Ray Tracing in Computer Graphics
        1. Forward Ray Tracing
        2. Backward Ray Tracing
      2. Tracing Primitives
        1. Tracing Spheres
        2. Tracing Planes
        3. Tracing Triangles
        4. Tracing Additional Primitives
      3. Implementing Ray Tracing
        1. Mathematics for Ray Tracing
        2. Data Structures for Ray Tracing
        3. The Ray Tracer
        4. Tracing Rays
        5. Storing Rendering Results to External Files
        6. The Ray Tracer’s Main Source File
      4. Real-Time Ray Tracing
        1. Ray Tracing on Multi-Core Processors
        2. Rendering Farms
        3. Ray Tracing on the GPU
        4. Ray Tracing Hardware
        5. Additional Ray Tracing Topics
      5. Summary
      6. Chapter Questions
      7. Chapter Exercises
    4. 4. Rasterization
      1. Software Rendering
        1. CPU Software Rendering
      2. Rasterizing Primitives
        1. Clipping
        2. Scan-Line Conversion
        3. Creating, Clearing, and Displaying the Canvas
        4. Drawing Pixels
        5. Drawing Lines
        6. Drawing Polygons
      3. Rendering Buffers
        1. Secondary Buffers
        2. The Depth Buffer
        3. Tertiary Buffers
        4. Stencil Buffers
      4. Additional Rasterization Topics
        1. Transformation and Spaces
        2. Back-Face Culling
      5. OpenGL
      6. Direct3D 9 and 10
        1. Direct3D9 Demo
        2. Direct3D 10
      7. Summary
      8. Chapter Questions
      9. Chapter Exercises
    5. 5. Programmable Shaders
      1. Shaders in Computer Graphics
        1. Types of Shaders
      2. Low-Level Shaders
        1. Working with Low-Level Shaders
      3. High-Level Shaders
      4. OpenGL’s GLSL
        1. Overview to GLSL
        2. Setting up and Using GLSL
        3. GLSL Example Shader
      5. Direct3D’s HLSL
        1. Semantics
        2. Shaders, Techniques, and Passes
        3. Setting Up and Using HLSL
        4. HLSL Example Shader
      6. Additional Shader Technologies and Tools
        1. NVIDIA’s Cg
        2. Pixar’s RenderMan
      7. Summary
      8. Chapter Questions
  6. 2. Shading and Surfaces
    1. 6. Mapping Surfaces
      1. Texture Mapping in Games
        1. Color Formats
      2. Images
        1. Image Compression
        2. Working with TGA Images
        3. Working with DDS Images
      3. Texture Mapping in Graphics APIs
        1. Texture Coordinates
        2. Texture Filtering and Mipmaps
        3. OpenGL Texture Mapping in Shaders
        4. Direct3D 9 Texture Mapping in Shaders
        5. Direct3D 10 Texture Mapping in Shaders
      4. Texture Compression
        1. Color Map Compression
        2. DXTC Normal Map Compression
        3. 3Dc Compression
        4. A8L8 Format
        5. Using DDS Compressed Textures in Shaders
      5. Summary
      6. Chapter Questions
      7. Chapter Exercises
    2. 7. Additional Surface Mapping
      1. Alpha Mapping
        1. Implementing Alpha Maps in OpenGL
        2. Implementing Alpha Maps in Direct3D
      2. Cube Mapping
        1. Implementing Cube Mapping in OpenGL
        2. Implementing Cube Mapping in Direct3D
      3. Reflections
        1. Implementing Reflection Mapping in OpenGL
        2. Implementing Reflection Mapping in Direct3D
      4. Refractions
        1. Implementing Refraction Mapping in OpenGL
      5. Render Targets
        1. OpenGL Frame Buffer Objects
        2. Direct3D 9 Render Targets
        3. Direct3D 10 Render Targets
      6. Image Filters
        1. Luminance Filter
        2. Sepia Filter
      7. Additional Texture Mapping Techniques
        1. Billboards
        2. Super Sampling
        3. Dynamic Cube Mapping
      8. Summary
      9. Chapter Questions
      10. Chapter Exercises
  7. 3. Direct and Global Illumination
    1. 8. Lighting and Materials
      1. Lighting Overview
        1. Lighting in Computer Graphics
        2. Types of Light Sources
        3. Per-Vertex and Per-Pixel Lighting
        4. Light Models
        5. Lighting Terms
      2. Materials
      3. Implementing Lighting
        1. Lambert Diffuse
        2. Phong
        3. Blinn-Phong
      4. Extensions to Per-Pixel Lighting
        1. Bump Mapping
        2. Creating Bump Map Textures
        3. Implementing Bump Mapping
        4. Normal Mapping
        5. Parallax Mapping
      5. Additional Lighting Techniques
        1. Point Lights
        2. Bloom
        3. Lens Flare
        4. Light Shafts
      6. Summary
      7. Chapter Questions
      8. Chapter Exercises
    2. 9. Advanced Lighting and Shadows
      1. Shadows in Games
        1. Real-Time Versus Preprocessed Shadows
        2. Popular Types of Shadows
        3. Shadow Imposters
      2. Projection Shadows
        1. Rendering Projected Shadows
        2. The Shadow Matrix
      3. Shadow Volumes
        1. Finding the Silhouette Edges
        2. Rendering the Shadow Volume
      4. Shadow Mapping
        1. Rendering with the Shadow Map
      5. Soft Shadows
      6. Light Mapping
        1. Calculating Light Map Coordinates
        2. Calculating Lumels of a Light Map
      7. Deferred Shading
        1. Creating the G-Buffer for Deferred Shading
        2. Rendering with the G-buffer
      8. Summary
      9. Chapter Questions
      10. Chapter Exercises
    3. 10. Global Illumination Techniques
      1. Overview of Global Illumination
        1. Direct Lighting versus Indirect Lighting
      2. Ambient Occlusion
        1. Alternative Method for Calculating Ambient Occlusion
        2. Bent Normal
        3. Implementing Ambient Occlusion
        4. SSAO
      3. Path Tracing
        1. Extending the Ray Tracing Algorithm
      4. Radiosity
        1. Calculating Radiosity
        2. Form Factors
        3. Implementing Radiosity
      5. Photon Mapping
        1. The kd-Tree
        2. Calculating Photon Maps
        3. Applying Photon Maps to a Ray-Traced Scene
      6. Precomputed Radiance Transfer
        1. Overview of Spherical Harmonics
        2. Calculating Spherical Harmonics Data
        3. Spherical Harmonics Un-Shadowed
        4. Spherical Harmonics Shadowed
        5. Spherical Harmonics Inter-Reflected
      7. Summary
      8. Chapter Questions
      9. Chapter Exercises
  8. 4. Special Effects
    1. 11. Special Effects: High Dynamic Range
      1. Overview of HDR
        1. What Is HDR?
      2. Implementing HDR
        1. Creating Floating-Point Buffers and Rendering HDR Data
        2. Tone Mapping
      3. HDR Special Effects and Additional Topics
        1. Bloom
        2. Streaks
        3. Dynamic Tone Mapping
      4. Summary
      5. Chapter Questions
      6. Chapter Exercises
    2. 12. Special Effects: Additional Effects
      1. Blurring
      2. Depth of Field
        1. Depth-Based Blurring
      3. Motion Blur
        1. Fast Motion Blur
        2. Geometry-Based Motion Blur
        3. Pixel-Based Motion Blur
      4. Particle Systems
        1. Point Masses
        2. Billboards and Point Sprites
        3. Sparks
        4. Fire
        5. Smoke
        6. Additional Particle Effects
        7. Particle System Demo
      5. Additional Effects
        1. Weapon Effects
        2. Dynamic Decals on Surfaces
      6. Summary
      7. Chapter Questions
      8. Chapter Exercises
  9. 5. Rendering Nature
    1. 13. Sky and Terrain Rendering
      1. Sky Rendering
        1. Sky Planes
        2. Sky Boxes
        3. Sky Domes
        4. Clouds
      2. Terrains
        1. Brute Force Rendering Terrains
        2. Height Map Terrains
        3. Terrain Generation
        4. Terrain Box Filtering
        5. Texturing Terrains
        6. Terrain Patches
      3. Additional Topics
      4. Terrain Demo
      5. Summary
      6. Chapter Questions
      7. Chapter Exercises
    2. 14. Water Rendering
      1. Examining Water in Modern Games
        1. Goldeneye 007: Nintendo 64
        2. Perfect Dark: Nintendo 64
        3. Dragonball Z Budokai Tenkaichi 2: Nintendo Wii
        4. Half-Life 2 Lost Coast: PC
        5. Crysis: PC
        6. BioShock: PC and Xbox 360
      2. Additional Water Effects
        1. Optimizations
        2. Underwater Rendering
        3. Audio Underwater
        4. Water Splashes and Interaction
        5. Water Particle Systems
        6. Water Physics
        7. Shorelines
      3. Water Rendering Demo
      4. Summary
      5. Chapter Questions
      6. Chapter Exercises
  10. 6. Optimizations and Conclusions
    1. 15. Optimization
      1. Culling Geometry
      2. Far Plane Culling
        1. Back-Face Culling
        2. Frustum Culling
        3. Occlusion Culling
      3. Scene and Space Partitioning
        1. BSP Trees
        2. Potential Visibility Sets
        3. Octrees
        4. Portals and Sectors
        5. Continuous Level-of-Detail
        6. Additional Scene Partitioning Techniques
      4. Geometry Instancing
      5. Additional Optimization Techniques
        1. Dynamic Branching
        2. State Management
      6. Summary
      7. Chapter Questions
      8. Chapter Exercises
    2. 16. Conclusions
      1. A Look Behind
        1. Game Mathematics
        2. Ray Tracing
        3. Rasterization
        4. Advancements in Lights and Shadows
        5. Rendering People and Nature Realistically
      2. A Look Forward
        1. Data Structures and Algorithms
        2. Game Engine Design and Architecture
      3. Final Thoughts
  11. A. Answers to Chapter Questions
    1. Chapter 1 Answers
    2. Chapter 2 Answers
    3. Chapter 3 Answers
    4. Chapter 4 Answers
    5. Chapter 5 Answers
    6. Chapter 6 Answers
    7. Chapter 7 Answers
    8. Chapter 8 Answers
    9. Chapter 9 Answers
    10. Chapter 10 Answers
    11. Chapter 11 Answers
    12. Chapter 12 Answers
    13. Chapter 13 Answers
    14. Chapter 14 Answers
    15. Chapter 15 Answers
  12. B. Compiling the Sample Source Code
    1. Compiling on Win32
    2. Compiling on Mac
    3. Compiling on Linux
  13. C. Recommended Resources
    1. Recommended Tools
    2. Recommended Books
    3. Recommended Web Sites
  14. D. OBJ Loader
    1. The File Format
    2. Loading Tokens
    3. Loading the OBJ File
    4. Generating Tangents