类似 Photoshop 的“变亮”问题片段着色器
我在 OpenGL 中标记它是因为我认为它与该空间相关(尽管命名不同)。
我正在尝试在使用 OpenGL (ES2?) 的 Flash 11 中实现类似 Photoshop 的混合功能。我在变亮方面遇到了特殊问题,我认为应该是:
outputColor.rgb = max(base.rgb, Blend.rgb);
我相信我遇到了问题,因为我的图层具有透明度。然而,即使当我预乘图层时,我仍然遇到问题(图像仍然太暗)。
我在这里错过了一步吗? (这是AGAL,Adobe的gl程序集)
[Shader.Fragment]
tex ft0, v0, fs0 <2d,nearest,nomip,clamp>
tex ft1, v0, fs1 <2d,nearest,nomip,clamp>
// premultiply
mul ft2, ft1.xyzw, ft1.wwww
// premultiplied values
max oc, ft0, ft2
I'm tagging this in OpenGL because I think it's relevant to that space (albeit a different naming).
I'm trying to get photoshop-like blending to work in Flash 11 which uses OpenGL (ES2?). I'm having particular issues with lighten, which I believe should be:
outputColor.rgb = max(base.rgb, blend.rgb);
I believe I am having issues because my layers have transparency. However, even when I pre-multiply my layers, I still am having issues (the image is too dark still).
Am I missing a step here? (This is AGAL, Adobe's gl assembly)
[Shader.Fragment]
tex ft0, v0, fs0 <2d,nearest,nomip,clamp>
tex ft1, v0, fs1 <2d,nearest,nomip,clamp>
// premultiply
mul ft2, ft1.xyzw, ft1.wwww
// premultiplied values
max oc, ft0, ft2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请注意,您还乘以 alpha 本身。
因此,您输出的是( ra, ga, ba, aa ),而不是( ra, ga, ba, a ),如果与黑色背景混合,这将导致图像变暗
您可以尝试这样做:
Pay attention, you are also multiplying alpha by itself.
So instead of having ( r.a, g.a, b.a, a ), you are outputting ( r.a, g.a, b.a, a.a ), which will lead to darker image if blended with a black background
You may try doing this :
正如crazyjul提到的,你必须从alpha预乘的颜色值中恢复原始颜色值。我相信以下代码应该有效:
行
max ft0, ft0, fc0
和max ft1, ft1, fc0
是避免除以零 alpha 值所必需的。您可以设置fc0
常量来包含诸如0,0,0,0.001
之类的内容。另请注意,我们使用第二层 (
ft1
) 的 alpha 作为结果 alpha。我不知道是否正确。As crazyjul mentioned, you have to restore original color values from alpha-premultiplied ones. I believe that the following code should work:
Lines
max ft0, ft0, fc0
andmax ft1, ft1, fc0
are necessary to avoid divizion by zero alpha value. You can setfc0
constant to contain smth like0,0,0,0.001
.Also note that we use alpha of the second layer (
ft1
) as the resulting alpha. I don't know whether it is correct.