Multiple light sources

Started by
2 comments, last by cody 16 years, 4 months ago
Hi, i am wondering how to render many light sources in a shader. Whats the 'standard' approach? Creating a shader for one light and render in many passes? Or should i calculate for example 8 lights in one shader? Which gfx cards are capable of doing that, as the shader will get pretty big especially for more complex lighting equations? My geforce 8800 has no problem with that, but i dont think that it would work on older shader 2.0 cards or something. One more problem is that older cards dont have flow control. When your shader is for 8 lights and you only have 3 lights, then you still to calculate all 8 lights. Or write a extra shader for for 1-8 lights. thanks for your suggestions!
Advertisement

Hi,

I think that there isn't really a standard approach. Most of the implementations are doing certain simplifications anyway. So, in a way, having 8 different lightsources is an overshoot most of the time, and also, takes just too much of processing power. For example, if I remember correctly, Half Life 2 supported like 2 light sources + a certain ambient cube with the rest of the lights baked in.

Anyway, as you mentioned, there are different approached such as

- multipass rendering, you can still render several light sources per pass depending on the hardware

- deferred shading (basic setup is expensive), lighting is slightly less expensive

- a fixed number of lights + some approximation for the rest of the lights (ie. the HL method).

For starters, I'd do an analysis of the environment and see how many light sources usually affect the objects. Usually this isn't very big number. If you are having really huge objects, you should consider splitting them smaller.

SM2.0 cards should support static branching, which should provide you the means to handle a variable amount of lights. There are also other ways to save yourself from writing tens of different kind of shaders for changing lighting conditions.

Good luck!

First of all, there's really no single right way of doing things and as is the case with mostly all other programming related tasks, it's mainly about trade-offs and our choices between the bad and the worse! :}

Instead of repeating what's been already said, I provide some links to get you up and running. Feel free to ask if you need further clarifications.

Lighting rendering architecture doubt
Lighting Implementations
Thanks guys. A single correct solution to the problem would have been too easy.:)

This topic is closed to new replies.

Advertisement