@deck.gl/extensions 9.0.35 → 9.1.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.
Files changed (128) hide show
  1. package/dist/brushing/brushing-extension.d.ts +1 -0
  2. package/dist/brushing/brushing-extension.d.ts.map +1 -1
  3. package/dist/brushing/brushing-extension.js +15 -19
  4. package/dist/brushing/shader-module.d.ts +8 -2
  5. package/dist/brushing/shader-module.d.ts.map +1 -1
  6. package/dist/brushing/shader-module.js +74 -50
  7. package/dist/clip/clip-extension.d.ts +5 -2
  8. package/dist/clip/clip-extension.d.ts.map +1 -1
  9. package/dist/clip/clip-extension.js +36 -42
  10. package/dist/collision-filter/collision-filter-effect.d.ts +4 -4
  11. package/dist/collision-filter/collision-filter-effect.d.ts.map +1 -1
  12. package/dist/collision-filter/collision-filter-effect.js +27 -13
  13. package/dist/collision-filter/collision-filter-extension.d.ts +1 -1
  14. package/dist/collision-filter/collision-filter-extension.d.ts.map +1 -1
  15. package/dist/collision-filter/collision-filter-extension.js +5 -6
  16. package/dist/collision-filter/collision-filter-pass.d.ts +7 -3
  17. package/dist/collision-filter/collision-filter-pass.d.ts.map +1 -1
  18. package/dist/collision-filter/collision-filter-pass.js +8 -3
  19. package/dist/collision-filter/shader-module.d.ts +3 -2
  20. package/dist/collision-filter/shader-module.d.ts.map +1 -1
  21. package/dist/collision-filter/shader-module.js +74 -52
  22. package/dist/data-filter/aggregator.d.ts +4 -10
  23. package/dist/data-filter/aggregator.d.ts.map +1 -1
  24. package/dist/data-filter/aggregator.js +14 -8
  25. package/dist/data-filter/data-filter-extension.d.ts.map +1 -1
  26. package/dist/data-filter/data-filter-extension.js +40 -38
  27. package/dist/data-filter/shader-module.d.ts +11 -4
  28. package/dist/data-filter/shader-module.d.ts.map +1 -1
  29. package/dist/data-filter/shader-module.js +189 -131
  30. package/dist/dist.dev.js +2699 -2028
  31. package/dist/fill-style/fill-style-extension.d.ts.map +1 -1
  32. package/dist/fill-style/fill-style-extension.js +11 -4
  33. package/dist/fill-style/shader-module.d.ts +64 -6
  34. package/dist/fill-style/shader-module.d.ts.map +1 -1
  35. package/dist/fill-style/shader-module.js +73 -51
  36. package/dist/fp64/fp64-extension.d.ts +1 -0
  37. package/dist/fp64/fp64-extension.d.ts.map +1 -1
  38. package/dist/fp64/fp64-extension.js +7 -19
  39. package/dist/fp64/project64.d.ts +2 -2
  40. package/dist/fp64/project64.d.ts.map +1 -1
  41. package/dist/fp64/project64.glsl.d.ts +1 -1
  42. package/dist/fp64/project64.glsl.d.ts.map +1 -1
  43. package/dist/fp64/project64.glsl.js +18 -21
  44. package/dist/fp64/project64.js +24 -24
  45. package/dist/index.cjs +1017 -523
  46. package/dist/index.cjs.map +3 -3
  47. package/dist/index.d.ts +1 -0
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +3 -0
  50. package/dist/mask/mask-effect.d.ts +5 -3
  51. package/dist/mask/mask-effect.d.ts.map +1 -1
  52. package/dist/mask/mask-effect.js +12 -5
  53. package/dist/mask/mask-extension.d.ts +1 -1
  54. package/dist/mask/mask-extension.d.ts.map +1 -1
  55. package/dist/mask/mask-extension.js +13 -8
  56. package/dist/mask/mask-pass.d.ts +38 -38
  57. package/dist/mask/mask-pass.d.ts.map +1 -1
  58. package/dist/mask/mask-pass.js +3 -0
  59. package/dist/mask/shader-module.d.ts +60 -3
  60. package/dist/mask/shader-module.d.ts.map +1 -1
  61. package/dist/mask/shader-module.js +73 -46
  62. package/dist/path-style/path-style-extension.d.ts.map +1 -1
  63. package/dist/path-style/path-style-extension.js +20 -24
  64. package/dist/path-style/shaders.glsl.d.ts.map +1 -1
  65. package/dist/path-style/shaders.glsl.js +11 -7
  66. package/dist/terrain/height-map-builder.d.ts.map +1 -1
  67. package/dist/terrain/height-map-builder.js +3 -0
  68. package/dist/terrain/shader-module.d.ts +60 -6
  69. package/dist/terrain/shader-module.d.ts.map +1 -1
  70. package/dist/terrain/shader-module.js +69 -61
  71. package/dist/terrain/terrain-cover.d.ts.map +1 -1
  72. package/dist/terrain/terrain-cover.js +3 -0
  73. package/dist/terrain/terrain-effect.d.ts +4 -2
  74. package/dist/terrain/terrain-effect.d.ts.map +1 -1
  75. package/dist/terrain/terrain-effect.js +31 -18
  76. package/dist/terrain/terrain-extension.d.ts.map +1 -1
  77. package/dist/terrain/terrain-extension.js +3 -0
  78. package/dist/terrain/terrain-pass.d.ts +43 -38
  79. package/dist/terrain/terrain-pass.d.ts.map +1 -1
  80. package/dist/terrain/terrain-pass.js +10 -0
  81. package/dist/terrain/terrain-picking-pass.d.ts +5 -0
  82. package/dist/terrain/terrain-picking-pass.d.ts.map +1 -1
  83. package/dist/terrain/terrain-picking-pass.js +10 -0
  84. package/dist/terrain/utils.d.ts.map +1 -1
  85. package/dist/terrain/utils.js +3 -0
  86. package/dist/utils/debug.d.ts +2 -2
  87. package/dist/utils/debug.d.ts.map +1 -1
  88. package/dist/utils/debug.js +3 -1
  89. package/dist/utils/projection-utils.d.ts.map +1 -1
  90. package/dist/utils/projection-utils.js +3 -0
  91. package/dist.min.js +1102 -817
  92. package/package.json +8 -8
  93. package/src/brushing/brushing-extension.ts +17 -20
  94. package/src/brushing/shader-module.ts +58 -47
  95. package/src/clip/clip-extension.ts +38 -40
  96. package/src/collision-filter/collision-filter-effect.ts +31 -20
  97. package/src/collision-filter/collision-filter-extension.ts +6 -7
  98. package/src/collision-filter/collision-filter-pass.ts +9 -3
  99. package/src/collision-filter/shader-module.ts +40 -22
  100. package/src/data-filter/aggregator.ts +23 -11
  101. package/src/data-filter/data-filter-extension.ts +68 -48
  102. package/src/data-filter/shader-module.ts +144 -84
  103. package/src/fill-style/fill-style-extension.ts +13 -5
  104. package/src/fill-style/shader-module.ts +84 -52
  105. package/src/fp64/fp64-extension.ts +8 -19
  106. package/src/fp64/project64.glsl.ts +18 -21
  107. package/src/fp64/project64.ts +27 -28
  108. package/src/index.ts +5 -0
  109. package/src/mask/mask-effect.ts +17 -7
  110. package/src/mask/mask-extension.ts +16 -9
  111. package/src/mask/mask-pass.ts +4 -0
  112. package/src/mask/shader-module.ts +63 -27
  113. package/src/path-style/path-style-extension.ts +27 -28
  114. package/src/path-style/shaders.glsl.ts +13 -7
  115. package/src/terrain/height-map-builder.ts +4 -0
  116. package/src/terrain/shader-module.ts +62 -44
  117. package/src/terrain/terrain-cover.ts +4 -0
  118. package/src/terrain/terrain-effect.ts +36 -19
  119. package/src/terrain/terrain-extension.ts +4 -0
  120. package/src/terrain/terrain-pass.ts +12 -0
  121. package/src/terrain/terrain-picking-pass.ts +12 -0
  122. package/src/terrain/utils.ts +4 -0
  123. package/src/utils/debug.ts +4 -0
  124. package/src/utils/projection-utils.ts +4 -0
  125. package/dist/utils/syntax-tags.d.ts +0 -6
  126. package/dist/utils/syntax-tags.d.ts.map +0 -1
  127. package/dist/utils/syntax-tags.js +0 -5
  128. package/src/utils/syntax-tags.ts +0 -5
