我决定不从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 = `
- #ifdef GL_ES
- precision mediump float;
- #endif
- #extension GL_OES_standard_derivatives : enable
- vec2 resolution = vec2(1.0,1.0);
- varying vec2 vUv;
- uniform float time;
- vec2 rotz(in vec2 p, float ang) { return vec2(p.x*cos(ang)-p.y*sin(ang),p.x*sin(ang)+p.y*cos(ang)); }
- voidmain( void ) {
- vec2 p = (vUv -0.5) * 2.0 ;
- p.x *= resolution.x/resolution.y;
- vec3 col = vec3(0);
- p = rotz(p, time*0.5+atan(p.y,p.x)*5.0);
- p *= 1.1+sin(time*0.5);
- for (int i = 0; i < 20; i++) {
- float dist = abs(p.y + sin(float(i)+time*0.1+3.0*p.x)) - 0.1;
- if (dist < 1.0) { col += (1.0-pow(abs(dist), 0.28))*vec3(0.8+0.2*sin(time),0.9+0.1*sin(time*1.1),1); }
- p *= 1.3;
- p = rotz(p, 30.0);
- p.y += 0.1*sin(0.5*time
- Cesium 与 Babylon.js 可视化 glsl 特效篇(三十七) - 小专栏