InstancedMesh + InstancedBufferGeometry

I want to do some instanced rendering with some extra attributes beyond instanceMatrix and color, so I’m using InstancedBufferGeometry and some patched materials.

This works great, until I try and introduce my own instanceMatrix, and an attribute mat4 instanceMatrix; at which point I get the usual gl errors due to a too large vertex attribute.

My question is, can I use an InstancedBufferGeometry inside an InstancedMesh if I want to add a few more instanced fields?

Alternatively, could someone point me to an example of getting a mat4 InstancedBufferAttribute to work?

Matrix attributes are not supported by three.js. The implementation of InstancedMesh is one exception. There is also a respective GitHub issue:

However, notice that this issue was filed before InstancedMesh was available. In the last time, this feature was not requested anymore.

Right, I know they’re not supported, that’s why I’m asking the question.

What I’m asking is whether I can use InstancedMesh to handle the “special case” for the transforms in addition to using an InstancedBufferGeometry to handle other, 1-4 element vector instance attributes.

Alternatively I’m asking for an example of using four vec4 buffer attributes to write into a single mat4 attribute in the shader.

Okay, to answer my own question: yes.

If you pass an InstancedBufferGeometry as the geometry argument to the InstancedMesh constructor, then this allows you to both use the instanceMatrix and color instance attributes on the InstancedMesh as well as any additional, custom InstancedBufferAttributes you may have defined on your InstancedBufferGeometry (for example, a per instance roughness, assuming you modify the relevant part of the standard material to take roughness as an attribute rather than a uniform/texture).

Which is great :slight_smile: