Skip to content

Commit 8cf2bf0

Browse files
committed
wip
1 parent 79bec73 commit 8cf2bf0

File tree

2 files changed

+68
-39
lines changed

2 files changed

+68
-39
lines changed

src/app/(main)/community/events/map/engine.ts

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ class MapEngine implements MapHandle {
144144
}
145145
private pointerTrail: PointerTrailEntry[] = []
146146
private pointerTrailBuffer = new Float32Array(POINTER_TRAIL_CAPACITY * 4)
147+
private lastPointerSample: { x: number; y: number; time: number } | null =
148+
null
147149
private destroyed = false
148150

149151
constructor(options: InternalOptions) {
@@ -271,21 +273,35 @@ class MapEngine implements MapHandle {
271273
}
272274

273275
private pushPointerTrail(px: number, py: number, time: number) {
274-
const last = this.pointerTrail[this.pointerTrail.length - 1]
275-
if (last) {
276-
const dx = last.x - px
277-
const dy = last.y - py
276+
const lastSample = this.lastPointerSample
277+
if (lastSample) {
278+
const dx = px - lastSample.x
279+
const dy = py - lastSample.y
278280
const distanceSq = dx * dx + dy * dy
279-
if (
280-
distanceSq <
281-
POINTER_TRAIL_MIN_DISTANCE * POINTER_TRAIL_MIN_DISTANCE
282-
) {
283-
last.x = px
284-
last.y = py
285-
last.time = time
281+
if (distanceSq < 0.25) {
282+
this.insertPointerPoint(px, py, time)
283+
this.lastPointerSample = { x: px, y: py, time }
286284
return
287285
}
286+
const distance = Math.sqrt(distanceSq)
287+
const dt = Math.max(time - lastSample.time, 1)
288+
const subdivisions = Math.min(
289+
4,
290+
Math.max(0, Math.ceil(distance / POINTER_TRAIL_MIN_DISTANCE) - 1),
291+
)
292+
for (let i = 1; i <= subdivisions; i++) {
293+
const t = i / (subdivisions + 1)
294+
const interpTime = lastSample.time + dt * t
295+
const interpX = lastSample.x + dx * t
296+
const interpY = lastSample.y + dy * t
297+
this.insertPointerPoint(interpX, interpY, interpTime)
298+
}
288299
}
300+
this.insertPointerPoint(px, py, time)
301+
this.lastPointerSample = { x: px, y: py, time }
302+
}
303+
304+
private insertPointerPoint(px: number, py: number, time: number) {
289305
if (this.pointerTrail.length >= POINTER_TRAIL_CAPACITY) {
290306
this.pointerTrail.shift()
291307
}
@@ -351,6 +367,8 @@ class MapEngine implements MapHandle {
351367
pointerPosition[1],
352368
performance.now(),
353369
)
370+
} else {
371+
this.lastPointerSample = null
354372
}
355373
if (!this.pointer.active || event.pointerId !== this.pointer.id) return
356374
const scale = this.pixelRatio
@@ -386,12 +404,14 @@ class MapEngine implements MapHandle {
386404
private handlePointerUp = (event: PointerEvent) => {
387405
if (event.type === "pointerleave" || event.type === "pointercancel") {
388406
this.hoverPointer.hasValue = false
407+
this.lastPointerSample = null
389408
}
390409
if (!this.pointer.active || event.pointerId !== this.pointer.id) return
391410
this.pointer.active = false
392411
this.canvas.releasePointerCapture(event.pointerId)
393412
this.canvas.style.cursor = "default"
394413
this.pointer.lastMoveTime = 0
414+
this.lastPointerSample = null
395415
}
396416

397417
private handleDebugClick =

src/app/(main)/community/events/map/shaders.ts

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,33 @@ void main() {
8585
if (uv.y < 0.0 || uv.y > 1.0) {
8686
discard;
8787
}
88-
vec2 delta = abs(fragPx - center);
89-
if (delta.x > 0.5 * uSquare || delta.y > 0.5 * uSquare) {
90-
discard;
91-
}
9288
float markerType = markerTypeAtCellCenterPx(center);
89+
float pointerHalo = 0.0;
90+
float pointerTrail = 0.0;
91+
for (int i = 0; i < 8; i++) {
92+
if (i >= uPointerTrailCount) {
93+
break;
94+
}
95+
vec4 entry = uPointerTrail[i];
96+
vec2 trailPos = entry.xy;
97+
float age = clamp(entry.z, 0.0, 1.0);
98+
float fade = 1.0 - age;
99+
float centerDist = length(center - trailPos);
100+
float centerInfluence = clamp(1.0 - centerDist / (uCell * 8.0), 0.0, 1.0);
101+
pointerTrail = max(pointerTrail, fade * centerInfluence);
102+
if (markerType > 0.5) {
103+
float haloRadius = 0.5 * uSquare + 3.5 * uCell;
104+
float haloDist = length(fragPx - trailPos);
105+
float haloInfluence = clamp(1.0 - haloDist / haloRadius, 0.0, 1.0);
106+
pointerHalo = max(pointerHalo, fade * haloInfluence * haloInfluence * 0.35);
107+
}
108+
}
109+
if (uPointerActive > 0 && markerType > 0.5) {
110+
float haloRadius = 0.5 * uSquare + 2.5 * uCell;
111+
float haloDist = length(fragPx - uPointerCenter);
112+
float haloFactor = clamp(1.0 - haloDist / haloRadius, 0.0, 1.0);
113+
pointerHalo = max(pointerHalo, haloFactor * 0.6);
114+
}
93115
vec2 landUV = vec2(uv.x, 1.0 - uv.y);
94116
float seaCoverage = sampleCoverage(landUV);
95117
float landCoverage = 1.0 - seaCoverage;
@@ -102,35 +124,22 @@ void main() {
102124
} else if (markerType > 0.5) {
103125
color = uMarkerColor;
104126
}
105-
float pointerHalo = 0.0;
106-
if (uPointerActive > 0 && markerType > 0.5) {
107-
vec2 pointerDelta = abs(center - uPointerCenter);
108-
if (pointerDelta.x < 0.5 * uCell && pointerDelta.y < 0.5 * uCell) {
109-
float haloRadius = 0.5 * uSquare + 0.75 * uCell;
110-
float haloDist = length(fragPx - uPointerCenter);
111-
float haloFactor = clamp(1.0 - haloDist / haloRadius, 0.0, 1.0);
112-
pointerHalo = haloFactor * haloFactor;
113-
}
127+
float halfSquare = 0.5 * uSquare;
128+
if (pointerTrail > 0.0 && markerType <= 0.5) {
129+
float shrink = clamp(1.0 - pointerTrail * 0.12, 0.9, 1.0);
130+
halfSquare *= shrink;
114131
}
115-
float pointerTrail = 0.0;
116-
for (int i = 0; i < 8; i++) {
117-
if (i >= uPointerTrailCount) {
118-
break;
119-
}
120-
vec4 entry = uPointerTrail[i];
121-
vec2 trailPos = entry.xy;
122-
float age = clamp(entry.z, 0.0, 1.0);
123-
float fade = 1.0 - age;
124-
float dist = length(center - trailPos);
125-
float influence = max(0.0, 1.0 - dist / (uCell * 3.0));
126-
pointerTrail = max(pointerTrail, fade * influence);
132+
vec2 delta = abs(fragPx - center);
133+
if (delta.x > halfSquare || delta.y > halfSquare) {
134+
discard;
127135
}
128-
if (pointerTrail > 0.0) {
129-
color = mix(color, vec3(1.0), pointerTrail * 0.3);
136+
float alpha = 1.0;
137+
if (pointerTrail > 0.0 && markerType <= 0.5) {
138+
alpha = clamp(1.0 - pointerTrail * 0.08, 0.7, 1.0);
130139
}
131140
if (pointerHalo > 0.0) {
132141
color = mix(color, vec3(1.0), pointerHalo * 0.7);
133142
}
134-
outColor = vec4(color, 1.0);
143+
outColor = vec4(color, alpha);
135144
}
136145
`

0 commit comments

Comments
 (0)