Book Image

OpenGL 4 Shading Language Cookbook - Third Edition

By : David Wolff
Book Image

OpenGL 4 Shading Language Cookbook - Third Edition

By: David Wolff

Overview of this book

OpenGL 4 Shading Language Cookbook, Third Edition provides easy-to-follow recipes that first walk you through the theory and background behind each technique, and then proceed to showcase and explain the GLSL and OpenGL code needed to implement them. The book begins by familiarizing you with beginner-level topics such as compiling and linking shader programs, saving and loading shader binaries (including SPIR-V), and using an OpenGL function loader library. We then proceed to cover basic lighting and shading effects. After that, you'll learn to use textures, produce shadows, and use geometry and tessellation shaders. Topics such as particle systems, screen-space ambient occlusion, deferred rendering, depth-based tessellation, and physically based rendering will help you tackle advanced topics. OpenGL 4 Shading Language Cookbook, Third Edition also covers advanced topics such as shadow techniques (including the two of the most common techniques: shadow maps and shadow volumes). You will learn how to use noise in shaders and how to use compute shaders. The book provides examples of modern shading techniques that can be used as a starting point for programmers to expand upon to produce modern, interactive, 3D computer-graphics applications.
Table of Contents (17 chapters)
Title Page
Packt Upsell
Contributors
Preface
Index

Index

A

  • active uniform variables
    • listing / Getting a list of active uniform variables, How it works...
  • active vertex input attributes
    • listing / Getting a list of active vertex input attributes and locations, Getting ready, How it works...
  • adjacency modes / Drawing silhouette lines using the geometry shader
  • airy disc / Creating a bloom effect
  • aliasing artifacts / Using multisample anti-aliasing
  • alpha maps
    • using, to discard pixels / Using alpha maps to discard pixels, How it works...
  • ambient component / Implementing the Phong reflection model
  • ambient occlusion / Screen space ambient occlusion
  • anti-aliasing / Using multisample anti-aliasing
  • application binary interface (ABI) / Using a loading library to access the latest OpenGL functionality
  • arrays
    • passing, to functions / Passing arrays or structures to a function
  • attribute indexes
    • specifying, without layout qualifiers / Specifying attribute indexes without using layout qualifiers
  • attribute location
    • obtaining / Getting a list of active vertex input attributes and locations, Getting ready, How it works...

B

  • Bernstein polynomials / Tessellating a curve
  • Bidirectional Reflectance Distribution Function (BRDF) / Diffuse image-based lighting
  • billboarding / How it works...
  • black holes / Implementing a particle simulation with the compute shader
  • blending functions / Tessellating a curve
  • Blinn-Phong reflection model
    • about / The Blinn-Phong reflection model
    • implementing / The Blinn-Phong reflection model, How it works...
    • reference / The Blinn-Phong reflection model
  • bloom effect
    • creating / Creating a bloom effect, Getting ready, How to do it..., How it works...
  • bright-pass filter / Creating a bloom effect
  • buffer ping-ponging / Creating a particle system using transform feedback
  • bump map / Parallax mapping

C

  • C++ shader program class
    • building / Building a C++ shader program class, How to do it..., How it works...
  • call by copy-restore / How it works...
  • call by value-result / How it works...
  • call by value-return / How it works...
  • canonical viewing volume / Rendering shadows with shadow maps
  • Carmack's reverse / There's more...
  • cartoon shading effect
    • creating / Creating a cartoon shading effect, Getting ready, There's more...
  • cel shading / Creating a cartoon shading effect
  • characteristic specular reflectance / A physically-based reflection model
  • chromatic aberration / Chromatic aberration
  • chromaticity / Implementing HDR lighting with tone mapping
  • CIE XYZ color space / Implementing HDR lighting with tone mapping
  • cloth simulation
    • with compute shader / Using the compute shader for cloth simulation, Getting ready, How to do it..., How it works..., There's more...
  • cloud-like effect
    • creating / Creating a cloud-like effect, Getting ready, How it works..., There's more...
  • cloud generation
    • reference / See also
  • compatibility profiles / Profiles – core versus compatibility
  • compute shader
    • about / Introduction
    • compute space / Compute space and work groups
    • work groups / Compute space and work groups
    • compute shape / Compute space and work groups
    • executing / Executing the compute shader
    • particle simulation, implementing / Implementing a particle simulation with the compute shader, How to do it..., How it works...
    • fractal texture, creating / Creating a fractal texture using the compute shader, How to do it..., How it works...
    • using, for cloth simulation / Using the compute shader for cloth simulation, Getting ready, How to do it..., How it works..., There's more...
    • edge detection filter, implementing / Implementing an edge detection filter with the compute shader, How to do it..., How it works...
  • convolution filters / Introduction
  • core profile / Profiles – core versus compatibility
  • cube map / Simulating reflection with cube maps
    • reflection, simulating / Simulating reflection with cube maps, How to do it..., How it works...
    • refraction, simulating / Simulating refraction with cube maps, Getting ready, How it works...
  • cubic Bezier curve / Tessellating a curve
  • curve
    • tessellating / Tessellating a curve, How to do it..., How it works..., There's more...

