Jump to content
  • Advertisement
Sign in to follow this  
pcg4m3s

OpenGL How to have more than 8 spotlights

This topic is 3012 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How must I do to have more than 8 spotlights in opengl?


glLightfv(GL_LIGHT0,GL_SPECULAR,luceSpeculare);
glEnable(GL_LIGHT0);
glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,60.0f);
glLightfv(GL_LIGHT0,GL_POSITION,posizioneLampione0);
glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,direzioneLuceGiu);
...
...
...
glLightfv(GL_LIGHT7,GL_SPECULAR,luceSpeculare);
glEnable(GL_LIGHT7);
glLightf(GL_LIGHT7,GL_SPOT_CUTOFF,60.0f);
glLightfv(GL_LIGHT7,GL_POSITION,posizioneLampione7);
glLightfv(GL_LIGHT7,GL_SPOT_DIRECTION,direzioneLuceGiu);


I need more than 8 spotlight.

Share this post


Link to post
Share on other sites
Advertisement
There are a few options. You can do multipass rendering, which basically means drawing your geometry more than once and each time you set 8 different lights and accumulate the result. Another couple of options are to use deferred or light-pre-pass rendering techniques.

Share this post


Link to post
Share on other sites
Quote:
Original post by Dave
There are a few options. You can do multipass rendering, which basically means drawing your geometry more than once and each time you set 8 different lights and accumulate the result. Another couple of options are to use deferred or light-pre-pass rendering techniques.


can you do a simply example, please?
i don't understand very well because i don't speak english very good...
thank you!!!

Share this post


Link to post
Share on other sites
1) Get the first 8 lights and draw the object as normal.
2) Disable ambient lighting, and enable additive blending.
3) Render the object again with the next 8 lights.
4) If there's more lights remaining, go to step 3.
5) Enable ambient lighting, and disable additive blending.

Share this post


Link to post
Share on other sites
Quote:
Original post by Hodgman
1) Get the first 8 lights and draw the object as normal.
2) Disable ambient lighting, and enable additive blending.
3) Render the object again with the next 8 lights.
4) If there's more lights remaining, go to step 3.

can you do an example with code?

Share this post


Link to post
Share on other sites
Another option, if you don't need all the lights all the time is to group them up.

For each Object
-collect upto the 8 light sources that affect this object
-glEnable and glLightf the parameters for the lights you found
-disable any extra lights if your object has less that 8 sources
-draw your object

The hard part of this is figuring out what lights you may need. Take a look at the OpenGl Redbook for the equations used for lighting. You can use each light's spot exponent and attenuation factor to determine the maximum effective range of that light. So, when collecting the list of lights for an object, you check to see what lights are most going to affect the object based on range. This way you only render each object once.

Share this post


Link to post
Share on other sites
Quote:
can you do an example with code?
Writing up a working code example for this would be non-trivial and could take quite a while. Maybe you'll get lucky and someone will do it for you, but I think it's unlikely.

A better bet would probably be to try and code it yourself, and then post back here if you run into problems. Unfortunately, dealing with multiple lights can get kind of complicated no matter how you approach it. I'll also mention that although you can probably get away with using the fixed-function pipeline for this, these days most people's efforts are focused on shader-based techniques (such as the aforementioned 'deferred lighting' and so on), so if you're serious about supporting multiple dynamic lights, you might want to start looking into the programmable pipeline.

Share this post


Link to post
Share on other sites
most games only deal with one light at a time
eg quake3

draw object
for all lights
{
is object inside a spotlight?
yes - enable spotlight, enable blending
draw object again
}

Share this post


Link to post
Share on other sites
Quote:
most games only deal with one light at a time
eg quake3

draw object
for all lights
{
is object inside a spotlight?
yes - enable spotlight, enable blending
draw object again
}
Are you sure that's what Q3 does? IINM, dynamic entities such as characters and items are lit at the vertex level using a pre-computed 'light grid', while static geometry is lit using either pre-computed lightmaps or pre-computed vertex lighting.

Share this post


Link to post
Share on other sites
Quote:
Original post by jyk
Quote:
most games only deal with one light at a time
eg quake3

draw object
for all lights
{
is object inside a spotlight?
yes - enable spotlight, enable blending
draw object again
}
Are you sure that's what Q3 does? IINM, dynamic entities such as characters and items are lit at the vertex level using a pre-computed 'light grid', while static geometry is lit using either pre-computed lightmaps or pre-computed vertex lighting.


As you said, that's what Quake 3 does.
For Doom 3, which is shader based, it handles 1 light at a time I believe with additive blending (glBlendFunc(GL_ONE, GL_ONE))

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!