Jump to content
  • Advertisement
Sign in to follow this  
ClementLuminy

Multiple light Solutions ....

This topic is 4488 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!