GL_FLOAT texture clamped to {0,1}

When using a texture of type GL_FLOAT in my GLSL program, the values of the texture appear to be clamped to the range {0,1}. What are my options for getting around this?

Do you mean that you created a texture with internal format GL_FLOAT? I think you mean external format of type GL_FLOAT, but you must specify also internal format to NV float format(FLOAT_RGBA32_NV) or ATI(ARB) float format(eg. RGBA_FLOAT32_ATI).
If you dont clamp float texture in shader it isnt clamped at all. But dont forget, that framebuffer is clamped(if isnt float too).

Thanks Matt. Looks like I was using the wrong internal format and the texture wasn’t being treated as a float texture at all. It appears that a float texture also must be rectangular to work properly. It’ll be a miracle if I ever get all these little details straight in my head.

Texture must be rectangular only if you use NV float format. If you use ATi float format you can have normal texture 2d target too.

Originally posted by Matt Zamborsky:
Texture must be rectangular only if you use NV float format. If you use ATi float format you can have normal texture 2d target too.
If you have a GeForce 6xxx (NV4X) you can also use GL_TEXTURE_2D texture target for floating point textures.

for NV float format too? I think no, but maybe you are right.

If you use the NV_float_buffer extension you always need to use rectangle textures. If you use the ARB_texture_float or ATI_texture_float extensions (supported by 6800 GPUs) you can use any texture type you want.

On a related subject, what do people use to read unclamped data back into system memory? glReadPixels returns clamped data. ARB_color_buffer_float is supposed to get around this problem with its glClampColorARB function, but it is not supported on my 6800. Is there perhaps some way to read data back from a texture object that I don’t know about?

/as3yo

Originally posted by mogumbo:
On a related subject, what do people use to read unclamped data back into system memory? glReadPixels returns clamped data. ARB_color_buffer_float is supposed to get around this problem with its glClampColorARB function, but it is not supported on my 6800. Is there perhaps some way to read data back from a texture object that I don’t know about?
Are you sure about that? It works fine on my 6600 GT , so I guess it shouldn’t be a problem for a 6800 either. Maybe wrong driver? I’m using the ForceWare 76.41 and deactivate clamping like this:

 
// disable color clamping for fragment colors
glClampColorARB( GL_CLAMP_FRAGMENT_COLOR_ARB, GL_FALSE );
// and the same for reading back with ReadPixels
glClamColorARB( GL_CLAMP_READ_COLOR_ARB, GL_FALSE );
 

I hope it helps :wink:

That’s exactly what I was trying to do. Upon further inspection I see that ARB_color_buffer_float is available on my graphics card in Windows but not Linux. (How incredibly annoying.) Unfortunately, I’m working in Linux on this project. So how can I get the same functionality in Linux? Any ideas?

Yet another related problem is simply reading back floating point data with the proper precision. Doing glReadPixels(0, 0, TEX_SIZE, TEX_SIZE, GL_RED, GL_FLOAT, (GLvoid*)data_f) on Linux actually gives me 8-bit precision in the values that are read. I can only seem to get full floating point precision by using the format GL_DEPTH_COMPONENT instead of GL_RED.

Originally posted by schaaade:
Are you sure about that? It works fine on my 6600 GT , so I guess it shouldn’t be a problem for a 6800 either.
Hmmmm, maybe I should take that back…
I’ve just realised that it’s working also without using the color_buffer_float extension. In my case this is probably due to being using an FBO as render target (only available for Windows with beta drivers by now). Actually I’m rendering to a RGB32F_ARB texture using the ARB_texture_float extension. This way, I get the correct (unclamped) values when I read back the content of the color buffer with glReadPixels.
I’ve just tried to do the same with a GL_RGBA8 texture (each texel is a GL_UNSIGNED_BYTE) and independently of whether I enable/disable the clamping with glClampColorARB, the result that I read back with glReadPixels is clamped to be within [0,1].
So, anyone can bring some light to this? When are the values being clamped?

I believe float texture data are clamped only if they’re processed through the main frame buffer.
In order to prevent that and as some of the community members have stated above, the use of an intermidiate render target of type float is required.
Now on NVIDIA previous generation of graphic cards like the FX for example, the texture must be of type RECTANGLE, on newer cards however you can get away just fine with a regular 2D or cube texture.
I’ve used PBuffers in the past to prevent the clamping of my data, and these days FBOs seem to do a hell lot better of a job at this with a decent performance increase.
/end

So, is there a way to read data back from a texture object? I only know of glReadPixels, which reads data back from the framebuffer.

The common thing to do is use the readPixels function while you’re still within the active context of a float PBuffer or an FBO (before you call your mainWindow.setCurrent() or whatever equivalent)
Btw what graphic card are you using?

So, is there a way to read data back from a texture object?
glGetTexImage, perhaps?

JCD, I haven’t had luck reading unclamped data with glReadPixels, unless I use GL_DEPTH_COMPONENT. There’s probably something I’m still doing wrong, though. 6800GT. I would love to be using FBO, but I’m doing this on Linux. Wish I could put it off for a couple months until FBO is supported on Linux also. By the way, nice demos lately.

Korval, that works like a charm. Thank you. I’ve never even seen that command before. And the values come back unclamped.

Thanks for your kind words mate, I appreciate that :slight_smile:
Now how fast (or slow) is that glGetTexImage function?

glGetTexImage seems plenty slow. But that’s what downsampling is for, which is what I’m working on right now :slight_smile: