首页 > 其他分享 >Mapbox 与 Babylon.js 可视化 glsl 特效篇(三十)

Mapbox 与 Babylon.js 可视化 glsl 特效篇(三十)

时间:2022-12-09 20:01:40浏览次数:66  
标签:glsl babylonjs Mapbox kk float js vec2 mapbox dot

我决定不从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;
  • const vec2 iResolution = vec2(1.0,1.0);
  • varying vec2 vUv;
  • #define POINT_COUNT 8
  • vec2 points[POINT_COUNT];
  • constfloat speed = -0.5;
  • constfloat len = 0.25;
  • constfloat scale = 0.012;
  • float intensity = 1.3;
  • float radius = 0.015;
  • //https://www.shadertoy.com/view/MlKcDD
  • //Signed distance to a quadratic bezier
  • floatsdBezier(vec2 pos, vec2 A, vec2 B, vec2 C){
  • vec2 a = B - A;
  • vec2 b = A - 2.0*B + C;
  • vec2 c = a * 2.0;
  • vec2 d = A - pos;
  • float kk = 1.0 / dot(b,b);
  • float kx = kk * dot(a,b);
  • float ky = kk * (2.0*dot(a,a)+dot(d,b)) / 3.0;
  • float kz = kk * dot(d,a);

标签:glsl,babylonjs,Mapbox,kk,float,js,vec2,mapbox,dot
From: https://www.cnblogs.com/haibalai/p/16969864.html

相关文章