Passing a 2D Array to a shader

Godot Version

v4.4.1.stable.official [49a5bc7b6]

Question

Is it possible to pass an array of arrays or preferably an array of PackedFloat32Arrays to a shader?
As far as I am aware, I can pass stuff from scripts to shaders through uniforms, but it seems that it’s not 1:1 type alignment and that array uniforms themselves are only a thing since Godot 4.

I can find some other way to do what I want, tho it will be a bit more difficult if neither generic 2D arrays nor packed arrays can be passed to shaders.

What I mean is passing something like this to a shader.

var a: Array[Array]
var b: Array[PackedFloat32Array]

Thanks for help!

You can pass packed arrays. Not arrays of arrays though. If you for some reason need to do that, pack everything into one array and send strides in another array. Or pack separator values if your use case would allow for them.

1 Like

If you just want a 2D rectangular array, you can simplify @normalized’s scheme to a single stride value alongside the actual array.

1 Like

I see, thank you for the help!