Create multiple sphere with InstancedBufferGeometry

I am trying to create multiple spheres with Instanced Buffer Geometry, but I have no results, I am doing something wrong, this already has a headache.

this is the pen https://codepen.io/AlainBarrios/pen/RwNZYxB?editors=1000

Do you need to use InstancedBufferGeometry, and if so what are you trying to do with it? The code you show so far would be simpler with InstancedMesh — see the example here.

If you really do need to use InstancedBufferGeometry, note that the “instance” attributes cannot simply be reused from a normal geometry — they should be attributes of a different length, containing one value (scalar or vector) per instance.

1 Like

@Alain_Barrios
Hi!
Remove this line from the constructor of material:
side: THREE.DoubleSide

And your main() function in the vertex shader should be like that:

void main() {
    vec3 pos = position + instPosition;
    vUv = instUV;
    gl_Position = projectionMatrix * modelViewMatrix * vec4( pos, 1.0 );
}

You need to use not only position of an instance, but also taking in count the position of a vertex in geometry vec3 pos = position + instPosition;.

1 Like