Top Banner
SHADERS Chris Kerkhoff Matthew Sullivan 10/16/2009
16

Shaders

Feb 23, 2016

Download

Documents

Maik

Shaders. Chris Kerkhoff Matthew 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). - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Shaders

SHADERS

Chris KerkhoffMatthew Sullivan

10/16/2009

Page 2: Shaders

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.

Page 3: Shaders

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

Page 4: Shaders

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).

Page 5: Shaders

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

Page 6: Shaders

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.

Page 7: Shaders
Page 8: Shaders

The GPU Today Large Frame Buffer Complicated Pipeline It’s fixed-function But we can specify

shader programsthat execute in certain pipeline

stages

Page 9: Shaders
Page 10: Shaders

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)

Page 11: Shaders

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

Page 12: Shaders

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

Page 13: 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.

Page 14: Shaders

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

Page 15: Shaders

DirectX 11-3 new Shader types