金属:线性纹理过滤无法按预期工作

时间:2016-11-25 19:42:43

标签: ios metal

我在iOS上使用Metal,使用以下片段着色器:

constexpr sampler s(coord::normalized,
                    address::clamp_to_zero,
                    filter::linear);

fragment half4 passThroughFragment(VertexInOut inFrag [[stage_in]],
                                   texture2d<float> tex [[ texture(0) ]])
{
    return half4(tex.sample(s, inFrag.uv));
}

我的纹理是4x4图像。尽管过滤设置为线性,但我得到以下图像,最近邻过滤:

Image with nearest neighbor filtering

似乎我的uv很好,因为当我修改片段着色器时如下:

return half4(0, inFrag.uv.x, inFrag.uv.y, 1);

我得到了预期的图片:

Plot of UV coordinates

除了指定filter::linear之外,线性过滤还需要做些什么吗?

1 个答案:

答案 0 :(得分:4)

我的设备(iPad Pro)上的MTLPixelFormatRGBA32Float类型的纹理似乎不支持线性过滤。当我更改为MTLPixelFormatRGBA8Unorm时,过滤按预期工作。