Sign in to follow this  
smallGame

Compression in HLSL

Recommended Posts

smallGame    211

Hi,

 

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,

 

cheers,

Edited by smallGame

Share this post


Link to post
Share on other sites
smallGame    211

Hi Hodgman,

 

I am using shader model 4 and 5, I don't have any restriction...

 

I saw you are helping a lot of people on this forum, so I guess I ll have a solution quite soon :) . I am really wondering why talented people like you spend so much time to help people stuck like me :).

 

Thanks,

Share this post


Link to post
Share on other sites
smallGame    211

Hi,

 

Thanks for your help ! Everything is working perfectly ! So it was an easy question I miss-read the doc ;)
 

see you

Edited by smallGame

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this