PDA

View Full Version : GL_FLOAT texture clamped to {0,1}



mogumbo
04-23-2005, 01:50 PM
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?

Matt Zamborsky
04-23-2005, 04:23 PM
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).

mogumbo
04-25-2005, 01:54 PM
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.

Matt Zamborsky
04-26-2005, 06:00 AM
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.

Corrail
04-26-2005, 07:11 AM
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.

Matt Zamborsky
04-27-2005, 10:40 AM
for NV float format too? I think no, but maybe you are right.

jra101
04-27-2005, 12:35 PM
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.

mogumbo
04-27-2005, 01:23 PM
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?

Java Cool Dude
04-27-2005, 07:11 PM
/as3yo

schaaade
04-28-2005, 04:16 AM
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 ;)

mogumbo
04-28-2005, 04:38 AM
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?

mogumbo
04-28-2005, 06:03 AM
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.

schaaade
04-28-2005, 06:30 AM
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?

Java Cool Dude
04-28-2005, 08:36 AM
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

mogumbo
04-28-2005, 09:37 AM
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.

Java Cool Dude
04-28-2005, 09:52 AM
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?

Korval
04-28-2005, 09:55 AM
So, is there a way to read data back from a texture object?glGetTexImage, perhaps?

mogumbo
04-28-2005, 10:29 AM
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.

Java Cool Dude
04-28-2005, 12:12 PM
Thanks for your kind words mate, I appreciate that :)
Now how fast (or slow) is that glGetTexImage function?

mogumbo
04-28-2005, 12:24 PM
glGetTexImage seems plenty slow. But that's what downsampling is for, which is what I'm working on right now :)