DOC PREVIEW
GT ECE 4893 - Lecture 9: Programmable Shaders
School name Georgia Tech
Pages 40

This preview shows page 1-2-3-19-20-38-39-40 out of 40 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 40 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 40 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 40 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 40 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 40 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 40 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 40 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 40 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 40 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Lecture 9: Programmable ShadersWhy Programmable ShadersEvolution of Graphics Processing UnitsProgrammable Graphics PipelineGraphics Programmable PipelineShader LanguagesBasic Shader MechanicsVertex ShaderVertex ShaderInput to Vertex ShaderPixel (or Fragment) ShaderPixel ShaderUse of the Vertex ShaderUse of Pixel ShaderHLSL / CgA Simple Vertex ShaderA Simple Vertex Shader (Alternative)SemanticThe uniform Type QualifierA Simple Pixel (or Fragment) ShaderProfilesFlow Control (Predicating Constants)DirectX Effect FX FrameworkAn Example of an FX FileCreating an Effect from Direct3D AppsSetting Effect ParametersApplying an EffectChange Parameters During a PassSlide 29Vertex Shader Code for TexturingPixel Shader Code for TexturingMath OperatorsStandard Library FunctionSampler Objects (in .fx file)Vertex Shader: Logical ViewPixel Shader: Logical ViewSlide 37Slide 38Per-Vertex vs. Per-Pixel ShadingSlide 40Lecture 9: Programmable ShadersProf. Hsien-Hsin Sean LeeSchool of Electrical and Computer EngineeringGeorgia Institute of TechnologyWhy Programmable Shaders•Hardwired pipeline –Produces limited effects–Effects look the same–Gamers want unique look-n-feel–Multi-texturing somewhat alleviates this, but not enough–Less interoperable, less portable•Programmable Shaders–Vertex Shader–Pixel or Fragment Shader–Starting from DX 8.0 (assembly)–DX 9.0 added HLSL (High Level Shading Language)–HLSL (MS) is compatible with Cg (Nvidia)Evolution of Graphics Processing Units•Pre-GPU–Video controller–Dumb frame buffer•First generation GPU–PCI bus–Raterization done on GPU –ATI Rage, Nvidia TNT2, 3dfx Voodoo3 (‘96)•Second generation GPU–AGP–Include T&L into GPU–Nvidia GeForce 256, ATI Radeon 7500, S3 Savage3D (’98)•Third generation GPU–Programmable vertex shader–Nvidia GeForce3, ATI Radeon 8500, Microsoft Xbox (’01)•Fourth generation GPU–Both programmability in vertex and fragment shaders–Nvidia GeForce FX, ATI Radeon 9700 (’02)Programmable Graphics PipelineSource: Cg tutorial3D Apps3D API:Direct3DGPUFrontendPrimitiveAssemblyRasterization & InterpolationRaster OperationsFrame BufferProgrammable Vertex ShaderProgrammable Fragment ShaderTransformedverticesTransformedFragmentsAPI commandsGPU cmd & data streamVtx indexAssembledpolygonsPixellocationPixelupdatesNVidia GeForce FXFixed Function PipelineFixed Function PipelineGraphics Programmable PipelineVerticesVertex ShaderHW T&LCulling ClippingRasterizationBlend MaskFF PixelPixel ShaderInput AssemblerGeometry ShaderRasterizationOutput MergerVertex ShaderPixel ShaderDirectX 10.0 Pipeline, Fully ProgrammableDirectX 8.0 PipelineChoice between programmable and fixed function pipeline (mutually exclusive, parallel pipelines)Shader Languages•HLSL most common post-DX 10.0.–No assembly shaders allowed in DX 10.0.•Other options: –Cg (compatible with HLSL)–GLSL –Legacy DirectX shaders in assembly–Sh–OpenVidia (U of Toronto)Basic Shader Mechanics•Data types:–Typically floats, and vectors/matrices of floats–Fixed size arrays–Three 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 GPU–Flow control is very simple:•No recursion•Fixed size loops for v_2_0 or earlier•Simple if-then-else statements allowed in the latest APIs•Texkill (asm) or clip (HLSL) or discard (GLSL) or 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 leaves them untouched for pixel shader–Output to Pixel (fragment) shader•Vertex shader is executed once per vertex, thus less expensive than pixel shaderoD1Vertex Shader VertexShaderv15v0 v1 v2Vertex data registersVertex streamCnC0C1C2Constant registers (n=95 or 255)r11r0r1r212 Temporary registersEach register is a 4-component vector register except aLaLLoop Registera0Address RegisteroPos oTntexturepositionfogoFogoD0Diff. colorSpec. coloroPtsOutputPt sizeInput to Vertex ShaderVector ComponentShader decl name RegisterPosition D3DVSDE_POSITION V0Blend Weight D3DVSDE_BLENDWEIGHT V1Blend Indices 1 thru 5D3DVSDE_BLENDINDICES V2Normal D3DVSDE_NORMAL V3Point Size D3DVSDE_PSIZE V4Diffuse D3DVSDE_DIFFUSE V5Specular D3DVSDE_SPECULAR V6Texture CoordinatesD3DVSDE_TEXTCOORD0 – 7 V7 to v14Position 2 D3DVSDE_POSITION2 V15Normal 2 D3DVSDE_NORMAL2 v16Pixel (or Fragment) Shader•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.•Output –Color (including alpha)–Depth value•Executed once per pixel so is executed a lot more times than vertex shader typically–It is advantageous to compute stuff on a per-vertex basis to improve performancePixel ShaderPixelShaderv0 v1Color registersPixel streamCnC0C1Constant registers(8 for v1, 32 for v2)rnr0r1Temporary registers(2, 4, 24, ..)oC0 oDepthDepthcolortnt0t1Texture colorRegisters(4 or 6)sns0s1Sampler Registerscolor1(spec)Color0(diff)Use of the Vertex Shader•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., Gouround shading)•Distort geometry (waves, fish-eye camera)Adapted from Mart Slot’s presentationUse of Pixel Shader•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 mappingAdapted from Mart Slot’s presentationHLSL / Cg•Compatible, jointly developed by Microsoft and Nvidia•A C-like language and syntax•But do not have–Pointers–Dynamic memory allocation–Unstructured/complex control structure •e.g. goto•Recursion (note that functions are inlined)–Bitwise operations (may have in the future)A Simple Vertex Shader uniform extern float4x4 gWVP;struct VtxOutput {float4 position : POSITION;float4 color : COLOR;};VtxOutput All_greenVS(float2 position : POSITION){VtxOutput OUT;OUT.position = mul(float4(position, -30.0f, 1.0f), gWVP);OUT.color = float4(0, 1, 0, 1);return OUT;}Adapted from Cg TutorialSemanticsReserved data typePassed from D3D


View Full Document

GT ECE 4893 - Lecture 9: Programmable Shaders

Documents in this Course
Load more
Download Lecture 9: 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 Lecture 9: 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 Lecture 9: 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?