1 / 111

GL2 Shading Language

GL2 Shading Language. Bill Licea-Kane ATI Research, Inc. bill@ati.com. GL2 Shading Language Back to the future.

milagrost
Download Presentation

GL2 Shading Language

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. GL2 Shading Language Bill Licea-Kane ATI Research, Inc. bill@ati.com

  2. GL2 Shading LanguageBack to the future “As far as generating pictures from data is concerned, we feel the display processor should be a specialized device, capable only of generating pictures from read-only representations in core.” Myer and Sutherland, On the Design of Display Processors.Communications of the ACM, Volume 11 Number 6, June, 1968

  3. GL2 Shading LanguageBack to the future • June 30, 1992 • OpenGL 1.0 Final Draft published

  4. GL2 Shading LanguageBack to the future “OpenGL does not provide a programming language. Its function may be controlled by turning operations on or off or specifying parameters to operations, but the rendering algorithms are essentially fixed. One reason for this decision is that, for performance reasons, graphics hardware is usually designed to apply certain operations in a specific order; replacing these operations with arbitrary algorithms is usually infeasible. Programmability would conflict with keeping the API close to the hardware and thus with the goal of maximum performance.” Segal and Akeley, The Design of the OpenGL Graphics Interface, 1994

  5. GL2 Shading LanguageBack to the future • August 23, 1993 • First OpenGL 1.0 implementation ships

  6. GL2 Shading LanguageBack to the future billa@entropy.sps.mot.com (William C. Archibald) writes:|> 1)Quite a few modern rendering techniques and renderers|> support shader function calls at arbitrary points|> across a surface being rendered. ... What I would|> _like_ to do is call the shader at visible|> (front-facing) points. Is there _any_ way to do|> this kind of thing in OpenGL?Not with the current API. One could extend OpenGL in this manner... Akeley, comp.graphics.opengl posting, 13 Oct 1993

  7. GL2 Shading LanguageBack to the present • February 27, 2003 • arb-gl2 workgroup publishesDraft OpenGL Shading Language • End construction zone

  8. GL2 Shading LanguageBack to the present • October 22, 2004 • Official OpenGL specification published • Authored by Mark Segal & Kurt Akeley

  9. GL2 Shading LanguageOverview • How we replace Fixed Function • Review Shading Language • Shading Language examples

  10. Key Points (1) • Vertex shader replaces fixed vertex processing • Fragment shader replaces fixed fragment processing • Application can pass variables to shaders (including vertices!) • Restricted variable passing to fragment shader

  11. Immediate Mode Per Vertex Operations & Primitive Assembly Polynomial Evaluator DisplayList Per Fragment Operations Frame Buffer CPU Rasterization Texture Memory Pixel Operations OpenGL Architecture

  12. Key Points (2) • Vertex shader bypasses • Vertex Transformation • Normal Transformation, Normalization • Lighting • Texture Coordinate Generation and Transformation • Fragment shader bypasses • Texture accesses & application • Fog

  13. Key Points (3) • OpenGL Shading Language is based on C • Additional data types • Some C++ features • Function overloading • Constructors • Variables declared anywhere

  14. Variable Definitions (1) • Attribute - frequently changing values passed between application and vertex shader • Uniform - infrequently changing values passed between application and both shaders • Varying - output of vertex shader passed to fragment shader

  15. Variable Definitions (2) • Sampler - accesses textures • Built-in - accesses OpenGl state information

  16. Additional Features • Common graphics functionality available from built-in functions • Shader programs are defined as part of OpenGL state • Shaders replace fixed functionality • Cannot mix-n-match functions • Shaders operate independently • Allows for parallelism • Multiple texture accesses allowed

  17. OpenGLFixed Function Vertex Vertex (object) Vertex (clip) Transform[MVP],[MV],[MV]-T Normal Vertex (eye) ColorSecondaryColor Front&BackColor [0,1] Lighting Front&BackSecondaryColor [0,1] Texgen TextureMatrixn TexCoordn TexCoordn EdgeFlag EdgeFlag

  18. GL2 Vertex Processor Vertex (object) Vertex (clip) Uniform Normal Vertex (eye) ColorSecondaryColor VertexShader Front&BackColor Front&BackSecondaryColor TexCoordn Temporaries TexCoordn EdgeFlag EdgeFlag

  19. GL2 Vertex ProcessorAdd Fog Coordinate Vertex Position Uniform Normal ClipVertex ColorSecondaryColor VertexShader Front&BackColor Front&BackSecondaryColor FogCoord FogFragCoord MultiTexCoordn Temporaries TexCoord[n] EdgeFlag EdgeFlag

  20. GL2 Vertex ProcessorGeneralize Input Attribute0 Position Uniform Attribute1 ClipVertex Attribute2 VertexShader Front&BackColor … Front&BackSecondaryColor Attributen FogFragCoord Temporaries TexCoord[n] EdgeFlag EdgeFlag

  21. GL2 Vertex ProcessorGeneralize Output Attribute0 Position Uniform Attribute1 ClipVertex Attribute2 VertexShader Varying0 … Varying1 Attributen Varying2 … Temporaries Varyingn EdgeFlag EdgeFlag

  22. GL2 Vertex ProcessorAdditional Output Attribute0 Position Uniform Attribute1 ClipVertex Attribute2 PointSize VertexShader … Varying0 Attributen Varying1 Varying2 … Temporaries Varyingn EdgeFlag EdgeFlag

  23. GL2 Vertex LimitsActive Attributes (16 vec4) Attribute0 Position Uniform Attribute1 ClipVertex Attribute2 PointSize VertexShader … Varying0 Attributen Varying1 Varying2 … Temporaries Varyingn EdgeFlag EdgeFlag

  24. GL2 Vertex LimitsUniform (512 words) Attribute0 Position Uniform Attribute1 ClipVertex Attribute2 PointSize VertexShader … Varying0 Attributen Varying1 Varying2 … Temporaries Varyingn EdgeFlag EdgeFlag

  25. GL2 Vertex LimitsVarying (32 floats) Attribute0 Position Uniform Attribute1 ClipVertex Attribute2 PointSize VertexShader … Varying0 Attributen Varying1 Varying2 … Temporaries Varyingn EdgeFlag EdgeFlag

  26. GL2 Vertex LimitsInstructions (Virtual) Attribute0 Position Uniform Attribute1 ClipVertex Attribute2 PointSize VertexShader … Varying0 Attributen Varying1 Varying2 … Temporaries Varyingn EdgeFlag EdgeFlag

  27. GL2 Vertex LimitsTemporaries (Virtual) Attribute0 Position Uniform Attribute1 ClipVertex Attribute2 PointSize VertexShader … Varying0 Attributen Varying1 Varying2 … Temporaries Varyingn EdgeFlag EdgeFlag

  28. GL2 Vertex LimitsTexture Units (1) Attribute0 Position Texture Uniform Attribute1 ClipVertex Attribute2 PointSize VertexShader … Varying0 Attributen Varying1 Varying2 … Temporaries Varyingn EdgeFlag EdgeFlag

  29. Position Position ClipVertex ClipVertex Varyingn Varyingn EdgeFlag EdgeFlag OpenGLFixed Function Rasterization Position PrimitiveAssembly ClipVertex Flatshade Varyingn Culling orClipping EdgeFlag PointLinePolygonRasterization FaceProcessing RasterPos Varyingn Pixel RectangleBitmapRasterization Varyingn Coord

  30. OpenGLFixed Function Fragment Color SecondaryColor Texn TEn Sum Fog TexCoord[n] Color [0,1] z (|ze|,f ) Depth Depth Coord Coord FrontFacing FrontFacing

  31. GL2 Fragment Processor Color Texture Uniform SecondaryColor FragmentShader TexCoord[n] Color z (|ze|,f ) Depth Depth Temporaries Coord Coord FrontFacing FrontFacing

  32. GL2 Fragment ProcessorNames Color0 Texture Uniform Color1 FragmentShader TexCoord[n] FragColor FogFragCoord FragDepth FragDepth Temporaries FragCoord FragCoord FrontFacing FrontFacing

  33. GL2 Fragment ProcessorGeneralize Input Varying0 Texture Uniform Varying1 Varying2 FragmentShader … FragColor Varyingn FragDepth FragDepth Temporaries FragCoord FragCoord FrontFacing FrontFacing

  34. GL2 Fragment LimitsUniforms (64 words) Varying0 Texture Uniform Varying1 Varying2 FragmentShader … FragColor Varyingn FragDepth FragDepth Temporaries FragCoord FragCoord FrontFacing FrontFacing

  35. GL2 Fragment LimitsVarying (32 floats) Varying0 Texture Uniform Varying1 Varying2 FragmentShader … FragColor Varyingn FragDepth FragDepth Temporaries FragCoord FragCoord FrontFacing FrontFacing

  36. GL2 Fragment LimitsInstructions (virtual) Varying0 Texture Uniform Varying1 Varying2 FragmentShader … FragColor Varyingn FragDepth FragDepth Temporaries FragCoord FragCoord FrontFacing FrontFacing

  37. GL2 Fragment LimitsTemporaries (virtual) Varying0 Texture Uniform Varying1 Varying2 FragmentShader … FragColor Varyingn FragDepth FragDepth Temporaries FragCoord FragCoord FrontFacing FrontFacing

  38. GL2 Fragment LimitsTexture Units (2) Varying0 Texture Uniform Varying1 Varying2 FragmentShader … FragColor Varyingn FragDepth FragDepth Temporaries FragCoord FragCoord FrontFacing FrontFacing

  39. GL2 Fragment LimitsFragment Output (fixed) Varying0 Texture Uniform Varying1 Varying2 FragmentShader … FragColor Varyingn FragDepth FragDepth Temporaries FragCoord FragCoord FrontFacing FrontFacing

  40. GL2 Shading LanguageToday • How we replace Fixed Function • Review Shading Language • Shading Language examples

  41. GL2 Shading LanguageTypes • void • float • int • bool • samplernD samplerCube samplerShadownD

  42. GL2 Shading LanguageTypes • void • float vec2 vec3 vec4 • mat2 mat3 mat4 • int ivec2 ivec3 ivec4 • bool bvec2 bvec3 bvec4 • samplernD samplerCube samplerShadownD

  43. GL2 Shading LanguageTypes • struct (with some minor restrictions) • No qualifiers • No bit fields • No forward references • No in-place definitions • No anonymous structures

  44. GL2 Shading LanguageTypes • arrays ( with some minor restrictions) • one dimensional • size is integral constant expression • can declare unsized array, but… • specify size and type of array ONCE • any basic type and struct • NO initialization at declaration

  45. GL2 Shading LanguageReserved Types • half hvec2 hvec3 hvec4 • fixed fvec2 fvec3 fvec4 • double dvec2 dvec3 dvec4 • sampler2DRect sampler3DRect

  46. GL2 Shading LanguageScope • global • outside function • shared globals must be same type • local (nested) • within function definition • within function • within compound statement

  47. GL2 Shading LanguageType Qualifiers • const • attribute • uniform • varying • (default)

  48. GL2 Shading LanguageOperators • grouping: () • array subscript: [] • function call and constructor: () • field selector and swizzle: . • postfix: ++ -- • prefix: ++ -- + - !

  49. GL2 Shading LanguageOperators • binary: * / + - • relational: < <= > >= • equality: == != • logical: && ^^ || • selection: ?: • assignment: = *= /= += -=

  50. GL2 Shading LanguageReserved Operators • prefix: ~ • binary: % • bitwise: << >> & ^ | • assignment: %= <<= >>= &= ^= |=

More Related