I need help, sorry my english is bad…
I know material has a limit on the impact on light … I also know to increase the limit on the material, namely by using the material.MaxSimultaneousLights
but it can be used if creating new materials … meaning that it cannot be increased directly by means of mesh.material.maxSimultaneousLight. I want to upgrade the material without creating a new material.
so how do you improve the material?
You may create a function parsing all scene materials to patch this property, and call it whenever you want? Containing something like this:
mtl.maxSimultaneousLights = 7;
Thanks @Vinc3r for reply…
I’ve do it, but it just add property to the array and has no effect on the scene
I’m not sure what you mean. In the playground you’ve linked above, there is neither materials nor gltf.
sorry, about gltf forget it… so how to increase the light limit on the material?
I was thinking about this solution, but increasing maxSimultaneousLights above 9 returns us issue about shader compilation:
I don’t know why I have issue in my playground, 'cause an example found on the doc allows 16 simultaneousLights.
Actually it looks like a bug, when switching to BJS v4.2 in my example I can set
mtl.maxSimultaneousLights = 300 without any issue. It’s been a long time I pinged @Deltakosh
There is a limit on the number of uniform buffers used in a shader. It seems 12 is a common value, at least it’s the one of my GPU for the vertex shader.
Each light consumes a buffer. Babylon is also using a buffer for the scene, mesh and material objects. So, with 9 lights, you reach the limit of 12. Adding a new light will get you an error saying that you exceed the maximum number of uniform buffers you can use in a vertex shader. In 4.2 we did not create a uniform buffer for the mesh data, so you had room for an additional light compared to 5.0.
I can set
mtl.maxSimultaneousLights = 300
maxSimultaneousLights is just the maximum number of simultaneous lights allowed, it does not create uniform buffers. Try to create 11 lights: it won’t work even in 4.2 (because 11 lights + scene + material buffers = 13):
OK thanks for the explanations!
Thanks @Evgeni_Popov @Vinc3r for reply and for explanations
uhhh so in my project every object should have light and allow make a lot of light.
like this https://playground.babylonjs.com/#20OAV9#3583
any suggestions how to solve it?
It’s a bad idea to use a lot of lights because it’s taxing on performance.
If your lights don’t move, you should bake the lighting into textures instead.
There are technics to use a lot of lights (like deferred shading), but it is not supported by Babylon yet.
@Evgeni_Popov thanks for reply…
This is an interesting idea. there’s no harm in trying. so, how to bake light into a texture?
You would need to do that in your DCC tool like Blender. Look for “lightmap” in this forum, a number of posts should show up. I myself does not know how to create them in external tools.
Okay thanks you so much @Evgeni_Popov and @Vinc3r for reply
My tutorial can help you about lightmaps From Blender to BabylonJS - Nothing-is-3D (not using PBRMaterial at that time but logic keep the same)
I’ve tried it. I see that in each mesh includes one lightmap … can one lightmap be added to many meshes?
Yep of course, you just have to share UV2 unwrap between meshes.
I do not understand how. do you have an example?
Since Blender 2.8+ you can edit multiple meshes as the same time, so just select them, be sure that your correct UV channel is active on all meshes (my ReTiCo addon could help to quickly activate UV1 or 2 on selection), unwrap, and you’re good.
I mean implementing to script. I have one lightmap, inside which corresponds to multiple meshes