1. Mick West

    Mick West Administrator Staff Member

    Metabunk 2018-04-05 13-44-19.

    This is the discussion thread for the Metabunk Mirage Simulator, which you can see at:

    A work in progress, the mirage simulator aims to be a physically accurate simulation of the refraction of light from distance objects, and the resulting artifacts such as looming and mirages.

    The approach used is to model the atmosphere where 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 is of Tornoto 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]
    Last edited: Apr 5, 2018
    • Like Like x 2
  2. DarkStar

    DarkStar Active Member

    1.2 was just an example for a high amount of refraction over water as opposed to default standard refraction.

    I did find this http://www.ngs.noaa.gov/PUBS_LIB/ResultsOfLevelingRefractionTests_by_NGS_TR_NOS92_NGS22.pdf

    I plan to review it later.

    It might be useful to have it as a variable but that's up to you. Sounds like surveyors shoot both directions and take the average to cancel out both refraction (assumes same conditions over time) and curvature.

    Reading more...

    I would really like to make a refraction calculator where you set up some Bézier curves for each of the major parameters and it shows you what would happen (pressure, temp, co2, water vapor, etc).

    Would be a lot of work though.
  3. Mick West

    Mick West Administrator Staff Member

    Me too. I very briefly started to discuss this with Andrew Young
    • Like Like x 1
  4. DarkStar

    DarkStar Active Member

    For the visualization part I found this which might help anyone interested in an attempt: D3 visualization library

    Example site animates some Bézier curves and simple line chart with code sample

    So I was thinking for starters that you setup a curve for each parameter which controls its value along the vertical. maybe allow the user to add or delete control points, or just have it fixed at maybe 4 points. We could even start with just straight lines and see how that goes.

    So the temp curve might just be slowly decreasing as per normal, or it might increase, then decrease, then increase again, etc...

    And you need a 'laser' that you can position vertically, rotate, and pick a frequency of light (rainbow mode would be fun). Might also be fun to have an array of 'lasers' so you can measure multiple lines of sight at the same time.

    And then you just iterate over Snell's equation at some fine-grained level using the formula to compute the index of refraction for each point. Sound about right?

    Kind of like the PHET refraction simulator (click on More Tools, twice to launch it)

    but that doesn't do the gradients unfortunately...
    • Like Like x 1
  5. Mick West

    Mick West Administrator Staff Member

    Kind of, you need to use the Taylor series method to get the actual curve, as just using successive linear adjustments gives errors. However it does seem like essentially using lots of very thin layers is an approach people have used before. There's some relevant papers I've been looking at here:

    Simulation of atmospheric phenomena, Gutierrez, 2006
    Atmospheric Refraction, Cheng, 2012
    (claims to give the same results as the above, but simpler).

    Real-Time Simulation of Dynamic Mirage Scenes, Wang, 2006
  6. Mordred

    Mordred New Member

    Good papers I've read them, I looked over the calculator. Its a good start. I would think the calculations for K would be a good approach.
  7. Mick West

    Mick West Administrator Staff Member

    I made a start with a mirage simulator:

    Metabunk 2018-03-28 16-21-00.

    It's mostly just preliminary UI, but it lets you play around a little to see various effects - not physically based though. You should be able to drag around the dots. Ignore the numbers.
    • Winner Winner x 2
  8. Mick West

    Mick West Administrator Staff Member

    Fata Morgana:
    Metabunk 2018-03-28 16-24-54.

    Again, not a physics based simulation. Yet.
    • Like Like x 1
  9. Z.W. Wolf

    Z.W. Wolf Senior Member


    Still from FE YT video showing "impossible" view of Rogers Center dome. (Should be hidden by x number of feet.)

    • Like Like x 1
  10. Mick West

    Mick West Administrator Staff Member

    You can get something pretty close with the current setup. This is just doing a very simple mapping of the slope of the line to stretching/compression of the image. There's no calculation at all yet. I faked the horizon here.

    Metabunk 2018-03-29 11-31-03.
    The building positions are a bit different as it was taken from a different angle.

    The plan is to to ray trace, one ray per screen line. It will step forward, and adjust the ray angle based on changes in the refractive index. The ray will either hit the ocean or hit the skyline (or island, boat, etc) image
    • Like Like x 1
    • Winner Winner x 1
  11. StarGazer

    StarGazer Member

    I know that the simulator isn't physically accurate yet, but how accurate can it get?

    For now all I see a 2D image being stretched and compressed which isn't a 3D model :(
  12. Mick West

    Mick West Administrator Staff Member

    It's not accurate at all right now. It's just a mock up to test display and editing a graph. I just hacked it together with some sample code. It needs the math discussed in earlier posts.

    The object image (city/mountain/ship) will be treated like a billboard. The distances within the object are typically very small compared with the distance to the image. So refraction has very little effect over that short distance. Compare the size of downtown Toronto to the distance across the lake:

    Metabunk 2018-03-29 21-00-54.

    Essentially I'll be modeling the 3D atmosphere between the camera and the object, but not the atmosphere inside the object. I doubt the difference would be detectable.

    So the answer is "very accurate"
    • Like Like x 1
    • Winner Winner x 1
  13. Mick West

    Mick West Administrator Staff Member

    First pass at physically based ray tracing:
    Metabunk 2018-03-31 15-15-53.


    Ray tracing is done using an iterative method which varies based on how the steps are. This creates differences mostly when dealing with very shallow angles, especially when "ducts" form.

    A vast amount can be done with this, but it requires some UI work.
  14. Mick West

    Mick West Administrator Staff Member

    So here's one of the laser experiment.With no temperature change the laser is hidden:
    Metabunk 2018-03-31 15-45-54.

    Bit with a very slight inversion at 10 feet, it springs into view:
    Metabunk 2018-03-31 15-47-18.

    Also with a VERY small reduction to the 0ft temperature
    Metabunk 2018-03-31 15-48-28.
  15. Mick West

    Mick West Administrator Staff Member

    Here's that zoomed in.

    Metabunk 2018-03-31 15-54-48.

    What's interesting is the really small temperature difference needed. The laser is just hidden in the bottom few feet. There's standard refraction here, but not enough to bring the laser into view:
    Metabunk 2018-03-31 15-55-38.

    But with just a 0.5°C reduction in temperature between 5 feet and the lake surface:
    Metabunk 2018-03-31 15-58-02.

    The light path now curves around to the bottom of the target position.

    Metabunk 2018-03-31 15-59-09.

    A smoother inversion layer gives less distortion
    Metabunk 2018-03-31 16-02-11.

    Metabunk 2018-03-31 16-02-43.
  16. Mick West

    Mick West Administrator Staff Member

    Here's a general illustration of the the reason using lasers is a terrible idea:
    Metabunk 2018-03-31 16-12-06.

    There's massive distortion of the image, which is quite obvious. But if we were just looking at this laser at night then we'd just see this green dot seemingly 20 feet above the horizon.

    Photos and video beat lasers because you can see the distortion.
  17. Z.W. Wolf

    Z.W. Wolf Senior Member

    I'm already having fun playing around with it. Looking forward to the improved version.

    If I might make a suggestion, I'd like the option of being able to type in numerical values. I think I'd find it easier than the mouse drag.

    In this situation, if the camera were mounted on a drone, the Rogers Centre dome would disappear as the drone gained just a little altitude... proving that it was only visible lower down because of atmospheric refraction.

    You should be able to simulate that effect.
    Last edited: Mar 31, 2018
    • Like Like x 1
  18. Mick West

    Mick West Administrator Staff Member

    A variety of UI, optimizations, and quality changes:

    Metabunk 2018-04-02 12-26-30.

    Notable you can adjust the viewer height with a slider. And you can resize and move the rendered image and the ray graph.

    Not much more time for changes until next week. But at that point I'll look more into the physical accuracy. I'm not entirely sure how best to step the ray though a continuously variable medium. Right now it's done by stepping two parallel rays a different length (based on change of speed of light * 1/n), then adjusting the actual ray to be perpendicular to the vector joining the two endpoints. I feel there must be a better way based on the 3D gradient of n, but it's not jumping out at me.

    The "narrow" option changes the spacing of these side rays - essentially the width of the simplified wavefront.

    I'm also assuming a constant pressure lapse rate, and then calculating n from t and this lapsed p.

    The editable temperature gradient is now smoothed internally, this could be tweak, and I need to add a visualization for it. Next week!
    Last edited: Apr 2, 2018
  19. Clouds Givemethewillies

    Clouds Givemethewillies Active Member

    You might find this useful for setting some values/limits on typical temperature profiles:
    " The Story of Diurnal Boundary Layer Growth Told in Vertical Profiles of Virtual Potential Temperature"
  20. Mick West

    Mick West Administrator Staff Member

  21. Clouds Givemethewillies

    Clouds Givemethewillies Active Member

    Unfortunately you really need some high resolution measurements near to the surface. A 'coffee cup' sonde (Windsond) hanging from a drone would be good, and you get it all back with luck. Coffe cup.PNG
  22. Mick West

    Mick West Administrator Staff Member

    Interesting looking at things like this:

    Metabunk 2018-04-02 17-06-22.

    It's a 2°C inversion between 20 and 50 feet. This creates a duct, seen in this highly exaggerated side view of the light paths
    Metabunk 2018-04-02 17-07-44.
    The top of the duct is where there's a rapid increase in temperature above 20 feet

    The bottom of the duct is mostly just straight lines skimming the curve of the earth. It's kind of like a ray of light bouncing around the inside of huge concave mirror at a very shallow angle.
  23. Mick West

    Mick West Administrator Staff Member

    Metabunk 2018-04-02 23-10-19.

    Added display of the refractive index per pixel.
  24. Mick West

    Mick West Administrator Staff Member

    • Winner Winner x 1
  25. Mick West

    Mick West Administrator Staff Member

    Much smoother interpolation of temperature curves.
    Added a "Debug" button that shows the curves for first 100 feet
    Red = temperature
    yellow = refractive index
    white = scaled refractive index (scaled so you see more details when it's not changing much)

    Metabunk 2018-04-03 22-22-34.
  26. Mick West

    Mick West Administrator Staff Member