Godot Version
v4.4.stable.official [4c311cbee]
Question
I’m trying to pass the INSTANCE_CUSTOM parameter to the spatial shader for the mesh in a MultiMesh, but I can’t seem to make it work. I’m hoping someone familiar with this can take a look. Thanks!
Notes:
I’ve successfully displayed the MultiMesh and changed the mesh color via the shader.
On line 33 of main.gd, I passed custom data to each mesh in the MultiMesh. However, the shader reads it as the default VEC4(0.0) value.
——————
main.gd:
extends Node3D
var ps = PhysicsServer3D
var rs = RenderingServer
var muiltiMeshNode: MultiMeshInstance3D
func _ready() → void:
muiltiMeshNode = MultiMeshInstance3D.new()
add_child(muiltiMeshNode)
muiltiMeshNode.visible = true
var mm: MultiMesh = MultiMesh.new()
#add mesh to multi mesh
var mesh: BoxMesh = BoxMesh.new()
var mate1 = ShaderMaterial.new()
mate1.shader = load(“res://t1.gdshader”)
mesh.surface_set_material(0, mate1)
mm.mesh = mesh
mm.transform_format = MultiMesh.TRANSFORM_3D
mm.instance_count = 5
mm.visible_instance_count = -1
#mm.use_colors = true
mm.use_custom_data = true
for i in mm.instance_count:
mm.set_instance_transform(i, Transform3D(Vector3(1.0, 0.0, 0.0), Vector3(0.0, 1.0, 0.0), Vector3(0.0, 0.0, 1.0), Vector3(i * 3.0, 0.0, 0.0)))
#mm.set_instance_color(i, Color(0.0, 0.0, 1.0, 0.0))
mm.set_instance_custom_data(i, Color.BLUE)
muiltiMeshNode.multimesh = mm
func _process(_delta: float) → void:
pass
——————
ti.gdshader:
shader_type spatial;
void vertex(){
//COLOR = vec4(0.0,1.0,0.0,1.0);
COLOR = INSTANCE_CUSTOM;
}
void fragment() {
ALBEDO = COLOR.rgb;
}
——————