I have tried to optimize the rendering i want, and i still have a little performance bottleneck.
I have now 61 lights in the map.
I have a simple algorithm to calculate all the lights in a circle around the player, and toggle off/on lights. I have for each check, i have to toggle on around 10-15 lights. Like @Leonidas in the thread mentioned before, i see a little lag when i toggle them on.
Is there another way to optimize that ? May be with lights less intensive ? Thanks
Your solution needs to have all the lights activated if i understand well. So i will reach the WebGL error mentioned before MAX_FRAGMENT_UNIFORM_VECTORS
It’s not a great solution, but one thing you can do to avoid the MAX_FRAGMENT_UNIFORM_VECTORS problem is to split your scene objects (and duplicate materials if they are shared) and lights onto different layers. That way you won’t be exposing all objects/materials to lights that they don’t have to be affected by.
I understand, but you can start splitting your geometry and lights up on different layers. Lights will affect all objects/materials on the same layer, regardless of whether they are in range or not. If you split your level up onto separate layers, and then the lights for those respective areas onto those same new layers, you can control the number of uniforms that are being passed to each material.
You might have some trouble lighting the player, since he would need to be lit by practically all the lights, which would cause an overload. A quick and dirty way to address that would be to have a single light for the player on his own layer that adjusts its brightness based on the proximity to the other lights.
and i have this warning in Chrome 91 / macOS Big Sur 11.4
[.WebGL-0x7fee69cb5600]GL ERROR :GL_INVALID_OPERATION : glDrawElements: Texture bound to texture unit 0 with internal format GL_DEPTH_COMPONENT32F is not compatible with sampler type GL_SAMPLER_2D
Ok, i have tryied to update parameters but it didn’t change anything.
I have another question on lighting topic. Many elements in my scene are static, like buildings.
If i understand well, using lightmaps could be a good performance improvement.
My building model don’t have “Lightmapped” option activated, so shadows are calculated in realtime. If i activate the option, i have the warning “UV1 is missing”.
When i check the model, i didn’t have the “Pipeline” option on the right panel, like in the doc (Runtime Lightmaps | Learn PlayCanvas)
Unfortunately, unwrap UV is not available with GLB at the moment. You would either have to use the older JSON format or unwrap the UVs in the modelling program before importing them
I noticed in my projects that when selecting a model that has a UV1 to be lightmapped, the editor will still say that UV1 is missing. Since I had my own lightmaps, it didn’t affect me much, but seeing this thread, I thought I would mention it here.
What I mean is choosing a RenderElement that does indeed have a UV1 will still show as having no UV1 when selected for lightmapping in the editor for runtime lightmaps.
The clustered lighting is a way to go with many lights. I’m not sure what the problem is with that warning you get, it’s not something obvious. Do you not get that warning when clustered lights are disabled?
Without clustered lights, you should be able to enable / disable lights as needed, but each time a new number of lights is used a new shader gets compiled, which takes 100s of ms for more complex shaders. Eventually the cache would contain all variants needed, but that’s not a solution.