简体   繁体   English

如何在没有抗锯齿的情况下在 Unity 着色器中采样 2D 纹理?

[英]How can I sample a 2D texture in a Unity shader without antialiasing?

I'm making a simple 3D game using my own shader, and want to emulate an 8-bit pixel art style.我正在使用自己的着色器制作一个简单的 3D 游戏,并希望模拟 8 位像素艺术风格。 To do this, I need to sample a low-resolution texture without the sampler interpolating between inter-pixel values.为此,我需要对低分辨率纹理进行采样,而不需要采样器在像素间值之间进行插值。 Hopefully this will also reduce processing time since it won't need to calculate the interpolation.希望这也将减少处理时间,因为它不需要计算插值。 Is there a way I can accomplish this?有什么办法可以做到这一点?

Ok, turns out there was something I didn't realise about 2D textures.好的,事实证明我没有意识到 2D 纹理。 I'd already set its Filter Mode to 'point', which turns off interpolation in the sampling, but I hadn't noticed that there's a box marked 'Non-Power of 2'.我已经将其过滤模式设置为“点”,这会关闭采样中的插值,但我没有注意到有一个标记为“非 2 的幂”的框。 What this does is, if your texture has dimensions that aren't a power of 2 (ie 1024) it upscales it so that it is.这样做的目的是,如果您的纹理的尺寸不是 2 的幂(即 1024),它会放大它,使其成为 2 的幂。 It does this so that it can apply compression to the texture, since compression only works on power-of-2 images in Unity.它这样做是为了可以对纹理应用压缩,因为压缩仅适用于 Unity 中的 2 次方图像。 However, it applies antialiasing to the upscale regardless of Sample Mode, so the interpolation was actually being 'baked in' by the compiler and had nothing to do with the sampler or the shader whatsoever.但是,无论采样模式如何,它都会对高档应用抗锯齿,因此插值实际上是由编译器“烘焙”的,与采样器或着色器无关。

Turning this OFF solved the problem;关闭它解决了问题; however once I'm happy with my textures I will be expanding them to a power-of-2 size with trailing padding in order to take advantage of it.然而,一旦我对我的纹理感到满意,我就会将它们扩展到带有尾部填充的 2 的幂大小,以便利用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM