Search Unity

Accurately simulating Atmospheric Refraction

Discussion in 'Shaders' started by orilevenglick, Dec 3, 2019.

  1. orilevenglick

    orilevenglick

    Joined:
    Apr 7, 2019
    Posts:
    7
    I am trying to create an accurate simulation of the night's sky and the horizon, so taking atmospheric refraction into account is crutial. Would layers upon layers of materials with a decreasing index of refraction be good and CPU-friendly enough? Or better yet, are there any specialized methods of doing it?
    Thanks in advance,
    Ori
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    7,683
    Not remotely CPU friendly. And this is the shader subforum, so maybe you mean GPU friendly? In that case it's even more GPU unfriendly than it is CPU unfriendly. GPUs are using rasterization, not raytracing, so refraction through transparent mediums is totally faked approximations, and certainly don't have any impact on lighting calculations. You might be able to fake something like a sun or moon dipping under the horizon in terms of looking at it, but it won't affect the lighting accurately in the least.

    Depending on the scale you're looking to do, there exist plenty of analytical solutions for solving the affects of atmospheric refraction. You could apply those to a skybox shader, or for calculating a directional light orientation & color that approximates the real world affects.

    I mean really you're doing the same thing you were asking about in your previous question about bending light. This isn't something that GPUs or CPUs are particularly good at, so it's going to be really, really hard to do. And you're probably much better off using some kind of raymarched or analytical approach than anything that involves mesh geometry.