英文:
Unity - Border around opaque area of transparent texture
问题
我已经创建了一个透明的纹理,用于在玻璃罐模型上使用(1024 x 1024 PNG)。
我已经将以下设置应用到了纹理上,预览看起来很好。
但是,当我在着色器图中对纹理进行采样时,纹理不透明部分周围似乎有一种阿尔法填充效果。
这在实际模型上非常明显。
我需要应用哪些设置以防止这种情况发生?
英文:
I've made a transparent texture to use on a glass jar model. (1024 x 1024 PNG)
I've applied the following settings to the texture and the preview looks good.
But when I sample the texture in shader graph there's a sort of alpha padding around the opaque part of the texture.
Which is quite obvious on the actual model
What settings do I need to apply to prevent this from happening?
答案1
得分: 1
以下是翻译好的部分:
问题的根本原因是纹理采样中的颜色渗透,如下图所示:
看脚部。
原因是尽管像素是透明的,但它们实际上仍然保留了一些颜色值。通常这只是黑色或白色,但这取决于用于创建图像文件的程序。不能100%确定,但为了压缩,将颜色溢出到透明区域可能更便宜。
我提出的以下图表可以“修复”/避免这个问题:
而不是仅使用包含“无效”颜色数据的纹理,只需使用其实际正确的 alpha 通道,然后将图像叠加到背景颜色上。
对于贴纸的行为,只需确保将“Mode”从默认值“Overlay”更改为“Overwrite”。然后,作为结果的 alpha,您可以使用这个混合结果的 alpha。
这样,您就可以完全控制两者 - 图像可以包含透明度,背景颜色也可以根据您的需求是透明的还是不透明的。
英文:
The underlying issue is the color bleeding in the texture sample like e.g.
see the feet.
The reason is that even though the pixels are transparent they actually still hold some color value. Mostly this is just either black or white but it depends on the program that was used to create the image file. Not 100% sure but for compression it might be cheaper to simply let your color overbleed into the transparent area.
The following Graph I came up with can "fix" / avoid this
Instead of using alone the texture which includes the "invalid" color data simply use its alpha channel which is actually correct and rather overlay (Blend) the image over a background color.
For the behavior of a sticker just make sure to change the Mode
from the default Overlay
to Overwrite
. And then as resulting alpha you can just use the alpha from this blended result.
This way you have full control over both -> The image can contain transparencies and the background color can as well or just be opaque according to your needs
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论