This is the discussion thread for the Metabunk Refraction Simulator (previously called the mirage simulator), which you can see at:
How to use it:
A work in progress, the refraction simulator aims to be a physically accurate simulation of the refraction of light from distant objects and the resulting artifacts such as looming, distortion, and mirages.
The approach used is to model the atmosphere where the refractive index is a function of altitude, being derived from pressure (using standard atmosphere pressure altitudes) and temperature (using a user-editable temperature profile.
The simulator then traces a single ray for each line of the image, starting at the eye/camera position. The ray is stepped through the atmosphere, and the direction modified based on the refractive index gradient. This is repeated until it hits the ground, the target object, or misses both (and continues into the sky - no provision yet for ground behind the object.)
This approach is able to replicate all refraction phenomena, including ducting and Fata Morgana, within physically reasonable temperature profiles.
It also replicates a variety of situations that have led people to suspect that the Earth might actually be flat - including laser tests. The default configuration was of Toronto from 31 miles away. There's a laser dot at the shoreline of the target image which is hidden with a standard atmosphere, but which you can bring into view with a temperature inversion forming a duct (move the 30ft point 1° to the right.)
I'm continuing to work on it, and invite feedback.
[This is a summary post. Some information may be repeated in the following discussion. The thread started in 2016, but serious work on the simulator only started in March 2018]