@@ -1,32 +1,43 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
1
5
  import type {ShaderModule} from '@luma.gl/shadertools';
2
6
  import {project, fp64LowPart} from '@deck.gl/core';
3
- import type {Viewport, ProjectUniforms} from '@deck.gl/core';
7
+ import type {ProjectProps, ProjectUniforms} from '@deck.gl/core';
4
8
 
5
9
  import type {Texture} from '@luma.gl/core';
6
- import {glsl} from '../utils/syntax-tags';
10
+
11
+ const uniformBlock = /* glsl */ `\
12
+ uniform fillUniforms {
13
+ vec2 patternTextureSize;
14
+ bool patternEnabled;
15
+ bool patternMask;
16
+ vec2 uvCoordinateOrigin;
17
+ vec2 uvCoordinateOrigin64Low;
18
+ } fill;
19
+ `;
7
20
 
8
21
  /*
9
22
  * fill pattern shader module
10
23
  */
11
- const patternVs = glsl`
24
+ const patternVs = /* glsl */ `
12
25
  in vec4 fillPatternFrames;
13
26
  in float fillPatternScales;
14
27
  in vec2 fillPatternOffsets;
15
28
 
16
- uniform bool fill_patternEnabled;
17
- uniform vec2 fill_patternTextureSize;
18
-
19
29
  out vec2 fill_uv;
