Common ShaderMaterial for multiple mesh instances with changing shader parameters

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By tor


I would like to use a single ShaderMaterial for multiple mesh instances while being able to change some specific shader parameters for each mesh instance, but I couldn’t.

The reason is that I send large textures to this shader, but I don’t want to send them again and again for each mesh (performance issue). This is not a problem as it would be enough for all the mesh instances to share the same material, but the thing is that I need some parameters to change according to the mesh being drawn.

How can I do that? Is there some method called before the actual draw process in which I can set the shader parameters before the mesh is drawn? Is there another way I can achieve what I am trying to do?

Thanks a lot.

:bust_in_silhouette: Reply From: bignobody

Yes, this is easy to fix. I am new to Godot, but had this same kind of issue.

Go to your ShaderMaterial in the Inspector and expand the Resource section. Turn the Local To Scene checkbox to On. Worked for me!

Hmm I think that duplicates the resource unfortunately.

tor | 2019-01-27 07:20

This answer saved me so much frustration! THANKS!

HeroicNate | 2021-01-13 07:14