Sign in to follow this  

Storing value across two texture channels?

This topic is 1508 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

You can sort of think of it as two base-256 digits. So if you wanted to store the value 1000 there, you would have:

 

B: (1000 / 256 )    A: (1000 - 1000 / 256 * 256)     // (integer math)

B: 3     A: 232

 

And then to reconstruct:

weight = B * (256 ^ 1) + A * (256 ^ 0)

weight = 3 * 256  +  232 * 1

weight = 1000

 

 

Of course, if it's a weight, you're probably expecting normalized [0-1] values. (Splitting it across 2 channels gives you 65536 separate weights between 0 and 1 instead of 256). In this case, multiply the weight by 256 and use the fractional and non fractional values.

 

So, in HLSL for instance:

float weightTemp = weight * 256;

float bValue = floor(weightTemp) / 256; // bring it back to [0-1] so it fits in B

float aValue = frac(weightTemp);

 

Then to reconstruct:

float4 weightTemp; // Assume this is the texture sample

float weight = weightTemp.b + weightTemp.a / 256;

 

 

Note that texture filtering doesn't make sense anymore if you're storing a value across two channels. So you'll have to use point sampling.

Share this post


Link to post
Share on other sites

This topic is 1508 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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