Table of Contents

real-time shader programming
Real-Time Shader Programming
byRon Fosner ISBN:1558608532
Morgan Kaufmann Publishers 2003 (406 pages)

An indispensable reference for the game developer, graphics programmer, game artist, or visualization programmer, to create countless real-time 3D effects.

Companion Web Site

Table of Contents
Real-Time Shader Programming—Covering DirectX 9.0
Chapter 1 - Introduction
Chapter 2 - Preliminary Math
Chapter 3 - Mathematics of Lighting and Shading
Chapter 4 - Introduction to Shaders
Chapter 5 - Shader Setup in DirectX
Chapter 6 - Shader Tools and Resources
Chapter 7 - Shader Buffet
Chapter 8 - Shader Reference
Part I - Vertex Shader Reference
Part II - Pixel Shader Reference
About the CD-Rom
List of Figures
List of Tables
List of Sidebars

Now that PC users have entered the realm of programmable hardware, graphics programmers can create 3D images and animations comparable to those produced by RenderMan’s procedural programs—-but in real time. Here is a book that will bring this cutting-edge technology to your computer.

Beginning with the mathematical basics of vertex and pixel shaders, and building to detailed accounts of programmable shader operations, Real-Time Shader Programming provides the foundation and techniques necessary for replicating popular cinema-style 3D graphics as well as creating your own real-time procedural shaders.

A compelling writing style, color illustrations throughout, and scores of online resources make Real-Time Shader Programming an indispensable tutorial/reference for the game developer, graphics programmer, game artist, or visualization programmer, to create countless real-time 3D effects.

About the Author

A graphics programmer for nearly 20 years, Ron Fosner wrote the book OpenGL Programming for Windows 95 and Windows NT, published articles for Microsoft Systems Journal, Dr. Dobb’s, Game Developer Magazine, Gamasutra, and Microsoft Developer Network CD's, and lectured at the Windows Developer and Game Developers conferences. He currently runs, a graphics consultancy firm.

Real-Time Shader Programming—Covering DirectX 9.0

Ron Fosner


Publishing Director: Diane D. Cerra
Publishing Services Manager: Edward Wade
Project Managment/Proofreading: Yonie Overton
Editorial Coordinator: Mona Buehler
Cover Design: Ross Carron Design
Text Design: Frances Baca Design
Composition: Proctor-Willenbacher
Technical Illustration: Dartmouth Publishing, Inc.
Copyeditor: Robert Fiske
Indexer: Richard Shrout
Interior Printer: Quebecor World Book Services
Cover Printer: Phoenix Color Corporation

About the cover: The cover image, "Pipe Dream" Demo, is taken from a real-time DirectX 9 Radeon 9700 version of "Pipe Dream" from Animusic's DVD entitled, ANIMUSIC: A Computer Animation Video Album ( This was shown in offline-rendered form in the Electronic Theatre at Siggraph 2001. All of the animation is data-driven from the original data from the Animusic demo. However, the motion blur is done using shaders to dynamically alter the shape and lighting of the balls (which are really a cylinder covered by two hemispheres) and the strings (which have a static string shape and a plucked vibrating shape). For example, a ball's shape was distorted in the vertex shader by stretching the length of the cylinder's axis from the ball's apparent velocity. The velocity was used to calculate a vertex blurriness factor in the vertex shader, which was then passed to the pixel shader, where the blurriness was used to spread out the specular highlights and make the highlight spread in the direction of travel. The full details can be found on ATI's website. Thanks to David Gosselin of ATI Research for being a good sport about providing me images on short notice.

Figure credits: (1) Figure 3–39 from "Digital Facial Engraving" by Victor Ostromoukhov, Proceedings of SIGGRAPH `99, page 421. © 1999 Association for Computing Machinery. Reprinted with permission. (2) Figure 3–40 from "Real-Time Hatching" by Emil Praun, Hugues Hoppe, Matthew Webb, and Adam Finkelstein, Proceedings of SIGGRAPH `01, page 583. © 2001 Association for Computing Machinery. Reprinted with permission. (3) Figure 3–42 from "A Non-Photorealistic Lighting Model for Automatic Technical Illustration" by Amy Gooch, Bruce Gooch, Peter Shirley, and Elaine Cohen, Proceedings of SIGGRAPH `98, page 452. © 1998 Association for Computing Machinery. Reprinted with permission. (4) Figure 3–43 from Jet Set Radio Future.© 2002 Sega Enterprises, Inc. All rights reserved.

Designations used by companies to distinguish their products are often claimed as trademarks or registered trademarks. In all instances in which Morgan Kaufmann Publishers is aware of a claim, the product names appear in initial capital or all capital letters. Readers, however, should contact the appropriate companies for more complete information regarding trademarks and registration.

Morgan Kaufmann Publishers
An Imprint of Elsevier Science
340 Pine Street, Sixth Floor
San Francisco, CA 94104–3205

Copyright © 2003 Elsevier Science (USA)

All rights reserved.

07 06 05 04 03 5 4 3 2 1

No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means—electronic, mechanical, photocopying, or otherwise—without the prior written permission of the publisher.

Library of Congress Control Number: 2002112069


To my three exciting women—
Sue, Rachael, and Olivia.
Thank you

About the Author

Ron Fosner has worked as a graphics programmer since the mid-1980s, first doing rudimentary 3D graphics in assembly language, then learning OpenGL when it became available on Windows systems. The lack of any good information on programming OpenGL on Windows led him to write the first widely successful introductory book on OpenGL programming, OpenGL Programming for Windows 95 and Windows NT. In addition to writing books, Ron has published numerous articles on 3D graphics and code optimization and is a frequent lecturer at the Windows Developer (WinDev) and Game Developers (GDC) conferences.

In the mid-1990s, the leading edge of real-time 3D graphics programming shifted from data visualization to game programming and so did Ron, forming a graphics programming company. Since that time, Ron has programmed four rendering engines, one facial animation engine, a stock market visualization tool, and a video editing tool. Recently, he has been involved in programming internet tools for performance and unit testing. In addition to programming, Ron tries to spread his knowledge on graphics and programming by writing articles for numerous magazines, including Microsoft Systems Journal, Dr. Dobb's, Game Developer Magazine, and Gamasutra, as well as articles for the Microsoft Developer Network CDs.