From a6babb418f1a6e1100eb11bad56044af1f4ab5ad Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Mon, 19 Jun 2017 17:49:23 +0700 Subject: [PATCH] Rewrite monochrome effect for Zeldas. Fixed #1505 OoT Ending Screen Freeze Effect Color Wrong --- .../GLSL/glsl_CombinerProgramBuilder.cpp | 51 ++++++++++++++----- .../glsl_CombinerProgramUniformFactory.cpp | 9 +++- src/GraphicsDrawer.cpp | 21 -------- 3 files changed, 45 insertions(+), 36 deletions(-) diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp index 4f63d507..49094d7e 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp +++ b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp @@ -972,26 +972,42 @@ public: " lowp vec4 tex3Point = c0 + abs(offset.x)*(c1-c0) + abs(offset.y)*(c2-c0); \n" "#define READ_TEX(name, tex, texCoord, fbMonochrome, fbFixedAlpha) \\\n" " { \\\n" - " lowp vec4 texStandard = texture(tex, texCoord); \\\n" - " FILTER_3POINT(tex, texCoord); \\\n" - " name = uTextureFilterMode == 0 ? texStandard : tex3Point; \\\n" + " if (fbMonochrome == 3) { \\\n" + " mediump ivec2 coord = ivec2(gl_FragCoord.xy); \\\n" + " name = texelFetch(tex, coord, 0); \\\n" + " } else { \\\n" + " lowp vec4 texStandard = texture(tex, texCoord); \\\n" + " FILTER_3POINT(tex, texCoord); \\\n" + " name = uTextureFilterMode == 0 ? texStandard : tex3Point; \\\n" + " } \\\n" " if (fbMonochrome == 1) name = vec4(name.r); \\\n" - " else if (fbMonochrome == 2) \\\n" + " else if (fbMonochrome == 2) \\\n" " name.rgb = vec3(dot(vec3(0.2126, 0.7152, 0.0722), name.rgb)); \\\n" - " if (fbFixedAlpha == 1) name.a = 0.825; \\\n" + " else if (fbMonochrome == 3) { \\\n" + " name.rgb = vec3(dot(vec3(0.2126, 0.7152, 0.0722), name.rgb)); \\\n" + " name.a = 0.0; \\\n" + " } \\\n" + " if (fbFixedAlpha == 1) name.a = 0.825; \\\n" " } \n" ; } else { m_part = "#define READ_TEX(name, tex, texCoord, fbMonochrome, fbFixedAlpha) \\\n" - " { \\\n" - " name = texture(tex, texCoord); \\\n" - " if (fbMonochrome == 1) name = vec4(name.r); \\\n" - " else if (fbMonochrome == 2) \\\n" + " { \\\n" + " if (fbMonochrome == 3) { \\\n" + " mediump ivec2 coord = ivec2(gl_FragCoord.xy); \\\n" + " name = texelFetch(tex, coord, 0); \\\n" + " } else name = texture(tex, texCoord); \\\n" + " if (fbMonochrome == 1) name = vec4(name.r); \\\n" + " else if (fbMonochrome == 2) \\\n" " name.rgb = vec3(dot(vec3(0.2126, 0.7152, 0.0722), name.rgb)); \\\n" - " if (fbFixedAlpha == 1) name.a = 0.825; \\\n" + " else if (fbMonochrome == 3) { \\\n" + " name.rgb = vec3(dot(vec3(0.2126, 0.7152, 0.0722), name.rgb)); \\\n" + " name.a = 0.0; \\\n" + " } \\\n" + " if (fbFixedAlpha == 1) name.a = 0.825; \\\n" " } \n" - ; + ; } } else { m_part = @@ -1543,12 +1559,21 @@ public: " \n" "lowp vec4 readTexMS(in lowp sampler2DMS mstex, in mediump vec2 texCoord, in lowp int fbMonochrome, in lowp int fbFixedAlpha) \n" "{ \n" - " mediump vec2 msTexSize = vec2(textureSize(mstex)); \n" - " mediump ivec2 itexCoord = ivec2(msTexSize * texCoord); \n" + " mediump ivec2 itexCoord; \n" + " if (fbMonochrome == 3) { \n" + " itexCoord = ivec2(gl_FragCoord.xy); \n" + " } else { \n" + " mediump vec2 msTexSize = vec2(textureSize(mstex)); \n" + " itexCoord = ivec2(msTexSize * texCoord); \n" + " } \n" " lowp vec4 texColor = sampleMS(mstex, itexCoord); \n" " if (fbMonochrome == 1) texColor = vec4(texColor.r); \n" " else if (fbMonochrome == 2) \n" " texColor.rgb = vec3(dot(vec3(0.2126, 0.7152, 0.0722), texColor.rgb)); \n" + " else if (fbMonochrome == 3) { \n" + " texColor.rgb = vec3(dot(vec3(0.2126, 0.7152, 0.0722), texColor.rgb)); \n" + " texColor.a = 0.0; \n" + " } \n" " if (fbFixedAlpha == 1) texColor.a = 0.825; \n" " return texColor; \n" "} \n" diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramUniformFactory.cpp b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramUniformFactory.cpp index c22834f1..8f75c380 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramUniformFactory.cpp +++ b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramUniformFactory.cpp @@ -201,9 +201,14 @@ public: nFbMonochromeMode0 = 1; if (gDP.otherMode.imageRead == 0) nFbFixedAlpha0 = 1; - } - else if (gSP.textureTile[0]->size == G_IM_SIZ_16b && gSP.textureTile[0]->format == G_IM_FMT_IA) + } else if (gSP.textureTile[0]->size == G_IM_SIZ_16b && gSP.textureTile[0]->format == G_IM_FMT_IA) { nFbMonochromeMode0 = 2; + } else if (cache.current[0]->size == G_IM_SIZ_16b && gSP.textureTile[0]->size == G_IM_SIZ_8b && gSP.textureTile[0]->format == G_IM_FMT_CI) { + // Zelda monochrome effect + nFbMonochromeMode0 = 3; + nFbMonochromeMode1 = 3; + } + nMSTex0Enabled = cache.current[0]->frameBufferTexture == CachedTexture::fbMultiSample ? 1 : 0; } if (cache.current[1] != nullptr && cache.current[1]->frameBufferTexture != CachedTexture::fbNone) { diff --git a/src/GraphicsDrawer.cpp b/src/GraphicsDrawer.cpp index a84d5b41..77fe4def 100644 --- a/src/GraphicsDrawer.cpp +++ b/src/GraphicsDrawer.cpp @@ -1039,25 +1039,6 @@ bool texturedRectPaletteMod(const GraphicsDrawer::TexturedRectParams & _params) return true; } -static -bool texturedRectMonochromeBackground(const GraphicsDrawer::TexturedRectParams & _params) -{ - if (gDP.textureImage.address >= gDP.colorImage.address && - gDP.textureImage.address <= (gDP.colorImage.address + gDP.colorImage.width*gDP.colorImage.height * 2)) { - - FrameBuffer * pCurrentBuffer = frameBufferList().getCurrent(); - if (pCurrentBuffer != nullptr) { - FrameBuffer_ActivateBufferTexture(0, pCurrentBuffer); - CombinerInfo::get().setMonochromeCombiner(); - return false; - } else - return true; - - } - - return false; -} - // Special processing of textured rect. // Return true if actuial rendering is not necessary bool(*texturedRectSpecial)(const GraphicsDrawer::TexturedRectParams & _params) = nullptr; @@ -1556,8 +1537,6 @@ void GraphicsDrawer::_setSpecialTexrect() const texturedRectSpecial = texturedRectBGCopy; else if (strstr(name, (const char *)"PAPER MARIO") || strstr(name, (const char *)"MARIO STORY")) texturedRectSpecial = texturedRectPaletteMod; - else if (strstr(name, (const char *)"ZELDA")) - texturedRectSpecial = texturedRectMonochromeBackground; else texturedRectSpecial = nullptr; }