How it works...

In the preceding code for computing the Gaussian weights (code segment 3), the function named gauss computes the one-dimensional Gaussian function where the first argument is the value for x and the second argument is sigma squared. Note that we only need to compute the positive offsets because the Gaussian is symmetric about zero. As we are only computing the positive offsets, we need to carefully compute the sum of the weights. We double all of the non-zero values because they will be used twice (for the positive and negative offsets).

The first pass (function pass1) renders the scene to a texture using the Blinn-Phong reflection model.

The second pass (function pass2) applies the weighted vertical sum of the Gaussian blur ...

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.