Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×
Graphics Books Media Software Programming Book Reviews Hardware IT Technology

OpenGL Shading Language 96

Martin Ecker writes "A few months ago, the OpenGL Shading Language -- OpenGL's own high-level shading language for programming Graphics Processing Units (GPUs) -- was ratified by the Architectural Review Board (ARB) responsible for the development and extension of the OpenGL graphics API. The first real-world implementations are just becoming available in the latest graphics drivers of the big graphics hardware vendors. Now the first book that features this new shading language is available, with the intention of becoming the standard book on the subject. Randi J. Rost's OpenGL Shading Language (published by Addison-Wesley) is a good introduction to developing shaders with the new OpenGL Shading Language, and demonstrates a number of useful applications for real-time programmable shaders." Read on for the rest of Ecker's review.
OpenGL Shading Language
author Randi J. Rost
pages 608
publisher Addison-Wesley Publishing
rating 8/10
reviewer Martin Ecker
ISBN 0321197895
summary A solid introduction to developing shaders in the OpenGL Shading Language.

Because of its orange cover, the book is also called the "Orange Book," and together with its siblings, the classic "Red Book" (aka OpenGL Programming Guide) and the "Blue Book" (aka OpenGL Reference Manual (see this earlier review), it is a member of the OpenGL family of books from Addison-Wesley. Although it has a short overview of the basic features of OpenGL, it is intended for an audience that is already somewhat familiar with OpenGL and with 3D graphics programming in general. The interested reader should probably have read the "Red Book" or at least have a good understanding of how to use the OpenGL graphics API before attempting to tackle this book.

Rost, as well as the co-authors on some of the chapters, John M. Kessenich and Barthold Lichtenbelt, all employees of the graphics hardware vendor 3Dlabs, were driving forces behind the inception of the OpenGL Shading Language. They are also core contributors to the final language specification as well as the OpenGL extensions that provide the framework for this new shading language. So the information in the book actually comes from the people that created the language, which is a definite plus.

The book consists of 17 chapters and two appendices which can be roughly categorized into four major parts: An introduction to the basics of OpenGL and GPU programmability; a description of the OpenGL Shading Language and the associated OpenGL extensions; a number of chapters that show the shading language in action; and finally a reference section on the language grammar and the entry points introduced by the new OpenGL extensions. Each chapter of the book has numerous interesting references to get further information on the presented topics. I can only recommend taking a closer look at some of them.

The first two chapters of the book describe the basics of the OpenGL graphics API, followed by an overview of the new programmable processors in the graphics pipeline and an overview of the shading language used to program them. The introductory chapter on OpenGL basics is very well written and worth the read even for more experienced OpenGL programmers. However, as mentioned above, the reader should have enough expertise in using OpenGL to be able to understand the more advanced parts of the book. The introductory chapter won't be enough in my opinion.

The third chapter, written by John Kessenich - one of the main authors of the OpenGL shading language specification - presents the language definition. This chapter is where the basic data types as well as the available control structures are described in detail. For people interested in writing a compiler for the OpenGL Shading Language, Appendix A also contains the entire language grammar in BNF.

Chapter four moves on to describe the programmable graphics pipeline, which was first introduced in the second chapter, in more detail. The programmable vertex and fragment processors and their interaction with OpenGL's fixed functionality are presented. In chapter five, the description of the shading language concludes with the available built-in functions. Chapter six offers the first simple example that shows the shading language in action - a shader to procedurally create a brick texture.

Until this point, the book doesn't talk much about how to integrate shaders into the host program running on the CPU. New OpenGL extensions were created for this purpose, in particular GL_ARB_shader_objects, GL_ARB_vertex_shader, and GL_ARB_fragment_shader. Chapter seven contains detailed descriptions of the entry points provided by these new extensions. 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. Appendix B also has a reference section on the new entry points similar in style to the "Blue Book." 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 remaining chapters delve into the really interesting topic: shader development. These chapters offer multiple ideas on what can be done with shaders and how to effectively use them in graphics programming. Standard techniques, such as bump mapping, procedurally creating textures, using noise, and others, are presented. Chapter nine deserves special mention because it presents shaders that mimic the behavior of the OpenGL fixed-function pipeline. Many developers new to shader programming are faced with re-implementing certain features offered by OpenGL's fixed functionality. This chapter addresses this.

Chapter fourteen also deserves mention. Shaders that procedurally create textures usually suffer from aliasing artifacts. This chapter shows a number of anti-aliasing techniques to diminish these artifacts. In my opinion, this important topic has not received the attention it deserves -- it's good to see such a chapter in this book.

Closing this section of the book, chapters fifteen and sixteen describe some interesting non-photorealistic shaders and shaders for doing image processing. (For more ideas on what can be done with shaders I also recommend the book "GPU Gems", which I have read and reviewed some time ago.

The final chapter of the book (chapter seventeen) is a language comparison with other high-level shading languages such as the RenderMan Shading Language, SGI's Interactive Shading Language from the OpenGL Shader package, Microsoft's HLSL, and NVIDIA's Cg. Although I am quite familiar with most of these languages, I found this chapter to be an interesting read because it attempts to look at the languages objectively, listing advantages and disadvantages of the various approaches.

The book contains many diagrams and images, all in black and white, except for 16 pages containing 30 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.

There is also a website for the book where you can find an errata list and download a sample chapter (chapter six). As mentioned above, this chapter develops a simple brick shader to show the basic features of the shading language. The website also has all the shaders presented in the book available for download. Because the book does not come with a CD-ROM this is the only means of getting shaders code without having to type them. At the time of this review, the site appeared to be in a transitional state.

Rost's OpenGL Shading Language succeeds at giving a good introduction to shader programming with the OpenGL Shading Language. Not only does it provide the necessary technical instruction to allow the reader to write his/her own shaders as well as integrate them with the host program, it also demonstrates a number of practical applications for shaders and tries to encourage exploring the new dimension of real-time graphics programming opened up by the OpenGL Shading Language. Since there is no other book currently available on this topic, it is hard to say whether the "Orange Book" will stand the test of time and actually become the reference book on the OpenGL Shading Language, but I believe it will.


Ecker has been involved in real-time graphics programming for more than 9 years and works as a arcade game developer. He also works on a graphics-related open source project called XEngine. You can purchase OpenGL Shading Language from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, carefully read the book review guidelines, then visit the submission page.

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

OpenGL Shading Language

Comments Filter:
  • by saha ( 615847 ) on Thursday July 15, 2004 @05:27PM (#9711499)
    "The final chapter of the book (chapter seventeen) is a language comparison with other high-level shading languages such as the RenderMan Shading Language, SGI's Interactive Shading Language from the OpenGL Shader package, Microsoft's HLSL, and NVIDIA's Cg. ." Not to forget ATI's RenderMonkey.

    I spoke to a friend who is a developer for visualization applications. He feels that with Open GL 1.5 and some of the new ratified standards from the OpenGL ARB, OpenGL is back on par with Direct X 9.0.

    Anyone have other insights ?

  • Useful book (Score:5, Informative)

    by PixelSlut ( 620954 ) on Thursday July 15, 2004 @05:29PM (#9711521)
    I found the Orange Book to be a very good introduction to GLSL, and I think it'll make for a good reference as I develop stuff. It does a good job of explaining how GLSL fits into the entire GL pipeline, which is cool because I don't know of any other books on OpenGL shader development that do this (It was hard to write a book on GL shaders before, and while GLSL is still ARB extensions, it's pretty clear that it's really targeted towards the core, while ARBvp1/ARBfp1 really seemed to just be placeholders until something really robust--GLSL--could come along).
  • by MisterFancypants ( 615129 ) on Thursday July 15, 2004 @05:46PM (#9711654)
    In a way, I'd say it's more advanced thatn DirectX 9.0. At least in terms of shaders. GLSL allows you to design things to be more modular. You can write multiple shaders (multiple vertex shaders, multiple fragment shaders) and then link them together into a single program object.

    You can do that with DX9 too, using HLSL and the 'FX' effects file system.

    This is a very good step in the right direction, I think. Also, HLSL specifically compiles its code into a DirectX-specified shading assembly. Microsoft is controlling those, of course, so there's less room for innovation of compiler optimizations on the part of the hardware vendors.

    There is no reason why the vendors can't take the DX shader assembly code and reorder/optimize it for their card's strengths at the driver level. (NVidia and ATI both already do this).

  • by PixelSlut ( 620954 ) on Thursday July 15, 2004 @05:46PM (#9711659)
    Anyone know if Doom 3 uses these newly ratified extension? I would imagine it does - but I of course have no facts to back this up.
    I would not bet on it out of the box. I would probably bet against it. :)

    That said, I do remember JohnC saying at some point that he is committed to doing a codepath for this, so it's extremely likely that it will appear in a future patch. I am very excited to see how it performs.

  • by scratchor ( 31393 ) on Thursday July 15, 2004 @05:51PM (#9711702) Homepage
    "Not to forget ATI's RenderMonkey."

    RenderMonkey is not a language, but an IDE for several shading languages, such as HLSL, Cg and GLSL.
  • by sjf ( 3790 ) on Thursday July 15, 2004 @05:56PM (#9711748)
    http://www.opengl.org/documentation/oglsl.html

    Save youselves a bob or two.

    -S
  • by Anonymous Coward on Thursday July 15, 2004 @06:02PM (#9711783)
    Yes - if you have one of the newer cards that support it. Apple has been a very big supporter of OpenGL the last couple of years; they were even a little ahead of the standards committee on this one.

    Apple has a great tool called OpenGL Shader Builder that comes with the developer tools on Panther. I don't remember how long Shader Builder has been around but I know it has been at least a couple of years. It even existed before the standard shader language existed, for writing to NVidia and ATI's individual vendor-specific shader languages before there was a standard. Apple made Shader Builder extensible so they could just add the standard language as an additional shader language to the tool.

    Shader Builder is cool - you can edit your shader program directly as shader code mneumonics or whatever, run it and debug it interactively, and if I remember right it even generates the C code with the appropriate OpenGL calls to create and load the shader program for you. You just copy and paste right into your C file.

    I don't know of anything else like it on any other platform; there may be an equivalent tool on windows but I have never seen it.
  • by Have Blue ( 616 ) on Thursday July 15, 2004 @08:25PM (#9712707) Homepage
    Minor nit- REYES is not a "shading method" on the same level as rasterization/scanline or ray tracing. I believe it's a specific 3D graphics program. What you describe here is adaptive subdivision surfaces, which are a common high-end technique but not fundamentally different from simple polygon rasterization.
  • by Anonymous Coward on Thursday July 15, 2004 @08:58PM (#9712863)
    PRMan implements the REYES algorithm, based in buckets, micropolygons and other things you can learn by reading any of the book about it. Pixie also implements a REYES like method. BTW, REYES can be expanded as Renders Everything You Ever Saw.
  • by Anonymous Coward on Friday July 16, 2004 @01:57AM (#9714113)
    You should actually write this up in wikipedia [wikipedia.com]. It's quite a good write up on the subject.

    Thanks!
  • by ceoyoyo ( 59147 ) on Saturday July 17, 2004 @02:02AM (#9723589)
    Shader builder lets you write vertex and fragment programs and see the result on a quad, sphere or teapot. In Panther you can write in either the ATI vertex/fragment assembly or the ARB standard. In Tiger I believe you will be able to use the OpenGL Shader Language as well. It's handy for testing shaders and it can generate the OpenGL code for you as a XCode project.

Top Ten Things Overheard At The ANSI C Draft Committee Meetings: (5) All right, who's the wiseguy who stuck this trigraph stuff in here?

Working...