Instances and draw calls

It has always been my thought that if you create an object with a single material (1 draw call) and that if you then create instances of that object then you will still only have one draw call no matter the number of instances. However, recently, I ran into an issue with this idea. Here is an example :

4 cubes

A simple scene with a red cube and 3 instances. There is an additional white cube (invisible when you initially load) that is the camera “target”. The scene was created with Blender 2.90 and exported witth @JCPalmer 's great exporter.

Cube…001 - on the far left, the original cube with one vertex tweeked to change shape and make it easier to understand. Cube.002: first instance - scaled by a factor of .5. Cube.003 : 2nd instance rotated 180 degrees. Cube.004 : 3rd instance scaled by a factor of -1 in the X direction (essentially a mirror of the original cube)

Now open the Inspector and look at the meshes - the camera target is invisible. Now click the statistics tab - you will see 2 draw calls. Make the white target cube visible - now three draw calls. Make both the camera target and Cube.004 invisible - one draw call. The Cube.004 is a draw call to itself even though is is an instanced mesh - both according to the Inspector and the exported .babylon file.

If you look at the scaling of that Cube.004 you will notice it is -1,-1,-1 - even though I only scaled the X axis by that value - I was expecting -1,1,1.

Anyone know what is going on? An issue with the exporter? Or does BJS not like -ve scales?

Stay Safe All, gryff :slight_smile:

Hello this is because instances must have the same winding order and by scaling one instance by -1 you force babylonjs to exclude that instance from the instance pool in order to render it with the different winding order :wink:

This one may come from the exporter

But in the PG Inspector, Cube.004 still shows up as an “InstancedMesh” - so it appears as though it is not being excluded?

Stay Safe David, gryff :slight_smile:

It is still an instance but not rendered in the same rendering train as we need to switch the winding order

I looked at the .babylon file. There the exported scaling of cube 4 is -1, -1, -1. @gryff, is this what you intended? I would have expected that the -1 * -1, -1, -1 === 1, -1, -1.

As far as draw calls, I was not aware myself even what a winding order is.