glClampColorARB and color clamping

Hi everybody! I’m new to shaders and I’m trying to figure out how to apply a LookUpTable texture to convert colors of another texture in a fragment shader. My problem is that my original texture is a TC medical image, and i’d like my fragment shader to operate or original rather than clamped color values. I found an extension called
glClampColorARB which should disable color clamping.
I’m using it (and other extensions) through GLEW library,

glClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB, FALSE);

glClampColorARB(GL_CLAMP_FRAGMENT_COLOR_ARB,FALSE);

but it doesn’t seem to work. the colors are clamped as usual and glGetError() doesn’t find any error. Am I missing something?
Is there another way to keep colors unclamped?
I need unclamped values also beacause I’d like to perform some Image filtering via GPU, and clamping and conversion to fixed point float would bring to round-off errors, i think.
that’s how my textures are generated:
Image
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE8, width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, pixData._Myfirst );
Look Up Table
glTexImage1D(GL_TEXTURE_1D, 0, GL_LUMINANCE8, size, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, pixData._Myfirst );

Can anyone help me?
thanx

Color clamping is part of the ARB_color_buffer_float extension.
http://oss.sgi.com/projects/ogl-sample/registry/ARB/color_buffer_float.txt

You need to render to a floating point buffer to let it have an effect. It’s disabled by default on those. You can’t really disable it for fixed point color buffer formats.

The input data has not much to do with it.
LUMINANCE8 is a fixed color format per definition. Accessing fixed point textures in the fragment pipeline will always result in values in the range of 0.0 to 1.0.
If you input data is not normalized but exceeding that range already, you need to use a floating point texture.

Hi,

I got a question in the same direction. How do I set up a floating point texture? Somehow like this:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, cols, rows, 0, GL_RGB, GL_FLOAT, a)

Originally posted by Relic:
[b]Color clamping is part of the ARB_color_buffer_float extension.
http://oss.sgi.com/projects/ogl-sample/registry/ARB/color_buffer_float.txt

You need to render to a floating point buffer to let it have an effect. It’s disabled by default on those. You can’t really disable it for fixed point color buffer formats.

The input data has not much to do with it.
LUMINANCE8 is a fixed color format per definition. Accessing fixed point textures in the fragment pipeline will always result in values in the range of 0.0 to 1.0.
If you input data is not normalized but exceeding that range already, you need to use a floating point texture.[/b]
I see…but reading the ARB_color_buffer_float extension specification I thought that passing FALSE to glClampColorARB would disable clamping also in fixed point mode, this is taken from the specification:
"Vertex color clamping is controlled
by calling

    void ClampColorARB(enum target, enum clamp)  

with a <target> set to VERTEX_COLOR_CLAMP_ARB.  If <clamp> is TRUE,  
vertex color clamping is enabled; if <clamp> is FALSE, vertex color  
clamping is disabled.  If <clamp> is FIXED_ONLY_ARB, vertex color  
clamping is enabled if all enabled color buffers have fixed-point  
components.  "

Maybe I am misunderstanding something…
You say that spacifying float textures would make it work? Or “rendering to a floating point buffer” is something different?

Anyway, thanks a lot

You don’t want vertex colors to be unclamped, you want fragment values written to a color buffer to be general floating point including values outside the range [0.0,1.0] and it sounds like you want texture input data to be floating point too.

Repeating what I said:
“You need to render to a floating point buffer to let it [color clamp setting] have an effect.”

Read this: http://oss.sgi.com/projects/ogl-sample/registry/ARB/color_buffer_float.txt

Medical imaging data is normally 16 bit depth, if you only have an 8 bit input then your luminance8 is ok.
If you have more precision in the input data, use a different format which matches better, like luminance16 or if the input data is already floating point (not always in the 0.0 to 1.0 range) you should use floating point textures to keep the precision, BUT this only improves the input (texture fetch is not clamped if you read from a floating point texture), you still must render to a floating point color buffer if you require unclamped floating point results.

Originally posted by Ferenzzy:
[b]Hi,

I got a question in the same direction. How do I set up a floating point texture? Somehow like this:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, cols, rows, 0, GL_RGB, GL_FLOAT, a)[/b]
No, that’s a fixed point RGB 8 bit texture built from floating point user data.
You must use a floating point internalFormat parameter to get a floating point texture.
Read http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_float.txt
which is based on
http://oss.sgi.com/projects/ogl-sample/registry/ATI/texture_float.txt
There is a third extension allowing this too: http://oss.sgi.com/projects/ogl-sample/registry/NV/float_buffer.txt
Make sure your OpenGL implementation advertises one of the extensions.

In your case using ARB_texture_float would be
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F_ARB, cols, rows, 0, GL_RGB, GL_FLOAT, a)

Thanks Relic, that fixed my problem.

Originally posted by Relic:
[b]Color clamping is part of the ARB_color_buffer_float extension.
http://oss.sgi.com/projects/ogl-sample/registry/ARB/color_buffer_float.txt

You need to render to a floating point buffer to let it have an effect. It’s disabled by default on those.
[/b]
AFAIK it’s only disabled for fixed point buffer.

No, read the spec:
“The default state for fragment clamping is “FIXED_ONLY”, which has the behavior of clamping colors for fixed-point color buffers and not clamping colors for floating-pont color buffers.”

Originally posted by Relic:
No, read the spec:
“The default state for fragment clamping is “FIXED_ONLY”, which has the behavior of clamping colors for fixed-point color buffers and not clamping colors for floating-pont color buffers.”

I have read the spec and that is what I mean. I have understood your posting wrong. My fault, a logical one. I have thought: The feature of “unclamped values” is disabled for fixed point.

I’m sorry, maybe it’s a stupid question…but what does “Render to a float buffer” mean? I guess it’s not using floating point internal format for textures…
thanx
M.

Originally posted by Massimo:
I’m sorry, maybe it’s a stupid question…but what does “Render to a float buffer” mean? I guess it’s not using floating point internal format for textures…
thanx
M.

Yes, the internal format of the texture/renderbuffer is a float like GL_RGBA32F_ARB. This means a float buffer.

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