Jump to content
  • Advertisement
Sign in to follow this  
quant

Multiple lights in a scene with vertex shaders

This topic is 5390 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

Whats the usual way of handling many lights in a vertex shader? I would like there to be a variable number of lights, not sure how to achieve this.

Share this post


Link to post
Share on other sites
Advertisement
To have a variable number of lights in a single shader you need dynamic flow control, which is a vs.3.0 feature (I think 2.0 only supports static flow control).

If you don't mind have more than 1 shader (and you'd better like this idea, as you don't have any choice ;) ), you can compile a variety of shaders, where you specify the number and type of lights at compile time... that just needs static flow control, OR the compiler can unroll the loop so it needs no special feature.

Another solution is to just support a maximum nummber of lights, and color the unused ones black. This is horrible, but it will work. It can work at a temporary solution until you're ready to tackle dealing with all the varieties of shaders you'll need.

Share this post


Link to post
Share on other sites
Quote:
Original post by quant
Whats the usual way of handling many lights in a vertex shader?

I would like there to be a variable number of lights, not sure how to achieve this.


You can use a static array in vs_2_0 and up, as long as the loop varies on the a uniform parameter (which I would expect for a # of lights). e.g.
uniform int numlights;

...

Color = 0;
for(int i = 0;i < numlights;i++)
{
Color = LightColor * dot(Normal, -LightDirection);
}


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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!