I am trying to send an array of float values(height map) to GLSL as a GL_TEXTURE_2D. While I have the samplers set right, the issue comes from the clamping that happens when I upload the texture using glTexImage2D().
glGenTextures(1, &_idnewTID);
glBindTexture(GL_TEXTURE_2D, _idnewTID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, regMesh._cols, regMesh._rows, 0, GL_RED, GL_FLOAT, regMesh._heightMap);
The values that I am sending are in the range 900.0f to 1590.0f. But this gets completely clamped out to 1.0f as it loads into the GL_TEXTURE_2D
.
How do I preserve the values from being clamped to [0,1]. How should I modify the glTexImage2D() function to get this achieved?
P.S I know the sampler works fine because when I divide the values by 1500.0f and upload it to GPU and scale it in the shader, I get the proper height map structure.
First, you should always use a sized internal format (that's the third parameter of glTexImage*
). GL_RED
leaves too much up to the implementation.
Second, you are trying to store and use floating-point data. So you need to choose a floating-point internal format, rather than a normalized integer one. If the internal format's size doesn't end in F
, then it's not storing floating-point values. GL_R32F
would be appropriate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With