Skip to main content

Graphics Tech in Cesium - Fog

We recently added fog to Cesium, which will be in the 1.16 release on December 1. Fog is a graphics technique for fading out distant geometry. Early games introduced fog to hide artifacts of geometry rendered in the distance. Even after it was no longer needed, games continued to support fog because it adds realism to the scene and reduces the number of draw calls since geometry completely in fog can be culled.

In Cesium, the fog is a blend of the atmosphere color and the terrain on the horizon. Terrain tiles that would be partially in fog will have their screen-space error increased, allowing lower-resolution terrain to be rendered. Terrain tiles that are completely in the fog will be culled completely or not even requested.

These optimizations decrease the number both of tiles rendered and of tiles requested from the server by 35% for horizon views.

Here's a mountainous view with the camera at a height of 3,600 meters and a pitch of -15 degrees:

In the top row, the third column shows the visual difference when using fog. For many applications, the user is not focused on distant terrain so the difference will be at worst not noticeable, and at best more visually appealing.

In the bottom row, the third column shows a visualization of the distant tiles that are culled due to fog. Note that many of those tiles were not visible at all.

Here's a flat view with the camera at a height of 490 meters and a pitch of 0 degrees:

There are three parameters to fog that can be set, which applications can take advantage of for further performance gains.

First, fog can be turned off altogether. If the viewer will be primarily in space, fog can safely be disabled, reducing the complexity of the shader for rendering the globe. It can also be disabled for top-down views, which do not benefit from fog as only tiles on the horizon are affected.

For applications where the viewer will be closer to the surface and look towards the horizon, fog can be adjusted with two properties: 'density' and screenSpaceErrorFactor. The density parameter is a scalar in the [0.0, 1.0] range that exponentially changes the start and end distance of the fog. The screenSpaceErrorFactor linearly increases the screen-space error of the terrain as the distance to the viewer increases and is partially obscured by fog.

Note that when fog is disabled, the higher resolution tiles on the horizon will act as a pre-fetch when the user drags the terrain to move forward. Changing the parameters to make the fog more aggressive may cause a more noticeable “popping” of the terrain tiles as higher resolutions tiles become available to render when the view changes quickly. In these cases, applications should either change the parameters to make fog less aggressive or disable it altogether.

Here's the previous views with the default values changed to be more aggressive (more fog, fewer tiles):

The leftmost column uses Cesium’s default values and produces the same results shown above. The middle column increases density and screenSpaceErrorFactor so more tiles are completely in fog (which are then culled) and the tiles in partial fog are rendered at a lower resolution. Note that fewer tiles are required (especially compared to no fog and especially for the second view with a low height and 0-degree pitch) at the cost of lower visual quality in the distance.