From 1fe9ce3bf9f94bdd86edfda7e49e52c95c7f4643 Mon Sep 17 00:00:00 2001 From: Logan McNaughton Date: Tue, 17 Apr 2018 12:38:24 -0600 Subject: [PATCH] Fix BAR Fog with N64 Depth Compare --- .../OpenGLContext/GLSL/glsl_ShaderStorage.h | 2 +- .../GLSL/glsl_SpecialShadersFactory.cpp | 51 +++++++++++++++---- src/Graphics/OpenGLContext/opengl_GLInfo.cpp | 3 +- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_ShaderStorage.h b/src/Graphics/OpenGLContext/GLSL/glsl_ShaderStorage.h index 6a83d523..6c521dda 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_ShaderStorage.h +++ b/src/Graphics/OpenGLContext/GLSL/glsl_ShaderStorage.h @@ -20,7 +20,7 @@ namespace glsl { bool _saveCombinerKeys(const graphics::Combiners & _combiners) const; bool _loadFromCombinerKeys(graphics::Combiners & _combiners); - const u32 m_formatVersion = 0x1FU; + const u32 m_formatVersion = 0x20U; const u32 m_keysFormatVersion = 0x04; const opengl::GLInfo & m_glinfo; opengl::CachedUseProgram * m_useProgram; diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.cpp b/src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.cpp index 0e65f794..5ed68257 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.cpp +++ b/src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.cpp @@ -60,20 +60,51 @@ namespace glsl { "uniform lowp usampler2D uTlutImage;\n" "uniform sampler2D uDepthImage; \n" "uniform lowp vec4 uFogColor; \n" - "OUT lowp vec4 fragColor; \n" + ; + + if (config.frameBufferEmulation.N64DepthCompare != 0) { + if (_glinfo.imageTextures) + m_part += "layout(binding = 2, r32f) highp uniform restrict readonly image2D uDepthImageZ; \n"; + + if (_glinfo.ext_fetch) { + m_part += + "layout(location = 0) OUT lowp vec4 fragColor; \n" + "layout(location = 1) inout highp vec4 depthZ; \n" + ; + } else + m_part += "OUT lowp vec4 fragColor; \n"; + } else + m_part += "OUT lowp vec4 fragColor; \n"; + + m_part += "lowp float get_alpha() \n" "{ \n" ; - if (_glinfo.fetch_depth) { - m_part += - " highp float bufZ = gl_LastFragDepthARM; \n" - ; + + if (config.frameBufferEmulation.N64DepthCompare == 0) { + if (_glinfo.fetch_depth) { + m_part += + " highp float bufZ = gl_LastFragDepthARM; \n" + ; + } else { + m_part += + " mediump ivec2 coord = ivec2(gl_FragCoord.xy); \n" + " highp float bufZ = texelFetch(uDepthImage,coord, 0).r; \n" + ; + } } else { - m_part += - " mediump ivec2 coord = ivec2(gl_FragCoord.xy); \n" - " highp float bufZ = texelFetch(uDepthImage,coord, 0).r; \n" - ; + if (_glinfo.imageTextures) { + m_part += + " mediump ivec2 coord = ivec2(gl_FragCoord.xy); \n" + " highp float bufZ = imageLoad(uDepthImageZ,coord).r; \n" + ; + } else if (_glinfo.ext_fetch) { + m_part += + " highp float bufZ = depthZ.r; \n" + ; + } } + m_part += " highp int iZ = bufZ > 0.999 ? 262143 : int(floor(bufZ * 262143.0));\n" " mediump int y0 = clamp(iZ/512, 0, 511); \n" @@ -90,7 +121,7 @@ namespace glsl { "} \n" ; - if (_glinfo.fetch_depth) + if (config.frameBufferEmulation.N64DepthCompare == 0 && _glinfo.fetch_depth) m_part = "#extension GL_ARM_shader_framebuffer_fetch_depth_stencil : enable \n" + m_part; } }; diff --git a/src/Graphics/OpenGLContext/opengl_GLInfo.cpp b/src/Graphics/OpenGLContext/opengl_GLInfo.cpp index 387a86a5..15b39eb5 100644 --- a/src/Graphics/OpenGLContext/opengl_GLInfo.cpp +++ b/src/Graphics/OpenGLContext/opengl_GLInfo.cpp @@ -52,8 +52,7 @@ void GLInfo::init() { imageTextures = (numericVersion >= 31); msaa = numericVersion >= 31; } else { - imageTextures = ((numericVersion >= 43) || (Utils::isExtensionSupported(*this, "GL_ARB_shader_image_load_store") && - Utils::isExtensionSupported(*this, "GL_ARB_compute_shader"))); + imageTextures = (numericVersion >= 42) || Utils::isExtensionSupported(*this, "GL_ARB_shader_image_load_store"); msaa = true; }