I need to draw a bunch of rectangles (possibly hundreds) with a custom shader, but each rectangle needs to have different uniforms set in the shader. As per documentation I tried using _draw() on a Node2D and the rects are indeed drawn with the shader. However it seems that uniforms cannot be changed between draw calls as all my rects are just drawn with same uniforms values. This is what I'm doing:
func _draw():
set_material(material)
material.set_shader_param("a", 1)
draw_rect(Rect2(0.0, 0.0, 200.0, 200.0), Color(1.0, 1.0, 1.0, 1.0))
material.set_shader_param("a", 2)
draw_rect(Rect2(200.0, 200.0, 200.0, 200.0), Color(1.0, 1.0, 1.0, 1.0))
Both rects are drawn with value of the uniform "a" set to 2. I'm aware it may not be an optimal approach. Is there a "proper" way to handle this?