解释预乘alpha的工作原理 [英] Explain how premultiplied alpha works

查看:777
本文介绍了解释预乘alpha的工作原理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释一下为什么从数学上讲,相同的预乘alpha(以及校正后的混合功能)渲染与正常" alpha看上去不同吗?

Can somebody please explain why rendering with premultiplied alpha (and corrected blending function) looks differently than "normal" alpha when, mathematically speaking, those are the same?

我已经研究了这篇文章,以了解预乘alpha:

I've looked into this post for understanding of premultiplied alpha:

http://blogs.msdn. com/b/shawnhar/archive/2009/11/06/premultiplied-alpha.aspx

作者还说结束计算是相同的:

The author also said that the end computation is the same:

查看常规与预乘alpha的混合方程式.如果将此颜色格式转换替换为预乘混合函数,则将获得常规混合函数,因此两种方法都会产生相同的最终结果.区别在于预乘alpha将(source.rgb * source.a)计算作为预处理而不是在混合硬件内部进行."

"Look at the blend equations for conventional vs. premultiplied alpha. If you substitute this color format conversion into the premultiplied blend function, you get the conventional blend function, so either way produces the same end result. The difference is that premultiplied alpha applies the (source.rgb * source.a) computation as a preprocess rather than inside the blending hardware."

我错过了什么吗?为什么结果不同呢?

Am I missing something? Why is the result different then?

neshone

推荐答案

这是一个猜测,因为目前还没有足够的信息可以解决这个问题.

This is a guess, because there is not enough information yet to figure it out.

应该相同.一种获得不同值的常见方法是在预乘和渲染步骤之间使用不同的Gamma校正方法.

It should be the same. One common way of getting a different value is to use a different Gamma correction method between the premultiply and the rendering step.

我猜测您的其中一个阶段(混合阶段或预乘阶段)是使用不同的伽玛值完成的.如果使用DirectXTex texconv之类的工具生成预乘纹理,并使用默认的srgb选项预乘alpha,则采样器必须为_SRGB格式,并且渲染目标也应为_SRGB.如果您以线性方式处理它们,则即使您在与采样相同的着色器中进行预乘(取决于3D API和渲染目标设置的差异),也可能无法渲染到_SRGB目标或使用伽玛校正对纹理进行采样. .这样做会使两种方法的中间音之间的alpha值显着不同.

I am going to guess that one of your stages, either the blending, or the premultiplying stage is being done with a different gamma value. If you generate your premultiplied textures with a tool like DirectXTex texconv and use the default srgb option for premultiplying alpha, then your sampler needs to be an _SRGB format and your render target should be _SRGB as well. If you are treating them linearly then you may not be able to render to an _SRGB target or sample the texture with gamma correction, even if you are doing the premultiply in the same shader that samples (depending on 3D API and render target setup differences). Doing so will cause the alpha to be significantly different between the two methods in the midtones.

请参阅:线性的重要性.

如果要在Photoshop中生成Alpha,则应该了解几件事. Photoshop不会以线性或sRGB格式保存Alpha.它将其保存为Gamma值,介于线性和sRGB之间.如果在Photoshop中进行预乘,它将正确计算预乘,但以错误的斜率保存结果.如果您生成普通的alpha,然后在3d API中将其作为sRGB或LINEAR进行采样,则它将很接近,但在任何情况下都不与Photoshop显示的值匹配.

If you are generating the alpha in Photoshop then you should know a couple things. Photoshop does not save alpha in linear OR sRGB format. It saves it as a Gamma value about half way between linear and sRGB. If you premultiply in Photoshop it will compute the premultiply correctly but save the result with the wrong ramp. If you generate a normal alpha then sample it as sRGB or LINEAR in your 3d API it will be close but will not match the values Photoshop shows in either case.

对于更深入的答复,我们将需要的信息是.

For a more in depth reply the information we would need would be.

  • 您正在使用什么3d API.
  • 如何生成和采样纹理
  • 您何时以及如何对Alpha进行预乘.
  • 最好是显示错误的代码或着色器示例.

这篇关于解释预乘alpha的工作原理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