@pirireis/webglobeplugins 1.2.17 → 1.2.19

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": "@pirireis/webglobeplugins",
3
- "version": "1.2.17",
3
+ "version": "1.2.19",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT",
@@ -16,6 +16,7 @@ const uniformBindingPoints = {
16
16
  };
17
17
  // last value of uint16 is 65535
18
18
  export const IndexAttributeEscapeValue = -1;
19
+ export const DEPTH_START_ANGLE = 60;
19
20
  const styleBlockManager = new UniformBlockManager('Style', [
20
21
  { name: "defaultColor", type: "vec4", value: new Float32Array([0.0, 0.0, 0.0, 0.0]) },
21
22
  { name: "hoverColor", type: "vec4", value: new Float32Array([0, 0, 0, 0]) },
@@ -95,8 +96,11 @@ void main() {
95
96
  if (!hasDemSample) {
96
97
  altitude = 0.0 / 0.0;
97
98
  }
98
-
99
- vec3 position = a_position * (elevation + altitude * elevation_scale);
99
+ float elevation_for_z_fighting = 0.0;
100
+ if ( world_tilt > ${DEPTH_START_ANGLE * (3.14159265 / 180.0)} ) {
101
+ elevation_for_z_fighting = (23.0 - z_level) * 0.012;
102
+ }
103
+ vec3 position = a_position * (elevation + altitude * elevation_scale + elevation_for_z_fighting);
100
104
  gl_Position = cartesian3DToGLPosition(position);
101
105
  } else {
102
106
  vec2 mercatorXY = a_xy * POLE_BY_PI;
@@ -6,6 +6,7 @@ import { IndexPolygonMap } from "./data/index-polygon-map";
6
6
  import { TestRecords } from "./test-records";
7
7
  import { defaultblendfunction } from "../../../util/globe-default-gl-states";
8
8
  import { opacityCheck } from "../../../util/check/typecheck";
9
+ import { DEPTH_START_ANGLE } from "../../../programs/polygon-on-globe/texture-dem-triangles";
9
10
  export class TerrainPolygonSemiPlugin {
10
11
  id;
11
12
  globe = null;
@@ -397,32 +398,59 @@ export class TerrainPolygonSemiPlugin {
397
398
  }
398
399
  draw3D() {
399
400
  const gl = this.globe.gl;
401
+ const { Tilt } = this.globe.api_GetCurrentLookInfo();
402
+ const useDepth = Tilt > DEPTH_START_ANGLE;
400
403
  gl.disable(gl.DEPTH_TEST);
401
404
  gl.enable(gl.BLEND);
402
405
  defaultblendfunction(gl);
406
+ // Use LEQUAL. Since Poly didn't write depth, lines test against Terrain.
407
+ // Vertices match terrain, so LEQUAL passes.
408
+ // FIX: Line vs Terrain z-fighting.
409
+ // polygonOffset does NOT work reliably for lines in WebGL implementations.
410
+ // We use gl.depthRange to bias the depth values of the lines slightly towards the camera.
411
+ // This pulls the lines "forward" mathematically without changing geometry.
403
412
  // drawPoints
404
413
  if (this._options.showTesselationPoints) {
405
414
  this._program.draw(this._attributeLoader, this._drawPointsRangeIndexParams, this._uboHandler);
406
415
  }
407
- if (this._pickerDisplayer && !this._options.pickablePause) {
416
+ if (this._pickerDisplayer && !this._options.pickablePause && !useDepth) {
408
417
  this._pickerDisplayer.bindFBO();
409
418
  this._pickerDisplayer.clearTextures();
410
- // gl.enable(gl.DEPTH_TEST);
411
419
  }
412
420
  gl.frontFace(gl.CW);
421
+ let prevDepthMask;
422
+ let origDepthRange;
423
+ if (useDepth) {
424
+ // --- FIX START: Poly/Edge Z-Fighting ---
425
+ // 1. Enable Depth Test so offset works against terrain
426
+ gl.enable(gl.DEPTH_TEST);
427
+ // 2. Pull polygons closer to camera to avoid terrain fighting
428
+ gl.enable(gl.POLYGON_OFFSET_FILL);
429
+ gl.polygonOffset(-2.0, -2.0);
430
+ origDepthRange = gl.getParameter(gl.DEPTH_RANGE);
431
+ gl.depthRange(origDepthRange[0], origDepthRange[1] - 0.0017);
432
+ // 3. Disable Depth Write so edges (drawn later) can overlap cleanly without fighting
433
+ // (Edges will test against Terrain depth, which they pass/equal)
434
+ prevDepthMask = gl.getParameter(gl.DEPTH_WRITEMASK);
435
+ gl.depthMask(false);
436
+ }
413
437
  this._program.draw(this._attributeLoader, this._drawRangeIndexParams, this._uboHandler);
438
+ // Restore states
439
+ // --- FIX END ---
414
440
  gl.frontFace(gl.CCW);
415
- if (this._pickerDisplayer && !this._options.pickablePause) {
441
+ if (this._pickerDisplayer && !this._options.pickablePause && !useDepth) {
416
442
  gl.bindFramebuffer(gl.FRAMEBUFFER, null);
417
443
  this._pickerDisplayer.drawColorTexture();
418
444
  this._selfSelect();
419
445
  }
420
446
  if (this._options.drawEdges) {
421
- gl.disable(gl.DEPTH_TEST);
422
- // gl.enable(gl.POLYGON_OFFSET_FILL);
423
- // gl.polygonOffset(-3.0, -3.0);
424
447
  this._program.draw(this._attributeLoader, this._drawRealEdgeArcs, this._uboForRealEdgeArcs);
425
- // gl.disable(gl.POLYGON_OFFSET_FILL);
448
+ // Restore original depth range immediately
449
+ }
450
+ if (useDepth) {
451
+ gl.depthMask(prevDepthMask);
452
+ gl.depthRange(origDepthRange[0], origDepthRange[1]);
453
+ gl.disable(gl.POLYGON_OFFSET_FILL);
426
454
  }
427
455
  gl.enable(gl.DEPTH_TEST);
428
456
  }