Posted
by
samzenpuson Friday November 13, 2009 @04:12PM
from the read-all-about-it dept.

Martin Ecker writes "The “OpenGL Shading Language” (also called the Orange Book because of its orange cover) is back in its third edition, with updated discussions of the OpenGL shading language (up to version 1.40, introduced with OpenGL 3.1). Like the previous edition, the third edition of the book is one of the best introductions to GLSL — the OpenGL Shading Language — that not only teaches the ins and outs of GLSL itself but also explains in-depth how to develop shaders in GLSL for lighting, shadows, animation, and other topics relevant to real-time computer graphics." Keep reading for the rest of Martin's review.

OpenGL Shading Language Third Edition

author

Randi J. Rost, Bill Licea-Kane

pages

458

publisher

Addison-Wesley Professional

rating

9/10

reviewer

Martin Ecker

ISBN

978-0-321-63763-5

summary

A solid introduction to developing shaders in the OpenGL Shading Language GLSL

Not unexpectedly the book starts out with a brief review of OpenGL basics. However, I would not recommend diving into this book without having prior experience with OpenGL, or at least with some other kind of 3D API, such as Direct3D. The book targets an audience that is already familiar with computer graphics and with OpenGL. Furthermore, knowledge of the C programming language is expected.

The next few chapters introduce the syntax and semantics of GLSL. At its core, GLSL is very similar to C. All the usual control flow statements, such as if statements and for loops, are available. However, the language adds some graphics-specific types, such as vectors and matrices. Even though this material is fairly dry, the writing is easy to follow and all concepts are presented with plenty of examples. Also uniform blocks — a new feature of GLSL version 1.40 — are discussed. Uniform blocks are used to efficiently send a block of variables via a uniform buffer to the GPU.

After familiarizing the reader with the language itself, chapter four delves into the integration of the shader-programmable units into the OpenGL pipeline, in particular the vertex and fragment shader units. Note that geometry shaders are not discussed in this book since they are a fairly recent addition to the OpenGL 3.2 specification. The next chapter goes over all the built-in, common functions that GLSL provides, such as sin, cos, abs, fract, and so on. Being more of a visual learner, what I really like about this chapter that the authors provide function graphs for each of the functions introduced. After all the basics of the shading language have been laid out in previous chapters, chapter six is dedicated to a full-fledged example that uses GLSL to procedurally render a brick pattern. If you're already familiar with other shading languages, such as Direct3D's HLSL or Cg, and you want to switch over to OpenGL/GLSL, I recommend jumping straight to this chapter to see how much you can grasp and then going back to the preceding pages to fill in the blanks if necessary.

The somewhat lengthy chapter seven contains detailed descriptions of the entry points provided by OpenGL to create and set up shader programs. Among other things, it describes how shader objects are created, compiled, and then linked to form shader programs that can then be used to render objects. Chapter seven concludes the dry, technical part of the book that introduced both the shading language and the necessary infrastructure to use it from a host program running on the CPU. The remainder of the book concentrates on numerous graphics techniques that can be achieved with shaders, such as bump mapping, lighting, shadows, animation, procedural effects, and many more. In short, it's the real fun part of the book where all the theory gets put into practice.

One of the highlights for me is the chapter on writing lighting shaders that discusses hemi-sphere lighting, image-based lighting using environment maps as light probes, and spherical harmonics lighting. The chapter on lighting is concluded by a discussion of the ÜberLight shader, a shader for a very versatile lighting model initially presented as RenderMan shader by Pixar Animation Studios.Where there's no light there's shadow and so the book has an interesting chapter on various shadowing techniques, in particular ambient occlusion, shadow maps, and an interesting technique for rendering shadow volumes using deferred shading. The latter technique can be used to render soft shadows convincingly.

The most interesting chapter for me in the book is the one on surface characteristics. It discusses and develops shaders to render surface materials that exhibit complex light interaction. The authors start out with a discussion of refraction and present shaders to achieve the classic Fresnel reflection/refraction and chromatic aberration effects. Then diffraction, i.e. light bending around sharp edges, is discussed and a shader that renders a vinyl record realistically is developed. Finally, the chapter focuses on BRDF-based lighting and develops various material shaders using the BRDF model, a quite important topic nowadays since more and more video games now actually use BRDF-based lighting models.

Another important chapter in the book in my opinion is chapter seventeen about antialiased procedural textures. I consider it important because it is often ignored that shaders that procedurally create textures usually suffer from aliasing artifacts. This chapter shows a number of anti-aliasing techniques to diminish these issues. Chapter eighteen is a fun chapter on non-photorealistic rendering, discussing hatching, Gooch shading, and how to render the Mandelbrot set in a shader. Finally, the book closes with a comparison of GLSL with other shading languages, in particular RenderMan, HLSL, and Cg. This is mostly of interest to real geeks and language lawyers ;)

As in the previous edition, all images and diagrams in the book are in black and white, except for a few pages that contain 34 color plates in the middle of the book. Most of the images are not overly "flashy" but do give a practical idea of the types of rendered images a particular shader can produce.

The book’s accompanying website offers the source code to all the shaders presented in the book for download. Also available are other shaders not mentioned in the book and a demo application including source code, which nicely demonstrates the shaders in action. Most of the shaders are available under a very liberal BSD-style open source license.

The third edition of "OpenGL Shading Language" is an excellent introduction to shader programming with GLSL. It provides an in-depth and comprehensive discussion of the shading language itself as well as the C shader API used to create and manage shaders in the host program. The best and largest part of the book focuses on developing shaders for various applications, such as lighting, shadows, animation, and other areas of real-time computer graphics. If you’re interested in learning GLSL and shader programming in OpenGL, this is the book to get.

