diff --git a/res/CMakeLists.txt b/res/CMakeLists.txt index 1913c065..b91f2165 100644 --- a/res/CMakeLists.txt +++ b/res/CMakeLists.txt @@ -211,7 +211,6 @@ add_resources( shaders/imesh_point.vert shaders/imesh_tex.frag shaders/imesh_texa.frag - shaders/imesh_texr.frag shaders/imesh_tex.vert shaders/mesh.frag shaders/mesh.vert diff --git a/res/shaders/imesh_texa.frag b/res/shaders/imesh_texa.frag index db2934ea..ed21a86d 100644 --- a/res/shaders/imesh_texa.frag +++ b/res/shaders/imesh_texa.frag @@ -9,5 +9,5 @@ uniform sampler2D texture; varying vec2 fragTex; void main() { - gl_FragColor = vec4(color.rgb, color.a * texture2D(texture, fragTex).a); + gl_FragColor = vec4(color.rgb, color.a * texture2D(texture, fragTex).TEX_ALPHA); } diff --git a/res/shaders/imesh_texr.frag b/res/shaders/imesh_texr.frag deleted file mode 100644 index 5d7bc68c..00000000 --- a/res/shaders/imesh_texr.frag +++ /dev/null @@ -1,13 +0,0 @@ -//----------------------------------------------------------------------------- -// Indexed Mesh rendering shader -// -// Copyright 2016 Aleksey Egorov -//----------------------------------------------------------------------------- -uniform vec4 color; -uniform sampler2D texture; - -varying vec2 fragTex; - -void main() { - gl_FragColor = vec4(color.rgb, color.a * texture2D(texture, fragTex).r); -} diff --git a/res/shaders/mesh_fill.frag b/res/shaders/mesh_fill.frag index 4521ca96..74b38603 100644 --- a/res/shaders/mesh_fill.frag +++ b/res/shaders/mesh_fill.frag @@ -7,6 +7,6 @@ uniform vec4 color; uniform sampler2D texture; void main() { - if(texture2D(texture, gl_FragCoord.xy / 32.0).a < 0.5) discard; + if(texture2D(texture, gl_FragCoord.xy / 32.0).TEX_ALPHA < 0.5) discard; gl_FragColor = color; } diff --git a/src/render/gl2shader.cpp b/src/render/gl2shader.cpp index 786a6a99..828808ca 100644 --- a/src/render/gl2shader.cpp +++ b/src/render/gl2shader.cpp @@ -84,12 +84,21 @@ static GLuint CompileShader(const std::string &res, GLenum type) { // the `precision` keyword entirely, because that's clearly how minor versions work. // Christ, what a trash fire. - std::string src(resData, size); + const char *prelude; #if defined(HAVE_GLES) - src = "#version 100\nprecision highp float;\n" + src; + prelude = R"( +#version 100 +#define TEX_ALPHA a +precision highp float; +)"; #else - src = "#version 120\n" + src; + prelude = R"( +#version 120 +#define TEX_ALPHA r +)"; #endif + std::string src(resData, size); + src = prelude + src; GLuint shader = glCreateShader(type); ssassert(shader != 0, "glCreateShader failed");