Fermat's principle states that light will take the path between two points that minimizes the time, rather than the distance, required to travel between them. In most cases, light simply moves in a straight line, but when it moves from one material to another, it refracts, bending its path according to the properties of the two materials. The important factor is the difference in refractive index, a number determined by the material's molecular structure, conductivity, and other properties. Vacuum has a refractive index of 1, and air is quite close, with 1.0003. However, water has a refractive index of about 1.33. This is why objects appear shifted when you dip them partway into water.
The shortest distance between two points is a straight line, so this certainly doesn't look right. However, if we instead plot according to time, taking the speed of the light into account,
The light moves more slowly in the second material, so we stretch out the line we had. Looking at it this way, it's much clearer why the light is bent in space.
I always enjoy making these write-ups, and I'm sure it's good practice, so I'll be back here as often as my workload allows. As always, questions are welcome, on this or any of the older posts.