public void RenderAtmosphere() { // blend between three standard textures depending on the time of day if (nightSkyTexture != null && daySkyTexture != null && cuspSkyTexture != null) { float sunPositionX = (float)(SUN_ORBIT_RADIUS * System.Math.Sin(2 * System.Math.PI * timeOfDay / HOURS_PER_DAY)); float sunPositionY = (float)(SUN_ORBIT_RADIUS * -System.Math.Cos(2 * System.Math.PI * timeOfDay / HOURS_PER_DAY) + _sunOrbitYOffset); float sunPositionZ = _sunOrbitZOffset; // offset from equator float alpha = 1 - 4 * Math.Abs(sunPositionY - _sunOrbitYOffset) / SUN_ORBIT_RADIUS; if (alpha < 0) { alpha = 0; } // first render the furthest if (timeOfDay < 6 || timeOfDay >= 18) { Engine.Atmosphere.SkySphere_SetTexture(nightSkyTexture.ID); Engine.LightEngine.set_EnableLight(_sunLight, false); Engine.LightEngine.set_EnableLight(_moonLight, true); } else { Engine.Atmosphere.SkySphere_SetTexture(daySkyTexture.ID); DxVBLibA.D3DLIGHT8 sunLight = Engine.LightEngine.GetLightByIndex(_sunLight); sunLight.Direction = Engine.Gl.Vector3(-sunPositionX, -sunPositionY, -sunPositionZ); float brightness = (1 - alpha) / 4F; float ambient = 0.2F; sunLight.ambient.r = ambient; sunLight.ambient.g = ambient; sunLight.ambient.b = ambient; sunLight.ambient.a = ambient; sunLight.diffuse.r = brightness; sunLight.diffuse.g = brightness; sunLight.diffuse.b = brightness; sunLight.diffuse.a = brightness; sunLight.specular.r = brightness; sunLight.specular.g = brightness; sunLight.specular.b = brightness; sunLight.specular.a = brightness; Engine.LightEngine.UpdateLight(_sunLight, ref sunLight); Engine.LightEngine.set_EnableLight(_sunLight, true); Engine.LightEngine.set_EnableLight(_moonLight, false); } Engine.Atmosphere.SkySphere_SetColor(1, 1, 1, 1); Engine.Atmosphere.Atmosphere_Render(); // now render the cusp, weighted by timeofday Engine.Atmosphere.SkySphere_SetTexture(cuspSkyTexture.ID); Engine.Atmosphere.SkySphere_SetColor(1, 1, 1, alpha); Engine.Atmosphere.Atmosphere_Render(); Engine.Atmosphere.Sun_SetPosition(sunPositionX, sunPositionY, sunPositionZ); } // render the atmosphere Engine.Atmosphere.Atmosphere_Render(); }
public void SetSky(ITexture day, ITexture night, ITexture cusp, ITexture sun) { nightSkyTexture = night; daySkyTexture = day; cuspSkyTexture = cusp; Engine.Atmosphere.SkySphere_Enable(true); Engine.Atmosphere.SkySphere_SetRadius(1000); Engine.Atmosphere.Sun_SetTexture(sun.ID); Engine.Atmosphere.Sun_SetBillboardSize(0.5f); Engine.Atmosphere.Sun_Enable(true); DxVBLibA.D3DLIGHT8 sunLight = new DxVBLibA.D3DLIGHT8(); sunLight.Type = DxVBLibA.CONST_D3DLIGHTTYPE.D3DLIGHT_DIRECTIONAL; sunLight.Direction = Engine.Gl.Vector3(1, -1, 0); sunLight.ambient = Engine.Gl.DXColor(0, 0, 0, 1); sunLight.diffuse = Engine.Gl.DXColor(1, 1, 1, 1); sunLight.specular = Engine.Gl.DXColor(1, 1, 1, 1); sunLight.Attenuation0 = 0; sunLight.Attenuation1 = 0; sunLight.Attenuation2 = 0; _sunLight = Engine.LightEngine.CreateLight(ref sunLight, "sun", false); _sunOrbitYOffset = 200; _sunOrbitZOffset = 200; DxVBLibA.D3DLIGHT8 moonLight = new DxVBLibA.D3DLIGHT8(); moonLight.Type = DxVBLibA.CONST_D3DLIGHTTYPE.D3DLIGHT_DIRECTIONAL; moonLight.Direction = Engine.Gl.Vector3(1, -1, 0); moonLight.ambient = Engine.Gl.DXColor(0.1f, 0.1f, 0.1f, 1); moonLight.diffuse = Engine.Gl.DXColor(0.1f, 0.1f, 0.1f, 1); moonLight.specular = Engine.Gl.DXColor(0.1f, 0.1f, 0.1f, 1); moonLight.Attenuation0 = 0; moonLight.Attenuation1 = 0; moonLight.Attenuation2 = 0; _moonLight = Engine.LightEngine.CreateLight(ref moonLight, "moon", false); }
public void SetSky( ITexture day, ITexture night, ITexture cusp, ITexture sun ) { nightSkyTexture = night; daySkyTexture = day; cuspSkyTexture = cusp; Engine.Atmosphere.SkySphere_Enable( true ); Engine.Atmosphere.SkySphere_SetRadius( 1000 ); Engine.Atmosphere.Sun_SetTexture(sun.ID); Engine.Atmosphere.Sun_SetBillboardSize(0.5f); Engine.Atmosphere.Sun_Enable(true); DxVBLibA.D3DLIGHT8 sunLight = new DxVBLibA.D3DLIGHT8(); sunLight.Type = DxVBLibA.CONST_D3DLIGHTTYPE.D3DLIGHT_DIRECTIONAL; sunLight.Direction = Engine.Gl.Vector3(1, -1, 0); sunLight.ambient = Engine.Gl.DXColor(0, 0, 0, 1); sunLight.diffuse = Engine.Gl.DXColor(1, 1, 1, 1); sunLight.specular = Engine.Gl.DXColor(1, 1, 1, 1); sunLight.Attenuation0 = 0; sunLight.Attenuation1 = 0; sunLight.Attenuation2 = 0; _sunLight = Engine.LightEngine.CreateLight(ref sunLight, "sun", false); _sunOrbitYOffset = 200; _sunOrbitZOffset = 200; DxVBLibA.D3DLIGHT8 moonLight = new DxVBLibA.D3DLIGHT8(); moonLight.Type = DxVBLibA.CONST_D3DLIGHTTYPE.D3DLIGHT_DIRECTIONAL; moonLight.Direction = Engine.Gl.Vector3(1, -1, 0); moonLight.ambient = Engine.Gl.DXColor(0.1f, 0.1f, 0.1f, 1); moonLight.diffuse = Engine.Gl.DXColor(0.1f, 0.1f, 0.1f, 1); moonLight.specular = Engine.Gl.DXColor(0.1f, 0.1f, 0.1f, 1); moonLight.Attenuation0 = 0; moonLight.Attenuation1 = 0; moonLight.Attenuation2 = 0; _moonLight = Engine.LightEngine.CreateLight(ref moonLight, "moon", false); }