1 / 16

Shaders

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

maik
Download Presentation

Shaders

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Shaders Chris Kerkhoff Matthew Sullivan 10/16/2009

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

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

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

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

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

  7. The GPU Today • Large Frame Buffer • Complicated Pipeline • It’s fixed-function • But we can specify shader programs that execute in certain pipeline stages

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

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

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

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

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

  13. DirectX 11-3 new Shader types

  14. Links • http://graphics.cs.williams.edu/archive/SweeneyHPG2009/TimHPG2009.pdf • http://wapedia.mobi/en/Shader_Model • http://www.absoluteastronomy.com/topics/Pixel_shader • http://en.wikipedia.org/wiki/Shaders • http://en.wikipedia.org/wiki/Shader_%28realtime,_logical%29 • http://my.opera.com/Vorlath/blog/2008/01/22/opengl-pixel-shaders-and-why-the-future-of-software-depends-on-it

More Related