Selecting passes for lighting system

Started by
1 comment, last by 3DModelerMan 9 years, 8 months ago

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.

Advertisement

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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

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.

This topic is closed to new replies.

Advertisement