From e358a6dcbe8e6b25b5477d8b110c3b4a21790cb1 Mon Sep 17 00:00:00 2001 From: raven02 Date: Sun, 13 Apr 2014 16:01:55 +0800 Subject: [PATCH 1/3] Handle ABSDIFF blending mode using GL_EXT_shader_framebuffer_fetch --- GPU/GLES/FragmentShaderGenerator.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/GPU/GLES/FragmentShaderGenerator.cpp b/GPU/GLES/FragmentShaderGenerator.cpp index 5d02b0ca79..b09722b0c7 100644 --- a/GPU/GLES/FragmentShaderGenerator.cpp +++ b/GPU/GLES/FragmentShaderGenerator.cpp @@ -292,6 +292,7 @@ void ComputeFragmentShaderID(FragmentShaderID *id) { bool enableAlphaDoubling = !alphaToColorDoubling && CanDoubleSrcBlendMode(); bool doTextureProjection = gstate.getUVGenMode() == GE_TEXMAP_TEXTURE_MATRIX; bool doTextureAlpha = gstate.isTextureAlphaUsed(); + bool computeAbsdiff = gstate.getBlendEq() == GE_BLENDMODE_ABSDIFF; ReplaceAlphaType stencilToAlpha = ReplaceAlphaWithStencil(); // All texfuncs except replace are the same for RGB as for RGBA with full alpha. @@ -326,11 +327,16 @@ void ComputeFragmentShaderID(FragmentShaderID *id) { // 3 bits id0 |= ReplaceAlphaWithStencilType() << 21; } + id0 |= (alphaTestAgainstZero & 1) << 24; if (enableAlphaTest) gpuStats.numAlphaTestedDraws++; else gpuStats.numNonAlphaTestedDraws++; + + if (computeAbsdiff) { + id->d[0] |= (computeAbsdiff & 1) << 25; + } } id->d[0] = id0; @@ -407,6 +413,7 @@ void GenerateFragmentShader(char *buffer) { bool enableAlphaDoubling = !alphaToColorDoubling && CanDoubleSrcBlendMode(); bool doTextureProjection = gstate.getUVGenMode() == GE_TEXMAP_TEXTURE_MATRIX; bool doTextureAlpha = gstate.isTextureAlphaUsed(); + bool computeAbsdiff = gstate.getBlendEq() == GE_BLENDMODE_ABSDIFF; ReplaceAlphaType stencilToAlpha = ReplaceAlphaWithStencil(); if (gstate_c.textureFullAlpha && gstate.getTextureFunction() != GE_TEXFUNC_REPLACE) @@ -592,6 +599,11 @@ void GenerateFragmentShader(char *buffer) { } } + // Handle ABSDIFF blending mode using GL_EXT_shader_framebuffer_fetch + if (computeAbsdiff && gl_extensions.EXT_shader_framebuffer_fetch) { + WRITE(p, " gl_FragColor.rgb = abs(v.rgb - gl_LastFragData[0].rgb);\n"); + } + switch (stencilToAlpha) { case REPLACE_ALPHA_DUALSOURCE: WRITE(p, " fragColor0 = vec4(v.rgb, 0.0);\n"); From f1254c79ed7a1aff398891f11a842885221da468 Mon Sep 17 00:00:00 2001 From: raven02 Date: Sun, 13 Apr 2014 16:03:50 +0800 Subject: [PATCH 2/3] Turn off regular alpha blending --- GPU/GLES/StateMapping.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/GPU/GLES/StateMapping.cpp b/GPU/GLES/StateMapping.cpp index 1378d7efb5..179039094f 100644 --- a/GPU/GLES/StateMapping.cpp +++ b/GPU/GLES/StateMapping.cpp @@ -325,7 +325,12 @@ void TransformDrawEngine::ApplyDrawState(int prim) { } if (((blendFuncEq >= GE_BLENDMODE_MIN) && gl_extensions.EXT_blend_minmax) || gl_extensions.GLES3) { - glstate.blendEquation.set(eqLookup[blendFuncEq]); + if (blendFuncEq == GE_BLENDMODE_ABSDIFF && gl_extensions.EXT_shader_framebuffer_fetch) { + // Handle GE_BLENDMODE_ABSDIFF in fragment shader and turn off regular alpha blending here. + glstate.blend.set(false); + } else { + glstate.blendEquation.set(eqLookup[blendFuncEq]); + } } else { glstate.blendEquation.set(eqLookupNoMinMax[blendFuncEq]); } From a9d7be1eab89150b1b799a1dd69801423aeec5c4 Mon Sep 17 00:00:00 2001 From: raven02 Date: Sun, 13 Apr 2014 16:13:59 +0800 Subject: [PATCH 3/3] Should be id0 --- GPU/GLES/FragmentShaderGenerator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GPU/GLES/FragmentShaderGenerator.cpp b/GPU/GLES/FragmentShaderGenerator.cpp index b09722b0c7..c31683f53c 100644 --- a/GPU/GLES/FragmentShaderGenerator.cpp +++ b/GPU/GLES/FragmentShaderGenerator.cpp @@ -335,7 +335,7 @@ void ComputeFragmentShaderID(FragmentShaderID *id) { gpuStats.numNonAlphaTestedDraws++; if (computeAbsdiff) { - id->d[0] |= (computeAbsdiff & 1) << 25; + id0 |= (computeAbsdiff & 1) << 25; } }