Atlaslog
Atlaslog / Examples / Cesium / Postprocess Bloom
Cesium · Runnable Example

Postprocess Bloom

Runnable Cesium example: Postprocess Bloom. Open the live demo, read the complete source, and copy the file into your project. No build step or API key.

Open standalone → Chinese notes All Cesium examples
/demos/cesium-postprocess-bloom.htmlLIVE
single HTML file · CDN dependencies onlyinterface may contain Chinese labels

Source

demos/cesium-postprocess-bloom.html
<!--
  示例:打开泛光让亮部溢出光晕
  要点:scene.postProcessStages.bloom 的 contrast、brightness 与 glowOnly 控制强光扩散
  依赖:CesiumJS 1.121 · jsDelivr CDN,发光对象由代码生成
-->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta name="robots" content="noindex,follow">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>泛光后处理</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cesium@1.121.0/Build/Cesium/Widgets/widgets.css">
<style>
  html,body{height:100%;margin:0}
  body{background:#0e1116;color:#e6e8ec;overflow:hidden;
       font:13px/1.6 -apple-system,"Segoe UI","PingFang SC",sans-serif}
  #c{height:100%}
  .hud{position:absolute;left:12px;top:12px;z-index:5;background:rgba(23,28,35,.92);
       border:1px solid #2a313b;border-radius:6px;padding:9px 12px;font-size:12px;
       color:#a2a9b6;width:250px}
  .hud b{color:#e6e8ec;font-weight:600}
  .hud .row{margin-top:7px}
  input[type=range]{width:100%}
  .hud button{font:inherit;font-size:12px;padding:3px 9px;border-radius:4px;cursor:pointer;
       border:1px solid #343b46;background:#1d232b;color:#cfd6e2;margin-top:8px}
  .hud button.on{background:#1d3a5c;border-color:#3d6f9e;color:#cfe4ff}
  .cesium-viewer-bottom .cesium-widget-credits,.cesium-viewer-animationContainer,
  .cesium-viewer-timelineContainer{display:none!important}
</style>
</head>
<body>
<div id="c"></div>
<div class="hud">
  <div><b>泛光</b></div>
  <div class="row">对比阈值 <span id="cVal">130</span></div>
  <div class="row"><input id="c" type="range" min="60" max="240" step="5" value="130"></div>
  <div class="row">亮度 <span id="bVal">-0.15</span></div>
  <div class="row"><input id="b" type="range" min="-0.6" max="0.6" step="0.05" value="-0.15"></div>
  <div class="row"><button id="glow">只显示光晕</button></div>
</div>
<script src="https://cdn.jsdelivr.net/npm/cesium@1.121.0/Build/Cesium/Cesium.js"></script>
<script>
(function () {
  'use strict';

  var viewer = new Cesium.Viewer('c', {
    baseLayer: false,
    baseLayerPicker: false, geocoder: false, homeButton: false,
    sceneModePicker: false, navigationHelpButton: false,
    animation: false, timeline: false, fullscreenButton: false,
    infoBox: false, selectionIndicator: false
  });

  var scene = viewer.scene;
  scene.globe.baseColor = Cesium.Color.fromCssColorString('#141c26');
  scene.backgroundColor = Cesium.Color.fromCssColorString('#080b10');
  scene.skyBox.show = false;
  scene.sun.show = false;
  scene.moon.show = false;
  if (scene.skyAtmosphere) scene.skyAtmosphere.show = false;

  /* 一排高亮球体与点,作为泛光源 */
  var LIGHTS = [
    [116.372, 39.902, '#7ad4ff', 160],
    [116.384, 39.906, '#ffd166', 200],
    [116.396, 39.903, '#8affc1', 170],
    [116.406, 39.908, '#ff8fa3', 220]
  ];

  LIGHTS.forEach(function (l) {
    viewer.entities.add({
      position: Cesium.Cartesian3.fromDegrees(l[0], l[1], l[3] / 2),
      ellipsoid: {
        radii: new Cesium.Cartesian3(l[3], l[3], l[3]),
        material: Cesium.Color.fromCssColorString(l[2])
      }
    });
    viewer.entities.add({
      position: Cesium.Cartesian3.fromDegrees(l[0], l[1], l[3] + 90),
      point: {
        pixelSize: 18,
        color: Cesium.Color.fromCssColorString(l[2]),
        disableDepthTestDistance: Number.POSITIVE_INFINITY
      }
    });
  });

  /* 暗色底座,衬托光晕 */
  viewer.entities.add({
    position: Cesium.Cartesian3.fromDegrees(116.389, 39.906, -10),
    box: {
      dimensions: new Cesium.Cartesian3(4200, 1600, 20),
      material: Cesium.Color.fromCssColorString('#1b2532')
    }
  });

  var bloom = scene.postProcessStages.bloom;
  bloom.enabled = true;
  bloom.uniforms.contrast = 130;
  bloom.uniforms.brightness = -0.15;
  bloom.uniforms.glowOnly = false;

  document.getElementById('c').addEventListener('input', function () {
    bloom.uniforms.contrast = parseFloat(this.value);
    document.getElementById('cVal').textContent = this.value;
  });

  document.getElementById('b').addEventListener('input', function () {
    bloom.uniforms.brightness = parseFloat(this.value);
    document.getElementById('bVal').textContent = parseFloat(this.value).toFixed(2);
  });

  document.getElementById('glow').addEventListener('click', function () {
    bloom.uniforms.glowOnly = !bloom.uniforms.glowOnly;
    this.className = bloom.uniforms.glowOnly ? 'on' : '';
  });

  viewer.camera.flyTo({
    destination: Cesium.Cartesian3.fromDegrees(116.389, 39.884, 2100),
    orientation: {
      heading: 0,
      pitch: Cesium.Math.toRadians(-20),
      roll: 0
    },
    duration: 0
  });
})();
</script>
</body>
</html>
Language: the code and this page are in English; the full tutorial and API notes for this example are in Chinese. The demo itself is the authoritative version — it runs exactly as shown.

More Cesium examples

Cesium · EXAMPLEPostprocess Color Cesium · EXAMPLEProcedural Terrain Cesium · EXAMPLEProjection