我决定不从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;
- uniform vec2 iResolution;
- varying vec2 vUv;
- // Rand value between 0 and 1
- floatrand(vec2 p) {
- return fract(sin(dot(p, vec2(12.543,514.123)))*4732.12);
- }
- // Value noise
- floatnoise(vec2 p) {
- vec2 f = smoothstep(0.0, 1.0, fract(p));
- vec2 i = floor(p);
- float a = rand(i);
- float b = rand(i+vec2(1.0,0.0));
- float c = rand(i+vec2(0.0,1.0));
- float d = rand(i+vec2(1.0,1.0));
- return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);
- }
- // Fractal noise
- floatfbm(vec2 p) {
- float a = 0.5;
- float r = 0.0;
- for (int i = 0; i < 8; i++) {
- r += a*noise(p);
- a *= 0.5;
- p *= 2.0;
- }
- return r;
- }
Mapbox 与 Babylon.js 可视化 glsl 特效篇(十七) - 小专栏
标签:glsl,babylonjs,Mapbox,0.0,float,js,vec2,mapbox,1.0 From: https://www.cnblogs.com/haibalai/p/16969842.html