Godot Version
4.2.2
Question
I do I pass an array to a shader in godot? How do I modify arrays? I kinda need this.
4.2.2
I do I pass an array to a shader in godot? How do I modify arrays? I kinda need this.
as a uniform:
uniform float myValues[12];
Right, But what if that just doesn’t work it just returns white for everything?
if I use the code (not real code just demonstrating that if I change the grid it return an failure)
uniform int array[300];
void fragment(){
array[15] = 1;
}
Pretty confident you aren’t to assign values to a uniform within a shader, don’t expect those values to save between frames or even shading stages at the very least. You could make it not a uniform by removing the qualifier.
Could you give a more concrete example of what you are hoping to do?
Falling sand.
I am pretty sure it works. Check out my Spectrum Analyzer shader where I use an array to pass frequency data to VU meters in the shader code: Spectrum Analyzer - Godot Shaders
Anyway, as gertkeno says, uniform parameters are read-only, and you aren’t supposed to change their values.
Ahhh, Alright, thanks.
You might have to learn a lot more about shaders before falling sand, it’s rather tricky and involves lower-level tech that’s at least somwhat supported in Godot i.e. compute shaders.
Here’s a game that’s entire selling point is doing it’s sandy physics on the GPU
On the other end Noita is popular and does everything CPU side.