Gravity effects the energy of a photon per the equation GM/c^2r. I understand that a photon traveling on a crash course with a black hole will be blue shifted according to the hole's mass, however I'm a little confused as to what happens when a photon simply passes nearby a massive object. For example, if photon A passes by black hole B, it will be affected in proportion to its distance to the object. Is it fair to say that the photon will be blue shifted as it's distance lessens and then redshifted in equal amount when it passes by and the distance increases? Or would the sum total energy of the photon be lessened by having this interaction? How about if there is two black holes and the photon passes directly in between them?