How do I get the position of each instance in MultiMeshInstance at fragment()?

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

Hello everyone!

I need to get the position of each instance to do some computation.

I have tried NODE_POSITION_WORLD and VERTEX.

The NODE_POSITION_WORLD can get the position of the MultiMeshInstance node. All the instances have the same value!

shader_type spatial;
//render_mode world_vertex_coords;

void fragment() {
	ALBEDO = NODE_POSITION_WORLD.xyz;
}

And VERTEX looks like it would return the position of each pixel in view space.

shader_type spatial;
//render_mode world_vertex_coords;

void fragment() {
	ALBEDO = VERTEX.xyz;
}

Is there a way to get the position of each instance in MultiMeshInstance at fragment()?

:bust_in_silhouette: Reply From: SneaK1ng

got the answer from:
https://godotforums.org/d/33709-how-do-i-get-the-position-of-each-instance-in-multimeshinstance-at-fragment

shader_type spatial;
varying vec3 instance_pos;

void vertex() {
	instance_pos = MODEL_MATRIX[3].xyz;
}

void fragment() {
	ALBEDO = instance_pos.rgb;
}