Pack four bytes in a float
问题 I'm writing a shader (HLSL), and I need to pack a color value into the R32 format. I've found various pieces of code for packing a float into the R8G8B8A8 format, but none of them seem to work in reverse. I'm targeting SM3.0, so (afaik) bit operations are not an option. To sum it up, I need to be able to do this: float4 color = ...; // Where color ranges from 0 -> 1 float packedValue = pack(color); Anyone know how to do this? UPDATE I've gotten some headway... perhaps this will help to