0
votes

I need to pass a buffer to Metal fragment shader which is an array of N float values. But I want the shader to interpolate values if the width of the texture to which it is drawn is more than N pixels. If I use a texture, it is easy to use sampler and set linear filtering, but it's not clear if interpolation can be setup on an arbitrary buffer in fragment shader.

1

1 Answers

1
votes

No, it's not possible to make Metal interpolate over values in a buffer for you. Metal has no way of knowing that the buffer has an associated "geometry". For example, an array of N float values could be N horizontal elements, N vertical elements, 5 rows of N/5 elements, etc. Interpolation requires knowledge of which elements are neighbors of a given element, which requires knowledge of geometry.

You can, of course, do the interpolation yourself in the shader.

You can also create a texture from a buffer using the -newTextureWithDescriptor:.../makeTexture() method of MTLBuffer. Then you can sample from that texture.