@deck.gl/extensions 9.0.0-beta.2 → 9.0.0-beta.4
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/brushing/brushing-extension.js +80 -0
- package/{typed → dist}/brushing/shader-module.d.ts +1 -1
- package/{typed → dist}/brushing/shader-module.d.ts.map +1 -1
- package/dist/{esm/brushing → brushing}/shader-module.js +24 -30
- package/dist/clip/clip-extension.js +117 -0
- package/{typed → dist}/collision-filter/collision-filter-effect.d.ts.map +1 -1
- package/dist/collision-filter/collision-filter-effect.js +193 -0
- package/dist/collision-filter/collision-filter-extension.js +49 -0
- package/{typed → dist}/collision-filter/collision-filter-pass.d.ts.map +1 -1
- package/dist/collision-filter/collision-filter-pass.js +25 -0
- package/dist/{esm/collision-filter → collision-filter}/shader-module.js +17 -24
- package/dist/data-filter/aggregator.js +104 -0
- package/{typed → dist}/data-filter/data-filter-extension.d.ts +36 -5
- package/dist/data-filter/data-filter-extension.d.ts.map +1 -0
- package/dist/data-filter/data-filter-extension.js +243 -0
- package/{typed → dist}/data-filter/shader-module.d.ts +1 -1
- package/dist/data-filter/shader-module.d.ts.map +1 -0
- package/dist/data-filter/shader-module.js +187 -0
- package/dist/dist.dev.js +1847 -13033
- package/dist/fill-style/fill-style-extension.js +118 -0
- package/dist/{esm/fill-style → fill-style}/shaders.glsl.js +37 -43
- package/dist/fp64/fp64-extension.js +35 -0
- package/dist/{esm/fp64 → fp64}/project64.glsl.js +19 -1
- package/dist/fp64/project64.js +50 -0
- package/dist/index.cjs +2814 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/{typed → dist}/mask/mask-effect.d.ts +1 -1
- package/dist/mask/mask-effect.d.ts.map +1 -0
- package/dist/mask/mask-effect.js +194 -0
- package/dist/mask/mask-extension.js +57 -0
- package/{typed → dist}/mask/mask-pass.d.ts.map +1 -1
- package/dist/mask/mask-pass.js +44 -0
- package/dist/{esm/mask → mask}/shader-module.js +18 -21
- package/dist/path-style/path-style-extension.js +111 -0
- package/dist/{esm/path-style → path-style}/shaders.glsl.js +20 -13
- package/{typed → dist}/terrain/height-map-builder.d.ts +1 -1
- package/dist/terrain/height-map-builder.d.ts.map +1 -0
- package/dist/terrain/height-map-builder.js +104 -0
- package/{typed → dist}/terrain/shader-module.d.ts +2 -2
- package/dist/terrain/shader-module.d.ts.map +1 -0
- package/dist/terrain/shader-module.js +139 -0
- package/{typed → dist}/terrain/terrain-cover.d.ts +1 -1
- package/dist/terrain/terrain-cover.d.ts.map +1 -0
- package/dist/terrain/terrain-cover.js +187 -0
- package/{typed → dist}/terrain/terrain-effect.d.ts +1 -1
- package/dist/terrain/terrain-effect.d.ts.map +1 -0
- package/dist/terrain/terrain-effect.js +184 -0
- package/dist/terrain/terrain-extension.js +44 -0
- package/{typed → dist}/terrain/terrain-pass.d.ts +2 -2
- package/dist/terrain/terrain-pass.d.ts.map +1 -0
- package/dist/terrain/terrain-pass.js +61 -0
- package/{typed → dist}/terrain/terrain-picking-pass.d.ts +1 -1
- package/dist/terrain/terrain-picking-pass.d.ts.map +1 -0
- package/dist/terrain/terrain-picking-pass.js +66 -0
- package/dist/terrain/utils.js +21 -0
- package/{typed → dist}/utils/debug.d.ts.map +1 -1
- package/dist/utils/debug.js +50 -0
- package/dist/utils/projection-utils.js +153 -0
- package/dist.min.js +104 -208
- package/package.json +19 -12
- package/src/collision-filter/collision-filter-effect.ts +12 -8
- package/src/collision-filter/collision-filter-pass.ts +1 -3
- package/src/data-filter/data-filter-extension.ts +136 -29
- package/src/data-filter/shader-module.ts +31 -3
- package/src/mask/mask-effect.ts +0 -1
- package/src/mask/mask-pass.ts +1 -3
- package/src/terrain/terrain-effect.ts +8 -2
- package/src/terrain/terrain-pass.ts +2 -5
- package/src/terrain/terrain-picking-pass.ts +1 -3
- package/src/utils/debug.ts +1 -2
- package/dist/es5/brushing/brushing-extension.js +0 -108
- package/dist/es5/brushing/brushing-extension.js.map +0 -1
- package/dist/es5/brushing/shader-module.js +0 -50
- package/dist/es5/brushing/shader-module.js.map +0 -1
- package/dist/es5/clip/clip-extension.js +0 -98
- package/dist/es5/clip/clip-extension.js.map +0 -1
- package/dist/es5/collision-filter/collision-filter-effect.js +0 -294
- package/dist/es5/collision-filter/collision-filter-effect.js.map +0 -1
- package/dist/es5/collision-filter/collision-filter-extension.js +0 -109
- package/dist/es5/collision-filter/collision-filter-extension.js.map +0 -1
- package/dist/es5/collision-filter/collision-filter-pass.js +0 -79
- package/dist/es5/collision-filter/collision-filter-pass.js.map +0 -1
- package/dist/es5/collision-filter/shader-module.js +0 -39
- package/dist/es5/collision-filter/shader-module.js.map +0 -1
- package/dist/es5/data-filter/aggregator.js +0 -79
- package/dist/es5/data-filter/aggregator.js.map +0 -1
- package/dist/es5/data-filter/data-filter-extension.js +0 -236
- package/dist/es5/data-filter/data-filter-extension.js.map +0 -1
- package/dist/es5/data-filter/shader-module.js +0 -122
- package/dist/es5/data-filter/shader-module.js.map +0 -1
- package/dist/es5/fill-style/fill-style-extension.js +0 -190
- package/dist/es5/fill-style/fill-style-extension.js.map +0 -1
- package/dist/es5/fill-style/shaders.glsl.js +0 -59
- package/dist/es5/fill-style/shaders.glsl.js.map +0 -1
- package/dist/es5/fp64/fp64-extension.js +0 -55
- package/dist/es5/fp64/fp64-extension.js.map +0 -1
- package/dist/es5/fp64/project64.glsl.js +0 -9
- package/dist/es5/fp64/project64.glsl.js.map +0 -1
- package/dist/es5/fp64/project64.js +0 -52
- package/dist/es5/fp64/project64.js.map +0 -1
- package/dist/es5/index.js +0 -88
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/mask/mask-effect.js +0 -279
- package/dist/es5/mask/mask-effect.js.map +0 -1
- package/dist/es5/mask/mask-extension.js +0 -113
- package/dist/es5/mask/mask-extension.js.map +0 -1
- package/dist/es5/mask/mask-pass.js +0 -106
- package/dist/es5/mask/mask-pass.js.map +0 -1
- package/dist/es5/mask/shader-module.js +0 -38
- package/dist/es5/mask/shader-module.js.map +0 -1
- package/dist/es5/path-style/path-style-extension.js +0 -169
- package/dist/es5/path-style/path-style-extension.js.map +0 -1
- package/dist/es5/path-style/shaders.glsl.js +0 -25
- package/dist/es5/path-style/shaders.glsl.js.map +0 -1
- package/dist/es5/terrain/height-map-builder.js +0 -111
- package/dist/es5/terrain/height-map-builder.js.map +0 -1
- package/dist/es5/terrain/shader-module.js +0 -86
- package/dist/es5/terrain/shader-module.js.map +0 -1
- package/dist/es5/terrain/terrain-cover.js +0 -256
- package/dist/es5/terrain/terrain-cover.js.map +0 -1
- package/dist/es5/terrain/terrain-effect.js +0 -326
- package/dist/es5/terrain/terrain-effect.js.map +0 -1
- package/dist/es5/terrain/terrain-extension.js +0 -94
- package/dist/es5/terrain/terrain-extension.js.map +0 -1
- package/dist/es5/terrain/terrain-pass.js +0 -121
- package/dist/es5/terrain/terrain-pass.js.map +0 -1
- package/dist/es5/terrain/terrain-picking-pass.js +0 -124
- package/dist/es5/terrain/terrain-picking-pass.js.map +0 -1
- package/dist/es5/terrain/utils.js +0 -35
- package/dist/es5/terrain/utils.js.map +0 -1
- package/dist/es5/utils/debug.js +0 -71
- package/dist/es5/utils/debug.js.map +0 -1
- package/dist/es5/utils/projection-utils.js +0 -168
- package/dist/es5/utils/projection-utils.js.map +0 -1
- package/dist/esm/brushing/brushing-extension.js +0 -68
- package/dist/esm/brushing/brushing-extension.js.map +0 -1
- package/dist/esm/brushing/shader-module.js.map +0 -1
- package/dist/esm/clip/clip-extension.js +0 -86
- package/dist/esm/clip/clip-extension.js.map +0 -1
- package/dist/esm/collision-filter/collision-filter-effect.js +0 -246
- package/dist/esm/collision-filter/collision-filter-effect.js.map +0 -1
- package/dist/esm/collision-filter/collision-filter-extension.js +0 -75
- package/dist/esm/collision-filter/collision-filter-extension.js.map +0 -1
- package/dist/esm/collision-filter/collision-filter-pass.js +0 -32
- package/dist/esm/collision-filter/collision-filter-pass.js.map +0 -1
- package/dist/esm/collision-filter/shader-module.js.map +0 -1
- package/dist/esm/data-filter/aggregator.js +0 -102
- package/dist/esm/data-filter/aggregator.js.map +0 -1
- package/dist/esm/data-filter/data-filter-extension.js +0 -189
- package/dist/esm/data-filter/data-filter-extension.js.map +0 -1
- package/dist/esm/data-filter/shader-module.js +0 -164
- package/dist/esm/data-filter/shader-module.js.map +0 -1
- package/dist/esm/fill-style/fill-style-extension.js +0 -156
- package/dist/esm/fill-style/fill-style-extension.js.map +0 -1
- package/dist/esm/fill-style/shaders.glsl.js.map +0 -1
- package/dist/esm/fp64/fp64-extension.js +0 -20
- package/dist/esm/fp64/fp64-extension.js.map +0 -1
- package/dist/esm/fp64/project64.glsl.js.map +0 -1
- package/dist/esm/fp64/project64.js +0 -43
- package/dist/esm/fp64/project64.js.map +0 -1
- package/dist/esm/index.js +0 -11
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/mask/mask-effect.js +0 -228
- package/dist/esm/mask/mask-effect.js.map +0 -1
- package/dist/esm/mask/mask-extension.js +0 -83
- package/dist/esm/mask/mask-extension.js.map +0 -1
- package/dist/esm/mask/mask-pass.js +0 -58
- package/dist/esm/mask/mask-pass.js.map +0 -1
- package/dist/esm/mask/shader-module.js.map +0 -1
- package/dist/esm/path-style/path-style-extension.js +0 -130
- package/dist/esm/path-style/path-style-extension.js.map +0 -1
- package/dist/esm/path-style/shaders.glsl.js.map +0 -1
- package/dist/esm/terrain/height-map-builder.js +0 -86
- package/dist/esm/terrain/height-map-builder.js.map +0 -1
- package/dist/esm/terrain/shader-module.js +0 -127
- package/dist/esm/terrain/shader-module.js.map +0 -1
- package/dist/esm/terrain/terrain-cover.js +0 -212
- package/dist/esm/terrain/terrain-cover.js.map +0 -1
- package/dist/esm/terrain/terrain-effect.js +0 -219
- package/dist/esm/terrain/terrain-effect.js.map +0 -1
- package/dist/esm/terrain/terrain-extension.js +0 -59
- package/dist/esm/terrain/terrain-extension.js.map +0 -1
- package/dist/esm/terrain/terrain-pass.js +0 -71
- package/dist/esm/terrain/terrain-pass.js.map +0 -1
- package/dist/esm/terrain/terrain-picking-pass.js +0 -73
- package/dist/esm/terrain/terrain-picking-pass.js.map +0 -1
- package/dist/esm/terrain/utils.js +0 -19
- package/dist/esm/terrain/utils.js.map +0 -1
- package/dist/esm/utils/debug.js +0 -61
- package/dist/esm/utils/debug.js.map +0 -1
- package/dist/esm/utils/projection-utils.js +0 -134
- package/dist/esm/utils/projection-utils.js.map +0 -1
- package/typed/data-filter/data-filter-extension.d.ts.map +0 -1
- package/typed/data-filter/shader-module.d.ts.map +0 -1
- package/typed/index.d.ts +0 -19
- package/typed/index.d.ts.map +0 -1
- package/typed/mask/mask-effect.d.ts.map +0 -1
- package/typed/terrain/height-map-builder.d.ts.map +0 -1
- package/typed/terrain/shader-module.d.ts.map +0 -1
- package/typed/terrain/terrain-cover.d.ts.map +0 -1
- package/typed/terrain/terrain-effect.d.ts.map +0 -1
- package/typed/terrain/terrain-pass.d.ts.map +0 -1
- package/typed/terrain/terrain-picking-pass.d.ts.map +0 -1
- /package/{typed → dist}/brushing/brushing-extension.d.ts +0 -0
- /package/{typed → dist}/brushing/brushing-extension.d.ts.map +0 -0
- /package/{typed → dist}/clip/clip-extension.d.ts +0 -0
- /package/{typed → dist}/clip/clip-extension.d.ts.map +0 -0
- /package/{typed → dist}/collision-filter/collision-filter-effect.d.ts +0 -0
- /package/{typed → dist}/collision-filter/collision-filter-extension.d.ts +0 -0
- /package/{typed → dist}/collision-filter/collision-filter-extension.d.ts.map +0 -0
- /package/{typed → dist}/collision-filter/collision-filter-pass.d.ts +0 -0
- /package/{typed → dist}/collision-filter/shader-module.d.ts +0 -0
- /package/{typed → dist}/collision-filter/shader-module.d.ts.map +0 -0
- /package/{typed → dist}/data-filter/aggregator.d.ts +0 -0
- /package/{typed → dist}/data-filter/aggregator.d.ts.map +0 -0
- /package/{typed → dist}/fill-style/fill-style-extension.d.ts +0 -0
- /package/{typed → dist}/fill-style/fill-style-extension.d.ts.map +0 -0
- /package/{typed → dist}/fill-style/shaders.glsl.d.ts +0 -0
- /package/{typed → dist}/fill-style/shaders.glsl.d.ts.map +0 -0
- /package/{typed → dist}/fp64/fp64-extension.d.ts +0 -0
- /package/{typed → dist}/fp64/fp64-extension.d.ts.map +0 -0
- /package/{typed → dist}/fp64/project64.d.ts +0 -0
- /package/{typed → dist}/fp64/project64.d.ts.map +0 -0
- /package/{typed → dist}/fp64/project64.glsl.d.ts +0 -0
- /package/{typed → dist}/fp64/project64.glsl.d.ts.map +0 -0
- /package/{typed → dist}/mask/mask-extension.d.ts +0 -0
- /package/{typed → dist}/mask/mask-extension.d.ts.map +0 -0
- /package/{typed → dist}/mask/mask-pass.d.ts +0 -0
- /package/{typed → dist}/mask/shader-module.d.ts +0 -0
- /package/{typed → dist}/mask/shader-module.d.ts.map +0 -0
- /package/{typed → dist}/path-style/path-style-extension.d.ts +0 -0
- /package/{typed → dist}/path-style/path-style-extension.d.ts.map +0 -0
- /package/{typed → dist}/path-style/shaders.glsl.d.ts +0 -0
- /package/{typed → dist}/path-style/shaders.glsl.d.ts.map +0 -0
- /package/{typed → dist}/terrain/terrain-extension.d.ts +0 -0
- /package/{typed → dist}/terrain/terrain-extension.d.ts.map +0 -0
- /package/{typed → dist}/terrain/utils.d.ts +0 -0
- /package/{typed → dist}/terrain/utils.d.ts.map +0 -0
- /package/{typed → dist}/utils/debug.d.ts +0 -0
- /package/{typed → dist}/utils/projection-utils.d.ts +0 -0
- /package/{typed → dist}/utils/projection-utils.d.ts.map +0 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Model } from '@luma.gl/engine';
|
|
2
|
+
import { GL } from '@luma.gl/constants';
|
|
3
|
+
const AGGREGATE_VS = `\
|
|
4
|
+
#version 300 es
|
|
5
|
+
#define SHADER_NAME data-filter-vertex-shader
|
|
6
|
+
|
|
7
|
+
#ifdef FLOAT_TARGET
|
|
8
|
+
in float filterIndices;
|
|
9
|
+
in float filterPrevIndices;
|
|
10
|
+
#else
|
|
11
|
+
in vec2 filterIndices;
|
|
12
|
+
in vec2 filterPrevIndices;
|
|
13
|
+
#endif
|
|
14
|
+
|
|
15
|
+
out vec4 vColor;
|
|
16
|
+
const float component = 1.0 / 255.0;
|
|
17
|
+
|
|
18
|
+
void main() {
|
|
19
|
+
#ifdef FLOAT_TARGET
|
|
20
|
+
dataFilter_value *= float(filterIndices != filterPrevIndices);
|
|
21
|
+
gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
|
|
22
|
+
vColor = vec4(0.0, 0.0, 0.0, 1.0);
|
|
23
|
+
#else
|
|
24
|
+
// Float texture is not supported: pack result into 4 channels x 256 px x 64px
|
|
25
|
+
dataFilter_value *= float(filterIndices.x != filterPrevIndices.x);
|
|
26
|
+
float col = filterIndices.x;
|
|
27
|
+
float row = filterIndices.y * 4.0;
|
|
28
|
+
float channel = floor(row);
|
|
29
|
+
row = fract(row);
|
|
30
|
+
vColor = component * vec4(bvec4(channel == 0.0, channel == 1.0, channel == 2.0, channel == 3.0));
|
|
31
|
+
gl_Position = vec4(col * 2.0 - 1.0, row * 2.0 - 1.0, 0.0, 1.0);
|
|
32
|
+
#endif
|
|
33
|
+
gl_PointSize = 1.0;
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
36
|
+
const AGGREGATE_FS = `\
|
|
37
|
+
#version 300 es
|
|
38
|
+
#define SHADER_NAME data-filter-fragment-shader
|
|
39
|
+
precision highp float;
|
|
40
|
+
|
|
41
|
+
in vec4 vColor;
|
|
42
|
+
|
|
43
|
+
out vec4 fragColor;
|
|
44
|
+
|
|
45
|
+
void main() {
|
|
46
|
+
if (dataFilter_value < 0.5) {
|
|
47
|
+
discard;
|
|
48
|
+
}
|
|
49
|
+
fragColor = vColor;
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
52
|
+
export function supportsFloatTarget(device) {
|
|
53
|
+
// @ts-expect-error
|
|
54
|
+
const gl = device.gl;
|
|
55
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_best_practices#Support_for_float_textures_doesnt_mean_you_can_render_into_them!
|
|
56
|
+
return Boolean(gl.getExtension('EXT_float_blend') &&
|
|
57
|
+
// WebGL 2
|
|
58
|
+
(gl.getExtension('EXT_color_buffer_float') ||
|
|
59
|
+
// WebGL 1
|
|
60
|
+
gl.getExtension('WEBGL_color_buffer_float')));
|
|
61
|
+
}
|
|
62
|
+
// A 1x1 framebuffer object that encodes the total count of filtered items
|
|
63
|
+
export function getFramebuffer(device, useFloatTarget) {
|
|
64
|
+
if (useFloatTarget) {
|
|
65
|
+
return device.createFramebuffer({
|
|
66
|
+
width: 1,
|
|
67
|
+
height: 1,
|
|
68
|
+
colorAttachments: [
|
|
69
|
+
device.createTexture({
|
|
70
|
+
format: device.info.type === 'webgl2' ? 'rgba32float' : 'rgba8unorm',
|
|
71
|
+
type: GL.FLOAT,
|
|
72
|
+
mipmaps: false
|
|
73
|
+
})
|
|
74
|
+
]
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return device.createFramebuffer({
|
|
78
|
+
width: 256,
|
|
79
|
+
height: 64,
|
|
80
|
+
colorAttachments: [device.createTexture({ format: 'rgba8unorm', type: GL.FLOAT, mipmaps: false })]
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
// Increments the counter based on dataFilter_value
|
|
84
|
+
export function getModel(device, shaderOptions, useFloatTarget) {
|
|
85
|
+
shaderOptions.defines.NON_INSTANCED_MODEL = 1;
|
|
86
|
+
if (useFloatTarget) {
|
|
87
|
+
shaderOptions.defines.FLOAT_TARGET = 1;
|
|
88
|
+
}
|
|
89
|
+
return new Model(device, {
|
|
90
|
+
id: 'data-filter-aggregation-model',
|
|
91
|
+
vertexCount: 1,
|
|
92
|
+
isInstanced: false,
|
|
93
|
+
drawMode: GL.POINTS,
|
|
94
|
+
vs: AGGREGATE_VS,
|
|
95
|
+
fs: AGGREGATE_FS,
|
|
96
|
+
...shaderOptions
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
export const parameters = {
|
|
100
|
+
blend: true,
|
|
101
|
+
blendFunc: [GL.ONE, GL.ONE, GL.ONE, GL.ONE],
|
|
102
|
+
blendEquation: [GL.FUNC_ADD, GL.FUNC_ADD],
|
|
103
|
+
depthTest: false
|
|
104
|
+
};
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import type { Layer, LayerContext, Accessor, UpdateParameters } from '@deck.gl/core';
|
|
2
2
|
import { LayerExtension } from '@deck.gl/core';
|
|
3
|
+
type FilterCategory = number | string;
|
|
3
4
|
export type DataFilterExtensionProps<DataT = any> = {
|
|
4
5
|
/**
|
|
5
6
|
* Accessor to retrieve the value for each object that it will be filtered by.
|
|
6
7
|
* Returns either a number (if `filterSize: 1`) or an array of numbers.
|
|
7
8
|
*/
|
|
8
9
|
getFilterValue?: Accessor<DataT, number | number[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Accessor to retrieve the category (`number | string`) for each object that it will be filtered by.
|
|
12
|
+
* Returns either a single category (if `filterSize: 1`) or an array of categories.
|
|
13
|
+
*/
|
|
14
|
+
getFilterCategory?: Accessor<DataT, FilterCategory | FilterCategory[]>;
|
|
9
15
|
/**
|
|
10
16
|
* Enable/disable the data filter. If the data filter is disabled, all objects are rendered.
|
|
11
17
|
* @default true
|
|
@@ -33,6 +39,11 @@ export type DataFilterExtensionProps<DataT = any> = {
|
|
|
33
39
|
* @default true
|
|
34
40
|
*/
|
|
35
41
|
filterTransformColor?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* The categories which define whether an object should be rendered.
|
|
44
|
+
* @default []
|
|
45
|
+
*/
|
|
46
|
+
filterCategories: FilterCategory[] | FilterCategory[][];
|
|
36
47
|
/**
|
|
37
48
|
* Only called if the `countItems` option is enabled.
|
|
38
49
|
*/
|
|
@@ -44,21 +55,26 @@ export type DataFilterExtensionProps<DataT = any> = {
|
|
|
44
55
|
}) => void;
|
|
45
56
|
};
|
|
46
57
|
type DataFilterExtensionOptions = {
|
|
58
|
+
/**
|
|
59
|
+
* The size of the category filter (number of columns to filter by). The category filter can show/hide data based on 1-4 properties of each object.
|
|
60
|
+
* @default 1
|
|
61
|
+
*/
|
|
62
|
+
categorySize?: 1 | 2 | 3 | 4;
|
|
47
63
|
/**
|
|
48
64
|
* The size of the filter (number of columns to filter by). The data filter can show/hide data based on 1-4 numeric properties of each object.
|
|
49
65
|
* @default 1
|
|
50
66
|
*/
|
|
51
|
-
filterSize
|
|
67
|
+
filterSize?: 1 | 2 | 3 | 4;
|
|
52
68
|
/**
|
|
53
69
|
* Use 64-bit precision instead of 32-bit.
|
|
54
70
|
* @default false
|
|
55
71
|
*/
|
|
56
|
-
fp64
|
|
72
|
+
fp64?: boolean;
|
|
57
73
|
/**
|
|
58
74
|
* If `true`, reports the number of filtered objects with the `onFilteredItemsChange` callback.
|
|
59
75
|
* @default `false`.
|
|
60
76
|
*/
|
|
61
|
-
countItems
|
|
77
|
+
countItems?: boolean;
|
|
62
78
|
};
|
|
63
79
|
/** Adds GPU-based data filtering functionalities to layers. It allows the layer to show/hide objects based on user-defined properties. */
|
|
64
80
|
export default class DataFilterExtension extends LayerExtension<DataFilterExtensionOptions> {
|
|
@@ -67,6 +83,10 @@ export default class DataFilterExtension extends LayerExtension<DataFilterExtens
|
|
|
67
83
|
type: string;
|
|
68
84
|
value: number;
|
|
69
85
|
};
|
|
86
|
+
getFilterCategory: {
|
|
87
|
+
type: string;
|
|
88
|
+
value: number;
|
|
89
|
+
};
|
|
70
90
|
onFilteredItemsChange: {
|
|
71
91
|
type: string;
|
|
72
92
|
value: null;
|
|
@@ -75,16 +95,27 @@ export default class DataFilterExtension extends LayerExtension<DataFilterExtens
|
|
|
75
95
|
filterEnabled: boolean;
|
|
76
96
|
filterRange: number[];
|
|
77
97
|
filterSoftRange: null;
|
|
98
|
+
filterCategories: number[];
|
|
78
99
|
filterTransformSize: boolean;
|
|
79
100
|
filterTransformColor: boolean;
|
|
80
101
|
};
|
|
81
102
|
static extensionName: string;
|
|
82
|
-
constructor({ filterSize, fp64, countItems }?: Partial<DataFilterExtensionOptions>);
|
|
83
103
|
getShaders(this: Layer<DataFilterExtensionProps>, extension: this): any;
|
|
84
104
|
initializeState(this: Layer<DataFilterExtensionProps>, context: LayerContext, extension: this): void;
|
|
85
|
-
updateState(this: Layer<DataFilterExtensionProps>, { props, oldProps }: UpdateParameters<Layer<DataFilterExtensionProps
|
|
105
|
+
updateState(this: Layer<DataFilterExtensionProps>, { props, oldProps, changeFlags }: UpdateParameters<Layer<DataFilterExtensionProps>>, extension: this): void;
|
|
86
106
|
draw(this: Layer<DataFilterExtensionProps>, params: any, extension: this): void;
|
|
87
107
|
finalizeState(this: Layer<DataFilterExtensionProps>): void;
|
|
108
|
+
/**
|
|
109
|
+
* Updates the bitmask used on the GPU to perform the filter based on the
|
|
110
|
+
* `filterCategories` prop. The mapping between categories and bit in the bitmask
|
|
111
|
+
* is performed by `_getCategoryKey()`
|
|
112
|
+
*/
|
|
113
|
+
_updateCategoryBitMask(this: Layer<DataFilterExtensionProps>, params: any, extension: this): void;
|
|
114
|
+
/**
|
|
115
|
+
* Returns an index of bit in the bitmask for a given category. If the category has
|
|
116
|
+
* not yet been assigned a bit, a new one is assigned.
|
|
117
|
+
*/
|
|
118
|
+
_getCategoryKey(this: Layer<DataFilterExtensionProps>, category: FilterCategory, channel: number): number;
|
|
88
119
|
}
|
|
89
120
|
export {};
|
|
90
121
|
//# sourceMappingURL=data-filter-extension.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-filter-extension.d.ts","sourceRoot":"","sources":["../../src/data-filter/data-filter-extension.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,243 @@
|
|
|
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 { GL } from '@luma.gl/constants';
|
|
21
|
+
import { _deepEqual as deepEqual, LayerExtension, log } from '@deck.gl/core';
|
|
22
|
+
import { shaderModule, shaderModule64 } from "./shader-module.js";
|
|
23
|
+
import * as aggregator from "./aggregator.js";
|
|
24
|
+
const defaultProps = {
|
|
25
|
+
getFilterValue: { type: 'accessor', value: 0 },
|
|
26
|
+
getFilterCategory: { type: 'accessor', value: 0 },
|
|
27
|
+
onFilteredItemsChange: { type: 'function', value: null, optional: true },
|
|
28
|
+
filterEnabled: true,
|
|
29
|
+
filterRange: [-1, 1],
|
|
30
|
+
filterSoftRange: null,
|
|
31
|
+
filterCategories: [0],
|
|
32
|
+
filterTransformSize: true,
|
|
33
|
+
filterTransformColor: true
|
|
34
|
+
};
|
|
35
|
+
const DATA_TYPE_FROM_SIZE = {
|
|
36
|
+
1: 'float',
|
|
37
|
+
2: 'vec2',
|
|
38
|
+
3: 'vec3',
|
|
39
|
+
4: 'vec4'
|
|
40
|
+
};
|
|
41
|
+
/** Adds GPU-based data filtering functionalities to layers. It allows the layer to show/hide objects based on user-defined properties. */
|
|
42
|
+
export default class DataFilterExtension extends LayerExtension {
|
|
43
|
+
static { this.defaultProps = defaultProps; }
|
|
44
|
+
static { this.extensionName = 'DataFilterExtension'; }
|
|
45
|
+
getShaders(extension) {
|
|
46
|
+
const { categorySize, filterSize, fp64 } = extension.opts;
|
|
47
|
+
return {
|
|
48
|
+
modules: [fp64 ? shaderModule64 : shaderModule],
|
|
49
|
+
defines: {
|
|
50
|
+
DATACATEGORY_TYPE: DATA_TYPE_FROM_SIZE[categorySize || 1],
|
|
51
|
+
DATACATEGORY_CHANNELS: categorySize,
|
|
52
|
+
DATAFILTER_TYPE: DATA_TYPE_FROM_SIZE[filterSize || 1],
|
|
53
|
+
DATAFILTER_DOUBLE: Boolean(fp64)
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
initializeState(context, extension) {
|
|
58
|
+
const attributeManager = this.getAttributeManager();
|
|
59
|
+
const { categorySize, filterSize, fp64 } = extension.opts;
|
|
60
|
+
if (attributeManager) {
|
|
61
|
+
attributeManager.add({
|
|
62
|
+
filterValues: {
|
|
63
|
+
size: filterSize,
|
|
64
|
+
type: fp64 ? GL.DOUBLE : GL.FLOAT,
|
|
65
|
+
accessor: 'getFilterValue',
|
|
66
|
+
shaderAttributes: {
|
|
67
|
+
filterValues: {
|
|
68
|
+
divisor: 0
|
|
69
|
+
},
|
|
70
|
+
instanceFilterValues: {
|
|
71
|
+
divisor: 1
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
filterCategoryValues: {
|
|
76
|
+
size: categorySize,
|
|
77
|
+
type: GL.FLOAT,
|
|
78
|
+
accessor: 'getFilterCategory',
|
|
79
|
+
transform: categorySize === 1
|
|
80
|
+
? d => extension._getCategoryKey.call(this, d, 0)
|
|
81
|
+
: d => d.map((x, i) => extension._getCategoryKey.call(this, x, i)),
|
|
82
|
+
shaderAttributes: {
|
|
83
|
+
filterCategoryValues: {
|
|
84
|
+
divisor: 0
|
|
85
|
+
},
|
|
86
|
+
instanceFilterCategoryValues: {
|
|
87
|
+
divisor: 1
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
const { device } = this.context;
|
|
94
|
+
if (attributeManager && extension.opts.countItems) {
|
|
95
|
+
const useFloatTarget = aggregator.supportsFloatTarget(device);
|
|
96
|
+
// This attribute is needed for variable-width data, e.g. Path, SolidPolygon, Text
|
|
97
|
+
// The vertex shader checks if a vertex has the same "index" as the previous vertex
|
|
98
|
+
// so that we only write one count cross multiple vertices of the same object
|
|
99
|
+
attributeManager.add({
|
|
100
|
+
filterIndices: {
|
|
101
|
+
size: useFloatTarget ? 1 : 2,
|
|
102
|
+
vertexOffset: 1,
|
|
103
|
+
type: GL.UNSIGNED_BYTE,
|
|
104
|
+
normalized: true,
|
|
105
|
+
accessor: (object, { index }) => {
|
|
106
|
+
const i = object && object.__source ? object.__source.index : index;
|
|
107
|
+
return useFloatTarget ? (i + 1) % 255 : [(i + 1) % 255, Math.floor(i / 255) % 255];
|
|
108
|
+
},
|
|
109
|
+
shaderAttributes: {
|
|
110
|
+
filterPrevIndices: {
|
|
111
|
+
vertexOffset: 0
|
|
112
|
+
},
|
|
113
|
+
filterIndices: {
|
|
114
|
+
vertexOffset: 1
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
const filterFBO = aggregator.getFramebuffer(device, useFloatTarget);
|
|
120
|
+
const filterModel = aggregator.getModel(device, extension.getShaders.call(this, extension), useFloatTarget);
|
|
121
|
+
this.setState({ filterFBO, filterModel });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
updateState({ props, oldProps, changeFlags }, extension) {
|
|
125
|
+
const attributeManager = this.getAttributeManager();
|
|
126
|
+
const { categorySize } = extension.opts;
|
|
127
|
+
if (this.state.filterModel) {
|
|
128
|
+
const filterNeedsUpdate =
|
|
129
|
+
// attributeManager must be defined for filterModel to be set
|
|
130
|
+
attributeManager.attributes.filterValues.needsUpdate() ||
|
|
131
|
+
attributeManager.attributes.filterCategoryValues?.needsUpdate() ||
|
|
132
|
+
props.filterEnabled !== oldProps.filterEnabled ||
|
|
133
|
+
props.filterRange !== oldProps.filterRange ||
|
|
134
|
+
props.filterSoftRange !== oldProps.filterSoftRange ||
|
|
135
|
+
props.filterCategories !== oldProps.filterCategories;
|
|
136
|
+
if (filterNeedsUpdate) {
|
|
137
|
+
this.setState({ filterNeedsUpdate });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (attributeManager?.attributes.filterCategoryValues) {
|
|
141
|
+
// Update bitmask if accessor or selected categories has changed
|
|
142
|
+
const categoryBitMaskNeedsUpdate = attributeManager.attributes.filterCategoryValues.needsUpdate() ||
|
|
143
|
+
!deepEqual(props.filterCategories, oldProps.filterCategories, 2);
|
|
144
|
+
if (categoryBitMaskNeedsUpdate) {
|
|
145
|
+
this.setState({ categoryBitMaskNeedsUpdate });
|
|
146
|
+
}
|
|
147
|
+
// Need to recreate category map if categorySize has changed
|
|
148
|
+
const resetCategories = changeFlags.dataChanged;
|
|
149
|
+
if (resetCategories) {
|
|
150
|
+
this.setState({
|
|
151
|
+
categoryMap: Array(categorySize)
|
|
152
|
+
.fill(0)
|
|
153
|
+
.map(() => ({}))
|
|
154
|
+
});
|
|
155
|
+
attributeManager.attributes.filterCategoryValues.setNeedsUpdate('categoryMap');
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
draw(params, extension) {
|
|
160
|
+
const filterFBO = this.state.filterFBO;
|
|
161
|
+
const filterModel = this.state.filterModel;
|
|
162
|
+
const filterNeedsUpdate = this.state.filterNeedsUpdate;
|
|
163
|
+
const categoryBitMaskNeedsUpdate = this.state.categoryBitMaskNeedsUpdate;
|
|
164
|
+
const { onFilteredItemsChange } = this.props;
|
|
165
|
+
if (categoryBitMaskNeedsUpdate) {
|
|
166
|
+
extension._updateCategoryBitMask.call(this, params, extension);
|
|
167
|
+
}
|
|
168
|
+
if (filterNeedsUpdate && onFilteredItemsChange && filterModel) {
|
|
169
|
+
const { attributes: { filterValues, filterCategoryValues, filterIndices } } = this.getAttributeManager();
|
|
170
|
+
filterModel.setVertexCount(this.getNumInstances());
|
|
171
|
+
this.context.device.clearWebGL({ framebuffer: filterFBO, color: [0, 0, 0, 0] });
|
|
172
|
+
filterModel.updateModuleSettings(params.moduleParameters);
|
|
173
|
+
// @ts-expect-error filterValue and filterIndices should always have buffer value
|
|
174
|
+
filterModel.setAttributes({
|
|
175
|
+
...filterValues.getValue(),
|
|
176
|
+
...filterCategoryValues?.getValue(),
|
|
177
|
+
...filterIndices?.getValue()
|
|
178
|
+
});
|
|
179
|
+
filterModel.setUniforms(params.uniforms);
|
|
180
|
+
filterModel.device.withParametersWebGL({
|
|
181
|
+
framebuffer: filterFBO,
|
|
182
|
+
// ts-ignore 'readonly' cannot be assigned to the mutable type '[GLBlendEquation, GLBlendEquation]'
|
|
183
|
+
...aggregator.parameters,
|
|
184
|
+
viewport: [0, 0, filterFBO.width, filterFBO.height]
|
|
185
|
+
}, () => {
|
|
186
|
+
filterModel.draw(this.context.renderPass);
|
|
187
|
+
});
|
|
188
|
+
const color = filterModel.device.readPixelsToArrayWebGL(filterFBO);
|
|
189
|
+
let count = 0;
|
|
190
|
+
for (let i = 0; i < color.length; i++) {
|
|
191
|
+
count += color[i];
|
|
192
|
+
}
|
|
193
|
+
onFilteredItemsChange({ id: this.id, count });
|
|
194
|
+
this.state.filterNeedsUpdate = false;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
finalizeState() {
|
|
198
|
+
const filterFBO = this.state.filterFBO;
|
|
199
|
+
const filterModel = this.state.filterModel;
|
|
200
|
+
// filterFBO.color.delete();
|
|
201
|
+
filterFBO?.destroy();
|
|
202
|
+
filterModel?.destroy();
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Updates the bitmask used on the GPU to perform the filter based on the
|
|
206
|
+
* `filterCategories` prop. The mapping between categories and bit in the bitmask
|
|
207
|
+
* is performed by `_getCategoryKey()`
|
|
208
|
+
*/
|
|
209
|
+
_updateCategoryBitMask(params, extension) {
|
|
210
|
+
const { categorySize } = extension.opts;
|
|
211
|
+
const { filterCategories } = this.props;
|
|
212
|
+
const categoryBitMask = new Uint32Array([0, 0, 0, 0]);
|
|
213
|
+
const categoryFilters = (categorySize === 1 ? [filterCategories] : filterCategories);
|
|
214
|
+
const maxCategories = categorySize === 1 ? 128 : categorySize === 2 ? 64 : 32;
|
|
215
|
+
for (let c = 0; c < categoryFilters.length; c++) {
|
|
216
|
+
const categoryFilter = categoryFilters[c];
|
|
217
|
+
for (const category of categoryFilter) {
|
|
218
|
+
const key = extension._getCategoryKey.call(this, category, c);
|
|
219
|
+
if (key < maxCategories) {
|
|
220
|
+
const channel = c * (maxCategories / 32) + Math.floor(key / 32);
|
|
221
|
+
categoryBitMask[channel] += Math.pow(2, key % 32); // 1 << key fails for key > 30
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
log.warn(`Exceeded maximum number of categories (${maxCategories})`)();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/* eslint-disable-next-line camelcase */
|
|
229
|
+
params.uniforms.filter_categoryBitMask = categoryBitMask;
|
|
230
|
+
this.state.categoryBitMaskNeedsUpdate = false;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Returns an index of bit in the bitmask for a given category. If the category has
|
|
234
|
+
* not yet been assigned a bit, a new one is assigned.
|
|
235
|
+
*/
|
|
236
|
+
_getCategoryKey(category, channel) {
|
|
237
|
+
const categoryMap = this.state.categoryMap[channel];
|
|
238
|
+
if (!(category in categoryMap)) {
|
|
239
|
+
categoryMap[category] = Object.keys(categoryMap).length;
|
|
240
|
+
}
|
|
241
|
+
return categoryMap[category];
|
|
242
|
+
}
|
|
243
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ShaderModule } from '@luma.gl/shadertools';
|
|
2
|
-
import type { DataFilterExtensionProps } from
|
|
2
|
+
import type { DataFilterExtensionProps } from "./data-filter-extension.js";
|
|
3
3
|
type DataFilterModuleSettings = {
|
|
4
4
|
extensions: any[];
|
|
5
5
|
} & DataFilterExtensionProps;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shader-module.d.ts","sourceRoot":"","sources":["../../src/data-filter/shader-module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAC,wBAAwB,EAAC,mCAAgC;AA8FtE,KAAK,wBAAwB,GAAG;IAC9B,UAAU,EAAE,GAAG,EAAE,CAAC;CACnB,GAAG,wBAAwB,CAAC;AAkG7B,eAAO,MAAM,YAAY,EAAE,YAAY,CAAC,wBAAwB,CAM/D,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,YAAY,CAAC,wBAAwB,CAMjE,CAAC"}
|
|
@@ -0,0 +1,187 @@
|
|
|
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
|
+
uniform ivec4 filter_categoryBitMask;
|
|
13
|
+
|
|
14
|
+
#ifdef NON_INSTANCED_MODEL
|
|
15
|
+
#define DATAFILTER_ATTRIB filterValues
|
|
16
|
+
#define DATAFILTER_ATTRIB_64LOW filterValues64Low
|
|
17
|
+
#define DATACATEGORY_ATTRIB filterCategoryValues
|
|
18
|
+
#else
|
|
19
|
+
#define DATAFILTER_ATTRIB instanceFilterValues
|
|
20
|
+
#define DATAFILTER_ATTRIB_64LOW instanceFilterValues64Low
|
|
21
|
+
#define DATACATEGORY_ATTRIB instanceFilterCategoryValues
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
in DATAFILTER_TYPE DATAFILTER_ATTRIB;
|
|
25
|
+
#ifdef DATAFILTER_DOUBLE
|
|
26
|
+
in DATAFILTER_TYPE DATAFILTER_ATTRIB_64LOW;
|
|
27
|
+
|
|
28
|
+
uniform DATAFILTER_TYPE filter_min64High;
|
|
29
|
+
uniform DATAFILTER_TYPE filter_max64High;
|
|
30
|
+
#endif
|
|
31
|
+
in DATACATEGORY_TYPE DATACATEGORY_ATTRIB;
|
|
32
|
+
|
|
33
|
+
out float dataFilter_value;
|
|
34
|
+
|
|
35
|
+
float dataFilter_reduceValue(float value) {
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
float dataFilter_reduceValue(vec2 value) {
|
|
39
|
+
return min(value.x, value.y);
|
|
40
|
+
}
|
|
41
|
+
float dataFilter_reduceValue(vec3 value) {
|
|
42
|
+
return min(min(value.x, value.y), value.z);
|
|
43
|
+
}
|
|
44
|
+
float dataFilter_reduceValue(vec4 value) {
|
|
45
|
+
return min(min(value.x, value.y), min(value.z, value.w));
|
|
46
|
+
}
|
|
47
|
+
void dataFilter_setValue(DATAFILTER_TYPE valueFromMin, DATAFILTER_TYPE valueFromMax, DATACATEGORY_TYPE category) {
|
|
48
|
+
if (filter_enabled) {
|
|
49
|
+
if (filter_useSoftMargin) {
|
|
50
|
+
dataFilter_value = dataFilter_reduceValue(
|
|
51
|
+
smoothstep(filter_min, filter_softMin, valueFromMin) *
|
|
52
|
+
(1.0 - smoothstep(filter_softMax, filter_max, valueFromMax))
|
|
53
|
+
);
|
|
54
|
+
} else {
|
|
55
|
+
dataFilter_value = dataFilter_reduceValue(
|
|
56
|
+
step(filter_min, valueFromMin) * step(valueFromMax, filter_max)
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
#if DATACATEGORY_CHANNELS == 1 // One 128-bit mask
|
|
61
|
+
int dataFilter_masks = filter_categoryBitMask[int(category / 32.0)];
|
|
62
|
+
#elif DATACATEGORY_CHANNELS == 2 // Two 64-bit masks
|
|
63
|
+
ivec2 dataFilter_masks = ivec2(
|
|
64
|
+
filter_categoryBitMask[int(category.x / 32.0)],
|
|
65
|
+
filter_categoryBitMask[int(category.y / 32.0) + 2]
|
|
66
|
+
);
|
|
67
|
+
#elif DATACATEGORY_CHANNELS == 3 // Three 32-bit masks
|
|
68
|
+
ivec3 dataFilter_masks = filter_categoryBitMask.xyz;
|
|
69
|
+
#else // Four 32-bit masks
|
|
70
|
+
ivec4 dataFilter_masks = filter_categoryBitMask;
|
|
71
|
+
#endif
|
|
72
|
+
|
|
73
|
+
// Shift mask and extract relevant bits
|
|
74
|
+
DATACATEGORY_TYPE dataFilter_bits = DATACATEGORY_TYPE(dataFilter_masks) / pow(DATACATEGORY_TYPE(2.0), mod(category, 32.0));
|
|
75
|
+
dataFilter_bits = mod(floor(dataFilter_bits), 2.0);
|
|
76
|
+
|
|
77
|
+
#if DATACATEGORY_CHANNELS == 1
|
|
78
|
+
if(dataFilter_bits == 0.0) dataFilter_value = 0.0;
|
|
79
|
+
#else
|
|
80
|
+
if(any(equal(dataFilter_bits, DATACATEGORY_TYPE(0.0)))) dataFilter_value = 0.0;
|
|
81
|
+
#endif
|
|
82
|
+
} else {
|
|
83
|
+
dataFilter_value = 1.0;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
`;
|
|
87
|
+
const fs = `
|
|
88
|
+
uniform bool filter_transformColor;
|
|
89
|
+
in float dataFilter_value;
|
|
90
|
+
`;
|
|
91
|
+
/* eslint-disable camelcase */
|
|
92
|
+
function getUniforms(opts) {
|
|
93
|
+
if (!opts || !('extensions' in opts)) {
|
|
94
|
+
return {};
|
|
95
|
+
}
|
|
96
|
+
const { filterRange = [-1, 1], filterEnabled = true, filterTransformSize = true, filterTransformColor = true } = opts;
|
|
97
|
+
const filterSoftRange = opts.filterSoftRange || filterRange;
|
|
98
|
+
return {
|
|
99
|
+
...(Number.isFinite(filterRange[0])
|
|
100
|
+
? {
|
|
101
|
+
filter_min: filterRange[0],
|
|
102
|
+
filter_softMin: filterSoftRange[0],
|
|
103
|
+
filter_softMax: filterSoftRange[1],
|
|
104
|
+
filter_max: filterRange[1]
|
|
105
|
+
}
|
|
106
|
+
: {
|
|
107
|
+
filter_min: filterRange.map(r => r[0]),
|
|
108
|
+
filter_softMin: filterSoftRange.map(r => r[0]),
|
|
109
|
+
filter_softMax: filterSoftRange.map(r => r[1]),
|
|
110
|
+
filter_max: filterRange.map(r => r[1])
|
|
111
|
+
}),
|
|
112
|
+
filter_enabled: filterEnabled,
|
|
113
|
+
filter_useSoftMargin: Boolean(opts.filterSoftRange),
|
|
114
|
+
filter_transformSize: filterEnabled && filterTransformSize,
|
|
115
|
+
filter_transformColor: filterEnabled && filterTransformColor
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function getUniforms64(opts) {
|
|
119
|
+
if (!opts || !('extensions' in opts)) {
|
|
120
|
+
return {};
|
|
121
|
+
}
|
|
122
|
+
const uniforms = getUniforms(opts);
|
|
123
|
+
if (Number.isFinite(uniforms.filter_min)) {
|
|
124
|
+
const min64High = Math.fround(uniforms.filter_min);
|
|
125
|
+
uniforms.filter_min -= min64High;
|
|
126
|
+
uniforms.filter_softMin -= min64High;
|
|
127
|
+
uniforms.filter_min64High = min64High;
|
|
128
|
+
const max64High = Math.fround(uniforms.filter_max);
|
|
129
|
+
uniforms.filter_max -= max64High;
|
|
130
|
+
uniforms.filter_softMax -= max64High;
|
|
131
|
+
uniforms.filter_max64High = max64High;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
const min64High = uniforms.filter_min.map(Math.fround);
|
|
135
|
+
uniforms.filter_min = uniforms.filter_min.map((x, i) => x - min64High[i]);
|
|
136
|
+
uniforms.filter_softMin = uniforms.filter_softMin.map((x, i) => x - min64High[i]);
|
|
137
|
+
uniforms.filter_min64High = min64High;
|
|
138
|
+
const max64High = uniforms.filter_max.map(Math.fround);
|
|
139
|
+
uniforms.filter_max = uniforms.filter_max.map((x, i) => x - max64High[i]);
|
|
140
|
+
uniforms.filter_softMax = uniforms.filter_softMax.map((x, i) => x - max64High[i]);
|
|
141
|
+
uniforms.filter_max64High = max64High;
|
|
142
|
+
}
|
|
143
|
+
return uniforms;
|
|
144
|
+
}
|
|
145
|
+
const inject = {
|
|
146
|
+
'vs:#main-start': `
|
|
147
|
+
#ifdef DATAFILTER_DOUBLE
|
|
148
|
+
dataFilter_setValue(
|
|
149
|
+
DATAFILTER_ATTRIB - filter_min64High + DATAFILTER_ATTRIB_64LOW,
|
|
150
|
+
DATAFILTER_ATTRIB - filter_max64High + DATAFILTER_ATTRIB_64LOW,
|
|
151
|
+
DATACATEGORY_ATTRIB
|
|
152
|
+
);
|
|
153
|
+
#else
|
|
154
|
+
dataFilter_setValue(DATAFILTER_ATTRIB, DATAFILTER_ATTRIB, DATACATEGORY_ATTRIB);
|
|
155
|
+
#endif
|
|
156
|
+
`,
|
|
157
|
+
'vs:#main-end': `
|
|
158
|
+
if (dataFilter_value == 0.0) {
|
|
159
|
+
gl_Position = vec4(0.);
|
|
160
|
+
}
|
|
161
|
+
`,
|
|
162
|
+
'vs:DECKGL_FILTER_SIZE': `
|
|
163
|
+
if (filter_transformSize) {
|
|
164
|
+
size = size * dataFilter_value;
|
|
165
|
+
}
|
|
166
|
+
`,
|
|
167
|
+
'fs:DECKGL_FILTER_COLOR': `
|
|
168
|
+
if (dataFilter_value == 0.0) discard;
|
|
169
|
+
if (filter_transformColor) {
|
|
170
|
+
color.a *= dataFilter_value;
|
|
171
|
+
}
|
|
172
|
+
`
|
|
173
|
+
};
|
|
174
|
+
export const shaderModule = {
|
|
175
|
+
name: 'data-filter',
|
|
176
|
+
vs,
|
|
177
|
+
fs,
|
|
178
|
+
inject,
|
|
179
|
+
getUniforms
|
|
180
|
+
};
|
|
181
|
+
export const shaderModule64 = {
|
|
182
|
+
name: 'data-filter-fp64',
|
|
183
|
+
vs,
|
|
184
|
+
fs,
|
|
185
|
+
inject,
|
|
186
|
+
getUniforms: getUniforms64
|
|
187
|
+
};
|