Air's refractive index depends on temperature: colder, denser air refracts light more. Using the standard visible-light approximation for the refractivity of air (pressure P ≈ 1013 hPa held fixed):
n(T) = 1 + 0.0786 / T (T in kelvin)
The observer's eye sends out a fan of near-horizontal rays. The air above the ground is split into layer count horizontal slabs, each at its own temperature from the gradient dT/dh, so each slab has its own n. For light crossing horizontal boundaries between slabs, Snell's law reduces to a single conserved quantity along the whole ray — the horizontal invariant:
n(h)·cos φ(h) = n(h_eye)·cos φ_eye (φ = angle from horizontal)
Each ray is marched slab by slab; wherever n·cosφ would exceed 1 in the next slab the ray undergoes total internal reflection and bends back the way it curved — the mechanism behind the doubled, inverted bands of a Fata Morgana. Because the eye can't see the curve, it perceives each incoming ray as if it travelled in a straight line — so the apparent image is built by extrapolating each ray's final arrival angle straight back to the object's real distance. That apparent position is what an observer (or an untrained witness) reports seeing, and it can sit above, below, doubled, stretched or inverted relative to the real object.
- Temperature gradient — negative (hot ground, cool air above) curves rays upward into the eye and produces an inferior mirage (a false "water" band below the object, common as desert/road shimmer). Positive (cold air trapped near the surface under a warmer layer aloft — a true temperature inversion) curves rays downward and produces a superior mirage, which can loom, stretch or invert the object into an apparently levitating, saucer-like shape — the classic Fata Morgana misreported as a UFO.
- Layer count — how finely the continuous temperature profile is discretized into constant-n slabs for the Snell-law marching; more layers converge to the smooth continuous-gradient ray path.
- Object distance — longer paths accumulate more bending, since curvature integrates over the whole ray length.
- Object height — sets the real silhouette (dashed) that the apparent image (solid) is compared against.
Vertical scale on the diagram is exaggerated for visibility — real mirages form within centimetres to a few metres of the surface, which is exactly why they are so often misjudged in scale and distance by observers, feeding UFO reports.