我正在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
,还需要做些什么才能使线性过滤起作用吗?