# How to change texture per instance in InstancedMesh?

**URL:** https://discourse.threejs.org/t/how-to-change-texture-per-instance-in-instancedmesh/36304
**Category:** Questions
**Tags:** materials, textures, instanced-mesh
**Created:** [March 24, 2022, 1:36am UTC](https://discourse.threejs.org/t/how-to-change-texture-per-instance-in-instancedmesh/36304 "2022-03-24T01:36:57Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![delongjs](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@delongjs](https://discourse.threejs.org/u/delongjs)
#### Post date: [March 24, 2022, 1:36am UTC](https://discourse.threejs.org/t/how-to-change-texture-per-instance-in-instancedmesh/36304/1 "2022-03-24T01:36:57Z")

</div>

Hello, I’m new to three.js. How does that possible if my mouse moves to the ball, it changes the texture instead of changing the color?  
[https://threejs.org/examples/#webgl\_instancing\_raycast](https://threejs.org/examples/#webgl_instancing_raycast)

Because I saw the document, the methods only setColorAt and setMatrixAt can control the ball, how do I change the texture? Thanks.  
[https://threejs.org/docs/#api/en/objects/InstancedMesh](https://threejs.org/docs/#api/en/objects/InstancedMesh)

---

<div class="post-metadata">

### Author: ![makc3d](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/makc3d/32/10452_2.png) [@makc3d](https://discourse.threejs.org/u/makc3d)
#### Post date: [March 24, 2022, 2:52am UTC](https://discourse.threejs.org/t/how-to-change-texture-per-instance-in-instancedmesh/36304/2 "2022-03-24T02:52:23Z")

</div>

if you check how [those methods](https://github.com/mrdoob/three.js/blob/c7d06c02e302ab9c20fe8b33eade4b61c6712654/src/objects/InstancedMesh.js#L94) work, you’ll see that they just alter the values in attributes, while textures end up being set via uniforms. however, you could have an attribute of indices into a texture atlas, for example. in simpler terms, it not quite possible but you can fake it.

---

<div class="post-metadata">

### Author: ![delongjs](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@delongjs](https://discourse.threejs.org/u/delongjs)
#### Post date: [March 24, 2022, 3:00am UTC](https://discourse.threejs.org/t/how-to-change-texture-per-instance-in-instancedmesh/36304/3 "2022-03-24T03:00:42Z")

</div>

Thanks, is there any sample code I can reference?

---

<div class="post-metadata">

### Author: ![hofk](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/hofk/32/44944_2.png) [@hofk](https://discourse.threejs.org/u/hofk)
#### Post date: [March 24, 2022, 7:33am UTC](https://discourse.threejs.org/t/how-to-change-texture-per-instance-in-instancedmesh/36304/4 "2022-03-24T07:33:08Z")

</div>

related [How to set different textures on each InstancedMesh?](https://discourse.threejs.org/t/how-to-set-different-textures-on-each-instancedmesh/29433)

---

<div class="post-metadata">

### Author: ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)
#### Post date: [March 24, 2022, 9:18am UTC](https://discourse.threejs.org/t/how-to-change-texture-per-instance-in-instancedmesh/36304/5 "2022-03-24T09:18:10Z")

</div>

/cc

> <https://stackoverflow.com/questions/71596401/how-to-change-texcture-per-instance-in-instancedmesh>
