@playcanvas/supersplat-viewer 1.16.4 → 1.16.6
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/dist/index.js +1 -1
- package/package.json +1 -1
- package/public/index.js +892 -25
- package/public/index.js.map +1 -1
package/public/index.js
CHANGED
|
@@ -22008,7 +22008,7 @@ class RenderPassUpdateClustered extends RenderPass {
|
|
|
22008
22008
|
let _skinUpdateIndex = 0;
|
|
22009
22009
|
const viewProjMat = new Mat4();
|
|
22010
22010
|
const viewInvMat = new Mat4();
|
|
22011
|
-
const viewMat = new Mat4();
|
|
22011
|
+
const viewMat$1 = new Mat4();
|
|
22012
22012
|
const viewMat3 = new Mat3();
|
|
22013
22013
|
const tempSphere = new BoundingSphere();
|
|
22014
22014
|
const tempFrustum = new Frustum();
|
|
@@ -22155,11 +22155,11 @@ class Renderer {
|
|
|
22155
22155
|
viewInvMat.setTRS(pos, rot, Vec3.ONE);
|
|
22156
22156
|
}
|
|
22157
22157
|
this.viewInvId.setValue(viewInvMat.data);
|
|
22158
|
-
viewMat.copy(viewInvMat).invert();
|
|
22159
|
-
this.viewId.setValue(viewMat.data);
|
|
22160
|
-
viewMat3.setFromMat4(viewMat);
|
|
22158
|
+
viewMat$1.copy(viewInvMat).invert();
|
|
22159
|
+
this.viewId.setValue(viewMat$1.data);
|
|
22160
|
+
viewMat3.setFromMat4(viewMat$1);
|
|
22161
22161
|
this.viewId3.setValue(viewMat3.data);
|
|
22162
|
-
viewProjMat.mul2(projMat, viewMat);
|
|
22162
|
+
viewProjMat.mul2(projMat, viewMat$1);
|
|
22163
22163
|
this.viewProjId.setValue(viewProjMat.data);
|
|
22164
22164
|
camera._storeShaderMatrices(viewProjMat, jitterX, jitterY, this.device.renderVersion);
|
|
22165
22165
|
this.flipYId.setValue(flipY ? -1 : 1);
|
|
@@ -22243,8 +22243,8 @@ class Renderer {
|
|
|
22243
22243
|
viewInvMat.setTRS(pos, rot, Vec3.ONE);
|
|
22244
22244
|
this.viewInvId.setValue(viewInvMat.data);
|
|
22245
22245
|
}
|
|
22246
|
-
viewMat.copy(viewInvMat).invert();
|
|
22247
|
-
viewProjMat.mul2(projMat, viewMat);
|
|
22246
|
+
viewMat$1.copy(viewInvMat).invert();
|
|
22247
|
+
viewProjMat.mul2(projMat, viewMat$1);
|
|
22248
22248
|
camera.frustum.setFromMat4(viewProjMat);
|
|
22249
22249
|
}
|
|
22250
22250
|
setBaseConstants(device, material) {
|
|
@@ -70618,15 +70618,21 @@ const createRotateTrack = (position, target, fov, keys = 12, duration = 20) => {
|
|
|
70618
70618
|
const positions = [];
|
|
70619
70619
|
const targets = [];
|
|
70620
70620
|
const fovs = new Array(keys).fill(fov);
|
|
70621
|
-
const
|
|
70622
|
-
const
|
|
70623
|
-
const
|
|
70621
|
+
const dx = position.x - target.x;
|
|
70622
|
+
const dy = position.y - target.y;
|
|
70623
|
+
const dz = position.z - target.z;
|
|
70624
|
+
const horizontalRadius = Math.sqrt(dx * dx + dz * dz);
|
|
70625
|
+
const totalDist = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
70626
|
+
// when the offset is nearly vertical, use a fraction of the total distance
|
|
70627
|
+
// as the orbit radius so the camera actually moves in a circle
|
|
70628
|
+
const minRadius = totalDist * 0.3;
|
|
70629
|
+
const radius = Math.max(horizontalRadius, minRadius);
|
|
70630
|
+
const startAngle = Math.atan2(dx, dz);
|
|
70624
70631
|
for (let i = 0; i < keys; ++i) {
|
|
70625
|
-
|
|
70626
|
-
|
|
70627
|
-
positions.push(target.
|
|
70628
|
-
positions.push(target.
|
|
70629
|
-
positions.push(target.z + vec.z);
|
|
70632
|
+
const angle = startAngle - i / keys * Math.PI * 2;
|
|
70633
|
+
positions.push(target.x + radius * Math.sin(angle));
|
|
70634
|
+
positions.push(target.y + dy);
|
|
70635
|
+
positions.push(target.z + radius * Math.cos(angle));
|
|
70630
70636
|
targets.push(target.x);
|
|
70631
70637
|
targets.push(target.y);
|
|
70632
70638
|
targets.push(target.z);
|
|
@@ -70788,8 +70794,9 @@ const nearlyEquals = (a, b, epsilon = 1e-4) => {
|
|
|
70788
70794
|
};
|
|
70789
70795
|
const vecToAngles = (result, vec) => {
|
|
70790
70796
|
const radToDeg = 180 / Math.PI;
|
|
70791
|
-
|
|
70792
|
-
result.
|
|
70797
|
+
const horizLenSq = vec.x * vec.x + vec.z * vec.z;
|
|
70798
|
+
result.x = Math.asin(Math.max(-1, Math.min(1, vec.y))) * radToDeg;
|
|
70799
|
+
result.y = horizLenSq > 1e-8 ? Math.atan2(-vec.x, -vec.z) * radToDeg : 0;
|
|
70793
70800
|
result.z = 0;
|
|
70794
70801
|
return result;
|
|
70795
70802
|
};
|
|
@@ -71199,6 +71206,112 @@ class OrbitController {
|
|
|
71199
71206
|
}
|
|
71200
71207
|
}
|
|
71201
71208
|
|
|
71209
|
+
const RAD_TO_DEG = 180 / Math.PI;
|
|
71210
|
+
/** XZ distance below which the walker considers itself arrived */
|
|
71211
|
+
const ARRIVAL_DIST = 0.5;
|
|
71212
|
+
/** Minimum XZ speed (m/s) to not count as blocked */
|
|
71213
|
+
const BLOCKED_SPEED = 0.6;
|
|
71214
|
+
/** Seconds of continuous low-progress before stopping the walk */
|
|
71215
|
+
const BLOCKED_DURATION = 0.2;
|
|
71216
|
+
/**
|
|
71217
|
+
* Generates synthetic move/rotate input to auto-walk toward a target position.
|
|
71218
|
+
*
|
|
71219
|
+
* Designed to feed into FpsController's existing update path so there is no
|
|
71220
|
+
* duplicated physics. Each frame it appends yaw-rotation and forward-movement
|
|
71221
|
+
* deltas to the shared CameraFrame, and monitors arrival / blocked conditions.
|
|
71222
|
+
*/
|
|
71223
|
+
class WalkSource {
|
|
71224
|
+
/**
|
|
71225
|
+
* Forward input scale (matches InputController.moveSpeed for consistent
|
|
71226
|
+
* speed with regular WASD walking).
|
|
71227
|
+
*/
|
|
71228
|
+
walkSpeed = 4;
|
|
71229
|
+
/**
|
|
71230
|
+
* Yaw rotation damping while auto-walking toward a target.
|
|
71231
|
+
*/
|
|
71232
|
+
rotateDamping = 0.99;
|
|
71233
|
+
/**
|
|
71234
|
+
* Callback fired when an auto-walk completes (arrival or obstacle).
|
|
71235
|
+
*/
|
|
71236
|
+
onComplete = null;
|
|
71237
|
+
_target = null;
|
|
71238
|
+
_blockedTime = 0;
|
|
71239
|
+
_prevDist = Infinity;
|
|
71240
|
+
get isWalking() {
|
|
71241
|
+
return this._target !== null;
|
|
71242
|
+
}
|
|
71243
|
+
/**
|
|
71244
|
+
* Begin auto-walking toward a world-space target position.
|
|
71245
|
+
*
|
|
71246
|
+
* @param target - The destination (XZ used for navigation).
|
|
71247
|
+
*/
|
|
71248
|
+
walkTo(target) {
|
|
71249
|
+
if (!this._target) {
|
|
71250
|
+
this._target = new Vec3();
|
|
71251
|
+
}
|
|
71252
|
+
this._target.copy(target);
|
|
71253
|
+
this._blockedTime = 0;
|
|
71254
|
+
this._prevDist = Infinity;
|
|
71255
|
+
}
|
|
71256
|
+
/**
|
|
71257
|
+
* Cancel any active auto-walk.
|
|
71258
|
+
*/
|
|
71259
|
+
cancelWalk() {
|
|
71260
|
+
if (this._target) {
|
|
71261
|
+
this._target = null;
|
|
71262
|
+
this._blockedTime = 0;
|
|
71263
|
+
this.onComplete?.();
|
|
71264
|
+
}
|
|
71265
|
+
}
|
|
71266
|
+
/**
|
|
71267
|
+
* Compute walk deltas and append them to the frame. Must be called
|
|
71268
|
+
* before* the camera controller reads the frame.
|
|
71269
|
+
*
|
|
71270
|
+
* @param dt - Frame delta time in seconds.
|
|
71271
|
+
* @param cameraPosition - Camera world position (previous frame output).
|
|
71272
|
+
* @param cameraAngles - Camera Euler angles in degrees (previous frame output).
|
|
71273
|
+
* @param frame - The shared CameraFrame to append deltas to.
|
|
71274
|
+
*/
|
|
71275
|
+
update(dt, cameraPosition, cameraAngles, frame) {
|
|
71276
|
+
if (!this._target)
|
|
71277
|
+
return;
|
|
71278
|
+
const target = this._target;
|
|
71279
|
+
const dx = target.x - cameraPosition.x;
|
|
71280
|
+
const dz = target.z - cameraPosition.z;
|
|
71281
|
+
const xzDist = Math.sqrt(dx * dx + dz * dz);
|
|
71282
|
+
// arrival
|
|
71283
|
+
if (xzDist < ARRIVAL_DIST) {
|
|
71284
|
+
this.cancelWalk();
|
|
71285
|
+
return;
|
|
71286
|
+
}
|
|
71287
|
+
// blocked detection: compare with previous frame's distance
|
|
71288
|
+
if (this._prevDist !== Infinity && dt > 0) {
|
|
71289
|
+
const speed = (this._prevDist - xzDist) / dt;
|
|
71290
|
+
if (speed < BLOCKED_SPEED) {
|
|
71291
|
+
this._blockedTime += dt;
|
|
71292
|
+
if (this._blockedTime >= BLOCKED_DURATION) {
|
|
71293
|
+
this.cancelWalk();
|
|
71294
|
+
return;
|
|
71295
|
+
}
|
|
71296
|
+
}
|
|
71297
|
+
else {
|
|
71298
|
+
this._blockedTime = 0;
|
|
71299
|
+
}
|
|
71300
|
+
}
|
|
71301
|
+
this._prevDist = xzDist;
|
|
71302
|
+
// yaw toward target
|
|
71303
|
+
const targetYaw = Math.atan2(-dx, -dz) * RAD_TO_DEG;
|
|
71304
|
+
let yawDiff = targetYaw - cameraAngles.y;
|
|
71305
|
+
yawDiff = ((yawDiff % 360) + 540) % 360 - 180;
|
|
71306
|
+
const rotAlpha = damp(this.rotateDamping, dt);
|
|
71307
|
+
// FpsController applies: _angles.y += -rotate[0]
|
|
71308
|
+
frame.deltas.rotate.append([-(yawDiff * rotAlpha), 0, 0]);
|
|
71309
|
+
// scale forward speed by alignment: turn in place first, then accelerate
|
|
71310
|
+
const alignment = Math.max(0, Math.cos(yawDiff * Math.PI / 180));
|
|
71311
|
+
frame.deltas.move.append([0, 0, this.walkSpeed * dt * alignment]);
|
|
71312
|
+
}
|
|
71313
|
+
}
|
|
71314
|
+
|
|
71202
71315
|
const tmpCamera = new Camera();
|
|
71203
71316
|
const tmpv = new Vec3();
|
|
71204
71317
|
const createCamera = (position, target, fov) => {
|
|
@@ -71246,6 +71359,10 @@ class CameraManager {
|
|
|
71246
71359
|
};
|
|
71247
71360
|
controllers.fly.collider = collider;
|
|
71248
71361
|
controllers.fps.collider = collider;
|
|
71362
|
+
const walkSource = new WalkSource();
|
|
71363
|
+
walkSource.onComplete = () => {
|
|
71364
|
+
events.fire('walkComplete');
|
|
71365
|
+
};
|
|
71249
71366
|
const getController = (cameraMode) => {
|
|
71250
71367
|
return controllers[cameraMode];
|
|
71251
71368
|
};
|
|
@@ -71277,6 +71394,9 @@ class CameraManager {
|
|
|
71277
71394
|
// update transition timer
|
|
71278
71395
|
transitionTimer = Math.min(1, transitionTimer + deltaTime * transitionSpeed);
|
|
71279
71396
|
const controller = getController(state.cameraMode);
|
|
71397
|
+
if (state.cameraMode === 'fps') {
|
|
71398
|
+
walkSource.update(dt, this.camera.position, this.camera.angles, frame);
|
|
71399
|
+
}
|
|
71280
71400
|
controller.update(dt, frame, target);
|
|
71281
71401
|
if (transitionTimer < 1) {
|
|
71282
71402
|
// lerp away from previous camera during transition
|
|
@@ -71347,6 +71467,9 @@ class CameraManager {
|
|
|
71347
71467
|
});
|
|
71348
71468
|
// handle camera mode switching
|
|
71349
71469
|
events.on('cameraMode:changed', (value, prev) => {
|
|
71470
|
+
if (prev === 'fps') {
|
|
71471
|
+
walkSource.cancelWalk();
|
|
71472
|
+
}
|
|
71350
71473
|
// snapshot the current pose before any controller mutation
|
|
71351
71474
|
startTransition();
|
|
71352
71475
|
target.copy(this.camera);
|
|
@@ -71386,6 +71509,21 @@ class CameraManager {
|
|
|
71386
71509
|
target.fov = tmpCamera.fov;
|
|
71387
71510
|
startTransition();
|
|
71388
71511
|
});
|
|
71512
|
+
// tap-to-walk: start auto-walking toward a picked 3D position
|
|
71513
|
+
events.on('walkTo', (position) => {
|
|
71514
|
+
if (state.cameraMode === 'fps') {
|
|
71515
|
+
walkSource.walkTo(position);
|
|
71516
|
+
events.fire('walkIndicator:setTarget', position);
|
|
71517
|
+
}
|
|
71518
|
+
});
|
|
71519
|
+
// cancel any active auto-walk
|
|
71520
|
+
events.on('walkCancel', () => {
|
|
71521
|
+
walkSource.cancelWalk();
|
|
71522
|
+
events.fire('walkIndicator:setTarget', null);
|
|
71523
|
+
});
|
|
71524
|
+
events.on('walkComplete', () => {
|
|
71525
|
+
events.fire('walkIndicator:setTarget', null);
|
|
71526
|
+
});
|
|
71389
71527
|
}
|
|
71390
71528
|
}
|
|
71391
71529
|
|
|
@@ -71659,6 +71797,10 @@ class InputController {
|
|
|
71659
71797
|
_tapTouches = 0;
|
|
71660
71798
|
_tapDelta = 0;
|
|
71661
71799
|
_tapJump = false;
|
|
71800
|
+
// Screen coordinates of the last touch start (for tap-to-walk picking)
|
|
71801
|
+
_lastTouchOffsetX = 0;
|
|
71802
|
+
_lastTouchOffsetY = 0;
|
|
71803
|
+
_picker = null;
|
|
71662
71804
|
moveSpeed = 4;
|
|
71663
71805
|
orbitSpeed = 18;
|
|
71664
71806
|
pinchSpeed = 0.4;
|
|
@@ -71691,6 +71833,13 @@ class InputController {
|
|
|
71691
71833
|
// Detect double taps manually because iOS doesn't send dblclick events
|
|
71692
71834
|
const lastTap = { time: 0, x: 0, y: 0 };
|
|
71693
71835
|
canvas.addEventListener('pointerdown', (event) => {
|
|
71836
|
+
// Store touch coordinates for tap-to-walk picking
|
|
71837
|
+
this._lastTouchOffsetX = event.offsetX;
|
|
71838
|
+
this._lastTouchOffsetY = event.offsetY;
|
|
71839
|
+
// Cancel any active auto-walk on new touch input
|
|
71840
|
+
if (state.cameraMode === 'fps' && event.pointerType === 'touch') {
|
|
71841
|
+
events.fire('walkCancel');
|
|
71842
|
+
}
|
|
71694
71843
|
const now = Date.now();
|
|
71695
71844
|
const delay = Math.max(0, now - lastTap.time);
|
|
71696
71845
|
if (delay < 300 &&
|
|
@@ -71706,16 +71855,15 @@ class InputController {
|
|
|
71706
71855
|
}
|
|
71707
71856
|
});
|
|
71708
71857
|
// Calculate pick location on double click
|
|
71709
|
-
let picker = null;
|
|
71710
71858
|
events.on('inputEvent', async (eventName, event) => {
|
|
71711
71859
|
switch (eventName) {
|
|
71712
71860
|
case 'dblclick': {
|
|
71713
71861
|
if (state.cameraMode === 'fps')
|
|
71714
71862
|
break;
|
|
71715
|
-
if (!
|
|
71716
|
-
|
|
71863
|
+
if (!this._picker) {
|
|
71864
|
+
this._picker = new Picker(app, camera);
|
|
71717
71865
|
}
|
|
71718
|
-
const result = await
|
|
71866
|
+
const result = await this._picker.pick(event.offsetX / canvas.clientWidth, event.offsetY / canvas.clientHeight);
|
|
71719
71867
|
if (result) {
|
|
71720
71868
|
events.fire('pick', result);
|
|
71721
71869
|
}
|
|
@@ -71845,7 +71993,11 @@ class InputController {
|
|
|
71845
71993
|
this._state.shift += key[keyCode.SHIFT];
|
|
71846
71994
|
this._state.ctrl += key[keyCode.CTRL];
|
|
71847
71995
|
const isFps = state.cameraMode === 'fps';
|
|
71848
|
-
//
|
|
71996
|
+
// Cancel any active auto-walk when the user provides WASD/arrow input
|
|
71997
|
+
if (isFps && (this._state.axis.x !== 0 || this._state.axis.z !== 0)) {
|
|
71998
|
+
events.fire('walkCancel');
|
|
71999
|
+
}
|
|
72000
|
+
// Tap detection using existing MultiTouchSource deltas
|
|
71849
72001
|
if (isFps) {
|
|
71850
72002
|
const prevTaps = this._tapTouches;
|
|
71851
72003
|
this._tapTouches = Math.max(0, this._tapTouches + count[0]);
|
|
@@ -71860,7 +72012,24 @@ class InputController {
|
|
|
71860
72012
|
// Touch just ended (1+ → 0): check if it was a tap
|
|
71861
72013
|
if (prevTaps > 0 && this._tapTouches === 0) {
|
|
71862
72014
|
if (this._tapDelta < TAP_EPSILON) {
|
|
71863
|
-
|
|
72015
|
+
if (state.touchControlScheme === 'pinch') {
|
|
72016
|
+
// Tap-to-walk: pick the 3D location and auto-walk toward it
|
|
72017
|
+
const { app, camera } = this.global;
|
|
72018
|
+
const canvas = app.graphicsDevice.canvas;
|
|
72019
|
+
if (!this._picker) {
|
|
72020
|
+
this._picker = new Picker(app, camera);
|
|
72021
|
+
}
|
|
72022
|
+
const pickX = this._lastTouchOffsetX / canvas.clientWidth;
|
|
72023
|
+
const pickY = this._lastTouchOffsetY / canvas.clientHeight;
|
|
72024
|
+
this._picker.pick(pickX, pickY).then((result) => {
|
|
72025
|
+
if (result && state.cameraMode === 'fps') {
|
|
72026
|
+
events.fire('walkTo', result);
|
|
72027
|
+
}
|
|
72028
|
+
});
|
|
72029
|
+
}
|
|
72030
|
+
else {
|
|
72031
|
+
this._tapJump = true;
|
|
72032
|
+
}
|
|
71864
72033
|
}
|
|
71865
72034
|
}
|
|
71866
72035
|
}
|
|
@@ -72567,6 +72736,698 @@ class VoxelDebugOverlay {
|
|
|
72567
72736
|
}
|
|
72568
72737
|
}
|
|
72569
72738
|
|
|
72739
|
+
// ── gsplat fragment shader overrides (GLSL) ─────────────────────────────────
|
|
72740
|
+
const gsplatPSGlsl = /* glsl */ `
|
|
72741
|
+
|
|
72742
|
+
#ifndef DITHER_NONE
|
|
72743
|
+
#include "bayerPS"
|
|
72744
|
+
#include "opacityDitherPS"
|
|
72745
|
+
varying float id;
|
|
72746
|
+
#endif
|
|
72747
|
+
|
|
72748
|
+
#if defined(SHADOW_PASS) || defined(PICK_PASS) || defined(PREPASS_PASS)
|
|
72749
|
+
uniform float alphaClip;
|
|
72750
|
+
#endif
|
|
72751
|
+
|
|
72752
|
+
#ifdef PREPASS_PASS
|
|
72753
|
+
varying float vLinearDepth;
|
|
72754
|
+
#include "floatAsUintPS"
|
|
72755
|
+
#endif
|
|
72756
|
+
|
|
72757
|
+
varying mediump vec2 gaussianUV;
|
|
72758
|
+
varying mediump vec4 gaussianColor;
|
|
72759
|
+
|
|
72760
|
+
#if defined(GSPLAT_UNIFIED_ID) && defined(PICK_PASS)
|
|
72761
|
+
flat varying uint vPickId;
|
|
72762
|
+
#endif
|
|
72763
|
+
|
|
72764
|
+
#ifdef PICK_PASS
|
|
72765
|
+
#include "pickPS"
|
|
72766
|
+
#endif
|
|
72767
|
+
|
|
72768
|
+
#ifndef PICK_PASS
|
|
72769
|
+
uniform vec4 camera_params;
|
|
72770
|
+
#endif
|
|
72771
|
+
uniform vec4 viewport_size;
|
|
72772
|
+
uniform mat4 matrix_projection;
|
|
72773
|
+
|
|
72774
|
+
uniform mat4 walk_viewInverse;
|
|
72775
|
+
uniform vec3 walk_target;
|
|
72776
|
+
uniform float walk_radius;
|
|
72777
|
+
uniform float walk_time;
|
|
72778
|
+
|
|
72779
|
+
float walkLinearizeDepth(float z) {
|
|
72780
|
+
if (camera_params.w == 0.0)
|
|
72781
|
+
return (camera_params.z * camera_params.y) /
|
|
72782
|
+
(camera_params.y + z * (camera_params.z - camera_params.y));
|
|
72783
|
+
else
|
|
72784
|
+
return camera_params.z + z * (camera_params.y - camera_params.z);
|
|
72785
|
+
}
|
|
72786
|
+
|
|
72787
|
+
vec3 walkReconstructWorldPos() {
|
|
72788
|
+
float linearDepth = walkLinearizeDepth(gl_FragCoord.z);
|
|
72789
|
+
vec2 ndc = gl_FragCoord.xy * viewport_size.zw * 2.0 - 1.0;
|
|
72790
|
+
vec3 viewPos = vec3(
|
|
72791
|
+
ndc.x * linearDepth / matrix_projection[0][0],
|
|
72792
|
+
ndc.y * linearDepth / matrix_projection[1][1],
|
|
72793
|
+
-linearDepth
|
|
72794
|
+
);
|
|
72795
|
+
return (walk_viewInverse * vec4(viewPos, 1.0)).xyz;
|
|
72796
|
+
}
|
|
72797
|
+
|
|
72798
|
+
const float EXP4 = exp(-4.0);
|
|
72799
|
+
const float INV_EXP4 = 1.0 / (1.0 - EXP4);
|
|
72800
|
+
|
|
72801
|
+
float normExp(float x) {
|
|
72802
|
+
return (exp(x * -4.0) - EXP4) * INV_EXP4;
|
|
72803
|
+
}
|
|
72804
|
+
|
|
72805
|
+
void main(void) {
|
|
72806
|
+
mediump float A = dot(gaussianUV, gaussianUV);
|
|
72807
|
+
if (A > 1.0) {
|
|
72808
|
+
discard;
|
|
72809
|
+
}
|
|
72810
|
+
|
|
72811
|
+
mediump float alpha = normExp(A) * gaussianColor.a;
|
|
72812
|
+
|
|
72813
|
+
#if defined(SHADOW_PASS) || defined(PICK_PASS) || defined(PREPASS_PASS)
|
|
72814
|
+
if (alpha < alphaClip) {
|
|
72815
|
+
discard;
|
|
72816
|
+
}
|
|
72817
|
+
#endif
|
|
72818
|
+
|
|
72819
|
+
#ifdef PICK_PASS
|
|
72820
|
+
|
|
72821
|
+
#ifdef GSPLAT_UNIFIED_ID
|
|
72822
|
+
pcFragColor0 = encodePickOutput(vPickId);
|
|
72823
|
+
#else
|
|
72824
|
+
pcFragColor0 = getPickOutput();
|
|
72825
|
+
#endif
|
|
72826
|
+
#ifdef DEPTH_PICK_PASS
|
|
72827
|
+
pcFragColor1 = getPickDepth();
|
|
72828
|
+
#endif
|
|
72829
|
+
|
|
72830
|
+
#elif SHADOW_PASS
|
|
72831
|
+
|
|
72832
|
+
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
|
72833
|
+
|
|
72834
|
+
#elif PREPASS_PASS
|
|
72835
|
+
|
|
72836
|
+
gl_FragColor = float2vec4(vLinearDepth);
|
|
72837
|
+
|
|
72838
|
+
#else
|
|
72839
|
+
if (alpha < 1.0 / 255.0) {
|
|
72840
|
+
discard;
|
|
72841
|
+
}
|
|
72842
|
+
|
|
72843
|
+
#ifndef DITHER_NONE
|
|
72844
|
+
opacityDither(alpha, id * 0.013);
|
|
72845
|
+
#endif
|
|
72846
|
+
|
|
72847
|
+
if (walk_radius > 0.0) {
|
|
72848
|
+
vec3 walkWorldPos = walkReconstructWorldPos();
|
|
72849
|
+
float xzDist = length(walkWorldPos.xz - walk_target.xz);
|
|
72850
|
+
|
|
72851
|
+
float nd = xzDist / walk_radius;
|
|
72852
|
+
float lightFalloff = 1.0 / (1.0 + nd * nd * 8.0);
|
|
72853
|
+
float coreBoost = 1.0 / (1.0 + nd * nd * 200.0);
|
|
72854
|
+
|
|
72855
|
+
float pulse = 1.0 + 0.1 * sin(walk_time * 3.0);
|
|
72856
|
+
|
|
72857
|
+
float ringPhase = fract(walk_time * 0.5);
|
|
72858
|
+
float ringPos = nd - ringPhase;
|
|
72859
|
+
float ringFade = 1.0 - ringPhase;
|
|
72860
|
+
float crest = smoothstep(0.1, 0.0, abs(ringPos)) * 1.0 * ringFade * (1.0 + lightFalloff);
|
|
72861
|
+
float trough = smoothstep(0.25, 0.0, abs(ringPos + 0.15)) * -1.0 * ringFade;
|
|
72862
|
+
float ring = crest + trough;
|
|
72863
|
+
|
|
72864
|
+
float intensity = (lightFalloff * 0.8 + coreBoost * 1.5 + ring) * pulse;
|
|
72865
|
+
|
|
72866
|
+
float lum = dot(gaussianColor.rgb, vec3(0.299, 0.587, 0.114));
|
|
72867
|
+
float adaptiveIntensity = intensity * (1.0 - lum * 0.7);
|
|
72868
|
+
vec3 litColor = gaussianColor.xyz * (1.0 + vec3(0.85, 0.92, 1.0) * adaptiveIntensity);
|
|
72869
|
+
float spatialFalloff = normExp(A);
|
|
72870
|
+
float boostedBase = mix(gaussianColor.a, 1.0, min(intensity * 0.3, 1.0));
|
|
72871
|
+
float glowAlpha = spatialFalloff * boostedBase;
|
|
72872
|
+
|
|
72873
|
+
gl_FragColor = vec4(litColor * glowAlpha, glowAlpha);
|
|
72874
|
+
} else {
|
|
72875
|
+
gl_FragColor = vec4(gaussianColor.xyz * alpha, alpha);
|
|
72876
|
+
}
|
|
72877
|
+
#endif
|
|
72878
|
+
}
|
|
72879
|
+
`;
|
|
72880
|
+
// ── gsplat fragment shader overrides (WGSL) ─────────────────────────────────
|
|
72881
|
+
const gsplatPSWgsl = /* wgsl */ `
|
|
72882
|
+
|
|
72883
|
+
#ifndef DITHER_NONE
|
|
72884
|
+
#include "bayerPS"
|
|
72885
|
+
#include "opacityDitherPS"
|
|
72886
|
+
varying id: f32;
|
|
72887
|
+
#endif
|
|
72888
|
+
|
|
72889
|
+
#if defined(SHADOW_PASS) || defined(PICK_PASS) || defined(PREPASS_PASS)
|
|
72890
|
+
uniform alphaClip: f32;
|
|
72891
|
+
#endif
|
|
72892
|
+
|
|
72893
|
+
#ifdef PREPASS_PASS
|
|
72894
|
+
varying vLinearDepth: f32;
|
|
72895
|
+
#include "floatAsUintPS"
|
|
72896
|
+
#endif
|
|
72897
|
+
|
|
72898
|
+
const EXP4_F: f32 = exp(-4.0);
|
|
72899
|
+
const INV_EXP4_F: f32 = 1.0 / (1.0 - EXP4_F);
|
|
72900
|
+
|
|
72901
|
+
fn normExp(x: f32) -> f32 {
|
|
72902
|
+
return (exp(x * -4.0) - EXP4_F) * INV_EXP4_F;
|
|
72903
|
+
}
|
|
72904
|
+
|
|
72905
|
+
varying gaussianUV: vec2f;
|
|
72906
|
+
varying gaussianColor: vec4f;
|
|
72907
|
+
|
|
72908
|
+
#if defined(GSPLAT_UNIFIED_ID) && defined(PICK_PASS)
|
|
72909
|
+
varying @interpolate(flat) vPickId: u32;
|
|
72910
|
+
#endif
|
|
72911
|
+
|
|
72912
|
+
#ifdef PICK_PASS
|
|
72913
|
+
#include "pickPS"
|
|
72914
|
+
#endif
|
|
72915
|
+
|
|
72916
|
+
uniform walk_viewInverse: mat4x4f;
|
|
72917
|
+
uniform walk_target: vec3f;
|
|
72918
|
+
uniform walk_radius: f32;
|
|
72919
|
+
uniform walk_time: f32;
|
|
72920
|
+
|
|
72921
|
+
fn walkLinearizeDepth(z: f32) -> f32 {
|
|
72922
|
+
if (uniform.camera_params.w == 0.0) {
|
|
72923
|
+
return (uniform.camera_params.z * uniform.camera_params.y) /
|
|
72924
|
+
(uniform.camera_params.y + z * (uniform.camera_params.z - uniform.camera_params.y));
|
|
72925
|
+
} else {
|
|
72926
|
+
return uniform.camera_params.z + z * (uniform.camera_params.y - uniform.camera_params.z);
|
|
72927
|
+
}
|
|
72928
|
+
}
|
|
72929
|
+
|
|
72930
|
+
fn walkReconstructWorldPos(fragCoord: vec4f) -> vec3f {
|
|
72931
|
+
let linearDepth = walkLinearizeDepth(fragCoord.z);
|
|
72932
|
+
let ndc = fragCoord.xy * uniform.viewport_size.zw * 2.0 - 1.0;
|
|
72933
|
+
let viewPos = vec3f(
|
|
72934
|
+
ndc.x * linearDepth / uniform.matrix_projection[0][0],
|
|
72935
|
+
-ndc.y * linearDepth / uniform.matrix_projection[1][1],
|
|
72936
|
+
-linearDepth
|
|
72937
|
+
);
|
|
72938
|
+
return (uniform.walk_viewInverse * vec4f(viewPos, 1.0)).xyz;
|
|
72939
|
+
}
|
|
72940
|
+
|
|
72941
|
+
@fragment
|
|
72942
|
+
fn fragmentMain(input: FragmentInput) -> FragmentOutput {
|
|
72943
|
+
var output: FragmentOutput;
|
|
72944
|
+
|
|
72945
|
+
let A: f32 = f32(dot(gaussianUV, gaussianUV));
|
|
72946
|
+
if (A > 1.0) {
|
|
72947
|
+
discard;
|
|
72948
|
+
return output;
|
|
72949
|
+
}
|
|
72950
|
+
|
|
72951
|
+
var alpha: f32 = normExp(A) * f32(gaussianColor.a);
|
|
72952
|
+
|
|
72953
|
+
#if defined(SHADOW_PASS) || defined(PICK_PASS) || defined(PREPASS_PASS)
|
|
72954
|
+
if (alpha < uniform.alphaClip) {
|
|
72955
|
+
discard;
|
|
72956
|
+
return output;
|
|
72957
|
+
}
|
|
72958
|
+
#endif
|
|
72959
|
+
|
|
72960
|
+
#ifdef PICK_PASS
|
|
72961
|
+
|
|
72962
|
+
#ifdef GSPLAT_UNIFIED_ID
|
|
72963
|
+
output.color = encodePickOutput(vPickId);
|
|
72964
|
+
#else
|
|
72965
|
+
output.color = getPickOutput();
|
|
72966
|
+
#endif
|
|
72967
|
+
#ifdef DEPTH_PICK_PASS
|
|
72968
|
+
output.color1 = getPickDepth();
|
|
72969
|
+
#endif
|
|
72970
|
+
|
|
72971
|
+
#elif SHADOW_PASS
|
|
72972
|
+
|
|
72973
|
+
output.color = vec4f(0.0, 0.0, 0.0, 1.0);
|
|
72974
|
+
|
|
72975
|
+
#elif PREPASS_PASS
|
|
72976
|
+
|
|
72977
|
+
output.color = float2vec4(vLinearDepth);
|
|
72978
|
+
|
|
72979
|
+
#else
|
|
72980
|
+
|
|
72981
|
+
if (alpha < 1.0 / 255.0) {
|
|
72982
|
+
discard;
|
|
72983
|
+
return output;
|
|
72984
|
+
}
|
|
72985
|
+
|
|
72986
|
+
#ifndef DITHER_NONE
|
|
72987
|
+
opacityDither(alpha, id * 0.013);
|
|
72988
|
+
#endif
|
|
72989
|
+
|
|
72990
|
+
let gc = vec3f(gaussianColor.xyz);
|
|
72991
|
+
|
|
72992
|
+
if (uniform.walk_radius > 0.0) {
|
|
72993
|
+
let walkWorldPos = walkReconstructWorldPos(pcPosition);
|
|
72994
|
+
let xzDist = length(walkWorldPos.xz - uniform.walk_target.xz);
|
|
72995
|
+
|
|
72996
|
+
let nd = xzDist / uniform.walk_radius;
|
|
72997
|
+
let lightFalloff = 1.0 / (1.0 + nd * nd * 8.0);
|
|
72998
|
+
let coreBoost = 1.0 / (1.0 + nd * nd * 200.0);
|
|
72999
|
+
|
|
73000
|
+
let pulse = 1.0 + 0.1 * sin(uniform.walk_time * 3.0);
|
|
73001
|
+
|
|
73002
|
+
let ringPhase = fract(uniform.walk_time * 0.5);
|
|
73003
|
+
let ringPos = nd - ringPhase;
|
|
73004
|
+
let ringFade = 1.0 - ringPhase;
|
|
73005
|
+
let crest = smoothstep(0.1, 0.0, abs(ringPos)) * 1.0 * ringFade * (1.0 + lightFalloff);
|
|
73006
|
+
let trough = smoothstep(0.25, 0.0, abs(ringPos + 0.15)) * -1.0 * ringFade;
|
|
73007
|
+
let ring = crest + trough;
|
|
73008
|
+
|
|
73009
|
+
let intensity = (lightFalloff * 0.8 + coreBoost * 1.5 + ring) * pulse;
|
|
73010
|
+
|
|
73011
|
+
let lum = dot(gc, vec3f(0.299, 0.587, 0.114));
|
|
73012
|
+
let adaptiveIntensity = intensity * (1.0 - lum * 0.7);
|
|
73013
|
+
let litColor = gc * (1.0 + vec3f(0.85, 0.92, 1.0) * adaptiveIntensity);
|
|
73014
|
+
let spatialFalloff = normExp(A);
|
|
73015
|
+
let boostedBase = mix(f32(gaussianColor.a), 1.0, min(intensity * 0.3, 1.0));
|
|
73016
|
+
let glowAlpha = spatialFalloff * boostedBase;
|
|
73017
|
+
|
|
73018
|
+
output.color = vec4f(litColor * glowAlpha, glowAlpha);
|
|
73019
|
+
} else {
|
|
73020
|
+
output.color = vec4f(gc * alpha, alpha);
|
|
73021
|
+
}
|
|
73022
|
+
#endif
|
|
73023
|
+
|
|
73024
|
+
return output;
|
|
73025
|
+
}`;
|
|
73026
|
+
// ── Core billboard shaders ──────────────────────────────────────────────────
|
|
73027
|
+
const coreVS = /* glsl */ `
|
|
73028
|
+
attribute vec3 vertex_position;
|
|
73029
|
+
|
|
73030
|
+
uniform mat4 matrix_viewProjection;
|
|
73031
|
+
uniform mat4 walk_viewInverse;
|
|
73032
|
+
uniform vec3 walk_target;
|
|
73033
|
+
uniform vec4 viewport_size;
|
|
73034
|
+
|
|
73035
|
+
varying vec2 vUV;
|
|
73036
|
+
|
|
73037
|
+
void main() {
|
|
73038
|
+
vec3 camRight = normalize(vec3(walk_viewInverse[0][0], 0.0, walk_viewInverse[0][2]));
|
|
73039
|
+
vec3 up = vec3(0.0, 1.0, 0.0);
|
|
73040
|
+
|
|
73041
|
+
float halfWidth = 0.0075;
|
|
73042
|
+
float halfHeight = 10000.0;
|
|
73043
|
+
|
|
73044
|
+
vec3 centerWorld = walk_target + up * vertex_position.y * halfHeight;
|
|
73045
|
+
|
|
73046
|
+
vec4 targetClip = matrix_viewProjection * vec4(walk_target, 1.0);
|
|
73047
|
+
float minPixelHalf = 1.0 / viewport_size.x * targetClip.w;
|
|
73048
|
+
float effectiveHalfWidth = max(halfWidth, minPixelHalf);
|
|
73049
|
+
|
|
73050
|
+
vec3 worldPos = centerWorld + camRight * vertex_position.x * effectiveHalfWidth;
|
|
73051
|
+
|
|
73052
|
+
gl_Position = matrix_viewProjection * vec4(worldPos, 1.0);
|
|
73053
|
+
vUV = vertex_position.xy;
|
|
73054
|
+
}
|
|
73055
|
+
`;
|
|
73056
|
+
const coreVS_WGSL = /* wgsl */ `
|
|
73057
|
+
attribute vertex_position: vec3f;
|
|
73058
|
+
uniform matrix_viewProjection: mat4x4f;
|
|
73059
|
+
uniform walk_viewInverse: mat4x4f;
|
|
73060
|
+
uniform walk_target: vec3f;
|
|
73061
|
+
uniform viewport_size: vec4f;
|
|
73062
|
+
varying vUV: vec2f;
|
|
73063
|
+
|
|
73064
|
+
@vertex fn vertexMain(input: VertexInput) -> VertexOutput {
|
|
73065
|
+
var output: VertexOutput;
|
|
73066
|
+
|
|
73067
|
+
let camRight = normalize(vec3f(uniform.walk_viewInverse[0][0], 0.0, uniform.walk_viewInverse[0][2]));
|
|
73068
|
+
let up = vec3f(0.0, 1.0, 0.0);
|
|
73069
|
+
|
|
73070
|
+
let halfWidth = 0.0075;
|
|
73071
|
+
let halfHeight = 10000.0;
|
|
73072
|
+
|
|
73073
|
+
let centerWorld = uniform.walk_target + up * input.vertex_position.y * halfHeight;
|
|
73074
|
+
|
|
73075
|
+
let targetClip = uniform.matrix_viewProjection * vec4f(uniform.walk_target, 1.0);
|
|
73076
|
+
let minPixelHalf = 1.0 / uniform.viewport_size.x * targetClip.w;
|
|
73077
|
+
let effectiveHalfWidth = max(halfWidth, minPixelHalf);
|
|
73078
|
+
|
|
73079
|
+
let worldPos = centerWorld + camRight * input.vertex_position.x * effectiveHalfWidth;
|
|
73080
|
+
|
|
73081
|
+
output.position = uniform.matrix_viewProjection * vec4f(worldPos, 1.0);
|
|
73082
|
+
output.vUV = input.vertex_position.xy;
|
|
73083
|
+
return output;
|
|
73084
|
+
}
|
|
73085
|
+
`;
|
|
73086
|
+
const coreFS = /* glsl */ `
|
|
73087
|
+
precision highp float;
|
|
73088
|
+
|
|
73089
|
+
uniform float walk_time;
|
|
73090
|
+
|
|
73091
|
+
varying vec2 vUV;
|
|
73092
|
+
|
|
73093
|
+
void main() {
|
|
73094
|
+
if (abs(vUV.y) > 0.95) discard;
|
|
73095
|
+
|
|
73096
|
+
float pulse = 1.0 + 0.08 * sin(walk_time * 3.0);
|
|
73097
|
+
vec3 color = vec3(2.55, 2.76, 3.0) * pulse;
|
|
73098
|
+
|
|
73099
|
+
gl_FragColor = vec4(color, 1.0);
|
|
73100
|
+
}
|
|
73101
|
+
`;
|
|
73102
|
+
const coreFS_WGSL = /* wgsl */ `
|
|
73103
|
+
uniform walk_time: f32;
|
|
73104
|
+
varying vUV: vec2f;
|
|
73105
|
+
|
|
73106
|
+
@fragment fn fragmentMain(input: FragmentInput) -> FragmentOutput {
|
|
73107
|
+
var output: FragmentOutput;
|
|
73108
|
+
|
|
73109
|
+
if (abs(input.vUV.y) > 0.95) {
|
|
73110
|
+
discard;
|
|
73111
|
+
return output;
|
|
73112
|
+
}
|
|
73113
|
+
|
|
73114
|
+
let pulse = 1.0 + 0.08 * sin(uniform.walk_time * 3.0);
|
|
73115
|
+
let color = vec3f(2.55, 2.76, 3.0) * pulse;
|
|
73116
|
+
|
|
73117
|
+
output.color = vec4f(color, 1.0);
|
|
73118
|
+
return output;
|
|
73119
|
+
}
|
|
73120
|
+
`;
|
|
73121
|
+
// ── Particle shaders ────────────────────────────────────────────────────────
|
|
73122
|
+
const particleVS = /* glsl */ `
|
|
73123
|
+
attribute vec3 vertex_position;
|
|
73124
|
+
attribute vec2 aQuadCorner;
|
|
73125
|
+
|
|
73126
|
+
uniform mat4 matrix_viewProjection;
|
|
73127
|
+
uniform mat4 walk_viewInverse;
|
|
73128
|
+
uniform vec3 walk_target;
|
|
73129
|
+
uniform float walk_time;
|
|
73130
|
+
|
|
73131
|
+
varying vec2 vUV;
|
|
73132
|
+
varying float vFade;
|
|
73133
|
+
|
|
73134
|
+
void main() {
|
|
73135
|
+
float rand0 = vertex_position.x;
|
|
73136
|
+
float rand1 = vertex_position.y;
|
|
73137
|
+
float rand2 = vertex_position.z;
|
|
73138
|
+
|
|
73139
|
+
float baseAngle = rand0 * 6.28318530718;
|
|
73140
|
+
float rBase = sqrt(rand2) * 0.4;
|
|
73141
|
+
float r = rBase * smoothstep(0.0, 0.5, walk_time);
|
|
73142
|
+
|
|
73143
|
+
float riseSpeed = 0.3 + rand2 * 0.4;
|
|
73144
|
+
float t = fract(max(walk_time - rand1 * 2.0, 0.0) * riseSpeed);
|
|
73145
|
+
float y = t * t * 1.5 - 0.1;
|
|
73146
|
+
|
|
73147
|
+
float swirl = baseAngle + t * (0.5 + rand1);
|
|
73148
|
+
float swirlR = r + 0.01;
|
|
73149
|
+
vec3 center = walk_target + vec3(swirlR * cos(swirl), y, swirlR * sin(swirl));
|
|
73150
|
+
|
|
73151
|
+
vec3 camRight = walk_viewInverse[0].xyz;
|
|
73152
|
+
vec3 camUp = walk_viewInverse[1].xyz;
|
|
73153
|
+
float halfSize = 0.00625;
|
|
73154
|
+
|
|
73155
|
+
vec3 worldPos = center
|
|
73156
|
+
+ camRight * aQuadCorner.x * halfSize
|
|
73157
|
+
+ camUp * aQuadCorner.y * halfSize;
|
|
73158
|
+
|
|
73159
|
+
gl_Position = matrix_viewProjection * vec4(worldPos, 1.0);
|
|
73160
|
+
vUV = aQuadCorner;
|
|
73161
|
+
float maxT = 1.0 - rBase;
|
|
73162
|
+
vFade = smoothstep(0.0, 0.1, t) * smoothstep(maxT, maxT - 0.15, t);
|
|
73163
|
+
}
|
|
73164
|
+
`;
|
|
73165
|
+
const particleVS_WGSL = /* wgsl */ `
|
|
73166
|
+
attribute vertex_position: vec3f;
|
|
73167
|
+
attribute aQuadCorner: vec2f;
|
|
73168
|
+
|
|
73169
|
+
uniform matrix_viewProjection: mat4x4f;
|
|
73170
|
+
uniform walk_viewInverse: mat4x4f;
|
|
73171
|
+
uniform walk_target: vec3f;
|
|
73172
|
+
uniform walk_time: f32;
|
|
73173
|
+
|
|
73174
|
+
varying vUV: vec2f;
|
|
73175
|
+
varying vFade: f32;
|
|
73176
|
+
|
|
73177
|
+
@vertex fn vertexMain(input: VertexInput) -> VertexOutput {
|
|
73178
|
+
var output: VertexOutput;
|
|
73179
|
+
|
|
73180
|
+
let rand0 = input.vertex_position.x;
|
|
73181
|
+
let rand1 = input.vertex_position.y;
|
|
73182
|
+
let rand2 = input.vertex_position.z;
|
|
73183
|
+
|
|
73184
|
+
let baseAngle = rand0 * 6.28318530718;
|
|
73185
|
+
let rBase = sqrt(rand2) * 0.4;
|
|
73186
|
+
let r = rBase * smoothstep(0.0, 0.5, uniform.walk_time);
|
|
73187
|
+
|
|
73188
|
+
let riseSpeed = 0.3 + rand2 * 0.4;
|
|
73189
|
+
let t = fract(max(uniform.walk_time - rand1 * 2.0, 0.0) * riseSpeed);
|
|
73190
|
+
let y = t * t * 1.5 - 0.1;
|
|
73191
|
+
|
|
73192
|
+
let swirl = baseAngle + t * (0.5 + rand1);
|
|
73193
|
+
let swirlR = r + 0.01;
|
|
73194
|
+
let center = uniform.walk_target + vec3f(swirlR * cos(swirl), y, swirlR * sin(swirl));
|
|
73195
|
+
|
|
73196
|
+
let camRight = uniform.walk_viewInverse[0].xyz;
|
|
73197
|
+
let camUp = uniform.walk_viewInverse[1].xyz;
|
|
73198
|
+
let halfSize = 0.00625;
|
|
73199
|
+
|
|
73200
|
+
let worldPos = center
|
|
73201
|
+
+ camRight * input.aQuadCorner.x * halfSize
|
|
73202
|
+
+ camUp * input.aQuadCorner.y * halfSize;
|
|
73203
|
+
|
|
73204
|
+
output.position = uniform.matrix_viewProjection * vec4f(worldPos, 1.0);
|
|
73205
|
+
output.vUV = input.aQuadCorner;
|
|
73206
|
+
let maxT = 1.0 - rBase;
|
|
73207
|
+
output.vFade = smoothstep(0.0, 0.1, t) * smoothstep(maxT, maxT - 0.15, t);
|
|
73208
|
+
return output;
|
|
73209
|
+
}
|
|
73210
|
+
`;
|
|
73211
|
+
const particleFS = /* glsl */ `
|
|
73212
|
+
precision highp float;
|
|
73213
|
+
|
|
73214
|
+
varying vec2 vUV;
|
|
73215
|
+
varying float vFade;
|
|
73216
|
+
|
|
73217
|
+
void main() {
|
|
73218
|
+
float r = length(vUV);
|
|
73219
|
+
if (r > 1.0 || vFade < 0.5) discard;
|
|
73220
|
+
gl_FragColor = vec4(2.55, 2.76, 3.0, 1.0);
|
|
73221
|
+
}
|
|
73222
|
+
`;
|
|
73223
|
+
const particleFS_WGSL = /* wgsl */ `
|
|
73224
|
+
varying vUV: vec2f;
|
|
73225
|
+
varying vFade: f32;
|
|
73226
|
+
|
|
73227
|
+
@fragment fn fragmentMain(input: FragmentInput) -> FragmentOutput {
|
|
73228
|
+
var output: FragmentOutput;
|
|
73229
|
+
|
|
73230
|
+
let r = length(input.vUV);
|
|
73231
|
+
if (r > 1.0 || input.vFade < 0.5) {
|
|
73232
|
+
discard;
|
|
73233
|
+
return output;
|
|
73234
|
+
}
|
|
73235
|
+
output.color = vec4f(2.55, 2.76, 3.0, 1.0);
|
|
73236
|
+
return output;
|
|
73237
|
+
}
|
|
73238
|
+
`;
|
|
73239
|
+
// ── Constants & helpers ─────────────────────────────────────────────────────
|
|
73240
|
+
const PARTICLE_COUNT = 250;
|
|
73241
|
+
const QUAD_CORNERS = [-1, -1, 1, -1, 1, 1, -1, 1];
|
|
73242
|
+
const viewMat = new Mat4();
|
|
73243
|
+
const invViewMat = new Mat4();
|
|
73244
|
+
const targetVec = new Float32Array(3);
|
|
73245
|
+
const mulberry32 = (seed) => {
|
|
73246
|
+
return () => {
|
|
73247
|
+
seed |= 0;
|
|
73248
|
+
seed = seed + 0x6D2B79F5 | 0;
|
|
73249
|
+
let t = Math.imul(seed ^ seed >>> 15, 1 | seed);
|
|
73250
|
+
t ^= t + Math.imul(t ^ t >>> 7, 61 | t);
|
|
73251
|
+
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
73252
|
+
};
|
|
73253
|
+
};
|
|
73254
|
+
// ── WalkIndicator ───────────────────────────────────────────────────────────
|
|
73255
|
+
class WalkIndicator {
|
|
73256
|
+
app;
|
|
73257
|
+
target = null;
|
|
73258
|
+
startTime = 0;
|
|
73259
|
+
visible = false;
|
|
73260
|
+
origGlsl;
|
|
73261
|
+
origWgsl;
|
|
73262
|
+
coreEntity;
|
|
73263
|
+
particleEntity;
|
|
73264
|
+
constructor(app) {
|
|
73265
|
+
this.app = app;
|
|
73266
|
+
const device = app.graphicsDevice;
|
|
73267
|
+
const glsl = ShaderChunks.get(device, 'glsl');
|
|
73268
|
+
const wgsl = ShaderChunks.get(device, 'wgsl');
|
|
73269
|
+
this.origGlsl = glsl.get('gsplatPS');
|
|
73270
|
+
this.origWgsl = wgsl.get('gsplatPS');
|
|
73271
|
+
glsl.set('gsplatPS', gsplatPSGlsl);
|
|
73272
|
+
wgsl.set('gsplatPS', gsplatPSWgsl);
|
|
73273
|
+
this.coreEntity = this.createCoreEntity();
|
|
73274
|
+
this.particleEntity = this.createParticleEntity();
|
|
73275
|
+
app.on('framerender', () => {
|
|
73276
|
+
if (this.target && this.visible) {
|
|
73277
|
+
app.renderNextFrame = true;
|
|
73278
|
+
}
|
|
73279
|
+
});
|
|
73280
|
+
}
|
|
73281
|
+
createCoreEntity() {
|
|
73282
|
+
const device = this.app.graphicsDevice;
|
|
73283
|
+
const mesh = new Mesh(device);
|
|
73284
|
+
mesh.setPositions([-1, -1, 0, 1, -1, 0, 1, 1, 0, -1, 1, 0], 3);
|
|
73285
|
+
mesh.setIndices([0, 1, 2, 0, 2, 3]);
|
|
73286
|
+
mesh.update(PRIMITIVE_TRIANGLES);
|
|
73287
|
+
const material = new ShaderMaterial({
|
|
73288
|
+
uniqueName: 'walkCoreMaterial',
|
|
73289
|
+
vertexGLSL: coreVS,
|
|
73290
|
+
fragmentGLSL: coreFS,
|
|
73291
|
+
vertexWGSL: coreVS_WGSL,
|
|
73292
|
+
fragmentWGSL: coreFS_WGSL,
|
|
73293
|
+
attributes: {
|
|
73294
|
+
vertex_position: SEMANTIC_POSITION
|
|
73295
|
+
}
|
|
73296
|
+
});
|
|
73297
|
+
material.blendType = BLEND_NONE;
|
|
73298
|
+
material.depthWrite = true;
|
|
73299
|
+
material.depthTest = true;
|
|
73300
|
+
material.cull = CULLFACE_NONE;
|
|
73301
|
+
material.update();
|
|
73302
|
+
const mi = new MeshInstance(mesh, material);
|
|
73303
|
+
mi.cull = false;
|
|
73304
|
+
const entity = new Entity('walkCore');
|
|
73305
|
+
entity.addComponent('render', {
|
|
73306
|
+
meshInstances: [mi]
|
|
73307
|
+
});
|
|
73308
|
+
entity.enabled = false;
|
|
73309
|
+
this.app.root.addChild(entity);
|
|
73310
|
+
return entity;
|
|
73311
|
+
}
|
|
73312
|
+
createParticleEntity() {
|
|
73313
|
+
const device = this.app.graphicsDevice;
|
|
73314
|
+
const rng = mulberry32(42);
|
|
73315
|
+
const totalVerts = PARTICLE_COUNT * 4;
|
|
73316
|
+
const totalIndices = PARTICLE_COUNT * 6;
|
|
73317
|
+
const particleData = new Float32Array(totalVerts * 3);
|
|
73318
|
+
const corners = new Float32Array(totalVerts * 2);
|
|
73319
|
+
const indices = new Uint16Array(totalIndices);
|
|
73320
|
+
for (let i = 0; i < PARTICLE_COUNT; i++) {
|
|
73321
|
+
const rand0 = i / PARTICLE_COUNT;
|
|
73322
|
+
const rand1 = rng();
|
|
73323
|
+
const rand2 = rng();
|
|
73324
|
+
const base = i * 4;
|
|
73325
|
+
for (let j = 0; j < 4; j++) {
|
|
73326
|
+
const vi = base + j;
|
|
73327
|
+
particleData[vi * 3] = rand0;
|
|
73328
|
+
particleData[vi * 3 + 1] = rand1;
|
|
73329
|
+
particleData[vi * 3 + 2] = rand2;
|
|
73330
|
+
corners[vi * 2] = QUAD_CORNERS[j * 2];
|
|
73331
|
+
corners[vi * 2 + 1] = QUAD_CORNERS[j * 2 + 1];
|
|
73332
|
+
}
|
|
73333
|
+
const ii = i * 6;
|
|
73334
|
+
indices[ii] = base;
|
|
73335
|
+
indices[ii + 1] = base + 1;
|
|
73336
|
+
indices[ii + 2] = base + 2;
|
|
73337
|
+
indices[ii + 3] = base;
|
|
73338
|
+
indices[ii + 4] = base + 2;
|
|
73339
|
+
indices[ii + 5] = base + 3;
|
|
73340
|
+
}
|
|
73341
|
+
const mesh = new Mesh(device);
|
|
73342
|
+
mesh.setPositions(particleData, 3);
|
|
73343
|
+
mesh.setVertexStream(SEMANTIC_TEXCOORD1, corners, 2);
|
|
73344
|
+
mesh.setIndices(indices);
|
|
73345
|
+
mesh.update(PRIMITIVE_TRIANGLES);
|
|
73346
|
+
const material = new ShaderMaterial({
|
|
73347
|
+
uniqueName: 'walkParticleMaterial',
|
|
73348
|
+
vertexGLSL: particleVS,
|
|
73349
|
+
fragmentGLSL: particleFS,
|
|
73350
|
+
vertexWGSL: particleVS_WGSL,
|
|
73351
|
+
fragmentWGSL: particleFS_WGSL,
|
|
73352
|
+
attributes: {
|
|
73353
|
+
vertex_position: SEMANTIC_POSITION,
|
|
73354
|
+
aQuadCorner: SEMANTIC_TEXCOORD1
|
|
73355
|
+
}
|
|
73356
|
+
});
|
|
73357
|
+
material.blendType = BLEND_NONE;
|
|
73358
|
+
material.depthWrite = true;
|
|
73359
|
+
material.depthTest = true;
|
|
73360
|
+
material.cull = CULLFACE_NONE;
|
|
73361
|
+
material.update();
|
|
73362
|
+
const mi = new MeshInstance(mesh, material);
|
|
73363
|
+
mi.cull = false;
|
|
73364
|
+
const entity = new Entity('walkParticles');
|
|
73365
|
+
entity.addComponent('render', {
|
|
73366
|
+
meshInstances: [mi]
|
|
73367
|
+
});
|
|
73368
|
+
entity.enabled = false;
|
|
73369
|
+
this.app.root.addChild(entity);
|
|
73370
|
+
return entity;
|
|
73371
|
+
}
|
|
73372
|
+
/**
|
|
73373
|
+
* Set or clear the walk target position.
|
|
73374
|
+
*
|
|
73375
|
+
* @param pos - World-space target position, or null to clear.
|
|
73376
|
+
*/
|
|
73377
|
+
setTarget(pos) {
|
|
73378
|
+
this.target = pos ? pos.clone() : null;
|
|
73379
|
+
this.visible = !!pos;
|
|
73380
|
+
if (pos) {
|
|
73381
|
+
this.startTime = performance.now() / 1000;
|
|
73382
|
+
}
|
|
73383
|
+
this.coreEntity.enabled = this.visible;
|
|
73384
|
+
this.particleEntity.enabled = this.visible;
|
|
73385
|
+
this.app.renderNextFrame = true;
|
|
73386
|
+
}
|
|
73387
|
+
/**
|
|
73388
|
+
* Update uniforms for the walk highlight effect. Call from a prerender hook.
|
|
73389
|
+
*
|
|
73390
|
+
* @param camera - The camera entity used for rendering.
|
|
73391
|
+
*/
|
|
73392
|
+
update(camera) {
|
|
73393
|
+
const device = this.app.graphicsDevice;
|
|
73394
|
+
const scope = device.scope;
|
|
73395
|
+
const cam = camera.camera;
|
|
73396
|
+
viewMat.copy(cam.viewMatrix);
|
|
73397
|
+
invViewMat.copy(viewMat).invert();
|
|
73398
|
+
scope.resolve('walk_viewInverse').setValue(invViewMat.data);
|
|
73399
|
+
if (this.target) {
|
|
73400
|
+
const camPos = camera.getPosition();
|
|
73401
|
+
const dist = camPos.distance(this.target);
|
|
73402
|
+
this.visible = dist > 2.0;
|
|
73403
|
+
this.coreEntity.enabled = this.visible;
|
|
73404
|
+
this.particleEntity.enabled = this.visible;
|
|
73405
|
+
const elapsed = performance.now() / 1000 - this.startTime;
|
|
73406
|
+
targetVec[0] = this.target.x;
|
|
73407
|
+
targetVec[1] = this.target.y;
|
|
73408
|
+
targetVec[2] = this.target.z;
|
|
73409
|
+
scope.resolve('walk_target').setValue(targetVec);
|
|
73410
|
+
scope.resolve('walk_radius').setValue(this.visible ? 1.5 : 0);
|
|
73411
|
+
scope.resolve('walk_time').setValue(elapsed);
|
|
73412
|
+
}
|
|
73413
|
+
else {
|
|
73414
|
+
targetVec[0] = 0;
|
|
73415
|
+
targetVec[1] = 0;
|
|
73416
|
+
targetVec[2] = 0;
|
|
73417
|
+
scope.resolve('walk_target').setValue(targetVec);
|
|
73418
|
+
scope.resolve('walk_radius').setValue(0);
|
|
73419
|
+
scope.resolve('walk_time').setValue(0);
|
|
73420
|
+
}
|
|
73421
|
+
}
|
|
73422
|
+
destroy() {
|
|
73423
|
+
const device = this.app.graphicsDevice;
|
|
73424
|
+
ShaderChunks.get(device, 'glsl').set('gsplatPS', this.origGlsl);
|
|
73425
|
+
ShaderChunks.get(device, 'wgsl').set('gsplatPS', this.origWgsl);
|
|
73426
|
+
this.coreEntity.destroy();
|
|
73427
|
+
this.particleEntity.destroy();
|
|
73428
|
+
}
|
|
73429
|
+
}
|
|
73430
|
+
|
|
72570
73431
|
const gammaChunkGlsl = `
|
|
72571
73432
|
vec3 prepareOutputFromGamma(vec3 gammaColor) {
|
|
72572
73433
|
return gammaColor;
|
|
@@ -72648,6 +73509,7 @@ class Viewer {
|
|
|
72648
73509
|
annotations;
|
|
72649
73510
|
forceRenderNextFrame = false;
|
|
72650
73511
|
voxelOverlay = null;
|
|
73512
|
+
walkIndicator = null;
|
|
72651
73513
|
origChunks;
|
|
72652
73514
|
constructor(global, gsplatLoad, skyboxLoad, voxelLoad) {
|
|
72653
73515
|
this.global = global;
|
|
@@ -72755,9 +73617,10 @@ class Viewer {
|
|
|
72755
73617
|
applyCamera(this.cameraManager.camera);
|
|
72756
73618
|
}
|
|
72757
73619
|
});
|
|
72758
|
-
// Render voxel debug overlay
|
|
73620
|
+
// Render voxel debug overlay and update walk indicator
|
|
72759
73621
|
app.on('prerender', () => {
|
|
72760
73622
|
this.voxelOverlay?.update();
|
|
73623
|
+
this.walkIndicator?.update(camera);
|
|
72761
73624
|
});
|
|
72762
73625
|
// update state on first frame
|
|
72763
73626
|
events.on('firstFrame', () => {
|
|
@@ -72790,6 +73653,10 @@ class Viewer {
|
|
|
72790
73653
|
}
|
|
72791
73654
|
this.cameraManager = new CameraManager(global, sceneBound, collider);
|
|
72792
73655
|
applyCamera(this.cameraManager.camera);
|
|
73656
|
+
this.walkIndicator = new WalkIndicator(app);
|
|
73657
|
+
events.on('walkIndicator:setTarget', (pos) => {
|
|
73658
|
+
this.walkIndicator?.setTarget(pos);
|
|
73659
|
+
});
|
|
72793
73660
|
const { instance } = gsplat;
|
|
72794
73661
|
if (instance) {
|
|
72795
73662
|
// kick off gsplat sorting immediately now that camera is in position
|
|
@@ -74513,7 +75380,7 @@ const initXr = (global) => {
|
|
|
74513
75380
|
});
|
|
74514
75381
|
};
|
|
74515
75382
|
|
|
74516
|
-
var version = "1.16.
|
|
75383
|
+
var version = "1.16.6";
|
|
74517
75384
|
|
|
74518
75385
|
const loadGsplat = async (app, config, progressCallback) => {
|
|
74519
75386
|
const { contents, contentUrl, unified, aa } = config;
|