vk-book/data/shaders/AlphaTest.sp

21 lines
679 B
SourcePawn
Raw Normal View History

2025-05-23 21:13:53 -04:00
//
void runAlphaTest(float alpha, float alphaThreshold)
{
if (alphaThreshold > 0.0) {
// http://alex-charlton.com/posts/Dithering_on_the_GPU/
// https://forums.khronos.org/showthread.php/5091-screen-door-transparency
mat4 thresholdMatrix = mat4(
1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0,
13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0,
4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0,
16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0
);
alpha = clamp(alpha - 0.5 * thresholdMatrix[int(mod(gl_FragCoord.x, 4.0))][int(mod(gl_FragCoord.y, 4.0))], 0.0, 1.0);
if (alpha < alphaThreshold)
discard;
}
}