I'm using Metal on iOS with the following fragment shader:
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));
}
My texture is a 4x4 image. Despite the filtering set to linear, I get the following image, with nearest neighbor filtering:
It seems that my uv's are fine, since when I modify the fragment shader as follows:
return half4(0, inFrag.uv.x, inFrag.uv.y, 1);
I get the expected image:
Is there something else I need to do for linear filtering to work other than specify filter::linear
?
It appears linear filtering isn't supported for textures of type MTLPixelFormatRGBA32Float
on my device (iPad Pro). When I change to MTLPixelFormatRGBA8Unorm
, filtering works as expected.