What determines the direction in which a substance diffuses across a membrane?