[DX9] rendering to alpha channel of surface

Started by
4 comments, last by Damocles 14 years, 11 months ago
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?
------------------------------------------[New Delta Games] | [Sliders]
Advertisement
of course you can render directly into your alpha channel
and you can view that channel in PIX
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?
------------------------------------------[New Delta Games] | [Sliders]
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.
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 :)
------------------------------------------[New Delta Games] | [Sliders]
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)
------------------------------------------[New Delta Games] | [Sliders]

This topic is closed to new replies.

Advertisement