diff options
author | Hugo Locurcio <hugo.locurcio@hugo.pro> | 2021-08-14 18:29:52 +0200 |
---|---|---|
committer | Hugo Locurcio <hugo.locurcio@hugo.pro> | 2022-08-01 23:38:06 +0200 |
commit | 813f6a5d57be7c5003cc25521556c11215907a55 (patch) | |
tree | db7665adfc229b59538c7730e8b6f5d04b5a04be /servers/rendering/renderer_rd | |
parent | 5ecd61a3150f87a433dd5a7ff49a842b72516640 (diff) |
Add `hint_transparent` to use a transparent black placeholder texture
This can be used in shaders to avoid the need to supply a transparent
placeholder texture manually.
Diffstat (limited to 'servers/rendering/renderer_rd')
3 files changed, 22 insertions, 0 deletions
diff --git a/servers/rendering/renderer_rd/storage_rd/material_storage.cpp b/servers/rendering/renderer_rd/storage_rd/material_storage.cpp index 8297e72260..88ce6c261c 100644 --- a/servers/rendering/renderer_rd/storage_rd/material_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/material_storage.cpp @@ -1125,6 +1125,9 @@ void MaterialStorage::MaterialData::update_textures(const HashMap<StringName, Va case ShaderLanguage::ShaderNode::Uniform::HINT_DEFAULT_BLACK: { rd_texture = texture_storage->texture_rd_get_default(TextureStorage::DEFAULT_RD_TEXTURE_BLACK); } break; + case ShaderLanguage::ShaderNode::Uniform::HINT_DEFAULT_TRANSPARENT: { + rd_texture = texture_storage->texture_rd_get_default(TextureStorage::DEFAULT_RD_TEXTURE_TRANSPARENT); + } break; case ShaderLanguage::ShaderNode::Uniform::HINT_ANISOTROPY: { rd_texture = texture_storage->texture_rd_get_default(TextureStorage::DEFAULT_RD_TEXTURE_ANISO); } break; diff --git a/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp b/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp index 17a6ad57f9..e20a04ff2a 100644 --- a/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp @@ -96,6 +96,7 @@ TextureStorage::TextureStorage() { Vector<uint8_t> pv; pv.resize(16 * 4); for (int i = 0; i < 16; i++) { + // Opaque white. pv.set(i * 4 + 0, 255); pv.set(i * 4 + 1, 255); pv.set(i * 4 + 2, 255); @@ -109,6 +110,7 @@ TextureStorage::TextureStorage() { } for (int i = 0; i < 16; i++) { + // Opaque black. pv.set(i * 4 + 0, 0); pv.set(i * 4 + 1, 0); pv.set(i * 4 + 2, 0); @@ -122,6 +124,21 @@ TextureStorage::TextureStorage() { } for (int i = 0; i < 16; i++) { + // Transparent black. + pv.set(i * 4 + 0, 0); + pv.set(i * 4 + 1, 0); + pv.set(i * 4 + 2, 0); + pv.set(i * 4 + 3, 0); + } + + { + Vector<Vector<uint8_t>> vpv; + vpv.push_back(pv); + default_rd_textures[DEFAULT_RD_TEXTURE_TRANSPARENT] = RD::get_singleton()->texture_create(tformat, RD::TextureView(), vpv); + } + + for (int i = 0; i < 16; i++) { + // Opaque normal map "flat" color. pv.set(i * 4 + 0, 128); pv.set(i * 4 + 1, 128); pv.set(i * 4 + 2, 255); @@ -135,6 +152,7 @@ TextureStorage::TextureStorage() { } for (int i = 0; i < 16; i++) { + // Opaque flowmap "flat" color. pv.set(i * 4 + 0, 255); pv.set(i * 4 + 1, 128); pv.set(i * 4 + 2, 255); diff --git a/servers/rendering/renderer_rd/storage_rd/texture_storage.h b/servers/rendering/renderer_rd/storage_rd/texture_storage.h index f07f764761..682c951f63 100644 --- a/servers/rendering/renderer_rd/storage_rd/texture_storage.h +++ b/servers/rendering/renderer_rd/storage_rd/texture_storage.h @@ -46,6 +46,7 @@ public: enum DefaultRDTexture { DEFAULT_RD_TEXTURE_WHITE, DEFAULT_RD_TEXTURE_BLACK, + DEFAULT_RD_TEXTURE_TRANSPARENT, DEFAULT_RD_TEXTURE_NORMAL, DEFAULT_RD_TEXTURE_ANISO, DEFAULT_RD_TEXTURE_DEPTH, |