[SOLVED] Rectangle light source

Hey guys,

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

Try setting the intensity to 0.0 instead of disabling light entities, since that would force the light cells to be recalculated.

1 Like

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.

1 Like

Calling @mvaligursky , curious what he thinks.

@eproasim
The lights are linked to default World layer

@vogloblinsky,

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.

Is this with clustered lighting enabled? As long as you don’t need shadows, it should be pretty straightforward to setup: PlayCanvas Examples

No clustered lights not enabled. All the lights are added in 3D editor mode, and just activated by code in my final game.

What would be the advantage for my use-case ?

Increased performance and it may be able to get around the iOS light limit?

Just added in my project :

pc.LayerComposition.clusteredLightingEnabled = true;
pc.app.scene.layers.clusteredLightingCells = new pc.Vec3(20, 2, 20);
pc.app.scene.layers.clusteredLightingMaxLights = 48;

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

Is there a documentation about these options ?

The API is still in the works, the example is your best bet and you can also check the source code here:

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)

Link to scene : https://playcanvas.com/editor/scene/1091565

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

See: UV auto-unwrap is not supported for GLB model assets · Issue #194 · playcanvas/editor · GitHub

1 Like

Good morning @yaustar,

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.

Yep, if you have baked the lightmaps outside of PlayCanvas, that works as well.

The UV1 is needed for runtime or Editor lightmapping

I understand,

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.

Oh interesting. Can you create an issue on the Editor repo with an example FBX that we can look at please?

Issue submitted: Editor always reports Missing UV1 on RenderComponents · Issue #478 · playcanvas/editor · GitHub

Repro: https://playcanvas.com/editor/scene/1202294

2 Likes

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.