The Cg Tutorial 111
The Cg Tutorial: The Definitive Guide to Programmable Real-Time Graphics | |
author | Randima Fernando, Mark J. Kilgard |
pages | 384 |
publisher | Addison-Wesley Publishing |
rating | 8 |
reviewer | Martin Ecker |
ISBN | 0321194969 |
summary | An excellent introduction to the high-level shading language Cg (C for Graphics) and its uses in real-time 3D graphics. |
The first half of the book teaches the basic language constructs of the Cg shading language and shows how to use them in concrete example shaders, whereas the second half concentrates on more advanced techniques that can be achieved on today's programmable GPUs with Cg, such as environment or bump mapping. Even these more advanced techniques are explained in a clear and easy-to-understand manner, but the authors do not neglect to present the mathematics behind the techniques in detail. Especially the more serious 3D programmer will appreciate this fact. The explanation of texture space bump mapping must be the easiest-to-understand explanation of the technique I have read to date, which alone makes it worth to have this book on my shelf. At this point it is important to note that the book does not discuss the Cg runtime which is used by applications to compile and upload shaders to the GPU. The book focuses exclusively on the Cg language itself. So if you're already familiar with Cg and want to learn how to use the Cg runtime, this book is not for you and you should rather read the freely available Cg Users Manual.
The book contains many diagrams and figures to illustrate the discussed equations and show the rendered images produced by the presented shaders. Note that most figures in the book are in black and white which sometimes leads to funny situations, such as in chapter 2.4.3 where the resulting image of a shader that renders a green triangle is shown. Since the figure is not in color the triangle that is supposed to be solid green ends up being solid gray. However, in the middle of the book there are sixteen pages with color plates that depict most of the important color images and also show some additional images of various applications, NVIDIA demos, and shaders written for Cg shader contests at www.cgshaders.org.
Accompanying the book on CD-ROM is an application framework that allows you to modify, compile, and run all the example shaders in the book without having to worry about setting up a 3D graphics API, such as OpenGL or Direct3D. The application framework uses configuration files to load meshes and textures and set up the graphics pipeline appropriately for the shaders. This way the Cg shaders can be examined and modified in isolation with the results being immediately visible in the render window of the application. Thanks to this framework application even readers that are not yet familiar with a 3D graphics API or even 3D artists interested in programmable shading on modern GPUs can begin to learn Cg and experiment with real-time shaders.
A final note for programmers using Direct3D 9: The high-level shading language included with the latest version of Direct3D, simply called HLSL for High-Level Shader Language, is syntactically equivalent to Cg. Everything written in the book about Cg equally applies to HLSL. Thus, the book is also an excellent guide for programmers that only intend to work with HLSL.
This book truly is the definitive guide for all beginners with the Cg language, and also more advanced 3D programmers will find the chapters about vertex skinning, environment mapping, bump mapping, and other advanced techniques interesting. Once you've started writing shaders in Cg you will never want to go back to writing them in low-level assembly shading languages ever again.
You can purchase The Cg Tutorial: The Definitive Guide to Programmable Real-Time Graphics from bn.com. The book's official website has additional information and ordering options besides. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
Looks Interesting (Score:4, Interesting)
nforce looks pretty cool though.
Re:NVIDIA (Score:3, Interesting)
Sounds interesting, but (Score:5, Interesting)
Seriously, I really would like someone to debunk this idea if possible, because I have picked up an interest in graphics programming and am just starting out - would like to know more. It seems like an easier / pragmatic route (due to code reusability) to go the other route ...
Re:NVIDIA (Score:2, Interesting)
I think i would prefer better eye-candy to more eye-candy.
Re:NVIDIA (Score:3, Interesting)
GCC and ANSI C standards (Score:5, Interesting)
Re:Looks Interesting (Score:2, Interesting)
Re:why nvidia may not be going the way of 3dfx yet (Score:2, Interesting)
On a related note, does Age Of Mythology even support the ATI Radeon 9700 Pro? We messed with it for hours trying different patches, hacking the video card support files in the game, could NOT get it out of software mode. *Sigh*
Re:NVIDIA (Score:2, Interesting)
Mindless trivia: The original user components of AmigaDOS were written in BCPL, by a British company (Metacomco) contracted by Commodore. Through various revisions, they were rewritten by Commodore in C.
Cg IS NOT vendor specific (Score:3, Interesting)
It is another layer and a nice one to boot. There is no performance loss running it on ATI's cards, infact the few demos I have written have run better on my friends radeon than on my Geforce3 by a long shot.
Quit trying to demonize nVidia for bringing some peace to the hectic world of writing shaders nine thousand different ways so some guy with an obscure video card doesn't complain.
-bort
Be wary... (Score:3, Interesting)
Cg was developed, designed, and created by nvidia. While one of their claims is that it can be made to run on any card and is multiplatform, don't let that fool you. Cg is, at its worst, a thinly veiled attempt to convince developers to produce optimal code for nvidia cards at the expense of broad hardware support. ATI has already said that they will not be supporting Cg (in order for it to work best on ATI cards, someone needs to create profiles for it) and will instead be supporting HLSL. I doubt S3/Via or SIS have the resources to commit to 2 different projects, so I bet they're going to go with HLSL.
If you don't understand why nvidia might be looking for code that works best only on its cards (it's almost a "duh" question), look at it a different way. Look at the GFFX. In almost every instance, it's a failure. Sure, it can stick to 32-bit precision, but it runs really, really slow when you do (just look at the 3dmark03 scores recently released and john carmack's .plan comments). When it runs at 16-bit precision, it's still damn slow, almost always losing out to the Radeon 9700/9800s, but it's a little more competitive (DX9's minimum spec appears to require 24bit precision, but rumor says the jury's still out on that). It's in nvidia's best interest to make the FX appear to be fast (which it isn't), and so they're relegated to make Cg code that optimizes for nvidia cards their best interest.
Sorry I don't have links, but the beyond3d.com [beyond3d.com] forums have a lot of information on this subject.
Re:Do they still make "demos"? (Score:2, Interesting)
I think a console like the PS2 is a much better place for exhibiting the old-fashioned "clever hack", because its weird and exposed architecture allows for many, many more ways to do things, some of which can be very "crazy". Plus hand-coding assembly to fit in 4K or 16K for the vector units seems very similar to the old demo contests... is there a demo scene for the PS2 linux kit? There should be if there isn't...