Skip to content

Commit

Permalink
Merge pull request #1590 from unknownbrackets/gpu-rounding
Browse files Browse the repository at this point in the history
Do alpha test equal compares using rounding
  • Loading branch information
hrydgard committed Apr 29, 2013
2 parents 3534f7b + 3a769bb commit 232b354
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions GPU/GLES/FragmentShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 232b354

Please sign in to comment.