Vertex lighting - static and dynamic

Started by
7 comments, last by Tom 18 years, 8 months ago
This has been bothering me for a long time, and I never thought to ask here until just last night. I see a lot of games that have static vertex lighting, but they also have dynamic lighting for torches and whatnot. I know some people use light maps, but I'm sure others use vertex lighting. I was wondering, is there a way to mix static and dynamic lighting in hardware to maximize performance? How do the pros do it?

GDNet+. It's only $5 a month. You know you want it.

Advertisement
Are you using HLSL? If not, you should look into it, because it makes situations like this much easier. You can code custom shaders that will take any kind of lighting into account - for example 2 dynamic lights and a shadow map.

That is certainly how it is handled with professional graphics engines. Some use runtime fragment to dynamically link the necessary shaders.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
Hi there Tom,
How are you doing buddy?

The Problem
Static lights and dynamic lights? How to use them and when?

The Solution
Well Tom, I don't work in a fancy game development company but I shall do my best to answer your question. What normally happens is that in a scene you may have a light bulb and then a few windows... so what I generally do is have a mixture of them.

Lights in the Fixed Function Pipeline (D3DLIGHT9 , IDirect3DDevice9::SetLight())
Using the lights here are really simple as you just create a light structure, and set them using the SetLight method... you maybe update every frame for the dynamic one's. Shaders are faster though.

Lights in Shaders
When using shaders it's best to keep the lights to a minimum, what I normally do is have a light for each pass in the shader which is terrible but it gives you some flexibility. So it's a give and take basically.

I would think that the pro's calculate how many lights there are in the correct scene and batch them in the shader and do all the neccesary calculations of lights in less passes.

I hope this helps a bit.
Take care.
Quote:Original post by Armadon
Lights in Shaders
When using shaders it's best to keep the lights to a minimum, what I normally do is have a light for each pass in the shader which is terrible but it gives you some flexibility. So it's a give and take basically.

Depending on the shader model (and if you are thrify enough), you can combine multiple dynamic lights per pass. For example, with vs_2_0/ps_2_0 it is pretty easy to have 2 or more lights. And even after that you can use a lightmap, too.

Quote:I would think that the pro's calculate how many lights there are in the correct scene and batch them in the shader and do all the neccesary calculations of lights in less passes.

A good practice is to select 2-4 dynamic lights per object, usually based upon proximity. You also have to take into account the different types of light (ie point, spot, directional, ect...). Some, like point lights, are more expensive than others, both in the lighting phase and especially in the shadowing stage.

Which brings me to another point - you have to be very careful about using multiple light sources with shadows, especially if you are using shadowmapping. More than 1 or 2 lights can really bring down an application fast if you do full shadowing calculations with them.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
Thanks for the replies. To be more specific, I'm wondering if there's a way to do it in the fixed pipeline. For optimal performance, you'd want to use pre-lit vertices (D3DLVERTEX) for static geometry that typically doesn't receive much dynamic lighting ... but that's the problem, because then you have to calculate dynamic lighting on your own, in software. I've seen several products (Gothic II, Dungeon Siege II) that look like they use both static and dynamic vertex lighting. It's interesting to hear people using fragment shaders for this, but I'm more interested in stories that use the fixed-function pipeline, because it's more accessible to me at the moment.

GDNet+. It's only $5 a month. You know you want it.

Quote:Original post by Tom
It's interesting to hear people using fragment shaders for this, but I'm more interested in stories that use the fixed-function pipeline, because it's more accessible to me at the moment.

This is easy enough, as well. Just use the dynamic FFP functionality (IDirect3DDevice9::SetLight()) and the required texture stage states for the static lightmapping.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
What states would I use to have lightmaps with dynamic lighting?

GDNet+. It's only $5 a month. You know you want it.

Quote:Original post by Tom
What states would I use to have lightmaps with dynamic lighting?

Check out this Gamasutra article. It was made during DX6, but the render states and texture stages states will be the same.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
Thanks for the link. (For some reason, this particular article isn't in the Gamasutra compendium that's floating around, so I missed it.)

Unfortunately, I seem to have wandered off the original topic. Perhaps I should rephrase my original question by providing a situation. I'd like to have static lighting for my scene to optimize rendering performance (by assigning default vertex colors), but I would also like to have dynamic lights that illuminate nearby geometry. If at all possible, I'd like the video hardware to process this dynamic lighting; I can provide a culled set of vertices myself to limit processing to the area immediately around the light source.

Is there a way to set this up in the fixed pipeline with DX8? Is it even possible to give a vertex a color value and still have it be affected by lights? Perhaps I can add the light value to the color value and cap it at 1.0 (white)? I don't know just how flexible the FVF really is.

GDNet+. It's only $5 a month. You know you want it.

This topic is closed to new replies.

Advertisement