Browse Source

Some fixes for instance shader parameters

Yuri Rubinsky 2 years ago
parent
commit
c07d13182c

+ 15 - 15
scene/3d/visual_instance_3d.cpp

@@ -74,10 +74,6 @@ RID VisualInstance3D::get_instance() const {
 	return instance;
 	return instance;
 }
 }
 
 
-RID VisualInstance3D::_get_visual_instance_rid() const {
-	return instance;
-}
-
 void VisualInstance3D::set_layer_mask(uint32_t p_mask) {
 void VisualInstance3D::set_layer_mask(uint32_t p_mask) {
 	layers = p_mask;
 	layers = p_mask;
 	RenderingServer::get_singleton()->instance_set_layer_mask(instance, p_mask);
 	RenderingServer::get_singleton()->instance_set_layer_mask(instance, p_mask);
@@ -106,7 +102,6 @@ bool VisualInstance3D::get_layer_mask_value(int p_layer_number) const {
 }
 }
 
 
 void VisualInstance3D::_bind_methods() {
 void VisualInstance3D::_bind_methods() {
-	ClassDB::bind_method(D_METHOD("_get_visual_instance_rid"), &VisualInstance3D::_get_visual_instance_rid);
 	ClassDB::bind_method(D_METHOD("set_base", "base"), &VisualInstance3D::set_base);
 	ClassDB::bind_method(D_METHOD("set_base", "base"), &VisualInstance3D::set_base);
 	ClassDB::bind_method(D_METHOD("get_base"), &VisualInstance3D::get_base);
 	ClassDB::bind_method(D_METHOD("get_base"), &VisualInstance3D::get_base);
 	ClassDB::bind_method(D_METHOD("get_instance"), &VisualInstance3D::get_instance);
 	ClassDB::bind_method(D_METHOD("get_instance"), &VisualInstance3D::get_instance);
@@ -216,15 +211,20 @@ GeometryInstance3D::VisibilityRangeFadeMode GeometryInstance3D::get_visibility_r
 }
 }
 
 
 const StringName *GeometryInstance3D::_instance_uniform_get_remap(const StringName p_name) const {
 const StringName *GeometryInstance3D::_instance_uniform_get_remap(const StringName p_name) const {
-	StringName *r = instance_uniform_property_remap.getptr(p_name);
+	StringName *r = instance_shader_parameter_property_remap.getptr(p_name);
 	if (!r) {
 	if (!r) {
 		String s = p_name;
 		String s = p_name;
+#ifndef DISABLE_DEPRECATED
 		if (s.begins_with("shader_uniforms/")) {
 		if (s.begins_with("shader_uniforms/")) {
-			StringName name = s.replace("shader_uniforms/", "");
-			instance_uniform_property_remap[p_name] = name;
-			return instance_uniform_property_remap.getptr(p_name);
+			s = s.replace("shader_uniforms/", "instance_shader_parameters/");
+		}
+#endif // DISABLE_DEPRECATED
+		if (s.begins_with("instance_shader_parameters/")) {
+			StringName pname = StringName(s);
+			StringName name = s.replace("instance_shader_parameters/", "");
+			instance_shader_parameter_property_remap[pname] = name;
+			return instance_shader_parameter_property_remap.getptr(pname);
 		}
 		}
-
 		return nullptr;
 		return nullptr;
 	}
 	}
 
 
@@ -247,7 +247,7 @@ bool GeometryInstance3D::_set(const StringName &p_name, const Variant &p_value)
 		set_gi_mode(GI_MODE_DYNAMIC);
 		set_gi_mode(GI_MODE_DYNAMIC);
 		return true;
 		return true;
 	}
 	}
-#endif
+#endif // DISABLE_DEPRECATED
 	return false;
 	return false;
 }
 }
 
 
