Photoshop 的“屏幕” DirectX 中的模式
编辑:问题解决了! 见帖子末尾。
如何在 DirectX 8 中实现 Photoshop 的“屏幕”混合模式?
信息,我发现了这个主题(http://www.ziggyware.com/ readarticle.php?article_id=228):
结果 = 1 – (1 – 目的地) * (1 – 源) 结果 = 1 – (1 – 源 – 目的地 + 目的地 * 源) 结果 = 1 – 1 + 源 + 目的地 – 目的地 * 源 结果 = 源 + 目的地 – 目的地 * 源 结果 = 目标 + 源 – 源 * 目标 结果 = 目的地 + 源 * (1 – 目的地)
现在我们已经算出了数学结果, 我们只需设置混合模式:
BlendOperation = 添加 目的地混合=一 源混合 = 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%
Edit: Problem solved! See end of post.
How to implement "Screen" blending mode from Photoshop in DirectX 8?
Info, i've found on this topic (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
I assume DirectX blending states must be:
pD3DDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
pD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
pD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_INVDESTCOLOR);
Is it correct? (I have a wrong result)
Photoshop result:
http://img192.imageshack.us/img192/7015/photoshopf.jpg
My result in DirectX:
http://img193.imageshack.us/img193/2969/directx.jpg
Problem solving:
formula doesn't consider image alpha, to fix it you need to make image background solid black with 100% opacity
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下行是错误的:
您的意图可能是声明 alpha 混合器应该执行 ADD,但是 D3DTSS_COLOROP 设置不会影响最终的混合器,而是设置纹理组合器。 您将其设置为向从纹理采样的颜色中添加某些内容(上一个/下一个阶段的结果或类似的内容),这是错误的。 D3DTOP_SELECTARG1 或默认的 D3DTOP_MODULATE 应该可以完成这项工作。
你需要写的是:
Following line is wrong:
Your intention is probably to state alpha blender should do ADD, but the D3DTSS_COLOROP setting does not affect final blender, it sets texture combiner instead. You set it to add something (result of previous/following stage, or something like that) to the color you sample from the texture, which is wrong. D3DTOP_SELECTARG1 or default D3DTOP_MODULATE should do the job.
What you need to write instead is:
数学似乎是正确的,并且您设置 DirectX 函数的方式应该有效。
我的建议是:
检查您是否可以执行其他混合模式以及它们是否生成正确的输出。
The math seems correct, and the way you set the DirectX functions should work.
My advice is:
Check that you can do other blending modes and that they generate the correct output.