How to change texture/color per object instance in InstancedMesh

Instancing is a more advanced approach recently being easier to start with with InstancedMesh, to add any more individual attributes you need to add a InstancedBufferAttribute to the geometry which instead controlling the attributes of a vertex, will be the attribute per instance, for example a individual color per instance.

For textures this requires more work depending on your case, if you have many different textures you would have to pack them into a texture atlas or texture array, replacing the line in the code sampling from the texture.

Anyway for more individual control you have to patch the material with a onBeforeCompile callback or you might take a look at this plugin i made to make patching easier.

1 Like