我决定不从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 = `
uniform float ratio;
float PI = 3.1415926;
uniform float iTime;
const vec2 iResolution = vec2(1.0,1.0);
varying vec2 vUv;
voidmain() {
vec2 p = (vUv - 0.5) * 2.0;
float tau = PI * 2.0;
float a = atan(p.x,p.y);
float r = length§*0.75;
vec2 uv = vec2(a/tau,r);
//get the color
float xCol = (uv.x - (iTime / 3.0)) * 3.0;
xCol = mod(xCol, 3.0);
vec3 horColour = vec3(0.25, 0.25, 0.25);
if (xCol < 1.0) {
horColour.r += 1.0 - xCol;
horColour.g += xCol;
}
elseif (xCol < 2.0) {
xCol -= 1.0;
horColour.g += 1.0 - xCol;
horColour.b += xCol;
}
else {
Mapbox 与 Babylon.js 可视化 glsl 特效篇(六) - 小专栏