@openglobus/og 0.13.1 → 0.13.2

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.1",
3
+ "version": "0.13.2",
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;
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 * v_rgba.a * strokeAlpha * (0.5 - opacity) * 2.0;
255
238
  }
256
-
257
- outScreen = vec4(v_rgba.rgb, opacity * v_rgba.a);
258
239
  }`
259
240
  });
260
241
  }
@@ -303,7 +284,6 @@ export function label_screen() {
303
284
  attribute float a_fontIndex;
304
285
 
305
286
  varying float v_outline;
306
- varying float v_isOutlinePass;
307
287
  varying vec2 v_uv;
308
288
  varying vec4 v_rgba;
309
289
  varying float v_fontIndex;
@@ -316,7 +296,6 @@ export function label_screen() {
316
296
  uniform float planetRadius;
317
297
  uniform vec3 scaleByDistance;
318
298
  uniform float opacity;
319
- uniform int isOutlinePass;
320
299
  uniform float depthOffset;
321
300
 
322
301
  const vec3 ZERO3 = vec3(0.0);
@@ -336,7 +315,6 @@ export function label_screen() {
336
315
  vec3 cameraPos = eyePositionHigh + eyePositionLow;
337
316
 
338
317
  v_outline = a_outline;
339
- v_isOutlinePass = float(isOutlinePass);
340
318
  v_uv = vec2(a_texCoord.xy);
341
319
  v_rgba = a_rgba;
342
320
  v_fontIndex = a_fontIndex;
@@ -391,9 +369,9 @@ export function label_screen() {
391
369
 
392
370
  uniform sampler2D fontTextureArr[MAX_SIZE];
393
371
  uniform vec4 sdfParamsArr[MAX_SIZE];
372
+ uniform int isOutlinePass;
394
373
 
395
374
  varying float v_outline;
396
- varying float v_isOutlinePass;
397
375
  varying vec2 v_uv;
398
376
  varying vec4 v_rgba;
399
377
  varying float v_fontIndex;
@@ -464,18 +442,21 @@ export function label_screen() {
464
442
  fontIndex = v_fontIndex + 0.1;
465
443
 
466
444
  vec4 sdfParams = getSDFParams();
467
-
445
+ float sd = getDistance();
468
446
  vec2 dxdy = fwidth(v_uv) * sdfParams.xy;
469
- 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;
470
448
  float opacity = clamp(dist * sdfParams.w / length(dxdy) + 0.5, 0.0, 1.0);
471
449
 
472
- vec4 color = v_rgba;
473
- color.a *= opacity;
474
- if (color.a < 0.01) {
475
- 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 * v_rgba.a * strokeAlpha * (0.5 - opacity) * 2.0;
476
459
  }
477
-
478
- gl_FragColor = vec4(v_rgba.rgb, opacity * v_rgba.a);
479
460
  }`
480
461
  });
481
462
  }