# ShaderMaterial preventing Instance Mesh setMatrixAt from updating

**URL:** <https://discourse.threejs.org/t/shadermaterial-preventing-instance-mesh-setmatrixat-from-updating/63915>\
**Category:** Questions\
**Tags:** shader-material, instanced-mesh\
**Created:** [April 10, 2024, 12:18pm UTC](https://discourse.threejs.org/t/shadermaterial-preventing-instance-mesh-setmatrixat-from-updating/63915 "2024-04-10T12:18:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vardan\_Betikyan](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/vardan_betikyan/32/34487_2.png) [@Vardan\_Betikyan](https://discourse.threejs.org/u/Vardan_Betikyan)\
**Post date:** [April 10, 2024, 12:18pm UTC](https://discourse.threejs.org/t/shadermaterial-preventing-instance-mesh-setmatrixat-from-updating/63915/1 "2024-04-10T12:18:46Z")

</div>

The `SphereInstanceMeshOutline`’s instances are stuck at `0,0,0` and aren’t updating at all. I think the shader is causing an interference?

```
// Outlines
const outlineThickness = 0.05;
const outlineGeo = new THREE.SphereGeometry( 0.5, 32, 16 );
const outlineMesh = new THREE.ShaderMaterial( {
	vertexShader: `
		void main( ) {
			vec3 newPosition = position + normal * ${outlineThickness};
			gl_Position = projectionMatrix * modelViewMatrix * vec4( newPosition, 1 );
		}
	`,
	fragmentShader: `
		void main( ) {
			gl_FragColor = vec4( 0.2, 0.2, 0.2, 1 );
		}
	`,
	side: THREE.BackSide
} );

SphereInstanceMeshOutline = new THREE.InstancedMesh( outlineGeo, outlineMesh, amount );
SphereInstanceMeshOutline.material.needsUpdate = true;

function updateInstance( dummy, index ) {
	dummy.updateMatrix( );
	SphereInstanceMeshOutline.setMatrixAt( index, object.matrix );
	
	SphereInstanceMeshOutline.instanceMatrix.needsUpdate = true;
}

```

When I try to replace the `ShaderMaterial` to a simple `MeshStandardMaterial` for testing purposes, the instances positions update normally

---

<div class="post-metadata">

**Author:** ![Arthur](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/arthur/32/22954_2.png) [@Arthur](https://discourse.threejs.org/u/Arthur)\
**Post date:** [April 10, 2024, 1:13pm UTC](https://discourse.threejs.org/t/shadermaterial-preventing-instance-mesh-setmatrixat-from-updating/63915/2 "2024-04-10T13:13:16Z")

</div>

Your shader needs to use the instance’s matrix or all your instances will be at the same position, see the code [here](https://github.com/mrdoob/three.js/blob/1832e7f67116bdc88c00c3cd71bb872b48540964/src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl.js).

---

<div class="post-metadata">

**Author:** ![Vardan\_Betikyan](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/vardan_betikyan/32/34487_2.png) [@Vardan\_Betikyan](https://discourse.threejs.org/u/Vardan_Betikyan)\
**Post date:** [April 10, 2024, 1:36pm UTC](https://discourse.threejs.org/t/shadermaterial-preventing-instance-mesh-setmatrixat-from-updating/63915/3 "2024-04-10T13:36:51Z")

</div>

Added the multiplier `instanceMatrix` to the `gl_Position`:  
`gl_Position = projectionMatrix * modelViewMatrix * instanceMatrix * vec4( newPosition, 1 );`

Works perfectly! Thank you very much!
