Jump to content
  • Advertisement
Sign in to follow this  
kauna

Converting float3 to packed r11g11b10_float in shader

This topic is 2099 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 recently needed to store HDR values in a structured buffer and to save a bit of memory and to have acceptable precision I decided to use the r11g11b10 encoding. I tried RGBM and RGBE encoding first but I found them too imprecise for my needs. The encoding doesn't use sign bit so it can't be used for storing negative values.

 

I couldn't find any source for the task and there were few similar question so here's the HLSL code I came up with.

uint float3_to_r11g11b10(float3 rgb)
{
	uint3 Values = f32tof16(rgb);

	return ((Values.r >> 4) & 0x7ff) | (((Values.g << 7) & 0x3ff800)) | (((Values.b << 17) & 0xffc00000));
}

float3 r11g11b10_to_float3(uint rgb)
{
	return f16tof32(uint3((rgb & 0x7ff) << 4, (rgb & 0x3ff800) >> 7, (rgb & 0xffc00000) >> 17));
}

According to the MSDN the f32to16 and f16tof32 works best under shader model 5.0. Otherwise it is emulated.

 

Best regards!

Share this post


Link to post
Share on other sites
Advertisement

For future reference you can look at PackedVector::XMStoreFloat3PK in DirectXPackedVector.inl (from the Windows 8 SDK).

Share this post


Link to post
Share on other sites

Thanks, I am aware of those functions. As far as I know, they just aren't available in HLSL.

 

Cheers!

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!