LGhassen / Scatterer

Atmospheric scattering mod for KSP
Other
190 stars 51 forks source link

atmosphere blend mode adds together wrong, objects seen through atmospheres tend to become overexposed. #118

Closed WhirligigGirl closed 2 years ago

WhirligigGirl commented 3 years ago

Scatterer atmospheres tend to brighten background objects behind them, such as stars on the skybox, and when a scatterer atmosphere is seen from inside or behind another scatterer atmosphere, the result is that the atmosphere in the sky is overexposed.

This has been addressed somewhat by extinction but it seems to not be completely fixed, there still appears to be some unrealistic behavior.

Some examples of the incorrect behavior:

image

Stolen from Bill & Jeb's Most Excellent Adventure by Cupcake Landers, here we can see Alternis Jool (which is exposed correctly when seen alone in space) with EVE clouds and a scatterer atmosphere, has become overexposed, too bright, when seen in Alternis Kerbin's sky.

image

Lito in Whirligig World, atmosphere at the limb is too bright, adding onto the skybox instead of absorbing light from it

image

Lito's atmosphere rim gets much brighter when in front of Reander instead of the skybox

Here are some photos of the correct behavior in real life:

image

image

Refraction occurs in real atmospheres, but this post isn't about refraction--just demonstrating that the Moon does get reddened, but it has to get really squashed before that can happen

image

Titan has some regular blue rayleigh scattering going on in addition to the orange haze, but when seen against the very bright Saturn:

image

We see only orange.

SpaceEngine seems to get it right: Here's two atmospheres visually intersecting as seen from a third:

image

And here are some pictures of a correct implementation in a work-in-progress version of the game Personal Space. Posts about scattering: Scatterbrained. Scatterbrained II.

image

image

Now I stress that my argument mostly comes from a few real world examples and a sort of visual intuition and I don't actually know what I'm talking about. What follows is a paraphrased conversation between me and someone who does:

Me: so you know how in scatterer, atmospheres make the background brighter and two scatterer atmosphere will add and be too bright? I know you fixed this in your implementation of scattering in personal space at one point where atmospheres always scatter out more light even if you stack atmospheres. do you know what the math for that kind of blend is? (Or slightly more formal language for what I'm describing)

NovaSilisko (Personal Space developer and less relevantly, former KSP developer)

For one I kinda kludged together some extinction math. The other is what i usually see referred to as "one-minus" blending. Let me see if i can find the relevant bit:

final = bg + (1.0 - bg) * newstuff

is the gist of it. Then there is my questionable extinction function:

inline float3 Extinct(in float3 sourceColor, in float columnDensity, in float3 netCoeff)
{
    float3 extinction = exp(-columnDensity * netCoeff * _Opacity);
    return sourceColor * extinction;
}

render order is important as well

LGhassen commented 3 years ago

@GregroxMun I'm already doing "one minus blending". In the case of atmosphere seen from the ground I believe that it behaves correctly, but cupcake's videos are overexposed. This behaviour probably does happen in scaledSpace only, and I suspect extinctions may be applied together, then atmospheres together which would be obviously wrong, or something is wrong with back to front sorting, not sure. I'll need to do a deep dive in this, but as a heads up, I'll probably be busy irl for a month or longer so not sure when I'll be back.

LGhassen commented 3 years ago

@GregroxMun I did some tests and the soft additive blending + back to front sorting are both working correctly. However extinction doesn't scale correctly with experimentalAtmoScale and may be too weak in general. Will look into it again soon.

LGhassen commented 2 years ago

Fixed in latest version