Cesium 与 Babylon.js 可视化 glsl 特效篇(十七)
Posted haibalai
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Cesium 与 Babylon.js 可视化 glsl 特效篇(十七)相关的知识,希望对你有一定的参考价值。
我决定不从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 = `
- precision highp float;
- uniform float iTime;
- uniform vec2 iResolution;
- varying vec2 vUv;
- // Rand value between 0 and 1
- floatrand(vec2 p)
- return fract(sin(dot(p, vec2(12.543,514.123)))*4732.12);
- // Value noise
- floatnoise(vec2 p)
- vec2 f = smoothstep(0.0, 1.0, fract(p));
- vec2 i = floor(p);
- float a = rand(i);
- float b = rand(i+vec2(1.0,0.0));
- float c = rand(i+vec2(0.0,1.0));
- float d = rand(i+vec2(1.0,1.0));
- return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);
- // Fractal noise
- floatfbm(vec2 p)
- float a = 0.5;
- float r = 0.0;
- for (int i = 0; i < 8; i++)
- r += a*noise(p);
- a *= 0.5;
- p *= 2.0;
- return r;
- // Lasers originating from a central point
- floatlaser(vec2 p, int num)
- float r = atan(p.x, p.y);
- float sn = sin(r*float(num)+iTime);
- float lzr = 0.5+0.5*sn;
- lzr = lzr*lzr*lzr*lzr*lzr;
- float glow = pow(clamp(sn, 0.0, 1.0),100.0);
- return lzr+glow;
- // Mix of fractal noises to simulate fog
- floatclouds(vec2 uv)
- vec2 t = vec2(0,iTime);
- float c1 = fbm(fbm(uv*3.0)*0.75+uv*3.0+t/3.0);
- float c2 = fbm(fbm(uv*2.0)*0.5+uv*7.0+t/3.0);
- float c3 = fbm(fbm(uv*10.0-t)*0.75+uv*5.0+t/6.0);
- float r = mix(c1, c2, c3*c3);
- return r*r;
- voidmain(void)
- vec2 uv = (vUv - 0.4) * 2.0;
- vec2 hs = iResolution.xy/iResolution.y*0.5;
- vec2 uvc = uv-hs;
- float l = (1.0 + 3.0*noise(vec2(15.0-iTime)))
- * laser(vec2(uv.x+0.5, uv.y*(0.5 + 10.0*noise(vec2(iTime/5.0))) + 0.1), 15);
- l += fbm(vec2(2.0*iTime))
- * laser(vec2(hs.x-uvc.x-0.2, uv.y+0.1), 25);
- l += noise(vec2(iTime-73.0))
- * laser(vec2(uvc.x, 1.0-uv.y+0.5), 30);
- float c = clouds(uv);
- vec4 col = vec4(0, 1, 0, 1)*(uv.y*l+uv.y*uv.y)*c;
- gl_FragColor = pow(col, vec4(0.75));
- `;
- const vertexShader = `
- attribute vec3 position;
- attribute vec2 uv;
- varying vec2 vUv;
- uniform mat4 worldViewProjection;
- voidmain()
- vUv = uv;
- gl_Position = worldViewProjection * vec4(position, 1.0);
- `
- let map = baseMapCtrl.getViewer(this.mapId);
- let scene = BabylonMapManager.getScene(map);
以上是关于Cesium 与 Babylon.js 可视化 glsl 特效篇(十七)的主要内容,如果未能解决你的问题,请参考以下文章
Cesium 与 Babylon.js 可视化 glsl 特效篇(十四)
Cesium 与 Babylon.js 可视化 glsl 特效篇(十八)
Cesium 与 Babylon.js 可视化 glsl 特效篇(二十)
Cesium 与 Babylon.js 可视化 glsl 特效篇(十六)