Dynamic enable of point light

Hello.

We are creating a maze for a mobile game. We want to use instanced meshes for decoration of walls, floors, arches, doors. Materials have a limit on the number of light sources (maxSimultaneousLights). That’s why we disable the point light, which is located far from the camera.

Map in blender:

Render in Babylonjs:

The first time the point light is turned on, we get a frame loss (render delay). But when it turns on again there is no loss.

I made a simple example in the PG:

After 4.5 seconds, the light turns on for the first time, there is a loss of frames.

Is there a way to programmatically solve this?

I read a lot of documentation, experimented for a few days, but could not get rid of this problem.
I will be glad of any help!

To get rid of the render delay you may use this light with zero intensity in the beginning - https://playground.babylonjs.com/#8IMNBM#368
And control all meshes in your scene (include them into light computing or exclude them):

light.excludedMeshes.push(mesh)
light.includedOnlyMeshes.push(mesh)

If you want more than 4 lights for some material use something like
material.maxSimultaneousLights = 8;

2 Likes

@labris thanks for your reply!

In our scene we use a large number of instanced meshes.
Instanced mesh is one material, one texture for meshes, it’s less calculations and smaller scene size.

We tried increasing maxSimultaneousLights and using intensity (even before creating this topic on the forum). This does not work with instanced meshes.

In this example, you can see how the light stops turning on (use W and S for camera movement).
After several light sources, the limit is triggered. By increasing the limit we will break the scene.
Only intensity is used here:

This example shows how well turning on the light with setEnabled works:

In this example, setEnabled works with a smooth increase in intensity (this is what we need):

But we get frame loss at the first light switch when there are much more polygons.

We are ready to detain the player before the start of the game in order to run through the entire map for the first time to turn on the light. But it seems strange. Maybe there is another way?

1 Like

Hey there, here’s an example I made from your last playground to show another approach using pooling to reuse the lights. It uses just 7 lights instead of 40 (you can check the node tree in the inspector to see how many are created). Since they’re always enabled hopefully the initial stutter will be fixed in your final project as well. :crossed_fingers: :slight_smile:

3 Likes

The light arrays pushing and popping as @Blake suggested is a good approach. Since you have a lot of lights in your scene you’ll need a kind of LightManager anyway, arrays are the simplest solution here.

You may check if it will work in our case - https://playground.babylonjs.com/#8IMNBM#412

1 Like

@Blake Wow! Great idea :smiley: After loading the map from Blender, I will be able to record the coordinates and properties of the points of light. I will be able to move the light to where the player expects to see it.

@labris The idea of using the intensity property works! I will try to combine this with the movement of points of light.

Thank you for your help!

1 Like

Seems that you are making some FPS game. Would be nice to have a look when ready :slight_smile:

2 Likes

@Rubaka your game looks stunning, cant wait to try it !!!

1 Like

I want to play it now ;D

1 Like

Just found your lessons how you are making this game with Babylon.js :slight_smile: https://www.youtube.com/channel/UCJpdRLRArqPskXq_TIJ9SeQ

5 Likes