When light enters a different medium, such as going from air to glass, it interacts with the atoms or molecules of that medium. This interaction can cause the light to be absorbed and re-emitted by the atoms or molecules, which leads to a delay in the overall speed of the light wave. This delay is what we perceive as a decrease in the speed of light in that medium.
When light exits the medium and returns to a less dense medium (such as going from glass back into air), it again interacts with the atoms or molecules at the interface. The absorbed energy from the light is then re-emitted, allowing the light to resume its original speed.
It's important to note that the speed of light in a vacuum is constant, and it only changes when passing through a medium due to these interactions. The energy of light, on the other hand, depends on its frequency or wavelength. The frequency of light remains constant as it passes through different media, while the wavelength changes.
In summary, the energy of light remains the same as it passes through different media, while the speed of light can vary depending on the properties of the medium. The interactions between light and the atoms or molecules of the medium cause delays and alterations in the speed of light, but the overall energy of the light remains unchanged.