Cesium特效——城市白模的科技动效的各种效果

最终效果图如下:

实现方法:

步骤一:使用cesiumlib生产白模,格式为3dtiles

注意事项:采用其他方式可能导致白模贴地,从而导致不能实现该效果,例如把步骤二的服务地址改为Cesium Sandcastle 里的3dtiles服务,就不能实现效果图里的效果。原因是cesiumlib生成的白模服务本质上是错误的,是都在一个平面上。所以为保证精确度,场景需要小一些。

设置拉伸高度。

提交处理:

步骤二:设置样式(style)、customShader

导入3dtiles服务:

javascript 复制代码
  const tileset = await Cesium.Cesium3DTileset.fromUrl(
    "第一步生成的3dtiles数据发布的服务地址"
  );
  viewer.scene.primitives.add(tileset);

设置样式:

javascript 复制代码
const style = new Cesium.Cesium3DTileStyle({
    color: {
      conditions: [
        ["${Floor} < 10.0", "color('#00356A')"], // 深蓝色
        ["(${Floor} >= 10.0) && (${Floor} < 20.0)", "color('#0099FF')"], // 亮蓝色
        ["(${Floor} >= 20.0) && (${Floor} < 30.0)", "color('#0066CC')"], // 电蓝色
        ["(${Floor} >= 30.0) && (${Floor} < 60.0)", "color('#00FFFF')"], // 荧光蓝
        ["${Floor} >= 60.0", "color('#0033CC')"], // 深蓝色
      ],
    },
  });
tileset.style = style;

设置shader:

javascript 复制代码
// 增加自定义shader
  let customShader = new Cesium.CustomShader({
    //PBR(基于物理的渲染)或 UNLIT,具体取决于所需的结果。
    lightingModel: Cesium.LightingModel.UNLIT,
    fragmentShaderText: `
            void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {
                float _baseHeight = 0.0; // 物体的基础高度,需要修改成一个合适的建筑基础高度
                float _heightRange = 30.0; // 高亮的范围(_baseHeight ~ _baseHeight + _heightRange) 默认是 0-60米
                float _glowRange = 300.0; // 光环的移动范围(高度)
                float vtxf_height = fsInput.attributes.positionMC.z-_baseHeight;
                float vtxf_a11 = fract(czm_frameNumber / 120.0) * 3.14159265 * 2.0;
                float vtxf_a12 = vtxf_height / _heightRange + sin(vtxf_a11) * 0.1;
                material.diffuse*= vec3(vtxf_a12, vtxf_a12, vtxf_a12);
                float vtxf_a13 = fract(czm_frameNumber / 120.0);
                float vtxf_h = clamp(vtxf_height / _glowRange, 0.0, 1.0);
                vtxf_a13 = abs(vtxf_a13 - 0.5) * 2.0;
                float vtxf_diff = step(0.005, abs(vtxf_h - vtxf_a13));
                material.diffuse += material.diffuse * (1.0 - vtxf_diff);
            }	 	
            `,
  });
  tileset.customShader = customShader;
}
相关推荐
AI算力6 小时前
私有云时代来临:AI NAS如何重塑你的数字生活?
人工智能·科技·ai·生活·nas·ai算力·ainas
观察世界3 天前
字节 Seed 发布 Seedream 5.5:同一张图可编辑 100 轮,严重文字损坏率降至 0.4%
科技·ai
观察世界6 天前
前沿模型论坛发布越狱评级框架:给网络安全类越狱分等级,决定先修哪个
科技
昂永科技|非标件自动报价系统6 天前
# 昂永(上海)科技非标件自动核价系统落地无锡先导,助力制造核价数字化
大数据·科技·制造
行者无疆_ty6 天前
王兴兴:宇树未来将重点攻克机器人大脑——从「四肢发达」到「头脑不简单」,具身智能的临界点到了吗?
科技·热点追踪
硅谷秋水7 天前
面向科学的科学AI智能体:任务、架构、评估与挑战综述
人工智能·科技·语言模型
被放养的研究生7 天前
第五章 信息安全及信息科技风险管理
科技·金融监管计算机类
Laite_tech7 天前
XLED-400LED荧光光源在自动化高通量荧光成像LED的TTL触发与软件集成
科技
Laite_tech8 天前
XLED-400活细胞成像与多色动态成像技术优势
科技
量子客8 天前
发改委:重点发展量子科技等,带动资本投早、投小、投长期、投硬科技
科技