跪拜 Guibai
← All articles
Cesium · WebGL · Vue.js

A Pure-Shader Sunset Glow for Cesium with a Real-Time Intensity Slider

By Tony费 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Cesium's `PostProcessStage` is the sanctioned extension point for screen-space effects, and this shader demonstrates the full recipe — multi-octave noise, masked regions, uniform-driven animation, and lifecycle-safe stage management — that any geospatial app can reuse for fog, storm fronts, or aurora overlays without pulling in a third-party library.

Summary

Six octaves of fractional Brownian motion noise, each with independent UV scaling and time offsets, generate irregular cloud textures that drift slowly across the scene. The shader blends an orange-red to golden-orange gradient based on local cloud density, and a smoothstep mask on the vertical texture coordinate keeps the effect strictly above the horizon — terrain and buildings remain untouched. A Vue 3 wrapper exposes a slider that pushes a `fireCloudStrength` uniform into the stage in real time, ranging from 0 to 0.8, and a toggle adds or removes the post-process stage from Cesium's pipeline without restarting the viewer. The animation loop runs on `requestAnimationFrame`, incrementing a time uniform to drive all three cloud layers at different speeds and directions.

Takeaways
Six FBM octaves with decreasing amplitude (0.52 start, 0.46 multiplier) and UV scaling by 2.2 per octave produce the cloud texture.
Three independent UV sets, each offset by different time-driven vectors, create parallax-like cloud motion.
A `smoothstep(0.05, 0.75, v_textureCoordinates.y)` mask restricts the effect to the sky, leaving terrain and buildings untouched.
The final color blends `vec3(1.0,0.42,0.18)` and `vec3(1.0,0.72,0.25)` according to the combined cloud density.
A slider updates the `fireCloudStrength` uniform (0–0.8) live; the toggle adds or removes the entire `PostProcessStage` from the pipeline.
The animation loop uses `requestAnimationFrame` to increment a `time` uniform by 0.016 each frame, driving all cloud layers.
Cleanup in `onUnmounted` removes the stage and destroys the viewer to free GPU resources.
Conclusions

The Y-axis mask is the detail that makes the effect usable in a real geospatial app — without it, the clouds would tint terrain and buildings, breaking the illusion.

Running three separate FBM evaluations with distinct UV scales and time offsets costs more GPU cycles than a single evaluation, but the visual payoff is cloud layers that move at different apparent depths, which a single noise field cannot fake.

Toggling the effect by adding and removing the `PostProcessStage` rather than setting a zero-strength uniform avoids wasting GPU time on a no-op shader pass.

Concepts & terms
PostProcessStage
A Cesium API that inserts a custom fragment shader into the rendering pipeline after the scene is drawn but before the frame is displayed, enabling full-screen effects like color grading, bloom, or weather overlays.
FBM (Fractional Brownian Motion) noise
A technique that sums multiple octaves of noise, each with increasing frequency and decreasing amplitude, to produce natural-looking textures with detail at many scales — widely used for clouds, terrain, and water.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