@pirireis/webglobeplugins 0.0.1
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/arrowfield/adaptor.js +11 -0
- package/arrowfield/index.js +4 -0
- package/arrowfield/plugin.js +128 -0
- package/compassrose/compassrose.js +394 -0
- package/compassrose/index.js +2 -0
- package/heatwavemaps/index.js +4 -0
- package/heatwavemaps/isobar/objectarraylabels.js +247 -0
- package/heatwavemaps/isobar/plugin.js +337 -0
- package/heatwavemaps/isobar/quadtreecontours.js +338 -0
- package/heatwavemaps/plugins/heatwaveglobeshell.js +257 -0
- package/index.js +8 -0
- package/package.json +7 -0
- package/programs/arrowfield/index.js +2 -0
- package/programs/arrowfield/logic.js +284 -0
- package/programs/arrowfield/object.js +89 -0
- package/programs/float2legendwithratio/index.js +3 -0
- package/programs/float2legendwithratio/logic.js +189 -0
- package/programs/float2legendwithratio/object.js +132 -0
- package/programs/globeshell/index.js +2 -0
- package/programs/globeshell/noise/noises.js +0 -0
- package/programs/globeshell/wiggle/index.js +6 -0
- package/programs/globeshell/wiggle/logic.js +374 -0
- package/programs/globeshell/wiggle/object.js +94 -0
- package/programs/helpers/blender/index.js +0 -0
- package/programs/helpers/blender/program.js +91 -0
- package/programs/helpers/fadeaway/index.js +3 -0
- package/programs/helpers/fadeaway/logic.js +76 -0
- package/programs/helpers/fadeaway/object.js +20 -0
- package/programs/helpers/index.js +2 -0
- package/programs/index.js +21 -0
- package/programs/programcache.js +119 -0
- package/programs/rings/distancering/circleflatprogram.js +135 -0
- package/programs/rings/distancering/circlepaddysharedbuffer.js +502 -0
- package/programs/rings/distancering/index.js +5 -0
- package/programs/rings/distancering/paddyflatprogram.js +131 -0
- package/programs/rings/distancering/shader.js +0 -0
- package/programs/rings/index.js +9 -0
- package/programs/totems/camerauniformblock.js +129 -0
- package/programs/totems/index.js +2 -0
- package/programs/util.js +17 -0
- package/programs/vectorfields/index.js +3 -0
- package/programs/vectorfields/logics/drawrectangleparticles.js +125 -0
- package/programs/vectorfields/logics/index.js +5 -0
- package/programs/vectorfields/logics/pixelbased.js +161 -0
- package/programs/vectorfields/logics/ubo.js +64 -0
- package/programs/vectorfields/pingpongbuffermanager.js +80 -0
- package/rangerings/index.js +3 -0
- package/rangerings/rangerings.js +88 -0
- package/timetracks/adaptors.js +133 -0
- package/timetracks/index.js +3 -0
- package/timetracks/plugin.js +304 -0
- package/timetracks/program.js +850 -0
- package/timetracks/programpoint.js +168 -0
- package/util/datamanager/datamanager.js +168 -0
- package/util/datamanager/index.js +3 -0
- package/util/datamanager/pointcoordinatesdatacalculator.js +133 -0
- package/util/datamanager/pointcoordsmeta.js +22 -0
- package/util/geometry/geodatafromtexture.js +52 -0
- package/util/geometry/index.js +44 -0
- package/util/index.js +13 -0
- package/util/jshelpers/index.js +1 -0
- package/util/jshelpers/timefilters.js +32 -0
- package/util/jshelpers/timemethods.js +19 -0
- package/util/programs/index.js +2 -0
- package/util/programs/shapesonglobe.js +248 -0
- package/util/programs/supersampletotextures.js +142 -0
- package/util/programs/texturetoglobe.js +203 -0
- package/util/shaderfunctions/geometrytransformations.js +129 -0
- package/util/shaderfunctions/index.js +2 -0
- package/util/shaderfunctions/nodata.js +10 -0
- package/util/shaderfunctions/noisefunctions.js +44 -0
- package/util/webglobe/gldefaultstates.js +4 -0
- package/util/webglobe/index.js +2 -0
- package/util/webglobe/rasteroverlay.js +96 -0
- package/util/webglobjectbuilders.js +256 -0
- package/waveparticles/adaptor.js +16 -0
- package/waveparticles/index.js +4 -0
- package/waveparticles/plugin.js +281 -0
- package/wind/imagetovectorfieldandmagnitude.js +39 -0
- package/wind/index.js +7 -0
- package/wind/plugin.js +1032 -0
- package/wind/vectorfieldimage.js +27 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
export const CameraUniformBlockString = `
|
|
2
|
+
layout(std140) uniform CameraUniformBlock {
|
|
3
|
+
mat4 view; // 64 bytes 0
|
|
4
|
+
mat4 projection; // 64 bytes 64
|
|
5
|
+
vec3 translate; // 12 bytes 128
|
|
6
|
+
bool is3D; // 4 bytes 140
|
|
7
|
+
vec2 mapWH; // 8 bytes 144
|
|
8
|
+
vec2 screenWH; // 8 bytes 152
|
|
9
|
+
float z_level; // 4 bytes 160 | 164
|
|
10
|
+
}; // 11 lines
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export default class
|
|
16
|
+
|
|
17
|
+
CameraUniformBlockTotem {
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
constructor() {
|
|
21
|
+
this.id = "CameraUniformBlockTotem"
|
|
22
|
+
this.description = `Sets a uniform block and provides buffer for it. The following is the glsl uniform block:` + CameraUniformBlockString;
|
|
23
|
+
this.gl = null;
|
|
24
|
+
this.globe = null;
|
|
25
|
+
this.ubo = null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
init(globe, gl) {
|
|
30
|
+
this.gl = gl;
|
|
31
|
+
this.globe = globe;
|
|
32
|
+
this.ubo = this._createUBO();
|
|
33
|
+
this.traslateFloat32 = new Float32Array(3);
|
|
34
|
+
this.mapWHFloat32 = new Float32Array(2);
|
|
35
|
+
this.setGeometry();
|
|
36
|
+
this.resize();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
_createUBO() {
|
|
41
|
+
const { gl } = this;
|
|
42
|
+
const ubo = gl.createBuffer();
|
|
43
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
|
|
44
|
+
gl.bufferData(gl.UNIFORM_BUFFER, 164, gl.STREAM_DRAW);
|
|
45
|
+
gl.bindBufferBase(gl.UNIFORM_BUFFER, 0, ubo);
|
|
46
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
47
|
+
return ubo;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
resize() {
|
|
52
|
+
const { gl, globe, ubo } = this;
|
|
53
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
|
|
54
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 152, new Float32Array([globe.api_ScrW(), globe.api_ScrH()]));
|
|
55
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
setGeometry() {
|
|
60
|
+
const { gl, globe, ubo } = this;
|
|
61
|
+
const is3D = globe.api_GetCurrentGeometry() === 0;
|
|
62
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
|
|
63
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 140, new Float32Array([is3D]));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
draw3D(projection, modelView, translate) {
|
|
67
|
+
|
|
68
|
+
const { gl, traslateFloat32, ubo, mapWHFloat32, globe } = this;
|
|
69
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
|
|
70
|
+
{ // view, projection, translate
|
|
71
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 0, modelView);
|
|
72
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 64, projection);
|
|
73
|
+
traslateFloat32.set([translate.x, translate.y, translate.z], 0);
|
|
74
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 128, traslateFloat32);
|
|
75
|
+
}
|
|
76
|
+
{
|
|
77
|
+
// zoom level
|
|
78
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 160, new Float32Array([globe.api_GetCurrentLODWithDecimal()]));
|
|
79
|
+
}
|
|
80
|
+
{ // mapWH
|
|
81
|
+
if (globe.api_GetCurrentGeometry() === 1) {
|
|
82
|
+
const { width, height } = globe.api_GetCurrentWorldWH();
|
|
83
|
+
mapWHFloat32.set([width, height]);
|
|
84
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 144, mapWHFloat32);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
getUBO() {
|
|
92
|
+
return this.ubo;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
bind(bindingPoint) {
|
|
97
|
+
const { gl, ubo } = this;
|
|
98
|
+
gl.bindBufferBase(gl.UNIFORM_BUFFER, bindingPoint, ubo);
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
unbind(bindingPoint) {
|
|
103
|
+
const { gl } = this;
|
|
104
|
+
gl.bindBufferBase(gl.UNIFORM_BUFFER, bindingPoint, null);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
free() {
|
|
109
|
+
const { gl, ubo } = this;
|
|
110
|
+
gl.deleteBuffer(ubo);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
readBuffer() {
|
|
114
|
+
const result = new Float32Array(41);
|
|
115
|
+
this.gl.bindBuffer(this.gl.UNIFORM_BUFFER, this.ubo);
|
|
116
|
+
this.gl.getBufferSubData(this.gl.UNIFORM_BUFFER, 0, result);
|
|
117
|
+
this.gl.bindBuffer(this.gl.UNIFORM_BUFFER, null);
|
|
118
|
+
return {
|
|
119
|
+
view: result.slice(0, 16),
|
|
120
|
+
projection: result.slice(16, 32),
|
|
121
|
+
translate: result.slice(32, 35),
|
|
122
|
+
is3D: result[35],
|
|
123
|
+
mapWH: result.slice(36, 38),
|
|
124
|
+
screenWH: result.slice(38, 40),
|
|
125
|
+
z_level: result[40]
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
package/programs/util.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
export function longlatbbox2normalbbox({ minLon = -180, maxLon = 180, minLat = -90, maxLat = 90 } = {}) {
|
|
4
|
+
// x
|
|
5
|
+
const horOffset = (minLon) * Math.PI / 180;
|
|
6
|
+
const horSize = (maxLon - minLon) * Math.PI / 180;
|
|
7
|
+
// y
|
|
8
|
+
const vertOffset = (90 - maxLat) * Math.PI / 180;
|
|
9
|
+
const vertSize = (maxLat - minLat) * Math.PI / 180;
|
|
10
|
+
|
|
11
|
+
const result = {
|
|
12
|
+
bboxOffsetRad: new Float32Array([horOffset, vertOffset]),
|
|
13
|
+
bboxSizeRad: new Float32Array([horSize, vertSize])
|
|
14
|
+
};
|
|
15
|
+
console.log("longlatbbox2normalbbox", result);
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { createProgram } from "../../../util";
|
|
2
|
+
import { UBO_BINDING_POINT, shaderUboSource } from "./ubo.js";
|
|
3
|
+
import { glProgramCache } from "../../programcache.js";
|
|
4
|
+
/**
|
|
5
|
+
* [+] ubo
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const vertexShaderSource = `#version 300 es
|
|
9
|
+
precision highp float;
|
|
10
|
+
`+ shaderUboSource + `
|
|
11
|
+
uniform sampler2D u_vector_field;
|
|
12
|
+
in vec2 in_position;
|
|
13
|
+
out vec3 base_color;
|
|
14
|
+
vec2 lookup_wind(const vec2 uv) { // gerek kalmayabilir. sampler linear methodu ayni isi yapiyor
|
|
15
|
+
// return texture(u_vector_field, uv).rg; // lower-res hardware filtering
|
|
16
|
+
vec2 res = vec2(textureSize(u_vector_field, 0));
|
|
17
|
+
vec2 px = 1.0 / res;
|
|
18
|
+
vec2 vc = (floor(uv * res)) * px;
|
|
19
|
+
vec2 f = fract(uv * res);
|
|
20
|
+
vec2 tl = texture(u_vector_field, vc).rg;
|
|
21
|
+
vec2 tr = texture(u_vector_field, vc + vec2(px.x, 0)).rg;
|
|
22
|
+
vec2 bl = texture(u_vector_field, vc + vec2(0, px.y)).rg;
|
|
23
|
+
vec2 br = texture(u_vector_field, vc + px).rg;
|
|
24
|
+
return mix(mix(tl, tr, f.x), mix(bl, br, f.x), f.y);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
void main(){
|
|
29
|
+
vec2 direction_vector = lookup_wind(in_position);
|
|
30
|
+
if (direction_vector.r == 0.0 && direction_vector.g == 0.0){ return;}
|
|
31
|
+
|
|
32
|
+
vec2 limp;
|
|
33
|
+
if ( 0 == gl_VertexID) { limp = -tail_wing_base_limp; }
|
|
34
|
+
else if ( 1 == gl_VertexID) { limp = vec2( tail_wing_base_limp.x, -tail_wing_base_limp.y); }
|
|
35
|
+
else if ( 2 == gl_VertexID) { limp = tail_wing_base_limp; }
|
|
36
|
+
else { limp = vec2(-tail_wing_base_limp.x, tail_wing_base_limp.y); } // if ( 3 == gl_VertexID)
|
|
37
|
+
|
|
38
|
+
limp = (limp * mat2(
|
|
39
|
+
direction_vector.x, -direction_vector.y,
|
|
40
|
+
direction_vector.y, direction_vector.x)) / draw_texture_size;
|
|
41
|
+
|
|
42
|
+
vec2 pos = in_position * 2.0 - 1.0;
|
|
43
|
+
gl_Position = vec4(pos + limp, 0.0, 1.0);
|
|
44
|
+
base_color = color;
|
|
45
|
+
}`;
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
const fragmentShaderSource = `#version 300 es
|
|
49
|
+
precision highp float;
|
|
50
|
+
out vec4 outColor;
|
|
51
|
+
in vec3 base_color;
|
|
52
|
+
void main(){
|
|
53
|
+
outColor = vec4(base_color, 1.0);
|
|
54
|
+
}`;
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class Logic {
|
|
58
|
+
|
|
59
|
+
constructor(gl) {
|
|
60
|
+
this.gl = gl;
|
|
61
|
+
[this.program,
|
|
62
|
+
this._vector_field_location] = this._createProgram();
|
|
63
|
+
// this.decoyBuffer = new DecoyBufferManager(gl);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
_createProgram() {
|
|
67
|
+
const gl = this.gl;
|
|
68
|
+
const program = createProgram(gl, vertexShaderSource, fragmentShaderSource);
|
|
69
|
+
// ubo point
|
|
70
|
+
const ubo_location = gl.getUniformBlockIndex(program, 'UBO');
|
|
71
|
+
gl.uniformBlockBinding(program, ubo_location, UBO_BINDING_POINT);
|
|
72
|
+
return [program, gl.getUniformLocation(program, 'u_vector_field')];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @param {*} bufferManager | PingPongBufferManager
|
|
79
|
+
* @param {*} vectorTexture | RG32F texture R: x, G: y
|
|
80
|
+
* @param {*} uboManager | WaveParticalUboManager under ubo.js
|
|
81
|
+
*/
|
|
82
|
+
draw(bufferManager, vectorTexture, uboManager) {
|
|
83
|
+
const { gl, program } = this;
|
|
84
|
+
gl.useProgram(program);
|
|
85
|
+
gl.bindVertexArray(bufferManager.getSourceVao());
|
|
86
|
+
// gl.bindVertexArray(this.decoyBuffer.getSourceVao());
|
|
87
|
+
|
|
88
|
+
uboManager.bind();
|
|
89
|
+
|
|
90
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
91
|
+
gl.uniform1i(this._vector_field_location, 0);
|
|
92
|
+
gl.bindTexture(
|
|
93
|
+
gl.TEXTURE_2D,
|
|
94
|
+
vectorTexture
|
|
95
|
+
);
|
|
96
|
+
gl.drawArraysInstanced(gl.TRIANGLE_FAN, 0, 4, bufferManager.length);
|
|
97
|
+
gl.drawArraysInstanced(gl.POINTS, 0, 4, bufferManager.length);
|
|
98
|
+
gl.bindVertexArray(null);
|
|
99
|
+
uboManager.unbind();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
free() {
|
|
103
|
+
this.gl.deleteProgram(this.program);
|
|
104
|
+
this.program = null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
export default class {
|
|
111
|
+
constructor(gl) {
|
|
112
|
+
this.gl = gl;
|
|
113
|
+
this.logic = glProgramCache.getProgram(gl, Logic);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
draw(bufferManager, vectorTexture, uboManager) {
|
|
117
|
+
this.logic.draw(bufferManager, vectorTexture, uboManager);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
free() {
|
|
121
|
+
glProgramCache.releaseProgram(this.logic);
|
|
122
|
+
this.logic = null;
|
|
123
|
+
this.gl = null;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { createShader } from "../../../util";
|
|
2
|
+
import { UBO_SIZE, UBO_BINDING_POINT, shaderUboSource } from "./ubo.js";
|
|
3
|
+
import { glProgramCache } from "../../programcache";
|
|
4
|
+
|
|
5
|
+
// program output is buffer
|
|
6
|
+
// TODO: Mechanism for randomness
|
|
7
|
+
// drop out mechanism
|
|
8
|
+
// random particle position mechanism
|
|
9
|
+
|
|
10
|
+
const vertexShaderSource = `#version 300 es
|
|
11
|
+
` + shaderUboSource + `
|
|
12
|
+
|
|
13
|
+
uniform sampler2D vector_field;
|
|
14
|
+
in vec2 in_position;
|
|
15
|
+
out vec2 out_position;
|
|
16
|
+
|
|
17
|
+
// float random(vec2 st){
|
|
18
|
+
// float t = dot(st, vec2(12.9898,78.233));
|
|
19
|
+
// return fract(sin(t) * (t+43758.5453123));
|
|
20
|
+
// }
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
const vec3 rand_constants = vec3(12.9898, 78.233, 4375.85453);
|
|
24
|
+
float random(const vec2 co) {
|
|
25
|
+
float t = dot(rand_constants.xy, co);
|
|
26
|
+
return fract(sin(t) * (rand_constants.z + t));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
vec2 lookup_wind(const vec2 uv) { // gerek kalmayabilir. sampler linear methodu ayni isi yapiyor
|
|
30
|
+
// return texture(vector_field, uv).rg; // lower-res hardware filtering
|
|
31
|
+
vec2 res = vec2(textureSize(vector_field, 0));
|
|
32
|
+
if (res.x == 0.0 || res.y == 0.0){ return vec2(0.0);}
|
|
33
|
+
vec2 px = 1.0 / res;
|
|
34
|
+
vec2 vc = (floor(uv * res)) * px;
|
|
35
|
+
vec2 f = fract(uv * res);
|
|
36
|
+
vec2 tl = texture(vector_field, vc).rg;
|
|
37
|
+
vec2 tr = texture(vector_field, vc + vec2(px.x, 0)).rg;
|
|
38
|
+
vec2 bl = texture(vector_field, vc + vec2(0, px.y)).rg;
|
|
39
|
+
vec2 br = texture(vector_field, vc + px).rg;
|
|
40
|
+
if (tl.x == 0.0 && tl.y == 0.0){ return vec2(0.0);}
|
|
41
|
+
if (tr.x == 0.0 && tr.y == 0.0){ return vec2(0.0);}
|
|
42
|
+
if (bl.x == 0.0 && bl.y == 0.0){ return vec2(0.0);}
|
|
43
|
+
if (br.x == 0.0 && br.y == 0.0){ return vec2(0.0);}
|
|
44
|
+
return mix(mix(tl, tr, f.x), mix(bl, br, f.x), f.y);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
vec2 random_position(vec2 st){
|
|
49
|
+
return vec2(random(st), random(st + 1.0));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
void main(){
|
|
54
|
+
vec2 vec = lookup_wind(in_position).xy;
|
|
55
|
+
if (vec.x == 0.0 && vec.y == 0.0){
|
|
56
|
+
out_position = random_position(in_position);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
float random_value = random(in_position + random_seed);
|
|
60
|
+
if (random_value < drop_rate){ //TODO: more sophisticated drop out mechanism mi
|
|
61
|
+
out_position = random_position(in_position);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
out_position = in_position - (vec / draw_texture_size) * range; //*0.0014
|
|
65
|
+
}
|
|
66
|
+
`;
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
const fragmentShaderSource = `#version 300 es
|
|
70
|
+
precision highp float;
|
|
71
|
+
void main(){
|
|
72
|
+
}`;
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class Logic {
|
|
76
|
+
constructor(gl) {
|
|
77
|
+
this.gl = gl;
|
|
78
|
+
[this.program, this._vector_field_location] = this._createProgram();
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @param {*} bufferManager | PingPongBufferManager
|
|
84
|
+
* @param {*} vectorTexture RG32F texture R: x, G: y
|
|
85
|
+
* @param {*} uboManager | WaveParticalUboManager under ubo.js
|
|
86
|
+
*/
|
|
87
|
+
move(bufferManager, vectorTexture, uboManager) {
|
|
88
|
+
const { gl, program, _vector_field_location } = this;
|
|
89
|
+
gl.useProgram(program);
|
|
90
|
+
gl.enable(gl.RASTERIZER_DISCARD);
|
|
91
|
+
gl.bindVertexArray(bufferManager.getSourceVao());
|
|
92
|
+
gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, bufferManager.getTargetTF());
|
|
93
|
+
gl.beginTransformFeedback(gl.POINTS);
|
|
94
|
+
uboManager.bind();
|
|
95
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
96
|
+
gl.bindTexture(gl.TEXTURE_2D, vectorTexture);
|
|
97
|
+
gl.uniform1i(_vector_field_location, 0);
|
|
98
|
+
gl.drawArraysInstanced(gl.POINTS, 0, 1, bufferManager.length);
|
|
99
|
+
gl.endTransformFeedback();
|
|
100
|
+
gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, null);
|
|
101
|
+
gl.bindVertexArray(null);
|
|
102
|
+
uboManager.unbind();
|
|
103
|
+
gl.disable(gl.RASTERIZER_DISCARD);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
// -- private methods
|
|
108
|
+
|
|
109
|
+
_createProgram() {
|
|
110
|
+
const gl = this.gl;
|
|
111
|
+
const vertexShader = createShader(gl, gl.VERTEX_SHADER, vertexShaderSource);
|
|
112
|
+
const fragmentShader = createShader(gl, gl.FRAGMENT_SHADER, fragmentShaderSource);
|
|
113
|
+
const program = gl.createProgram();
|
|
114
|
+
gl.attachShader(program, vertexShader);
|
|
115
|
+
gl.attachShader(program, fragmentShader);
|
|
116
|
+
gl.transformFeedbackVaryings(
|
|
117
|
+
program,
|
|
118
|
+
["out_position"],
|
|
119
|
+
gl.SEPARATE_ATTRIBS
|
|
120
|
+
);
|
|
121
|
+
gl.linkProgram(program);
|
|
122
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
123
|
+
throw new Error(gl.getProgramParameter(program));
|
|
124
|
+
}
|
|
125
|
+
const ubo_location = gl.getUniformBlockIndex(program, 'UBO');
|
|
126
|
+
gl.uniformBlockBinding(program, ubo_location, UBO_BINDING_POINT);
|
|
127
|
+
return [program, gl.getUniformLocation(program, 'vector_field')];;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
free() {
|
|
131
|
+
this.gl.deleteProgram(this.program);
|
|
132
|
+
this.program = null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
getInPositionLocation() {
|
|
136
|
+
return this.gl.getAttribLocation(this.program, 'in_position');
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
export default class {
|
|
142
|
+
constructor(gl) {
|
|
143
|
+
this.gl = gl;
|
|
144
|
+
this.logic = glProgramCache.getProgram(gl, Logic);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
move(bufferManager, vectorTexture, uboManager) {
|
|
148
|
+
this.logic.move(bufferManager, vectorTexture, uboManager);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
free() {
|
|
152
|
+
glProgramCache.releaseProgram(this.gl, Logic);
|
|
153
|
+
this.program = null;
|
|
154
|
+
this.gl = null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
getInPositionLocation() {
|
|
159
|
+
return this.logic.getInPositionLocation();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const UBO_BINDING_POINT = 0;
|
|
2
|
+
const INITIAL_UBO_DATA = new Float32Array([93.17, 0.2, 1.0, 7.0, 1.0, 1.0, 1.0, 0.05, 2000, 2000]);
|
|
3
|
+
const shaderUboSource = `
|
|
4
|
+
layout(std140) uniform UBO {
|
|
5
|
+
float random_seed;
|
|
6
|
+
float range;
|
|
7
|
+
vec2 tail_wing_base_limp;
|
|
8
|
+
vec3 color;
|
|
9
|
+
float drop_rate;
|
|
10
|
+
vec2 draw_texture_size;
|
|
11
|
+
};`;
|
|
12
|
+
|
|
13
|
+
const UBO_SIZE = 40;
|
|
14
|
+
|
|
15
|
+
class WaveParticalUboManager {
|
|
16
|
+
|
|
17
|
+
constructor(gl) {
|
|
18
|
+
this.gl = gl;
|
|
19
|
+
this.ubo = this._createBuffer();
|
|
20
|
+
this._data = null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
update({ range, random_seed, tail_wing_base_limp, draw_texture_size, drop_rate, color }) {
|
|
25
|
+
const { gl, ubo } = this;
|
|
26
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
|
|
27
|
+
if (random_seed !== undefined) gl.bufferSubData(gl.UNIFORM_BUFFER, 0, new Float32Array([random_seed]));
|
|
28
|
+
if (range !== undefined) gl.bufferSubData(gl.UNIFORM_BUFFER, 4, new Float32Array([range]));
|
|
29
|
+
if (tail_wing_base_limp !== undefined) gl.bufferSubData(gl.UNIFORM_BUFFER, 8, new Float32Array(tail_wing_base_limp));
|
|
30
|
+
if (color !== undefined) gl.bufferSubData(gl.UNIFORM_BUFFER, 16, new Float32Array(color));
|
|
31
|
+
if (drop_rate !== undefined) gl.bufferSubData(gl.UNIFORM_BUFFER, 28, new Float32Array([drop_rate]));
|
|
32
|
+
if (draw_texture_size !== undefined) gl.bufferSubData(gl.UNIFORM_BUFFER, 32, new Float32Array(draw_texture_size));
|
|
33
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
_createBuffer() {
|
|
39
|
+
const gl = this.gl;
|
|
40
|
+
const buffer = gl.createBuffer();
|
|
41
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, buffer);
|
|
42
|
+
gl.bufferData(gl.UNIFORM_BUFFER, INITIAL_UBO_DATA, gl.STATIC_DRAW);
|
|
43
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
44
|
+
return buffer;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
bind() {
|
|
49
|
+
const { gl, ubo } = this;
|
|
50
|
+
gl.bindBufferBase(gl.UNIFORM_BUFFER, UBO_BINDING_POINT, ubo);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
unbind() {
|
|
54
|
+
const gl = this.gl;
|
|
55
|
+
gl.bindBufferBase(gl.UNIFORM_BUFFER, UBO_BINDING_POINT, null);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
free() {
|
|
59
|
+
const { gl, _buffer } = this;
|
|
60
|
+
gl.deleteBuffer(_buffer);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { WaveParticalUboManager, UBO_SIZE, UBO_BINDING_POINT, shaderUboSource };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages PingPong Buffers.
|
|
3
|
+
* Updated positions are written to the target buffer.
|
|
4
|
+
* Then source and target buffers are swapped.
|
|
5
|
+
*
|
|
6
|
+
* update coords and draw particles programs will use this class.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export default class {
|
|
10
|
+
constructor(gl, particleCount, inPositionLocation = 0) {
|
|
11
|
+
this.gl = gl;
|
|
12
|
+
this._inPositionLocation = inPositionLocation;
|
|
13
|
+
this._buffers = [gl.createBuffer(), gl.createBuffer()];
|
|
14
|
+
this._tfs = this._createTransformFeedbacksAndBindBuffers();
|
|
15
|
+
this._vaos = this._createVaos();
|
|
16
|
+
this.setParticleCount(particleCount);
|
|
17
|
+
this._index = 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
setParticleCount(count) {
|
|
21
|
+
const gl = this.gl;
|
|
22
|
+
this.length = count;
|
|
23
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this._buffers[0]);
|
|
24
|
+
gl.bufferData(gl.ARRAY_BUFFER, randomNumbers(this.length * 2), gl.DYNAMIC_DRAW);
|
|
25
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this._buffers[1]);
|
|
26
|
+
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this.length * 2), gl.DYNAMIC_DRAW);
|
|
27
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
28
|
+
this._index = 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
_createTransformFeedbacksAndBindBuffers() {
|
|
32
|
+
const gl = this.gl;
|
|
33
|
+
const tfs = [gl.createTransformFeedback(), gl.createTransformFeedback()];
|
|
34
|
+
tfs.forEach((tf, idx) => {
|
|
35
|
+
gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, tf);
|
|
36
|
+
gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 0, this._buffers[idx]);
|
|
37
|
+
});
|
|
38
|
+
gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, null);
|
|
39
|
+
return tfs;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
_createVaos() {
|
|
43
|
+
const gl = this.gl;
|
|
44
|
+
const vaos = [gl.createVertexArray(), gl.createVertexArray()];
|
|
45
|
+
vaos.forEach((vao, idx) => { // TODO: try with single vao for both buffers
|
|
46
|
+
gl.bindVertexArray(vao);
|
|
47
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this._buffers[idx]);
|
|
48
|
+
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
|
|
49
|
+
gl.vertexAttribDivisor(0, 1);
|
|
50
|
+
gl.enableVertexAttribArray(this._inPositionLocation);
|
|
51
|
+
gl.bindVertexArray(null);
|
|
52
|
+
});
|
|
53
|
+
return vaos;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getSourceVao() { return this._vaos[this._index]; }
|
|
57
|
+
getTargetVao() { return this._vaos[1 - this._index]; }
|
|
58
|
+
sourceBuffer() { return this._buffers[this._index]; }
|
|
59
|
+
targetBuffer() { return this._buffers[1 - this._index]; }
|
|
60
|
+
getTargetTF() { return this._tfs[1 - this._index]; }
|
|
61
|
+
swap() { this._index = 1 - this._index; }
|
|
62
|
+
|
|
63
|
+
free() {
|
|
64
|
+
this.gl.deleteBuffer(this._buffers[0]);
|
|
65
|
+
this.gl.deleteBuffer(this._buffers[1]);
|
|
66
|
+
this.gl.deleteTransformFeedback(this._tfs[0]);
|
|
67
|
+
this.gl.deleteTransformFeedback(this._tfs[1]);
|
|
68
|
+
this.gl.deleteVertexArray(this._vaos[0]);
|
|
69
|
+
this.gl.deleteVertexArray(this._vaos[1]);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function randomNumbers(count) {
|
|
74
|
+
const result = new Float32Array(count);
|
|
75
|
+
const random = Math.random;
|
|
76
|
+
for (let i = 0; i < count; i++) {
|
|
77
|
+
result[i] = random() * 2 - 1;
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { rings } from "../programs";
|
|
2
|
+
|
|
3
|
+
const { CircleFlatProgram, PaddyFlatProgram, CirclePaddySharedBuffer } = rings;
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @typedef RangeRingData
|
|
8
|
+
* @property {number} centerX
|
|
9
|
+
* @property {number} centerY
|
|
10
|
+
* @property {Array<Ring>} rings
|
|
11
|
+
*
|
|
12
|
+
* @typedef Ring
|
|
13
|
+
* @property {number} radius
|
|
14
|
+
* @property {number} padding
|
|
15
|
+
* @property {[number, number, number]} color
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* TODO: Tasarim dusunceleri
|
|
21
|
+
* Static Dynamic icin farkli pluginler olusturulabilir.
|
|
22
|
+
* Boylelikle bir pluginin iki bufferManageri yonetmesi gerekmez.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export default class {
|
|
26
|
+
|
|
27
|
+
constructor(id, padCount = 12, compass = 0, circleEdgeCount = 72) {
|
|
28
|
+
this.id = id;
|
|
29
|
+
this.compass = compass;
|
|
30
|
+
this.padCount = padCount;
|
|
31
|
+
this.circleEdgeCount = circleEdgeCount;
|
|
32
|
+
this.bufferManager = null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
init(globe, gl) {
|
|
36
|
+
this.gl = gl;
|
|
37
|
+
this.globe = globe;
|
|
38
|
+
this.circleFlatProgram = new CircleFlatProgram(globe, gl);
|
|
39
|
+
this.paddyFlatProgram = new PaddyFlatProgram(globe, gl);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
free() {
|
|
43
|
+
this.circleFlatProgram.free();
|
|
44
|
+
this.paddyFlatProgram.free();
|
|
45
|
+
if (this.bufferManager !== null) {
|
|
46
|
+
this.bufferManager.free();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
draw3D() {
|
|
52
|
+
const { circleFlatProgram, paddyFlatProgram, padCount, bufferManager, compass, gl, circleEdgeCount } = this;
|
|
53
|
+
// if (globe.api_GetCurrentGeometry() === 0) return; // do not draw in 3D mode
|
|
54
|
+
if (this.bufferManager !== null && bufferManager.length > 0) {
|
|
55
|
+
gl.disable(gl.DEPTH_TEST);
|
|
56
|
+
// gl.enable(gl.BLEND);
|
|
57
|
+
// gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
|
|
58
|
+
circleFlatProgram.draw(bufferManager, compass, circleEdgeCount);
|
|
59
|
+
paddyFlatProgram.draw(bufferManager, padCount, compass);
|
|
60
|
+
gl.enable(gl.DEPTH_TEST);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
setPadCount(padCount) {
|
|
65
|
+
this.padCount = padCount;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @param {RangeRingData} rangeRingData
|
|
70
|
+
* 0 compass limps
|
|
71
|
+
* other real distance limp
|
|
72
|
+
*/
|
|
73
|
+
setCampass(compass) {
|
|
74
|
+
this.compass = compass;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
initilizeBufferManager(initialRingCapacity, bufferDrawType) {
|
|
78
|
+
const { gl, globe } = this
|
|
79
|
+
this.bufferDrawType = bufferDrawType;
|
|
80
|
+
this.bufferManager = new CirclePaddySharedBuffer(gl, globe, { bufferType: this.bufferDrawType, initialRingCapacity: initialRingCapacity });
|
|
81
|
+
return this.bufferManager;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
getBufferManager() {
|
|
85
|
+
return this.bufferManager;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
}
|