DirectX9中的Alpha混合问题 [英] Alpha Blending problems in DirectX9
问题描述
我非常渴望在DirectX中获得所需的alpha混合结果.我尝试绘制纹理,并在其上绘制彩色三角形条.
I am quite desperate to achieve desired alpha blending results in DirectX. I am try to draw texture, and on it a color triangle strip.
尽管进行了所有尝试,但试条的颜色似乎受之前绘制的纹理的颜色影响.即使将D3DRS_ALPHABLENDENABLE设置为FALSE,我仍然看到受影响的颜色.
Despite all my attempts it seems that color of the strip is affected by the color of the texture drawn before. Even if I set D3DRS_ALPHABLENDENABLE to FALSE, I still see the color affected.
这是图像的外观(使用openGL渲染)
Here is how the image suppose to looks like (Rendered with openGL)
这是我使用DirectX渲染所得到的:
And here is what I get with directX rendering:
如您所见,第二个图像紫色带具有黄色阴影,没有任何特定原因:((黄色矩形是纹理,而不是多边形).
As you can see, the second image purple strip has yellow shade without any specific reason :( (The yellow rectangle is a texture, not a polygon).
这是我在引擎初始化中使用的设置:
Here is the setting I use in Engine initialization:
m_pDirect3D_Device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
m_pDirect3D_Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
m_pDirect3D_Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
m_pDirect3D_Device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_BLENDDIFFUSEALPHA);
m_pDirect3D_Device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
m_pDirect3D_Device->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
这些设置是唯一可以使我正确进行纹理Alpha混合的设置,但是我绝不能实现多边形的正确混合.有帮助吗?
Those settings are the only settings that gave me correct Alpha Blending of textures, but I can in no way achieve correct blending of polygons. Any Help?
推荐答案
我最终知道了.除了Alpha Blending外,还有Color Blending.因此DirectX将最后一个纹理的颜色与最后一个图元合并.为了解决这个问题,我们需要设置:
I figured it out eventually. In addition to Alpha Blending there is a Color Blending. So DirectX merges color of the last texture with the last primitive. In order to solve it we need to set:
m_pDirect3D_Device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTSS_COLORARG1);
m_pDirect3D_Device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
在绘制图元之前-表示仅从图元(漫反射)中获取颜色,并且:
before drawing the primitives - meaning only take color from primitive (Diffuse), and:
m_pDirect3D_Device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTSS_COLORARG1);
m_pDirect3D_Device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
在绘制纹理之前-表示仅使用纹理颜色.
before drawing the texture - meaning only use texture colors.
这篇关于DirectX9中的Alpha混合问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!