From 3b9f16e8ddce81be8121ce0a29d743807b6d7a41 Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Sun, 30 Jul 2017 22:50:39 +0700 Subject: [PATCH] Fix regression with blending in A Bug's Life, #1488 Hack alert: The problem blender is used in two cycles mode, but both cycles are the same: c_in*a_in + c_mem * 1ma I have no access to c_mem from shader. Therefore, I use c_in instead of c_mem in the first cycle. Result of the second cycle will be blended with c_mem by GL blender, as usual. This is pretty good approximation, no problems noticed. --- .../GLSL/glsl_CombinerProgramBuilder.cpp | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp index c6733fda..9bf876e7 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp +++ b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp @@ -10,6 +10,8 @@ using namespace glsl; +u32 g_cycleType = G_CYC_1CYCLE; + /*---------------_compileCombiner-------------*/ static @@ -468,6 +470,13 @@ public: m_part = " if (uForceBlendCycle1 != 0) { \n" " muxPM[0] = clampedColor; \n" + ; + if (g_cycleType == G_CYC_2CYCLE) { + m_part += + " muxPM[1] = clampedColor; \n" + ; + } + m_part += " muxA[0] = clampedColor.a; \n" " lowp float muxa; \n" " if (uBlendMux1[1] == 0) \n" @@ -514,6 +523,13 @@ public: m_part = " if (uForceBlendCycle1 != 0) { \n" " muxPM[0] = clampedColor; \n" + ; + if (g_cycleType == G_CYC_2CYCLE) { + m_part += + " muxPM[1] = clampedColor; \n" + ; + } + m_part += " muxA[0] = clampedColor.a; \n" " muxB[0] = 1.0 - muxA[uBlendMux1[1]]; \n" " lowp vec4 blend1 = (muxPM[uBlendMux1[0]] * muxA[uBlendMux1[1]]) + (muxPM[uBlendMux1[2]] * muxB[uBlendMux1[3]]); \n" @@ -534,6 +550,7 @@ public: m_part = " if (uForceBlendCycle2 != 0) { \n" " muxPM[0] = clampedColor; \n" + " muxPM[1] = vec4(0.0); \n" " muxA[0] = clampedColor.a; \n" " lowp float muxa; \n" " if (uBlendMux2[1] == 0) \n" @@ -581,6 +598,7 @@ public: m_part = " if (uForceBlendCycle2 != 0) { \n" " muxPM[0] = clampedColor; \n" + " muxPM[1] = vec4(0.0); \n" " muxA[0] = clampedColor.a; \n" " muxB[0] = 1.0 - muxA[uBlendMux2[1]]; \n" " lowp vec4 blend2 = muxPM[uBlendMux2[0]] * muxA[uBlendMux2[1]] + muxPM[uBlendMux2[2]] * muxB[uBlendMux2[3]]; \n" @@ -1685,8 +1703,6 @@ public: /*---------------ShaderPartsEnd-------------*/ -u32 g_cycleType = G_CYC_1CYCLE; - static bool needClampColor() { return g_cycleType <= G_CYC_2CYCLE;