I am Rendering to a SurfaceFormat.Color. (R8G8B8A8) The alpha of this format has 8 bits and I want to be able to use those 8 bits as a bit field.
For example, in one pass of my render, I want to save a bit value like 1 or 4 passing => 00000001 = 1 or 00000010 = 4 ....
The problem is that the output data of my pixel shader need to be in the range of [0 - 1].
How can I encode, for example, the value 00100001 = 33 in my surface.
I am doing this:
PixelShaderOutput PShader( PS_INPUT pin ) : COLOR0
{
PixelShaderOutput output;
///bla bla bla
output.color.a = 33 / 255;
return output;
}
Is this the right way?
Will I be able to read it in the other side? I mean, in another shader, when I need to read this value, can I use float value = ReadTexture(...) * 255;
where value
will have 33? (or 00100001)
The GPU will make the right "convertion", cause 33 / 255 = 0,1294117647058824. Will it be encoded as 00100001 in the texture?
In this new shader I want to this value as a bitfield like:
bool xTextureRepeat = fmod(value , 64) >= 32;