Updating single element from uniform array via script

Godot Version

4.2.2

Question

Hello! I have a shader question. I currently am updating my shader uniform array like so:

I have an array on my shader like this:

uniform vec2 positions[3]; // Array of positions to highlight

I am able to update it from code like this:

material.set_shader_parameter("positions", [Vector2(0.9, 0.9), Vector2(0.7, 0.7), Vector2(0.5, 0.5)])

BUT! How do I update a single element? I have tried material.set_shader_parameter("positions[0]", Vector2(0.1, 0.5)) to no avail.

Thank you!

I’d try maybe to get the whole array in GDScript, modify it in the GDScript script, then send the modified array as the new positions’ array to the shader.
It’d go something like this:

# Retrieving the array
var new_positions := material.get_shader_parameter("positions") as Array
# Modifiying the array hic et nunc
new_positions[...] = ...
# Updating the shader
material.set_shader_parameter("positions", new_positions)
1 Like

Did it work?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.