# Turn off skyAtmosphere after sunset?

**URL:** <https://community.cesium.com/t/turn-off-skyatmosphere-after-sunset/3311>\
**Category:** CesiumJS\
**Created:** [November 12, 2015, 9:39pm UTC](https://community.cesium.com/t/turn-off-skyatmosphere-after-sunset/3311 "2015-11-12T21:39:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Whalley](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/matt_whalley/32/2115_2.png) [@Matt\_Whalley](https://community.cesium.com/u/Matt_Whalley)\
**Post date:** [November 12, 2015, 9:39pm UTC](https://community.cesium.com/t/turn-off-skyatmosphere-after-sunset/3311/1 "2015-11-12T21:39:58Z")

</div>

I’m using Cesium for out-the-window visualization in a flight simulator. I’d like to hide/destroy the skyAtmosphere at night.

Any suggestions on how to determine if the sun has set?

Thanks, Matt.

---

<div class="post-metadata">

**Author:** ![Matt\_Amato](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/matt_amato/32/1993_2.png) [@Matt\_Amato](https://community.cesium.com/u/Matt_Amato)\
**Post date:** [November 12, 2015, 10:16pm UTC](https://community.cesium.com/t/turn-off-skyatmosphere-after-sunset/3311/2 "2015-11-12T22:16:43Z")

</div>

We actually had some code laying around to do something close to this. Here’s a Sandcastle example that uses the camera position to determine whether the sun is visible at that location and turns on/off atmosphere. Just replace viewer.scene.camera.position with whatever position you want. Eventually, we’ll probably have some cool built in visualization for this in Cesium itself.

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var transformMatrix = new Cesium.Matrix4();

var toSun = new Cesium.Cartesian3();

var toMoon = new Cesium.Cartesian3();

viewer.clock.onTick.addEventListener(function(clock) {

var position = viewer.scene.camera.position;

var up = viewer.scene.globe.ellipsoid.geodeticSurfaceNormal(position);

var time = clock.currentTime;

Cesium.Transforms.computeTemeToPseudoFixedMatrix(time, transformMatrix);

Cesium.Simon1994PlanetaryPositions.computeSunPositionInEarthInertialFrame(time, toSun);

Cesium.Matrix3.multiplyByVector(transformMatrix, toSun, toSun);

Cesium.Cartesian3.normalize(toSun, toSun);

viewer.scene.skyAtmosphere.show = Cesium.Cartesian3.dot(up, toSun) \> 0.0;

});

---

<div class="post-metadata">

**Author:** ![Matt\_Whalley](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/matt_whalley/32/2115_2.png) [@Matt\_Whalley](https://community.cesium.com/u/Matt_Whalley)\
**Post date:** [November 12, 2015, 11:08pm UTC](https://community.cesium.com/t/turn-off-skyatmosphere-after-sunset/3311/3 "2015-11-12T23:08:37Z")

</div>

Thanks!

I also found a nice little library for calculating the sun position:

[https://github.com/mourner/suncalc](https://github.com/mourner/suncalc)

my code:

function updateSkyAtmosphere() {

var dateNow = Cesium.JulianDate.toDate(viewer.clock.currentTime);

var sunPos = SunCalc.getPosition(dateNow, acState.lat, acState.lng);

viewer.scene.skyAtmosphere.show = sunPos.altitude \> 0;

}

---

<div class="post-metadata">

**Author:** ![TheSurfingCoder](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/thesurfingcoder/32/28173_2.png) [@TheSurfingCoder](https://community.cesium.com/u/TheSurfingCoder)\
**Post date:** [May 16, 2025, 3:37pm UTC](https://community.cesium.com/t/turn-off-skyatmosphere-after-sunset/3311/4 "2025-05-16T15:37:42Z")

</div>

I just tested this out yesterday and it worked great! I was trying to hack around in non-native ways, but this ended up being great.

However, i do think it’d be great to have a dynamic SkyAtmosphere property to change with sun altitude, similar to how you can do this for Atmosphere with scene.atmosphere.dynamicLighting = DynamicAtmosphereLightingType.SUNLIGHT;

I believe you guys already have something in place for Cesium Unreal, but it could be valuable for JS
