@openglobus/og 0.13.0 → 0.13.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openglobus/og",
3
- "version": "0.13.0",
3
+ "version": "0.13.3",
4
4
  "description": "[OpenGlobus](http://www.openglobus.org/) is a javascript library designed to display interactive 3d maps and planets with map tiles, imagery and vector data, markers and 3d objects. It uses the WebGL technology, open source and completely free.",
5
5
  "directories": {
6
6
  "example": "./sandbox"
@@ -252,10 +252,9 @@ class LabelHandler extends BillboardHandler {
252
252
 
253
253
  gl.drawArrays(gl.TRIANGLES, 0, this._vertexBuffer.numItems);
254
254
 
255
- gl.depthFunc(gl.EQUAL);
256
-
257
255
  //
258
256
  // no outline PASS
257
+ gl.depthFunc(gl.EQUAL);
259
258
  gl.uniform1i(shu.isOutlinePass, 0);
260
259
  gl.uniform1f(shu.depthOffset, ec.polygonOffsetUnits + window.LABEL_DEPTH_OFFSET);
261
260
 
@@ -158,7 +158,7 @@ export function drawnode_screen_wl() {
158
158
  varying vec4 vTextureCoord;
159
159
  varying vec2 vGlobalTextureCoord;
160
160
  varying vec4 v_vertex;
161
- varying float v_height;
161
+ varying float v_height;
162
162
 
163
163
  void main(void) {
164
164
 
@@ -209,27 +209,31 @@ export function drawnode_screen_wl() {
209
209
 
210
210
  ${DEF_BLEND_WEBGL1}
211
211
 
212
+ float shininess;
213
+ float reflection;
214
+ float diffuseLightWeighting;
215
+ vec3 night;
212
216
 
213
217
  void main(void) {
214
-
218
+
215
219
  float overGround = 1.0 - step(0.1, v_height);
216
220
  vec3 normal = normalize(normalMatrix * ((texture2D(uNormalMap, vTextureCoord.zw).rgb - 0.5) * 2.0));
217
221
  vec3 lightDirection = normalize(lightsPositions[0].xyz - v_vertex.xyz * lightsPositions[0].w);
218
222
  vec3 eyeDirection = normalize(-v_vertex.xyz);
219
223
  vec3 reflectionDirection = reflect(-lightDirection, normal);
220
224
  vec4 nightImageColor = texture2D( nightTexture, vGlobalTextureCoord.st );
221
- float shininess = texture2D( specularTexture, vGlobalTextureCoord.st ).r * 255.0 * overGround;
222
- float reflection = max( dot(reflectionDirection, eyeDirection), 0.0);
223
- float diffuseLightWeighting = max(dot(normal, lightDirection), 0.0);
224
- vec3 night = nightStep * (0.3 - diffuseLightWeighting) * nightImageColor.rgb;
225
+ shininess = texture2D( specularTexture, vGlobalTextureCoord.st ).r * 255.0 * overGround;
226
+ reflection = max( dot(reflectionDirection, eyeDirection), 0.0);
227
+ diffuseLightWeighting = max(dot(normal, lightDirection), 0.0);
228
+ night = nightStep * (.18 - diffuseLightWeighting * 3.0) * nightImageColor.rgb;
225
229
  night *= overGround * step(0.0, night);
226
230
 
227
231
  vec3 spec = specular.rgb * pow( reflection, specular.w) * shininess;
228
- vec3 lightWeighting = ambient + diffuse * diffuseLightWeighting + spec + night;
232
+ vec4 lightWeighting = vec4(ambient + diffuse * diffuseLightWeighting + spec + night, 1.0);
229
233
 
230
234
  gl_FragColor = texture2D( defaultTexture, vTextureCoord.xy );
231
235
  if( samplerCount == 0 ) {
232
- gl_FragColor *= vec4(lightWeighting, 1);
236
+ gl_FragColor *= lightWeighting;
233
237
  return;
234
238
  }
235
239
 
@@ -237,30 +241,30 @@ export function drawnode_screen_wl() {
237
241
 
238
242
  blend(gl_FragColor, samplerArr[0], tileOffsetArr[0], layerOpacityArr[0]);
239
243
  if( samplerCount == 1 ) {
240
- gl_FragColor *= vec4(lightWeighting, 1);
244
+ gl_FragColor *= lightWeighting;
241
245
  return;
242
246
  }
243
247
 
244
248
  blend(gl_FragColor, samplerArr[1], tileOffsetArr[1], layerOpacityArr[1]);
245
249
  if( samplerCount == 2 ) {
246
- gl_FragColor *= vec4(lightWeighting, 1);
250
+ gl_FragColor *= lightWeighting;
247
251
  return;
248
252
  }
249
253
 
250
254
  blend(gl_FragColor, samplerArr[2], tileOffsetArr[2], layerOpacityArr[2]);
251
255
  if( samplerCount == 3 ) {
252
- gl_FragColor *= vec4(lightWeighting, 1);
256
+ gl_FragColor *= lightWeighting;
253
257
  return;
254
258
  }
255
259
 
256
260
  blend(gl_FragColor, samplerArr[3], tileOffsetArr[3], layerOpacityArr[3]);
257
261
  if( samplerCount == 4 ) {
258
- gl_FragColor *= vec4(lightWeighting, 1);
262
+ gl_FragColor *= lightWeighting;
259
263
  return;
260
264
  }
261
265
 
262
266
  blend(gl_FragColor, samplerArr[4], tileOffsetArr[4], layerOpacityArr[4]);
263
- gl_FragColor *= vec4(lightWeighting, 1);
267
+ gl_FragColor *= lightWeighting;
264
268
  }`
265
269
  });
266
270
  }
@@ -65,7 +65,6 @@ export function label_webgl2() {
65
65
  flat out int v_fontIndex;
66
66
  out vec4 v_outlineColor;
67
67
  flat out float v_outline;
68
- flat out int v_isOutlinePass;
69
68
 
70
69
  uniform vec2 viewport;
71
70
  uniform mat4 viewMatrix;
@@ -75,7 +74,6 @@ export function label_webgl2() {
75
74
  uniform float planetRadius;
76
75
  uniform vec3 scaleByDistance;
77
76
  uniform float opacity;
78
- uniform int isOutlinePass;
79
77
  uniform float depthOffset;
80
78
 
81
79
  const vec3 ZERO3 = vec3(0.0);
@@ -95,7 +93,6 @@ export function label_webgl2() {
95
93
  vec3 cameraPos = eyePositionHigh + eyePositionLow;
96
94
 
97
95
  v_outline = a_outline;
98
- v_isOutlinePass = isOutlinePass;
99
96
 
100
97
  v_fontIndex = int(a_fontIndex);
101
98
  v_uv = vec2(a_texCoord.xy);
@@ -138,6 +135,8 @@ export function label_webgl2() {
138
135
  fragmentShader:
139
136
  `#version 300 es
140
137
 
138
+ uniform int isOutlinePass;
139
+
141
140
  precision highp float;
142
141
  precision highp int;
143
142
 
@@ -150,7 +149,6 @@ export function label_webgl2() {
150
149
 
151
150
  uniform sampler2D fontTextureArr[MAX_SIZE];
152
151
  uniform vec4 sdfParamsArr[MAX_SIZE];
153
- flat in int v_isOutlinePass;
154
152
 
155
153
  flat in int v_fontIndex;
156
154
  in vec2 v_uv;
@@ -219,42 +217,25 @@ export function label_webgl2() {
219
217
  return sdfParamsArr[10];
220
218
  }
221
219
  }
222
-
223
- // void main () {
224
- //
225
- // float sd = getDistance();
226
- //
227
- // vec4 sdfParams = getSDFParams();
228
- //
229
- // vec2 dxdy = fwidth(v_uv) * sdfParams.xy;
230
- // float dist = sd + min(0.001, 0.5 - 1.0 / sdfParams.w) - 0.5;
231
- // float opacity = clamp(dist * sdfParams.w / length(dxdy) + 0.5, 0.0, 1.0);
232
- //
233
- // float strokeDist = sd + min(v_outline, 0.5 - 1.0 / sdfParams.w) - 0.5;
234
- // float strokeAlpha = v_rgba.a * clamp(strokeDist * sdfParams.w / length(dxdy) + 0.5, 0.0, 1.0);
235
- //
236
- // if (strokeAlpha < 0.01) {
237
- // discard;
238
- // }
239
- //
240
- // outScreen = v_rgba * opacity * v_rgba.a + v_outlineColor * v_outlineColor.a * strokeAlpha * (1.0 - opacity);
241
- // }
242
-
220
+
243
221
  void main () {
244
222
 
245
223
  vec4 sdfParams = getSDFParams();
246
-
224
+ float sd = getDistance();
247
225
  vec2 dxdy = fwidth(v_uv) * sdfParams.xy;
248
- float dist = getDistance() + min(v_isOutlinePass == 0 ? 0.001 : v_outline, 0.5 - 1.0 / sdfParams.w) - 0.5;
226
+ float dist = sd + min(0.001, 0.5 - 1.0 / sdfParams.w) - 0.5;
249
227
  float opacity = clamp(dist * sdfParams.w / length(dxdy) + 0.5, 0.0, 1.0);
250
228
 
251
- vec4 color = v_rgba;
252
- color.a *= opacity;
253
- if (color.a < 0.01) {
254
- discard;
255
- }
256
-
257
- outScreen = vec4(v_rgba.rgb, opacity * v_rgba.a);
229
+ if(isOutlinePass == 0){
230
+ outScreen = vec4(v_rgba.rgb, opacity * v_rgba.a);
231
+ } else {
232
+ float strokeDist = sd + min(v_outline, 0.5 - 1.0 / sdfParams.w) - 0.5;
233
+ float strokeAlpha = v_rgba.a * clamp(strokeDist * sdfParams.w / length(dxdy) + 0.5, 0.0, 1.0);
234
+ if(strokeAlpha < 0.1){
235
+ discard;
236
+ }
237
+ outScreen = v_rgba * strokeAlpha * (0.5 - opacity) * 2.0;
238
+ }
258
239
  }`
259
240
  });
260
241
  }
@@ -302,12 +283,10 @@ export function label_screen() {
302
283
  attribute vec4 a_rgba;
303
284
  attribute float a_fontIndex;
304
285
 
286
+ varying float v_outline;
305
287
  varying vec2 v_uv;
306
288
  varying vec4 v_rgba;
307
289
  varying float v_fontIndex;
308
- varying vec4 v_outlineColor;
309
- varying float v_outline;
310
- varying float v_isOutlinePass;
311
290
 
312
291
  uniform vec2 viewport;
313
292
  uniform mat4 viewMatrix;
@@ -317,7 +296,6 @@ export function label_screen() {
317
296
  uniform float planetRadius;
318
297
  uniform vec3 scaleByDistance;
319
298
  uniform float opacity;
320
- uniform int isOutlinePass;
321
299
  uniform float depthOffset;
322
300
 
323
301
  const vec3 ZERO3 = vec3(0.0);
@@ -337,13 +315,12 @@ export function label_screen() {
337
315
  vec3 cameraPos = eyePositionHigh + eyePositionLow;
338
316
 
339
317
  v_outline = a_outline;
340
- v_isOutlinePass = float(isOutlinePass);
341
-
342
- v_fontIndex = a_fontIndex;
343
318
  v_uv = vec2(a_texCoord.xy);
319
+ v_rgba = a_rgba;
320
+ v_fontIndex = a_fontIndex;
321
+
344
322
  vec3 look = a_positions - cameraPos;
345
323
  float lookDist = length(look);
346
- v_rgba = a_rgba;
347
324
 
348
325
  if(opacity * step(lookDist, sqrt(dot(cameraPos,cameraPos) - planetRadius) + sqrt(dot(a_positions,a_positions) - planetRadius)) == 0.0){
349
326
  return;
@@ -392,16 +369,14 @@ export function label_screen() {
392
369
 
393
370
  uniform sampler2D fontTextureArr[MAX_SIZE];
394
371
  uniform vec4 sdfParamsArr[MAX_SIZE];
372
+ uniform int isOutlinePass;
395
373
 
396
- varying float v_isOutlinePass;
397
-
398
- varying float v_fontIndex;
374
+ varying float v_outline;
399
375
  varying vec2 v_uv;
400
376
  varying vec4 v_rgba;
401
-
402
- varying float v_outline;
403
-
404
- varying vec3 v_pickingColor;
377
+ varying float v_fontIndex;
378
+
379
+ float fontIndex;
405
380
 
406
381
  float median(float r, float g, float b) {
407
382
  return max(min(r, g), min(max(r, g), b));
@@ -409,27 +384,27 @@ export function label_screen() {
409
384
 
410
385
  float getDistance() {
411
386
  vec3 msdf;
412
- if(v_fontIndex >= 0.0 && v_fontIndex < 1.0) {
387
+ if(fontIndex >= 0.0 && fontIndex < 1.0) {
413
388
  msdf = texture2D(fontTextureArr[0], v_uv).rgb;
414
- } else if(v_fontIndex >= 1.0 && v_fontIndex < 2.0){
389
+ } else if(fontIndex >= 1.0 && fontIndex < 2.0){
415
390
  msdf = texture2D(fontTextureArr[1], v_uv).rgb;
416
- } else if(v_fontIndex >= 2.0 && v_fontIndex < 3.0){
391
+ } else if(fontIndex >= 2.0 && fontIndex < 3.0){
417
392
  msdf = texture2D(fontTextureArr[2], v_uv).rgb;
418
- } else if(v_fontIndex >= 3.0 && v_fontIndex < 4.0){
393
+ } else if(fontIndex >= 3.0 && fontIndex < 4.0){
419
394
  msdf = texture2D(fontTextureArr[3], v_uv).rgb;
420
- } else if(v_fontIndex >= 4.0 && v_fontIndex < 5.0){
395
+ } else if(fontIndex >= 4.0 && fontIndex < 5.0){
421
396
  msdf = texture2D(fontTextureArr[4], v_uv).rgb;
422
- } else if(v_fontIndex >= 5.0 && v_fontIndex < 6.0){
397
+ } else if(fontIndex >= 5.0 && fontIndex < 6.0){
423
398
  msdf = texture2D(fontTextureArr[5], v_uv).rgb;
424
- } else if(v_fontIndex >= 6.0 && v_fontIndex < 7.0){
399
+ } else if(fontIndex >= 6.0 && fontIndex < 7.0){
425
400
  msdf = texture2D(fontTextureArr[6], v_uv).rgb;
426
- } else if(v_fontIndex >= 7.0 && v_fontIndex < 8.0){
401
+ } else if(fontIndex >= 7.0 && fontIndex < 8.0){
427
402
  msdf = texture2D(fontTextureArr[7], v_uv).rgb;
428
- } else if(v_fontIndex >= 8.0 && v_fontIndex < 9.0){
403
+ } else if(fontIndex >= 8.0 && fontIndex < 9.0){
429
404
  msdf = texture2D(fontTextureArr[8], v_uv).rgb;
430
- } else if(v_fontIndex >= 9.0 && v_fontIndex < 10.0){
405
+ } else if(fontIndex >= 9.0 && fontIndex < 10.0){
431
406
  msdf = texture2D(fontTextureArr[9], v_uv).rgb;
432
- } else if(v_fontIndex >= 10.0 && v_fontIndex < 11.0){
407
+ } else if(fontIndex >= 10.0 && fontIndex < 11.0){
433
408
  msdf = texture2D(fontTextureArr[10], v_uv).rgb;
434
409
  }
435
410
  return median(msdf.r, msdf.g, msdf.b);
@@ -437,46 +412,51 @@ export function label_screen() {
437
412
 
438
413
 
439
414
  vec4 getSDFParams() {
440
- if(v_fontIndex >= 0.0 && v_fontIndex < 1.0) {
415
+ if(fontIndex >= 0.0 && fontIndex < 1.0) {
441
416
  return sdfParamsArr[0];
442
- } else if(v_fontIndex >= 1.0 && v_fontIndex < 2.0){
417
+ } else if(fontIndex >= 1.0 && fontIndex < 2.0){
443
418
  return sdfParamsArr[1];
444
- } else if(v_fontIndex >= 2.0 && v_fontIndex < 3.0){
419
+ } else if(fontIndex >= 2.0 && fontIndex < 3.0){
445
420
  return sdfParamsArr[2];
446
- } else if(v_fontIndex >= 3.0 && v_fontIndex < 4.0){
421
+ } else if(fontIndex >= 3.0 && fontIndex < 4.0){
447
422
  return sdfParamsArr[3];
448
- } else if(v_fontIndex >= 4.0 && v_fontIndex < 5.0){
423
+ } else if(fontIndex >= 4.0 && fontIndex < 5.0){
449
424
  return sdfParamsArr[4];
450
- } else if(v_fontIndex >= 5.0 && v_fontIndex < 6.0){
425
+ } else if(fontIndex >= 5.0 && fontIndex < 6.0){
451
426
  return sdfParamsArr[5];
452
- } else if(v_fontIndex >= 6.0 && v_fontIndex < 7.0){
427
+ } else if(fontIndex >= 6.0 && fontIndex < 7.0){
453
428
  return sdfParamsArr[6];
454
- } else if(v_fontIndex >= 7.0 && v_fontIndex < 8.0){
429
+ } else if(fontIndex >= 7.0 && fontIndex < 8.0){
455
430
  return sdfParamsArr[7];
456
- } else if(v_fontIndex >= 8.0 && v_fontIndex < 9.0){
431
+ } else if(fontIndex >= 8.0 && fontIndex < 9.0){
457
432
  return sdfParamsArr[8];
458
- } else if(v_fontIndex >= 9.0 && v_fontIndex < 10.0){
433
+ } else if(fontIndex >= 9.0 && fontIndex < 10.0){
459
434
  return sdfParamsArr[9];
460
- } else if(v_fontIndex >= 10.0 && v_fontIndex < 11.0){
435
+ } else if(fontIndex >= 10.0 && fontIndex < 11.0){
461
436
  return sdfParamsArr[10];
462
437
  }
463
438
  }
464
439
 
465
440
  void main () {
466
441
 
467
- vec4 sdfParams = getSDFParams();
442
+ fontIndex = v_fontIndex + 0.1;
468
443
 
444
+ vec4 sdfParams = getSDFParams();
445
+ float sd = getDistance();
469
446
  vec2 dxdy = fwidth(v_uv) * sdfParams.xy;
470
- float dist = getDistance() + min(v_isOutlinePass == 0.0 ? 0.001 : v_outline, 0.5 - 1.0 / sdfParams.w) - 0.5;
447
+ float dist = sd + min(0.001, 0.5 - 1.0 / sdfParams.w) - 0.5;
471
448
  float opacity = clamp(dist * sdfParams.w / length(dxdy) + 0.5, 0.0, 1.0);
472
449
 
473
- vec4 color = v_rgba;
474
- color.a *= opacity;
475
- if (color.a < 0.01) {
476
- discard;
450
+ if(isOutlinePass == 0){
451
+ gl_FragColor = vec4(v_rgba.rgb, opacity * v_rgba.a);
452
+ } else {
453
+ float strokeDist = sd + min(v_outline, 0.5 - 1.0 / sdfParams.w) - 0.5;
454
+ float strokeAlpha = v_rgba.a * clamp(strokeDist * sdfParams.w / length(dxdy) + 0.5, 0.0, 1.0);
455
+ if(strokeAlpha < 0.1){
456
+ discard;
457
+ }
458
+ gl_FragColor = v_rgba * strokeAlpha * (0.5 - opacity) * 2.0;
477
459
  }
478
-
479
- gl_FragColor = vec4(v_rgba.rgb, opacity * v_rgba.a);
480
460
  }`
481
461
  });
482
462
  }