diff --git a/drivers/gles2/rasterizer_canvas_gles2.cpp b/drivers/gles2/rasterizer_canvas_gles2.cpp index 4cbd6bbe200..9891b4252cb 100644 --- a/drivers/gles2/rasterizer_canvas_gles2.cpp +++ b/drivers/gles2/rasterizer_canvas_gles2.cpp @@ -1682,6 +1682,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; @@ -2044,6 +2047,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 8b90051f2f9..359378acfb9 100644 --- a/drivers/gles2/rasterizer_scene_gles2.cpp +++ b/drivers/gles2/rasterizer_scene_gles2.cpp @@ -1420,6 +1420,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 b10e20e0367..416df39dde9 100644 --- a/drivers/gles2/rasterizer_storage_gles2.cpp +++ b/drivers/gles2/rasterizer_storage_gles2.cpp @@ -6456,32 +6456,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) { @@ -6489,13 +6502,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) { @@ -6503,7 +6516,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 fa9a8e6fab7..25523daab83 100644 --- a/drivers/gles2/rasterizer_storage_gles2.h +++ b/drivers/gles2/rasterizer_storage_gles2.h @@ -111,6 +111,7 @@ public: struct Resources { GLuint white_tex; GLuint black_tex; + GLuint transparent_tex; GLuint normal_tex; GLuint aniso_tex; diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp index 4323d741260..62e609c3a32 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.cpp +++ b/drivers/gles3/rasterizer_canvas_gles3.cpp @@ -195,6 +195,9 @@ void RasterizerCanvasGLES3::_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; @@ -1275,6 +1278,9 @@ void RasterizerCanvasGLES3::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/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index 87a629a0144..3ab1f447e1d 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -1195,6 +1195,9 @@ bool RasterizerSceneGLES3::_setup_material(RasterizerStorageGLES3::Material *p_m case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK: { tex = storage->resources.black_tex; } break; + case ShaderLanguage::ShaderNode::Uniform::HINT_TRANSPARENT: { + tex = storage->resources.transparent_tex; + } break; case ShaderLanguage::ShaderNode::Uniform::HINT_ANISO: { tex = storage->resources.aniso_tex; } break; diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index a98f6275719..b992292f3cf 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -6596,6 +6596,9 @@ void RasterizerStorageGLES3::update_particles() { case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK: { tex = resources.black_tex; } break; + case ShaderLanguage::ShaderNode::Uniform::HINT_TRANSPARENT: { + tex = resources.transparent_tex; + } break; case ShaderLanguage::ShaderNode::Uniform::HINT_ANISO: { tex = resources.aniso_tex; } break; @@ -8202,32 +8205,45 @@ void RasterizerStorageGLES3::initialize() { shaders.copy.init(); { - //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) { @@ -8235,13 +8251,13 @@ void RasterizerStorageGLES3::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) { @@ -8249,7 +8265,6 @@ void RasterizerStorageGLES3::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); @@ -8264,15 +8279,15 @@ void RasterizerStorageGLES3::initialize() { glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, 8, 8, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, depthtexdata); glBindTexture(GL_TEXTURE_2D, 0); + // Opaque white color for 3D texture. glGenTextures(1, &resources.white_tex_3d); - glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_3D, resources.white_tex_3d); glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, 2, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, whitetexdata); - glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0); + // Opaque white color for texture array. glGenTextures(1, &resources.white_tex_array); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D_ARRAY, resources.white_tex_array); @@ -8411,6 +8426,7 @@ void RasterizerStorageGLES3::initialize() { void RasterizerStorageGLES3::finalize() { glDeleteTextures(1, &resources.white_tex); glDeleteTextures(1, &resources.black_tex); + glDeleteTextures(1, &resources.transparent_tex); glDeleteTextures(1, &resources.normal_tex); glDeleteTextures(1, &resources.depth_tex); } diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h index 8c2a8b72e21..e2527136d4c 100644 --- a/drivers/gles3/rasterizer_storage_gles3.h +++ b/drivers/gles3/rasterizer_storage_gles3.h @@ -140,6 +140,7 @@ public: struct Resources { GLuint white_tex; GLuint black_tex; + GLuint transparent_tex; GLuint normal_tex; GLuint aniso_tex; GLuint depth_tex; diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index edb8a7514e4..6bd31b3e3b5 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -198,6 +198,7 @@ const char *ShaderLanguage::token_names[TK_MAX] = { "RENDER_MODE", "HINT_WHITE_TEXTURE", "HINT_BLACK_TEXTURE", + "HINT_TRANSPARENT_TEXTURE", "HINT_NORMAL_TEXTURE", "HINT_ANISO_TEXTURE", "HINT_ALBEDO_TEXTURE", @@ -295,6 +296,7 @@ const ShaderLanguage::KeyWord ShaderLanguage::keyword_list[] = { { TK_RENDER_MODE, "render_mode" }, { TK_HINT_WHITE_TEXTURE, "hint_white" }, { TK_HINT_BLACK_TEXTURE, "hint_black" }, + { TK_HINT_TRANSPARENT_TEXTURE, "hint_transparent" }, { TK_HINT_NORMAL_TEXTURE, "hint_normal" }, { TK_HINT_ANISO_TEXTURE, "hint_aniso" }, { TK_HINT_ALBEDO_TEXTURE, "hint_albedo" }, @@ -5977,6 +5979,8 @@ Error ShaderLanguage::_parse_shader(const Map &p_funct uniform2.hint = ShaderNode::Uniform::HINT_WHITE; } else if (tk.type == TK_HINT_BLACK_TEXTURE) { uniform2.hint = ShaderNode::Uniform::HINT_BLACK; + } else if (tk.type == TK_HINT_TRANSPARENT_TEXTURE) { + uniform2.hint = ShaderNode::Uniform::HINT_TRANSPARENT; } else if (tk.type == TK_HINT_NORMAL_TEXTURE) { uniform2.hint = ShaderNode::Uniform::HINT_NORMAL; } else if (tk.type == TK_HINT_ANISO_TEXTURE) { diff --git a/servers/visual/shader_language.h b/servers/visual/shader_language.h index 97bfe504c0c..826b8b20ed8 100644 --- a/servers/visual/shader_language.h +++ b/servers/visual/shader_language.h @@ -157,6 +157,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, @@ -643,6 +644,7 @@ public: HINT_NORMAL, HINT_BLACK, HINT_WHITE, + HINT_TRANSPARENT, HINT_ANISO, HINT_MAX };