I need to normalize a floating point texture to the range [0.0, 1.0].
The technique I’m using is the following (more info in this post from my blog):
[ul][li] dump the texture data into a fp array using glGetTexImage look for min and max values in the array normalize the texture values using a fragment shader based on the formula norm_value = (value - min) / (max - min);[/ul][/li]Does it exist a better way to do this (maybe without dumping the texture data, so using just shaders)???
Well you can do it on the GPU. I’d suggest you “downsample” your texture in a “mipmap” fashion, so for the top level you find the max and min in each 2x2 texel block and a texture of half the dimensions. The repeat until you’re down to 1x1, which then contains the min and max of the entire texture. Then you can sample this texture in your shader and normalize the texture on the GPU.
That looks a very good idea!
Do you have any example code/reference about MipMap textures, GLSL shaders and FBO?
I have some doubts about using MipMap textures and FBO with a fragment shader…