Skip to main content
GameDev.net gamedev.net
🔒 Locked

Alpha blending problem(with picture)

Started by malyskolacek Nov 30, 2001 at 12:23 PM 1 replies 150+ views
Original Post
malyskolacek
malyskolacek
Here I have a problem: This problem occurs when a tree is behind an other, and not always. Here's some code I do for alpha blending: m_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); m_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); m_pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); m_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); m_pd3dDevice->SetRenderState(D3DRS_ALPHAREF, 0x08); m_pd3dDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); I don't know what to do with it... Edited by - malyskolacek on November 30, 2001 1:27:05 PM
nPawn
nPawn
My guess would be that you are drawing the tree, alpha blended with the blue background (since you haven''t drawn the other tree yet), then you draw the next tree behind that tree. To overcome this you need to draw trees in the back first to make sure the tree in front of it gets blended with it and not just the blank blue background. Just a guess as i''ve had a similar problem, and when i drew stuff in the back first it started blending better.
JimH
JimH
I''m not exactly sure, but let me take a wild guess at what''s happening. Perhaps the alpha values surrounding the branches are not zero. So when you draw the first tree, the area surrounding the branch is blended and becomes mostly blue and then the z-buffer is updated to indicate that these blue pixels are as near as the tree branch. Then when you draw the other tree further away, it is behind those blue pixels.

If that''s the case, maybe you need to have the tree''s alpha channel be defined more like a stencil with only completely black or white values. Otherwise, as nPawn said, draw back to front.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.