Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does an any image file format support negative floats?

Tags:

image

opengl

I'm using OpenGL for implementing some screen space filters. For debugging purposes, I would like to save a bunch of textures so a can compare individual pixel values. The problem is that these 16-bit float textures have negative values. Do you know of any image file formats that support negative values? How could I export them?

like image 598
tuket Avatar asked Nov 22 '25 22:11

tuket


1 Answers

Yes there are some such formats ... What you need is to use non clamped floating formats. This is what I am using:

GL_LUMINANCE32F_ARB
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE32F_ARB, size, size, 0, GL_LUMINANCE, GL_FLOAT, data);

Here an example:

  • raytrace through 3D mesh

In there I am passing geometry in a float texture that is not clamped so it has full range not just <0,1> As you can see negative range is included too ...

There are few others but once I found the one was no point to look for more of them...

You can verify clamping using the GLSL debug prints

Also IIRC there was some function to set the clamping behavior of OpenGL but never used it (if my memory serves well).

[Edit1] exporting to file

this is a problem and unless yo are exporting to ASCII or math matrix files I do not know of any format supporting negative pixel values...

So you need to workaround... so simply convert range to non negative ones like this:

float max = ???; //some value that is safely bigger than biggest abs value in your images
for (each pixel x,y)
 {
 pixel(x,y) = 0.5*(max + pixel(x,y))
 }

and then converting back if needed

for (each pixel x,y)
 {
 pixel(x,y) = (2.0*pixel(x,y)-max);
 }

another common way is to normalize to range <0,1> which has the advantage that from RGB colors you can infere 3D direction... (like on normal/bump maps)

pixel(x,y) = 0.5 + 0.5*pixel(x,y)/max; 

and back

pixel(x,y) = 2.0*max*pixel(x,y)-max; 
like image 145
Spektre Avatar answered Nov 25 '25 14:11

Spektre