@mapcatch/util 2.0.3 → 2.0.5-a

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 (74) hide show
  1. package/.eslintrc.js +54 -0
  2. package/.husky/pre-commit +1 -0
  3. package/.prettierrc +4 -0
  4. package/.vscode/settings.json +2 -0
  5. package/CHANGELOG.md +5 -1
  6. package/README.md +44 -0
  7. package/debug/app.js +26 -0
  8. package/debug/index.html +55 -0
  9. package/debug/libs/vue.global.js +16159 -0
  10. package/debug/my_icon.png +0 -0
  11. package/docs/Catolog.md +24 -0
  12. package/docs/Constant.md +92 -0
  13. package/docs/Event.md +90 -0
  14. package/docs/Util.md +345 -0
  15. package/package.json +2 -2
  16. package/src/constants/crs.js +42098 -42098
  17. package/src/constants/default_layers.js +102 -11
  18. package/src/constants/index.js +1 -0
  19. package/src/constants/layer_groups_multispectral.js +34 -0
  20. package/src/constants/layer_icons.js +1 -0
  21. package/src/gl-operations/constants.js +9 -9
  22. package/src/gl-operations/default_options.js +97 -97
  23. package/src/gl-operations/index.js +532 -520
  24. package/src/gl-operations/reglCommands/contours.js +27 -27
  25. package/src/gl-operations/reglCommands/default.js +45 -43
  26. package/src/gl-operations/reglCommands/hillshading.js +340 -332
  27. package/src/gl-operations/reglCommands/index.js +6 -6
  28. package/src/gl-operations/reglCommands/multiLayers.js +303 -301
  29. package/src/gl-operations/reglCommands/transitions.js +111 -109
  30. package/src/gl-operations/reglCommands/util.js +71 -71
  31. package/src/gl-operations/renderer.js +209 -192
  32. package/src/gl-operations/shaders/fragment/convertDem.js +25 -25
  33. package/src/gl-operations/shaders/fragment/convolutionSmooth.js +54 -54
  34. package/src/gl-operations/shaders/fragment/diffCalc.js +33 -33
  35. package/src/gl-operations/shaders/fragment/drawResult.js +46 -41
  36. package/src/gl-operations/shaders/fragment/hillshading/hsAdvAmbientShadows.js +78 -78
  37. package/src/gl-operations/shaders/fragment/hillshading/hsAdvDirect.js +59 -54
  38. package/src/gl-operations/shaders/fragment/hillshading/hsAdvFinalBaselayer.js +30 -30
  39. package/src/gl-operations/shaders/fragment/hillshading/hsAdvFinalColorscale.js +60 -55
  40. package/src/gl-operations/shaders/fragment/hillshading/hsAdvMergeAndScaleTiles.js +26 -26
  41. package/src/gl-operations/shaders/fragment/hillshading/hsAdvNormals.js +25 -25
  42. package/src/gl-operations/shaders/fragment/hillshading/hsAdvSmooth.js +53 -53
  43. package/src/gl-operations/shaders/fragment/hillshading/hsAdvSoftShadows.js +80 -80
  44. package/src/gl-operations/shaders/fragment/hillshading/hsPregen.js +54 -49
  45. package/src/gl-operations/shaders/fragment/interpolateColor.js +65 -62
  46. package/src/gl-operations/shaders/fragment/interpolateColorOnly.js +49 -46
  47. package/src/gl-operations/shaders/fragment/interpolateValue.js +136 -123
  48. package/src/gl-operations/shaders/fragment/multiAnalyze1Calc.js +35 -35
  49. package/src/gl-operations/shaders/fragment/multiAnalyze2Calc.js +45 -45
  50. package/src/gl-operations/shaders/fragment/multiAnalyze3Calc.js +53 -53
  51. package/src/gl-operations/shaders/fragment/multiAnalyze4Calc.js +61 -61
  52. package/src/gl-operations/shaders/fragment/multiAnalyze5Calc.js +69 -69
  53. package/src/gl-operations/shaders/fragment/multiAnalyze6Calc.js +77 -77
  54. package/src/gl-operations/shaders/fragment/single.js +93 -88
  55. package/src/gl-operations/shaders/transform.js +21 -21
  56. package/src/gl-operations/shaders/util/computeColor.glsl +85 -84
  57. package/src/gl-operations/shaders/util/getTexelValue.glsl +10 -10
  58. package/src/gl-operations/shaders/util/isCloseEnough.glsl +9 -9
  59. package/src/gl-operations/shaders/util/rgbaToFloat.glsl +17 -17
  60. package/src/gl-operations/shaders/vertex/double.js +16 -16
  61. package/src/gl-operations/shaders/vertex/multi3.js +19 -19
  62. package/src/gl-operations/shaders/vertex/multi4.js +22 -22
  63. package/src/gl-operations/shaders/vertex/multi5.js +25 -25
  64. package/src/gl-operations/shaders/vertex/multi6.js +28 -28
  65. package/src/gl-operations/shaders/vertex/single.js +13 -13
  66. package/src/gl-operations/shaders/vertex/singleNotTransformed.js +11 -11
  67. package/src/gl-operations/texture_manager.js +141 -141
  68. package/src/gl-operations/util.js +336 -336
  69. package/src/measure/index.js +14 -8
  70. package/src/transform.js +3 -0
  71. package/src/util.js +14 -6
  72. package/vite.config.js +58 -0
  73. package/dist/catchUtil.min.esm.js +0 -112833
  74. package/dist/catchUtil.min.js +0 -2922
