Archived

This topic is now archived and is closed to further replies.

ogracian

How to perform alpha test in DirectX

Recommended Posts

Hi, I am having troubles to setup my Direct 3D to perform alpha Test, so I really apreciate any help. I know how to render a poly using alpha blend but I am not sure how so setup alpha test, here is how I set up my alpha blend code: D3DTLVERTEX square1[4]; square1[0] = D3DTLVERTEX(D3DVECTOR(x1, y1, 0.0), 1.0, RGBA_MAKE(255, 255, 255, alpha), 0, 0, 0); square1[1] = D3DTLVERTEX(D3DVECTOR(x2, y1, 0.0), 1.0, RGBA_MAKE(255, 255, 255, alpha), 0, 1, 0); square1[2] = D3DTLVERTEX(D3DVECTOR(x1, y2, 0.0), 1.0, RGBA_MAKE(255, 255, 255, alpha), 0, 0, 1); square1[3] = D3DTLVERTEX(D3DVECTOR(x2, y2, 0.0), 1.0, RGBA_MAKE(255, 255, 255, alpha), 0, 1, 1); // // Set alphablending flag Screen->Get3DDevice()->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, true); Screen->Get3DDevice()->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA); Screen->Get3DDevice()->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA); Screen->Get3DDevice()->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); Screen->Get3DDevice()->SetTexture(0, m_lpDDS); if(SUCCEEDED(Screen->Get3DDevice()->BeginScene())) { Screen->Get3DDevice()->DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_TLVERTEX, square1, 4, 0); Screen->Get3DDevice()->SetTexture(0, NULL); Screen->Get3DDevice()->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, false); Screen->Get3DDevice()->EndScene(); } // // Turn Off alpha blending Screen->Get3DDevice()->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, false); So I really apreciate so much if any could tell me how to perform alpha test. Best Regards! Oscar

Share this post


Link to post
Share on other sites
// Enable alpha testing (skips pixels with less than a certain alpha.)
g_pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_ALPHAREF, 0x08 );
g_pd3dDevice->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL );

Share this post


Link to post
Share on other sites