This topic is now archived and is closed to further replies.


How to simulate multiple light sources?

Recommended Posts

Prozak    898
Began working with Vertex/Pixel shaders recently. I know opengl only has suport for 8 lights, but there are ways to work arround that, and have as many as one wants... So, what are those ways? I can process all the static lights in a map and create a lightmap for all polygons in the map, I guess. What about dinamic lights, ala Doom 3 for example? Im guessing they aren''t constrained by any n amount of lights... Salsa cooked it, your eyes eat it!
[Hugo Ferreira][Positronic Dreams][Colibri 3D Engine][Entropy HL2 MOD][My DevDiary]
[Yann L.][Enginuity] [Penny Arcade] [MSDN][VS RoadMap][Humus][BSPs][UGP][NeHe]
                          Prozak - The GameDever formally known as pentium3id

Share this post

Link to post
Share on other sites
Sneftel    1788
Well, you could render the scene multiple times, with subsequent times using additive blending.

You probably don''t need to do this, tho. It''s very unusual for more than 8 lights to actually have a significant impact on a single object. Just pick the eight that''ll have the greatest intensity (light_intensity / (distance * distance)) and use those.

"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post

Link to post
Share on other sites
MumbleFuzz    188
I''m fairly new to graphics programming, but here''s what I know about real time lighting methods.

Firstly, as far as I know, OpenGL''s lighting model is purely vertex-based. This makes it awkward to use, and the results, when compared to current engines, are generally poor.

As Sneftel suggests, the best way is to render the scene several times, once for each light, using additive blending. To render a scene, you''d do the following:

1. Disable writes to colour buffer. Render scene to depth buffer.

2. Enable colour writes.

3. For each light, render scene using additive blending.

How you do the lighting depends on how much you want to use pixel shaders. I don''t have great shader support on my PC, so I use a slightly inelegant lighting model that involves lots of multitextuing and a slightly crude approximation of the lighting. Look around online for a tutorial if you''re not sure.

Of course, if you want Doom 3 style lighting, you''ll need the shadows as well. The shadow volume/stencil buffer combo is easily combined with such a lighting technique. Google for more on that as well.

Share this post

Link to post
Share on other sites