How it works...

The GLM library provides 2D, 3D, and 4D coherent noise via the glm::perlin function. It returns a float roughly between -1 and 1. We start by allocating a buffer named data to hold the generated noise values.

Next, we loop over each texel and compute the x and y coordinates (normalized). Then, we loop over octaves. Here, we compute the sum of the previous equation, storing the first term in the first component, the first two terms in the second, and so on. The value is scaled into the range from 0 to 1, then multiplied by 255 and cast to a byte.

The next few lines of code should be familiar. Texture memory is allocated with glTexStorage2D and the data is loaded into GPU memory using glTexSubImage2D.

Finally, the array named data is deleted, as it is no longer needed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.140.108