20
30
  out vec4 fill_patternBounds;
21
31
  out vec4 fill_patternPlacement;
22
32
  `;
23
33
 
24
- const patternFs = glsl`
25
- uniform bool fill_patternEnabled;
26
- uniform bool fill_patternMask;
34
+ const vs = `
35
+ ${uniformBlock}
36
+ ${patternVs}
37
+ `;
38
+
39
+ const patternFs = /* glsl */ `
27
40
  uniform sampler2D fill_patternTexture;
28
- uniform vec2 fill_uvCoordinateOrigin;
29
- uniform vec2 fill_uvCoordinateOrigin64Low;
30
41
 
31
42
  in vec4 fill_patternBounds;
32
43
  in vec4 fill_patternPlacement;
@@ -35,86 +46,107 @@ in vec2 fill_uv;
35
46
  const float FILL_UV_SCALE = 512.0 / 40000000.0;
36
47
  `;
37
48
 
49
+ const fs = `
50
+ ${uniformBlock}
51
+ ${patternFs}
52
+ `;
53
+
38
54
  const inject = {
39
- 'vs:DECKGL_FILTER_GL_POSITION': glsl`
55
+ 'vs:DECKGL_FILTER_GL_POSITION': /* glsl */ `
40
56
  fill_uv = geometry.position.xy;
41
57
  `,
42
58
 
43
- 'vs:DECKGL_FILTER_COLOR': glsl`
44
- if (fill_patternEnabled) {
45
- fill_patternBounds = fillPatternFrames / vec4(fill_patternTextureSize, fill_patternTextureSize);
59
+ 'vs:DECKGL_FILTER_COLOR': /* glsl */ `
60
+ if (fill.patternEnabled) {
61
+ fill_patternBounds = fillPatternFrames / vec4(fill.patternTextureSize, fill.patternTextureSize);
46
62
  fill_patternPlacement.xy = fillPatternOffsets;
47
63
  fill_patternPlacement.zw = fillPatternScales * fillPatternFrames.zw;
48
64
  }
49
65
  `,
50
66
 
51
- 'fs:DECKGL_FILTER_COLOR': glsl`
52
- if (fill_patternEnabled) {
67
+ 'fs:DECKGL_FILTER_COLOR': /* glsl */ `
68
+ if (fill.patternEnabled) {
53
69
  vec2 scale = FILL_UV_SCALE * fill_patternPlacement.zw;
54
- vec2 patternUV = mod(mod(fill_uvCoordinateOrigin, scale) + fill_uvCoordinateOrigin64Low + fill_uv, scale) / scale;
70
+ vec2 patternUV = mod(mod(fill.uvCoordinateOrigin, scale) + fill.uvCoordinateOrigin64Low + fill_uv, scale) / scale;
55
71
  patternUV = mod(fill_patternPlacement.xy + patternUV, 1.0);
56
72
 
57
73
  vec2 texCoords = fill_patternBounds.xy + fill_patternBounds.zw * patternUV;
58
74
 
59
75
  vec4 patternColor = texture(fill_patternTexture, texCoords);
60
76
  color.a *= patternColor.a;
61
- if (!fill_patternMask) {
77
+ if (!fill.patternMask) {
62
78
  color.rgb = patternColor.rgb;
63
79
  }
64
80
  }
65
81
  `
66
82
  };
67
83
 
68
- type FillStyleModuleSettings =
69
- | {
70
- viewport: Viewport;
71
- fillPatternEnabled?: boolean;
72
- fillPatternMask?: boolean;
73
- }
74
- | {
75
- fillPatternTexture: Texture;
76
- };
84
+ export type FillStyleModuleProps = {
85
+ project: ProjectProps;
86
+ fillPatternEnabled?: boolean;
87
+ fillPatternMask?: boolean;
88
+ fillPatternTexture: Texture;
89
+ };
90
+
91
+ type FillStyleModuleUniforms = {
92
+ patternTextureSize?: [number, number];
93
+ patternEnabled?: boolean;
94
+ patternMask?: boolean;
95
+ uvCoordinateOrigin?: [number, number];
96
+ uvCoordinateOrigin64Low?: [number, number];
97
+ };
98
+
99
+ type FillStyleModuleBindings = {
100
+ fill_patternTexture?: Texture;
101
+ };
77
102
 
78
103
  /* eslint-disable camelcase */
79
104
  function getPatternUniforms(
80
- opts: FillStyleModuleSettings | {},
81
- uniforms: Record<string, any>
82
- ): Record<string, any> {
105
+ opts?: FillStyleModuleProps | {}
106
+ ): FillStyleModuleBindings & FillStyleModuleUniforms {
83
107
  if (!opts) {
84
108
  return {};
85
109
  }
110
+ const uniforms: FillStyleModuleBindings & FillStyleModuleUniforms = {};
86
111
  if ('fillPatternTexture' in opts) {
87
112
  const {fillPatternTexture} = opts;
88
- return {
89
- fill_patternTexture: fillPatternTexture,
90
- fill_patternTextureSize: [fillPatternTexture.width, fillPatternTexture.height]
91
- };
113
+ uniforms.fill_patternTexture = fillPatternTexture;
114
+ uniforms.patternTextureSize = [fillPatternTexture.width, fillPatternTexture.height];
92
115
  }
93
- if ('viewport' in opts) {
116
+ if ('project' in opts) {
94
117
  const {fillPatternMask = true, fillPatternEnabled = true} = opts;
95
- const {project_uCommonOrigin: coordinateOriginCommon} = uniforms as ProjectUniforms;
118
+ const projectUniforms = project.getUniforms(opts.project) as ProjectUniforms;
119
+ const {commonOrigin: coordinateOriginCommon} = projectUniforms;
96
120
 
97
- const coordinateOriginCommon64Low = [
121
+ const coordinateOriginCommon64Low: [number, number] = [
98
122
  fp64LowPart(coordinateOriginCommon[0]),
99
123
  fp64LowPart(coordinateOriginCommon[1])
100
124
  ];
101
125
 
102
- return {
103
- fill_uvCoordinateOrigin: coordinateOriginCommon.slice(0, 2),
104
- fill_uvCoordinateOrigin64Low: coordinateOriginCommon64Low,
105
- fill_patternMask: fillPatternMask,
106
- fill_patternEnabled: fillPatternEnabled
107
- };
126
+ uniforms.uvCoordinateOrigin = coordinateOriginCommon.slice(0, 2) as [number, number];
127
+ uniforms.uvCoordinateOrigin64Low = coordinateOriginCommon64Low;
128
+ uniforms.patternMask = fillPatternMask;
129
+ uniforms.patternEnabled = fillPatternEnabled;
108
130
  }
109
- return {};
131
+ return uniforms;
110
132
  }
111
133
 
112
- export const patternShaders: ShaderModule<FillStyleModuleSettings> = {
113
- name: 'fill-pattern',
114
- vs: patternVs,
115
- fs: patternFs,
134
+ export const patternShaders = {
135
+ name: 'fill',
136
+ vs,
137
+ fs,
116
138
  inject,
117
139
  dependencies: [project],
118
- // @ts-expect-error stricter luma gl types
119
- getUniforms: getPatternUniforms
120
- };
140
+ getUniforms: getPatternUniforms,
141
+ uniformTypes: {
142
+ patternTextureSize: 'vec2<f32>',
143
+ patternEnabled: 'i32',
144
+ patternMask: 'i32',
145
+ uvCoordinateOrigin: 'vec2<f32>',
146
+ uvCoordinateOrigin64Low: 'vec2<f32>'
147
+ }
148
+ } as const satisfies ShaderModule<
149
+ FillStyleModuleProps,
150
+ FillStyleModuleUniforms,
151
+ FillStyleModuleBindings
152
+ >;
@@ -1,22 +1,6 @@
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.
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
20
4
 
21
5
  import {LayerExtension, COORDINATE_SYSTEM} from '@deck.gl/core';
22
6
  import project64 from './project64';
@@ -40,4 +24,9 @@ export default class Fp64Extension extends LayerExtension {
40
24
  modules: [project64]
41
25
  };
42
26
  }
27
+
28
+ draw(this: Layer, params: any, extension: this): void {
29
+ const {viewport} = params.context;
30
+ this.setShaderModuleProps({project64: {viewport}});
31
+ }
43
32
  }
@@ -1,28 +1,16 @@
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.
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
20
4
 
21
5
  export default `\
22
6
 
23
7
  const vec2 WORLD_SCALE_FP64 = vec2(81.4873275756836, 0.0000032873668232014097);
24
8
 
25
- uniform vec2 project_uViewProjectionMatrixFP64[16];
9
+ uniform project64Uniforms {
10
+ vec2 scale;
11
+ mat4 viewProjectionMatrix;
12
+ mat4 viewProjectionMatrix64Low;
13
+ } project64;
26
14
 
27
15
  // longitude: lnglat_fp64.xy; latitude: lnglat_fp64.zw
28
16
  void mercatorProject_fp64(vec4 lnglat_fp64, out vec2 out_val[2]) {
@@ -56,7 +44,16 @@ void project_position_fp64(vec2 position, vec2 position64xyLow, out vec2 out_val
56
44
 
57
45
  vec4 project_common_position_to_clipspace_fp64(vec2 vertex_pos_modelspace[4]) {
58
46
  vec2 vertex_pos_clipspace[4];
59
- mat4_vec4_mul_fp64(project_uViewProjectionMatrixFP64, vertex_pos_modelspace,
47
+ vec2 viewProjectionMatrixFP64[16];
48
+ for (int i = 0; i < 4; i++) {
49
+ for (int j = 0; j < 4; j++) {
50
+ viewProjectionMatrixFP64[4 * i + j] = vec2(
51
+ project64.viewProjectionMatrix[j][i],
52
+ project64.viewProjectionMatrix64Low[j][i]
53
+ );
54
+ }
55
+ }
56
+ mat4_vec4_mul_fp64(viewProjectionMatrixFP64, vertex_pos_modelspace,
60
57
  vertex_pos_clipspace);
61
58
  return vec4(
62
59
  vertex_pos_clipspace[0].x,
@@ -1,22 +1,6 @@
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.
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
20
4
 
21
5
  /* eslint-disable camelcase */
22
6
  import {fp64} from '@luma.gl/shadertools';
@@ -27,7 +11,7 @@ import {project, _memoize as memoize} from '@deck.gl/core';
27
11
  import type {Viewport} from '@deck.gl/core';
28
12
  import project64Shader from './project64.glsl';
29
13
 
30
- type Project64ModuleSettings = {
14
+ type Project64ModuleProps = {
31
15
  viewport: Viewport;
32
16
  };
33
17
 
@@ -35,15 +19,21 @@ export default {
35
19
  name: 'project64',
36
20
  dependencies: [project, fp64],
37
21
  vs: project64Shader,
38
- getUniforms
39
- } as ShaderModule<Project64ModuleSettings>;
22
+ getUniforms,
23
+ uniformTypes: {
24
+ scale: 'vec2<f32>',
25
+ // Cannot pass as vec2[16], so instead split into 2 mat4x4
26
+ viewProjectionMatrix: 'mat4x4<f32>',
27
+ viewProjectionMatrix64Low: 'mat4x4<f32>'
28
+ }
29
+ } as ShaderModule<Project64ModuleProps>;
40
30
 
41
31
  // TODO - this module should calculate the 64 bit uniforms
42
32
  // It is currently done by project to minimize duplicated work
43
33
 
44
34
  const getMemoizedUniforms = memoize(calculateUniforms);
45
35
 
46
- function getUniforms(opts?: Project64ModuleSettings | {}): Record<string, any> {
36
+ function getUniforms(opts?: Project64ModuleProps | {}): Record<string, any> {
47
37
  if (opts && 'viewport' in opts) {
48
38
  const {viewProjectionMatrix, scale} = opts.viewport;
49
39
  // We only need to update fp64 uniforms if fp32 projection is being updated
@@ -60,11 +50,20 @@ function calculateUniforms({
60
50
  scale: number;
61
51
  }) {
62
52
  const glViewProjectionMatrixFP64 = fp64ifyMatrix4(viewProjectionMatrix);
63
- const scaleFP64 = fp64ify(scale);
64
-
53
+ const viewProjectionMatrix64High = new Float32Array(16);
54
+ const viewProjectionMatrix64Low = new Float32Array(16);
55
+ for (let i = 0; i < 4; i++) {
56
+ for (let j = 0; j < 4; j++) {
57
+ // Match order used in project.viewProjectionMatrix
58
+ const from = 4 * i + j;
59
+ const to = 4 * j + i;
60
+ viewProjectionMatrix64High[to] = glViewProjectionMatrixFP64[2 * from];
61
+ viewProjectionMatrix64Low[to] = glViewProjectionMatrixFP64[2 * from + 1];
62
+ }
63
+ }
65
64
  return {
66
- project_uViewProjectionMatrixFP64: glViewProjectionMatrixFP64,
67
- project64_uViewProjectionMatrix: glViewProjectionMatrixFP64,
68
- project64_uScale: scaleFP64
65
+ scale: fp64ify(scale),
66
+ viewProjectionMatrix: [...viewProjectionMatrix64High],
67
+ viewProjectionMatrix64Low: [...viewProjectionMatrix64Low]
69
68
  };
70
69
  }
package/src/index.ts CHANGED
@@ -1,3 +1,7 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
1
5
  export {default as BrushingExtension} from './brushing/brushing-extension';
2
6
  export {default as DataFilterExtension} from './data-filter/data-filter-extension';
3
7
  export {default as Fp64Extension} from './fp64/fp64-extension';
@@ -29,3 +33,4 @@ export type {ClipExtensionProps} from './clip/clip-extension';
29
33
  export type {CollisionFilterExtensionProps} from './collision-filter/collision-filter-extension';
30
34
  export type {MaskExtensionProps} from './mask/mask-extension';
31
35
  export type {TerrainExtensionProps} from './terrain/terrain-extension';
36
+ export type {TerrainModuleProps} from './terrain/shader-module';
@@ -1,3 +1,7 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
1
5
  import {
2
6
  Layer,
3
7
  Viewport,
@@ -186,8 +190,10 @@ export default class MaskEffect implements Effect {
186
190
  viewports: maskViewport ? [maskViewport] : [],
187
191
  onViewportActive,
188
192
  views,
189
- moduleParameters: {
190
- devicePixelRatio: 1
193
+ shaderModuleProps: {
194
+ project: {
195
+ devicePixelRatio: 1
196
+ }
191
197
  }
192
198
  });
193
199
 
@@ -257,13 +263,17 @@ export default class MaskEffect implements Effect {
257
263
  return channelMap;
258
264
  }
259
265
 
260
- getModuleParameters(): {
261
- maskMap: Texture;
262
- maskChannels: Record<string, Mask> | null;
266
+ getShaderModuleProps(): {
267
+ mask: {
268
+ maskMap: Texture;
269
+ maskChannels: Record<string, Mask> | null;
270
+ };
263
271
  } {
264
272
  return {
265
- maskMap: this.masks ? this.maskMap! : this.dummyMaskMap!,
266
- maskChannels: this.masks
273
+ mask: {
274
+ maskMap: this.masks ? this.maskMap! : this.dummyMaskMap!,
275
+ maskChannels: this.masks
276
+ }
267
277
  };
268
278
  }
269
279
 
@@ -1,5 +1,9 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
1
5
  import {COORDINATE_SYSTEM, Layer, LayerExtension, log} from '@deck.gl/core';
2
- import mask from './shader-module';
6
+ import mask, {MaskProps} from './shader-module';
3
7
  import MaskEffect from './mask-effect';
4
8
 
5
9
  const defaultProps = {
@@ -49,17 +53,18 @@ export default class MaskExtension extends LayerExtension {
49
53
  }
50
54
 
51
55
  /* eslint-disable camelcase */
52
- draw(this: Layer<Required<MaskExtensionProps>>, {uniforms, context, moduleParameters}: any) {
53
- uniforms.mask_maskByInstance = this.state.maskByInstance;
56
+ draw(this: Layer<Required<MaskExtensionProps>>, {context, shaderModuleProps}: any) {
57
+ const maskProps = {} as MaskProps;
58
+ maskProps.maskByInstance = Boolean(this.state.maskByInstance);
54
59
  const {maskId, maskInverted} = this.props;
55
- const {maskChannels} = moduleParameters;
60
+ const {maskChannels} = shaderModuleProps.mask || {};
56
61
  const {viewport} = context;
57
62
  if (maskChannels && maskChannels[maskId]) {
58
63
  const {index, bounds, coordinateOrigin: fromCoordinateOrigin} = maskChannels[maskId];
59
64
  let {coordinateSystem: fromCoordinateSystem} = maskChannels[maskId];
60
- uniforms.mask_enabled = true;
61
- uniforms.mask_channel = index;
62
- uniforms.mask_inverted = maskInverted;
65
+ maskProps.enabled = true;
66
+ maskProps.channel = index;
67
+ maskProps.inverted = maskInverted;
63
68
 
64
69
  if (fromCoordinateSystem === COORDINATE_SYSTEM.DEFAULT) {
65
70
  fromCoordinateSystem = viewport.isGeospatial
@@ -69,12 +74,14 @@ export default class MaskExtension extends LayerExtension {
69
74
  const opts = {modelMatrix: null, fromCoordinateOrigin, fromCoordinateSystem};
70
75
  const bl = this.projectPosition([bounds[0], bounds[1], 0], opts);
71
76
  const tr = this.projectPosition([bounds[2], bounds[3], 0], opts);
72
- uniforms.mask_bounds = [bl[0], bl[1], tr[0], tr[1]];
77
+ maskProps.bounds = [bl[0], bl[1], tr[0], tr[1]];
73
78
  } else {
74
79
  if (maskId) {
75
80
  log.warn(`Could not find a mask layer with id: ${maskId}`)();
76
81
  }
77
- uniforms.mask_enabled = false;
82
+ maskProps.enabled = false;
78
83
  }
84
+
85
+ this.setShaderModuleProps({mask: maskProps});
79
86
  }
80
87
  }
@@ -1,3 +1,7 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
1
5
  import type {Device, Framebuffer, RenderPipelineParameters, Texture} from '@luma.gl/core';
2
6
  import {Layer, _LayersPass as LayersPass, LayersPassRenderOptions, Viewport} from '@deck.gl/core';
3
7
 
@@ -1,38 +1,52 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
1
5
  import type {ShaderModule} from '@luma.gl/shadertools';
2
6
  import {project} from '@deck.gl/core';
3
7
  import type {Texture} from '@luma.gl/core';
4
- import {glsl} from '../utils/syntax-tags';
5
8
 
6
- const vs = glsl`
7
- uniform vec4 mask_bounds;
8
- uniform bool mask_maskByInstance;
9
+ const uniformBlock = /* glsl */ `\
10
+ uniform maskUniforms {
11
+ vec4 bounds;
12
+ highp int channel;
13
+ bool enabled;
14
+ bool inverted;
15
+ bool maskByInstance;
16
+ } mask;
17
+ `;
18
+
19
+ const vertex = /* glsl */ `
9
20
  vec2 mask_getCoords(vec4 position) {
10
- return (position.xy - mask_bounds.xy) / (mask_bounds.zw - mask_bounds.xy);
21
+ return (position.xy - mask.bounds.xy) / (mask.bounds.zw - mask.bounds.xy);
11
22
  }
12
23
  `;
13
24
 
14
- const fs = glsl`
25
+ const vs = `
26
+ ${uniformBlock}
27
+ ${vertex}
28
+ `;
29
+
30
+ const fragment = /* glsl */ `
15
31
  uniform sampler2D mask_texture;
16
- uniform int mask_channel;
17
- uniform bool mask_enabled;
18
- uniform bool mask_inverted;
32
+
19
33
  bool mask_isInBounds(vec2 texCoords) {
20
- if (!mask_enabled) {
34
+ if (!mask.enabled) {
21
35
  return true;
22
36
  }
23
37
  vec4 maskColor = texture(mask_texture, texCoords);
24
38
  float maskValue = 1.0;
25
- if (mask_channel == 0) {
39
+ if (mask.channel == 0) {
26
40
  maskValue = maskColor.r;
27
- } else if (mask_channel == 1) {
41
+ } else if (mask.channel == 1) {
28
42
  maskValue = maskColor.g;
29
- } else if (mask_channel == 2) {
43
+ } else if (mask.channel == 2) {
30
44
  maskValue = maskColor.b;
31
- } else if (mask_channel == 3) {
45
+ } else if (mask.channel == 3) {
32
46
  maskValue = maskColor.a;
33
47
  }
34
48
 
35
- if (mask_inverted) {
49
+ if (mask.inverted) {
36
50
  return maskValue >= 0.5;
37
51
  } else {
38
52
  return maskValue < 0.5;
@@ -40,47 +54,62 @@ bool mask_isInBounds(vec2 texCoords) {
40
54
  }
41
55
  `;
42
56
 
57
+ const fs = `
58
+ ${uniformBlock}
59
+ ${fragment}
60
+ `;
61
+
43
62
  const inject = {
44
- 'vs:#decl': glsl`
63
+ 'vs:#decl': /* glsl */ `
45
64
  out vec2 mask_texCoords;
46
65
  `,
47
- 'vs:#main-end': glsl`
66
+ 'vs:#main-end': /* glsl */ `
48
67
  vec4 mask_common_position;
49
- if (mask_maskByInstance) {
68
+ if (mask.maskByInstance) {
50
69
  mask_common_position = project_position(vec4(geometry.worldPosition, 1.0));
51
70
  } else {
52
71
  mask_common_position = geometry.position;
53
72
  }
54
73
  mask_texCoords = mask_getCoords(mask_common_position);
55
74
  `,
56
- 'fs:#decl': glsl`
75
+ 'fs:#decl': /* glsl */ `
57
76
  in vec2 mask_texCoords;
58
77
  `,
59
- 'fs:#main-start': glsl`
60
- if (mask_enabled) {
78
+ 'fs:#main-start': /* glsl */ `
79
+ if (mask.enabled) {
61
80
  bool mask = mask_isInBounds(mask_texCoords);
62
81
 
63
82
  // Debug: show extent of render target
64
83
  // fragColor = vec4(mask_texCoords, 0.0, 1.0);
65
- fragColor = texture(mask_texture, mask_texCoords);
84
+ // fragColor = texture(mask_texture, mask_texCoords);
66
85
 
67
86
  if (!mask) discard;
68
87
  }
69
88
  `
70
89
  };
71
90
 
72
- type MaskModuleSettings = {
91
+ type MaskBindingProps = {
73
92
  maskMap?: Texture;
74
93
  };
75
94
 
95
+ type MaskUniformProps = {
96
+ bounds: [number, number, number, number];
97
+ channel: number;
98
+ enabled: boolean;
99
+ inverted: boolean;
100
+ maskByInstance: boolean;
101
+ };
102
+
103
+ export type MaskProps = MaskBindingProps & MaskUniformProps;
104
+
76
105
  /* eslint-disable camelcase */
77
- const getMaskUniforms = (opts?: MaskModuleSettings | {}): Record<string, any> => {
106
+ const getMaskUniforms = (opts?: MaskProps | {}): Record<string, any> => {
78
107
  if (opts && 'maskMap' in opts) {
79
108
  return {
80
109
  mask_texture: opts.maskMap
81
110
  };
82
111
  }
83
- return {};
112
+ return opts || {};
84
113
  };
85
114
 
86
115
  export default {
@@ -89,5 +118,12 @@ export default {
89
118
  vs,
90
119
  fs,
91
120
  inject,
92
- getUniforms: getMaskUniforms
93
- } as ShaderModule<MaskModuleSettings>;
121
+ getUniforms: getMaskUniforms,
122
+ uniformTypes: {
123
+ bounds: 'vec4<f32>',
124
+ channel: 'i32',
125
+ enabled: 'i32',
126
+ inverted: 'i32',
127
+ maskByInstance: 'i32'
128
+ }
129
+ } as const satisfies ShaderModule<MaskProps>;