|

Addison-Wesley / Prentice Hall

Computer Science

My Instructor Resource Center :  Log in or request access

Cg Tutorial, The: The Definitive Guide to Programmable Real-Time Graphics
Randima Fernando, (Series Editor)
Mark J. Kilgard

ISBN-10: 0321194969
ISBN-13:  9780321194961

Publisher:  Addison-Wesley Professional
Copyright:  2003
Format:  Paper Bound w/CD-ROM; 384 pp
Published:  02/26/2003
Status: Instock



This book introduces the features and benefits of the Cg language and methodically shows how to use it for a variety of applications. The instruction is progressive, starting with simple examples and building up to more advanced techniques. The explanations are beautifully illustrated, including 16 pages of 4-color plates.

You will find that Cg allows students to focus on graphics algorithms rather than just state management and it allows the GPU to be used for more than just graphics. For instance, the GPU could be used for collision detection, chemical simulation, or animation.

And, as an aide for teaching, the application framework that accompanies the book (which is also available online) allows students to run and modify the examples in the book, without any knowledge whatsoever of C/C++, OpenGL, or DirectX. It is a set of standalone applications, one for each example, that works out of the box allowing you to introduce Cg to students earlier in the curriculum.



Figures and Plates.


Examples.


Tables.


Equations.


Foreword.


Preface.


1. Introduction.

What Is Cg?

A Language for Programming Graphics Hardware.

Cg's Data-Flow Model.

GPU Specialization and CPU Generalization.

The Performance Rationale for Cg.

Coexistence with Conventional Languages.

Other Aspects of Cg.

The Limited Execution Environment of Cg Programs.

Vertices, Fragments, and the Graphics Pipeline.

The Evolution of Computer Graphics Hardware.

Four Generations of Computer Graphics Hardware.

The Graphics Hardware Pipeline.

The Programmable Graphics Pipeline.

Cg Provides Vertex and Fragment Programmability.

Cg's Historical Development.

Microsoft and NVIDIA's Collaboration to Develop Cg and HLSL.

Noninteractive Shading Languages.

Programming Interfaces for 3D Graphics.

The Cg Environment.

Standard 3D Programming Interfaces: OpenGL and Direct3D.

The Cg Compiler and Runtime.

The CgFX Toolkit and File Format.

Exercises.

Further Reading.



2. The Simplest Programs.

A Simple Vertex Program.

Output Structures.

Identifiers.

Structure Members.

Vectors.

Matrices.

Semantics.

Functions.

Input and Output Semantics Are Different.

The Function Body.

Compiling Your Example.

Vertex Program Profiles.

Classes of Cg Compilation Errors.

Profile-Dependent Errors.

The Norm: Multiple Entry Functions.

Downloading and Configuring Vertex and Fragment Programs.

A Simple Fragment Program.

Fragment Program Profiles.

Rendering with Your Vertex and Fragment Program Examples.

Rendering a Triangle with OpenGL.

Rendering a Triangle with Direct3D.

Getting the Same Results.

Exercises.

Further Reading.



3. Parameters, Textures, and Expressions.

Parameters.

Uniform Parameters.

The const Type Qualifier.

Varying Parameters.

Texture Samplers.

Sampler Objects.

Sampling Textures.

Sending Texture Coordinates While Sampling a Texture.

Math Expressions.

Operators.

Profile-Dependent Numeric Data Types.

Standard Library Built-In Functions.

2D Twisting.

Double Vision.

Exercises.

Further Reading.



4. Transformations.

Coordinate Systems.

Object Space.

Homogeneous Coordinates.

World Space.

The Modeling Transform.

Eye Space.

The View Transform.

Clip Space.

The Projection Transform.

Normalized Device Coordinates.

Window Coordinates.

Applying the Theory

Exercises.

Further Reading.



5. Lighting.

Lighting and Lighting Models.

Implementing the Basic Per-Vertex Lighting Model.

The Basic Lighting Model.

A Vertex Program for Basic Per-Vertex Lighting.

The Fragment Program for Per-Vertex Lighting.

Per-Vertex Lighting Results.

Per-Fragment Lighting.

Implementing Per-Fragment Lighting.

The Vertex Program for Per-Fragment Lighting.

The Fragment Program for Per-Fragment Lighting.

Creating a Lighting Function.

Declaring a Function.

A Lighting Function

Structures.

Arrays.

Flow Control.

Computing the Diffuse and Specular Lighting.

Extending the Basic Model.

Distance Attenuation.

Adding a Spotlight Effect.

Directional Lights.

Exercises.

Further Reading.



6. Animation.

Movement in Time.

A Pulsating Object.

The Vertex Program.

Displacement Calculation.

Particle Systems.

Initial Conditions.

Vectorized Computations.

The Particle System Parameters.

The Vertex Program.

Dressing Up Your Particle System.

Key-Frame Interpolation.

