How it works...

The buildOffsetTex function creates our three-dimensional texture of random offsets. The first parameter, texSize, defines the width and height of the texture. To create the preceding images, I used a value of 8. The second and third parameters, samplesU and samplesV, define the number of samples in the u and v directions. I used a value of 4 and 8, respectively, for a total of 32 samples. The u and v directions are arbitrary axes that are used to define a grid of offsets. To understand this, take a look at the following diagram:

The offsets are initially defined to be centered on a grid of size samplesU x samplesV (4 x 4 in ...

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.