17

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?

genpfault
  • 51,148
  • 11
  • 85
  • 139
lokstok
  • 231
  • 1
  • 2
  • 7

2 Answers2

18

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.

alariq
  • 496
  • 3
  • 10
  • 1
    The link in the answer can be found here: https://web.archive.org/web/20120229133252/http://www.gpgpu.org/wiki/FAQ – Dávid Tóth Apr 27 '21 at 05:15
4

FP textures have a special designated range of internal formats (RGBA_16F,RGBA_32F,etc). Regular textures store fixed-point data, so reading from them gives you [0,1] range values. Contrary, FP textures give you [-inf,+inf] range as a result (not necessarily with a higher precision).

In many cases (like HDR rendering) you can easily proceed without FP textures, just by transforming the values to fit in [0,1] range. But there are cases like deferred rendering when you may want to store, for example, world-space coordinate without caring about their range.

kvark
  • 5,291
  • 2
  • 24
  • 33
  • They are also useful to get data to the shaders (e.g. isovalues). – pmr Apr 18 '11 at 22:03
  • 1
    So how would you go about reading a normal RGB or RGBA 8-bit per channel image and how are the values interpreted internally? e.g. will the value ranging from 0-255 or 0-1 be scaled to some other range internally? – lokstok Apr 19 '11 at 14:14
  • @lokstok. There is a parameter to glTexImage called 'normalized'. If set to "true" your input bytes will be converted in [0,1] range. Otherwise I suppose you'll get [0-255] (I didn't try that). – kvark Apr 19 '11 at 14:30