Dark models depending on time of day

It’s probably not the case that the models are dark “in general”, but only when viewn from a certain direction (at a respective time). The effect can also be observed in the basic 3D Models Sandcastle at Cesium Sandcastle : When dragging the time-slider at the bottom, one can see that the plane is dark at some times. This is caused by the fact that the default light of the scene defaults to the light from the sun - and … well, at night, things tend to be dark.

(Unless you rotate the view, and see the plane from the bottom - the globe does not really cast a shadow, so to speak).

The proper solution depends on the exact requirements. A very simple, “static” solution would be to just use a fixed directional light (instead of the sunlight) - in the sandcastle, this could be

viewer.scene.light = new Cesium.DirectionalLight({
  direction : new Cesium.Cartesian3(0, 0.7, -0.5)
});

The direction might depend on the location of your model on the globe. If that changes, or there are multiple models, you could consider different options. A “generic” one could be to use the “flashlight” approach that is shown in Cesium Sandcastle : It sets up a directional light and adds a scene.preRender.addEventListener callback that updates the direction of this light, based on the camera direction, in each frame. Applied to the 3DModels example with the plane:

viewer.scene.light = new Cesium.DirectionalLight({
  direction: viewer.scene.camera.directionWC,
});
viewer.scene.preRender.addEventListener(function (scene, time) {
  viewer.scene.light.direction = Cesium.Cartesian3.clone(
    viewer.scene.camera.directionWC,
    viewer.scene.light.direction
  );
});

This way, the light direction will always be along the view direction of the camera, and the model should always appear bright.

3 Likes