Creating lights dynamically that effect instanced meshes with includedOnlyMeshes

Hello everyone!

I decided to make a new thread related to my question in another thread. Best way to create part of a mesh that acts as a light source - #10 by Panuchka

It seems to me that dynamic lights with includedOnlyMeshes populated after render loop has been initialized do not have an effect on instanced meshes at all! There was some code comments that pointed to the fact that “do nothing as all the work will be done by source mesh”. Could someone clarify this behavior and if this is working as intended.

My use case is to have many instanced meshes (wall and floor tiles) that have meta information about whether or not they have lights included in them. I planned to use includedOnlyMeshes to manually turn on/off lights that are not in players radius, or otherwise would break the light limit count of the material.

Here is an example of the problem. In the setTimeout function the (instanced) ball does not light up at all when the spotlight is created and includedOnlyMeshes is updated: https://playground.babylonjs.com/#1FUKMR#8

Here is an example without instancing: https://playground.babylonjs.com/#1FUKMR#9

Instances cannot have different lighting than the root mesh unfortunately as they are rendered in one draw call (so same context)

2 Likes

Damn that is a bummer :laughing: I was trying to find a silver bullet for my lighting problem in the other thread… Back to square one, since I really want to use instances, as I will probably have hundreds of space ship walls/floors!

You may use clones instead of instances - https://playground.babylonjs.com/#1FUKMR#12

This is very reasonable and reliable way :slight_smile: