@pirireis/webglobeplugins 0.8.5 → 0.8.7

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 (61) hide show
  1. package/bearing-line/plugin.js +51 -43
  2. package/circle-line-chain/plugin.js +52 -44
  3. package/compass-rose/compass-rose-padding-flat.js +3 -0
  4. package/compassrose/compassrose.js +1 -8
  5. package/heatwave/isobar/plugin.js +4 -1
  6. package/heatwave/isobar/quadtreecontours.js +0 -2
  7. package/heatwave/plugins/heatwaveglobeshell.js +2 -0
  8. package/package.json +1 -1
  9. package/partialrings/goals.md +2 -0
  10. package/partialrings/plugin.js +2 -1
  11. package/point-glow-line-to-earth/draw-subset-obj.js +27 -0
  12. package/point-glow-line-to-earth/keymethod.js +0 -0
  13. package/point-glow-line-to-earth/plugin.js +439 -0
  14. package/point-glow-line-to-earth/types.js +26 -0
  15. package/point-heat-map/index.js +0 -3
  16. package/point-heat-map/plugin-webworker.js +4 -9
  17. package/point-heat-map/point-to-heat-map-flow.js +0 -6
  18. package/point-tracks/plugin.js +42 -17
  19. package/programs/arrowfield/logic.js +6 -4
  20. package/programs/arrowfield/object.js +1 -1
  21. package/programs/float2legendwithratio/object.js +5 -4
  22. package/programs/globe-util/is-globe-moved.js +27 -0
  23. package/programs/globeshell/wiggle/logic.js +3 -7
  24. package/programs/globeshell/wiggle/object.js +1 -2
  25. package/programs/line-on-globe/circle-accurate-3d.js +16 -23
  26. package/programs/line-on-globe/circle-accurate-flat.js +21 -21
  27. package/programs/line-on-globe/lines-color-instanced-flat.js +6 -7
  28. package/programs/line-on-globe/naive-accurate-flexible.js +239 -0
  29. package/programs/line-on-globe/to-the-surface.js +129 -0
  30. package/programs/picking/pickable-renderer.js +216 -0
  31. package/programs/point-on-globe/element-globe-surface-glow.js +168 -0
  32. package/programs/point-on-globe/element-point-glow.js +184 -0
  33. package/programs/point-on-globe/square-pixel-point.js +8 -7
  34. package/programs/programcache.js +9 -0
  35. package/programs/rings/partial-ring/piece-of-pie.js +1 -1
  36. package/programs/totems/camerauniformblock.js +23 -2
  37. package/rangerings/plugin.js +9 -6
  38. package/shaders/fragment-toy/firework.js +55 -0
  39. package/shaders/fragment-toy/singularity.js +59 -0
  40. package/types.js +16 -0
  41. package/util/account/single-attribute-buffer-management/buffer-manager.js +2 -6
  42. package/util/account/util.js +17 -7
  43. package/util/check/typecheck.js +11 -0
  44. package/util/gl-util/buffer/integrate-buffer.js +74 -0
  45. package/util/gl-util/draw-options/client.js +59 -0
  46. package/util/gl-util/draw-options/methods.js +46 -0
  47. package/util/gl-util/draw-options/types.js +18 -0
  48. package/util/gl-util/uniform-block/manager.js +176 -0
  49. package/util/gl-util/uniform-block/roadmap.md +70 -0
  50. package/util/gl-util/uniform-block/shader.js +0 -0
  51. package/util/gl-util/uniform-block/types.js +7 -0
  52. package/util/jshelpers/equality.js +17 -0
  53. package/util/picking/picker-displayer.js +1 -1
  54. package/util/programs/shapesonglobe.js +17 -19
  55. package/util/shaderfunctions/geometrytransformations.js +27 -63
  56. package/bearing-line/roadmap.md +0 -15
  57. package/point-heat-map/plugin.js +0 -132
  58. package/programs/line-on-globe/naive-accurate.js +0 -221
  59. package/programs/line-on-globe/to-the-origin.js +0 -164
  60. package/util/jshelpers/timemethods.js +0 -19
  61. /package/{programs/point-on-globe/element-draw-glow.js → point-glow-line-to-earth/adaptors.js} +0 -0
