Instances Issues, textures and occluding

Hey guys im trying to work out if its an instance limitation or im coding incorrectly.

I have a sphere, on this sphere are POI markers, some have imported Meshes but the majority have meshPlanes with Billboard_all set.
For an optimization pass im trying to get the plane meshes instanced to reduce draw calls. When enabled it can display up to 40 plane mesh markers on the surface (With more occluded on the other side). However these meshes are increasing the draw calls on average +160 when theres around 30 visible.

Instances look to be the way to drastically reduce the draw call. However im currently stuck.

  1. a Standard diffuse texture with alpha is not working with Instances (like Specular is set to 100%)
const poiMaterial= new BABYLON.StandardMaterial(`poi_material`, scene);
poiMaterial.diffuseTexture = new BABYLON.Texture('./textures/UI/poi_ico.png', scene);
poiMaterial.diffuseTexture.hasAlpha = true;

// This part sits in an array.map() to setup the instance properties
const poi = poiTemplate.createInstance(obj.entityName);
poi.material = poiMaterial;
// More code to define the instance like pos, parent, and custom properties.
// Also linked a textBlock with offset to each POI
  1. Occluding individual instances doesn’t seem to work.
scene.registerBeforeRender(() => {
  scene.meshes.forEach(mesh => {
	switch (mesh.type) {
		case 'surfaceObject':
			const dist = mesh.getDistanceToCamera();
				if (!mesh.isModel && mesh.isVisible && dist < 400) {
					mesh.isOccluded ? mesh.poiLabel.isVisible = false : mesh.poiLabel.isVisible = true;
					mesh.isOccluded ? mesh.freezeWorldMatrix() : mesh.unfreezeWorldMatrix(); // Testing this to see if any performance gain
				}
				if (mesh.isModel && mesh.isVisible && dist < 400) {
					mesh.isOccluded ? mesh.parent.bodyLabel.isVisible = false : mesh.parent.bodyLabel.isVisible = true;
				}
		break;
      // Other cases statements
		}
	})
})

If i create all the POI as just meshes (no instances) everything works just with a decent hit to the draw calls.

It would be great is you could provide a Playground to repro the issues you are facing.

About 1. it sounds pretty strange and I ll have a look as soon as you have a repro.

About 2. Occlusion Queries would work at the draw call level so as all instances are rendered at once I guess there is no easy way to figure out which one is in or not.

Ping @Evgeni_Popov to confirm ?

For 1, you can try to set Mesh.INSTANCEDMESH_SORT_TRANSPARENT = true.

For 2 that can’t work as @sebavan said, all instances are drawn in a single draw call, so the occlusion result is for the bounding box that encompassed all the instances.

1 Like