]> git.lizzy.rs Git - minetest.git/commitdiff
shaders: Fix transparency on GC7000L (#10036)
authormntmn <lukas@mnt.mn>
Tue, 25 Aug 2020 18:49:51 +0000 (20:49 +0200)
committerGitHub <noreply@github.com>
Tue, 25 Aug 2020 18:49:51 +0000 (20:49 +0200)
Workaround for the missing GL_ALPHA_TEST implementation in Mesa (etnaviv driver).

client/shaders/nodes_shader/opengl_fragment.glsl
client/shaders/object_shader/opengl_fragment.glsl
src/client/shader.cpp

index 19e6c2d861734f5bf84e0f1c5aed49604d03ce94..7213612bd25d21c3dc30fcb3269f78c96d6da8a0 100644 (file)
@@ -190,6 +190,14 @@ void main(void)
 #endif
        vec4 base = texture2D(baseTexture, uv).rgba;
 
+#ifdef USE_DISCARD
+       // If alpha is zero, we can just discard the pixel. This fixes transparency
+       // on GPUs like GC7000L, where GL_ALPHA_TEST is not implemented in mesa.
+       if (base.a == 0.0) {
+               discard;
+       }
+#endif
+
 #ifdef ENABLE_BUMPMAPPING
        if (use_normalmap) {
                vec3 L = normalize(lightVec);
index 0534dc049ca7a4f0cf79af52c3797ce6d7c0c29d..2d33ca4392ddd15fbd71aecb771a1568e80ec78a 100644 (file)
@@ -129,6 +129,14 @@ void main(void)
 
        vec4 base = texture2D(baseTexture, uv).rgba;
 
+#ifdef USE_DISCARD
+       // If alpha is zero, we can just discard the pixel. This fixes transparency
+       // on GPUs like GC7000L, where GL_ALPHA_TEST is not implemented in mesa.
+       if (base.a == 0.0) {
+               discard;
+       }
+#endif
+
 #ifdef ENABLE_BUMPMAPPING
        if (use_normalmap) {
                vec3 L = normalize(lightVec);
index ee6079f7aeaba6423d4d2494e275ed75fd3c49f3..0aba7b118f985647ed698bc2481f402724dab458 100644 (file)
@@ -38,6 +38,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "gamedef.h"
 #include "client/tile.h"
 
+#if ENABLE_GLES
+#ifdef _IRR_COMPILE_WITH_OGLES1_
+#include <GLES/gl.h>
+#else
+#include <GLES2/gl2.h>
+#endif
+#else
+#include <GL/gl.h>
+#endif
+
 /*
        A cache from shader name to shader path
 */
@@ -607,6 +617,14 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp
        // Create shaders header
        std::string shaders_header = "#version 120\n";
 
+#ifdef __unix__
+       // For renderers that should use discard instead of GL_ALPHA_TEST
+       const char* gl_renderer = (const char*)glGetString(GL_RENDERER);
+       if (strstr(gl_renderer, "GC7000")) {
+               shaders_header += "#define USE_DISCARD\n";
+       }
+#endif
+
        static const char* drawTypes[] = {
                "NDT_NORMAL",
                "NDT_AIRLIKE",