Optimization - merge instances

Hello, I know that there was written a lot about instances / clones and such and that we need to keep number of draw calls as low as possible.

But what I cannot find anywhere is some info about performance impact of merging instances vs merging clones.

Curently I creating my tilebased “world” by merging clones of the “base tile of specific terrain type” into one mesh - thus I endup with bunch of merged mesh clones which works fine. But FPS-wise I am considering to make instances instead of clones in the first place and then merge instances into the final mesh.

But it is not quite easy to do (sadly I cannot just switch .clone for .createInstance as it crashes during merge if I do so) and I am afraid that it might not have any performance impact whatsoever. Can someone explain if there is difference between merging clones together vs merging instances together ?

And one more - mesh that is DISABLED setEnabled(false) is fully deactivated and doesnt consume any computation time right ? Because I am “reusing” merged clones rather than destroying them (in hope that it is more efficient than destroy them just to create new clones later) and they are disabled while they are sitting “in buffer” waiting to be reused.

Thanx very much for some answers and insight :slight_smile: I am really trying to optimize as much as I can since very beginning, but some of these basic principles are still kinda tricky :slight_smile:

1 Like

Hi @stealman and welcome to the form. This post from the previous forum should prove helpful Can you merge instances? - Questions & Answers - HTML5 Game Devs Forum

The short answer is it is not possible to merge instances

The difference is in the construction of an instance and a clone.

1 Like

solid particle system may be an alternative

Thanx !! I have read somewhere that merging instances will be available in some post from 2015, thus I expected it to be working by now.

Anyway this SPS seems to be interesting alternative that I can give it a try :slight_smile: Seems little bit complicated but it could fit my needs, thanx for that idea !!

Merging instances does not make a lot of sense to me as instances are technically only matrices applied to a root mesh.

So in your case your should not merge instances but keep them separated

I thought that merging instances is pointless - thats why I asked here to be sure.

I tried both approaches - having instance-per-tile, or create clone-per-tile and then merge them - merged clones proven to be faster.

To be more specific - merged clones are little bit slower in the time of creation (when they first appear) but they are faster later. Instances were faster to create, but later were little bit slower. In my specific scenario.

What comes to my mind - is there some simple way how to know whether or not has my GPU support for instances ? I read that it is hardware-dependent.

But at the end of the day, I am ok with curent FPS (no lights yet) - just wanted to be sure whether or not there is some easy-to-have optimization :slight_smile:


yes you can get this info from engine.getCaps().instancedArrays