Jump to content
  • Advertisement
Sign in to follow this  
Mr Kickass

Using multiple passes with HLSL?

This topic is 4842 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 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?

Share this post


Link to post
Share on other sites
Advertisement
You'll probably want to make sure your blend state is set to something like SRCBLEND=ONE, DESTBLEND=ONE, ALPHABLENDENABLE=TRUE.

xyzzy

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!