D

  • 2D quad
    • tessellating / Tessellating a 2D quad, Getting ready, How to do it..., How it works...
  • 2D texture
    • applying / Applying a 2D texture, Getting ready, How to do it..., How it works...
    • sampler binding, specifying within GLSL / Specifying the sampler binding within GLSL
  • 3D surface
    • tessellating / Tessellating a 3D surface, How to do it..., How it works...
  • debugging
    • with two-sided rendering / Using two-sided rendering for debugging
  • debug messages
    • obtaining / Getting debug messages, Getting ready, How it works..., There's more...
  • deferred shading
    • using / Using deferred shading, Getting ready, How it works..., There's more...
    • about / Using deferred shading
  • deprecation model / Profiles – core versus compatibility
  • depth shadows / Introduction
  • depth test
    • configuring / Configuring the depth test, How it works...
  • diffuse component / Implementing the Phong reflection model
  • diffuse convolution map / Diffuse image-based lighting
  • diffuse image-based lighting
    • implementing / Diffuse image-based lighting, How to do it...
  • diffuse reflection / Diffuse and per-vertex shading with a single point light source
  • diffuse reflectivity / Diffuse and per-vertex shading with a single point light source
  • diffuse shading
    • with single point light source / Diffuse and per-vertex shading with a single point light source, How to do it..., How it works..., There's more...
  • directional light source
    • for shading / Shading with a directional light source, How it works...
    • about / Shading with a directional light source
  • disintegration effect
    • creating / Creating a disintegration effect, Getting ready, How it works...

E

  • edge detection / Applying an edge detection filter
  • edge detection filter
    • applying / Applying an edge detection filter, Getting ready, How to do it..., There's more...
    • optimization techniques / Optimization techniques
    • implementing, with compute shader / Implementing an edge detection filter with the compute shader, How to do it..., How it works...
  • element arrays
    • using / Using element arrays
  • environment mapping / Simulating reflection with cube maps
  • equirectangular panoramic map / Diffuse image-based lighting

F

  • feathering / There's more...
  • filter kernel / Applying an edge detection filter
  • fire
    • simulating, with particles / Simulating fire with particles, Getting ready, How to do it...
  • flat shading
    • about / Implementing flat shading
    • implementing / Implementing flat shading, How it works...
  • fog
    • simulating / Simulating fog, There's more...
    • distance, computing from eye / Computing distance from the eye
  • forward-compatible context / Profiles – core versus compatibility
  • fractal texture
    • creating, with compute shader / Creating a fractal texture using the compute shader, How to do it..., How it works...
  • fragments
    • discarding, to create perforated look / Discarding fragments to create a perforated look, How it works...
  • fragment shaders / Vertex and fragment shaders
  • framebuffer object (FBO) / Introduction, Rendering to a texture, How to do it..., Getting ready, Getting ready
  • Fresnel equations / The Fresnel equations
  • Fresnel reflection / A physically-based reflection model
  • functions
    • using, in shaders / Using functions in shaders, There's more...
    • const qualifier / The const qualifier
    • overloading / Function overloading
    • arrays, passing / Passing arrays or structures to a function
    • structures, passing / Passing arrays or structures to a function
  • fuzzy systems / Creating a particle fountain

