Skip to content

Commit 842f982

Browse files
authored
Merge pull request #96819 from clayjohn/GLES3-instance-uniforms
Implement instance uniforms in Compatibility renderer
2 parents e7c39ef + 29df589 commit 842f982

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

drivers/gles3/rasterizer_scene_gles3.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3443,6 +3443,7 @@ void RasterizerSceneGLES3::_render_list_template(RenderListParameters *p_params,
34433443
}
34443444

34453445
material_storage->shaders.scene_shader.version_set_uniform(SceneShaderGLES3::MODEL_FLAGS, inst->flags_cache, shader->version, instance_variant, spec_constants);
3446+
material_storage->shaders.scene_shader.version_set_uniform(SceneShaderGLES3::INSTANCE_OFFSET, uint32_t(inst->shader_uniforms_offset), shader->version, instance_variant, spec_constants);
34463447

34473448
if (p_pass_mode == PASS_MODE_MATERIAL) {
34483449
material_storage->shaders.scene_shader.version_set_uniform(SceneShaderGLES3::UV_OFFSET, p_params->uv_offset, shader->version, instance_variant, spec_constants);

drivers/gles3/shaders/scene.glsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ uniform highp mat4 world_transform;
430430
uniform highp vec3 compressed_aabb_position;
431431
uniform highp vec3 compressed_aabb_size;
432432
uniform highp vec4 uv_scale;
433+
uniform highp uint instance_offset;
433434

434435
uniform highp uint model_flags;
435436

@@ -1201,6 +1202,7 @@ ivec2 multiview_uv(ivec2 uv) {
12011202
uniform highp mat4 world_transform;
12021203
uniform mediump float opaque_prepass_threshold;
12031204
uniform highp uint model_flags;
1205+
uniform highp uint instance_offset;
12041206

12051207
#if defined(RENDER_MATERIAL)
12061208
layout(location = 0) out vec4 albedo_output_buffer;

drivers/gles3/storage/material_storage.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,7 @@ MaterialStorage::MaterialStorage() {
13791379

13801380
actions.check_multiview_samplers = RasterizerGLES3::get_singleton()->is_xr_enabled();
13811381
actions.global_buffer_array_variable = "global_shader_uniforms";
1382+
actions.instance_uniform_index_variable = "instance_offset";
13821383

13831384
shaders.compiler_scene.initialize(actions);
13841385
}

servers/rendering/shader_compiler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene
951951
code = _get_global_shader_uniform_from_type_and_index(p_default_actions.global_buffer_array_variable, code, u.type);
952952
} else if (u.scope == ShaderLanguage::ShaderNode::Uniform::SCOPE_INSTANCE) {
953953
//instance variable, index it as such
954-
code = "(" + p_default_actions.instance_uniform_index_variable + "+" + itos(u.instance_index) + ")";
954+
code = "(" + p_default_actions.instance_uniform_index_variable + "+" + itos(u.instance_index) + "u)";
955955
code = _get_global_shader_uniform_from_type_and_index(p_default_actions.global_buffer_array_variable, code, u.type);
956956
} else {
957957
//regular uniform, index from UBO
@@ -1051,7 +1051,7 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene
10511051
code = _get_global_shader_uniform_from_type_and_index(p_default_actions.global_buffer_array_variable, code, u.type);
10521052
} else if (u.scope == ShaderLanguage::ShaderNode::Uniform::SCOPE_INSTANCE) {
10531053
//instance variable, index it as such
1054-
code = "(" + p_default_actions.instance_uniform_index_variable + "+" + itos(u.instance_index) + ")";
1054+
code = "(" + p_default_actions.instance_uniform_index_variable + "+" + itos(u.instance_index) + "u)";
10551055
code = _get_global_shader_uniform_from_type_and_index(p_default_actions.global_buffer_array_variable, code, u.type);
10561056
} else {
10571057
//regular uniform, index from UBO

servers/rendering/shader_language.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9089,10 +9089,6 @@ Error ShaderLanguage::_parse_shader(const HashMap<StringName, FunctionInfo> &p_f
90899089
_set_error(vformat(RTR("Uniform instances are not yet implemented for '%s' shaders."), shader_type_identifier));
90909090
return ERR_PARSE_ERROR;
90919091
}
9092-
if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
9093-
_set_error(RTR("Uniform instances are not supported in gl_compatibility shaders."));
9094-
return ERR_PARSE_ERROR;
9095-
}
90969092
if (uniform_scope == ShaderNode::Uniform::SCOPE_LOCAL) {
90979093
tk = _get_token();
90989094
if (tk.type != TK_UNIFORM) {

0 commit comments

Comments
 (0)