At work here is some basic physics. When the sun heats up the atmosphere above the ocean, it creates a gradient of temperatures: Near the surface, it’s still relatively cool because the water is chilling that air, but sitting above that is a layer of warmer air. Now, light doesn't always travel in a straight line. When it hits a boundary between two layers of the atmosphere that are different temperatures (and therefore different densities), it bends and travels through the new layer at a different angle. This is known as refraction. The change in the light's angle of travel depends on the difference in density between the two layers.How does bending light create a mirage? The rest of the effect is caused by how your brain works. When light hits your eyes, your brain assumes it arrived there in a straight path between you and the object reflecting the light. So if light is bent on its way toward you, your brain will think the object is where it would be if the light's path was straight. This is why when you are looking down on a surface of water, objects under the surface will appear to be in a different spot than they actually are—just ask a spear fisherman...if you happen to know a spear fisherman. The human brain doesn't automatically account for the refraction. (Interestingly, the brains of some birds like ospreys do correct for the effect so that when they dive headlong into the water after a fish, they are right on target.)