G

  • g-buffer / Using deferred shading
  • gamma correction
    • used, for improving image quality / Using gamma correction to improve image quality, How to do it..., There's more...
  • Gaussian blur filter
    • applying / Applying a Gaussian blur filter, Getting ready, How it works...
    • about / Applying a Gaussian blur filter
  • General Purpose Computing on Graphics Processing Units (GPGPU) / GLSL
  • geometry shader
    • shadows, creating / How it works..., There's more...
  • geometry shader (GS)
    • about / The geometry shader
    • point sprites, using / Point sprites with the geometry shader, Getting ready, How to do it..., How it works..., There's more...
    • silhouette lines, drawing / Drawing silhouette lines using the geometry shader, How to do it..., How it works..., There's more...
    • shadows, creating / Creating shadows using shadow volumes and the geometry shader, How to do it..., How it works...
  • GGX / A physically-based reflection model
  • GLAD
    • reference / Using a loading library to access the latest OpenGL functionality, Getting ready
  • glDrawElements function
    • reference / Using element arrays
  • global index / Compute space and work groups
  • glossy reflectance / A physically-based reflection model
  • glTexParameteri
    • reference / How it works...
  • Gouraud shading / Per-vertex versus per-fragment, Using per-fragment shading for improved realism
  • Graphics Processing Units (GPUs) / Introduction

H

  • HDR lighting
    • implementing, with tone mapping / Implementing HDR lighting with tone mapping, Getting ready, How to do it..., See also
  • height map / Parallax mapping
  • High Dynamic Range imaging (HDR imaging) / Implementing HDR lighting with tone mapping
  • High Dynamic Range rendering (HDR rendering) / Implementing HDR lighting with tone mapping
  • homogeneous clip coordinates / Rendering shadows with shadow maps

I

  • image-based lighting / Diffuse image-based lighting
  • image load/store / Implementing order-independent transparency
  • image quality
    • improving, with gamma correction / Using gamma correction to improve image quality, How to do it..., There's more...
  • immutable storage textures / Introduction
  • indexed buffer targets / How it works...
  • instanced meshes
    • particle system, creating / Creating a particle system using instanced meshes, Getting ready, How to do it..., How it works...
  • instance name
    • using, with uniform block / Using an instance name with a uniform block
  • instancing / Creating a particle fountain
  • interleaved arrays / Interleaved arrays

J

  • Jet Propulsion Laboratory (JPL) / The Blinn-Phong reflection model

L

  • Lambertian reflectance / A physically-based reflection model
  • layout qualifiers
    • using, with uniform block / Using layout qualifiers with uniform blocks
    • using / Using layout qualifiers
  • level-of-detail (LOD) algorithms / The tessellation shaders, Tessellating based on depth
  • loading library
    • used, for accessing OpenGL functionality / Using a loading library to access the latest OpenGL functionality, How to do it..., How it works..., See also
  • locality of reference / Interleaved arrays

M

  • Mandelbrot set / Creating a fractal texture using the compute shader
  • mathematics
    • with OpenGL Mathematics (GLM) / Using GLM for mathematics, How to do it..., There's more..., See also
  • metalness workflow / A physically-based reflection model
  • microfacet distribution function / A physically-based reflection model
  • microfacet theory / A physically-based reflection model
  • microgeometry normal distribution function / A physically-based reflection model
  • Monte Carlo estimator / Diffuse image-based lighting
  • multiple positional lights
    • for shading / Shading with multiple positional lights, How it works...
  • multiple textures
    • applying / Applying multiple textures, How it works..., There's more...
  • multisample anti-aliasing (MSAA)
    • using / Using multisample anti-aliasing, There's more...
    • about / Using multisample anti-aliasing

N

  • night-vision effect
    • creating / Creating a night-vision effect, How to do it..., How it works...
  • noise texture
    • creating, with GLM / Creating a noise texture using GLM, Getting ready, There's more...
  • nonlocal viewer
    • using / Using a nonlocal viewer
    • about / Using a nonlocal viewer
  • normal map
    • using / Using normal maps, How it works...
    • about / Parallax mapping
  • normal mapping / Using normal maps
  • NVIDIA plugin
    • reference / Using normal maps

