O'Reilly logo

Graphics Shaders, 2nd Edition by Steve Cunningham, Mike Bailey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

vii
Foreword xix
Preface xxiii
1. The Fixed-Function Graphics Pipeline 1
The Traditional View 2
The Vertex Operation 2
The Fragment Processing Part of the Pipeline 6
State in the Graphics Pipeline 7
Contents
viii
Contents
How the Traditional View Is Implemented 8
Vertex Processing 9
Rendering Processing 10
Homogeneous Coordinates in the Fixed-Function Pipeline 14
Vertex Arrays 17
Conclusions 20
Exercises 21
2. OpenGL Shader Evolution 25
History of Shaders 27
OpenGL Shader History 30
OpenGL 2.0/GLSL 1.10 30
OpenGL 3.x/GLSL 3.30 31
OpenGL 4.0/GLSL 4.00 32
OpenGL 4.x/GLSL 4.x0 33
What’s Behind These Developments? 34
OpenGL ES 34
How Can You Respond to These Changes? 35
Our Approach in this Book 36
Variable Name Convention 36
Exercises 37
3. Fundamental Shader Concepts 39
Shaders in the Graphics Pipeline 39
Vertex Shaders 42
Fragment Shaders 47
Tessellation Shaders 50
Geometry Shaders 53
ix
Contents
The GLSL Shading Language 54
Passing Data from Your Application into Shaders 59
Defining Attribute Variables in Your Application 59
Defining Uniform Variables in Your Application 62
A Convenient Way to Transition to the Newer Versions of GLSL 64
Exercises 67
4. Using glman 69
Using glman 71
Loading a GLIB File 72
Editing GLIB and Shader Source Files 72
GLIB Scene Creation 72
Window and Viewing 73
Transformations 73
Defining Geometry 73
Specifying Textures 76
Specifying Shaders 77
Miscellaneous 78
Specifying Uniform Variables 79
Examples of GLIB Files 81
More on Textures and Noise 82
Using Textures 82
Using Noise 84
Functions in the glman Interface Window 86
Generating and Displaying a Hardcopy of Your Scene 86
Global Scene Transformation 86
Eye Transformation 87
Object Picking and Transformation 87
Texture Transformation 88
Monitoring the Frame Rate 88
Miscellaneous 89
Exercises 90
x
Contents
5. The GLSL Shader Language 91
Factors that Shape Shader Languages 92
Graphics Card Capabilities 93
General GLSL Language Concepts 95
Shared Namespace 95
Extended Function and Operator Capabilities 96
New Functions 97
New Variable Types 97
New Function Parameter Types 98
Language Details 98
Omitted Language Features 98
New Matrix and Vector Types 99
Name Sets 100
Vector Constructors 101
Functions Extended to Matrices and Vectors 102
Operations Extended to Matrices and Vectors 105
New Functions 106
Swizzle 112
New Function Parameter Types 112
Const 113
Compatibility Mode 114
Defining Compatibility Mode 114
OpenGL 2.1 Built-in Data Types 114
Summary 120
Exercises 120
6. Lighting 123
The ADS Lighting Model 124
The ADS Lighting Model Function 125
Types of Lights 127
Positional Lights 128
Directional Lights 128
Spot Lights 129
xi
Contents
Contents
Setting Up Lighting for Shading 131
Flat Shading 132
Smooth (Gouraud) Shading 133
Phong Shading 134
Anisotropic Shading 135
Exercises 137
7. Vertex Shaders 139
Vertex Shaders in the Graphics Pipeline 140
Input to Vertex Shaders 140
Output from Vertex Shaders 142
Fixed-Function Processing After the Vertex Shader 145
The Relation of Vertex Shaders to Tessellation Shaders 146
The Relation of Vertex Shaders to Geometry Shaders 146
Replacing Fixed-Function Graphics with Vertex Shaders 146
Standard Vertex Processing 147
Going Beyond the Fixed-Function Pipeline with Vertex Shaders 148
Vertex Modification 148
Issues in Vertex Shaders 151
Creating Normals 152
Summary 153
Exercises 154
8. Fragment Shaders and Surface Appearance 157
Basic Function of a Fragment Shader 158
Inputs to Fragment Shaders 158
Particularly Important “In” Variables for the Fragment Shader 161
Coordinate Systems 162

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required