@deck.gl/extensions 8.9.0-alpha.4 → 8.9.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +3688 -14538
- package/dist/es5/brushing/brushing.js +0 -8
- package/dist/es5/brushing/brushing.js.map +1 -1
- package/dist/es5/clip/clip.js +5 -5
- package/dist/es5/clip/clip.js.map +1 -1
- package/dist/es5/collide/collide-effect.js +285 -0
- package/dist/es5/collide/collide-effect.js.map +1 -0
- package/dist/es5/collide/collide-pass.js +80 -0
- package/dist/es5/collide/collide-pass.js.map +1 -0
- package/dist/es5/collide/collide.js +116 -0
- package/dist/es5/collide/collide.js.map +1 -0
- package/dist/es5/collide/shader-module.js +39 -0
- package/dist/es5/collide/shader-module.js.map +1 -0
- package/dist/es5/common/projection-utils.js +164 -0
- package/dist/es5/common/projection-utils.js.map +1 -0
- package/dist/es5/data-filter/shader-module.js +1 -0
- package/dist/es5/data-filter/shader-module.js.map +1 -1
- package/dist/es5/fill-style/fill-style.js +16 -125
- package/dist/es5/fill-style/fill-style.js.map +1 -1
- package/dist/es5/fill-style/shaders.glsl.js +6 -8
- package/dist/es5/fill-style/shaders.glsl.js.map +1 -1
- package/dist/es5/fp64/project64.glsl.js +1 -1
- package/dist/es5/index.js +16 -0
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/mask/mask-effect.js +280 -0
- package/dist/es5/mask/mask-effect.js.map +1 -0
- package/dist/es5/mask/mask-pass.js +106 -0
- package/dist/es5/mask/mask-pass.js.map +1 -0
- package/dist/es5/mask/mask.js +17 -4
- package/dist/es5/mask/mask.js.map +1 -1
- package/dist/es5/mask/shader-module.js +1 -1
- package/dist/es5/mask/shader-module.js.map +1 -1
- package/dist/es5/mask/utils.js +136 -0
- package/dist/es5/mask/utils.js.map +1 -0
- package/dist/es5/path-style/shaders.glsl.js +1 -1
- package/dist/es5/terrain/height-map-builder.js +116 -0
- package/dist/es5/terrain/height-map-builder.js.map +1 -0
- package/dist/es5/terrain/shader-module.js +84 -0
- package/dist/es5/terrain/shader-module.js.map +1 -0
- package/dist/es5/terrain/terrain-cover.js +259 -0
- package/dist/es5/terrain/terrain-cover.js.map +1 -0
- package/dist/es5/terrain/terrain-effect.js +337 -0
- package/dist/es5/terrain/terrain-effect.js.map +1 -0
- package/dist/es5/terrain/terrain-pass.js +122 -0
- package/dist/es5/terrain/terrain-pass.js.map +1 -0
- package/dist/es5/terrain/terrain-picking-pass.js +130 -0
- package/dist/es5/terrain/terrain-picking-pass.js.map +1 -0
- package/dist/es5/terrain/terrain.js +101 -0
- package/dist/es5/terrain/terrain.js.map +1 -0
- package/dist/es5/terrain/utils.js +32 -0
- package/dist/es5/terrain/utils.js.map +1 -0
- package/dist/es5/utils/debug.js +71 -0
- package/dist/es5/utils/debug.js.map +1 -0
- package/dist/esm/brushing/brushing.js +0 -7
- package/dist/esm/brushing/brushing.js.map +1 -1
- package/dist/esm/clip/clip.js +5 -4
- package/dist/esm/clip/clip.js.map +1 -1
- package/dist/esm/collide/collide-effect.js +250 -0
- package/dist/esm/collide/collide-effect.js.map +1 -0
- package/dist/esm/collide/collide-pass.js +30 -0
- package/dist/esm/collide/collide-pass.js.map +1 -0
- package/dist/esm/collide/collide.js +78 -0
- package/dist/esm/collide/collide.js.map +1 -0
- package/dist/esm/collide/shader-module.js +32 -0
- package/dist/esm/collide/shader-module.js.map +1 -0
- package/dist/esm/common/projection-utils.js +130 -0
- package/dist/esm/common/projection-utils.js.map +1 -0
- package/dist/esm/data-filter/shader-module.js +1 -0
- package/dist/esm/data-filter/shader-module.js.map +1 -1
- package/dist/esm/fill-style/fill-style.js +20 -72
- package/dist/esm/fill-style/fill-style.js.map +1 -1
- package/dist/esm/fill-style/shaders.glsl.js +5 -7
- package/dist/esm/fill-style/shaders.glsl.js.map +1 -1
- package/dist/esm/fp64/project64.glsl.js +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/mask/mask-effect.js +233 -0
- package/dist/esm/mask/mask-effect.js.map +1 -0
- package/dist/esm/mask/mask-pass.js +62 -0
- package/dist/esm/mask/mask-pass.js.map +1 -0
- package/dist/esm/mask/mask.js +14 -3
- package/dist/esm/mask/mask.js.map +1 -1
- package/dist/esm/mask/shader-module.js +1 -1
- package/dist/esm/mask/shader-module.js.map +1 -1
- package/dist/esm/mask/utils.js +109 -0
- package/dist/esm/mask/utils.js.map +1 -0
- package/dist/esm/path-style/shaders.glsl.js +1 -1
- package/dist/esm/terrain/height-map-builder.js +92 -0
- package/dist/esm/terrain/height-map-builder.js.map +1 -0
- package/dist/esm/terrain/shader-module.js +73 -0
- package/dist/esm/terrain/shader-module.js.map +1 -0
- package/dist/esm/terrain/terrain-cover.js +219 -0
- package/dist/esm/terrain/terrain-cover.js.map +1 -0
- package/dist/esm/terrain/terrain-effect.js +231 -0
- package/dist/esm/terrain/terrain-effect.js.map +1 -0
- package/dist/esm/terrain/terrain-pass.js +69 -0
- package/dist/esm/terrain/terrain-pass.js.map +1 -0
- package/dist/esm/terrain/terrain-picking-pass.js +75 -0
- package/dist/esm/terrain/terrain-picking-pass.js.map +1 -0
- package/dist/esm/terrain/terrain.js +62 -0
- package/dist/esm/terrain/terrain.js.map +1 -0
- package/dist/esm/terrain/utils.js +21 -0
- package/dist/esm/terrain/utils.js.map +1 -0
- package/dist/esm/utils/debug.js +61 -0
- package/dist/esm/utils/debug.js.map +1 -0
- package/dist.min.js +1359 -1
- package/package.json +6 -4
- package/src/brushing/brushing.ts +0 -11
- package/src/clip/clip.ts +6 -5
- package/src/collide/collide-effect.ts +257 -0
- package/src/collide/collide-pass.ts +35 -0
- package/src/collide/collide.ts +79 -0
- package/src/collide/shader-module.ts +113 -0
- package/src/common/projection-utils.ts +187 -0
- package/src/data-filter/shader-module.ts +6 -0
- package/src/fill-style/fill-style.ts +15 -53
- package/src/fill-style/shaders.glsl.ts +6 -7
- package/src/index.ts +4 -0
- package/src/mask/mask-effect.ts +255 -0
- package/src/mask/mask-pass.ts +67 -0
- package/src/mask/mask.ts +17 -7
- package/src/mask/shader-module.ts +7 -1
- package/src/mask/utils.ts +148 -0
- package/src/terrain/height-map-builder.ts +120 -0
- package/src/terrain/shader-module.ts +161 -0
- package/src/terrain/terrain-cover.ts +225 -0
- package/src/terrain/terrain-effect.ts +223 -0
- package/src/terrain/terrain-pass.ts +86 -0
- package/src/terrain/terrain-picking-pass.ts +87 -0
- package/src/terrain/terrain.ts +74 -0
- package/src/terrain/utils.ts +29 -0
- package/src/utils/debug.ts +59 -0
- package/typed/brushing/brushing.d.ts +0 -1
- package/typed/brushing/brushing.d.ts.map +1 -1
- package/typed/brushing/brushing.js +83 -0
- package/typed/brushing/shader-module.js +116 -0
- package/typed/clip/clip.d.ts +1 -1
- package/typed/clip/clip.d.ts.map +1 -1
- package/typed/clip/clip.js +114 -0
- package/typed/collide/collide-effect.d.ts +28 -0
- package/typed/collide/collide-effect.d.ts.map +1 -0
- package/typed/collide/collide-pass.d.ts +14 -0
- package/typed/collide/collide-pass.d.ts.map +1 -0
- package/typed/collide/collide.d.ts +41 -0
- package/typed/collide/collide.d.ts.map +1 -0
- package/typed/collide/shader-module.d.ts +4 -0
- package/typed/collide/shader-module.d.ts.map +1 -0
- package/typed/common/projection-utils.d.ts +27 -0
- package/typed/common/projection-utils.d.ts.map +1 -0
- package/typed/data-filter/aggregator.js +98 -0
- package/typed/data-filter/data-filter.js +159 -0
- package/typed/data-filter/shader-module.d.ts.map +1 -1
- package/typed/data-filter/shader-module.js +152 -0
- package/typed/fill-style/fill-style.d.ts +14 -5
- package/typed/fill-style/fill-style.d.ts.map +1 -1
- package/typed/fill-style/fill-style.js +152 -0
- package/typed/fill-style/shaders.glsl.d.ts.map +1 -1
- package/typed/fill-style/shaders.glsl.js +95 -0
- package/typed/fp64/fp64.js +34 -0
- package/typed/fp64/project64.glsl.js +100 -0
- package/typed/fp64/project64.js +50 -0
- package/typed/index.d.ts +4 -0
- package/typed/index.d.ts.map +1 -1
- package/typed/index.js +9 -0
- package/typed/mask/mask-effect.d.ts +42 -0
- package/typed/mask/mask-effect.d.ts.map +1 -0
- package/typed/mask/mask-pass.d.ts +19 -0
- package/typed/mask/mask-pass.d.ts.map +1 -0
- package/typed/mask/mask.d.ts +9 -3
- package/typed/mask/mask.d.ts.map +1 -1
- package/typed/mask/mask.js +48 -0
- package/typed/mask/shader-module.d.ts.map +1 -1
- package/typed/mask/shader-module.js +73 -0
- package/typed/mask/utils.d.ts +13 -0
- package/typed/mask/utils.d.ts.map +1 -0
- package/typed/path-style/path-style.js +107 -0
- package/typed/path-style/shaders.glsl.js +93 -0
- package/typed/terrain/height-map-builder.d.ts +38 -0
- package/typed/terrain/height-map-builder.d.ts.map +1 -0
- package/typed/terrain/height-map.d.ts +27 -0
- package/typed/terrain/height-map.d.ts.map +1 -0
- package/typed/terrain/shader-module-offset.d.ts +4 -0
- package/typed/terrain/shader-module-offset.d.ts.map +1 -0
- package/typed/terrain/shader-module-source.d.ts +4 -0
- package/typed/terrain/shader-module-source.d.ts.map +1 -0
- package/typed/terrain/shader-module.d.ts +31 -0
- package/typed/terrain/shader-module.d.ts.map +1 -0
- package/typed/terrain/terrain-cover.d.ts +46 -0
- package/typed/terrain/terrain-cover.d.ts.map +1 -0
- package/typed/terrain/terrain-effect.d.ts +29 -0
- package/typed/terrain/terrain-effect.d.ts.map +1 -0
- package/typed/terrain/terrain-pass.d.ts +11 -0
- package/typed/terrain/terrain-pass.d.ts.map +1 -0
- package/typed/terrain/terrain-picking-pass.d.ts +19 -0
- package/typed/terrain/terrain-picking-pass.d.ts.map +1 -0
- package/typed/terrain/terrain.d.ts +21 -0
- package/typed/terrain/terrain.d.ts.map +1 -0
- package/typed/terrain/utils.d.ts +5 -0
- package/typed/terrain/utils.d.ts.map +1 -0
- package/typed/utils/debug.d.ts +6 -0
- package/typed/utils/debug.d.ts.map +1 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
import { Framebuffer, Texture2D, withParameters } from '@luma.gl/core';
|
|
3
|
+
import { _LayersPass as LayersPass } from '@deck.gl/core';
|
|
4
|
+
export default class MaskPass extends LayersPass {
|
|
5
|
+
constructor(gl, props) {
|
|
6
|
+
super(gl, props);
|
|
7
|
+
|
|
8
|
+
_defineProperty(this, "maskMap", void 0);
|
|
9
|
+
|
|
10
|
+
_defineProperty(this, "fbo", void 0);
|
|
11
|
+
|
|
12
|
+
const {
|
|
13
|
+
mapSize = 2048
|
|
14
|
+
} = props;
|
|
15
|
+
this.maskMap = new Texture2D(gl, {
|
|
16
|
+
width: mapSize,
|
|
17
|
+
height: mapSize,
|
|
18
|
+
parameters: {
|
|
19
|
+
[10241]: 9729,
|
|
20
|
+
[10240]: 9729,
|
|
21
|
+
[10242]: 33071,
|
|
22
|
+
[10243]: 33071
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
this.fbo = new Framebuffer(gl, {
|
|
26
|
+
id: 'maskmap',
|
|
27
|
+
width: mapSize,
|
|
28
|
+
height: mapSize,
|
|
29
|
+
attachments: {
|
|
30
|
+
[36064]: this.maskMap
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
render(options) {
|
|
36
|
+
const gl = this.gl;
|
|
37
|
+
const colorMask = [false, false, false, false];
|
|
38
|
+
colorMask[options.channel] = true;
|
|
39
|
+
return withParameters(gl, {
|
|
40
|
+
clearColor: [255, 255, 255, 255],
|
|
41
|
+
blend: true,
|
|
42
|
+
blendFunc: [0, 1],
|
|
43
|
+
blendEquation: 32778,
|
|
44
|
+
colorMask,
|
|
45
|
+
depthTest: false
|
|
46
|
+
}, () => super.render({ ...options,
|
|
47
|
+
target: this.fbo,
|
|
48
|
+
pass: 'mask'
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
shouldDrawLayer(layer) {
|
|
53
|
+
return layer.props.operation.includes('mask');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
delete() {
|
|
57
|
+
this.fbo.delete();
|
|
58
|
+
this.maskMap.delete();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=mask-pass.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/mask/mask-pass.ts"],"names":["Framebuffer","Texture2D","withParameters","_LayersPass","LayersPass","MaskPass","constructor","gl","props","mapSize","maskMap","width","height","parameters","fbo","id","attachments","render","options","colorMask","channel","clearColor","blend","blendFunc","blendEquation","depthTest","target","pass","shouldDrawLayer","layer","operation","includes","delete"],"mappings":";AAAA,SAAQA,WAAR,EAAqBC,SAArB,EAAgCC,cAAhC,QAAqD,eAArD;AACA,SAAQC,WAAW,IAAIC,UAAvB,QAAiE,eAAjE;AAOA,eAAe,MAAMC,QAAN,SAAuBD,UAAvB,CAAkC;AAI/CE,EAAAA,WAAW,CAACC,EAAD,EAAKC,KAAL,EAA4C;AACrD,UAAMD,EAAN,EAAUC,KAAV;;AADqD;;AAAA;;AAGrD,UAAM;AAACC,MAAAA,OAAO,GAAG;AAAX,QAAmBD,KAAzB;AAEA,SAAKE,OAAL,GAAe,IAAIT,SAAJ,CAAcM,EAAd,EAAkB;AAC/BI,MAAAA,KAAK,EAAEF,OADwB;AAE/BG,MAAAA,MAAM,EAAEH,OAFuB;AAG/BI,MAAAA,UAAU,EAAE;AACV,qBADU;AAEV,qBAFU;AAGV,sBAHU;AAIV;AAJU;AAHmB,KAAlB,CAAf;AAWA,SAAKC,GAAL,GAAW,IAAId,WAAJ,CAAgBO,EAAhB,EAAoB;AAC7BQ,MAAAA,EAAE,EAAE,SADyB;AAE7BJ,MAAAA,KAAK,EAAEF,OAFsB;AAG7BG,MAAAA,MAAM,EAAEH,OAHqB;AAI7BO,MAAAA,WAAW,EAAE;AACX,iBAAwB,KAAKN;AADlB;AAJgB,KAApB,CAAX;AAQD;;AAEDO,EAAAA,MAAM,CAACC,OAAD,EAAiC;AACrC,UAAMX,EAAE,GAAG,KAAKA,EAAhB;AAEA,UAAMY,SAAS,GAAG,CAAC,KAAD,EAAQ,KAAR,EAAe,KAAf,EAAsB,KAAtB,CAAlB;AACAA,IAAAA,SAAS,CAACD,OAAO,CAACE,OAAT,CAAT,GAA6B,IAA7B;AAEA,WAAOlB,cAAc,CACnBK,EADmB,EAEnB;AACEc,MAAAA,UAAU,EAAE,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,EAAgB,GAAhB,CADd;AAEEC,MAAAA,KAAK,EAAE,IAFT;AAGEC,MAAAA,SAAS,EAAE,MAHb;AAIEC,MAAAA,aAAa,OAJf;AAKEL,MAAAA,SALF;AAMEM,MAAAA,SAAS,EAAE;AANb,KAFmB,EAUnB,MAAM,MAAMR,MAAN,CAAa,EAAC,GAAGC,OAAJ;AAAaQ,MAAAA,MAAM,EAAE,KAAKZ,GAA1B;AAA+Ba,MAAAA,IAAI,EAAE;AAArC,KAAb,CAVa,CAArB;AAYD;;AAEDC,EAAAA,eAAe,CAACC,KAAD,EAAQ;AACrB,WAAOA,KAAK,CAACrB,KAAN,CAAYsB,SAAZ,CAAsBC,QAAtB,CAA+B,MAA/B,CAAP;AACD;;AAEDC,EAAAA,MAAM,GAAG;AACP,SAAKlB,GAAL,CAASkB,MAAT;AACA,SAAKtB,OAAL,CAAasB,MAAb;AACD;;AAzD8C","sourcesContent":["import {Framebuffer, Texture2D, withParameters} from '@luma.gl/core';\nimport {_LayersPass as LayersPass, LayersPassRenderOptions} from '@deck.gl/core';\n\ntype MaskPassRenderOptions = LayersPassRenderOptions & {\n /** The channel to render into, 0:red, 1:green, 2:blue, 3:alpha */\n channel: number;\n};\n\nexport default class MaskPass extends LayersPass {\n maskMap: Texture2D;\n fbo: Framebuffer;\n\n constructor(gl, props: {id: string; mapSize?: number}) {\n super(gl, props);\n\n const {mapSize = 2048} = props;\n\n this.maskMap = new Texture2D(gl, {\n width: mapSize,\n height: mapSize,\n parameters: {\n [gl.TEXTURE_MIN_FILTER]: gl.LINEAR,\n [gl.TEXTURE_MAG_FILTER]: gl.LINEAR,\n [gl.TEXTURE_WRAP_S]: gl.CLAMP_TO_EDGE,\n [gl.TEXTURE_WRAP_T]: gl.CLAMP_TO_EDGE\n }\n });\n\n this.fbo = new Framebuffer(gl, {\n id: 'maskmap',\n width: mapSize,\n height: mapSize,\n attachments: {\n [gl.COLOR_ATTACHMENT0]: this.maskMap\n }\n });\n }\n\n render(options: MaskPassRenderOptions) {\n const gl = this.gl;\n\n const colorMask = [false, false, false, false];\n colorMask[options.channel] = true;\n\n return withParameters(\n gl,\n {\n clearColor: [255, 255, 255, 255],\n blend: true,\n blendFunc: [gl.ZERO, gl.ONE],\n blendEquation: gl.FUNC_SUBTRACT,\n colorMask,\n depthTest: false\n },\n () => super.render({...options, target: this.fbo, pass: 'mask'})\n );\n }\n\n shouldDrawLayer(layer) {\n return layer.props.operation.includes('mask');\n }\n\n delete() {\n this.fbo.delete();\n this.maskMap.delete();\n }\n}\n"],"file":"mask-pass.js"}
|
package/dist/esm/mask/mask.js
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
2
|
import { COORDINATE_SYSTEM, LayerExtension, log } from '@deck.gl/core';
|
|
3
3
|
import mask from './shader-module';
|
|
4
|
+
import MaskEffect from './mask-effect';
|
|
4
5
|
const defaultProps = {
|
|
5
|
-
maskId: ''
|
|
6
|
+
maskId: '',
|
|
7
|
+
maskByInstance: undefined,
|
|
8
|
+
maskInverted: false
|
|
6
9
|
};
|
|
7
10
|
export default class MaskExtension extends LayerExtension {
|
|
11
|
+
initializeState() {
|
|
12
|
+
var _this$context$deck;
|
|
13
|
+
|
|
14
|
+
(_this$context$deck = this.context.deck) === null || _this$context$deck === void 0 ? void 0 : _this$context$deck._addDefaultEffect(new MaskEffect());
|
|
15
|
+
}
|
|
16
|
+
|
|
8
17
|
getShaders() {
|
|
9
18
|
let maskByInstance = ('instancePositions' in this.getAttributeManager().attributes);
|
|
10
19
|
|
|
11
|
-
if (
|
|
20
|
+
if (this.props.maskByInstance !== undefined) {
|
|
12
21
|
maskByInstance = Boolean(this.props.maskByInstance);
|
|
13
22
|
}
|
|
14
23
|
|
|
@@ -25,7 +34,8 @@ export default class MaskExtension extends LayerExtension {
|
|
|
25
34
|
}) {
|
|
26
35
|
uniforms.mask_maskByInstance = this.state.maskByInstance;
|
|
27
36
|
const {
|
|
28
|
-
maskId
|
|
37
|
+
maskId,
|
|
38
|
+
maskInverted
|
|
29
39
|
} = this.props;
|
|
30
40
|
const {
|
|
31
41
|
maskChannels
|
|
@@ -45,6 +55,7 @@ export default class MaskExtension extends LayerExtension {
|
|
|
45
55
|
} = maskChannels[maskId];
|
|
46
56
|
uniforms.mask_enabled = true;
|
|
47
57
|
uniforms.mask_channel = index;
|
|
58
|
+
uniforms.mask_inverted = maskInverted;
|
|
48
59
|
|
|
49
60
|
if (fromCoordinateSystem === COORDINATE_SYSTEM.DEFAULT) {
|
|
50
61
|
fromCoordinateSystem = viewport.isGeospatial ? COORDINATE_SYSTEM.LNGLAT : COORDINATE_SYSTEM.CARTESIAN;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/mask/mask.ts"],"names":["COORDINATE_SYSTEM","LayerExtension","log","mask","defaultProps","maskId","MaskExtension","
|
|
1
|
+
{"version":3,"sources":["../../../src/mask/mask.ts"],"names":["COORDINATE_SYSTEM","LayerExtension","log","mask","MaskEffect","defaultProps","maskId","maskByInstance","undefined","maskInverted","MaskExtension","initializeState","context","deck","_addDefaultEffect","getShaders","getAttributeManager","attributes","props","Boolean","state","modules","draw","uniforms","moduleParameters","mask_maskByInstance","maskChannels","viewport","index","bounds","coordinateOrigin","fromCoordinateOrigin","coordinateSystem","fromCoordinateSystem","mask_enabled","mask_channel","mask_inverted","DEFAULT","isGeospatial","LNGLAT","CARTESIAN","opts","modelMatrix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MAAAA,QAAQ,CAACW,YAAT,GAAwB,KAAxB;AACD;AACF;;AAlDuD;;gBAArCxB,a,kBACGL,Y;;gBADHK,a,mBAEI,e","sourcesContent":["import {COORDINATE_SYSTEM, Layer, LayerExtension, log} from '@deck.gl/core';\nimport mask from './shader-module';\nimport MaskEffect from './mask-effect';\n\nconst defaultProps = {\n maskId: '',\n maskByInstance: undefined,\n maskInverted: false\n};\n\nexport type MaskExtensionProps = {\n /**\n * Id of the layer that defines the mask. The mask layer must use the prop `operation: 'mask'`.\n * Masking is disabled if `maskId` is empty or no valid mask layer with the specified id is found.\n */\n maskId?: string;\n /**\n * controls whether an object is clipped by its anchor (usually defined by an accessor called `getPosition`, e.g. icon, scatterplot) or by its geometry (e.g. path, polygon).\n * If not specified, it is automatically deduced from the layer.\n */\n maskByInstance?: boolean;\n /**\n * Inverts the masking operation\n */\n maskInverted?: boolean;\n};\n\n/** Allows layers to show/hide objects by a geofence. */\nexport default class MaskExtension extends LayerExtension {\n static defaultProps = defaultProps;\n static extensionName = 'MaskExtension';\n\n initializeState(this: Layer<MaskExtensionProps>) {\n this.context.deck?._addDefaultEffect(new MaskEffect());\n }\n\n getShaders(this: Layer<MaskExtensionProps>): any {\n // Infer by geometry if 'maskByInstance' prop isn't explictly set\n let maskByInstance = 'instancePositions' in this.getAttributeManager()!.attributes;\n // Users can override by setting the `maskByInstance` prop\n if (this.props.maskByInstance !== undefined) {\n maskByInstance = Boolean(this.props.maskByInstance);\n }\n this.state.maskByInstance = maskByInstance;\n\n return {\n modules: [mask]\n };\n }\n\n /* eslint-disable camelcase */\n draw(this: Layer<Required<MaskExtensionProps>>, {uniforms, context, moduleParameters}: any) {\n uniforms.mask_maskByInstance = this.state.maskByInstance;\n const {maskId, maskInverted} = this.props;\n const {maskChannels} = moduleParameters;\n const {viewport} = context;\n if (maskChannels && maskChannels[maskId]) {\n const {index, bounds, coordinateOrigin: fromCoordinateOrigin} = maskChannels[maskId];\n let {coordinateSystem: fromCoordinateSystem} = maskChannels[maskId];\n uniforms.mask_enabled = true;\n uniforms.mask_channel = index;\n uniforms.mask_inverted = maskInverted;\n\n if (fromCoordinateSystem === COORDINATE_SYSTEM.DEFAULT) {\n fromCoordinateSystem = viewport.isGeospatial\n ? COORDINATE_SYSTEM.LNGLAT\n : COORDINATE_SYSTEM.CARTESIAN;\n }\n const opts = {modelMatrix: null, fromCoordinateOrigin, fromCoordinateSystem};\n const bl = this.projectPosition([bounds[0], bounds[1], 0], opts);\n const tr = this.projectPosition([bounds[2], bounds[3], 0], opts);\n uniforms.mask_bounds = [bl[0], bl[1], tr[0], tr[1]];\n } else {\n if (maskId) {\n log.warn(`Could not find a mask layer with id: ${maskId}`)();\n }\n uniforms.mask_enabled = false;\n }\n }\n}\n"],"file":"mask.js"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { project } from '@deck.gl/core';
|
|
2
2
|
const vs = "\nuniform vec4 mask_bounds;\nuniform bool mask_maskByInstance;\nvec2 mask_getCoords(vec4 position) {\n return (position.xy - mask_bounds.xy) / (mask_bounds.zw - mask_bounds.xy);\n}\n";
|
|
3
|
-
const fs = "\nuniform sampler2D mask_texture;\nuniform int mask_channel;\nuniform bool mask_enabled;\nbool mask_isInBounds(vec2 texCoords) {\n if (!mask_enabled) {\n return true;\n }\n vec4 maskColor = texture2D(mask_texture, texCoords);\n float maskValue = 1.0;\n if (mask_channel == 0) {\n maskValue = maskColor.r;\n } else if (mask_channel == 1) {\n maskValue = maskColor.g;\n } else if (mask_channel == 2) {\n maskValue = maskColor.b;\n } else if (mask_channel == 3) {\n maskValue = maskColor.a;\n }\n return maskValue < 0.5;\n}\n";
|
|
3
|
+
const fs = "\nuniform sampler2D mask_texture;\nuniform int mask_channel;\nuniform bool mask_enabled;\nuniform bool mask_inverted;\nbool mask_isInBounds(vec2 texCoords) {\n if (!mask_enabled) {\n return true;\n }\n vec4 maskColor = texture2D(mask_texture, texCoords);\n float maskValue = 1.0;\n if (mask_channel == 0) {\n maskValue = maskColor.r;\n } else if (mask_channel == 1) {\n maskValue = maskColor.g;\n } else if (mask_channel == 2) {\n maskValue = maskColor.b;\n } else if (mask_channel == 3) {\n maskValue = maskColor.a;\n }\n\n if (mask_inverted) {\n return maskValue >= 0.5;\n } else {\n return maskValue < 0.5;\n }\n}\n";
|
|
4
4
|
const inject = {
|
|
5
5
|
'vs:#decl': "\nvarying vec2 mask_texCoords;\n",
|
|
6
6
|
'vs:#main-end': "\n vec4 mask_common_position;\n if (mask_maskByInstance) {\n mask_common_position = project_position(vec4(geometry.worldPosition, 1.0));\n } else {\n mask_common_position = geometry.position;\n }\n mask_texCoords = mask_getCoords(mask_common_position);\n",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/mask/shader-module.ts"],"names":["project","vs","fs","inject","getMaskUniforms","opts","mask_texture","maskMap","name","dependencies","getUniforms"],"mappings":"AAAA,SAAQA,OAAR,QAAsB,eAAtB;AAIA,MAAMC,EAAE,4LAAR;AAQA,MAAMC,EAAE,
|
|
1
|
+
{"version":3,"sources":["../../../src/mask/shader-module.ts"],"names":["project","vs","fs","inject","getMaskUniforms","opts","mask_texture","maskMap","name","dependencies","getUniforms"],"mappings":"AAAA,SAAQA,OAAR,QAAsB,eAAtB;AAIA,MAAMC,EAAE,4LAAR;AAQA,MAAMC,EAAE,gpBAAR;AA6BA,MAAMC,MAAM,GAAG;AACb,gDADa;AAIb,oSAJa;AAab,gDAba;AAgBb;AAhBa,CAAf;;AAkCA,MAAMC,eAAe,GAAIC,IAAD,IAAyD;AAC/E,MAAIA,IAAI,IAAI,aAAaA,IAAzB,EAA+B;AAC7B,WAAO;AACLC,MAAAA,YAAY,EAAED,IAAI,CAACE;AADd,KAAP;AAGD;;AACD,SAAO,EAAP;AACD,CAPD;;AASA,eAAe;AACbC,EAAAA,IAAI,EAAE,MADO;AAEbC,EAAAA,YAAY,EAAE,CAACT,OAAD,CAFD;AAGbC,EAAAA,EAHa;AAIbC,EAAAA,EAJa;AAKbC,EAAAA,MALa;AAMbO,EAAAA,WAAW,EAAEN;AANA,CAAf","sourcesContent":["import {project} from '@deck.gl/core';\nimport type {_ShaderModule as ShaderModule} from '@deck.gl/core';\nimport type {Texture2D} from '@luma.gl/webgl';\n\nconst vs = `\nuniform vec4 mask_bounds;\nuniform bool mask_maskByInstance;\nvec2 mask_getCoords(vec4 position) {\n return (position.xy - mask_bounds.xy) / (mask_bounds.zw - mask_bounds.xy);\n}\n`;\n\nconst fs = `\nuniform sampler2D mask_texture;\nuniform int mask_channel;\nuniform bool mask_enabled;\nuniform bool mask_inverted;\nbool mask_isInBounds(vec2 texCoords) {\n if (!mask_enabled) {\n return true;\n }\n vec4 maskColor = texture2D(mask_texture, texCoords);\n float maskValue = 1.0;\n if (mask_channel == 0) {\n maskValue = maskColor.r;\n } else if (mask_channel == 1) {\n maskValue = maskColor.g;\n } else if (mask_channel == 2) {\n maskValue = maskColor.b;\n } else if (mask_channel == 3) {\n maskValue = maskColor.a;\n }\n\n if (mask_inverted) {\n return maskValue >= 0.5;\n } else {\n return maskValue < 0.5;\n }\n}\n`;\n\nconst inject = {\n 'vs:#decl': `\nvarying vec2 mask_texCoords;\n`,\n 'vs:#main-end': `\n vec4 mask_common_position;\n if (mask_maskByInstance) {\n mask_common_position = project_position(vec4(geometry.worldPosition, 1.0));\n } else {\n mask_common_position = geometry.position;\n }\n mask_texCoords = mask_getCoords(mask_common_position);\n`,\n 'fs:#decl': `\nvarying vec2 mask_texCoords;\n`,\n 'fs:#main-start': `\n if (mask_enabled) {\n bool mask = mask_isInBounds(mask_texCoords);\n\n // Debug: show extent of render target\n // gl_FragColor = vec4(mask_texCoords, 0.0, 1.0);\n gl_FragColor = texture2D(mask_texture, mask_texCoords);\n\n if (!mask) discard;\n }\n`\n};\n\ntype MaskModuleSettings = {\n maskMap?: Texture2D;\n};\n\n/* eslint-disable camelcase */\nconst getMaskUniforms = (opts?: MaskModuleSettings | {}): Record<string, any> => {\n if (opts && 'maskMap' in opts) {\n return {\n mask_texture: opts.maskMap\n };\n }\n return {};\n};\n\nexport default {\n name: 'mask',\n dependencies: [project],\n vs,\n fs,\n inject,\n getUniforms: getMaskUniforms\n} as ShaderModule<MaskModuleSettings>;\n"],"file":"shader-module.js"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { OrthographicView, WebMercatorViewport, log } from '@deck.gl/core';
|
|
2
|
+
import { fitBounds } from '@math.gl/web-mercator';
|
|
3
|
+
export function getMaskBounds({
|
|
4
|
+
layers,
|
|
5
|
+
viewport
|
|
6
|
+
}) {
|
|
7
|
+
let bounds = null;
|
|
8
|
+
|
|
9
|
+
for (const layer of layers) {
|
|
10
|
+
const subLayerBounds = layer.getBounds();
|
|
11
|
+
|
|
12
|
+
if (subLayerBounds) {
|
|
13
|
+
if (bounds) {
|
|
14
|
+
bounds[0] = Math.min(bounds[0], subLayerBounds[0][0]);
|
|
15
|
+
bounds[1] = Math.min(bounds[1], subLayerBounds[0][1]);
|
|
16
|
+
bounds[2] = Math.max(bounds[2], subLayerBounds[1][0]);
|
|
17
|
+
bounds[3] = Math.max(bounds[3], subLayerBounds[1][1]);
|
|
18
|
+
} else {
|
|
19
|
+
bounds = [subLayerBounds[0][0], subLayerBounds[0][1], subLayerBounds[1][0], subLayerBounds[1][1]];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const viewportBounds = viewport.getBounds();
|
|
25
|
+
|
|
26
|
+
if (!bounds) {
|
|
27
|
+
return viewportBounds;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const paddedBounds = _doubleBounds(viewportBounds);
|
|
31
|
+
|
|
32
|
+
if (bounds[2] - bounds[0] < paddedBounds[2] - paddedBounds[0] || bounds[3] - bounds[1] < paddedBounds[3] - paddedBounds[1]) {
|
|
33
|
+
return bounds;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
bounds[0] = Math.max(bounds[0], paddedBounds[0]);
|
|
37
|
+
bounds[1] = Math.max(bounds[1], paddedBounds[1]);
|
|
38
|
+
bounds[2] = Math.min(bounds[2], paddedBounds[2]);
|
|
39
|
+
bounds[3] = Math.min(bounds[3], paddedBounds[3]);
|
|
40
|
+
return bounds;
|
|
41
|
+
}
|
|
42
|
+
export function getMaskViewport({
|
|
43
|
+
bounds,
|
|
44
|
+
viewport,
|
|
45
|
+
width,
|
|
46
|
+
height
|
|
47
|
+
}) {
|
|
48
|
+
if (bounds[2] <= bounds[0] || bounds[3] <= bounds[1]) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (viewport.resolution !== undefined) {
|
|
53
|
+
log.warn('MaskExtension is not supported in GlobeView')();
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const padding = 1;
|
|
58
|
+
width -= padding * 2;
|
|
59
|
+
height -= padding * 2;
|
|
60
|
+
|
|
61
|
+
if (viewport.isGeospatial) {
|
|
62
|
+
const {
|
|
63
|
+
longitude,
|
|
64
|
+
latitude,
|
|
65
|
+
zoom
|
|
66
|
+
} = fitBounds({
|
|
67
|
+
width,
|
|
68
|
+
height,
|
|
69
|
+
bounds: [[bounds[0], bounds[1]], [bounds[2], bounds[3]]],
|
|
70
|
+
maxZoom: 20
|
|
71
|
+
});
|
|
72
|
+
return new WebMercatorViewport({
|
|
73
|
+
longitude,
|
|
74
|
+
latitude,
|
|
75
|
+
zoom,
|
|
76
|
+
x: padding,
|
|
77
|
+
y: padding,
|
|
78
|
+
width,
|
|
79
|
+
height
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const center = [(bounds[0] + bounds[2]) / 2, (bounds[1] + bounds[3]) / 2, 0];
|
|
84
|
+
const scale = Math.min(1048576, width / (bounds[2] - bounds[0]), height / (bounds[3] - bounds[1]));
|
|
85
|
+
return new OrthographicView({
|
|
86
|
+
x: padding,
|
|
87
|
+
y: padding
|
|
88
|
+
}).makeViewport({
|
|
89
|
+
width,
|
|
90
|
+
height,
|
|
91
|
+
viewState: {
|
|
92
|
+
target: center,
|
|
93
|
+
zoom: Math.log2(scale)
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function _doubleBounds(bounds) {
|
|
99
|
+
const size = {
|
|
100
|
+
x: bounds[2] - bounds[0],
|
|
101
|
+
y: bounds[3] - bounds[1]
|
|
102
|
+
};
|
|
103
|
+
const center = {
|
|
104
|
+
x: bounds[0] + 0.5 * size.x,
|
|
105
|
+
y: bounds[1] + 0.5 * size.y
|
|
106
|
+
};
|
|
107
|
+
return [center.x - size.x, center.y - size.y, center.x + size.x, center.y + size.y];
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/mask/utils.ts"],"names":["OrthographicView","WebMercatorViewport","log","fitBounds","getMaskBounds","layers","viewport","bounds","layer","subLayerBounds","getBounds","Math","min","max","viewportBounds","paddedBounds","_doubleBounds","getMaskViewport","width","height","resolution","undefined","warn","padding","isGeospatial","longitude","latitude","zoom","maxZoom","x","y","center","scale","makeViewport","viewState","target","log2","size"],"mappings":"AAAA,SAAQA,gBAAR,EAA0BC,mBAA1B,EAA+CC,GAA/C,QAA0E,eAA1E;AACA,SAAQC,SAAR,QAAwB,uBAAxB;AASA,OAAO,SAASC,aAAT,CAAuB;AAC5BC,EAAAA,MAD4B;AAE5BC,EAAAA;AAF4B,CAAvB,EAMQ;AAEb,MAAIC,MAAyB,GAAG,IAAhC;;AACA,OAAK,MAAMC,KAAX,IAAoBH,MAApB,EAA4B;AAC1B,UAAMI,cAAc,GAAGD,KAAK,CAACE,SAAN,EAAvB;;AACA,QAAID,cAAJ,EAAoB;AAClB,UAAIF,MAAJ,EAAY;AACVA,QAAAA,MAAM,CAAC,CAAD,CAAN,GAAYI,IAAI,CAACC,GAAL,CAASL,MAAM,CAAC,CAAD,CAAf,EAAoBE,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A,IAAI,EAAEhB,IAAI,CAACyB,IAAL,CAAUJ,KAAV;AAFG;AAHG,GAHT,CAAP;AAWD;;AAED,SAAShB,aAAT,CAAuBT,MAAvB,EAAuD;AACrD,QAAM8B,IAAI,GAAG;AACXR,IAAAA,CAAC,EAAEtB,MAAM,CAAC,CAAD,CAAN,GAAYA,MAAM,CAAC,CAAD,CADV;AAEXuB,IAAAA,CAAC,EAAEvB,MAAM,CAAC,CAAD,CAAN,GAAYA,MAAM,CAAC,CAAD;AAFV,GAAb;AAIA,QAAMwB,MAAM,GAAG;AACbF,IAAAA,CAAC,EAAEtB,MAAM,CAAC,CAAD,CAAN,GAAY,MAAM8B,IAAI,CAACR,CADb;AAEbC,IAAAA,CAAC,EAAEvB,MAAM,CAAC,CAAD,CAAN,GAAY,MAAM8B,IAAI,CAACP;AAFb,GAAf;AAIA,SAAO,CAACC,MAAM,CAACF,CAAP,GAAWQ,IAAI,CAACR,CAAjB,EAAoBE,MAAM,CAACD,CAAP,GAAWO,IAAI,CAACP,CAApC,EAAuCC,MAAM,CAACF,CAAP,GAAWQ,IAAI,CAACR,CAAvD,EAA0DE,MAAM,CAACD,CAAP,GAAWO,IAAI,CAACP,CAA1E,CAAP;AACD","sourcesContent":["import {OrthographicView, WebMercatorViewport, log, Layer, Viewport} from '@deck.gl/core';\nimport {fitBounds} from '@math.gl/web-mercator';\n\nexport type MaskBounds = [number, number, number, number];\n\n/*\n * Compute the bounds of the mask in world space, such that it covers an\n * area currently visible (extended by a buffer) or the area of the masking\n * data, whichever is smaller\n */\nexport function getMaskBounds({\n layers,\n viewport\n}: {\n layers: Layer[];\n viewport: Viewport;\n}): MaskBounds {\n // Join the bounds of layer data\n let bounds: MaskBounds | null = null;\n for (const layer of layers) {\n const subLayerBounds = layer.getBounds();\n if (subLayerBounds) {\n if (bounds) {\n bounds[0] = Math.min(bounds[0], subLayerBounds[0][0]);\n bounds[1] = Math.min(bounds[1], subLayerBounds[0][1]);\n bounds[2] = Math.max(bounds[2], subLayerBounds[1][0]);\n bounds[3] = Math.max(bounds[3], subLayerBounds[1][1]);\n } else {\n bounds = [\n subLayerBounds[0][0],\n subLayerBounds[0][1],\n subLayerBounds[1][0],\n subLayerBounds[1][1]\n ];\n }\n }\n }\n const viewportBounds = viewport.getBounds();\n if (!bounds) {\n return viewportBounds;\n }\n\n // Expand viewport bounds by 2X. Heurestically chosen to avoid masking\n // errors when mask is partially out of view\n const paddedBounds = _doubleBounds(viewportBounds);\n\n // When bounds of the mask are smaller than the viewport bounds simply use\n // mask bounds, so as to maximize resolution & avoid mask rerenders\n if (\n bounds[2] - bounds[0] < paddedBounds[2] - paddedBounds[0] ||\n bounds[3] - bounds[1] < paddedBounds[3] - paddedBounds[1]\n ) {\n return bounds;\n }\n\n // As viewport shrinks, to avoid pixelation along mask edges\n // we need to reduce the bounds and only render the visible portion\n // of the mask.\n // We pad the viewport bounds to capture the section\n // of the mask just outside the viewport to correctly maskByInstance.\n // Intersect mask & padded viewport bounds\n bounds[0] = Math.max(bounds[0], paddedBounds[0]);\n bounds[1] = Math.max(bounds[1], paddedBounds[1]);\n bounds[2] = Math.min(bounds[2], paddedBounds[2]);\n bounds[3] = Math.min(bounds[3], paddedBounds[3]);\n return bounds;\n}\n\n/*\n * Compute viewport to render the mask into, covering the given bounds\n */\nexport function getMaskViewport({\n bounds,\n viewport,\n width,\n height\n}: {\n bounds: MaskBounds;\n viewport: Viewport;\n width: number;\n height: number;\n}): Viewport | null {\n if (bounds[2] <= bounds[0] || bounds[3] <= bounds[1]) {\n return null;\n }\n\n if (viewport.resolution !== undefined) {\n log.warn('MaskExtension is not supported in GlobeView')();\n return null;\n }\n\n // Single pixel border to prevent mask bleeding at edge of texture\n const padding = 1;\n width -= padding * 2;\n height -= padding * 2;\n\n if (viewport.isGeospatial) {\n const {longitude, latitude, zoom} = fitBounds({\n width,\n height,\n bounds: [\n [bounds[0], bounds[1]],\n [bounds[2], bounds[3]]\n ],\n maxZoom: 20\n });\n return new WebMercatorViewport({\n longitude,\n latitude,\n zoom,\n x: padding,\n y: padding,\n width,\n height\n });\n }\n\n const center = [(bounds[0] + bounds[2]) / 2, (bounds[1] + bounds[3]) / 2, 0];\n const scale = Math.min(\n 1048576, // maxZoom of 20: Math.pow(2, 20) = 1048576\n width / (bounds[2] - bounds[0]),\n height / (bounds[3] - bounds[1])\n );\n\n return new OrthographicView({\n x: padding,\n y: padding\n }).makeViewport({\n width,\n height,\n viewState: {\n target: center,\n zoom: Math.log2(scale)\n }\n });\n}\n\nfunction _doubleBounds(bounds: MaskBounds): MaskBounds {\n const size = {\n x: bounds[2] - bounds[0],\n y: bounds[3] - bounds[1]\n };\n const center = {\n x: bounds[0] + 0.5 * size.x,\n y: bounds[1] + 0.5 * size.y\n };\n return [center.x - size.x, center.y - size.y, center.x + size.x, center.y + size.y];\n}\n"],"file":"utils.js"}
|
|
@@ -3,7 +3,7 @@ export const dashShaders = {
|
|
|
3
3
|
'vs:#decl': "\nattribute vec2 instanceDashArrays;\nattribute float instanceDashOffsets;\nvarying vec2 vDashArray;\nvarying float vDashOffset;\n",
|
|
4
4
|
'vs:#main-end': "\nvDashArray = instanceDashArrays;\nvDashOffset = instanceDashOffsets / width.x;\n",
|
|
5
5
|
'fs:#decl': "\nuniform float dashAlignMode;\nuniform float capType;\nuniform bool dashGapPickable;\nvarying vec2 vDashArray;\nvarying float vDashOffset;\n\nfloat round(float x) {\n return floor(x + 0.5);\n}\n",
|
|
6
|
-
'fs:#main-start': "\n float solidLength = vDashArray.x;\n float gapLength = vDashArray.y;\n float unitLength = solidLength + gapLength;\n\n float offset;\n\n if (unitLength > 0.0) {\n if (dashAlignMode == 0.0) {\n offset = vDashOffset;\n } else {\n unitLength = vPathLength / round(vPathLength / unitLength);\n offset = solidLength / 2.0;\n }\n\n float unitOffset = mod(clamp(vPathPosition.y, 0.0, vPathLength) + offset, unitLength);\n\n if (gapLength > 0.0 && unitOffset > solidLength) {\n if (capType <= 0.5) {\n if (!(dashGapPickable && picking_uActive)) {\n discard;\n }\n } else {\n
|
|
6
|
+
'fs:#main-start': "\n float solidLength = vDashArray.x;\n float gapLength = vDashArray.y;\n float unitLength = solidLength + gapLength;\n\n float offset;\n\n if (unitLength > 0.0) {\n if (dashAlignMode == 0.0) {\n offset = vDashOffset;\n } else {\n unitLength = vPathLength / round(vPathLength / unitLength);\n offset = solidLength / 2.0;\n }\n\n float unitOffset = mod(clamp(vPathPosition.y, 0.0, vPathLength) + offset, unitLength);\n\n if (gapLength > 0.0 && unitOffset > solidLength) {\n if (capType <= 0.5) {\n if (!(dashGapPickable && picking_uActive)) {\n discard;\n }\n } else {\n float distToEnd = length(vec2(\n min(unitOffset - solidLength, unitLength - unitOffset),\n vPathPosition.x\n ));\n if (distToEnd > 1.0) {\n if (!(dashGapPickable && picking_uActive)) {\n discard;\n }\n }\n }\n }\n }\n"
|
|
7
7
|
}
|
|
8
8
|
};
|
|
9
9
|
export const offsetShaders = {
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
import { Framebuffer } from '@luma.gl/core';
|
|
3
|
+
import { joinLayerBounds, getRenderBounds, makeViewport } from '../common/projection-utils';
|
|
4
|
+
import { createRenderTarget } from './utils';
|
|
5
|
+
const MAP_MAX_SIZE = 2048;
|
|
6
|
+
export class HeightMapBuilder {
|
|
7
|
+
static isSupported(gl) {
|
|
8
|
+
return Framebuffer.isSupported(gl, {
|
|
9
|
+
colorBufferFloat: true
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
constructor(gl) {
|
|
14
|
+
_defineProperty(this, "renderViewport", null);
|
|
15
|
+
|
|
16
|
+
_defineProperty(this, "bounds", null);
|
|
17
|
+
|
|
18
|
+
_defineProperty(this, "fbo", void 0);
|
|
19
|
+
|
|
20
|
+
_defineProperty(this, "gl", void 0);
|
|
21
|
+
|
|
22
|
+
_defineProperty(this, "layers", []);
|
|
23
|
+
|
|
24
|
+
_defineProperty(this, "layersBounds", []);
|
|
25
|
+
|
|
26
|
+
_defineProperty(this, "layersBoundsCommon", null);
|
|
27
|
+
|
|
28
|
+
_defineProperty(this, "lastViewport", null);
|
|
29
|
+
|
|
30
|
+
this.gl = gl;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
getRenderFramebuffer() {
|
|
34
|
+
if (!this.renderViewport) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!this.fbo) {
|
|
39
|
+
this.fbo = createRenderTarget(this.gl, {
|
|
40
|
+
id: 'height-map',
|
|
41
|
+
float: true
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return this.fbo;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
shouldUpdate({
|
|
49
|
+
layers,
|
|
50
|
+
viewport
|
|
51
|
+
}) {
|
|
52
|
+
const layersChanged = layers.length !== this.layers.length || layers.some((layer, i) => layer !== this.layers[i] || layer.props.transitions || layer.getBounds() !== this.layersBounds[i]);
|
|
53
|
+
|
|
54
|
+
if (layersChanged) {
|
|
55
|
+
this.layers = layers;
|
|
56
|
+
this.layersBounds = layers.map(layer => layer.getBounds());
|
|
57
|
+
this.layersBoundsCommon = joinLayerBounds(layers, viewport);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const viewportChanged = !this.lastViewport || !viewport.equals(this.lastViewport);
|
|
61
|
+
|
|
62
|
+
if (!this.layersBoundsCommon) {
|
|
63
|
+
this.renderViewport = null;
|
|
64
|
+
} else if (layersChanged || viewportChanged) {
|
|
65
|
+
const bounds = getRenderBounds(this.layersBoundsCommon, viewport);
|
|
66
|
+
this.bounds = bounds;
|
|
67
|
+
this.lastViewport = viewport;
|
|
68
|
+
const scale = viewport.scale;
|
|
69
|
+
const pixelWidth = (bounds[2] - bounds[0]) * scale;
|
|
70
|
+
const pixelHeight = (bounds[3] - bounds[1]) * scale;
|
|
71
|
+
this.renderViewport = pixelWidth > 0 || pixelHeight > 0 ? makeViewport({
|
|
72
|
+
bounds: [viewport.center[0] - 1, viewport.center[1] - 1, viewport.center[0] + 1, viewport.center[1] + 1],
|
|
73
|
+
zoom: viewport.zoom,
|
|
74
|
+
width: Math.min(pixelWidth, MAP_MAX_SIZE),
|
|
75
|
+
height: Math.min(pixelHeight, MAP_MAX_SIZE),
|
|
76
|
+
viewport
|
|
77
|
+
}) : null;
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
delete() {
|
|
85
|
+
if (this.fbo) {
|
|
86
|
+
this.fbo.color.delete();
|
|
87
|
+
this.fbo.delete();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=height-map-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/terrain/height-map-builder.ts"],"names":["Framebuffer","joinLayerBounds","getRenderBounds","makeViewport","createRenderTarget","MAP_MAX_SIZE","HeightMapBuilder","isSupported","gl","colorBufferFloat","constructor","getRenderFramebuffer","renderViewport","fbo","id","float","shouldUpdate","layers","viewport","layersChanged","length","some","layer","i","props","transitions","getBounds","layersBounds","map","layersBoundsCommon","viewportChanged","lastViewport","equals","bounds","scale","pixelWidth","pixelHeight","center","zoom","width","Math","min","height","delete","color"],"mappings":";AAAA,SAAQA,WAAR,QAA0B,eAA1B;AACA,SAAQC,eAAR,EAAyBC,eAAzB,EAA0CC,YAA1C,QAAqE,4BAArE;AACA,SAAQC,kBAAR,QAAiC,SAAjC;AAIA,MAAMC,YAAY,GAAG,IAArB;AASA,OAAO,MAAMC,gBAAN,CAAuB;AAgBV,SAAXC,WAAW,CAACC,EAAD,EAAqC;AACrD,WAAOR,WAAW,CAACO,WAAZ,CAAwBC,EAAxB,EAA4B;AAACC,MAAAA,gBAAgB,EAAE;AAAnB,KAA5B,CAAP;AACD;;AAEDC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AAc;AACZ,WAAKA,GAAL,CAAS+B,KAAT,CAAeD,MAAf;AACA,WAAK9B,GAAL,CAAS8B,MAAT;AACD;AACF;;AAvG2B","sourcesContent":["import {Framebuffer} from '@luma.gl/core';\nimport {joinLayerBounds, getRenderBounds, makeViewport, Bounds} from '../common/projection-utils';\nimport {createRenderTarget} from './utils';\n\nimport type {Viewport, Layer} from '@deck.gl/core';\n\nconst MAP_MAX_SIZE = 2048;\n\n/**\n * Manages the lifecycle of the height map (a framebuffer that encodes elevation).\n * One instance of height map is is shared across all layers. It is updated when the viewport changes\n * or when some terrain source layer's data changes.\n * During the draw call of any terrainFittingMode:offset layers,\n * the vertex shader reads from this framebuffer to retrieve its z offset.\n */\nexport class HeightMapBuilder {\n /** Viewport used to draw into the texture */\n renderViewport: Viewport | null = null;\n /** Bounds of the height map texture, in cartesian space */\n bounds: Bounds | null = null;\n\n protected fbo?: Framebuffer;\n protected gl: WebGLRenderingContext;\n /** Last rendered layers */\n private layers: Layer[] = [];\n /** Last layer.getBounds() */\n private layersBounds: ([number[], number[]] | null)[] = [];\n /** The union of layersBounds in cartesian space */\n private layersBoundsCommon: Bounds | null = null;\n private lastViewport: Viewport | null = null;\n\n static isSupported(gl: WebGLRenderingContext): boolean {\n return Framebuffer.isSupported(gl, {colorBufferFloat: true});\n }\n\n constructor(gl: WebGLRenderingContext) {\n this.gl = gl;\n }\n\n /** Returns the height map framebuffer for read/write access.\n * Returns null when the texture is invalid.\n */\n getRenderFramebuffer(): Framebuffer | null {\n if (!this.renderViewport) {\n return null;\n }\n if (!this.fbo) {\n this.fbo = createRenderTarget(this.gl, {id: 'height-map', float: true});\n }\n return this.fbo;\n }\n\n /** Called every render cycle to check if the framebuffer needs update */\n shouldUpdate({layers, viewport}: {layers: Layer[]; viewport: Viewport}): boolean {\n const layersChanged =\n layers.length !== this.layers.length ||\n layers.some(\n (layer, i) =>\n // Layer instance is updated\n // Layer props might have changed\n // Undetermined props could have an effect on the output geometry of a terrain source,\n // for example getElevation+updateTriggers, elevationScale, modelMatrix\n layer !== this.layers[i] ||\n // Some prop is in transition\n layer.props.transitions ||\n // Layer's geometry bounds have changed\n layer.getBounds() !== this.layersBounds[i]\n );\n\n if (layersChanged) {\n // Recalculate cached bounds\n this.layers = layers;\n this.layersBounds = layers.map(layer => layer.getBounds());\n this.layersBoundsCommon = joinLayerBounds(layers, viewport);\n }\n\n const viewportChanged = !this.lastViewport || !viewport.equals(this.lastViewport);\n\n if (!this.layersBoundsCommon) {\n this.renderViewport = null;\n } else if (layersChanged || viewportChanged) {\n const bounds = getRenderBounds(this.layersBoundsCommon, viewport);\n this.bounds = bounds;\n this.lastViewport = viewport;\n\n const scale = viewport.scale;\n const pixelWidth = (bounds[2] - bounds[0]) * scale;\n const pixelHeight = (bounds[3] - bounds[1]) * scale;\n\n this.renderViewport =\n pixelWidth > 0 || pixelHeight > 0\n ? makeViewport({\n // It's not important whether the geometry is visible in this viewport, because\n // vertices will not use the standard project_to_clipspace in the DRAW_TO_HEIGHT_MAP shader\n // However the viewport must have the same center and zoom as the screen viewport\n // So that projection uniforms used for calculating z are the same\n bounds: [\n viewport.center[0] - 1,\n viewport.center[1] - 1,\n viewport.center[0] + 1,\n viewport.center[1] + 1\n ],\n zoom: viewport.zoom,\n width: Math.min(pixelWidth, MAP_MAX_SIZE),\n height: Math.min(pixelHeight, MAP_MAX_SIZE),\n viewport\n })\n : null;\n return true;\n }\n return false;\n }\n\n delete() {\n if (this.fbo) {\n this.fbo.color.delete();\n this.fbo.delete();\n }\n }\n}\n"],"file":"height-map-builder.js"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { project } from '@deck.gl/core';
|
|
2
|
+
export const TERRAIN_MODE = {
|
|
3
|
+
NONE: 0,
|
|
4
|
+
WRITE_HEIGHT_MAP: 1,
|
|
5
|
+
USE_HEIGHT_MAP: 2,
|
|
6
|
+
USE_COVER: 3,
|
|
7
|
+
USE_COVER_ONLY: 4,
|
|
8
|
+
SKIP: 5
|
|
9
|
+
};
|
|
10
|
+
const TERRAIN_MODE_CONSTANTS = Object.keys(TERRAIN_MODE).map(key => "const float TERRAIN_MODE_".concat(key, " = ").concat(TERRAIN_MODE[key], ".0;")).join('\n');
|
|
11
|
+
export const terrainModule = {
|
|
12
|
+
name: 'terrain',
|
|
13
|
+
dependencies: [project],
|
|
14
|
+
inject: {
|
|
15
|
+
'vs:#decl': "\nuniform float terrain_mode;\nuniform sampler2D terrain_map;\nuniform vec4 terrain_bounds;\nvarying vec3 commonPos;\n".concat(TERRAIN_MODE_CONSTANTS, "\n "),
|
|
16
|
+
'vs:#main-start': "\nif (terrain_mode == TERRAIN_MODE_SKIP) {\n gl_Position = vec4(0.0);\n return;\n}\n",
|
|
17
|
+
'vs:DECKGL_FILTER_GL_POSITION': "\ncommonPos = geometry.position.xyz;\nif (terrain_mode == TERRAIN_MODE_WRITE_HEIGHT_MAP) {\n vec2 texCoords = (commonPos.xy - terrain_bounds.xy) / terrain_bounds.zw;\n position = vec4(texCoords * 2.0 - 1.0, 0.0, 1.0);\n}\nif (terrain_mode == TERRAIN_MODE_USE_HEIGHT_MAP) {\n vec3 anchor = geometry.worldPosition;\n anchor.z = 0.0;\n vec3 anchorCommon = project_position(anchor);\n vec2 texCoords = (anchorCommon.xy - terrain_bounds.xy) / terrain_bounds.zw;\n if (texCoords.x >= 0.0 && texCoords.y >= 0.0 && texCoords.x <= 1.0 && texCoords.y <= 1.0) {\n float terrainZ = texture2D(terrain_map, texCoords).r;\n geometry.position.z += terrainZ;\n position = project_common_position_to_clipspace(geometry.position);\n }\n}\n ",
|
|
18
|
+
'fs:#decl': "\nuniform float terrain_mode;\nuniform sampler2D terrain_map;\nuniform vec4 terrain_bounds;\nvarying vec3 commonPos;\n".concat(TERRAIN_MODE_CONSTANTS, "\n "),
|
|
19
|
+
'fs:#main-start': "\nif (terrain_mode == TERRAIN_MODE_WRITE_HEIGHT_MAP) {\n gl_FragColor = vec4(commonPos.z, 0.0, 0.0, 1.0);\n return;\n}\n ",
|
|
20
|
+
'fs:DECKGL_FILTER_COLOR': "\nif ((terrain_mode == TERRAIN_MODE_USE_COVER) || (terrain_mode == TERRAIN_MODE_USE_COVER_ONLY)) {\n vec2 texCoords = (commonPos.xy - terrain_bounds.xy) / terrain_bounds.zw;\n vec4 pixel = texture2D(terrain_map, texCoords);\n if (terrain_mode == TERRAIN_MODE_USE_COVER_ONLY) {\n color = pixel;\n } else {\n // pixel is premultiplied\n color = pixel + color * (1.0 - pixel.a);\n }\n return;\n}\n "
|
|
21
|
+
},
|
|
22
|
+
getUniforms: (opts = {}, uniforms) => {
|
|
23
|
+
if ('dummyHeightMap' in opts) {
|
|
24
|
+
const {
|
|
25
|
+
drawToTerrainHeightMap,
|
|
26
|
+
heightMap,
|
|
27
|
+
heightMapBounds,
|
|
28
|
+
dummyHeightMap,
|
|
29
|
+
terrainCover,
|
|
30
|
+
useTerrainHeightMap,
|
|
31
|
+
terrainSkipRender
|
|
32
|
+
} = opts;
|
|
33
|
+
const {
|
|
34
|
+
project_uCommonOrigin
|
|
35
|
+
} = uniforms;
|
|
36
|
+
let mode = terrainSkipRender ? TERRAIN_MODE.SKIP : TERRAIN_MODE.NONE;
|
|
37
|
+
let sampler = dummyHeightMap;
|
|
38
|
+
let bounds = null;
|
|
39
|
+
|
|
40
|
+
if (drawToTerrainHeightMap) {
|
|
41
|
+
mode = TERRAIN_MODE.WRITE_HEIGHT_MAP;
|
|
42
|
+
bounds = heightMapBounds;
|
|
43
|
+
} else if (useTerrainHeightMap && heightMap) {
|
|
44
|
+
mode = TERRAIN_MODE.USE_HEIGHT_MAP;
|
|
45
|
+
sampler = heightMap;
|
|
46
|
+
bounds = heightMapBounds;
|
|
47
|
+
} else if (terrainCover) {
|
|
48
|
+
const isPicking = opts.pickingActive;
|
|
49
|
+
sampler = isPicking ? terrainCover.getPickingFramebuffer() : terrainCover.getRenderFramebuffer();
|
|
50
|
+
|
|
51
|
+
if (isPicking) {
|
|
52
|
+
mode = TERRAIN_MODE.SKIP;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (sampler) {
|
|
56
|
+
mode = mode === TERRAIN_MODE.SKIP ? TERRAIN_MODE.USE_COVER_ONLY : TERRAIN_MODE.USE_COVER;
|
|
57
|
+
bounds = terrainCover.bounds;
|
|
58
|
+
} else {
|
|
59
|
+
sampler = dummyHeightMap;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
terrain_mode: mode,
|
|
65
|
+
terrain_map: sampler,
|
|
66
|
+
terrain_bounds: bounds ? [bounds[0] - project_uCommonOrigin[0], bounds[1] - project_uCommonOrigin[1], bounds[2] - bounds[0], bounds[3] - bounds[1]] : [0, 0, 0, 0]
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=shader-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/terrain/shader-module.ts"],"names":["project","TERRAIN_MODE","NONE","WRITE_HEIGHT_MAP","USE_HEIGHT_MAP","USE_COVER","USE_COVER_ONLY","SKIP","TERRAIN_MODE_CONSTANTS","Object","keys","map","key","join","terrainModule","name","dependencies","inject","getUniforms","opts","uniforms","drawToTerrainHeightMap","heightMap","heightMapBounds","dummyHeightMap","terrainCover","useTerrainHeightMap","terrainSkipRender","project_uCommonOrigin","mode","sampler","bounds","isPicking","pickingActive","getPickingFramebuffer","getRenderFramebuffer","terrain_mode","terrain_map","terrain_bounds"],"mappings":"AAAA,SAAQA,OAAR,QAAsB,eAAtB;AAoBA,OAAO,MAAMC,YAAY,GAAG;AAC1BC,EAAAA,IAAI,EAAE,CADoB;AAG1BC,EAAAA,gBAAgB,EAAE,CAHQ;AAK1BC,EAAAA,cAAc,EAAE,CALU;AAO1BC,EAAAA,SAAS,EAAE,CAPe;AAS1BC,EAAAA,cAAc,EAAE,CATU;AAW1BC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GR,eAAT;AACD,OAJM,MAIA,IAAIE,YAAJ,EAAkB;AAEvB,cAAMO,SAAS,GAAGb,IAAI,CAACc,aAAvB;AACAH,QAAAA,OAAO,GAAGE,SAAS,GACfP,YAAY,CAACS,qBAAb,EADe,GAEfT,YAAY,CAACU,oBAAb,EAFJ;;AAGA,YAAIH,SAAJ,EAAe;AAEbH,UAAAA,IAAI,GAAG5B,YAAY,CAACM,IAApB;AACD;;AACD,YAAIuB,OAAJ,EAAa;AACXD,UAAAA,IAAI,GAAGA,IAAI,KAAK5B,YAAY,CAACM,IAAtB,GAA6BN,YAAY,CAACK,cAA1C,GAA2DL,YAAY,CAACI,SAA/E;AACA0B,UAAAA,MAAM,GAAGN,YAAY,CAACM,MAAtB;AACD,SAHD,MAGO;AACLD,UAAAA,OAAO,GAAGN,cAAV;AACD;AACF;;AAGD,aAAO;AACLY,QAAAA,YAAY,EAAEP,IADT;AAELQ,QAAAA,WAAW,EAAEP,OAFR;AAILQ,QAAAA,cAAc,EAAEP,MAAM,GAClB,CACEA,MAAM,CAAC,CAAD,CAAN,GAAYH,qBAAqB,CAAC,CAAD,CADnC,EAEEG,MAAM,CAAC,CAAD,CAAN,GAAYH,qBAAqB,CAAC,CAAD,CAFnC,EAGEG,MAAM,CAAC,CAAD,CAAN,GAAYA,MAAM,CAAC,CAAD,CAHpB,EAIEA,MAAM,CAAC,CAAD,CAAN,GAAYA,MAAM,CAAC,CAAD,CAJpB,CADkB,GAOlB,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV;AAXC,OAAP;AAaD;;AACD,WAAO,IAAP;AACD;AAzH0B,CAAtB","sourcesContent":["import {project} from '@deck.gl/core';\nimport type {_ShaderModule as ShaderModule} from '@deck.gl/core';\n\nimport type {Texture2D} from '@luma.gl/core';\nimport type {Bounds} from '../common/projection-utils';\nimport type {TerrainCover} from './terrain-cover';\n\n/** Module parameters expected by the terrain shader module */\nexport type TerrainModuleSettings = {\n pickingActive?: boolean;\n heightMap: Texture2D | null;\n heightMapBounds?: Bounds | null;\n dummyHeightMap: Texture2D;\n terrainCover?: TerrainCover | null;\n drawToTerrainHeightMap?: boolean;\n useTerrainHeightMap?: boolean;\n terrainSkipRender?: boolean;\n};\n\n/** A model can have one of the following modes */\nexport const TERRAIN_MODE = {\n NONE: 0,\n /** A terrain layer rendering encoded ground elevation into the height map */\n WRITE_HEIGHT_MAP: 1,\n /** An offset layer reading encoded ground elevation from the height map */\n USE_HEIGHT_MAP: 2,\n /** A terrain layer rendering to screen, using the cover fbo overlaid with its own texture */\n USE_COVER: 3,\n /** A terrain layer rendering to screen, using the cover fbo as texture */\n USE_COVER_ONLY: 4,\n /** Draped layer is rendered into a texture, and never to screen */\n SKIP: 5\n};\n\nconst TERRAIN_MODE_CONSTANTS = Object.keys(TERRAIN_MODE)\n .map(key => `const float TERRAIN_MODE_${key} = ${TERRAIN_MODE[key]}.0;`)\n .join('\\n');\n\nexport const terrainModule = {\n name: 'terrain',\n dependencies: [project],\n inject: {\n 'vs:#decl': `\nuniform float terrain_mode;\nuniform sampler2D terrain_map;\nuniform vec4 terrain_bounds;\nvarying vec3 commonPos;\n${TERRAIN_MODE_CONSTANTS}\n `,\n 'vs:#main-start': `\nif (terrain_mode == TERRAIN_MODE_SKIP) {\n gl_Position = vec4(0.0);\n return;\n}\n`,\n 'vs:DECKGL_FILTER_GL_POSITION': `\ncommonPos = geometry.position.xyz;\nif (terrain_mode == TERRAIN_MODE_WRITE_HEIGHT_MAP) {\n vec2 texCoords = (commonPos.xy - terrain_bounds.xy) / terrain_bounds.zw;\n position = vec4(texCoords * 2.0 - 1.0, 0.0, 1.0);\n}\nif (terrain_mode == TERRAIN_MODE_USE_HEIGHT_MAP) {\n vec3 anchor = geometry.worldPosition;\n anchor.z = 0.0;\n vec3 anchorCommon = project_position(anchor);\n vec2 texCoords = (anchorCommon.xy - terrain_bounds.xy) / terrain_bounds.zw;\n if (texCoords.x >= 0.0 && texCoords.y >= 0.0 && texCoords.x <= 1.0 && texCoords.y <= 1.0) {\n float terrainZ = texture2D(terrain_map, texCoords).r;\n geometry.position.z += terrainZ;\n position = project_common_position_to_clipspace(geometry.position);\n }\n}\n `,\n 'fs:#decl': `\nuniform float terrain_mode;\nuniform sampler2D terrain_map;\nuniform vec4 terrain_bounds;\nvarying vec3 commonPos;\n${TERRAIN_MODE_CONSTANTS}\n `,\n 'fs:#main-start': `\nif (terrain_mode == TERRAIN_MODE_WRITE_HEIGHT_MAP) {\n gl_FragColor = vec4(commonPos.z, 0.0, 0.0, 1.0);\n return;\n}\n `,\n 'fs:DECKGL_FILTER_COLOR': `\nif ((terrain_mode == TERRAIN_MODE_USE_COVER) || (terrain_mode == TERRAIN_MODE_USE_COVER_ONLY)) {\n vec2 texCoords = (commonPos.xy - terrain_bounds.xy) / terrain_bounds.zw;\n vec4 pixel = texture2D(terrain_map, texCoords);\n if (terrain_mode == TERRAIN_MODE_USE_COVER_ONLY) {\n color = pixel;\n } else {\n // pixel is premultiplied\n color = pixel + color * (1.0 - pixel.a);\n }\n return;\n}\n `\n },\n getUniforms: (opts = {}, uniforms) => {\n if ('dummyHeightMap' in opts) {\n const {\n drawToTerrainHeightMap,\n heightMap,\n heightMapBounds,\n dummyHeightMap,\n terrainCover,\n useTerrainHeightMap,\n terrainSkipRender\n } = opts;\n const {project_uCommonOrigin} = uniforms;\n\n let mode: number = terrainSkipRender ? TERRAIN_MODE.SKIP : TERRAIN_MODE.NONE;\n // height map if case USE_HEIGHT_MAP, terrain cover if USE_COVER, otherwise empty\n let sampler: Texture2D = dummyHeightMap;\n // height map bounds if case USE_HEIGHT_MAP, terrain cover bounds if USE_COVER, otherwise null\n let bounds: number[] | null = null;\n if (drawToTerrainHeightMap) {\n mode = TERRAIN_MODE.WRITE_HEIGHT_MAP;\n bounds = heightMapBounds!;\n } else if (useTerrainHeightMap && heightMap) {\n mode = TERRAIN_MODE.USE_HEIGHT_MAP;\n sampler = heightMap;\n bounds = heightMapBounds!;\n } else if (terrainCover) {\n // This is a terrain layer\n const isPicking = opts.pickingActive;\n sampler = isPicking\n ? terrainCover.getPickingFramebuffer()\n : terrainCover.getRenderFramebuffer();\n if (isPicking) {\n // Never render the layer itself in picking pass\n mode = TERRAIN_MODE.SKIP;\n }\n if (sampler) {\n mode = mode === TERRAIN_MODE.SKIP ? TERRAIN_MODE.USE_COVER_ONLY : TERRAIN_MODE.USE_COVER;\n bounds = terrainCover.bounds;\n } else {\n sampler = dummyHeightMap;\n }\n }\n\n /* eslint-disable camelcase */\n return {\n terrain_mode: mode,\n terrain_map: sampler,\n // Convert bounds to the common space, as [minX, minY, width, height]\n terrain_bounds: bounds\n ? [\n bounds[0] - project_uCommonOrigin[0],\n bounds[1] - project_uCommonOrigin[1],\n bounds[2] - bounds[0],\n bounds[3] - bounds[1]\n ]\n : [0, 0, 0, 0]\n };\n }\n return null;\n }\n} as ShaderModule<TerrainModuleSettings>;\n"],"file":"shader-module.js"}
|