diff --git a/drivers/gles3/storage/material_storage.cpp b/drivers/gles3/storage/material_storage.cpp index 41c23fc3ec0..25af7ff6913 100644 --- a/drivers/gles3/storage/material_storage.cpp +++ b/drivers/gles3/storage/material_storage.cpp @@ -586,11 +586,7 @@ void ShaderData::get_shader_uniform_list(List *p_param_list) const if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_LOCAL) { continue; } - if (E.value.texture_order >= 0) { - filtered_uniforms.push_back(Pair(E.key, E.value.texture_order + 100000)); - } else { - filtered_uniforms.push_back(Pair(E.key, E.value.order)); - } + filtered_uniforms.push_back(Pair(E.key, E.value.prop_order)); } int uniform_count = filtered_uniforms.size(); sorter.sort(filtered_uniforms.ptr(), uniform_count); @@ -640,7 +636,7 @@ bool ShaderData::is_parameter_texture(const StringName &p_param) const { return false; } - return uniforms[p_param].texture_order >= 0; + return uniforms[p_param].is_texture(); } /////////////////////////////////////////////////////////////////////////// @@ -719,7 +715,7 @@ void MaterialData::update_uniform_buffer(const HashMap &E : p_uniforms) { - if (E.value.order < 0) { + if (E.value.is_texture()) { continue; // texture, does not go here } diff --git a/servers/rendering/dummy/storage/material_storage.cpp b/servers/rendering/dummy/storage/material_storage.cpp index 64f6b55172c..e8b553ca763 100644 --- a/servers/rendering/dummy/storage/material_storage.cpp +++ b/servers/rendering/dummy/storage/material_storage.cpp @@ -102,11 +102,7 @@ void MaterialStorage::get_shader_parameter_list(RID p_shader, List if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_LOCAL) { continue; } - if (E.value.texture_order >= 0) { - filtered_uniforms.push_back(Pair(E.key, E.value.texture_order + 100000)); - } else { - filtered_uniforms.push_back(Pair(E.key, E.value.order)); - } + filtered_uniforms.push_back(Pair(E.key, E.value.prop_order)); } int uniform_count = filtered_uniforms.size(); sorter.sort(filtered_uniforms.ptr(), uniform_count); diff --git a/servers/rendering/renderer_rd/storage_rd/material_storage.cpp b/servers/rendering/renderer_rd/storage_rd/material_storage.cpp index 8b74ebfacd1..63dc54e24ca 100644 --- a/servers/rendering/renderer_rd/storage_rd/material_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/material_storage.cpp @@ -580,11 +580,7 @@ void MaterialStorage::ShaderData::get_shader_uniform_list(List *p_ if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_LOCAL) { continue; } - if (E.value.texture_order >= 0) { - filtered_uniforms.push_back(Pair(E.key, E.value.texture_order + 100000)); - } else { - filtered_uniforms.push_back(Pair(E.key, E.value.order)); - } + filtered_uniforms.push_back(Pair(E.key, E.value.prop_order)); } int uniform_count = filtered_uniforms.size(); sorter.sort(filtered_uniforms.ptr(), uniform_count); @@ -634,7 +630,7 @@ bool MaterialStorage::ShaderData::is_parameter_texture(const StringName &p_param return false; } - return uniforms[p_param].texture_order >= 0; + return uniforms[p_param].is_texture(); } /////////////////////////////////////////////////////////////////////////// @@ -645,7 +641,7 @@ void MaterialStorage::MaterialData::update_uniform_buffer(const HashMap &E : p_uniforms) { - if (E.value.order < 0) { + if (E.value.is_texture()) { continue; // texture, does not go here } diff --git a/servers/rendering/shader_compiler.cpp b/servers/rendering/shader_compiler.cpp index 2542f2eed76..49e005ca962 100644 --- a/servers/rendering/shader_compiler.cpp +++ b/servers/rendering/shader_compiler.cpp @@ -922,7 +922,7 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene if (shader->uniforms.has(vnode->name)) { //its a uniform! const ShaderLanguage::ShaderNode::Uniform &u = shader->uniforms[vnode->name]; - if (u.texture_order >= 0) { + if (u.is_texture()) { StringName name; if (u.hint == ShaderLanguage::ShaderNode::Uniform::HINT_SCREEN_TEXTURE) { name = "color_buffer"; @@ -1039,7 +1039,7 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene if (shader->uniforms.has(anode->name)) { //its a uniform! const ShaderLanguage::ShaderNode::Uniform &u = shader->uniforms[anode->name]; - if (u.texture_order >= 0) { + if (u.is_texture()) { code = _mkid(anode->name); //texture, use as is } else { //a scalar or vector diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp index 10c1158d958..0d34ab62029 100644 --- a/servers/rendering/shader_language.cpp +++ b/servers/rendering/shader_language.cpp @@ -8202,6 +8202,7 @@ Error ShaderLanguage::_parse_shader(const HashMap &p_f int texture_binding = 0; int uniforms = 0; int instance_index = 0; + int prop_index = 0; #ifdef DEBUG_ENABLED uint64_t uniform_buffer_size = 0; uint64_t max_uniform_buffer_size = 0; @@ -8756,6 +8757,7 @@ Error ShaderLanguage::_parse_shader(const HashMap &p_f ++texture_binding; } uniform.order = -1; + uniform.prop_order = prop_index++; } else { if (uniform_scope == ShaderNode::Uniform::SCOPE_INSTANCE && (type == TYPE_MAT2 || type == TYPE_MAT3 || type == TYPE_MAT4)) { _set_error(vformat(RTR("The '%s' qualifier is not supported for matrix types."), "SCOPE_INSTANCE")); @@ -8764,6 +8766,7 @@ Error ShaderLanguage::_parse_shader(const HashMap &p_f uniform.texture_order = -1; if (uniform_scope != ShaderNode::Uniform::SCOPE_INSTANCE) { uniform.order = uniforms++; + uniform.prop_order = prop_index++; #ifdef DEBUG_ENABLED if (check_device_limit_warnings) { if (uniform.array_size > 0) { diff --git a/servers/rendering/shader_language.h b/servers/rendering/shader_language.h index 40f524ec9d7..4354ea970b2 100644 --- a/servers/rendering/shader_language.h +++ b/servers/rendering/shader_language.h @@ -648,6 +648,7 @@ public: }; int order = 0; + int prop_order = 0; int texture_order = 0; int texture_binding = 0; DataType type = TYPE_VOID; @@ -664,6 +665,11 @@ public: String group; String subgroup; + _FORCE_INLINE_ bool is_texture() const { + // Order is assigned to -1 for texture uniforms. + return order < 0; + } + Uniform() { hint_range[0] = 0.0f; hint_range[1] = 1.0f;