7
votes

In Metal shading language, what is the exact difference between read and sample function to access texture pixels, and which one should be used when?

1

1 Answers

16
votes

A few differences:

  • You can sample outside the bounds of the texture. But you should not read outside the texture.
  • Sampling can use normalized coordinates (between 0 and 1). Reading always uses pixel coordinates.
  • Samplers can interpolate between pixel values (for example if you're sampling in between two pixels). Reading always gives you the exact pixel value.