@openglobus/og 0.13.2 → 0.13.5

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.
@@ -92,6 +92,14 @@ export function billboardPicking() {
92
92
  vec4 posRTE = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);
93
93
  vec4 projPos = projectionMatrix * posRTE;
94
94
 
95
+ float camSlope = dot(vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]), normalize(cameraPos));
96
+ if(camSlope > 0.5) {
97
+ float dist = dot(look, normalize(cameraPos));
98
+ projPos.z += dist * 0.02;
99
+ }else{
100
+ projPos.z += -(abs(projPos.z)) * 0.002;
101
+ }
102
+
95
103
  projPos.z += depthOffset + a_offset.z;
96
104
 
97
105
  vec2 screenPos = project(projPos);
@@ -6,6 +6,10 @@
6
6
 
7
7
  import { Program } from '../webgl/Program.js';
8
8
 
9
+ const DEFINE = `
10
+ #define EMPTY -1.0
11
+ #define RTL 1.0`;
12
+
9
13
  const PROJECT = `vec2 project(vec4 p) {
10
14
  return (0.5 * p.xyz / p.w + 0.5).xy * viewport;
11
15
  }`;
@@ -47,7 +51,9 @@ export function label_webgl2() {
47
51
  },
48
52
  vertexShader:
49
53
  `#version 300 es
50
-
54
+
55
+ ${DEFINE}
56
+
51
57
  in float a_outline;
52
58
  in vec4 a_gliphParam;
53
59
  in vec2 a_vertices;
@@ -77,14 +83,14 @@ export function label_webgl2() {
77
83
  uniform float depthOffset;
78
84
 
79
85
  const vec3 ZERO3 = vec3(0.0);
80
-
86
+
81
87
  ${PROJECT}
82
88
 
83
89
  ${ROTATE2D}
84
90
 
85
91
  void main() {
86
92
 
87
- if(a_texCoord.z == -1.0) {
93
+ if(a_texCoord.w == EMPTY) {
88
94
  gl_Position = vec4(0.0);
89
95
  return;
90
96
  }
@@ -95,7 +101,7 @@ export function label_webgl2() {
95
101
  v_outline = a_outline;
96
102
 
97
103
  v_fontIndex = int(a_fontIndex);
98
- v_uv = vec2(a_texCoord.xy);
104
+ v_uv = a_texCoord.xy;
99
105
  vec3 look = a_positions - cameraPos;
100
106
  float lookDist = length(look);
101
107
  v_rgba = a_rgba;
@@ -127,8 +133,18 @@ export function label_webgl2() {
127
133
  projPos.z += depthOffset + a_offset.z;
128
134
 
129
135
  vec2 screenPos = project(projPos);
130
-
131
- vec2 v = screenPos + rotate2d(a_rotation) * ((a_vertices * a_gliphParam.xy + a_gliphParam.zw + vec2(a_texCoord.z, 0.0) + vec2(a_texCoord.w, 0.0)) * a_size * scd + a_offset.xy);
136
+
137
+ vec2 vert = a_vertices;
138
+ vec4 gp = a_gliphParam;
139
+ if(a_texCoord.w == RTL){
140
+ vert.x = step(vert.x * 0.5 + 1.0, 1.0);
141
+ gp.x = -a_gliphParam.x;
142
+ gp.z = -(a_gliphParam.z + a_texCoord.z);
143
+ }else{
144
+ gp.z = a_gliphParam.z + a_texCoord.z;
145
+ }
146
+
147
+ vec2 v = screenPos + rotate2d(a_rotation) * ((vert * gp.xy + gp.zw) * a_size * scd + a_offset.xy);
132
148
 
133
149
  gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);
134
150
  }`,
@@ -234,8 +250,8 @@ export function label_webgl2() {
234
250
  if(strokeAlpha < 0.1){
235
251
  discard;
236
252
  }
237
- outScreen = v_rgba * v_rgba.a * strokeAlpha * (0.5 - opacity) * 2.0;
238
- }
253
+ outScreen = v_rgba * strokeAlpha * (0.5 - opacity) * 2.0;
254
+ }
239
255
  }`
240
256
  });
241
257
  }
@@ -270,7 +286,9 @@ export function label_screen() {
270
286
  a_fontIndex: "float"
271
287
  },
272
288
  vertexShader:
273
- `
289
+ `
290
+ ${DEFINE}
291
+
274
292
  attribute float a_outline;
275
293
  attribute vec4 a_gliphParam;
276
294
  attribute vec2 a_vertices;
@@ -306,7 +324,7 @@ export function label_screen() {
306
324
 
307
325
  void main() {
308
326
 
309
- if(a_texCoord.z == -1.0) {
327
+ if(a_texCoord.w == EMPTY) {
310
328
  gl_Position = vec4(0.0);
311
329
  return;
312
330
  }
@@ -349,9 +367,19 @@ export function label_screen() {
349
367
  projPos.z += depthOffset + a_offset.z;
350
368
 
351
369
  vec2 screenPos = project(projPos);
352
-
353
- vec2 v = screenPos + rotate2d(a_rotation) * ((a_vertices * a_gliphParam.xy + a_gliphParam.zw + vec2(a_texCoord.z, 0.0) + vec2(a_texCoord.w, 0.0)) * a_size * scd + a_offset.xy);
354
-
370
+
371
+ vec2 vert = a_vertices;
372
+ vec4 gp = a_gliphParam;
373
+ if(a_texCoord.w == RTL){
374
+ vert.x = step(vert.x * 0.5 + 1.0, 1.0);
375
+ gp.x = -a_gliphParam.x;
376
+ gp.z = -(a_gliphParam.z + a_texCoord.z);
377
+ }else{
378
+ gp.z = a_gliphParam.z + a_texCoord.z;
379
+ }
380
+
381
+ vec2 v = screenPos + rotate2d(a_rotation) * ((vert * gp.xy + gp.zw) * a_size * scd + a_offset.xy);
382
+
355
383
  gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);
356
384
  }`,
