Advertisement

Alpha channel in vertex structure DX9

Started by February 04, 2024 07:00 PM
2 comments, last by Juliean 10 months, 3 weeks ago
m_pD3DDevice->SetRenderState( D3DRS_COLORVERTEX, TRUE );

	m_pD3DDevice->SetRenderState( D3DRS_DIFFUSEMATERIALSOURCE,  
                                D3DMCS_COLOR1 );

	m_pD3DDevice->SetRenderState( D3DRS_DIFFUSEMATERIALSOURCE,  
                                D3DMCS_COLOR2 );


	m_pD3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE);

	m_pD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	m_pD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
struct D3DVERTEX
{
	D3DXVECTOR3 p;
	D3DXVECTOR3 n;
	D3DCOLOR diffuse;
	D3DCOLOR	specular;
	float tu, tv;
};

I did lock vertex buffer (DirectX 9) and trying use alpha channel in vertex (set to zero):

	((D3DVERTEX*)pSrc)[i].diffuse = D3DCOLOR_ARGB(0, 255, 255, 255);
		
	((D3DVERTEX*)pSrc)[i].specular = D3DCOLOR_ARGB(0, r, g, b);

I set the alpha channel to zero, but it doesn't affect the final image. What is the matter?

Maybe i am wrong in this, because this was very long time ago. But "alpha blending" is for fixed function only. If you use shaders, you have to do the blending calculations by yourself, programming it manually in your shader.

If you are not using shaders, try adding these as well (after alphablendenable)

g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);

g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);

g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE);

Advertisement

Geri said:
Maybe i am wrong in this, because this was very long time ago. But "alpha blending" is for fixed function only. If you use shaders, you have to do the blending calculations by yourself, programming it manually in your shader.

Not quite. Even with shaders, you still have to configure that alpha-blending state of the device. Shaders allow you to calculate and output an alpha value, but how it's blended is up to the GPU. At least up until, including, DirectX11. Can't talk about DX12 or later.

Can't really comment on the rest. I'm pretty sure he is actually using fixed-function, at least D3DRS_DIFFUSEMATERIALSOURCE and D3DRS_COLORVERTEX make no sense with shaders. Probably something to do with fixed-function commands missing, similar to what you shown.

This topic is closed to new replies.

Advertisement