@antv/l7-layers 2.6.6 → 2.6.10
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.
- package/es/core/BaseLayer.js +4 -0
- package/es/core/BaseLayer.js.map +1 -1
- package/es/core/BaseModel.d.ts +4 -0
- package/es/core/BaseModel.js +19 -2
- package/es/core/BaseModel.js.map +1 -1
- package/es/index.d.ts +2 -1
- package/es/index.js +2 -1
- package/es/index.js.map +1 -1
- package/es/line/models/arc.js +6 -4
- package/es/line/models/arc.js.map +1 -1
- package/es/utils/dataMappingStyle.d.ts +1 -0
- package/es/utils/dataMappingStyle.js +4 -0
- package/es/utils/dataMappingStyle.js.map +1 -1
- package/es/wind/index.d.ts +36 -0
- package/es/wind/index.js +91 -0
- package/es/wind/index.js.map +1 -0
- package/es/wind/models/index.d.ts +5 -0
- package/es/wind/models/index.js +6 -0
- package/es/wind/models/index.js.map +1 -0
- package/es/wind/models/utils.d.ts +19 -0
- package/es/wind/models/utils.js +201 -0
- package/es/wind/models/utils.js.map +1 -0
- package/es/wind/models/wind.d.ts +31 -0
- package/es/wind/models/wind.js +298 -0
- package/es/wind/models/wind.js.map +1 -0
- package/es/wind/models/windRender.d.ts +104 -0
- package/es/wind/models/windRender.js +346 -0
- package/es/wind/models/windRender.js.map +1 -0
- package/es/wind/models/windShader.d.ts +12 -0
- package/es/wind/models/windShader.js +7 -0
- package/es/wind/models/windShader.js.map +1 -0
- package/lib/core/BaseLayer.js +4 -0
- package/lib/core/BaseLayer.js.map +1 -1
- package/lib/core/BaseModel.js +19 -2
- package/lib/core/BaseModel.js.map +1 -1
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -1
- package/lib/line/models/arc.js +6 -4
- package/lib/line/models/arc.js.map +1 -1
- package/lib/utils/dataMappingStyle.js +4 -0
- package/lib/utils/dataMappingStyle.js.map +1 -1
- package/lib/wind/index.js +104 -0
- package/lib/wind/index.js.map +1 -0
- package/lib/wind/models/index.js +17 -0
- package/lib/wind/models/index.js.map +1 -0
- package/lib/wind/models/utils.js +228 -0
- package/lib/wind/models/utils.js.map +1 -0
- package/lib/wind/models/wind.js +310 -0
- package/lib/wind/models/wind.js.map +1 -0
- package/lib/wind/models/windRender.js +340 -0
- package/lib/wind/models/windRender.js.map +1 -0
- package/lib/wind/models/windShader.js +19 -0
- package/lib/wind/models/windShader.js.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
+
import * as glUtils from './utils';
|
|
5
|
+
import { drawFrag, drawVert, fullScreenFrag, fullScreenVert, updateFrag, updateVert } from './windShader';
|
|
6
|
+
|
|
7
|
+
function getColorRamp(colors) {
|
|
8
|
+
var canvas = document.createElement('canvas');
|
|
9
|
+
var ctx = canvas.getContext('2d');
|
|
10
|
+
canvas.width = 256;
|
|
11
|
+
canvas.height = 1;
|
|
12
|
+
var gradient = ctx.createLinearGradient(0, 0, 256, 0);
|
|
13
|
+
|
|
14
|
+
for (var _i = 0, _Object$keys = Object.keys(colors); _i < _Object$keys.length; _i++) {
|
|
15
|
+
var stop = _Object$keys[_i];
|
|
16
|
+
gradient.addColorStop(+stop, colors[+stop]);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
ctx.fillStyle = gradient;
|
|
20
|
+
ctx.fillRect(0, 0, 256, 1);
|
|
21
|
+
canvas = null;
|
|
22
|
+
return new Uint8Array(ctx.getImageData(0, 0, 256, 1).data);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function bindAttribute(gl, buffer, attribute, numComponents) {
|
|
26
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
27
|
+
gl.enableVertexAttribArray(attribute);
|
|
28
|
+
gl.vertexAttribPointer(attribute, numComponents, gl.FLOAT, false, 0, 0);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function bindFramebuffer(gl, framebuffer, texture) {
|
|
32
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
|
33
|
+
|
|
34
|
+
if (texture) {
|
|
35
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export var Wind = function () {
|
|
40
|
+
function Wind(options) {
|
|
41
|
+
_classCallCheck(this, Wind);
|
|
42
|
+
|
|
43
|
+
_defineProperty(this, "width", 512);
|
|
44
|
+
|
|
45
|
+
_defineProperty(this, "height", 512);
|
|
46
|
+
|
|
47
|
+
_defineProperty(this, "pixels", void 0);
|
|
48
|
+
|
|
49
|
+
_defineProperty(this, "fadeOpacity", void 0);
|
|
50
|
+
|
|
51
|
+
_defineProperty(this, "speedFactor", void 0);
|
|
52
|
+
|
|
53
|
+
_defineProperty(this, "dropRate", void 0);
|
|
54
|
+
|
|
55
|
+
_defineProperty(this, "dropRateBump", void 0);
|
|
56
|
+
|
|
57
|
+
_defineProperty(this, "gl", void 0);
|
|
58
|
+
|
|
59
|
+
_defineProperty(this, "drawProgram", void 0);
|
|
60
|
+
|
|
61
|
+
_defineProperty(this, "fullScreenProgram", void 0);
|
|
62
|
+
|
|
63
|
+
_defineProperty(this, "updateProgram", void 0);
|
|
64
|
+
|
|
65
|
+
_defineProperty(this, "rampColors", void 0);
|
|
66
|
+
|
|
67
|
+
_defineProperty(this, "numParticles", 65536);
|
|
68
|
+
|
|
69
|
+
_defineProperty(this, "numParticlesSize", void 0);
|
|
70
|
+
|
|
71
|
+
_defineProperty(this, "particleStateResolution", void 0);
|
|
72
|
+
|
|
73
|
+
_defineProperty(this, "quadBuffer", void 0);
|
|
74
|
+
|
|
75
|
+
_defineProperty(this, "particleIndexBuffer", void 0);
|
|
76
|
+
|
|
77
|
+
_defineProperty(this, "framebuffer", void 0);
|
|
78
|
+
|
|
79
|
+
_defineProperty(this, "colorRampTexture", void 0);
|
|
80
|
+
|
|
81
|
+
_defineProperty(this, "backgroundTexture", void 0);
|
|
82
|
+
|
|
83
|
+
_defineProperty(this, "screenTexture", void 0);
|
|
84
|
+
|
|
85
|
+
_defineProperty(this, "particleStateTexture0", void 0);
|
|
86
|
+
|
|
87
|
+
_defineProperty(this, "particleStateTexture1", void 0);
|
|
88
|
+
|
|
89
|
+
_defineProperty(this, "windTexture", void 0);
|
|
90
|
+
|
|
91
|
+
_defineProperty(this, "windData", void 0);
|
|
92
|
+
|
|
93
|
+
this.gl = options.glContext;
|
|
94
|
+
this.width = options.imageWidth;
|
|
95
|
+
this.height = options.imageHeight;
|
|
96
|
+
this.fadeOpacity = options.fadeOpacity;
|
|
97
|
+
this.speedFactor = options.speedFactor;
|
|
98
|
+
this.dropRate = options.dropRate;
|
|
99
|
+
this.dropRateBump = options.dropRateBump;
|
|
100
|
+
this.rampColors = options.rampColors;
|
|
101
|
+
this.init();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
_createClass(Wind, [{
|
|
105
|
+
key: "init",
|
|
106
|
+
value: function init() {
|
|
107
|
+
var gl = this.gl;
|
|
108
|
+
this.fadeOpacity = 0.996;
|
|
109
|
+
this.speedFactor = 0.25;
|
|
110
|
+
this.dropRate = 0.003;
|
|
111
|
+
this.dropRateBump = 0.01;
|
|
112
|
+
this.drawProgram = glUtils.createProgram(gl, drawVert, drawFrag);
|
|
113
|
+
this.fullScreenProgram = glUtils.createProgram(gl, fullScreenVert, fullScreenFrag);
|
|
114
|
+
this.updateProgram = glUtils.createProgram(gl, updateVert, updateFrag);
|
|
115
|
+
this.quadBuffer = glUtils.createBuffer(gl, new Float32Array([0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]));
|
|
116
|
+
this.framebuffer = gl.createFramebuffer();
|
|
117
|
+
this.colorRampTexture = glUtils.createTexture(this.gl, this.gl.LINEAR, getColorRamp(this.rampColors), 16, 16);
|
|
118
|
+
var emptyPixels = new Uint8Array(this.width * this.height * 4);
|
|
119
|
+
this.backgroundTexture = glUtils.createTexture(gl, gl.NEAREST, emptyPixels, this.width, this.height);
|
|
120
|
+
this.screenTexture = glUtils.createTexture(gl, gl.NEAREST, emptyPixels, this.width, this.height);
|
|
121
|
+
var particleRes = this.particleStateResolution = Math.ceil(Math.sqrt(this.numParticles));
|
|
122
|
+
this.numParticlesSize = particleRes * particleRes;
|
|
123
|
+
var particleState = new Uint8Array(this.numParticlesSize * 4);
|
|
124
|
+
|
|
125
|
+
for (var i = 0; i < particleState.length; i++) {
|
|
126
|
+
particleState[i] = Math.floor(Math.random() * 256);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
this.particleStateTexture0 = glUtils.createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
|
|
130
|
+
this.particleStateTexture1 = glUtils.createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
|
|
131
|
+
var particleIndices = new Float32Array(this.numParticlesSize);
|
|
132
|
+
|
|
133
|
+
for (var i$1 = 0; i$1 < this.numParticlesSize; i$1++) {
|
|
134
|
+
particleIndices[i$1] = i$1;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
this.particleIndexBuffer = glUtils.createBuffer(gl, particleIndices);
|
|
138
|
+
}
|
|
139
|
+
}, {
|
|
140
|
+
key: "setWind",
|
|
141
|
+
value: function setWind(windData) {
|
|
142
|
+
this.windData = windData;
|
|
143
|
+
this.windTexture = glUtils.createDataTexture(this.gl, this.gl.LINEAR, windData.image);
|
|
144
|
+
}
|
|
145
|
+
}, {
|
|
146
|
+
key: "updateParticelNum",
|
|
147
|
+
value: function updateParticelNum(num) {
|
|
148
|
+
var gl = this.gl;
|
|
149
|
+
|
|
150
|
+
if (num !== this.numParticles) {
|
|
151
|
+
this.numParticles = num;
|
|
152
|
+
var particleRes = this.particleStateResolution = Math.ceil(Math.sqrt(this.numParticles));
|
|
153
|
+
this.numParticlesSize = particleRes * particleRes;
|
|
154
|
+
var particleState = new Uint8Array(this.numParticlesSize * 4);
|
|
155
|
+
|
|
156
|
+
for (var i = 0; i < particleState.length; i++) {
|
|
157
|
+
particleState[i] = Math.floor(Math.random() * 256);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
this.particleStateTexture0 = glUtils.createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
|
|
161
|
+
this.particleStateTexture1 = glUtils.createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
|
|
162
|
+
var particleIndices = new Float32Array(this.numParticlesSize);
|
|
163
|
+
|
|
164
|
+
for (var i$1 = 0; i$1 < this.numParticlesSize; i$1++) {
|
|
165
|
+
particleIndices[i$1] = i$1;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
this.particleIndexBuffer = glUtils.createBuffer(gl, particleIndices);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}, {
|
|
172
|
+
key: "updateWindDir",
|
|
173
|
+
value: function updateWindDir(uMin, uMax, vMin, vMax) {
|
|
174
|
+
this.windData.uMin = uMin;
|
|
175
|
+
this.windData.uMax = uMax;
|
|
176
|
+
this.windData.vMin = vMin;
|
|
177
|
+
this.windData.vMax = vMax;
|
|
178
|
+
}
|
|
179
|
+
}, {
|
|
180
|
+
key: "updateColorRampTexture",
|
|
181
|
+
value: function updateColorRampTexture(rampColors) {
|
|
182
|
+
if (this.isColorChanged(rampColors)) {
|
|
183
|
+
this.rampColors = rampColors;
|
|
184
|
+
var gl = this.gl;
|
|
185
|
+
gl.deleteTexture(this.colorRampTexture);
|
|
186
|
+
this.colorRampTexture = glUtils.createTexture(gl, gl.LINEAR, getColorRamp(rampColors), 16, 16);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}, {
|
|
190
|
+
key: "isColorChanged",
|
|
191
|
+
value: function isColorChanged(rampColors) {
|
|
192
|
+
var keys = Object.keys(rampColors);
|
|
193
|
+
|
|
194
|
+
for (var _i2 = 0, _keys = keys; _i2 < _keys.length; _i2++) {
|
|
195
|
+
var item = _keys[_i2];
|
|
196
|
+
|
|
197
|
+
var _key = Number(item);
|
|
198
|
+
|
|
199
|
+
if (!this.rampColors[_key]) {
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (this.rampColors[_key] && this.rampColors[_key] !== rampColors[_key]) {
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
}, {
|
|
211
|
+
key: "reSize",
|
|
212
|
+
value: function reSize(width, height) {
|
|
213
|
+
if (width !== this.width || height !== this.height) {
|
|
214
|
+
var gl = this.gl;
|
|
215
|
+
gl.deleteTexture(this.backgroundTexture);
|
|
216
|
+
gl.deleteTexture(this.screenTexture);
|
|
217
|
+
this.width = width;
|
|
218
|
+
this.height = height;
|
|
219
|
+
var emptyPixels = new Uint8Array(width * height * 4);
|
|
220
|
+
this.backgroundTexture = glUtils.createTexture(gl, gl.NEAREST, emptyPixels, width, height);
|
|
221
|
+
this.screenTexture = glUtils.createTexture(gl, gl.NEAREST, emptyPixels, width, height);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}, {
|
|
225
|
+
key: "draw",
|
|
226
|
+
value: function draw() {
|
|
227
|
+
var _this$windData;
|
|
228
|
+
|
|
229
|
+
if ((_this$windData = this.windData) !== null && _this$windData !== void 0 && _this$windData.image) {
|
|
230
|
+
var gl = this.gl;
|
|
231
|
+
glUtils.bindTexture(gl, this.windTexture, 0);
|
|
232
|
+
glUtils.bindTexture(gl, this.particleStateTexture0, 1);
|
|
233
|
+
this.drawScreen();
|
|
234
|
+
this.updateParticles();
|
|
235
|
+
return {
|
|
236
|
+
d: this.pixels,
|
|
237
|
+
w: this.width,
|
|
238
|
+
h: this.height
|
|
239
|
+
};
|
|
240
|
+
} else {
|
|
241
|
+
return {
|
|
242
|
+
d: new Uint8Array([0, 0, 0, 0]),
|
|
243
|
+
w: 1,
|
|
244
|
+
h: 1
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}, {
|
|
249
|
+
key: "drawScreen",
|
|
250
|
+
value: function drawScreen() {
|
|
251
|
+
var gl = this.gl;
|
|
252
|
+
bindFramebuffer(gl, this.framebuffer, this.screenTexture);
|
|
253
|
+
gl.viewport(0, 0, this.width, this.height);
|
|
254
|
+
this.drawFullTexture(this.backgroundTexture, this.fadeOpacity);
|
|
255
|
+
this.drawParticles();
|
|
256
|
+
gl.disable(gl.BLEND);
|
|
257
|
+
this.pixels = new Uint8Array(4 * this.width * this.height);
|
|
258
|
+
gl.readPixels(0, 0, this.width, this.height, gl.RGBA, gl.UNSIGNED_BYTE, this.pixels);
|
|
259
|
+
bindFramebuffer(gl, null, null);
|
|
260
|
+
gl.viewport(0, 0, this.gl.canvas.width, this.gl.canvas.height);
|
|
261
|
+
var temp = this.backgroundTexture;
|
|
262
|
+
this.backgroundTexture = this.screenTexture;
|
|
263
|
+
this.screenTexture = temp;
|
|
264
|
+
}
|
|
265
|
+
}, {
|
|
266
|
+
key: "drawFullTexture",
|
|
267
|
+
value: function drawFullTexture(texture, opacity) {
|
|
268
|
+
var gl = this.gl;
|
|
269
|
+
var program = this.fullScreenProgram;
|
|
270
|
+
gl.useProgram(program);
|
|
271
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.quadBuffer);
|
|
272
|
+
gl.vertexAttribPointer(program.a_pos, 2, gl.FLOAT, false, 0, 0);
|
|
273
|
+
gl.enableVertexAttribArray(program.a_pos);
|
|
274
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
275
|
+
glUtils.bindTexture(gl, texture, 2);
|
|
276
|
+
gl.uniform1i(program.u_screen, 2);
|
|
277
|
+
gl.uniform1f(program.u_opacity, opacity);
|
|
278
|
+
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
|
279
|
+
}
|
|
280
|
+
}, {
|
|
281
|
+
key: "drawParticles",
|
|
282
|
+
value: function drawParticles() {
|
|
283
|
+
var gl = this.gl;
|
|
284
|
+
var program = this.drawProgram;
|
|
285
|
+
gl.useProgram(program);
|
|
286
|
+
bindAttribute(gl, this.particleIndexBuffer, program.a_index, 1);
|
|
287
|
+
glUtils.bindTexture(gl, this.colorRampTexture, 2);
|
|
288
|
+
gl.uniform1i(program.u_wind, 0);
|
|
289
|
+
gl.uniform1i(program.u_particles, 1);
|
|
290
|
+
gl.uniform1i(program.u_color_ramp, 2);
|
|
291
|
+
gl.uniform1f(program.u_particles_res, this.particleStateResolution);
|
|
292
|
+
gl.uniform2f(program.u_wind_min, this.windData.uMin, this.windData.vMin);
|
|
293
|
+
gl.uniform2f(program.u_wind_max, this.windData.uMax, this.windData.vMax);
|
|
294
|
+
gl.drawArrays(gl.POINTS, 0, this.numParticlesSize);
|
|
295
|
+
}
|
|
296
|
+
}, {
|
|
297
|
+
key: "updateParticles",
|
|
298
|
+
value: function updateParticles() {
|
|
299
|
+
var gl = this.gl;
|
|
300
|
+
bindFramebuffer(gl, this.framebuffer, this.particleStateTexture1);
|
|
301
|
+
gl.viewport(0, 0, this.particleStateResolution, this.particleStateResolution);
|
|
302
|
+
var program = this.updateProgram;
|
|
303
|
+
gl.useProgram(program);
|
|
304
|
+
bindAttribute(gl, this.quadBuffer, program.a_pos, 2);
|
|
305
|
+
gl.uniform1i(program.u_wind, 0);
|
|
306
|
+
gl.uniform1i(program.u_particles, 1);
|
|
307
|
+
gl.uniform1f(program.u_rand_seed, Math.random());
|
|
308
|
+
gl.uniform2f(program.u_wind_res, this.windData.image.width * 2, this.windData.image.height * 2);
|
|
309
|
+
gl.uniform2f(program.u_wind_min, this.windData.uMin, this.windData.vMin);
|
|
310
|
+
gl.uniform2f(program.u_wind_max, this.windData.uMax, this.windData.vMax);
|
|
311
|
+
gl.uniform1f(program.u_speed_factor, this.speedFactor);
|
|
312
|
+
gl.uniform1f(program.u_drop_rate, this.dropRate);
|
|
313
|
+
gl.uniform1f(program.u_drop_rate_bump, this.dropRateBump);
|
|
314
|
+
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
|
315
|
+
var temp = this.particleStateTexture0;
|
|
316
|
+
this.particleStateTexture0 = this.particleStateTexture1;
|
|
317
|
+
this.particleStateTexture1 = temp;
|
|
318
|
+
bindFramebuffer(gl, null, null);
|
|
319
|
+
}
|
|
320
|
+
}, {
|
|
321
|
+
key: "destroy",
|
|
322
|
+
value: function destroy() {
|
|
323
|
+
this.gl.deleteBuffer(this.quadBuffer);
|
|
324
|
+
this.gl.deleteBuffer(this.particleIndexBuffer);
|
|
325
|
+
this.gl.deleteFramebuffer(this.framebuffer);
|
|
326
|
+
this.gl.deleteShader(this.drawProgram.vertexShader);
|
|
327
|
+
this.gl.deleteShader(this.drawProgram.fragmentShader);
|
|
328
|
+
this.gl.deleteProgram(this.drawProgram);
|
|
329
|
+
this.gl.deleteShader(this.fullScreenProgram.vertexShader);
|
|
330
|
+
this.gl.deleteShader(this.fullScreenProgram.fragmentShader);
|
|
331
|
+
this.gl.deleteProgram(this.fullScreenProgram);
|
|
332
|
+
this.gl.deleteShader(this.updateProgram.vertexShader);
|
|
333
|
+
this.gl.deleteShader(this.updateProgram.fragmentShader);
|
|
334
|
+
this.gl.deleteProgram(this.updateProgram);
|
|
335
|
+
this.gl.deleteTexture(this.colorRampTexture);
|
|
336
|
+
this.gl.deleteTexture(this.backgroundTexture);
|
|
337
|
+
this.gl.deleteTexture(this.screenTexture);
|
|
338
|
+
this.gl.deleteTexture(this.particleStateTexture0);
|
|
339
|
+
this.gl.deleteTexture(this.particleStateTexture1);
|
|
340
|
+
this.gl.deleteTexture(this.windTexture);
|
|
341
|
+
}
|
|
342
|
+
}]);
|
|
343
|
+
|
|
344
|
+
return Wind;
|
|
345
|
+
}();
|
|
346
|
+
//# sourceMappingURL=windRender.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/wind/models/windRender.ts"],"names":["glUtils","drawFrag","drawVert","fullScreenFrag","fullScreenVert","updateFrag","updateVert","getColorRamp","colors","canvas","document","createElement","ctx","getContext","width","height","gradient","createLinearGradient","Object","keys","stop","addColorStop","fillStyle","fillRect","Uint8Array","getImageData","data","bindAttribute","gl","buffer","attribute","numComponents","bindBuffer","ARRAY_BUFFER","enableVertexAttribArray","vertexAttribPointer","FLOAT","bindFramebuffer","framebuffer","texture","FRAMEBUFFER","framebufferTexture2D","COLOR_ATTACHMENT0","TEXTURE_2D","Wind","options","glContext","imageWidth","imageHeight","fadeOpacity","speedFactor","dropRate","dropRateBump","rampColors","init","drawProgram","createProgram","fullScreenProgram","updateProgram","quadBuffer","createBuffer","Float32Array","createFramebuffer","colorRampTexture","createTexture","LINEAR","emptyPixels","backgroundTexture","NEAREST","screenTexture","particleRes","particleStateResolution","Math","ceil","sqrt","numParticles","numParticlesSize","particleState","i","length","floor","random","particleStateTexture0","particleStateTexture1","particleIndices","i$1","particleIndexBuffer","windData","windTexture","createDataTexture","image","num","uMin","uMax","vMin","vMax","isColorChanged","deleteTexture","item","key","Number","bindTexture","drawScreen","updateParticles","d","pixels","w","h","viewport","drawFullTexture","drawParticles","disable","BLEND","readPixels","RGBA","UNSIGNED_BYTE","temp","opacity","program","useProgram","a_pos","uniform1i","u_screen","uniform1f","u_opacity","drawArrays","TRIANGLES","a_index","u_wind","u_particles","u_color_ramp","u_particles_res","uniform2f","u_wind_min","u_wind_max","POINTS","u_rand_seed","u_wind_res","u_speed_factor","u_drop_rate","u_drop_rate_bump","deleteBuffer","deleteFramebuffer","deleteShader","vertexShader","fragmentShader","deleteProgram"],"mappings":";;;AAAA,OAAO,KAAKA,OAAZ,MAAyB,SAAzB;AACA,SACEC,QADF,EAEEC,QAFF,EAGEC,cAHF,EAIEC,cAJF,EAKEC,UALF,EAMEC,UANF,QAOO,cAPP;;AASA,SAASC,YAAT,CAAsBC,MAAtB,EAAyD;AACvD,MAAIC,MAAM,GAAGC,QAAQ,CAACC,aAAT,C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,KAAKlF,UAA1B;AACA,WAAK/B,EAAL,CAAQiH,YAAR,CAAqB,KAAKvD,mBAA1B;AAEA,WAAK1D,EAAL,CAAQkH,iBAAR,CAA0B,KAAKxG,WAA/B;AAGA,WAAKV,EAAL,CAAQmH,YAAR,CAAqB,KAAKxF,WAAL,CAAiByF,YAAtC;AAEA,WAAKpH,EAAL,CAAQmH,YAAR,CAAqB,KAAKxF,WAAL,CAAiB0F,cAAtC;AACA,WAAKrH,EAAL,CAAQsH,aAAR,CAAsB,KAAK3F,WAA3B;AAGA,WAAK3B,EAAL,CAAQmH,YAAR,CAAqB,KAAKtF,iBAAL,CAAuBuF,YAA5C;AAEA,WAAKpH,EAAL,CAAQmH,YAAR,CAAqB,KAAKtF,iBAAL,CAAuBwF,cAA5C;AACA,WAAKrH,EAAL,CAAQsH,aAAR,CAAsB,KAAKzF,iBAA3B;AAGA,WAAK7B,EAAL,CAAQmH,YAAR,CAAqB,KAAKrF,aAAL,CAAmBsF,YAAxC;AAEA,WAAKpH,EAAL,CAAQmH,YAAR,CAAqB,KAAKrF,aAAL,CAAmBuF,cAAxC;AACA,WAAKrH,EAAL,CAAQsH,aAAR,CAAsB,KAAKxF,aAA3B;AAEA,WAAK9B,EAAL,CAAQqE,aAAR,CAAsB,KAAKlC,gBAA3B;AACA,WAAKnC,EAAL,CAAQqE,aAAR,CAAsB,KAAK9B,iBAA3B;AACA,WAAKvC,EAAL,CAAQqE,aAAR,CAAsB,KAAK5B,aAA3B;AACA,WAAKzC,EAAL,CAAQqE,aAAR,CAAsB,KAAKf,qBAA3B;AACA,WAAKtD,EAAL,CAAQqE,aAAR,CAAsB,KAAKd,qBAA3B;AACA,WAAKvD,EAAL,CAAQqE,aAAR,CAAsB,KAAKT,WAA3B;AACD;AAtbH;;AAAA;AAAA","sourcesContent":["import * as glUtils from './utils';\nimport {\n drawFrag,\n drawVert,\n fullScreenFrag,\n fullScreenVert,\n updateFrag,\n updateVert,\n} from './windShader';\n\nfunction getColorRamp(colors: { [key: number]: string }) {\n let canvas = document.createElement('canvas') as HTMLCanvasElement;\n const ctx = canvas.getContext('2d') as CanvasRenderingContext2D;\n\n canvas.width = 256;\n canvas.height = 1;\n\n const gradient = ctx.createLinearGradient(0, 0, 256, 0);\n for (const stop of Object.keys(colors)) {\n gradient.addColorStop(+stop, colors[+stop]);\n }\n\n ctx.fillStyle = gradient;\n ctx.fillRect(0, 0, 256, 1);\n\n // @ts-ignore dispose canvas element\n canvas = null;\n\n return new Uint8Array(ctx.getImageData(0, 0, 256, 1).data);\n}\n\nfunction bindAttribute(\n gl: WebGLRenderingContext,\n buffer: any,\n attribute: any,\n numComponents: any,\n) {\n gl.bindBuffer(gl.ARRAY_BUFFER, buffer);\n gl.enableVertexAttribArray(attribute);\n gl.vertexAttribPointer(attribute, numComponents, gl.FLOAT, false, 0, 0);\n}\n\nfunction bindFramebuffer(\n gl: WebGLRenderingContext,\n framebuffer: any,\n texture: any,\n) {\n gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);\n if (texture) {\n gl.framebufferTexture2D(\n gl.FRAMEBUFFER,\n gl.COLOR_ATTACHMENT0,\n gl.TEXTURE_2D,\n texture,\n 0,\n );\n }\n}\n\nexport interface IWindData {\n uMin: number;\n uMax: number;\n vMin: number;\n vMax: number;\n image: HTMLImageElement;\n}\n\nexport interface IWind {\n width: number;\n height: number;\n\n fadeOpacity: number;\n speedFactor: number;\n dropRate: number;\n dropRateBump: number;\n\n setWind: (windData: IWindData) => void;\n draw: () => { d: Uint8Array; w: number; h: number };\n updateParticelNum: (num: number) => void;\n updateWindDir: (\n uMin: number,\n uMax: number,\n vMin: number,\n vMax: number,\n ) => void;\n updateColorRampTexture: (rampColors: { [key: number]: string }) => void;\n\n reSize: (width: number, height: number) => void;\n destroy: () => void;\n}\n\nexport interface IWindProps {\n glContext: WebGLRenderingContext;\n imageWidth: number;\n imageHeight: number;\n fadeOpacity: number;\n speedFactor: number;\n dropRate: number;\n dropRateBump: number;\n rampColors: { [key: number]: string };\n}\n\nexport class Wind {\n public width: number = 512;\n public height: number = 512;\n\n public pixels: Uint8Array;\n\n public fadeOpacity: number;\n public speedFactor: number;\n public dropRate: number;\n public dropRateBump: number;\n private gl: WebGLRenderingContext;\n private drawProgram: WebGLProgram;\n private fullScreenProgram: WebGLProgram;\n private updateProgram: WebGLProgram;\n\n private rampColors: { [key: number]: string };\n\n private numParticles: number = 65536;\n private numParticlesSize: number;\n private particleStateResolution: number;\n\n private quadBuffer: WebGLBuffer | null;\n private particleIndexBuffer: WebGLBuffer | null;\n\n private framebuffer: WebGLFramebuffer | null;\n\n private colorRampTexture: WebGLTexture | null;\n private backgroundTexture: WebGLTexture | null;\n private screenTexture: WebGLTexture | null;\n private particleStateTexture0: WebGLTexture | null;\n private particleStateTexture1: WebGLTexture | null;\n private windTexture: WebGLTexture | null;\n\n private windData: IWindData;\n\n constructor(options: IWindProps) {\n this.gl = options.glContext;\n this.width = options.imageWidth;\n this.height = options.imageHeight;\n this.fadeOpacity = options.fadeOpacity;\n this.speedFactor = options.speedFactor;\n this.dropRate = options.dropRate;\n this.dropRateBump = options.dropRateBump;\n\n this.rampColors = options.rampColors;\n this.init();\n }\n\n public init() {\n const gl = this.gl;\n\n this.fadeOpacity = 0.996; // how fast the particle trails fade on each frame\n this.speedFactor = 0.25; // how fast the particles move\n this.dropRate = 0.003; // how often the particles move to a random place\n this.dropRateBump = 0.01; // drop rate increase relative to individual particle speed\n\n this.drawProgram = glUtils.createProgram(gl, drawVert, drawFrag);\n this.fullScreenProgram = glUtils.createProgram(\n gl,\n fullScreenVert,\n fullScreenFrag,\n );\n this.updateProgram = glUtils.createProgram(gl, updateVert, updateFrag);\n\n this.quadBuffer = glUtils.createBuffer(\n gl,\n new Float32Array([0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]),\n );\n\n this.framebuffer = gl.createFramebuffer();\n\n this.colorRampTexture = glUtils.createTexture(\n this.gl,\n this.gl.LINEAR,\n getColorRamp(this.rampColors),\n 16,\n 16,\n );\n\n const emptyPixels = new Uint8Array(this.width * this.height * 4);\n\n // screen textures to hold the drawn screen for the previous and the current frame\n\n this.backgroundTexture = glUtils.createTexture(\n gl,\n gl.NEAREST,\n emptyPixels,\n this.width,\n this.height,\n );\n this.screenTexture = glUtils.createTexture(\n gl,\n gl.NEAREST,\n emptyPixels,\n this.width,\n this.height,\n );\n\n // we create a square texture where each pixel will hold a particle position encoded as RGBA\n const particleRes = (this.particleStateResolution = Math.ceil(\n Math.sqrt(this.numParticles),\n ));\n // particleRes size\n this.numParticlesSize = particleRes * particleRes;\n\n const particleState = new Uint8Array(this.numParticlesSize * 4);\n for (let i = 0; i < particleState.length; i++) {\n particleState[i] = Math.floor(Math.random() * 256); // randomize the initial particle positions\n }\n // textures to hold the particle state for the current and the next frame\n this.particleStateTexture0 = glUtils.createTexture(\n gl,\n gl.NEAREST,\n particleState,\n particleRes,\n particleRes,\n );\n this.particleStateTexture1 = glUtils.createTexture(\n gl,\n gl.NEAREST,\n particleState,\n particleRes,\n particleRes,\n );\n\n const particleIndices = new Float32Array(this.numParticlesSize);\n for (let i$1 = 0; i$1 < this.numParticlesSize; i$1++) {\n particleIndices[i$1] = i$1;\n }\n this.particleIndexBuffer = glUtils.createBuffer(gl, particleIndices);\n }\n\n public setWind(windData: IWindData) {\n this.windData = windData;\n this.windTexture = glUtils.createDataTexture(\n this.gl,\n this.gl.LINEAR,\n windData.image,\n );\n }\n\n /**\n * 更新风场粒子数量\n * @param num\n */\n public updateParticelNum(num: number) {\n const gl = this.gl;\n if (num !== this.numParticles) {\n this.numParticles = num; // params number\n\n // we create a square texture where each pixel will hold a particle position encoded as RGBA\n const particleRes = (this.particleStateResolution = Math.ceil(\n Math.sqrt(this.numParticles),\n ));\n this.numParticlesSize = particleRes * particleRes;\n\n const particleState = new Uint8Array(this.numParticlesSize * 4);\n for (let i = 0; i < particleState.length; i++) {\n particleState[i] = Math.floor(Math.random() * 256); // randomize the initial particle positions\n }\n // textures to hold the particle state for the current and the next frame\n this.particleStateTexture0 = glUtils.createTexture(\n gl,\n gl.NEAREST,\n particleState,\n particleRes,\n particleRes,\n );\n this.particleStateTexture1 = glUtils.createTexture(\n gl,\n gl.NEAREST,\n particleState,\n particleRes,\n particleRes,\n );\n\n const particleIndices = new Float32Array(this.numParticlesSize);\n for (let i$1 = 0; i$1 < this.numParticlesSize; i$1++) {\n particleIndices[i$1] = i$1;\n }\n this.particleIndexBuffer = glUtils.createBuffer(gl, particleIndices);\n }\n }\n\n /**\n * 更新风场风向风速\n * @param uMin\n * @param uMax\n * @param vMin\n * @param vMax\n */\n public updateWindDir(uMin: number, uMax: number, vMin: number, vMax: number) {\n this.windData.uMin = uMin;\n this.windData.uMax = uMax;\n this.windData.vMin = vMin;\n this.windData.vMax = vMax;\n }\n\n /**\n * update rampColors\n * @param rampColors\n */\n public updateColorRampTexture(rampColors: { [key: number]: string }) {\n if (this.isColorChanged(rampColors)) {\n this.rampColors = rampColors;\n\n const gl = this.gl;\n gl.deleteTexture(this.colorRampTexture);\n this.colorRampTexture = glUtils.createTexture(\n gl,\n gl.LINEAR,\n getColorRamp(rampColors),\n 16,\n 16,\n );\n }\n }\n\n public isColorChanged(rampColors: { [key: number]: string }): boolean {\n const keys = Object.keys(rampColors);\n for (const item of keys) {\n const key = Number(item);\n // exist new key -> color need update\n if (!this.rampColors[key]) {\n return true;\n }\n // value changed -> color need update\n if (this.rampColors[key] && this.rampColors[key] !== rampColors[key]) {\n return true;\n }\n }\n return false;\n }\n\n public reSize(width: number, height: number) {\n if (width !== this.width || height !== this.height) {\n const gl = this.gl;\n gl.deleteTexture(this.backgroundTexture);\n gl.deleteTexture(this.screenTexture);\n\n this.width = width;\n this.height = height;\n const emptyPixels = new Uint8Array(width * height * 4);\n // screen textures to hold the drawn screen for the previous and the current frame\n this.backgroundTexture = glUtils.createTexture(\n gl,\n gl.NEAREST,\n emptyPixels,\n width,\n height,\n );\n this.screenTexture = glUtils.createTexture(\n gl,\n gl.NEAREST,\n emptyPixels,\n width,\n height,\n );\n }\n }\n\n public draw() {\n if (this.windData?.image) {\n const gl = this.gl;\n\n glUtils.bindTexture(gl, this.windTexture, 0);\n glUtils.bindTexture(gl, this.particleStateTexture0, 1);\n\n this.drawScreen(); // draw Particles into framebuffer\n this.updateParticles();\n\n return { d: this.pixels, w: this.width, h: this.height };\n } else {\n return { d: new Uint8Array([0, 0, 0, 0]), w: 1, h: 1 };\n }\n }\n\n public drawScreen() {\n const gl = this.gl;\n\n // draw the screen into a temporary framebuffer to retain it as the background on the next frame\n bindFramebuffer(gl, this.framebuffer, this.screenTexture);\n\n gl.viewport(0, 0, this.width, this.height);\n\n this.drawFullTexture(this.backgroundTexture, this.fadeOpacity);\n this.drawParticles();\n\n gl.disable(gl.BLEND);\n\n this.pixels = new Uint8Array(4 * this.width * this.height);\n gl.readPixels(\n 0,\n 0,\n this.width,\n this.height,\n gl.RGBA,\n gl.UNSIGNED_BYTE,\n this.pixels,\n );\n\n bindFramebuffer(gl, null, null);\n gl.viewport(0, 0, this.gl.canvas.width, this.gl.canvas.height);\n\n // save the current screen as the background for the next frame\n const temp = this.backgroundTexture;\n this.backgroundTexture = this.screenTexture;\n this.screenTexture = temp;\n }\n\n public drawFullTexture(texture: any, opacity: number) {\n const gl = this.gl;\n const program = this.fullScreenProgram as any;\n gl.useProgram(program);\n\n // bindAttribute(gl, this.quadBuffer, program.a_pos, 2);\n\n gl.bindBuffer(gl.ARRAY_BUFFER, this.quadBuffer);\n gl.vertexAttribPointer(program.a_pos, 2, gl.FLOAT, false, 0, 0);\n gl.enableVertexAttribArray(program.a_pos);\n\n gl.bindBuffer(gl.ARRAY_BUFFER, null);\n\n glUtils.bindTexture(gl, texture, 2);\n gl.uniform1i(program.u_screen, 2);\n gl.uniform1f(program.u_opacity, opacity);\n\n gl.drawArrays(gl.TRIANGLES, 0, 6);\n // gl.drawArrays(gl.POINTS, 0, 6);\n }\n\n public drawParticles() {\n const gl = this.gl;\n const program = this.drawProgram as any;\n gl.useProgram(program);\n\n bindAttribute(gl, this.particleIndexBuffer, program.a_index, 1);\n glUtils.bindTexture(gl, this.colorRampTexture, 2);\n\n gl.uniform1i(program.u_wind, 0);\n gl.uniform1i(program.u_particles, 1);\n gl.uniform1i(program.u_color_ramp, 2);\n\n gl.uniform1f(program.u_particles_res, this.particleStateResolution);\n gl.uniform2f(program.u_wind_min, this.windData.uMin, this.windData.vMin);\n gl.uniform2f(program.u_wind_max, this.windData.uMax, this.windData.vMax);\n\n gl.drawArrays(gl.POINTS, 0, this.numParticlesSize);\n }\n\n public updateParticles() {\n const gl = this.gl;\n bindFramebuffer(gl, this.framebuffer, this.particleStateTexture1);\n gl.viewport(\n 0,\n 0,\n this.particleStateResolution,\n this.particleStateResolution,\n );\n\n const program = this.updateProgram as any;\n gl.useProgram(program);\n\n bindAttribute(gl, this.quadBuffer, program.a_pos, 2);\n\n gl.uniform1i(program.u_wind, 0);\n gl.uniform1i(program.u_particles, 1);\n\n gl.uniform1f(program.u_rand_seed, Math.random());\n gl.uniform2f(\n program.u_wind_res,\n this.windData.image.width * 2,\n this.windData.image.height * 2,\n );\n gl.uniform2f(program.u_wind_min, this.windData.uMin, this.windData.vMin);\n gl.uniform2f(program.u_wind_max, this.windData.uMax, this.windData.vMax);\n gl.uniform1f(program.u_speed_factor, this.speedFactor);\n gl.uniform1f(program.u_drop_rate, this.dropRate);\n gl.uniform1f(program.u_drop_rate_bump, this.dropRateBump);\n\n gl.drawArrays(gl.TRIANGLES, 0, 6);\n\n // swap the particle state textures so the new one becomes the current one\n const temp = this.particleStateTexture0;\n this.particleStateTexture0 = this.particleStateTexture1;\n this.particleStateTexture1 = temp;\n\n bindFramebuffer(gl, null, null);\n\n // gl.viewport(0, 0, this.gl.canvas.width, this.gl.canvas.height);\n }\n\n public destroy() {\n // private drawProgram: WebGLProgram;\n // private fullScreenProgram: WebGLProgram;\n // private updateProgram: WebGLProgram;\n\n // private quadBuffer: WebGLBuffer | null;\n // private particleIndexBuffer: WebGLBuffer | null;\n\n // private framebuffer: WebGLFramebuffer | null;\n\n // private colorRampTexture: WebGLTexture | null;\n // private backgroundTexture: WebGLTexture | null;\n // private screenTexture: WebGLTexture | null;\n // private particleStateTexture0: WebGLTexture | null;\n // private particleStateTexture1: WebGLTexture | null;\n // private windTexture: WebGLTexture | null;\n\n this.gl.deleteBuffer(this.quadBuffer);\n this.gl.deleteBuffer(this.particleIndexBuffer);\n\n this.gl.deleteFramebuffer(this.framebuffer);\n\n // @ts-ignore\n this.gl.deleteShader(this.drawProgram.vertexShader);\n // @ts-ignore\n this.gl.deleteShader(this.drawProgram.fragmentShader);\n this.gl.deleteProgram(this.drawProgram);\n\n // @ts-ignore\n this.gl.deleteShader(this.fullScreenProgram.vertexShader);\n // @ts-ignore\n this.gl.deleteShader(this.fullScreenProgram.fragmentShader);\n this.gl.deleteProgram(this.fullScreenProgram);\n\n // @ts-ignore\n this.gl.deleteShader(this.updateProgram.vertexShader);\n // @ts-ignore\n this.gl.deleteShader(this.updateProgram.fragmentShader);\n this.gl.deleteProgram(this.updateProgram);\n\n this.gl.deleteTexture(this.colorRampTexture);\n this.gl.deleteTexture(this.backgroundTexture);\n this.gl.deleteTexture(this.screenTexture);\n this.gl.deleteTexture(this.particleStateTexture0);\n this.gl.deleteTexture(this.particleStateTexture1);\n this.gl.deleteTexture(this.windTexture);\n }\n}\n"],"file":"windRender.js"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* drawProgram drawVert drawFrag
|
|
3
|
+
* screenProgram screenVert screenFrag
|
|
4
|
+
* updateProgram updateVert updateFrag
|
|
5
|
+
* fullScreenProgram fullScreenVert fullScreenFrag
|
|
6
|
+
*/
|
|
7
|
+
export declare const drawVert = "\n precision mediump float;\n \n attribute float a_index;\n \n uniform sampler2D u_particles;\n uniform float u_particles_res;\n \n varying vec2 v_particle_pos;\n \n void main() {\n vec4 color = texture2D(u_particles, vec2(\n fract(a_index / u_particles_res),\n floor(a_index / u_particles_res) / u_particles_res)\n );\n \n // decode current particle position from the pixel's RGBA value\n v_particle_pos = vec2( color.r / 255.0 + color.b, color.g / 255.0 + color.a);\n \n gl_PointSize = 1.0;\n gl_Position = vec4(2.0 * v_particle_pos.x - 1.0, 1.0 - 2.0 * v_particle_pos.y, 0, 1);\n }";
|
|
8
|
+
export declare const drawFrag = "\n precision mediump float;\n \n uniform sampler2D u_wind;\n uniform vec2 u_wind_min;\n uniform vec2 u_wind_max;\n uniform sampler2D u_color_ramp;\n \n varying vec2 v_particle_pos;\n \n void main() {\n vec2 velocity = mix(u_wind_min, u_wind_max, texture2D(u_wind, v_particle_pos).rg);\n float speed_t = length(velocity) / length(u_wind_max);\n \n // color ramp is encoded in a 16x16 texture \n vec2 ramp_pos = vec2( fract(16.0 * speed_t), floor(16.0 * speed_t) / 16.0); \n \n gl_FragColor = texture2D(u_color_ramp, ramp_pos);\n }";
|
|
9
|
+
export declare const updateVert = "\n precision mediump float;\n \n attribute vec2 a_pos;\n \n varying vec2 v_tex_pos;\n \n void main() {\n v_tex_pos = a_pos;\n gl_Position = vec4(1.0 - 2.0 * a_pos, 0, 1);\n // framebuffer \u59CB\u7EC8\u7528\u94FA\u6EE1\u5C4F\u5E55\u7684 texture\n }";
|
|
10
|
+
export declare const updateFrag = "\n precision highp float;\n \n uniform sampler2D u_particles;\n uniform sampler2D u_wind;\n uniform vec2 u_wind_res;\n uniform vec2 u_wind_min;\n uniform vec2 u_wind_max;\n uniform float u_rand_seed;\n uniform float u_speed_factor;\n uniform float u_drop_rate;\n uniform float u_drop_rate_bump;\n \n varying vec2 v_tex_pos;\n \n // pseudo-random generator\n const vec3 rand_constants = vec3(12.9898, 78.233, 4375.85453);\n float rand(const vec2 co) {\n float t = dot(rand_constants.xy, co);\n return fract(sin(t) * (rand_constants.z + t));\n }\n \n // wind speed lookup; use manual bilinear filtering based on 4 adjacent pixels for smooth interpolation\n vec2 lookup_wind(const vec2 uv) {\n // return texture2D(u_wind, uv).rg; // lower-res hardware filtering\n vec2 px = 1.0 / u_wind_res;\n vec2 vc = (floor(uv * u_wind_res)) * px;\n vec2 f = fract(uv * u_wind_res);\n vec2 tl = texture2D(u_wind, vc).rg;\n vec2 tr = texture2D(u_wind, vc + vec2(px.x, 0)).rg;\n vec2 bl = texture2D(u_wind, vc + vec2(0, px.y)).rg;\n vec2 br = texture2D(u_wind, vc + px).rg;\n return mix(mix(tl, tr, f.x), mix(bl, br, f.x), f.y);\n }\n \n void main() {\n vec4 color = texture2D(u_particles, v_tex_pos);\n vec2 pos = vec2(\n color.r / 255.0 + color.b,\n color.g / 255.0 + color.a); // decode particle position from pixel RGBA\n vec2 velocity = mix(u_wind_min, u_wind_max, lookup_wind(pos));\n float speed_t = length(velocity) / length(u_wind_max);\n \n // take EPSG:4236 distortion into account for calculating where the particle moved\n float distortion = cos(radians(pos.y * 180.0 - 90.0));\n vec2 offset = vec2(velocity.x / distortion, -velocity.y) * 0.0001 * u_speed_factor;\n \n // update particle position, wrapping around the date line\n pos = fract(1.0 + pos + offset);\n \n // a random seed to use for the particle drop\n vec2 seed = (pos + v_tex_pos) * u_rand_seed;\n \n // drop rate is a chance a particle will restart at random position, to avoid degeneration\n float drop_rate = u_drop_rate + speed_t * u_drop_rate_bump;\n float drop = step(1.0 - drop_rate, rand(seed));\n \n vec2 random_pos = vec2(\n rand(seed + 1.3),\n rand(seed + 2.1));\n pos = mix(pos, random_pos, drop);\n \n // encode the new particle position back into RGBA\n gl_FragColor = vec4(\n fract(pos * 255.0),\n floor(pos * 255.0) / 255.0);\n }";
|
|
11
|
+
export declare const fullScreenVert = "\n precision mediump float;\n \n attribute vec2 a_pos;\n \n varying vec2 v_tex_pos;\n \n void main() {\n v_tex_pos = a_pos;\n gl_Position = vec4(1.0 - 2.0 * a_pos, 0.0, 1.0);\n gl_PointSize = 100.0;\n }";
|
|
12
|
+
export declare const fullScreenFrag = "\n precision mediump float;\n \n uniform sampler2D u_screen;\n uniform float u_opacity;\n varying vec2 v_tex_pos;\n \n void main() {\n vec4 color = texture2D(u_screen, 1.0 - v_tex_pos);\n \n // a hack to guarantee opacity fade out even with a value close to 1.0\n gl_FragColor = vec4(floor(255.0 * color * u_opacity) / 255.0);\n }";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export var drawVert = "\n precision mediump float;\n \n attribute float a_index;\n \n uniform sampler2D u_particles;\n uniform float u_particles_res;\n \n varying vec2 v_particle_pos;\n \n void main() {\n vec4 color = texture2D(u_particles, vec2(\n fract(a_index / u_particles_res),\n floor(a_index / u_particles_res) / u_particles_res)\n );\n \n // decode current particle position from the pixel's RGBA value\n v_particle_pos = vec2( color.r / 255.0 + color.b, color.g / 255.0 + color.a);\n \n gl_PointSize = 1.0;\n gl_Position = vec4(2.0 * v_particle_pos.x - 1.0, 1.0 - 2.0 * v_particle_pos.y, 0, 1);\n }";
|
|
2
|
+
export var drawFrag = "\n precision mediump float;\n \n uniform sampler2D u_wind;\n uniform vec2 u_wind_min;\n uniform vec2 u_wind_max;\n uniform sampler2D u_color_ramp;\n \n varying vec2 v_particle_pos;\n \n void main() {\n vec2 velocity = mix(u_wind_min, u_wind_max, texture2D(u_wind, v_particle_pos).rg);\n float speed_t = length(velocity) / length(u_wind_max);\n \n // color ramp is encoded in a 16x16 texture \n vec2 ramp_pos = vec2( fract(16.0 * speed_t), floor(16.0 * speed_t) / 16.0); \n \n gl_FragColor = texture2D(u_color_ramp, ramp_pos);\n }";
|
|
3
|
+
export var updateVert = "\n precision mediump float;\n \n attribute vec2 a_pos;\n \n varying vec2 v_tex_pos;\n \n void main() {\n v_tex_pos = a_pos;\n gl_Position = vec4(1.0 - 2.0 * a_pos, 0, 1);\n // framebuffer \u59CB\u7EC8\u7528\u94FA\u6EE1\u5C4F\u5E55\u7684 texture\n }";
|
|
4
|
+
export var updateFrag = "\n precision highp float;\n \n uniform sampler2D u_particles;\n uniform sampler2D u_wind;\n uniform vec2 u_wind_res;\n uniform vec2 u_wind_min;\n uniform vec2 u_wind_max;\n uniform float u_rand_seed;\n uniform float u_speed_factor;\n uniform float u_drop_rate;\n uniform float u_drop_rate_bump;\n \n varying vec2 v_tex_pos;\n \n // pseudo-random generator\n const vec3 rand_constants = vec3(12.9898, 78.233, 4375.85453);\n float rand(const vec2 co) {\n float t = dot(rand_constants.xy, co);\n return fract(sin(t) * (rand_constants.z + t));\n }\n \n // wind speed lookup; use manual bilinear filtering based on 4 adjacent pixels for smooth interpolation\n vec2 lookup_wind(const vec2 uv) {\n // return texture2D(u_wind, uv).rg; // lower-res hardware filtering\n vec2 px = 1.0 / u_wind_res;\n vec2 vc = (floor(uv * u_wind_res)) * px;\n vec2 f = fract(uv * u_wind_res);\n vec2 tl = texture2D(u_wind, vc).rg;\n vec2 tr = texture2D(u_wind, vc + vec2(px.x, 0)).rg;\n vec2 bl = texture2D(u_wind, vc + vec2(0, px.y)).rg;\n vec2 br = texture2D(u_wind, vc + px).rg;\n return mix(mix(tl, tr, f.x), mix(bl, br, f.x), f.y);\n }\n \n void main() {\n vec4 color = texture2D(u_particles, v_tex_pos);\n vec2 pos = vec2(\n color.r / 255.0 + color.b,\n color.g / 255.0 + color.a); // decode particle position from pixel RGBA\n vec2 velocity = mix(u_wind_min, u_wind_max, lookup_wind(pos));\n float speed_t = length(velocity) / length(u_wind_max);\n \n // take EPSG:4236 distortion into account for calculating where the particle moved\n float distortion = cos(radians(pos.y * 180.0 - 90.0));\n vec2 offset = vec2(velocity.x / distortion, -velocity.y) * 0.0001 * u_speed_factor;\n \n // update particle position, wrapping around the date line\n pos = fract(1.0 + pos + offset);\n \n // a random seed to use for the particle drop\n vec2 seed = (pos + v_tex_pos) * u_rand_seed;\n \n // drop rate is a chance a particle will restart at random position, to avoid degeneration\n float drop_rate = u_drop_rate + speed_t * u_drop_rate_bump;\n float drop = step(1.0 - drop_rate, rand(seed));\n \n vec2 random_pos = vec2(\n rand(seed + 1.3),\n rand(seed + 2.1));\n pos = mix(pos, random_pos, drop);\n \n // encode the new particle position back into RGBA\n gl_FragColor = vec4(\n fract(pos * 255.0),\n floor(pos * 255.0) / 255.0);\n }";
|
|
5
|
+
export var fullScreenVert = "\n precision mediump float;\n \n attribute vec2 a_pos;\n \n varying vec2 v_tex_pos;\n \n void main() {\n v_tex_pos = a_pos;\n gl_Position = vec4(1.0 - 2.0 * a_pos, 0.0, 1.0);\n gl_PointSize = 100.0;\n }";
|
|
6
|
+
export var fullScreenFrag = "\n precision mediump float;\n \n uniform sampler2D u_screen;\n uniform float u_opacity;\n varying vec2 v_tex_pos;\n \n void main() {\n vec4 color = texture2D(u_screen, 1.0 - v_tex_pos);\n \n // a hack to guarantee opacity fade out even with a value close to 1.0\n gl_FragColor = vec4(floor(255.0 * color * u_opacity) / 255.0);\n }";
|
|
7
|
+
//# sourceMappingURL=windShader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/wind/models/windShader.ts"],"names":["drawVert","drawFrag","updateVert","updateFrag","fullScreenVert","fullScreenFrag"],"mappings":"AAMA,OAAO,IAAMA,QAAQ,4pBAAd;AAuBP,OAAO,IAAMC,QAAQ,kjBAAd;AAoBP,OAAO,IAAMC,UAAU,yQAAhB;AAaP,OAAO,IAAMC,UAAU,k9EAAhB;AAoEP,OAAO,IAAMC,cAAc,mQAApB;AAaP,OAAO,IAAMC,cAAc,+VAApB","sourcesContent":["/**\n * drawProgram drawVert drawFrag\n * screenProgram screenVert screenFrag\n * updateProgram updateVert updateFrag\n * fullScreenProgram fullScreenVert fullScreenFrag\n */\nexport const drawVert = `\n precision mediump float;\n \n attribute float a_index;\n \n uniform sampler2D u_particles;\n uniform float u_particles_res;\n \n varying vec2 v_particle_pos;\n \n void main() {\n vec4 color = texture2D(u_particles, vec2(\n fract(a_index / u_particles_res),\n floor(a_index / u_particles_res) / u_particles_res)\n );\n \n // decode current particle position from the pixel's RGBA value\n v_particle_pos = vec2( color.r / 255.0 + color.b, color.g / 255.0 + color.a);\n \n gl_PointSize = 1.0;\n gl_Position = vec4(2.0 * v_particle_pos.x - 1.0, 1.0 - 2.0 * v_particle_pos.y, 0, 1);\n }`;\n\nexport const drawFrag = `\n precision mediump float;\n \n uniform sampler2D u_wind;\n uniform vec2 u_wind_min;\n uniform vec2 u_wind_max;\n uniform sampler2D u_color_ramp;\n \n varying vec2 v_particle_pos;\n \n void main() {\n vec2 velocity = mix(u_wind_min, u_wind_max, texture2D(u_wind, v_particle_pos).rg);\n float speed_t = length(velocity) / length(u_wind_max);\n \n // color ramp is encoded in a 16x16 texture \n vec2 ramp_pos = vec2( fract(16.0 * speed_t), floor(16.0 * speed_t) / 16.0); \n \n gl_FragColor = texture2D(u_color_ramp, ramp_pos);\n }`;\n\nexport const updateVert = `\n precision mediump float;\n \n attribute vec2 a_pos;\n \n varying vec2 v_tex_pos;\n \n void main() {\n v_tex_pos = a_pos;\n gl_Position = vec4(1.0 - 2.0 * a_pos, 0, 1);\n // framebuffer 始终用铺满屏幕的 texture\n }`;\n\nexport const updateFrag = `\n precision highp float;\n \n uniform sampler2D u_particles;\n uniform sampler2D u_wind;\n uniform vec2 u_wind_res;\n uniform vec2 u_wind_min;\n uniform vec2 u_wind_max;\n uniform float u_rand_seed;\n uniform float u_speed_factor;\n uniform float u_drop_rate;\n uniform float u_drop_rate_bump;\n \n varying vec2 v_tex_pos;\n \n // pseudo-random generator\n const vec3 rand_constants = vec3(12.9898, 78.233, 4375.85453);\n float rand(const vec2 co) {\n float t = dot(rand_constants.xy, co);\n return fract(sin(t) * (rand_constants.z + t));\n }\n \n // wind speed lookup; use manual bilinear filtering based on 4 adjacent pixels for smooth interpolation\n vec2 lookup_wind(const vec2 uv) {\n // return texture2D(u_wind, uv).rg; // lower-res hardware filtering\n vec2 px = 1.0 / u_wind_res;\n vec2 vc = (floor(uv * u_wind_res)) * px;\n vec2 f = fract(uv * u_wind_res);\n vec2 tl = texture2D(u_wind, vc).rg;\n vec2 tr = texture2D(u_wind, vc + vec2(px.x, 0)).rg;\n vec2 bl = texture2D(u_wind, vc + vec2(0, px.y)).rg;\n vec2 br = texture2D(u_wind, vc + px).rg;\n return mix(mix(tl, tr, f.x), mix(bl, br, f.x), f.y);\n }\n \n void main() {\n vec4 color = texture2D(u_particles, v_tex_pos);\n vec2 pos = vec2(\n color.r / 255.0 + color.b,\n color.g / 255.0 + color.a); // decode particle position from pixel RGBA\n vec2 velocity = mix(u_wind_min, u_wind_max, lookup_wind(pos));\n float speed_t = length(velocity) / length(u_wind_max);\n \n // take EPSG:4236 distortion into account for calculating where the particle moved\n float distortion = cos(radians(pos.y * 180.0 - 90.0));\n vec2 offset = vec2(velocity.x / distortion, -velocity.y) * 0.0001 * u_speed_factor;\n \n // update particle position, wrapping around the date line\n pos = fract(1.0 + pos + offset);\n \n // a random seed to use for the particle drop\n vec2 seed = (pos + v_tex_pos) * u_rand_seed;\n \n // drop rate is a chance a particle will restart at random position, to avoid degeneration\n float drop_rate = u_drop_rate + speed_t * u_drop_rate_bump;\n float drop = step(1.0 - drop_rate, rand(seed));\n \n vec2 random_pos = vec2(\n rand(seed + 1.3),\n rand(seed + 2.1));\n pos = mix(pos, random_pos, drop);\n \n // encode the new particle position back into RGBA\n gl_FragColor = vec4(\n fract(pos * 255.0),\n floor(pos * 255.0) / 255.0);\n }`;\n\nexport const fullScreenVert = `\n precision mediump float;\n \n attribute vec2 a_pos;\n \n varying vec2 v_tex_pos;\n \n void main() {\n v_tex_pos = a_pos;\n gl_Position = vec4(1.0 - 2.0 * a_pos, 0.0, 1.0);\n gl_PointSize = 100.0;\n }`;\n\nexport const fullScreenFrag = `\n precision mediump float;\n \n uniform sampler2D u_screen;\n uniform float u_opacity;\n varying vec2 v_tex_pos;\n \n void main() {\n vec4 color = texture2D(u_screen, 1.0 - v_tex_pos);\n \n // a hack to guarantee opacity fade out even with a value close to 1.0\n gl_FragColor = vec4(floor(255.0 * color * u_opacity) / 255.0);\n }`;\n"],"file":"windShader.js"}
|
package/lib/core/BaseLayer.js
CHANGED
|
@@ -672,11 +672,15 @@ var BaseLayer = (_dec = (0, _l7Core.lazyInject)(_l7Core.TYPES.IGlobalConfigServi
|
|
|
672
672
|
}, {
|
|
673
673
|
key: "destroy",
|
|
674
674
|
value: function destroy() {
|
|
675
|
+
var _this$layerModel;
|
|
676
|
+
|
|
675
677
|
this.hooks.beforeDestroy.call();
|
|
676
678
|
this.layerSource.off('update', this.sourceEvent);
|
|
677
679
|
this.multiPassRenderer.destroy();
|
|
678
680
|
this.styleAttributeService.clearAllAttributes();
|
|
679
681
|
this.hooks.afterDestroy.call();
|
|
682
|
+
(_this$layerModel = this.layerModel) === null || _this$layerModel === void 0 ? void 0 : _this$layerModel.clearModels();
|
|
683
|
+
this.encodedData = null;
|
|
680
684
|
this.emit('remove', {
|
|
681
685
|
target: this,
|
|
682
686
|
type: 'remove'
|