• Advertisement
Sign in to follow this  

pack\unpack four 4bit values into one 16 bit value

This topic is 3290 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

I'm trying to minimize space used by deffered render as much as possbile. I have four parameters for material appearence. Each parameter requires at least 4 bit precision. I'm trying to pack them into one 16bit float value and unpack later. How this can be done? My latest achivement is to pack 3 discrete parameter with values of 0.1 0.2 ... 0.9 That dosnt help that much. remark: pack\unpacking is done in pixel shader.

Share this post


Link to post
Share on other sites
Advertisement
Why 16 bit float? I think it would be a lot easier and less error prone and possibly even faster to use an integer format. RGBA4444 would be perfect, if that one is available on your platform.

Share this post


Link to post
Share on other sites
My G-buffer is 4 ARGB16 bit textures, currently one of the textures is completely used by parameters. If I can pack parameters to one 16bit float that would give me additional three slots for other things.

Share this post


Link to post
Share on other sites
Bitwise dosnt compile under SM 3_0, do they work only on SM 4_0 exclusively?

Share this post


Link to post
Share on other sites
Quote:
Original post by Viik
Bitwise dosnt compile under SM 3_0, do they work only on SM 4_0 exclusively?


Yes, they're part of SM 4.0 Hardware, and they're not present previous shader models.

Share this post


Link to post
Share on other sites
Solution found, this is code:

Packing
half4 param = float4(oren_roughness, cook_roughness, cook_fresnel, metalness); // every parametets has a values in range [0..1]
param.xyz = floor(param.xyz * 16); // only first three will be coded
half X = param.x + param.y * 16 + param.z * 256 + param.w; // this will go into 16bit render target

Unpacking
float dec = diffuse_tex.a; // this is packed parameters read from texture
half4 param = 0;
param.a = frac(dec);
param.b = floor(dec / 256);
half t2 = fmod(dec, 256);
param.g = floor(t2 / 16);
param.r = fmod(t2, 16) / 16;
param.rgb /= 16;

Share this post


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

  • Advertisement