mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Draw moving icon sets on the GPU through the Cesium draw port
An icon set whose items move along motion segments, glide their course, recede toward the limb, pick through a larger proxy or switch images by drawn size, or that takes columns, now draws as one instanced IconSetPrimitive in place of its billboards. The set switches the first time an item needs it (or columns arrive) and stays switched; a course blend alone switches it only when everything it holds can go. The Cesium ports advertise columns, motionSegments and courseGlide. GPU sets refuse loudly what billboards draw and they do not: clamped heights, fadeByDistance, displayRange, offsets, anchors other than the centre, axis and screen rotations, opaque and additive blends, images other than URLs and SVG, and more images than the shared atlas has room for. A refused write changes nothing. The shared icon columns gain an image switch size, a pick proxy and a per-row depth-test distance (defaulting to always over depth, as before), arcs gain a climb rate, and the epoch rebases in both directions. Rows keep asking for frames while they move, turn or blend; a write that moves a row as it already moves (a restyle, a focus change) leaves its segment alone. Billboard icons now fade with focus as GPU ones do. Conformance gains columns and motion checks for the Cesium adapter.
This commit is contained in:
1 parent
f0427fc63e
commit
bb85e0fa74
15 files changed
+1675
-39
No files matched your search
@@ -54,11 +54,21 @@ function createAtlas() {
|
||||
return slot;
|
||||
},
|
||||
|
||||
/** Whether `url` at `sizePx` already has a slot. */
|
||||
has(url, sizePx) {
|
||||
return slotOfKey.has(`${sizePx}|${url}`);
|
||||
},
|
||||
|
||||
/** Whether a slot's image is packed and drawable. */
|
||||
ready(slot) {
|
||||
return atlas.rects[slot * 4 + 2] > 0;
|
||||
},
|
||||
|
||||
/** Whether a slot's image failed to load, or had no room to pack. */
|
||||
failed(slot) {
|
||||
return entries[slot]?.failed === true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Call `listener` after every repack, so the renderer, drawing on demand,
|
||||
* can ask for the frame that shows a newly loaded image.
|
||||
|
||||
+23
-4
@@ -9,7 +9,8 @@
|
||||
* - lerp: straight from `base` to `base + U` between two fix times (the interpolation
|
||||
* between two known fixes), course affine in the fraction;
|
||||
* - arc: a constant-rate turn from a fix in its east/north plane (`U`, `V`), with the
|
||||
* elapsed time clamped (warm-up before the first fix, coast after the last).
|
||||
* elapsed time clamped (warm-up before the first fix, coast after the last),
|
||||
* climbing along the fix's up axis (`U × V`) at a constant rate.
|
||||
*
|
||||
* The arc uses `cos a − cos(a+b) = 2 sin(b/2) sin(a+b/2)`, so its offset is
|
||||
* `v·t·sinc(ωt/2)·(sin, cos)(a + ωt/2)`: no cancellation in float32 and no branch
|
||||
@@ -43,6 +44,7 @@ const TRACK = 17; // rad, clockwise from north
|
||||
const OMEGA = 18; // rad/s
|
||||
const COURSE0 = 19; // deg
|
||||
const COURSE_SLOPE = 20; // lerp: deg per unit fraction
|
||||
const CLIMB = 20; // arc: m/s along the fix's up axis (U × V)
|
||||
const SLEW_OFFSET = 21; // deg still to glide at SLEW_T0
|
||||
const SLEW_T0 = 22; // s
|
||||
const SLEW_RATE = 23; // deg/s; negative holds the course at the glide's start
|
||||
@@ -107,11 +109,13 @@ export function writeLerpSegment(out, row, segment) {
|
||||
|
||||
/**
|
||||
* Turn at a constant rate from `fix` (at `t0`) in its east/north plane, with the
|
||||
* elapsed time clamped to `[minDt, maxDt]`.
|
||||
* elapsed time clamped to `[minDt, maxDt]`, climbing along the fix's up axis at
|
||||
* `climbMps` (default 0).
|
||||
* @param {Float32Array} out
|
||||
* @param {number} row
|
||||
* @param {{fix: Cesium.Cartesian3, t0: number, minDt: number, maxDt: number,
|
||||
* speedMps: number, trackDeg: number, turnRateDps: number}} segment
|
||||
* speedMps: number, trackDeg: number, turnRateDps: number,
|
||||
* climbMps?: number}} segment
|
||||
*/
|
||||
export function writeArcSegment(out, row, segment) {
|
||||
const o = row * SEGMENT_STRIDE;
|
||||
@@ -135,6 +139,7 @@ export function writeArcSegment(out, row, segment) {
|
||||
out[o + TRACK] = (segment.trackDeg || 0) * DEG;
|
||||
out[o + OMEGA] = Math.abs(omega) < STRAIGHT_BELOW_RAD_PER_SEC ? 0 : omega;
|
||||
out[o + COURSE0] = norm360(segment.trackDeg || 0);
|
||||
out[o + CLIMB] = segment.climbMps || 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -266,6 +271,19 @@ export function segmentPosition(
|
||||
x += seg[o + AXIS_U] * e + seg[o + AXIS_V] * n;
|
||||
y += seg[o + AXIS_U + 1] * e + seg[o + AXIS_V + 1] * n;
|
||||
z += seg[o + AXIS_U + 2] * e + seg[o + AXIS_V + 2] * n;
|
||||
const climb = seg[o + CLIMB] * dt;
|
||||
if (climb !== 0) {
|
||||
// Up is east × north.
|
||||
const ux = seg[o + AXIS_U];
|
||||
const uy = seg[o + AXIS_U + 1];
|
||||
const uz = seg[o + AXIS_U + 2];
|
||||
const vx = seg[o + AXIS_V];
|
||||
const vy = seg[o + AXIS_V + 1];
|
||||
const vz = seg[o + AXIS_V + 2];
|
||||
x += (uy * vz - uz * vy) * climb;
|
||||
y += (uz * vx - ux * vz) * climb;
|
||||
z += (ux * vy - uy * vx) * climb;
|
||||
}
|
||||
}
|
||||
result.x = x;
|
||||
result.y = y;
|
||||
@@ -293,7 +311,7 @@ float iconSegmentParameter(vec4 seg3, vec4 seg4, float tau) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
vec3 iconSegmentPosition(vec4 seg0, vec4 seg1, vec4 seg2, vec4 seg3, vec4 seg4, float tau) {
|
||||
vec3 iconSegmentPosition(vec4 seg0, vec4 seg1, vec4 seg2, vec4 seg3, vec4 seg4, vec4 seg5, float tau) {
|
||||
vec3 high = seg0.xyz;
|
||||
vec3 low = vec3(seg0.w, seg1.xy);
|
||||
vec3 axisU = vec3(seg1.zw, seg2.x);
|
||||
@@ -309,6 +327,7 @@ vec3 iconSegmentPosition(vec4 seg0, vec4 seg1, vec4 seg2, vec4 seg3, vec4 seg4,
|
||||
float reach = seg4.x * t * iconSinc(half_);
|
||||
float heading = seg4.y + half_;
|
||||
p += axisU * (reach * sin(heading)) + axisV * (reach * cos(heading));
|
||||
p += cross(axisU, axisV) * (seg5.x * t);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -245,3 +245,54 @@ test('a zero-rate glide holds the course however the segment turns', () => {
|
||||
writeCourseGlide(seg, 0, 90, 0, 0);
|
||||
assert.ok(courseGap(segmentCourse(seg, 0, 20), 90) < 1e-4, 'arc turn held');
|
||||
});
|
||||
|
||||
test('an arc climbs along the fix’s up axis at its climb rate, inside its clamped time', () => {
|
||||
const seg = new Float32Array(SEGMENT_STRIDE);
|
||||
writeArcSegment(seg, 0, {
|
||||
fix,
|
||||
t0: 100,
|
||||
minDt: -10,
|
||||
maxDt: 20,
|
||||
speedMps: 200,
|
||||
trackDeg: 90,
|
||||
turnRateDps: 3,
|
||||
climbMps: 15,
|
||||
});
|
||||
const up = Cesium.Ellipsoid.WGS84.geodeticSurfaceNormal(fix);
|
||||
for (const [tau, dt] of [
|
||||
[108, 8],
|
||||
[130, 20],
|
||||
[80, -10],
|
||||
]) {
|
||||
const flat = productionArc(fix, 200, 90, 3, dt).position;
|
||||
const want = Cesium.Cartesian3.add(
|
||||
flat,
|
||||
Cesium.Cartesian3.multiplyByScalar(up, 15 * dt, new Cesium.Cartesian3()),
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
const at = segmentPosition(seg, 0, tau);
|
||||
assert.ok(
|
||||
Cesium.Cartesian3.distance(at, want) < 0.05,
|
||||
`at ${dt} s: ${Cesium.Cartesian3.distance(at, want)} m off`,
|
||||
);
|
||||
}
|
||||
// The climb does not turn the course.
|
||||
assert.ok(courseGap(segmentCourse(seg, 0, 108), 90 + 3 * 8) < 1e-3);
|
||||
});
|
||||
|
||||
test('an arc written without a climb stays in its tangent plane', () => {
|
||||
const seg = new Float32Array(SEGMENT_STRIDE);
|
||||
seg.fill(7);
|
||||
writeArcSegment(seg, 0, {
|
||||
fix,
|
||||
t0: 0,
|
||||
minDt: 0,
|
||||
maxDt: 30,
|
||||
speedMps: 100,
|
||||
trackDeg: 0,
|
||||
turnRateDps: 0,
|
||||
});
|
||||
const at = segmentPosition(seg, 0, 30);
|
||||
const want = productionArc(fix, 100, 0, 0, 30).position;
|
||||
assert.ok(Cesium.Cartesian3.distance(at, want) < 0.05);
|
||||
});
|
||||
+73
-7
@@ -14,6 +14,7 @@
|
||||
* long the session runs.
|
||||
*/
|
||||
import * as Cesium from 'cesium';
|
||||
import { HORIZON_LIFT_M } from '../geo/horizon.js';
|
||||
import {
|
||||
SEGMENT_STRIDE,
|
||||
segmentCourse,
|
||||
@@ -21,8 +22,11 @@ import {
|
||||
shiftSegmentTimes,
|
||||
} from './iconSegment.js';
|
||||
|
||||
/** Floats per row of style: size, scale, alpha, atlas slots, flags, focus, near/far scaler. */
|
||||
export const STYLE_STRIDE = 12;
|
||||
/**
|
||||
* Floats per row of style: size, scale, alpha, atlas slots, flags, focus,
|
||||
* near/far scaler, near-image switch, pick proxy and depth-test distance.
|
||||
*/
|
||||
export const STYLE_STRIDE = 16;
|
||||
|
||||
const WIDTH = 0;
|
||||
const HEIGHT = 1;
|
||||
@@ -36,6 +40,16 @@ const NEAR_DISTANCE = 8;
|
||||
const NEAR_VALUE = 9;
|
||||
const FAR_DISTANCE = 10;
|
||||
const FAR_VALUE = 11;
|
||||
const IMAGE_SWITCH = 12;
|
||||
const PROXY_WIDTH = 13;
|
||||
const PROXY_HEIGHT = 14;
|
||||
const DEPTH_TEST_DISTANCE = 15;
|
||||
|
||||
/**
|
||||
* A depth-test distance at or past this draws over depth at any distance
|
||||
* (Infinity, which a float column does not carry through every GPU).
|
||||
*/
|
||||
export const ICON_ALWAYS_OVER_DEPTH = 1e30;
|
||||
|
||||
/** Row flags, combined in the style's flags float. */
|
||||
export const ICON_SHOWN = 1;
|
||||
@@ -50,9 +64,9 @@ export const ICON_RECEDES = 4;
|
||||
*/
|
||||
export const ICON_CULL_LIFT = 8;
|
||||
/** The ellipsoid height a CULL_LIFT row is raised to for the horizon test. */
|
||||
export const ICON_CULL_HEIGHT_M = 12;
|
||||
export const ICON_CULL_HEIGHT_M = HORIZON_LIFT_M;
|
||||
|
||||
/** Move the epoch forward once render times pass this many seconds. */
|
||||
/** Move the epoch once render times are this many seconds from it. */
|
||||
const REBASE_AFTER_SEC = 1800;
|
||||
|
||||
/**
|
||||
@@ -169,14 +183,14 @@ export function createIconSet({ capacity = 1024, epoch } = {}) {
|
||||
},
|
||||
|
||||
/**
|
||||
* Move the epoch to `julianDate` once it is more than half an hour ahead,
|
||||
* shifting every stored time. Call between frames, never while a caller holds
|
||||
* Move the epoch to `julianDate` once it is more than half an hour away
|
||||
* (ahead, or behind on a clock set back), shifting every stored time. Call between frames, never while a caller holds
|
||||
* times in the old base.
|
||||
* @returns {boolean} Whether it moved.
|
||||
*/
|
||||
rebase(julianDate) {
|
||||
const shift = set.seconds(julianDate);
|
||||
if (shift < REBASE_AFTER_SEC) return false;
|
||||
if (Math.abs(shift) < REBASE_AFTER_SEC) return false;
|
||||
for (let row = 0; row < count; row++) {
|
||||
shiftSegmentTimes(segments, row, -shift);
|
||||
expires[row] -= shift;
|
||||
@@ -231,6 +245,7 @@ export function createIconSet({ capacity = 1024, epoch } = {}) {
|
||||
style[o + FOCUS] = 1;
|
||||
style[o + IMAGE_FAR] = -1;
|
||||
style[o + IMAGE_NEAR] = -1;
|
||||
style[o + DEPTH_TEST_DISTANCE] = ICON_ALWAYS_OVER_DEPTH;
|
||||
colors.fill(255, row * 4, row * 4 + 4);
|
||||
expires[row] = -Infinity;
|
||||
markRow(row);
|
||||
@@ -360,6 +375,57 @@ export function createIconSet({ capacity = 1024, epoch } = {}) {
|
||||
return style[row * STYLE_STRIDE + IMAGE_NEAR];
|
||||
},
|
||||
|
||||
/**
|
||||
* Draw the near image once the icon is wider than `px` CSS pixels on
|
||||
* screen; 0 (the default) switches past the renderer's own device-pixel
|
||||
* threshold.
|
||||
*/
|
||||
setImageSwitch(row, px) {
|
||||
writeStyle(row, IMAGE_SWITCH, px);
|
||||
},
|
||||
imageSwitch(row) {
|
||||
return style[row * STYLE_STRIDE + IMAGE_SWITCH];
|
||||
},
|
||||
|
||||
/**
|
||||
* An invisible pick target of `width × height` CSS pixels, picked
|
||||
* wherever it or the icon covers; 0 × 0 (the default) picks the icon's
|
||||
* drawn pixels only.
|
||||
*/
|
||||
setPickProxy(row, width, height) {
|
||||
const o = row * STYLE_STRIDE;
|
||||
if (
|
||||
style[o + PROXY_WIDTH] === Math.fround(width) &&
|
||||
style[o + PROXY_HEIGHT] === Math.fround(height)
|
||||
)
|
||||
return;
|
||||
style[o + PROXY_WIDTH] = width;
|
||||
style[o + PROXY_HEIGHT] = height;
|
||||
set.dirty.style.mark(row);
|
||||
},
|
||||
pickProxyWidth(row) {
|
||||
return style[row * STYLE_STRIDE + PROXY_WIDTH];
|
||||
},
|
||||
pickProxyHeight(row) {
|
||||
return style[row * STYLE_STRIDE + PROXY_HEIGHT];
|
||||
},
|
||||
|
||||
/**
|
||||
* Draw over depth within `metres` of the eye, as a billboard's
|
||||
* `disableDepthTestDistance`: 0 tests depth everywhere, Infinity (the
|
||||
* default) never does.
|
||||
*/
|
||||
setDepthTestDistance(row, metres) {
|
||||
writeStyle(
|
||||
row,
|
||||
DEPTH_TEST_DISTANCE,
|
||||
metres >= ICON_ALWAYS_OVER_DEPTH ? ICON_ALWAYS_OVER_DEPTH : metres,
|
||||
);
|
||||
},
|
||||
depthTestDistance(row) {
|
||||
return style[row * STYLE_STRIDE + DEPTH_TEST_DISTANCE];
|
||||
},
|
||||
|
||||
/** Size by camera distance, as Cesium's NearFarScalar (unset: 1 everywhere). */
|
||||
setScaleByDistance(row, scalar) {
|
||||
const o = row * STYLE_STRIDE;
|
||||
|
||||
@@ -4,6 +4,7 @@ import * as Cesium from 'cesium';
|
||||
import {
|
||||
createIconSet,
|
||||
DirtyRows,
|
||||
ICON_ALWAYS_OVER_DEPTH,
|
||||
ICON_CULL_HEIGHT_M,
|
||||
ICON_CULL_LIFT,
|
||||
ICON_ROTATES,
|
||||
@@ -14,6 +15,7 @@ import {
|
||||
writeCourseGlide,
|
||||
writeHoldSegment,
|
||||
} from './iconSegment.js';
|
||||
import { liftedForHorizon } from '../geo/horizon.js';
|
||||
|
||||
function place(set, id, lon, course = 0) {
|
||||
const row = set.add(id, { id });
|
||||
@@ -228,6 +230,21 @@ test('rebasing moves the epoch without moving any row', () => {
|
||||
assert.deepEqual(set.dirty.segments.runs(set.count), [[0, 0]]);
|
||||
});
|
||||
|
||||
test('a clock set back more than half an hour moves the epoch back too', () => {
|
||||
const epoch = Cesium.JulianDate.fromIso8601('2026-11-03T12:00:00Z');
|
||||
const set = createIconSet({ epoch });
|
||||
const row = place(set, 'a', 4);
|
||||
const before = set.position(row, 0);
|
||||
const earlier = (s) =>
|
||||
Cesium.JulianDate.addSeconds(epoch, s, new Cesium.JulianDate());
|
||||
assert.equal(set.rebase(earlier(-1000)), false);
|
||||
assert.equal(set.rebase(earlier(-86400)), true);
|
||||
assert.equal(set.seconds(earlier(-86400)), 0);
|
||||
assert.ok(
|
||||
Cesium.Cartesian3.distance(set.position(row, 86400), before) < 0.01,
|
||||
);
|
||||
});
|
||||
|
||||
test('a cull-lift row is judged at no lower than the cull height above the ellipsoid', () => {
|
||||
const set = createIconSet();
|
||||
const row = set.add('a');
|
||||
@@ -249,3 +266,71 @@ test('a cull-lift row is judged at no lower than the cull height above the ellip
|
||||
'a contact floored higher keeps its own height',
|
||||
);
|
||||
});
|
||||
|
||||
test('the Cesium-free horizon lift judges the point a cull-lift row is judged at', () => {
|
||||
const set = createIconSet();
|
||||
const row = set.add('a');
|
||||
set.setFlag(row, ICON_CULL_LIFT, true);
|
||||
for (const [lon, lat, h] of [
|
||||
[4.05, 51.93, -40],
|
||||
[4.05, 51.93, 3],
|
||||
[-84.43, 33.64, 11.9],
|
||||
[139.7, 35.6, 500],
|
||||
[0, 89.5, -10],
|
||||
]) {
|
||||
const p = Cesium.Cartesian3.fromDegrees(lon, lat, h);
|
||||
const lifted = liftedForHorizon(p);
|
||||
assert.ok(
|
||||
Cesium.Cartesian3.distance(set.cullPoint(row, p), lifted) < 1e-6,
|
||||
`${lon}, ${lat}, ${h} m`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('a new row draws over depth everywhere, with no proxy and the default image switch', () => {
|
||||
const set = createIconSet();
|
||||
const row = set.add('a');
|
||||
assert.equal(set.depthTestDistance(row), Math.fround(ICON_ALWAYS_OVER_DEPTH));
|
||||
assert.equal(set.pickProxyWidth(row), 0);
|
||||
assert.equal(set.pickProxyHeight(row), 0);
|
||||
assert.equal(set.imageSwitch(row), 0);
|
||||
});
|
||||
|
||||
test('the switch, proxy and depth-test columns mark the row only when they change', () => {
|
||||
const set = createIconSet();
|
||||
const row = set.add('a');
|
||||
settle(set);
|
||||
set.setImageSwitch(row, 40);
|
||||
set.setPickProxy(row, 30, 20);
|
||||
set.setDepthTestDistance(row, 5000);
|
||||
assert.deepEqual(set.dirty.style.runs(set.count), [[0, 0]]);
|
||||
assert.equal(set.imageSwitch(row), 40);
|
||||
assert.equal(set.pickProxyWidth(row), 30);
|
||||
assert.equal(set.pickProxyHeight(row), 20);
|
||||
assert.equal(set.depthTestDistance(row), 5000);
|
||||
settle(set);
|
||||
set.setImageSwitch(row, 40);
|
||||
set.setPickProxy(row, 30, 20);
|
||||
set.setDepthTestDistance(row, 5000);
|
||||
assert.ok(set.dirty.style.empty, 'unchanged writes leave it clean');
|
||||
set.setDepthTestDistance(row, Infinity);
|
||||
assert.equal(
|
||||
set.depthTestDistance(row),
|
||||
Math.fround(ICON_ALWAYS_OVER_DEPTH),
|
||||
'Infinity is carried as the always-over-depth value',
|
||||
);
|
||||
});
|
||||
|
||||
test('removing a row moves its switch, proxy and depth-test columns too', () => {
|
||||
const set = createIconSet({ capacity: 4 });
|
||||
set.add('a');
|
||||
const b = set.add('b');
|
||||
set.setPickProxy(b, 44, 33);
|
||||
set.setDepthTestDistance(b, 0);
|
||||
set.remove('a');
|
||||
const moved = set.row('b');
|
||||
assert.equal(moved, 0);
|
||||
assert.equal(set.pickProxyWidth(moved), 44);
|
||||
assert.equal(set.pickProxyHeight(moved), 33);
|
||||
assert.equal(set.depthTestDistance(moved), 0);
|
||||
});
|
||||
@@ -39,6 +39,7 @@ const ATTRIBUTE_LOCATIONS = Object.freeze({
|
||||
style2: 9,
|
||||
color: 10,
|
||||
pickColor: 11,
|
||||
style3: 12,
|
||||
});
|
||||
|
||||
const VERTEX_SHADER = /* glsl */ `
|
||||
@@ -52,6 +53,7 @@ in vec4 seg5;
|
||||
in vec4 style0; // width, height, scale, alpha
|
||||
in vec4 style1; // far image, near image, flags, focus
|
||||
in vec4 style2; // scale by distance (near, near value, far, far value)
|
||||
in vec4 style3; // near-image switch (CSS px), pick proxy size (CSS px), depth-test distance
|
||||
in vec4 color;
|
||||
in vec4 pickColor;
|
||||
|
||||
@@ -63,10 +65,13 @@ uniform vec3 u_cameraUp;
|
||||
uniform vec4 u_recession; // limb distance, start ratio, strength, enabled
|
||||
uniform vec3 u_recessionFloors; // scale, alpha, combined alpha
|
||||
uniform vec4 u_slots[${MAX_ICON_SLOTS}];
|
||||
uniform float u_cull; // 1: hide rows past the ellipsoid's horizon
|
||||
uniform float u_pickPass; // 1 while drawing for a pick
|
||||
|
||||
out vec2 v_uv;
|
||||
out vec4 v_color;
|
||||
out vec4 v_pickColor;
|
||||
out float v_proxy;
|
||||
|
||||
// The row's anchor in clip space before screen offsets, for effects that wrap
|
||||
// main() (cyber sonar) and must not change geometry or picks.
|
||||
@@ -99,15 +104,16 @@ void main() {
|
||||
v_pickColor = pickColor;
|
||||
v_uv = vec2(0.0);
|
||||
v_color = vec4(0.0);
|
||||
v_proxy = 0.0;
|
||||
gl_Position = vec4(0.0, 0.0, 2.0, 1.0); // outside the clip volume: not drawn
|
||||
|
||||
float flags = style1.z;
|
||||
if (!iconFlag(flags, 1.0)) return;
|
||||
|
||||
vec3 rte = iconSegmentPosition(seg0, seg1, seg2, seg3, seg4, u_tau);
|
||||
vec3 rte = iconSegmentPosition(seg0, seg1, seg2, seg3, seg4, seg5, u_tau);
|
||||
vec3 world = u_cameraPosition + rte;
|
||||
vec3 cullPoint = iconFlag(flags, ${ICON_CULL_LIFT.toFixed(1)}) ? iconCullPoint(world) : world;
|
||||
if (occludedByEllipsoid(cullPoint)) return;
|
||||
if (u_cull > 0.5 && occludedByEllipsoid(cullPoint)) return;
|
||||
|
||||
vec4 positionEC = czm_modelViewRelativeToEye * vec4(rte, 1.0);
|
||||
if (positionEC.z >= 0.0) return; // behind the camera
|
||||
@@ -131,12 +137,20 @@ void main() {
|
||||
}
|
||||
|
||||
float glyphPx = style0.x * scale * distanceScale * czm_pixelRatio;
|
||||
float slot = glyphPx > ${NEAR_IMAGE_PX.toFixed(1)} ? style1.y : style1.x;
|
||||
bool nearImage = style3.x > 0.0
|
||||
? glyphPx / czm_pixelRatio > style3.x
|
||||
: glyphPx > ${NEAR_IMAGE_PX.toFixed(1)};
|
||||
float slot = nearImage ? style1.y : style1.x;
|
||||
if (slot < 0.0) return; // no image set
|
||||
vec4 rect = u_slots[int(slot)];
|
||||
if (rect.z <= 0.0) return; // image not loaded yet
|
||||
|
||||
vec2 halfSize = style0.xy * (scale * distanceScale * 0.5) * corner;
|
||||
// A pick proxy: picked over the larger of it and the drawn icon.
|
||||
if (u_pickPass > 0.5 && style3.y > 0.0 && style3.z > 0.0) {
|
||||
halfSize = max(abs(halfSize), style3.yz * 0.5) * corner;
|
||||
v_proxy = 1.0;
|
||||
}
|
||||
if (iconFlag(flags, 2.0)) {
|
||||
float course = radians(iconSegmentCourse(seg3, seg4, seg5, u_tau));
|
||||
vec3 up = czm_geodeticSurfaceNormal(world, vec3(0.0), czm_ellipsoidInverseRadii * czm_ellipsoidInverseRadii);
|
||||
@@ -162,10 +176,13 @@ void main() {
|
||||
#ifdef LOG_DEPTH
|
||||
czm_vertexLogDepth();
|
||||
#endif
|
||||
// Depth test disabled at any distance: draw on the near plane, as a billboard
|
||||
// with disableDepthTestDistance = Infinity.
|
||||
// Depth test disabled within the row's distance (by default at any
|
||||
// distance): draw on the near plane, as a billboard does inside its
|
||||
// disableDepthTestDistance.
|
||||
float zclip = gl_Position.z / gl_Position.w;
|
||||
if (zclip >= -1.0 && zclip <= 1.0) {
|
||||
bool overDepth = style3.w >= 1.0e30 || // ICON_ALWAYS_OVER_DEPTH
|
||||
distanceSq < style3.w * style3.w;
|
||||
if (overDepth && zclip >= -1.0 && zclip <= 1.0) {
|
||||
gl_Position.z = -gl_Position.w;
|
||||
#ifdef LOG_DEPTH
|
||||
v_depthFromNearPlusOne = 1.0;
|
||||
@@ -183,10 +200,13 @@ uniform sampler2D u_atlas;
|
||||
in vec2 v_uv;
|
||||
in vec4 v_color;
|
||||
in vec4 v_pickColor;
|
||||
in float v_proxy;
|
||||
|
||||
void main() {
|
||||
vec4 color = czm_gammaCorrect(texture(u_atlas, v_uv));
|
||||
color *= czm_gammaCorrect(v_color);
|
||||
// A pick proxy is picked wherever it covers, drawn or not.
|
||||
if (v_proxy > 0.5) color = vec4(1.0);
|
||||
if (color.a < 0.005) discard;
|
||||
#ifdef OPAQUE
|
||||
if (color.a < 0.995) discard;
|
||||
@@ -208,16 +228,24 @@ const EARTH_BOUNDS = new Cesium.BoundingSphere(
|
||||
);
|
||||
|
||||
/**
|
||||
* @param {{ set: object, renderTime: () => Cesium.JulianDate,
|
||||
* requestRender?: () => void }} options `renderTime` gives the instant to draw
|
||||
* at (the layer's delayed clock). `requestRender` asks for a frame when the
|
||||
* atlas packs a newly loaded image, for a layer that does not render
|
||||
* continuously.
|
||||
* @param {{ set: object, renderTime: (frameState: object) => Cesium.JulianDate,
|
||||
* requestRender?: () => void, cull?: () => boolean,
|
||||
* pickObject?: (id: string, set: object, primitive: object) => object }} options
|
||||
* `renderTime` gives the instant to draw at (the layer's delayed clock), from
|
||||
* the frame being drawn. `requestRender` asks for a frame when the atlas packs
|
||||
* a newly loaded image, for a layer that does not render continuously.
|
||||
* `cull` says whether rows past the ellipsoid's horizon are hidden (by
|
||||
* default always). `pickObject` builds a row's pick object around the
|
||||
* `primitive` drill picks hide it by (by default `{ id, iconSet, meta,
|
||||
* primitive }`).
|
||||
*/
|
||||
export class IconSetPrimitive {
|
||||
constructor({ set, renderTime, requestRender }) {
|
||||
constructor({ set, renderTime, requestRender, cull, pickObject }) {
|
||||
this.set = set;
|
||||
this.renderTime = renderTime;
|
||||
this._cull = cull ?? (() => true);
|
||||
this._pickObject = pickObject ?? null;
|
||||
this._pickPass = 0;
|
||||
this._stopAtlasListener = requestRender
|
||||
? iconAtlas.onChange(requestRender)
|
||||
: null;
|
||||
@@ -254,6 +282,8 @@ export class IconSetPrimitive {
|
||||
u_recessionFloors: () => primitive._recessionFloors,
|
||||
u_slots: () => primitive._slots,
|
||||
u_atlas: () => primitive._texture,
|
||||
u_cull: () => (primitive._cull() ? 1 : 0),
|
||||
u_pickPass: () => primitive._pickPass,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -272,7 +302,9 @@ export class IconSetPrimitive {
|
||||
const context = frameState.context;
|
||||
this._syncAtlas(context);
|
||||
if (!this._texture) return;
|
||||
const renderTime = this.renderTime();
|
||||
// Read as the commands run, which they do right after this update.
|
||||
this._pickPass = frameState.passes.pick ? 1 : 0;
|
||||
const renderTime = this.renderTime(frameState);
|
||||
set.rebase(renderTime);
|
||||
if (this._generation !== set.generation) this._allocate(context);
|
||||
this._upload(context);
|
||||
@@ -364,7 +396,7 @@ export class IconSetPrimitive {
|
||||
strideInBytes: SEGMENT_BYTES,
|
||||
instanceDivisor: 1,
|
||||
});
|
||||
for (let i = 0; i < 3; i++)
|
||||
for (let i = 0; i < 4; i++)
|
||||
attributes.push({
|
||||
index: ATTRIBUTE_LOCATIONS[`style${i}`],
|
||||
vertexBuffer: buffers.style,
|
||||
@@ -448,17 +480,19 @@ export class IconSetPrimitive {
|
||||
},
|
||||
};
|
||||
handle = {
|
||||
pickId: context.createPickId({
|
||||
id,
|
||||
// Which set drew the pick: ownership for layers whose row ids are
|
||||
// upstream ids a sibling may share.
|
||||
iconSet: set,
|
||||
get meta() {
|
||||
const at = set.row(id);
|
||||
return at >= 0 ? set.metaAt(at) : undefined;
|
||||
pickId: context.createPickId(
|
||||
this._pickObject?.(id, set, facade) ?? {
|
||||
id,
|
||||
// Which set drew the pick: ownership for layers whose row ids are
|
||||
// upstream ids a sibling may share.
|
||||
iconSet: set,
|
||||
get meta() {
|
||||
const at = set.row(id);
|
||||
return at >= 0 ? set.metaAt(at) : undefined;
|
||||
},
|
||||
primitive: facade,
|
||||
},
|
||||
primitive: facade,
|
||||
}),
|
||||
),
|
||||
};
|
||||
set.setHandle(row, handle);
|
||||
}
|
||||
|
||||
@@ -186,6 +186,7 @@ test('consumer build includes only infrastructure code and resolves assets under
|
||||
const entry = output.find((item) => item.type === 'chunk' && item.isEntry);
|
||||
const sources = Object.keys(entry.modules).filter((id) => id.endsWith('.js'));
|
||||
assert.deepEqual(sources.map((id) => id.split('/').at(-1)).sort(), [
|
||||
'aircraftRecession.js',
|
||||
'camera.js',
|
||||
'cameraControls.js',
|
||||
'cameraInput.js',
|
||||
@@ -200,7 +201,13 @@ test('consumer build includes only infrastructure code and resolves assets under
|
||||
'events.js',
|
||||
'follow.js',
|
||||
'frame.js',
|
||||
'gpuIcons.js',
|
||||
'heights.js',
|
||||
'horizon.js',
|
||||
'iconAtlas.js',
|
||||
'iconSegment.js',
|
||||
'iconSet.js',
|
||||
'iconSetPrimitive.js',
|
||||
'infrastructure.js',
|
||||
'infrastructureData.js',
|
||||
'infrastructureOverlayEntry.js',
|
||||
@@ -209,6 +216,7 @@ test('consumer build includes only infrastructure code and resolves assets under
|
||||
'internals.js',
|
||||
'localGeojsonCore.js',
|
||||
'localGeojsonLod.js',
|
||||
'motionModel.js',
|
||||
'pickRegistry.js',
|
||||
'query.js',
|
||||
'rendererOf.js',
|
||||
|
||||
Reference in new issue
Block a user