Shading languages: General

From OpenGL Wiki
Jump to: navigation, search

Shading languages are the interface used to program key parts of the modern graphics pipeline which have previously been fixed function state machines without programmability. With shading languages the vertex transformation and lighting fixed function pipeline is replaced by vertex program instructions supplied by the application, and key parts of the rasterization pipeline, mainly texture environment and fog are replaced by fragment program instructions supplied by the application. The key to understanding shaders is that vertex shaders are fed by graphics primitives like triangles and lines with vertex attributes like color, texture coordinates, position and other generic attributes, for each vertex the program is executed, the output is screen space primitives with similar types of per vertex data to the input. The output of a vertex shader is then transformed to the viewport and clipped by the fixed function pipeline. The primitive is rasterized using prudicing per fragment interpolated values for the results of the vertex shader. The fragment shader program is then executed for each pixel produced by aforementioned interpolation process using the interpolated output of the vertex shader as the input to the fragment shader. The fragment shader outputs color attributes and possibly other outputs like zbuffer depth (outputs supported depend on specific shader language feature support). The output from the fragment shader is depth tested and stencil tested using fixed function hardware and if passed the color is blended with the destination pixel using the fixed function hardware.