Skip to content

Commit 44c9808

Browse files
authoredAug 25, 2020
shaders: Fix transparency on GC7000L (#10036)
Workaround for the missing GL_ALPHA_TEST implementation in Mesa (etnaviv driver).
1 parent f27cf47 commit 44c9808

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed
 

‎client/shaders/nodes_shader/opengl_fragment.glsl

+8
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ void main(void)
190190
#endif
191191
vec4 base = texture2D(baseTexture, uv).rgba;
192192

193+
#ifdef USE_DISCARD
194+
// If alpha is zero, we can just discard the pixel. This fixes transparency
195+
// on GPUs like GC7000L, where GL_ALPHA_TEST is not implemented in mesa.
196+
if (base.a == 0.0) {
197+
discard;
198+
}
199+
#endif
200+
193201
#ifdef ENABLE_BUMPMAPPING
194202
if (use_normalmap) {
195203
vec3 L = normalize(lightVec);

‎client/shaders/object_shader/opengl_fragment.glsl

+8
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ void main(void)
129129

130130
vec4 base = texture2D(baseTexture, uv).rgba;
131131

132+
#ifdef USE_DISCARD
133+
// If alpha is zero, we can just discard the pixel. This fixes transparency
134+
// on GPUs like GC7000L, where GL_ALPHA_TEST is not implemented in mesa.
135+
if (base.a == 0.0) {
136+
discard;
137+
}
138+
#endif
139+
132140
#ifdef ENABLE_BUMPMAPPING
133141
if (use_normalmap) {
134142
vec3 L = normalize(lightVec);

‎src/client/shader.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3838
#include "gamedef.h"
3939
#include "client/tile.h"
4040

41+
#if ENABLE_GLES
42+
#ifdef _IRR_COMPILE_WITH_OGLES1_
43+
#include <GLES/gl.h>
44+
#else
45+
#include <GLES2/gl2.h>
46+
#endif
47+
#else
48+
#include <GL/gl.h>
49+
#endif
50+
4151
/*
4252
A cache from shader name to shader path
4353
*/
@@ -607,6 +617,14 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp
607617
// Create shaders header
608618
std::string shaders_header = "#version 120\n";
609619

620+
#ifdef __unix__
621+
// For renderers that should use discard instead of GL_ALPHA_TEST
622+
const char* gl_renderer = (const char*)glGetString(GL_RENDERER);
623+
if (strstr(gl_renderer, "GC7000")) {
624+
shaders_header += "#define USE_DISCARD\n";
625+
}
626+
#endif
627+
610628
static const char* drawTypes[] = {
611629
"NDT_NORMAL",
612630
"NDT_AIRLIKE",

0 commit comments

Comments
 (0)
Please sign in to comment.