@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,210 +1,210 @@
1
- import REGL from 'regl'
2
- import {
3
- CLEAR_COLOR,
4
- MAX_TEXTURE_DIMENSION,
5
- EARTH_SUN_DISTANCE,
6
- SUN_RADIUS
7
- } from './constants'
8
-
9
- import TextureManager from './texture_manager'
10
- import * as util from './util'
11
- import { vec3 } from 'gl-matrix'
12
- import * as reglCommands from './reglCommands'
13
-
14
-
15
- export default class Renderer {
16
- constructor (gloperations, tileSize, nodataValue, scaleInput, sentinelInput, colorscaleMaxLength, sentinelMaxLength, aboveColor, belowColor) {
17
- const canvas = document.createElement('canvas')
18
- let maxTextureDimension = MAX_TEXTURE_DIMENSION
19
- let normalTextureDimension = 1024
20
-
21
- const regl = REGL({
22
- canvas: canvas,
23
- // profile: true,
24
- // extension only used for advanced hillshading
25
- // TODO: add fallback to rgba if writing to float fails
26
- optionalExtensions: ['OES_texture_float', 'WEBGL_color_buffer_float'],
27
- onDone: function (err, regl) {
28
- if (err) {
29
- console.error(err)
30
- return
31
- } else {
32
- // cannot use this directly as it seems to cause some issues
33
- // maxTextureDimension = regl.limits.maxTextureSize;
34
- if (regl.limits.maxTextureSize > 2048) {
35
- maxTextureDimension = 2048
36
- }
37
- if (regl.limits.maxTextureSize > 4096) {
38
- maxTextureDimension = 4096
39
- }
40
- if (regl.limits.maxTextureSize > 8192) {
41
- maxTextureDimension = 8192
42
- }
43
-
44
- // TODO: use lower normal dimension where relevant
45
- // Currently set to same due to a bug
46
- normalTextureDimension = maxTextureDimension
47
- }
48
- // TODO: Improve software rendering detection
49
- if (regl.limits.maxFragmentUniforms === 261) {
50
- console.warn('Software rendering detected. Many features of this plugin will fail.\
51
- If you have a GPU, check if drivers are installed ok?')
52
- }
53
- }
54
- })
55
-
56
- const commonDrawConfig = reglCommands.getCommonDrawConfiguration(tileSize, nodataValue)
57
- const fragMacros = {
58
- SCALE_MAX_LENGTH: colorscaleMaxLength,
59
- SENTINEL_MAX_LENGTH: sentinelMaxLength
60
- }
61
-
62
- // Assign object "instance" properties.
63
- Object.assign(this, {
64
- gloperations: gloperations,
65
- canvas: canvas,
66
- regl: regl,
67
- tileSize: tileSize,
68
- nodataValue: nodataValue,
69
- maxTextureDimension: maxTextureDimension,
70
- normalTextureDimension: normalTextureDimension,
71
- scaleInput: scaleInput,
72
- sentinelInput: sentinelInput,
73
- scaleColormap: util.createColormapTexture(scaleInput, regl),
74
- sentinelColormap: util.createColormapTexture(sentinelInput, regl),
75
- textureManager: new TextureManager(regl, tileSize, normalTextureDimension, false),
76
- drawTile: reglCommands.createDrawTileCommand(regl, commonDrawConfig, fragMacros),
77
- aboveColor: util.colorStringToInts(aboveColor || '#00000000').map(i => i / 255.0),
78
- belowColor: util.colorStringToInts(belowColor || '#00000000').map(i => i / 255.0)
79
- })
80
- }
81
-
82
- destroy () {
83
- if (this.regl) this.regl.destroy()
84
- this.regl = null
85
- }
86
-
87
- renderTile ({ coords, pixelData }, _hillshadeOptions, zoom) {
88
- const {
89
- regl,
90
- textureManager,
91
- tileSize
92
- } = this
93
- this.setCanvasSize(tileSize, tileSize)
94
- // Add image to the texture and retrieve its texture coordinates.
95
- const textureBounds = textureManager.addTile(coords, pixelData)
96
-
97
- regl.clear({ color: CLEAR_COLOR })
98
-
99
- const zoomdelta = _hillshadeOptions.hsSimpleZoomdelta || 0
100
-
101
- const offset_pixels = Math.max(0.5, 2 ** (zoom + zoomdelta) / 2048)
102
- const offset_texcoords = offset_pixels / textureManager.texture.width
103
-
104
- if (_hillshadeOptions.hillshadeType === 'none') {
105
- this.drawTile({
106
- canvasSize: [tileSize, tileSize],
107
- canvasCoordinates: [0, 0],
108
- textureBounds,
109
- texture: textureManager.texture,
110
- scaleLength: this.scaleInput.length,
111
- sentinelLength: this.sentinelInput.length,
112
- scaleColormap: this.scaleColormap,
113
- sentinelColormap: this.sentinelColormap,
114
- enableSimpleHillshade: false,
115
- aboveColor: this.aboveColor,
116
- belowColor: this.belowColor
117
- })
118
- } else if (_hillshadeOptions.hillshadeType === 'simple') {
119
- this.drawTileHsSimple({
120
- scaleLength: this.scaleInput.length,
121
- sentinelLength: this.sentinelInput.length,
122
- scaleColormap: this.scaleColormap,
123
- sentinelColormap: this.sentinelColormap,
124
- canvasSize: [tileSize, tileSize],
125
- canvasCoordinates: [0, 0],
126
- textureBounds: textureBounds,
127
- texture: textureManager.texture,
128
- textureSize: textureManager.texture.width,
129
- tileSize: tileSize,
130
- offset: offset_texcoords,
131
- enableSimpleHillshade: true,
132
- // elevationScale: _hillshadeOptions.hsElevationScale,
133
- azimuth: _hillshadeOptions.hsSimpleAzimuth,
134
- altitude: _hillshadeOptions.hsSimpleAltitude,
135
- slopescale: _hillshadeOptions.hsSimpleSlopescale,
136
- aboveColor: this.aboveColor,
137
- belowColor: this.belowColor
138
- })
139
- }
140
-
141
- // Since the tile will fill the whole canvas, the offset is simply [0, 0].
142
- return [0, 0]
143
- }
144
-
145
- setCanvasSize (width, height) {
146
- Object.assign(this.canvas, { width, height })
147
- }
148
-
149
- generateAmbientDirections (iterations) {
150
- const ambientDirections = []
151
- for (let i = 0; i < iterations; i++) {
152
- const direction = vec3.random(vec3.create(), Math.random())
153
- ambientDirections.push(direction)
154
- }
155
- this.ambientDirections = ambientDirections
156
- }
157
-
158
- generateSunDirections (iterations, sunRadiusMultiplier) {
159
- const sunDirections = []
160
- for (let i = 0; i < iterations; i++) {
161
- const direction = vec3.normalize(
162
- vec3.create(),
163
- vec3.add(
164
- vec3.create(),
165
- vec3.scale(
166
- vec3.create(),
167
- vec3.normalize(vec3.create(), [1, 1, 1]),
168
- EARTH_SUN_DISTANCE
169
- ),
170
- vec3.random(vec3.create(), SUN_RADIUS * sunRadiusMultiplier)
171
- )
172
- )
173
- sunDirections.push(direction)
174
- }
175
- this.sunDirections = sunDirections
176
- }
177
-
178
- updateColorscale (scaleInput) {
179
- this.scaleInputPrevious = this.scaleInput
180
- this.scaleInput = scaleInput
181
- this.scaleColormapPrevious = this.scaleColormap
182
- this.scaleColormap = util.createColormapTexture(scaleInput, this.regl)
183
- }
184
- updateOuteRangeColor (aboveColor, belowColor) {
185
- this.aboveColorPrevious = this.aboveColor
186
- this.aboveColor = util.colorStringToInts(aboveColor || '#00000000').map(i => i / 255.0)
187
- this.belowColorPrevious = this.belowColor
188
- this.belowColor = util.colorStringToInts(belowColor || '#00000000').map(i => i / 255.0)
189
- }
190
- updateSentinels (sentinelInput) {
191
- this.sentinelInputPrevious = this.sentinelInput
192
- this.sentinelInput = sentinelInput
193
- this.sentinelColormapPrevious = this.sentinelColormap
194
- this.sentinelColormap = util.createColormapTexture(sentinelInput, this.regl)
195
- }
196
- setMaxTextureDimension (newMaxTextureDimension) {
197
- const {
198
- textureManager,
199
- tileSize,
200
- regl
201
- } = this
202
-
203
- textureManager.destroy()
204
-
205
- Object.assign(this, {
206
- maxTextureDimension: newMaxTextureDimension,
207
- textureManager: new TextureManager(regl, tileSize, newMaxTextureDimension, false)
208
- })
209
- }
1
+ import REGL from 'regl'
2
+ import {
3
+ CLEAR_COLOR,
4
+ MAX_TEXTURE_DIMENSION,
5
+ EARTH_SUN_DISTANCE,
6
+ SUN_RADIUS
7
+ } from './constants'
8
+
9
+ import TextureManager from './texture_manager'
10
+ import * as util from './util'
11
+ import { vec3 } from 'gl-matrix'
12
+ import * as reglCommands from './reglCommands'
13
+
14
+
15
+ export default class Renderer {
16
+ constructor (gloperations, tileSize, nodataValue, scaleInput, sentinelInput, colorscaleMaxLength, sentinelMaxLength, aboveColor, belowColor) {
17
+ const canvas = document.createElement('canvas')
18
+ let maxTextureDimension = MAX_TEXTURE_DIMENSION
19
+ let normalTextureDimension = 1024
20
+
21
+ const regl = REGL({
22
+ canvas: canvas,
23
+ // profile: true,
24
+ // extension only used for advanced hillshading
25
+ // TODO: add fallback to rgba if writing to float fails
26
+ optionalExtensions: ['OES_texture_float', 'WEBGL_color_buffer_float'],
27
+ onDone: function (err, regl) {
28
+ if (err) {
29
+ console.error(err)
30
+ return
31
+ } else {
32
+ // cannot use this directly as it seems to cause some issues
33
+ // maxTextureDimension = regl.limits.maxTextureSize;
34
+ if (regl.limits.maxTextureSize > 2048) {
35
+ maxTextureDimension = 2048
36
+ }
37
+ if (regl.limits.maxTextureSize > 4096) {
38
+ maxTextureDimension = 4096
39
+ }
40
+ if (regl.limits.maxTextureSize > 8192) {
41
+ maxTextureDimension = 8192
42
+ }
43
+
44
+ // TODO: use lower normal dimension where relevant
45
+ // Currently set to same due to a bug
46
+ normalTextureDimension = maxTextureDimension
47
+ }
48
+ // TODO: Improve software rendering detection
49
+ if (regl.limits.maxFragmentUniforms === 261) {
50
+ console.warn('Software rendering detected. Many features of this plugin will fail.\
51
+ If you have a GPU, check if drivers are installed ok?')
52
+ }
53
+ }
54
+ })
55
+
56
+ const commonDrawConfig = reglCommands.getCommonDrawConfiguration(tileSize, nodataValue)
57
+ const fragMacros = {
58
+ SCALE_MAX_LENGTH: colorscaleMaxLength,
59
+ SENTINEL_MAX_LENGTH: sentinelMaxLength
60
+ }
61
+
62
+ // Assign object "instance" properties.
63
+ Object.assign(this, {
64
+ gloperations: gloperations,
65
+ canvas: canvas,
66
+ regl: regl,
67
+ tileSize: tileSize,
68
+ nodataValue: nodataValue,
69
+ maxTextureDimension: maxTextureDimension,
70
+ normalTextureDimension: normalTextureDimension,
71
+ scaleInput: scaleInput,
72
+ sentinelInput: sentinelInput,
73
+ scaleColormap: util.createColormapTexture(scaleInput, regl),
74
+ sentinelColormap: util.createColormapTexture(sentinelInput, regl),
75
+ textureManager: new TextureManager(regl, tileSize, normalTextureDimension, false),
76
+ drawTile: reglCommands.createDrawTileCommand(regl, commonDrawConfig, fragMacros),
77
+ aboveColor: util.colorStringToInts(aboveColor || '#00000000').map(i => i / 255.0),
78
+ belowColor: util.colorStringToInts(belowColor || '#00000000').map(i => i / 255.0)
79
+ })
80
+ }
81
+
82
+ destroy () {
83
+ if (this.regl) this.regl.destroy()
84
+ this.regl = null
85
+ }
86
+
87
+ renderTile ({ coords, pixelData }, _hillshadeOptions, zoom) {
88
+ const {
89
+ regl,
90
+ textureManager,
91
+ tileSize
92
+ } = this
93
+ this.setCanvasSize(tileSize, tileSize)
94
+ // Add image to the texture and retrieve its texture coordinates.
95
+ const textureBounds = textureManager.addTile(coords, pixelData)
96
+
97
+ regl.clear({ color: CLEAR_COLOR })
98
+
99
+ const zoomdelta = _hillshadeOptions.hsSimpleZoomdelta || 0
100
+
101
+ const offset_pixels = Math.max(0.5, 2 ** (zoom + zoomdelta) / 2048)
102
+ const offset_texcoords = offset_pixels / textureManager.texture.width
103
+
104
+ if (_hillshadeOptions.hillshadeType === 'none') {
105
+ this.drawTile({
106
+ canvasSize: [tileSize, tileSize],
107
+ canvasCoordinates: [0, 0],
108
+ textureBounds,
109
+ texture: textureManager.texture,
110
+ scaleLength: this.scaleInput.length,
111
+ sentinelLength: this.sentinelInput.length,
112
+ scaleColormap: this.scaleColormap,
113
+ sentinelColormap: this.sentinelColormap,
114
+ enableSimpleHillshade: false,
115
+ aboveColor: this.aboveColor,
116
+ belowColor: this.belowColor
117
+ })
118
+ } else if (_hillshadeOptions.hillshadeType === 'simple') {
119
+ this.drawTileHsSimple({
120
+ scaleLength: this.scaleInput.length,
121
+ sentinelLength: this.sentinelInput.length,
122
+ scaleColormap: this.scaleColormap,
123
+ sentinelColormap: this.sentinelColormap,
124
+ canvasSize: [tileSize, tileSize],
125
+ canvasCoordinates: [0, 0],
126
+ textureBounds: textureBounds,
127
+ texture: textureManager.texture,
128
+ textureSize: textureManager.texture.width,
129
+ tileSize: tileSize,
130
+ offset: offset_texcoords,
131
+ enableSimpleHillshade: true,
132
+ // elevationScale: _hillshadeOptions.hsElevationScale,
133
+ azimuth: _hillshadeOptions.hsSimpleAzimuth,
134
+ altitude: _hillshadeOptions.hsSimpleAltitude,
135
+ slopescale: _hillshadeOptions.hsSimpleSlopescale,
136
+ aboveColor: this.aboveColor,
137
+ belowColor: this.belowColor
138
+ })
139
+ }
140
+
141
+ // Since the tile will fill the whole canvas, the offset is simply [0, 0].
142
+ return [0, 0]
143
+ }
144
+
145
+ setCanvasSize (width, height) {
146
+ Object.assign(this.canvas, { width, height })
147
+ }
148
+
149
+ generateAmbientDirections (iterations) {
150
+ const ambientDirections = []
151
+ for (let i = 0; i < iterations; i++) {
152
+ const direction = vec3.random(vec3.create(), Math.random())
153
+ ambientDirections.push(direction)
154
+ }
155
+ this.ambientDirections = ambientDirections
156
+ }
157
+
158
+ generateSunDirections (iterations, sunRadiusMultiplier) {
159
+ const sunDirections = []
160
+ for (let i = 0; i < iterations; i++) {
161
+ const direction = vec3.normalize(
162
+ vec3.create(),
163
+ vec3.add(
164
+ vec3.create(),
165
+ vec3.scale(
166
+ vec3.create(),
167
+ vec3.normalize(vec3.create(), [1, 1, 1]),
168
+ EARTH_SUN_DISTANCE
169
+ ),
170
+ vec3.random(vec3.create(), SUN_RADIUS * sunRadiusMultiplier)
171
+ )
172
+ )
173
+ sunDirections.push(direction)
174
+ }
175
+ this.sunDirections = sunDirections
176
+ }
177
+
178
+ updateColorscale (scaleInput) {
179
+ this.scaleInputPrevious = this.scaleInput
180
+ this.scaleInput = scaleInput
181
+ this.scaleColormapPrevious = this.scaleColormap
182
+ this.scaleColormap = util.createColormapTexture(scaleInput, this.regl)
183
+ }
184
+ updateOuteRangeColor (aboveColor, belowColor) {
185
+ this.aboveColorPrevious = this.aboveColor
186
+ this.aboveColor = util.colorStringToInts(aboveColor || '#00000000').map(i => i / 255.0)
187
+ this.belowColorPrevious = this.belowColor
188
+ this.belowColor = util.colorStringToInts(belowColor || '#00000000').map(i => i / 255.0)
189
+ }
190
+ updateSentinels (sentinelInput) {
191
+ this.sentinelInputPrevious = this.sentinelInput
192
+ this.sentinelInput = sentinelInput
193
+ this.sentinelColormapPrevious = this.sentinelColormap
194
+ this.sentinelColormap = util.createColormapTexture(sentinelInput, this.regl)
195
+ }
196
+ setMaxTextureDimension (newMaxTextureDimension) {
197
+ const {
198
+ textureManager,
199
+ tileSize,
200
+ regl
201
+ } = this
202
+
203
+ textureManager.destroy()
204
+
205
+ Object.assign(this, {
206
+ maxTextureDimension: newMaxTextureDimension,
207
+ textureManager: new TextureManager(regl, tileSize, newMaxTextureDimension, false)
208
+ })
209
+ }
210
210
  }
@@ -1,26 +1,26 @@
1
- import glsl from 'glslify'
2
-
3
- export default glsl`#ifdef GL_FRAGMENT_PRECISION_HIGH
4
- precision highp float;
5
- #else
6
- precision mediump float;
7
- #endif
8
-
9
- #pragma glslify: floatToRgba = require(glsl-float-to-rgba)
10
-
11
- uniform float nodataValue;
12
- uniform bool littleEndian;
13
- uniform sampler2D texture;
14
- varying vec2 vTexCoord;
15
-
16
- void main() {
17
- //sample the texture
18
- vec3 rgb = texture2D(texture, vTexCoord).rgb;
19
-
20
- // Convert the red, green, and blue channels into a float
21
- float f = -10000.0 + ((rgb.r * 255.0 * 256.0 * 256.0 + rgb.g * 255.0 * 256.0 + rgb.b * 255.0) * 0.1);
22
-
23
- // convert to rgba and write to framebuffer
24
- gl_FragColor = floatToRgba(f, littleEndian);
25
- }
1
+ import glsl from 'glslify'
2
+
3
+ export default glsl`#ifdef GL_FRAGMENT_PRECISION_HIGH
4
+ precision highp float;
5
+ #else
6
+ precision mediump float;
7
+ #endif
8
+
9
+ #pragma glslify: floatToRgba = require(glsl-float-to-rgba)
10
+
11
+ uniform float nodataValue;
12
+ uniform bool littleEndian;
13
+ uniform sampler2D texture;
14
+ varying vec2 vTexCoord;
15
+
16
+ void main() {
17
+ //sample the texture
18
+ vec3 rgb = texture2D(texture, vTexCoord).rgb;
19
+
20
+ // Convert the red, green, and blue channels into a float
21
+ float f = -10000.0 + ((rgb.r * 255.0 * 256.0 * 256.0 + rgb.g * 255.0 * 256.0 + rgb.b * 255.0) * 0.1);
22
+
23
+ // convert to rgba and write to framebuffer
24
+ gl_FragColor = floatToRgba(f, littleEndian);
25
+ }
26
26
  `
@@ -1,55 +1,55 @@
1
- import glsl from 'glslify'
2
-
3
- export default glsl`#ifdef GL_FRAGMENT_PRECISION_HIGH
4
- precision highp float;
5
- #else
6
- precision mediump float;
7
- #endif
8
-
9
- #pragma glslify: rgbaToFloat = require(glsl-rgba-to-float)
10
- #pragma glslify: floatToRgba = require(glsl-float-to-rgba)
11
- #pragma glslify: isCloseEnough = require(../util/isCloseEnough.glsl)
12
- #pragma glslify: getTexelValue = require(../util/getTexelValue.glsl)
13
-
14
- uniform sampler2D texture;
15
- uniform float textureSize;
16
- uniform bool littleEndian;
17
- uniform float nodataValue;
18
- varying vec2 vTexCoord;
19
- uniform int kernelSize;
20
-
21
- int kernelEnd = int(kernelSize/2);
22
- int kernelStart = kernelEnd * -1;
23
-
24
- float runConvKernel(vec2 pos, vec2 onePixel) {
25
- float convKernelWeight = 0.0;
26
- float sum = 0.0;
27
-
28
- for (int i = -20; i < 20; i ++) {
29
- if (i < kernelStart) continue;
30
- if (i > kernelEnd) break;
31
- for (int j = -20; j < 20; j ++) {
32
- if (j < kernelStart) continue;
33
- if (j > kernelEnd) break;
34
- float texelValue = getTexelValue(texture, pos + onePixel * vec2(i, j), littleEndian);
35
- if (!isCloseEnough(texelValue, nodataValue)) {
36
- sum = sum + texelValue;
37
- convKernelWeight = convKernelWeight + 1.0;
38
- }
39
- }
40
- }
41
- return (sum / convKernelWeight);
42
- }
43
-
44
-
45
- void main() {
46
- float texelFloat = getTexelValue(texture, vTexCoord, littleEndian);
47
- if (isCloseEnough(texelFloat, nodataValue)) {
48
- gl_FragColor = floatToRgba(nodataValue, littleEndian);
49
- } else {
50
- vec2 onePixel = vec2(1.0, 1.0) / textureSize;
51
- float texelFloatSmoothed = runConvKernel(vTexCoord, onePixel);
52
- gl_FragColor = floatToRgba(texelFloatSmoothed, littleEndian);
53
- }
54
- }
1
+ import glsl from 'glslify'
2
+
3
+ export default glsl`#ifdef GL_FRAGMENT_PRECISION_HIGH
4
+ precision highp float;
5
+ #else
6
+ precision mediump float;
7
+ #endif
8
+
9
+ #pragma glslify: rgbaToFloat = require(glsl-rgba-to-float)
10
+ #pragma glslify: floatToRgba = require(glsl-float-to-rgba)
11
+ #pragma glslify: isCloseEnough = require(../util/isCloseEnough.glsl)
12
+ #pragma glslify: getTexelValue = require(../util/getTexelValue.glsl)
13
+
14
+ uniform sampler2D texture;
15
+ uniform float textureSize;
16
+ uniform bool littleEndian;
17
+ uniform float nodataValue;
18
+ varying vec2 vTexCoord;
19
+ uniform int kernelSize;
20
+
21
+ int kernelEnd = int(kernelSize/2);
22
+ int kernelStart = kernelEnd * -1;
23
+
24
+ float runConvKernel(vec2 pos, vec2 onePixel) {
25
+ float convKernelWeight = 0.0;
26
+ float sum = 0.0;
27
+
28
+ for (int i = -20; i < 20; i ++) {
29
+ if (i < kernelStart) continue;
30
+ if (i > kernelEnd) break;
31
+ for (int j = -20; j < 20; j ++) {
32
+ if (j < kernelStart) continue;
33
+ if (j > kernelEnd) break;
34
+ float texelValue = getTexelValue(texture, pos + onePixel * vec2(i, j), littleEndian);
35
+ if (!isCloseEnough(texelValue, nodataValue)) {
36
+ sum = sum + texelValue;
37
+ convKernelWeight = convKernelWeight + 1.0;
38
+ }
39
+ }
40
+ }
41
+ return (sum / convKernelWeight);
42
+ }
43
+
44
+
45
+ void main() {
46
+ float texelFloat = getTexelValue(texture, vTexCoord, littleEndian);
47
+ if (isCloseEnough(texelFloat, nodataValue)) {
48
+ gl_FragColor = floatToRgba(nodataValue, littleEndian);
49
+ } else {
50
+ vec2 onePixel = vec2(1.0, 1.0) / textureSize;
51
+ float texelFloatSmoothed = runConvKernel(vTexCoord, onePixel);
52
+ gl_FragColor = floatToRgba(texelFloatSmoothed, littleEndian);
53
+ }
54
+ }
55
55
  `
@@ -1,34 +1,34 @@
1
- import glsl from 'glslify'
2
-
3
- export default glsl`#ifdef GL_FRAGMENT_PRECISION_HIGH
4
- precision highp float;
5
- #else
6
- precision mediump float;
7
- #endif
8
-
9
- #pragma glslify: floatToRgba = require(glsl-float-to-rgba)
10
- #pragma glslify: isCloseEnough = require(../util/isCloseEnough.glsl)
11
- #pragma glslify: getTexelValue = require(../util/getTexelValue.glsl)
12
-
13
- uniform float nodataValue;
14
- uniform bool littleEndian;
15
- uniform sampler2D textureA;
16
- uniform sampler2D textureB;
17
-
18
- varying vec2 vTexCoordA;
19
- varying vec2 vTexCoordB;
20
-
21
- void main() {
22
- float texelFloatA = getTexelValue(textureA, vTexCoordA, littleEndian);
23
- float texelFloatB = getTexelValue(textureB, vTexCoordB, littleEndian);
24
- bool aIsNodata = isCloseEnough(texelFloatA, nodataValue);
25
- bool bIsNodata = isCloseEnough(texelFloatB, nodataValue);
26
-
27
- if (aIsNodata || bIsNodata) {
28
- gl_FragColor = floatToRgba(nodataValue, littleEndian);
29
- } else {
30
- float diff = texelFloatB - texelFloatA;
31
- gl_FragColor = floatToRgba(diff, littleEndian);
32
- }
33
- }
1
+ import glsl from 'glslify'
2
+
3
+ export default glsl`#ifdef GL_FRAGMENT_PRECISION_HIGH
4
+ precision highp float;
5
+ #else
6
+ precision mediump float;
7
+ #endif
8
+
9
+ #pragma glslify: floatToRgba = require(glsl-float-to-rgba)
10
+ #pragma glslify: isCloseEnough = require(../util/isCloseEnough.glsl)
11
+ #pragma glslify: getTexelValue = require(../util/getTexelValue.glsl)
12
+
13
+ uniform float nodataValue;
14
+ uniform bool littleEndian;
15
+ uniform sampler2D textureA;
16
+ uniform sampler2D textureB;
17
+
18
+ varying vec2 vTexCoordA;
19
+ varying vec2 vTexCoordB;
20
+
21
+ void main() {
22
+ float texelFloatA = getTexelValue(textureA, vTexCoordA, littleEndian);
23
+ float texelFloatB = getTexelValue(textureB, vTexCoordB, littleEndian);
24
+ bool aIsNodata = isCloseEnough(texelFloatA, nodataValue);
25
+ bool bIsNodata = isCloseEnough(texelFloatB, nodataValue);
26
+
27
+ if (aIsNodata || bIsNodata) {
28
+ gl_FragColor = floatToRgba(nodataValue, littleEndian);
29
+ } else {
30
+ float diff = texelFloatB - texelFloatA;
31
+ gl_FragColor = floatToRgba(diff, littleEndian);
32
+ }
33
+ }
34
34
  `