Key-Framing Background.

Interpolation Approaches.

Basic Key-Frame Interpolation.

Key-Frame Interpolation with Lighting.

Vertex Skinning.

The Theory of Vertex Skinning.

Vertex Skinning in a Vertex Program.

Exercises.

Further Reading.



7. Environment Mapping Techniques.

Environment Mapping.

Cube Map Textures.

Generating Cube Maps.

The Environment Mapping Concept.

Computing Reflection Vectors.

Assumptions for Environment Mapping.

Reflective Environment Mapping.

Application-Specified Parameters.

The Vertex Program.

The Fragment Program.

Control Maps.

Vertex Program vs. Fragment Program.

Refractive Environment Mapping.

The Physics of Refraction.

The Vertex Program.

The Fragment Program.

The Fresnel Effect and Chromatic Dispersion.

The Fresnel Effect.

Chromatic Dispersion.

Application-Specified Parameters.

The Vertex Program.

The Fragment Program.

Exercises.

Further Reading.



8. Bump Mapping.

Bump Mapping a Brick Wall.

The Brick Wall Normal Map.

Storing Bump Maps As Normal Map Textures.

Simple Bump Mapping for a Brick Wall.

Specular Bump Mapping.

Bump Mapping Other Geometry.

Bump Mapping a Brick Floor.

The Vertex Program for Rendering a Brick Floor.

Bump Mapping a Torus.

The Mathematics of the Torus.

The Bump-Mapped Torus Vertex Program.

Bump Mapping Textured Polygonal Meshes.

Examining a Single Triangle.

Caveats.

Generalizing to a Polygonal Mesh.

Combining Bump Mapping with Other Effects.

Decal Maps.

Gloss Maps.

Geometric Self-Shadowing.

Exercises.

Further Reading.



9. Advanced Topics.

Fog.

Uniform Fog.

The Attributes of Fog.

The Mathematics of Fog.

Intuiting the Equations.

Creating Uniform Fog with Cg.

Nonphotorealistic Rendering.

Toon Shading.

Implementing Toon Shading.

Putting It All Together.

Problems with This Technique.

Projective Texturing.

How Projective Texturing Works.

Implementing Projective Texturing.

The Code for Projective Texturing.

Shadow Mapping.

Compositing.

Mapping Input to Output Pixels.

Basic Compositing Operations.

Exercises.

Further Reading.



10. Profiles and Performance.

Profile Descriptions.

The Vertex Shader Profile for DirectX 8.

The Basic NVIDIA Vertex Program Profile for OpenGL.

The ARB Vertex Program Profile for OpenGL.

The Vertex Shader Profiles for DirectX 9.

The Advanced NVIDIA Vertex Program Profile for OpenGL.

The Pixel Shader Profiles for DirectX 8.

The Basic NVIDIA Fragment Program Profile for OpenGL.

The DirectX 9 Pixel Shader Profiles.

The ARB Fragment Program Profile for OpenGL.

The Advanced NVIDIA Fragment Program Profile for OpenGL.

Performance.

Use the Cg Standard Library.

Take Advantage of Uniform Parameters.

Using Vertex Programs vs. Fragment Programs.

Data Types and Their Impact on Performance.

Take Advantage of Vectorization.

Use Textures to Encode Functions.

Use Swizzling and Negation Freely.

Shade Only the Pixels That You Must.

Shorter Assembly Is Not Necessarily Faster.

Exercises.

Further Reading.



Appendix A. Getting Started with Cg.

Getting This Book's Accompanying Software.

Getting the Cg Toolkit.



Appendix B. The Cg Runtime.

What Is the Cg Runtime?

Why Use the Cg Runtime?

Future-Proofing.

No Dependency Issues.

Input Parameter Management.

How Does the Cg Runtime Work?.

Header Files.

Creating a Context.

Compiling a Program.

Loading a Program.

Modifying the Program Parameters.

Executing a Program.

Releasing Resources.

Handling Errors.

More Details.



Appendix C. The CgFX File Format.

What Is CgFX?

Format Overview.

Techniques.

Passes.

Render States.

Variables and Semantics.

Annotations.

A Sample CgFX File.

Cg Plug-Ins Supporting the CgFX Format.

Learning More About CgFX.



Appendix D. Cg Keywords.

Cg Keyword List.



Appendix E. Cg Standard Library Functions.

Mathematical Functions.

Geometric Functions.

Texture Map Functions.

Derivative Functions.

Debugging Function.



Index. 0321194969T02192003

View a Sample Chapter PDF:/samplechapter/0321194969.pdf

Randima (Randy) Fernando is Manager of Developer Education at NVIDIA.

Mark J. Kilgard is a Senior Software Engineer at NVIDIA.

"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.

    Pearson Higher Education offers special pricing when you choose to package your text with other student resources. If you're interested in creating a cost-saving package for your students contact your Pearson Higher Education representative.