I'd like to know the general formula of the gravitational red shift for light emitted from the center of a massive body of density $\rho$ and radius $R$ where the light is emitted from the center of the massive body up a tunnel and received at a radius $r$ distance from the center, where $r<R$.
3 Answers
The $g_{\rm tt}$ of the interior Schwarzschild metric inside of a sphere of constant local density is
$$g_{\rm tt}= \rm \frac{1}{4}\left(3 \sqrt{1-\frac{r_s}{r_g}}-\sqrt{1-\frac{r_s \ r^2}{r_g^3}}\right)^2 $$
($\rm r_s=2GM/c^2$ and $\rm r_g$ is the radius of the sphere), and the gravitational time dilation is simply ${\rm d\tau/dt}=\sqrt{g_{\rm tt}}$, so that is the factor by which a signal emitted at an $\rm r$ inside of the sphere will be received redshifted at infinity. For a signal emitted at infinity and received at an $\rm r$ inside of the sphere take the reciprocal to get the blueshift.
I can provide a formula based on Newtonian gravity and energy conservation, quantum mechanics $ (E = \hbar \nu) $, and special relativity $ (E=mc^2) $. It should work for weak gravitational fields, like for the Earth and the Sun. (The Schwarzschild radius of the body must be much smaller than the radius of the body itself.)
The energy to raise a photon in a gravitational field comes at the expense of the photon's energy. Let $ M $ be the mass of the body within a radius, $ r $. Therefore, $$- \hbar \ d\nu = \frac{GMm}{r^2}dr = \frac{G (\rho \frac{4}{3} \pi r^3) m}{r^2}dr = \frac{4}{3} \pi G \rho \ m \ r \ dr $$ From special relativity and quantum mechanics, $$ m=\frac{E}{c^2}=\frac{\hbar \nu}{c^2} $$ Therefore, $$- \hbar \ d\nu = \frac{4}{3} \pi G \rho \ \frac{\hbar \nu}{c^2} \ r \ dr \\ \frac{d\nu}{\nu} = - \frac{4 \pi G \rho}{3c^2} r \ dr \\ \int_{\nu_0}^{\nu_R} \frac{d\nu}{\nu} = - \int_0^R \frac{4 \pi G \rho}{3c^2} r \ dr \\ ln \left(\frac{\nu_R}{\nu_0} \right) = - \frac{2 \pi G \rho R^2}{3c^2} $$ Therefore, $$ \frac{\nu_R}{\nu_0}=exp \left(- \frac{2 \pi G \rho R^2}{3c^2} \right) $$ The radius, $ R $ , could be the radius of the massive body, or the radius of the massive body could be larger than $ R $. The same formula applies to both cases.
Continuing from the post on the interior Schwarzschild metric, if the photon is emitted from $ r $,
$$ \frac{ d\tau}{dt} = \frac{ \lambda_r}{\lambda_\infty} = \frac{1}{2} \left( 3 \sqrt{1 - \frac{r_s}{r_g}} - \sqrt{ 1 - \frac{ r^2 \, r_s} {r_g^3}} \right) $$
If the photon is emitted from $ r=0 $, $$ \frac{ d\tau}{dt} = \frac{ \lambda_0}{\lambda_\infty} = \frac{1}{2} \left( 3 \sqrt{1 - \frac{r_s}{r_g}} - \sqrt{ 1 - \frac{ \left( 0 \right) ^2 \, r_s} {r_g^3}} \right) = \frac{1}{2} \left( 3 \sqrt{1 - \frac{r_s}{r_g}} - 1 \right) $$ Now, $$ \frac{ \lambda_r }{ \lambda_0 } = \frac{ \lambda_r }{ \lambda_\infty } \frac{ \lambda_\infty }{ \lambda_0 } $$ Therefore, $$ \frac{ \lambda_r }{ \lambda_0 } = \frac{3 \sqrt{1 - \frac{r_s}{r_g}} - \sqrt{ 1 - \frac{ r^2 \, r_s} {r_g^3}}}{ 3 \sqrt{1 - \frac{r_s}{r_g}} - 1 } $$ Substituting $$ r_s = \frac{2GM}{c^2} $$ and $$ M = \rho \frac{4}{3} \pi \, r_g^3 $$ provides the formula in terms of $ \rho $, $ r $, and $ r_g $ as requested.