I have a spatial shader that I want to apply to all MeshInstance3Ds in every scene (like a global shading effect), but I cannot figure out a practical way of doing it. Applying the shader manually to each mesh would take forever, and a loop to apply it at runtime would cause a massive lag spike. Is there a way to make a MeshInstance3D have this shader applied by default, or is there a better method I’m missing?
If you don’t want going one by one adding them to a group you can use the SceneTree.node_added signal in a singleton (autoload) and add them to that group in there.
Like:
extends Node
func _enter_tree() -> void:
get_tree().node_added.connect(func(node:Node):
if node is GeometryInstance3D:
node.add_to_group('to_appy_material')
)
func change_material(material:Material) -> void:
get_tree().set_group('to_appy_material', 'material_override', material)