O

  • object handle / How it works...
  • object local coordinate system / Using normal maps
  • octave frequency / Creating a noise texture using GLM
  • OpenGL
    • version, determining / Determining the GLSL and OpenGL version, How it works...
  • OpenGL Extension Wrangler (GLEW)
    • about / Using a loading library to access the latest OpenGL functionality
    • reference / See also
  • OpenGL functionality
    • accessing, with loading library / Using a loading library to access the latest OpenGL functionality, How to do it..., How it works..., There's more...
  • OpenGL function loader / Using a loading library to access the latest OpenGL functionality
  • OpenGL Loading Library / Using a loading library to access the latest OpenGL functionality
  • OpenGL Mathematics (GLM)
    • used, for mathematics / Using GLM for mathematics, How to do it..., There's more...
    • about / Using GLM for mathematics
    • using, as input to OpenGL / Using the GLM types as input to OpenGL
    • reference / See also
    • noise texture, creating / Creating a noise texture using GLM, Getting ready, There's more...
  • OpenGL shader validator
    • reference / Getting ready
  • OpenGL Shading Language (GLSL)
    • about / Introduction, GLSL
    • profiles / Profiles – core versus compatibility
    • determining / Determining the GLSL and OpenGL version, How it works...
  • order-independent transparency
    • implementing / Implementing order-independent transparency, Getting ready, How to do it..., How it works...

P

  • paint-spatter effect
    • creating / Creating a paint-spatter effect, Getting ready, There's more...
  • parallax mapping
    • about / Parallax mapping
    • implementing / Getting ready
  • particle fountain
    • creating / Creating a particle fountain, Getting ready, How it works..., There's more...
  • particles
    • fire, simulating / Simulating fire with particles, Getting ready, How to do it...
    • smoke, simulating / Simulating smoke with particles, How to do it...
  • particle simulation
    • implementing, with compute shader / Implementing a particle simulation with the compute shader, How to do it..., How it works...
  • particle system
    • creating, with transform feedback / Creating a particle system using transform feedback, Getting ready, How to do it..., How it works...
    • creating, with instanced meshes / Creating a particle system using instanced meshes, Getting ready, How to do it..., How it works...
  • patch primitive / The tessellation shaders
  • penumbra / There's more...
  • per-fragment shading
    • used, for improved realism / Using per-fragment shading for improved realism, How to do it...
  • per-vertex shading
    • with single point light source / Diffuse and per-vertex shading with a single point light source, How to do it..., How it works..., There's more...
    • versus per-fragment shading / Per-vertex versus per-fragment
  • percentage-closer filtering (PCF)
    • shadow edges, anti-aliasing / Anti-aliasing shadow edges with PCF, How to do it..., How it works...
    • about / Anti-aliasing shadow edges with PCF
  • perforated look
    • creating, with discarded fragments / Discarding fragments to create a perforated look, How it works...
  • Perlin noise
    • reference / Introduction
  • Perlin noise generator / Creating a noise texture using GLM
  • perspective division / Rendering shadows with shadow maps
  • Phong interpolation / Using per-fragment shading for improved realism
  • Phong reflection model
    • about / Learning the basics first
    • implementing / Implementing the Phong reflection model, Getting ready, How it works...
    • nonlocal viewer, using / Using a nonlocal viewer
    • per-vertex shading, versus per-fragment shading / Per-vertex versus per-fragment
    • directional lights / Directional lights
    • light attenuation, with distance / Light attenuation with distance
  • Phong shading / Using per-fragment shading for improved realism
  • Phong shading model / Implementing the Phong reflection model
  • physically-based reflection model
    • implementing / A physically-based reflection model, Getting ready, How to do it..., There's more...
  • physically-based rendering (PBR) / A physically-based reflection model
  • pixels
    • discarding, with alpha maps / Using alpha maps to discard pixels, How it works...
  • point sprites
    • about / Point sprites with the geometry shader
    • with geometry shader / Point sprites with the geometry shader, Getting ready, How to do it..., How it works..., There's more...
  • procedural texture / Rendering to a texture
  • profiles
    • about / Profiles – core versus compatibility
    • core profile / Profiles – core versus compatibility
    • compatibility profiles / Profiles – core versus compatibility
  • programmable shaders / Learning the basics first
  • program pipelines
    • using / Using program pipelines, How to do it..., How it works..., There's more...
  • projected texture
    • applying / Applying a projected texture, How to do it..., How it works...
  • projection matrix (P) / Applying a projected texture
  • projective texture mapping
    • about / Applying a projected texture
    • reference / Applying a projected texture
  • provoking vertex / How it works...

