Jump to content
  • Advertisement
Sign in to follow this  
BaSSraf

Blending multiple passes problem (alpha mask)

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

Hey all :) I'm having the following problem: (pseudo loop) (1) As a mask, I render some quads with a texture having transparent sections using shader X (2) Now I again render these quads but now with full opaque textures using shader Y But whatever I try (blend modes etc) they dont blend as they should. The result I want would be the shape of the mask with the texture of pass 2. In other words, I want to be able to add many passes, but keep the shape of pass 1 (the mask). The result I get now (at best) makes me think that the render target blending doesnt actually use the target alpha, because when I use: Device->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_DESTALPHA ); Device->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ZERO ); The result is just the textured quads from pass 2... Any ideas on how to solve this?

Share this post


Link to post
Share on other sites
Advertisement
Given you mention you're using two different shaders, you're effectively looking for a way to "communicate" between them - such that Shader Y modifies its results based on whatever Shader X spat out. Correct?

Without any more details, I'm not sure exactly how you could do it using the fixed function pipeline (if that is at all possible), but one idea you might want to consider is stencil buffering.

If you can get the first pass, your mask, to write a "0" or "1" to the stencil buffer as appropriate, you should be able to set up the second pass to have its pixels eliminated based on a simple stencil test.

hth
Jack

Share this post


Link to post
Share on other sites
Quote:
Original post by jollyjeffers
Given you mention you're using two different shaders, you're effectively looking for a way to "communicate" between them - such that Shader Y modifies its results based on whatever Shader X spat out. Correct?


Yes completely correct :)

Quote:

Without any more details, I'm not sure exactly how you could do it using the fixed function pipeline (if that is at all possible)


I'm using a z-test "equal" for writing the 2nd\3rd etc layers, so all transforms need to be FF or Shader based anyway to avoid Z-fighting.. :(

Quote:

, but one idea you might want to consider is stencil buffering.
If you can get the first pass, your mask, to write a "0" or "1" to the stencil buffer as appropriate, you should be able to set up the second pass to have its pixels eliminated based on a simple stencil test.
hth
Jack


I thought of that, but the first layer (which should effectively be the mask) is anti-aliased (pre rendered) so I cant simply reject them I actually have to blend the color of the 2nd layer with the anti-aliased edges as well - is there a way to use the stencil values for doing blending in the pixelshader or whatever? (or maybe some other method you now know off :))

Thanks :)

Share this post


Link to post
Share on other sites
Btw, i've looked at dynamic shader fragment linking.. and of course building 1 big shader would work, but I want the user to be able to add shaders to materials themselves (as newly blended layers) so if I dont combine them in multiple passes i'll be out of VS/PS instructions in no time.. (damn its a shame rendertarget blending doesnt blend as expected..)

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!