Arcgis 与 Claygl 可视化 glsl 特效篇(九)

发布时间 2023-04-18 09:36:43作者: 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 = `
  • constfloat ratio = 1.0;
  • float PI = 3.1415926;
  • uniform float iTime;
  • const vec2 iResolution = vec2(1.0,1.0);
  • varying vec2 vUv;
  • constfloat cloudscale = 1.1;
  • constfloat speed = 0.03;
  • constfloat clouddark = 0.5;
  • constfloat cloudlight = 0.3;
  • constfloat cloudcover = 0.2;
  • constfloat cloudalpha = 8.0;
  • constfloat skytint = 0.5;
  • const vec3 skycolour1 = vec3(0.2, 0.4, 0.6);
  • const vec3 skycolour2 = vec3(0.4, 0.7, 1.0);
  • const mat2 m = mat2( 1.6, 1.2, -1.2, 1.6 );
  • vec2 hash( vec2 p ) {
  • p = vec2(dot(p,vec2(127.1,311.7)), dot(p,vec2(269.5,183.3)));
  • return -1.0 + 2.0*fract(sin(p)*43758.5453123);
  • }
  • floatnoise( in vec2 p ) {
  • constfloat K1 = 0.366025404; // (sqrt(3)-1)/2;
  • constfloat K2 = 0.211324865; // (3-sqrt(3))/6;
  • vec2 i = floor(p + (p.x+p.y)*K1);
  • vec2 a = p - i + (i.x+i.y)*K2;
  • vec2 o = (a.x>a.y) ? vec2(1.0,0.0) : vec2(0.0,1.0); //vec2 of = 0.5 + 0.5*vec2(sign(a.x-a.y), sign(a.y-a.x));
  • vec2 b = a - o + K2;
  • vec2 c = a - 1.0 + 2.0*K2;
  • vec3 h = max(0.5-vec3(dot(a,a), dot(b,b), dot(c,c) ), 0.0 );
  • vec3 n = h*h*h*h*vec3( dot(a,hash(i+0.0)), dot(b,hash(i+o)), dot(c,hash(i+1.0)));
  • return dot(n, vec3(70.0));
  • }
  • floatfbm(vec2 n) {
  • float total = 0.0, amplitude = 0.1;
  • for (int i = 0; i < 7; i++) {
  • total += noise(n) * amplitude;
  • n = m * n;
  • amplitude *= 0.4;
  • }
  • return total;
  • }
  • voidmain() {
  • vec2 p = (vUv - 0.5) * 2.0;
  • vec2 uv = p*vec2(iResolution.x/iResolution.y,1.0);
  • float time = iTime * speed;
  • float q = fbm(uv * cloudscale * 0.5);
  • //ridged noise shape
  • float r = 0.0;
  • uv *= cloudscale;
  • uv -= q - time;
  • float weight = 0.8;
  • for (int i=0; i<8; i++){
  • r += abs(weight*noise( uv ));
  • uv = m*uv + time;
  • weight *= 0.7;
  • }
  • //noise shape
  • float f = 0.0;
  • uv = p*vec2(iResolution.x/iResolution.y,1.0);
  • uv *= cloudscale;
  • uv -= q - time;
  • weight = 0.7;
  • for (int i=0; i<8; i++){
  • f += weight*noise( uv );
  • uv = m*uv + time;
  • weight *= 0.6;
  • }
  • f *= r + f;
  • //noise colour
  • float c = 0.0;
  • time = iTime * speed * 2.0;
  • uv = p*vec2(iResolution.x/iResolution.y,1.0);
  • uv *= cloudscale*2.0;
  • uv -= q - time;
  • weight = 0.4;

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