human: When light enters a medium other than a vacuum it slows down. When Light exits the medium and enters back into the vacuum it speeds back up. Where does the energy come that accelerates the light?

assistant: The energy of light does not change as it enters or exits a medium. The speed of light, however, is dependent on the properties of the medium through which it is traveling. When light enters a medium other than a vacuum, it interacts with the atoms or molecules in the medium, which causes it to slow down. When it exits the medium and enters back into a vacuum, it is no longer interacting with these particles, so it speeds back up to its original speed in the vacuum.

This change in speed does not violate the law of conservation of energy, as the energy of the light remains constant throughout the process. The energy of a photon, which is the particle that light can be thought of as consisting of, is determined solely by its frequency or wavelength. So, as the speed of light changes in a medium, its frequency or wavelength must also change in order to maintain the same energy.

human: Why do certain materials affect the speed of light transmitted?

assistant: To answer this, we need to clear a few concepts first. Light does not function in a way that you would expect a day to day wave to function. For instance, sound waves have different velocities in different mediums. The mechanism that makes this possible is NOT the same as the mechanism that makes light have "different speeds" through different mediums.

Now, let's first explore how light travels through transparent objects. Light is made up of little packets of energy, called "photons". Now the speed that these photons travel in the universe is always the same in any case. This speed is the speed of light in vacuum. So what happens when light enters say, glass? Well, atoms present in this piece of glass, specifically electrons absorb these photons and go to a higher orbit around the nucleus. After a little bit of time, they spontaneously emit a photon and drop in their orbits. This happens for a while, where these photons are absorbed, held by the electron for a very short amount of time, emitted and repeat, till they reach the other boundary of the piece of glass. 

This is why the speed of light in a medium appears to be different depending upon the medium that it passes through. 

Here's an analogy to make you understand this concept better. Say you want to run from your house to your school. You always run at the same speed. One day, you took a route where you met no one on your way. Hence, you reached school early. On the next day however, you met some friends along a different route that you took. You met with them, chatted for a bit and started running again till you met another friend. This went on till you reached school. Now, your average speed was lower than the previous day. This does not however mean that your running speed was lower. In this analogy, you are a photon, the two different routes to your school are the different mediums, while your friends are the atoms present in the medium. 

I hope you understood the concept well. Feel free to ask me for any clarifications!