Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is a floating point texture?

I tried reading the OpenGL ARB_texture_float spec, but I still cannot get it in my head..

And how is floating point data related to just normal 8-bit per channel RGBA or RGB data from an image that I am loading into a texture?

like image 999
lokstok Avatar asked Apr 18 '11 21:04

lokstok


1 Answers

Here is a read a little bit here about it.

Basically floating point texture is a texture in which data is of floating point type :) That is it is not clamped. So if you have 3.14f in your texture you will read the same value in the shader.

You may create them with different numbers of channels. Also you may crate 16 or 32 bit textures depending on the format. e.g.

// create 32bit 4 component texture, each component has type float    
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 16, 16, 0, GL_RGBA, GL_FLOAT, data);

where data could be like this:

float data[16][16];
for(int i=0;i<16*16;++i) data[i] = sin(i*M_PI/180.0f); // whatever

then in shader you can get exactly same (if you use FLOAT32 texture) value.

e.g.

uniform sampler2D myFloatTex;
float value = texture2D(myFloatTex, texcoord.xy);

If you were using 16bit format, say GL_RGBA16F, then whenever you read in shader you will have a convertion. So, to avoid this you may use half4 type: half4 value = texture2D(my16BitTex, texcoord.xy);

So, basically, difference between the normalized 8bit and floating point texture is that in the first case your values will be brought to [0..1] range and clamped, whereas in latter you will receive your values as is ( except for 16<->32 conversion, see my example above).

Not that you'd probably want to use them with FBO as a render target, in this case you need to know that not all of the formats may be attached as a render target. E.g. you cannot attach Luminance and intensity formats.

Also not all hardware supports filtering of floating point textures, so you need to check it first for your case if you need it.

Hope this helps.

like image 113
alariq Avatar answered Dec 31 '22 23:12

alariq