I want to put 4 values of 256 bits in a float and read these 4 values in HLSL. Do you know if it is possible, in c++ I see several way to do that by using union or reinterpret_cast. But both are not avaible in HLSL:
To be clear I wrote a simple example :
// 4 values in c++ char v1 = 1, v2 = 2, v3 = 3, v4 = 4; // Store them in C++ int store = (v1 << 0) | (v2 << 8) | (v3 << 16) | (v4 << 24); // Put them in a float float valueStored = *reinterpret_cast<float*>(&store); // Now I want to use these values // Oh no I cannot use reinterpret_cast!! :( in HLSL int uncompress = *reinterpret_cast<int*>(&valueStored); // Read the value char o1, o2, o3, o4; o1 = (char) uncompress & 0xFF; o2 = (char)(uncompress >> 8) & 0xFF; o3 = (char)(uncompress >> 16) & 0xFF; o4 = (char)(uncompress >> 24) & 0xFF;
I want to use a float and not an int because I want to send a float4 to the GPU, with 3 floats and 1 float with 4 values.
Thanks for your help,
Edited by smallGame, 22 June 2013 - 12:32 PM.