Antialiased backbuffer flickering in DX9

0

im trying to render transparent grey scene as a death indicator and im having a trouble with flickering only when multisampling is enabled! I tried to load texture from a file instead of having it raw like it is right now and i also tried different swap effects and different msaa types and none of it worked. I thought it might have been something with device clear but as i look at it everything should be fine. To be sure im checking if multisampling is supported and it actually is. I have no idea where problem could be :/ Every help would be gratefully appriciated :) Image illustrating the problem

    static PVERTEX vMESH[] = {
        { -0.5f, 0.0f,  0.5f, 0.0f, 0.0f},
        {  0.5f, 0.0f,  0.5f, 1.0f, 0.0f},
        { -0.5f, 0.0f, -0.5f, 0.0f, 1.0f},
        {  0.5f, 0.0f, -0.5f, 1.0f, 1.0f}};
    LPVOID pDATA = NULL;

    m_pDevice->CreateVertexBuffer(
        4 * sizeof(PVERTEX),
        0, T3DFVF_PVERTEX,
        D3DPOOL_MANAGED,
        &m_pBACKVB, NULL);

    D3DXCreateTexture(
        m_pDevice,
        pMODE->Width,
        pMODE->Height, 1,
        D3DUSAGE_RENDERTARGET,
        pMODE->Format,
        D3DPOOL_DEFAULT,
        &m_pBACKTEX);

    m_pBACKTEX->GetSurfaceLevel( 0, &m_pBACKBUF);
    m_pDevice->GetDepthStencilSurface(&m_pZBUF);
    m_pDevice->GetRenderTarget( 0, &m_pRTARGET);

    m_pBACKVB->Lock( 0, 0, &pDATA, 0);
    memcpy( pDATA, vMESH, 4 * sizeof(PVERTEX));
    m_pBACKVB->Unlock();

void CTClientGame::BeginGHOSTScene()
{
    m_pDevice->m_pDevice->SetRenderTarget( 0, m_pDevice->m_pBACKBUF);
    m_pDevice->m_pDevice->Clear(
        0, NULL,
        D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
        D3DCOLOR_ARGB( 0, 0, 0, 0),
        1.0f, 0);
}

void CTClientGame::EndGHOSTScene()
{
    DWORD dwALPHA = DWORD((DWORD(m_dwGHOSTTick * ALPHA_MAX / TGHOST_TICK) << 24) & 0xFF000000);

    CTClientCAM vCAMERA;
    D3DXMATRIX vWorld;

    m_pDevice->m_pDevice->SetRenderTarget( 0, m_pDevice->m_pRTARGET);
    m_pDevice->m_pDevice->Clear(
        0, NULL,
        D3DCLEAR_TARGET,
        D3DCOLOR_ARGB( 0xFF, 0x00, 0x00, 0x00),
        1.0f, 0);
    D3DXMatrixIdentity(&vWorld);

    vCAMERA.InitOrthoCamera(
        m_pDevice->m_pDevice,
        -1.0f,
        1.0f,
        1.0f,
        1.0f);

    vCAMERA.SetPosition(
        D3DXVECTOR3( 0.0f, 0.5f, 0.0f),
        D3DXVECTOR3( 0.0f, 0.0f, 0.0f),
        D3DXVECTOR3( 0.0f, 0.0f, 1.0f),
        FALSE);
    vCAMERA.Activate(TRUE);

    m_pDevice->m_pDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
    m_pDevice->m_pDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_DOTPRODUCT3);
    m_pDevice->m_pDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
    m_pDevice->m_pDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);

    m_pDevice->m_pDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
    m_pDevice->m_pDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
    m_pDevice->m_pDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE);

    m_pDevice->m_pDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
    m_pDevice->m_pDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);

    m_pDevice->m_pDevice->SetRenderState( D3DRS_TEXTUREFACTOR, 0x004C4C4C);
    m_pDevice->m_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE);
    m_pDevice->m_pDevice->SetRenderState( D3DRS_ALPHATESTENABLE, FALSE);
    m_pDevice->m_pDevice->SetRenderState( D3DRS_FOGENABLE, FALSE);

    m_pDevice->m_pDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE);
    m_pDevice->m_pDevice->SetRenderState( D3DRS_ZENABLE, FALSE);

    m_pDevice->m_pDevice->SetStreamSource( 0, m_pDevice->m_pBACKVB, 0, sizeof(PVERTEX));
    m_pDevice->m_pDevice->SetTexture( 0, m_pDevice->m_pBACKTEX);

    m_pDevice->m_pDevice->SetTransform( D3DTS_WORLD, &vWorld);
    m_pDevice->m_pDevice->SetFVF(T3DFVF_PVERTEX);
    m_pDevice->m_pDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2);

    m_pDevice->m_pDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG2);
    m_pDevice->m_pDevice->SetRenderState( D3DRS_BLENDOP, D3DBLENDOP_SUBTRACT);
    m_pDevice->m_pDevice->SetRenderState( D3DRS_TEXTUREFACTOR, 0xFFFFFFFF);
    m_pDevice->m_pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE);
    m_pDevice->m_pDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE);
    m_pDevice->m_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE);
    m_pDevice->m_pDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2);

    m_pDevice->m_pDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
    m_pDevice->m_pDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
    m_pDevice->m_pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR);

    m_pDevice->m_pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
    m_pDevice->m_pDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
    m_pDevice->m_pDevice->SetRenderState( D3DRS_BLENDOP, D3DBLENDOP_ADD);
    m_pDevice->m_pDevice->SetRenderState( D3DRS_TEXTUREFACTOR, dwALPHA);

    m_pDevice->m_pDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2);
    m_pCamera->Activate(TRUE);
}
c++
directx-9
asked on Stack Overflow Feb 26, 2020 by Agnares

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0