Jump to content
  • Advertisement
Sign in to follow this  
Damocles

[DX9] rendering to alpha channel of surface

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

Is it possible to render directly to the alpha channel of a render surface? Preferably while also rendering to the color channels. I know one option is to make a second surface and render to that using multiple render targets, but this has the drawback of consuming extra texture memory for the second surface, and I'm also not sure how good the support is for MRTs on older hardware (I'm aiming for as low a HW requirement as possible). I am however targeting shader model 2 as the base platform, so if someone knows for certain that every SM2 card supports MRTs then I'll probably end up doing that. However, it would be nice if there is a way to simply render directly to the alpha channel of a surface. Anyone know how?

Share this post


Link to post
Share on other sites
Advertisement
of course you can render directly into your alpha channel
and you can view that channel in PIX

Share this post


Link to post
Share on other sites
Quote:
of course you can render directly into your alpha channel


Okay, good to know. So the next question would be - what D3D9 methods are used to tell the renderer to draw into the alpha channel?

Share this post


Link to post
Share on other sites
By default you will always be rendering to the alpha channel as long as your render target has one. If alpha-blending is disabled, then whatever value your pixel shader outputs for the alpha channel will be directly written to the render target's alpha channel. If blending is enabled, the value will depend on the previous alpha channel value contained in the render target as well as your ALPHASRCBLEND and ALPHADESTBLEND render states (by default they will be added).

If you only want to render to just the alpha channel, you can use the COLORWRITEENABLE render state to specify which channels should be written to.

Share this post


Link to post
Share on other sites
Thanks MJP, that clears it up. I had thought that when alpha blending was off, the alpha component of the render data was ignored, not written to the alpha channel. Which is why I couldn't find anything on writing to the channel, because it's the default behaviour :)

Share this post


Link to post
Share on other sites
Hmm... the results have not been what I was expecting...

I'm trying to get to a point where I could render a 50% opaque texture onto the surface twice, in the same position, and the alpha on the surface would then become 100% opaque, because the two 50% channels get added together.

I initially thought that setting:

d3d->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_ADD);

would work, but the alpha channels seem modulated rather than added. Drawing two 50% opaque textures results in a roughly 85% opaque surface. I've spent the last few hours trying all the different combinations of alpha and blend ops I can think of, but nothing seems to work the way I'd like it to.

Anyone know which settings are needed to work as I need? (ie adding two 50% opaque pixels gives a 100% opaque pixel)

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!