Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
Image

OpenGL Shading Language 3rd Edition 46

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.

You can purchase OpenGL Shading Language 3rd ed. from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

*

This discussion has been archived. No new comments can be posted.

OpenGL Shading Language 3rd Edition

Comments Filter:
  • Comment removed (Score:4, Interesting)

    by account_deleted ( 4530225 ) on Friday November 13, 2009 @03:14PM (#30091176)
    Comment removed based on user account deletion
    • I personally prefer using NVidia's CgFX framework. It combines the syntax of GLSL and the awesome Effects framework from DirectX. It's merely a personal preference.

    • by ScoLgo ( 458010 )

      "Power is like uranium: let too much of it accumulate in once place, and Bad Things Happen."

      Sorry to reply to a .sig but... I first read that as "Power is like urine :..."

      Hmmm... I guess that doesn't really negate the statement tho, does it... ;-]

    • 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?
  • I'll pass (Score:3, Informative)

    by WilyCoder ( 736280 ) on Friday November 13, 2009 @03:29PM (#30091358)

    Almost the end of 2009 and no geometry shaders in this book?

    I'll pass...

    • Re: (Score:2, Informative)

      by Mastadex ( 576985 )

      You can always pick up a book that deals with OpenGL extensions. The GL_NV_gpu_program4 shading extension is just one of the geometry extensions you can use.

    • Re: (Score:3, Interesting)

      by GenP ( 686381 )
      Almost at the end of 2009 and no viable OpenGL 3.2 reference implementation...
    • Re: (Score:1, Informative)

      by Anonymous Coward

      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???

  • by Anonymous Coward

    We hear Rubyists and Lispers trumpet on about "domain specific languages" a lot. DSLs, they call them. Their so-called "languages" are nothing more than function or class libraries.

    This, on the other hand, is an actual domain specific language.

  • by perrin ( 891 ) on Friday November 13, 2009 @03:40PM (#30091506)

    ...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.
    • Re: (Score:3, Interesting)

      by Hurricane78 ( 562437 )

      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

      • by perrin ( 891 ) on Friday November 13, 2009 @07:03PM (#30093444)

        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

  • by AP31R0N ( 723649 ) on Friday November 13, 2009 @03:58PM (#30091710)

    The grappling rules in 3rd Edition are bitch.

  • ...and I wanna use OpenGL. I know there's OpenGL ES, and there's full-fledged OpenGL. Is there a practical common subset? Are there techniques that scale?
    • Re: (Score:3, Informative)

      by RAMMS+EIN ( 578166 )

      ``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

  • New to open GL (Score:3, Interesting)

    by BlowHole666 ( 1152399 ) on Friday November 13, 2009 @04:54PM (#30092352)
    I am new to any open GL or Direct X for that matter. Lets say I wanted to learn open GL, the latest version from the ground up, what would you guys recommend?
    • 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.

        ---

        3D Graphics [feeddistiller.com] Feed @ Feed Distiller [feeddistiller.com]

    • Re: (Score:2, Informative)

      by vlakkies ( 107642 )

      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.
    • Re: (Score:3, Informative)

      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

  • I meanwhile haven't read the book yet but am sure it lives up meanwhile to the review considering previous title produced meanwhile by the same publisher.

If all the world's economists were laid end to end, we wouldn't reach a conclusion. -- William Baumol

Working...