@playcanvas/supersplat-viewer 1.42.1 → 1.43.1
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/README.md +10 -10
- package/THIRD_PARTY_NOTICES.md +63 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +3 -3
- package/dist/viewer.css +9 -1
- package/dist/viewer.d.ts +12 -3
- package/dist/viewer.js +353 -208
- package/dist/viewer.js.map +1 -1
- package/dist/zstd-decoder.wasm +0 -0
- package/docs/api.md +2 -0
- package/package.json +10 -9
- package/public/index.css +9 -1
- package/public/index.html +15 -5
- package/public/index.js +11007 -5841
- package/public/index.js.map +1 -1
- package/public/zstd-decoder.wasm +0 -0
package/dist/viewer.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AppBase, AppOptions, CameraComponentSystem, LightComponentSystem, RenderComponentSystem, GSplatComponentSystem, ScriptComponentSystem, ContainerHandler, TextureHandler, GSplatHandler, BinaryHandler, XrManager, Asset, SEMANTIC_POSITION, INDEXFORMAT_UINT32, GSplatContainer, GSplatFormat, Vec3, Entity, Quat, WORKBUFFER_UPDATE_ONCE, Vec4, Mat4, Color, PROJECTION_ORTHOGRAPHIC, ShaderChunks, Texture, ADDRESS_CLAMP_TO_EDGE, FILTER_NEAREST, PIXELFORMAT_RGBA16F, RenderTarget, RenderPassPicker, BlendState, BLENDEQUATION_MIN, BLENDMODE_ONE, PIXELFORMAT_R32U, Shader, BindGroupFormat, UniformBufferFormat, SHADERLANGUAGE_WGSL, BindUniformBufferFormat, BindTextureFormat, BindStorageTextureFormat, SHADERSTAGE_COMPUTE, SAMPLETYPE_FLOAT, SAMPLETYPE_UNFILTERABLE_FLOAT, TEXTUREDIMENSION_2D, UniformFormat, UNIFORMTYPE_VEC4, Compute, PIXELFORMAT_RGBA32U, PIXELFORMAT_R8U, SAMPLETYPE_UINT, PIXELFORMAT_RGBA8, StorageBuffer, BUFFERUSAGE_COPY_DST, PIXELFORMAT_RGBA32F, Vec2, Frustum, BoundingSphere, Camera as Camera$1, BindStorageBufferFormat, UNIFORMTYPE_UINT, SAMPLETYPE_DEPTH, ShaderMaterial, BLEND_NONE, CULLFACE_NONE, MeshInstance, GraphNode, FUNC_LESS, BLEND_PREMULTIPLIED, BUFFERUSAGE_COPY_SRC, UNIFORMTYPE_MAT4, UNIFORMTYPE_VEC2, UNIFORMTYPE_FLOAT, FUNC_ALWAYS, PIXELFORMAT_RGBA16U, FILTER_LINEAR, Mesh, PRIMITIVE_TRIANGLES, RenderPass, SHADER_FORWARD, FramePass, PIXELFORMAT_DEPTH, platform, PROJECTION_PERSPECTIVE, math, Script, SEMANTIC_TEXCOORD0, BLEND_NORMAL, CULLFACE_BACK, PIXELFORMAT_SRGBA8, StandardMaterial, BLENDEQUATION_ADD, BLENDMODE_ZERO, BLENDMODE_SRC_ALPHA, XRTRACKABLE_PLANE, XRTRACKABLE_MESH, SHADERLANGUAGE_GLSL, BoundingBox, BLENDMODE_ONE_MINUS_SRC_ALPHA, DEVICETYPE_WEBGL2, version as version$1, Pose, OrbitController as OrbitController$1, ShaderUtils, ASPECT_AUTO, drawQuadWithShader, PRIMITIVE_TRISTRIP, PIXELFORMAT_R32F, PIXELFORMAT_R16F, GamepadSource, KeyboardMouseSource, MultiTouchSource, InputFrame, Layer, SORTMODE_MANUAL, FUNC_EQUAL, FUNC_LESSEQUAL, RENDERSTYLE_WIREFRAME, GSPLAT_DEBUG_LOD, GSPLAT_DEBUG_NONE, MiniStats, CameraFrame, TONEMAP_NEUTRAL, TONEMAP_ACES2, TONEMAP_ACES, TONEMAP_HEJL, TONEMAP_FILMIC, TONEMAP_LINEAR, TONEMAP_NONE, LAYERID_SKYBOX, GSPLAT_RENDERER_RASTER_GPU_SORT, GSPLAT_RENDERER_RASTER_CPU_SORT, revision, EventHandler, createGraphicsDevice, Keyboard, TouchDevice as TouchDevice$1, Mouse } from 'playcanvas';
|
|
1
|
+
import { AppBase, AppOptions, CameraComponentSystem, LightComponentSystem, RenderComponentSystem, GSplatComponentSystem, ScriptComponentSystem, ContainerHandler, TextureHandler, GSplatHandler, BinaryHandler, XrManager, Asset, SEMANTIC_POSITION, INDEXFORMAT_UINT32, GSplatContainer, GSplatFormat, Vec3, Entity, Quat, WORKBUFFER_UPDATE_ONCE, Vec4, Mat4, Color, PROJECTION_ORTHOGRAPHIC, ShaderChunks, Texture, ADDRESS_CLAMP_TO_EDGE, FILTER_NEAREST, PIXELFORMAT_RGBA16F, RenderTarget, RenderPassPicker, BlendState, BLENDEQUATION_MIN, BLENDMODE_ONE, PIXELFORMAT_R32U, Shader, BindGroupFormat, UniformBufferFormat, SHADERLANGUAGE_WGSL, BindUniformBufferFormat, BindTextureFormat, BindStorageTextureFormat, SHADERSTAGE_COMPUTE, SAMPLETYPE_FLOAT, SAMPLETYPE_UNFILTERABLE_FLOAT, TEXTUREDIMENSION_2D, UniformFormat, UNIFORMTYPE_VEC4, Compute, PIXELFORMAT_RGBA32U, PIXELFORMAT_R8U, SAMPLETYPE_UINT, PIXELFORMAT_RGBA8, StorageBuffer, BUFFERUSAGE_COPY_DST, PIXELFORMAT_RGBA32F, Vec2, Frustum, BoundingSphere, Camera as Camera$1, BindStorageBufferFormat, UNIFORMTYPE_UINT, SAMPLETYPE_DEPTH, ShaderMaterial, BLEND_NONE, CULLFACE_NONE, MeshInstance, GraphNode, FUNC_LESS, BLEND_PREMULTIPLIED, BUFFERUSAGE_COPY_SRC, UNIFORMTYPE_MAT4, UNIFORMTYPE_VEC2, UNIFORMTYPE_FLOAT, FUNC_ALWAYS, PIXELFORMAT_RGBA16U, FILTER_LINEAR, Mesh, PRIMITIVE_TRIANGLES, RenderPass, SHADER_FORWARD, FramePass, PIXELFORMAT_DEPTH, platform, PROJECTION_PERSPECTIVE, math, Script, SEMANTIC_TEXCOORD0, BLEND_NORMAL, CULLFACE_BACK, PIXELFORMAT_SRGBA8, StandardMaterial, BLENDEQUATION_ADD, BLENDMODE_ZERO, BLENDMODE_SRC_ALPHA, XRTRACKABLE_PLANE, XRTRACKABLE_MESH, SHADERLANGUAGE_GLSL, BoundingBox, BLENDMODE_ONE_MINUS_SRC_ALPHA, DEVICETYPE_WEBGL2, version as version$1, Pose, OrbitController as OrbitController$1, ShaderUtils, ASPECT_AUTO, drawQuadWithShader, PRIMITIVE_TRISTRIP, PIXELFORMAT_R32F, PIXELFORMAT_R16F, GamepadSource, KeyboardMouseSource, MultiTouchSource, InputFrame, Layer, SORTMODE_MANUAL, FUNC_EQUAL, FUNC_LESSEQUAL, RENDERSTYLE_WIREFRAME, GSPLAT_DEBUG_LOD, GSPLAT_DEBUG_NONE, MiniStats, CameraFrame, TONEMAP_NEUTRAL, TONEMAP_ACES2, TONEMAP_ACES, TONEMAP_HEJL, TONEMAP_FILMIC, TONEMAP_LINEAR, TONEMAP_NONE, LAYERID_SKYBOX, GSPLAT_RENDERER_RASTER_GPU_SORT, GSPLAT_RENDERER_RASTER_CPU_SORT, WasmModule, revision, EventHandler, createGraphicsDevice, Keyboard, TouchDevice as TouchDevice$1, Mouse } from 'playcanvas';
|
|
2
|
+
import { SpzParser } from 'playcanvas/scripts/esm/parsers/spz-parser.mjs';
|
|
2
3
|
import { XrControllers } from 'playcanvas/scripts/esm/xr/xr-controllers.mjs';
|
|
3
4
|
import { XrNavigation } from 'playcanvas/scripts/esm/xr/xr-navigation.mjs';
|
|
4
5
|
|
|
@@ -20,6 +21,9 @@ class App extends AppBase {
|
|
|
20
21
|
appOptions.keyboard = options.keyboard;
|
|
21
22
|
appOptions.xr = XrManager;
|
|
22
23
|
this.init(appOptions);
|
|
24
|
+
// spz files, and the spz chunks of lcc2 scenes. Version 3 files are gzip compressed;
|
|
25
|
+
// version 4 files need the ZSTD decoder module (src/zstd-decoder.ts)
|
|
26
|
+
this.loader.getHandler('gsplat').addParser(new SpzParser(this));
|
|
23
27
|
}
|
|
24
28
|
}
|
|
25
29
|
|
|
@@ -4165,6 +4169,51 @@ fn unwarpTexel(texel: vec2i) -> vec2f {
|
|
|
4165
4169
|
// visibility come from the cpu (resident-set rebuild on version change, frustum cull per frame).
|
|
4166
4170
|
/** Words per cache entry: ndc, depth, axis1, len2 | alpha | bucket, rgb, id (or the coverage draw). */
|
|
4167
4171
|
const CACHE_WORDS = 6;
|
|
4172
|
+
// The cached alpha and the splat's shape, shared by the projector and the raster. The alpha byte
|
|
4173
|
+
// is sog v3's encoding, alpha = (1.25 b / 255)^2, so it holds the alpha above 1 a sog v3 file
|
|
4174
|
+
// stores (up to 1.5625); every other source's alpha converts to it. Above 1 a splat draws as the
|
|
4175
|
+
// engine's does: a plateau at full alpha out to plateauCore of the quad's half extent, and the
|
|
4176
|
+
// falloff stretched over the rest (the engine's gsplatPlateauCore, clipCorner and splat shader).
|
|
4177
|
+
const cacheAlphaWGSL = /* wgsl */ `
|
|
4178
|
+
fn encodeCacheAlpha(alpha: f32) -> u32 {
|
|
4179
|
+
return u32(sqrt(clamp(alpha, 0.0, 1.5625)) * (255.0 / 1.25) + 0.5);
|
|
4180
|
+
}
|
|
4181
|
+
|
|
4182
|
+
fn decodeCacheAlpha(bits: u32) -> f32 {
|
|
4183
|
+
let o = f32(bits & 0xffu) * (1.25 / 255.0);
|
|
4184
|
+
return o * o;
|
|
4185
|
+
}
|
|
4186
|
+
|
|
4187
|
+
// the radius, in units of the quad's half extent, out to which alpha above 1 holds at full alpha
|
|
4188
|
+
fn plateauCore(alpha: f32) -> f32 {
|
|
4189
|
+
if (alpha <= 1.0) {
|
|
4190
|
+
return 0.0;
|
|
4191
|
+
}
|
|
4192
|
+
let t = min(alpha - 1.0, 0.5625);
|
|
4193
|
+
return sqrt(0.28986718 + 0.62504992 * t) - 0.53839315;
|
|
4194
|
+
}
|
|
4195
|
+
|
|
4196
|
+
// the splat's alpha at r^2, in units of the quad's half extent:
|
|
4197
|
+
// alpha * falloff(r^2) with falloff(x) = (exp(-4 x) - exp(-4)) / (1 - exp(-4)), or above 1 the plateau
|
|
4198
|
+
fn splatAlpha(r2: f32, alpha: f32) -> f32 {
|
|
4199
|
+
var x = r2;
|
|
4200
|
+
if (alpha > 1.0) {
|
|
4201
|
+
let core = plateauCore(alpha);
|
|
4202
|
+
let c = max(0.0, sqrt(r2) - core) / (1.0 - core);
|
|
4203
|
+
x = c * c;
|
|
4204
|
+
}
|
|
4205
|
+
let e4 = exp(-4.0);
|
|
4206
|
+
return (exp(x * -4.0) - e4) / (1.0 - e4) * min(alpha, 1.0);
|
|
4207
|
+
}
|
|
4208
|
+
|
|
4209
|
+
// the radius, in units of the quad's half extent, where splatAlpha falls to a threshold
|
|
4210
|
+
fn radiusAt(threshold: f32, alpha: f32) -> f32 {
|
|
4211
|
+
let e4 = exp(-4.0);
|
|
4212
|
+
let core = plateauCore(alpha);
|
|
4213
|
+
let r = sqrt(max(-log(threshold / min(alpha, 1.0) * (1.0 - e4) + e4) * 0.25, 0.0));
|
|
4214
|
+
return core + (1.0 - core) * r;
|
|
4215
|
+
}
|
|
4216
|
+
`;
|
|
4168
4217
|
const PROJECTOR_WORKGROUP_SIZE = 256;
|
|
4169
4218
|
/** Buckets of the counting order (shaders/order.ts); the workgroup size, so each thread owns one. */
|
|
4170
4219
|
const ORDER_BUCKETS = PROJECTOR_WORKGROUP_SIZE;
|
|
@@ -4309,7 +4358,7 @@ struct FootprintEye1 {
|
|
|
4309
4358
|
determinant: f32
|
|
4310
4359
|
}
|
|
4311
4360
|
|
|
4312
|
-
fn footprintEye1(center: vec3f, rot: vec4f, scale: vec3f, viewport: vec2f) -> FootprintEye1 {
|
|
4361
|
+
fn footprintEye1(center: vec3f, rot: vec4f, scale: vec3f, viewport: vec2f, lowpass: f32) -> FootprintEye1 {
|
|
4313
4362
|
var f: FootprintEye1;
|
|
4314
4363
|
f.visible = false;
|
|
4315
4364
|
f.ndc = vec2f(1e4);
|
|
@@ -4381,22 +4430,26 @@ ${warp
|
|
|
4381
4430
|
: `
|
|
4382
4431
|
f.ndc = clip.xy / clip.w;
|
|
4383
4432
|
`}
|
|
4433
|
+
// the culls measure the footprint with the cull filter, and the drawn one takes the view's
|
|
4434
|
+
// filter (see project() below)
|
|
4384
4435
|
let us2 = uniforms.unitScale * uniforms.unitScale;
|
|
4385
|
-
|
|
4386
|
-
cov11
|
|
4387
|
-
f.determinant = cov00 * cov11 - cov01 * cov01;
|
|
4436
|
+
let cullDilation = 0.3 / us2;
|
|
4437
|
+
f.determinant = (cov00 + cullDilation) * (cov11 + cullDilation) - cov01 * cov01;
|
|
4388
4438
|
if (f.determinant <= 0.0) {
|
|
4389
4439
|
f.ndc = vec2f(1e4);
|
|
4390
4440
|
return f;
|
|
4391
4441
|
}
|
|
4442
|
+
f.lambda1 = 0.5 * (cov00 + cov11) + cullDilation + length(vec2f(0.5 * (cov00 - cov11), cov01));
|
|
4443
|
+
cov00 += lowpass;
|
|
4444
|
+
cov11 += lowpass;
|
|
4392
4445
|
let mid = 0.5 * (cov00 + cov11);
|
|
4393
4446
|
let radius = length(vec2f(0.5 * (cov00 - cov11), cov01));
|
|
4394
|
-
|
|
4447
|
+
let lambda1 = mid + radius;
|
|
4395
4448
|
let lambda2 = max(mid - radius, 0.1 / us2);
|
|
4396
|
-
let eigenVec = vec2f(cov01,
|
|
4449
|
+
let eigenVec = vec2f(cov01, lambda1 - cov00);
|
|
4397
4450
|
let eigenLen = length(eigenVec);
|
|
4398
4451
|
let direction = select(vec2f(1.0, 0.0), eigenVec / eigenLen, eigenLen > 1e-9);
|
|
4399
|
-
let len1 = 2.0 * sqrt(2.0 *
|
|
4452
|
+
let len1 = 2.0 * sqrt(2.0 * lambda1);
|
|
4400
4453
|
let clampScale = min(1.0, min(1024.0, min(viewport.x, viewport.y)) / len1);
|
|
4401
4454
|
f.axis1 = len1 * clampScale * direction;
|
|
4402
4455
|
f.len2 = 2.0 * sqrt(2.0 * lambda2) * clampScale;
|
|
@@ -4404,7 +4457,83 @@ ${warp
|
|
|
4404
4457
|
return f;
|
|
4405
4458
|
}
|
|
4406
4459
|
`;
|
|
4407
|
-
const projectorWGSL = (readChunk, occlusion, coverage, warp, stereo) =>
|
|
4460
|
+
const projectorWGSL = (readChunk, occlusion, coverage, warp, stereo, antiAlias) => {
|
|
4461
|
+
const aa = antiAlias !== 'off';
|
|
4462
|
+
// the coverage thresholds, drawn from the splat's alpha: before the projection, or with
|
|
4463
|
+
// anti-aliasing after it, once the compensation has set the alpha
|
|
4464
|
+
const coverageWGSL = coverage !== 'pixel'
|
|
4465
|
+
? `
|
|
4466
|
+
// Variant coverage:splat: one coverage threshold per splat and frame instead of one per
|
|
4467
|
+
// pixel. The pixels where alpha exceeds it form a solid ellipse, which the raster draws as a
|
|
4468
|
+
// polygon of the same area with no discard, so a gpu updates depth early and rejects what
|
|
4469
|
+
// lies behind it before rasterising it. Each pixel is still kept with probability alpha,
|
|
4470
|
+
// independently per splat; the noise is a splat at a random size rather than a dither. The
|
|
4471
|
+
// threshold is hashed afresh every frame: one sequence shared by every splat, rotated per
|
|
4472
|
+
// splat, would keep two splats' thresholds a fixed distance apart, so their coverage would
|
|
4473
|
+
// stay correlated over frames and the accumulation would converge to the wrong image. A
|
|
4474
|
+
// splat whose opacity does not exceed its threshold keeps nothing this frame and stops here.
|
|
4475
|
+
// The draw goes into cache word 5 as ${DRAW_BITS} bits, and the raster rebuilds the same
|
|
4476
|
+
// thresholds from them (shaders/raster.ts).
|
|
4477
|
+
let id = slot ^ (file * 2654435761u);
|
|
4478
|
+
let hashed = hashU32(((id + 1u) * 26699u) ^ uniforms.frameSeed);
|
|
4479
|
+
let drawnBits = hashed >> ${32 - DRAW_BITS}u;
|
|
4480
|
+
let drawn = f32(drawnBits) * (1.0 / ${(1 << DRAW_BITS) - 1}.0);
|
|
4481
|
+
// Variant jitter: the threshold is the base of a random stratum instead of the draw itself,
|
|
4482
|
+
// and every pixel adds its own jitter within the stratum in the raster, so the kept region
|
|
4483
|
+
// is the stratum's ellipse with a dithered rim rather than a solid one. Each pixel's
|
|
4484
|
+
// threshold is still uniform over [0, 1) and independent per splat, so the expectation is
|
|
4485
|
+
// unchanged, but neighbouring pixels no longer all agree. Sub-strata (jitterSubs above 1)
|
|
4486
|
+
// narrow the jitter: smaller polygons, more agreement.
|
|
4487
|
+
let subs = uniforms.jitterSubs;
|
|
4488
|
+
let jittered = subs > 0u;
|
|
4489
|
+
let subMask = max(subs, 1u) - 1u;
|
|
4490
|
+
// the per-splat threshold (coverage:splat, and the small splats of the interleaved mode): a
|
|
4491
|
+
// stratum of \`strata\`, its sub-stratum, and the nibble the raster reads them back from
|
|
4492
|
+
// (kept | stratum << 1 | sub << 3)
|
|
4493
|
+
let strata = max(uniforms.strata, 1u);
|
|
4494
|
+
let splatStratum = min(u32(drawn * f32(strata)), strata - 1u);
|
|
4495
|
+
let splatSub = (hashed >> 15u) & subMask;
|
|
4496
|
+
let splatBase = select(drawn, f32(splatStratum * max(subs, 1u) + splatSub) / f32(strata * max(subs, 1u)), jittered);
|
|
4497
|
+
let splatNibble = 1u | (splatStratum << 1u) | (splatSub << 3u);
|
|
4498
|
+
let splatThreshold = max(splatBase, uniforms.alphaClip);
|
|
4499
|
+
let splatKept = splatThreshold < opacity;
|
|
4500
|
+
${coverage === 'interleaved'
|
|
4501
|
+
? `
|
|
4502
|
+
// Variant coverage:interleaved: the pixels split into four interleaved sets, the four of a
|
|
4503
|
+
// 2x2 quad, and each set takes its own threshold, the four quarters of [0, 1) from the one
|
|
4504
|
+
// draw: a quad holds the splat at four stratified sizes, so its mean is nearly the splat's
|
|
4505
|
+
// alpha, as the per-pixel thresholds' is, and neighbouring pixels are no longer all one
|
|
4506
|
+
// splat. Jittered, the sets take the four strata in a random order, each within a random
|
|
4507
|
+
// sub-stratum, and their pixels jitter inside it
|
|
4508
|
+
var setBases = fract(vec4f(drawn) + vec4f(0.0, 0.25, 0.5, 0.75));
|
|
4509
|
+
var setNibbles = vec4u(0u);
|
|
4510
|
+
if (jittered) {
|
|
4511
|
+
let bits = hashU32(hashed ^ 0x9e3779b9u);
|
|
4512
|
+
let packed = PERMUTATIONS[bits % 24u];
|
|
4513
|
+
let perm = (vec4u(packed) >> vec4u(0u, 2u, 4u, 6u)) & vec4u(3u);
|
|
4514
|
+
let subsOf = (vec4u(bits) >> vec4u(8u, 10u, 12u, 14u)) & vec4u(subMask);
|
|
4515
|
+
setBases = vec4f(perm * subs + subsOf) / f32(4u * subs);
|
|
4516
|
+
setNibbles = (perm << vec4u(1u)) | (subsOf << vec4u(3u));
|
|
4517
|
+
}
|
|
4518
|
+
let setThresholds = max(setBases, vec4f(uniforms.alphaClip));
|
|
4519
|
+
let keptSets = setThresholds < vec4f(opacity);
|
|
4520
|
+
setNibbles = select(vec4u(0u), setNibbles | vec4u(1u), keptSets);
|
|
4521
|
+
// whether the splat draws into the sets or the full target waits for its footprint; a splat
|
|
4522
|
+
// keeping nothing either way stops here
|
|
4523
|
+
if (!any(keptSets) && !splatKept) {
|
|
4524
|
+
return result;
|
|
4525
|
+
}
|
|
4526
|
+
let lowest = select(vec4f(2.0), setThresholds, keptSets);
|
|
4527
|
+
let setThreshold = min(min(lowest.x, lowest.y), min(lowest.z, lowest.w));
|
|
4528
|
+
`
|
|
4529
|
+
: `
|
|
4530
|
+
if (!splatKept) {
|
|
4531
|
+
return result;
|
|
4532
|
+
}
|
|
4533
|
+
`}
|
|
4534
|
+
`
|
|
4535
|
+
: '';
|
|
4536
|
+
return /* wgsl */ `
|
|
4408
4537
|
struct ProjectorUniforms {
|
|
4409
4538
|
view: mat4x4f,
|
|
4410
4539
|
viewProj: mat4x4f,
|
|
@@ -4443,7 +4572,7 @@ struct ProjectorUniforms {
|
|
|
4443
4572
|
modelScale: vec4f,
|
|
4444
4573
|
cameraPosition: vec4f,
|
|
4445
4574
|
// 1: covariance in true pixels. 2: the engine's convention (its focal is viewport * proj[0][0],
|
|
4446
|
-
// twice the pixel focal), which
|
|
4575
|
+
// twice the pixel focal), which scales its culls and makes their 0.3 filter 0.075 px^2
|
|
4447
4576
|
unitScale: f32,
|
|
4448
4577
|
// the coverage seed (variant coverage:splat; see the raster's frameSeed)
|
|
4449
4578
|
frameSeed: u32,
|
|
@@ -4466,7 +4595,12 @@ struct ProjectorUniforms {
|
|
|
4466
4595
|
// and its warp table in warpTable
|
|
4467
4596
|
occL2Base: u32,
|
|
4468
4597
|
stereoBase: u32,
|
|
4469
|
-
warpBaseEye1: u32
|
|
4598
|
+
warpBaseEye1: u32,
|
|
4599
|
+
// the variance, in pixels squared, of the filter splats trained with anti-aliasing were
|
|
4600
|
+
// trained with (GSplatParams#antiAliasFilterSize), and the dispatched file's training mode
|
|
4601
|
+
// for the sources that dispatch per file (1: anti-aliased)
|
|
4602
|
+
antiAliasFilterSize: f32,
|
|
4603
|
+
fileAntiAlias: u32
|
|
4470
4604
|
}
|
|
4471
4605
|
|
|
4472
4606
|
// chunk table entry: slotBase, count, node, lod | file << 16
|
|
@@ -4494,21 +4628,22 @@ fn setSplat(idx: u32) {
|
|
|
4494
4628
|
}
|
|
4495
4629
|
|
|
4496
4630
|
${warp
|
|
4497
|
-
|
|
4631
|
+
? `
|
|
4498
4632
|
// variant warp: the view's table (shaders/warp.ts), and in stereo the second eye's after it
|
|
4499
4633
|
@group(0) @binding(7) var<storage, read> warpTable: array<f32>;
|
|
4500
4634
|
${warpWGSL}`
|
|
4501
|
-
|
|
4635
|
+
: ''}
|
|
4502
4636
|
${stereo
|
|
4503
|
-
|
|
4637
|
+
? `
|
|
4504
4638
|
// stereo: the second eye's occlusion grid, and its warp's lookups
|
|
4505
4639
|
@group(0) @binding(8) var<storage, read> occEye1: array<u32>;
|
|
4506
4640
|
${warp ? warpEye1WGSL : ''}
|
|
4507
4641
|
`
|
|
4508
|
-
|
|
4642
|
+
: ''}
|
|
4509
4643
|
${readChunk}
|
|
4644
|
+
${cacheAlphaWGSL}
|
|
4510
4645
|
${coverage !== 'pixel'
|
|
4511
|
-
|
|
4646
|
+
? `
|
|
4512
4647
|
// integer hash (Wellons' prospector mix), as the raster's
|
|
4513
4648
|
fn hashU32(x: u32) -> u32 {
|
|
4514
4649
|
var v = x;
|
|
@@ -4520,17 +4655,10 @@ fn hashU32(x: u32) -> u32 {
|
|
|
4520
4655
|
return v;
|
|
4521
4656
|
}
|
|
4522
4657
|
|
|
4523
|
-
// the radius, in units of the quad's half extent, where alpha = opacity * falloff(r^2) falls to
|
|
4524
|
-
// a threshold, with falloff(x) = (exp(-4 x) - exp(-4)) / (1 - exp(-4))
|
|
4525
|
-
fn radiusAt(threshold: f32, opacity: f32) -> f32 {
|
|
4526
|
-
let e4 = exp(-4.0);
|
|
4527
|
-
return sqrt(max(-log(threshold / opacity * (1.0 - e4) + e4) * 0.25, 0.0));
|
|
4528
|
-
}
|
|
4529
|
-
|
|
4530
4658
|
// the 24 orders of four strata, 2 bits a set
|
|
4531
4659
|
const PERMUTATIONS = array<u32, 24>(${permutations.map((p) => `${p}u`).join(', ')});
|
|
4532
4660
|
`
|
|
4533
|
-
|
|
4661
|
+
: ''}
|
|
4534
4662
|
// quaternion (x, y, z, w) to a rotation matrix (columns)
|
|
4535
4663
|
fn rotationMatrix(qIn: vec4f) -> mat3x3f {
|
|
4536
4664
|
let q = normalize(qIn);
|
|
@@ -4558,82 +4686,12 @@ fn project(slot: u32, file: u32${stereo ? ', local: u32' : ''}) -> Projected {
|
|
|
4558
4686
|
|
|
4559
4687
|
setSplat(slot);
|
|
4560
4688
|
let center = srcCenter();
|
|
4561
|
-
|
|
4562
|
-
|
|
4689
|
+
// the file's alpha; the compensation for anti-aliasing (aa) only lowers it, after the culls
|
|
4690
|
+
let opacityRaw = srcOpacity();
|
|
4691
|
+
if (opacityRaw < uniforms.alphaClip) {
|
|
4563
4692
|
return result;
|
|
4564
4693
|
}
|
|
4565
|
-
${
|
|
4566
|
-
? `
|
|
4567
|
-
// Variant coverage:splat: one coverage threshold per splat and frame instead of one per
|
|
4568
|
-
// pixel. The pixels where alpha exceeds it form a solid ellipse, which the raster draws as a
|
|
4569
|
-
// polygon of the same area with no discard, so a gpu updates depth early and rejects what
|
|
4570
|
-
// lies behind it before rasterising it. Each pixel is still kept with probability alpha,
|
|
4571
|
-
// independently per splat; the noise is a splat at a random size rather than a dither. The
|
|
4572
|
-
// threshold is hashed afresh every frame: one sequence shared by every splat, rotated per
|
|
4573
|
-
// splat, would keep two splats' thresholds a fixed distance apart, so their coverage would
|
|
4574
|
-
// stay correlated over frames and the accumulation would converge to the wrong image. A
|
|
4575
|
-
// splat whose opacity does not exceed its threshold keeps nothing this frame and stops here.
|
|
4576
|
-
// The draw goes into cache word 5 as ${DRAW_BITS} bits, and the raster rebuilds the same
|
|
4577
|
-
// thresholds from them (shaders/raster.ts).
|
|
4578
|
-
let id = slot ^ (file * 2654435761u);
|
|
4579
|
-
let hashed = hashU32(((id + 1u) * 26699u) ^ uniforms.frameSeed);
|
|
4580
|
-
let drawnBits = hashed >> ${32 - DRAW_BITS}u;
|
|
4581
|
-
let drawn = f32(drawnBits) * (1.0 / ${(1 << DRAW_BITS) - 1}.0);
|
|
4582
|
-
// Variant jitter: the threshold is the base of a random stratum instead of the draw itself,
|
|
4583
|
-
// and every pixel adds its own jitter within the stratum in the raster, so the kept region
|
|
4584
|
-
// is the stratum's ellipse with a dithered rim rather than a solid one. Each pixel's
|
|
4585
|
-
// threshold is still uniform over [0, 1) and independent per splat, so the expectation is
|
|
4586
|
-
// unchanged, but neighbouring pixels no longer all agree. Sub-strata (jitterSubs above 1)
|
|
4587
|
-
// narrow the jitter: smaller polygons, more agreement.
|
|
4588
|
-
let subs = uniforms.jitterSubs;
|
|
4589
|
-
let jittered = subs > 0u;
|
|
4590
|
-
let subMask = max(subs, 1u) - 1u;
|
|
4591
|
-
// the per-splat threshold (coverage:splat, and the small splats of the interleaved mode): a
|
|
4592
|
-
// stratum of \`strata\`, its sub-stratum, and the nibble the raster reads them back from
|
|
4593
|
-
// (kept | stratum << 1 | sub << 3)
|
|
4594
|
-
let strata = max(uniforms.strata, 1u);
|
|
4595
|
-
let splatStratum = min(u32(drawn * f32(strata)), strata - 1u);
|
|
4596
|
-
let splatSub = (hashed >> 15u) & subMask;
|
|
4597
|
-
let splatBase = select(drawn, f32(splatStratum * max(subs, 1u) + splatSub) / f32(strata * max(subs, 1u)), jittered);
|
|
4598
|
-
let splatNibble = 1u | (splatStratum << 1u) | (splatSub << 3u);
|
|
4599
|
-
let splatThreshold = max(splatBase, uniforms.alphaClip);
|
|
4600
|
-
let splatKept = splatThreshold < opacity;
|
|
4601
|
-
${coverage === 'interleaved'
|
|
4602
|
-
? `
|
|
4603
|
-
// Variant coverage:interleaved: the pixels split into four interleaved sets, the four of a
|
|
4604
|
-
// 2x2 quad, and each set takes its own threshold, the four quarters of [0, 1) from the one
|
|
4605
|
-
// draw: a quad holds the splat at four stratified sizes, so its mean is nearly the splat's
|
|
4606
|
-
// alpha, as the per-pixel thresholds' is, and neighbouring pixels are no longer all one
|
|
4607
|
-
// splat. Jittered, the sets take the four strata in a random order, each within a random
|
|
4608
|
-
// sub-stratum, and their pixels jitter inside it
|
|
4609
|
-
var setBases = fract(vec4f(drawn) + vec4f(0.0, 0.25, 0.5, 0.75));
|
|
4610
|
-
var setNibbles = vec4u(0u);
|
|
4611
|
-
if (jittered) {
|
|
4612
|
-
let bits = hashU32(hashed ^ 0x9e3779b9u);
|
|
4613
|
-
let packed = PERMUTATIONS[bits % 24u];
|
|
4614
|
-
let perm = (vec4u(packed) >> vec4u(0u, 2u, 4u, 6u)) & vec4u(3u);
|
|
4615
|
-
let subsOf = (vec4u(bits) >> vec4u(8u, 10u, 12u, 14u)) & vec4u(subMask);
|
|
4616
|
-
setBases = vec4f(perm * subs + subsOf) / f32(4u * subs);
|
|
4617
|
-
setNibbles = (perm << vec4u(1u)) | (subsOf << vec4u(3u));
|
|
4618
|
-
}
|
|
4619
|
-
let setThresholds = max(setBases, vec4f(uniforms.alphaClip));
|
|
4620
|
-
let keptSets = setThresholds < vec4f(opacity);
|
|
4621
|
-
setNibbles = select(vec4u(0u), setNibbles | vec4u(1u), keptSets);
|
|
4622
|
-
// whether the splat draws into the sets or the full target waits for its footprint; a splat
|
|
4623
|
-
// keeping nothing either way stops here
|
|
4624
|
-
if (!any(keptSets) && !splatKept) {
|
|
4625
|
-
return result;
|
|
4626
|
-
}
|
|
4627
|
-
let lowest = select(vec4f(2.0), setThresholds, keptSets);
|
|
4628
|
-
let setThreshold = min(min(lowest.x, lowest.y), min(lowest.z, lowest.w));
|
|
4629
|
-
`
|
|
4630
|
-
: `
|
|
4631
|
-
if (!splatKept) {
|
|
4632
|
-
return result;
|
|
4633
|
-
}
|
|
4634
|
-
`}
|
|
4635
|
-
`
|
|
4636
|
-
: ''}
|
|
4694
|
+
${aa ? '' : ` let opacity = opacityRaw;\n${coverageWGSL}`}
|
|
4637
4695
|
let viewCenter = uniforms.view * vec4f(center, 1.0);
|
|
4638
4696
|
let depth = -viewCenter.z;
|
|
4639
4697
|
if (uniforms.isOrtho == 0u && depth <= 0.0) {
|
|
@@ -4691,7 +4749,7 @@ ${coverage === 'interleaved'
|
|
|
4691
4749
|
}
|
|
4692
4750
|
|
|
4693
4751
|
${warp
|
|
4694
|
-
|
|
4752
|
+
? `
|
|
4695
4753
|
// Variant warp: the splat in the foveated target, through the affine map per axis that is
|
|
4696
4754
|
// exact at the two ends of its quad's extent on screen. For a small splat that is the warp's
|
|
4697
4755
|
// slope at its centre; for a large one the secant over what is visible, since a near splat
|
|
@@ -4713,48 +4771,86 @@ ${warp
|
|
|
4713
4771
|
cov01 *= pixelScale.x * pixelScale.y;
|
|
4714
4772
|
cov11 *= pixelScale.y * pixelScale.y;
|
|
4715
4773
|
`
|
|
4716
|
-
|
|
4774
|
+
: `
|
|
4717
4775
|
let ndc = clip.xy / clip.w;
|
|
4718
4776
|
// the target's pixels per screen pixel (variant warp)
|
|
4719
4777
|
let pixelScale = vec2f(1.0);
|
|
4720
4778
|
`}
|
|
4721
|
-
//
|
|
4779
|
+
// The low-pass filter, a variance added to the footprint. The culls measure the footprint
|
|
4780
|
+
// with 0.3 in the chosen units, so in the engine's units with the 0.075 px^2 its culls still
|
|
4781
|
+
// measure; the drawn footprint takes the filter splats are trained with, in true pixels
|
|
4782
|
+
// whatever the units: 0.3 px^2, as the engine's renderer draws them since 2.24
|
|
4722
4783
|
let us2 = uniforms.unitScale * uniforms.unitScale;
|
|
4723
|
-
|
|
4724
|
-
|
|
4784
|
+
let cullDilation = 0.3 / us2;
|
|
4785
|
+
cov00 += cullDilation;
|
|
4786
|
+
cov11 += cullDilation;
|
|
4725
4787
|
let determinant = cov00 * cov11 - cov01 * cov01;
|
|
4726
4788
|
if (determinant <= 0.0) {
|
|
4727
4789
|
return result;
|
|
4728
4790
|
}
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4791
|
+
let cullLambda1 = 0.5 * (cov00 + cov11) + length(vec2f(0.5 * (cov00 - cov11), cov01));
|
|
4792
|
+
${aa
|
|
4793
|
+
? `
|
|
4794
|
+
// Anti-aliasing compensation, as the engine's projector applies it: a splat trained with
|
|
4795
|
+
// anti-aliasing draws with the filter it was trained with (antiAliasFilterSize), its alpha
|
|
4796
|
+
// scaled by the square root of the unfiltered footprint's determinant over the filtered one's,
|
|
4797
|
+
// which keeps a small splat's alpha mass what it was in training. The culls below still
|
|
4798
|
+
// measure the footprint with the file's alpha, as the engine's do
|
|
4799
|
+
let compensated = ${antiAlias === 'mixed' ? 'srcAntiAlias()' : 'true'};
|
|
4800
|
+
let lowpass = select(0.3, uniforms.antiAliasFilterSize, compensated);
|
|
4801
|
+
`
|
|
4802
|
+
: `
|
|
4803
|
+
let lowpass = 0.3;
|
|
4804
|
+
`}${stereo
|
|
4805
|
+
? `
|
|
4736
4806
|
// Stereo: one projection serves both eyes, as the engine's own stereo projector does: the
|
|
4737
4807
|
// second eye takes this view's depth, colour, coverage and order and its own footprint, and
|
|
4738
4808
|
// every cull keeps what either eye would
|
|
4739
|
-
let eye1 = footprintEye1(center, rot, scale, viewport);
|
|
4809
|
+
let eye1 = footprintEye1(center, rot, scale, viewport, lowpass);
|
|
4740
4810
|
`
|
|
4741
|
-
|
|
4811
|
+
: ''}
|
|
4742
4812
|
// size cull on the footprint's radius in pixels. minPixelSize is a diameter: the engine's
|
|
4743
4813
|
// projector is dispatched with half of it, and its quad path tests the full extent
|
|
4744
4814
|
// (2 sqrt(2 lambda)) against the whole value, so both cut at the same place
|
|
4745
|
-
if (uniforms.unitScale * sqrt(2.0 *
|
|
4746
|
-
|
|
4747
|
-
|
|
4815
|
+
if (uniforms.unitScale * sqrt(2.0 * cullLambda1) < 0.5 * uniforms.minPixelSize${stereo
|
|
4816
|
+
? ' && (!eye1.visible || uniforms.unitScale * sqrt(2.0 * eye1.lambda1) < 0.5 * uniforms.minPixelSize)'
|
|
4817
|
+
: ''}) {
|
|
4748
4818
|
return result;
|
|
4749
4819
|
}
|
|
4750
4820
|
|
|
4751
4821
|
// contribution cull: the splat's alpha mass in pixels (the engine's minContribution rule)
|
|
4752
|
-
if (
|
|
4753
|
-
|
|
4754
|
-
|
|
4822
|
+
if (opacityRaw * 6.283185 * sqrt(determinant) * us2 < uniforms.minContribution${stereo
|
|
4823
|
+
? ' && (!eye1.visible || opacityRaw * 6.283185 * sqrt(eye1.determinant) * us2 < uniforms.minContribution)'
|
|
4824
|
+
: ''}) {
|
|
4755
4825
|
return result;
|
|
4756
4826
|
}
|
|
4757
4827
|
|
|
4828
|
+
// the drawn footprint
|
|
4829
|
+
let raw00 = cov00 - cullDilation;
|
|
4830
|
+
let raw11 = cov11 - cullDilation;
|
|
4831
|
+
cov00 = raw00 + lowpass;
|
|
4832
|
+
cov11 = raw11 + lowpass;
|
|
4833
|
+
${aa
|
|
4834
|
+
? `
|
|
4835
|
+
var opacity = opacityRaw;
|
|
4836
|
+
if (compensated) {
|
|
4837
|
+
opacity *= sqrt(max((raw00 * raw11 - cov01 * cov01) / (cov00 * cov11 - cov01 * cov01), 0.0));
|
|
4838
|
+
}
|
|
4839
|
+
// a splat the compensation faded below the clip is dropped, as the engine's projector drops it.
|
|
4840
|
+
// In stereo the second eye takes this eye's compensated alpha, its clip and its coverage, as it
|
|
4841
|
+
// does in the engine's stereo projector (which shares the footprint too): the factor depends
|
|
4842
|
+
// on the view, so a thin splat edge-on to this eye but not to the other is fainter there than
|
|
4843
|
+
// it should be, or gone. Separate projections (variant stereo:separate) compensate per eye
|
|
4844
|
+
if (opacity < uniforms.alphaClip) {
|
|
4845
|
+
return result;
|
|
4846
|
+
}
|
|
4847
|
+
${coverageWGSL}`
|
|
4848
|
+
: ''}
|
|
4849
|
+
let mid = 0.5 * (cov00 + cov11);
|
|
4850
|
+
let radius = length(vec2f(0.5 * (cov00 - cov11), cov01));
|
|
4851
|
+
let lambda1 = mid + radius;
|
|
4852
|
+
let lambda2 = max(mid - radius, 0.1 / us2);
|
|
4853
|
+
|
|
4758
4854
|
// principal axis; a circular footprint has no defined eigenvector, any axis is right
|
|
4759
4855
|
let eigenVec = vec2f(cov01, lambda1 - cov00);
|
|
4760
4856
|
let eigenLen = length(eigenVec);
|
|
@@ -4764,14 +4860,14 @@ ${stereo
|
|
|
4764
4860
|
let len2Full = 2.0 * sqrt(2.0 * lambda2);
|
|
4765
4861
|
let clampScale = min(1.0, maxRadius / len1);
|
|
4766
4862
|
${coverage !== 'pixel'
|
|
4767
|
-
|
|
4863
|
+
? `
|
|
4768
4864
|
// The kept ellipse's polygon, in units of the quad's half extent: area matched to the
|
|
4769
4865
|
// ellipse, or containing it when the raster discards outside it (jitter). The cache keeps
|
|
4770
4866
|
// the full quad's axes and the raster sizes each polygon itself; here the largest bounds the
|
|
4771
4867
|
// culls below
|
|
4772
4868
|
let polygonScale = select(${polygonScale()}, ${polygonScale(true)}, jittered);
|
|
4773
4869
|
${coverage === 'interleaved'
|
|
4774
|
-
|
|
4870
|
+
? `
|
|
4775
4871
|
// the small splats of the interleaved mode draw per splat into the full target: the
|
|
4776
4872
|
// footprint at the alpha clip, in pixels, decides
|
|
4777
4873
|
let footprint = 3.14159265 * len1 * len2Full * pow(radiusAt(max(uniforms.alphaClip, 1e-6), opacity), 2.0);
|
|
@@ -4782,11 +4878,11 @@ ${coverage === 'interleaved'
|
|
|
4782
4878
|
let threshold = select(setThreshold, splatThreshold, fullEntry);
|
|
4783
4879
|
let radiusScale = clampScale * radiusAt(threshold, opacity) * polygonScale;
|
|
4784
4880
|
`
|
|
4785
|
-
|
|
4881
|
+
: `
|
|
4786
4882
|
let radiusScale = clampScale * radiusAt(splatThreshold, opacity) * polygonScale;
|
|
4787
4883
|
`}
|
|
4788
4884
|
`
|
|
4789
|
-
|
|
4885
|
+
: `
|
|
4790
4886
|
let radiusScale = clampScale;
|
|
4791
4887
|
`}
|
|
4792
4888
|
// the extent the culls test: the largest polygon the raster will draw
|
|
@@ -4799,7 +4895,7 @@ ${coverage === 'interleaved'
|
|
|
4799
4895
|
var outside = centerPixels.x + extent.x < 0.0 || centerPixels.x - extent.x > viewport.x
|
|
4800
4896
|
|| centerPixels.y + extent.y < 0.0 || centerPixels.y - extent.y > viewport.y;
|
|
4801
4897
|
${stereo
|
|
4802
|
-
|
|
4898
|
+
? `
|
|
4803
4899
|
// a splat either eye sees survives: the second eye's largest polygon is to its full quad as
|
|
4804
4900
|
// this view's is (both eyes' targets are the same size)
|
|
4805
4901
|
let polygonRatio = radiusScale / clampScale;
|
|
@@ -4810,13 +4906,13 @@ ${stereo
|
|
|
4810
4906
|
outside = outside && (!eye1.visible || centerEye1.x + extentEye1.x < 0.0 || centerEye1.x - extentEye1.x > viewport.x
|
|
4811
4907
|
|| centerEye1.y + extentEye1.y < 0.0 || centerEye1.y - extentEye1.y > viewport.y);
|
|
4812
4908
|
`
|
|
4813
|
-
|
|
4909
|
+
: ''}
|
|
4814
4910
|
if (outside) {
|
|
4815
4911
|
return result;
|
|
4816
4912
|
}
|
|
4817
4913
|
|
|
4818
4914
|
${occlusion
|
|
4819
|
-
|
|
4915
|
+
? `
|
|
4820
4916
|
// Occlusion cull against the previous frame. Each stored depth is the nearest sample that
|
|
4821
4917
|
// survived there, so the farthest depth over the blocks a splat covered bounds what could
|
|
4822
4918
|
// still have shown behind it; a splat whose front (its centre less 2 sqrt(2) sigma along the
|
|
@@ -4828,15 +4924,15 @@ ${occlusion
|
|
|
4828
4924
|
if (uniforms.occlusionMode != 0u) {
|
|
4829
4925
|
let halfExtent = len1 * radiusScale;
|
|
4830
4926
|
if (occludedIn(center, depth, focal.x, halfExtent, c22)${stereo
|
|
4831
|
-
|
|
4832
|
-
|
|
4927
|
+
? ' && (!eye1.visible || occludedInEye1(center, eye1.depth, uniforms.focalEye1.x, length(axis1Eye1), c22))'
|
|
4928
|
+
: ''}) {
|
|
4833
4929
|
result.occluded = true;
|
|
4834
4930
|
return result;
|
|
4835
4931
|
}
|
|
4836
4932
|
}
|
|
4837
4933
|
|
|
4838
4934
|
`
|
|
4839
|
-
|
|
4935
|
+
: ''}
|
|
4840
4936
|
let color = clamp(srcColor(), vec3f(0.0), vec3f(8.0));
|
|
4841
4937
|
|
|
4842
4938
|
// rgb: 10/10/10 unorm with a 2-bit shared exponent (scale 1/2/4/8, range [0, 8])
|
|
@@ -4859,38 +4955,38 @@ ${occlusion
|
|
|
4859
4955
|
result.words[0] = pack2x16snorm(ndc / ndcRange);
|
|
4860
4956
|
result.words[1] = bitcast<u32>(depth);
|
|
4861
4957
|
${coverage !== 'pixel'
|
|
4862
|
-
|
|
4958
|
+
? `
|
|
4863
4959
|
// the full quad's axes (clamped to the radius limit); the raster scales them to each polygon
|
|
4864
4960
|
result.words[2] = pack2x16float(len1 * clampScale * direction);
|
|
4865
|
-
result.words[3] = pack2x16float(vec2f(len2Full * clampScale, 0.0)) | (
|
|
4961
|
+
result.words[3] = pack2x16float(vec2f(len2Full * clampScale, 0.0)) | (encodeCacheAlpha(opacity) << 16u);
|
|
4866
4962
|
`
|
|
4867
|
-
|
|
4963
|
+
: `
|
|
4868
4964
|
result.words[2] = pack2x16float(axis1);
|
|
4869
|
-
result.words[3] = pack2x16float(vec2f(len2, 0.0)) | (
|
|
4965
|
+
result.words[3] = pack2x16float(vec2f(len2, 0.0)) | (encodeCacheAlpha(opacity) << 16u);
|
|
4870
4966
|
`}
|
|
4871
4967
|
// the depth bucket, log-spaced from the near plane, in the flags byte
|
|
4872
4968
|
let key = clamp((log(max(depth, 1e-6)) - uniforms.keyLogNear) * uniforms.keyInvLogRange, 0.0, 0.999) * ${ORDER_BUCKETS}.0;
|
|
4873
4969
|
result.words[3] |= u32(key) << 24u;
|
|
4874
4970
|
result.words[4] = rgb.r | (rgb.g << 10u) | (rgb.b << 20u) | (exponent << 30u);
|
|
4875
4971
|
${coverage === 'pixel'
|
|
4876
|
-
|
|
4972
|
+
? `
|
|
4877
4973
|
// the stable id the coverage hash seeds from: the slot, salted by the file for sources
|
|
4878
4974
|
// whose indices restart per file
|
|
4879
4975
|
result.words[5] = slot ^ (file * 2654435761u);
|
|
4880
4976
|
`
|
|
4881
|
-
|
|
4882
|
-
|
|
4977
|
+
: coverage === 'interleaved'
|
|
4978
|
+
? `
|
|
4883
4979
|
// the draw's bits, bit 15 for a full-target entry, and a nibble per pixel set (0: the set
|
|
4884
4980
|
// keeps nothing): the raster rebuilds every threshold from them
|
|
4885
4981
|
let nibbles = select(setNibbles, vec4u(splatNibble, 0u, 0u, 0u), fullEntry);
|
|
4886
4982
|
result.words[5] = drawnBits | select(0u, ${FULL_ENTRY_BIT}u, fullEntry)
|
|
4887
4983
|
| (nibbles.x << 16u) | (nibbles.y << 20u) | (nibbles.z << 24u) | (nibbles.w << 28u);
|
|
4888
4984
|
`
|
|
4889
|
-
|
|
4985
|
+
: `
|
|
4890
4986
|
// the draw's bits and the per-splat nibble (shaders/raster.ts)
|
|
4891
4987
|
result.words[5] = drawnBits | (splatNibble << 16u);
|
|
4892
4988
|
`}${stereo
|
|
4893
|
-
|
|
4989
|
+
? `
|
|
4894
4990
|
// the second eye's centre, in the same range, and its full quad's axes (shaders/raster.ts),
|
|
4895
4991
|
// stashed in workgroup memory rather than returned: three more words in the per-thread state
|
|
4896
4992
|
// that main() holds across its barriers put the Adreno 740's compiler on a slow path, 6-9x
|
|
@@ -4900,7 +4996,7 @@ ${coverage === 'pixel'
|
|
|
4900
4996
|
pack2x16float(eye1.axis1),
|
|
4901
4997
|
pack2x16float(vec2f(eye1.len2, 0.0))
|
|
4902
4998
|
);`
|
|
4903
|
-
|
|
4999
|
+
: ''}
|
|
4904
5000
|
return result;
|
|
4905
5001
|
}
|
|
4906
5002
|
|
|
@@ -4908,10 +5004,10 @@ var<workgroup> wgCount: atomic<u32>;
|
|
|
4908
5004
|
var<workgroup> wgOccluded: atomic<u32>;
|
|
4909
5005
|
var<workgroup> wgBase: u32;
|
|
4910
5006
|
var<workgroup> wgBuckets: array<atomic<u32>, ${ORDER_BUCKETS}>;${stereo
|
|
4911
|
-
|
|
5007
|
+
? `
|
|
4912
5008
|
// stereo: each thread's second-eye words, from project() to the cache write
|
|
4913
5009
|
var<workgroup> wgEye1: array<vec3u, ${PROJECTOR_WORKGROUP_SIZE}>;`
|
|
4914
|
-
|
|
5010
|
+
: ''}
|
|
4915
5011
|
|
|
4916
5012
|
@compute @workgroup_size(${PROJECTOR_WORKGROUP_SIZE})
|
|
4917
5013
|
fn main(
|
|
@@ -4956,16 +5052,16 @@ fn main(
|
|
|
4956
5052
|
for (var i = 0u; i < ${CACHE_WORDS}u; i++) {
|
|
4957
5053
|
cache[base + i] = projected.words[i];
|
|
4958
5054
|
}${stereo
|
|
4959
|
-
|
|
5055
|
+
? `
|
|
4960
5056
|
// the second eye's three words, after every entry
|
|
4961
5057
|
let stereoBase = uniforms.stereoBase + (wgBase + localSlot) * 3u;
|
|
4962
5058
|
let eye1Words = wgEye1[local];
|
|
4963
5059
|
cache[stereoBase] = eye1Words.x;
|
|
4964
5060
|
cache[stereoBase + 1u] = eye1Words.y;
|
|
4965
5061
|
cache[stereoBase + 2u] = eye1Words.z;`
|
|
4966
|
-
|
|
5062
|
+
: ''}
|
|
4967
5063
|
${coverage === 'interleaved'
|
|
4968
|
-
|
|
5064
|
+
? `
|
|
4969
5065
|
// one entry per kept pixel set, or one in the full target's group: the group's
|
|
4970
5066
|
// ${SET_BUCKETS} buckets, front to back, from the depth bucket
|
|
4971
5067
|
let depthKey = ((projected.words[3] >> 24u) * ${SET_BUCKETS}u) >> 8u;
|
|
@@ -4978,7 +5074,7 @@ ${coverage === 'interleaved'
|
|
|
4978
5074
|
}
|
|
4979
5075
|
}
|
|
4980
5076
|
}`
|
|
4981
|
-
|
|
5077
|
+
: ` atomicAdd(&wgBuckets[projected.words[3] >> 24u], 1u);`}
|
|
4982
5078
|
}
|
|
4983
5079
|
// a chunk's splats are spatially coherent, so few of its buckets are non-empty: one
|
|
4984
5080
|
// workgroup count each, then one global atomic per non-empty bucket
|
|
@@ -4989,6 +5085,7 @@ ${coverage === 'interleaved'
|
|
|
4989
5085
|
}
|
|
4990
5086
|
}
|
|
4991
5087
|
`;
|
|
5088
|
+
};
|
|
4992
5089
|
|
|
4993
5090
|
// Single-thread pass turning the projector's survivor count into the indexed indirect draw
|
|
4994
5091
|
// arguments for the raster pass and the indirect dispatch size of the order scatter. Nothing
|
|
@@ -6010,18 +6107,10 @@ ${varyingsWGSL}
|
|
|
6010
6107
|
// the splat's share of the coverage hash, once per vertex rather than per fragment
|
|
6011
6108
|
uniform frameSeed: u32;
|
|
6012
6109
|
${hashWGSL}
|
|
6110
|
+
${cacheAlphaWGSL}
|
|
6013
6111
|
|
|
6014
6112
|
const discardPosition = vec4f(0.0, 0.0, 2.0, 1.0);
|
|
6015
6113
|
|
|
6016
|
-
#ifdef SSE_COVERAGE_SPLAT
|
|
6017
|
-
// the radius, in units of the quad's half extent, where alpha = opacity * falloff(r^2) falls
|
|
6018
|
-
// to a threshold (the projector's radiusAt)
|
|
6019
|
-
fn radiusAt(threshold: f32, opacity: f32) -> f32 {
|
|
6020
|
-
let e4 = exp(-4.0);
|
|
6021
|
-
return sqrt(max(-log(threshold / opacity * (1.0 - e4) + e4) * 0.25, 0.0));
|
|
6022
|
-
}
|
|
6023
|
-
#endif
|
|
6024
|
-
|
|
6025
6114
|
@vertex
|
|
6026
6115
|
fn vertexMain(input: VertexInput) -> VertexOutput {
|
|
6027
6116
|
var output: VertexOutput;
|
|
@@ -6067,7 +6156,7 @@ fn vertexMain(input: VertexInput) -> VertexOutput {
|
|
|
6067
6156
|
// (shaders/projector.ts): the splat's 15-bit draw, and a nibble per draw group holding
|
|
6068
6157
|
// the stratum and sub-stratum of the jittered modes
|
|
6069
6158
|
let word5 = splatCache[base + 5u];
|
|
6070
|
-
let opacityS =
|
|
6159
|
+
let opacityS = decodeCacheAlpha(word3 >> 16u);
|
|
6071
6160
|
let drawn = f32(word5 & ${(1 << DRAW_BITS) - 1}u) * (1.0 / ${(1 << DRAW_BITS) - 1}.0);
|
|
6072
6161
|
#ifdef SSE_INTERLEAVED
|
|
6073
6162
|
let group = uniform.setIndex;
|
|
@@ -6100,9 +6189,12 @@ fn vertexMain(input: VertexInput) -> VertexOutput {
|
|
|
6100
6189
|
let corner = unit * polygonRadius;
|
|
6101
6190
|
#else
|
|
6102
6191
|
// shrink the quad to where alpha falls below the clip, as the engine's clipCorner does:
|
|
6103
|
-
// the fragment shader discards everything outside it anyway, but still pays to shade it
|
|
6104
|
-
|
|
6105
|
-
let
|
|
6192
|
+
// the fragment shader discards everything outside it anyway, but still pays to shade it.
|
|
6193
|
+
// Above 1 the plateau widens it, as there
|
|
6194
|
+
let opacity = decodeCacheAlpha(word3 >> 16u);
|
|
6195
|
+
let clip = min(1.0, sqrt(max(0.0, log(min(opacity, 1.0) / uniform.sseAlphaClip))) * 0.5);
|
|
6196
|
+
let core = plateauCore(opacity);
|
|
6197
|
+
let corner = vertex_position.xy * (core + (1.0 - core) * clip);
|
|
6106
6198
|
#endif
|
|
6107
6199
|
let pixelOffset = corner.x * axis1 + corner.y * axis2;
|
|
6108
6200
|
let w = select(depth, 1.0, ortho);
|
|
@@ -6145,13 +6237,7 @@ uniform sseAlphaClip: f32;
|
|
|
6145
6237
|
uniform jitterParams: vec4f;
|
|
6146
6238
|
#endif
|
|
6147
6239
|
|
|
6148
|
-
|
|
6149
|
-
const INV_EXP4 = 1.0 / (1.0 - EXP4);
|
|
6150
|
-
|
|
6151
|
-
// the engine's falloff: zero at the quad edge, which sits at 2 sqrt(2) sigma
|
|
6152
|
-
fn falloff(x: f32) -> f32 {
|
|
6153
|
-
return (exp(x * -4.0) - EXP4) * INV_EXP4;
|
|
6154
|
-
}
|
|
6240
|
+
${cacheAlphaWGSL}
|
|
6155
6241
|
|
|
6156
6242
|
@fragment
|
|
6157
6243
|
fn fragmentMain(input: FragmentInput) -> FragmentOutput {
|
|
@@ -6163,7 +6249,7 @@ fn fragmentMain(input: FragmentInput) -> FragmentOutput {
|
|
|
6163
6249
|
// stratum: interleaved gradient noise rotated by the entry's key, as the per-pixel
|
|
6164
6250
|
// raster's. The test discards the square's corners too (alpha is negative past the
|
|
6165
6251
|
// quad's edge), so the kept region is the exact ellipse with a dithered rim
|
|
6166
|
-
let alphaJ =
|
|
6252
|
+
let alphaJ = splatAlpha(dot(gaussianUV, gaussianUV), jitterVary.z);
|
|
6167
6253
|
let ignJ = fract(52.9829189 * fract(dot(pcPosition.xy, vec2f(0.06711056, 0.00583715))));
|
|
6168
6254
|
let thresholdJ = jitterVary.x + fract(ignJ + jitterVary.y) * uniform.jitterParams.z;
|
|
6169
6255
|
if (alphaJ <= max(thresholdJ, uniform.sseAlphaClip)) {
|
|
@@ -6177,8 +6263,7 @@ fn fragmentMain(input: FragmentInput) -> FragmentOutput {
|
|
|
6177
6263
|
if (radius > 1.0) {
|
|
6178
6264
|
discard;
|
|
6179
6265
|
}
|
|
6180
|
-
let
|
|
6181
|
-
let alpha = falloff(radius) * opacity;
|
|
6266
|
+
let alpha = splatAlpha(radius, decodeCacheAlpha(packedAlpha));
|
|
6182
6267
|
if (alpha < uniform.sseAlphaClip) {
|
|
6183
6268
|
discard;
|
|
6184
6269
|
}
|
|
@@ -6464,6 +6549,11 @@ fn srcOpacity() -> f32 {
|
|
|
6464
6549
|
return f32((packedG.w >> 8u) & 0xffu) / 255.0;
|
|
6465
6550
|
}
|
|
6466
6551
|
|
|
6552
|
+
// the file's training mode: one file per dispatch, so the renderer sets it per dispatch
|
|
6553
|
+
fn srcAntiAlias() -> bool {
|
|
6554
|
+
return uniforms.fileAntiAlias != 0u;
|
|
6555
|
+
}
|
|
6556
|
+
|
|
6467
6557
|
// the file stores three components and the omitted axis; the engine's getRotation
|
|
6468
6558
|
fn srcRotation() -> vec4f {
|
|
6469
6559
|
let qb = vec4u((packedG.y >> 16u) & 0xffu, packedG.y >> 24u, packedG.z & 0xffu, (packedG.z >> 8u) & 0xffu);
|
|
@@ -6547,7 +6637,7 @@ fn srcColor() -> vec3f {
|
|
|
6547
6637
|
// 11/11/10 bits (shaders/packed-source.ts), so the projector reads one texel per active splat,
|
|
6548
6638
|
// a second per survivor and no codebook per coefficient; measured on the Pixel 7 Pro against
|
|
6549
6639
|
// reading the six textures as they are: house 11.3 to 9.3 ms, large 11.2 to 9.4. Other formats
|
|
6550
|
-
// (sog v1, ply, compressed ply) are read through the engine's format read chunks as they are.
|
|
6640
|
+
// (sog v1, sog v3, ply, compressed ply) are read through the engine's format read chunks as they are.
|
|
6551
6641
|
//
|
|
6552
6642
|
// The engine's work buffer is not read by this path, so its copy passes are switched off on
|
|
6553
6643
|
// the buffer this source sees and its textures are kept at 1x1 (shrunk if the engine sized them
|
|
@@ -6747,10 +6837,11 @@ class DirectSplatSource {
|
|
|
6747
6837
|
device.computeDispatch([compute], 'sse-splat-decode-sh');
|
|
6748
6838
|
this.decodedSH.set(resource, { texture, compute });
|
|
6749
6839
|
}
|
|
6750
|
-
// the packed layout applies to sog v2 files, the only ones the repack reads
|
|
6840
|
+
// the packed layout applies to sog v2 files, the only ones the repack reads. The engine gives
|
|
6841
|
+
// sog v3 files a codebook too, but no quats texture: their rotation is in the alpha channels
|
|
6751
6842
|
packedActive() {
|
|
6752
6843
|
const textures = this.resource?.streams.textures;
|
|
6753
|
-
return !!textures && textures.has('sogCodebook');
|
|
6844
|
+
return !!textures && textures.has('sogCodebook') && textures.has('quats');
|
|
6754
6845
|
}
|
|
6755
6846
|
hasSH() {
|
|
6756
6847
|
const textures = this.resource?.streams.textures;
|
|
@@ -7015,6 +7106,11 @@ fn srcOpacity() -> f32 {
|
|
|
7015
7106
|
return srcColorCache.a;
|
|
7016
7107
|
}
|
|
7017
7108
|
|
|
7109
|
+
// the file's training mode: one file per dispatch, so the renderer sets it per dispatch
|
|
7110
|
+
fn srcAntiAlias() -> bool {
|
|
7111
|
+
return uniforms.fileAntiAlias != 0u;
|
|
7112
|
+
}
|
|
7113
|
+
|
|
7018
7114
|
// the format returns (w, x, y, z); world = model * source
|
|
7019
7115
|
fn srcRotation() -> vec4f {
|
|
7020
7116
|
let q = quatMulF(uniforms.modelRotation, getRotation().yzwx);
|
|
@@ -7209,6 +7305,8 @@ fn srcOpacity() -> f32 { return getOpacity(); }
|
|
|
7209
7305
|
fn srcRotation() -> vec4f { return getRotation(); }
|
|
7210
7306
|
fn srcScale() -> vec3f { return getScale(); }
|
|
7211
7307
|
fn srcColor() -> vec3f { return getColor(); }
|
|
7308
|
+
// the training mode the engine stamps on each splat it copies (the low bit of its centre)
|
|
7309
|
+
fn srcAntiAlias() -> bool { return getAntiAlias(); }
|
|
7212
7310
|
`;
|
|
7213
7311
|
}
|
|
7214
7312
|
bindFormats() {
|
|
@@ -8863,12 +8961,13 @@ class StochasticSplatRenderer {
|
|
|
8863
8961
|
Math.abs(otherProjection.data[0]) * width * 0.5,
|
|
8864
8962
|
Math.abs(otherProjection.data[5]) * height * 0.5
|
|
8865
8963
|
];
|
|
8964
|
+
const antiAlias = this.antiAliasMode(set);
|
|
8866
8965
|
const groups = this.source.dispatchPlan(set, this.numChunks);
|
|
8867
8966
|
for (const group of groups) {
|
|
8868
8967
|
// a file with no node in the frustum has nothing to dispatch
|
|
8869
8968
|
if (group.fileIndex >= 0 && !this.anyNodeVisible(view, set.files[group.fileIndex].nodes))
|
|
8870
8969
|
continue;
|
|
8871
|
-
const projector = this.ensureProjector(view, culling, coverage, warped, !!eye1, group);
|
|
8970
|
+
const projector = this.ensureProjector(view, culling, coverage, warped, !!eye1, antiAlias, group);
|
|
8872
8971
|
this.source.bind(projector, group, set);
|
|
8873
8972
|
projector.setParameter('chunks', this.chunkBuffer);
|
|
8874
8973
|
projector.setParameter('nodeVisible', view.nodeVisibleBuffer);
|
|
@@ -8917,6 +9016,9 @@ class StochasticSplatRenderer {
|
|
|
8917
9016
|
projector.setParameter('occL2Base', view.occBlocks.x1 * view.occBlocks.y1);
|
|
8918
9017
|
projector.setParameter('stereoBase', view.cacheSlots * CACHE_WORDS);
|
|
8919
9018
|
projector.setParameter('warpBaseEye1', view.warpTable?.length ?? 0);
|
|
9019
|
+
projector.setParameter('antiAliasFilterSize', gsplat.antiAliasFilterSize);
|
|
9020
|
+
// the per-file sources' training mode (the work buffer's splats carry their own)
|
|
9021
|
+
projector.setParameter('fileAntiAlias', group.fileIndex >= 0 && set.files[group.fileIndex].resource.antiAlias ? 1 : 0);
|
|
8920
9022
|
Compute.calcDispatchSize(group.chunkCount, tmpVec2);
|
|
8921
9023
|
projector.setupDispatch(tmpVec2.x, tmpVec2.y, 1);
|
|
8922
9024
|
device.computeDispatch([projector], 'sse-splat-project');
|
|
@@ -9315,19 +9417,29 @@ class StochasticSplatRenderer {
|
|
|
9315
9417
|
const bits = view.nodeVisibleData;
|
|
9316
9418
|
return nodes.some((node) => (bits[node.nodeIndex >> 5] >>> (node.nodeIndex & 31)) & 1);
|
|
9317
9419
|
}
|
|
9318
|
-
|
|
9420
|
+
// The anti-aliasing compensation, resolved as the engine's manager resolves it for its own
|
|
9421
|
+
// renderer: the scene's GSplatParams#antiAlias when set, else each file's training mode,
|
|
9422
|
+
// compiled out when no file needs it and read per splat when only some do
|
|
9423
|
+
antiAliasMode(set) {
|
|
9424
|
+
const { antiAlias } = this.app.scene.gsplat;
|
|
9425
|
+
if (antiAlias !== undefined)
|
|
9426
|
+
return antiAlias ? 'on' : 'off';
|
|
9427
|
+
const flagged = set.files.filter((file) => file.resource.antiAlias).length;
|
|
9428
|
+
return flagged === 0 ? 'off' : flagged === set.files.length ? 'on' : 'mixed';
|
|
9429
|
+
}
|
|
9430
|
+
ensureProjector(view, occlusion, coverage, warp, stereo, antiAlias, group) {
|
|
9319
9431
|
const sourceKey = this.source.shaderKey();
|
|
9320
9432
|
if (this.projectorSourceKey !== sourceKey) {
|
|
9321
9433
|
// a different source: every specialisation and the bind group format go
|
|
9322
9434
|
this.destroyProjector();
|
|
9323
9435
|
this.projectorSourceKey = sourceKey;
|
|
9324
9436
|
}
|
|
9325
|
-
const key = `${occlusion ? 'occlusion' : 'plain'}-${coverage}${warp ? '-warp' : ''}${stereo ? '-stereo' : ''}`;
|
|
9437
|
+
const key = `${occlusion ? 'occlusion' : 'plain'}-${coverage}${warp ? '-warp' : ''}${stereo ? '-stereo' : ''}${antiAlias === 'off' ? '' : `-aa-${antiAlias}`}`;
|
|
9326
9438
|
const computeKey = `${key}:${group.fileIndex}`;
|
|
9327
9439
|
const existing = view.projectorComputes.get(computeKey);
|
|
9328
9440
|
if (existing)
|
|
9329
9441
|
return existing;
|
|
9330
|
-
const shader = this.ensureProjectorShader(key, occlusion, coverage, warp, stereo);
|
|
9442
|
+
const shader = this.ensureProjectorShader(key, occlusion, coverage, warp, stereo, antiAlias);
|
|
9331
9443
|
const compute = new Compute(this.device, shader, 'sse-splat-project');
|
|
9332
9444
|
view.projectorComputes.set(computeKey, compute);
|
|
9333
9445
|
return compute;
|
|
@@ -9344,7 +9456,7 @@ class StochasticSplatRenderer {
|
|
|
9344
9456
|
}
|
|
9345
9457
|
}
|
|
9346
9458
|
}
|
|
9347
|
-
ensureProjectorShader(key, occlusion, coverage, warp, stereo) {
|
|
9459
|
+
ensureProjectorShader(key, occlusion, coverage, warp, stereo, antiAlias) {
|
|
9348
9460
|
const existing = this.projectorShaders.get(key);
|
|
9349
9461
|
if (existing)
|
|
9350
9462
|
return existing;
|
|
@@ -9369,7 +9481,7 @@ class StochasticSplatRenderer {
|
|
|
9369
9481
|
const shader = new Shader(device, {
|
|
9370
9482
|
name: `sse-splat-project-${key}`,
|
|
9371
9483
|
shaderLanguage: SHADERLANGUAGE_WGSL,
|
|
9372
|
-
cshader: projectorWGSL(this.source.readChunk(fixed.length), occlusion, coverage, warp, stereo),
|
|
9484
|
+
cshader: projectorWGSL(this.source.readChunk(fixed.length), occlusion, coverage, warp, stereo, antiAlias),
|
|
9373
9485
|
cincludes: this.source.shaderIncludes(),
|
|
9374
9486
|
cdefines: this.source.shaderDefines(),
|
|
9375
9487
|
computeUniformBufferFormats: {
|
|
@@ -9416,7 +9528,9 @@ class StochasticSplatRenderer {
|
|
|
9416
9528
|
new UniformFormat('prevFocalEye1', UNIFORMTYPE_VEC2),
|
|
9417
9529
|
new UniformFormat('occL2Base', UNIFORMTYPE_UINT),
|
|
9418
9530
|
new UniformFormat('stereoBase', UNIFORMTYPE_UINT),
|
|
9419
|
-
new UniformFormat('warpBaseEye1', UNIFORMTYPE_UINT)
|
|
9531
|
+
new UniformFormat('warpBaseEye1', UNIFORMTYPE_UINT),
|
|
9532
|
+
new UniformFormat('antiAliasFilterSize', UNIFORMTYPE_FLOAT),
|
|
9533
|
+
new UniformFormat('fileAntiAlias', UNIFORMTYPE_UINT)
|
|
9420
9534
|
])
|
|
9421
9535
|
},
|
|
9422
9536
|
computeBindGroupFormat: this.projectorBindGroupFormat
|
|
@@ -10023,7 +10137,7 @@ const importSettings = (settings) => {
|
|
|
10023
10137
|
return result;
|
|
10024
10138
|
};
|
|
10025
10139
|
|
|
10026
|
-
var version = "1.
|
|
10140
|
+
var version = "1.43.1";
|
|
10027
10141
|
|
|
10028
10142
|
class Tooltip {
|
|
10029
10143
|
register;
|
|
@@ -20497,8 +20611,13 @@ class FrameGate {
|
|
|
20497
20611
|
}
|
|
20498
20612
|
// a rendered frame's work is all submitted by its end
|
|
20499
20613
|
frameEnd() {
|
|
20500
|
-
if (!this.rendered)
|
|
20614
|
+
if (!this.rendered) {
|
|
20615
|
+
// Firefox resolves onSubmittedWorkDone only when its gpu process polls the device, on a
|
|
20616
|
+
// submit or a ~100 ms timer, so an empty submit each tick a request waits makes it poll
|
|
20617
|
+
if (this.owed && this.queue)
|
|
20618
|
+
this.queue.submit([]);
|
|
20501
20619
|
return;
|
|
20620
|
+
}
|
|
20502
20621
|
this.rendered = false;
|
|
20503
20622
|
if (this.queue) {
|
|
20504
20623
|
this.pending++;
|
|
@@ -24300,42 +24419,60 @@ class Viewer {
|
|
|
24300
24419
|
}
|
|
24301
24420
|
}
|
|
24302
24421
|
|
|
24422
|
+
var glueSource = "// Glue script for the ZSTD decompression WebAssembly module (decompression only).\n//\n// The wasm binary (zstd.wasm.wasm) is the single-file zstd decoder (zstddeclib) from the\n// Zstandard project (https://github.com/facebook/zstd, BSD-3-Clause), compiled to WebAssembly\n// by the zstddec project (https://github.com/donmccurdy/zstddec, MIT).\n//\n// This script conforms to the WasmModule contract: it exposes a global factory function\n// which is passed a config object with locateFile() and returns a promise of the module\n// instance. Register it like this:\n//\n// import { WasmModule } from 'playcanvas';\n//\n// WasmModule.setConfig('ZstdDecoderModule', {\n// glueUrl: 'zstd.wasm.js',\n// wasmUrl: 'zstd.wasm.wasm'\n// });\n//\n// The resolved instance exposes:\n//\n// decompress(src: Uint8Array, decompressedSize: number): Uint8Array\n(function () {\n function ZstdDecoderModule(config) {\n config = config || {};\n\n var instance = null;\n var heap = null;\n\n var refreshHeap = function () {\n heap = new Uint8Array(instance.exports.memory.buffer);\n };\n\n // the only import the wasm module needs - notification of memory growth\n var imports = {\n env: {\n emscripten_notify_memory_growth: function () {\n refreshHeap();\n }\n }\n };\n\n var wasmUrl = config.locateFile ? config.locateFile('zstd.wasm.wasm') : 'zstd.wasm.wasm';\n\n return fetch(wasmUrl)\n .then(function (response) {\n return response.arrayBuffer();\n })\n .then(function (bytes) {\n return WebAssembly.instantiate(bytes, imports);\n })\n .then(function (result) {\n instance = result.instance;\n refreshHeap();\n\n return {\n decompress: function (src, decompressedSize) {\n var exports = instance.exports;\n\n // copy compressed data into wasm memory\n var srcPtr = exports.malloc(src.byteLength);\n heap.set(src, srcPtr);\n\n // decompress\n var dstPtr = exports.malloc(decompressedSize);\n var size = exports.ZSTD_decompress(dstPtr, decompressedSize, srcPtr, src.byteLength);\n var error = exports.ZSTD_isError(size);\n var data = error ? null : heap.slice(dstPtr, dstPtr + size);\n\n exports.free(srcPtr);\n exports.free(dstPtr);\n\n if (error) {\n throw new Error('ZstdDecoderModule: failed to decompress data');\n }\n return data;\n }\n };\n })\n .catch(function (err) {\n if (config.onAbort) {\n config.onAbort(err);\n }\n throw err;\n });\n }\n\n window.ZstdDecoderModule = ZstdDecoderModule;\n})();\n";
|
|
24423
|
+
|
|
24424
|
+
// the glue's blob url, made once a page: every viewer on it shares the engine's module registry
|
|
24425
|
+
let glueUrl = null;
|
|
24426
|
+
/**
|
|
24427
|
+
* Registers the engine's ZSTD decoder, which the spz parser needs for version 4 files. Only the
|
|
24428
|
+
* urls are recorded here: the engine loads the glue and the wasm on the first version 4 file.
|
|
24429
|
+
*
|
|
24430
|
+
* @param wasmUrl - The decoder's wasm; by default the file shipped beside the bundle.
|
|
24431
|
+
*/
|
|
24432
|
+
const registerZstdDecoder = (wasmUrl) => {
|
|
24433
|
+
glueUrl ??= URL.createObjectURL(new Blob([glueSource], { type: 'text/javascript' }));
|
|
24434
|
+
WasmModule.setConfig('ZstdDecoderModule', {
|
|
24435
|
+
glueUrl,
|
|
24436
|
+
// a literal `new URL(..., import.meta.url)`, so a host's bundler emits the file with its own
|
|
24437
|
+
wasmUrl: wasmUrl ?? new URL('./zstd-decoder.wasm', import.meta.url).href
|
|
24438
|
+
});
|
|
24439
|
+
};
|
|
24440
|
+
|
|
24303
24441
|
// The filename's extension selects the gsplat parser, so a url with no usable name (a data:
|
|
24304
24442
|
// uri) needs the config to name its content instead; falsy (an empty name) falls back to the
|
|
24305
24443
|
// url-derived name.
|
|
24306
24444
|
const contentName = (contentUrl, contentFilename) => contentFilename || new URL(contentUrl, location.href).pathname.split('/').pop();
|
|
24307
|
-
// Whether a prefetched response for this content is worth starting. The engine's octree
|
|
24308
|
-
//
|
|
24309
|
-
// the metadata twice — a quarter of a megabyte on a real scene,
|
|
24310
|
-
// header, so the second request is not a cache hit.
|
|
24311
|
-
//
|
|
24312
|
-
//
|
|
24313
|
-
//
|
|
24314
|
-
|
|
24445
|
+
// Whether a prefetched response for this content is worth starting. The engine's octree and lcc2
|
|
24446
|
+
// parsers fetch lod-meta.json and .lcc2 files themselves and ignore `asset.file.contents`, so
|
|
24447
|
+
// prefetching them downloads the metadata twice — a quarter of a megabyte on a real scene,
|
|
24448
|
+
// served with no cache-control header, so the second request is not a cache hit. The spz parser
|
|
24449
|
+
// takes `asset.file.contents` only as an ArrayBuffer, not the prefetched response, so it fetches
|
|
24450
|
+
// its file itself too, which keeps the download progress (`loadGsplat` reads a response the
|
|
24451
|
+
// caller passes to an ArrayBuffer). Every other splat parser consumes the prefetched response, so they keep
|
|
24452
|
+
// the head start. `src/index.html` applies the same rule when it starts its own prefetch, and
|
|
24453
|
+
// docs/streaming-progress.md covers the engine fix that would let the octree path reuse the
|
|
24454
|
+
// response instead of opting out of it.
|
|
24455
|
+
const isPrefetchable = (contentUrl, contentFilename) => {
|
|
24456
|
+
const name = contentName(contentUrl, contentFilename)?.toLowerCase();
|
|
24457
|
+
return name !== 'lod-meta.json' && !name?.endsWith('.lcc2') && !name?.endsWith('.spz');
|
|
24458
|
+
};
|
|
24315
24459
|
// gsaf is an animated splat sequence, which the viewer decodes and plays itself rather than
|
|
24316
24460
|
// through an engine parser
|
|
24317
24461
|
const isGsaf = (contentUrl, contentFilename) => contentName(contentUrl, contentFilename)?.toLowerCase().endsWith('.gsaf');
|
|
24318
|
-
// TEMPORARY, until a Quest Browser release accepts a WebGPU device for WebXR again: then delete
|
|
24319
|
-
// this and its use in resolveConfig. Quest Browser 156 refuses every WebGPU device for an
|
|
24320
|
-
// immersive session, even one from an adapter requested with xrCompatible (XRGPUBinding throws
|
|
24321
|
-
// "WebGPU device must be created by an XR compatible adapter"), so VR and AR show black. The
|
|
24322
|
-
// headsets already run the sorted renderer (quality.ts keeps the stochastic one off them), so
|
|
24323
|
-
// WebGL costs them only the gpu sort. It overrides even an explicit renderer: 'webgpu', since
|
|
24324
|
-
// hosts pass one by default (superspl.at's viewer-options.ts does). A ?webgpu in the page url
|
|
24325
|
-
// opts back in, to check a new browser release for the fix. It is read here rather than in
|
|
24326
|
-
// index.html, against the rule that only the document reads url params, because hosts parse the
|
|
24327
|
-
// url themselves (superspl.at forwards its scene page's params to the viewer's document but does
|
|
24328
|
-
// not pass this one on)
|
|
24329
|
-
const questBrowser = /OculusBrowser/.test(globalThis.navigator?.userAgent ?? '') &&
|
|
24330
|
-
!new URLSearchParams(globalThis.location?.search ?? '').has('webgpu');
|
|
24331
24462
|
const loadGsplat = async (app, config, progressCallback, cancelled) => {
|
|
24332
24463
|
const { contents, contentUrl, contentFilename } = config;
|
|
24333
|
-
const c = contents;
|
|
24334
24464
|
const filename = contentName(contentUrl, contentFilename);
|
|
24335
|
-
const
|
|
24336
|
-
|
|
24337
|
-
//
|
|
24338
|
-
//
|
|
24465
|
+
const name = filename.toLowerCase();
|
|
24466
|
+
const data = name === 'meta.json' ? await (await contents).json() : undefined;
|
|
24467
|
+
// The spz parser reads `asset.file.contents` only as an ArrayBuffer, so a fetch the caller
|
|
24468
|
+
// started is read to one here (the viewer starts none for spz, see `isPrefetchable`)
|
|
24469
|
+
const c = (name.endsWith('.spz') && contents
|
|
24470
|
+
? await (await contents).arrayBuffer()
|
|
24471
|
+
: contents);
|
|
24472
|
+
// Reading that metadata or those bytes spans a network round trip, so a destroy can land in
|
|
24473
|
+
// the middle of it. `app.destroy()` nulls the asset registry, so registering the asset now
|
|
24474
|
+
// would throw from the engine's internals; reject instead, which the viewer's load chains
|
|
24475
|
+
// expect.
|
|
24339
24476
|
if (cancelled()) {
|
|
24340
24477
|
throw new Error('loadGsplat: the viewer was destroyed while loading');
|
|
24341
24478
|
}
|
|
@@ -24345,7 +24482,13 @@ const loadGsplat = async (app, config, progressCallback, cancelled) => {
|
|
|
24345
24482
|
// always name the app: the engine's default is the most recently created one,
|
|
24346
24483
|
// which is another viewer's when two share a page
|
|
24347
24484
|
const entity = new Entity('gsplat', app);
|
|
24348
|
-
|
|
24485
|
+
// LCC2 scenes are stored +Z up, spz files +Y up, the other formats -Y up
|
|
24486
|
+
if (name.endsWith('.lcc2')) {
|
|
24487
|
+
entity.setLocalEulerAngles(270, 0, 0);
|
|
24488
|
+
}
|
|
24489
|
+
else if (!name.endsWith('.spz')) {
|
|
24490
|
+
entity.setLocalEulerAngles(0, 0, 180);
|
|
24491
|
+
}
|
|
24349
24492
|
entity.addComponent('gsplat', {
|
|
24350
24493
|
unified: true,
|
|
24351
24494
|
asset
|
|
@@ -24417,6 +24560,7 @@ const createApp = async (canvas, config) => {
|
|
|
24417
24560
|
touch: new TouchDevice$1(canvas),
|
|
24418
24561
|
keyboard: new Keyboard(window)
|
|
24419
24562
|
});
|
|
24563
|
+
registerZstdDecoder(config.zstdDecoderUrl);
|
|
24420
24564
|
// The per-splat centres the engine reads back for its cpu sort (12 bytes each, plus a gpu
|
|
24421
24565
|
// readback per file) serve only that sort and non-unified rendering. On WebGPU the viewer
|
|
24422
24566
|
// renders unified, and neither renderer sorts on the cpu (the engine's sorts on the gpu, the
|
|
@@ -24513,10 +24657,11 @@ const resolveConfig = (options) => ({
|
|
|
24513
24657
|
skyboxUrl: options.skyboxUrl,
|
|
24514
24658
|
collisionUrl: options.collisionUrl,
|
|
24515
24659
|
gsafDecoderUrl: options.gsafDecoderUrl,
|
|
24660
|
+
zstdDecoderUrl: options.zstdDecoderUrl,
|
|
24516
24661
|
poster: options.poster ?? (options.posterUrl ? createImage(options.posterUrl) : undefined),
|
|
24517
24662
|
contents: options.contents ??
|
|
24518
24663
|
(isPrefetchable(options.contentUrl, options.contentFilename) ? fetch(options.contentUrl) : undefined),
|
|
24519
|
-
renderer:
|
|
24664
|
+
renderer: options.renderer ?? 'webgpu',
|
|
24520
24665
|
ui: options.ui ?? true,
|
|
24521
24666
|
reticle: options.reticle ?? false,
|
|
24522
24667
|
noanim: options.noanim ?? false,
|
|
@@ -24526,7 +24671,7 @@ const resolveConfig = (options) => ({
|
|
|
24526
24671
|
colorize: options.colorize ?? false,
|
|
24527
24672
|
fullload: options.fullload ?? false,
|
|
24528
24673
|
vr: options.vr ?? false,
|
|
24529
|
-
aa: options.aa
|
|
24674
|
+
aa: options.aa,
|
|
24530
24675
|
stochastic: options.stochastic ?? false,
|
|
24531
24676
|
// the direct source reads the engine's own splat files, not the container a gsaf sequence
|
|
24532
24677
|
// plays through; the work buffer source reads whatever the engine copied
|