如何消除金属中的模糊纹理? [英] How can I get rid of blurry textures in Metal?
问题描述
我刚刚创建了一个Metal模板,并稍微修改了代码.我使用Minecraft 16x16青金石矿石纹理切换了默认的颜色图,但是由于某些原因,当它们的分辨率较低时,它们就会模糊掉.我正在尝试实现像素化的Minecraft外观,因此想知道如何禁用这种模糊/过滤功能.
I just created a Metal template and changed up the code a little. I switched out the default colormap with the Minecraft 16x16 lapis ore texture, but for some reason they are blurred out when they are low resolution. I am trying to achieve that pixelated, Minecraft look and so would like to know how to disable this blurring/filtering.
有没有一种方法可以加载/呈现资产而不会造成这种模糊?这是我的负载资产功能:
Is there a way to load/present assets without this blurring? Here is my load asset function:
class func loadTexture(device: MTLDevice, textureName: String) throws -> MTLTexture {
/// Load texture data with optimal parameters for sampling
return try MTKTextureLoader(device: device).newTexture(name: textureName, scaleFactor: 1.0, bundle: nil, options: [
MTKTextureLoader.Option.textureUsage: NSNumber(value: MTLTextureUsage.shaderRead.rawValue),
MTKTextureLoader.Option.textureStorageMode: NSNumber(value: MTLStorageMode.`private`.rawValue)
])
}
这是我得到的模糊立方体的屏幕截图:
Here is a screenshot of the blurry cube I'm getting:
推荐答案
在纹理样本调用中(在着色器中),您需要将放大滤镜设置为最近",而不是线性",就像这样(假设您的采样器在着色器中被声明为内联):
In your texture sample call (in the shader), you need to set your magnification filter to 'nearest', instead of 'linear', like so (assuming your sampler is declared inline inside your shader):
constexpr sampler textureSampler (mag_filter::nearest, // <-- Set this to 'nearest' if you don't want any filtering on magnification
min_filter::nearest);
// Sample the texture to obtain a color
const half4 colorSample = colorTexture.sample(textureSampler, in.textureCoordinate);
这篇关于如何消除金属中的模糊纹理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!