Instanced mesh with different material?

You may ignore/delete this, i guess being tired is a sign of needing sleep, who knew? :smile:

1 Like

After looking at some code this seems like a bigger job than first expected,

I’m now testing a “sharedGeometryMesh” class at the cost of drawcalls,
2500 spheres, 2500 drawcalls, slim 4-6 fps improvement over normal clones (chrome 73)
normal: https://playground.babylonjs.com/#B4VFIH#3 (27-29 fps)
shared: https://playground.babylonjs.com/#B4VFIH#2 (33-35 fps, (occationally jumping up to 40-44 :confused: ))

It looks like it’ll have to be instances of clones for the time being… big butt pain of managing code to keep track of all that :smile:

Thanks for trying:)

I think it’ll require some shader magic, but i have no clue what i’m looking at :smile:
surely it must be possible to pass an alternative color value for each instance and switch between the colors on the GPU with little extra compute cost, no? :thinking:

oh well, I started making a manager for the instancing of clones
still needs a bit of work, but performance seems OK so far
https://playground.babylonjs.com/indexStable.html#J4KPQE#1 3k meshes

it is technically feasible as we can send more than just matrix per instance

Been looking around, thinking of the best possible solution…

Would it be possible to make a future feature request to support separate outlines & overlays for instances?
or maybe it would hurt instance performance too much?

I think the overlay would solve my issue at least, assuming they could be done in the same drawcall, but it’d also be a nice addition without having to add anything odd :slight_smile:

so that overlay would contain whatever data you want and then you will use that data from your shader?

Yes, so each instance could have a separate overlayColor
or even renderOverlay turn on/off
like you would any other mesh: https://playground.babylonjs.com/#ALD5NY#1

1 Like

but that will require you to build a shader material right?

I fear so, i can feel my mind melting everytime i look at anything shader related lol,
For now, i simplified my mesh to make it scalable so i only need that one mesh & one extra drawcall per material.

1 Like