@@ -270,13 +270,13 @@ void GeometryInstance3D::_get_property_list(List<PropertyInfo> *p_list) const {
 		if (def_value.get_type() != Variant::NIL) {
 		if (def_value.get_type() != Variant::NIL) {
 			has_def_value = true;
 			has_def_value = true;
 		}
 		}
-		if (instance_uniforms.has(pi.name)) {
+		if (instance_shader_parameters.has(pi.name)) {
 			pi.usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE | (has_def_value ? (PROPERTY_USAGE_CHECKABLE | PROPERTY_USAGE_CHECKED) : PROPERTY_USAGE_NONE);
 			pi.usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE | (has_def_value ? (PROPERTY_USAGE_CHECKABLE | PROPERTY_USAGE_CHECKED) : PROPERTY_USAGE_NONE);
 		} else {
 		} else {
 			pi.usage = PROPERTY_USAGE_EDITOR | (has_def_value ? PROPERTY_USAGE_CHECKABLE : PROPERTY_USAGE_NONE); //do not save if not changed
 			pi.usage = PROPERTY_USAGE_EDITOR | (has_def_value ? PROPERTY_USAGE_CHECKABLE : PROPERTY_USAGE_NONE); //do not save if not changed
 		}
 		}
 
 
-		pi.name = "shader_uniforms/" + pi.name;
+		pi.name = "instance_shader_parameters/" + pi.name;
 		p_list->push_back(pi);
 		p_list->push_back(pi);
 	}
 	}
 }
 }
@@ -315,9 +315,9 @@ void GeometryInstance3D::set_instance_shader_parameter(const StringName &p_name,
 	if (p_value.get_type() == Variant::NIL) {
 	if (p_value.get_type() == Variant::NIL) {
 		Variant def_value = RS::get_singleton()->instance_geometry_get_shader_parameter_default_value(get_instance(), p_name);
 		Variant def_value = RS::get_singleton()->instance_geometry_get_shader_parameter_default_value(get_instance(), p_name);
 		RS::get_singleton()->instance_geometry_set_shader_parameter(get_instance(), p_name, def_value);
 		RS::get_singleton()->instance_geometry_set_shader_parameter(get_instance(), p_name, def_value);
-		instance_uniforms.erase(p_value);
+		instance_shader_parameters.erase(p_value);
 	} else {
 	} else {
-		instance_uniforms[p_name] = p_value;
+		instance_shader_parameters[p_name] = p_value;
 		if (p_value.get_type() == Variant::OBJECT) {
 		if (p_value.get_type() == Variant::OBJECT) {
 			RID tex_id = p_value;
 			RID tex_id = p_value;
 			RS::get_singleton()->instance_geometry_set_shader_parameter(get_instance(), p_name, tex_id);
 			RS::get_singleton()->instance_geometry_set_shader_parameter(get_instance(), p_name, tex_id);

+ 2 - 4
scene/3d/visual_instance_3d.h

@@ -40,8 +40,6 @@ class VisualInstance3D : public Node3D {
 	RID instance;
 	RID instance;
 	uint32_t layers = 1;
 	uint32_t layers = 1;
 
 
-	RID _get_visual_instance_rid() const;
-
 protected:
 protected:
 	void _update_visibility();
 	void _update_visibility();
 
 
@@ -119,8 +117,8 @@ private:
 
 
 	float lod_bias = 1.0;
 	float lod_bias = 1.0;
 
 
-	mutable HashMap<StringName, Variant> instance_uniforms;
-	mutable HashMap<StringName, StringName> instance_uniform_property_remap;
+	mutable HashMap<StringName, Variant> instance_shader_parameters;
+	mutable HashMap<StringName, StringName> instance_shader_parameter_property_remap;
 
 
 	float extra_cull_margin = 0.0;
 	float extra_cull_margin = 0.0;
 	LightmapScale lightmap_scale = LIGHTMAP_SCALE_1X;
 	LightmapScale lightmap_scale = LIGHTMAP_SCALE_1X;

+ 4 - 0
servers/rendering/shader_language.cpp

@@ -8178,6 +8178,10 @@ Error ShaderLanguage::_parse_shader(const HashMap<StringName, FunctionInfo> &p_f
 					}
 					}
 				}
 				}
 #endif // DEBUG_ENABLED
 #endif // DEBUG_ENABLED
+				if (String(shader_type_identifier) != "spatial") {
+					_set_error(vformat(RTR("Uniform instances are not yet implemented for '%s' shaders."), shader_type_identifier));
+					return ERR_PARSE_ERROR;
+				}
 				if (uniform_scope == ShaderNode::Uniform::SCOPE_LOCAL) {
 				if (uniform_scope == ShaderNode::Uniform::SCOPE_LOCAL) {
 					tk = _get_token();
 					tk = _get_token();
 					if (tk.type != TK_UNIFORM) {
 					if (tk.type != TK_UNIFORM) {