安卓。和引擎。使用透明度时的图像伪影
我正在使用 AndEngine(基于 OpenGL 的 2D 引擎)。当我使用透明纹理(PNG 图像)时,图像边框上出现图像伪影。我需要帮助解决这个问题。我附上了 2 张图片。首先,我只使用某种字体显示文本。在第二个上,您可以看到圆角,但在纹理的角上,您也可以看到伪影。请注意,这仅发生在真实设备上。在模拟器上一切正常。我的设备是运行 Android 2.1 的 Samsung i5700 Galaxy Spica
I am using AndEngine (2D OpenGL-based engine). When i use textures with transparency (PNG images) i have image artifacts on the borders on image. I need help fixing this. I have attached 2 images. On first i have just text displayed using some font. On the second you can see the rounded corner but on the corner of the texture you can see the artifact as well. Please note that this occurs only on REAL device. On emulator all is OK. My device is Samsung i5700 Galaxy Spica running Android 2.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
AndEngine Artifacts 大社区 Wiki
Sprite 伪像
双线性过滤会插入最近四个像素的颜色,这使得纹理在缩放/旋转或使用非整数值移动时效果很好,但有一些困难。
黑色或暗线伪影 纹理
图集背景可能是黑色,并且纹理区域的边缘像素与该背景混合。使用自定义透明纹理图集,或使用修改后的TextureAtlas构建器,该构建器会用透明度填充自身(TODO查找描述此问题的论坛链接)
Sprite边缘具有不需要的alpha
如果纹理背景是透明的,则alpha仍然会混合到边缘颜色中。
将 1 像素挤出添加到纹理区域(在边缘处的额外行/列中重复边缘像素),并将区域边缘定位在原始边缘像素和添加的边缘像素之间。这将确保双线性插值仅从您的区域中选取像素。
其他边缘伪影
如果纹理区域太近,则区域边缘可能会占用其他区域边缘的一些像素。在纹理区域之间使用填充。
文本伪影 基线
下方偶尔出现小垂直线 (GLES1)
在我的字体中,
J
字符具有过度向左延伸的下部曲线,这会在渲染I
字母,因为IJ
在纹理中彼此相邻,并且可能太近。尝试降低字体大小,增加纹理大小,或修改更大的
Font.PADDING
值(5
对我有用,而不是1
)。但请注意,默认情况下,增加PADDING
也会增加行间距,这可能是不需要的。可以在必要时引入和使用新的YPADDING
来进行补偿。消失的字母
字母按需渲染到字体纹理图集。这可能会导致纹理图集空间不足,从而产生有趣的效果(请参阅消失 ChangeableText)。
一种解决方案是将此代码段插入到
Font#createLetter(char)
方法中:Big Community Wiki of AndEngine Artifacts
Sprite artifacts
BILINEAR filtering interpolates the colour of the nearest four pixels, which makes the texture nice while scaled/rotated, or shifted with non-integer values, but has some difficulties.
Black or dark line artifact
The texture atlas background is possibly black, and edge pixels of the texregion get mixed with this background. Use a custom transparent texture atlas, or use a modified TextureAtlas builder which fills up itself with transparency (TODO find forum link where this is described)
Sprite edge has unwanted alpha
If the texture background is transparent, the alpha is still mixed into edge colors.
Add an 1-pixel extrusion to your texture region (repeat the edge pixels in an extra row/col at the edges), and position your region edges between the original and the added edge pixels. This will make sure bilinear interpolation picks only pixels from your region.
Other edge artifact
If texture regions are too close, a region edge may take some pixels from an other regions edge. Use padding between texture regions.
Text artifacts
Ocassional small vertical line under the baseline (GLES1)
In my font, the
J
char had an overly left-extending lower curve, which causes a small artifact when rendering theI
letter, sinceIJ
are next to each other in the texture, and possibly too near.Try lowering the font size, increasing the texture size, or hacking in larger
Font.PADDING
value (5
worked for me instead of1
). Note however that by default, increasing thePADDING
increases the line spacing too, which may not be desired. A newYPADDING
can be introduced and used where necessary to compensate.Disappearing letters
The letters are rendered to the Font texture atlas on-demand. This can lead to running out of space on the texture atlas, yielding fun effects (see Dissapearing ChangeableText).
One solution can be to insert this snippet to the
Font#createLetter(char)
method:我想出了解决办法。这些伪影背后的原因是纹理过滤设置。我使用了 TextureOptions.BILINEAR 和 TextureOptions.BILINEAR_PREMULTIPLYALPHA 导致了伪影。我选择了 TextureOptions.DEFAULT,纹理变得清晰且没有任何伪影。但有一个缺点。我的游戏中有流畅的精灵运动。但通过这种新的过滤设置(以及因此产生的纹理清晰度),精灵运动变得不平滑......有点不稳定。需要创建几个具有不同过滤选项的纹理图集。
I figured out the solution. The reason behind these artifacts was the texture filtering settings. I used TextureOptions.BILINEAR and TextureOptions.BILINEAR_PREMULTIPLYALPHA which caused the artifacts. I selected the TextureOptions.DEFAULT and the textures became crisp and without any artifacts. There's one drawback though. I have smooth sprite movement in my game. But with this new filtering setting(and texture crispness as a result) the sprite movement became not smooth... a bit choppy. Will need to create couple of TextureAtlases with different filtering options.
也许这有帮助http://www.andengine。 org/forums/gles1/black-lines-around-sprites-t5255.html#p25366
Maybe this help http://www.andengine.org/forums/gles1/black-lines-around-sprites-t5255.html#p25366
我会检查引擎上的缩小/放大过滤器设置。插值纹理时,如果纹理应用程序的目标与纹理的大小不同,则可能会出现伪影。
I'd check the minification/magnification filters settings on the engine. When textures are interpolated, artifacts may occur if the target of the texture application is not the same size as the texture.
当您将纹理区域放置在纹理中时,请确保留下几个像素的缓冲区。我发现了同样的问题,纹理显示了相邻纹理区域的一个像素左右。只需添加 2-5 像素边界,它就会消失。
When you place textureRegions in a texture, be sure to leave a buffer of a few pixels. I have found this same problem, with the texture displaying a pixel or so of the adjacent texture region. Just add a 2-5 pixel boundary and it should go away.