Arcgis 与 Claygl 可视化 glsl 特效篇(二十一)

发布时间 2023-04-18 09:38:44作者: haibalai

我决定不从claygl基础来讲了 直接整合arcgis与claygl可视化来讲
关于整合clagyl 有兴趣看我这篇文章 arcgis 与 claygl 引擎结合做地图可视化

我整合一个类库 后续不断更新中

  • npm i @haibalai/gismap4-claygl

 

初始化gismap4-claygl 类库, view是arcgis的sceneView对象

  • import { ClayglMapManager} from "@haibalai/gismap4-claygl";
  • ClayglMapManager.init(view);

 

添加特效

  • import { ClayglMapManager} from "@haibalai/gismap4-claygl";
  • import * as clay from "claygl";
  • const fragmentShader = `
  • uniform float iTime;
  • const vec2 iResolution = vec2(1.0,1.0);
  • varying vec2 iMouse;
  • varying vec2 vUv;
  • floatCircle(vec2 uv, vec2 pos, float r){
  • float d = length(uv - pos);
  • return r / d;
  • }
  • floatrandom(vec2 p)
  • {
  • return fract(sin(dot(vec2(100.,324.), p)) * 22141.);
  • }
  • voidmain(void) {
  • // vc - voronoi coords, mc - metaballs coords
  • vec2 vc = (vUv - 0.5) * 2.0;
  • vec2 mc = vc ;
  • vc.x *= iResolution.x/iResolution.y;
  • mc.x *= iResolution.x/iResolution.y;
  • // voronoi
  • vc *= 9.;
  • vec2 i = floor(vc);
  • vec2 gv = fract(vc) - .5;
  • float minDist = 1.;
  • for(float y = -1.; y <= 1.; y++)
  • {
  • for(float x = -1.; x <= 1.; x++)
  • {
  • vec2 o = vec2(x,y);
  • vec2 rp = vec2(random(i + o.xy), random(i + o.xy));
  • vec2 p = o + sin(rp * iTime) * .5;
  • float d = length(gv - p);
  • if(d < minDist){
  • minDist = d;
  • }
  • }
  • }
  • vec3 col = vec3(.5,.75,1.5) * minDist;
  • // metaballs
  • float r = .05;
  • float c = Circle(mc, vec2(sin(iTime * 2.) * .4, cos(iTime * .4) * .4), r);
  • c += Circle(mc, vec2(sin(iTime * .5) * .4, cos(iTime * .7) * .4), r);
  • c += Circle(mc, vec2(sin(iTime * .7) * .4, cos(iTime * .8) * .4), r);

Arcgis 与 Claygl 可视化 glsl 特效篇(二十一) - 小专栏