Jump to content

  • Log In with Google      Sign In   
  • Create Account

Selecting passes for lighting system


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
2 replies to this topic

#1 3DModelerMan   Members   -  Reputation: 1068

Like
0Likes
Like

Posted 20 August 2014 - 06:21 PM

So I've finally got all my shaders and blending figured out, and it's time to decide where the heck I'm actually going to do each part of my lighting calculations. I have a temporary system setup right now, where I render the single pass materials first, and for materials that use lighting, I simply render the ambient color in this pass. Then I render my forward lighting passes with additive blending in the next stage. What I'm having trouble deciding though, is what to break up into which passes.

 

I always see examples calculating ambient light in the same shader that forward lighting is calculated in, but that results in the unlit parts of the object being far too bright when more than one light is shining on the object. Is it a good idea to be drawing plain ambient color to the screen in the first pass and blending over that?

 

And for the lighting shaders, I currently have a seperate shader for rendering each kind of light. A shader for rendering a directional light, and a shader for rendering up to 8 point, or spot lights at once. Is there the potential to gain performance by just sending as many lights at once as possible, and then using branching in the shader to determine how to render them?

 

I don't need any concrete answers really, because obviously the "best" approach depends on the kind of scene I plan to render, but I'd at least like to get an idea of exactly what work is usually divided among which passes.



Sponsor:

#2 L. Spiro   Crossbones+   -  Reputation: 14262

Like
5Likes
Like

Posted 20 August 2014 - 07:30 PM

I always see examples calculating ambient light in the same shader that forward lighting is calculated in, but that results in the unlit parts of the object being far too bright when more than one light is shining on the object.

Disable or set to 0 ambient on any passes except the first.
Include as many lights as possible into a single pass.
 

Is it a good idea to be drawing plain ambient color to the screen in the first pass and blending over that?

Multiple passes are only necessary when using shadow maps (and some rare edge cases that likely don’t apply to you), and even when using shadow maps you can still include, in the first pass, ambient light, the first shadow-mapped light, and all lights that do not cast a shadow.
In other words, there is almost no reason for an ambient-only pass.

 

Is there the potential to gain performance by just sending as many lights at once as possible

Of course there is. Never submit geometry more often than you must.

 

and then using branching in the shader to determine how to render them?

No.
Use branchless for loops that render directional lights, then point lights, then spot lights, then whatever lights. The order doesn’t matter, just draw each type of light together without branching.


L. Spiro


Edited by L. Spiro, 20 August 2014 - 08:14 PM.

It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#3 3DModelerMan   Members   -  Reputation: 1068

Like
0Likes
Like

Posted 20 August 2014 - 08:17 PM

Okay. Thanks. I'll probably try and limit my passes and pass all the lights at once that way... I never noticed your blog before, there's some pretty good stuff on there for graphics engines that would probably be useful for me to read.






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