【问题标题】:How can I get rid of blurry textures in Metal?如何摆脱 Metal 中的模糊纹理?
【发布时间】:2020-03-07 02:13:28
【问题描述】:

我刚刚创建了一个 Metal 模板并稍微修改了代码。我用 Minecraft 16x16 青金石矿石纹理切换了默认颜色图,但由于某种原因,它们在低分辨率时会变得模糊。我正在尝试实现像素化的 Minecraft 外观,因此想知道如何禁用这种模糊/过滤。

有没有办法加载/呈现资产而不会出现这种模糊?这是我的加载资产功能:

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)
    ])
}

这是我得到的模糊立方体的屏幕截图:

【问题讨论】:

标签: swift textures metal


【解决方案1】:

在您的纹理采样调用中(在着色器中),您需要将放大过滤器设置为“最近”,而不是“线性”,就像这样(假设您的采样器在着色器中被声明为内联):

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);

【讨论】:

  • 谢谢,但你知道如何让它接受具有部分透明部分的纹理吗?无论如何
  • @Idk 那是另一回事——请发布一个新问题。
猜你喜欢
  • 1970-01-01
  • 2021-08-24
  • 1970-01-01
  • 2022-08-11
  • 1970-01-01
  • 2012-02-14
  • 1970-01-01
  • 2021-09-04
  • 2019-06-11
相关资源
最近更新 更多