Sign in to follow this  
fervent

[MDX] More than eight lights in a scene?

Recommended Posts

fervent    145
Hi, I'm trying to attach a light to each rocket my guy fires in managed direct3d. Problem is, once the scene displays the maximum number of hardware lights, additional lights don't render. What are my options from simple to complex if I want additional lights on screen? Lightmaps? Normalmaps? Shaders? Where do I start? Thanks, Dave

Share this post


Link to post
Share on other sites
Smit    310
You could have a texture which you blend into the area around the rocket. You could also download the Half Life 1 (or 2 I suppose) SDK and look at the RGP code, it attaches a light onto the rockets and mabye you could get an idea of the method from there.

Share this post


Link to post
Share on other sites
sirob    1181
Quote:
Original post by fervent
Where do I start?


That depends on where you want to go. :)

A little more information about the project would be very helpful here. 2D and 3D solutions would likely be very different. I'll assume you're using 3D, since that's the only help I can provide you with.

What's important to note is that anything above 8 lights would be getting pretty slow. It's not to say too slow, but slow. The best solution would be to pick the most "important" lights, ie. the lights that would have the most effect on the view, and ignore the others. This might not look as well, but it's a good way of keeping performance and still having a light on each rocket (or at least, as far as the user is concerned).

A second option is using more than one pass. This means, rendering the entire scene twice (or more!). Once with lights 1-8 on, then with lights 9-16 on, etc. etc. This will, of course, have somewhat of an ill effect on performance, especially as the scene gains complexity. You'd literally be drawing everything twice (or more).

Another option would be shaders. With that, the options really are unlimited. You could basically do anything you'd like, but the more you do, the worse performance will be. With SM2 and SM3, the number of registers would allow you to go up to a double digit number of lights, though this isn't likely to give acceptable performance.

This is all I can think of as general solutions, which would work in any situation. There are probably more specific solutions which would work out for your specific needs. If you give some more info on what you're trying to do, and what estimated number of lights you're looking to support, I (or someone else) might have more ideas :).

Hope this helps.

Share this post


Link to post
Share on other sites
fervent    145
Thanks guys.

Yes, I'm using MD3d. Im curious about the eight lights being per object as opposed to per scene. If someone can explain how to restrict the lights to an object, that may be enough to solve my problem.

Right now, I simply add a new light for each rocket object (device.Lights[i]). I disable the lights as soon as they go off screen or collide, but even with that additional bit of logic, I can still have 10-20 rockets on screen at once.

Share this post


Link to post
Share on other sites
JWalsh    498
fervent,

Lighting in DirectX is really just a mathematical procedure for determining the color at a given vertex, when taking into account the "lights" in an area.

For example, let's say you've got a cube. By itself, the cube is simply the color of its texture, blended with the color of its vertices. With lighting disabled, this is exactly what you'd see. However, when you enable lighting, the cube is now considered to be the colors of its texture, blended with the color of its vertices, modified by the amount of light it absorbs/reflects as controlled by its material.

When using the FVF, DirectX is willing to calculate for you the color of a vertex combined with up to 8 "lights." This means that for every vertex, DirectX will take the color of that vertex and multiply it by the amount of light it receives from the 8 lights pre-established by the device settings, that is, SetLight( 0...7 ).

Here's the kicker, since DirectX performs that calculation per vertex, and you submit your vertices in a batch as a single polygon, you can actually change lights 0-7 in between rendering polygons, or in between rendering objects, its really up to you. There are generally two systems, not counting hybrids of the two, which help you get more out of your 8 lights.

1. Sort by relevance. Not all lights are created equal. For different objects, different lights might be more important then others. For example, although particle effects are cool looking and you might want them to show up on walls, etc...they might not necessarily need to show up on your ships. As well, you might decide that a ship is only lit by its own rockets, not the rockets of the surrounding ships. This is just a way to make sure the most important lights are active. Usually this is implemented by giving lights either a global "priority" flag, or several flags, each for different types of objects being rendered. Before rendering an object, you enable/disable lights based upon their priority with respect to the current type of object.

2. Sort by distance. A more natural looking method is to sort by distance. Before rendering an object you determine the 8 nearest lights. In your case, this would always include a rockets own lights, and then perhaps a few of the rockets on the ship closest to it. (Always include your "global" light, if you have one).

So the above are the two general ways using the FVF in which to handle per-object or per-vertex lighting limitations. Now, there's also another way using vertex shaders. The FVF limits you to 8 lights per vertex, but with shaders you're only limited by the number of input registers in your version of DirectX or supported by your video card. Its conceivable to have dozens of lights acting on a single vertex. In fact, many people combine both the above methods into a single, intelligent lighting system which prioritizes lights and then sorts them by distance...and then passes perhaps 10-15 of them to vertex shaders to be used on the current object.

If you need help with the lighting calculations for shaders (its real easy) just post on this thread or another and I'm sure myself or someone else will be happy to help you.

Cheers and good luck!

Share this post


Link to post
Share on other sites
fervent    145
jwalsh,

Thanks so much for yourreply! I just implemented the closest lights method you described above. Works like a charm! :)

Thank you!

-David

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this