357
385
  fragmentShader:
@@ -455,7 +483,7 @@ export function label_screen() {
455
483
  if(strokeAlpha < 0.1){
456
484
  discard;
457
485
  }
458
- gl_FragColor = v_rgba * v_rgba.a * strokeAlpha * (0.5 - opacity) * 2.0;
486
+ gl_FragColor = v_rgba * strokeAlpha * (0.5 - opacity) * 2.0;
459
487
  }
460
488
  }`
461
489
  });
@@ -487,6 +515,9 @@ export function labelPicking() {
487
515
  },
488
516
  vertexShader:
489
517
  `
518
+
519
+ ${DEFINE}
520
+
490
521
  attribute vec4 a_gliphParam;
491
522
  attribute vec2 a_vertices;
492
523
  attribute vec4 a_texCoord;
@@ -519,7 +550,7 @@ export function labelPicking() {
519
550
  vec3 a_positions = a_positionsHigh + a_positionsLow;
520
551
  vec3 cameraPos = eyePositionHigh + eyePositionLow;
521
552
 
522
- if(a_texCoord.z == -1.0){
553
+ if(a_texCoord.w == EMPTY) {
523
554
  gl_Position = vec4(0.0);
524
555
  return;
525
556
  }
@@ -554,7 +585,19 @@ export function labelPicking() {
554
585
  projPos.z += depthOffset + a_offset.z;
555
586
 
556
587
  vec2 screenPos = project(projPos);
557
- vec2 v = screenPos + rotate2d(a_rotation) * ((a_vertices * a_gliphParam.xy + a_gliphParam.zw + vec2(a_texCoord.z, 0.0) + vec2(a_texCoord.w, 0.0)) * a_size * scd + a_offset.xy);
588
+
589
+ vec2 vert = a_vertices;
590
+ vec4 gp = a_gliphParam;
591
+ if(a_texCoord.w == RTL){
592
+ vert.x = step(vert.x * 0.5 + 1.0, 1.0);
593
+ gp.x = -a_gliphParam.x;
594
+ gp.z = -(a_gliphParam.z + a_texCoord.z);
595
+ }else{
596
+ gp.z = a_gliphParam.z + a_texCoord.z;
597
+ }
598
+
599
+ vec2 v = screenPos + rotate2d(a_rotation) * ((vert * gp.xy + gp.zw) * a_size * scd + a_offset.xy);
600
+
558
601
  gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);
559
602
  }`,
560
603
  fragmentShader:
@@ -86,16 +86,20 @@ class FontAtlas {
86
86
  tc[10] = r.left / w;
87
87
  tc[11] = r.top / h;
88
88
 
89
- atlas.nodes[ti] = new TextureAtlasNode(r, tc);
90
- atlas.nodes[ti].metrics = ci;
91
-
92
- atlas.nodes[ti].metrics.nWidth = atlas.nodes[ti].metrics.width / s;
93
- atlas.nodes[ti].metrics.nHeight = atlas.nodes[ti].metrics.height / s;
94
- atlas.nodes[ti].metrics.nAdvance = atlas.nodes[ti].metrics.xadvance / s;
95
- atlas.nodes[ti].metrics.nXOffset = atlas.nodes[ti].metrics.xoffset / s;
96
- atlas.nodes[ti].metrics.nYOffset = 1.0 - atlas.nodes[ti].metrics.yoffset / s;
97
-
98
- atlas.nodes[ti].emptySize = 1;
89
+ let taNode = new TextureAtlasNode(r, tc);
90
+ let ciNorm = ci.char.normalize('NFKC');
91
+ let ciCode = ciNorm.charCodeAt();
92
+ taNode.metrics = ci;
93
+ taNode.metrics.nChar = ciNorm;
94
+ taNode.metrics.nCode = ciCode;
95
+ taNode.metrics.nWidth = taNode.metrics.width / s;
96
+ taNode.metrics.nHeight = taNode.metrics.height / s;
97
+ taNode.metrics.nAdvance = taNode.metrics.xadvance / s;
98
+ taNode.metrics.nXOffset = taNode.metrics.xoffset / s;
99
+ taNode.metrics.nYOffset = 1.0 - taNode.metrics.yoffset / s;
100
+ taNode.emptySize = 1;
101
+
102
+ atlas.nodes.set(ciNorm.charCodeAt(), taNode);
99
103
  }
100
104
 
101
105
  atlas.kernings = {};
@@ -106,14 +110,20 @@ class FontAtlas {
106
110
  let first = ki.first,
107
111
  second = ki.second;
108
112
 
109
- let charFirst = idToChar[first],
110
- charSecond = idToChar[second];
113
+ //let charFirst = idToChar[first],
114
+ // charSecond = idToChar[second];
115
+
116
+ // if (!atlas.kernings[charFirst]) {
117
+ // atlas.kernings[charFirst] = {};
118
+ // }
119
+ //
120
+ // atlas.kernings[charFirst][charSecond] = ki.amount / s;
111
121
 
112
- if (!atlas.kernings[charFirst]) {
113
- atlas.kernings[charFirst] = {};
122
+ if (!atlas.kernings[first]) {
123
+ atlas.kernings[first] = {};
114
124
  }
115
125
 
116
- atlas.kernings[charFirst][charSecond] = ki.amount / s;
126
+ atlas.kernings[first][second] = ki.amount / s;
117
127
  }
118
128
  }
119
129