SHADERS Chris Kerkhoff Matthew Sullivan 10/16/2009
Feb 23, 2016
SHADERS
Chris KerkhoffMatthew Sullivan
10/16/2009
What is a Shader? Shaders are simple programs that
describe the traits of either a vertex or a pixel.
Shaders replace a section of video hardware that's typically called the Fixed Function Pipeline (FFP).
The FFP performs lighting and texture mapping in a hard-coded manner, while shaders let you replace this hard-coded approach with a programmable one.
Three types Pixel
Calculates actual color for a pixel Vertex
Projects 3D points onto 2D plane (the viewport) and calculates Z depth
Geometry Modifies existing 3D meshes or creates new
ones from formulas
Simplified GPU pipeline The CPU sends instructions and geometry data to
the GPU. Within the vertex shader, the geometry is
transformed and lighting calculations are performed.
If a geometry shader is in the graphic processing unit, some changes of the geometries in the scene are performed.
The calculated geometry is triangulated (subdivided into triangles).
Triangles are transformed into pixel quads (one pixel quad is a 2 × 2 pixel primitive).
The Need Real world optics and lighting are far too
complex for even the fastest computers Ray tracing which is state of the art for
3D graphics is still too complex to run in realtime for scenes of a high enough complexity to look real
Shaders are written to apply transformations to a large set of elements at a time
Modern GPUs have multiple shader pipelines
Pixel Shader The only type of Shader that actually shades anything Takes a color from a texture map and modifies by the
effect of various light sources on the surface A simplified model is: Ambient+Lambertian+Specular Ambient is fake light to avoid the need for
environmental lighting to fill in shadow Lambertian represents the coloring of a perfectly
diffuse (or flat) surface Specular highlighting is the result of a perfectly glossy
surface; the real world is combination of the two.
The GPU Today Large Frame Buffer Complicated Pipeline It’s fixed-function But we can specify
shader programsthat execute in certain pipeline
stages
Shader Program Limitations
No random-access memory writes Can write to current pixel in frame buffer Can’t create data structures
Can’t traverse data structures Can hack it using texture accesses
Hard to share data between main program and shader programs
Weird programming language HLSL (High Level Shader Language, similar to
Cg)
Programmable Shaders Manipulate vertices and textures Implement oversampling and
interpolation techniques Most of these computations involve
matrix and vector operations Good for Scientists and Engineers
Programming Shaders GLSL (OpenGL Shading Language)in
OpenGL (1.5+) HLSL (High Level Shader Language) in
Microsoft Direct3D API (Direct3D 9+) Cg (C for Graphics) developed by Nvidia
for programming vertex and pixel shaders
Universal Shaders Early video cards had dedicated
processors for different shaders (Vertex, Geometry, Pixel) This simplified the hardware requirements for
each type but was inflexible Modern video cards (DirectX 10 and
newer; GeForce 8xxx+, Radeon HD) have universal shaders which can be assigned to the different functions at the discretion of the programmer.
Universal Shaders and GPGPU
There are a few early programs that attempted to use dedicated shaders for GPGPU, but the limitations make this very challenging and inefficient
Universal shaders with their increased flexibility allowed for GPGPU to really take off
DirectX 11-3 new Shader types
Links http://graphics.cs.williams.edu/archive/S
weeneyHPG2009/TimHPG2009.pdf http://wapedia.mobi/en/Shader_Model http://www.absoluteastronomy.com/topic
s/Pixel_shader http://en.wikipedia.org/wiki/Shaders http://en.wikipedia.org/wiki/Shader_%28r
ealtime,_logical%29 http://my.opera.com/Vorlath/blog/2008/0
1/22/opengl-pixel-shaders-and-why-the-future-of-software-depends-on-it