2020-12-16 23:44:15 +00:00
|
|
|
|
2020-12-18 01:36:20 +00:00
|
|
|
#define FUNC_NEVER 512 // 0x0200
|
|
|
|
#define FUNC_LESS 513 // 0x0201
|
|
|
|
#define FUNC_EQUAL 514 // 0x0202
|
|
|
|
#define FUNC_LEQUAL 515 // 0x0203
|
|
|
|
#define FUNC_GREATER 516 // 0x0204
|
|
|
|
#define FUNC_NOTEQUAL 517 // 0x0205
|
|
|
|
#define FUNC_GEQUAL 518 // 0x0206
|
|
|
|
#define FUNC_ALWAYS 519 // 0x0207
|
2020-12-16 23:44:15 +00:00
|
|
|
|
|
|
|
#if @alphaFunc != FUNC_ALWAYS && @alphaFunc != FUNC_NEVER
|
|
|
|
uniform float alphaRef;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void alphaTest()
|
|
|
|
{
|
2020-12-26 22:45:53 +00:00
|
|
|
#if @alphaToCoverage
|
2021-01-01 16:01:33 +00:00
|
|
|
float coverageAlpha = (gl_FragData[0].a - clamp(alphaRef, 0.0001, 0.9999)) / max(fwidth(gl_FragData[0].a), 0.0001) + 0.5;
|
2020-12-26 22:45:53 +00:00
|
|
|
|
|
|
|
// Some functions don't make sense with A2C or are a pain to think about and no meshes use them anyway
|
|
|
|
// Use regular alpha testing in such cases until someone complains.
|
|
|
|
#if @alphaFunc == FUNC_NEVER
|
2020-12-16 23:44:15 +00:00
|
|
|
discard;
|
2020-12-26 22:45:53 +00:00
|
|
|
#elif @alphaFunc == FUNC_LESS
|
|
|
|
gl_FragData[0].a = 1.0 - coverageAlpha;
|
|
|
|
#elif @alphaFunc == FUNC_EQUAL
|
|
|
|
if (gl_FragData[0].a != alphaRef)
|
|
|
|
discard;
|
|
|
|
#elif @alphaFunc == FUNC_LEQUAL
|
|
|
|
gl_FragData[0].a = 1.0 - coverageAlpha;
|
|
|
|
#elif @alphaFunc == FUNC_GREATER
|
|
|
|
gl_FragData[0].a = coverageAlpha;
|
|
|
|
#elif @alphaFunc == FUNC_NOTEQUAL
|
|
|
|
if (gl_FragData[0].a == alphaRef)
|
|
|
|
discard;
|
|
|
|
#elif @alphaFunc == FUNC_GEQUAL
|
|
|
|
gl_FragData[0].a = coverageAlpha;
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#if @alphaFunc == FUNC_NEVER
|
2020-12-16 23:44:15 +00:00
|
|
|
discard;
|
2020-12-26 22:45:53 +00:00
|
|
|
#elif @alphaFunc == FUNC_LESS
|
2021-01-02 18:27:25 +00:00
|
|
|
if (gl_FragData[0].a >= alphaRef)
|
2020-12-26 22:45:53 +00:00
|
|
|
discard;
|
|
|
|
#elif @alphaFunc == FUNC_EQUAL
|
|
|
|
if (gl_FragData[0].a != alphaRef)
|
|
|
|
discard;
|
|
|
|
#elif @alphaFunc == FUNC_LEQUAL
|
2021-01-02 18:27:25 +00:00
|
|
|
if (gl_FragData[0].a > alphaRef)
|
2020-12-26 22:45:53 +00:00
|
|
|
discard;
|
|
|
|
#elif @alphaFunc == FUNC_GREATER
|
2021-01-02 18:27:25 +00:00
|
|
|
if (gl_FragData[0].a <= alphaRef)
|
2020-12-26 22:45:53 +00:00
|
|
|
discard;
|
|
|
|
#elif @alphaFunc == FUNC_NOTEQUAL
|
|
|
|
if (gl_FragData[0].a == alphaRef)
|
|
|
|
discard;
|
|
|
|
#elif @alphaFunc == FUNC_GEQUAL
|
2021-01-02 18:27:25 +00:00
|
|
|
if (gl_FragData[0].a < alphaRef)
|
2020-12-26 22:45:53 +00:00
|
|
|
discard;
|
|
|
|
#endif
|
2020-12-16 23:44:15 +00:00
|
|
|
#endif
|
|
|
|
}
|