Alpha Channel for TV mixing [Resolved]

Started by
3 comments, last by darrenmarklines 18 years ago
Hi, I'm using DirectX8.1 and creating a 32Bit backbuffer A8R8G8B8 format. I want to blend the RGB component with with a mixture of 32Bit colour info and the 32Bit textures' alpha component. so...

	m_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
	m_pD3DDevice->SetRenderState(D3DRS_SPECULARENABLE , FALSE );
	m_pD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	m_pD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
	m_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
	m_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
	m_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
	m_pD3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_DISABLE );

	m_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP,  D3DTOP_MODULATE  );
	m_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
	m_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
	m_pD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP,  D3DTOP_DISABLE );
my problem is that the RGB looks good, but the backbuffers' alpha is not blending as I want. I want the alpha to 'OR' with any other alpha that is rendered, thus if a primative is drawn with an alpha of .5 followed by a primative drawn with and alpha of .1 the backbuffer should have a result of .5, at the moment the backbuffer has a value of .1. Any ideas? [Edited by - darrenmarklines on March 20, 2006 7:56:54 AM]
Advertisement
Look into seperatealphablendenable, alphasrcblend, alphadestblend, and alphablendop.
i've realised the blendmode is the issue, could you elaborate?
I was just pointing out that on certain newer cards you can choose to blend color and alpha different, which is likely something you're going to want. You can emulate this on older cards by using colorwriteenable of RGB, drawing color, then colorwriteenable of A, setting a different blending mode, and drawing your alpha.

As for 'OR'ing the values, I'm not sure how you expect OR to work with float values. Your example is doing a MAX, which may be what you want, in which case you'll want this:

(alpha)blendop = d3dblend_max
(alpha)srcblend = d3dblend_one
(alpha)destblend = d3dblend_one

which will do finalalpha = max(1*newalpha, 1*backbufferalpha).

Check if your card supports seperatealphablendenable (d3dcaps.misccaps & D3DPMISCCAPS_SEPARATEALPHABLEND). If it does enable it, and setup your alpha extra alpha blend modes. If not, you'll need to render in two passes, doing color first, then alpha, and using D3DRS_COLORWRITEENABLE to choose which you're currently affecting.
Thanks for your help Namethatnobodyelsetook,

My solution, because of dx8.1, was to write the RGB and Alpha in seperate passes using D3DRS_COLORWRITEENABLE, then use an apropriate blend mode.

Darren

This topic is closed to new replies.

Advertisement