light.includedOnlyMeshes for instances

Would it be possible to allow instances of meshes to work with include/exclude meshes for lights?

I’m working on an old browser game (, currently converting our pseudo-3D map to WebGL using Babylon. A universe has around 400k stars and several million planets. It looks much better if the planets are properly lit by their star, currently I have to clone the planets for that and can’t use instances. Performance is tolerable working with small grids for which planets are shown, but it’s a bit wasteful in terms of resources. Also, adding clones appears much slower than adding instances, making traversal between grids somewhat choppy.

Thanks for all the effort you’ve put into Babylon, it makes working with webGL a breeze!

Welcome aboard!

It’s not possible because the mesh instances share the same material than the source mesh, and the lighting code is part of the material. That’s what make drawing all instances in a single draw call possible. And it also explains why it is faster than cloned meshes, because in this case each clone will need its own draw call to be rendered.

Maybe you can try to set the position/direction of the light of the star which is closer to the view, so that the planet system closer to the viewer is the one correctly lit?


May be you can make some sort of compromise. Create n clones of the planet (say 4) and use them as a source to create instances or thin instances. The further away you would exclude from light. The closest gets full lights. The 2 in between could use 2 different materials with a different level of directIntensity that will diffuse the light on the material.

1 Like

Thanks for the feedback.

There can be several systems with different planets in view, so it’s difficult to find a middle ground. Rendering performance is great with small boxes, but the background grid updates, cloning and disposing objects make things quite choppy sometimes. I wonder if running the engine in a worker could fix that.