DOC PREVIEW
GT ECE 4893 - Programmable Shaders
School name Georgia Tech
Pages 70

This preview shows page 1-2-3-4-5-33-34-35-36-66-67-68-69-70 out of 70 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 70 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 70 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 70 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 70 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 70 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 70 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 70 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 70 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 70 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 70 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 70 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 70 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 70 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 70 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 70 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Programmable Shaders Prof. Aaron Lanterman (Based on slides by Prof. Hsien-Hsin Sean Lee) School of Electrical and Computer Engineering Georgia Institute of TechnologyXNA rendering pipeline • Vertex shader outputs transformed vertex position, texture coordinates, color, etc. – Solid deforming, skeletal animation, particle motion, etc. • Rasterization interpolates and determines what pixels to draw • Pixel shader outputs pixel color, depth (optional) – Per-pixel lighting, procedural texture generation, postprocessing effects, brightness, contrast, blur, etc. Vertex Data (Model Space) Vertex Processing Rasterization Pixel Processing Output Merger Other Memory Resources (Texture, Constants, etc) Final image : Programmable : Fixed operations : Data supply From A. Lobao, B. Evangelista, and J.A. Leal de Farias, “XNA 2.0 Game Programming: From Novice to Professional”Shader languages • HLSL/Cg most common – Both are compatible – No assembly shaders allowed in DirectX 10 • Other alternatives: – GLSL (for OpenGL) – Sh – Legacy DirectX shaders in assemblyMotivation for shader languages From The Cg Tutorial float3 cSpecular = pow(max(0, dot(Nf, H)), phongExp).xxx; float3 cPlastic = Cd * (cAmbient + cDiffuse) + Cs * cSpecular;The Cg Tutorial book (NVIDIA) From The Cg TutorialShader data • Typically floats, and vectors/matrices of floats • Fixed size arrays • Three main types: – Per-instance data, e.g., per-vertex position – Per-pixel interpolated data, e.g., texture coordinates – Per-batch data, e.g., light position • Data are tightly bound to the GPUShader flow control • Very simple • No recursion • Fixed size loops for Shader Model 2.0 or earlier • Simple if-then-else statements allowed in the latest APIs • Texkill (asm) or clip (HLSL) or discard (GLSL) allows you to abort a write to a pixel (form of flow control)Vertex shader • Transform to clip-space (i.e., screen space) • Inputs: – Common inputs: • Vertex position (x, y, z, w) • Texture coordinate • Constant inputs • Can also have fog, color as input, but usually passes them untouched to the pixel shader – Output to a pixel (fragment) shader • Vertex shader is executed once per vertex, could be less expensive than pixel shaderoD1 Vertex shader data flow (3.0) Vertex Shader v15 v0 v1 v2 16 Vertex data registers Vertex stream Cn C0 C1 C2 Constant float registers (at least 256) 16 Constant Integer Registers r31 r0 r1 r2 32 Temporary registers Each register is a 4-component vector register except aL aL Loop Register a0 Address Register oPos oTn texture position fog oFog oD0 Diff. color Spec. color oPts Output Pt size 12 output registersVertex shader: logical view Vertex Processing Unit Per-vertex Input Data Per-vertex Output Data Register File r0 r1 r2 r3 ... Swizzle / Mask Unit .rgba .xyzw .zzzz .xxyz ... cosine log sine sub add ... Math/Logic Unit Shader Resources (bound by application) Shader Start Addr Bound Textures Bound Samplers Bound Consants Sampler Unit Texture Memory Shader Constants Input Data Architectural State Output Data Control Logic State Information Memory Transformed and Lit verticesSome uses of vertex shaders • Transform vertices to clip-space • Pass normal, texture coordinates to PS • Transform vectors to other spaces (e.g., texture space) • Calculate per-vertex lighting (e.g., Gouraud shading) • Distort geometry (waves, fish-eye camera) Adapted from Mart Slot’s presentationPixel (or fragment) shader (1) • Determine each fragment’s color – Custom (sophisticated) pixel operations – Texture sampling • Inputs – Interpolated output from vertex shader – Typically vertex position, vertex normals, texture coordinates, etc. – These registers could be reused for other purpose • Output – Color (including alpha) – Depth value (optional)Pixel (or fragment) shader (2) • Executed once per pixel, hence typically executed many more times than a vertex shader • It is advantageous to compute stuff on a per-vertex basis to improve performancePixel shader data flow (3.0) Pixel Shader Color (diff/spec) and texture coord. registers Pixel stream Cn C0 C1 Constant registers (16 INT, 224 Float) r31 r0 r1 Temporary registers oC0 oDepth Depth color s15 s0 s1 Sampler Registers (Up to 16 texture surfaces can be read in a single pass) v9 v0 v1Pixel shader: logical view Pixel Processing Unit Per-pixel Input Data Per-pixel Output Data Register File r0 r1 r2 r3 ... Swizzle / Mask Unit .rgba .xyzw .zzzz .xxyz ... cosine log sine sub add ... Math/Logic Unit Shader Resources (bound by application) Shader Start Addr Bound Textures Bound Samplers Bound Consants Sampler Unit Texture Memory Shader Constants Input Data Architectural State Output Data Control Logic State Information Memory Interpolator Pixel Color Depth Info Stencil Info Color buffer Depth Buffer Stencil BufferSome uses of pixel shaders • Texturing objects • Per-pixel lighting (e.g., Phong shading) • Normal mapping (each pixel has its own normal) • Shadows (determine whether a pixel is shadowed or not) • Environment mapping Adapted from Mart Slot’s presentationHLSL / Cg • A C-like language and syntax • But does not have – Pointers – Dynamic memory allocation – Unstructured/complex control structure • e.g., goto • Recursion (note that functions are inlined) • Integer & bitwise operations available in VS/PS 4.0, but not previous versionsUniform vs. variable input • Two different input data types in shader code • uniform (a keyword in Cg/HLSL) input: – Global, do not change per vertex– Outside the scope of the shader function – Define in the beginning of a shader code • Variable input – Attributes associated with each vertex – Declared using semanticsThe uniform type qualifier • A uniform variable value can come from an external source – E.g., your C# application • Retrieve the initial value from a constant register (e.g., c0, read-only) in the GPU • Uniform (or global) to all processed vertices in the entire shading processSemantics • Something not in usual C/C++ programming • A colon and a keyword, e.g., – MonsterPos : POSITION – VertexColor : COLOR – Vertexnormal : NORMAL


View Full Document

GT ECE 4893 - Programmable Shaders

Documents in this Course
Load more
Download Programmable Shaders
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Programmable Shaders and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Programmable Shaders 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?