Mapbox 與 Babylon.js 視覺化 glsl 特效篇(二十六)
阿新 • • 發佈:2022-12-09
我決定不從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;
- uniform vec2 iResolution;
- varying vec2 vUv;
- vec3 COLOR1 = vec3(0.0, 0.0, 0.3);
- vec3 COLOR2 = vec3(0.5, 0.0, 0.0);
- float BLOCK_WIDTH = 0.01;
- voidmain(void) {
- vec2 uv = (vUv - 0.3) * 2.0 ;
- // To create the BG pattern
- vec3 final_color = vec3(1.0);
- vec3 bg_color = vec3(0.0);
- vec3 wave_color = vec3(0.0);
- float c1 = mod(uv.x, 2.0 * BLOCK_WIDTH);
- c1 = step(BLOCK_WIDTH, c1);
- float c2 = mod(uv.y, 2.0 * BLOCK_WIDTH);
- c2 = step(BLOCK_WIDTH, c2);
- bg_color = mix(uv.x * COLOR1, uv.y * COLOR2, c1 * c2);