I want to create a menu screen where the text moves into the window when the scene starts; the movement of the menu items should be done via shaders (or rather via a single shader that I hope to reuse).
Here is the scene setup:
and the shader that is applied to both labels:
shader_type canvas_item;
uniform float progress: hint_range(0.0, 1.0);
void vertex() {
VERTEX.x = VERTEX.x - (1.0 - progress) * 200.0;
}
I am just moving the pixels via a vertex shader. The 1.0 - progress is there so that I can update the shader more easily via a tween.
Speaking of the tween, in the parent node of the scene I have this code:
extends Control
func _ready():
var tween := create_tween()
tween.tween_property($MarginContainer/VBoxContainer/Label, "material:shader_parameter/progress", 1.0, 0.5)
tween.tween_property($MarginContainer/VBoxContainer/Label2, "material:shader_parameter/progress", 1.0, 2.0)
This works but not in the intended way: Both labels are moving at the same time and at the same speed. I know this happens because when I update the shader on the first Label it also updates on Label2. Even leaving the second tween_property method out would still get the same result.
So, is it possible to have one shader applied to multiple nodes and keep the values unique to each node? I know that I can fix it by creating multiple shaders with the same code but that does not feel elegant at all. Is there a better way?