I would like to store two float values ββin one 32-bit float variable. Encoding will happen in C #, while decoding should be done in the HLSL shader.
The best solution I have found so far is a complicated posting of the decimal fraction offset in the encoded values ββand storing them as an integer and decimal number of the floating βcarrierβ:
123.456 -> 12.3 and 45.6
It cannot handle negative values, but that's fine.
However, I was wondering if there is a better way to do this.
EDIT: A few additional details about the task:
I work with a fixed data structure in Unity, where vertex data is stored as a float. (Float2 for UV, float3 - normal, etc.). Apparently, there is no way to correctly add additional data, so I have to work within these limits, so I decided that all this is due to a more general problem of data encoding.For example, I can sacrifice secondary UV data to transmit additional 2x2 data channels.
The goal is the shader model 3.0, but I don't mind if decoding worked reasonably well on SM2.0.
Data loss is fine as long as it is "reasonable." The expected range of values ββis 0..64, but, as I think, 0..1 will be fine too, as it is cheap to reassign to any range inside the shader. It is important to keep accuracy as high as possible. Negative values ββare not important.
source share