How to do it...

To generate a bloom effect, perform the following steps:

  1. In the first pass, render the scene to the framebuffer with a high-res backing texture.
  2. In the second pass, switch to a framebuffer containing a high-res texture that is smaller than the size of the full render. In the example code, we use a texture that is one-eighth the size. Draw a fullscreen quad to initiate the fragement shader for each pixel, and in the fragment shader sample from the high-res texture, and write only those values that are larger than LumThresh. Otherwise, color the pixel black:
vec4 val = texture(HdrTex, TexCoord); 
if( luminance(val.rgb) > LumThresh ) 
  FragColor = val; 
else 
  FragColor = vec4(0.0); 
  1. In the third and fourth passes, apply the Gaussian ...

Get OpenGL 4 Shading Language Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.