Multiple lights with Multipass

Started by
3 comments, last by SiS-Shadowman 16 years, 6 months ago
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?
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

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
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Changing it wasn't much of a problem, I'm just a perfectionist, that's why I wanted to know *g.
Thanks for helping me again.

This topic is closed to new replies.

Advertisement