@@ -0,0 +1,129 @@
1
+ import { createProgram } from './util'
2
+
3
+ import { CameraUniformBlockTotemCache, CameraUniformBlockString } from '../totems';
4
+ import { cartesian3DToGLPosition, R_3D } from '../../util/shaderfunctions/geometrytransformations';
5
+ import { noRegisterGlobeProgramCache } from '../programcache';
6
+ import { attributeLoader } from '../../util/gl-util/buffer/integrate-buffer';
7
+ import '../draw-options/types';
8
+ import { drawInstanced } from '../draw-options/methods';
9
+
10
+ const vs = `#version 300 es
11
+ ${R_3D}
12
+ ${CameraUniformBlockString}
13
+ ${cartesian3DToGLPosition}
14
+ in vec3 pos3D
15
+ in vec4 color;
16
+ out float ratio;
17
+ out flat vec4 vColor;
18
+ void main(){
19
+ if ( gl_VertexID == 0) {
20
+ gl_Position = cartesian3DToGLPosition(pos3D);
21
+ ratio =0.0;
22
+ } else {
23
+ vec3 sea_level_pos3D = norm(pos3D) * R_3D;
24
+ gl_Position = cartesian3DToGLPosition(pos3D);
25
+ ratio = 1.0;
26
+ }
27
+ vColor = color;
28
+ }`;
29
+
30
+ const fs = `#version 300 es
31
+ uniform float opacity;
32
+ uniform float phase;
33
+ uniform float fadeOpacity;
34
+ in flat vec4 vColor;
35
+ in float ratio;
36
+ out vec4 fragColor;
37
+ void main(){
38
+ fragColor = vec4( vColor.rgb, vColor.a * opacity);
39
+ if (fadeOpacity < 1.0) {
40
+ float alpha= mix( fadeOpacity, vColor.a, fract( ratio + phase ));
41
+ fragColor.a *= alpha;
42
+ }
43
+ }`;
44
+
45
+
46
+
47
+
48
+ class Logic {
49
+ constructor(globe) {
50
+ this.globe = globe;
51
+ this.gl = globe.gl;
52
+
53
+ this.program = createProgram(this.gl, vs, fs);
54
+ const { gl, program } = this;
55
+
56
+ this._opacity = {
57
+ lastValue: 1.0,
58
+ location: gl.getUniformLocation(program, 'opacity')
59
+ }
60
+ this._phase = {
61
+ lastValue: 1.0,
62
+ location: gl.getUniformLocation(program, 'phase')
63
+ }
64
+ this._fadeOpacity = {
65
+ lastValue: 1.0,
66
+ location: gl.getUniformBlockLocation(program, 'fadeOpacity')
67
+ }
68
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
69
+ gl.useProgram(program);
70
+ [this._opacity, this._phase, this._fadeOpacity].forEach((wrapper) => gl.uniform1f(wrapper.location, wrapper.lastValue))
71
+ gl.useProgram(currentProgram)
72
+ gl.useProgram(program);
73
+ gl.bindAttribLocation(program, 0, 'pos3D');
74
+ gl.bindAttribLocation(program, 1, 'color');
75
+
76
+ this.cameraUniformBlockTotem = new CameraUniformBlockTotemCache.get(globe);
77
+ this.cameraBlockBindingPoint = 0;
78
+ const cameraBlockIndex = gl.getUniformBlockLocation(program, 'CameraUniformBlock');
79
+ gl.uniformBlockBinding(program, cameraBlockIndex, this.cameraBlockBindingPoint)
80
+ }
81
+
82
+ createVao(pos3DObj, colorObj) {
83
+ const { gl } = this;
84
+ const vao = gl.createVertexArray();
85
+ const divisor = 1;
86
+ gl.bindVertexArray(vao);
87
+
88
+ attributeLoader(gl, pos3DObj, 0, 3, { divisor });
89
+ attributeLoader(gl, colorObj, 1, 4, { divisor, escapeValue: [-1, -1, -1, -1] });
90
+
91
+ gl.bindVertexArray(null);
92
+ this._vaoCache.push(vao);
93
+ return vao;
94
+ }
95
+
96
+
97
+ /**
98
+ *
99
+ * @param {WebGL2RenderingContext.vertexArrayObject} vao
100
+ * @param {Render} drawOptions
101
+ */
102
+ draw(vao, drawOptions, { opacity = 1.0, fadeOpacity = 1.0, }) {
103
+
104
+ const { globe, gl, program, _opacity, _fadeOpacity } = this;
105
+ gl.useProgram(program);
106
+ gl.bindVertexArray(vao);
107
+
108
+ if (fadeOpacity < 1.0) {
109
+ this._updatePhase();
110
+ globe.drawRender();
111
+ }
112
+ if (fadeOpacity !== _fadeOpacity.lastValue) {
113
+ _fadeOpacity.lastValue = fadeOpacity;
114
+ gl.uniform1f(_fadeOpacity.location, fadeOpacity);
115
+ }
116
+ if (opacity !== _opacity.lastValue) {
117
+ _opacity.lastValue = opacity;
118
+ gl.uniform1f(_opacity.location, opacity);
119
+ }
120
+ drawInstanced(gl, gl.TRIANGLE_FAN, drawOptions)
121
+ }
122
+
123
+
124
+ _updatePhase() {
125
+ this._phase.lastValue = (Date.now() / 3.0) % 1000;
126
+ gl.uniform1f(_phase.location, _phase.lastValue);
127
+ }
128
+ }
129
+
@@ -0,0 +1,216 @@
1
+ import { createProgram } from "../../util";
2
+ import { CameraUniformBlockTotemCache, CameraUniformBlockString } from "../totems";
3
+ import { mercatorXYToGLPosition, cartesian3DToGLPosition, R_3D, R } from "../../util/shaderfunctions/geometrytransformations";
4
+ import { noRegisterGlobeProgramCache } from "../programcache";
5
+ import "../../util/gl-util/draw-options/types";
6
+ import { drawArrays } from "../../util/gl-util/draw-options/methods";
7
+ import { attributeLoader } from "../../util/gl-util/buffer/integrate-buffer";
8
+ import { UniformBlockManager } from "../../util/gl-util/uniform-block/manager";
9
+
10
+
11
+ const uniformBindingPoints = {
12
+ camera: 0,
13
+ flexible: 1
14
+ };
15
+
16
+ const uniformBlockManager = new UniformBlockManager(
17
+ "FlexibleBlock",
18
+ [
19
+ { name: "u_rgba", type: "vec4", value: new Float32Array([1, 1, 1, 1]) },
20
+ { name: "u_opacity", type: "float", value: new Float32Array([1.0]) },
21
+ { name: "u_size_multiplier", type: "float", value: new Float32Array([1.0]) },
22
+ { name: "u_size", type: "float", value: new Float32Array([1.0]) },
23
+ { name: "u_minimum_size", type: "float", value: new Float32Array([1.0]) },
24
+ { name: "u_draw_mode", type: "int", value: new Int32Array([0]) }, // 0.0 for point, 1.0 for line
25
+ { name: "u_is_circle", type: "bool", value: new Float32Array([1.0]) },
26
+ { name: "u_dash_count", type: "float", value: new Float32Array([1.0]) },
27
+ { name: "u_dash_opacity_multiplier", type: "float", value: new Float32Array([1.0]) },
28
+ { name: "u_dash_phase", type: "float", value: new Float32Array([0.0]) },
29
+ ], uniformBindingPoints.flexible);
30
+
31
+
32
+ const vs = `#version 300 es
33
+ ${R}
34
+ ${R_3D}
35
+ ${CameraUniformBlockString}
36
+ ${mercatorXYToGLPosition}
37
+ ${cartesian3DToGLPosition}
38
+
39
+ ${uniformBlockManager.glslCode()}
40
+
41
+ precision highp float;
42
+ precision highp int;
43
+
44
+ in vec3 pos3D;
45
+ in vec2 pos2D;
46
+ in vec4 rgba;
47
+ in float size;
48
+
49
+
50
+ flat out highp int vVertexID;
51
+
52
+ out vec4 v_rgba;
53
+
54
+ out float v_length;
55
+
56
+ void main() {
57
+
58
+ v_rgba = (rgba.r == -1.0) ? u_rgba : rgba;
59
+ v_rgba.a *= u_opacity;
60
+ gl_PointSize = max(((size == -1.0) ? u_size : size) * u_size_multiplier, u_minimum_size);
61
+
62
+ float size_fixer;
63
+ if(is3D){
64
+ gl_Position = cartesian3DToGLPosition(pos3D);
65
+ size_fixer = smoothstep(0.15, 1.0, 0.5 * R_3D / gl_Position.w) ;
66
+ } else {
67
+ gl_Position = mercatorXYToGLPosition(pos2D);
68
+ size_fixer = smoothstep(2.0, 5.2, z_level);
69
+ }
70
+ gl_PointSize *= size_fixer;
71
+ switch (u_draw_mode) {
72
+ case 0:
73
+ vVertexID = gl_VertexID;
74
+ break;
75
+ case 1:
76
+ v_length = float(gl_VertexID % 2);
77
+ vVertexID = (gl_VertexID - gl_VertexID % 2) / 2; // a line takes two points
78
+ break;
79
+ default:
80
+ break;
81
+ }
82
+ }`;
83
+
84
+ const fs = `#version 300 es
85
+ precision highp float;
86
+ precision highp int;
87
+
88
+ ${uniformBlockManager.glslCode()}
89
+
90
+ flat in highp int vVertexID;
91
+
92
+ in vec4 v_rgba;
93
+ in float v_length;
94
+
95
+ layout(location = 0) out vec4 fragColor;
96
+ layout(location = 1) out int vertexID;
97
+
98
+ void main() {
99
+ vertexID = vVertexID;
100
+ fragColor = v_rgba;
101
+
102
+ switch (u_draw_mode) {
103
+ case 0:
104
+ float d = distance(gl_PointCoord, vec2(0.5, 0.5));
105
+ if (u_is_circle) {
106
+ if (d > 0.5) discard;
107
+ fragColor.a *= smoothstep(0.5, 0.45, d);
108
+ }
109
+ if (u_dash_opacity_multiplier < 1.0) {
110
+ float dash = sin(d * 3.14159 * 2.0 * u_dash_count + u_dash_phase) * (1.0 - u_dash_opacity_multiplier) + u_dash_opacity_multiplier;
111
+ fragColor.a *= dash;
112
+ }
113
+ break;
114
+ case 1:
115
+ if (u_dash_opacity_multiplier < 1.0 && fract((v_length + u_dash_phase) * u_dash_count) < 0.5) {
116
+ fragColor.a *= u_dash_opacity_multiplier;
117
+ }
118
+ break;
119
+ }
120
+ }`;
121
+
122
+
123
+ class PointOnGlobeProgram {
124
+
125
+ constructor(globe) {
126
+
127
+ this.globe = globe;
128
+ this.gl = globe.gl;
129
+ this._isFreed = false;
130
+ this.program = createProgram(this.gl, vs, fs);
131
+
132
+ const { gl, program } = this;
133
+
134
+ // assign opacity
135
+
136
+
137
+ // assign attribute locations
138
+ gl.bindAttribLocation(program, 0, "pos3D");
139
+ gl.bindAttribLocation(program, 1, "pos2D");
140
+ gl.bindAttribLocation(program, 2, "rgba");
141
+ gl.bindAttribLocation(program, 3, "size");
142
+ // arrange camera uniform block
143
+
144
+
145
+ this.cameraBlockTotem = CameraUniformBlockTotemCache.get(globe);
146
+ this.cameraBlockTotem.assignBindingPoint(program, uniformBindingPoints.camera);
147
+ uniformBlockManager.assignBindingPoint(this.gl, this.program);
148
+ this._defaultUBO = uniformBlockManager.createUBO(this.gl);
149
+
150
+ this._defaultUBO.update(new Map([
151
+ ["u_rgba", [1, 1, 1, 1]],
152
+ ["u_opacity", [1.0]],
153
+ ["u_size_multiplier", [1.0]],
154
+ ["u_size", [1.0]],
155
+ ["u_is_circle", [1.0]],
156
+ ]));
157
+ }
158
+
159
+
160
+ createUBO() {
161
+ const ubo = uniformBlockManager.createUBO(this.gl);
162
+ return ubo;
163
+ }
164
+
165
+ createVAO(pos3DBufferObj, pos2DBufferObj, rgbaBufferObj, sizeBufferObj) {
166
+
167
+ const { gl } = this;
168
+ const vao = gl.createVertexArray();
169
+ gl.bindVertexArray(vao);
170
+
171
+ attributeLoader(gl, pos3DBufferObj, 0, 3);
172
+ attributeLoader(gl, pos2DBufferObj, 1, 2);
173
+ attributeLoader(gl, rgbaBufferObj, 2, 4, { escapeValues: [-1, -1, -1, -1] });
174
+ attributeLoader(gl, sizeBufferObj, 3, 1, { escapeValues: [-1] });
175
+
176
+ gl.bindVertexArray(null);
177
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
178
+ return vao;
179
+ }
180
+
181
+
182
+ /**
183
+ *
184
+ * @param {vertexArrayObject} vao
185
+ * @param {DrawRangeIndexParams} drawOptions
186
+ */
187
+ draw(vao, drawOptions, ubo = null) {
188
+ const { gl, program } = this;
189
+ gl.useProgram(program);
190
+ gl.bindVertexArray(vao);
191
+ this.cameraBlockTotem.bind(uniformBindingPoints.camera);
192
+ ubo = ubo || this._defaultUBO;
193
+ ubo.bind();
194
+
195
+ drawArrays(gl, gl.POINTS, drawOptions);
196
+ ubo.unbind();
197
+ this.cameraBlockTotem.unbind(uniformBindingPoints.camera);
198
+ gl.bindVertexArray(null);
199
+ }
200
+
201
+ free() {
202
+ if (this._isFreed) return;
203
+ const { gl, globe } = this;
204
+ CameraUniformBlockTotemCache.release(globe);
205
+ gl.deleteProgram(this.program);
206
+ this._isFreed = true;
207
+ }
208
+ }
209
+
210
+
211
+ const PickableRendererProgramCache = Object.freeze({
212
+ get: (globe) => noRegisterGlobeProgramCache.getProgram(globe, PointOnGlobeProgram),
213
+ release: (globe) => noRegisterGlobeProgramCache.releaseProgram(globe, PointOnGlobeProgram)
214
+ });
215
+
216
+ export { PickableRendererProgramCache };
@@ -0,0 +1,168 @@
1
+ /**
2
+ * *
3
+ * * *
4
+ * * * *
5
+ * * *
6
+ * *
7
+ */
8
+
9
+
10
+
11
+ import { CameraUniformBlockTotemCache, CameraUniformBlockString } from "../totems";
12
+ import { PI, mercatorXYToGLPosition, cartesian3DToGLPosition, circleLimpFromLongLatRadCenterCartesian3D_accurate } from "../../util/shaderfunctions/geometrytransformations";
13
+ import { createProgram } from "../../util";
14
+ import { noRegisterGlobeProgramCache } from "../programcache";
15
+ import { attributeLoader } from "../../util/gl-util/buffer/integrate-buffer";
16
+ import { drawInstanced } from "../../util/gl-util/draw-options/methods";
17
+ import { UniformBlockManager } from "../../util/gl-util/uniform-block/manager";
18
+
19
+
20
+ const uboBlockManager = new UniformBlockManager(
21
+ "FlexibleBlock",
22
+ [
23
+ { name: "u_color", type: "vec4" },
24
+ { name: "u_radius", type: "float" }
25
+ ],
26
+ 1
27
+ );
28
+
29
+ const vs = `#version 300 es
30
+ ${PI}
31
+ ${CameraUniformBlockString}
32
+ ${cartesian3DToGLPosition}
33
+ ${circleLimpFromLongLatRadCenterCartesian3D_accurate}
34
+
35
+ uniform float edge_count;
36
+
37
+ in vec3 pos3D;
38
+ in float radius;
39
+ in vec4 color;
40
+
41
+ ${uboBlockManager.glslCode()}
42
+
43
+ out vec4 vColor;
44
+
45
+ void main() {
46
+
47
+ float radius_ = ( radius == -1.0 ) ? u_radius : radius;
48
+ vec4 color = ( color.r == -1.0 ) ? u_color : color;
49
+
50
+ if ( gl_VertexID == 0 ) {
51
+ gl_Position = cartesian3DToGLPosition(pos3D);
52
+ vColor = vColor;
53
+ } else {
54
+ float angle = PI * 2.0 * float( gl_VertexID - 1 ) / edge_count;
55
+ vec3 position = circleLimpFromLongLatRadCenterCartesian3D_accurate(pos3D, radius, angle);
56
+ gl_Position = cartesian3DToGLPosition(position);
57
+ float distance = distance(position, pos3D);
58
+
59
+
60
+
61
+ vColor = vec4(color.rgb, color.a * (1.0 - distance / radius));
62
+ }
63
+ }`;
64
+
65
+
66
+ const fs = `#version 300 es
67
+ precision highp float;
68
+
69
+ uniform float opacity;
70
+ in vec4 vColor;
71
+
72
+ out vec4 fragColor;
73
+
74
+ void main() {
75
+ fragColor = vColor;
76
+ fragColor.a *= opacity;
77
+ }`;
78
+
79
+
80
+ class Logic {
81
+ constructor(globe) {
82
+ this.globe = globe;
83
+ this.gl = globe.gl;
84
+
85
+ this._vaoCache = [];
86
+
87
+ this.program = createProgram(this.gl, vs, fs);
88
+
89
+ const { gl, program } = this;
90
+
91
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
92
+ gl.useProgram(program);
93
+ // set uniform locations
94
+ this._uniforms = {
95
+ edge_count_loc: gl.getUniformLocation(program, "edge_count"),
96
+ edge_count: 40,
97
+ opacity_loc: gl.getUniformLocation(program, "opacity"),
98
+ opacity: 1.0
99
+ };
100
+ // last values
101
+ gl.uniform1f(this._uniforms.edge_count_loc, this._uniforms.edge_count);
102
+ gl.uniform1f(this._uniforms.opacity_loc, this._uniforms.opacity);
103
+
104
+ gl.useProgram(currentProgram);
105
+ // assign attribute locations
106
+ gl.bindAttribLocation(program, 0, "pos3D");
107
+ gl.bindAttribLocation(program, 1, "radius");
108
+ gl.bindAttribLocation(program, 2, "color");
109
+ // camera uniform block
110
+ this.cameraUniformBlockTotem = CameraUniformBlockTotemCache.get(globe);
111
+ this.cameraBlockBindingPoint = 0;
112
+ const cameraBlockIndex = gl.getUniformBlockIndex(program, "CameraUniformBlock");
113
+ gl.uniformBlockBinding(program, cameraBlockIndex, this.cameraBlockBindingPoint);
114
+
115
+ uboBlockManager.assignBindingPoint(this.gl, this.program);
116
+ this._defaultUBO = uboBlockManager.createUBO(this.gl);
117
+ }
118
+
119
+
120
+ createVAO(pos3DObj, radiusObj, colorObj) {
121
+ const { gl } = this;
122
+ const vao = gl.createVertexArray();
123
+ const divisor = 1;
124
+ gl.bindVertexArray(vao);
125
+
126
+ // TODO constants to escape values
127
+ attributeLoader(gl, pos3DObj, 0, 3, { divisor });
128
+ attributeLoader(gl, radiusObj, 1, 1, { divisor, escapeValues: [-1] });
129
+ attributeLoader(gl, colorObj, 2, 4, { divisor, escapeValues: [-1, -1, -1, -1] });
130
+
131
+ gl.bindVertexArray(null);
132
+ this._vaoCache.push(vao);
133
+ return vao;
134
+ }
135
+
136
+
137
+ draw(vao, drawOptions, opacity = 1.0, ubo = null) {
138
+ const { gl, program } = this;
139
+ gl.useProgram(program);
140
+ gl.bindVertexArray(vao);
141
+ if (opacity !== this._uniforms.opacity) {
142
+ gl.uniform1f(this._uniforms.opacity_loc, opacity);
143
+ this._uniforms.opacity = opacity;
144
+ }
145
+ ubo = ubo || this._defaultUBO;
146
+ ubo.bind();
147
+ drawInstanced(gl, gl.TRIANGLE_FAN, drawOptions);
148
+ ubo.unbind();
149
+ gl.bindVertexArray(null);
150
+ }
151
+
152
+
153
+ free() {
154
+ if (this._isFreed) return;
155
+ CameraUniformBlockTotemCache.release(this.globe);
156
+ this.gl.deleteProgram(this.program);
157
+ for (const vao of this._vaoCache) this.gl.deleteVertexArray(vao);
158
+ this._isFreed = true;
159
+ }
160
+ }
161
+
162
+
163
+ const ElementGlobeSufaceGlowCache = Object.freeze({
164
+ get: (globe) => noRegisterGlobeProgramCache.getProgram(globe, Logic),
165
+ release: (globe) => noRegisterGlobeProgramCache.releaseProgram(globe)
166
+ })
167
+
168
+ export { ElementGlobeSufaceGlowCache };
@@ -0,0 +1,184 @@
1
+ import { createProgram } from "../../util";
2
+ import { CameraUniformBlockTotemCache, CameraUniformBlockString } from "../totems";
3
+ import { mercatorXYToGLPosition, cartesian3DToGLPosition } from "../../util/shaderfunctions/geometrytransformations";
4
+ import { noRegisterGlobeProgramCache } from "../programcache";
5
+ import { attributeLoader } from "../../util/gl-util/buffer/integrate-buffer";
6
+ import { drawArrays } from "../../util/gl-util/draw-options/methods";
7
+ import { UniformBlockManager } from "../../util/gl-util/uniform-block/manager";
8
+ import { singularity } from "../../shaders/fragment-toy/singularity";
9
+ import { firework } from "../../shaders/fragment-toy/firework";
10
+
11
+
12
+ const cameraBlockBindingPoint = 0;
13
+ const flexibleBlockBindingPoint = 1;
14
+
15
+ const uniformBlockManager = new UniformBlockManager(
16
+ "FlexibleBlock",
17
+ [
18
+ { name: "u_rgba", type: "vec4", value: new Float32Array([1, 1, 1, 1]) },
19
+ { name: "u_size_multiplier", type: "float", value: new Float32Array([1.0]) },
20
+ { name: "u_opacity", type: "float", value: new Float32Array([1.0]) },
21
+ { name: "u_size", type: "float", value: new Float32Array([1.0]) },
22
+ { name: "u_minimumSize", type: "float", value: new Float32Array([25.0]) },
23
+ { name: "u_phase", type: "float", value: new Float32Array([1.0]) },
24
+ ], flexibleBlockBindingPoint);
25
+
26
+ const vs = `#version 300 es
27
+ precision highp float;
28
+
29
+ ${CameraUniformBlockString}
30
+ ${mercatorXYToGLPosition}
31
+ ${cartesian3DToGLPosition}
32
+
33
+ ${uniformBlockManager.glslCode()}
34
+
35
+
36
+ in vec3 pos3D;
37
+ in vec2 pos2D;
38
+ in vec4 color;
39
+ in float size;
40
+
41
+ out vec4 vColor;
42
+ flat out float v_size;
43
+
44
+
45
+
46
+ void main() {
47
+
48
+ if(is3D){
49
+ gl_Position = cartesian3DToGLPosition(pos3D);
50
+ }
51
+ else {
52
+ gl_Position = mercatorXYToGLPosition(pos2D);
53
+ }
54
+
55
+ gl_PointSize = max(
56
+ ((size == -1.0) ? u_size : size ) * u_size_multiplier,
57
+ u_minimumSize);
58
+ v_size = gl_PointSize;
59
+ vColor = (color.r == -1.0) ? u_rgba : color;
60
+ vColor.a *= u_opacity;
61
+
62
+ }`;
63
+
64
+
65
+ const fs = `#version 300 es
66
+ precision highp float;
67
+
68
+ ${uniformBlockManager.glslCode()}
69
+
70
+ in vec4 vColor;
71
+ out vec4 fragColor;
72
+
73
+ flat in float v_size;
74
+
75
+ ${firework}
76
+ ${singularity}
77
+
78
+ void main() {
79
+ fragColor = vColor;
80
+
81
+ float dist = distance(gl_PointCoord, vec2(0.5, 0.5)) * 2.0;
82
+ if ( dist > 1.0) discard;
83
+
84
+ // center glow
85
+ float center_alpha = smoothstep(0.5, 0.0, dist) * 0.3;
86
+ // center_alpha = smoothstep(0.0, 1.0, center_alpha);
87
+
88
+ // circle pattern
89
+ float threshold = fract(( - dist + u_phase - 0.5));
90
+ float circle_alpha = sin( threshold * 1.57 );
91
+ circle_alpha = smoothstep((v_size / (v_size + .5)), 1.0, circle_alpha);
92
+
93
+ float outer_circle_alpha = sin(dist * 1.57 );
94
+ outer_circle_alpha = smoothstep((v_size / (v_size + .5)), 1.0, outer_circle_alpha);
95
+
96
+ // fragColor = singularity(gl_PointCoord, u_phase);
97
+
98
+ fragColor.a *= smoothstep(0.0, 1.1, ( 0.4 * u_opacity + center_alpha + circle_alpha+ outer_circle_alpha));
99
+ }`;
100
+
101
+ class Logic {
102
+
103
+ constructor(globe) {
104
+ this.globe = globe;
105
+ this.gl = globe.gl;
106
+
107
+ this.program = createProgram(this.gl, vs, fs);
108
+
109
+ const { gl, program } = this;
110
+
111
+
112
+ gl.bindAttribLocation(program, 0, "pos3D");
113
+ gl.bindAttribLocation(program, 1, "pos2D");
114
+ gl.bindAttribLocation(program, 2, "color");
115
+ gl.bindAttribLocation(program, 3, "size");
116
+ // assign uniform block
117
+
118
+ this.cameraBlockTotem = CameraUniformBlockTotemCache.get(globe);
119
+ this.cameraBlockTotem.assignBindingPoint(program, cameraBlockBindingPoint);
120
+
121
+ uniformBlockManager.assignBindingPoint(this.gl, this.program);
122
+ this._defaultUBO = uniformBlockManager.createUBO(this.gl);
123
+ }
124
+
125
+
126
+ createVAO(pos3DBuffer, pos2DBuffer, colorBuffer, sizeBuffer) {
127
+
128
+ const { gl } = this;
129
+
130
+ const vao = gl.createVertexArray();
131
+ gl.bindVertexArray(vao);
132
+
133
+ attributeLoader(gl, pos3DBuffer, 0, 3);
134
+ attributeLoader(gl, pos2DBuffer, 1, 2);
135
+ attributeLoader(gl, colorBuffer, 2, 4, { escapeValues: [-1, -1, -1, -1] });
136
+ attributeLoader(gl, sizeBuffer, 3, 1, { escapeValues: [-1] });
137
+
138
+ gl.bindVertexArray(null);
139
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
140
+
141
+ return vao;
142
+ }
143
+
144
+
145
+ createUBO() {
146
+ const ubo = uniformBlockManager.createUBO(this.gl);
147
+ return ubo;
148
+ }
149
+
150
+ draw(vao, drawOptions, ubo = null) {
151
+ const { gl, program, cameraBlockTotem } = this;
152
+ gl.useProgram(program);
153
+ gl.bindVertexArray(vao);
154
+ cameraBlockTotem.bind(cameraBlockBindingPoint);
155
+
156
+ ubo = ubo || this._defaultUBO;
157
+
158
+ ubo.bind();
159
+ drawArrays(gl, gl.POINTS, drawOptions);
160
+ ubo.unbind();
161
+
162
+ gl.bindVertexArray(null);
163
+ cameraBlockTotem.unbind(cameraBlockBindingPoint);
164
+ this.globe.DrawRender();
165
+ }
166
+
167
+
168
+
169
+ // for singleton cache interation
170
+
171
+ free() {
172
+ if (this._isFreed) return;
173
+ CameraUniformBlockTotemCache.release(this.globe);
174
+ this.gl.deleteProgram(this.program);
175
+ this._isFreed = true;
176
+ }
177
+ }
178
+
179
+ const ElementPointGlowProgramCache = Object.freeze({
180
+ get: (globe) => noRegisterGlobeProgramCache.getProgram(globe, Logic),
181
+ release: globe => noRegisterGlobeProgramCache.releaseProgram(globe, Logic)
182
+ });
183
+
184
+ export { ElementPointGlowProgramCache };