How it works...

The fragment shader is broken into two subroutine functions, one for each pass. Within the pass1 function, we simply apply the Phong shading model to the fragment. The result is written to the FBO, which contains a texture to be used in the second pass.

In the second pass, the pass2 function is executed. We start by retrieving a noise value (noise), and the color from the render texture from the first pass (color). Then, we compute the luminance value for the color and store that result in the green variable. This will eventually be used as the green component of the final color.

We use the same texture coordinates here, assuming that the noise texture is the same size as the render texture. It would be more space efficient ...

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.