我决定不从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 vUv;
floathash(float x)
{
return fract(21654.6512 * sin(385.51 * x));
}
floathash(vec2 p)
{
return fract(21654.65155 * sin(35.51 * p.x + 45.51 * p.y));
}
floatlhash(float x, float y)
{
float h = 0.0;
for(int i = 0;i < 5;i++)
{
h += (fract(21654.65155 * float(i) * sin(35.51 * x + 45.51 * float(i) * y * (5.0 / float(i))))* 2.0 - 1.0) / 10.0;
}
return h / 5.0 + 0.02;
return (fract(21654.65155 * sin(35.51 * x + 45.51 * y))* 2.0 - 1.0) / 20.0;
}
floatnoise(vec2 p)
{
vec2 fl = floor§;
vec2 fr = fract§;
fr.x = smoothstep(0.0,1.0,fr.x);
fr.y = smoothstep(0.0,1.0,fr.y);
float a = mix(hash(fl + vec2(0.0,0.0)), hash(fl + vec2(1.0,0.0)),fr.x);
float b = mix(hash(fl + vec2(0.0,1.0)), hash(fl + vec2(1.0,1.0)),fr.x);
return mix(a,b,fr.y);
}
//Fractal Brownian Motion
floatfbm(vec2 p)
{
float v = 0.0, f = 1.0, a = 0.5;
for(int i = 0;i < 5; i++)
{
v += noise(p * f) * a;
Cesium 与 Babylon.js 可视化 glsl 特效篇(三十一) - 小专栏