forked from Mirrorlandia_minetest/minetest
Fix GLES2 discard behaviour (texture transparency)
This commit is contained in:
parent
d1e0f73b77
commit
ea250ff5c5
@ -463,13 +463,16 @@ void main(void)
|
|||||||
vec2 uv = varTexCoord.st;
|
vec2 uv = varTexCoord.st;
|
||||||
|
|
||||||
vec4 base = texture2D(baseTexture, uv).rgba;
|
vec4 base = texture2D(baseTexture, uv).rgba;
|
||||||
#ifdef USE_DISCARD
|
|
||||||
// If alpha is zero, we can just discard the pixel. This fixes transparency
|
// 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,
|
// 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.
|
// 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;
|
discard;
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
color = base.rgb;
|
color = base.rgb;
|
||||||
|
@ -328,13 +328,16 @@ void main(void)
|
|||||||
vec2 uv = varTexCoord.st;
|
vec2 uv = varTexCoord.st;
|
||||||
vec4 base = texture2D(baseTexture, uv).rgba;
|
vec4 base = texture2D(baseTexture, uv).rgba;
|
||||||
|
|
||||||
#ifdef USE_DISCARD
|
|
||||||
// If alpha is zero, we can just discard the pixel. This fixes transparency
|
// 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,
|
// 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.
|
// 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;
|
discard;
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
color = base.rgb;
|
color = base.rgb;
|
||||||
|
@ -674,8 +674,12 @@ ShaderInfo ShaderSource::generateShader(const std::string &name,
|
|||||||
if (strstr(gl_renderer, "GC7000"))
|
if (strstr(gl_renderer, "GC7000"))
|
||||||
use_discard = true;
|
use_discard = true;
|
||||||
#endif
|
#endif
|
||||||
if (use_discard && shaderinfo.base_material != video::EMT_SOLID)
|
if (use_discard) {
|
||||||
|
if (shaderinfo.base_material == video::EMT_TRANSPARENT_ALPHA_CHANNEL)
|
||||||
shaders_header << "#define USE_DISCARD 1\n";
|
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"
|
#define PROVIDE(constant) shaders_header << "#define " #constant " " << (int)constant << "\n"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user