@mapcatch/util 2.0.4 → 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 (68) 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/README.md +44 -0
  6. package/debug/app.js +26 -0
  7. package/debug/index.html +55 -0
  8. package/debug/libs/vue.global.js +16159 -0
  9. package/debug/my_icon.png +0 -0
  10. package/docs/Catolog.md +24 -0
  11. package/docs/Constant.md +92 -0
  12. package/docs/Event.md +90 -0
  13. package/docs/Util.md +345 -0
  14. package/package.json +21 -1
  15. package/src/constants/crs.js +42098 -42098
  16. package/src/constants/default_layers.js +42 -94
  17. package/src/gl-operations/constants.js +9 -9
  18. package/src/gl-operations/default_options.js +97 -97
  19. package/src/gl-operations/index.js +532 -532
  20. package/src/gl-operations/reglCommands/contours.js +27 -27
  21. package/src/gl-operations/reglCommands/default.js +45 -45
  22. package/src/gl-operations/reglCommands/hillshading.js +340 -340
  23. package/src/gl-operations/reglCommands/index.js +6 -6
  24. package/src/gl-operations/reglCommands/multiLayers.js +303 -303
  25. package/src/gl-operations/reglCommands/transitions.js +111 -111
  26. package/src/gl-operations/reglCommands/util.js +71 -71
  27. package/src/gl-operations/renderer.js +209 -209
  28. package/src/gl-operations/shaders/fragment/convertDem.js +25 -25
  29. package/src/gl-operations/shaders/fragment/convolutionSmooth.js +54 -54
  30. package/src/gl-operations/shaders/fragment/diffCalc.js +33 -33
  31. package/src/gl-operations/shaders/fragment/drawResult.js +46 -46
  32. package/src/gl-operations/shaders/fragment/hillshading/hsAdvAmbientShadows.js +78 -78
  33. package/src/gl-operations/shaders/fragment/hillshading/hsAdvDirect.js +59 -59
  34. package/src/gl-operations/shaders/fragment/hillshading/hsAdvFinalBaselayer.js +30 -30
  35. package/src/gl-operations/shaders/fragment/hillshading/hsAdvFinalColorscale.js +60 -60
  36. package/src/gl-operations/shaders/fragment/hillshading/hsAdvMergeAndScaleTiles.js +26 -26
  37. package/src/gl-operations/shaders/fragment/hillshading/hsAdvNormals.js +25 -25
  38. package/src/gl-operations/shaders/fragment/hillshading/hsAdvSmooth.js +53 -53
  39. package/src/gl-operations/shaders/fragment/hillshading/hsAdvSoftShadows.js +80 -80
  40. package/src/gl-operations/shaders/fragment/hillshading/hsPregen.js +54 -54
  41. package/src/gl-operations/shaders/fragment/interpolateColor.js +65 -65
  42. package/src/gl-operations/shaders/fragment/interpolateColorOnly.js +49 -49
  43. package/src/gl-operations/shaders/fragment/interpolateValue.js +136 -136
  44. package/src/gl-operations/shaders/fragment/multiAnalyze1Calc.js +35 -35
  45. package/src/gl-operations/shaders/fragment/multiAnalyze2Calc.js +45 -45
  46. package/src/gl-operations/shaders/fragment/multiAnalyze3Calc.js +53 -53
  47. package/src/gl-operations/shaders/fragment/multiAnalyze4Calc.js +61 -61
  48. package/src/gl-operations/shaders/fragment/multiAnalyze5Calc.js +69 -69
  49. package/src/gl-operations/shaders/fragment/multiAnalyze6Calc.js +77 -77
  50. package/src/gl-operations/shaders/fragment/single.js +93 -93
  51. package/src/gl-operations/shaders/transform.js +21 -21
  52. package/src/gl-operations/shaders/util/computeColor.glsl +85 -85
  53. package/src/gl-operations/shaders/util/getTexelValue.glsl +10 -10
  54. package/src/gl-operations/shaders/util/isCloseEnough.glsl +9 -9
  55. package/src/gl-operations/shaders/util/rgbaToFloat.glsl +17 -17
  56. package/src/gl-operations/shaders/vertex/double.js +16 -16
  57. package/src/gl-operations/shaders/vertex/multi3.js +19 -19
  58. package/src/gl-operations/shaders/vertex/multi4.js +22 -22
  59. package/src/gl-operations/shaders/vertex/multi5.js +25 -25
  60. package/src/gl-operations/shaders/vertex/multi6.js +28 -28
  61. package/src/gl-operations/shaders/vertex/single.js +13 -13
  62. package/src/gl-operations/shaders/vertex/singleNotTransformed.js +11 -11
  63. package/src/gl-operations/texture_manager.js +141 -141
  64. package/src/gl-operations/util.js +336 -336
  65. package/src/util.js +14 -6
  66. package/vite.config.js +58 -0
  67. package/dist/catchUtil.min.esm.js +0 -113044
  68. package/dist/catchUtil.min.js +0 -2928
@@ -1,340 +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
- 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
- }
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
+ }