@@ -1,332 +1,340 @@
1
- import vertSingle from '../shaders/vertex/single.js'
2
- import vertDouble from '../shaders/vertex/double.js'
3
- import vertSingleNotTransformed from '../shaders/vertex/singleNotTransformed.js'
4
-
5
- import fragSingle from '../shaders/fragment/single.js'
6
- import fragHsPregen from '../shaders/fragment/hillshading/hsPregen.js'
7
- import fragHsAdvMergeAndScaleTiles from '../shaders/fragment/hillshading/hsAdvMergeAndScaleTiles.js'
8
- import fragHsAdvNormals from '../shaders/fragment/hillshading/hsAdvNormals.js'
9
- import fragHsAdvDirectLight from '../shaders/fragment/hillshading/hsAdvDirect.js'
10
- import fragHsAdvSoftShadows from '../shaders/fragment/hillshading/hsAdvSoftShadows.js'
11
- import fragHsAdvAmbientShadows from '../shaders/fragment/hillshading/hsAdvAmbientShadows.js'
12
- import fragHsAdvFinalColorscale from '../shaders/fragment/hillshading/hsAdvFinalColorscale.js'
13
- import fragHsAdvFinalBaselayer from '../shaders/fragment/hillshading/hsAdvFinalBaselayer.js'
14
- import fragHsAdvSmooth from '../shaders/fragment/hillshading/hsAdvSmooth.js'
15
-
16
- import {
17
- DEG2RAD,
18
- SLOPEFACTOR
19
- } from '../constants'
20
-
21
- import * as util from '../util'
22
-
23
- const littleEndian = util.machineIsLittleEndian()
24
-
25
- /**
26
- * The resulting Regl DrawCommand is used to draw a single tile. The fragment shader decodes the
27
- * Float32 value of a pixel and colorizes it with the given color scale (and/or sentinel values).
28
- * Hillshading is applied with a simple and fast algorithm
29
- */
30
- export function createDrawTileHsSimpleCommand (regl, commonConfig, fragMacros) {
31
- return regl({
32
- ...commonConfig,
33
- vert: vertSingle,
34
- frag: util.defineMacros(fragSingle, fragMacros),
35
- uniforms: {
36
- ...commonConfig.uniforms,
37
- scaleLength: regl.prop('scaleLength'),
38
- sentinelLength: regl.prop('sentinelLength'),
39
- scaleColormap: regl.prop('scaleColormap'),
40
- sentinelColormap: regl.prop('sentinelColormap'),
41
- texture: (_, { texture }) => texture,
42
- enableSimpleHillshade: (_, { enableSimpleHillshade }) => enableSimpleHillshade,
43
- azimuth: (_, { azimuth }) => azimuth,
44
- altitude: (_, { altitude }) => altitude,
45
- slopescale: (_, { slopescale }) => slopescale,
46
- deg2rad: DEG2RAD,
47
- slopeFactor: SLOPEFACTOR,
48
- offset: (_, { offset }) => offset,
49
- textureBounds: (_, { textureBounds }) => {
50
- return [
51
- [textureBounds[0].x],
52
- [textureBounds[0].y],
53
- [textureBounds[1].x],
54
- [textureBounds[1].y]
55
- ]
56
- },
57
- textureSize: (_, { textureSize }) => textureSize,
58
- tileSize: (_, { tileSize }) => tileSize
59
- },
60
- attributes: {
61
- ...commonConfig.attributes,
62
- texCoord: (_, { textureBounds }) => util.getTexCoordVerticesTriangleStripQuad(textureBounds)
63
- }
64
- })
65
- }
66
-
67
- /**
68
- * The resulting Regl DrawCommand is used to draw a single tile. The fragment shader decodes the
69
- * Float32 value of a pixel and colorizes it with the given color scale (and/or sentinel values).
70
- * Hillshading is applied from a pre-generated texture
71
- */
72
- export function createDrawTileHsPregenCommand (regl, commonConfig, fragMacros) {
73
- return regl({
74
- ...commonConfig,
75
- vert: vertDouble,
76
- frag: util.defineMacros(fragHsPregen, fragMacros),
77
- uniforms: {
78
- ...commonConfig.uniforms,
79
- scaleLength: regl.prop('scaleLength'),
80
- sentinelLength: regl.prop('sentinelLength'),
81
- scaleColormap: regl.prop('scaleColormap'),
82
- sentinelColormap: regl.prop('sentinelColormap'),
83
- texture: (_, { texture }) => texture,
84
- hillshadePregenTexture: (_, { hillshadePregenTexture }) => hillshadePregenTexture
85
- },
86
- attributes: {
87
- ...commonConfig.attributes,
88
- texCoordA: (_, { textureBounds }) => util.getTexCoordVerticesTriangleStripQuad(textureBounds),
89
- texCoordB: (_, { textureBoundsHs }) => util.getTexCoordVerticesTriangleStripQuad(textureBoundsHs)
90
- }
91
- })
92
- }
93
-
94
-
95
- /**
96
- * The resulting Regl DrawCommand is used to get the float values from the 3x3
97
- * adjacent tiles. The float values can be scaled to adjust the hillshading.
98
- * It will be saved to a framebuffer and is used as an input to advanced hillshading
99
- */
100
- export function createHsAdvMergeAndScaleTiles (regl) {
101
- return regl({
102
- vert: vertSingleNotTransformed,
103
- frag: fragHsAdvMergeAndScaleTiles,
104
- uniforms: {
105
- littleEndian: littleEndian,
106
- nodataValue: regl.prop('nodataValue'),
107
- texture: regl.prop('texture'),
108
- floatScale: regl.prop('floatScale')
109
- },
110
- attributes: {
111
- // 18 triangles = 9 tiles
112
- position: [
113
- [-1, 1], [-1 / 3, 1], [-1, 1 / 3], [-1 / 3, 1 / 3], [-1 / 3, 1], [-1, 1 / 3],
114
- [-1, 1 / 3], [-1 / 3, 1 / 3], [-1, -1 / 3], [-1 / 3, -1 / 3], [-1 / 3, 1 / 3], [-1, -1 / 3],
115
- [-1, -1 / 3], [-1 / 3, -1 / 3], [-1, -1], [-1 / 3, -1], [-1 / 3, -1 / 3], [-1, -1],
116
- [-1 / 3, 1], [1 / 3, 1], [-1 / 3, 1 / 3], [1 / 3, 1 / 3], [1 / 3, 1], [-1 / 3, 1 / 3],
117
- [-1 / 3, 1 / 3], [1 / 3, 1 / 3], [-1 / 3, -1 / 3], [1 / 3, -1 / 3], [1 / 3, 1 / 3], [-1 / 3, -1 / 3],
118
- [-1 / 3, -1 / 3], [1 / 3, -1 / 3], [-1 / 3, -1], [1 / 3, -1], [1 / 3, -1 / 3], [-1 / 3, -1],
119
- [1 / 3, 1], [1, 1], [1 / 3, 1 / 3], [1, 1 / 3], [1, 1], [1 / 3, 1 / 3],
120
- [1 / 3, 1 / 3], [1, 1 / 3], [1 / 3, -1 / 3], [1, -1 / 3], [1, 1 / 3], [1 / 3, -1 / 3],
121
- [1 / 3, -1 / 3], [1, -1 / 3], [1 / 3, -1], [1, -1], [1, -1 / 3], [1 / 3, -1]
122
- ],
123
- texCoord: regl.prop('texCoord')
124
- },
125
- depth: { enable: false },
126
- primitive: 'triangles',
127
- count: 54,
128
- viewport: (_, { canvasSize: [width, height] }) => ({ width, height }),
129
- framebuffer: regl.prop('fbo')
130
- })
131
- }
132
-
133
-
134
- /**
135
- * The resulting Regl DrawCommand is for using a convolution kernel to smooth the input data.
136
- * Currently hard-coded the kernel and positions in the shader to reduce number of uniforms.
137
- * TODO: Merge with contours function
138
- */
139
- export function createHsAdvSmoothCommand (regl, commonConfig) {
140
- return regl({
141
- ...commonConfig,
142
- vert: vertSingleNotTransformed,
143
- frag: fragHsAdvSmooth,
144
- uniforms: {
145
- ...commonConfig.uniforms,
146
- tInput: regl.prop('tInput'),
147
- textureSize: regl.prop('textureSize'),
148
- kernelSize: regl.prop('kernelSize')
149
- },
150
- attributes: {
151
- position: [[-1, 1], [1, 1], [-1, -1], [1, -1]],
152
- texCoord: [[0, 1], [1, 1], [0, 0], [1, 0]]
153
- },
154
- framebuffer: regl.prop('fbo')
155
- })
156
- }
157
-
158
-
159
- /**
160
- * The resulting Regl DrawCommand is used to calculate the normals.
161
- * It is used as an input to advanced hillshading
162
- */
163
- export function createHsAdvCalcNormals (
164
- regl,
165
- commonConfig
166
- ) {
167
- return regl({
168
- ...commonConfig,
169
- vert: vertSingleNotTransformed,
170
- frag: fragHsAdvNormals,
171
- uniforms: {
172
- ...commonConfig.uniforms,
173
- tInput: regl.prop('tInput'),
174
- pixelScale: regl.prop('pixelScale'),
175
- onePixel: regl.prop('onePixel')
176
- },
177
- attributes: {
178
- position: [[-1, 1], [1, 1], [-1, -1], [1, -1]],
179
- texCoord: [[0, 1], [1, 1], [0, 0], [1, 0]]
180
- },
181
- framebuffer: regl.prop('fbo')
182
- })
183
- }
184
-
185
- /**
186
- * The resulting Regl DrawCommand is used to show hillshading without shadows.
187
- * Not currently used
188
- */
189
- export function createHsAdvDirectLightning (
190
- regl,
191
- commonConfig
192
- ) {
193
- return regl({
194
- ...commonConfig,
195
- vert: vertSingleNotTransformed,
196
- frag: fragHsAdvDirectLight,
197
- uniforms: {
198
- ...commonConfig.uniforms,
199
- scaleLength: regl.prop('scaleLength'),
200
- sentinelLength: regl.prop('sentinelLength'),
201
- scaleColormap: regl.prop('scaleColormap'),
202
- sentinelColormap: regl.prop('sentinelColormap'),
203
- tInput: regl.prop('tInput'),
204
- tNormal: regl.prop('tNormal'),
205
- floatScale: regl.prop('floatScale'),
206
- sunDirection: regl.prop('sunDirection')
207
- },
208
- attributes: {
209
- position: [[-1, 1], [1, 1], [-1, -1], [1, -1]],
210
- texCoord: [[0, 1], [1, 1], [0, 0], [1, 0]]
211
- }
212
- })
213
- }
214
-
215
- /**
216
- * The resulting Regl DrawCommand is used to calculate soft shadows.
217
- */
218
- export function createHsAdvSoftShadows (
219
- regl,
220
- commonConfig
221
- ) {
222
- return regl({
223
- ...commonConfig,
224
- vert: vertSingleNotTransformed,
225
- frag: fragHsAdvSoftShadows,
226
- uniforms: {
227
- ...commonConfig.uniforms,
228
- tInput: regl.prop('tInput'),
229
- tNormal: regl.prop('tNormal'),
230
- tSrc: regl.prop('tSrc'),
231
- softIterations: regl.prop('softIterations'),
232
- pixelScale: regl.prop('pixelScale'),
233
- resolution: regl.prop('resolution'),
234
- sunDirection: regl.prop('sunDirection')
235
- },
236
- attributes: {
237
- position: [[-1, 1], [1, 1], [-1, -1], [1, -1]],
238
- texCoord: [[1 / 3, 2 / 3], [2 / 3, 2 / 3], [1 / 3, 1 / 3], [2 / 3, 1 / 3]]
239
- },
240
- framebuffer: regl.prop('fbo')
241
- })
242
- }
243
-
244
- /**
245
- * The resulting Regl DrawCommand is used to calculate ambient lighting.
246
- */
247
- export function createHsAdvAmbientShadows (
248
- regl,
249
- commonConfig
250
- ) {
251
- return regl({
252
- ...commonConfig,
253
- vert: vertSingleNotTransformed,
254
- frag: fragHsAdvAmbientShadows,
255
- uniforms: {
256
- ...commonConfig.uniforms,
257
- tInput: regl.prop('tInput'),
258
- tNormal: regl.prop('tNormal'),
259
- tSrc: regl.prop('tSrc'),
260
- ambientIterations: regl.prop('ambientIterations'),
261
- pixelScale: regl.prop('pixelScale'),
262
- resolution: regl.prop('resolution'),
263
- direction: regl.prop('direction')
264
- },
265
- attributes: {
266
- position: [[-1, 1], [1, 1], [-1, -1], [1, -1]],
267
- texCoord: [[1 / 3, 2 / 3], [2 / 3, 2 / 3], [1 / 3, 1 / 3], [2 / 3, 1 / 3]]
268
- },
269
- framebuffer: regl.prop('fbo')
270
- })
271
- }
272
-
273
- /**
274
- * The resulting Regl DrawCommand is used to combine soft and ambient shading,
275
- * use the colormap on the input floats and apply the hillshading.
276
- */
277
- export function createHsAdvFinalColorscale (
278
- regl,
279
- commonConfig
280
- ) {
281
- return regl({
282
- ...commonConfig,
283
- vert: vertDouble,
284
- frag: fragHsAdvFinalColorscale,
285
- uniforms: {
286
- ...commonConfig.uniforms,
287
- scaleLength: regl.prop('scaleLength'),
288
- sentinelLength: regl.prop('sentinelLength'),
289
- scaleColormap: regl.prop('scaleColormap'),
290
- sentinelColormap: regl.prop('sentinelColormap'),
291
- tInput: regl.prop('tInput'),
292
- tSoftShadow: regl.prop('tSoftShadow'),
293
- tAmbient: regl.prop('tAmbient'),
294
- floatScale: regl.prop('floatScale'),
295
- finalSoftMultiplier: regl.prop('finalSoftMultiplier'),
296
- finalAmbientMultiplier: regl.prop('finalAmbientMultiplier')
297
- },
298
- attributes: {
299
- ...commonConfig.attributes,
300
- texCoordA: [[1 / 3, 2 / 3], [2 / 3, 2 / 3], [1 / 3, 1 / 3], [2 / 3, 1 / 3]],
301
- texCoordB: [[0, 1], [1, 1], [0, 0], [1, 0]]
302
- }
303
- })
304
- }
305
-
306
- /**
307
- * The resulting Regl DrawCommand is used to combine soft and ambient shading,
308
- * use the baselayer tile and apply the hillshading.
309
- */
310
- export function createHsAdvFinalBaselayer (
311
- regl,
312
- commonConfig
313
- ) {
314
- return regl({
315
- ...commonConfig,
316
- vert: vertDouble,
317
- frag: fragHsAdvFinalBaselayer,
318
- uniforms: {
319
- ...commonConfig.uniforms,
320
- tBase: regl.prop('tBase'),
321
- tSoftShadow: regl.prop('tSoftShadow'),
322
- tAmbient: regl.prop('tAmbient'),
323
- finalSoftMultiplier: regl.prop('finalSoftMultiplier'),
324
- finalAmbientMultiplier: regl.prop('finalAmbientMultiplier')
325
- },
326
- attributes: {
327
- ...commonConfig.attributes,
328
- texCoordA: regl.prop('baseTexCoords'),
329
- texCoordB: [[0, 1], [1, 1], [0, 0], [1, 0]]
330
- }
331
- })
332
- }
1
+ import vertSingle from '../shaders/vertex/single.js'
2
+ import vertDouble from '../shaders/vertex/double.js'
3
+ import vertSingleNotTransformed from '../shaders/vertex/singleNotTransformed.js'
4
+
5
+ import fragSingle from '../shaders/fragment/single.js'
6
+ import fragHsPregen from '../shaders/fragment/hillshading/hsPregen.js'
7
+ import fragHsAdvMergeAndScaleTiles from '../shaders/fragment/hillshading/hsAdvMergeAndScaleTiles.js'
8
+ import fragHsAdvNormals from '../shaders/fragment/hillshading/hsAdvNormals.js'
9
+ import fragHsAdvDirectLight from '../shaders/fragment/hillshading/hsAdvDirect.js'
10
+ import fragHsAdvSoftShadows from '../shaders/fragment/hillshading/hsAdvSoftShadows.js'
11
+ import fragHsAdvAmbientShadows from '../shaders/fragment/hillshading/hsAdvAmbientShadows.js'
12
+ import fragHsAdvFinalColorscale from '../shaders/fragment/hillshading/hsAdvFinalColorscale.js'
13
+ import fragHsAdvFinalBaselayer from '../shaders/fragment/hillshading/hsAdvFinalBaselayer.js'
14
+ import fragHsAdvSmooth from '../shaders/fragment/hillshading/hsAdvSmooth.js'
15
+
16
+ import {
17
+ DEG2RAD,
18
+ SLOPEFACTOR
19
+ } from '../constants'
20
+
21
+ import * as util from '../util'
22
+
23
+ const littleEndian = util.machineIsLittleEndian()
24
+
25
+ /**
26
+ * The resulting Regl DrawCommand is used to draw a single tile. The fragment shader decodes the
27
+ * Float32 value of a pixel and colorizes it with the given color scale (and/or sentinel values).
28
+ * Hillshading is applied with a simple and fast algorithm
29
+ */
30
+ export function createDrawTileHsSimpleCommand (regl, commonConfig, fragMacros) {
31
+ return regl({
32
+ ...commonConfig,
33
+ vert: vertSingle,
34
+ frag: util.defineMacros(fragSingle, fragMacros),
35
+ uniforms: {
36
+ ...commonConfig.uniforms,
37
+ scaleLength: regl.prop('scaleLength'),
38
+ sentinelLength: regl.prop('sentinelLength'),
39
+ scaleColormap: regl.prop('scaleColormap'),
40
+ sentinelColormap: regl.prop('sentinelColormap'),
41
+ aboveColor: regl.prop('aboveColor'),
42
+ belowColor: regl.prop('belowColor'),
43
+ texture: (_, { texture }) => texture,
44
+ enableSimpleHillshade: (_, { enableSimpleHillshade }) => enableSimpleHillshade,
45
+ azimuth: (_, { azimuth }) => azimuth,
46
+ altitude: (_, { altitude }) => altitude,
47
+ slopescale: (_, { slopescale }) => slopescale,
48
+ deg2rad: DEG2RAD,
49
+ slopeFactor: SLOPEFACTOR,
50
+ offset: (_, { offset }) => offset,
51
+ textureBounds: (_, { textureBounds }) => {
52
+ return [
53
+ [textureBounds[0].x],
54
+ [textureBounds[0].y],
55
+ [textureBounds[1].x],
56
+ [textureBounds[1].y]
57
+ ]
58
+ },
59
+ textureSize: (_, { textureSize }) => textureSize,
60
+ tileSize: (_, { tileSize }) => tileSize
61
+ },
62
+ attributes: {
63
+ ...commonConfig.attributes,
64
+ texCoord: (_, { textureBounds }) => util.getTexCoordVerticesTriangleStripQuad(textureBounds)
65
+ }
66
+ })
67
+ }
68
+
69
+ /**
70
+ * The resulting Regl DrawCommand is used to draw a single tile. The fragment shader decodes the
71
+ * Float32 value of a pixel and colorizes it with the given color scale (and/or sentinel values).
72
+ * Hillshading is applied from a pre-generated texture
73
+ */
74
+ export function createDrawTileHsPregenCommand (regl, commonConfig, fragMacros) {
75
+ return regl({
76
+ ...commonConfig,
77
+ vert: vertDouble,
78
+ frag: util.defineMacros(fragHsPregen, fragMacros),
79
+ uniforms: {
80
+ ...commonConfig.uniforms,
81
+ scaleLength: regl.prop('scaleLength'),
82
+ sentinelLength: regl.prop('sentinelLength'),
83
+ scaleColormap: regl.prop('scaleColormap'),
84
+ sentinelColormap: regl.prop('sentinelColormap'),
85
+ aboveColor: regl.prop('aboveColor'),
86
+ belowColor: regl.prop('belowColor'),
87
+ texture: (_, { texture }) => texture,
88
+ hillshadePregenTexture: (_, { hillshadePregenTexture }) => hillshadePregenTexture
89
+ },
90
+ attributes: {
91
+ ...commonConfig.attributes,
92
+ texCoordA: (_, { textureBounds }) => util.getTexCoordVerticesTriangleStripQuad(textureBounds),
93
+ texCoordB: (_, { textureBoundsHs }) => util.getTexCoordVerticesTriangleStripQuad(textureBoundsHs)
94
+ }
95
+ })
96
+ }
97
+
98
+
99
+ /**
100
+ * The resulting Regl DrawCommand is used to get the float values from the 3x3
101
+ * adjacent tiles. The float values can be scaled to adjust the hillshading.
102
+ * It will be saved to a framebuffer and is used as an input to advanced hillshading
103
+ */
104
+ export function createHsAdvMergeAndScaleTiles (regl) {
105
+ return regl({
106
+ vert: vertSingleNotTransformed,
107
+ frag: fragHsAdvMergeAndScaleTiles,
108
+ uniforms: {
109
+ littleEndian: littleEndian,
110
+ nodataValue: regl.prop('nodataValue'),
111
+ texture: regl.prop('texture'),
112
+ floatScale: regl.prop('floatScale')
113
+ },
114
+ attributes: {
115
+ // 18 triangles = 9 tiles
116
+ position: [
117
+ [-1, 1], [-1 / 3, 1], [-1, 1 / 3], [-1 / 3, 1 / 3], [-1 / 3, 1], [-1, 1 / 3],
118
+ [-1, 1 / 3], [-1 / 3, 1 / 3], [-1, -1 / 3], [-1 / 3, -1 / 3], [-1 / 3, 1 / 3], [-1, -1 / 3],
119
+ [-1, -1 / 3], [-1 / 3, -1 / 3], [-1, -1], [-1 / 3, -1], [-1 / 3, -1 / 3], [-1, -1],
120
+ [-1 / 3, 1], [1 / 3, 1], [-1 / 3, 1 / 3], [1 / 3, 1 / 3], [1 / 3, 1], [-1 / 3, 1 / 3],
121
+ [-1 / 3, 1 / 3], [1 / 3, 1 / 3], [-1 / 3, -1 / 3], [1 / 3, -1 / 3], [1 / 3, 1 / 3], [-1 / 3, -1 / 3],
122
+ [-1 / 3, -1 / 3], [1 / 3, -1 / 3], [-1 / 3, -1], [1 / 3, -1], [1 / 3, -1 / 3], [-1 / 3, -1],
123
+ [1 / 3, 1], [1, 1], [1 / 3, 1 / 3], [1, 1 / 3], [1, 1], [1 / 3, 1 / 3],
124
+ [1 / 3, 1 / 3], [1, 1 / 3], [1 / 3, -1 / 3], [1, -1 / 3], [1, 1 / 3], [1 / 3, -1 / 3],
125
+ [1 / 3, -1 / 3], [1, -1 / 3], [1 / 3, -1], [1, -1], [1, -1 / 3], [1 / 3, -1]
126
+ ],
127
+ texCoord: regl.prop('texCoord')
128
+ },
129
+ depth: { enable: false },
130
+ primitive: 'triangles',
131
+ count: 54,
132
+ viewport: (_, { canvasSize: [width, height] }) => ({ width, height }),
133
+ framebuffer: regl.prop('fbo')
134
+ })
135
+ }
136
+
137
+
138
+ /**
139
+ * The resulting Regl DrawCommand is for using a convolution kernel to smooth the input data.
140
+ * Currently hard-coded the kernel and positions in the shader to reduce number of uniforms.
141
+ * TODO: Merge with contours function
142
+ */
143
+ export function createHsAdvSmoothCommand (regl, commonConfig) {
144
+ return regl({
145
+ ...commonConfig,
146
+ vert: vertSingleNotTransformed,
147
+ frag: fragHsAdvSmooth,
148
+ uniforms: {
149
+ ...commonConfig.uniforms,
150
+ tInput: regl.prop('tInput'),
151
+ textureSize: regl.prop('textureSize'),
152
+ kernelSize: regl.prop('kernelSize')
153
+ },
154
+ attributes: {
155
+ position: [[-1, 1], [1, 1], [-1, -1], [1, -1]],
156
+ texCoord: [[0, 1], [1, 1], [0, 0], [1, 0]]
157
+ },
158
+ framebuffer: regl.prop('fbo')
159
+ })
160
+ }
161
+
162
+
163
+ /**
164
+ * The resulting Regl DrawCommand is used to calculate the normals.
165
+ * It is used as an input to advanced hillshading
166
+ */
167
+ export function createHsAdvCalcNormals (
168
+ regl,
169
+ commonConfig
170
+ ) {
171
+ return regl({
172
+ ...commonConfig,
173
+ vert: vertSingleNotTransformed,
174
+ frag: fragHsAdvNormals,
175
+ uniforms: {
176
+ ...commonConfig.uniforms,
177
+ tInput: regl.prop('tInput'),
178
+ pixelScale: regl.prop('pixelScale'),
179
+ onePixel: regl.prop('onePixel')
180
+ },
181
+ attributes: {
182
+ position: [[-1, 1], [1, 1], [-1, -1], [1, -1]],
183
+ texCoord: [[0, 1], [1, 1], [0, 0], [1, 0]]
184
+ },
185
+ framebuffer: regl.prop('fbo')
186
+ })
187
+ }
188
+
189
+ /**
190
+ * The resulting Regl DrawCommand is used to show hillshading without shadows.
191
+ * Not currently used
192
+ */
193
+ export function createHsAdvDirectLightning (
194
+ regl,
195
+ commonConfig
196
+ ) {
197
+ return regl({
198
+ ...commonConfig,
199
+ vert: vertSingleNotTransformed,
200
+ frag: fragHsAdvDirectLight,
201
+ uniforms: {
202
+ ...commonConfig.uniforms,
203
+ scaleLength: regl.prop('scaleLength'),
204
+ sentinelLength: regl.prop('sentinelLength'),
205
+ scaleColormap: regl.prop('scaleColormap'),
206
+ sentinelColormap: regl.prop('sentinelColormap'),
207
+ tInput: regl.prop('tInput'),
208
+ tNormal: regl.prop('tNormal'),
209
+ floatScale: regl.prop('floatScale'),
210
+ sunDirection: regl.prop('sunDirection'),
211
+ aboveColor: regl.prop('aboveColor'),
212
+ belowColor: regl.prop('belowColor')
213
+ },
214
+ attributes: {
215
+ position: [[-1, 1], [1, 1], [-1, -1], [1, -1]],
216
+ texCoord: [[0, 1], [1, 1], [0, 0], [1, 0]]
217
+ }
218
+ })
219
+ }
220
+
221
+ /**
222
+ * The resulting Regl DrawCommand is used to calculate soft shadows.
223
+ */
224
+ export function createHsAdvSoftShadows (
225
+ regl,
226
+ commonConfig
227
+ ) {
228
+ return regl({
229
+ ...commonConfig,
230
+ vert: vertSingleNotTransformed,
231
+ frag: fragHsAdvSoftShadows,
232
+ uniforms: {
233
+ ...commonConfig.uniforms,
234
+ tInput: regl.prop('tInput'),
235
+ tNormal: regl.prop('tNormal'),
236
+ tSrc: regl.prop('tSrc'),
237
+ softIterations: regl.prop('softIterations'),
238
+ pixelScale: regl.prop('pixelScale'),
239
+ resolution: regl.prop('resolution'),
240
+ sunDirection: regl.prop('sunDirection')
241
+ },
242
+ attributes: {
243
+ position: [[-1, 1], [1, 1], [-1, -1], [1, -1]],
244
+ texCoord: [[1 / 3, 2 / 3], [2 / 3, 2 / 3], [1 / 3, 1 / 3], [2 / 3, 1 / 3]]
245
+ },
246
+ framebuffer: regl.prop('fbo')
247
+ })
248
+ }
249
+
250
+ /**
251
+ * The resulting Regl DrawCommand is used to calculate ambient lighting.
252
+ */
253
+ export function createHsAdvAmbientShadows (
254
+ regl,
255
+ commonConfig
256
+ ) {
257
+ return regl({
258
+ ...commonConfig,
259
+ vert: vertSingleNotTransformed,
260
+ frag: fragHsAdvAmbientShadows,
261
+ uniforms: {
262
+ ...commonConfig.uniforms,
263
+ tInput: regl.prop('tInput'),
264
+ tNormal: regl.prop('tNormal'),
265
+ tSrc: regl.prop('tSrc'),
266
+ ambientIterations: regl.prop('ambientIterations'),
267
+ pixelScale: regl.prop('pixelScale'),
268
+ resolution: regl.prop('resolution'),
269
+ direction: regl.prop('direction')
270
+ },
271
+ attributes: {
272
+ position: [[-1, 1], [1, 1], [-1, -1], [1, -1]],
273
+ texCoord: [[1 / 3, 2 / 3], [2 / 3, 2 / 3], [1 / 3, 1 / 3], [2 / 3, 1 / 3]]
274
+ },
275
+ framebuffer: regl.prop('fbo')
276
+ })
277
+ }
278
+
279
+ /**
280
+ * The resulting Regl DrawCommand is used to combine soft and ambient shading,
281
+ * use the colormap on the input floats and apply the hillshading.
282
+ */
283
+ export function createHsAdvFinalColorscale (
284
+ regl,
285
+ commonConfig
286
+ ) {
287
+ return regl({
288
+ ...commonConfig,
289
+ vert: vertDouble,
290
+ frag: fragHsAdvFinalColorscale,
291
+ uniforms: {
292
+ ...commonConfig.uniforms,
293
+ scaleLength: regl.prop('scaleLength'),
294
+ sentinelLength: regl.prop('sentinelLength'),
295
+ scaleColormap: regl.prop('scaleColormap'),
296
+ sentinelColormap: regl.prop('sentinelColormap'),
297
+ tInput: regl.prop('tInput'),
298
+ tSoftShadow: regl.prop('tSoftShadow'),
299
+ tAmbient: regl.prop('tAmbient'),
300
+ floatScale: regl.prop('floatScale'),
301
+ finalSoftMultiplier: regl.prop('finalSoftMultiplier'),
302
+ finalAmbientMultiplier: regl.prop('finalAmbientMultiplier'),
303
+ aboveColor: regl.prop('aboveColor'),
304
+ belowColor: regl.prop('belowColor')
305
+ },
306
+ attributes: {
307
+ ...commonConfig.attributes,
308
+ texCoordA: [[1 / 3, 2 / 3], [2 / 3, 2 / 3], [1 / 3, 1 / 3], [2 / 3, 1 / 3]],
309
+ texCoordB: [[0, 1], [1, 1], [0, 0], [1, 0]]
310
+ }
311
+ })
312
+ }
313
+
314
+ /**
315
+ * The resulting Regl DrawCommand is used to combine soft and ambient shading,
316
+ * use the baselayer tile and apply the hillshading.
317
+ */
318
+ export function createHsAdvFinalBaselayer (
319
+ regl,
320
+ commonConfig
321
+ ) {
322
+ return regl({
323
+ ...commonConfig,
324
+ vert: vertDouble,
325
+ frag: fragHsAdvFinalBaselayer,
326
+ uniforms: {
327
+ ...commonConfig.uniforms,
328
+ tBase: regl.prop('tBase'),
329
+ tSoftShadow: regl.prop('tSoftShadow'),
330
+ tAmbient: regl.prop('tAmbient'),
331
+ finalSoftMultiplier: regl.prop('finalSoftMultiplier'),
332
+ finalAmbientMultiplier: regl.prop('finalAmbientMultiplier')
333
+ },
334
+ attributes: {
335
+ ...commonConfig.attributes,
336
+ texCoordA: regl.prop('baseTexCoords'),
337
+ texCoordB: [[0, 1], [1, 1], [0, 0], [1, 0]]
338
+ }
339
+ })
340
+ }