简体   繁体   中英

Metal shader interpolate values in buffer

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM