Texture2d float values?

So I was messing around with a floating point texture in a GLSL shader and I noticed that the value returned from texture2d(sampler2d, vec2) seems to clamp beyond [0,1]. Is there anyway to get it to use the actual value stored in the texture even if its beyond those values?

I understand when actually rendering the fragment color it will clamp beyond [0,1] unless this can be changed to, but I was planning on doing some multitexturing stuff, and being able to get values beyond [0,1] would be really helpful.

Does anyone know of a way to change this?

The value in texture can be beyond [0, 1], it depends on what you fill in.

Use appropriate value with the right internal texture format when you create your texture :
glTexImage2D(GL_TEXTURE_2D,0,internalFormat,…)

Some of them are unclamped, GL_RGB16F_ARB for example. See the developer site of NVidia … there is a great page with all OpenGL extension, included the ones for unclamped texture format.

Just to clarify, I am putting values beyond [0,1] in the texture, it just wasn’t returning them. For instance if texture[0] = 2.0, and I get

color = tetxture2D(0,0);

then

gl_FragColor = vec4(color.x / 2, 0, 0, 1);

Still only shows the equivalent of a half-red color, the same it does the same with texture[0] = 1.0, or 1000.0.

This was as an internal format of GL_FLOAT.

I will go look for a internal format that claims not to clamp at [0,1] and see if that helps.

Can you put the code where you load your fp texture?

GL_FLOAT is not an internal but a data type, the type of the data you give for example to glTexImage2D.
Like dgedge said, internal format should be RGBA16F_ARB or RGBA32F_ARB.

If you want texture values outside [0…1], texture declaration should be something like that :

glTexImage2D(GL_TEXTURE_2D,0,GL_RGB16F_ARB,width,height,0,GL_RGB,GL_FLOAT,aPointerOfFloat);

To see if texture values are clamped or not, try a more visual effect than a half-red color !

vec color = texture2D(tex,coord).rgb;

if ( color.x > 1.0 )
gl_FragColor = vec4(1.0,0.0,0.0,1.0)
else
gl_FragColor = vec4(0.0,1.0,0.0,1.0)

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size, 4, 0, GL_RGBA, GL_FLOAT, this->texture);

And that probably would be a better test, I’ll try that real quick.

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, size, 4, 0, GL_RGBA, GL_FLOAT, this->texture);

GL_RGBA clamp values between 0 and 1

Texture values will be clamped to [0…1] if you use
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size, 4, 0, GL_RGBA, GL_FLOAT, this->texture)

(your texture have a strange size : width = size and height = 4 ???)

Use,

glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA16F_ARB,width,height,0,GL_RGBA,GL_FLOAT,this->texture);

if you want values outside [0…1] !

first! :smiley:

use GL_RGBA32F with GL_FLOAT
GL_RGBA16F with GL_HALF_FLOAT_ARB

You have edited your message :stuck_out_tongue:

BTW, GL_HALF_FLOAT or GL_FLOAT is not important. GL_FLOAT works with GL_RGBA16F_ARB or GL_RGBA32F_ARB.

Cool,

GL_RGBA32F_ARB seems to fix my issue.

Thanks everyone.

You have edited your message :stuck_out_tongue:

Yes, but my post is on top of yours! :slight_smile:

BTW, GL_HALF_FLOAT or GL_FLOAT is not important. GL_FLOAT works with GL_RGBA16F_ARB or GL_RGBA32F_ARB.

Yes you are right, opengl do the conversion, 32 bits -> 16bits but in practice, I don’t any interest to lost precision with GL_RGBA16F_ARB using float data.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.