Packing a float into a texture

I know there are probably a couple of ways to do this. But is there a stardard way people use to pack a floating point into a texture.

I would like to extract it as a float in a fragment shader.

If its a 32 bit int I can cleanly take 8 bits and store them in the RGBA channel, then in my fragment shader do something like

vec4 texVal = glTexture1d(tex,value.u);
float number = dot(texVal,vec4(1,256,2^16,2^24)

(except I’ll also have to account for normalisation of the texture values to [-1,1]…gah)

Just wondering if there was a way of doing this with a float, or even if I can use some other channel (such as a depth texture). To store the values.

(I know above if I can figure out how to pack an int, I can convert my float to an int in the main application and convert it back in the frag shader…however all these conversions will start slowing things down)


There are floating point texture internalFormats to store IEEE 32 bit data directly.
Look with glGetString(GL_EXTENSIONS) what “float” extensions your implementaion offers (e.g. something like GL_ARB_texture_float, GL_ATI_texture_float, GL_NV_float_buffer)
Specs are here:

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