Skip to content

Commit 29df589

Browse files
committed
Implement instance uniforms in Compatibility renderer
1 parent 97ef3c8 commit 29df589

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
@@ -3453,6 +3453,7 @@ void RasterizerSceneGLES3::_render_list_template(RenderListParameters *p_params,
34533453
}
34543454

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

34573458
if (p_pass_mode == PASS_MODE_MATERIAL) {
34583459
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
@@ -261,6 +261,7 @@ uniform highp mat4 world_transform;
261261
uniform highp vec3 compressed_aabb_position;
262262
uniform highp vec3 compressed_aabb_size;
263263
uniform highp vec4 uv_scale;
264+
uniform highp uint instance_offset;
264265

265266
uniform highp uint model_flags;
266267

@@ -965,6 +966,7 @@ ivec2 multiview_uv(ivec2 uv) {
965966
uniform highp mat4 world_transform;
966967
uniform mediump float opaque_prepass_threshold;
967968
uniform highp uint model_flags;
969+
uniform highp uint instance_offset;
968970

969971
#if defined(RENDER_MATERIAL)
970972
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
@@ -1371,6 +1371,7 @@ MaterialStorage::MaterialStorage() {
13711371

13721372
actions.check_multiview_samplers = RasterizerGLES3::get_singleton()->is_xr_enabled();
13731373
actions.global_buffer_array_variable = "global_shader_uniforms";
1374+
actions.instance_uniform_index_variable = "instance_offset";
13741375

13751376
shaders.compiler_scene.initialize(actions);
13761377
}

servers/rendering/shader_compiler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene
949949
code = _get_global_shader_uniform_from_type_and_index(p_default_actions.global_buffer_array_variable, code, u.type);
950950
} else if (u.scope == ShaderLanguage::ShaderNode::Uniform::SCOPE_INSTANCE) {
951951
//instance variable, index it as such
952-
code = "(" + p_default_actions.instance_uniform_index_variable + "+" + itos(u.instance_index) + ")";
952+
code = "(" + p_default_actions.instance_uniform_index_variable + "+" + itos(u.instance_index) + "u)";
953953
code = _get_global_shader_uniform_from_type_and_index(p_default_actions.global_buffer_array_variable, code, u.type);
954954
} else {
955955
//regular uniform, index from UBO
@@ -1049,7 +1049,7 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene
10491049
code = _get_global_shader_uniform_from_type_and_index(p_default_actions.global_buffer_array_variable, code, u.type);
10501050
} else if (u.scope == ShaderLanguage::ShaderNode::Uniform::SCOPE_INSTANCE) {
10511051
//instance variable, index it as such
1052-
code = "(" + p_default_actions.instance_uniform_index_variable + "+" + itos(u.instance_index) + ")";
1052+
code = "(" + p_default_actions.instance_uniform_index_variable + "+" + itos(u.instance_index) + "u)";
10531053
code = _get_global_shader_uniform_from_type_and_index(p_default_actions.global_buffer_array_variable, code, u.type);
10541054
} else {
10551055
//regular uniform, index from UBO

servers/rendering/shader_language.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9049,10 +9049,6 @@ Error ShaderLanguage::_parse_shader(const HashMap<StringName, FunctionInfo> &p_f
90499049
_set_error(vformat(RTR("Uniform instances are not yet implemented for '%s' shaders."), shader_type_identifier));
90509050
return ERR_PARSE_ERROR;
90519051
}
9052-
if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
9053-
_set_error(RTR("Uniform instances are not supported in gl_compatibility shaders."));
9054-
return ERR_PARSE_ERROR;
9055-
}
90569052
if (uniform_scope == ShaderNode::Uniform::SCOPE_LOCAL) {
90579053
tk = _get_token();
90589054
if (tk.type != TK_UNIFORM) {

0 commit comments

Comments
 (0)