Sign in to follow this  
Guthur

ID3DX10Sprite - Sprite on sprite transparency blending issue

Recommended Posts

I am wanting to make use of ID3DX10Sprite for a 2D GUI over a 3D scene. I set up the blend state of the the Output Merger (fig 1) and my sprite render code (fig 2). This gives me transparency with sprite on 3D scene. The problem is i don't have sprite on sprite transparency instead its as if nothing is there and it draws the 3D scene below instead of the other sprite. I was thinking that it might be something to do with blend sources and that previously drawn sprites are maybe not present at the blending stage. Thanks, fig 1
int CDXGraphics::CreateSpriteBlenderState()
{
    D3D10_BLEND_DESC bd;
    ZeroMemory(&bd, sizeof(D3D10_BLEND_DESC));
    bd.AlphaToCoverageEnable = FALSE;
    bd.BlendEnable[0] = TRUE;
    bd.BlendEnable[1] = TRUE;
    bd.SrcBlend = D3D10_BLEND_SRC_ALPHA;
    bd.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
    bd.BlendOp = D3D10_BLEND_OP_ADD;
    bd.SrcBlendAlpha = D3D10_BLEND_ZERO;
    bd.DestBlendAlpha = D3D10_BLEND_ZERO;
    bd.BlendOpAlpha = D3D10_BLEND_OP_ADD;
    bd.RenderTargetWriteMask[0] = 0xf;

    this->m_pD3dDevice->CreateBlendState(&bd, &m_SpriteAlphaOnBlenderState);
    return 0;
}


fig 2
int CDXGraphics::Render(vector<Sprite2D*> sprites)
{
HRESULT hr = 0;
size_t spriteCount = sprites.size();
int spriteIndex = 0;
D3DX10_SPRITE* ptrSprites = new D3DX10_SPRITE[spriteCount];
vector<Sprite2D*>::iterator iterSprites = sprites.begin();

float fCurrentBlendFactor[4];
unsigned int iCurrentSampleMask = 0;
ID3D10BlendState* pCurrentBS = NULL;
this->m_pD3dDevice->OMGetBlendState(&pCurrentBS, fCurrentBlendFactor, &iCurrentSampleMask);
this->m_pD3dDevice->OMSetBlendState(m_SpriteAlphaOnBlenderState, 0, 0xffffffff);

for(iterSprites; iterSprites < sprites.end(); ++iterSprites)
{
    ptrSprites[spriteIndex] = ((Sprite2D*)*iterSprites)->m_d3d10Sprite;
    spriteIndex++;
}

m_pSpriteDevice->Begin(D3DX10_SPRITE_SAVE_STATE);
hr = m_pSpriteDevice->DrawSpritesImmediate(ptrSprites, spriteIndex, 0, 0);
m_pSpriteDevice->End();

this->m_pD3dDevice->OMSetBlendState(pCurrentBS, fCurrentBlendFactor, iCurrentSampleMask);
delete[spriteCount] ptrSprites;
return hr;
}


Share this post


Link to post
Share on other sites
Sorted (hhh slight pun)...

It was the depth stencil buffer causing it. Not sure yet exactly why just know it works when its not setup.

The reason i looked was because the sprites were actually being drawn in the wrong order which seemed odd and I thought somehow sprite depth might be messing up the alpha test.

Should be able to work it out now, i may just remove it for sprite drawing if i can.

Share this post


Link to post
Share on other sites
If anyone is interested it was down to the fact i used a 2D transformation function which of course left all the sprites the same distance from the camera in 3D space, doh.

I'll just need to add a little depth to my sprite layers :p

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this