@pirireis/webglobeplugins 1.2.17 → 1.2.20
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
|
@@ -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
|
-
|
|
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;
|
|
@@ -297,6 +298,8 @@ export class TerrainPolygonSemiPlugin {
|
|
|
297
298
|
if (this._options.pickable === false) {
|
|
298
299
|
throw new Error("TerrainPolygonSemiPlugin is not pickable. Set pickable option to true on construction to enable picking.");
|
|
299
300
|
}
|
|
301
|
+
if (!this._useDepth())
|
|
302
|
+
return null;
|
|
300
303
|
return this._lastPickedPolygon;
|
|
301
304
|
}
|
|
302
305
|
getPolygon(key) {
|
|
@@ -395,34 +398,75 @@ export class TerrainPolygonSemiPlugin {
|
|
|
395
398
|
this._pickerDisplayer?.resize();
|
|
396
399
|
}
|
|
397
400
|
}
|
|
401
|
+
_useDepth() {
|
|
402
|
+
const { Tilt } = this.globe.api_GetCurrentLookInfo();
|
|
403
|
+
const useDepth = Tilt > DEPTH_START_ANGLE;
|
|
404
|
+
if (this._lastPickedPolygon !== null && useDepth) {
|
|
405
|
+
this._lastPickedPolygon = null;
|
|
406
|
+
this.globe.DrawRender();
|
|
407
|
+
this._uboHandler.updateSingle("private_pickedIndex", new Float32Array([IndexAttributeEscapeValue]));
|
|
408
|
+
}
|
|
409
|
+
return useDepth;
|
|
410
|
+
}
|
|
411
|
+
getDepthStartAngle() {
|
|
412
|
+
return DEPTH_START_ANGLE;
|
|
413
|
+
}
|
|
398
414
|
draw3D() {
|
|
399
415
|
const gl = this.globe.gl;
|
|
400
|
-
|
|
416
|
+
const useDepth = this._useDepth();
|
|
401
417
|
gl.enable(gl.BLEND);
|
|
402
418
|
defaultblendfunction(gl);
|
|
419
|
+
// Use LEQUAL. Since Poly didn't write depth, lines test against Terrain.
|
|
420
|
+
// Vertices match terrain, so LEQUAL passes.
|
|
421
|
+
// FIX: Line vs Terrain z-fighting.
|
|
422
|
+
// polygonOffset does NOT work reliably for lines in WebGL implementations.
|
|
423
|
+
// We use gl.depthRange to bias the depth values of the lines slightly towards the camera.
|
|
424
|
+
// This pulls the lines "forward" mathematically without changing geometry.
|
|
403
425
|
// drawPoints
|
|
404
426
|
if (this._options.showTesselationPoints) {
|
|
405
427
|
this._program.draw(this._attributeLoader, this._drawPointsRangeIndexParams, this._uboHandler);
|
|
406
428
|
}
|
|
407
|
-
if (this._pickerDisplayer && !this._options.pickablePause) {
|
|
429
|
+
if (this._pickerDisplayer && !this._options.pickablePause && !useDepth) {
|
|
408
430
|
this._pickerDisplayer.bindFBO();
|
|
409
431
|
this._pickerDisplayer.clearTextures();
|
|
410
|
-
// gl.enable(gl.DEPTH_TEST);
|
|
411
432
|
}
|
|
412
433
|
gl.frontFace(gl.CW);
|
|
434
|
+
let prevDepthMask;
|
|
435
|
+
let origDepthRange;
|
|
436
|
+
if (useDepth) {
|
|
437
|
+
// --- FIX START: Poly/Edge Z-Fighting ---
|
|
438
|
+
// 1. Enable Depth Test so offset works against terrain
|
|
439
|
+
gl.enable(gl.DEPTH_TEST);
|
|
440
|
+
// 2. Pull polygons closer to camera to avoid terrain fighting
|
|
441
|
+
gl.enable(gl.POLYGON_OFFSET_FILL);
|
|
442
|
+
gl.polygonOffset(-2.0, -2.0);
|
|
443
|
+
origDepthRange = gl.getParameter(gl.DEPTH_RANGE);
|
|
444
|
+
gl.depthRange(origDepthRange[0], origDepthRange[1] - 0.0017);
|
|
445
|
+
// 3. Disable Depth Write so edges (drawn later) can overlap cleanly without fighting
|
|
446
|
+
// (Edges will test against Terrain depth, which they pass/equal)
|
|
447
|
+
prevDepthMask = gl.getParameter(gl.DEPTH_WRITEMASK);
|
|
448
|
+
gl.depthMask(false);
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
gl.disable(gl.DEPTH_TEST);
|
|
452
|
+
}
|
|
413
453
|
this._program.draw(this._attributeLoader, this._drawRangeIndexParams, this._uboHandler);
|
|
454
|
+
// Restore states
|
|
455
|
+
// --- FIX END ---
|
|
414
456
|
gl.frontFace(gl.CCW);
|
|
415
|
-
if (this._pickerDisplayer && !this._options.pickablePause) {
|
|
457
|
+
if (this._pickerDisplayer && !this._options.pickablePause && !useDepth) {
|
|
416
458
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
417
459
|
this._pickerDisplayer.drawColorTexture();
|
|
418
460
|
this._selfSelect();
|
|
419
461
|
}
|
|
420
462
|
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
463
|
this._program.draw(this._attributeLoader, this._drawRealEdgeArcs, this._uboForRealEdgeArcs);
|
|
425
|
-
//
|
|
464
|
+
// Restore original depth range immediately
|
|
465
|
+
}
|
|
466
|
+
if (useDepth) {
|
|
467
|
+
gl.depthMask(prevDepthMask);
|
|
468
|
+
gl.depthRange(origDepthRange[0], origDepthRange[1]);
|
|
469
|
+
gl.disable(gl.POLYGON_OFFSET_FILL);
|
|
426
470
|
}
|
|
427
471
|
gl.enable(gl.DEPTH_TEST);
|
|
428
472
|
}
|
|
@@ -472,26 +516,6 @@ function inputCheck(input) {
|
|
|
472
516
|
}
|
|
473
517
|
return true;
|
|
474
518
|
}
|
|
475
|
-
function getGlStates(gl) {
|
|
476
|
-
return {
|
|
477
|
-
depthTest: gl.isEnabled(gl.DEPTH_TEST),
|
|
478
|
-
cullFace: gl.isEnabled(gl.CULL_FACE),
|
|
479
|
-
blend: gl.isEnabled(gl.BLEND),
|
|
480
|
-
scissorTest: gl.isEnabled(gl.SCISSOR_TEST),
|
|
481
|
-
depthMask: gl.getParameter(gl.DEPTH_WRITEMASK),
|
|
482
|
-
colorMask: gl.getParameter(gl.COLOR_WRITEMASK),
|
|
483
|
-
frontFace: gl.getParameter(gl.FRONT_FACE),
|
|
484
|
-
viewport: gl.getParameter(gl.VIEWPORT),
|
|
485
|
-
scissorBox: gl.getParameter(gl.SCISSOR_BOX),
|
|
486
|
-
currentProgram: gl.getParameter(gl.CURRENT_PROGRAM),
|
|
487
|
-
vao: gl.getParameter(gl.VERTEX_ARRAY_BINDING),
|
|
488
|
-
arrayBuffer: gl.getParameter(gl.ARRAY_BUFFER_BINDING),
|
|
489
|
-
elementArrayBuffer: gl.getParameter(gl.ELEMENT_ARRAY_BUFFER_BINDING),
|
|
490
|
-
framebuffer: gl.getParameter(gl.FRAMEBUFFER_BINDING),
|
|
491
|
-
activeTexture: gl.getParameter(gl.ACTIVE_TEXTURE),
|
|
492
|
-
texture2DArray: gl.getParameter(gl.TEXTURE_BINDING_2D_ARRAY),
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
519
|
function roundTo6(n) {
|
|
496
520
|
// Keep at most 6 digits after the decimal (degrees), then quantize to float32
|
|
497
521
|
// to match GPU attribute precision and make identity comparisons stable.
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* add implicit texture display program for color
|
|
3
|
-
* add fence on query return and return id.
|
|
4
|
-
* support R32I, R32F, R16UI, R32UI
|
|
5
|
-
*/
|
|
6
1
|
import { textureOnCanvasProgramCache } from "../programs/draw-texture-on-canvas";
|
|
7
2
|
import { fence } from "./fence";
|
|
8
3
|
const ESCAPE_VALUE = -1;
|