From the Back Cover
"Cg is the key to unlocking the power of a new generation of programmable graphics hardware. This book is the definitive introduction to Cg, and will be essential for anyone programming high-quality real-time graphics. The Cg Tutorial will teach you to use Cg to create effects never before available for real-time applications."
--Larry Gritz, Author of Advanced RenderMan (Morgan Kaufmann, 2000) "An important and timely book: Pixel-level procedural textures--animated clouds, fire, water, the whole bag of procedural tricks--finally go from the movie screen to the desktop. Access to computation of this power through a C-like language will usher in an exciting new era for the graphics community."
--Ken Perlin, Professor, New York University
Cg (C for graphics) is a complete programming environment for the fast creation of special effects and real-time cinematic quality experiences on multiple platforms. By providing a new level of abstraction, Cg lets developers more directly target OpenGL®, DirectX®, Windows®, Linux, Mac OS X®, and console platforms, such as the Xbox, without having to program directly to the graphics hardware assembly language. Cg was developed by NVIDIA® Corporation in close collaboration with Microsoft® Corporation, and is compatible with both the OpenGL API and Microsoft's HLSL for DirectX 9.0.
The Cg Tutorial explains how to implement both basic and advanced techniques for today's programmable GPU architectures.
Major topics covered include: 3D transformations Per-vertex and per-pixel lighting Skinning and key-frame interpolation Environment mapping Bump mapping Fog Performance optimization Projective texturing Cartoon shading Compositing
The accompanying CD-ROM includes the tools needed to run the sample programs in the book.
0321194969B02192003
About the Author
Randima (Randy) Fernando is Manager of Developer Education at NVIDIA.
Mark J. Kilgard is a Senior Software Engineer at NVIDIA.
0321194969AB01152003
Excerpt. © Reprinted by permission. All rights reserved.
Once upon a time, real-time computer graphics was all about vertices, triangles, and pixels. In fact, it still is. However, the level at which a programmer controls the processing and appearance of these graphics primitives has advanced considerably. Until a few years ago, programmers had to rely on the CPU to process all the transformation and rasterization algorithms needed to produce computer-generated images. Over time, hardware engineers executed these algorithms via specialized, high-performance 3D graphics hardware. Rather than implement the algorithms directly, programmers learned to access the hardware-provided graphics functionality through standard 3D programming interfaces, such as OpenGL (developed by Silicon Graphics SGI) and Direct3D (developed by Microsoft). At first, such costly 3D graphics hardware appeared only in high-priced UNIX workstations and flight simulators. Now, through the miracle of Moore’s Law, the benefits of graphics hardware acceleration have been bestowed on low-cost PCs and game consoles.
Although the performance gained by employing dedicated graphics hardware to execute the brute-force tasks of transforming vertices, rasterizing triangles, and updating pixels far exceeded the performance possible just with CPU programming, real-time 3D programmers gave up a considerable measure of control in exchange for this speed. Developers were limited to using a fixed-function palette of graphics operations that the hardware could handle. Sometimes a skilled and dedicated programmer could coax the graphics programming interface and hardware to accomplish something beyond the ordinary, but this was usually hard, time-consuming work.
While graphics hardware engineers were advancing the real-time performance of their specialized pixel-pushing hardware, off-line computer graphics software packages such as Pixar’s PhotoRealistic RenderMan were changing the look of movies and television with amazing computer-generated special effects. The pre-recorded nature of movies and most television content makes these media well suited for offline rendering. Computer-generated images for film and video are not rendered in real time but instead carefully constructed frame by frame in hours, days, or weeks using standard general-purpose CPUs. The advantage of using general-purpose CPUs is that rather than settle for hard-wired hardware algorithms, programmers and artists can use the CPU to create any effect they might imagine. What these so-called offline rendering systems lack in relative speed, they make up in rendering quality and realism.
The flexibility and generality of offline rendering systems are the key features that have been missing from preceding generations of 3D graphics hardware. In other words, what was lost was programmability.
Realizing this limitation, computer graphics architects have designed a new generation of graphics hardware that permits an unprecedented degree of programmability. Now, many of the programmable shading techniques that are employed so successfully in offline rendering can enter the realm of real-time graphics.
Developers of offline rendering systems created a type of specialized computer language known as a shading language to express the graphics operations required to make surfaces look the way artists intend. A shading language for programmable graphics hardware provides the same sort of functionality but in the context of real-time graphics hardware. Graphics programmers and artists benefit from such a high-level programming language in much the same way that conventional programmers do from C++ or Java. Using a high-level language for graphics hardware automates the process of translating the programmer’s intent into a form that the graphics hardware can execute.
This book is about Cg, the premier language for programmable graphics hardware. NVIDIA developed Cg in close collaboration with Microsoft. Cg is the most portable and productive way for you to unleash the power within programmable graphics hardware. This book is a tutorial to teach you how to write Cg programs.Our Intended Audience
We tried to write this book in a way that makes it valuable to both novices and advanced readers. If you’re new to the world of programmable graphics, this book should give you a firm foundation on which to build. If you encounter a word or concept that is foreign to you and not sufficiently explained, consult the “Further Reading” section at the end of each chapter.
The main audience for this book is 3D game and application programmers, managers of such projects, real-time 3D artists, and computer graphics students—or anyone else interested in learning about the state of the art in real-time rendering. You do not have to be an experienced programmer to learn Cg from this book, though you should be relatively familiar with programming language concepts. If you are familiar with C or one of its derivatives, such as C++ or Java, Cg will be very approachable. Cg programs are relatively short, often less than a page, so even an artist or novice programmer can get the gist of Cg from this tutorial and learn to write interesting Cg programs.
Computer graphics programming involves math. Understanding basic algebra and trigonometry will help you appreciate several sections. You should also be familiar with the math behind basic computer graphics vertex transformation and lighting models. You do not need to know OpenGL or Direct3D, but familiarity with either programming interface is very helpful. All of the Cg examples described work with either OpenGL or Direct3D unless otherwise noted. Some examples that require advanced Cg functionality may not work on older graphics processors.The Book’s StructureChapter 1 introduces Cg. Each chapter that follows is a short tutorial that presents specific Cg concepts and techniques. The tutorials build upon each other, so we recommend reading the chapters in order.
Chapter 1 lays out the foundations of Cg and real-time programmable graphics hardware.Chapter 2 presents the simplest Cg programs.Chapter 3 explains parameters, textures, and expressions.Chapter 4 shows how to transform vertices.Chapter 5 covers the implementation of lighting models with Cg. Chapter 6 describes how to animate and morph models with Cg vertex programs. Chapter 7 explains environment mapping with Cg.Chapter 8 shows how to implement bump mapping.Chapter 9 discusses a number of advanced topics: fog, cartoon shading, projected spotlights, shadow mapping, and compositing.Chapter 10 explains the set of currently available Cg vertex and fragment profiles, and provides advice for improving the performance of Cg programs.
This book gets you started but does not contain everything you will eventually want to know about Cg. This tutorial complements other documentation (such as the Cg Toolkit User’s Manual: A Developer’s Guide to Programmable Graphics) included with the Cg Toolkit. Please consult the user’s manual and other Cg documentation for further information.Trying the Examples
We’ve designed the accompanying software framework so that you can get straight to work, even if you don’t know anything about OpenGL, Direct3D, C, or C++. Our goal is to isolate the Cg language and allow you to experiment freely with it. Of course, as you move toward starting a real-world application with Cg, your project will probably require some combination of OpenGL, Direct3D, C, and C++.
The accompanying software framework allows you to try out the various Cg examples in the book without worrying about graphics APIs, C, or C++ code. The latest versions of the applications are free to download via the book’s companion Web site. The software on the accompanying CD works only on the Windows platform, but versions for Linux and Macintosh systems are available online. Appendix A explains how to download the latest versions of Cg and the accompanying tutorial application.
The tutorial application makes it easy for you to tweak the book’s examples, to see how changing a particular Cg example can immediately affect the rendered 3D result. If you can, have a computer that supports Cg nearby to try out the examples. With our software, you just write Cg programs without worrying about the particulars, such as loading 3D models and textures. When you want to know all the gory details, examine the source code, all of which is freely available for download, so you can see how Cg interfaces with C++ and OpenGL or Direct3D. The Cg Toolkit also comes with several simple examples that you can learn from.The end of each chapter includes suggested exercises that you can work on to explore Cg further.
0321194969P02192003
The Cg Tutorial: The Definitive Guide to Programmable Real-Time Graphics FROM OUR EDITORS
The Barnes & Noble Review
In recent years, the benefits of graphics hardware acceleration have moved from high-end UNIX workstations to cheap PCs and consoles. But there was a trade-off. All but the most skilled real-time 3D programmers have been restricted to using a fixed-function palette of graphics operations provided by their hardware.
Meanwhile, software like Pixarᄑs RenderMan introduced shading languages that made possible stunning movie and TV effects. But Renderman has the luxury of offline rendering. What if we could bring the same techniques to low-end platforms? And free our best graphics programmers from the drudgery of assembly language, giving them the productivity benefits of, say, Java? And let them easily retarget code for new platforms (say, from DirectX to console)?
Thanks to NVIDIAᄑs Cg language, all thatᄑs possible. You just have to learn it -- and for that, thereᄑs The Cg Tutorial.
The authors cover every facet of real-time programming with Cg, from simple vertices, parameters, textures, and expressions through lighting, environment and bump mapping. Youᄑll master 3D transformations, skinning and keyframe interpolation, projective texturing, cartoon shading, compositing, and more.
Youᄑll learn pixel-level techniques for creating everything from animated clouds to fog, fire, and water -- stuff youᄑve only seen on the big screen. Thereᄑs a chapter on optimizing performance, plus a CD full of tools and code.
Welcome to the next revolution in graphics programming. Bill Camarda
Bill Camarda is a consultant, writer, and web/multimedia content developer. His 15 books include Special Edition Using Word 2000 and Upgrading & Fixing Networks for Dummies, Second Edition.
FROM THE PUBLISHER
"Cg is the key to unlocking the power of a new generation of programmable graphics hardware. This book is the definitive introduction to Cg, and will be essential for anyone programming high-quality real-time graphics. The Cg Tutorial will teach you to use Cg to create effects never before available for real-time applications."
--Larry Gritz, Author of Advanced RenderMan (Morgan Kaufmann, 2000) "An important and timely book: Pixel-level procedural textures--animated clouds, fire, water, the whole bag of procedural tricks--finally go from the movie screen to the desktop. Access to computation of this power through a C-like language will usher in an exciting new era for the graphics community."
--Ken Perlin, Professor, New York University
Cg (C for graphics) is a complete programming environment forthe fast creation of special effects and real-time cinematic quality experiences on multiple platforms. By providing a new level of abstraction, Cg lets developers more directly target OpenGL®, DirectX®, Windows®, Linux, Mac OS X®, and console platforms, such as the Xbox, without having to program directly to the graphics hardware assembly language. Cg was developed by NVIDIA® Corporation in close collaboration with Microsoft® Corporation, and is compatible with both the OpenGL API and Microsoft's HLSL for DirectX 9.0.
The Cg Tutorial explains how to implement both basic and advanced techniques for today's programmable GPU architectures.
Major topics covered include: 3D transformationsPer-vertex and per-pixel lightingSkinning andkey-frame interpolationEnvironment mappingBump mappingFogPerformance optimizationProjective texturingCartoon shadingCompositing
The accompanying CD-ROM includes the tools needed to run the sample programs in the book.
FROM THE CRITICS
Slashdot.org
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. ... 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.