Normalization of a floating point texture
Introduction
As I’ve explained in my previous post, floating point textures don’t clamp values to the range [0.0, 1.0], so if you want to use them you have to normalize the values after the computation.
In this post I’m going to explain the technique I’m using to normalize the floating point textures so to display them correctly after the computation.
Normalization
The normalization formula is quite simple, it’s:
norm_value = (value - min) / (max - min);
Where min and max are the smallest and the biggest values stored in the texture.
The first thing to do to normalize a texture is to find the min and max values and the simplest way to do that is dumping the texture data into a float array using the function glGetTexImage, after that it’s easy to find the required values with a simple for cycle.
The last step is to apply the normalization formula on all the texels, I do that using a fragment shader.
Times
The average execution times for the normalization are the following:
- dump data with glGetTexImage: 30 ms.
- find min and max: 5 ms.
- normalization shader: 2 ms.
so the total average time is 37 ms.