How would I get an RGB value from a material in code by inputing an x,y,z world position?

To add, in case it wasn’t obvious, the material is being used as a height map. The mesh is being rebuilt at edit time.