Revision as of 04:40, 23 January 2007 editTechnoFaye (talk | contribs)1,421 edits move general paragraph on hardware to hardware section and elim redundant stuff there SEE DISCUSSION PAGE before reverting← Previous edit | Revision as of 04:44, 23 January 2007 edit undoTechnoFaye (talk | contribs)1,421 edits →References: section now unusedNext edit → | ||
Line 43: | Line 43: | ||
*]: ''OpenGL Shading Language'', Addison-Wesley Professional, ISBN 0-321-19789-5 | *]: ''OpenGL Shading Language'', Addison-Wesley Professional, ISBN 0-321-19789-5 | ||
*: ''HLSL Tutorial using DirectX with lots of sample code'' | *: ''HLSL Tutorial using DirectX with lots of sample code'' | ||
== References == | |||
#{{note|glslangUniforms}} Search for the issue "32) Can you explain how uniform loading works?". This is an example of how a complex data structure must be broken in basic data elements. | |||
#{{note|multitexturing}} Required machinery has been introduced in OpenGL by but this specification is no more available since its integration in core OpenGL 1.2. | |||
#{{note|glslangSamplers}} Search again for the issue "25) How are samplers used to access textures?". You may also want to check out "Subsection 2.14.4 Samplers". | |||
#{{note|nvdeveloper}} Search for various papers on per-pixel lighting. | |||
#{{note|glslangResources}} You'll be glad to see those limits are (at least theorically) rather high. Check out for the string "52) How should resource limits for the shading language be defined?" and look for your favorite video card at . | |||
] | ] |
Revision as of 04:44, 23 January 2007
This December 2006 may be confusing or unclear to readers. Please help clarify the December 2006. There might be a discussion about this on the talk page. (Learn how and when to remove this message) |
A shader is a computer program used in 3D computer graphics to determine the final surface properties of an object.
Introduction
In the 3D computer graphics creation process, shaders are used to define "materials", and are attached to the different surfaces of objects. For example, for a simple ceramic mug model, a single ceramic shader will be attached to the entire mug; for a hammer model, a rubber or plastic shader will be attached to the handle and a metal shader to the striking surface. A shader can also make minor adjustments to an object's shape.
During the rendering process, the rendering program will run the various surface shaders as it attempts to draw the various surfaces, passing to the shader programs all of the needed parameters, such as the specific 3D location of the part of the surface being drawn, the location, directions, and colors of all the lights, any texture or bump maps needed by the shader, and environment or shadow maps. The shader program will return as it outputs the final color of a given pixel in a scene. In layman's terms, a shader answers the question (that the rendering program asks), "Given the locations of all the objects, all the lights, and the camera in a scene, what color should I draw this particular object at this particular location?"
Pixel shaders
Pixel shaders are short computer programs which compute the brightness and color of pixels making up a 3D scene. They are applied to every pixel and are used to simulate effects such as lighting, textures, shadows, reflections, colored glass, oily skin, glare, bumps, rainbows, smoke, glowing objects, and lens flare.
They are also used to simulate multi-layer surfaces, such as blood flow under skin, translucent objects, layers of clothing; as well as effects like eye-pupil adjustment to backlight, depth of field defocus, and atmospheric or underwater haze associated with with distance.
Vertex shaders
Objects are defined by a set of points in 3D space and lines between some of the points, making a set of triangles that define the shape of a 3D surface. When seen from a distance, the individual triangles making up a curved surface can't be seen and the object looks smooth.
The points are called vertexes (or vertices). A vertex shader moves the vertexes slightly, allowing you to "warp" the shape of an object. For example, to round off the corners of a cube and make it not so "sharp", you can take the points (vertexes) which happen to be near a corner of the cube and move them slightly toward the center of the cube, but points on the cube which are far from a corner would not get moved at all.
Vertex shaders are actually short computer programs which get applied to each vertex defining the object. They have to be short because they get run for every vertex in the 3D world. They run on the programmable vertex processors found in modern graphics cards.
The name "vertex shader" may be confusing, because a vertex shader changes the position of something, not it's shade (color and brightness). In particular, they are different from pixel shaders, which DO modify the color and brightness of the pixels on the flat surfaces defined by the vertexes. Because of this, the vertex shader program must be run before the pixel shader is.
Geometry shaders
Geometry shaders are a new type of shaders coming in next generation graphics hardware like the GeForce 8 Series and Radeon R600. Geometry shaders do per-primitive operations on vertices grouped into primitives like triangles, lines, strips and points outputted by vertex shaders. Geometry shaders can make copies of the inputted primitives, so unlike vertex shaders they can actually create new vertices. Examples of use include shadow volumes on the GPU, render-to-cubemap and procedural generation. In non-realtime applications for which rendering speed is less important than final image quality (such as special effects for movies), shaders can be arbitrarily complex. The RenderMan Shading Language is a common non-realtime shading language used extensively by visual effects studios for film and television.
Shader Hardware
Since each pixel's value can be computed separately, modern graphics cards have a dozen or so shader units which all run at the same time (in parallel), allowing a great deal of computation to be done quickly so tthe scene can be rendered in real time. State-of-the-art graphics cards (like the nVidia GeForce 8 series) have over 100 processors which can be used as either vertex or pixel shaders, as needed.
Shaders are usually written using a shading language, a specifically designed programming language.
The increasing performance and programmability of shader-based architectures attracted researchers interested in exploiting the new parallel model for General Purpose computation on GPUs. This demonstrated that shaders could be used to process a large variety of information, and not just rendering-specific tasks. This new programming model, which resembles stream processing, allows high computational rates at extremely low cost that will operate on a wide installed base (e.g. the common home PC).
See also
Further reading
- GLSL: OpenGL Shading Language @ Lighthouse 3D - GLSL Tutorial
- Steve Upstill: The RenderMan Companion: A Programmer's Guide to Realistic Computer Graphics, Addison-Wesley, ISBN 0-201-50868-0
- David S. Elbert, F. Kenton Musgrave, Darwyn Peachey, Ken Perlin, Steven Worley: Texturing and modeling: a procedural approach, AP Professional, ISBN 0-12-228730-4. Ken Perlin is the author of Perlin noise, an important procedural texturing primitive.
- Randima Fernando, Mark Kilgard. The Cg Tutorial: The Definitive Guide to Programmable Real-Time Graphics, Addison-Wesley Professional, ISBN 0-321-19496-9
- Randi J. Rost: OpenGL Shading Language, Addison-Wesley Professional, ISBN 0-321-19789-5
- Riemer's DirectX & HLSL Tutorial: HLSL Tutorial using DirectX with lots of sample code