我决定不从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 M_PI = 3.1415926;
- float M_TWO_PI = 6.28318530718;
- vec3 iMouse = vec3(0.0, 0.0 ,0.0 );
- uniform float iTime;
- const vec2 iResolution = vec2(1.0,1.0);
- varying vec2 vUv;
- floatrand(vec2 n) {
- return fract(sin(dot(n, vec2(12.9898,12.1414))) * 83758.5453);
- }
- floatnoise(vec2 n) {
- const vec2 d = vec2(0.0, 1.0);
- vec2 b = floor(n);
- vec2 f = smoothstep(vec2(0.0), vec2(1.0), fract(n));
- return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);
- }
- vec3 ramp(float t) {
- return t <= .5 ? vec3( 1. - t * 1.4, .2, 1.05 ) / t : vec3( .3 * (1. - t) * 2., .2, 1.05 ) / t;
- }
- vec2 polarMap(vec2 uv, float shift, float inner) {
- uv = vec2(0.5) - uv;
- float px = 1.0 - fract(atan(uv.y, uv.x) / 6.28 + 0.25) + shift;
- float py = (sqrt(uv.x * uv.x + uv.y * uv.y) * (1.0 + inner * 2.0) - inner) * 2.0;
- return vec2(px, py);
Mapbox 与 Babylon.js 可视化 glsl 特效篇(五) - 小专栏
标签:glsl,uv,1.0,0.0,float,js,mapbox,vec2,Mapbox From: https://www.cnblogs.com/haibalai/p/16919486.html