val = 1 - ((positionX & 1) & (positionY & 1));
if(positionX % 2 == 0 && positionY % 2 == 0)
return black;
return white;
So this is the new code:
float3 screenTones(float2 texcoord)
{
uint positionX = uint(texcoord.x * SCREEN_WIDTH);
uint positionY = uint(texcoord.y * SCREEN_HEIGHT);
float currentLuminosity = luminosity(tex2D(s0,texcoord).rgb);
int val = 0;
if(currentLuminosity > 0.8)
{
val = 1;
}
else if(currentLuminosity > 0.6)
{
val = 1 - ((positionX & 1) & (positionY & 1));
}
else if(currentLuminosity > 0.4)
{
val = 1 - (positionY & 1);
}
else if(currentLuminosity > 0.2)
{
val = 1 - ((positionX & 1) | (positionY & 1));
}
return float3(val, val, val);
}
One thing I do wonder about is whether all the if-statements can be removed. Could it be done by multiplying the value up then doing some clamping? I don't think it's likely, but if it were possible, would you want to complicate the code?