@playcanvas/supersplat-viewer 1.3.0 → 1.3.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 +2 -2
- package/dist/index.js +1 -1
- package/package.json +9 -12
- package/public/index.js +2658 -386
- package/public/index.js.map +1 -1
package/public/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const TRACEID_GPU_TIMINGS = 'GpuTimings';
|
|
2
2
|
|
|
3
|
-
const version = '2.
|
|
4
|
-
const revision = '
|
|
3
|
+
const version = '2.11.3';
|
|
4
|
+
const revision = '99c96dd';
|
|
5
5
|
function extend(target, ex) {
|
|
6
6
|
for(const prop in ex){
|
|
7
7
|
const copy = ex[prop];
|
|
@@ -5063,7 +5063,7 @@ semanticToLocation[SEMANTIC_ATTR13] = 13;
|
|
|
5063
5063
|
semanticToLocation[SEMANTIC_ATTR14] = 14;
|
|
5064
5064
|
semanticToLocation[SEMANTIC_ATTR15] = 15;
|
|
5065
5065
|
|
|
5066
|
-
let id$
|
|
5066
|
+
let id$d = 0;
|
|
5067
5067
|
class BindBaseFormat {
|
|
5068
5068
|
constructor(name, visibility){
|
|
5069
5069
|
this.slot = -1;
|
|
@@ -5104,7 +5104,7 @@ class BindGroupFormat {
|
|
|
5104
5104
|
this.textureFormats = [];
|
|
5105
5105
|
this.storageTextureFormats = [];
|
|
5106
5106
|
this.storageBufferFormats = [];
|
|
5107
|
-
this.id = id$
|
|
5107
|
+
this.id = id$d++;
|
|
5108
5108
|
let slot = 0;
|
|
5109
5109
|
formats.forEach((format)=>{
|
|
5110
5110
|
format.slot = slot++;
|
|
@@ -5221,11 +5221,11 @@ class TextureUtils {
|
|
|
5221
5221
|
}
|
|
5222
5222
|
}
|
|
5223
5223
|
|
|
5224
|
-
let id$
|
|
5224
|
+
let id$c = 0;
|
|
5225
5225
|
class Texture {
|
|
5226
5226
|
constructor(graphicsDevice, options = {}){
|
|
5227
5227
|
this._gpuSize = 0;
|
|
5228
|
-
this.id = id$
|
|
5228
|
+
this.id = id$c++;
|
|
5229
5229
|
this._invalid = false;
|
|
5230
5230
|
this._lockedLevel = -1;
|
|
5231
5231
|
this._lockedMode = TEXTURELOCK_NONE;
|
|
@@ -5723,7 +5723,7 @@ const getBuiltInTexture = (device, name)=>{
|
|
|
5723
5723
|
return cache.map.get(name);
|
|
5724
5724
|
};
|
|
5725
5725
|
|
|
5726
|
-
let id$
|
|
5726
|
+
let id$b = 0;
|
|
5727
5727
|
class DynamicBindGroup {
|
|
5728
5728
|
constructor(){
|
|
5729
5729
|
this.offsets = [];
|
|
@@ -5733,7 +5733,7 @@ class BindGroup {
|
|
|
5733
5733
|
constructor(graphicsDevice, format, defaultUniformBuffer){
|
|
5734
5734
|
this.renderVersionUpdated = -1;
|
|
5735
5735
|
this.uniformBufferOffsets = [];
|
|
5736
|
-
this.id = id$
|
|
5736
|
+
this.id = id$b++;
|
|
5737
5737
|
this.device = graphicsDevice;
|
|
5738
5738
|
this.format = format;
|
|
5739
5739
|
this.dirty = true;
|
|
@@ -6131,7 +6131,7 @@ class ScopeSpace {
|
|
|
6131
6131
|
}
|
|
6132
6132
|
}
|
|
6133
6133
|
|
|
6134
|
-
let id$
|
|
6134
|
+
let id$a = 0;
|
|
6135
6135
|
class VertexBuffer {
|
|
6136
6136
|
constructor(graphicsDevice, format, numVertices, options){
|
|
6137
6137
|
this.usage = BUFFER_STATIC;
|
|
@@ -6139,7 +6139,7 @@ class VertexBuffer {
|
|
|
6139
6139
|
this.device = graphicsDevice;
|
|
6140
6140
|
this.format = format;
|
|
6141
6141
|
this.numVertices = numVertices;
|
|
6142
|
-
this.id = id$
|
|
6142
|
+
this.id = id$a++;
|
|
6143
6143
|
this.impl = graphicsDevice.createVertexBufferImpl(this, format, options);
|
|
6144
6144
|
this.numBytes = format.verticesByteSize ? format.verticesByteSize : format.size * numVertices;
|
|
6145
6145
|
this.adjustVramSizeTracking(graphicsDevice._vram, this.numBytes);
|
|
@@ -6717,10 +6717,10 @@ class GraphicsDevice extends EventHandler {
|
|
|
6717
6717
|
validateAttributes(shader, vb0Format, vb1Format) {}
|
|
6718
6718
|
}
|
|
6719
6719
|
|
|
6720
|
-
let id$
|
|
6720
|
+
let id$9 = 0;
|
|
6721
6721
|
class RenderTarget {
|
|
6722
6722
|
constructor(options = {}){
|
|
6723
|
-
this.id = id$
|
|
6723
|
+
this.id = id$9++;
|
|
6724
6724
|
const device = options.colorBuffer?.device ?? options.colorBuffers?.[0].device ?? options.depthBuffer?.device ?? options.graphicsDevice;
|
|
6725
6725
|
this._device = device;
|
|
6726
6726
|
const { maxSamples } = this._device;
|
|
@@ -10143,11 +10143,11 @@ class ShaderDefinitionUtils {
|
|
|
10143
10143
|
}
|
|
10144
10144
|
}
|
|
10145
10145
|
|
|
10146
|
-
let id$
|
|
10146
|
+
let id$8 = 0;
|
|
10147
10147
|
class Shader {
|
|
10148
10148
|
constructor(graphicsDevice, definition){
|
|
10149
10149
|
this.attributes = new Map();
|
|
10150
|
-
this.id = id$
|
|
10150
|
+
this.id = id$8++;
|
|
10151
10151
|
this.device = graphicsDevice;
|
|
10152
10152
|
this.definition = definition;
|
|
10153
10153
|
this.name = definition.name || 'Untitled';
|
|
@@ -11124,10 +11124,10 @@ class WebgpuCompute {
|
|
|
11124
11124
|
}
|
|
11125
11125
|
}
|
|
11126
11126
|
|
|
11127
|
-
let id$
|
|
11127
|
+
let id$7 = 0;
|
|
11128
11128
|
class StorageBuffer {
|
|
11129
11129
|
constructor(graphicsDevice, byteSize, bufferUsage = 0){
|
|
11130
|
-
this.id = id$
|
|
11130
|
+
this.id = id$7++;
|
|
11131
11131
|
this.device = graphicsDevice;
|
|
11132
11132
|
this.byteSize = byteSize;
|
|
11133
11133
|
this.bufferUsage = bufferUsage;
|
|
@@ -11241,8 +11241,10 @@ class WebgpuGraphicsDevice extends GraphicsDevice {
|
|
|
11241
11241
|
this.textureFloatFilterable = requireFeature('float32-filterable');
|
|
11242
11242
|
this.textureFloatBlendable = requireFeature('float32-blendable');
|
|
11243
11243
|
this.extCompressedTextureS3TC = requireFeature('texture-compression-bc');
|
|
11244
|
+
this.extCompressedTextureS3TCSliced3D = requireFeature('texture-compression-bc-sliced-3d');
|
|
11244
11245
|
this.extCompressedTextureETC = requireFeature('texture-compression-etc2');
|
|
11245
11246
|
this.extCompressedTextureASTC = requireFeature('texture-compression-astc');
|
|
11247
|
+
this.extCompressedTextureASTCSliced3D = requireFeature('texture-compression-astc-sliced-3d');
|
|
11246
11248
|
this.supportsTimestampQuery = requireFeature('timestamp-query');
|
|
11247
11249
|
this.supportsDepthClip = requireFeature('depth-clip-control');
|
|
11248
11250
|
this.supportsDepth32Stencil = requireFeature('depth32float-stencil8');
|
|
@@ -12474,7 +12476,7 @@ class WebglTexture {
|
|
|
12474
12476
|
let mipObject;
|
|
12475
12477
|
let resMult;
|
|
12476
12478
|
const requiredMipLevels = texture.numLevels;
|
|
12477
|
-
if (texture.array) {
|
|
12479
|
+
if (texture.array && !this._glCreated) {
|
|
12478
12480
|
gl.texStorage3D(gl.TEXTURE_2D_ARRAY, requiredMipLevels, this._glInternalFormat, texture._width, texture._height, texture._arrayLength);
|
|
12479
12481
|
}
|
|
12480
12482
|
while(texture._levels[mipLevel] || mipLevel === 0){
|
|
@@ -12629,6 +12631,13 @@ class WebglTexture {
|
|
|
12629
12631
|
texture.adjustVramSizeTracking(device._vram, texture._gpuSize);
|
|
12630
12632
|
this._glCreated = true;
|
|
12631
12633
|
}
|
|
12634
|
+
uploadImmediate(device, texture) {
|
|
12635
|
+
if (texture._needsUpload || texture._needsMipmapsUpload) {
|
|
12636
|
+
device.setTexture(texture, 0);
|
|
12637
|
+
texture._needsUpload = false;
|
|
12638
|
+
texture._needsMipmapsUpload = false;
|
|
12639
|
+
}
|
|
12640
|
+
}
|
|
12632
12641
|
read(x, y, width, height, options) {
|
|
12633
12642
|
const texture = this.texture;
|
|
12634
12643
|
const device = texture.device;
|
|
@@ -14648,14 +14657,14 @@ function createGraphicsDevice(canvas, options = {}) {
|
|
|
14648
14657
|
});
|
|
14649
14658
|
}
|
|
14650
14659
|
|
|
14651
|
-
let id$
|
|
14660
|
+
let id$6 = 0;
|
|
14652
14661
|
class IndexBuffer {
|
|
14653
14662
|
constructor(graphicsDevice, format, numIndices, usage = BUFFER_STATIC, initialData, options){
|
|
14654
14663
|
this.device = graphicsDevice;
|
|
14655
14664
|
this.format = format;
|
|
14656
14665
|
this.numIndices = numIndices;
|
|
14657
14666
|
this.usage = usage;
|
|
14658
|
-
this.id = id$
|
|
14667
|
+
this.id = id$6++;
|
|
14659
14668
|
this.impl = graphicsDevice.createIndexBufferImpl(this, options);
|
|
14660
14669
|
const bytesPerIndex = typedArrayIndexFormatsByteSize[format];
|
|
14661
14670
|
this.bytesPerIndex = bytesPerIndex;
|
|
@@ -17313,7 +17322,7 @@ class QuadRender {
|
|
|
17313
17322
|
device.setViewport(viewport.x, viewport.y, viewport.z, viewport.w);
|
|
17314
17323
|
device.setScissor(scissor.x, scissor.y, scissor.z, scissor.w);
|
|
17315
17324
|
}
|
|
17316
|
-
device.setVertexBuffer(device.quadVertexBuffer
|
|
17325
|
+
device.setVertexBuffer(device.quadVertexBuffer);
|
|
17317
17326
|
const shader = this.shader;
|
|
17318
17327
|
device.setShader(shader);
|
|
17319
17328
|
if (device.supportsUniformBuffers) {
|
|
@@ -17595,7 +17604,7 @@ class SkinBatchInstance extends SkinInstance {
|
|
|
17595
17604
|
}
|
|
17596
17605
|
}
|
|
17597
17606
|
|
|
17598
|
-
let id$
|
|
17607
|
+
let id$5 = 0;
|
|
17599
17608
|
class GeometryData {
|
|
17600
17609
|
constructor(){
|
|
17601
17610
|
this.initDefaults();
|
|
@@ -17652,7 +17661,7 @@ class Mesh extends RefCountedObject {
|
|
|
17652
17661
|
count: 0
|
|
17653
17662
|
}
|
|
17654
17663
|
], this.skin = null, this.boneAabb = null, this._aabbVer = 0, this._aabb = new BoundingBox(), this._geometryData = null, this._morph = null, this._storageIndex = false, this._storageVertex = false;
|
|
17655
|
-
this.id = id$
|
|
17664
|
+
this.id = id$5++;
|
|
17656
17665
|
this.device = graphicsDevice;
|
|
17657
17666
|
this._storageIndex = options?.storageIndex || false;
|
|
17658
17667
|
this._storageVertex = options?.storageVertex || false;
|
|
@@ -18188,7 +18197,7 @@ class LightmapCache {
|
|
|
18188
18197
|
}
|
|
18189
18198
|
}
|
|
18190
18199
|
|
|
18191
|
-
let id$
|
|
18200
|
+
let id$4 = 0;
|
|
18192
18201
|
const _tmpAabb = new BoundingBox();
|
|
18193
18202
|
const _tempBoneAabb = new BoundingBox();
|
|
18194
18203
|
const _tempSphere = new BoundingSphere();
|
|
@@ -18255,7 +18264,7 @@ class MeshInstance {
|
|
|
18255
18264
|
this.visibleThisFrame = false;
|
|
18256
18265
|
this.flipFacesFactor = 1;
|
|
18257
18266
|
this.gsplatInstance = null;
|
|
18258
|
-
this.id = id$
|
|
18267
|
+
this.id = id$4++;
|
|
18259
18268
|
this.isVisibleFunc = null;
|
|
18260
18269
|
this.instancingData = null;
|
|
18261
18270
|
this.indirectData = null;
|
|
@@ -20668,7 +20677,7 @@ class GraphNode extends EventHandler {
|
|
|
20668
20677
|
}
|
|
20669
20678
|
}
|
|
20670
20679
|
|
|
20671
|
-
const _viewMat = new Mat4();
|
|
20680
|
+
const _viewMat$1 = new Mat4();
|
|
20672
20681
|
const _viewProjMat = new Mat4();
|
|
20673
20682
|
const _viewportMatrix = new Mat4();
|
|
20674
20683
|
class LightCamera {
|
|
@@ -20717,8 +20726,8 @@ class LightCamera {
|
|
|
20717
20726
|
cookieNode.setPosition(light._node.getPosition());
|
|
20718
20727
|
cookieNode.setRotation(light._node.getRotation());
|
|
20719
20728
|
cookieNode.rotateLocal(-90, 0, 0);
|
|
20720
|
-
_viewMat.setTRS(cookieNode.getPosition(), cookieNode.getRotation(), Vec3.ONE).invert();
|
|
20721
|
-
_viewProjMat.mul2(cookieCamera.projectionMatrix, _viewMat);
|
|
20729
|
+
_viewMat$1.setTRS(cookieNode.getPosition(), cookieNode.getRotation(), Vec3.ONE).invert();
|
|
20730
|
+
_viewProjMat.mul2(cookieCamera.projectionMatrix, _viewMat$1);
|
|
20722
20731
|
const cookieMatrix = light.cookieMatrix;
|
|
20723
20732
|
const rectViewport = light.atlasViewport;
|
|
20724
20733
|
_viewportMatrix.setViewport(rectViewport.x, rectViewport.y, rectViewport.z, rectViewport.w);
|
|
@@ -21666,13 +21675,13 @@ blendModes[BLEND_MAX] = {
|
|
|
21666
21675
|
dst: BLENDMODE_ONE,
|
|
21667
21676
|
op: BLENDEQUATION_MAX
|
|
21668
21677
|
};
|
|
21669
|
-
let id$
|
|
21678
|
+
let id$3 = 0;
|
|
21670
21679
|
class Material {
|
|
21671
21680
|
constructor(){
|
|
21672
21681
|
this.meshInstances = [];
|
|
21673
21682
|
this.name = 'Untitled';
|
|
21674
21683
|
this.userId = '';
|
|
21675
|
-
this.id = id$
|
|
21684
|
+
this.id = id$3++;
|
|
21676
21685
|
this.variants = new Map();
|
|
21677
21686
|
this.defines = new Map();
|
|
21678
21687
|
this._definesDirty = false;
|
|
@@ -22650,7 +22659,6 @@ class WorldClustersAllocator {
|
|
|
22650
22659
|
return this._empty;
|
|
22651
22660
|
}
|
|
22652
22661
|
assign(renderPasses) {
|
|
22653
|
-
const empty = this.empty;
|
|
22654
22662
|
tempClusterArray.push(...this._allocated);
|
|
22655
22663
|
this._allocated.length = 0;
|
|
22656
22664
|
this._clusters.clear();
|
|
@@ -22676,7 +22684,7 @@ class WorldClustersAllocator {
|
|
|
22676
22684
|
ra.lightClusters = clusters;
|
|
22677
22685
|
}
|
|
22678
22686
|
if (!ra.lightClusters) {
|
|
22679
|
-
ra.lightClusters = empty;
|
|
22687
|
+
ra.lightClusters = this.empty;
|
|
22680
22688
|
}
|
|
22681
22689
|
}
|
|
22682
22690
|
}
|
|
@@ -22937,7 +22945,7 @@ const _tempSet = new Set();
|
|
|
22937
22945
|
const _tempMeshInstances = [];
|
|
22938
22946
|
const _tempMeshInstancesSkinned = [];
|
|
22939
22947
|
class Renderer {
|
|
22940
|
-
constructor(graphicsDevice){
|
|
22948
|
+
constructor(graphicsDevice, scene){
|
|
22941
22949
|
this.clustersDebugRendered = false;
|
|
22942
22950
|
this.processingMeshInstances = new Set();
|
|
22943
22951
|
this.lights = [];
|
|
@@ -22945,15 +22953,18 @@ class Renderer {
|
|
|
22945
22953
|
this.cameraDirShadowLights = new Map();
|
|
22946
22954
|
this.dirLightShadows = new Map();
|
|
22947
22955
|
this.blueNoise = new BlueNoise(123);
|
|
22956
|
+
this.gsplatDirector = null;
|
|
22948
22957
|
this.device = graphicsDevice;
|
|
22949
|
-
this.scene =
|
|
22958
|
+
this.scene = scene;
|
|
22950
22959
|
this.worldClustersAllocator = new WorldClustersAllocator(graphicsDevice);
|
|
22951
22960
|
this.lightTextureAtlas = new LightTextureAtlas(graphicsDevice);
|
|
22952
22961
|
this.shadowMapCache = new ShadowMapCache();
|
|
22953
22962
|
this.shadowRenderer = new ShadowRenderer(this, this.lightTextureAtlas);
|
|
22954
22963
|
this._shadowRendererLocal = new ShadowRendererLocal(this, this.shadowRenderer);
|
|
22955
22964
|
this._shadowRendererDirectional = new ShadowRendererDirectional(this, this.shadowRenderer);
|
|
22956
|
-
|
|
22965
|
+
if (this.scene.clusteredLightingEnabled) {
|
|
22966
|
+
this._renderPassUpdateClustered = new RenderPassUpdateClustered(this.device, this, this.shadowRenderer, this._shadowRendererLocal, this.lightTextureAtlas);
|
|
22967
|
+
}
|
|
22957
22968
|
this.viewUniformFormat = null;
|
|
22958
22969
|
this.viewBindGroupFormat = null;
|
|
22959
22970
|
this._skinTime = 0;
|
|
@@ -23011,7 +23022,7 @@ class Renderer {
|
|
|
23011
23022
|
this._shadowRendererDirectional = null;
|
|
23012
23023
|
this.shadowMapCache.destroy();
|
|
23013
23024
|
this.shadowMapCache = null;
|
|
23014
|
-
this._renderPassUpdateClustered
|
|
23025
|
+
this._renderPassUpdateClustered?.destroy();
|
|
23015
23026
|
this._renderPassUpdateClustered = null;
|
|
23016
23027
|
this.lightTextureAtlas.destroy();
|
|
23017
23028
|
this.lightTextureAtlas = null;
|
|
@@ -23828,8 +23839,8 @@ function vogelSpherePrecalculationSamples(numSamples) {
|
|
|
23828
23839
|
return samples;
|
|
23829
23840
|
}
|
|
23830
23841
|
class ForwardRenderer extends Renderer {
|
|
23831
|
-
constructor(graphicsDevice){
|
|
23832
|
-
super(graphicsDevice);
|
|
23842
|
+
constructor(graphicsDevice, scene){
|
|
23843
|
+
super(graphicsDevice, scene);
|
|
23833
23844
|
const device = this.device;
|
|
23834
23845
|
this._forwardDrawCalls = 0;
|
|
23835
23846
|
this._materialSwitches = 0;
|
|
@@ -24423,6 +24434,7 @@ class ForwardRenderer extends Renderer {
|
|
|
24423
24434
|
this.collectLights(comp);
|
|
24424
24435
|
this.beginFrame(comp);
|
|
24425
24436
|
this.setSceneConstants();
|
|
24437
|
+
this.gsplatDirector?.update(comp);
|
|
24426
24438
|
this.cullComposition(comp);
|
|
24427
24439
|
this.gpuUpdate(this.processingMeshInstances);
|
|
24428
24440
|
}
|
|
@@ -24480,6 +24492,8 @@ class Layer {
|
|
|
24480
24492
|
this.requiresLightCube = false;
|
|
24481
24493
|
this.cameras = [];
|
|
24482
24494
|
this.camerasSet = new Set();
|
|
24495
|
+
this.gsplatPlacements = [];
|
|
24496
|
+
this.gsplatPlacementsDirty = true;
|
|
24483
24497
|
this._dirtyComposition = false;
|
|
24484
24498
|
if (options.id !== undefined) {
|
|
24485
24499
|
this.id = options.id;
|
|
@@ -24514,6 +24528,7 @@ class Layer {
|
|
|
24514
24528
|
set enabled(val) {
|
|
24515
24529
|
if (val !== this._enabled) {
|
|
24516
24530
|
this._dirtyComposition = true;
|
|
24531
|
+
this.gsplatPlacementsDirty = true;
|
|
24517
24532
|
this._enabled = val;
|
|
24518
24533
|
if (val) {
|
|
24519
24534
|
this.incrementCounter();
|
|
@@ -24570,6 +24585,19 @@ class Layer {
|
|
|
24570
24585
|
}
|
|
24571
24586
|
this._refCounter--;
|
|
24572
24587
|
}
|
|
24588
|
+
addGSplatPlacement(placement) {
|
|
24589
|
+
if (!this.gsplatPlacements.includes(placement)) {
|
|
24590
|
+
this.gsplatPlacements.push(placement);
|
|
24591
|
+
this.gsplatPlacementsDirty = true;
|
|
24592
|
+
}
|
|
24593
|
+
}
|
|
24594
|
+
removeGSplatPlacement(placement) {
|
|
24595
|
+
const index = this.gsplatPlacements.indexOf(placement);
|
|
24596
|
+
if (index >= 0) {
|
|
24597
|
+
this.gsplatPlacements.splice(index, 1);
|
|
24598
|
+
this.gsplatPlacementsDirty = true;
|
|
24599
|
+
}
|
|
24600
|
+
}
|
|
24573
24601
|
addMeshInstances(meshInstances, skipShadowCasters) {
|
|
24574
24602
|
const destMeshInstances = this.meshInstances;
|
|
24575
24603
|
const destMeshInstancesSet = this.meshInstancesSet;
|
|
@@ -24812,7 +24840,7 @@ const sortPriority = (arr)=>arr.sort(cmpPriority);
|
|
|
24812
24840
|
|
|
24813
24841
|
class LayerComposition extends EventHandler {
|
|
24814
24842
|
constructor(name = 'Untitled'){
|
|
24815
|
-
super(), this.layerList = [], this.layerIdMap = new Map(), this.layerNameMap = new Map(), this.layerOpaqueIndexMap = new Map(), this.layerTransparentIndexMap = new Map(), this.subLayerList = [], this.subLayerEnabled = [], this.cameras = [], this._renderActions = [], this._dirty = false;
|
|
24843
|
+
super(), this.layerList = [], this.layerIdMap = new Map(), this.layerNameMap = new Map(), this.layerOpaqueIndexMap = new Map(), this.layerTransparentIndexMap = new Map(), this.subLayerList = [], this.subLayerEnabled = [], this.cameras = [], this.camerasSet = new Set(), this._renderActions = [], this._dirty = false;
|
|
24816
24844
|
this.name = name;
|
|
24817
24845
|
this._opaqueOrder = {};
|
|
24818
24846
|
this._transparentOrder = {};
|
|
@@ -24840,14 +24868,15 @@ class LayerComposition extends EventHandler {
|
|
|
24840
24868
|
if (this._dirty) {
|
|
24841
24869
|
this._dirty = false;
|
|
24842
24870
|
this.cameras.length = 0;
|
|
24871
|
+
this.camerasSet.clear();
|
|
24843
24872
|
for(let i = 0; i < len; i++){
|
|
24844
24873
|
const layer = this.layerList[i];
|
|
24845
24874
|
layer._dirtyComposition = false;
|
|
24846
24875
|
for(let j = 0; j < layer.cameras.length; j++){
|
|
24847
|
-
const
|
|
24848
|
-
|
|
24849
|
-
|
|
24850
|
-
this.cameras.push(
|
|
24876
|
+
const cameraComponent = layer.cameras[j];
|
|
24877
|
+
if (!this.camerasSet.has(cameraComponent.camera)) {
|
|
24878
|
+
this.camerasSet.add(cameraComponent.camera);
|
|
24879
|
+
this.cameras.push(cameraComponent);
|
|
24851
24880
|
}
|
|
24852
24881
|
}
|
|
24853
24882
|
}
|
|
@@ -25210,7 +25239,7 @@ const channelMap = {
|
|
|
25210
25239
|
'aaa': 0b1000,
|
|
25211
25240
|
'rgb': 0b0111
|
|
25212
25241
|
};
|
|
25213
|
-
let id = 0;
|
|
25242
|
+
let id$2 = 0;
|
|
25214
25243
|
class LightRenderData {
|
|
25215
25244
|
constructor(camera, face, light){
|
|
25216
25245
|
this.light = light;
|
|
@@ -25249,7 +25278,7 @@ class Light {
|
|
|
25249
25278
|
this._evtDeviceRestored = null;
|
|
25250
25279
|
this.device = graphicsDevice;
|
|
25251
25280
|
this.clusteredLighting = clusteredLighting;
|
|
25252
|
-
this.id = id++;
|
|
25281
|
+
this.id = id$2++;
|
|
25253
25282
|
this._evtDeviceRestored = graphicsDevice.on('devicerestored', this.onDeviceRestored, this);
|
|
25254
25283
|
this._type = LIGHTTYPE_DIRECTIONAL;
|
|
25255
25284
|
this._color = new Color(0.8, 0.8, 0.8);
|
|
@@ -26455,13 +26484,11 @@ class Morph extends RefCountedObject {
|
|
|
26455
26484
|
this.targetsTexturePositions = this._createTexture('MorphPositionsTexture', this._textureFormat, targets.length, [
|
|
26456
26485
|
texturesDataPositions
|
|
26457
26486
|
]);
|
|
26458
|
-
this.targetsTexturePositions.upload();
|
|
26459
26487
|
}
|
|
26460
26488
|
if (texturesDataNormals.length > 0) {
|
|
26461
26489
|
this.targetsTextureNormals = this._createTexture('MorphNormalsTexture', this._textureFormat, targets.length, [
|
|
26462
26490
|
texturesDataNormals
|
|
26463
26491
|
]);
|
|
26464
|
-
this.targetsTextureNormals.upload();
|
|
26465
26492
|
}
|
|
26466
26493
|
const formatDesc = [
|
|
26467
26494
|
{
|
|
@@ -27686,7 +27713,7 @@ class ParticleEmitter {
|
|
|
27686
27713
|
if (this.colorMap === null) this.colorMap = this.defaultParamTexture;
|
|
27687
27714
|
this.spawnBounds = this.emitterShape === EMITTERSHAPE_BOX ? this.emitterExtents : this.emitterRadius;
|
|
27688
27715
|
this.useCpu = this.useCpu || this.sort > PARTICLESORT_NONE || gd.maxVertexTextures <= 1 || gd.fragmentUniformsCount < 64 || gd.forceCpuParticles;
|
|
27689
|
-
this._destroyResources();
|
|
27716
|
+
const wasVisible = this._destroyResources();
|
|
27690
27717
|
this.pack8 = (this.pack8 || !gd.textureFloatRenderable) && !this.useCpu;
|
|
27691
27718
|
particleTexHeight = this.useCpu || this.pack8 ? 4 : 2;
|
|
27692
27719
|
this.useMesh = !!this.mesh;
|
|
@@ -27789,7 +27816,6 @@ class ParticleEmitter {
|
|
|
27789
27816
|
mesh.primitive[0].indexed = true;
|
|
27790
27817
|
this.material = this._createMaterial();
|
|
27791
27818
|
this.resetMaterial();
|
|
27792
|
-
const wasVisible = this.meshInstance ? this.meshInstance.visible : true;
|
|
27793
27819
|
this.meshInstance = new MeshInstance(mesh, this.material, this.node);
|
|
27794
27820
|
this.meshInstance.pick = false;
|
|
27795
27821
|
this.meshInstance.updateKey();
|
|
@@ -28249,12 +28275,14 @@ class ParticleEmitter {
|
|
|
28249
28275
|
this.internalTex3 = null;
|
|
28250
28276
|
this.colorParam?.destroy();
|
|
28251
28277
|
this.colorParam = null;
|
|
28252
|
-
this.vertexBuffer?.destroy();
|
|
28253
28278
|
this.vertexBuffer = undefined;
|
|
28254
|
-
this.indexBuffer?.destroy();
|
|
28255
28279
|
this.indexBuffer = undefined;
|
|
28280
|
+
const wasVisible = this.meshInstance?.visible ?? true;
|
|
28281
|
+
this.meshInstance?.destroy();
|
|
28282
|
+
this.meshInstance = null;
|
|
28256
28283
|
this.material?.destroy();
|
|
28257
28284
|
this.material = null;
|
|
28285
|
+
return wasVisible;
|
|
28258
28286
|
}
|
|
28259
28287
|
destroy() {
|
|
28260
28288
|
this.camera = null;
|
|
@@ -33364,29 +33392,232 @@ class GSplatData {
|
|
|
33364
33392
|
}
|
|
33365
33393
|
}
|
|
33366
33394
|
|
|
33395
|
+
var glslGsplatCopyToWorkBufferPS = `
|
|
33396
|
+
#define GSPLAT_CENTER_NOPROJ
|
|
33397
|
+
#include "gsplatStructsVS"
|
|
33398
|
+
#include "gsplatCenterVS"
|
|
33399
|
+
#include "gsplatEvalSHVS"
|
|
33400
|
+
#include "gsplatQuatToMat3VS"
|
|
33401
|
+
#include "gsplatSourceFormatVS"
|
|
33402
|
+
uniform mat4 uTransform;
|
|
33403
|
+
uniform int uStartLine;
|
|
33404
|
+
uniform int uViewportWidth;
|
|
33405
|
+
#ifdef GSPLAT_LOD
|
|
33406
|
+
uniform usampler2D uIntervalsTexture;
|
|
33407
|
+
#endif
|
|
33408
|
+
#ifdef GSPLAT_COLORIZE
|
|
33409
|
+
uniform vec3 uLodColor;
|
|
33410
|
+
#endif
|
|
33411
|
+
uniform int uActiveSplats;
|
|
33412
|
+
void main(void) {
|
|
33413
|
+
ivec2 localFragCoords = ivec2(int(gl_FragCoord.x), int(gl_FragCoord.y) - uStartLine);
|
|
33414
|
+
int targetIndex = localFragCoords.y * uViewportWidth + localFragCoords.x;
|
|
33415
|
+
if (targetIndex >= uActiveSplats) {
|
|
33416
|
+
pcFragColor0 = vec4(0.0);
|
|
33417
|
+
pcFragColor1 = vec4(0.0);
|
|
33418
|
+
pcFragColor2 = vec4(0.0);
|
|
33419
|
+
pcFragColor3 = vec4(0.0);
|
|
33420
|
+
} else {
|
|
33421
|
+
#ifdef GSPLAT_LOD
|
|
33422
|
+
int intervalsSize = int(textureSize(uIntervalsTexture, 0).x);
|
|
33423
|
+
ivec2 intervalUV = ivec2(targetIndex % intervalsSize, targetIndex / intervalsSize);
|
|
33424
|
+
uint originalIndex = texelFetch(uIntervalsTexture, intervalUV, 0).r;
|
|
33425
|
+
#else
|
|
33426
|
+
uint originalIndex = uint(targetIndex);
|
|
33427
|
+
#endif
|
|
33428
|
+
|
|
33429
|
+
#if defined(GSPLAT_SOGS_DATA) || defined(GSPLAT_COMPRESSED_DATA)
|
|
33430
|
+
uint srcSize = uint(textureSize(packedTexture, 0).x);
|
|
33431
|
+
#else
|
|
33432
|
+
uint srcSize = uint(textureSize(splatColor, 0).x);
|
|
33433
|
+
#endif
|
|
33434
|
+
|
|
33435
|
+
SplatSource source;
|
|
33436
|
+
source.id = uint(originalIndex);
|
|
33437
|
+
source.uv = ivec2(source.id % srcSize, source.id / srcSize);
|
|
33438
|
+
vec3 modelCenter = readCenter(source);
|
|
33439
|
+
modelCenter = (uTransform * vec4(modelCenter, 1.0)).xyz;
|
|
33440
|
+
SplatCenter center;
|
|
33441
|
+
initCenter(modelCenter, center);
|
|
33442
|
+
vec3 covA, covB;
|
|
33443
|
+
readCovariance(source, covA, covB);
|
|
33444
|
+
mat3 C = mat3(
|
|
33445
|
+
covA.x, covA.y, covA.z,
|
|
33446
|
+
covA.y, covB.x, covB.y,
|
|
33447
|
+
covA.z, covB.y, covB.z
|
|
33448
|
+
);
|
|
33449
|
+
mat3 linear = mat3(uTransform);
|
|
33450
|
+
mat3 Ct = linear * C * transpose(linear);
|
|
33451
|
+
covA = Ct[0];
|
|
33452
|
+
covB = vec3(Ct[1][1], Ct[1][2], Ct[2][2]);
|
|
33453
|
+
vec4 color = readColor(source);
|
|
33454
|
+
#if SH_BANDS > 0
|
|
33455
|
+
vec3 dir = normalize(center.view * mat3(center.modelView));
|
|
33456
|
+
vec3 sh[SH_COEFFS];
|
|
33457
|
+
float scale;
|
|
33458
|
+
readSHData(source, sh, scale);
|
|
33459
|
+
color.xyz += evalSH(sh, dir) * scale;
|
|
33460
|
+
#endif
|
|
33461
|
+
#ifdef GSPLAT_COLORIZE
|
|
33462
|
+
color.xyz *= uLodColor;
|
|
33463
|
+
#endif
|
|
33464
|
+
pcFragColor0 = color;
|
|
33465
|
+
pcFragColor1 = vec4(modelCenter, 1.0);
|
|
33466
|
+
pcFragColor2 = vec4(covA, 1.0);
|
|
33467
|
+
pcFragColor3 = vec4(covB, 1.0);
|
|
33468
|
+
}
|
|
33469
|
+
}
|
|
33470
|
+
`;
|
|
33471
|
+
|
|
33472
|
+
var wgslGsplatCopyToWorkBufferPS = `
|
|
33473
|
+
#define GSPLAT_CENTER_NOPROJ
|
|
33474
|
+
#include "gsplatStructsVS"
|
|
33475
|
+
#include "gsplatCenterVS"
|
|
33476
|
+
#include "gsplatEvalSHVS"
|
|
33477
|
+
#include "gsplatQuatToMat3VS"
|
|
33478
|
+
#include "gsplatSourceFormatVS"
|
|
33479
|
+
uniform uTransform: mat4x4f;
|
|
33480
|
+
uniform uStartLine: i32;
|
|
33481
|
+
uniform uViewportWidth: i32;
|
|
33482
|
+
#ifdef GSPLAT_LOD
|
|
33483
|
+
var uIntervalsTexture: texture_2d<u32>;
|
|
33484
|
+
#endif
|
|
33485
|
+
#ifdef GSPLAT_COLORIZE
|
|
33486
|
+
uniform uLodColor: vec3f;
|
|
33487
|
+
#endif
|
|
33488
|
+
uniform uActiveSplats: i32;
|
|
33489
|
+
@fragment
|
|
33490
|
+
fn fragmentMain(input: FragmentInput) -> FragmentOutput {
|
|
33491
|
+
var output: FragmentOutput;
|
|
33492
|
+
|
|
33493
|
+
let localFragCoords = vec2i(i32(input.position.x), i32(input.position.y) - uniform.uStartLine);
|
|
33494
|
+
let targetIndex = localFragCoords.y * uniform.uViewportWidth + localFragCoords.x;
|
|
33495
|
+
|
|
33496
|
+
if (targetIndex >= uniform.uActiveSplats) {
|
|
33497
|
+
output.color = vec4f(0.0);
|
|
33498
|
+
output.color1 = vec4f(0.0);
|
|
33499
|
+
output.color2 = vec4f(0.0);
|
|
33500
|
+
output.color3 = vec4f(0.0);
|
|
33501
|
+
} else {
|
|
33502
|
+
#ifdef GSPLAT_LOD
|
|
33503
|
+
let intervalsSize = i32(textureDimensions(uIntervalsTexture, 0).x);
|
|
33504
|
+
let intervalUV = vec2i(targetIndex % intervalsSize, targetIndex / intervalsSize);
|
|
33505
|
+
let originalIndex = textureLoad(uIntervalsTexture, intervalUV, 0).r;
|
|
33506
|
+
#else
|
|
33507
|
+
let originalIndex = targetIndex;
|
|
33508
|
+
#endif
|
|
33509
|
+
|
|
33510
|
+
var srcSize: u32;
|
|
33511
|
+
#if defined(GSPLAT_SOGS_DATA) || defined(GSPLAT_COMPRESSED_DATA)
|
|
33512
|
+
srcSize = u32(textureDimensions(packedTexture, 0).x);
|
|
33513
|
+
#else
|
|
33514
|
+
srcSize = u32(textureDimensions(splatColor, 0).x);
|
|
33515
|
+
#endif
|
|
33516
|
+
|
|
33517
|
+
var source: SplatSource;
|
|
33518
|
+
source.id = u32(originalIndex);
|
|
33519
|
+
source.uv = vec2i(i32(source.id % srcSize), i32(source.id / srcSize));
|
|
33520
|
+
var modelCenter = readCenter(&source);
|
|
33521
|
+
modelCenter = (uniform.uTransform * vec4f(modelCenter, 1.0)).xyz;
|
|
33522
|
+
var center: SplatCenter;
|
|
33523
|
+
initCenter(modelCenter, ¢er);
|
|
33524
|
+
var covA: vec3f;
|
|
33525
|
+
var covB: vec3f;
|
|
33526
|
+
readCovariance(&source, &covA, &covB);
|
|
33527
|
+
let C = mat3x3f(
|
|
33528
|
+
vec3f(covA.x, covA.y, covA.z),
|
|
33529
|
+
vec3f(covA.y, covB.x, covB.y),
|
|
33530
|
+
vec3f(covA.z, covB.y, covB.z)
|
|
33531
|
+
);
|
|
33532
|
+
let linear = mat3x3f(uniform.uTransform[0].xyz, uniform.uTransform[1].xyz, uniform.uTransform[2].xyz);
|
|
33533
|
+
let Ct = linear * C * transpose(linear);
|
|
33534
|
+
covA = Ct[0];
|
|
33535
|
+
covB = vec3f(Ct[1][1], Ct[1][2], Ct[2][2]);
|
|
33536
|
+
var color = readColor(&source);
|
|
33537
|
+
#if SH_BANDS > 0
|
|
33538
|
+
let dir = normalize(center.view * mat3x3f(center.modelView[0].xyz, center.modelView[1].xyz, center.modelView[2].xyz));
|
|
33539
|
+
var sh: array<vec3f, SH_COEFFS>;
|
|
33540
|
+
var scale: f32;
|
|
33541
|
+
readSHData(&source, &sh, &scale);
|
|
33542
|
+
color = vec4f(color.xyz + evalSH(&sh, dir) * scale, color.w);
|
|
33543
|
+
#endif
|
|
33544
|
+
#ifdef GSPLAT_COLORIZE
|
|
33545
|
+
color = vec4f(color.xyz * uniform.uLodColor, color.w);
|
|
33546
|
+
#endif
|
|
33547
|
+
output.color = color;
|
|
33548
|
+
output.color1 = vec4f(modelCenter, 1.0);
|
|
33549
|
+
output.color2 = vec4f(covA, 1.0);
|
|
33550
|
+
output.color3 = vec4f(covB, 1.0);
|
|
33551
|
+
}
|
|
33552
|
+
|
|
33553
|
+
return output;
|
|
33554
|
+
}
|
|
33555
|
+
`;
|
|
33556
|
+
|
|
33557
|
+
let id$1 = 0;
|
|
33558
|
+
const tempMap = new Map();
|
|
33559
|
+
class WorkBufferRenderInfo {
|
|
33560
|
+
constructor(device, key, material){
|
|
33561
|
+
this.device = device;
|
|
33562
|
+
this.material = material;
|
|
33563
|
+
const clonedDefines = new Map(material.defines);
|
|
33564
|
+
const shader = ShaderUtils.createShader(this.device, {
|
|
33565
|
+
uniqueName: `SplatCopyToWorkBuffer:${key}`,
|
|
33566
|
+
attributes: {
|
|
33567
|
+
vertex_position: SEMANTIC_POSITION
|
|
33568
|
+
},
|
|
33569
|
+
vertexDefines: clonedDefines,
|
|
33570
|
+
fragmentDefines: clonedDefines,
|
|
33571
|
+
vertexChunk: 'fullscreenQuadVS',
|
|
33572
|
+
fragmentGLSL: glslGsplatCopyToWorkBufferPS,
|
|
33573
|
+
fragmentWGSL: wgslGsplatCopyToWorkBufferPS
|
|
33574
|
+
});
|
|
33575
|
+
this.quadRender = new QuadRender(shader);
|
|
33576
|
+
}
|
|
33577
|
+
destroy() {
|
|
33578
|
+
this.material?.destroy();
|
|
33579
|
+
this.quadRender?.destroy();
|
|
33580
|
+
}
|
|
33581
|
+
}
|
|
33367
33582
|
class GSplatResourceBase {
|
|
33368
33583
|
constructor(device, gsplatData){
|
|
33584
|
+
this.id = id$1++;
|
|
33585
|
+
this.workBufferRenderInfos = new Map();
|
|
33369
33586
|
this.device = device;
|
|
33370
33587
|
this.gsplatData = gsplatData;
|
|
33371
33588
|
this.centers = new Float32Array(gsplatData.numSplats * 3);
|
|
33372
33589
|
gsplatData.getCenters(this.centers);
|
|
33373
33590
|
this.aabb = new BoundingBox();
|
|
33374
33591
|
gsplatData.calcAabb(this.aabb);
|
|
33375
|
-
|
|
33376
|
-
|
|
33377
|
-
|
|
33378
|
-
|
|
33379
|
-
|
|
33380
|
-
|
|
33381
|
-
|
|
33382
|
-
|
|
33383
|
-
|
|
33384
|
-
|
|
33385
|
-
|
|
33386
|
-
|
|
33387
|
-
|
|
33388
|
-
|
|
33389
|
-
|
|
33592
|
+
this.mesh = GSplatResourceBase.createMesh(device);
|
|
33593
|
+
this.instanceIndices = GSplatResourceBase.createInstanceIndices(device, gsplatData.numSplats);
|
|
33594
|
+
this.mesh.incRefCount();
|
|
33595
|
+
this.mesh.aabb.copy(this.aabb);
|
|
33596
|
+
}
|
|
33597
|
+
destroy() {
|
|
33598
|
+
this.mesh?.destroy();
|
|
33599
|
+
this.instanceIndices?.destroy();
|
|
33600
|
+
this.workBufferRenderInfos.forEach((info)=>info.destroy());
|
|
33601
|
+
this.workBufferRenderInfos.clear();
|
|
33602
|
+
}
|
|
33603
|
+
getWorkBufferRenderInfo(useIntervals, colorizeLod) {
|
|
33604
|
+
this.configureMaterialDefines(tempMap);
|
|
33605
|
+
if (useIntervals) tempMap.set('GSPLAT_LOD', '');
|
|
33606
|
+
if (colorizeLod) tempMap.set('GSPLAT_COLORIZE', '');
|
|
33607
|
+
const key = Array.from(tempMap.entries()).map(([k, v])=>`${k}=${v}`).join(';');
|
|
33608
|
+
let info = this.workBufferRenderInfos.get(key);
|
|
33609
|
+
if (!info) {
|
|
33610
|
+
const material = new ShaderMaterial();
|
|
33611
|
+
this.configureMaterial(material);
|
|
33612
|
+
tempMap.forEach((v, k)=>material.setDefine(k, v));
|
|
33613
|
+
info = new WorkBufferRenderInfo(this.device, key, material);
|
|
33614
|
+
this.workBufferRenderInfos.set(key, info);
|
|
33615
|
+
}
|
|
33616
|
+
tempMap.clear();
|
|
33617
|
+
return info;
|
|
33618
|
+
}
|
|
33619
|
+
static createMesh(device) {
|
|
33620
|
+
const splatInstanceSize = GSplatResourceBase.instanceSize;
|
|
33390
33621
|
const meshPositions = new Float32Array(12 * splatInstanceSize);
|
|
33391
33622
|
const meshIndices = new Uint32Array(6 * splatInstanceSize);
|
|
33392
33623
|
for(let i = 0; i < splatInstanceSize; ++i){
|
|
@@ -33414,28 +33645,42 @@ class GSplatResourceBase {
|
|
|
33414
33645
|
3 + b
|
|
33415
33646
|
], i * 6);
|
|
33416
33647
|
}
|
|
33417
|
-
|
|
33418
|
-
|
|
33419
|
-
|
|
33420
|
-
|
|
33421
|
-
|
|
33422
|
-
|
|
33423
|
-
|
|
33648
|
+
const mesh = new Mesh(device);
|
|
33649
|
+
mesh.setPositions(meshPositions, 3);
|
|
33650
|
+
mesh.setIndices(meshIndices);
|
|
33651
|
+
mesh.update();
|
|
33652
|
+
return mesh;
|
|
33653
|
+
}
|
|
33654
|
+
static createInstanceIndices(device, splatCount) {
|
|
33655
|
+
const splatInstanceSize = GSplatResourceBase.instanceSize;
|
|
33656
|
+
const numSplats = Math.ceil(splatCount / splatInstanceSize) * splatInstanceSize;
|
|
33657
|
+
const numSplatInstances = numSplats / splatInstanceSize;
|
|
33658
|
+
const indexData = new Uint32Array(numSplatInstances);
|
|
33659
|
+
for(let i = 0; i < numSplatInstances; ++i){
|
|
33660
|
+
indexData[i] = i * splatInstanceSize;
|
|
33661
|
+
}
|
|
33662
|
+
const vertexFormat = new VertexFormat(device, [
|
|
33663
|
+
{
|
|
33664
|
+
semantic: SEMANTIC_ATTR13,
|
|
33665
|
+
components: 1,
|
|
33666
|
+
type: TYPE_UINT32,
|
|
33667
|
+
asInt: true
|
|
33668
|
+
}
|
|
33669
|
+
]);
|
|
33670
|
+
const instanceIndices = new VertexBuffer(device, vertexFormat, numSplatInstances, {
|
|
33424
33671
|
usage: BUFFER_STATIC,
|
|
33425
33672
|
data: indexData.buffer
|
|
33426
33673
|
});
|
|
33674
|
+
return instanceIndices;
|
|
33427
33675
|
}
|
|
33428
|
-
|
|
33429
|
-
this.mesh?.destroy();
|
|
33430
|
-
this.instanceIndices?.destroy();
|
|
33431
|
-
}
|
|
33432
|
-
get instanceSize() {
|
|
33676
|
+
static get instanceSize() {
|
|
33433
33677
|
return 128;
|
|
33434
33678
|
}
|
|
33435
33679
|
get numSplats() {
|
|
33436
33680
|
return this.gsplatData.numSplats;
|
|
33437
33681
|
}
|
|
33438
33682
|
configureMaterial(material) {}
|
|
33683
|
+
configureMaterialDefines(defines) {}
|
|
33439
33684
|
evalTextureSize(count) {
|
|
33440
33685
|
return Vec2.ZERO;
|
|
33441
33686
|
}
|
|
@@ -33503,11 +33748,14 @@ class GSplatResource extends GSplatResourceBase {
|
|
|
33503
33748
|
this.sh12to15Texture?.destroy();
|
|
33504
33749
|
super.destroy();
|
|
33505
33750
|
}
|
|
33751
|
+
configureMaterialDefines(defines) {
|
|
33752
|
+
defines.set('SH_BANDS', this.shBands);
|
|
33753
|
+
}
|
|
33506
33754
|
configureMaterial(material) {
|
|
33755
|
+
this.configureMaterialDefines(material.defines);
|
|
33507
33756
|
material.setParameter('splatColor', this.colorTexture);
|
|
33508
33757
|
material.setParameter('transformA', this.transformATexture);
|
|
33509
33758
|
material.setParameter('transformB', this.transformBTexture);
|
|
33510
|
-
material.setDefine('SH_BANDS', this.shBands);
|
|
33511
33759
|
if (this.sh1to3Texture) material.setParameter('splatSH_1to3', this.sh1to3Texture);
|
|
33512
33760
|
if (this.sh4to7Texture) material.setParameter('splatSH_4to7', this.sh4to7Texture);
|
|
33513
33761
|
if (this.sh8to11Texture) material.setParameter('splatSH_8to11', this.sh8to11Texture);
|
|
@@ -33755,7 +34003,7 @@ class CustomRenderPass extends RenderPass {
|
|
|
33755
34003
|
super(...args), this.executeCallback = null;
|
|
33756
34004
|
}
|
|
33757
34005
|
}
|
|
33758
|
-
const invModelMat = new Mat4();
|
|
34006
|
+
const invModelMat$1 = new Mat4();
|
|
33759
34007
|
const dir$1 = new Vec3();
|
|
33760
34008
|
class GSplatResolveSH {
|
|
33761
34009
|
constructor(device, gsplatInstance){
|
|
@@ -33819,8 +34067,8 @@ class GSplatResolveSH {
|
|
|
33819
34067
|
if (updateMode === 'disable') {
|
|
33820
34068
|
return;
|
|
33821
34069
|
}
|
|
33822
|
-
invModelMat.invert(modelMat);
|
|
33823
|
-
invModelMat.transformVector(camera.forward, dir$1);
|
|
34070
|
+
invModelMat$1.invert(modelMat);
|
|
34071
|
+
invModelMat$1.transformVector(camera.forward, dir$1);
|
|
33824
34072
|
dir$1.normalize();
|
|
33825
34073
|
if (updateMode === 'enable' && dir$1.equalsApprox(prevDir, 1e-3)) {
|
|
33826
34074
|
return;
|
|
@@ -34203,79 +34451,215 @@ class GSplatSorter extends EventHandler {
|
|
|
34203
34451
|
}
|
|
34204
34452
|
|
|
34205
34453
|
var glslGsplatSogsReorderPS = `
|
|
34206
|
-
|
|
34207
|
-
|
|
34208
|
-
|
|
34209
|
-
|
|
34210
|
-
|
|
34211
|
-
|
|
34212
|
-
|
|
34213
|
-
|
|
34214
|
-
|
|
34215
|
-
|
|
34216
|
-
|
|
34217
|
-
}
|
|
34218
|
-
|
|
34219
|
-
|
|
34220
|
-
|
|
34221
|
-
|
|
34222
|
-
|
|
34223
|
-
|
|
34224
|
-
|
|
34225
|
-
|
|
34226
|
-
|
|
34227
|
-
|
|
34228
|
-
|
|
34229
|
-
|
|
34230
|
-
|
|
34231
|
-
|
|
34232
|
-
|
|
34233
|
-
vec4(meansLSample, shLabelsSample.x),
|
|
34234
|
-
vec4(meansUSample, shLabelsSample.y),
|
|
34235
|
-
vec4(quatsSample),
|
|
34236
|
-
vec4(scalesSample, 0.0)
|
|
34237
|
-
);
|
|
34454
|
+
#include "gsplatPackingPS"
|
|
34455
|
+
uniform highp sampler2D means_l;
|
|
34456
|
+
uniform highp sampler2D means_u;
|
|
34457
|
+
uniform highp sampler2D quats;
|
|
34458
|
+
uniform highp sampler2D scales;
|
|
34459
|
+
uniform highp sampler2D sh0;
|
|
34460
|
+
uniform highp sampler2D sh_labels;
|
|
34461
|
+
uniform highp uint numSplats;
|
|
34462
|
+
#ifdef REORDER_V1
|
|
34463
|
+
float sigmoid(float x) { return 1.0 / (1.0 + exp(-x)); }
|
|
34464
|
+
vec3 vmin(vec3 v) { return vec3(min(min(v.x, v.y), v.z)); }
|
|
34465
|
+
vec3 vmax(vec3 v) { return vec3(max(max(v.x, v.y), v.z)); }
|
|
34466
|
+
vec3 resolve(vec3 m, vec3 M, vec3 v) { return (mix(m, M, v) - vmin(m)) / (vmax(M) - vmin(m)); }
|
|
34467
|
+
|
|
34468
|
+
uniform vec3 scalesMins;
|
|
34469
|
+
uniform vec3 scalesMaxs;
|
|
34470
|
+
uniform vec4 sh0Mins;
|
|
34471
|
+
uniform vec4 sh0Maxs;
|
|
34472
|
+
#else
|
|
34473
|
+
uniform vec4 scales_codebook[64];
|
|
34474
|
+
uniform vec4 sh0_codebook[64];
|
|
34475
|
+
#endif
|
|
34476
|
+
void main(void) {
|
|
34477
|
+
int w = int(textureSize(means_l, 0).x);
|
|
34478
|
+
ivec2 uv = ivec2(gl_FragCoord.xy);
|
|
34479
|
+
if (uint(uv.x + uv.y * w) >= numSplats) {
|
|
34480
|
+
discard;
|
|
34238
34481
|
}
|
|
34482
|
+
vec3 meansLSample = texelFetch(means_l, uv, 0).xyz;
|
|
34483
|
+
vec3 meansUSample = texelFetch(means_u, uv, 0).xyz;
|
|
34484
|
+
vec4 quatsSample = texelFetch(quats, uv, 0);
|
|
34485
|
+
vec3 scalesSample = texelFetch(scales, uv, 0).xyz;
|
|
34486
|
+
vec4 sh0Sample = texelFetch(sh0, uv, 0);
|
|
34487
|
+
vec2 shLabelsSample = texelFetch(sh_labels, uv, 0).xy;
|
|
34488
|
+
#ifdef REORDER_V1
|
|
34489
|
+
uint scale = pack101010(resolve(scalesMins, scalesMaxs, scalesSample));
|
|
34490
|
+
uint sh0 = pack111110(resolve(sh0Mins.xyz, sh0Maxs.xyz, sh0Sample.xyz));
|
|
34491
|
+
float alpha = sigmoid(mix(sh0Mins.w, sh0Maxs.w, sh0Sample.w));
|
|
34492
|
+
#else
|
|
34493
|
+
uint scale = pack101010(resolveCodebook(scalesSample, scales_codebook));
|
|
34494
|
+
uint sh0 = pack111110(resolveCodebook(sh0Sample.xyz, sh0_codebook));
|
|
34495
|
+
float alpha = sh0Sample.w;
|
|
34496
|
+
#endif
|
|
34497
|
+
uint qmode = uint(quatsSample.w * 255.0) - 252u;
|
|
34498
|
+
pcFragColor0 = uvec4(
|
|
34499
|
+
pack8888(vec4(meansLSample, shLabelsSample.x)),
|
|
34500
|
+
pack8888(vec4(meansUSample, shLabelsSample.y)),
|
|
34501
|
+
pack8888(vec4(quatsSample.xyz, alpha)),
|
|
34502
|
+
(scale << 2u) | qmode
|
|
34503
|
+
);
|
|
34504
|
+
pcFragColor1 = unpack8888(sh0);
|
|
34505
|
+
}
|
|
34239
34506
|
`;
|
|
34240
34507
|
|
|
34241
34508
|
var wgslGsplatSogsReorderPS = `
|
|
34242
|
-
|
|
34243
|
-
|
|
34244
|
-
|
|
34245
|
-
|
|
34246
|
-
|
|
34247
|
-
|
|
34248
|
-
|
|
34249
|
-
|
|
34250
|
-
|
|
34251
|
-
|
|
34252
|
-
|
|
34253
|
-
}
|
|
34254
|
-
fn
|
|
34255
|
-
|
|
34256
|
-
|
|
34257
|
-
|
|
34258
|
-
|
|
34259
|
-
|
|
34260
|
-
|
|
34261
|
-
|
|
34262
|
-
|
|
34263
|
-
|
|
34264
|
-
|
|
34265
|
-
|
|
34266
|
-
|
|
34267
|
-
|
|
34268
|
-
|
|
34269
|
-
|
|
34270
|
-
let shLabelsSample: vec2<f32> = textureLoad(sh_labels, uv, 0).xy;
|
|
34271
|
-
output.color = packUVec32(
|
|
34272
|
-
vec4(meansLSample, shLabelsSample.x),
|
|
34273
|
-
vec4(meansUSample, shLabelsSample.y),
|
|
34274
|
-
vec4(quatsSample),
|
|
34275
|
-
vec4(scalesSample, 0.0)
|
|
34276
|
-
);
|
|
34509
|
+
#include "gsplatPackingPS"
|
|
34510
|
+
var means_l: texture_2d<f32>;
|
|
34511
|
+
var means_u: texture_2d<f32>;
|
|
34512
|
+
var quats: texture_2d<f32>;
|
|
34513
|
+
var scales: texture_2d<f32>;
|
|
34514
|
+
var sh0: texture_2d<f32>;
|
|
34515
|
+
var sh_labels: texture_2d<f32>;
|
|
34516
|
+
uniform numSplats: u32;
|
|
34517
|
+
#ifdef REORDER_V1
|
|
34518
|
+
fn sigmoid(x: f32) -> f32 { return 1.0 / (1.0 + exp(-x)); }
|
|
34519
|
+
fn vmin(v: vec3f) -> vec3f { return vec3f(min(min(v.x, v.y), v.z)); }
|
|
34520
|
+
fn vmax(v: vec3f) -> vec3f { return vec3f(max(max(v.x, v.y), v.z)); }
|
|
34521
|
+
fn resolve(m: vec3f, M: vec3f, v: vec3f) -> vec3f { return (mix(m, M, v) - vmin(m)) / (vmax(M) - vmin(m)); }
|
|
34522
|
+
uniform scalesMins: vec3f;
|
|
34523
|
+
uniform scalesMaxs: vec3f;
|
|
34524
|
+
uniform sh0Mins: vec4f;
|
|
34525
|
+
uniform sh0Maxs: vec4f;
|
|
34526
|
+
#else
|
|
34527
|
+
uniform scales_codebook: array<vec4f, 64>;
|
|
34528
|
+
uniform sh0_codebook: array<vec4f, 64>;
|
|
34529
|
+
#endif
|
|
34530
|
+
@fragment
|
|
34531
|
+
fn fragmentMain(input: FragmentInput) -> FragmentOutput {
|
|
34532
|
+
var output: FragmentOutput;
|
|
34533
|
+
let w: u32 = textureDimensions(means_l, 0).x;
|
|
34534
|
+
let uv: vec2<u32> = vec2<u32>(input.position.xy);
|
|
34535
|
+
if (uv.x + uv.y * w >= uniform.numSplats) {
|
|
34536
|
+
discard;
|
|
34277
34537
|
return output;
|
|
34278
34538
|
}
|
|
34539
|
+
let meansLSample: vec3<f32> = textureLoad(means_l, uv, 0).xyz;
|
|
34540
|
+
let meansUSample: vec3<f32> = textureLoad(means_u, uv, 0).xyz;
|
|
34541
|
+
let quatsSample: vec4<f32> = textureLoad(quats, uv, 0);
|
|
34542
|
+
let scalesSample: vec3<f32> = textureLoad(scales, uv, 0).xyz;
|
|
34543
|
+
let sh0Sample: vec4f = textureLoad(sh0, uv, 0);
|
|
34544
|
+
let shLabelsSample: vec2<f32> = textureLoad(sh_labels, uv, 0).xy;
|
|
34545
|
+
#ifdef REORDER_V1
|
|
34546
|
+
let scale = pack101010(resolve(uniform.scalesMins, uniform.scalesMaxs, scalesSample));
|
|
34547
|
+
let sh0 = pack111110(resolve(uniform.sh0Mins.xyz, uniform.sh0Maxs.xyz, sh0Sample.xyz));
|
|
34548
|
+
let alpha = sigmoid(mix(uniform.sh0Mins.w, uniform.sh0Maxs.w, sh0Sample.w));
|
|
34549
|
+
#else
|
|
34550
|
+
let scale = pack101010(resolveCodebook(scalesSample, &uniform.scales_codebook));
|
|
34551
|
+
let sh0 = pack111110(resolveCodebook(sh0Sample.xyz, &uniform.sh0_codebook));
|
|
34552
|
+
let alpha = sh0Sample.w;
|
|
34553
|
+
#endif
|
|
34554
|
+
let qmode = u32(quatsSample.w * 255.0) - 252u;
|
|
34555
|
+
output.color = vec4u(
|
|
34556
|
+
pack8888(vec4f(meansLSample, shLabelsSample.x)),
|
|
34557
|
+
pack8888(vec4f(meansUSample, shLabelsSample.y)),
|
|
34558
|
+
pack8888(vec4f(quatsSample.xyz, alpha)),
|
|
34559
|
+
(scale << 2u) | qmode
|
|
34560
|
+
);
|
|
34561
|
+
output.color1 = unpack8888(sh0);
|
|
34562
|
+
return output;
|
|
34563
|
+
}
|
|
34564
|
+
`;
|
|
34565
|
+
|
|
34566
|
+
var glslGsplatSogsReorderSh = `
|
|
34567
|
+
#include "gsplatPackingPS"
|
|
34568
|
+
uniform highp sampler2D sh_centroids;
|
|
34569
|
+
uniform vec4 shN_codebook[64];
|
|
34570
|
+
void main(void) {
|
|
34571
|
+
ivec2 uv = ivec2(gl_FragCoord.xy);
|
|
34572
|
+
vec3 shNSample = texelFetch(sh_centroids, uv, 0).xyz;
|
|
34573
|
+
#ifdef REORDER_V1
|
|
34574
|
+
pcFragColor0 = unpack8888(pack111110(shNSample));
|
|
34575
|
+
#else
|
|
34576
|
+
pcFragColor0 = unpack8888(pack111110(resolveCodebook(shNSample, shN_codebook)));
|
|
34577
|
+
#endif
|
|
34578
|
+
}
|
|
34579
|
+
`;
|
|
34580
|
+
|
|
34581
|
+
var gsplatPackingPS$1 = `
|
|
34582
|
+
uint pack8888(vec4 v) {
|
|
34583
|
+
uvec4 t = uvec4(v * 255.0) << uvec4(24u, 16u, 8u, 0u);
|
|
34584
|
+
return t.x | t.y | t.z | t.w;
|
|
34585
|
+
}
|
|
34586
|
+
uint pack101010(vec3 v) {
|
|
34587
|
+
uvec3 t = uvec3(v * 1023.0) << uvec3(20u, 10u, 0u);
|
|
34588
|
+
return t.x | t.y | t.z;
|
|
34589
|
+
}
|
|
34590
|
+
uint pack111110(vec3 v) {
|
|
34591
|
+
uvec3 t = uvec3(v * vec3(2047.0, 2047.0, 1023.0)) << uvec3(21u, 10u, 0u);
|
|
34592
|
+
return t.x | t.y | t.z;
|
|
34593
|
+
}
|
|
34594
|
+
vec4 unpack8888(uint v) {
|
|
34595
|
+
return vec4((uvec4(v) >> uvec4(24u, 16u, 8u, 0u)) & 0xffu) / 255.0;
|
|
34596
|
+
}
|
|
34597
|
+
vec3 unpack101010(uint v) {
|
|
34598
|
+
return vec3((uvec3(v) >> uvec3(20u, 10u, 0u)) & 0x3ffu) / 1023.0;
|
|
34599
|
+
}
|
|
34600
|
+
vec3 unpack111110(uint v) {
|
|
34601
|
+
return vec3((uvec3(v) >> uvec3(21u, 10u, 0u)) & uvec3(0x7ffu, 0x7ffu, 0x3ffu)) / vec3(2047.0, 2047.0, 1023.0);
|
|
34602
|
+
}
|
|
34603
|
+
vec3 resolveCodebook(vec3 s, vec4 codebook[64]) {
|
|
34604
|
+
uvec3 idx = uvec3(s * 255.0);
|
|
34605
|
+
vec3 v = vec3(
|
|
34606
|
+
codebook[idx.x >> 2u][idx.x & 3u],
|
|
34607
|
+
codebook[idx.y >> 2u][idx.y & 3u],
|
|
34608
|
+
codebook[idx.z >> 2u][idx.z & 3u]
|
|
34609
|
+
);
|
|
34610
|
+
return (v - codebook[0].x) / (codebook[63].w - codebook[0].x);
|
|
34611
|
+
}
|
|
34612
|
+
`;
|
|
34613
|
+
|
|
34614
|
+
var wgslGsplatSogsReorderSH = `
|
|
34615
|
+
#include "gsplatPackingPS"
|
|
34616
|
+
var sh_centroids: texture_2d<f32>;
|
|
34617
|
+
uniform shN_codebook: array<vec4f, 64>;
|
|
34618
|
+
@fragment
|
|
34619
|
+
fn fragmentMain(input: FragmentInput) -> FragmentOutput {
|
|
34620
|
+
var output: FragmentOutput;
|
|
34621
|
+
var uv = vec2i(input.position.xy);
|
|
34622
|
+
var shNSample = textureLoad(sh_centroids, uv, 0).xyz;
|
|
34623
|
+
#ifdef REORDER_V1
|
|
34624
|
+
output.color = unpack8888(pack111110(shNSample));
|
|
34625
|
+
#else
|
|
34626
|
+
output.color = unpack8888(pack111110(resolveCodebook(shNSample, &uniform.shN_codebook)));
|
|
34627
|
+
#endif
|
|
34628
|
+
return output;
|
|
34629
|
+
}
|
|
34630
|
+
`;
|
|
34631
|
+
|
|
34632
|
+
var gsplatPackingPS = `
|
|
34633
|
+
fn pack8888(v: vec4f) -> u32 {
|
|
34634
|
+
let t = vec4u(v * 255.0) << vec4u(24u, 16u, 8u, 0u);
|
|
34635
|
+
return t.x | t.y | t.z | t.w;
|
|
34636
|
+
}
|
|
34637
|
+
fn pack101010(v: vec3f) -> u32 {
|
|
34638
|
+
let t = vec3u(v * vec3f(1023.0, 1023.0, 1023.0)) << vec3u(20u, 10u, 0u);
|
|
34639
|
+
return t.x | t.y | t.z;
|
|
34640
|
+
}
|
|
34641
|
+
fn pack111110(v: vec3f) -> u32 {
|
|
34642
|
+
let t = vec3u(v * vec3f(2047.0, 2047.0, 1023.0)) << vec3u(21u, 10u, 0u);
|
|
34643
|
+
return t.x | t.y | t.z;
|
|
34644
|
+
}
|
|
34645
|
+
fn unpack8888(v: u32) -> vec4f {
|
|
34646
|
+
return vec4f((vec4u(v) >> vec4u(24u, 16u, 8u, 0u)) & vec4u(0xffu)) / 255.0;
|
|
34647
|
+
}
|
|
34648
|
+
fn unpack101010(v: u32) -> vec3f {
|
|
34649
|
+
return vec3f((vec3u(v) >> vec3u(20u, 10u, 0u)) & vec3u(0x3ffu)) / 1023.0;
|
|
34650
|
+
}
|
|
34651
|
+
fn unpack111110(v: u32) -> vec3f {
|
|
34652
|
+
return vec3f((vec3u(v) >> vec3u(21u, 10u, 0u)) & vec3u(0x7ffu, 0x7ffu, 0x3ffu)) / vec3f(2047.0, 2047.0, 1023.0);
|
|
34653
|
+
}
|
|
34654
|
+
fn resolveCodebook(s: vec3f, codebook: ptr<uniform, array<vec4f, 64>>) -> vec3f {
|
|
34655
|
+
let idx = vec3u(s * 255.0);
|
|
34656
|
+
let v = vec3f(
|
|
34657
|
+
codebook[idx.x >> 2u][idx.x & 3u],
|
|
34658
|
+
codebook[idx.y >> 2u][idx.y & 3u],
|
|
34659
|
+
codebook[idx.z >> 2u][idx.z & 3u]
|
|
34660
|
+
);
|
|
34661
|
+
return (v - codebook[0].x) / (codebook[63].w - codebook[0].x);
|
|
34662
|
+
}
|
|
34279
34663
|
`;
|
|
34280
34664
|
|
|
34281
34665
|
const SH_C0$1 = 0.28209479177387814;
|
|
@@ -34335,25 +34719,48 @@ class GSplatSogsIterator {
|
|
|
34335
34719
|
}
|
|
34336
34720
|
}
|
|
34337
34721
|
if (s) {
|
|
34338
|
-
|
|
34339
|
-
|
|
34340
|
-
|
|
34341
|
-
|
|
34722
|
+
if (meta.version === 2) {
|
|
34723
|
+
const sx = scales.codebook[scales_data[i * 4 + 0]];
|
|
34724
|
+
const sy = scales.codebook[scales_data[i * 4 + 1]];
|
|
34725
|
+
const sz = scales.codebook[scales_data[i * 4 + 2]];
|
|
34726
|
+
s.set(sx, sy, sz);
|
|
34727
|
+
} else {
|
|
34728
|
+
const sx = lerp(scales.mins[0], scales.maxs[0], scales_data[i * 4 + 0] / 255);
|
|
34729
|
+
const sy = lerp(scales.mins[1], scales.maxs[1], scales_data[i * 4 + 1] / 255);
|
|
34730
|
+
const sz = lerp(scales.mins[2], scales.maxs[2], scales_data[i * 4 + 2] / 255);
|
|
34731
|
+
s.set(sx, sy, sz);
|
|
34732
|
+
}
|
|
34342
34733
|
}
|
|
34343
34734
|
if (c) {
|
|
34344
|
-
|
|
34345
|
-
|
|
34346
|
-
|
|
34347
|
-
|
|
34348
|
-
|
|
34735
|
+
if (meta.version === 2) {
|
|
34736
|
+
const r = sh0.codebook[sh0_data[i * 4 + 0]];
|
|
34737
|
+
const g = sh0.codebook[sh0_data[i * 4 + 1]];
|
|
34738
|
+
const b = sh0.codebook[sh0_data[i * 4 + 2]];
|
|
34739
|
+
const a = sh0_data[i * 4 + 3] / 255;
|
|
34740
|
+
c.set(0.5 + r * SH_C0$1, 0.5 + g * SH_C0$1, 0.5 + b * SH_C0$1, a);
|
|
34741
|
+
} else {
|
|
34742
|
+
const r = lerp(sh0.mins[0], sh0.maxs[0], sh0_data[i * 4 + 0] / 255);
|
|
34743
|
+
const g = lerp(sh0.mins[1], sh0.maxs[1], sh0_data[i * 4 + 1] / 255);
|
|
34744
|
+
const b = lerp(sh0.mins[2], sh0.maxs[2], sh0_data[i * 4 + 2] / 255);
|
|
34745
|
+
const a = lerp(sh0.mins[3], sh0.maxs[3], sh0_data[i * 4 + 3] / 255);
|
|
34746
|
+
c.set(0.5 + r * SH_C0$1, 0.5 + g * SH_C0$1, 0.5 + b * SH_C0$1, 1.0 / (1.0 + Math.exp(-a)));
|
|
34747
|
+
}
|
|
34349
34748
|
}
|
|
34350
34749
|
if (sh) {
|
|
34351
34750
|
const n = sh_labels_data[i * 4 + 0] + (sh_labels_data[i * 4 + 1] << 8);
|
|
34352
34751
|
const u = n % 64 * 15;
|
|
34353
34752
|
const v = Math.floor(n / 64);
|
|
34354
|
-
|
|
34355
|
-
for(let
|
|
34356
|
-
|
|
34753
|
+
if (meta.version === 2) {
|
|
34754
|
+
for(let j = 0; j < 3; ++j){
|
|
34755
|
+
for(let k = 0; k < 15; ++k){
|
|
34756
|
+
sh[j * 15 + k] = shN.codebook[sh_centroids_data[(u + k) * 4 + j + v * data.sh_centroids.width * 4]];
|
|
34757
|
+
}
|
|
34758
|
+
}
|
|
34759
|
+
} else {
|
|
34760
|
+
for(let j = 0; j < 3; ++j){
|
|
34761
|
+
for(let k = 0; k < 15; ++k){
|
|
34762
|
+
sh[j * 15 + k] = lerp(shN.mins, shN.maxs, sh_centroids_data[(u + k) * 4 + j + v * data.sh_centroids.width * 4] / 255);
|
|
34763
|
+
}
|
|
34357
34764
|
}
|
|
34358
34765
|
}
|
|
34359
34766
|
}
|
|
@@ -34370,6 +34777,8 @@ class GSplatSogsData {
|
|
|
34370
34777
|
this.sh_centroids?.destroy();
|
|
34371
34778
|
this.sh_labels?.destroy();
|
|
34372
34779
|
this.packedTexture?.destroy();
|
|
34780
|
+
this.packedSh0?.destroy();
|
|
34781
|
+
this.packedShN?.destroy();
|
|
34373
34782
|
}
|
|
34374
34783
|
createIter(p, r, s, c, sh) {
|
|
34375
34784
|
return new GSplatSogsIterator(this, p, r, s, c, sh);
|
|
@@ -34504,11 +34913,12 @@ class GSplatSogsData {
|
|
|
34504
34913
|
]);
|
|
34505
34914
|
}
|
|
34506
34915
|
packGpuMemory() {
|
|
34507
|
-
const { means_l, means_u, quats, scales, sh_labels, numSplats } = this;
|
|
34916
|
+
const { meta, means_l, means_u, quats, scales, sh0, sh_labels, numSplats } = this;
|
|
34508
34917
|
const { device } = means_l;
|
|
34509
34918
|
const { scope } = device;
|
|
34919
|
+
const shaderKey = meta.version === 2 ? 'v2' : 'v1';
|
|
34510
34920
|
const shader = ShaderUtils.createShader(device, {
|
|
34511
|
-
uniqueName:
|
|
34921
|
+
uniqueName: `GsplatSogsReorderShader-${shaderKey}`,
|
|
34512
34922
|
attributes: {
|
|
34513
34923
|
vertex_position: SEMANTIC_POSITION
|
|
34514
34924
|
},
|
|
@@ -34516,11 +34926,27 @@ class GSplatSogsData {
|
|
|
34516
34926
|
fragmentGLSL: glslGsplatSogsReorderPS,
|
|
34517
34927
|
fragmentWGSL: wgslGsplatSogsReorderPS,
|
|
34518
34928
|
fragmentOutputTypes: [
|
|
34519
|
-
'uvec4'
|
|
34520
|
-
|
|
34929
|
+
'uvec4',
|
|
34930
|
+
'vec4'
|
|
34931
|
+
],
|
|
34932
|
+
fragmentIncludes: new Map([
|
|
34933
|
+
[
|
|
34934
|
+
'gsplatPackingPS',
|
|
34935
|
+
device.isWebGPU ? gsplatPackingPS : gsplatPackingPS$1
|
|
34936
|
+
]
|
|
34937
|
+
]),
|
|
34938
|
+
fragmentDefines: meta.version === 2 ? undefined : new Map([
|
|
34939
|
+
[
|
|
34940
|
+
'REORDER_V1',
|
|
34941
|
+
'1'
|
|
34942
|
+
]
|
|
34943
|
+
])
|
|
34521
34944
|
});
|
|
34522
34945
|
const renderTarget = new RenderTarget({
|
|
34523
|
-
|
|
34946
|
+
colorBuffers: [
|
|
34947
|
+
this.packedTexture,
|
|
34948
|
+
this.packedSh0
|
|
34949
|
+
],
|
|
34524
34950
|
depth: false,
|
|
34525
34951
|
mipLevel: 0
|
|
34526
34952
|
});
|
|
@@ -34532,12 +34958,59 @@ class GSplatSogsData {
|
|
|
34532
34958
|
means_u,
|
|
34533
34959
|
quats,
|
|
34534
34960
|
scales,
|
|
34961
|
+
sh0,
|
|
34535
34962
|
sh_labels: sh_labels ?? means_l,
|
|
34536
|
-
numSplats
|
|
34963
|
+
numSplats,
|
|
34964
|
+
'scales_codebook[0]': this.meta.scales.codebook,
|
|
34965
|
+
'sh0_codebook[0]': this.meta.sh0.codebook,
|
|
34966
|
+
scalesMins: meta.scales.mins,
|
|
34967
|
+
scalesMaxs: meta.scales.maxs,
|
|
34968
|
+
sh0Mins: meta.sh0.mins,
|
|
34969
|
+
sh0Maxs: meta.sh0.maxs
|
|
34970
|
+
});
|
|
34971
|
+
drawQuadWithShader(device, renderTarget, shader);
|
|
34972
|
+
renderTarget.destroy();
|
|
34973
|
+
}
|
|
34974
|
+
packShMemory() {
|
|
34975
|
+
const { meta, sh_centroids } = this;
|
|
34976
|
+
const { device } = sh_centroids;
|
|
34977
|
+
const { scope } = device;
|
|
34978
|
+
const shaderKey = meta.version === 2 ? 'v2' : 'v1';
|
|
34979
|
+
const shader = ShaderUtils.createShader(device, {
|
|
34980
|
+
uniqueName: `GsplatSogsReorderShShader-${shaderKey}`,
|
|
34981
|
+
attributes: {
|
|
34982
|
+
vertex_position: SEMANTIC_POSITION
|
|
34983
|
+
},
|
|
34984
|
+
vertexChunk: 'fullscreenQuadVS',
|
|
34985
|
+
fragmentGLSL: glslGsplatSogsReorderSh,
|
|
34986
|
+
fragmentWGSL: wgslGsplatSogsReorderSH,
|
|
34987
|
+
fragmentIncludes: new Map([
|
|
34988
|
+
[
|
|
34989
|
+
'gsplatPackingPS',
|
|
34990
|
+
device.isWebGPU ? gsplatPackingPS : gsplatPackingPS$1
|
|
34991
|
+
]
|
|
34992
|
+
]),
|
|
34993
|
+
fragmentDefines: meta.version === 2 ? undefined : new Map([
|
|
34994
|
+
[
|
|
34995
|
+
'REORDER_V1',
|
|
34996
|
+
'1'
|
|
34997
|
+
]
|
|
34998
|
+
])
|
|
34999
|
+
});
|
|
35000
|
+
const renderTarget = new RenderTarget({
|
|
35001
|
+
colorBuffer: this.packedShN,
|
|
35002
|
+
depth: false,
|
|
35003
|
+
mipLevel: 0
|
|
35004
|
+
});
|
|
35005
|
+
device.setCullMode(CULLFACE_NONE);
|
|
35006
|
+
device.setBlendState(BlendState.NOBLEND);
|
|
35007
|
+
device.setDepthState(DepthState.NODEPTH);
|
|
35008
|
+
resolve(scope, {
|
|
35009
|
+
sh_centroids,
|
|
35010
|
+
'shN_codebook[0]': this.meta.shN.codebook
|
|
34537
35011
|
});
|
|
34538
35012
|
drawQuadWithShader(device, renderTarget, shader);
|
|
34539
35013
|
renderTarget.destroy();
|
|
34540
|
-
shader.destroy();
|
|
34541
35014
|
}
|
|
34542
35015
|
async prepareGpuData() {
|
|
34543
35016
|
const { device, height, width } = this.means_l;
|
|
@@ -34545,15 +35018,35 @@ class GSplatSogsData {
|
|
|
34545
35018
|
this.means_u._levels[0] = await readImageDataAsync(this.means_u);
|
|
34546
35019
|
this.packedTexture = new Texture(device, {
|
|
34547
35020
|
name: 'sogsPackedTexture',
|
|
34548
|
-
width
|
|
34549
|
-
height
|
|
35021
|
+
width,
|
|
35022
|
+
height,
|
|
34550
35023
|
format: PIXELFORMAT_RGBA32U,
|
|
34551
35024
|
mipmaps: false
|
|
34552
35025
|
});
|
|
35026
|
+
this.packedSh0 = new Texture(device, {
|
|
35027
|
+
name: 'sogsPackedSh0',
|
|
35028
|
+
width,
|
|
35029
|
+
height,
|
|
35030
|
+
format: PIXELFORMAT_RGBA8,
|
|
35031
|
+
mipmaps: false
|
|
35032
|
+
});
|
|
35033
|
+
this.packedShN = this.sh_centroids && new Texture(device, {
|
|
35034
|
+
name: 'sogsPackedShN',
|
|
35035
|
+
width: this.sh_centroids.width,
|
|
35036
|
+
height: this.sh_centroids.height,
|
|
35037
|
+
format: PIXELFORMAT_RGBA8,
|
|
35038
|
+
mipmaps: false
|
|
35039
|
+
});
|
|
34553
35040
|
device.on('devicerestored', ()=>{
|
|
34554
35041
|
this.packGpuMemory();
|
|
35042
|
+
if (this.packedShN) {
|
|
35043
|
+
this.packShMemory();
|
|
35044
|
+
}
|
|
34555
35045
|
});
|
|
34556
35046
|
this.packGpuMemory();
|
|
35047
|
+
if (this.packedShN) {
|
|
35048
|
+
this.packShMemory();
|
|
35049
|
+
}
|
|
34557
35050
|
}
|
|
34558
35051
|
reorderData() {
|
|
34559
35052
|
return this.prepareGpuData();
|
|
@@ -34561,8 +35054,8 @@ class GSplatSogsData {
|
|
|
34561
35054
|
}
|
|
34562
35055
|
|
|
34563
35056
|
const mat = new Mat4();
|
|
34564
|
-
const cameraPosition = new Vec3();
|
|
34565
|
-
const cameraDirection = new Vec3();
|
|
35057
|
+
const cameraPosition$1 = new Vec3();
|
|
35058
|
+
const cameraDirection$1 = new Vec3();
|
|
34566
35059
|
const viewport = [
|
|
34567
35060
|
0,
|
|
34568
35061
|
0
|
|
@@ -34604,7 +35097,7 @@ class GSplatInstance {
|
|
|
34604
35097
|
this.sorter = new GSplatSorter();
|
|
34605
35098
|
this.sorter.init(this.orderTexture, centers, chunks);
|
|
34606
35099
|
this.sorter.on('updated', (count)=>{
|
|
34607
|
-
this.meshInstance.instancingCount = Math.ceil(count /
|
|
35100
|
+
this.meshInstance.instancingCount = Math.ceil(count / GSplatResourceBase.instanceSize);
|
|
34608
35101
|
this.material.setParameter('numSplats', count);
|
|
34609
35102
|
});
|
|
34610
35103
|
this.setHighQualitySH(options.highQualitySH ?? false);
|
|
@@ -34652,16 +35145,16 @@ class GSplatInstance {
|
|
|
34652
35145
|
sort(cameraNode) {
|
|
34653
35146
|
if (this.sorter) {
|
|
34654
35147
|
const cameraMat = cameraNode.getWorldTransform();
|
|
34655
|
-
cameraMat.getTranslation(cameraPosition);
|
|
34656
|
-
cameraMat.getZ(cameraDirection);
|
|
35148
|
+
cameraMat.getTranslation(cameraPosition$1);
|
|
35149
|
+
cameraMat.getZ(cameraDirection$1);
|
|
34657
35150
|
const modelMat = this.meshInstance.node.getWorldTransform();
|
|
34658
35151
|
const invModelMat = mat.invert(modelMat);
|
|
34659
|
-
invModelMat.transformPoint(cameraPosition, cameraPosition);
|
|
34660
|
-
invModelMat.transformVector(cameraDirection, cameraDirection);
|
|
34661
|
-
if (!cameraPosition.equalsApprox(this.lastCameraPosition) || !cameraDirection.equalsApprox(this.lastCameraDirection)) {
|
|
34662
|
-
this.lastCameraPosition.copy(cameraPosition);
|
|
34663
|
-
this.lastCameraDirection.copy(cameraDirection);
|
|
34664
|
-
this.sorter.setCamera(cameraPosition, cameraDirection);
|
|
35152
|
+
invModelMat.transformPoint(cameraPosition$1, cameraPosition$1);
|
|
35153
|
+
invModelMat.transformVector(cameraDirection$1, cameraDirection$1);
|
|
35154
|
+
if (!cameraPosition$1.equalsApprox(this.lastCameraPosition) || !cameraDirection$1.equalsApprox(this.lastCameraDirection)) {
|
|
35155
|
+
this.lastCameraPosition.copy(cameraPosition$1);
|
|
35156
|
+
this.lastCameraDirection.copy(cameraDirection$1);
|
|
35157
|
+
this.sorter.setCamera(cameraPosition$1, cameraDirection$1);
|
|
34665
35158
|
}
|
|
34666
35159
|
}
|
|
34667
35160
|
this.updateViewport(cameraNode);
|
|
@@ -34693,31 +35186,65 @@ class GSplatSogsResource extends GSplatResourceBase {
|
|
|
34693
35186
|
this.gsplatData.destroy();
|
|
34694
35187
|
super.destroy();
|
|
34695
35188
|
}
|
|
35189
|
+
configureMaterialDefines(defines) {
|
|
35190
|
+
defines.set('GSPLAT_SOGS_DATA', true);
|
|
35191
|
+
defines.set('SH_BANDS', this.gsplatData.shBands);
|
|
35192
|
+
}
|
|
34696
35193
|
configureMaterial(material) {
|
|
34697
35194
|
const { gsplatData } = this;
|
|
34698
|
-
|
|
34699
|
-
|
|
35195
|
+
const { meta } = gsplatData;
|
|
35196
|
+
this.configureMaterialDefines(material.defines);
|
|
34700
35197
|
[
|
|
34701
35198
|
'packedTexture',
|
|
34702
|
-
'
|
|
34703
|
-
'
|
|
35199
|
+
'packedSh0',
|
|
35200
|
+
'packedShN'
|
|
34704
35201
|
].forEach((name)=>{
|
|
34705
35202
|
if (gsplatData[name]) {
|
|
34706
35203
|
material.setParameter(name, gsplatData[name]);
|
|
34707
35204
|
}
|
|
34708
35205
|
});
|
|
34709
35206
|
[
|
|
34710
|
-
'means'
|
|
34711
|
-
'scales',
|
|
34712
|
-
'sh0',
|
|
34713
|
-
'shN'
|
|
35207
|
+
'means'
|
|
34714
35208
|
].forEach((name)=>{
|
|
34715
|
-
const v =
|
|
35209
|
+
const v = meta[name];
|
|
34716
35210
|
if (v) {
|
|
34717
35211
|
material.setParameter(`${name}_mins`, v.mins);
|
|
34718
35212
|
material.setParameter(`${name}_maxs`, v.maxs);
|
|
34719
35213
|
}
|
|
34720
35214
|
});
|
|
35215
|
+
if (meta.version === 2) {
|
|
35216
|
+
[
|
|
35217
|
+
'scales',
|
|
35218
|
+
'sh0',
|
|
35219
|
+
'shN'
|
|
35220
|
+
].forEach((name)=>{
|
|
35221
|
+
const v = meta[name];
|
|
35222
|
+
if (v) {
|
|
35223
|
+
material.setParameter(`${name}_mins`, v.codebook[0]);
|
|
35224
|
+
material.setParameter(`${name}_maxs`, v.codebook[255]);
|
|
35225
|
+
}
|
|
35226
|
+
});
|
|
35227
|
+
} else {
|
|
35228
|
+
[
|
|
35229
|
+
'scales',
|
|
35230
|
+
'sh0'
|
|
35231
|
+
].forEach((name)=>{
|
|
35232
|
+
const v = meta[name];
|
|
35233
|
+
if (v) {
|
|
35234
|
+
material.setParameter(`${name}_mins`, Math.min(...v.mins.slice(0, 3)));
|
|
35235
|
+
material.setParameter(`${name}_maxs`, Math.max(...v.maxs.slice(0, 3)));
|
|
35236
|
+
}
|
|
35237
|
+
});
|
|
35238
|
+
[
|
|
35239
|
+
'shN'
|
|
35240
|
+
].forEach((name)=>{
|
|
35241
|
+
const v = meta[name];
|
|
35242
|
+
if (v) {
|
|
35243
|
+
material.setParameter(`${name}_mins`, v.mins);
|
|
35244
|
+
material.setParameter(`${name}_maxs`, v.maxs);
|
|
35245
|
+
}
|
|
35246
|
+
});
|
|
35247
|
+
}
|
|
34721
35248
|
}
|
|
34722
35249
|
evalTextureSize(count) {
|
|
34723
35250
|
return new Vec2(this.gsplatData.means_l.width, this.gsplatData.means_l.height);
|
|
@@ -35329,7 +35856,8 @@ class Asset extends EventHandler {
|
|
|
35329
35856
|
cache: true,
|
|
35330
35857
|
responseType: 'arraybuffer',
|
|
35331
35858
|
retry: maxRetries > 0,
|
|
35332
|
-
maxRetries: maxRetries
|
|
35859
|
+
maxRetries: maxRetries,
|
|
35860
|
+
progress: asset
|
|
35333
35861
|
}, callback);
|
|
35334
35862
|
}
|
|
35335
35863
|
}
|
|
@@ -38634,22 +39162,26 @@ void getGlossiness() {
|
|
|
38634
39162
|
var gsplatCenterVS$1 = `
|
|
38635
39163
|
uniform mat4 matrix_model;
|
|
38636
39164
|
uniform mat4 matrix_view;
|
|
38637
|
-
|
|
39165
|
+
#ifndef GSPLAT_CENTER_NOPROJ
|
|
39166
|
+
uniform mat4 matrix_projection;
|
|
39167
|
+
#endif
|
|
38638
39168
|
bool initCenter(vec3 modelCenter, out SplatCenter center) {
|
|
38639
39169
|
mat4 modelView = matrix_view * matrix_model;
|
|
38640
39170
|
vec4 centerView = modelView * vec4(modelCenter, 1.0);
|
|
38641
|
-
|
|
38642
|
-
|
|
38643
|
-
|
|
38644
|
-
|
|
38645
|
-
|
|
38646
|
-
|
|
38647
|
-
|
|
38648
|
-
|
|
39171
|
+
#ifndef GSPLAT_CENTER_NOPROJ
|
|
39172
|
+
if (centerView.z > 0.0) {
|
|
39173
|
+
return false;
|
|
39174
|
+
}
|
|
39175
|
+
vec4 centerProj = matrix_projection * centerView;
|
|
39176
|
+
#if WEBGPU
|
|
39177
|
+
centerProj.z = clamp(centerProj.z, 0, abs(centerProj.w));
|
|
39178
|
+
#else
|
|
39179
|
+
centerProj.z = clamp(centerProj.z, -abs(centerProj.w), abs(centerProj.w));
|
|
39180
|
+
#endif
|
|
39181
|
+
center.proj = centerProj;
|
|
39182
|
+
center.projMat00 = matrix_projection[0][0];
|
|
38649
39183
|
#endif
|
|
38650
39184
|
center.view = centerView.xyz / centerView.w;
|
|
38651
|
-
center.proj = centerProj;
|
|
38652
|
-
center.projMat00 = matrix_projection[0][0];
|
|
38653
39185
|
center.modelView = modelView;
|
|
38654
39186
|
return true;
|
|
38655
39187
|
}
|
|
@@ -38663,47 +39195,10 @@ vec4 readColor(in SplatSource source) {
|
|
|
38663
39195
|
`;
|
|
38664
39196
|
|
|
38665
39197
|
var gsplatCommonVS$1 = `
|
|
38666
|
-
|
|
38667
|
-
uint order;
|
|
38668
|
-
uint id;
|
|
38669
|
-
ivec2 uv;
|
|
38670
|
-
vec2 cornerUV;
|
|
38671
|
-
};
|
|
38672
|
-
struct SplatCenter {
|
|
38673
|
-
vec3 view;
|
|
38674
|
-
vec4 proj;
|
|
38675
|
-
mat4 modelView;
|
|
38676
|
-
float projMat00;
|
|
38677
|
-
};
|
|
38678
|
-
struct SplatCorner {
|
|
38679
|
-
vec2 offset;
|
|
38680
|
-
vec2 uv;
|
|
38681
|
-
#if GSPLAT_AA
|
|
38682
|
-
float aaFactor;
|
|
38683
|
-
#endif
|
|
38684
|
-
vec2 v;
|
|
38685
|
-
float dlen;
|
|
38686
|
-
};
|
|
39198
|
+
#include "gsplatStructsVS"
|
|
38687
39199
|
#include "gsplatEvalSHVS"
|
|
38688
39200
|
#include "gsplatQuatToMat3VS"
|
|
38689
|
-
#
|
|
38690
|
-
#include "gsplatCompressedDataVS"
|
|
38691
|
-
#if SH_COEFFS > 0
|
|
38692
|
-
#include "gsplatCompressedSHVS"
|
|
38693
|
-
#endif
|
|
38694
|
-
#elif GSPLAT_SOGS_DATA == true
|
|
38695
|
-
#include "gsplatSogsDataVS"
|
|
38696
|
-
#include "gsplatSogsColorVS"
|
|
38697
|
-
#if SH_COEFFS > 0
|
|
38698
|
-
#include "gsplatSogsSHVS"
|
|
38699
|
-
#endif
|
|
38700
|
-
#else
|
|
38701
|
-
#include "gsplatDataVS"
|
|
38702
|
-
#include "gsplatColorVS"
|
|
38703
|
-
#if SH_COEFFS > 0
|
|
38704
|
-
#include "gsplatSHVS"
|
|
38705
|
-
#endif
|
|
38706
|
-
#endif
|
|
39201
|
+
#include "gsplatSourceFormatVS"
|
|
38707
39202
|
#include "gsplatSourceVS"
|
|
38708
39203
|
#include "gsplatCenterVS"
|
|
38709
39204
|
#include "gsplatCornerVS"
|
|
@@ -38914,51 +39409,45 @@ mat3 quatToMat3(vec4 R) {
|
|
|
38914
39409
|
`;
|
|
38915
39410
|
|
|
38916
39411
|
var gsplatSogsColorVS$1 = `
|
|
38917
|
-
uniform
|
|
38918
|
-
uniform
|
|
38919
|
-
uniform
|
|
39412
|
+
uniform highp sampler2D packedSh0;
|
|
39413
|
+
uniform float sh0_mins;
|
|
39414
|
+
uniform float sh0_maxs;
|
|
38920
39415
|
float SH_C0 = 0.28209479177387814;
|
|
38921
39416
|
vec4 readColor(in SplatSource source) {
|
|
38922
|
-
|
|
38923
|
-
|
|
39417
|
+
vec3 clr = mix(vec3(sh0_mins), vec3(sh0_maxs), unpack111110(pack8888(texelFetch(packedSh0, source.uv, 0))));
|
|
39418
|
+
float alpha = float(packedSample.z & 0xffu) / 255.0;
|
|
39419
|
+
return vec4(vec3(0.5) + clr.xyz * SH_C0, alpha);
|
|
38924
39420
|
}
|
|
38925
39421
|
`;
|
|
38926
39422
|
|
|
38927
39423
|
var gsplatSogsDataVS$1 = `
|
|
39424
|
+
#include "gsplatPackingPS"
|
|
38928
39425
|
uniform highp usampler2D packedTexture;
|
|
38929
39426
|
uniform vec3 means_mins;
|
|
38930
39427
|
uniform vec3 means_maxs;
|
|
38931
|
-
uniform
|
|
38932
|
-
uniform
|
|
38933
|
-
vec4 unpackU32(uint v) {
|
|
38934
|
-
return vec4(
|
|
38935
|
-
float((v >> 24u) & 0xFFu) / 255.0,
|
|
38936
|
-
float((v >> 16u) & 0xFFu) / 255.0,
|
|
38937
|
-
float((v >> 8u) & 0xFFu) / 255.0,
|
|
38938
|
-
float(v & 0xFFu) / 255.0
|
|
38939
|
-
);
|
|
38940
|
-
}
|
|
39428
|
+
uniform float scales_mins;
|
|
39429
|
+
uniform float scales_maxs;
|
|
38941
39430
|
uvec4 packedSample;
|
|
38942
39431
|
vec3 readCenter(SplatSource source) {
|
|
38943
39432
|
packedSample = texelFetch(packedTexture, source.uv, 0);
|
|
38944
|
-
vec3 l =
|
|
38945
|
-
vec3 u =
|
|
39433
|
+
vec3 l = unpack8888(packedSample.x).xyz;
|
|
39434
|
+
vec3 u = unpack8888(packedSample.y).xyz;
|
|
38946
39435
|
vec3 n = (l * 255.0 + u * 255.0 * 256.0) / 65535.0;
|
|
38947
39436
|
vec3 v = mix(means_mins, means_maxs, n);
|
|
38948
39437
|
return sign(v) * (exp(abs(v)) - 1.0);
|
|
38949
39438
|
}
|
|
38950
39439
|
const float norm = 2.0 / sqrt(2.0);
|
|
38951
39440
|
void readCovariance(in SplatSource source, out vec3 covA, out vec3 covB) {
|
|
38952
|
-
|
|
38953
|
-
vec3 sdata =
|
|
38954
|
-
|
|
39441
|
+
vec3 qdata = unpack8888(packedSample.z).xyz;
|
|
39442
|
+
vec3 sdata = unpack101010(packedSample.w >> 2u);
|
|
39443
|
+
uint qmode = packedSample.w & 0x3u;
|
|
39444
|
+
vec3 abc = (qdata - 0.5) * norm;
|
|
38955
39445
|
float d = sqrt(max(0.0, 1.0 - dot(abc, abc)));
|
|
38956
|
-
|
|
38957
|
-
|
|
38958
|
-
((
|
|
38959
|
-
((mode == 2u) ? vec4(abc.xy, d, abc.z) : vec4(abc, d)));
|
|
39446
|
+
vec4 quat = (qmode == 0u) ? vec4(d, abc) :
|
|
39447
|
+
((qmode == 1u) ? vec4(abc.x, d, abc.yz) :
|
|
39448
|
+
((qmode == 2u) ? vec4(abc.xy, d, abc.z) : vec4(abc, d)));
|
|
38960
39449
|
mat3 rot = quatToMat3(quat);
|
|
38961
|
-
vec3 scale = exp(mix(scales_mins, scales_maxs, sdata));
|
|
39450
|
+
vec3 scale = exp(mix(vec3(scales_mins), vec3(scales_maxs), sdata));
|
|
38962
39451
|
mat3 M = transpose(mat3(
|
|
38963
39452
|
scale.x * rot[0],
|
|
38964
39453
|
scale.y * rot[1],
|
|
@@ -38970,27 +39459,72 @@ void readCovariance(in SplatSource source, out vec3 covA, out vec3 covB) {
|
|
|
38970
39459
|
`;
|
|
38971
39460
|
|
|
38972
39461
|
var gsplatSogsSHVS$1 = `
|
|
38973
|
-
uniform highp sampler2D
|
|
39462
|
+
uniform highp sampler2D packedShN;
|
|
38974
39463
|
uniform float shN_mins;
|
|
38975
39464
|
uniform float shN_maxs;
|
|
38976
39465
|
void readSHData(in SplatSource source, out vec3 sh[SH_COEFFS], out float scale) {
|
|
38977
|
-
ivec2 t = ivec2(packedSample.
|
|
39466
|
+
ivec2 t = ivec2(packedSample.xy & 255u);
|
|
38978
39467
|
int n = t.x + t.y * 256;
|
|
38979
39468
|
int u = (n % 64) * SH_COEFFS;
|
|
38980
39469
|
int v = n / 64;
|
|
38981
39470
|
for (int i = 0; i < SH_COEFFS; i++) {
|
|
38982
|
-
sh[i] = mix(vec3(shN_mins), vec3(shN_maxs), texelFetch(
|
|
39471
|
+
sh[i] = mix(vec3(shN_mins), vec3(shN_maxs), unpack111110(pack8888(texelFetch(packedShN, ivec2(u + i, v), 0))));
|
|
38983
39472
|
}
|
|
38984
39473
|
scale = 1.0;
|
|
38985
39474
|
}
|
|
38986
39475
|
`;
|
|
38987
39476
|
|
|
39477
|
+
var gsplatSourceFormatVS$1 = `
|
|
39478
|
+
#if defined(GSPLAT_WORKBUFFER_DATA)
|
|
39479
|
+
#include "gsplatWorkBufferVS"
|
|
39480
|
+
#elif GSPLAT_COMPRESSED_DATA == true
|
|
39481
|
+
#include "gsplatCompressedDataVS"
|
|
39482
|
+
#if SH_COEFFS > 0
|
|
39483
|
+
#include "gsplatCompressedSHVS"
|
|
39484
|
+
#endif
|
|
39485
|
+
#elif GSPLAT_SOGS_DATA == true
|
|
39486
|
+
#include "gsplatSogsDataVS"
|
|
39487
|
+
#include "gsplatSogsColorVS"
|
|
39488
|
+
#if SH_COEFFS > 0
|
|
39489
|
+
#include "gsplatSogsSHVS"
|
|
39490
|
+
#endif
|
|
39491
|
+
#else
|
|
39492
|
+
#include "gsplatDataVS"
|
|
39493
|
+
#include "gsplatColorVS"
|
|
39494
|
+
#if SH_COEFFS > 0
|
|
39495
|
+
#include "gsplatSHVS"
|
|
39496
|
+
#endif
|
|
39497
|
+
#endif
|
|
39498
|
+
`;
|
|
39499
|
+
|
|
39500
|
+
var gsplatStructsVS$1 = `
|
|
39501
|
+
struct SplatSource {
|
|
39502
|
+
uint order;
|
|
39503
|
+
uint id;
|
|
39504
|
+
ivec2 uv;
|
|
39505
|
+
vec2 cornerUV;
|
|
39506
|
+
};
|
|
39507
|
+
struct SplatCenter {
|
|
39508
|
+
vec3 view;
|
|
39509
|
+
vec4 proj;
|
|
39510
|
+
mat4 modelView;
|
|
39511
|
+
float projMat00;
|
|
39512
|
+
};
|
|
39513
|
+
struct SplatCorner {
|
|
39514
|
+
vec2 offset;
|
|
39515
|
+
vec2 uv;
|
|
39516
|
+
#if GSPLAT_AA
|
|
39517
|
+
float aaFactor;
|
|
39518
|
+
#endif
|
|
39519
|
+
vec2 v;
|
|
39520
|
+
float dlen;
|
|
39521
|
+
};
|
|
39522
|
+
`;
|
|
39523
|
+
|
|
38988
39524
|
var gsplatCornerVS$1 = `
|
|
38989
39525
|
uniform vec2 viewport;
|
|
38990
39526
|
uniform vec4 camera_params;
|
|
38991
|
-
bool
|
|
38992
|
-
vec3 covA, covB;
|
|
38993
|
-
readCovariance(source, covA, covB);
|
|
39527
|
+
bool initCornerCov(SplatSource source, SplatCenter center, out SplatCorner corner, vec3 covA, vec3 covB) {
|
|
38994
39528
|
mat3 Vrk = mat3(
|
|
38995
39529
|
covA.x, covA.y, covA.z,
|
|
38996
39530
|
covA.y, covB.x, covB.y,
|
|
@@ -39037,6 +39571,11 @@ bool initCorner(SplatSource source, SplatCenter center, out SplatCorner corner)
|
|
|
39037
39571
|
corner.uv = source.cornerUV;
|
|
39038
39572
|
return true;
|
|
39039
39573
|
}
|
|
39574
|
+
bool initCorner(SplatSource source, SplatCenter center, out SplatCorner corner) {
|
|
39575
|
+
vec3 covA, covB;
|
|
39576
|
+
readCovariance(source, covA, covB);
|
|
39577
|
+
return initCornerCov(source, center, corner, covA, covB);
|
|
39578
|
+
}
|
|
39040
39579
|
`;
|
|
39041
39580
|
|
|
39042
39581
|
var gsplatDataVS$1 = `
|
|
@@ -39256,6 +39795,23 @@ void main(void) {
|
|
|
39256
39795
|
}
|
|
39257
39796
|
`;
|
|
39258
39797
|
|
|
39798
|
+
var gsplatWorkBufferVS$1 = `
|
|
39799
|
+
uniform highp sampler2D center;
|
|
39800
|
+
uniform highp sampler2D covA;
|
|
39801
|
+
uniform highp sampler2D covB;
|
|
39802
|
+
uniform mediump sampler2D splatColor;
|
|
39803
|
+
vec3 readCenter(SplatSource source) {
|
|
39804
|
+
return texelFetch(center, source.uv, 0).xyz;
|
|
39805
|
+
}
|
|
39806
|
+
void readCovariance(in SplatSource source, out vec3 cov_A, out vec3 cov_B) {
|
|
39807
|
+
cov_A = texelFetch(covA, source.uv, 0).xyz;
|
|
39808
|
+
cov_B = texelFetch(covB, source.uv, 0).xyz;
|
|
39809
|
+
}
|
|
39810
|
+
vec4 readColor(in SplatSource source) {
|
|
39811
|
+
return texelFetch(splatColor, source.uv, 0);
|
|
39812
|
+
}
|
|
39813
|
+
`;
|
|
39814
|
+
|
|
39259
39815
|
var quadVS$1 = `
|
|
39260
39816
|
attribute vec2 aPosition;
|
|
39261
39817
|
varying vec2 uv0;
|
|
@@ -43121,12 +43677,16 @@ const shaderChunksGLSL = {
|
|
|
43121
43677
|
gsplatSogsColorVS: gsplatSogsColorVS$1,
|
|
43122
43678
|
gsplatSogsDataVS: gsplatSogsDataVS$1,
|
|
43123
43679
|
gsplatSogsSHVS: gsplatSogsSHVS$1,
|
|
43680
|
+
gsplatSourceFormatVS: gsplatSourceFormatVS$1,
|
|
43681
|
+
gsplatStructsVS: gsplatStructsVS$1,
|
|
43124
43682
|
gsplatDataVS: gsplatDataVS$1,
|
|
43125
43683
|
gsplatOutputVS: gsplatOutputVS$1,
|
|
43126
43684
|
gsplatPS: gsplatPS$1,
|
|
43127
43685
|
gsplatSHVS: gsplatSHVS$1,
|
|
43128
43686
|
gsplatSourceVS: gsplatSourceVS$1,
|
|
43129
43687
|
gsplatVS: gsplatVS$1,
|
|
43688
|
+
gsplatWorkBufferVS: gsplatWorkBufferVS$1,
|
|
43689
|
+
gsplatPackingPS: gsplatPackingPS$1,
|
|
43130
43690
|
quadVS: quadVS$1,
|
|
43131
43691
|
immediateLinePS: immediateLinePS$1,
|
|
43132
43692
|
immediateLineVS: immediateLineVS$1,
|
|
@@ -44571,18 +45131,22 @@ fn getGlossiness() {
|
|
|
44571
45131
|
var gsplatCenterVS = `
|
|
44572
45132
|
uniform matrix_model: mat4x4f;
|
|
44573
45133
|
uniform matrix_view: mat4x4f;
|
|
44574
|
-
|
|
45134
|
+
#ifndef GSPLAT_CENTER_NOPROJ
|
|
45135
|
+
uniform matrix_projection: mat4x4f;
|
|
45136
|
+
#endif
|
|
44575
45137
|
fn initCenter(modelCenter: vec3f, center: ptr<function, SplatCenter>) -> bool {
|
|
44576
45138
|
let modelView: mat4x4f = uniform.matrix_view * uniform.matrix_model;
|
|
44577
45139
|
let centerView: vec4f = modelView * vec4f(modelCenter, 1.0);
|
|
44578
|
-
|
|
44579
|
-
|
|
44580
|
-
|
|
44581
|
-
|
|
44582
|
-
|
|
45140
|
+
#ifndef GSPLAT_CENTER_NOPROJ
|
|
45141
|
+
if (centerView.z > 0.0) {
|
|
45142
|
+
return false;
|
|
45143
|
+
}
|
|
45144
|
+
var centerProj: vec4f = uniform.matrix_projection * centerView;
|
|
45145
|
+
centerProj.z = clamp(centerProj.z, 0.0, abs(centerProj.w));
|
|
45146
|
+
center.proj = centerProj;
|
|
45147
|
+
center.projMat00 = uniform.matrix_projection[0][0];
|
|
45148
|
+
#endif
|
|
44583
45149
|
center.view = centerView.xyz / centerView.w;
|
|
44584
|
-
center.proj = centerProj;
|
|
44585
|
-
center.projMat00 = uniform.matrix_projection[0][0];
|
|
44586
45150
|
center.modelView = modelView;
|
|
44587
45151
|
return true;
|
|
44588
45152
|
}
|
|
@@ -44596,45 +45160,10 @@ fn readColor(source: ptr<function, SplatSource>) -> vec4f {
|
|
|
44596
45160
|
`;
|
|
44597
45161
|
|
|
44598
45162
|
var gsplatCommonVS = `
|
|
44599
|
-
|
|
44600
|
-
order: u32,
|
|
44601
|
-
id: u32,
|
|
44602
|
-
uv: vec2<i32>,
|
|
44603
|
-
cornerUV: vec2f,
|
|
44604
|
-
}
|
|
44605
|
-
struct SplatCenter {
|
|
44606
|
-
view: vec3f,
|
|
44607
|
-
proj: vec4f,
|
|
44608
|
-
modelView: mat4x4f,
|
|
44609
|
-
projMat00: f32,
|
|
44610
|
-
}
|
|
44611
|
-
struct SplatCorner {
|
|
44612
|
-
offset: vec2f,
|
|
44613
|
-
uv: vec2f,
|
|
44614
|
-
#if GSPLAT_AA
|
|
44615
|
-
aaFactor: f32,
|
|
44616
|
-
#endif
|
|
44617
|
-
}
|
|
45163
|
+
#include "gsplatStructsVS"
|
|
44618
45164
|
#include "gsplatEvalSHVS"
|
|
44619
45165
|
#include "gsplatQuatToMat3VS"
|
|
44620
|
-
#
|
|
44621
|
-
#include "gsplatCompressedDataVS"
|
|
44622
|
-
#if SH_BANDS > 0
|
|
44623
|
-
#include "gsplatCompressedSHVS"
|
|
44624
|
-
#endif
|
|
44625
|
-
#elif GSPLAT_SOGS_DATA
|
|
44626
|
-
#include "gsplatSogsDataVS"
|
|
44627
|
-
#include "gsplatSogsColorVS"
|
|
44628
|
-
#if SH_BANDS > 0
|
|
44629
|
-
#include "gsplatSogsSHVS"
|
|
44630
|
-
#endif
|
|
44631
|
-
#else
|
|
44632
|
-
#include "gsplatDataVS"
|
|
44633
|
-
#include "gsplatColorVS"
|
|
44634
|
-
#if SH_BANDS > 0
|
|
44635
|
-
#include "gsplatSHVS"
|
|
44636
|
-
#endif
|
|
44637
|
-
#endif
|
|
45166
|
+
#include "gsplatSourceFormatVS"
|
|
44638
45167
|
#include "gsplatSourceVS"
|
|
44639
45168
|
#include "gsplatCenterVS"
|
|
44640
45169
|
#include "gsplatCornerVS"
|
|
@@ -44839,59 +45368,53 @@ fn quatToMat3(R: vec4<f32>) -> mat3x3<f32> {
|
|
|
44839
45368
|
`;
|
|
44840
45369
|
|
|
44841
45370
|
var gsplatSogsColorVS = `
|
|
44842
|
-
var
|
|
44843
|
-
uniform sh0_mins:
|
|
44844
|
-
uniform sh0_maxs:
|
|
45371
|
+
var packedSh0: texture_2d<f32>;
|
|
45372
|
+
uniform sh0_mins: f32;
|
|
45373
|
+
uniform sh0_maxs: f32;
|
|
44845
45374
|
const SH_C0: f32 = 0.28209479177387814;
|
|
44846
45375
|
fn readColor(source: ptr<function, SplatSource>) -> vec4f {
|
|
44847
|
-
let clr
|
|
44848
|
-
|
|
45376
|
+
let clr = mix(vec3f(uniform.sh0_mins), vec3f(uniform.sh0_maxs), unpack111110(pack8888(textureLoad(packedSh0, source.uv, 0))));
|
|
45377
|
+
let alpha = f32(packedSample.z & 0xffu) / 255.0;
|
|
45378
|
+
return vec4f(vec3f(0.5) + clr.xyz * SH_C0, alpha);
|
|
44849
45379
|
}
|
|
44850
45380
|
`;
|
|
44851
45381
|
|
|
44852
45382
|
var gsplatSogsDataVS = `
|
|
45383
|
+
#include "gsplatPackingPS"
|
|
44853
45384
|
var packedTexture: texture_2d<u32>;
|
|
44854
45385
|
uniform means_mins: vec3f;
|
|
44855
45386
|
uniform means_maxs: vec3f;
|
|
44856
|
-
uniform scales_mins:
|
|
44857
|
-
uniform scales_maxs:
|
|
44858
|
-
fn unpackU32(u: u32) -> vec4f {
|
|
44859
|
-
return vec4f(
|
|
44860
|
-
f32((u >> 24u) & 0xFFu) / 255.0,
|
|
44861
|
-
f32((u >> 16u) & 0xFFu) / 255.0,
|
|
44862
|
-
f32((u >> 8u) & 0xFFu) / 255.0,
|
|
44863
|
-
f32(u & 0xFFu) / 255.0
|
|
44864
|
-
);
|
|
44865
|
-
}
|
|
45387
|
+
uniform scales_mins: f32;
|
|
45388
|
+
uniform scales_maxs: f32;
|
|
44866
45389
|
var<private> packedSample: vec4<u32>;
|
|
44867
45390
|
fn readCenter(source: ptr<function, SplatSource>) -> vec3f {
|
|
44868
45391
|
packedSample = textureLoad(packedTexture, source.uv, 0);
|
|
44869
|
-
let l
|
|
44870
|
-
let u
|
|
44871
|
-
let n
|
|
44872
|
-
let v
|
|
45392
|
+
let l = unpack8888(packedSample.x).xyz;
|
|
45393
|
+
let u = unpack8888(packedSample.y).xyz;
|
|
45394
|
+
let n = (l * 255.0 + u * 255.0 * 256.0) / 65535.0;
|
|
45395
|
+
let v = mix(uniform.means_mins, uniform.means_maxs, n);
|
|
44873
45396
|
return sign(v) * (exp(abs(v)) - 1.0);
|
|
44874
45397
|
}
|
|
44875
45398
|
const norm: f32 = 2.0 / sqrt(2.0);
|
|
44876
45399
|
fn readCovariance(source: ptr<function, SplatSource>, covA_ptr: ptr<function, vec3f>, covB_ptr: ptr<function, vec3f>) {
|
|
44877
|
-
let qdata
|
|
44878
|
-
let sdata
|
|
44879
|
-
let
|
|
44880
|
-
let
|
|
44881
|
-
let
|
|
45400
|
+
let qdata = unpack8888(packedSample.z).xyz;
|
|
45401
|
+
let sdata = unpack101010(packedSample.w >> 2u);
|
|
45402
|
+
let qmode = packedSample.w & 0x3u;
|
|
45403
|
+
let abc = (qdata - 0.5) * norm;
|
|
45404
|
+
let d = sqrt(max(0.0, 1.0 - dot(abc, abc)));
|
|
44882
45405
|
var quat: vec4f;
|
|
44883
|
-
if (
|
|
45406
|
+
if (qmode == 0u) {
|
|
44884
45407
|
quat = vec4f(d, abc);
|
|
44885
|
-
} else if (
|
|
45408
|
+
} else if (qmode == 1u) {
|
|
44886
45409
|
quat = vec4f(abc.x, d, abc.y, abc.z);
|
|
44887
|
-
} else if (
|
|
45410
|
+
} else if (qmode == 2u) {
|
|
44888
45411
|
quat = vec4f(abc.x, abc.y, d, abc.z);
|
|
44889
45412
|
} else {
|
|
44890
45413
|
quat = vec4f(abc.x, abc.y, abc.z, d);
|
|
44891
45414
|
}
|
|
44892
|
-
let rot
|
|
44893
|
-
let scale
|
|
44894
|
-
let M
|
|
45415
|
+
let rot = quatToMat3(quat);
|
|
45416
|
+
let scale = exp(mix(vec3f(uniform.scales_mins), vec3f(uniform.scales_maxs), sdata));
|
|
45417
|
+
let M = transpose(mat3x3f(
|
|
44895
45418
|
scale.x * rot[0],
|
|
44896
45419
|
scale.y * rot[1],
|
|
44897
45420
|
scale.z * rot[2]
|
|
@@ -44902,28 +45425,70 @@ fn readCovariance(source: ptr<function, SplatSource>, covA_ptr: ptr<function, ve
|
|
|
44902
45425
|
`;
|
|
44903
45426
|
|
|
44904
45427
|
var gsplatSogsSHVS = `
|
|
44905
|
-
var
|
|
45428
|
+
var packedShN: texture_2d<f32>;
|
|
44906
45429
|
uniform shN_mins: f32;
|
|
44907
45430
|
uniform shN_maxs: f32;
|
|
44908
45431
|
fn readSHData(source: ptr<function, SplatSource>, sh: ptr<function, array<vec3f, SH_COEFFS>>, scale: ptr<function, f32>) {
|
|
44909
|
-
let t
|
|
44910
|
-
let n
|
|
44911
|
-
let u
|
|
44912
|
-
let v
|
|
45432
|
+
let t = vec2i(packedSample.xy & vec2u(255u));
|
|
45433
|
+
let n = t.x + t.y * 256;
|
|
45434
|
+
let u = (n % 64) * SH_COEFFS;
|
|
45435
|
+
let v = n / 64;
|
|
44913
45436
|
for (var i: i32 = 0; i < SH_COEFFS; i = i + 1) {
|
|
44914
|
-
sh[i] = mix(vec3f(uniform.shN_mins), vec3f(uniform.shN_maxs), textureLoad(
|
|
45437
|
+
sh[i] = mix(vec3f(uniform.shN_mins), vec3f(uniform.shN_maxs), unpack111110(pack8888(textureLoad(packedShN, vec2i(u + i, v), 0))));
|
|
44915
45438
|
}
|
|
44916
45439
|
*scale = 1.0;
|
|
44917
45440
|
}
|
|
44918
45441
|
`;
|
|
44919
45442
|
|
|
45443
|
+
var gsplatSourceFormatVS = `
|
|
45444
|
+
#if defined(GSPLAT_WORKBUFFER_DATA)
|
|
45445
|
+
#include "gsplatWorkBufferVS"
|
|
45446
|
+
#elif GSPLAT_COMPRESSED_DATA == true
|
|
45447
|
+
#include "gsplatCompressedDataVS"
|
|
45448
|
+
#if SH_BANDS > 0
|
|
45449
|
+
#include "gsplatCompressedSHVS"
|
|
45450
|
+
#endif
|
|
45451
|
+
#elif GSPLAT_SOGS_DATA
|
|
45452
|
+
#include "gsplatSogsDataVS"
|
|
45453
|
+
#include "gsplatSogsColorVS"
|
|
45454
|
+
#if SH_BANDS > 0
|
|
45455
|
+
#include "gsplatSogsSHVS"
|
|
45456
|
+
#endif
|
|
45457
|
+
#else
|
|
45458
|
+
#include "gsplatDataVS"
|
|
45459
|
+
#include "gsplatColorVS"
|
|
45460
|
+
#if SH_BANDS > 0
|
|
45461
|
+
#include "gsplatSHVS"
|
|
45462
|
+
#endif
|
|
45463
|
+
#endif
|
|
45464
|
+
`;
|
|
45465
|
+
|
|
45466
|
+
var gsplatStructsVS = `
|
|
45467
|
+
struct SplatSource {
|
|
45468
|
+
order: u32,
|
|
45469
|
+
id: u32,
|
|
45470
|
+
uv: vec2<i32>,
|
|
45471
|
+
cornerUV: vec2f,
|
|
45472
|
+
}
|
|
45473
|
+
struct SplatCenter {
|
|
45474
|
+
view: vec3f,
|
|
45475
|
+
proj: vec4f,
|
|
45476
|
+
modelView: mat4x4f,
|
|
45477
|
+
projMat00: f32,
|
|
45478
|
+
}
|
|
45479
|
+
struct SplatCorner {
|
|
45480
|
+
offset: vec2f,
|
|
45481
|
+
uv: vec2f,
|
|
45482
|
+
#if GSPLAT_AA
|
|
45483
|
+
aaFactor: f32,
|
|
45484
|
+
#endif
|
|
45485
|
+
}
|
|
45486
|
+
`;
|
|
45487
|
+
|
|
44920
45488
|
var gsplatCornerVS = `
|
|
44921
45489
|
uniform viewport: vec2f;
|
|
44922
45490
|
uniform camera_params: vec4f;
|
|
44923
|
-
fn
|
|
44924
|
-
var covA: vec3f;
|
|
44925
|
-
var covB: vec3f;
|
|
44926
|
-
readCovariance(source, &covA, &covB);
|
|
45491
|
+
fn initCornerCov(source: ptr<function, SplatSource>, center: ptr<function, SplatCenter>, corner: ptr<function, SplatCorner>, covA: vec3f, covB: vec3f) -> bool {
|
|
44927
45492
|
let Vrk = mat3x3f(
|
|
44928
45493
|
vec3f(covA.x, covA.y, covA.z),
|
|
44929
45494
|
vec3f(covA.y, covB.x, covB.y),
|
|
@@ -44970,6 +45535,12 @@ fn initCorner(source: ptr<function, SplatSource>, center: ptr<function, SplatCen
|
|
|
44970
45535
|
corner.uv = source.cornerUV;
|
|
44971
45536
|
return true;
|
|
44972
45537
|
}
|
|
45538
|
+
fn initCorner(source: ptr<function, SplatSource>, center: ptr<function, SplatCenter>, corner: ptr<function, SplatCorner>) -> bool {
|
|
45539
|
+
var covA: vec3f;
|
|
45540
|
+
var covB: vec3f;
|
|
45541
|
+
readCovariance(source, &covA, &covB);
|
|
45542
|
+
return initCornerCov(source, center, corner, covA, covB);
|
|
45543
|
+
}
|
|
44973
45544
|
`;
|
|
44974
45545
|
|
|
44975
45546
|
var gsplatDataVS = `
|
|
@@ -45221,7 +45792,7 @@ fn vertexMain(input: VertexInput) -> VertexOutput {
|
|
|
45221
45792
|
#endif
|
|
45222
45793
|
#if SH_BANDS > 0
|
|
45223
45794
|
let modelView3x3 = mat3x3f(center.modelView[0].xyz, center.modelView[1].xyz, center.modelView[2].xyz);
|
|
45224
|
-
let dir = normalize(
|
|
45795
|
+
let dir = normalize(center.view * modelView3x3);
|
|
45225
45796
|
var sh: array<vec3f, SH_COEFFS>;
|
|
45226
45797
|
var scale: f32;
|
|
45227
45798
|
readSHData(&source, &sh, &scale);
|
|
@@ -45241,6 +45812,23 @@ fn vertexMain(input: VertexInput) -> VertexOutput {
|
|
|
45241
45812
|
}
|
|
45242
45813
|
`;
|
|
45243
45814
|
|
|
45815
|
+
var gsplatWorkBufferVS = `
|
|
45816
|
+
var center: texture_2d<f32>;
|
|
45817
|
+
var covA: texture_2d<f32>;
|
|
45818
|
+
var covB: texture_2d<f32>;
|
|
45819
|
+
var splatColor: texture_2d<f32>;
|
|
45820
|
+
fn readCenter(source: ptr<function, SplatSource>) -> vec3f {
|
|
45821
|
+
return textureLoad(center, source.uv, 0).xyz;
|
|
45822
|
+
}
|
|
45823
|
+
fn readCovariance(source: ptr<function, SplatSource>, cov_A: ptr<function, vec3f>, cov_B: ptr<function, vec3f>) {
|
|
45824
|
+
*cov_A = textureLoad(covA, source.uv, 0).xyz;
|
|
45825
|
+
*cov_B = textureLoad(covB, source.uv, 0).xyz;
|
|
45826
|
+
}
|
|
45827
|
+
fn readColor(source: ptr<function, SplatSource>) -> vec4f {
|
|
45828
|
+
return textureLoad(splatColor, source.uv, 0);
|
|
45829
|
+
}
|
|
45830
|
+
`;
|
|
45831
|
+
|
|
45244
45832
|
var quadVS = `
|
|
45245
45833
|
attribute aPosition: vec2f;
|
|
45246
45834
|
varying uv0: vec2f;
|
|
@@ -49065,6 +49653,8 @@ const shaderChunksWGSL = {
|
|
|
49065
49653
|
gsplatCompressedDataVS,
|
|
49066
49654
|
gsplatCompressedSHVS,
|
|
49067
49655
|
gsplatEvalSHVS,
|
|
49656
|
+
gsplatSourceFormatVS,
|
|
49657
|
+
gsplatStructsVS,
|
|
49068
49658
|
gsplatQuatToMat3VS,
|
|
49069
49659
|
gsplatSogsColorVS,
|
|
49070
49660
|
gsplatSogsDataVS,
|
|
@@ -49075,6 +49665,8 @@ const shaderChunksWGSL = {
|
|
|
49075
49665
|
gsplatSHVS,
|
|
49076
49666
|
gsplatSourceVS,
|
|
49077
49667
|
gsplatVS,
|
|
49668
|
+
gsplatWorkBufferVS,
|
|
49669
|
+
gsplatPackingPS,
|
|
49078
49670
|
quadVS,
|
|
49079
49671
|
indirectCoreCS,
|
|
49080
49672
|
immediateLinePS,
|
|
@@ -49247,8 +49839,7 @@ class AppBase extends EventHandler {
|
|
|
49247
49839
|
defaultLayerComposition.pushTransparent(this.defaultLayerUi);
|
|
49248
49840
|
this.scene.layers = defaultLayerComposition;
|
|
49249
49841
|
AreaLightLuts.createPlaceholder(graphicsDevice);
|
|
49250
|
-
this.renderer = new ForwardRenderer(graphicsDevice);
|
|
49251
|
-
this.renderer.scene = this.scene;
|
|
49842
|
+
this.renderer = new ForwardRenderer(graphicsDevice, this.scene);
|
|
49252
49843
|
if (lightmapper) {
|
|
49253
49844
|
this.lightmapper = new lightmapper(graphicsDevice, this.root, this.scene, this.renderer, this.assets);
|
|
49254
49845
|
this.once('prerender', this._firstBake, this);
|
|
@@ -66055,7 +66646,7 @@ struct RotateResult {
|
|
|
66055
66646
|
fn rotateWithMatrix(quadXY: vec2f, pRotation: f32) -> RotateResult {
|
|
66056
66647
|
let c = cos(pRotation);
|
|
66057
66648
|
let s = sin(pRotation);
|
|
66058
|
-
let m = mat2x2f(vec2f(c, s), vec2f(
|
|
66649
|
+
let m = mat2x2f(vec2f(c, -s), vec2f(s, c));
|
|
66059
66650
|
return RotateResult(m * quadXY, m);
|
|
66060
66651
|
}
|
|
66061
66652
|
fn billboard(InstanceCoords: vec3f, quadXY: vec2f) -> vec3f {
|
|
@@ -66489,7 +67080,7 @@ struct RotateResult {
|
|
|
66489
67080
|
fn rotateWithMatrix(quadXY: vec2f, pRotation: f32) -> RotateResult {
|
|
66490
67081
|
let c = cos(pRotation);
|
|
66491
67082
|
let s = sin(pRotation);
|
|
66492
|
-
let m = mat2x2f(vec2f(c, s), vec2f(
|
|
67083
|
+
let m = mat2x2f(vec2f(c, -s), vec2f(s, c));
|
|
66493
67084
|
return RotateResult(m * quadXY, m);
|
|
66494
67085
|
}
|
|
66495
67086
|
fn billboard(InstanceCoords: vec3f, quadXY: vec2f) -> vec3f {
|
|
@@ -69196,6 +69787,8 @@ class ScreenComponentSystem extends ComponentSystem {
|
|
|
69196
69787
|
enabled: screen.enabled,
|
|
69197
69788
|
screenSpace: screen.screenSpace,
|
|
69198
69789
|
scaleMode: screen.scaleMode,
|
|
69790
|
+
scaleBlend: screen.scaleBlend,
|
|
69791
|
+
priority: screen.priority,
|
|
69199
69792
|
resolution: screen.resolution.clone(),
|
|
69200
69793
|
referenceResolution: screen.referenceResolution.clone()
|
|
69201
69794
|
});
|
|
@@ -74716,8 +75309,10 @@ class ScriptComponent extends Component {
|
|
|
74716
75309
|
if (args.properties && typeof args.properties === 'object') {
|
|
74717
75310
|
Object.assign(scriptInstance, args.properties);
|
|
74718
75311
|
}
|
|
74719
|
-
if (!(scriptInstance instanceof ScriptType)) {
|
|
74720
|
-
this._attributeDataMap.set(scriptName,
|
|
75312
|
+
if (!(scriptInstance instanceof ScriptType) && args.attributes) {
|
|
75313
|
+
this._attributeDataMap.set(scriptName, {
|
|
75314
|
+
...args.attributes
|
|
75315
|
+
});
|
|
74721
75316
|
}
|
|
74722
75317
|
const len = this._scripts.length;
|
|
74723
75318
|
let ind = -1;
|
|
@@ -75049,11 +75644,1360 @@ class ScriptComponentSystem extends ComponentSystem {
|
|
|
75049
75644
|
}
|
|
75050
75645
|
}
|
|
75051
75646
|
|
|
75647
|
+
var gsplatIntervalTextureGLSL = `
|
|
75648
|
+
precision highp usampler2D;
|
|
75649
|
+
uniform usampler2D uIntervalsTexture;
|
|
75650
|
+
uniform int uNumIntervals;
|
|
75651
|
+
uniform int uTextureWidth;
|
|
75652
|
+
uniform int uActiveSplats;
|
|
75653
|
+
ivec2 getCoordFromIndex(int index, int textureWidth) {
|
|
75654
|
+
return ivec2(index % textureWidth, index / textureWidth);
|
|
75655
|
+
}
|
|
75656
|
+
void main() {
|
|
75657
|
+
ivec2 coord = ivec2(gl_FragCoord.xy);
|
|
75658
|
+
int targetIndex = coord.y * uTextureWidth + coord.x;
|
|
75659
|
+
|
|
75660
|
+
if (targetIndex >= uActiveSplats) {
|
|
75661
|
+
gl_FragColor = 0u;
|
|
75662
|
+
return;
|
|
75663
|
+
}
|
|
75664
|
+
|
|
75665
|
+
int left = 0;
|
|
75666
|
+
int right = uNumIntervals - 1;
|
|
75667
|
+
int intervalIndex = 0;
|
|
75668
|
+
|
|
75669
|
+
while (left <= right) {
|
|
75670
|
+
int mid = (left + right) / 2;
|
|
75671
|
+
|
|
75672
|
+
int textureWidth = textureSize(uIntervalsTexture, 0).x;
|
|
75673
|
+
ivec2 intervalCoord = getCoordFromIndex(mid, textureWidth);
|
|
75674
|
+
uvec2 intervalData = texelFetch(uIntervalsTexture, intervalCoord, 0).rg;
|
|
75675
|
+
|
|
75676
|
+
uint accumulatedSum = intervalData.g;
|
|
75677
|
+
|
|
75678
|
+
if (uint(targetIndex) < accumulatedSum) {
|
|
75679
|
+
intervalIndex = mid;
|
|
75680
|
+
right = mid - 1;
|
|
75681
|
+
} else {
|
|
75682
|
+
left = mid + 1;
|
|
75683
|
+
}
|
|
75684
|
+
}
|
|
75685
|
+
|
|
75686
|
+
int textureWidth = textureSize(uIntervalsTexture, 0).x;
|
|
75687
|
+
ivec2 intervalCoord = getCoordFromIndex(intervalIndex, textureWidth);
|
|
75688
|
+
uvec2 intervalData = texelFetch(uIntervalsTexture, intervalCoord, 0).rg;
|
|
75689
|
+
|
|
75690
|
+
uint intervalStart = intervalData.r;
|
|
75691
|
+
uint currentAccSum = intervalData.g;
|
|
75692
|
+
|
|
75693
|
+
uint prevAccSum = 0u;
|
|
75694
|
+
if (intervalIndex > 0) {
|
|
75695
|
+
ivec2 prevCoord = getCoordFromIndex(intervalIndex - 1, textureWidth);
|
|
75696
|
+
prevAccSum = texelFetch(uIntervalsTexture, prevCoord, 0).g;
|
|
75697
|
+
}
|
|
75698
|
+
|
|
75699
|
+
uint offsetInInterval = uint(targetIndex) - prevAccSum;
|
|
75700
|
+
uint originalIndex = intervalStart + offsetInInterval;
|
|
75701
|
+
|
|
75702
|
+
gl_FragColor = originalIndex;
|
|
75703
|
+
}
|
|
75704
|
+
`;
|
|
75705
|
+
|
|
75706
|
+
var gsplatIntervalTextureWGSL = `
|
|
75707
|
+
var uIntervalsTexture: texture_2d<u32>;
|
|
75708
|
+
uniform uNumIntervals: i32;
|
|
75709
|
+
uniform uTextureWidth: i32;
|
|
75710
|
+
uniform uActiveSplats: i32;
|
|
75711
|
+
fn getCoordFromIndex(index: i32, textureWidth: i32) -> vec2i {
|
|
75712
|
+
return vec2i(index % textureWidth, index / textureWidth);
|
|
75713
|
+
}
|
|
75714
|
+
@fragment
|
|
75715
|
+
fn fragmentMain(input: FragmentInput) -> FragmentOutput {
|
|
75716
|
+
var output: FragmentOutput;
|
|
75717
|
+
|
|
75718
|
+
let coord = vec2i(i32(input.position.x), i32(input.position.y));
|
|
75719
|
+
let targetIndex = coord.y * uniform.uTextureWidth + coord.x;
|
|
75720
|
+
|
|
75721
|
+
if (targetIndex >= uniform.uActiveSplats) {
|
|
75722
|
+
output.color = 0u;
|
|
75723
|
+
return output;
|
|
75724
|
+
}
|
|
75725
|
+
|
|
75726
|
+
var left = 0i;
|
|
75727
|
+
var right = uniform.uNumIntervals - 1;
|
|
75728
|
+
var intervalIndex = 0i;
|
|
75729
|
+
|
|
75730
|
+
while (left <= right) {
|
|
75731
|
+
let mid = (left + right) / 2;
|
|
75732
|
+
|
|
75733
|
+
let textureWidth = i32(textureDimensions(uIntervalsTexture, 0).x);
|
|
75734
|
+
let intervalCoord = getCoordFromIndex(mid, textureWidth);
|
|
75735
|
+
let intervalData = textureLoad(uIntervalsTexture, intervalCoord, 0).rg;
|
|
75736
|
+
|
|
75737
|
+
let accumulatedSum = intervalData.g;
|
|
75738
|
+
|
|
75739
|
+
if (u32(targetIndex) < accumulatedSum) {
|
|
75740
|
+
intervalIndex = mid;
|
|
75741
|
+
right = mid - 1;
|
|
75742
|
+
} else {
|
|
75743
|
+
left = mid + 1;
|
|
75744
|
+
}
|
|
75745
|
+
}
|
|
75746
|
+
|
|
75747
|
+
let textureWidth = i32(textureDimensions(uIntervalsTexture, 0).x);
|
|
75748
|
+
let intervalCoord = getCoordFromIndex(intervalIndex, textureWidth);
|
|
75749
|
+
let intervalData = textureLoad(uIntervalsTexture, intervalCoord, 0).rg;
|
|
75750
|
+
|
|
75751
|
+
let intervalStart = intervalData.r;
|
|
75752
|
+
let currentAccSum = intervalData.g;
|
|
75753
|
+
|
|
75754
|
+
var prevAccSum = 0u;
|
|
75755
|
+
if (intervalIndex > 0) {
|
|
75756
|
+
let prevCoord = getCoordFromIndex(intervalIndex - 1, textureWidth);
|
|
75757
|
+
prevAccSum = textureLoad(uIntervalsTexture, prevCoord, 0).g;
|
|
75758
|
+
}
|
|
75759
|
+
|
|
75760
|
+
let offsetInInterval = u32(targetIndex) - prevAccSum;
|
|
75761
|
+
let originalIndex = intervalStart + offsetInInterval;
|
|
75762
|
+
|
|
75763
|
+
output.color = originalIndex;
|
|
75764
|
+
return output;
|
|
75765
|
+
}
|
|
75766
|
+
`;
|
|
75767
|
+
|
|
75768
|
+
class GSplatIntervalTexture {
|
|
75769
|
+
constructor(device){
|
|
75770
|
+
this.texture = null;
|
|
75771
|
+
this.rt = null;
|
|
75772
|
+
this.intervalsDataTexture = null;
|
|
75773
|
+
this.shader = null;
|
|
75774
|
+
this.device = device;
|
|
75775
|
+
}
|
|
75776
|
+
destroy() {
|
|
75777
|
+
this.texture?.destroy();
|
|
75778
|
+
this.texture = null;
|
|
75779
|
+
this.rt?.destroy();
|
|
75780
|
+
this.rt = null;
|
|
75781
|
+
this.intervalsDataTexture?.destroy();
|
|
75782
|
+
this.intervalsDataTexture = null;
|
|
75783
|
+
this.shader = null;
|
|
75784
|
+
}
|
|
75785
|
+
getShader() {
|
|
75786
|
+
if (!this.shader) {
|
|
75787
|
+
this.shader = ShaderUtils.createShader(this.device, {
|
|
75788
|
+
uniqueName: 'GSplatIntervalsShader',
|
|
75789
|
+
attributes: {
|
|
75790
|
+
aPosition: SEMANTIC_POSITION
|
|
75791
|
+
},
|
|
75792
|
+
vertexChunk: 'quadVS',
|
|
75793
|
+
fragmentGLSL: gsplatIntervalTextureGLSL,
|
|
75794
|
+
fragmentWGSL: gsplatIntervalTextureWGSL,
|
|
75795
|
+
fragmentOutputTypes: [
|
|
75796
|
+
'uint'
|
|
75797
|
+
]
|
|
75798
|
+
});
|
|
75799
|
+
}
|
|
75800
|
+
return this.shader;
|
|
75801
|
+
}
|
|
75802
|
+
createTexture(name, format, width, height) {
|
|
75803
|
+
return new Texture(this.device, {
|
|
75804
|
+
name: name,
|
|
75805
|
+
width: width,
|
|
75806
|
+
height: height,
|
|
75807
|
+
format: format,
|
|
75808
|
+
cubemap: false,
|
|
75809
|
+
mipmaps: false,
|
|
75810
|
+
minFilter: FILTER_NEAREST,
|
|
75811
|
+
magFilter: FILTER_NEAREST,
|
|
75812
|
+
addressU: ADDRESS_CLAMP_TO_EDGE,
|
|
75813
|
+
addressV: ADDRESS_CLAMP_TO_EDGE
|
|
75814
|
+
});
|
|
75815
|
+
}
|
|
75816
|
+
update(intervals) {
|
|
75817
|
+
if (!intervals || intervals.length === 0) {
|
|
75818
|
+
return 0;
|
|
75819
|
+
}
|
|
75820
|
+
let totalSplats = 0;
|
|
75821
|
+
for(let i = 0; i < intervals.length; i += 2){
|
|
75822
|
+
const start = intervals[i];
|
|
75823
|
+
const end = intervals[i + 1];
|
|
75824
|
+
totalSplats += end - start;
|
|
75825
|
+
}
|
|
75826
|
+
const maxTextureSize = this.device.maxTextureSize;
|
|
75827
|
+
let textureWidth = Math.ceil(Math.sqrt(totalSplats));
|
|
75828
|
+
textureWidth = Math.min(textureWidth, maxTextureSize);
|
|
75829
|
+
const textureHeight = Math.ceil(totalSplats / textureWidth);
|
|
75830
|
+
if (!this.texture) {
|
|
75831
|
+
this.texture = this.createTexture('intervalsTexture', PIXELFORMAT_R32U, textureWidth, textureHeight);
|
|
75832
|
+
}
|
|
75833
|
+
if (!this.rt) {
|
|
75834
|
+
this.rt = new RenderTarget({
|
|
75835
|
+
colorBuffer: this.texture,
|
|
75836
|
+
depth: false
|
|
75837
|
+
});
|
|
75838
|
+
}
|
|
75839
|
+
if (this.rt.width !== textureWidth || this.rt.height !== textureHeight) {
|
|
75840
|
+
this.rt.resize(textureWidth, textureHeight);
|
|
75841
|
+
}
|
|
75842
|
+
const numIntervals = intervals.length / 2;
|
|
75843
|
+
const dataTextureSize = Math.ceil(Math.sqrt(numIntervals));
|
|
75844
|
+
if (!this.intervalsDataTexture) {
|
|
75845
|
+
this.intervalsDataTexture = this.createTexture('intervalsData', PIXELFORMAT_RG32U, dataTextureSize, dataTextureSize);
|
|
75846
|
+
}
|
|
75847
|
+
if (this.intervalsDataTexture.width !== dataTextureSize) {
|
|
75848
|
+
this.intervalsDataTexture.resize(dataTextureSize, dataTextureSize);
|
|
75849
|
+
}
|
|
75850
|
+
const intervalsData = this.intervalsDataTexture.lock();
|
|
75851
|
+
let runningSum = 0;
|
|
75852
|
+
for(let i = 0; i < numIntervals; i++){
|
|
75853
|
+
const start = intervals[i * 2];
|
|
75854
|
+
const end = intervals[i * 2 + 1];
|
|
75855
|
+
const intervalSize = end - start;
|
|
75856
|
+
runningSum += intervalSize;
|
|
75857
|
+
intervalsData[i * 2] = start;
|
|
75858
|
+
intervalsData[i * 2 + 1] = runningSum;
|
|
75859
|
+
}
|
|
75860
|
+
this.intervalsDataTexture.unlock();
|
|
75861
|
+
const scope = this.device.scope;
|
|
75862
|
+
scope.resolve('uIntervalsTexture').setValue(this.intervalsDataTexture);
|
|
75863
|
+
scope.resolve('uNumIntervals').setValue(numIntervals);
|
|
75864
|
+
scope.resolve('uTextureWidth').setValue(textureWidth);
|
|
75865
|
+
scope.resolve('uActiveSplats').setValue(totalSplats);
|
|
75866
|
+
this.device.setCullMode(CULLFACE_NONE);
|
|
75867
|
+
this.device.setBlendState(BlendState.NOBLEND);
|
|
75868
|
+
this.device.setDepthState(DepthState.NODEPTH);
|
|
75869
|
+
drawQuadWithShader(this.device, this.rt, this.getShader());
|
|
75870
|
+
return totalSplats;
|
|
75871
|
+
}
|
|
75872
|
+
}
|
|
75873
|
+
|
|
75874
|
+
class GSplatInfo {
|
|
75875
|
+
constructor(device, resource, placement){
|
|
75876
|
+
this.activeSplats = 0;
|
|
75877
|
+
this.intervals = [];
|
|
75878
|
+
this.lineStart = 0;
|
|
75879
|
+
this.lineCount = 0;
|
|
75880
|
+
this.padding = 0;
|
|
75881
|
+
this.viewport = new Vec4();
|
|
75882
|
+
this.previousWorldTransform = new Mat4();
|
|
75883
|
+
this.aabb = new BoundingBox();
|
|
75884
|
+
this.device = device;
|
|
75885
|
+
this.resource = resource;
|
|
75886
|
+
this.node = placement.node;
|
|
75887
|
+
this.lodIndex = placement.lodIndex;
|
|
75888
|
+
this.numSplats = resource.centers.length / 3;
|
|
75889
|
+
this.aabb.copy(placement.aabb);
|
|
75890
|
+
this.intervalTexture = new GSplatIntervalTexture(device);
|
|
75891
|
+
this.updateIntervals(placement.intervals);
|
|
75892
|
+
}
|
|
75893
|
+
destroy() {
|
|
75894
|
+
this.intervals.length = 0;
|
|
75895
|
+
this.intervalTexture.destroy();
|
|
75896
|
+
}
|
|
75897
|
+
setLines(start, count, textureSize, activeSplats) {
|
|
75898
|
+
this.lineStart = start;
|
|
75899
|
+
this.lineCount = count;
|
|
75900
|
+
this.padding = textureSize * count - activeSplats;
|
|
75901
|
+
this.viewport.set(0, start, textureSize, count);
|
|
75902
|
+
}
|
|
75903
|
+
updateIntervals(intervals) {
|
|
75904
|
+
const resource = this.resource;
|
|
75905
|
+
this.intervals.length = 0;
|
|
75906
|
+
this.activeSplats = resource.numSplats;
|
|
75907
|
+
if (intervals.size > 0) {
|
|
75908
|
+
for (const interval of intervals.values()){
|
|
75909
|
+
this.intervals.push(interval.x, interval.y + 1);
|
|
75910
|
+
}
|
|
75911
|
+
this.activeSplats = this.intervalTexture.update(this.intervals);
|
|
75912
|
+
}
|
|
75913
|
+
}
|
|
75914
|
+
update() {
|
|
75915
|
+
const worldMatrix = this.node.getWorldTransform();
|
|
75916
|
+
const worldMatrixChanged = !this.previousWorldTransform.equals(worldMatrix);
|
|
75917
|
+
if (worldMatrixChanged) {
|
|
75918
|
+
this.previousWorldTransform.copy(worldMatrix);
|
|
75919
|
+
}
|
|
75920
|
+
return worldMatrixChanged;
|
|
75921
|
+
}
|
|
75922
|
+
}
|
|
75923
|
+
|
|
75924
|
+
function UnifiedSortWorker() {
|
|
75925
|
+
const myself = typeof self !== 'undefined' && self || require('node:worker_threads').parentPort;
|
|
75926
|
+
const centersMap = new Map();
|
|
75927
|
+
let centersData;
|
|
75928
|
+
let distances;
|
|
75929
|
+
let countBuffer;
|
|
75930
|
+
const evaluateSortKeys = (sortParams, minDist, divider, distances, countBuffer, centersData, bucketCount)=>{
|
|
75931
|
+
const { ids, lineStarts, padding, intervals, textureSize } = centersData;
|
|
75932
|
+
for(let paramIdx = 0; paramIdx < sortParams.length; paramIdx++){
|
|
75933
|
+
const params = sortParams[paramIdx];
|
|
75934
|
+
const { transformedDirection, offset, scale } = params;
|
|
75935
|
+
const dx = transformedDirection.x;
|
|
75936
|
+
const dy = transformedDirection.y;
|
|
75937
|
+
const dz = transformedDirection.z;
|
|
75938
|
+
const sdx = dx * scale * divider;
|
|
75939
|
+
const sdy = dy * scale * divider;
|
|
75940
|
+
const sdz = dz * scale * divider;
|
|
75941
|
+
const add = (offset - minDist) * divider;
|
|
75942
|
+
const id = ids[paramIdx];
|
|
75943
|
+
const centers = centersMap.get(id);
|
|
75944
|
+
if (!centers) {
|
|
75945
|
+
console.error('UnifiedSortWorker: No centers found for id', id);
|
|
75946
|
+
}
|
|
75947
|
+
let targetIndex = lineStarts[paramIdx] * textureSize;
|
|
75948
|
+
const intervalsArray = intervals[paramIdx].length > 0 ? intervals[paramIdx] : [
|
|
75949
|
+
0,
|
|
75950
|
+
centers.length / 3
|
|
75951
|
+
];
|
|
75952
|
+
for(let i = 0; i < intervalsArray.length; i += 2){
|
|
75953
|
+
const intervalStart = intervalsArray[i] * 3;
|
|
75954
|
+
const intervalEnd = intervalsArray[i + 1] * 3;
|
|
75955
|
+
for(let srcIndex = intervalStart; srcIndex < intervalEnd; srcIndex += 3){
|
|
75956
|
+
const x = centers[srcIndex];
|
|
75957
|
+
const y = centers[srcIndex + 1];
|
|
75958
|
+
const z = centers[srcIndex + 2];
|
|
75959
|
+
const sortKey = Math.floor(x * sdx + y * sdy + z * sdz + add);
|
|
75960
|
+
distances[targetIndex++] = sortKey;
|
|
75961
|
+
countBuffer[sortKey]++;
|
|
75962
|
+
}
|
|
75963
|
+
}
|
|
75964
|
+
const pad = padding[paramIdx];
|
|
75965
|
+
countBuffer[0] += pad;
|
|
75966
|
+
distances.fill(0, targetIndex, targetIndex + pad);
|
|
75967
|
+
targetIndex += pad;
|
|
75968
|
+
}
|
|
75969
|
+
};
|
|
75970
|
+
const countingSort = (bucketCount, countBuffer, numVertices, distances, order)=>{
|
|
75971
|
+
for(let i = 1; i < bucketCount; i++){
|
|
75972
|
+
countBuffer[i] += countBuffer[i - 1];
|
|
75973
|
+
}
|
|
75974
|
+
for(let i = 0; i < numVertices; i++){
|
|
75975
|
+
const distance = distances[i];
|
|
75976
|
+
const destIndex = --countBuffer[distance];
|
|
75977
|
+
order[destIndex] = i;
|
|
75978
|
+
}
|
|
75979
|
+
};
|
|
75980
|
+
const computeEffectiveDistanceRange = (sortParams)=>{
|
|
75981
|
+
let minDist = Infinity;
|
|
75982
|
+
let maxDist = -Infinity;
|
|
75983
|
+
for(let paramIdx = 0; paramIdx < sortParams.length; paramIdx++){
|
|
75984
|
+
const params = sortParams[paramIdx];
|
|
75985
|
+
const { transformedDirection, offset, scale, aabbMin, aabbMax } = params;
|
|
75986
|
+
const dx = transformedDirection.x;
|
|
75987
|
+
const dy = transformedDirection.y;
|
|
75988
|
+
const dz = transformedDirection.z;
|
|
75989
|
+
const pxMin = dx >= 0 ? aabbMin[0] : aabbMax[0];
|
|
75990
|
+
const pyMin = dy >= 0 ? aabbMin[1] : aabbMax[1];
|
|
75991
|
+
const pzMin = dz >= 0 ? aabbMin[2] : aabbMax[2];
|
|
75992
|
+
const pxMax = dx >= 0 ? aabbMax[0] : aabbMin[0];
|
|
75993
|
+
const pyMax = dy >= 0 ? aabbMax[1] : aabbMin[1];
|
|
75994
|
+
const pzMax = dz >= 0 ? aabbMax[2] : aabbMin[2];
|
|
75995
|
+
const dMin = pxMin * dx + pyMin * dy + pzMin * dz;
|
|
75996
|
+
const dMax = pxMax * dx + pyMax * dy + pzMax * dz;
|
|
75997
|
+
const eMin = dMin * scale + offset;
|
|
75998
|
+
const eMax = dMax * scale + offset;
|
|
75999
|
+
const localMin = Math.min(eMin, eMax);
|
|
76000
|
+
const localMax = Math.max(eMin, eMax);
|
|
76001
|
+
if (localMin < minDist) minDist = localMin;
|
|
76002
|
+
if (localMax > maxDist) maxDist = localMax;
|
|
76003
|
+
}
|
|
76004
|
+
if (minDist === Infinity) {
|
|
76005
|
+
minDist = 0;
|
|
76006
|
+
maxDist = 0;
|
|
76007
|
+
}
|
|
76008
|
+
return {
|
|
76009
|
+
minDist,
|
|
76010
|
+
maxDist
|
|
76011
|
+
};
|
|
76012
|
+
};
|
|
76013
|
+
const sort = (sortParams, order, centersData)=>{
|
|
76014
|
+
const { minDist, maxDist } = computeEffectiveDistanceRange(sortParams);
|
|
76015
|
+
const numVertices = centersData.totalUsedPixels;
|
|
76016
|
+
const compareBits = Math.max(10, Math.min(20, Math.round(Math.log2(numVertices / 4))));
|
|
76017
|
+
const bucketCount = 2 ** compareBits + 1;
|
|
76018
|
+
if (distances?.length !== numVertices) {
|
|
76019
|
+
distances = new Uint32Array(numVertices);
|
|
76020
|
+
}
|
|
76021
|
+
if (!countBuffer || countBuffer.length !== bucketCount) {
|
|
76022
|
+
countBuffer = new Uint32Array(bucketCount);
|
|
76023
|
+
} else {
|
|
76024
|
+
countBuffer.fill(0);
|
|
76025
|
+
}
|
|
76026
|
+
const range = maxDist - minDist;
|
|
76027
|
+
const divider = range < 1e-6 ? 0 : 1 / range * 2 ** compareBits;
|
|
76028
|
+
evaluateSortKeys(sortParams, minDist, divider, distances, countBuffer, centersData);
|
|
76029
|
+
countingSort(bucketCount, countBuffer, numVertices, distances, order);
|
|
76030
|
+
const count = numVertices;
|
|
76031
|
+
const transferList = [
|
|
76032
|
+
order.buffer
|
|
76033
|
+
];
|
|
76034
|
+
const response = {
|
|
76035
|
+
order: order.buffer,
|
|
76036
|
+
count,
|
|
76037
|
+
version: centersData.version
|
|
76038
|
+
};
|
|
76039
|
+
myself.postMessage(response, transferList);
|
|
76040
|
+
};
|
|
76041
|
+
myself.addEventListener('message', (message)=>{
|
|
76042
|
+
const msgData = message.data ?? message;
|
|
76043
|
+
switch(msgData.command){
|
|
76044
|
+
case 'addCenters':
|
|
76045
|
+
{
|
|
76046
|
+
centersMap.set(msgData.id, new Float32Array(msgData.centers));
|
|
76047
|
+
break;
|
|
76048
|
+
}
|
|
76049
|
+
case 'removeCenters':
|
|
76050
|
+
{
|
|
76051
|
+
centersMap.delete(msgData.id);
|
|
76052
|
+
break;
|
|
76053
|
+
}
|
|
76054
|
+
case 'sort':
|
|
76055
|
+
{
|
|
76056
|
+
const order = new Uint32Array(msgData.order);
|
|
76057
|
+
sort(msgData.sortParams, order, centersData);
|
|
76058
|
+
break;
|
|
76059
|
+
}
|
|
76060
|
+
case 'intervals':
|
|
76061
|
+
{
|
|
76062
|
+
centersData = msgData;
|
|
76063
|
+
break;
|
|
76064
|
+
}
|
|
76065
|
+
}
|
|
76066
|
+
});
|
|
76067
|
+
}
|
|
76068
|
+
|
|
76069
|
+
class GSplatUnifiedSorter extends EventHandler {
|
|
76070
|
+
constructor(){
|
|
76071
|
+
super(), this.bufferLength = 0, this.availableOrderData = [], this.jobsInFlight = 0, this.hasNewVersion = false, this.centersSet = new Set();
|
|
76072
|
+
const workerSource = `(${UnifiedSortWorker.toString()})()`;
|
|
76073
|
+
if (platform.environment === 'node') {
|
|
76074
|
+
this.worker = new Worker(workerSource, {
|
|
76075
|
+
eval: true
|
|
76076
|
+
});
|
|
76077
|
+
this.worker.on('message', this.onSorted.bind(this));
|
|
76078
|
+
} else {
|
|
76079
|
+
this.worker = new Worker(URL.createObjectURL(new Blob([
|
|
76080
|
+
workerSource
|
|
76081
|
+
], {
|
|
76082
|
+
type: "application/javascript"
|
|
76083
|
+
})));
|
|
76084
|
+
this.worker.addEventListener('message', this.onSorted.bind(this));
|
|
76085
|
+
}
|
|
76086
|
+
}
|
|
76087
|
+
onSorted(message) {
|
|
76088
|
+
const msgData = message.data ?? message;
|
|
76089
|
+
const orderData = new Uint32Array(msgData.order);
|
|
76090
|
+
this.jobsInFlight--;
|
|
76091
|
+
this.fire('sorted', msgData.count, msgData.version, orderData);
|
|
76092
|
+
if (orderData.length === this.bufferLength) {
|
|
76093
|
+
this.availableOrderData.push(orderData);
|
|
76094
|
+
}
|
|
76095
|
+
}
|
|
76096
|
+
destroy() {
|
|
76097
|
+
this.worker.terminate();
|
|
76098
|
+
this.worker = null;
|
|
76099
|
+
}
|
|
76100
|
+
setCenters(id, centers) {
|
|
76101
|
+
if (centers) {
|
|
76102
|
+
if (!this.centersSet.has(id)) {
|
|
76103
|
+
this.centersSet.add(id);
|
|
76104
|
+
const centersBuffer = centers.buffer.slice();
|
|
76105
|
+
this.worker.postMessage({
|
|
76106
|
+
command: 'addCenters',
|
|
76107
|
+
id: id,
|
|
76108
|
+
centers: centersBuffer
|
|
76109
|
+
}, [
|
|
76110
|
+
centersBuffer
|
|
76111
|
+
]);
|
|
76112
|
+
}
|
|
76113
|
+
} else {
|
|
76114
|
+
if (this.centersSet.has(id)) {
|
|
76115
|
+
this.centersSet.delete(id);
|
|
76116
|
+
this.worker.postMessage({
|
|
76117
|
+
command: 'removeCenters',
|
|
76118
|
+
id: id
|
|
76119
|
+
});
|
|
76120
|
+
}
|
|
76121
|
+
}
|
|
76122
|
+
}
|
|
76123
|
+
setSortParameters(payload) {
|
|
76124
|
+
this.hasNewVersion = true;
|
|
76125
|
+
const { textureSize } = payload;
|
|
76126
|
+
const newLength = textureSize * textureSize;
|
|
76127
|
+
if (newLength !== this.bufferLength) {
|
|
76128
|
+
this.bufferLength = newLength;
|
|
76129
|
+
this.availableOrderData.length = 0;
|
|
76130
|
+
}
|
|
76131
|
+
this.worker.postMessage(payload);
|
|
76132
|
+
}
|
|
76133
|
+
setSortParams(params) {
|
|
76134
|
+
if (this.hasNewVersion || this.jobsInFlight === 0) {
|
|
76135
|
+
let orderData = this.availableOrderData.pop();
|
|
76136
|
+
if (!orderData) {
|
|
76137
|
+
orderData = new Uint32Array(this.bufferLength);
|
|
76138
|
+
}
|
|
76139
|
+
this.jobsInFlight++;
|
|
76140
|
+
this.hasNewVersion = false;
|
|
76141
|
+
this.worker.postMessage({
|
|
76142
|
+
command: 'sort',
|
|
76143
|
+
sortParams: params,
|
|
76144
|
+
order: orderData.buffer
|
|
76145
|
+
}, [
|
|
76146
|
+
orderData.buffer
|
|
76147
|
+
]);
|
|
76148
|
+
}
|
|
76149
|
+
}
|
|
76150
|
+
}
|
|
76151
|
+
|
|
76152
|
+
const _viewMat = new Mat4();
|
|
76153
|
+
const colorizeLod = false;
|
|
76154
|
+
class GSplatWorkBufferRenderPass extends RenderPass {
|
|
76155
|
+
init(renderTarget) {
|
|
76156
|
+
super.init(renderTarget);
|
|
76157
|
+
this.colorOps.clear = false;
|
|
76158
|
+
this.depthStencilOps.clearDepth = false;
|
|
76159
|
+
}
|
|
76160
|
+
update(splats, cameraNode) {
|
|
76161
|
+
this.splats.length = 0;
|
|
76162
|
+
for(let i = 0; i < splats.length; i++){
|
|
76163
|
+
const splatInfo = splats[i];
|
|
76164
|
+
if (splatInfo.activeSplats > 0) {
|
|
76165
|
+
this.splats.push(splatInfo);
|
|
76166
|
+
}
|
|
76167
|
+
}
|
|
76168
|
+
this.cameraNode = cameraNode;
|
|
76169
|
+
return this.splats.length > 0;
|
|
76170
|
+
}
|
|
76171
|
+
execute() {
|
|
76172
|
+
const { device, splats, cameraNode } = this;
|
|
76173
|
+
device.setBlendState(BlendState.NOBLEND);
|
|
76174
|
+
device.setCullMode(CULLFACE_NONE);
|
|
76175
|
+
device.setDepthState(DepthState.NODEPTH);
|
|
76176
|
+
device.setStencilState();
|
|
76177
|
+
const viewInvMat = cameraNode.getWorldTransform();
|
|
76178
|
+
const viewMat = _viewMat.copy(viewInvMat).invert();
|
|
76179
|
+
device.scope.resolve('matrix_view').setValue(viewMat.data);
|
|
76180
|
+
for(let i = 0; i < splats.length; i++){
|
|
76181
|
+
this.renderSplat(splats[i]);
|
|
76182
|
+
}
|
|
76183
|
+
}
|
|
76184
|
+
renderSplat(splatInfo) {
|
|
76185
|
+
const { device, resource } = splatInfo;
|
|
76186
|
+
const scope = device.scope;
|
|
76187
|
+
const { intervals, activeSplats, lineStart, viewport, intervalTexture } = splatInfo;
|
|
76188
|
+
const workBufferRenderInfo = resource.getWorkBufferRenderInfo(intervals.length > 0, colorizeLod);
|
|
76189
|
+
workBufferRenderInfo.material.setParameters(device);
|
|
76190
|
+
scope.resolve('uTransform').setValue(splatInfo.node.getWorldTransform().data);
|
|
76191
|
+
if (intervalTexture.texture) {
|
|
76192
|
+
scope.resolve('uIntervalsTexture').setValue(intervalTexture.texture);
|
|
76193
|
+
}
|
|
76194
|
+
scope.resolve('uActiveSplats').setValue(activeSplats);
|
|
76195
|
+
scope.resolve('uStartLine').setValue(lineStart);
|
|
76196
|
+
scope.resolve('uViewportWidth').setValue(viewport.z);
|
|
76197
|
+
scope.resolve('matrix_model').setValue(splatInfo.node.getWorldTransform().data);
|
|
76198
|
+
workBufferRenderInfo.quadRender.render(viewport);
|
|
76199
|
+
}
|
|
76200
|
+
destroy() {
|
|
76201
|
+
this.splats.length = 0;
|
|
76202
|
+
super.destroy();
|
|
76203
|
+
}
|
|
76204
|
+
constructor(...args){
|
|
76205
|
+
super(...args), this.splats = [];
|
|
76206
|
+
}
|
|
76207
|
+
}
|
|
76208
|
+
|
|
76209
|
+
let id = 0;
|
|
76210
|
+
class GSplatWorkBuffer {
|
|
76211
|
+
constructor(device){
|
|
76212
|
+
this.id = id++;
|
|
76213
|
+
this.device = device;
|
|
76214
|
+
this.colorTexture = this.createTexture('splatColor', PIXELFORMAT_RGBA16F, 1, 1);
|
|
76215
|
+
this.covATexture = this.createTexture('covA', PIXELFORMAT_RGBA16F, 1, 1);
|
|
76216
|
+
this.covBTexture = this.createTexture('covB', PIXELFORMAT_RGBA16F, 1, 1);
|
|
76217
|
+
this.centerTexture = this.createTexture('center', PIXELFORMAT_RGBA16F, 1, 1);
|
|
76218
|
+
this.renderTarget = new RenderTarget({
|
|
76219
|
+
name: `GsplatWorkBuffer-MRT-${this.id}`,
|
|
76220
|
+
colorBuffers: [
|
|
76221
|
+
this.colorTexture,
|
|
76222
|
+
this.centerTexture,
|
|
76223
|
+
this.covATexture,
|
|
76224
|
+
this.covBTexture
|
|
76225
|
+
],
|
|
76226
|
+
depth: false,
|
|
76227
|
+
flipY: true
|
|
76228
|
+
});
|
|
76229
|
+
this.orderTexture = this.createTexture('SplatGlobalOrder', PIXELFORMAT_R32U, 1, 1);
|
|
76230
|
+
this.renderPass = new GSplatWorkBufferRenderPass(device);
|
|
76231
|
+
this.renderPass.init(this.renderTarget);
|
|
76232
|
+
}
|
|
76233
|
+
destroy() {
|
|
76234
|
+
this.renderPass?.destroy();
|
|
76235
|
+
this.colorTexture?.destroy();
|
|
76236
|
+
this.covATexture?.destroy();
|
|
76237
|
+
this.covBTexture?.destroy();
|
|
76238
|
+
this.centerTexture?.destroy();
|
|
76239
|
+
this.orderTexture?.destroy();
|
|
76240
|
+
this.renderTarget?.destroy();
|
|
76241
|
+
}
|
|
76242
|
+
get textureSize() {
|
|
76243
|
+
return this.orderTexture.width;
|
|
76244
|
+
}
|
|
76245
|
+
setOrderData(data) {
|
|
76246
|
+
const len = this.orderTexture.width * this.orderTexture.height;
|
|
76247
|
+
if (len !== data.length) ;
|
|
76248
|
+
this.orderTexture._levels[0] = data;
|
|
76249
|
+
this.orderTexture.upload();
|
|
76250
|
+
}
|
|
76251
|
+
createTexture(name, format, w, h) {
|
|
76252
|
+
return new Texture(this.device, {
|
|
76253
|
+
name: name,
|
|
76254
|
+
width: w,
|
|
76255
|
+
height: h,
|
|
76256
|
+
format: format,
|
|
76257
|
+
cubemap: false,
|
|
76258
|
+
mipmaps: false,
|
|
76259
|
+
minFilter: FILTER_NEAREST,
|
|
76260
|
+
magFilter: FILTER_NEAREST,
|
|
76261
|
+
addressU: ADDRESS_CLAMP_TO_EDGE,
|
|
76262
|
+
addressV: ADDRESS_CLAMP_TO_EDGE
|
|
76263
|
+
});
|
|
76264
|
+
}
|
|
76265
|
+
resize(textureSize) {
|
|
76266
|
+
this.renderTarget.resize(textureSize, textureSize);
|
|
76267
|
+
this.orderTexture.resize(textureSize, textureSize);
|
|
76268
|
+
}
|
|
76269
|
+
render(splats, cameraNode) {
|
|
76270
|
+
if (this.renderPass.update(splats, cameraNode)) {
|
|
76271
|
+
this.renderPass.render();
|
|
76272
|
+
}
|
|
76273
|
+
}
|
|
76274
|
+
}
|
|
76275
|
+
|
|
76276
|
+
class GSplatRenderer {
|
|
76277
|
+
constructor(device, node, cameraNode, layer, workBuffer){
|
|
76278
|
+
this.maxNumSplats = 0;
|
|
76279
|
+
this.instanceIndices = null;
|
|
76280
|
+
this.viewportParams = [
|
|
76281
|
+
0,
|
|
76282
|
+
0
|
|
76283
|
+
];
|
|
76284
|
+
this.device = device;
|
|
76285
|
+
this.node = node;
|
|
76286
|
+
this.cameraNode = cameraNode;
|
|
76287
|
+
this.layer = layer;
|
|
76288
|
+
this.workBuffer = workBuffer;
|
|
76289
|
+
this._material = new ShaderMaterial({
|
|
76290
|
+
uniqueName: 'UnifiedSplatMaterial',
|
|
76291
|
+
vertexGLSL: '#include "gsplatVS"',
|
|
76292
|
+
fragmentGLSL: '#include "gsplatPS"',
|
|
76293
|
+
vertexWGSL: '#include "gsplatVS"',
|
|
76294
|
+
fragmentWGSL: '#include "gsplatPS"',
|
|
76295
|
+
attributes: {
|
|
76296
|
+
vertex_position: SEMANTIC_POSITION,
|
|
76297
|
+
vertex_id_attrib: SEMANTIC_ATTR13
|
|
76298
|
+
}
|
|
76299
|
+
});
|
|
76300
|
+
this._material.setDefine('GSPLAT_WORKBUFFER_DATA', true);
|
|
76301
|
+
this._material.setParameter('splatColor', workBuffer.colorTexture);
|
|
76302
|
+
this._material.setParameter('covA', workBuffer.covATexture);
|
|
76303
|
+
this._material.setParameter('covB', workBuffer.covBTexture);
|
|
76304
|
+
this._material.setParameter('center', workBuffer.centerTexture);
|
|
76305
|
+
this._material.setDefine('SH_BANDS', '0');
|
|
76306
|
+
this._material.setParameter('numSplats', 0);
|
|
76307
|
+
this._material.setParameter('splatOrder', workBuffer.orderTexture);
|
|
76308
|
+
this._material.setParameter('alphaClip', 0.3);
|
|
76309
|
+
this._material.setDefine(`DITHER_${'NONE'}`, '');
|
|
76310
|
+
this._material.cull = CULLFACE_NONE;
|
|
76311
|
+
this._material.blendType = BLEND_PREMULTIPLIED;
|
|
76312
|
+
this._material.depthWrite = false;
|
|
76313
|
+
this._material.update();
|
|
76314
|
+
this.meshInstance = this.createMeshInstance();
|
|
76315
|
+
layer.addMeshInstances([
|
|
76316
|
+
this.meshInstance
|
|
76317
|
+
]);
|
|
76318
|
+
}
|
|
76319
|
+
destroy() {
|
|
76320
|
+
this.layer.removeMeshInstances([
|
|
76321
|
+
this.meshInstance
|
|
76322
|
+
]);
|
|
76323
|
+
this._material.destroy();
|
|
76324
|
+
this.meshInstance.destroy();
|
|
76325
|
+
}
|
|
76326
|
+
setNumSplats(count) {
|
|
76327
|
+
this.meshInstance.instancingCount = Math.ceil(count / GSplatResourceBase.instanceSize);
|
|
76328
|
+
this._material.setParameter('numSplats', count);
|
|
76329
|
+
this.meshInstance.visible = count > 0;
|
|
76330
|
+
}
|
|
76331
|
+
setMaxNumSplats(numSplats) {
|
|
76332
|
+
if (this.maxNumSplats !== numSplats) {
|
|
76333
|
+
this.maxNumSplats = numSplats;
|
|
76334
|
+
this.instanceIndices?.destroy();
|
|
76335
|
+
this.instanceIndices = GSplatResourceBase.createInstanceIndices(this.device, numSplats);
|
|
76336
|
+
this.meshInstance.setInstancing(this.instanceIndices, true);
|
|
76337
|
+
}
|
|
76338
|
+
}
|
|
76339
|
+
createMeshInstance() {
|
|
76340
|
+
const mesh = GSplatResourceBase.createMesh(this.device);
|
|
76341
|
+
const textureSize = this.workBuffer.textureSize;
|
|
76342
|
+
const instanceIndices = GSplatResourceBase.createInstanceIndices(this.device, textureSize * textureSize);
|
|
76343
|
+
const meshInstance = new MeshInstance(mesh, this._material);
|
|
76344
|
+
meshInstance.node = this.node;
|
|
76345
|
+
meshInstance.setInstancing(instanceIndices, true);
|
|
76346
|
+
meshInstance.instancingCount = 0;
|
|
76347
|
+
const thisCamera = this.cameraNode.camera;
|
|
76348
|
+
meshInstance.isVisibleFunc = (camera)=>{
|
|
76349
|
+
const vis = thisCamera.camera === camera;
|
|
76350
|
+
return vis;
|
|
76351
|
+
};
|
|
76352
|
+
return meshInstance;
|
|
76353
|
+
}
|
|
76354
|
+
updateViewport(cameraNode) {
|
|
76355
|
+
const camera = cameraNode.camera;
|
|
76356
|
+
const cameraRect = camera.rect;
|
|
76357
|
+
const renderTarget = camera?.renderTarget;
|
|
76358
|
+
const { width, height } = renderTarget ?? this.device;
|
|
76359
|
+
const viewport = this.viewportParams;
|
|
76360
|
+
viewport[0] = width * cameraRect.z;
|
|
76361
|
+
viewport[1] = height * cameraRect.w;
|
|
76362
|
+
const xr = camera?.camera?.xr;
|
|
76363
|
+
if (xr?.active && xr.views.list.length === 2) {
|
|
76364
|
+
viewport[0] *= 0.5;
|
|
76365
|
+
}
|
|
76366
|
+
this._material.setParameter('viewport', viewport);
|
|
76367
|
+
}
|
|
76368
|
+
}
|
|
76369
|
+
|
|
76370
|
+
class GSplatPlacement {
|
|
76371
|
+
constructor(resource, node, lodIndex = 0){
|
|
76372
|
+
this.intervals = new Map();
|
|
76373
|
+
this.lodIndex = 0;
|
|
76374
|
+
this._aabb = new BoundingBox();
|
|
76375
|
+
this.resource = resource;
|
|
76376
|
+
this.node = node;
|
|
76377
|
+
this.lodIndex = lodIndex;
|
|
76378
|
+
}
|
|
76379
|
+
set aabb(aabb) {
|
|
76380
|
+
this._aabb.copy(aabb);
|
|
76381
|
+
}
|
|
76382
|
+
get aabb() {
|
|
76383
|
+
return this._aabb;
|
|
76384
|
+
}
|
|
76385
|
+
}
|
|
76386
|
+
|
|
76387
|
+
const _invWorldMat = new Mat4();
|
|
76388
|
+
const _localCameraPos = new Vec3();
|
|
76389
|
+
const _tempCompletedUrls = [];
|
|
76390
|
+
class GSplatOctreeInstance {
|
|
76391
|
+
constructor(octree, placement, assetLoader){
|
|
76392
|
+
this.activePlacements = new Set();
|
|
76393
|
+
this.dirtyModifiedPlacements = false;
|
|
76394
|
+
this.pending = new Set();
|
|
76395
|
+
this.pendingDecrements = new Map();
|
|
76396
|
+
this.previousPosition = new Vec3();
|
|
76397
|
+
this.octree = octree;
|
|
76398
|
+
this.placement = placement;
|
|
76399
|
+
this.assetLoader = assetLoader;
|
|
76400
|
+
this.nodeLods = new Int32Array(octree.nodes.length);
|
|
76401
|
+
this.nodeLods.fill(-1);
|
|
76402
|
+
const numFiles = octree.files.length;
|
|
76403
|
+
this.filePlacements = new Array(numFiles).fill(null);
|
|
76404
|
+
}
|
|
76405
|
+
destroy() {
|
|
76406
|
+
this.pending.clear();
|
|
76407
|
+
this.pendingDecrements.clear();
|
|
76408
|
+
this.filePlacements.length = 0;
|
|
76409
|
+
}
|
|
76410
|
+
calculateNodeLod(localCameraPosition, nodeIndex, maxLod) {
|
|
76411
|
+
const node = this.octree.nodes[nodeIndex];
|
|
76412
|
+
const distance = localCameraPosition.distance(node.bounds.center);
|
|
76413
|
+
const lodDistances = [
|
|
76414
|
+
2,
|
|
76415
|
+
4,
|
|
76416
|
+
6,
|
|
76417
|
+
8,
|
|
76418
|
+
10
|
|
76419
|
+
];
|
|
76420
|
+
for(let lod = 0; lod < maxLod; lod++){
|
|
76421
|
+
if (distance < lodDistances[lod]) {
|
|
76422
|
+
return lod;
|
|
76423
|
+
}
|
|
76424
|
+
}
|
|
76425
|
+
return maxLod;
|
|
76426
|
+
}
|
|
76427
|
+
updateLod(cameraNode) {
|
|
76428
|
+
const worldCameraPosition = cameraNode.getPosition();
|
|
76429
|
+
const octreeWorldTransform = this.placement.node.getWorldTransform();
|
|
76430
|
+
_invWorldMat.copy(octreeWorldTransform).invert();
|
|
76431
|
+
const localCameraPosition = _invWorldMat.transformPoint(worldCameraPosition, _localCameraPos);
|
|
76432
|
+
const maxLod = this.octree.lodLevels - 1;
|
|
76433
|
+
const nodes = this.octree.nodes;
|
|
76434
|
+
for(let nodeIndex = 0; nodeIndex < nodes.length; nodeIndex++){
|
|
76435
|
+
const node = nodes[nodeIndex];
|
|
76436
|
+
const newLodIndex = this.calculateNodeLod(localCameraPosition, nodeIndex, maxLod);
|
|
76437
|
+
const currentLodIndex = this.nodeLods[nodeIndex];
|
|
76438
|
+
if (newLodIndex !== currentLodIndex) {
|
|
76439
|
+
const pendingOldFileIndex = this.pendingDecrements.get(nodeIndex);
|
|
76440
|
+
if (pendingOldFileIndex !== undefined) {
|
|
76441
|
+
this.decrementFileRef(pendingOldFileIndex, nodeIndex);
|
|
76442
|
+
this.pendingDecrements.delete(nodeIndex);
|
|
76443
|
+
}
|
|
76444
|
+
this.nodeLods[nodeIndex] = newLodIndex;
|
|
76445
|
+
const wasVisible = currentLodIndex >= 0;
|
|
76446
|
+
const willBeVisible = newLodIndex >= 0;
|
|
76447
|
+
if (!wasVisible && willBeVisible) {
|
|
76448
|
+
const newFileIndex = node.lods[newLodIndex].fileIndex;
|
|
76449
|
+
this.incrementFileRef(newFileIndex, nodeIndex, newLodIndex);
|
|
76450
|
+
} else if (wasVisible && !willBeVisible) {
|
|
76451
|
+
const oldFileIndex = node.lods[currentLodIndex].fileIndex;
|
|
76452
|
+
this.decrementFileRef(oldFileIndex, nodeIndex);
|
|
76453
|
+
} else if (wasVisible && willBeVisible) {
|
|
76454
|
+
const newFileIndex = node.lods[newLodIndex].fileIndex;
|
|
76455
|
+
const oldFileIndex = node.lods[currentLodIndex].fileIndex;
|
|
76456
|
+
this.incrementFileRef(newFileIndex, nodeIndex, newLodIndex);
|
|
76457
|
+
const newPlacement = this.filePlacements[newFileIndex];
|
|
76458
|
+
if (newPlacement?.resource) {
|
|
76459
|
+
this.decrementFileRef(oldFileIndex, nodeIndex);
|
|
76460
|
+
} else {
|
|
76461
|
+
this.pendingDecrements.set(nodeIndex, oldFileIndex);
|
|
76462
|
+
}
|
|
76463
|
+
}
|
|
76464
|
+
}
|
|
76465
|
+
}
|
|
76466
|
+
}
|
|
76467
|
+
incrementFileRef(fileIndex, nodeIndex, lodIndex) {
|
|
76468
|
+
if (fileIndex === -1) return;
|
|
76469
|
+
let placement = this.filePlacements[fileIndex];
|
|
76470
|
+
if (!placement) {
|
|
76471
|
+
placement = new GSplatPlacement(null, this.placement.node, lodIndex);
|
|
76472
|
+
this.filePlacements[fileIndex] = placement;
|
|
76473
|
+
if (!this.addFilePlacement(fileIndex)) {
|
|
76474
|
+
const fileUrl = this.octree.files[fileIndex];
|
|
76475
|
+
this.octree.ensureFileResource(fileUrl, this.assetLoader);
|
|
76476
|
+
this.pending.add(fileIndex);
|
|
76477
|
+
}
|
|
76478
|
+
}
|
|
76479
|
+
const nodes = this.octree.nodes;
|
|
76480
|
+
const node = nodes[nodeIndex];
|
|
76481
|
+
const lod = node.lods[lodIndex];
|
|
76482
|
+
const interval = new Vec2(lod.offset, lod.offset + lod.count - 1);
|
|
76483
|
+
placement.intervals.set(nodeIndex, interval);
|
|
76484
|
+
this.dirtyModifiedPlacements = true;
|
|
76485
|
+
}
|
|
76486
|
+
decrementFileRef(fileIndex, nodeIndex) {
|
|
76487
|
+
if (fileIndex === -1) return;
|
|
76488
|
+
const placement = this.filePlacements[fileIndex];
|
|
76489
|
+
if (placement) {
|
|
76490
|
+
placement.intervals.delete(nodeIndex);
|
|
76491
|
+
this.dirtyModifiedPlacements = true;
|
|
76492
|
+
if (placement.intervals.size === 0) {
|
|
76493
|
+
if (placement.resource) {
|
|
76494
|
+
this.activePlacements.delete(placement);
|
|
76495
|
+
}
|
|
76496
|
+
this.filePlacements[fileIndex] = null;
|
|
76497
|
+
this.pending.delete(fileIndex);
|
|
76498
|
+
}
|
|
76499
|
+
}
|
|
76500
|
+
}
|
|
76501
|
+
addFilePlacement(fileIndex) {
|
|
76502
|
+
const fileUrl = this.octree.files[fileIndex];
|
|
76503
|
+
const res = this.octree.getFileResource(fileUrl);
|
|
76504
|
+
if (res) {
|
|
76505
|
+
const placement = this.filePlacements[fileIndex];
|
|
76506
|
+
if (placement) {
|
|
76507
|
+
placement.resource = res;
|
|
76508
|
+
placement.aabb.copy(res.aabb);
|
|
76509
|
+
this.activePlacements.add(placement);
|
|
76510
|
+
this.dirtyModifiedPlacements = true;
|
|
76511
|
+
return true;
|
|
76512
|
+
}
|
|
76513
|
+
}
|
|
76514
|
+
return false;
|
|
76515
|
+
}
|
|
76516
|
+
testMoved() {
|
|
76517
|
+
const position = this.placement.node.getPosition();
|
|
76518
|
+
const length = position.distance(this.previousPosition);
|
|
76519
|
+
if (length > 1) {
|
|
76520
|
+
this.previousPosition.copy(position);
|
|
76521
|
+
return true;
|
|
76522
|
+
}
|
|
76523
|
+
return false;
|
|
76524
|
+
}
|
|
76525
|
+
update() {
|
|
76526
|
+
if (this.pending.size) {
|
|
76527
|
+
for (const fileIndex of this.pending){
|
|
76528
|
+
const fileUrl = this.octree.files[fileIndex];
|
|
76529
|
+
this.octree.ensureFileResource(fileUrl, this.assetLoader);
|
|
76530
|
+
const placement = this.filePlacements[fileIndex];
|
|
76531
|
+
if (placement && placement.intervals.size > 0 && this.addFilePlacement(fileIndex)) {
|
|
76532
|
+
_tempCompletedUrls.push(fileIndex);
|
|
76533
|
+
for (const [nodeIndex] of placement.intervals){
|
|
76534
|
+
const oldFileIndex = this.pendingDecrements.get(nodeIndex);
|
|
76535
|
+
if (oldFileIndex !== undefined) {
|
|
76536
|
+
this.decrementFileRef(oldFileIndex, nodeIndex);
|
|
76537
|
+
this.pendingDecrements.delete(nodeIndex);
|
|
76538
|
+
}
|
|
76539
|
+
}
|
|
76540
|
+
}
|
|
76541
|
+
}
|
|
76542
|
+
for (const fileIndex of _tempCompletedUrls){
|
|
76543
|
+
this.pending.delete(fileIndex);
|
|
76544
|
+
}
|
|
76545
|
+
_tempCompletedUrls.length = 0;
|
|
76546
|
+
}
|
|
76547
|
+
const dirty = this.dirtyModifiedPlacements;
|
|
76548
|
+
this.dirtyModifiedPlacements = false;
|
|
76549
|
+
return dirty;
|
|
76550
|
+
}
|
|
76551
|
+
}
|
|
76552
|
+
|
|
76553
|
+
const tmpMin = new Vec3();
|
|
76554
|
+
const tmpMax = new Vec3();
|
|
76555
|
+
class GSplatOctreeNode {
|
|
76556
|
+
constructor(lods, boundData){
|
|
76557
|
+
this.bounds = new BoundingBox();
|
|
76558
|
+
this.lods = lods;
|
|
76559
|
+
tmpMin.set(boundData.min[0], boundData.min[1], boundData.min[2]);
|
|
76560
|
+
tmpMax.set(boundData.max[0], boundData.max[1], boundData.max[2]);
|
|
76561
|
+
this.bounds.setMinMax(tmpMin, tmpMax);
|
|
76562
|
+
}
|
|
76563
|
+
}
|
|
76564
|
+
|
|
76565
|
+
class GSplatOctree {
|
|
76566
|
+
constructor(assetFileUrl, data){
|
|
76567
|
+
this.fileResources = new Map();
|
|
76568
|
+
this.files = data.filenames;
|
|
76569
|
+
this.lodLevels = data.lodLevels;
|
|
76570
|
+
this.assetFileUrl = assetFileUrl;
|
|
76571
|
+
this.baseDir = path.getDirectory(assetFileUrl);
|
|
76572
|
+
const leafNodes = [];
|
|
76573
|
+
this._extractLeafNodes(data.tree, leafNodes);
|
|
76574
|
+
this.nodes = leafNodes.map((nodeData)=>{
|
|
76575
|
+
const lods = [];
|
|
76576
|
+
for(let i = 0; i < this.lodLevels; i++){
|
|
76577
|
+
const lodData = nodeData.lods[i.toString()];
|
|
76578
|
+
if (lodData) {
|
|
76579
|
+
lods.push({
|
|
76580
|
+
file: this.files[lodData.file] || '',
|
|
76581
|
+
fileIndex: lodData.file,
|
|
76582
|
+
offset: lodData.offset || 0,
|
|
76583
|
+
count: lodData.count || 0
|
|
76584
|
+
});
|
|
76585
|
+
} else {
|
|
76586
|
+
lods.push({
|
|
76587
|
+
file: '',
|
|
76588
|
+
fileIndex: -1,
|
|
76589
|
+
offset: 0,
|
|
76590
|
+
count: 0
|
|
76591
|
+
});
|
|
76592
|
+
}
|
|
76593
|
+
}
|
|
76594
|
+
return new GSplatOctreeNode(lods, nodeData.bound);
|
|
76595
|
+
});
|
|
76596
|
+
}
|
|
76597
|
+
_extractLeafNodes(node, leafNodes) {
|
|
76598
|
+
if (node.lods) {
|
|
76599
|
+
leafNodes.push({
|
|
76600
|
+
lods: node.lods,
|
|
76601
|
+
bound: node.bound
|
|
76602
|
+
});
|
|
76603
|
+
} else if (node.children) {
|
|
76604
|
+
for (const child of node.children){
|
|
76605
|
+
this._extractLeafNodes(child, leafNodes);
|
|
76606
|
+
}
|
|
76607
|
+
}
|
|
76608
|
+
}
|
|
76609
|
+
getFullUrl(url) {
|
|
76610
|
+
return path.join(this.baseDir, url);
|
|
76611
|
+
}
|
|
76612
|
+
getFileResource(url) {
|
|
76613
|
+
return this.fileResources.get(url);
|
|
76614
|
+
}
|
|
76615
|
+
ensureFileResource(url, assetLoader) {
|
|
76616
|
+
if (this.fileResources.has(url)) {
|
|
76617
|
+
return;
|
|
76618
|
+
}
|
|
76619
|
+
const fullUrl = this.getFullUrl(url);
|
|
76620
|
+
const res = assetLoader.getResource(fullUrl);
|
|
76621
|
+
if (res) {
|
|
76622
|
+
this.fileResources.set(url, res);
|
|
76623
|
+
return;
|
|
76624
|
+
}
|
|
76625
|
+
assetLoader.load(fullUrl);
|
|
76626
|
+
}
|
|
76627
|
+
}
|
|
76628
|
+
|
|
76629
|
+
class GSplatOctreeResource {
|
|
76630
|
+
constructor(assetFileUrl, data){
|
|
76631
|
+
this.aabb = new BoundingBox();
|
|
76632
|
+
this.octree = new GSplatOctree(assetFileUrl, data);
|
|
76633
|
+
this.aabb.setMinMax(new Vec3(data.tree.bound.min), new Vec3(data.tree.bound.max));
|
|
76634
|
+
}
|
|
76635
|
+
}
|
|
76636
|
+
|
|
76637
|
+
class GSplatWorldState {
|
|
76638
|
+
constructor(device, version, splats){
|
|
76639
|
+
this.version = 0;
|
|
76640
|
+
this.sortParametersSet = false;
|
|
76641
|
+
this.sortedBefore = false;
|
|
76642
|
+
this.splats = [];
|
|
76643
|
+
this.textureSize = 0;
|
|
76644
|
+
this.totalUsedPixels = 0;
|
|
76645
|
+
this.version = version;
|
|
76646
|
+
this.splats = splats;
|
|
76647
|
+
this.estimateTextureSize(this.splats, device.maxTextureSize);
|
|
76648
|
+
this.assignLines(this.splats, this.textureSize);
|
|
76649
|
+
}
|
|
76650
|
+
estimateTextureSize(splats, maxSize) {
|
|
76651
|
+
const fits = (size)=>{
|
|
76652
|
+
let rows = 0;
|
|
76653
|
+
for (const splat of splats){
|
|
76654
|
+
rows += Math.ceil(splat.activeSplats / size);
|
|
76655
|
+
if (rows > size) return false;
|
|
76656
|
+
}
|
|
76657
|
+
return true;
|
|
76658
|
+
};
|
|
76659
|
+
let low = 1;
|
|
76660
|
+
let high = maxSize;
|
|
76661
|
+
let bestSize = null;
|
|
76662
|
+
while(low <= high){
|
|
76663
|
+
const mid = Math.floor((low + high) / 2);
|
|
76664
|
+
if (fits(mid)) {
|
|
76665
|
+
bestSize = mid;
|
|
76666
|
+
high = mid - 1;
|
|
76667
|
+
} else {
|
|
76668
|
+
low = mid + 1;
|
|
76669
|
+
}
|
|
76670
|
+
}
|
|
76671
|
+
if (bestSize === null) {
|
|
76672
|
+
this.textureSize = 0;
|
|
76673
|
+
return false;
|
|
76674
|
+
}
|
|
76675
|
+
this.textureSize = bestSize;
|
|
76676
|
+
return true;
|
|
76677
|
+
}
|
|
76678
|
+
destroy() {
|
|
76679
|
+
this.splats.forEach((splat)=>splat.destroy());
|
|
76680
|
+
this.splats.length = 0;
|
|
76681
|
+
}
|
|
76682
|
+
assignLines(splats, size) {
|
|
76683
|
+
if (splats.length === 0) {
|
|
76684
|
+
this.totalUsedPixels = 0;
|
|
76685
|
+
return;
|
|
76686
|
+
}
|
|
76687
|
+
let start = 0;
|
|
76688
|
+
for (const splat of splats){
|
|
76689
|
+
const activeSplats = splat.activeSplats;
|
|
76690
|
+
const numLines = Math.ceil(activeSplats / size);
|
|
76691
|
+
splat.setLines(start, numLines, size, activeSplats);
|
|
76692
|
+
start += numLines;
|
|
76693
|
+
}
|
|
76694
|
+
this.totalUsedPixels = start * size;
|
|
76695
|
+
}
|
|
76696
|
+
}
|
|
76697
|
+
|
|
76698
|
+
const cameraPosition = new Vec3();
|
|
76699
|
+
const cameraDirection = new Vec3();
|
|
76700
|
+
const translation = new Vec3();
|
|
76701
|
+
const invModelMat = new Mat4();
|
|
76702
|
+
const tempNonOctreePlacements = new Set();
|
|
76703
|
+
const tempOctreePlacements = new Set();
|
|
76704
|
+
const _updatedSplats = [];
|
|
76705
|
+
class GSplatManager {
|
|
76706
|
+
constructor(device, director, layer, cameraNode){
|
|
76707
|
+
this.node = new GraphNode('GSplatManager');
|
|
76708
|
+
this.worldStates = new Map();
|
|
76709
|
+
this.lastWorldStateVersion = 0;
|
|
76710
|
+
this.sortedVersion = 0;
|
|
76711
|
+
this.lastCameraPos = new Vec3(Infinity, Infinity, Infinity);
|
|
76712
|
+
this.layerPlacements = [];
|
|
76713
|
+
this.layerPlacementsDirty = false;
|
|
76714
|
+
this.octreeInstances = new Map();
|
|
76715
|
+
this.device = device;
|
|
76716
|
+
this.director = director;
|
|
76717
|
+
this.cameraNode = cameraNode;
|
|
76718
|
+
this.workBuffer = new GSplatWorkBuffer(device);
|
|
76719
|
+
this.renderer = new GSplatRenderer(device, this.node, this.cameraNode, layer, this.workBuffer);
|
|
76720
|
+
this.sorter = this.createSorter();
|
|
76721
|
+
}
|
|
76722
|
+
destroy() {
|
|
76723
|
+
this.workBuffer.destroy();
|
|
76724
|
+
this.renderer.destroy();
|
|
76725
|
+
this.sorter.destroy();
|
|
76726
|
+
}
|
|
76727
|
+
createSorter() {
|
|
76728
|
+
const sorter = new GSplatUnifiedSorter();
|
|
76729
|
+
sorter.on('sorted', (count, version, orderData)=>{
|
|
76730
|
+
this.onSorted(count, version, orderData);
|
|
76731
|
+
});
|
|
76732
|
+
return sorter;
|
|
76733
|
+
}
|
|
76734
|
+
reconcile(placements) {
|
|
76735
|
+
tempNonOctreePlacements.clear();
|
|
76736
|
+
for (const p of placements){
|
|
76737
|
+
if (p.resource instanceof GSplatOctreeResource) {
|
|
76738
|
+
if (!this.octreeInstances.has(p)) {
|
|
76739
|
+
this.octreeInstances.set(p, new GSplatOctreeInstance(p.resource.octree, p, this.director.assetLoader));
|
|
76740
|
+
}
|
|
76741
|
+
tempOctreePlacements.add(p);
|
|
76742
|
+
} else {
|
|
76743
|
+
tempNonOctreePlacements.add(p);
|
|
76744
|
+
}
|
|
76745
|
+
}
|
|
76746
|
+
for (const [placement, inst] of this.octreeInstances){
|
|
76747
|
+
if (!tempOctreePlacements.has(placement)) {
|
|
76748
|
+
this.octreeInstances.delete(placement);
|
|
76749
|
+
inst.destroy();
|
|
76750
|
+
}
|
|
76751
|
+
}
|
|
76752
|
+
this.layerPlacementsDirty = this.layerPlacements.length !== tempNonOctreePlacements.size;
|
|
76753
|
+
if (!this.layerPlacementsDirty) {
|
|
76754
|
+
for(let i = 0; i < this.layerPlacements.length; i++){
|
|
76755
|
+
const existing = this.layerPlacements[i];
|
|
76756
|
+
if (!tempNonOctreePlacements.has(existing)) {
|
|
76757
|
+
this.layerPlacementsDirty = true;
|
|
76758
|
+
break;
|
|
76759
|
+
}
|
|
76760
|
+
}
|
|
76761
|
+
}
|
|
76762
|
+
this.layerPlacements.length = 0;
|
|
76763
|
+
for (const p of tempNonOctreePlacements){
|
|
76764
|
+
this.layerPlacements.push(p);
|
|
76765
|
+
}
|
|
76766
|
+
tempNonOctreePlacements.clear();
|
|
76767
|
+
tempOctreePlacements.clear();
|
|
76768
|
+
}
|
|
76769
|
+
updateWorldState() {
|
|
76770
|
+
for (const [, inst] of this.octreeInstances){
|
|
76771
|
+
this.layerPlacementsDirty ||= inst.update();
|
|
76772
|
+
}
|
|
76773
|
+
const worldChanged = this.layerPlacementsDirty || this.worldStates.size === 0;
|
|
76774
|
+
if (worldChanged) {
|
|
76775
|
+
this.lastWorldStateVersion++;
|
|
76776
|
+
const splats = [];
|
|
76777
|
+
for (const p of this.layerPlacements){
|
|
76778
|
+
const splatInfo = new GSplatInfo(this.device, p.resource, p);
|
|
76779
|
+
splats.push(splatInfo);
|
|
76780
|
+
}
|
|
76781
|
+
for (const [, inst] of this.octreeInstances){
|
|
76782
|
+
inst.activePlacements.forEach((p)=>{
|
|
76783
|
+
splats.push(new GSplatInfo(this.device, p.resource, p));
|
|
76784
|
+
});
|
|
76785
|
+
}
|
|
76786
|
+
splats.forEach((splat)=>{
|
|
76787
|
+
this.sorter.setCenters(splat.resource.id, splat.resource.centers);
|
|
76788
|
+
});
|
|
76789
|
+
const newState = new GSplatWorldState(this.device, this.lastWorldStateVersion, splats);
|
|
76790
|
+
this.worldStates.set(this.lastWorldStateVersion, newState);
|
|
76791
|
+
this.layerPlacementsDirty = false;
|
|
76792
|
+
}
|
|
76793
|
+
}
|
|
76794
|
+
onSorted(count, version, orderData) {
|
|
76795
|
+
this.sortedVersion = version;
|
|
76796
|
+
const oldState = this.worldStates.get(version - 1);
|
|
76797
|
+
if (oldState) {
|
|
76798
|
+
this.worldStates.delete(version - 1);
|
|
76799
|
+
oldState.destroy();
|
|
76800
|
+
}
|
|
76801
|
+
const worldState = this.worldStates.get(version);
|
|
76802
|
+
if (worldState) {
|
|
76803
|
+
if (!worldState.sortedBefore) {
|
|
76804
|
+
worldState.sortedBefore = true;
|
|
76805
|
+
const textureSize = worldState.textureSize;
|
|
76806
|
+
if (textureSize !== this.workBuffer.textureSize) {
|
|
76807
|
+
this.workBuffer.resize(textureSize);
|
|
76808
|
+
this.renderer.setMaxNumSplats(textureSize * textureSize);
|
|
76809
|
+
}
|
|
76810
|
+
this.workBuffer.render(worldState.splats, this.cameraNode);
|
|
76811
|
+
}
|
|
76812
|
+
this.workBuffer.setOrderData(orderData);
|
|
76813
|
+
this.renderer.setNumSplats(count);
|
|
76814
|
+
}
|
|
76815
|
+
}
|
|
76816
|
+
update(scene) {
|
|
76817
|
+
let anyOctreeMoved = false;
|
|
76818
|
+
for (const [, inst] of this.octreeInstances){
|
|
76819
|
+
anyOctreeMoved ||= inst.testMoved();
|
|
76820
|
+
}
|
|
76821
|
+
const currentCameraPos = this.cameraNode.getPosition();
|
|
76822
|
+
const distance = this.lastCameraPos.distance(currentCameraPos);
|
|
76823
|
+
const cameraMoved = distance > 1.0;
|
|
76824
|
+
if (cameraMoved || anyOctreeMoved) {
|
|
76825
|
+
this.lastCameraPos.copy(currentCameraPos);
|
|
76826
|
+
for (const [, inst] of this.octreeInstances){
|
|
76827
|
+
inst.updateLod(this.cameraNode);
|
|
76828
|
+
}
|
|
76829
|
+
}
|
|
76830
|
+
this.updateWorldState();
|
|
76831
|
+
const lastState = this.worldStates.get(this.lastWorldStateVersion);
|
|
76832
|
+
if (lastState) {
|
|
76833
|
+
if (!lastState.sortParametersSet) {
|
|
76834
|
+
lastState.sortParametersSet = true;
|
|
76835
|
+
const payload = this.prepareSortParameters(lastState);
|
|
76836
|
+
this.sorter.setSortParameters(payload);
|
|
76837
|
+
}
|
|
76838
|
+
this.sort(lastState);
|
|
76839
|
+
}
|
|
76840
|
+
const sortedState = this.worldStates.get(this.sortedVersion);
|
|
76841
|
+
if (sortedState) {
|
|
76842
|
+
sortedState.splats.forEach((splat)=>{
|
|
76843
|
+
if (splat.update()) {
|
|
76844
|
+
_updatedSplats.push(splat);
|
|
76845
|
+
}
|
|
76846
|
+
});
|
|
76847
|
+
if (_updatedSplats.length > 0) {
|
|
76848
|
+
this.workBuffer.render(_updatedSplats, this.cameraNode);
|
|
76849
|
+
_updatedSplats.length = 0;
|
|
76850
|
+
}
|
|
76851
|
+
}
|
|
76852
|
+
}
|
|
76853
|
+
sort(lastState) {
|
|
76854
|
+
const cameraNode = this.cameraNode;
|
|
76855
|
+
const cameraMat = cameraNode.getWorldTransform();
|
|
76856
|
+
cameraMat.getTranslation(cameraPosition);
|
|
76857
|
+
cameraMat.getZ(cameraDirection).normalize();
|
|
76858
|
+
const sorterRequest = [];
|
|
76859
|
+
lastState.splats.forEach((splat)=>{
|
|
76860
|
+
const modelMat = splat.node.getWorldTransform();
|
|
76861
|
+
invModelMat.copy(modelMat).invert();
|
|
76862
|
+
const uniformScale = modelMat.getScale().x;
|
|
76863
|
+
const transformedDirection = invModelMat.transformVector(cameraDirection).normalize();
|
|
76864
|
+
modelMat.getTranslation(translation);
|
|
76865
|
+
const offset = translation.sub(cameraPosition).dot(cameraDirection);
|
|
76866
|
+
const aabbMin = splat.aabb.getMin();
|
|
76867
|
+
const aabbMax = splat.aabb.getMax();
|
|
76868
|
+
sorterRequest.push({
|
|
76869
|
+
transformedDirection,
|
|
76870
|
+
offset,
|
|
76871
|
+
scale: uniformScale,
|
|
76872
|
+
modelMat: modelMat.data.slice(),
|
|
76873
|
+
aabbMin: [
|
|
76874
|
+
aabbMin.x,
|
|
76875
|
+
aabbMin.y,
|
|
76876
|
+
aabbMin.z
|
|
76877
|
+
],
|
|
76878
|
+
aabbMax: [
|
|
76879
|
+
aabbMax.x,
|
|
76880
|
+
aabbMax.y,
|
|
76881
|
+
aabbMax.z
|
|
76882
|
+
]
|
|
76883
|
+
});
|
|
76884
|
+
});
|
|
76885
|
+
this.sorter.setSortParams(sorterRequest);
|
|
76886
|
+
this.renderer.updateViewport(cameraNode);
|
|
76887
|
+
}
|
|
76888
|
+
prepareSortParameters(worldState) {
|
|
76889
|
+
return {
|
|
76890
|
+
command: 'intervals',
|
|
76891
|
+
textureSize: worldState.textureSize,
|
|
76892
|
+
totalUsedPixels: worldState.totalUsedPixels,
|
|
76893
|
+
version: worldState.version,
|
|
76894
|
+
ids: worldState.splats.map((splat)=>splat.resource.id),
|
|
76895
|
+
lineStarts: worldState.splats.map((splat)=>splat.lineStart),
|
|
76896
|
+
padding: worldState.splats.map((splat)=>splat.padding),
|
|
76897
|
+
intervals: worldState.splats.map((splat)=>splat.intervals)
|
|
76898
|
+
};
|
|
76899
|
+
}
|
|
76900
|
+
}
|
|
76901
|
+
|
|
76902
|
+
class GSplatLayerData {
|
|
76903
|
+
constructor(device, director, layer, cameraNode){
|
|
76904
|
+
this.gsplatManager = new GSplatManager(device, director, layer, cameraNode);
|
|
76905
|
+
}
|
|
76906
|
+
destroy() {
|
|
76907
|
+
this.gsplatManager.destroy();
|
|
76908
|
+
}
|
|
76909
|
+
}
|
|
76910
|
+
class GSplatCameraData {
|
|
76911
|
+
destroy() {
|
|
76912
|
+
this.layersMap.forEach((layerData)=>layerData.destroy());
|
|
76913
|
+
this.layersMap.clear();
|
|
76914
|
+
}
|
|
76915
|
+
removeLayerData(layer) {
|
|
76916
|
+
const layerData = this.layersMap.get(layer);
|
|
76917
|
+
if (layerData) {
|
|
76918
|
+
layerData.destroy();
|
|
76919
|
+
this.layersMap.delete(layer);
|
|
76920
|
+
}
|
|
76921
|
+
}
|
|
76922
|
+
getLayerData(device, director, layer, cameraNode) {
|
|
76923
|
+
let layerData = this.layersMap.get(layer);
|
|
76924
|
+
if (!layerData) {
|
|
76925
|
+
layerData = new GSplatLayerData(device, director, layer, cameraNode);
|
|
76926
|
+
this.layersMap.set(layer, layerData);
|
|
76927
|
+
}
|
|
76928
|
+
return layerData;
|
|
76929
|
+
}
|
|
76930
|
+
constructor(){
|
|
76931
|
+
this.layersMap = new Map();
|
|
76932
|
+
}
|
|
76933
|
+
}
|
|
76934
|
+
class GSplatDirector {
|
|
76935
|
+
constructor(device, scene, assetLoader){
|
|
76936
|
+
this.camerasMap = new Map();
|
|
76937
|
+
this.octrees = new Map();
|
|
76938
|
+
this.device = device;
|
|
76939
|
+
this.assetLoader = assetLoader;
|
|
76940
|
+
this.scene = scene;
|
|
76941
|
+
}
|
|
76942
|
+
getCameraData(camera) {
|
|
76943
|
+
let cameraData = this.camerasMap.get(camera);
|
|
76944
|
+
if (!cameraData) {
|
|
76945
|
+
cameraData = new GSplatCameraData();
|
|
76946
|
+
this.camerasMap.set(camera, cameraData);
|
|
76947
|
+
}
|
|
76948
|
+
return cameraData;
|
|
76949
|
+
}
|
|
76950
|
+
update(comp) {
|
|
76951
|
+
this.camerasMap.forEach((cameraData, camera)=>{
|
|
76952
|
+
if (!comp.camerasSet.has(camera)) {
|
|
76953
|
+
cameraData.destroy();
|
|
76954
|
+
this.camerasMap.delete(camera);
|
|
76955
|
+
} else {
|
|
76956
|
+
cameraData.layersMap.forEach((layerData, layer)=>{
|
|
76957
|
+
if (!camera.layersSet.has(layer.id) || !layer.enabled) {
|
|
76958
|
+
layerData.destroy();
|
|
76959
|
+
cameraData.layersMap.delete(layer);
|
|
76960
|
+
}
|
|
76961
|
+
});
|
|
76962
|
+
}
|
|
76963
|
+
});
|
|
76964
|
+
const camerasComponents = comp.cameras;
|
|
76965
|
+
for(let i = 0; i < camerasComponents.length; i++){
|
|
76966
|
+
const camera = camerasComponents[i].camera;
|
|
76967
|
+
let cameraData = this.camerasMap.get(camera);
|
|
76968
|
+
const layerIds = camera.layers;
|
|
76969
|
+
for(let j = 0; j < layerIds.length; j++){
|
|
76970
|
+
const layer = comp.getLayerById(layerIds[j]);
|
|
76971
|
+
if (layer?.enabled) {
|
|
76972
|
+
if (layer.gsplatPlacementsDirty || !cameraData) {
|
|
76973
|
+
const placements = layer.gsplatPlacements;
|
|
76974
|
+
if (placements.length === 0) {
|
|
76975
|
+
if (cameraData) {
|
|
76976
|
+
cameraData.removeLayerData(layer);
|
|
76977
|
+
}
|
|
76978
|
+
} else {
|
|
76979
|
+
cameraData ??= this.getCameraData(camera);
|
|
76980
|
+
const layerData = cameraData.getLayerData(this.device, this, layer, camera.node);
|
|
76981
|
+
layerData.gsplatManager.reconcile(placements);
|
|
76982
|
+
}
|
|
76983
|
+
}
|
|
76984
|
+
}
|
|
76985
|
+
}
|
|
76986
|
+
cameraData?.layersMap.forEach((layerData)=>{
|
|
76987
|
+
layerData.gsplatManager.update(this.scene);
|
|
76988
|
+
});
|
|
76989
|
+
}
|
|
76990
|
+
for(let i = 0; i < comp.layerList.length; i++){
|
|
76991
|
+
comp.layerList[i].gsplatPlacementsDirty = false;
|
|
76992
|
+
}
|
|
76993
|
+
}
|
|
76994
|
+
}
|
|
76995
|
+
|
|
75052
76996
|
class GSplatComponent extends Component {
|
|
75053
76997
|
constructor(system, entity){
|
|
75054
76998
|
super(system, entity), this._layers = [
|
|
75055
76999
|
LAYERID_WORLD
|
|
75056
|
-
], this._instance = null, this._materialTmp = null, this._highQualitySH = true, this._customAabb = null, this._evtLayersChanged = null, this._evtLayerAdded = null, this._evtLayerRemoved = null, this._castShadows = false;
|
|
77000
|
+
], this._instance = null, this._placement = null, this._materialTmp = null, this._highQualitySH = true, this._customAabb = null, this._evtLayersChanged = null, this._evtLayerAdded = null, this._evtLayerRemoved = null, this._castShadows = false, this._unified = false;
|
|
75057
77001
|
this._assetReference = new AssetReference('asset', this, system.app.assets, {
|
|
75058
77002
|
add: this._onGSplatAssetAdded,
|
|
75059
77003
|
load: this._onGSplatAssetLoad,
|
|
@@ -75068,6 +77012,9 @@ class GSplatComponent extends Component {
|
|
|
75068
77012
|
set customAabb(value) {
|
|
75069
77013
|
this._customAabb = value;
|
|
75070
77014
|
this._instance?.meshInstance?.setCustomAabb(this._customAabb);
|
|
77015
|
+
if (this._placement && this._customAabb) {
|
|
77016
|
+
this._placement.aabb = this._customAabb;
|
|
77017
|
+
}
|
|
75071
77018
|
}
|
|
75072
77019
|
get customAabb() {
|
|
75073
77020
|
return this._customAabb;
|
|
@@ -75103,9 +77050,7 @@ class GSplatComponent extends Component {
|
|
|
75103
77050
|
set highQualitySH(value) {
|
|
75104
77051
|
if (value !== this._highQualitySH) {
|
|
75105
77052
|
this._highQualitySH = value;
|
|
75106
|
-
|
|
75107
|
-
this._instance.setHighQualitySH(value);
|
|
75108
|
-
}
|
|
77053
|
+
this._instance?.setHighQualitySH(value);
|
|
75109
77054
|
}
|
|
75110
77055
|
}
|
|
75111
77056
|
get highQualitySH() {
|
|
@@ -75145,6 +77090,16 @@ class GSplatComponent extends Component {
|
|
|
75145
77090
|
get castShadows() {
|
|
75146
77091
|
return this._castShadows;
|
|
75147
77092
|
}
|
|
77093
|
+
set unified(value) {
|
|
77094
|
+
if (this.enabled && this.entity.enabled) {
|
|
77095
|
+
return;
|
|
77096
|
+
}
|
|
77097
|
+
this._unified = value;
|
|
77098
|
+
this._onGSplatAssetAdded();
|
|
77099
|
+
}
|
|
77100
|
+
get unified() {
|
|
77101
|
+
return this._unified;
|
|
77102
|
+
}
|
|
75148
77103
|
set layers(value) {
|
|
75149
77104
|
this.removeFromLayers();
|
|
75150
77105
|
this._layers.length = 0;
|
|
@@ -75174,6 +77129,10 @@ class GSplatComponent extends Component {
|
|
|
75174
77129
|
return this._assetReference.id;
|
|
75175
77130
|
}
|
|
75176
77131
|
destroyInstance() {
|
|
77132
|
+
if (this._placement) {
|
|
77133
|
+
this.removeFromLayers();
|
|
77134
|
+
this._placement = null;
|
|
77135
|
+
}
|
|
75177
77136
|
if (this._instance) {
|
|
75178
77137
|
this.removeFromLayers();
|
|
75179
77138
|
this._instance?.destroy();
|
|
@@ -75181,6 +77140,13 @@ class GSplatComponent extends Component {
|
|
|
75181
77140
|
}
|
|
75182
77141
|
}
|
|
75183
77142
|
addToLayers() {
|
|
77143
|
+
if (this._placement) {
|
|
77144
|
+
const layers = this.system.app.scene.layers;
|
|
77145
|
+
for(let i = 0; i < this._layers.length; i++){
|
|
77146
|
+
layers.getLayerById(this._layers[i])?.addGSplatPlacement(this._placement);
|
|
77147
|
+
}
|
|
77148
|
+
return;
|
|
77149
|
+
}
|
|
75184
77150
|
const meshInstance = this.instance?.meshInstance;
|
|
75185
77151
|
if (meshInstance) {
|
|
75186
77152
|
const layers = this.system.app.scene.layers;
|
|
@@ -75192,6 +77158,13 @@ class GSplatComponent extends Component {
|
|
|
75192
77158
|
}
|
|
75193
77159
|
}
|
|
75194
77160
|
removeFromLayers() {
|
|
77161
|
+
if (this._placement) {
|
|
77162
|
+
const layers = this.system.app.scene.layers;
|
|
77163
|
+
for(let i = 0; i < this._layers.length; i++){
|
|
77164
|
+
layers.getLayerById(this._layers[i])?.removeGSplatPlacement(this._placement);
|
|
77165
|
+
}
|
|
77166
|
+
return;
|
|
77167
|
+
}
|
|
75195
77168
|
const meshInstance = this.instance?.meshInstance;
|
|
75196
77169
|
if (meshInstance) {
|
|
75197
77170
|
const layers = this.system.app.scene.layers;
|
|
@@ -75206,8 +77179,10 @@ class GSplatComponent extends Component {
|
|
|
75206
77179
|
this.removeFromLayers();
|
|
75207
77180
|
}
|
|
75208
77181
|
onInsertChild() {
|
|
75209
|
-
if (this.
|
|
75210
|
-
this.
|
|
77182
|
+
if (this.enabled && this.entity.enabled) {
|
|
77183
|
+
if (this._instance || this._placement) {
|
|
77184
|
+
this.addToLayers();
|
|
77185
|
+
}
|
|
75211
77186
|
}
|
|
75212
77187
|
}
|
|
75213
77188
|
onRemove() {
|
|
@@ -75246,7 +77221,7 @@ class GSplatComponent extends Component {
|
|
|
75246
77221
|
this._evtLayerAdded = layers.on('add', this.onLayerAdded, this);
|
|
75247
77222
|
this._evtLayerRemoved = layers.on('remove', this.onLayerRemoved, this);
|
|
75248
77223
|
}
|
|
75249
|
-
if (this._instance) {
|
|
77224
|
+
if (this._instance || this._placement) {
|
|
75250
77225
|
this.addToLayers();
|
|
75251
77226
|
} else if (this.asset) {
|
|
75252
77227
|
this._onGSplatAssetAdded();
|
|
@@ -75288,13 +77263,22 @@ class GSplatComponent extends Component {
|
|
|
75288
77263
|
_onGSplatAssetLoad() {
|
|
75289
77264
|
this.destroyInstance();
|
|
75290
77265
|
const asset = this._assetReference.asset;
|
|
77266
|
+
if (this.unified) {
|
|
77267
|
+
this._placement = null;
|
|
77268
|
+
if (asset) {
|
|
77269
|
+
this._placement = new GSplatPlacement(asset.resource, this.entity);
|
|
77270
|
+
}
|
|
77271
|
+
} else {
|
|
77272
|
+
if (asset) {
|
|
77273
|
+
this.instance = new GSplatInstance(asset.resource, {
|
|
77274
|
+
material: this._materialTmp,
|
|
77275
|
+
highQualitySH: this._highQualitySH
|
|
77276
|
+
});
|
|
77277
|
+
this._materialTmp = null;
|
|
77278
|
+
}
|
|
77279
|
+
}
|
|
75291
77280
|
if (asset) {
|
|
75292
|
-
this.
|
|
75293
|
-
material: this._materialTmp,
|
|
75294
|
-
highQualitySH: this._highQualitySH
|
|
75295
|
-
});
|
|
75296
|
-
this._materialTmp = null;
|
|
75297
|
-
this.customAabb = this.instance.resource.aabb.clone();
|
|
77281
|
+
this.customAabb = asset.resource.aabb.clone();
|
|
75298
77282
|
}
|
|
75299
77283
|
}
|
|
75300
77284
|
_onGSplatAssetUnload() {
|
|
@@ -75311,10 +77295,51 @@ class GSplatComponentData {
|
|
|
75311
77295
|
}
|
|
75312
77296
|
}
|
|
75313
77297
|
|
|
77298
|
+
class GSplatAssetLoaderBase {
|
|
77299
|
+
load(url) {}
|
|
77300
|
+
unload(url) {}
|
|
77301
|
+
getResource(url) {}
|
|
77302
|
+
}
|
|
77303
|
+
|
|
77304
|
+
class GSplatAssetLoader extends GSplatAssetLoaderBase {
|
|
77305
|
+
constructor(registry){
|
|
77306
|
+
super(), this._urlToAsset = new Map();
|
|
77307
|
+
this._registry = registry;
|
|
77308
|
+
}
|
|
77309
|
+
load(url) {
|
|
77310
|
+
let asset = this._urlToAsset.get(url);
|
|
77311
|
+
if (!asset) {
|
|
77312
|
+
asset = this._registry.getByUrl(url);
|
|
77313
|
+
if (!asset) {
|
|
77314
|
+
asset = new Asset(url, 'gsplat', {
|
|
77315
|
+
url
|
|
77316
|
+
});
|
|
77317
|
+
this._registry.add(asset);
|
|
77318
|
+
}
|
|
77319
|
+
this._urlToAsset.set(url, asset);
|
|
77320
|
+
}
|
|
77321
|
+
if (!asset.loaded && !asset.loading) {
|
|
77322
|
+
this._registry.load(asset);
|
|
77323
|
+
}
|
|
77324
|
+
}
|
|
77325
|
+
unload(url) {
|
|
77326
|
+
const asset = this._urlToAsset.get(url);
|
|
77327
|
+
if (asset) {
|
|
77328
|
+
asset.unload();
|
|
77329
|
+
this._urlToAsset.delete(url);
|
|
77330
|
+
}
|
|
77331
|
+
}
|
|
77332
|
+
getResource(url) {
|
|
77333
|
+
const asset = this._urlToAsset.get(url);
|
|
77334
|
+
return asset?.resource;
|
|
77335
|
+
}
|
|
77336
|
+
}
|
|
77337
|
+
|
|
75314
77338
|
const _schema = [
|
|
75315
77339
|
'enabled'
|
|
75316
77340
|
];
|
|
75317
77341
|
const _properties = [
|
|
77342
|
+
'unified',
|
|
75318
77343
|
'castShadows',
|
|
75319
77344
|
'material',
|
|
75320
77345
|
'highQualitySH',
|
|
@@ -75328,6 +77353,8 @@ class GSplatComponentSystem extends ComponentSystem {
|
|
|
75328
77353
|
this.ComponentType = GSplatComponent;
|
|
75329
77354
|
this.DataType = GSplatComponentData;
|
|
75330
77355
|
this.schema = _schema;
|
|
77356
|
+
const gsplatAssetLoader = new GSplatAssetLoader(app.assets);
|
|
77357
|
+
app.renderer.gsplatDirector = new GSplatDirector(app.graphicsDevice, app.scene, gsplatAssetLoader);
|
|
75331
77358
|
this.on('beforeremove', this.onRemove, this);
|
|
75332
77359
|
}
|
|
75333
77360
|
initializeComponentData(component, _data, properties) {
|
|
@@ -75349,7 +77376,10 @@ class GSplatComponentSystem extends ComponentSystem {
|
|
|
75349
77376
|
const data = {};
|
|
75350
77377
|
_properties.forEach((prop)=>{
|
|
75351
77378
|
if (prop === 'material') {
|
|
75352
|
-
|
|
77379
|
+
const srcMaterial = gSplatComponent[prop];
|
|
77380
|
+
if (srcMaterial) {
|
|
77381
|
+
data[prop] = srcMaterial.clone();
|
|
77382
|
+
}
|
|
75353
77383
|
} else {
|
|
75354
77384
|
data[prop] = gSplatComponent[prop];
|
|
75355
77385
|
}
|
|
@@ -79252,7 +81282,12 @@ class GSplatCompressedData {
|
|
|
79252
81282
|
for(let i = 0; i < 45; ++i){
|
|
79253
81283
|
shMembers.push(`f_rest_${i}`);
|
|
79254
81284
|
}
|
|
79255
|
-
|
|
81285
|
+
const location = Math.max(...[
|
|
81286
|
+
'f_dc_0',
|
|
81287
|
+
'f_dc_1',
|
|
81288
|
+
'f_dc_2'
|
|
81289
|
+
].map((name)=>members.indexOf(name)));
|
|
81290
|
+
members.splice(location + 1, 0, ...shMembers);
|
|
79256
81291
|
}
|
|
79257
81292
|
const data = {};
|
|
79258
81293
|
members.forEach((name)=>{
|
|
@@ -79349,17 +81384,18 @@ class GSplatCompressedResource extends GSplatResourceBase {
|
|
|
79349
81384
|
this.shTexture2?.destroy();
|
|
79350
81385
|
super.destroy();
|
|
79351
81386
|
}
|
|
81387
|
+
configureMaterialDefines(defines) {
|
|
81388
|
+
defines.set('GSPLAT_COMPRESSED_DATA', true);
|
|
81389
|
+
defines.set('SH_BANDS', this.shTexture0 ? 3 : 0);
|
|
81390
|
+
}
|
|
79352
81391
|
configureMaterial(material) {
|
|
79353
|
-
material.
|
|
81392
|
+
this.configureMaterialDefines(material.defines);
|
|
79354
81393
|
material.setParameter('packedTexture', this.packedTexture);
|
|
79355
81394
|
material.setParameter('chunkTexture', this.chunkTexture);
|
|
79356
81395
|
if (this.shTexture0) {
|
|
79357
|
-
material.setDefine('SH_BANDS', 3);
|
|
79358
81396
|
material.setParameter('shTexture0', this.shTexture0);
|
|
79359
81397
|
material.setParameter('shTexture1', this.shTexture1);
|
|
79360
81398
|
material.setParameter('shTexture2', this.shTexture2);
|
|
79361
|
-
} else {
|
|
79362
|
-
material.setDefine('SH_BANDS', 0);
|
|
79363
81399
|
}
|
|
79364
81400
|
}
|
|
79365
81401
|
evalTextureSize(count) {
|
|
@@ -79908,12 +81944,47 @@ const combineProgress = (target, assets)=>{
|
|
|
79908
81944
|
asset.on('error', done);
|
|
79909
81945
|
});
|
|
79910
81946
|
};
|
|
81947
|
+
const upgradeMeta = (meta)=>{
|
|
81948
|
+
const result = {
|
|
81949
|
+
version: 1,
|
|
81950
|
+
count: meta.means.shape[0],
|
|
81951
|
+
means: {
|
|
81952
|
+
mins: meta.means.mins,
|
|
81953
|
+
maxs: meta.means.maxs,
|
|
81954
|
+
files: meta.means.files
|
|
81955
|
+
},
|
|
81956
|
+
scales: {
|
|
81957
|
+
mins: meta.scales.mins,
|
|
81958
|
+
maxs: meta.scales.maxs,
|
|
81959
|
+
files: meta.scales.files
|
|
81960
|
+
},
|
|
81961
|
+
quats: {
|
|
81962
|
+
files: meta.quats.files
|
|
81963
|
+
},
|
|
81964
|
+
sh0: {
|
|
81965
|
+
mins: meta.sh0.mins,
|
|
81966
|
+
maxs: meta.sh0.maxs,
|
|
81967
|
+
files: meta.sh0.files
|
|
81968
|
+
}
|
|
81969
|
+
};
|
|
81970
|
+
if (meta.shN) {
|
|
81971
|
+
result.shN = {
|
|
81972
|
+
mins: meta.shN.mins,
|
|
81973
|
+
maxs: meta.shN.maxs,
|
|
81974
|
+
files: meta.shN.files
|
|
81975
|
+
};
|
|
81976
|
+
}
|
|
81977
|
+
return result;
|
|
81978
|
+
};
|
|
79911
81979
|
class SogsParser {
|
|
79912
81980
|
constructor(app, maxRetries){
|
|
79913
81981
|
this.app = app;
|
|
79914
81982
|
this.maxRetries = maxRetries;
|
|
79915
81983
|
}
|
|
79916
81984
|
async loadTextures(url, callback, asset, meta) {
|
|
81985
|
+
if (meta.version !== 2) {
|
|
81986
|
+
meta = upgradeMeta(meta);
|
|
81987
|
+
}
|
|
79917
81988
|
const { assets } = this.app;
|
|
79918
81989
|
const subs = [
|
|
79919
81990
|
'means',
|
|
@@ -79948,7 +82019,7 @@ class SogsParser {
|
|
|
79948
82019
|
await Promise.allSettled(promises);
|
|
79949
82020
|
const data = new GSplatSogsData();
|
|
79950
82021
|
data.meta = meta;
|
|
79951
|
-
data.numSplats = meta.
|
|
82022
|
+
data.numSplats = meta.count;
|
|
79952
82023
|
data.means_l = textures.means[0].resource;
|
|
79953
82024
|
data.means_u = textures.means[1].resource;
|
|
79954
82025
|
data.quats = textures.quats[0].resource;
|
|
@@ -79989,19 +82060,216 @@ class SogsParser {
|
|
|
79989
82060
|
}
|
|
79990
82061
|
}
|
|
79991
82062
|
|
|
82063
|
+
const parseZipArchive = (data)=>{
|
|
82064
|
+
const dataView = new DataView(data);
|
|
82065
|
+
const u16 = (offset)=>dataView.getUint16(offset, true);
|
|
82066
|
+
const u32 = (offset)=>dataView.getUint32(offset, true);
|
|
82067
|
+
const extractEocd = (offset)=>{
|
|
82068
|
+
return {
|
|
82069
|
+
magic: u32(offset),
|
|
82070
|
+
numFiles: u16(offset + 8),
|
|
82071
|
+
cdSizeBytes: u32(offset + 12),
|
|
82072
|
+
cdOffsetBytes: u32(offset + 16)
|
|
82073
|
+
};
|
|
82074
|
+
};
|
|
82075
|
+
const extractCdr = (offset)=>{
|
|
82076
|
+
const filenameLength = u16(offset + 28);
|
|
82077
|
+
const extraFieldLength = u16(offset + 30);
|
|
82078
|
+
const fileCommentLength = u16(offset + 32);
|
|
82079
|
+
return {
|
|
82080
|
+
magic: u32(offset),
|
|
82081
|
+
compressionMethod: u16(offset + 10),
|
|
82082
|
+
compressedSizeBytes: u32(offset + 20),
|
|
82083
|
+
uncompressedSizeBytes: u32(offset + 24),
|
|
82084
|
+
lfhOffsetBytes: u32(offset + 42),
|
|
82085
|
+
filename: new TextDecoder().decode(new Uint8Array(data, offset + 46, filenameLength)),
|
|
82086
|
+
recordSizeBytes: 46 + filenameLength + extraFieldLength + fileCommentLength
|
|
82087
|
+
};
|
|
82088
|
+
};
|
|
82089
|
+
const extractLfh = (offset)=>{
|
|
82090
|
+
const filenameLength = u16(offset + 26);
|
|
82091
|
+
const extraLength = u16(offset + 28);
|
|
82092
|
+
return {
|
|
82093
|
+
magic: u32(offset),
|
|
82094
|
+
offsetBytes: offset + 30 + filenameLength + extraLength
|
|
82095
|
+
};
|
|
82096
|
+
};
|
|
82097
|
+
const eocd = extractEocd(dataView.byteLength - 22);
|
|
82098
|
+
if (eocd.magic !== 0x06054b50) {
|
|
82099
|
+
throw new Error('Invalid zip file: EOCDR not found');
|
|
82100
|
+
}
|
|
82101
|
+
if (eocd.cdOffsetBytes === 0xffffffff || eocd.cdSizeBytes === 0xffffffff) {
|
|
82102
|
+
throw new Error('Invalid zip file: Zip64 not supported');
|
|
82103
|
+
}
|
|
82104
|
+
const result = [];
|
|
82105
|
+
let offset = eocd.cdOffsetBytes;
|
|
82106
|
+
for(let i = 0; i < eocd.numFiles; i++){
|
|
82107
|
+
const cdr = extractCdr(offset);
|
|
82108
|
+
if (cdr.magic !== 0x02014b50) {
|
|
82109
|
+
throw new Error('Invalid zip file: CDR not found');
|
|
82110
|
+
}
|
|
82111
|
+
const lfh = extractLfh(cdr.lfhOffsetBytes);
|
|
82112
|
+
if (lfh.magic !== 0x04034b50) {
|
|
82113
|
+
throw new Error('Invalid zip file: LFH not found');
|
|
82114
|
+
}
|
|
82115
|
+
result.push({
|
|
82116
|
+
filename: cdr.filename,
|
|
82117
|
+
compression: {
|
|
82118
|
+
0: 'none',
|
|
82119
|
+
8: 'deflate'
|
|
82120
|
+
}[cdr.compressionMethod] ?? 'unknown',
|
|
82121
|
+
data: new Uint8Array(data, lfh.offsetBytes, cdr.compressedSizeBytes)
|
|
82122
|
+
});
|
|
82123
|
+
offset += cdr.recordSizeBytes;
|
|
82124
|
+
}
|
|
82125
|
+
return result;
|
|
82126
|
+
};
|
|
82127
|
+
const inflate = async (compressed)=>{
|
|
82128
|
+
const ds = new DecompressionStream('deflate-raw');
|
|
82129
|
+
const out = new Blob([
|
|
82130
|
+
compressed
|
|
82131
|
+
]).stream().pipeThrough(ds);
|
|
82132
|
+
const ab = await new Response(out).arrayBuffer();
|
|
82133
|
+
return new Uint8Array(ab);
|
|
82134
|
+
};
|
|
82135
|
+
class SogBundleParser {
|
|
82136
|
+
constructor(app, maxRetries = 3){
|
|
82137
|
+
this.app = app;
|
|
82138
|
+
this.maxRetries = maxRetries;
|
|
82139
|
+
}
|
|
82140
|
+
load(url, callback, asset) {
|
|
82141
|
+
const handleArrayBuffer = async (arrayBuffer)=>{
|
|
82142
|
+
const files = parseZipArchive(arrayBuffer);
|
|
82143
|
+
for (const file of files){
|
|
82144
|
+
if (file.compression === 'deflate') {
|
|
82145
|
+
file.data = await inflate(file.data);
|
|
82146
|
+
}
|
|
82147
|
+
}
|
|
82148
|
+
const metaFile = files.find((f)=>f.filename === 'meta.json');
|
|
82149
|
+
if (!metaFile) {
|
|
82150
|
+
callback('Error: meta.json not found');
|
|
82151
|
+
return;
|
|
82152
|
+
}
|
|
82153
|
+
let meta;
|
|
82154
|
+
try {
|
|
82155
|
+
meta = JSON.parse(new TextDecoder().decode(metaFile.data));
|
|
82156
|
+
} catch (err) {
|
|
82157
|
+
callback(`Error parsing meta.json: ${err}`);
|
|
82158
|
+
return;
|
|
82159
|
+
}
|
|
82160
|
+
const filenames = [
|
|
82161
|
+
'means',
|
|
82162
|
+
'scales',
|
|
82163
|
+
'quats',
|
|
82164
|
+
'sh0',
|
|
82165
|
+
'shN'
|
|
82166
|
+
].map((key)=>meta[key]?.files ?? []).flat();
|
|
82167
|
+
const textures = {};
|
|
82168
|
+
const promises = [];
|
|
82169
|
+
for (const filename of filenames){
|
|
82170
|
+
const file = files.find((f)=>f.filename === filename);
|
|
82171
|
+
let texture;
|
|
82172
|
+
if (file) {
|
|
82173
|
+
texture = new Asset(filename, 'texture', {
|
|
82174
|
+
url: filename,
|
|
82175
|
+
filename,
|
|
82176
|
+
contents: file.data
|
|
82177
|
+
}, {
|
|
82178
|
+
mipmaps: false
|
|
82179
|
+
});
|
|
82180
|
+
} else {
|
|
82181
|
+
const url = new URL(filename, new URL(filename, window.location.href).toString()).toString();
|
|
82182
|
+
texture = new Asset(filename, 'texture', {
|
|
82183
|
+
url,
|
|
82184
|
+
filename
|
|
82185
|
+
}, {
|
|
82186
|
+
mipmaps: false
|
|
82187
|
+
});
|
|
82188
|
+
}
|
|
82189
|
+
const promise = new Promise((resolve, reject)=>{
|
|
82190
|
+
texture.on('load', ()=>resolve(null));
|
|
82191
|
+
texture.on('error', (err)=>reject(err));
|
|
82192
|
+
});
|
|
82193
|
+
this.app.assets.add(texture);
|
|
82194
|
+
textures[filename] = texture;
|
|
82195
|
+
promises.push(promise);
|
|
82196
|
+
}
|
|
82197
|
+
Object.values(textures).forEach((t)=>this.app.assets.load(t));
|
|
82198
|
+
await Promise.allSettled(promises);
|
|
82199
|
+
const data = new GSplatSogsData();
|
|
82200
|
+
data.meta = meta;
|
|
82201
|
+
data.numSplats = meta.count;
|
|
82202
|
+
data.means_l = textures[meta.means.files[0]].resource;
|
|
82203
|
+
data.means_u = textures[meta.means.files[1]].resource;
|
|
82204
|
+
data.quats = textures[meta.quats.files[0]].resource;
|
|
82205
|
+
data.scales = textures[meta.scales.files[0]].resource;
|
|
82206
|
+
data.sh0 = textures[meta.sh0.files[0]].resource;
|
|
82207
|
+
data.sh_centroids = textures[meta.shN?.files[0]]?.resource;
|
|
82208
|
+
data.sh_labels = textures[meta.shN?.files[1]]?.resource;
|
|
82209
|
+
const decompress = asset.data?.decompress;
|
|
82210
|
+
if (!decompress) {
|
|
82211
|
+
await data.prepareGpuData();
|
|
82212
|
+
}
|
|
82213
|
+
const resource = decompress ? new GSplatResource(this.app.graphicsDevice, await data.decompress()) : new GSplatSogsResource(this.app.graphicsDevice, data);
|
|
82214
|
+
callback(null, resource);
|
|
82215
|
+
};
|
|
82216
|
+
Asset.fetchArrayBuffer(url.load, (error, arrayBuffer)=>{
|
|
82217
|
+
if (error) {
|
|
82218
|
+
callback(error);
|
|
82219
|
+
} else {
|
|
82220
|
+
handleArrayBuffer(arrayBuffer);
|
|
82221
|
+
}
|
|
82222
|
+
}, asset, this.maxRetries);
|
|
82223
|
+
}
|
|
82224
|
+
}
|
|
82225
|
+
|
|
82226
|
+
class GSplatOctreeParser {
|
|
82227
|
+
constructor(app, maxRetries){
|
|
82228
|
+
this.app = app;
|
|
82229
|
+
this.maxRetries = maxRetries;
|
|
82230
|
+
}
|
|
82231
|
+
load(url, callback, asset) {
|
|
82232
|
+
if (typeof url === 'string') {
|
|
82233
|
+
url = {
|
|
82234
|
+
load: url,
|
|
82235
|
+
original: url
|
|
82236
|
+
};
|
|
82237
|
+
}
|
|
82238
|
+
const options = {
|
|
82239
|
+
retry: this.maxRetries > 0,
|
|
82240
|
+
maxRetries: this.maxRetries,
|
|
82241
|
+
responseType: Http.ResponseType.JSON
|
|
82242
|
+
};
|
|
82243
|
+
http.get(url.load, options, (err, data)=>{
|
|
82244
|
+
if (!err) {
|
|
82245
|
+
const resource = new GSplatOctreeResource(asset.file.url, data);
|
|
82246
|
+
callback(null, resource);
|
|
82247
|
+
} else {
|
|
82248
|
+
callback(`Error loading gsplat octree: ${url.original} [${err}]`);
|
|
82249
|
+
}
|
|
82250
|
+
});
|
|
82251
|
+
}
|
|
82252
|
+
}
|
|
82253
|
+
|
|
79992
82254
|
class GSplatHandler extends ResourceHandler {
|
|
79993
82255
|
constructor(app){
|
|
79994
82256
|
super(app, 'gsplat');
|
|
79995
82257
|
this.parsers = {
|
|
79996
82258
|
ply: new PlyParser(app, 3),
|
|
79997
|
-
|
|
82259
|
+
sog: new SogBundleParser(app),
|
|
82260
|
+
json: new SogsParser(app, 3),
|
|
82261
|
+
octree: new GSplatOctreeParser(app, 3)
|
|
79998
82262
|
};
|
|
79999
82263
|
}
|
|
80000
82264
|
_getUrlWithoutParams(url) {
|
|
80001
82265
|
return url.indexOf('?') >= 0 ? url.split('?')[0] : url;
|
|
80002
82266
|
}
|
|
80003
82267
|
_getParser(url) {
|
|
80004
|
-
const
|
|
82268
|
+
const basename = path.getBasename(this._getUrlWithoutParams(url)).toLowerCase();
|
|
82269
|
+
if (basename === 'lod-meta.json') {
|
|
82270
|
+
return this.parsers.octree;
|
|
82271
|
+
}
|
|
82272
|
+
const ext = path.getExtension(basename).replace('.', '');
|
|
80005
82273
|
return this.parsers[ext] || this.parsers.ply;
|
|
80006
82274
|
}
|
|
80007
82275
|
load(url, callback, asset) {
|
|
@@ -85753,6 +88021,9 @@ class RenderPassPicker extends RenderPass {
|
|
|
85753
88021
|
this.scene = scene;
|
|
85754
88022
|
this.layers = layers;
|
|
85755
88023
|
this.mapping = mapping;
|
|
88024
|
+
if (scene.clusteredLightingEnabled) {
|
|
88025
|
+
this.emptyWorldClusters = this.renderer.worldClustersAllocator.empty;
|
|
88026
|
+
}
|
|
85756
88027
|
}
|
|
85757
88028
|
execute() {
|
|
85758
88029
|
const device = this.device;
|
|
@@ -85782,7 +88053,7 @@ class RenderPassPicker extends RenderPass {
|
|
|
85782
88053
|
if (tempMeshInstances.length > 0) {
|
|
85783
88054
|
const clusteredLightingEnabled = scene.clusteredLightingEnabled;
|
|
85784
88055
|
if (clusteredLightingEnabled) {
|
|
85785
|
-
const lightClusters =
|
|
88056
|
+
const lightClusters = this.emptyWorldClusters;
|
|
85786
88057
|
lightClusters.activate();
|
|
85787
88058
|
}
|
|
85788
88059
|
renderer.setCameraUniforms(camera.camera, renderTarget);
|
|
@@ -88796,6 +91067,7 @@ const extToType = new Map([
|
|
|
88796
91067
|
['mjs', 'script'],
|
|
88797
91068
|
['ply', 'gsplat'],
|
|
88798
91069
|
['png', 'texture'],
|
|
91070
|
+
['sog', 'gsplat'],
|
|
88799
91071
|
['txt', 'text'],
|
|
88800
91072
|
['vert', 'shader'],
|
|
88801
91073
|
['webp', 'texture']
|