Hey, so i noticed that if i add to many light source’s (point light, spotlight, hemi light) then the engine says “no” by making them all black. Because im working on a map for my game witch is on a spacecraft, and there are alot of spotlights and pointlights, and since i have about 20 light source’s already everytime i add a light source the engine freeze for like 10 sec
And now if i add one more light everything turns pitch black, until i remove that light. i guess i runned in to some sort of limit.
So what should i do now? im not even close to finnish the map and there are aloooot more light needed :P.
So is baking the only way now? i tried cycles bake and it took forever since i had to bake every single texture on every freaking object…
But i still need to make an own texture for every freaken object right, and you see i got like over 200 objects in my scene and my map isnt even 25% done yet…
Make and bake a texture for every object will take hundred years!
How does other game engine work???
Like why cant i just select the light, and click bake, and then it just takes the light its currently emitting and just save it as like a texture paint to what ever object it hits.
Put anyways thats not my question. i wanna know how i can fix this “too many lights” problem
Does every single one of those 200 objects need to have unique textures?
Can’t you bake the texture to just one object then copy it? This is how just about every other game does this. The only exception that comes to my mind is Rage (which still used repeated textures, but I digress…)
Say you have 8 light fixtures running down your hall. There’s no need to have 8 seperate textures if they all look the same, right?
Just texture the one light fixture, and clone it. Better yet, create the light fixure in a seperate blend file and link it into your game as a group.
Create your scene from a handfull of pre-fabbed lego pieces, rather than trying to hand-sculpt every nut and bolt of your scene.
If you do this though, you wont be able to bake your lighting on the same UVs as the textures, so you’ll have to just set up a seperate UV for the light.
There’s no rule against having multiple UVs being projected onto the same geometry.
If you’re worried about taking too much time baking the lighting on each object individually:
-Go to File --> User Preferences —> Add-ons tab ----> search for ‘Texture Atlas’
^this is how other engines work
Texture Atlas basically lets you select a bunch of objects, then unwrap them as if they were one. All 200 of your objects can be mapped onto a single UV in a few clicks, ready for shadows baking.
I suggest dialing back and trying to make a much simpler scene before you try tackling a final product. Learn the techniques, the tricks, and establish a pipeline to work through. Once you’ve mastered the simple scene, you’ll be able to crank out the complex stuff just as fast as your renderer will allow.
This is ridicolous, so i really have to bake like a slave… really, there must be a way of like lower the resolution of the light or someshit until i start the game. and when i start the game i set camera render distance short so i can only see a few lights at the time
The light limits can only be overcome if the BGE’s render engine gets the capability to use a deferred or inferred rendering pipeline, which more or less requires a complete rewrite of the component.
There’s been work before on actually doing this, but right now it doesn’t look like the BGE is even close to getting it.
The other method would be to use a light management system which teleports lights around the scene with properties that get changed. However, if you need to see more than ten lights at once, then only option is baking, which by the way can be done using a low-resolution image to maximize smoothness and minimize render times.
The bge’s forward rendering uses a shader for each light source, so it depends on your gpu for how many shaders it can run at once. You can make your own deferred rendering 2d filter which computes all lights in 1 shader and pass light arrays to it stored in texture buffers using using pyOpengl. Though it’s too much high level work for a problem that can already be overcame using baking.
I might actually give it a shot hopefully in the near future.
the lightmanager with python (and dummies lights) require too many setups .
is not really doable
someone is able to write the real function ???
see below (all other code is right)
EDIT : also SUN and HEMI has the property “distance” , so is not very right
import bge
class LightManager:
def __init__(self):
self.lights_in_range = set() #the camera is a cone and the lights (for semplification) are all spheres
def update(self): #run each frame
scene = bge.logic.getCurrentScene()
cam = scene.active_camera
lights_in_range = set()
for light in scene.lights:
if not hasattr(light, "distance"): # hemy or sun, so include anyway [EDIT] not excactly so [EDIT]
lights_in_range.add(light)
continue
if cam.sphereInsideFrustum(light.worldPosition, light.distance) != 2: # not out (so inside)
lights_in_range.add(light)
if lights_in_range != self.lights_in_range: #if true need a refresh
self.lights_in_range = lights_in_range #save the new state
self.FUNCTIONINVENTED____RECALCULATEALLMATERIALSWITHTHESELIGHTS(tuple(lights_in_range))
def FUNCTIONINVENTED____RECALCULATEALLMATERIALSWITHTHESELIGHTS(self, lights):
pass
if not hasattr(bge.logic, "light_manager"):
bge.logic.light_manager = LightManager()
bge.logic.light_manager.update()
#the calculation itself of the distances for 50 lights cost 0.2ms (less of one IK)
that will take ages to make animations to every single light, and make them move to a new location whenever i enter a new room. then i can just bake. it wont go any faster
Not, actually, that’s the right thing to do! You can call it light lod! Place empties evrywhere a light should be, then add properties like intensity, color and type. Have an array of lights (10 or so) and make them be placed by the empties positions/orientation.
Also plan your lights carefully and you can use vertex lights and use fake lights at the distance - empties that turn all vertices near them to a specific color!
There are a few workarounds, just be creative!
Yes you need only a few lamps…lets say you have 200 fire torches in your map. The protagonist sees what…1-5 torches at once, so you need only 1-5 active lamps at any moment. (Light lod is a good explanation). Move a light with python to another position(new torch position) every time the protagonist is moving toward a new torch. Maybe use pointInsideFrustum function so you add a light source only if the lamp is in the field of view of the camera. Making light LOD system is a complex work, it is not easy, however it is the right way to go.
In my game there are approximately 100-200 light sources(torches,fireplaces,lanterns…etc) in each map and 5 real lamps at any given moment, only one lamp is constant- the player lamp, which properties(intensity,color…etc) are modified dynamically according to the environment.
For instance, each tree has a shadow property with certain distance property. So when the protagonist is in this certain range(distance) from the tree, the main player lamp properties are modified accordingly.
or simply make a sort of lod for the lights.
ad a few 100 lamps set its energy to zero, use python to set energy to 1 or whatever you like, when in range.
It’s not a matter of GPU power, it’s a hardware limit for shaders, even if every shader just setted a pixel’s color.
@yghtim, setting the energy to 0 still runs the lamp’s shader and processes lamp data as in getting the vector from pixel to light source and other falloff calculations etc.
Adding many lamps(objects) to the scene is not a good practice. A lamp object is an object after all and it affects performance. It must be initialized by the engine with all of its properties, like shadow,range,type…etc. and there is no “inactive” option in blender ge. So this lamp will be active, no matter if its energy is 0 or 100.
true, but with energy to 0 the load will be minimal. and doing it like that u can simply hold a few 100 lights, without them turning black. If you really use a few 100 lights it’s not recommended. but for a light of 20-30 it works nice.
you can also optimize it by removing the shado cast from them, and just parent a lamp to the player that only cast shadows. and put a hemi to use for global lighting (its energy to .2 or something)
with your blend in fullscreen i get 35FPS fix , both when the cube is in the middle of plane (with all lightsd visible)
and when is completely out of plane(without lights visible)
is normal?
maybe is my hardware? and i use blender 2.69 (if is a feauture i download immediately :yes:)