类似 Photoshop 的“变亮”问题片段着色器

发布于 2024-12-05 03:59:06 字数 509 浏览 0 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

此生挚爱伱 2024-12-12 03:59:06

请注意,您还乘以 alpha 本身。

因此,您输出的是( ra, ga, ba, aa ),而不是( ra, ga, ba, a ),如果与黑色背景混合,这将导致图像变暗

您可以尝试这样做:

// premultiply
mul ft2, ft1.xyzw, ft1.wwww
mov ft2.w, ft1.w

// premultiplied values
max oc, ft0, ft2

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 :

// premultiply
mul ft2, ft1.xyzw, ft1.wwww
mov ft2.w, ft1.w

// premultiplied values
max oc, ft0, ft2
半葬歌 2024-12-12 03:59:06

正如crazyjul提到的,你必须从alpha预乘的颜色值中恢复原始颜色值。我相信以下代码应该有效:

tex ft0, v0, fs0 <2d, nearest, nomip, clamp>
tex ft1, v0, fs1 <2d, nearest, nomip, clamp>

max ft0, ft0, fc0
div ft0.xyz, ft0.xyz, ft0.www // obtain original color 1

max ft1, ft1, fc0
div ft0.xyz, ft0.xyz, ft0.www // obtain original color 2

max ft1.xyz, ft0.xyz, ft1.xyz // lighten

mul ft1.xyz, ft1.xyz, ft1.www // pre-multiply output color with the second alpha
mov oc, ft1

max ft0, ft0, fc0max 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:

tex ft0, v0, fs0 <2d, nearest, nomip, clamp>
tex ft1, v0, fs1 <2d, nearest, nomip, clamp>

max ft0, ft0, fc0
div ft0.xyz, ft0.xyz, ft0.www // obtain original color 1

max ft1, ft1, fc0
div ft0.xyz, ft0.xyz, ft0.www // obtain original color 2

max ft1.xyz, ft0.xyz, ft1.xyz // lighten

mul ft1.xyz, ft1.xyz, ft1.www // pre-multiply output color with the second alpha
mov oc, ft1

Lines max ft0, ft0, fc0 and max ft1, ft1, fc0 are necessary to avoid divizion by zero alpha value. You can set fc0 constant to contain smth like 0,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文