我决定不从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;
- floatrandom (in vec2 p) {
- vec3 p3 = fract(vec3(p.xyx) * .1031);
- p3 += dot(p3, p3.yzx + 33.33);
- return fract((p3.x + p3.y) * p3.z);
- }
- floatnoise (in vec2 _st) {
- vec2 i = floor(_st);
- vec2 f = fract(_st);
- // Four corners in 2D of a tile
- float a = random(i);
- float b = random(i + vec2(1.0, 0.0));
- float c = random(i + vec2(0.0, 1.0));
- float d = random(i + vec2(1.0, 1.0));
- vec2 u = f * f * (3. - 2.0 * f);
- return mix(a, b, u.x) +
- (c - a)* u.y * (1. - u.x) +
- (d - b) * u.x * u.y;
- }
- floatlight(in vec2 pos,infloat size,infloat radius,infloat inner_fade,infloat outer_fade){
- float len = length(pos/size);
- return pow(clamp((1.0 - pow( clamp(len-radius,0.0,1.0) , 1.0/inner_fade)),0.0,1.0),1.0/outer_fade);
- }
Mapbox 与 Babylon.js 可视化 glsl 特效篇(十五) - 小专栏
标签:glsl,p3,babylonjs,1.0,float,js,mapbox,vec2,Mapbox From: https://www.cnblogs.com/haibalai/p/16919507.html