Which type of shader is it?
And which function do you need this into? (fragment or vertex?)
In a spatial
shader's vertex()
function you can access the model matrix as WORLD_MATRIX
, which is the global transform of the model. It is also available in the fragment() function.
In a canvas_item
shader, there is also WORLD_MATRIX
available in vertex()
(only), however it is the view space matrix, unfortunately. I think what you'd need here is missing, but maybe there is a trick to get it which I'm not aware of. Maybe un-composing with a camera matrix?
If all else fails another option is to declare a uniform mat4 my_matrix;
and pass what you need from GDScript to the ShaderMaterial
using set_shader_param
(make sure it is unique if you want different values for different objects).
If you need the local transform, that's also not available in shaders, you'd have to pass that in.