mirror of
https://github.com/godotengine/godot.git
synced 2024-11-29 07:32:20 +00:00
Add hint_transparent
to use a transparent black placeholder texture
This commit is contained in:
parent
17e8fa8632
commit
ab9a95f266
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -6449,32 +6449,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) {
|
||||
@ -6482,13 +6495,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) {
|
||||
@ -6496,7 +6509,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);
|
||||
|
@ -111,6 +111,7 @@ public:
|
||||
struct Resources {
|
||||
GLuint white_tex;
|
||||
GLuint black_tex;
|
||||
GLuint transparent_tex;
|
||||
GLuint normal_tex;
|
||||
GLuint aniso_tex;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -6588,6 +6588,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;
|
||||
@ -8194,32 +8197,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) {
|
||||
@ -8227,13 +8243,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) {
|
||||
@ -8241,7 +8257,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);
|
||||
@ -8256,15 +8271,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);
|
||||
@ -8403,6 +8418,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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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<StringName, FunctionInfo> &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) {
|
||||
|
@ -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
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user