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.
- 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
- 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.