Jump to content

  • Log In with Google      Sign In   
  • Create Account


Dealing with multiple lights in the shader?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 KaiserJohan   Members   -  Reputation: 1080

Like
0Likes
Like

Posted 20 March 2013 - 04:14 AM

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? 



Sponsor:

#2 C0lumbo   Crossbones+   -  Reputation: 2149

Like
0Likes
Like

Posted 20 March 2013 - 11:49 AM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS