minecraft-psx
minecraft-psx copied to clipboard
Alternate bayer pattern generation
Years ago (so things might be different now) I made a PS1 bayer dither shader. At first I used an array of 16 ints for the 4x4 pattern, but then I tried recreating it from a set of booleans and modulos which looked more complicated, but ran faster (288 FPS with array, ~700 FPS with the boolean modulo mess). Here's the code if you're interested.
PixCoord = texCoord * sourceSize[0].xy - 0.5; // Turning -1,1 range to pixel range, not centered on the pixels though.
float Modx4 = float(PixCoord.x - floor(PixCoord.x * 0.25) * 4.0 > 1.0);
float Mody4 = float(PixCoord.y - floor(PixCoord.y * 0.25) * 4.0 > 1.0);
float Modx2 = PixCoord.x - floor(PixCoord.x*0.5)*2.0;
float Mody2 = PixCoord.y - floor(PixCoord.y*0.5)*2.0;
float a = Mody2*6;
a = round(a - a*1.333333333333333 * Modx2);
float b = Mody4-4+Modx2*4;
float c = Modx4 - Modx4 * Mody4 * 2;
float Pattern = a+b+c;
AMD's GPU ShaderAnalyzer said it was somehow less instructions and cycles, I can't explain it.