• Advertisement
Sign in to follow this  

HLSL (Pixel Shader): Pack 32-bit float to 32-bit A8R8G8B8 render target

This topic is 4566 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 everyone, In pixel shader I need to store the 32-bit float value in 32-bit render target of the format A8R8G8B8. Then, during second rendering pass I'll need to unpack values stored in A8R8G8B8 back to 32-bit float. Anyone knows the fastest way to implement the packing / unpacking schema? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Hi,

float3 F32_Compress(float f)
{
float u,v,w;
float res_u, res_v;

u = floor(f*256.0);
res_u = f*256.0 - u;
v = floor(res_u * 256.0);
res_v = res_u*256.0 - v;
w = floor(res_v*256.0);

return (1/256.0*float3(u,v,w));
}

float F32_Decompress(float3 vec)
{
return (vec.x+vec.y*1.0/256.0+vec.z*1.0/65536.0);
}

This is not bit-per-bit copy (which would be a better solution) but it's not too bad.

Diego

Share this post


Link to post
Share on other sites
Thanks a lot,

Quote:
Original post by Cypher19
Why an A8R8G8B8 texture? Can't you just use an R32F?


I could and I did, but I'm testing different render target formats configurations for my deferred shading demo renderer.

Share this post


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

  • Advertisement