diff --git a/drivers/gles2/rasterizer_canvas_gles2.cpp b/drivers/gles2/rasterizer_canvas_gles2.cpp index d935c0857..bfb6f3c6a 100644 --- a/drivers/gles2/rasterizer_canvas_gles2.cpp +++ b/drivers/gles2/rasterizer_canvas_gles2.cpp @@ -30,8 +30,8 @@ #include "rasterizer_canvas_gles2.h" -#include "core/os/os.h" #include "core/config/project_settings.h" +#include "core/os/os.h" #include "drivers/gles2/rasterizer_gles2.h" #include "drivers/gles_common/rasterizer_asserts.h" #include "rasterizer_scene_gles2.h" @@ -1678,6 +1678,9 @@ void RasterizerCanvasGLES2::_legacy_canvas_render_item(Item *p_ci, RenderItemSta case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK: { glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex); } break; + case ShaderLanguage::ShaderNode::Uniform::HINT_TRANSPARENT: { + glBindTexture(GL_TEXTURE_2D, storage->resources.transparent_tex); + } break; case ShaderLanguage::ShaderNode::Uniform::HINT_ANISO: { glBindTexture(GL_TEXTURE_2D, storage->resources.aniso_tex); } break; @@ -2040,6 +2043,9 @@ void RasterizerCanvasGLES2::render_joined_item(const BItemJoined &p_bij, RenderI case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK: { glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex); } break; + case ShaderLanguage::ShaderNode::Uniform::HINT_TRANSPARENT: { + glBindTexture(GL_TEXTURE_2D, storage->resources.transparent_tex); + } break; case ShaderLanguage::ShaderNode::Uniform::HINT_ANISO: { glBindTexture(GL_TEXTURE_2D, storage->resources.aniso_tex); } break; diff --git a/drivers/gles2/rasterizer_scene_gles2.cpp b/drivers/gles2/rasterizer_scene_gles2.cpp index de4a60357..25492dd86 100644 --- a/drivers/gles2/rasterizer_scene_gles2.cpp +++ b/drivers/gles2/rasterizer_scene_gles2.cpp @@ -1392,6 +1392,9 @@ bool RasterizerSceneGLES2::_setup_material(RasterizerStorageGLES2::Material *p_m case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK: { glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex); } break; + case ShaderLanguage::ShaderNode::Uniform::HINT_TRANSPARENT: { + glBindTexture(GL_TEXTURE_2D, storage->resources.transparent_tex); + } break; case ShaderLanguage::ShaderNode::Uniform::HINT_ANISO: { glBindTexture(GL_TEXTURE_2D, storage->resources.aniso_tex); } break; diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp index 1ba6a1adf..6b423a7d5 100644 --- a/drivers/gles2/rasterizer_storage_gles2.cpp +++ b/drivers/gles2/rasterizer_storage_gles2.cpp @@ -30,8 +30,8 @@ #include "rasterizer_storage_gles2.h" -#include "core/math/transform.h" #include "core/config/project_settings.h" +#include "core/math/transform.h" #include "rasterizer_canvas_gles2.h" #include "rasterizer_scene_gles2.h" #include "servers/visual/shader_language.h" @@ -6096,32 +6096,45 @@ void RasterizerStorageGLES2::initialize() { } { - //default textures + // Generate default textures. + // Opaque white color. glGenTextures(1, &resources.white_tex); unsigned char whitetexdata[8 * 8 * 3]; for (int i = 0; i < 8 * 8 * 3; i++) { whitetexdata[i] = 255; } - glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, resources.white_tex); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, whitetexdata); glGenerateMipmap(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); + // Opaque black color. glGenTextures(1, &resources.black_tex); unsigned char blacktexdata[8 * 8 * 3]; for (int i = 0; i < 8 * 8 * 3; i++) { blacktexdata[i] = 0; } - glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, resources.black_tex); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, blacktexdata); glGenerateMipmap(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); + // Transparent black color. + glGenTextures(1, &resources.transparent_tex); + unsigned char transparenttexdata[8 * 8 * 4]; + for (int i = 0; i < 8 * 8 * 4; i++) { + transparenttexdata[i] = 0; + } + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, resources.transparent_tex); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, transparenttexdata); + glGenerateMipmap(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, 0); + + // Opaque "flat" normal map color. glGenTextures(1, &resources.normal_tex); unsigned char normaltexdata[8 * 8 * 3]; for (int i = 0; i < 8 * 8 * 3; i += 3) { @@ -6129,13 +6142,13 @@ void RasterizerStorageGLES2::initialize() { normaltexdata[i + 1] = 128; normaltexdata[i + 2] = 255; } - glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, resources.normal_tex); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, normaltexdata); glGenerateMipmap(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); + // Opaque "flat" flowmap color. glGenTextures(1, &resources.aniso_tex); unsigned char anisotexdata[8 * 8 * 3]; for (int i = 0; i < 8 * 8 * 3; i += 3) { @@ -6143,7 +6156,6 @@ void RasterizerStorageGLES2::initialize() { anisotexdata[i + 1] = 128; anisotexdata[i + 2] = 0; } - glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, resources.aniso_tex); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, anisotexdata); diff --git a/drivers/gles2/rasterizer_storage_gles2.h b/drivers/gles2/rasterizer_storage_gles2.h index 408932f16..61853a23d 100644 --- a/drivers/gles2/rasterizer_storage_gles2.h +++ b/drivers/gles2/rasterizer_storage_gles2.h @@ -109,6 +109,7 @@ public: struct Resources { GLuint white_tex; GLuint black_tex; + GLuint transparent_tex; GLuint normal_tex; GLuint aniso_tex; diff --git a/servers/visual/shader_language.h b/servers/visual/shader_language.h index 48e953d6b..555c5df1f 100644 --- a/servers/visual/shader_language.h +++ b/servers/visual/shader_language.h @@ -35,8 +35,8 @@ #include "core/containers/ordered_hash_map.h" #include "core/object/script_language.h" #include "core/string/string_name.h" -#include "core/typedefs.h" #include "core/string/ustring.h" +#include "core/typedefs.h" #include "core/variant/variant.h" class ShaderLanguage { @@ -156,6 +156,7 @@ public: TK_RENDER_MODE, TK_HINT_WHITE_TEXTURE, TK_HINT_BLACK_TEXTURE, + TK_HINT_TRANSPARENT_TEXTURE, TK_HINT_NORMAL_TEXTURE, TK_HINT_ANISO_TEXTURE, TK_HINT_ALBEDO_TEXTURE, @@ -642,6 +643,7 @@ public: HINT_NORMAL, HINT_BLACK, HINT_WHITE, + HINT_TRANSPARENT, HINT_ANISO, HINT_MAX };