public override void Render(GraphicsDevice graphicsDevice, IEnumerable <RenderItem> renderItems, ref Matrix XNAViewMatrix, ref Matrix XNAProjectionMatrix) { // Adjust Fog color for day-night conditions and overcast FogDay2Night( Viewer.World.MSTSSky.mstsskysolarDirection.Y, Viewer.World.MSTSSky.mstsskyovercastFactor); //if (Viewer.Settings.DistantMountains) SharedMaterialManager.FogCoeff *= (3 * (5 - Viewer.Settings.DistantMountainsFogValue) + 0.5f); if (Viewer.World.MSTSSky.mstsskylatitude > 0) // TODO: Use a dirty flag to determine if it is necessary to set the texture again { MSTSSkyShader.StarMapTexture = MSTSSkyStarTexture; } MSTSSkyShader.Random = Viewer.World.MSTSSky.mstsskymoonPhase; // Keep setting this before LightVector for the preshader to work correctly MSTSSkyShader.LightVector = Viewer.World.MSTSSky.mstsskysolarDirection; MSTSSkyShader.Time = (float)Viewer.Simulator.ClockTime / 100000; MSTSSkyShader.MoonScale = MSTSSkyConstants.skyRadius / 20; MSTSSkyShader.Overcast = Viewer.World.MSTSSky.mstsskyovercastFactor; MSTSSkyShader.SetFog(Viewer.World.MSTSSky.mstsskyfogDistance, ref SharedMaterialManager.FogColor); MSTSSkyShader.WindSpeed = Viewer.World.MSTSSky.mstsskywindSpeed; MSTSSkyShader.WindDirection = Viewer.World.MSTSSky.mstsskywindDirection; // Keep setting this after Time and Windspeed. Calculating displacement here. for (var i = 0; i < 5; i++) { graphicsDevice.SamplerStates[i] = SamplerState.LinearWrap; } // Sky dome graphicsDevice.DepthStencilState = DepthStencilState.DepthRead; Matrix viewXNASkyProj = XNAViewMatrix * Camera.XNASkyProjection; MSTSSkyShader.CurrentTechnique = MSTSSkyShader.Techniques["Sky"]; Viewer.World.MSTSSky.MSTSSkyMesh.drawIndex = 1; MSTSSkyShader.SetViewMatrix(ref XNAViewMatrix); ShaderPassesSky.Reset(); while (ShaderPassesSky.MoveNext()) { foreach (var item in renderItems) { Matrix wvp = item.XNAMatrix * viewXNASkyProj; MSTSSkyShader.SetMatrix(ref wvp); ShaderPassesSky.Current.Apply(); item.RenderPrimitive.Draw(graphicsDevice); } } MSTSSkyShader.CurrentTechnique = MSTSSkyShader.Techniques["Moon"]; Viewer.World.MSTSSky.MSTSSkyMesh.drawIndex = 2; graphicsDevice.BlendState = BlendState.NonPremultiplied; graphicsDevice.RasterizerState = RasterizerState.CullClockwise; // Send the transform matrices to the shader int mstsskyRadius = Viewer.World.MSTSSky.MSTSSkyMesh.mstsskyRadius; int mstscloudRadiusDiff = Viewer.World.MSTSSky.MSTSSkyMesh.mstscloudDomeRadiusDiff; XNAMoonMatrix = Matrix.CreateTranslation(Viewer.World.MSTSSky.mstsskylunarDirection * (mstsskyRadius)); Matrix XNAMoonMatrixView = XNAMoonMatrix * XNAViewMatrix; ShaderPassesMoon.Reset(); while (ShaderPassesMoon.MoveNext()) { foreach (var item in renderItems) { Matrix wvp = item.XNAMatrix * XNAMoonMatrixView * Camera.XNASkyProjection; MSTSSkyShader.SetMatrix(ref wvp); ShaderPassesMoon.Current.Apply(); item.RenderPrimitive.Draw(graphicsDevice); } } for (int i = 0; i < MSTSSkyCloudTexture.Count; i++) { if (i == 0) { MSTSSkyShader.CurrentTechnique = MSTSSkyShader.Techniques["Clouds"]; Viewer.World.MSTSSky.MSTSSkyMesh.drawIndex = 3; graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; ShaderPassesClouds[0].Reset(); while (ShaderPassesClouds[0].MoveNext()) { foreach (var item in renderItems) { Matrix wvp = item.XNAMatrix * viewXNASkyProj; MSTSSkyShader.SetMatrix(ref wvp); ShaderPassesClouds[0].Current.Apply(); item.RenderPrimitive.Draw(graphicsDevice); } } } } }
public override void Render(GraphicsDevice graphicsDevice, IEnumerable <RenderItem> renderItems, ref Matrix XNAViewMatrix, ref Matrix XNAProjectionMatrix) { // Adjust Fog color for day-night conditions and overcast FogDay2Night( Viewer.World.Sky.solarDirection.Y, Viewer.Simulator.Weather.OvercastFactor); //if (Viewer.Settings.DistantMountains) SharedMaterialManager.FogCoeff *= (3 * (5 - Viewer.Settings.DistantMountainsFogValue) + 0.5f); if (Viewer.World.Sky.latitude > 0) // TODO: Use a dirty flag to determine if it is necessary to set the texture again { SkyShader.StarMapTexture = StarTextureN; } else { SkyShader.StarMapTexture = StarTextureS; } SkyShader.Random = Viewer.World.Sky.moonPhase; // Keep setting this before LightVector for the preshader to work correctly SkyShader.LightVector = Viewer.World.Sky.solarDirection; SkyShader.Time = (float)Viewer.Simulator.ClockTime / 100000; SkyShader.MoonScale = SkyConstants.skyRadius / 20; SkyShader.Overcast = Viewer.Simulator.Weather.OvercastFactor; SkyShader.SetFog(Viewer.Simulator.Weather.FogDistance, ref SharedMaterialManager.FogColor); SkyShader.WindSpeed = Viewer.World.Sky.windSpeed; SkyShader.WindDirection = Viewer.World.Sky.windDirection; // Keep setting this after Time and Windspeed. Calculating displacement here. // Sky dome var rs = graphicsDevice.RenderState; rs.DepthBufferWriteEnable = false; SkyShader.CurrentTechnique = SkyShader.Techniques["Sky"]; Viewer.World.Sky.Primitive.drawIndex = 1; Matrix viewXNASkyProj = XNAViewMatrix * Camera.XNASkyProjection; SkyShader.SetViewMatrix(ref XNAViewMatrix); SkyShader.Begin(); ShaderPassesSky.Reset(); while (ShaderPassesSky.MoveNext()) { ShaderPassesSky.Current.Begin(); foreach (var item in renderItems) { Matrix wvp = item.XNAMatrix * viewXNASkyProj; SkyShader.SetMatrix(ref wvp); SkyShader.CommitChanges(); item.RenderPrimitive.Draw(graphicsDevice); } ShaderPassesSky.Current.End(); } SkyShader.End(); // Moon SkyShader.CurrentTechnique = SkyShader.Techniques["Moon"]; Viewer.World.Sky.Primitive.drawIndex = 2; rs.AlphaBlendEnable = true; rs.CullMode = CullMode.CullClockwiseFace; rs.DestinationBlend = Blend.InverseSourceAlpha; rs.SourceBlend = Blend.SourceAlpha; // Send the transform matrices to the shader int skyRadius = Viewer.World.Sky.Primitive.skyRadius; int cloudRadiusDiff = Viewer.World.Sky.Primitive.cloudDomeRadiusDiff; XNAMoonMatrix = Matrix.CreateTranslation(Viewer.World.Sky.lunarDirection * (skyRadius - (cloudRadiusDiff / 2))); Matrix XNAMoonMatrixView = XNAMoonMatrix * XNAViewMatrix; SkyShader.Begin(); ShaderPassesMoon.Reset(); while (ShaderPassesMoon.MoveNext()) { ShaderPassesMoon.Current.Begin(); foreach (var item in renderItems) { Matrix wvp = item.XNAMatrix * XNAMoonMatrixView * Camera.XNASkyProjection; SkyShader.SetMatrix(ref wvp); SkyShader.CommitChanges(); item.RenderPrimitive.Draw(graphicsDevice); } ShaderPassesMoon.Current.End(); } SkyShader.End(); // Clouds SkyShader.CurrentTechnique = SkyShader.Techniques["Clouds"]; Viewer.World.Sky.Primitive.drawIndex = 3; rs.CullMode = CullMode.CullCounterClockwiseFace; SkyShader.Begin(); ShaderPassesClouds.Reset(); while (ShaderPassesClouds.MoveNext()) { ShaderPassesClouds.Current.Begin(); foreach (var item in renderItems) { Matrix wvp = item.XNAMatrix * viewXNASkyProj; SkyShader.SetMatrix(ref wvp); SkyShader.CommitChanges(); item.RenderPrimitive.Draw(graphicsDevice); } ShaderPassesClouds.Current.End(); } SkyShader.End(); }