OpenGL Shading Language (3rd Edition)
Format: PDF / Kindle (mobi) / ePub
OpenGL® Shading Language, Third Edition, extensively updated for OpenGL 3.1, is the experienced application programmer’s guide to writing shaders. Part reference, part tutorial, this book thoroughly explains the shift from fixed-functionality graphics hardware to the new era of programmable graphics hardware and the additions to the OpenGL API that support this programmability. With OpenGL and shaders written in the OpenGL Shading Language, applications can perform better, achieving stunning graphics effects by using the capabilities of both the visual processing unit and the central processing unit.
In this book, you will find a detailed introduction to the OpenGL Shading Language (GLSL) and the new OpenGL function calls that support it. The text begins by describing the syntax and semantics of this high-level programming language. Once this foundation has been established, the book explores the creation and manipulation of shaders using new OpenGL function calls.
OpenGL® Shading Language, Third Edition, includes updated descriptions for the language and all the GLSL entry points added though OpenGL 3.1, as well as updated chapters that discuss transformations, lighting, shadows, and surface characteristics. The third edition also features shaders that have been updated to OpenGL Shading Language Version 1.40 and their underlying algorithms, including
- Traditional OpenGL fixed functionality
- Stored textures and procedural textures
- Image-based lighting
- Lighting with spherical harmonics
- Ambient occlusion and shadow mapping
- Volume shadows using deferred lighting
- Ward’s BRDF model
The color plate section illustrates the power and sophistication of the OpenGL Shading Language. The API Function Reference at the end of the book is an excellent guide to the
API entry points that support the OpenGL Shading Language.
destination buffer can be modified. The glStencilMask function controls the writing of particular bits in the stencil components of the destination buffer. Values in the framebuffer can be initialized with glClear. Values that will be used to initialize the color components, depth components, stencil components, and accumulation buffer components are set with glClearColor, glClearDepth, glClearStencil, and glClearAccum, respectively. The accumulation buffer operation can be specified with
multiple shader objects (and the subsequent From the Library of STEPHEN EISEMAN 56 Chapter 2: Basics need for a linker built into OpenGL) is a key difference between the OpenGL Shading Language and assembly-level APIs such as those provided by the OpenGL extensions ARB_vertex_program and ARB_fragment_program. For more complex shading tasks, separately compiled shader objects are a much more attractive alternative than a single, monolithic block of assembly-level code. The link step resolves
glVertexAttrib—Send generic vertex attributes to OpenGL one vertex at a time • glVertexAttribPointer—Specify location and organization of generic vertex attributes to be sent to OpenGL with vertex arrays These new entry points are all discussed in more detail in Chapter 7. Reference pages for all of the OpenGL Shading Language API entry points defined by these extensions are included in Appendix B at the back of this book. 2.6 Key Benefits The following key benefits are derived from the
a = a * b where the expression a * b must be semantically valid, and the type of the expression a * b must be the same as the type of a. The other assignment operators behave similarly. The ternary selection operator (?:) operates on three expressions: exp1 ? exp2 : exp3. This operator evaluates the first expression, which must result in a scalar Boolean. If the result is true, the operator selects to evaluate the second expression; otherwise, it selects to evaluate the third expression. Only
coord to access the 2D texture currently specified by sampler: uvec4 textureProjLod (usampler2D sampler, vec4 coord , float lod ) uvec4 textureProjGrad (usampler2D sampler, vec3 coord, vec2 dPdx, vec2 dPdy) Combinations of the suffixes Proj, Lod, Grad, and Offset are as described earlier. uvec4 textureProjGrad (usampler2D sampler, vec4 coord, vec2 dPdx, vec2 dPdy) uvec4 textureProjOffset (usampler2D sampler, vec3 coord, ivec2 offset [, float bias] ) uvec4 textureProjOffset (usampler2D sampler,