#how to signal a shader on a MeshInstance3D
1 messages · Page 1 of 1 (latest)
If you look at the MeshInstance3D in editor (inspector) you can see the following things:
MeshIntance3D is a node that has a "mesh" property that holds the actual mesh.
The mesh can have materials on it.
So I think meshinstance.mesh might access it directly?
But they are often read-only and I don't usually mess with them, as it will effect everything with the same mesh.
Then on the MeshInstance3D itself (not the mesh!) it also has one or more surface_material_override that can override specific materials on the mesh.
In addition, if you look under Geometry, there's one called "Material Override".
If you hover your mouse over it, it will say material_override
So, there are several different spots for materials.
Make sure you are targeting the correct one(s).
Sorry for late reply. Have you tried self.surface_material_override.set_shader_param("SPRITE_POS_X", -relative_position.x) ?
Materials are more or less just shaders
Oh wait
That's "param". ... I think it was changed to "parameter".
In Godot 4 but ye hmm
Oh right my bad. I was thinknig of material_override. Surface mat is the one that's an array that allows you to overwrite jsut 1 specific material.
So it'll need an index to know which material.
It mentions Material get_surface_override_material ( int surface ) const
That means you could use var material_to_change = get_surface_override_material(0)
Then material_to_change.set_shader_parameter("SPRITE_POS_X", -relative_position.x)
(material_to-change is just a var name, call it whatever you want)
There might be a way to do it in one line, but I'd imagine this would work fine.
Inherits: GeometryInstance3D< VisualInstance3D< Node3D< Node< Object Inherited By: SoftBody3D Node that instances meshes into a scenario. Description: MeshInstance3D is a node that takes a Mesh res...
The number (here 0) means first material. 1 would be second. 2 would be third etc.
Oh and if you want to update it on every frame, you could cache that material_to_change in _ready
Self is optional, it just makes things easier to read.
self.velocity is the same as velocity as an example.