• Advertisement
Sign in to follow this  

Dealing with multiple lights in the shader?

This topic is 1768 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,

 

Right now I only deal with one light, a directional one (like described in http://www.arcsynthesis.org/gltut/Illumination/Tutorial%2009.html). I provide a Vec4 'lightIntensity' and Vec3 'directionToLight' to the vertex shader and proceed to apply lightning. Not very flexible and soon I want to add more lights and of different types aswell.

 

So my question is what is the best practice when dealing with multiple lights and of multiple lightning types? 

Share this post


Link to post
Share on other sites
Advertisement

Three common solutions:

 

1. Use deferred shading.

2. Compile permutations of your shader for each combination of light states (beware, you can end up with a huge number of shaders this way)

3. Use for-loops and if-branches in your shader to handle the various lighting states.

 

If you're targeting desktop hardware, then #1 is best but #3 is fine - you might read about branches being expensive but on any vaguely modern desktop hardware branching on a uniform is pretty cheap. If you're targeting mobile, I'd recommend #2 but you might have to take steps (i.e. make assumptions) to keep the permutation count down.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement