我决定不从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 = `
- #define TAU 6.28318530718
- #define MAX_ITER 5
- precision highp float;
- uniform float iTime;
- uniform vec2 iResolution;
- varying vec2 vUv;
- voidmain(void) {
- float time = iTime * .5+23.0;
- // uv should be the 0-1 uv of texture...
- vec2 uv = vUv;
- #ifdef SHOW_TILING
- vec2 p = mod(uv*TAU*2.0, TAU)-250.0;
- #else
- vec2 p = mod(uv*TAU, TAU)-250.0;
- #endif
- vec2 i = vec2(p);
- float c = 1.0;
- float inten = .005;
- for (int n = 0; n < MAX_ITER; n++)
- {
- float t = time * (1.0 - (3.5 / float(n+1)));
- i = p + vec2(cos(t - i.x) + sin(t + i.y), sin(t - i.y) + cos(t + i.x));
- c += 1.0/length(vec2(p.x / (sin(i.x+t)/inten),p.y / (cos(i.y+t)/inten)));
- }
Mapbox 与 Babylon.js 可视化 glsl 特效篇(十一) - 小专栏
标签:glsl,TAU,uv,Mapbox,float,js,vec2,mapbox,babylonjs From: https://www.cnblogs.com/haibalai/p/16919496.html