To find out how the speed of light is related to optical density, we first have to figure out the refractive index of the medium in which the light is passing through. In a vacuum, light travels around roughly 300,000 kilometers per second, giving it a refractive index of 1. When light is traveling through water, it slows down to approximately 225,000 kilometers per second, which gives us a refractive index of 1.3. Light travels even slower when it's passing through glass,(200,000 kilometers per second) with a refraction index of 1.5.
In short, when the speed of light is slower passing throughair, than the medium the light is passing through is denser than air. When the speed of light is faster when passing through air, than the medium the light is passing through is more dense than the air is.