抗锯齿算法?

发布于 2024-09-05 05:20:30 字数 69 浏览 2 评论 0原文

我正在创建纹理并希望对它们进行抗锯齿处理。我可以访问每个像素的颜色,鉴于此我如何对整个纹理进行抗锯齿?

谢谢

I have textures that i'm creating and would like to antialias them. I have access to each pixel's color, given this how could I antialias the entire texture?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

梦里南柯 2024-09-12 05:20:30

抱歉,真正的抗锯齿并不在于从邻居那里获取平均颜色,如上所述。毫无疑问,这会柔化边缘,但它不是抗锯齿而是模糊。真正的抗锯齿无法在位图上正确完成,因为必须在绘制时进行计算,以判断哪些像素和/或边缘必须“软化”,哪些不能。例如:假设您绘制一条水平线,其厚度必须恰好为 1 像素(称为“高”),并且必须恰好放置在整数屏幕行坐标上。显然,您希望它不被软化,并且适当的抗锯齿算法可以做到这一点,将您的线条绘制为完美的实心像素行,周围环绕着完美的背景色像素,根本没有色调混合。但是,如果您在绘制同一条线(即位图)后应用平均方法,则该线的上方和下方将会变得模糊,从而产生 3 像素厚的水平线,这不是目标。当然,一切都可以通过正确的编码来实现,但是采用非常不同且更加复杂的方法。

I'm sorry but true anti-aliasing does not consist in getting the average color from the neighbours as commented above. This will undoubtfully soften the edges but it's not anti-aliasing but blurring. True anti-aliasing just cannot be done properly on a bitmap, since it has to be calculated at drawing time to tell which pixels and/or edges must be "softened" and which ones must not. For instance: imagine you draw an horizontal line which must be exactly 1 pixel thick (say "high") and must be placed exactly on an integer screen row coordinate. Obviously, you'll want it unsoftened, and proper anti-aliasing algorithm will do it, drawing your line as a perfect row of solid pixels surrounded by perfect background-coloured pixels, with no tone blending at all. But if you take this same line once it's been drawn (i.e. bitmap) and apply the average method, you'll get blurring above and below the line, resulting a 3 pixels thick horizontal line, which is not the goal. Of course, everything could be achieved through the right coding but from a very different and much more complex approach.

桜花祭 2024-09-12 05:20:30

抗锯齿的基本方法是:对于一个像素P,对其周围的像素进行采样。 P的新颜色是其原始颜色与样本颜色的平均值。

您可以采样更多或更少的像素,更改要采样的像素周围区域的大小,或者随机选择要采样的像素。

不过,正如其他人所说:抗锯齿并不是真正对已经是像素位图的图像进行的处理。这是一种在 2D/3D 渲染引擎中实现的技术。

The basic method for anti-aliasing is: for a pixel P, sample the pixels around it. P's new color is the average of its original color with those of the samples.

You might sample more or less pixels, change the size of the area around the pixel to sample, or randomly choose which pixels to sample.

As others have said, though: anti-aliasing isn't really something that's done to an image that's already a bitmap of pixels. It's a technique that's implemented in the 2D/3D rendering engine.

感情洁癖 2024-09-12 05:20:30

“抗锯齿”可以指多种不同的技术。这些通常都不是您需要提前对纹理执行的操作。

也许你的意思是 mip 映射? http://en.wikipedia.org/wiki/Mipmap

"Anti-aliasing" can refer to a broad range of different techniques. None of those would typically be something that you would do in advance to a texture.

Maybe you mean mip-mapping? http://en.wikipedia.org/wiki/Mipmap

累赘 2024-09-12 05:20:30

用如此模糊的术语来询问抗锯齿并没有多大意义。这完全取决于纹理的性质以及它们的使用方式。

但一般来说,如果您无法控制显示环境,并且纹理可能会缩放、旋转或与您无法控制的其他元素合成,则应使用透明度来指示图像的结束位置和结束位置仅部分填充像素。

一般来说,避免尖锐的边缘和相对于可能完成的缩放量而言较小的特征也是好的。

It's not very meaningful to ask about antialiasing in terms this vague. It all depends on the nature of the textures and how they will be used.

Generally though, if you don't have control over the display environment and your textures might be scaled, rotated, or composited with other elements you don't have any control over, you should use transparency to indicate where your image ends and where it only partially fills a pixel.

It's also generally good to avoid sharp edges and features that are small relative to the amount of scaling that might be done.

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