InstancedMesh with positional data only

Hi all :wave:

I’m trying to render grass using an instanced mesh. So far it’s looking pretty good but I’d like to optimise it a bit further. This is what I’ve got so far:

I’m only setting the position for every grass mesh using InstancedMesh.setMatrixAt(), which seems like a bit of a waste. Is there a way to prevent the allocation of 100k matrices in gpu memory and use a simple vector3 for the position instead?

I feel like InstancedBufferGeometry might be the solution here but I’m still not quite sure what the purpose is of InstancedBufferGeometry exactly and what its advantages are over InstancedMesh with a regular BufferGeometry.

Not with InstancedMesh.

Yes, you have to use InstancedBufferGeometry if you need more control over instanced rendering. However, this also means you have to write custom shader code (which is its major disadvantage). I suggest you study the following example to get more familiar with InstancedBufferGeometry:

https://threejs.org/examples/webgl_buffergeometry_instancing.html

3 Likes

Cool, thanks for the info! I’m already using custom shaders exclusively so that shouldn’t be an issue. I’ll have a go at it with that example.