我决定不从Babylonjs 基础来讲了 直接整合mapbox与babylonjs可视化来讲
我整合一个类库 后续不断更新中
- npm i @haibalai/mapbox-babylonjs
初始化mapbox-babylonjs 类库, map 是mapbox.gl 的map 对象
- import { BabylonMapManager } from "@haibalai/mapbox-babylonjs";
- BabylonMapManager.init(map);
添加特效
- import { BabylonMapManager } from "@haibalai/mapbox-babylonjs";
- const fragmentShader = `
- precision highp float;
- uniform float iTime;
- const vec2 iResolution = vec2(1.0,1.0);
- varying vec2 vUv;
- const mat2 m = mat2( 0.80, 0.60, -0.60, 0.80 );
- floatnoise( in vec2 p )
- {
- return sin(p.x)*sin(p.y);
- }
- floatfbm4( vec2 p )
- {
- float f = 0.0;
- f += 0.5000*noise( p ); p = m*p*2.02;
- f += 0.2500*noise( p ); p = m*p*2.03;
- f += 0.1250*noise( p ); p = m*p*2.01;
- f += 0.0625*noise( p );
- return f/0.9375;
- }
- floatfbm6( vec2 p )
- {
- float f = 0.0;
- f += 0.500000*(0.5+0.5*noise( p )); p = m*p*2.02;
- f += 0.250000*(0.5+0.5*noise( p )); p = m*p*2.03;
- f += 0.125000*(0.5+0.5*noise( p )); p = m*p*2.01;
- f += 0.062500*(0.5+0.5*noise( p )); p = m*p*2.04;
- f += 0.031250*(0.5+0.5*noise( p )); p = m*p*2.01;
- f += 0.015625*(0.5+0.5*noise( p ));
- return f/0.96875;
- }