From 3a769bb0477e32c89a776ff3094f51cdfa6758d9 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Mon, 29 Apr 2013 01:08:23 -0700 Subject: [PATCH] Do alpha test equal compares using rounding. Fixes accuracy problems, Popolocrois shows things now. --- GPU/GLES/FragmentShaderGenerator.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/GPU/GLES/FragmentShaderGenerator.cpp b/GPU/GLES/FragmentShaderGenerator.cpp index f922fb92d8..5d86326688 100644 --- a/GPU/GLES/FragmentShaderGenerator.cpp +++ b/GPU/GLES/FragmentShaderGenerator.cpp @@ -156,6 +156,8 @@ void GenerateFragmentShader(char *buffer) { WRITE(p, "varying vec2 v_texcoord;\n"); } + WRITE(p, "float round255f(in float x) { return floor(x * 255.0 + 0.5); }\n"); + WRITE(p, "void main() {\n"); if (gstate.isModeClear()) { @@ -223,8 +225,13 @@ void GenerateFragmentShader(char *buffer) { if (enableAlphaTest) { int alphaTestFunc = gstate.alphatest & 7; const char *alphaTestFuncs[] = { "#", "#", " != ", " == ", " >= ", " > ", " <= ", " < " }; // never/always don't make sense - if (alphaTestFuncs[alphaTestFunc][0] != '#') - WRITE(p, " if (v.a %s u_alphacolorref.a) discard;\n", alphaTestFuncs[alphaTestFunc]); + if (alphaTestFuncs[alphaTestFunc][0] != '#') { + // If it's an equality check (!=, ==, <=, >=), rounding is more likely to be important. + if (alphaTestFuncs[alphaTestFunc][2] == '=') + WRITE(p, " if (round255f(v.a) %s round255f(u_alphacolorref.a)) discard;\n", alphaTestFuncs[alphaTestFunc]); + else + WRITE(p, " if (v.a %s u_alphacolorref.a) discard;\n", alphaTestFuncs[alphaTestFunc]); + } } if (enableColorTest) {