rj-action-library/Runtime/Shading/Library/Dithering.gdshareinc

28 lines
642 B
Plaintext

const mat4 ditherMatrix = mat4(
vec4(0.0625, 0.5625, 0.1875, 0.6875),
vec4(0.8125, 0.3125, 0.9375, 0.4375),
vec4(0.25, 0.75, 0.125, 0.625),
vec4(1.0, 0.5, 0.875, 0.375));
float dither( float alpha, vec2 pos )
{
int x = int( pos.x ) % 4;
int y = int( pos.y ) % 4;
float res = 0.0;
vec4 temp;
if (x == 0) {temp = ditherMatrix[0];}
else if (x == 1) temp = ditherMatrix[1];
else if (x == 2) temp = ditherMatrix[2];
else if (x == 3) temp = ditherMatrix[3];
if (y == 0) {res = temp[0];}
else if (y == 1) res = temp[1];
else if (y == 2) res = temp[2];
else if (y == 3) res = temp[3];
return res;
}