R

  • random sampling
    • soft shadow edges, creating / Creating soft shadow edges with random sampling, How to do it..., How it works..., There's more...
  • reflectance equation / A physically-based reflection model
  • reflection
    • simulating, with cube map / Simulating reflection with cube maps, How to do it..., How it works...
  • refraction
    • simulating, with cube map / Simulating refraction with cube maps, Getting ready, How it works...
    • about / Simulating refraction with cube maps
    • Fresnel equations / The Fresnel equations
    • chromatic aberration / Chromatic aberration
    • through both sides of object / Refracting through both sides of the object
  • rendering equation / A physically-based reflection model
  • Runge-Kutta integration / Creating a particle system using transform feedback
  • rusted metal effect
    • creating / Creating a rusted metal effect, How to do it..., How it works...

S

  • sampler objects
    • about / Using sampler objects
    • using / Using sampler objects, How it works...
  • sampler variable / Applying a 2D texture
  • Schlick approximation / A physically-based reflection model
  • screen space ambient occlusion (SSAO)
    • about / Screen space ambient occlusion
    • implementing / Screen space ambient occlusion, Getting ready, How it works...
  • seamless noise texture
    • creating / Creating a seamless noise texture, Getting ready
  • separable shader objects / Using program pipelines
  • shaded mesh
    • wireframe, drawing / Drawing a wireframe on top of a shaded mesh, How to do it..., How it works..., There's more...
  • shader
    • data, sending with uniform variables / Sending data to a shader using uniform variables, There's more...
  • shader binary
    • saving / Saving and loading a shader binary, How to do it..., How it works...
    • loading / Saving and loading a shader binary, How to do it..., How it works...
  • shader pipeline / The shader pipeline extended
  • shader program
    • linking / Linking a shader program, Getting ready, How to do it..., How it works...
    • shader input/output variables / Shader input/output variables
    • deleting / Deleting a shader program
  • shader programs / GLSL
  • shaders
    • about / GLSL, Introduction
    • compiling / Compiling a shader, Getting ready, How to do it..., How it works...
    • shader object, deleting / Deleting a shader object
    • data, sending with vertex attributes / Sending data to a shader using vertex attributes and vertex buffer objects, Getting ready, How to do it..., How it works...
    • data, sending with vertex buffer objects / Sending data to a shader using vertex attributes and vertex buffer objects, Getting ready, How to do it..., How it works...
    • fragment shaders / Vertex and fragment shaders
    • vertex shaders / Vertex and fragment shaders
    • programmable shaders / Learning the basics first
    • functions, using / Using functions in shaders, There's more...
  • shader storage buffer objects (SSBO) / Implementing order-independent transparency
  • shading
    • with multiple positional lights / Shading with multiple positional lights, How it works...
    • with directional light source / Shading with a directional light source, How it works...
  • shadow acne effect / How it works...
  • shadow map
    • shadows, rendering / Rendering shadows with shadow maps, How to do it..., How it works...
    • about / Rendering shadows with shadow maps
    • aliasing / Aliasing
    • back faces, rendering / Rendering back faces only for the shadow map
  • shadow mapping / Introduction
  • shadows
    • creating, with geometry shader / Creating shadows using shadow volumes and the geometry shader, How to do it..., How it works..., There's more...
    • creating, with shadow volumes / Creating shadows using shadow volumes and the geometry shader, How to do it..., How it works..., There's more...
  • shadow volumes / Creating shadows using shadow volumes and the geometry shader
  • silhouette edges / Creating shadows using shadow volumes and the geometry shader
  • silhouette lines
    • drawing, with geometry shader / Drawing silhouette lines using the geometry shader, How to do it..., How it works..., There's more...
  • skybox / Simulating reflection with cube maps
  • smoke
    • simulating, with particles / Simulating smoke with particles, How to do it...
  • Snell's law / Simulating refraction with cube maps
  • Sobel operator / Applying an edge detection filter
  • soft shadow edges
    • creating, with random sampling / Creating soft shadow edges with random sampling, How to do it..., How it works..., There's more...
  • specular component / Implementing the Phong reflection model
  • specular highlights / Implementing the Phong reflection model
  • SPIR-V shader program
    • loading / Loading a SPIR-V shader program, How to do it..., There's more...
  • spotlight
    • simulating / Simulating a spotlight, Getting ready, How it works...
  • Standard, Portable Intermediate Representation - V (SPIR-V)
    • about / Loading a SPIR-V shader program
    • reference / Loading a SPIR-V shader program
  • stb_image.h file
    • reference / How it works...
  • std140 layout
    • reference / Using layout qualifiers with uniform blocks
  • steep parallax mapping
    • with self shadowing / Steep parallax mapping with self shadowing, How it works...
    • about / Steep parallax mapping with self shadowing
  • structures
    • passing, to functions / Passing arrays or structures to a function
  • subroutines
    • used, for selecting shader functionality / Using subroutines to select shader functionality, How to do it..., How it works..., There's more...
  • surface
    • animating, with vertex displacement / Animating a surface with vertex displacement, Getting ready, There's more...

