Jump to content
  • Advertisement
Sign in to follow this  
SiS-Shadowman

Multiple lights with Multipass

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

I'm trying to render a scene with multiple lights, and I wanted to do try this with a multipass approach before I try to rewrite the shader to use only a single pass. But I don't know how I need to setup the render states to render the scene. How can I define that each pass adds it's pixel's color to the previous one, not just overwrite it. My secon question is how I can get the best performance when using multiple passes. My approach is to render each object once for the first light and the ambient light. This pass needs to enable the zbuffer and to enable z-writing. Each additional pass for another light only needs to enable the zbuffer, but can disbale z-writing, since the zbuffer is filled with the zdata from the first pass. Is that approach usefull? Is there anything else I can do to speed things up?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
But I don't know how I need to setup the render states to render the scene.
How can I define that each pass adds it's pixel's color to the previous one, not just overwrite it.
You can put fixed-function style SetRenderState() calls within a pass{} block. So, for example you might have:

pass
{
AlphaBlendEnable = TRUE;
SrcBlend = ONE;
DestBlend = ONE;

PixelShader = /* ... */
}


You can do the same for z-write and z-read states.

The main exception, which is mostly annoying for post processing I find, is that you can't toggle render targets (etc..) using this syntax. You have to annotate the pass or technique and have your application handle it.

Quote:
Is that approach usefull? Is there anything else I can do to speed things up?
Combining Z-Fill and Ambient into one pass is a good idea and usually enough of an optimization.

There's only so much you can do with the "multiple-lights vs multiple-passes" architecture before you really want to look into things like deferred shading instead.

hth
Jack

Share this post


Link to post
Share on other sites
Thanks very much. I got it working :)

But there's one thing I'm not shure with. Normally, I only use one pass, thats why I just call SetStreamSource, SetFVF and SetIndices along with DrawIndexedPrimitive (or just DrawPrimitive) together. But with multiple passes, wich use the same VB and IB, would it be better to call the functions above once and not every pass? I'm not shure if this makes any (performance related) difference, so I'll just ask

Share this post


Link to post
Share on other sites
Your code will look cleaner by moving calls to where they really should be, but whether it'll improve performance much is debateable. On paper it should, but most decent drivers will do some basic redundant call filtering so the real cost is just the overhead of calling into the API/Driver which may or may not be an issue...

It's a trivial change so you might as well.

Jack

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!