Cesium 与 Babylon.js 可视化 glsl 特效篇(二十三)
我决定不从Babylonjs 基础来讲了 直接整合cesium与babylonjs可视化来讲
我整合一个类库 后续不断更新中
- npm i @haibalai/cesium-babylonjs
初始化cesium -babylonjs 类库, map 是cesium 的viewer对象
- import { BabylonMapManager } from "@haibalai/cesium-babylonjs";
- BabylonMapManager.init(map);
添加特效
- import { BabylonMapManager } from "@haibalai/cesium-babylonjs";
- const fragmentShader = `
- uniform float iTime;
- uniform vec2 iResolution;
- varying vec2 vUv;
- vec3 COLOR1 = vec3(0.0, 0.0, 0.3);
- vec3 COLOR2 = vec3(0.5, 0.0, 0.0);
- float BLOCK_WIDTH = 0.01;
- voidmain(void) {
- vec2 uv = (vUv - 0.3) * 2.0 ;
- // To create the BG pattern
- vec3 final_color = vec3(1.0);
- vec3 bg_color = vec3(0.0);
- vec3 wave_color = vec3(0.0);
- float c1 = mod(uv.x, 2.0 * BLOCK_WIDTH);
- c1 = step(BLOCK_WIDTH, c1);
- float c2 = mod(uv.y, 2.0 * BLOCK_WIDTH);
- c2 = step(BLOCK_WIDTH, c2);
- bg_color = mix(uv.x * COLOR1, uv.y * COLOR2, c1 * c2);
- // To create the waves
- float wave_width = 0.01;
- uv = -1.0 + 2.0 * uv;
- uv.y += 0.1;
- for(float i = 0.0; i < 10.0; i++) {
- uv.y += (0.07 * sin(uv.x + i/7.0 + iTime ));
- wave_width = abs(1.0 / (150.0 * uv.y));