我决定不从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 iTime;
- constfloat PI = 3.14159265359;
- floatrandom(float p){
- return fract(sin(p) * 10000.0);
- }
- floatnoise(vec2 p){
- float t = iTime / 2000.0;
- if(t > 1.0) t -= floor(t);
- return random(p.x * 14. + p.y * sin(t) * 0.5);
- }
- vec2 sw(vec2 p){
- return vec2(floor(p.x), floor(p.y));
- }
- vec2 se(vec2 p){
- return vec2(ceil(p.x), floor(p.y));
- }
- vec2 nw(vec2 p){
- return vec2(floor(p.x), ceil(p.y));
- }
- vec2 ne(vec2 p){
- return vec2(ceil(p.x), ceil(p.y));
- }
- floatsmoothNoise(vec2 p){
- vec2 inter = smoothstep(0.0, 1.0, fract(p));
- float s = mix(noise(sw(p)), noise(se(p)), inter.x);
- float n = mix(noise(nw(p)), noise(ne(p)), inter.x);
- return mix(s, n, inter.y);
- }
- mat2 rotate (infloat theta){
- float c = cos(theta);
- float s = sin(theta);
- return mat2(c, -s, s, c);
- }
- floatcirc(vec2 p){
- float r = length(p);
- r = log(sqrt(r));
- return abs(mod(4.0 * r, PI * 2.0) - PI) * 3.0 + 0.2;
- }
Mapbox 与 Babylon.js 可视化 glsl 特效篇(一) - 小专栏
标签:glsl,babylonjs,return,floor,float,js,mapbox,vec2,Mapbox From: https://www.cnblogs.com/haibalai/p/16919473.html