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

xii
Contents
Fragment Shader Processing 163
Outputs from Fragment Shaders 163
Replacing Fixed-Function Processing with Fragment Shaders 163
Shading 164
Traditional Texture Mapping 165
False Coloring 166
What Follows a Fragment Shader? 168
Additional Shader Effects 169
Discarding Pixels 169
Phong Shading 169
Shading with Analytic Normals 170
Anisotropic Shading 172
Data-Driven Coloring 173
Images Using Other Data 175
Exercises 177
9. Surface Textures in the Fragment Shader 179
Texture Coordinates 180
Traditional Texture Mapping 180
GLSL Texture Mapping 182
The Texture Context 184
Texture Environments in the Fixed-Function World 185
Texture Sampling Parameters 186
Samplers 186
Procedural Textures 187
Bump Mapping 193
Cube Maps 200
Render to Texture 205
Render to Texture for Multipass Rendering in glman 209
Exercises 212
xiii
Contents
Contents
10. Noise 213
Fundamental Noise Concepts 214
Three Types of Noise: Value, Gradient, and Value+Gradient 214
Cubic and Quintic Interpolation 215
Noise Equations 216
Other Noise Concepts 220
Fractional Brownian Motion (FBM, 1/f, Octaves) 220
Noise in Two and Three Dimensions 221
Using Noise with glman 223
Using Noise with the Built-In GLSL Functions 225
Turbulence 225
Some Examples of Noise in Different Environments 228
Marble Shader 230
Cloud Shader 231
Wood Shader 233
Advanced Noise Topics 235
Using Noisegraph 235
Exercises 237
11. Image Manipulation with Shaders 239
Basic Concepts 240
Single-Image Manipulation 241
Luminance 241
CMYK Conversions 243
Hue Shifting 246
Image Filtering 248
Image Blurring 249
Chromakey Images 251
Stereo Anaglyphs 252
3D TV 256
Edge Detection 259
Embossing 260
xiv
Contents
Toon Shader 262
Artistic Effects 264
Image Flipping, Rotation, and Warping 265
The Image Blending Process 270
Blending an Image with a Constant Base Image 271
Color Negative 272
Brightness 273
Contrast 274
Blending an Image with a Version of Itself 275
Saturation 275
Sharpness 276
Blending Two Different Images 277
Other Combinations 278
Image Transitions 281
Notes 286
Exercises 287
12. Geometry Shader Concepts and Examples 291
What Does the Geometry Shader Do? 292
New Adjacency Primitives 294
Layouts for Input and Output Variables 295
New OpenGL API Functions 296
New GLSL Variables and Variable Types 299
Communication between a Vertex or Tessellation Shader
and a Geometry Shader 299
Normals in Geometry Shaders 301
Examples 301
Bézier Curves 301
Shrinking Triangles 303
Sphere Subdivision 305
3D Object Silhouettes 309
Exercises 312
xv
Contents
Contents
13. Tessellation Shaders 315
What Are Tessellation Shaders? 315
Tessellation Shaders or Geometry Shaders? 317
Tessellation Shader Concepts 318
Issues in Setting Tessellation Levels 323
Examples 323
Isolines 324
Bézier Surface 327
Sphere Subdivision 334
Whole Sphere Subdivision while Adapting to Screen Coverage 341
PN Triangles 344
Summary 350
Exercises 351
14. The GLSL API 353
Shaders in the OpenGL Programming Process 353
Handling OpenGL Extensions 355
How Is a GLSL Shader Program Created? 355
Creating and Compiling Shader Objects 357
The CheckGLErrors Function 359
Creating, Attaching, Linking, and Activating Shader Programs 360
Creating a Shader Program and Attaching Shader Objects 361
Linking Shader Programs 361
Activating a Shader Program 362
Passing Data into Shaders 364
Defining Uniform Variables in Your Application 364
Uniform Variables in Compatibility Mode 367
Defining Attribute Variables in Your Application 368
Attribute Variables in Compatibility Mode 370
A C++ Class to Handle Shader Program Creation 371
Exercises 372
xvi
Contents
15. Using Shaders for Scientific Visualization 375
Image-Based Visualization Techniques 376
Image Negative 376
Image Edge Detection 377
Toon Rendering 377
Hyperbolic Geometry 378
3D Scalar Data Visualization 381
Point Clouds 383
Cutting Planes 387
Volume Probe 390
Direct Volume Rendering 392
More on Transfer Functions 398
Passing in Data Values with Your Geometry 403
Terrain Bump-Mapping 405
Flow Visualization 408
2D Line Integral Convolution 408
3D Line Integral Convolution 411
Extruding Objects for Streamlines 413
Geometry Visualization 416
Silhouettes 416
Hedgehog Plots 417
Exercises 420
16. Serious Fun 425
Light Interference 426
Diffraction Gratings 427
Oil Slicks 431
Lens Effects 433

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