I have a float4 coming into a compute shader, 3 of these floats are really floats but the fourth is 2 uints shifted together, how would i convert the float to uint by preserving the bit sequence instead of the numeric value?
on the c++ side i solved it by creating a uint pointer, filling it with the desired number and passing on the pointer as a float pointer instead. However in hlsl as similar as it is to c/c++ there are no pointers so im stuck here :|
In HLSL you should be able to do the following (assuming the value you are after is in f4.w)
uint ui = asuint( f4.w );
uint ui1 = ui & 0xffff;
uint ui2 = ui >> 16;
Basically it looks like the asuint intrinsic is your friend :)
You could use a union.
float f; // you float value is here
union X
{
float f;
short int a[2];
} x;
x.f = f;
int i1 = x.a[0]; // these are your ints
int i2 = x.a[1];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With