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

You don’t read back values from the rendering pipeline, really. It’s super slow, because it will have to stall the GPU pipeline to synchronize with the CPU.

If you still need this, the best option is probably to render the material in question to a render target, and then read back the pixels of this render target. The good news is that you can efficiently render many points at once this way, which should help with performance when generating terrain.