K10ud
December 16, 2023, 8:39pm
1
Godot Version
4.1.3
Question
Saw that it was now possible to adjust shader parameters per instance without having to duplicate the shader:
Unfortunately, there is like zero information online about this. Does anyone know how to accomplish this?
Was wondering how one would go about doing that in GDScript.
Calinou
December 16, 2023, 9:07pm
2
Exerion
December 17, 2023, 5:10pm
3
Is there any plans on doing it for 2D as well?
2 Likes
Calinou
December 18, 2023, 1:36am
4
It’s currently being worked on for particle shaders . The goal is to do the same for CanvasItem shaders in the future, although I can’t give an ETA.
1 Like
For other searching for this, it’s now implemented for Sprite2D (canvas_item shader).
In GDScript:
($Sprite2D as Sprite2D).set_instance_shader_parameter("outline_color", Color.BLUE)
In the shader:
instance uniform vec4 outline_color : source_color = vec4(1.0, 0.0, 0.0, 1.0);
Note that the method is called on the Sprite2D instead of the material (as is done with previous uniform vars).
You can still set parameters from the material if you like:
sprite.material.set_shader_parameter("progress", 0.0)