编辑:问题已经解决,请参考文章结尾。
如何在DirectX 8中实现Photoshop中的“屏幕”混合模式?
我在这个主题上找到的信息(http://www.ziggyware.com/readarticle.php?article_id=228):
Result = 1 – (1 – destination) * (1 – source) Result = 1 – (1 – source – destination + destination * source) Result = 1 – 1 + source + destination – destination * source Result = source + destination – destination * source Result = destination + source – source * destination Result = destination + source * (1 – destination)
Now that we have the math worked out, we simply have to set the blend modes:
BlendOperation = Add DestinationBlend = One SourceBlend = InvDestColor
我认为DirectX混合状态必须是:
pD3DDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
pD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
pD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_INVDESTCOLOR);
这正确吗?(我的结果不对)
Photoshop 结果:
http://img192.imageshack.us/img192/7015/photoshopf.jpg
DirectX 中我的结果:
http://img193.imageshack.us/img193/2969/directx.jpg
解决问题: 公式没有考虑图像的 alpha 通道,要修复它,您需要将图像背景设置为纯黑色,并将不透明度设置为 100%。