That's all well and good, but D3D9 HLSL does not support bitwise operators. After searching online, I found this blog post that describes how you can use a texture as a look-up table to perform bitwise operations: orenk2k.blogspot.com/2011/05/bitwise-operators-on-low-end-gpus.html so that's what I'm doing.
To use textures in this set up, you need to tell it where the texture lives, so in Game/Sweet.fx add something like this:
#if USE_CUSTOM == 1
texture bitwiseTex < string source = "SweetFX/Textures/bitwiseop.jpg"; >
{
Width = 256;
Height = 256;
Format = R8G8B8A8;
};
sampler bitwiseSampler
{
Texture = bitwiseTex;
AddressU = Clamp; AddressV = Clamp; AddressW = Clamp;
MipFilter = Point; MinFilter = Point; MagFilter = Point;
SRGBTexture = false;
};
#endif
float AND(in float A, in float B)
{
return tex2Dlod(bitwiseSampler, float4(A, B,0,0)).r;
// alternatively...
//return tex2D(bitwiseSampler, float2(A, B)).r;
}