Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Metal: linear texture filtering not working as expected

Tags:

ios

metal

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:

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:

Plot of UV coordinates

Is there something else I need to do for linear filtering to work other than specify filter::linear?

like image 644
Taylor Avatar asked Nov 25 '16 19:11

Taylor


1 Answers

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.

like image 68
Taylor Avatar answered Oct 05 '22 23:10

Taylor