Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL lights limit

As I was reading RedBook I stayed quite confused, that openGL can have maximum 8 lights in scene (number depending on implementation, but should be arround 8).

But I can imagine number of situations that would need more lights, so I think there's a trick arround this in game dev.

For example, you have very long street with 50 strretlights, or you can have squad of 20 peoples all using flashlights. How you actually simulate those situations? There's a problem, that light iluminates only the part of mesh, not whole cone between source and object, so if we don't have 100% clean air, there must be some sort of simulation also. What's the way this is done, and the game runs smooth?(I read also that enabling all 8 lights could kill FPS)

like image 778
Raven Avatar asked Aug 27 '10 11:08

Raven


People also ask

How do I use lighting in OpenGL?

With OpenGL, you need to explicitly enable (or disable) lighting. If lighting isn't enabled, the current color is simply mapped onto the current vertex, and no calculations concerning normals, light sources, the lighting model, and material properties are performed. Here's how to enable lighting: glEnable(GL_LIGHTING);

What is OpenGL lighting?

Lighting in OpenGL is therefore based on approximations of reality using simplified models that are much easier to process and look relatively similar. These lighting models are based on the physics of light as we understand it. One of those models is called the Phong lighting model .


1 Answers

8 lights is the limitation of fixed GL pipeline, where you enable each of them, set mode, parameters, etc. Now you have pixel shaders, and lighting is done within shader. There you can use large number of dynamic (not baked into textures) lights. You only need to supply all these lights' parameters sufficiently (maybe, in a texture), and test how many lights your shader is able to process. Also, in shader you can cull too weak lights (contributing too little into pixel value) or just too distant ones.

Update: complex shader with branching can even generate lights (think of long street or christmas tree). It could be more efficient than supply large number of parameters.

like image 53
alxx Avatar answered Nov 12 '22 10:11

alxx