9

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?

Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131

1 Answers1

23

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.
Matthijs Hollemans
  • 7,706
  • 2
  • 16
  • 23