Martin has been involved in real-time graphics programming for more than 10 years and works as a professional game developer for High Moon Studios in sunny California.

Something that keeps tripping me up with GL/SLANG is that it's close enough to C that I keep forgetting that it's not C. Fortunately, when I write SLANG code in Quartz Composer, the compilation happens instantaneously as I type, so I can't go too far wrong before I know there's a problem.

I'm learning GLSL right now and I would like to use it with Quartz Composer but I've never really worked with Quartz. Do you know of any tutorials related to using Quartz Composer that specifically deal with using GLSL?

Geometry Shaders are implemented as extensions and thus, are not part of the base language, which is what this book focuses on. you thought it was by accident that its not been part of the book all these years???

...which is exactly the same as the second edition. Almost. But not quite as painfully obvious a reprint as the OpenGL book that usually accompanies it (the Red Book). It just had some warnings that OpenGL 3 is, like, totally different, and saying that we are not going to bother with any of that, despite announcing that prominently on the cover of the book. Nothing on, for example, how to do transforms without all the old pipeline commands. Lots on, say, display lists, instead. Display lists that have been unofficially deprecated now for about a decade. Oh, well.

And for those not in the know, the Orange Book and the Red Book together form the unofficially official documentation for OpenGL.

Someone really needs to step up to produce quality documentation for the new lean and mean non-backward-compatible profile of OpenGL 3 if that is to make any headway. Or maybe that lets-make-the-API-even-more-low-level approach was wrong to begin with, and people are just afraid to say that out aloud like Mark Kilgard of NVIDIA recently did [slideshare.net] (see slide 35).

Anyway, if you are going to work with OpenGL, you need to read those two books. But you can just as well buy the previous edition.

Those slides just say that nVidia isn't going to remove or stop accelerating the deprecated bits of OpenGL any time soon because their customers are still using them. It also says that rewriting existing code not to use them is more effort than it's worth (for now), although for new code it's worth avoiding them. Not sure where you got the idea they he said the approach with OpenGL 3.x is wrong. Maybe he said more in person, but your claim is not backed up by the slides.

I'm a game designer, and not a game developer or graphics designer. But I think I'm a fairly good programmer. But I have trouble getting to that level that is a decade past display lists. What do you recommend for someone who learned OpenGL 1.2 back then, and wants to get up to a top notch experienced professional level in the fastest possible way (meaning with the highest compression of information that is at all possible)!

(I loathe those 600-800 page tomes where every 100 page chapter could be condensed t

If you do not have a passion for low-level graphics programming, I would strongly recommend using a higher level library like OpenSceneGraph or Ogre rather than programming directly at the nuts and bolts level of OpenGL. You get more done that way and leverage other people's experience instead of reinventing so many wheels yourself.

That's the thing: I have a passion for high-level physics programming. Meaning I would have my own non-graphics scene graph, and render out the actual scene from that one. But I don't want to put up with all that stupid special trickery. Like manually rendering shadows, instead of them being a natural result of lack of photon radiation. Or the "set of empty hulls" approach, instead of it being real materials with a volume. Etc.

All those standard packages exclusively use those things. And none of them seems

``I know there's OpenGL ES, and there's full-fledged OpenGL. Is there a practical common subset?''

Depends on which versions you're talking about. As this maemo.org page about OpenGL ES [maemo.org] nicely illustrates, there is some overlap, but nothing that works across all four of OpenGL 1.x, OpenGL 2.x, OpenGL ES 1.x and OpenGL ES 2.x.

The differences are in the supported shader models and in the support of fixed-point arithmetic.

OpenGL 1.x has floating point arithmetic and fixed shaders.OpenGL ES 1.x is sort of an ext

Don't learn OpenGL, learn graphics and software engineering first. Assuming you want to learn OpenGL for games, I would recommend David Eberly's 3D Game Engine Design [amazon.com] . It is extremely comprehensive and presents an incredibly well-designed engine, WildMagic (which has inspired many other engines, like jMonkey), for which you are given the full source on CD. If you're not looking for games, then you probably don't need to know the latest OpenGL stuff, because scientific visualization usually doesn't requ

I concur. This is very specialised programming, they are ownly a few teams in the
world making 3D game engines, once built, like the Unreal engine they
tend to sell the engine to other game companies to be used. So only
a very elite few progammers will every use OpenGL, unless you'll
hoping for a job at ID or Epic games, its probably not worth learning OpenGL.

OpenGL: A Primer by Edward Angel is very readable and a thin little book that is also inexpensive. I use in my class where I teach OpenGL. The Red Book and others are great references, but Angel is the best way to get your feet wet.

Don't:-) Well okay google a guide to GLUT (there are many out there), try and build something and make it more and more detailed. Once you reach a point of diminishing returns, and if you like it, you can browse for a book that'll take it to the next level.

JoGL is a quite a nice (Java) wrapper for OpenGL. Lets you do the windowing stuff in Java (nice n easy) and then the OpenGL calls translate almost exactly to their documented C equivalents described at: http://www.opengl.org/sdk/docs/ [opengl.org]

DirectX is good for games on the PC and XBox360. OpenGL is good for games (eg. IL2) and engineering on the PC, PS3, iPhone/iTouch, cellphones, military avionics, professional movie rendering, scientific visualization, Solaris/Unix etc. The only platform you can't develop for u