]> git.lizzy.rs Git - minetest.git/commitdiff
Fix GLES2 discard behaviour (texture transparency)
authorsfan5 <sfan5@live.de>
Fri, 10 Sep 2021 19:59:29 +0000 (21:59 +0200)
committersfan5 <sfan5@live.de>
Fri, 17 Sep 2021 16:13:50 +0000 (18:13 +0200)
client/shaders/nodes_shader/opengl_fragment.glsl
client/shaders/object_shader/opengl_fragment.glsl
src/client/shader.cpp

index f85ca7b4813a857690187d2975b8cfe1fa6fcf81..87ef9af7d649d3c16b52ff91a91b58a2b5194062 100644 (file)
@@ -463,13 +463,16 @@ void main(void)
        vec2 uv = varTexCoord.st;
 
        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,
        // and also on GLES 2, where GL_ALPHA_TEST is missing entirely.
-       if (base.a == 0.0) {
+#ifdef USE_DISCARD
+       if (base.a == 0.0)
+               discard;
+#endif
+#ifdef USE_DISCARD_REF
+       if (base.a < 0.5)
                discard;
-       }
 #endif
 
        color = base.rgb;
index 8d6f57a44383323333cacd900a7c9dcf7cc0b004..9a0b90f158a74406e1f389f3814c7fe7cf32e309 100644 (file)
@@ -328,13 +328,16 @@ void main(void)
        vec2 uv = varTexCoord.st;
        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,
        // and also on GLES 2, where GL_ALPHA_TEST is missing entirely.
-       if (base.a == 0.0) {
+#ifdef USE_DISCARD
+       if (base.a == 0.0)
+               discard;
+#endif
+#ifdef USE_DISCARD_REF
+       if (base.a < 0.5)
                discard;
-       }
 #endif
 
        color = base.rgb;
index 0b35c37afb134af6ac0c2506e845cab3dc097d7e..dc9e9ae6d64a3b9bdaa939c65bc787a51ba20110 100644 (file)
@@ -674,8 +674,12 @@ ShaderInfo ShaderSource::generateShader(const std::string &name,
        if (strstr(gl_renderer, "GC7000"))
                use_discard = true;
 #endif
-       if (use_discard && shaderinfo.base_material != video::EMT_SOLID)
-               shaders_header << "#define USE_DISCARD 1\n";
+       if (use_discard) {
+               if (shaderinfo.base_material == video::EMT_TRANSPARENT_ALPHA_CHANNEL)
+                       shaders_header << "#define USE_DISCARD 1\n";
+               else if (shaderinfo.base_material == video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF)
+                       shaders_header << "#define USE_DISCARD_REF 1\n";
+       }
 
 #define PROVIDE(constant) shaders_header << "#define " #constant " " << (int)constant << "\n"