The formation of mirage is a consequence of :
Varying R.I & TIR
Due to the varying refractive index in the air, the light rays keep bending and as the medium gets rarer and rarer, a point comes when the total internal reflection takes place. This is the reason of the formation of mirage.