PDA

View Full Version : OpenGL Lights



04-27-2006, 09:39 AM
Hi,
I'm the very beginner so don't laugh :p

I heard that OpenGL can handle only 8 different lights (LIGHT0-LIGHT7). It's very few I think... or maybe i'm wrong. But lets look at Unreal Tournament for example, I made some maps in UnrealED and there was a lots of lights (even few hundreds sometimes). So... how can OpenGL handle only 8 if my UT (using OpenGL renderer) can handle 'em all and everything is OK? Are these a different kind of lights? Or maybe there's some kind of other renderer working parallel with OpenGL that can handle the rest?

Thanx :)

Antorian
04-27-2006, 10:02 AM
In fact OpenGL use a max of 8 Lights when rendering a single Triangle.
So in a renderer you should not have more than eight light for a triangle, but a lot of lights for a scene can be rendered by selecting wich lights are coloring a given triangle.

So you need to focus the mathematical way that your renderer must manage lights in a scene and lights for triangle.
(Lightmaps, Light Quadtrees,VertexColor.... etc)

04-27-2006, 10:49 AM
So if I understand properly I can build a scene with more than 8 lights by selecting which light colors a triangle ? How can I select it ?

Maybe I tell what I wish to do. I have 3 cubes (6 polys for each) and I wanted to set 3 different lights for each cube. Should I use triangles instead of polys ? I know that Tris are better but is that necessary ?

I will be grateful for any answers
Thanx :)

Mars_999
04-27-2006, 11:17 AM
Originally posted by <alex>:
So if I understand properly I can build a scene with more than 8 lights by selecting which light colors a triangle ? How can I select it ?

Maybe I tell what I wish to do. I have 3 cubes (6 polys for each) and I wanted to set 3 different lights for each cube. Should I use triangles instead of polys ? I know that Tris are better but is that necessary ?

I will be grateful for any answers
Thanx :) Yes use GL_TRIANGLES not GL_POLYGONS speed reasons... You select the light by


//change GL_LIGHT0 to GL_LIGHT1-7
//you will need to check the specs on gllights
//for each light after 0 is setup differently with different setup values
//so make sure you set your light you want enabled with some known values
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);

zeoverlord
04-27-2006, 11:25 AM
Let's get one thing straight, the lights in unreal are not renderd as lights in openGL.
Unreals lights are baked into lightmaps when you export the map and is only then rendered in openGL as textures.

Any dynamic light's you see in most modern games are rendered one at the time using a fragment program and it is only in rare occations you need to use anything more than LIGHT0.

In your case i would reccomend setting the lights you need for a cube, render a cube the set the next set of light for the next cube and so on.
Allso quads work as well as triangles for this.

04-27-2006, 01:46 PM
OK thank you guys very much :) I thought that unreal's lights are different but i wasnt sure :) I'll change quads into tris and set the lights :)
thanx one more time :)

Joe the Programmer
04-29-2006, 07:02 PM
Triangles are more optimized than quads, but the real winner is triangle strips. I won't explain them here, but if you want truly optimized rendering, use triangle strips (or triangle fans for terrain engines).