How to set shader param of a MeshInstance in c++? What is the equivalent of shader data type mat3 in GDScript and C++?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By muratbozkurt35

And How should i use and set shader param mat3 in c++ and GDScript? And how can i use Transform object as 3 by 3 matrix?

I know setting shader param in gdscript like

get_node("...").mesh.surface_get_material(0).set_shader_param("paramName", value)

How can i do the samething in c++? What is the equivalent of shader mat3 type in GDScript and C++? How can i set uniform mat3 paramater in both using Transform?

:bust_in_silhouette: Reply From: ArdaE

Basis works fine for passing a 3x3 matrix from C++/GDScript to a mat3 uniform in a shader.

Note that you can’t fit all information in Transform into mat3 though. If your Transform describes any translation or projection, you’ll need to use a mat3 together with a Vector3 (or just a mat4 on its own) to represent it.

As for C++, you can do the following (assuming the node is a MeshInstance):
Ref<ShaderMaterial> shaderMaterial = godot::Object::cast_to<MeshInstance>(get_node("..."))->get_mesh()->surface_get_material(0);