Shaders Jeremy Nicholson COMP30019: Graphics and Interaction 05 Sep 2011 Jeremy Nicholson Shaders
Rendering Pipeline (Foley Figure 14.41) Jeremy Nicholson Shaders
Rendering Pipeline (OpenGL Red Book, section 1) Jeremy Nicholson Shaders
Rendering Pipeline (Angel Figure 1.38) Jeremy Nicholson Shaders
Rendering Pipeline Vertex processing: Vertex position: co-ordinate transformations (model) projection transformations Vertex colour: Illumination model Jeremy Nicholson Shaders
Rendering Pipeline Clipping and primitive assembly: Clipping: Clipping volume (based on viewing frustum) projection transformations Primitive assembly Vertices → line segments, polygons, etc. Jeremy Nicholson Shaders
Rendering Pipeline Rasterisation: Scan conversion of polygons Line segment → fragments Fragments: ”potential pixels” Position and colour to be entered into frame buffer Jeremy Nicholson Shaders
Rendering Pipeline Fragment processing: Hidden surface removal Some fragments may not be visible because they are behind other fragments Texturing, blending, etc. Jeremy Nicholson Shaders
Shaders Loosely speaking, programming on the GPU itself Typically high-powered processor, lots of RAM Parallel processing plays an important part not massively parallel typically only a couple of simple mathematical operations e.g. matrix multiplication of a single transformation matrix to many vertices Don’t typically do any “shading” Jeremy Nicholson Shaders
Types of Shaders Vertex Shader: Input: set of primitives (vertices) Output: set of primitives Operate on vertex values and associated data Normals Colour Material properties Texture? Jeremy Nicholson Shaders
Types of Shaders Geometry Shader: Input: set of primitives Output: set of primitives Add/remove vertices or other primitives Triangulation (why?) Hidden surface removal? Shadow volumes etc. Jeremy Nicholson Shaders
Types of Shaders Fragment Shader: Input: set of fragments Output: set of fragments Apply operations to viewport pixels (primarily colour) Texture mapping Bump mapping Potentially lighting model Rasterisation/anti-aliasing? Jeremy Nicholson Shaders
Types of Shaders Pixel Shader: Input: set of fragments Output: set of pixel values Actually rendering images to the display Depth testing/occlusion/blending Hardware conversion: dithering, γ -correction Double buffering Jeremy Nicholson Shaders
Shaders and the Rendering Pipeline Vertex processing: Vertex Shader Clipping and primitive assembly: Geometry Shader Rasterisation: Fragment Shader Fragment processing: Pixel Shader (Loosely) Jeremy Nicholson Shaders
Shaders and the Rendering Pipeline Vertex Shader: ??? Geometry Shader: ??? Fragment Shader: ??? Pixel Shader: ??? Jeremy Nicholson Shaders
Shaders and the Rendering Pipeline Vertex Shader: Modelling transform, Lighting, Viewing transform Geometry Shader: Trivial accept/reject, some Lighting Fragment Shader: Rasterisation Pixel Shader: Display (Typically, but Clipping and Map to 3D viewport are ”missing”) Jeremy Nicholson Shaders
Shaders in OpenGL Contrast with ”legacy” OpenGL Gives you the power (and hassle) of specifying your own modelling/viewing operations, illumination model, shading model Only Vertex/Geometry/Fragment Shaders implemented in OpenGL And geometry only recently! Manipulated using a pared-down programming language... Jeremy Nicholson Shaders
GLSL: The OpenGL shading language ”GL slang” Reference: Orange book Not many in-builts Some mathematical functions (e.g. Trigonometric) I/O partly limited: specific streams for vertex position, colour, etc. Jeremy Nicholson Shaders
GLSL: The OpenGL shading language Common key words: in - input (from OpenGL or earlier in the Shader pipeline) out - output (to next Shader in the pipeline, or occasionally OpenGL) uniform - ”constant” variable: same across many inputs (iterationsof Shader) — allowing preprocessing and optimisation varying - actual variable: for intermediate calculation etc. Jeremy Nicholson Shaders
Examples Trivial Example (Angel 2.2) Jeremy Nicholson Shaders
Examples Illumination Model (in Vertex Shader) (Angel 5.3) Jeremy Nicholson Shaders
Examples Illumination Model (in Fragment Shader) (Angel 5.6) Jeremy Nicholson Shaders
Recommend
More recommend