#Confusing note on the custom shader instancing example

2 messages · Page 1 of 1 (latest)

lean reef
#

In the bevy instancing example there's a note about the instance index that I don't understand

// NOTE: Passing 0 as the instance_index to get_world_from_local() is a hack
// for this example as the instance_index builtin would map to the wrong
// index in the Mesh array. This index could be passed in via another
// uniform instead but it's unnecessary for the example.
out.clip_position = mesh_position_local_to_clip(
    get_world_from_local(0u),
    vec4<f32>(position, 1.0)
);

Why is the hack here necessary? It's not clear to me what would be wrong with using the built-in instance index

zenith pasture
#

IIRC the reason this is fine in that example is because there's only one mesh that is being instanced so the first mesh is the correct mesh. You would need to setup a way to get the exact index in the mesh array but I don't currently remember how to do that part