@@ -14,9 +14,9 @@ public class AtmosphereRowOperation
1414 /// Size to increase image by due to atmosphere rendering.
1515 /// </summary>
1616 public const float ImageScaleFactor = 1.05f ;
17-
17+
1818 private const float InnerOpacityScale = 0.7f ;
19-
19+
2020 private readonly Image < Rgba32 > _source ;
2121 private readonly ReadOnlyCollection < CieLch > _gradient ;
2222
@@ -37,6 +37,7 @@ public class AtmosphereRowOperation
3737 /// Maximum distance from centre of Earth.
3838 /// </summary>
3939 private readonly double _maxDistance ;
40+
4041 private readonly float _opacity ;
4142
4243 /// <summary>
@@ -68,14 +69,17 @@ public AtmosphereRowOperation(Image<Rgba32> source, float atmosphere, float opac
6869
6970 _atmosphere = atmosphere ;
7071 _converter = new ColorSpaceConverter ( ) ;
71- _maxDistance = Distance ( _source . Width , _source . Height ) ;
72+ _maxDistance = Distance ( _source . Width , _source . Height * _source . Height ) ;
7273 }
7374
7475 public void Invoke ( Span < Vector4 > row , Point value )
7576 {
77+ var yDistance = value . Y - _source . Height / 2d ;
78+ var yDistanceSquared = yDistance * yDistance ;
79+
7680 for ( var x = 0 ; x < row . Length ; x ++ )
7781 {
78- var distance = Distance ( x , value . Y ) ;
82+ var distance = Distance ( x , yDistanceSquared ) ;
7983
8084 if ( distance < 1 - _atmosphere ) continue ;
8185
@@ -99,11 +103,9 @@ public void Invoke(Span<Vector4> row, Point value)
99103 /// Distance from point to Earth's circumference. A value of 1 is on the circumference, and less
100104 /// than 1 is inside the Earth.
101105 /// </summary>
102- private double Distance ( int x , int y )
106+ private double Distance ( int x , double yDistanceSquared )
103107 {
104108 var xDistance = x - _source . Width / 2d ;
105- var yDistance = y - _source . Height / 2d ;
106-
107- return xDistance * xDistance / _semiMajor2 + yDistance * yDistance / _semiMinor2 + BorderRatio ;
109+ return xDistance * xDistance / _semiMajor2 + ( yDistanceSquared ) / _semiMinor2 + BorderRatio ;
108110 }
109111}
0 commit comments