我决定不从Babylonjs 基础来讲了 直接整合cesium与babylonjs可视化来讲
我整合一个类库 后续不断更新中
- npm i @haibalai/cesium-babylonjs
初始化cesium -babylonjs 类库, map 是cesium 的viewer对象
- import { BabylonMapManager } from "@haibalai/cesium-babylonjs";
- BabylonMapManager.init(map);
添加特效
- import { BabylonMapManager } from "@haibalai/cesium-babylonjs";
- const fragmentShader = `
- #define TAU 6.28318530718
- #define MAX_ITER 5
- precision highp float;
- uniform float iTime;
- uniform vec2 iResolution;
- varying vec2 vUv;
- voidmain(void) {
- float time = iTime * .5+23.0;
- // uv should be the 0-1 uv of texture...
- vec2 uv = vUv;
- #ifdef SHOW_TILING
- vec2 p = mod(uv*TAU*2.0, TAU)-250.0;
- #else
- vec2 p = mod(uv*TAU, TAU)-250.0;
- #endif
- vec2 i = vec2(p);
- float c = 1.0;
- float inten = .005;
- for (int n = 0; n < MAX_ITER; n++)
- {
- float t = time * (1.0 - (3.5 / float(n+1)));
- i = p + vec2(cos(t - i.x) + sin(t + i.y), sin(t - i.y) + cos(t + i.x));
- c += 1.0/length(vec2(p.x / (sin(i.x+t)/inten),p.y / (cos(i.y+t)/inten)));
- }
- c /= float(MAX_ITER);
- c = 1.17-pow(c, 1.4);
- vec3 colour = vec3(pow(abs(c), 8.0));
Cesium 与 Babylon.js 可视化 glsl 特效篇(十一) - 小专栏
标签:glsl,TAU,uv,float,js,cesium,vec2,Cesium,babylonjs From: https://www.cnblogs.com/haibalai/p/17217420.html