@deck.gl/extensions 8.9.17 → 8.9.18

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.
@@ -0,0 +1,152 @@
1
+ /*
2
+ * data filter shader module
3
+ */
4
+ const vs = `
5
+ uniform DATAFILTER_TYPE filter_min;
6
+ uniform DATAFILTER_TYPE filter_softMin;
7
+ uniform DATAFILTER_TYPE filter_softMax;
8
+ uniform DATAFILTER_TYPE filter_max;
9
+ uniform bool filter_useSoftMargin;
10
+ uniform bool filter_enabled;
11
+ uniform bool filter_transformSize;
12
+
13
+ #ifdef NON_INSTANCED_MODEL
14
+ #define DATAFILTER_ATTRIB filterValues
15
+ #define DATAFILTER_ATTRIB_64LOW filterValues64Low
16
+ #else
17
+ #define DATAFILTER_ATTRIB instanceFilterValues
18
+ #define DATAFILTER_ATTRIB_64LOW instanceFilterValues64Low
19
+ #endif
20
+
21
+ attribute DATAFILTER_TYPE DATAFILTER_ATTRIB;
22
+ #ifdef DATAFILTER_DOUBLE
23
+ attribute DATAFILTER_TYPE DATAFILTER_ATTRIB_64LOW;
24
+
25
+ uniform DATAFILTER_TYPE filter_min64High;
26
+ uniform DATAFILTER_TYPE filter_max64High;
27
+ #endif
28
+
29
+ varying float dataFilter_value;
30
+
31
+ float dataFilter_reduceValue(float value) {
32
+ return value;
33
+ }
34
+ float dataFilter_reduceValue(vec2 value) {
35
+ return min(value.x, value.y);
36
+ }
37
+ float dataFilter_reduceValue(vec3 value) {
38
+ return min(min(value.x, value.y), value.z);
39
+ }
40
+ float dataFilter_reduceValue(vec4 value) {
41
+ return min(min(value.x, value.y), min(value.z, value.w));
42
+ }
43
+ void dataFilter_setValue(DATAFILTER_TYPE valueFromMin, DATAFILTER_TYPE valueFromMax) {
44
+ if (filter_enabled) {
45
+ if (filter_useSoftMargin) {
46
+ dataFilter_value = dataFilter_reduceValue(
47
+ smoothstep(filter_min, filter_softMin, valueFromMin) *
48
+ (1.0 - smoothstep(filter_softMax, filter_max, valueFromMax))
49
+ );
50
+ } else {
51
+ dataFilter_value = dataFilter_reduceValue(
52
+ step(filter_min, valueFromMin) * step(valueFromMax, filter_max)
53
+ );
54
+ }
55
+ } else {
56
+ dataFilter_value = 1.0;
57
+ }
58
+ }
59
+ `;
60
+ const fs = `
61
+ uniform bool filter_transformColor;
62
+ varying float dataFilter_value;
63
+ `;
64
+ const getUniforms = opts => {
65
+ if (!opts || !opts.extensions) {
66
+ return {};
67
+ }
68
+ const { filterRange = [-1, 1], filterEnabled = true, filterTransformSize = true, filterTransformColor = true } = opts;
69
+ const filterSoftRange = opts.filterSoftRange || filterRange;
70
+ const uniforms = Number.isFinite(filterRange[0])
71
+ ? {
72
+ filter_min: filterRange[0],
73
+ filter_softMin: filterSoftRange[0],
74
+ filter_softMax: filterSoftRange[1],
75
+ filter_max: filterRange[1]
76
+ }
77
+ : {
78
+ filter_min: filterRange.map(r => r[0]),
79
+ filter_softMin: filterSoftRange.map(r => r[0]),
80
+ filter_softMax: filterSoftRange.map(r => r[1]),
81
+ filter_max: filterRange.map(r => r[1])
82
+ };
83
+ uniforms.filter_enabled = filterEnabled;
84
+ uniforms.filter_useSoftMargin = Boolean(opts.filterSoftRange);
85
+ uniforms.filter_transformSize = filterEnabled && filterTransformSize;
86
+ uniforms.filter_transformColor = filterEnabled && filterTransformColor;
87
+ return uniforms;
88
+ };
89
+ const getUniforms64 = opts => {
90
+ if (!opts || !opts.extensions) {
91
+ return {};
92
+ }
93
+ const uniforms = getUniforms(opts);
94
+ if (Number.isFinite(uniforms.filter_min)) {
95
+ const min64High = Math.fround(uniforms.filter_min);
96
+ uniforms.filter_min -= min64High;
97
+ uniforms.filter_softMin -= min64High;
98
+ uniforms.filter_min64High = min64High;
99
+ const max64High = Math.fround(uniforms.filter_max);
100
+ uniforms.filter_max -= max64High;
101
+ uniforms.filter_softMax -= max64High;
102
+ uniforms.filter_max64High = max64High;
103
+ }
104
+ else {
105
+ const min64High = uniforms.filter_min.map(Math.fround);
106
+ uniforms.filter_min = uniforms.filter_min.map((x, i) => x - min64High[i]);
107
+ uniforms.filter_softMin = uniforms.filter_softMin.map((x, i) => x - min64High[i]);
108
+ uniforms.filter_min64High = min64High;
109
+ const max64High = uniforms.filter_max.map(Math.fround);
110
+ uniforms.filter_max = uniforms.filter_max.map((x, i) => x - max64High[i]);
111
+ uniforms.filter_softMax = uniforms.filter_softMax.map((x, i) => x - max64High[i]);
112
+ uniforms.filter_max64High = max64High;
113
+ }
114
+ return uniforms;
115
+ };
116
+ const inject = {
117
+ 'vs:#main-start': `
118
+ #ifdef DATAFILTER_DOUBLE
119
+ dataFilter_setValue(
120
+ DATAFILTER_ATTRIB - filter_min64High + DATAFILTER_ATTRIB_64LOW,
121
+ DATAFILTER_ATTRIB - filter_max64High + DATAFILTER_ATTRIB_64LOW
122
+ );
123
+ #else
124
+ dataFilter_setValue(DATAFILTER_ATTRIB, DATAFILTER_ATTRIB);
125
+ #endif
126
+ `,
127
+ 'vs:DECKGL_FILTER_SIZE': `
128
+ if (filter_transformSize) {
129
+ size = size * dataFilter_value;
130
+ }
131
+ `,
132
+ 'fs:DECKGL_FILTER_COLOR': `
133
+ if (dataFilter_value == 0.0) discard;
134
+ if (filter_transformColor) {
135
+ color.a *= dataFilter_value;
136
+ }
137
+ `
138
+ };
139
+ export const shaderModule = {
140
+ name: 'data-filter',
141
+ vs,
142
+ fs,
143
+ inject,
144
+ getUniforms
145
+ };
146
+ export const shaderModule64 = {
147
+ name: 'data-filter-fp64',
148
+ vs,
149
+ fs,
150
+ inject,
151
+ getUniforms: getUniforms64
152
+ };
@@ -0,0 +1,152 @@
1
+ import { LayerExtension } from '@deck.gl/core';
2
+ import { Texture2D } from '@luma.gl/core';
3
+ import GL from '@luma.gl/constants';
4
+ import { patternShaders } from './shaders.glsl';
5
+ const defaultProps = {
6
+ fillPatternEnabled: true,
7
+ fillPatternAtlas: null,
8
+ fillPatternMapping: null,
9
+ fillPatternMask: true,
10
+ getFillPattern: { type: 'accessor', value: d => d.pattern },
11
+ getFillPatternScale: { type: 'accessor', value: 1 },
12
+ getFillPatternOffset: { type: 'accessor', value: [0, 0] }
13
+ };
14
+ const DEFAULT_TEXTURE_PARAMETERS = {
15
+ [GL.TEXTURE_MIN_FILTER]: GL.LINEAR,
16
+ // GL.LINEAR is the default value but explicitly set it here
17
+ [GL.TEXTURE_MAG_FILTER]: GL.LINEAR,
18
+ // for texture boundary artifact
19
+ [GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,
20
+ [GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE
21
+ };
22
+ export default class FillStyleExtension extends LayerExtension {
23
+ constructor({ pattern = false } = {}) {
24
+ super({ pattern });
25
+ }
26
+ isEnabled(layer) {
27
+ return layer.getAttributeManager() && !layer.state.pathTesselator;
28
+ }
29
+ getShaders(extension) {
30
+ if (!extension.isEnabled(this)) {
31
+ return null;
32
+ }
33
+ return {
34
+ modules: [extension.opts.pattern && patternShaders].filter(Boolean)
35
+ };
36
+ }
37
+ initializeState(context, extension) {
38
+ if (!extension.isEnabled(this)) {
39
+ return;
40
+ }
41
+ const attributeManager = this.getAttributeManager();
42
+ if (extension.opts.pattern) {
43
+ attributeManager.add({
44
+ fillPatternFrames: {
45
+ size: 4,
46
+ accessor: 'getFillPattern',
47
+ transform: extension.getPatternFrame.bind(this),
48
+ shaderAttributes: {
49
+ fillPatternFrames: {
50
+ divisor: 0
51
+ },
52
+ instanceFillPatternFrames: {
53
+ divisor: 1
54
+ }
55
+ }
56
+ },
57
+ fillPatternScales: {
58
+ size: 1,
59
+ accessor: 'getFillPatternScale',
60
+ defaultValue: 1,
61
+ shaderAttributes: {
62
+ fillPatternScales: {
63
+ divisor: 0
64
+ },
65
+ instanceFillPatternScales: {
66
+ divisor: 1
67
+ }
68
+ }
69
+ },
70
+ fillPatternOffsets: {
71
+ size: 2,
72
+ accessor: 'getFillPatternOffset',
73
+ shaderAttributes: {
74
+ fillPatternOffsets: {
75
+ divisor: 0
76
+ },
77
+ instanceFillPatternOffsets: {
78
+ divisor: 1
79
+ }
80
+ }
81
+ }
82
+ });
83
+ }
84
+ this.setState({
85
+ emptyTexture: new Texture2D(this.context.gl, {
86
+ data: new Uint8Array(4),
87
+ width: 1,
88
+ height: 1
89
+ })
90
+ });
91
+ }
92
+ updateState({ props, oldProps }, extension) {
93
+ if (!extension.isEnabled(this)) {
94
+ return;
95
+ }
96
+ if (props.fillPatternAtlas && props.fillPatternAtlas !== oldProps.fillPatternAtlas) {
97
+ extension.loadPatternAtlas.call(this, props);
98
+ }
99
+ if (props.fillPatternMapping && props.fillPatternMapping !== oldProps.fillPatternMapping) {
100
+ extension.loadPatternMapping.call(this, props);
101
+ }
102
+ }
103
+ draw(params, extension) {
104
+ if (!extension.isEnabled(this)) {
105
+ return;
106
+ }
107
+ const { patternTexture } = this.state;
108
+ this.setModuleParameters({
109
+ fillPatternTexture: patternTexture || this.state.emptyTexture
110
+ });
111
+ }
112
+ finalizeState() {
113
+ const { patternTexture, emptyTexture } = this.state;
114
+ patternTexture?.delete();
115
+ emptyTexture?.delete();
116
+ }
117
+ async loadPatternAtlas({ fillPatternAtlas, fetch }) {
118
+ this.state.patternTexture?.delete();
119
+ this.setState({ patternTexture: null });
120
+ let image = fillPatternAtlas;
121
+ if (typeof image === 'string') {
122
+ image = await fetch(image, { propName: 'fillPatternAtlas', layer: this });
123
+ }
124
+ const patternTexture = image instanceof Texture2D
125
+ ? image
126
+ : new Texture2D(this.context.gl, {
127
+ data: image,
128
+ parameters: DEFAULT_TEXTURE_PARAMETERS
129
+ });
130
+ this.setState({ patternTexture });
131
+ }
132
+ async loadPatternMapping({ fillPatternMapping, fetch }) {
133
+ this.setState({ patternMapping: null });
134
+ let patternMapping = fillPatternMapping;
135
+ if (typeof patternMapping === 'string') {
136
+ patternMapping = await fetch(patternMapping, {
137
+ propName: 'fillPatternMapping',
138
+ layer: this
139
+ });
140
+ }
141
+ this.setState({ patternMapping });
142
+ this.getAttributeManager().invalidate('getFillPattern');
143
+ this.setNeedsUpdate();
144
+ }
145
+ getPatternFrame(name) {
146
+ const { patternMapping } = this.state;
147
+ const def = patternMapping && patternMapping[name];
148
+ return def ? [def.x, def.y, def.width, def.height] : [0, 0, 0, 0];
149
+ }
150
+ }
151
+ FillStyleExtension.extensionName = 'FillStyleExtension';
152
+ FillStyleExtension.defaultProps = defaultProps;
@@ -0,0 +1,95 @@
1
+ import { project, COORDINATE_SYSTEM } from '@deck.gl/core';
2
+ /*
3
+ * fill pattern shader module
4
+ */
5
+ const patternVs = `
6
+ #ifdef NON_INSTANCED_MODEL
7
+ #define FILL_PATTERN_FRAME_ATTRIB fillPatternFrames
8
+ #define FILL_PATTERN_SCALE_ATTRIB fillPatternScales
9
+ #define FILL_PATTERN_OFFSET_ATTRIB fillPatternOffsets
10
+ #else
11
+ #define FILL_PATTERN_FRAME_ATTRIB instanceFillPatternFrames
12
+ #define FILL_PATTERN_SCALE_ATTRIB instanceFillPatternScales
13
+ #define FILL_PATTERN_OFFSET_ATTRIB instanceFillPatternOffsets
14
+ #endif
15
+
16
+ attribute vec4 FILL_PATTERN_FRAME_ATTRIB;
17
+ attribute float FILL_PATTERN_SCALE_ATTRIB;
18
+ attribute vec2 FILL_PATTERN_OFFSET_ATTRIB;
19
+
20
+ uniform bool fill_patternEnabled;
21
+ uniform vec2 fill_patternTextureSize;
22
+
23
+ varying vec2 fill_uv;
24
+ varying vec4 fill_patternBounds;
25
+ varying vec3 fill_patternPlacement;
26
+ `;
27
+ const patternFs = `
28
+ uniform bool fill_patternEnabled;
29
+ uniform bool fill_patternMask;
30
+ uniform sampler2D fill_patternTexture;
31
+ uniform vec2 fill_uvCoordinateOrigin;
32
+
33
+ varying vec4 fill_patternBounds;
34
+ varying vec3 fill_patternPlacement;
35
+ varying vec2 fill_uv;
36
+
37
+ const float FILL_UV_SCALE = 512.0 / 40000000.0;
38
+ `;
39
+ const inject = {
40
+ 'vs:DECKGL_FILTER_GL_POSITION': `
41
+ fill_uv = geometry.position.xy;
42
+ `,
43
+ 'vs:DECKGL_FILTER_COLOR': `
44
+ if (fill_patternEnabled) {
45
+ fill_patternBounds = FILL_PATTERN_FRAME_ATTRIB / vec4(fill_patternTextureSize, fill_patternTextureSize);
46
+ fill_patternPlacement.xy = FILL_PATTERN_OFFSET_ATTRIB;
47
+ fill_patternPlacement.z = FILL_PATTERN_SCALE_ATTRIB * FILL_PATTERN_FRAME_ATTRIB.w;
48
+ }
49
+ `,
50
+ 'fs:DECKGL_FILTER_COLOR': `
51
+ if (fill_patternEnabled) {
52
+ float scale = FILL_UV_SCALE * fill_patternPlacement.z;
53
+ vec2 patternUV = mod(mod(fill_uvCoordinateOrigin, scale) + fill_uv, scale) / scale;
54
+ patternUV = mod(fill_patternPlacement.xy + patternUV, 1.0);
55
+
56
+ vec2 texCoords = fill_patternBounds.xy + fill_patternBounds.zw * patternUV;
57
+
58
+ vec4 patternColor = texture2D(fill_patternTexture, texCoords);
59
+ color.a *= patternColor.a;
60
+ if (!fill_patternMask) {
61
+ color.rgb = patternColor.rgb;
62
+ }
63
+ }
64
+ `
65
+ };
66
+ function getPatternUniforms(opts = {}, uniforms) {
67
+ if ('fillPatternTexture' in opts) {
68
+ const { fillPatternTexture } = opts;
69
+ return {
70
+ fill_patternTexture: fillPatternTexture,
71
+ fill_patternTextureSize: [fillPatternTexture.width, fillPatternTexture.height]
72
+ };
73
+ }
74
+ if (opts.viewport) {
75
+ const { viewport, fillPatternMask = true, fillPatternEnabled = true } = opts;
76
+ const { project_uCoordinateOrigin, project_uCoordinateSystem } = uniforms;
77
+ const coordinateOriginCommon = project_uCoordinateSystem === COORDINATE_SYSTEM.CARTESIAN
78
+ ? project_uCoordinateOrigin
79
+ : viewport.projectPosition(project_uCoordinateOrigin);
80
+ return {
81
+ fill_uvCoordinateOrigin: coordinateOriginCommon.slice(0, 2),
82
+ fill_patternMask: fillPatternMask,
83
+ fill_patternEnabled: fillPatternEnabled
84
+ };
85
+ }
86
+ return {};
87
+ }
88
+ export const patternShaders = {
89
+ name: 'fill-pattern',
90
+ vs: patternVs,
91
+ fs: patternFs,
92
+ inject,
93
+ dependencies: [project],
94
+ getUniforms: getPatternUniforms
95
+ };
@@ -0,0 +1,34 @@
1
+ // Copyright (c) 2015 - 2017 Uber Technologies, Inc.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in
11
+ // all copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ // THE SOFTWARE.
20
+ import { LayerExtension, COORDINATE_SYSTEM } from '@deck.gl/core';
21
+ import project64 from './project64';
22
+ export default class Fp64Extension extends LayerExtension {
23
+ getShaders(opts) {
24
+ const { coordinateSystem } = this.props;
25
+ if (coordinateSystem !== COORDINATE_SYSTEM.LNGLAT &&
26
+ coordinateSystem !== COORDINATE_SYSTEM.DEFAULT) {
27
+ throw new Error('fp64: coordinateSystem must be LNGLAT');
28
+ }
29
+ return {
30
+ modules: [project64]
31
+ };
32
+ }
33
+ }
34
+ Fp64Extension.extensionName = 'Fp64Extension';
@@ -0,0 +1,100 @@
1
+ // Copyright (c) 2015 - 2017 Uber Technologies, Inc.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in
11
+ // all copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ // THE SOFTWARE.
20
+ export default `\
21
+
22
+ const vec2 WORLD_SCALE_FP64 = vec2(81.4873275756836, 0.0000032873668232014097);
23
+
24
+ uniform vec2 project_uViewProjectionMatrixFP64[16];
25
+
26
+ // longitude: lnglat_fp64.xy; latitude: lnglat_fp64.zw
27
+ void mercatorProject_fp64(vec4 lnglat_fp64, out vec2 out_val[2]) {
28
+
29
+ #if defined(NVIDIA_FP64_WORKAROUND)
30
+ out_val[0] = sum_fp64(radians_fp64(lnglat_fp64.xy), PI_FP64 * ONE);
31
+ #else
32
+ out_val[0] = sum_fp64(radians_fp64(lnglat_fp64.xy), PI_FP64);
33
+ #endif
34
+ out_val[1] = sum_fp64(PI_FP64,
35
+ log_fp64(tan_fp64(sum_fp64(PI_4_FP64, radians_fp64(lnglat_fp64.zw) / 2.0))));
36
+ return;
37
+ }
38
+
39
+ void project_position_fp64(vec4 position_fp64, out vec2 out_val[2]) {
40
+ vec2 pos_fp64[2];
41
+ mercatorProject_fp64(position_fp64, pos_fp64);
42
+ out_val[0] = mul_fp64(pos_fp64[0], WORLD_SCALE_FP64);
43
+ out_val[1] = mul_fp64(pos_fp64[1], WORLD_SCALE_FP64);
44
+
45
+ return;
46
+ }
47
+
48
+ void project_position_fp64(vec2 position, vec2 position64xyLow, out vec2 out_val[2]) {
49
+ vec4 position64xy = vec4(
50
+ position.x, position64xyLow.x,
51
+ position.y, position64xyLow.y);
52
+
53
+ project_position_fp64(position64xy, out_val);
54
+ }
55
+
56
+ vec4 project_common_position_to_clipspace_fp64(vec2 vertex_pos_modelspace[4]) {
57
+ vec2 vertex_pos_clipspace[4];
58
+ mat4_vec4_mul_fp64(project_uViewProjectionMatrixFP64, vertex_pos_modelspace,
59
+ vertex_pos_clipspace);
60
+ return vec4(
61
+ vertex_pos_clipspace[0].x,
62
+ vertex_pos_clipspace[1].x,
63
+ vertex_pos_clipspace[2].x,
64
+ vertex_pos_clipspace[3].x
65
+ );
66
+ }
67
+
68
+ vec4 project_position_to_clipspace(
69
+ vec3 position, vec3 position64xyLow, vec3 offset, out vec4 commonPosition
70
+ ) {
71
+ // This is the local offset to the instance position
72
+ vec2 offset64[4];
73
+ vec4_fp64(vec4(offset, 0.0), offset64);
74
+
75
+ float z = project_size(position.z);
76
+
77
+ // Apply web mercator projection (depends on coordinate system imn use)
78
+ vec2 projectedPosition64xy[2];
79
+ project_position_fp64(position.xy, position64xyLow.xy, projectedPosition64xy);
80
+
81
+ vec2 commonPosition64[4];
82
+ commonPosition64[0] = sum_fp64(offset64[0], projectedPosition64xy[0]);
83
+ commonPosition64[1] = sum_fp64(offset64[1], projectedPosition64xy[1]);
84
+ commonPosition64[2] = sum_fp64(offset64[2], vec2(z, 0.0));
85
+ commonPosition64[3] = vec2(1.0, 0.0);
86
+
87
+ commonPosition = vec4(projectedPosition64xy[0].x, projectedPosition64xy[1].x, z, 1.0);
88
+
89
+ return project_common_position_to_clipspace_fp64(commonPosition64);
90
+ }
91
+
92
+ vec4 project_position_to_clipspace(
93
+ vec3 position, vec3 position64xyLow, vec3 offset
94
+ ) {
95
+ vec4 commonPosition;
96
+ return project_position_to_clipspace(
97
+ position, position64xyLow, offset, commonPosition
98
+ );
99
+ }
100
+ `;
@@ -0,0 +1,50 @@
1
+ // Copyright (c) 2015 - 2017 Uber Technologies, Inc.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in
11
+ // all copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ // THE SOFTWARE.
20
+ import { fp64 } from '@luma.gl/shadertools';
21
+ const { fp64ify, fp64ifyMatrix4 } = fp64;
22
+ import { project, _memoize as memoize } from '@deck.gl/core';
23
+ import project64Shader from './project64.glsl';
24
+ export default {
25
+ name: 'project64',
26
+ dependencies: [project, fp64],
27
+ vs: project64Shader,
28
+ getUniforms
29
+ };
30
+ // TODO - this module should calculate the 64 bit uniforms
31
+ // It is currently done by project to minimize duplicated work
32
+ const DEFAULT_MODULE_OPTIONS = {};
33
+ const getMemoizedUniforms = memoize(calculateUniforms);
34
+ function getUniforms(opts = DEFAULT_MODULE_OPTIONS) {
35
+ if (opts.viewport) {
36
+ const { viewProjectionMatrix, scale } = opts.viewport;
37
+ // We only need to update fp64 uniforms if fp32 projection is being updated
38
+ return getMemoizedUniforms({ viewProjectionMatrix, scale });
39
+ }
40
+ return {};
41
+ }
42
+ function calculateUniforms({ viewProjectionMatrix, scale }) {
43
+ const glViewProjectionMatrixFP64 = fp64ifyMatrix4(viewProjectionMatrix);
44
+ const scaleFP64 = fp64ify(scale);
45
+ return {
46
+ project_uViewProjectionMatrixFP64: glViewProjectionMatrixFP64,
47
+ project64_uViewProjectionMatrix: glViewProjectionMatrixFP64,
48
+ project64_uScale: scaleFP64
49
+ };
50
+ }
package/typed/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export { default as BrushingExtension } from './brushing/brushing-extension';
2
+ export { default as DataFilterExtension } from './data-filter/data-filter-extension';
3
+ export { default as Fp64Extension } from './fp64/fp64-extension';
4
+ export { default as PathStyleExtension } from './path-style/path-style-extension';
5
+ export { default as FillStyleExtension } from './fill-style/fill-style';
6
+ export { default as ClipExtension } from './clip/clip-extension';
7
+ export { default as MaskExtension } from './mask/mask';
8
+ // Shader module
9
+ export { default as project64 } from './fp64/project64';
@@ -0,0 +1,48 @@
1
+ import { COORDINATE_SYSTEM, LayerExtension, log } from '@deck.gl/core';
2
+ import mask from './shader-module';
3
+ const defaultProps = {
4
+ maskId: ''
5
+ };
6
+ export default class MaskExtension extends LayerExtension {
7
+ getShaders() {
8
+ // Infer by geometry if 'maskByInstance' prop isn't explictly set
9
+ let maskByInstance = 'instancePositions' in this.getAttributeManager().attributes;
10
+ // Users can override by setting the `maskByInstance` prop
11
+ if ('maskByInstance' in this.props) {
12
+ maskByInstance = this.props.maskByInstance;
13
+ }
14
+ this.state.maskByInstance = maskByInstance;
15
+ return {
16
+ modules: [mask]
17
+ };
18
+ }
19
+ draw({ uniforms, context, moduleParameters }) {
20
+ uniforms.mask_maskByInstance = this.state.maskByInstance;
21
+ const { maskId } = this.props;
22
+ const { maskChannels } = moduleParameters;
23
+ const { viewport } = context;
24
+ if (maskChannels && maskChannels[maskId]) {
25
+ const { index, bounds, coordinateOrigin: fromCoordinateOrigin } = maskChannels[maskId];
26
+ let { coordinateSystem: fromCoordinateSystem } = maskChannels[maskId];
27
+ uniforms.mask_enabled = true;
28
+ uniforms.mask_channel = index;
29
+ if (fromCoordinateSystem === COORDINATE_SYSTEM.DEFAULT) {
30
+ fromCoordinateSystem = viewport.isGeospatial
31
+ ? COORDINATE_SYSTEM.LNGLAT
32
+ : COORDINATE_SYSTEM.CARTESIAN;
33
+ }
34
+ const opts = { modelMatrix: null, fromCoordinateOrigin, fromCoordinateSystem };
35
+ const bl = this.projectPosition([bounds[0], bounds[1], 0], opts);
36
+ const tr = this.projectPosition([bounds[2], bounds[3], 0], opts);
37
+ uniforms.mask_bounds = [bl[0], bl[1], tr[0], tr[1]];
38
+ }
39
+ else {
40
+ if (maskId) {
41
+ log.warn(`Could not find a mask layer with id: ${maskId}`)();
42
+ }
43
+ uniforms.mask_enabled = false;
44
+ }
45
+ }
46
+ }
47
+ MaskExtension.extensionName = 'MaskExtension';
48
+ MaskExtension.defaultProps = defaultProps;