Multiple light Solutions ....

Started by
4 comments, last by hplus0603 18 years ago
Hello. I have created a shader which lit my model with Perpixel lighting. This shader is pretty complex and so, it can only handle one Spot Light. The problem is that with only one spot light, it's not easy to illuminate a complex scene ... I have an other Shader which can handle multiples lights using Per-vertex lighting. So i was thinking to use a multipass approach (combining both shader) to solve the problem. Do you think it's a good idea ? Do you know any other way to solve this problem ?? If you can give me some hints pleas, let me know ... Thanks a lot. Clement Vidal
Advertisement
you don't need multiple passes. Collect the x nearst lights. Pass them to a shader and do the calculations inside the shader. you can use branching inside the shader , so the shader can handle a different number of lights

hope this helps

greets
I have try to use branching in my shader to manage multiple lights sources, here is the (pseudo) code i was using:

COLOR_PAIR ColPair;
for(int i=0;i<numLight;i++)
{
ColPair += DoDirLight(...);
}

because the shader do PerPixel lighting, this computation is done inside a pixel shader, and this code do not compile succesfully, i get an error like:

x3511: loop does not terminate ( over 1024 iteration)

The variable numLight is a global variable, And i never manage to erase this error, that's why i'm planning to use a multipass approach....

if you can help me .... :)

Thanks a lot !
What is the shader version you are compiling the shader to?
I'm compiling using Vertex and Pixel shader 2.0
There are two approaches to multiple lights:

1) Single-pass: For each object, calculate less important (further away) lights in the vertex shader, and calculate more important (closer) lights in the pixel shader. Sum the two results. Often combined with spherical harmonic lighting for the per-vertex lights.

2) Multipass: For each light, calculate lighting (and shadowing). Blend into framebuffer with ONE,ONE blend mode (additive blending).

If you do stencil shadows, you pretty much have to do one pass per light that casts shadows, so option 2) is often used.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement