金属:线性纹理过滤未按预期工作
Metal: linear texture filtering not working as expected
我在 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
之外,我还需要做其他事情才能使线性过滤工作吗?
我的设备 (iPad Pro) 上 MTLPixelFormatRGBA32Float
类型的纹理似乎不支持线性过滤。当我更改为 MTLPixelFormatRGBA8Unorm
时,过滤按预期工作。
我在 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
之外,我还需要做其他事情才能使线性过滤工作吗?
我的设备 (iPad Pro) 上 MTLPixelFormatRGBA32Float
类型的纹理似乎不支持线性过滤。当我更改为 MTLPixelFormatRGBA8Unorm
时,过滤按预期工作。