How can I use InstancedMesh with RawShaderMaterial?

Somebody asked the same question last year.
https://discourse.threejs.org/t/how-do-i-use-instancedmesh-with-rawshadermaterial/25040
I have the same problem of only seeing the first instance.

Works as expected, if you add instanceMatrix attribute and multiply position with this matrix:

2 Likes

Is there a way to pass a custom per-instance attribute to the ShaderMaterial (fragmentShader) ?

@stopyransky
Somethingn like this?

geometry.setAttribute("customAttribute", new THREE.InstancedBufferAttribute(typedArray, 4));

...
// in vertex shader
attribute vec4 customAttribute;
varying vec4 vCustomAttribute;
...
vCustomAttribute = customAttribute;

// in fragment shader
varying vec4 vCustomAttribute;

:thinking:
Or do you mean something else?