我决定不从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;
const vec2 iResolution = vec2(1.0,1.0);
varying vec2 iMouse;
varying vec2 vUv;
floatCircle(vec2 uv, vec2 pos, float r){
float d = length(uv - pos);
return r / d;
}
floatrandom(vec2 p)
{
return fract(sin(dot(vec2(100.,324.), p)) * 22141.);
}
voidmain(void) {
// vc - voronoi coords, mc - metaballs coords
vec2 vc = (vUv - 0.5) * 2.0;
vec2 mc = vc ;
vc.x *= iResolution.x/iResolution.y;
mc.x *= iResolution.x/iResolution.y;
// voronoi
vc *= 9.;
vec2 i = floor(vc);
vec2 gv = fract(vc) - .5;
float minDist = 1.;
for(float y = -1.; y <= 1.; y++)
{
for(float x = -1.; x <= 1.; x++)
{
vec2 o = vec2(x,y);
vec2 rp = vec2(random(i + o.xy), random(i + o.xy));
vec2 p = o + sin(rp * iTime) * .5;
float d = length(gv - p);
Cesium 与 Babylon.js 可视化 glsl 特效篇(二十一) - 小专栏