T

  • tangent space / Using normal maps
  • tangent vectors
    • reference / Using normal maps
  • tessellation
    • based on depth / Tessellating based on depth, How to do it..., How it works...
  • Tessellation Control Shader (TCS) / The shader pipeline extended
  • Tessellation Evaluation Shader (TES) / The shader pipeline extended
  • tessellation primitive generator (TPG) / The tessellation shaders
  • tessellation shaders / The tessellation shaders
  • texture
    • rendering to / Rendering to a texture, How to do it..., How it works...
  • texture channel / How it works...
  • texture swim / There's more...
  • tone mapping
    • HDR lighting, implementing / Implementing HDR lighting with tone mapping, Getting ready, How to do it..., See also
    • about / Implementing HDR lighting with tone mapping
  • Tone Mapping Operator (TMO) / Implementing HDR lighting with tone mapping
  • toon shading / Creating a cartoon shading effect
  • transform feedback
    • about / Introduction, There's more..., There's more...
    • particle system, creating / Creating a particle system using transform feedback, Getting ready, How to do it..., How it works...
    • layout qualifiers, using / Using layout qualifiers
    • results, querying / Querying transform feedback results
  • triangle altitude / Drawing a wireframe on top of a shaded mesh
  • two-sided rendering
    • using, for debugging / Using two-sided rendering for debugging
  • two-sided shading
    • implementing / Implementing two-sided shading, How to do it..., There's more...

U

  • uniform block
    • using / Using uniform blocks and uniform buffer objects, How to do it..., How it works...
    • instance name, using / Using an instance name with a uniform block
    • layout qualifiers, using / Using layout qualifiers with uniform blocks
  • uniform buffer object
    • using / Using uniform blocks and uniform buffer objects, How to do it..., How it works..., There's more...
    • about / Using uniform blocks and uniform buffer objects
  • uniform variables
    • data, sending to shader / Sending data to a shader using uniform variables, There's more...

V

  • Verlet integration / Creating a particle system using transform feedback
  • vertex array object (VAO) / How it works..., Getting ready
  • vertex attributes
    • data, sending to shader / Sending data to a shader using vertex attributes and vertex buffer objects, Getting ready, How to do it..., How it works...
    • separate attribute format / Separate attribute format
    • fragment shader output / Fragment shader output
  • vertex buffer objects
    • data, sending to shader / Sending data to a shader using vertex attributes and vertex buffer objects, Getting ready, How to do it..., How it works...
  • vertex displacement
    • surface, animating / Animating a surface with vertex displacement, Getting ready, There's more...
  • vertex shaders / Vertex and fragment shaders
  • view matrix (V) / Applying a projected texture

W

  • wireframe
    • drawing, on top of shaded mesh / Drawing a wireframe on top of a shaded mesh, How to do it..., How it works..., There's more...
  • wood-grain effect
    • creating / Creating a wood-grain effect, How to do it..., How it works..., There's more...

Z

  • z-fail technique / There's more...
  • z-fighting / There's more...
  • z-pass technique / There's more...