Sign in to follow this  
ClementLuminy

Multiple light Solutions ....

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 !

Share this post


Link to post
Share on other sites
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.

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