The definitive reference and cookbook for the OpenGL Shading Language, the most exciting addition to OpenGL in years!
° Shading languages are the most important new development in graphics programming in years
° The author is at the very center of the activity surrounding the OpenGL Shading Language
° Both a tutorial and a reference, with lots of practical examples
Praise for OpenGL® Shading Language
“OpenGL® Shading Language provides a timely, thorough, and entertaining introduction to the only OpenGL ARB-approved high-level shading language in existence. Whether an expert or a novice, there are gems to be discovered throughout the book, and the reference pages will be your constant companion as you dig into the depths of the shading APIs. From algorithms to APIs, this book has you covered.”—Bob Kuehne
“Computer graphics and rendering technologies just took a giant leap forward with hardware vendors rapidly adopting the new OpenGL Shading Language. This book presents a detailed treatment of these exciting technologies in a way that is extremely helpful for visualization and game developers.”—Andy McGovern
“The OpenGL Shading Language is at the epicenter of the programmable graphics revolution, and Randi Rost has been at the center of the development of this significant new industry standard. If you need the inside track on how to use the OpenGL Shading Language to unleash new visual effects, and unlock the supercomputer hiding inside the new generation of graphics hardware, then this is the book for you.”—Neil Trevett
"The author has done an excellent job at setting the stage for shader development, what the purpose is, how to do it, and how it all fits together."
Strategic Software Program Manager, Intel Corporation
The OpenGL® Shading Language, a high-level procedural shading language for OpenGL®, is the most important new development in graphics programming to emerge in years. OpenGL is the leading cross-platform 3D-graphics API, and the OpenGL Shading Language allows developers to take total control over the most important stages of the graphics-processing pipeline.
OpenGL® Shading Language is the experienced application programmer's guide to writing shaders. Part reference, part tutorial, this book thoroughly explains the shift from fixed-functionality graphics hardware to the new era of programmable graphics hardware and the additions to the OpenGL API that support this programmability. With OpenGL and shaders written in the OpenGL Shading Language, applications can perform better, achieving stunning graphics effects by utilizing the capabilities of both the visual processing unit and the central processing unit.
In this book, you will find a detailed introduction to the OpenGL Shading Language and the new OpenGL function calls that support it. The text begins by describing the syntax and semantics of this high-level programming language. Once this foundation has been established, the book explores the creation and manipulation of shaders using new OpenGL function calls.
OpenGL® Shading Language features extensive examples of shaders and their underlying algorithms, including
The color plate section illustrates the power and sophistication of the OpenGL Shading Language. The API Function Reference at the end of the book is an excellent quick reference to the API entry points that support the OpenGL Shading Language. An enhanced online index allows readers to quickly and easily search the entire text for specific topics.
Download the Sample
Chapter related to this title.
About the Author.
About the Contributors.
1. Review of OpenGL Basics.
The Frame Buffer.
Frame Buffer Operations.
Rasterization and Back-End Processing.
Introduction to the OpenGL Shading Language.
Why Write Shaders?
OpenGL Programmable Processors.
Language Design Considerations.
Additions to C.
Additions from C++.
C Features Not Supported.
OpenGL Shading Language Compiler/Linker
OpenGL API Extensions.
Example Shader Pair.
Declarations and Scope.
Type Matching and Promotion.
Initializers and Constructors.
Qualifiers and Interface to a Shader.
The Vertex Processor.
Special Output Variables.
Built-in Varying Variables.
User-Defined Varying Variables.
The Fragment Processor.
Special Input Variables.
Special Output Variables.
Built-in Uniform Variables.
Interaction with OpenGL Fixed Functionality.
Two-Sided Color Mode.
Point Size Mode.
Angle and Trigonometry Functions.
Vector Relational Functions.
Texture Access Functions.
Fragment Processing Functions.
Brick Shader Overview.
Creating Shader Objects.
Compiling Shader Objects.
Linking and Using Shaders.
Specifying Vertex Attributes.
Specifying Uniform Variables.
Implementation-Dependent API Values.
Application Code for Brick Shaders.
Understand the Problem.
Add Complexity Progressively.
Test and Iterate.
Strive for Simplicity.
Consider Computational Frequency.
Analyze Your Algorithm.
Use the Built-in Functions.
Use Textures to Encode Complex Functions.
Review the Info Logs.
Use the Vertex Shader Output.
Use the Fragment Shader Output.
Use Simple Geometry.
Shader Development Tools.
OpenGL Shading Language Compiler Front End.
Material Properties and Lighting.
Texture Coordinate Generation.
Accessing Texture Maps from a Shader.
Simple Texturing Example.
Environment Mapping Example.
Polynomial Texture Mapping with BRDF Data.
Stripes vertex shader.
Stripes Fragment Shader.
Higher Dimensions of Noise.
Using Noise in OpenGL Shaders.
A Simple Noise Shader.
Sun Surface Shader.
Key-Frame Interpolation Vertex Shader.
Other Blending Effects.
Confetti Cannon Vertex Shader.
Confetti Cannon Fragment Shader.
Sources of Aliasing.
Antialiased Stripe Example.
Adaptive Analytic Prefiltering.
Antialiased Brick Fragment Shader.
Antialiased Checkerboard Fragment Shader.
Generating Hatching Strokes.
Obtaining Uniform Line Density.
Hatching Fragment Shader.
Technical Illustration Example.
About the Mandelbrot Set.
Geometric Image Transforms.
Lookup Table Operations.
Color Space Conversions.
Image Interpolation and Extrapolation.
Chronology of Shading Languages.
OpenGL Shader (ISL).
This book is an amazing measure of how far and how fast interactive shading has advanced. Not too many years ago, procedural shading was something done only in offline production rendering, creating some of the great results we all know from the movies, but were not anywhere close to interactive. Then a few research projects appeared, allowing a slightly modified but largely intact type of procedural shading to run in real-time. Finally, in a rush, widely accessible commercial systems started to support shading. Today, we've come to the point where a real-time shading language developed by a cross-vendor group of OpenGL participants has achieved official designation as an OpenGL Architecture Review Board approved extension. This book, written by one of those most responsible for spearheading the development and acceptance of the OpenGL shading language, is your guide to that language and the extensions to OpenGL that let you use it.
I came to my interest in procedural shading from a strange direction. In 1990, I started graduate school at the University of North Carolina in Chapel Hill because it seemed like a good place for someone whose primary interest was interactive 3D graphics. There, I started working on the Pixel-Planes project. This project had produced a new graphics machine with several interesting features beyond its performance at rendering large numbers of polygons per second. One feature in particular had an enormous impact on the research directions I've followed for the past 13 years. Pixel-Planes 5 had programmable pixel processors--lots of them. Programming these processors was similar in many ways to the assembly-language fragment programs that have burst onto the graphics scene in the past few years.
Programming them was exhilarating, yet also thoroughly exasperating.
I was far from the only person to notice both the power and pain of writing low-level code to execute per-pixel. Another group within the Pixel-Planes team built an assembler for shading code to make it a little easier to write, although it was still both difficult to write a good shader and ever-sorewarding once you had it working. The shaders produced will be familiar to anyone who has seen demos of any of the latest graphics products, and not surprisingly you'll find versions of many of them in this book: wood, clouds, brick, rock, reflective wavy water, and (of course) the Mandelbrot fractal set.
The rewards and difficulties presented by Pixel-Planes 5 shaders guided many of the design decisions behind the next machine, PixelFlow. PixelFlow was designed and built by a university/industry partnership with industrial participation first by Division, then by Hewlett-Packard. The result was the first interactive system capable of running procedural shaders compiled from a high-level shading language. PixelFlow was demonstrated at the SIGGRAPH conference in 1997. For a few years thereafter, if you were fortunate enough to be at UNC-Chapel Hill, you could write procedural shaders and run them in real-time when no one else could. And, of course, the only way to see them in action was to go there.
I left UNC for a shading project at SGI, with the hopes of providing a commercially supported shading language that could be used on more than just one machine at one site. Meanwhile, a shading language research project started up at Stanford, with some important results for shading on PC-level graphics hardware. PC graphics vendors across the board started to add low-level shading capabilities to their hardware. Soon, people everywhere could write shading code similar in many ways to that that had so inspired me on the Pixel Planes 5 machine. And, not surprisingly, soon people everywhere also knew that we were going to need a higher-level language for interactive shading.
Research continues into the use, improvement, and abuse of these languages at my lab at University of Maryland, Baltimore County; and at many, many others. However, the mere existence of real-time high-level shading languages is no longer the subject of that research. Interactive shading languages have moved from the research phase to wide availability. There are a number of options for anyone wanting to develop an application using the shading capabilities of modern graphics hardware. The principal choices are Cg, HLSL, and the OpenGL Shading Language. The last of which has the distinction of being the only one that has been through a rigorous multivendor review process. I participated in that process, as did over two dozen representatives from a dozen companies and universities.
This brings us back full circle to this book. If you are holding this book now, you are most likely interested in some of the same ideals that drove the creation of the OpenGL Shading Language, the desire for a cross-OS, crossplatform, robust and standardized shading language. You want to learn how to use all of that? Open up and start reading. Then get shading!
University of Maryland, Baltimore County, MD
Download the Index
file related to this title.