Correct me if i`m wrong

On a level how many lights should i have ? i don`t want to bake them.

I have 5 at the moment on separate layer, im using EMPTIES to spawn them in when i hit certain PLANES, when im out of range of the light
source i put PLANES in certain places to END OBJECT of the light.

Lets say im in a basement and i put some EMPTIES that spawn light
and when i move out that area they get deleted and respawn on new
EMPTIES that i have put on another part of the level that im entering. So in theory im using the same light sources but spawning them in
different places when they get deleted, when i trigger a new PLANE.

Is this the correct way too do it and save FPS and better optimization
because when i use loads of lamps it really drops the fps from 60fps to
40-45fps, it seems to be working for me but i want to be sure i`m correct.

Thanks for reading.

You’ve got a couple of options here. and it really depends on what type of scene were talking, a big warehouse with 30 hanging lights obviously doesn’t need 30 separate lamps, you can just have the material be shade-less and place a sun or hemi in the middle. What you’re doing is actually a pretty good system, having the lamps disappear when you’re not near them. You might be able to set up an LOD for the lamps with the new LOD system, where it replaces it with an empty or something like that, but I haven’t tried so don’t quote me on that (: as for the amount, I wouldn’t have more than 4-5 just to be safe.

Somebody said somewhere that OpenGL has a limit of 8 unique lights or something like that but I noticed that if you duplicate the same light in Blender using ALT+D you can add way more than 8. Can somebody explain the limitations or how to work around those limitations ?

Try using ALT+D and see at what number of lights it starts to fail. When you use ALT+D you end up using only one light because you are duplicating the same exact one.

Here is a test scene that behaves a bit weird or could be a camera bug. If I press P and look at the scene through the camera lens I get very low fps , somewhere in the 46 fps zone. If I delete the camera and press P I get 60 fps. Camera bug or is this normal ?

Attachments

lamps.blend (134 KB)

With no Camera, try zooming in so you have about the same view as the Camera would have, you’ll see performance dropping all the same.

I think Raco is right , because from some angles I’m getting 60 fps and then from other viewing angles I barely get 40+. I don’t know why it’s doing that.

It definitely has something to do with shading.

Please stick to the topic of my question thank you.

I can get around 8 lights before my FPS drops, however when i spawn lights in
is this considered duplicating or using the light on the different layer ?

@@thelaurent
Yeah it would be nice with LOD maybe if you ever look into it, you could tell me
and you really think its a good light system im using ?

@@blenderer2012
You have 144, that is crazy and it`s around 40fps and 50fps when not in camera mode.

@maseratzi Your method of optimisation is perfectly fine, there is always more you can do to optimise but anymore than what you have and it’ll soon be a choice between a visual drop in fidelity or performance.

My only other suggestion short of baking lights would be to disable specular on some lights i.e. fill lights, lights that are further away. Thelaurant makes good suggestions as well.

To answer your question, when adding a light to a scene (spawning a light) you create a duplicate of the light.
In multitexture mode spawning another light adds a visible source to the scene, whereas in glsl adding a light seems to override any previous duplicate of it. The light object still exists, it’s just only the most recent duplicate emits any light.

Also sorry to go slightly off topic but I just want to point out there’s some misinformation in this thread.

When you use ALT+D you end up using only one light because you are duplicating the same exact one.

That’s wrong, you are creating an instance so they share attributes, but in terms of rendering you have two distinct lights.
The maximum limit of 8 lights comes from older opengl. Multitexture mode has this limitation, GLSL does not.

@@Mattline1

Cheers for reply, yeah i am using GLSL but my goal is to make the game 60fps no compromising.
I have achieved this so far and really happy with it and maybe i will need to add some EMIT on
textures so they seem like there lighting up with the scene in parts a light can`t get too.

I see. Thanks for the info. So then the question becomes. How can we take the number of lights to absolute extreme ? How can we get an infinite number of lights ? Using render to texture ? Maybe that’s a deferred shading or deferred lighting trick/thing.

What about using emissive materials instead of lamps. Can we do that in BGE ?

@maseratzi Good idea, adding emit will be a good way of getting some ambient lighting in, combine that with an ambient occlusion bake and/or ssao and you have a nice approximation of light bounces.

chafari , nice example but performance hit is huge from those shadows (talking about LampNear.blend) , sometimes it runs with only 20fps and sometimes it climbs back to 60fps. Another thing is , how come the light cone margin is so nice and smooth and blended and then the rest of the shadows inside the light cone are not smooth or filtered at all ?

I would prefer to use texture projection but the projection options right now are not very good or very limited. Something like this example but with correct projection options to fake multiple light sources from just one lamp and only one texture.

Attachments

TexturedLight.blend (143 KB)

Be careful to test whatever you’re doing. testing will reveal flaws in any lighting setup.

Adding lights is good, but as matline1 says, the older lights tend to disappear. A better solution is to have a set of like 4-6 lights and use python to move them to the position and orientation of pre-placed empties which represent in game lights.

You can also have them take on the characteristics of the light you want by getting info from the empty’s properties.

It’s not an easy system to program, but the reward is the appearance of a well lit level without a drop in framerate.

How to:
First you need to get a list of light “hooks” (the empties which represent your lights) in the level, then get a list of your lights.

Check which light hooks are visible from the player’s position (if one is really far away or in another building, it can be classed as invisible, if it is behind your player and not pointing towards him likewise). Order the list by distance with the closest ones first.

Now place the lights on your list in the same location and orientation as the lighthooks, starting with the closest. Set their properties (energy, spotlight cone etc…) by getting info from the light hook.

If there are more lights than lighthooks, set the extra lights to zero energy.

Notes:
This system works best with static light sources (otherwise you have to update every frame, so 60 times per second instead of just two or three times per second), and it works best with an overhead or isometric view, rather than a FPS. It’s also best to use spotlights as these have a direction which can be checked to see if it is pointing towards your player. Finally it works best with the older types of renderer like Single texture or multitexture. You should take care if using this system to have a game where you don’t have lots of big open areas with multiple lights. It would be pretty bad in a huge warehouse with 30 lamps hanging from the ceiling, but it would work will in an indoor setting such as a space station or tunnel complex.