@@ -129,10 +129,8 @@ public struct SkyDate
129129
130130 public class SkyPrimitive : RenderPrimitive
131131 {
132- public const float SkyRadius = 6020 ;
133- public const float MoonRadius = 6010 ;
134- public const float CloudsRadius = 6000 ;
135- public const float CloudsFlatness = 0.1f ;
132+ public const float RadiusM = 6000 ;
133+ public const float CloudsAltitudeM = 1000 ;
136134
137135 public SkyElement Element ;
138136
@@ -143,9 +141,9 @@ public class SkyPrimitive : RenderPrimitive
143141 * - Clouds blended by overcast factor and animated by wind speed and direction
144142 *
145143 * Both the cloud-less sky and clouds use sky domes; the sky is
146- * perfectly spherical, while the cloud dome is squashed (see
147- * `CloudsFlatness`) to make it closer to a flat plane overhead,
148- * without losing the horizon connection .
144+ * perfectly spherical, while the cloud dome is flattened and offset
145+ * so that it passes closer over the camera but still extends beyond
146+ * the horizon by the same amount .
149147 *
150148 * The sky dome is the top hemisphere of a globe, plus an extension
151149 * below the horizon to ensure we never get to see the edge. Both the
@@ -173,6 +171,11 @@ public class SkyPrimitive : RenderPrimitive
173171 const int VertexCount = ( 2 * DomeVertices ) + MoonVertices ;
174172 const int IndexCount = DomeIndexes + MoonIndexes ;
175173
174+ // Calculate the height of the dome from top to bottom of extra steps (below horizon)
175+ static readonly float DomeHeightM = RadiusM * ( float ) ( 1 + Math . Sin ( MathHelper . ToRadians ( DomeStepsExtra * TuneDomeComponentDegrees ) ) ) ;
176+ static readonly float CloudsFlatness = 1 - ( ( RadiusM - CloudsAltitudeM ) / DomeHeightM ) ;
177+ static readonly float CloudsOffsetM = CloudsAltitudeM - ( RadiusM * CloudsFlatness ) ;
178+
176179 readonly VertexPositionNormalTexture [ ] VertexList ;
177180 readonly short [ ] IndexList ;
178181
@@ -186,8 +189,8 @@ public SkyPrimitive(RenderProcess renderProcess)
186189 IndexList = new short [ IndexCount ] ;
187190 var vertexIndex = 0 ;
188191 var indexIndex = 0 ;
189- InitializeDomeVertexList ( ref vertexIndex , SkyRadius ) ;
190- InitializeDomeVertexList ( ref vertexIndex , CloudsRadius , CloudsFlatness ) ;
192+ InitializeDomeVertexList ( ref vertexIndex , RadiusM ) ;
193+ InitializeDomeVertexList ( ref vertexIndex , RadiusM , CloudsFlatness , CloudsOffsetM ) ;
191194 InitializeDomeIndexList ( ref indexIndex ) ;
192195 InitializeMoonLists ( ref vertexIndex , ref indexIndex ) ;
193196 Debug . Assert ( vertexIndex == VertexCount , $ "Did not initialize all verticies; expected { VertexCount } , got { vertexIndex } ") ;
@@ -235,10 +238,10 @@ public override void Draw(GraphicsDevice graphicsDevice)
235238 }
236239 }
237240
238- void InitializeDomeVertexList ( ref int index , float radius , float flatness = 1 )
241+ void InitializeDomeVertexList ( ref int index , float radius , float flatness = 1 , float offset = 0 )
239242 {
240243 // Single vertex at zenith
241- VertexList [ index ] . Position = new Vector3 ( 0 , radius * flatness , 0 ) ;
244+ VertexList [ index ] . Position = new Vector3 ( 0 , ( radius * flatness ) + offset , 0 ) ;
242245 VertexList [ index ] . Normal = Vector3 . Normalize ( VertexList [ index ] . Position ) ;
243246 VertexList [ index ] . TextureCoordinate = new Vector2 ( 0.5f , 0.5f ) ;
244247 index ++ ;
@@ -248,7 +251,7 @@ void InitializeDomeVertexList(ref int index, float radius, float flatness = 1)
248251 var stepCos = ( float ) Math . Cos ( MathHelper . ToRadians ( 90f * step / DomeStepsMain ) ) ;
249252 var stepSin = ( float ) Math . Sin ( MathHelper . ToRadians ( 90f * step / DomeStepsMain ) ) ;
250253
251- var y = radius * stepCos * flatness ;
254+ var y = radius * stepCos ;
252255 var d = radius * stepSin ;
253256
254257 for ( var side = 0 ; side < DomeSides ; side ++ )
@@ -263,7 +266,7 @@ void InitializeDomeVertexList(ref int index, float radius, float flatness = 1)
263266 var v = 0.5f + ( ( float ) step / DomeStepsMain * sideSin / 2 ) ;
264267
265268 // Store the position, texture coordinates and normal (normalized position vector) for the current vertex
266- VertexList [ index ] . Position = new Vector3 ( x , y , z ) ;
269+ VertexList [ index ] . Position = new Vector3 ( x , ( y * flatness ) + offset , z ) ;
267270 VertexList [ index ] . Normal = Vector3 . Normalize ( VertexList [ index ] . Position ) ;
268271 VertexList [ index ] . TextureCoordinate = new Vector2 ( u , v ) ;
269272 index ++ ;
@@ -383,7 +386,7 @@ public override void Render(GraphicsDevice graphicsDevice, IEnumerable<RenderIte
383386 SkyShader . Random = Viewer . World . Sky . MoonPhase ; // Keep setting this before LightVector for the preshader to work correctly
384387 SkyShader . LightVector = Viewer . World . Sky . SolarDirection ;
385388 SkyShader . Time = ( float ) Viewer . Simulator . ClockTime / 100000 ;
386- SkyShader . MoonScale = SkyPrimitive . SkyRadius / 20 ;
389+ SkyShader . MoonScale = SkyPrimitive . RadiusM / 20 ;
387390 SkyShader . Overcast = Viewer . Simulator . Weather . OvercastFactor ;
388391 SkyShader . SetFog ( Viewer . Simulator . Weather . FogDistance , ref SharedMaterialManager . FogColor ) ;
389392 SkyShader . WindSpeed = Viewer . World . Sky . WindSpeed ;
@@ -395,15 +398,15 @@ public override void Render(GraphicsDevice graphicsDevice, IEnumerable<RenderIte
395398 }
396399
397400 var xnaSkyView = XNAViewMatrix * Camera . XNASkyProjection ;
398- var xnaMoonMatrix = Matrix . CreateTranslation ( Viewer . World . Sky . LunarDirection * SkyPrimitive . MoonRadius ) ;
401+ var xnaMoonMatrix = Matrix . CreateTranslation ( Viewer . World . Sky . LunarDirection * SkyPrimitive . RadiusM ) ;
399402 var xnaMoonView = xnaMoonMatrix * xnaSkyView ;
400403 SkyShader . SetViewMatrix ( ref XNAViewMatrix ) ;
401404
402405 // Sky dome
403406 SkyShader . CurrentTechnique = SkyShader . Techniques [ "Sky" ] ;
404407 Viewer . World . Sky . Primitive . Element = SkyPrimitive . SkyElement . Sky ;
405408 graphicsDevice . BlendState = BlendState . Opaque ;
406- graphicsDevice . DepthStencilState = DepthStencilState . DepthRead ;
409+ graphicsDevice . DepthStencilState = DepthStencilState . None ;
407410
408411 ShaderPassesSky . Reset ( ) ;
409412 while ( ShaderPassesSky . MoveNext ( ) )
0 commit comments