Using Node Material Editor to create many duplicate meshes

I am trying to find an even thinner way to do instancing than the ThinInstance approach already available.

The thin instance example on the Babylon JS youtube channel (Fun With Legos) shows creating an array of meshes to form an ocean made of lego bricks. In this example, the translate matrix is supplied in javascript code and then sent over as a matrix buffer to the GPU. But then the material editor is able to override the values and set them directly (happens at 22:51 in video).

My question: Is it possible to avoid setting the matrix in JS, then do all of the translating in a material, generating the positions entirely with the NME? Thus saving on the data required to be transferred to the GPU. It’s not a lot of data with a small number of instances, but with millions of instances it adds up quick.

If this is way out of scope of NME, that’s fine, but I’m curious to hear from folks with more experience with this sort of thing :slight_smile:

Hi @mattm and welcome to the forum

Thin instances are small mesh (small in the sense small memory footprint) with the minimum datas used to render it. It’s quite efficient even if you have to update the matrix for each one.

But, it’s also possible to generate the matrix in NME.

image

See the instanceID, it’s an integer that declares the number of the mesh being drawn. From that value, you can compute a matrix and use it to transform the mesh position.

This might (well, this will) make your shader more complex and difficult to debug but you won’t have to update matrices from JS code.

Depengin on you use case, this can be handy. For example, scattering meshes on a heightmap.

5 Likes