Using multiple passes with HLSL?

Started by
3 comments, last by Namethatnobodyelsetook 18 years, 8 months ago
I'm trying to do multiple passes with a lighting shader (for more than 1 light). Thing is it "starts over" for each pass and you only see the lighting effects of the last pass's light. How do you combine the effects of all the passes? I'd rather do this than use a loop inside the shader - or is this less efficent?
Advertisement
You'll probably want to make sure your blend state is set to something like SRCBLEND=ONE, DESTBLEND=ONE, ALPHABLENDENABLE=TRUE.

xyzzy
Also, be sure you're setting the following render state:

m_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_CURRENT);
m_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);

The second one can be set to the diffuse color, or the texture color, but at least one of them should be the current color of the vertex.

I've just started using DX's ASM shaders, so I'm not sure if the API passes over the stage state calls, but I hope this helps.
Quote:Original post by Mr Kickass
How do you combine the effects of all the passes?

Can't you just add them together on each iteration of the loop? I'm pretty sure that's how the book I was reading did it. Typically the contribution of lighting is additive, so a simple summation should yield correct results.

Quote:Original post by Mr Kickass
I'd rather do this than use a loop inside the shader - or is this less efficent?

From everything I've read and experimented with it is a better idea. However it's not always a good idea. More lights in a single pass mean that you only submit geometry once and only process each vertex once (in theory) and you can benefit from less state changing as well... However, you'll end up with a much longer shader - which may offset some of the performance gained in other areas, and it's quite possible you'll go beyond the limits of some low-end shader profiles. As with most things, it's a trade off [smile]

hth
Jack

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

Quote:Original post by tjsmith
The second one can be set to the diffuse color, or the texture color, but at least one of them should be the current color of the vertex.

The vertex has no current color in stage0. Specifying CURRENT on stage0 gets translated into DIFFUSE. If you do a modulate, which is pretty much standard, your method translates to DIFFUSE*DIFFUSE. When not using a texture, you should change the texture operation to SELECTARGn, where n is the argument set to diffuse. Even if you like the look of your color being squared, it's not going to match your textured objects.

This topic is closed to new replies.

Advertisement