Jump to content
  • Advertisement
Sign in to follow this  

how to pack a fp32 in two fp16

This topic is 4626 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, basically i need to pack a 32bit float in two 16bit float. What i want to do: I need to pack two 32 bits float in the four RGBA channel with fp16 internal format. I found some code but I can't get it to work properly. I want to write 2 tex coords in a RGBA fp16. pack code in a vertex shader:
float f = 8.0;
vec2 temp = max(gl_TexCoord[0].xy, 0.0);
vec2 msb = floor(temp * f) / f;
vec2 lsb = fract(temp * f); //(temp - msb) * f;
gl_FragColor.xyzw = vec4(msb.x, lsb.x, msb.y, lsb.y);

The output is rendered in a texture bound as color attachment to the current fbo. Later, i want to get the two packed tex coords with reading the previous written texture. unpack code in a different fragment shader:
vec4 temp = textureCube(CubeMap, WorldSpaceLightVec);
const vec2 weights = vec2( 8192.0, 8.0 );
temp *= weights.xyxy; // unpack [.rg -> u coord, .ba -> v coord ]
vec3 texCoord;
texCoord.x = temp.x + temp.y;
texCoord.y = temp.z + temp.w;

I need to use GL_RGBA16F_ARB internal format instead of GL_RGBA32F_ARB, in order to allow linear interpolation. If someone has an idea why it's not working or how to do such thing, please help me. Thanks in advance. [Edited by - Alkiem on October 20, 2005 8:08:43 PM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!