Sign in to follow this  
MickeyMouse

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

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this