Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Metal shader texture read vs sample

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?

like image 487
Deepak Sharma Avatar asked Apr 13 '18 15:04

Deepak Sharma


1 Answers

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.
like image 142
Matthijs Hollemans Avatar answered Oct 25 '22 04:10

Matthijs Hollemans