1 / 103

GL2 Shading Language

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

apu
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 LanguageToday • How we replace Fixed Function • Review Shading Language • Shading Language examples • Procedural Shader demo

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

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

  11. GL2 Vertex ProcessorNames Vertex Position Uniform Normal ClipVertex ColorSecondaryColor VertexShader Front&BackColor Front&BackSecondaryColor MultiTexCoordn Temporaries TexCoord[n] EdgeFlag EdgeFlag

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  33. GL2 Shading LanguageToday • How we replace Fixed Function • Review Shading Language • Shading Language examples • Procedural Shader demo

  34. GL2 Shading LanguagePreprocessor directives # #define #undef #if #ifdef #ifndef #else #elif #endif #error #pragma optimize(on|off) #pragma debug(on|off) #line line file __LINE__ __FILE__ __VERSION__ // comment /* comment */

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

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

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

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

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

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

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

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

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

  44. GL2 Shading LanguageConstructors • float() • int() • bool() • vec2() vec3() vec4() • mat2() mat3() mat4()

  45. GL2 Shading LanguageScalar Constructors float f; int i; bool b; float( b)// b=true?1.0:0.0; int( b)// b=true?1:0; bool( b)// identity float( i)// int to float int( i)// identity bool( i)// i!=0?true:false; float( f)// identity int( f)// float to int bool( f)// f!=0.0?true:false;

  46. GL2 Shading LanguageVector Constructors vec2 v2; vec3 v3; vec4 v4; vec2( 1.0 ,2.0) vec3( 0.0 ,0.0 ,1.0) vec4( 1.0 ,0.5 ,0.0 ,1.0) vec4( 1.0)// all 1.0 vec4( v2 ,v2)// different... vec4( v3 ,1.0)// ...types vec2( v4) float( v4)

  47. GL2 Shading LanguageMatrix Constructors vec4 v4; mat4 m4; mat4( 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10., 11., 12., 13., 14., 15., 16.) // row major mat4( v4, v4, v4, v4) mat4( 1.0)// identity matrix mat3( m4)// upper 3x3 vec4( m4)// 1st column float( m4) // upper 1x1

  48. GL2 Shading LanguageStructure Constructors struct light { float intensity; vec3 position; } light headLight = light( 0.2 ,vec3( 0.0 ,0.0, 1.0)); // same as light headLight; headLight.intensity = 0.2; headLight.position = vec3( 0.0 ,0.0, 1.0);

  49. GL2 Shading LanguageComponents • component accessor for vectors • xyzw rgba stpq [i] • component accessor for matrices • [i] [i][j]

  50. GL2 Shading LanguageVector components vec2 v2; vec3 v3; vec4 v4; v2.x// is a float v2.z// wrong: component undefined for type v4.rgba// is a vec4 v4.stp// is a vec3 v4.b// is a float v4.xy// is a vec2 v4.xgp // wrong: mismatched component sets

More Related