我在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图像。尽管过滤设置为线性,但我得到以下图像,最近邻过滤:
似乎我的uv很好,因为当我修改片段着色器时如下:
return half4(0, inFrag.uv.x, inFrag.uv.y, 1);
我得到了预期的图片:
除了指定filter::linear
之外,线性过滤还需要做些什么吗?
答案 0 :(得分:4)
我的设备(iPad Pro)上的MTLPixelFormatRGBA32Float
类型的纹理似乎不支持线性过滤。当我更改为MTLPixelFormatRGBA8Unorm
时,过滤按预期工作。