@mhagain: I'm having a problem with blending diffuse color with light using multipass, here is the Shader:
(I'm getting white meshes)
I don't see what's happening in your CalcLighting function, but you almost certainly don't want what I think you have.
The first thing is that the first pass isn't a diffuse pass, it's an ambient pass. This can be black (just output 0 from your PS) if you don't have any ambient light, but it's critically important to do it even if so as it's laying down a baseline for the additive passes. Alpha blending should be disabled, enable depth writing, do a standard depth test.
The second and subsequent passes are your additive passes. In order to understand how to do each of these, you first need to look at what a single pass/multiple light setup would look like:
output = ambient + diffuse * (light0 + light1 + light2 + light3); // assume 4 lights for the purpose of this example
Using some basic mathematics, let's break that into 5 passes, ambient plus 1 for each light, and we get:
output = ambient; // initial ambient pass - I've already covered this above
output += diffuse * light0; // first additive pass
output += diffuse * light1; // second additive pass
output += diffuse * light2; // third additive pass
output += diffuse * light3; // fourth additive pass
So each additive pass needs to sample the diffuse texture as well as calculate the lighting. The additive blend adds it to the result from the previous pass(es), enable depth testing but set the depth test to equal, disable depth writing, and you'll get the (mostly) correct result.
I put in "mostly" above because the one caveat is that if your lighting goes above 1.0 each pass will clamp, so it's not going to look 100% identical to a single pass/multiple light setup. You can of course draw to a floating point rendertarget if this is a problem for you, but I'd encourage experimentation before making that decision - it may be just fine as is.
If you want to use forward shading and lots of lights, you almost certainly want Forward+ shading (which a lot of AAA games are moving to).
The basic gist of the idea is to use a compute shader to bin all lights into the scene into a 2D grid indicating which parts of the screen they intersect with and then using the appropriate bin for all lighting calculating for a particular fragmnet. The binning is done by breaking the screen into a grid, generated a frustrum for each part of the grid, then doing an intersection test against each light volume and the frustrum for a particular grid location. If the light intersects, add it to that bin. More advanced versions of Forward+ deal with depth more intelligently.
It's a more advanced technique than either regular forward shading or deferred shading due to the use of compute shader, but it isn't that much more complex. It's all the same math you already have to do anyway (frustrum generation, intersection tests, etc.) just now it's in a computer shader instead of CPU code.
I suspect that the OP is using D3D9 (PS2.0 in the first post, SM3 in the effect file code).
Edited by mhagain, 14 June 2014 - 06:16 PM.