Chapter 4: Introduction to Shaders

OVERVIEW

Shaders are intended to replace the fixed matte-plastic look that has been a part of consumer level graphics programs and games for the past few years. Shaders are intended to give greater freedom to artists and programmers so they may create a unique look and style for their application. Shaders are designed to run on the hardware (assuming a suitable interface is there) in real time, with control over just how involved and complicated the shader is in the hands of the programmer and artist. With shaders you can

  • Perform basic geometry transformations

  • Warp the geometry

  • Blend or skin geometry

  • Generate color information (specular and diffuse)

  • ‘Tween vertices between transformation matrices

  • Generate texture coordinates

  • Transform texture coordinates

  • Size point sprites

  • Use a custom illumination model

  • Perform nonphotorealistic rendering

  • Perform bump, environment, and specular mapping

  • Perform your own texture-blending operations

  • Clip pixels

In fact, your options are limited only by your ingenuity and the size of the shader buffer (which limits how complicated your shader can be).

Writing a shader is a lot like programming PCs back in the old days, when the real programmers didn't use any fancy higher-level language. They programmed in assembler. While that may cause you to groan, it really shouldn't since programming in assembly (or in shader instructions) makes programming very simple and obvious though a bit tedious at times. The nice thing is that you know exactly what's happening in your shader. Errors are fairly obvious, both in rinding them in your code and in seeing them on the screen. The other advantage is that you can toss out anything that doesn't help you get the results you want. Shaders are generally very linear, and culling unnecessary instructions is the way you optimize shaders.

A Note on Higher Level Language Shaders

As I write this, DirectX 9 is in beta and has a specification for higher level shading language. NVIDIA has started promoting Cg, its higher level language. OpenGL 2.0 has a shading language. It's a confusing mess right now. The good thing is that everyone seems to agree that making it difficult is the worst thing that could happen. I chose not to include these languages because I think that sometime in mid- to late 2003, they will be standardized and reworked in such a way that you don't have to worry about shader versions, instruction limits, register assignments, etc. You should just program what you want, and the shader compiler will do the right thing, hiding the limits of the underlying hardware as much as possible. However, as anyone who's written time-critical software knows, sometimes you just have to fall back to assembler. Keep an eye on the http://www.directx.com Web site for updates.



Real-Time Shader Programming(c) Covering Directx 9. 0
Real-Time Shader Programming (The Morgan Kaufmann Series in Computer Graphics)
ISBN: 1558608532
EAN: 2147483647
Year: 2005
Pages: 104
Authors: Ron Fosner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net