@null3d/splats 0.0.0-stage → 0.0.0
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/LICENSE-APACHE +176 -0
- package/LICENSE-MIT +21 -0
- package/README.md +55 -2
- package/dist/splats.wasm +0 -0
- package/lib/chunks.d.ts +74 -0
- package/lib/chunks.js +170 -0
- package/lib/coverage.d.ts +18 -0
- package/lib/coverage.js +208 -0
- package/lib/feature.d.ts +10 -0
- package/lib/feature.js +39 -0
- package/lib/format.d.ts +35 -0
- package/lib/format.js +53 -0
- package/lib/gltf.d.ts +9 -0
- package/lib/gltf.js +174 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +10 -0
- package/lib/pack.d.ts +34 -0
- package/lib/pack.js +60 -0
- package/lib/select-reference.d.ts +12 -0
- package/lib/select-reference.js +103 -0
- package/lib/select-task.d.ts +58 -0
- package/lib/select-task.js +198 -0
- package/lib/select.d.ts +34 -0
- package/lib/select.js +121 -0
- package/lib/splats-mesh.wgsl-material-glsl-0-7c70ea7f8bc68f80.js +24 -0
- package/lib/splats-mesh.wgsl-material-glsl-1-4c5238f07ce504f6.js +24 -0
- package/lib/splats-mesh.wgsl-material-glsl-2-a1c90d44f96d6edc.js +24 -0
- package/lib/splats-mesh.wgsl-material-glsl-3-71d6a8492ec15318.js +24 -0
- package/lib/splats-mesh.wgsl-material-wgsl-0-e3d76625f2ac6140.js +24 -0
- package/lib/splats-mesh.wgsl-material-wgsl-2-a79d411b03e48a8f.js +24 -0
- package/lib/splats-mesh.wgsl.d.ts +6 -0
- package/lib/splats-mesh.wgsl.js +36 -0
- package/lib/splats.wgsl-material-glsl-0-820a413bdc6c214f.js +24 -0
- package/lib/splats.wgsl-material-glsl-1-218c97fea0e0021a.js +24 -0
- package/lib/splats.wgsl-material-glsl-2-a01ede5b80d9c4ec.js +24 -0
- package/lib/splats.wgsl-material-glsl-3-a38e648847680581.js +24 -0
- package/lib/splats.wgsl-material-glsl-64-284224c0525054d5.js +24 -0
- package/lib/splats.wgsl-material-glsl-65-fed0d228f3996b85.js +24 -0
- package/lib/splats.wgsl-material-glsl-66-5e88b8d27331ba9b.js +24 -0
- package/lib/splats.wgsl-material-glsl-67-b8d5a4ba09da08f2.js +24 -0
- package/lib/splats.wgsl-material-wgsl-0-7d98def36b682735.js +24 -0
- package/lib/splats.wgsl-material-wgsl-2-2117fc0ae3c904bc.js +24 -0
- package/lib/splats.wgsl-material-wgsl-64-646c09348ffc2153.js +24 -0
- package/lib/splats.wgsl-material-wgsl-66-16bc1350a6ccb2f9.js +24 -0
- package/lib/splats.wgsl.d.ts +14 -0
- package/lib/splats.wgsl.js +42 -0
- package/lib/spz-write.d.ts +9 -0
- package/lib/spz-write.js +133 -0
- package/lib/spz.d.ts +9 -0
- package/lib/spz.js +240 -0
- package/lib/stream.d.ts +126 -0
- package/lib/stream.js +304 -0
- package/lib/system.d.ts +110 -0
- package/lib/system.js +476 -0
- package/lib/version.d.ts +1 -0
- package/lib/version.js +3 -0
- package/package.json +54 -5
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// The TypeScript reference of the selection: the same distances, levels, sort and budget passes
|
|
2
|
+
// that the add-on's WebAssembly module runs on the job workers. The unit tests and the parity test
|
|
3
|
+
// compare the module with this, so a change to one that the other misses fails.
|
|
4
|
+
//
|
|
5
|
+
// The buffer holds a header of `HEADER` floats, then `STRIDE` floats for each chunk, then one float
|
|
6
|
+
// for each chunk's chosen count. The layout comes from the task module, so the two cannot drift.
|
|
7
|
+
import { BUDGET, CHUNK_COUNT, CLOUD_RADIUS, EYE, HEADER, LEVELS, STRIDE, TOTAL, } from './select-task.js';
|
|
8
|
+
/**
|
|
9
|
+
* The level that a chunk draws at, from the distance to its nearest point and the cloud's size. The
|
|
10
|
+
* distance is measured in the cloud's own radius, not the chunk's: a finer cut makes smaller chunks,
|
|
11
|
+
* and measuring against them would let a smaller chunk pass for a farther one, so the same view
|
|
12
|
+
* would draw fewer splats.
|
|
13
|
+
*/
|
|
14
|
+
export function levelOf(distance, radius, cloudRadius) {
|
|
15
|
+
const near = Math.max(distance - radius, 0);
|
|
16
|
+
const size = Math.max(cloudRadius, 1e-3);
|
|
17
|
+
if (near <= size * 2)
|
|
18
|
+
return 0;
|
|
19
|
+
if (near <= size * 4)
|
|
20
|
+
return 1;
|
|
21
|
+
if (near <= size * 8)
|
|
22
|
+
return 2;
|
|
23
|
+
return LEVELS - 1;
|
|
24
|
+
}
|
|
25
|
+
/** The scratch of the last call's chunk count. */
|
|
26
|
+
let scratch = {
|
|
27
|
+
chunks: -1,
|
|
28
|
+
distances: new Float32Array(0),
|
|
29
|
+
levels: new Uint8Array(0),
|
|
30
|
+
order: [],
|
|
31
|
+
};
|
|
32
|
+
/** Orders two chunk indices by their distance from the camera, nearest first. */
|
|
33
|
+
function byDistance(a, b) {
|
|
34
|
+
return scratch.distances[a] - scratch.distances[b];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Chooses each chunk's count and writes them after the chunks. Answers the total that draws.
|
|
38
|
+
* `view` is the whole buffer: the header, the chunks and the counts.
|
|
39
|
+
*/
|
|
40
|
+
export function runSelection(view) {
|
|
41
|
+
const chunks = view[CHUNK_COUNT];
|
|
42
|
+
if (chunks !== scratch.chunks) {
|
|
43
|
+
scratch = {
|
|
44
|
+
chunks,
|
|
45
|
+
distances: new Float32Array(chunks),
|
|
46
|
+
levels: new Uint8Array(chunks),
|
|
47
|
+
order: new Array(chunks),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const { distances, levels, order } = scratch;
|
|
51
|
+
const budget = view[BUDGET];
|
|
52
|
+
const eyeX = view[EYE];
|
|
53
|
+
const eyeY = view[EYE + 1];
|
|
54
|
+
const eyeZ = view[EYE + 2];
|
|
55
|
+
const cloudRadius = view[CLOUD_RADIUS];
|
|
56
|
+
for (let i = 0; i < chunks; i++) {
|
|
57
|
+
const at = HEADER + i * STRIDE;
|
|
58
|
+
const dx = view[at] - eyeX;
|
|
59
|
+
const dy = view[at + 1] - eyeY;
|
|
60
|
+
const dz = view[at + 2] - eyeZ;
|
|
61
|
+
const radius = view[at + 3];
|
|
62
|
+
const distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
63
|
+
distances[i] = distance > radius ? distance - radius : 0;
|
|
64
|
+
levels[i] = levelOf(distance, radius, cloudRadius);
|
|
65
|
+
order[i] = i;
|
|
66
|
+
}
|
|
67
|
+
order.sort(byDistance);
|
|
68
|
+
const countsAt = HEADER + chunks * STRIDE;
|
|
69
|
+
for (let i = 0; i < chunks; i++)
|
|
70
|
+
view[countsAt + i] = 0;
|
|
71
|
+
let left = budget;
|
|
72
|
+
let total = 0;
|
|
73
|
+
// The base level: each chunk, nearest first, keeps its coarsest prefix while the budget lasts.
|
|
74
|
+
// A budget too small for every level then thins the whole cloud rather than dropping its far
|
|
75
|
+
// parts, and a stream still fetches only the chunks that the budget reaches.
|
|
76
|
+
for (const i of order) {
|
|
77
|
+
if (left <= 0)
|
|
78
|
+
break;
|
|
79
|
+
const base = view[HEADER + i * STRIDE + 4 + (LEVELS - 1)];
|
|
80
|
+
const chosen = base < left ? base : left;
|
|
81
|
+
view[countsAt + i] = chosen;
|
|
82
|
+
left -= chosen;
|
|
83
|
+
total += chosen;
|
|
84
|
+
}
|
|
85
|
+
// The rest of the budget refines the nearest chunks first, up to the level that each one's
|
|
86
|
+
// distance asks for, so a near chunk is denser than a far one of the same size.
|
|
87
|
+
for (const i of order) {
|
|
88
|
+
if (left <= 0)
|
|
89
|
+
break;
|
|
90
|
+
const at = HEADER + i * STRIDE;
|
|
91
|
+
const target = view[at + 4 + levels[i]];
|
|
92
|
+
const chosen = view[countsAt + i];
|
|
93
|
+
if (chosen >= target)
|
|
94
|
+
continue;
|
|
95
|
+
const rest = target - chosen;
|
|
96
|
+
const more = rest < left ? rest : left;
|
|
97
|
+
view[countsAt + i] = chosen + more;
|
|
98
|
+
left -= more;
|
|
99
|
+
total += more;
|
|
100
|
+
}
|
|
101
|
+
view[TOTAL] = total;
|
|
102
|
+
return total;
|
|
103
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** The floats before the chunks: the count, the budget, the camera, and the answer's total. */
|
|
2
|
+
export declare const HEADER = 8;
|
|
3
|
+
/** The floats of each chunk: its centre, its radius and the counts of its four levels. */
|
|
4
|
+
export declare const STRIDE = 8;
|
|
5
|
+
/** The place of the chunk count in the header. */
|
|
6
|
+
export declare const CHUNK_COUNT = 0;
|
|
7
|
+
/** The place of the budget, the most splats that draw, in the header. */
|
|
8
|
+
export declare const BUDGET = 1;
|
|
9
|
+
/** The place of the camera's first number in the header. */
|
|
10
|
+
export declare const EYE = 2;
|
|
11
|
+
/** The place of the cloud's bounding radius in the header. */
|
|
12
|
+
export declare const CLOUD_RADIUS = 5;
|
|
13
|
+
/** The place of the total that draws in the header. */
|
|
14
|
+
export declare const TOTAL = 6;
|
|
15
|
+
/** The number of detail levels of a chunk: every splat, then half, a quarter and an eighth. */
|
|
16
|
+
export declare const LEVELS = 4;
|
|
17
|
+
/**
|
|
18
|
+
* One call's input, which the add-on reuses and refills so a call makes no object. `view` is
|
|
19
|
+
* shared with the worker where the page allows a `SharedArrayBuffer`, so its counts land in the
|
|
20
|
+
* add-on's buffer; without one, the worker answers with a copy.
|
|
21
|
+
*/
|
|
22
|
+
export interface SelectInput {
|
|
23
|
+
/** `select` chooses the counts; `drop` frees the selector's arrays. */
|
|
24
|
+
readonly op?: 'select';
|
|
25
|
+
/** The selector's number, which names its table and scratch in this worker. */
|
|
26
|
+
readonly id: number;
|
|
27
|
+
/** Changes when the chunk table changes: a new selector, or a new number of chunks. */
|
|
28
|
+
readonly version: number;
|
|
29
|
+
/** The number of chunks. */
|
|
30
|
+
readonly chunks: number;
|
|
31
|
+
/** The most splats that draw. */
|
|
32
|
+
budget: number;
|
|
33
|
+
/** The camera's world position. */
|
|
34
|
+
eyeX: number;
|
|
35
|
+
eyeY: number;
|
|
36
|
+
eyeZ: number;
|
|
37
|
+
/** The whole buffer: the header, the chunk table and the counts. */
|
|
38
|
+
readonly view: Float32Array;
|
|
39
|
+
}
|
|
40
|
+
/** A call's answer: the total that draws, and the counts when the page shares no memory. */
|
|
41
|
+
export interface SelectAnswer {
|
|
42
|
+
/** The number of splats that draw. */
|
|
43
|
+
readonly total: number;
|
|
44
|
+
/** The chosen count of each chunk, when the worker could not write into `view` itself. */
|
|
45
|
+
readonly counts?: Float32Array;
|
|
46
|
+
}
|
|
47
|
+
/** An input that frees the arrays of a selector, which a cloud leaves behind. */
|
|
48
|
+
export interface DropInput {
|
|
49
|
+
readonly op: 'drop';
|
|
50
|
+
readonly id: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Runs one call. The engine calls this once for each task, with the compiled WebAssembly module
|
|
54
|
+
* that the task names.
|
|
55
|
+
*/
|
|
56
|
+
export declare function run(input: unknown, modules: (name: string) => WebAssembly.Module): {
|
|
57
|
+
output: SelectAnswer;
|
|
58
|
+
};
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
// The add-on's selection task, which the engine imports in each job worker. It holds the
|
|
2
|
+
// WebAssembly module for the worker, copies the chunk table into the module's memory once, calls
|
|
3
|
+
// the module with the camera and the budget, and writes the counts back into the buffer that the
|
|
4
|
+
// sketch reads. The selection and its distance sort run in Rust under hard rule 42, so no loop
|
|
5
|
+
// over chunks runs in TypeScript in a frame.
|
|
6
|
+
//
|
|
7
|
+
// The worker keeps the chunk table and the scratch between calls, so a call copies only the few
|
|
8
|
+
// numbers that changed and the counts. The module imports nothing, so a worker loads it alone.
|
|
9
|
+
//
|
|
10
|
+
// The buffer holds a header of `HEADER` floats, then `STRIDE` floats for each chunk, then one float
|
|
11
|
+
// for each chunk's chosen count.
|
|
12
|
+
/** The floats before the chunks: the count, the budget, the camera, and the answer's total. */
|
|
13
|
+
export const HEADER = 8;
|
|
14
|
+
/** The floats of each chunk: its centre, its radius and the counts of its four levels. */
|
|
15
|
+
export const STRIDE = 8;
|
|
16
|
+
/** The place of the chunk count in the header. */
|
|
17
|
+
export const CHUNK_COUNT = 0;
|
|
18
|
+
/** The place of the budget, the most splats that draw, in the header. */
|
|
19
|
+
export const BUDGET = 1;
|
|
20
|
+
/** The place of the camera's first number in the header. */
|
|
21
|
+
export const EYE = 2;
|
|
22
|
+
/** The place of the cloud's bounding radius in the header. */
|
|
23
|
+
export const CLOUD_RADIUS = 5;
|
|
24
|
+
/** The place of the total that draws in the header. */
|
|
25
|
+
export const TOTAL = 6;
|
|
26
|
+
/** The number of detail levels of a chunk: every splat, then half, a quarter and an eighth. */
|
|
27
|
+
export const LEVELS = 4;
|
|
28
|
+
/** The module, which the worker instantiates at its first task and keeps. */
|
|
29
|
+
let wasm;
|
|
30
|
+
/**
|
|
31
|
+
* The next free byte of the module's memory. The module's first pages hold its shadow stack, which
|
|
32
|
+
* grows down from the top of them, so the add-on's arrays start above them.
|
|
33
|
+
*/
|
|
34
|
+
let next = 0;
|
|
35
|
+
/** The arrays that each selector keeps in this worker, by the input's `id`. */
|
|
36
|
+
const states = new Map();
|
|
37
|
+
/** The arrays of selectors that a cloud left, which a later selector takes back. */
|
|
38
|
+
const freed = [];
|
|
39
|
+
/** The bytes of a 64-bit float, and the alignment of one. */
|
|
40
|
+
const FLOAT_BYTES = 8;
|
|
41
|
+
/** Rounds `value` up to the next multiple of `unit`. */
|
|
42
|
+
function align(value, unit) {
|
|
43
|
+
return Math.ceil(value / unit) * unit;
|
|
44
|
+
}
|
|
45
|
+
/** Makes room for `bytes` in the module's memory and returns where it starts. */
|
|
46
|
+
function alloc(bytes) {
|
|
47
|
+
const module = wasm;
|
|
48
|
+
const needed = align(Math.max(1, bytes), FLOAT_BYTES);
|
|
49
|
+
// A block that a dropped selector left takes the array, so the memory stops growing after a
|
|
50
|
+
// cloud that a page creates and destroys again.
|
|
51
|
+
for (let i = 0; i < freed.length; i++) {
|
|
52
|
+
const block = freed[i];
|
|
53
|
+
if (block.bytes < needed)
|
|
54
|
+
continue;
|
|
55
|
+
freed.splice(i, 1);
|
|
56
|
+
return block.at;
|
|
57
|
+
}
|
|
58
|
+
const at = align(next, FLOAT_BYTES);
|
|
59
|
+
next = at + needed;
|
|
60
|
+
const have = module.memory.buffer.byteLength;
|
|
61
|
+
if (next > have)
|
|
62
|
+
module.memory.grow(Math.ceil((next - have) / 65536));
|
|
63
|
+
return at;
|
|
64
|
+
}
|
|
65
|
+
/** Gives a selector's array back, for the next selector to take. */
|
|
66
|
+
function release(at, bytes) {
|
|
67
|
+
freed.push({ at, bytes: align(Math.max(1, bytes), FLOAT_BYTES) });
|
|
68
|
+
}
|
|
69
|
+
/** Gives back every array that one selector holds. */
|
|
70
|
+
function drop(state) {
|
|
71
|
+
release(state.params, PARAMS * FLOAT_BYTES);
|
|
72
|
+
release(state.table, state.capacity * STRIDE * 4);
|
|
73
|
+
release(state.counts, state.capacity * 4);
|
|
74
|
+
release(state.distances, state.capacity * 4);
|
|
75
|
+
release(state.levels, state.capacity);
|
|
76
|
+
release(state.order, state.capacity * 4);
|
|
77
|
+
release(state.scratch, state.capacity * 4);
|
|
78
|
+
}
|
|
79
|
+
/** A failure of the module's code or its WebAssembly, which the engine reports at load. */
|
|
80
|
+
function loadError(message) {
|
|
81
|
+
const error = new Error(message);
|
|
82
|
+
error.name = 'TaskLoadError';
|
|
83
|
+
return error;
|
|
84
|
+
}
|
|
85
|
+
/** Starts the module on its first task in this worker, or fails the task at the load stage. */
|
|
86
|
+
function start(module) {
|
|
87
|
+
try {
|
|
88
|
+
wasm = new WebAssembly.Instance(module).exports;
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
throw loadError(`the splat selector could not start: ${e.message}`);
|
|
92
|
+
}
|
|
93
|
+
if (typeof wasm.splat_select !== 'function')
|
|
94
|
+
throw loadError('the splat selector holds no selection call');
|
|
95
|
+
// The module's memory starts with its shadow stack, so the first array goes above all of it.
|
|
96
|
+
next = wasm.memory.buffer.byteLength;
|
|
97
|
+
return wasm;
|
|
98
|
+
}
|
|
99
|
+
/** True when the typed array's bytes are shared with the thread that sent it. */
|
|
100
|
+
function shared(array) {
|
|
101
|
+
return typeof SharedArrayBuffer !== 'undefined' && array.buffer instanceof SharedArrayBuffer;
|
|
102
|
+
}
|
|
103
|
+
/** Writes a typed array's bytes into the module's memory at `at`. */
|
|
104
|
+
function writeBytes(at, array) {
|
|
105
|
+
const module = wasm;
|
|
106
|
+
const source = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
|
|
107
|
+
new Uint8Array(module.memory.buffer, at, array.byteLength).set(source);
|
|
108
|
+
}
|
|
109
|
+
/** Reads bytes from the module's memory at `at` into a typed array. */
|
|
110
|
+
function readBytes(at, array) {
|
|
111
|
+
const module = wasm;
|
|
112
|
+
const target = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
|
|
113
|
+
target.set(new Uint8Array(module.memory.buffer, at, array.byteLength));
|
|
114
|
+
}
|
|
115
|
+
/** The number of 64-bit floats in a call's parameter block. */
|
|
116
|
+
const PARAMS = 12;
|
|
117
|
+
/**
|
|
118
|
+
* The state that this worker keeps for a selector, which it makes at the first task that names it.
|
|
119
|
+
* A selector whose chunk count grows keeps its arrays while they hold the new count, and takes
|
|
120
|
+
* larger ones that double each time they must, so a cloud cut into many chunks does not leave one
|
|
121
|
+
* state's arrays behind for each chunk.
|
|
122
|
+
*/
|
|
123
|
+
function stateFor(input) {
|
|
124
|
+
const kept = states.get(input.id);
|
|
125
|
+
if (kept && kept.capacity >= input.chunks) {
|
|
126
|
+
// The caller names a new version when the chunk table changes, so a moved frame keeps the
|
|
127
|
+
// copy that the worker already holds and copies no table.
|
|
128
|
+
if (kept.version === input.version && kept.chunks === input.chunks)
|
|
129
|
+
return kept;
|
|
130
|
+
kept.version = input.version;
|
|
131
|
+
kept.chunks = input.chunks;
|
|
132
|
+
writeBytes(kept.table, input.view.subarray(HEADER, HEADER + input.chunks * STRIDE));
|
|
133
|
+
return kept;
|
|
134
|
+
}
|
|
135
|
+
const capacity = kept ? Math.max(input.chunks, kept.capacity * 2) : input.chunks;
|
|
136
|
+
if (kept)
|
|
137
|
+
drop(kept);
|
|
138
|
+
const state = {
|
|
139
|
+
version: input.version,
|
|
140
|
+
chunks: input.chunks,
|
|
141
|
+
capacity,
|
|
142
|
+
params: alloc(PARAMS * FLOAT_BYTES),
|
|
143
|
+
table: alloc(capacity * STRIDE * 4),
|
|
144
|
+
counts: alloc(capacity * 4),
|
|
145
|
+
distances: alloc(capacity * 4),
|
|
146
|
+
levels: alloc(capacity),
|
|
147
|
+
order: alloc(capacity * 4),
|
|
148
|
+
scratch: alloc(capacity * 4),
|
|
149
|
+
};
|
|
150
|
+
writeBytes(state.table, input.view.subarray(HEADER, HEADER + input.chunks * STRIDE));
|
|
151
|
+
states.set(input.id, state);
|
|
152
|
+
return state;
|
|
153
|
+
}
|
|
154
|
+
/** Chooses each chunk's count, writes it into the caller's buffer, and answers the total. */
|
|
155
|
+
function select(module, state, input) {
|
|
156
|
+
// The parameter block, written in place so a call makes no array.
|
|
157
|
+
const params = new Float64Array(module.memory.buffer, state.params, PARAMS);
|
|
158
|
+
params[0] = input.chunks;
|
|
159
|
+
params[1] = input.budget;
|
|
160
|
+
params[2] = input.eyeX;
|
|
161
|
+
params[3] = input.eyeY;
|
|
162
|
+
params[4] = input.eyeZ;
|
|
163
|
+
params[5] = input.view[CLOUD_RADIUS];
|
|
164
|
+
params[6] = state.table;
|
|
165
|
+
params[7] = state.counts;
|
|
166
|
+
params[8] = state.distances;
|
|
167
|
+
params[9] = state.levels;
|
|
168
|
+
params[10] = state.order;
|
|
169
|
+
params[11] = state.scratch;
|
|
170
|
+
const total = module.splat_select(state.params);
|
|
171
|
+
// The counts follow the chunk table in the buffer that the sketch reads.
|
|
172
|
+
if (shared(input.view)) {
|
|
173
|
+
const offset = (HEADER + input.chunks * STRIDE) * 4;
|
|
174
|
+
readBytes(state.counts, new Float32Array(input.view.buffer, offset, input.chunks));
|
|
175
|
+
return { total };
|
|
176
|
+
}
|
|
177
|
+
const copy = new Float32Array(input.chunks);
|
|
178
|
+
readBytes(state.counts, copy);
|
|
179
|
+
return { total, counts: copy };
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Runs one call. The engine calls this once for each task, with the compiled WebAssembly module
|
|
183
|
+
* that the task names.
|
|
184
|
+
*/
|
|
185
|
+
export function run(input, modules) {
|
|
186
|
+
const request = input;
|
|
187
|
+
if (request.op === 'drop') {
|
|
188
|
+
const state = states.get(request.id);
|
|
189
|
+
if (state) {
|
|
190
|
+
drop(state);
|
|
191
|
+
states.delete(request.id);
|
|
192
|
+
}
|
|
193
|
+
return { output: { total: 0 } };
|
|
194
|
+
}
|
|
195
|
+
const module = wasm ?? start(modules('splats'));
|
|
196
|
+
const state = stateFor(request);
|
|
197
|
+
return { output: select(module, state, request) };
|
|
198
|
+
}
|
package/lib/select.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Task } from '@null3d/engine';
|
|
2
|
+
import type { SplatChunk } from './chunks.js';
|
|
3
|
+
import { type SelectAnswer } from './select-task.js';
|
|
4
|
+
/** What the selection needs of a chunk: its bounds and its count, before its data arrives. */
|
|
5
|
+
export type ChunkBounds = Pick<SplatChunk, 'center' | 'radius' | 'count'>;
|
|
6
|
+
/** The task that chooses the splats: its module, and the WebAssembly module that it calls. */
|
|
7
|
+
export declare const SELECT_TASK: Task;
|
|
8
|
+
/** The buffer that the selection task reads, and the call that fills and sends it. */
|
|
9
|
+
export declare class SplatSelector {
|
|
10
|
+
private readonly view;
|
|
11
|
+
/** The task's input, which keeps its shape so a call makes no object. */
|
|
12
|
+
private readonly input;
|
|
13
|
+
/** How many splats draw of each chunk, which the task writes in the shared buffer. */
|
|
14
|
+
readonly counts: Float32Array;
|
|
15
|
+
/** This selector's number, which a grown cloud hands to its next selector. */
|
|
16
|
+
readonly id: number;
|
|
17
|
+
/**
|
|
18
|
+
* Makes the buffer of `chunks`, which stays the same while they do. `previousId` names the
|
|
19
|
+
* selector that this one replaces when a cloud grows, so the worker keeps its arrays while
|
|
20
|
+
* they hold the new chunk count.
|
|
21
|
+
*/
|
|
22
|
+
constructor(chunks: readonly ChunkBounds[], previousId?: number);
|
|
23
|
+
/**
|
|
24
|
+
* Asks a job worker which splats draw from `eye`, with `budget` splats at most. The answer's
|
|
25
|
+
* promise settles when the worker has filled `counts` and `total`. Without shared memory, the
|
|
26
|
+
* caller writes the answer's counts into `counts`.
|
|
27
|
+
*/
|
|
28
|
+
select(eye: ArrayLike<number>, budget: number): Promise<SelectAnswer>;
|
|
29
|
+
/**
|
|
30
|
+
* Frees this selector's arrays in the worker. A cloud's next selector takes them, or a later
|
|
31
|
+
* cloud does, so a page that makes and frees clouds does not grow the module's memory.
|
|
32
|
+
*/
|
|
33
|
+
drop(): void;
|
|
34
|
+
}
|
package/lib/select.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// The sketch's side of the selection: a buffer of chunks for the task, and the call that asks a job
|
|
2
|
+
// worker which splats draw. The selection and its distance sort run in the add-on's WebAssembly
|
|
3
|
+
// module in the worker (hard rule 42), so a frame's loop over chunks runs in Rust. The buffer is
|
|
4
|
+
// shared where the page allows it, so a call copies nothing but the few numbers of its answer and
|
|
5
|
+
// the counts. The task writes the counts into the buffer, which the sketch reads straight from it,
|
|
6
|
+
// so no count crosses a message on a page with shared memory and a call allocates no array.
|
|
7
|
+
import { runTask } from '@null3d/engine';
|
|
8
|
+
import { BUDGET, CHUNK_COUNT, CLOUD_RADIUS, EYE, HEADER, STRIDE, } from './select-task.js';
|
|
9
|
+
/** The task that chooses the splats: its module, and the WebAssembly module that it calls. */
|
|
10
|
+
export const SELECT_TASK = {
|
|
11
|
+
name: 'splats-select',
|
|
12
|
+
script: new URL('./select-task.js', import.meta.url),
|
|
13
|
+
wasm: [
|
|
14
|
+
{
|
|
15
|
+
name: 'splats',
|
|
16
|
+
url: new URL('../dist/splats.wasm', import.meta.url),
|
|
17
|
+
what: 'the splat selector',
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
};
|
|
21
|
+
/** One selector's number each, so a worker keeps each selector's arrays apart. */
|
|
22
|
+
let lastId = 0;
|
|
23
|
+
/** A number for each buffer of a selector, so a worker copies the chunk table again. */
|
|
24
|
+
let lastVersion = 0;
|
|
25
|
+
/** The buffer that the selection task reads, and the call that fills and sends it. */
|
|
26
|
+
export class SplatSelector {
|
|
27
|
+
view;
|
|
28
|
+
/** The task's input, which keeps its shape so a call makes no object. */
|
|
29
|
+
input;
|
|
30
|
+
/** How many splats draw of each chunk, which the task writes in the shared buffer. */
|
|
31
|
+
counts;
|
|
32
|
+
/** This selector's number, which a grown cloud hands to its next selector. */
|
|
33
|
+
id;
|
|
34
|
+
/**
|
|
35
|
+
* Makes the buffer of `chunks`, which stays the same while they do. `previousId` names the
|
|
36
|
+
* selector that this one replaces when a cloud grows, so the worker keeps its arrays while
|
|
37
|
+
* they hold the new chunk count.
|
|
38
|
+
*/
|
|
39
|
+
constructor(chunks, previousId) {
|
|
40
|
+
const floats = HEADER + chunks.length * STRIDE + chunks.length;
|
|
41
|
+
const buffer = typeof SharedArrayBuffer === 'undefined'
|
|
42
|
+
? new ArrayBuffer(floats * 4)
|
|
43
|
+
: new SharedArrayBuffer(floats * 4);
|
|
44
|
+
this.view = new Float32Array(buffer);
|
|
45
|
+
this.id = previousId ?? ++lastId;
|
|
46
|
+
this.input = {
|
|
47
|
+
op: 'select',
|
|
48
|
+
id: this.id,
|
|
49
|
+
version: ++lastVersion,
|
|
50
|
+
chunks: chunks.length,
|
|
51
|
+
budget: 0,
|
|
52
|
+
eyeX: 0,
|
|
53
|
+
eyeY: 0,
|
|
54
|
+
eyeZ: 0,
|
|
55
|
+
view: this.view,
|
|
56
|
+
};
|
|
57
|
+
this.view[CHUNK_COUNT] = chunks.length;
|
|
58
|
+
this.view[CLOUD_RADIUS] = cloudRadiusOf(chunks);
|
|
59
|
+
this.counts = this.view.subarray(HEADER + chunks.length * STRIDE, floats);
|
|
60
|
+
chunks.forEach((chunk, i) => {
|
|
61
|
+
const at = HEADER + i * STRIDE;
|
|
62
|
+
this.view[at] = chunk.center[0];
|
|
63
|
+
this.view[at + 1] = chunk.center[1];
|
|
64
|
+
this.view[at + 2] = chunk.center[2];
|
|
65
|
+
this.view[at + 3] = chunk.radius;
|
|
66
|
+
// Each level keeps a fraction of the chunk: all of it, a half, a quarter, an eighth.
|
|
67
|
+
for (let level = 0; level < 4; level++)
|
|
68
|
+
this.view[at + 4 + level] = Math.ceil(chunk.count / 2 ** level);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Asks a job worker which splats draw from `eye`, with `budget` splats at most. The answer's
|
|
73
|
+
* promise settles when the worker has filled `counts` and `total`. Without shared memory, the
|
|
74
|
+
* caller writes the answer's counts into `counts`.
|
|
75
|
+
*/
|
|
76
|
+
select(eye, budget) {
|
|
77
|
+
this.view[BUDGET] = budget;
|
|
78
|
+
this.view[EYE] = eye[0];
|
|
79
|
+
this.view[EYE + 1] = eye[1];
|
|
80
|
+
this.view[EYE + 2] = eye[2];
|
|
81
|
+
this.input.budget = budget;
|
|
82
|
+
this.input.eyeX = eye[0];
|
|
83
|
+
this.input.eyeY = eye[1];
|
|
84
|
+
this.input.eyeZ = eye[2];
|
|
85
|
+
return runTask(SELECT_TASK, this.input);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Frees this selector's arrays in the worker. A cloud's next selector takes them, or a later
|
|
89
|
+
* cloud does, so a page that makes and frees clouds does not grow the module's memory.
|
|
90
|
+
*/
|
|
91
|
+
drop() {
|
|
92
|
+
void runTask(SELECT_TASK, { op: 'drop', id: this.id }).catch(() => undefined);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The radius of a sphere that holds the cloud: the farthest chunk's own radius from the cloud's
|
|
97
|
+
* center. The selection measures distance in this size, so a finer cut does not thin the view.
|
|
98
|
+
*/
|
|
99
|
+
function cloudRadiusOf(chunks) {
|
|
100
|
+
if (chunks.length === 0)
|
|
101
|
+
return 0;
|
|
102
|
+
let x = 0;
|
|
103
|
+
let y = 0;
|
|
104
|
+
let z = 0;
|
|
105
|
+
for (const chunk of chunks) {
|
|
106
|
+
x += chunk.center[0];
|
|
107
|
+
y += chunk.center[1];
|
|
108
|
+
z += chunk.center[2];
|
|
109
|
+
}
|
|
110
|
+
x /= chunks.length;
|
|
111
|
+
y /= chunks.length;
|
|
112
|
+
z /= chunks.length;
|
|
113
|
+
let radius = 0;
|
|
114
|
+
for (const chunk of chunks) {
|
|
115
|
+
const dx = chunk.center[0] - x;
|
|
116
|
+
const dy = chunk.center[1] - y;
|
|
117
|
+
const dz = chunk.center[2] - z;
|
|
118
|
+
radius = Math.max(radius, Math.sqrt(dx * dx + dy * dy + dz * dz) + chunk.radius);
|
|
119
|
+
}
|
|
120
|
+
return radius;
|
|
121
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export default __null3dShader("[{\"webgl2\":{\"permutation\":0,\"wgsl\":null,\"glsl\":{\"main\":{\"vertex\":{\"source\":-1,\"uniformBlocks\":[{\"name\":\"Frame_block_2Vertex\",\"group\":0,\"binding\":0},{\"name\":\"CellOffsets_block_1Vertex\",\"group\":0,\"binding\":2},{\"name\":\"DrawTable_block_0Vertex\",\"group\":1,\"binding\":0}],\"textures\":[{\"name\":\"_group_2_binding_0_vs\",\"group\":2,\"binding\":0,\"sampler\":null},{\"name\":\"_group_2_binding_1_vs\",\"group\":2,\"binding\":1,\"sampler\":null},{\"name\":\"_group_2_binding_2_vs\",\"group\":2,\"binding\":2,\"sampler\":null},{\"name\":\"_group_2_binding_3_vs\",\"group\":2,\"binding\":3,\"sampler\":null}]},\"fragment\":{\"source\":-2,\"uniformBlocks\":[{\"name\":\"Frame_block_0Fragment\",\"group\":0,\"binding\":0}],\"textures\":[]}}}}}]");
|
|
2
|
+
|
|
3
|
+
function __null3dShader(text, hot, load, index, kind) {
|
|
4
|
+
const paths = __null3dShader.paths || (__null3dShader.paths = ["{\"blocks\":[],\"lists\":[]}", "{\"blocks\":[\"#version 300 es\",\"\\nuniform vec2 null3d_depth_mapping;\\n\",\"\\nprecision highp float;\",\"\\nprecision highp int;\\n\",\"\\nuniform highp uint naga_vs_first_instance;\\n\",\"\\nstruct Output {\\n float exposure;\\n highp uint tone_mapping;\\n highp uint flags;\\n highp uint render_size;\\n};\",\"\\nstruct Fog {\\n vec4 color;\\n vec4 shape;\\n float sun_glow;\\n float sun_exponent;\\n float spare;\\n highp uint curve;\\n};\",\"\\nstruct Aerial {\\n vec4 rayleigh;\\n vec4 shape;\\n vec4 sun;\\n vec4 sun_light;\\n vec4 moon;\\n vec4 moon_light;\\n};\",\"\\nstruct EnvironmentLight {\\n vec4 sh_a;\\n vec4 sh_b;\\n vec4 sh_c;\\n vec4 sh_d;\\n vec4 sh_e;\\n vec4 sh_f;\\n vec4 sh_g;\\n vec4 sh_h;\\n vec4 sh_i;\\n vec4 rotation_x;\\n vec4 rotation_y;\\n vec4 rotation_z;\\n vec4 params;\\n};\",\"\\nstruct ProbeGrid {\\n vec4 origin;\\n vec4 inverse_spacing;\\n vec4 counts;\\n vec4 params;\\n};\",\"\\nstruct Frame {\\n mat4x4 view_proj;\\n vec4 camera_position;\\n vec4 sun_direction;\\n vec4 sun_color;\\n vec4 fill_dir[3];\\n vec4 fill_col[3];\\n vec4 ambient;\\n Output output_;\\n Fog fog;\\n vec4 cluster_depth;\\n vec4 cluster_grid;\\n vec4 cluster_fit;\\n vec4 clock;\\n vec4 camera_world;\\n vec4 target_size;\\n vec4 camera_range;\\n vec4 occlusion;\\n EnvironmentLight environment;\\n ProbeGrid probe_grid;\\n vec4 hemisphere_x;\\n vec4 hemisphere_y;\\n vec4 hemisphere_z;\\n vec4 shadow_origin;\\n mat4x4 view;\\n mat4x4 projection;\\n mat4x4 reflection_reprojection;\\n vec4 reflection;\\n vec4 reflection_corner;\\n vec4 jitter;\\n Aerial aerial;\\n vec4 vignette;\\n mat4x4 camera_view_proj;\\n vec4 camera_target;\\n vec4 camera_eye;\\n vec4 bounce;\\n};\",\"\\nstruct Transform {\\n vec4 x;\\n vec4 y;\\n vec4 z;\\n};\",\"\\nstruct InstanceIn {\\n highp uint instance;\\n};\",\"\\nstruct Instance {\\n vec4 row_x;\\n vec4 row_y;\\n vec4 row_z;\\n highp uint material;\\n highp uint first_joint;\\n highp uint morph_weights;\\n bool drawn;\\n highp uint source;\\n bool streamed;\\n};\",\"\\nstruct DrawTable {\\n highp uvec4 items[1];\\n};\",\"\\nstruct CellOffsets {\\n vec4 items[512];\\n};\",\"\\nstruct FrameValues {\\n float time;\\n float deltaTime;\\n highp uint index;\\n bool lastFrame;\\n vec2 resolution;\\n};\",\"\\nstruct CameraValues {\\n vec3 position;\\n mat4x4 viewProjection;\\n mat4x4 view;\\n mat4x4 projection;\\n float near;\\n float far;\\n};\",\"\\nstruct ObjectValues {\\n vec3 position;\\n vec4 values;\\n mat4x4 worldMatrix;\\n mat3x3 normalMatrix;\\n highp uint id;\\n};\",\"\\nstruct Varyings {\\n vec4 clip;\\n vec2 offset;\\n vec3 conic;\\n vec4 color;\\n};\",\"\\nconst vec4 OUTSIDE_CLIP = vec4(2.0, 2.0, 2.0, 1.0);\",\"\\nconst highp uint INDEX_ROW_SHIFT = 11u;\",\"\\nconst highp uint NO_ROW = 4294967295u;\",\"\\nconst highp uint MATRIX_ROW_SHIFT = 9u;\",\"\\nconst highp uint CELL_SHIFT = 23u;\",\"\\nconst float EXTENT = 3.3;\",\"\\nconst float BLUR = 0.09;\",\"\\nconst float position_scale = 1.0;\\n\",\"\\nlayout(std140) uniform DrawTable_block_0Vertex { DrawTable _group_1_binding_0_vs; };\\n\",\"\\nuniform highp usampler2D _group_2_binding_2_vs;\\n\",\"\\nuniform highp usampler2D _group_2_binding_3_vs;\\n\",\"\\nuniform highp sampler2D _group_2_binding_0_vs;\\n\",\"\\nuniform highp sampler2D _group_2_binding_1_vs;\\n\",\"\\nlayout(std140) uniform CellOffsets_block_1Vertex { CellOffsets _group_0_binding_2_vs; };\\n\",\"\\nlayout(std140) uniform Frame_block_2Vertex { Frame _group_0_binding_0_vs; };\\n\",\"\\nfloat frame_null3d_builtins_0_ = 0.0;\\n\",\"\\nfloat frame_null3d_builtins_1_ = 0.0;\\n\",\"\\nhighp uint frame_null3d_builtins_2_ = 0u;\\n\",\"\\nbool frame_null3d_builtins_3_ = false;\\n\",\"\\nvec2 frame_null3d_builtins_4_ = vec2(0.0);\\n\",\"\\nvec3 camera_0_ = vec3(0.0);\\n\",\"\\nmat4x4 camera_1_ = mat4x4(0.0);\\n\",\"\\nmat4x4 camera_2_ = mat4x4(0.0);\\n\",\"\\nmat4x4 camera_3_ = mat4x4(0.0);\\n\",\"\\nfloat camera_4_ = 0.0;\\n\",\"\\nfloat camera_5_ = 0.0;\\n\",\"\\nvec3 object_0_ = vec3(0.0);\\n\",\"\\nvec4 object_1_ = vec4(0.0);\\n\",\"\\nmat4x4 object_2_ = mat4x4(0.0);\\n\",\"\\nmat3x3 object_3_ = mat3x3(0.0);\\n\",\"\\nhighp uint object_4_ = 0u;\\n\",\"\\nlayout(location = 0) in vec3 _p2vs_location0;\",\"\\nlayout(location = 1) in vec3 _p2vs_location1;\",\"\\nlayout(location = 2) in vec2 _p2vs_location2;\",\"\\nlayout(location = 4) in vec4 _p2vs_location4;\",\"\\nlayout(location = 5) in vec4 _p2vs_location5;\",\"\\nsmooth out vec2 _vs2fs_location0;\",\"\\nflat out vec3 _vs2fs_location1;\",\"\\nflat out vec4 _vs2fs_location2;\\n\",\"\\nvec4 clip_with_jitter(mat4x4 view_proj, vec2 jitter, vec3 relative_position) {\\n vec4 clip = (view_proj * vec4(relative_position, 1.0));\\n return (clip + vec4((jitter * clip.w), 0.0, 0.0));\\n}\\n\",\"\\nvec3 transform_point(vec4 param_1, vec4 param_2, vec4 param_3, vec3 p) {\\n vec4 q_1 = vec4(p, 1.0);\\n return vec3(dot(param_1, q_1), dot(param_2, q_1), dot(param_3, q_1));\\n}\\n\",\"\\nvec3 transform_direction(vec4 param_4, vec4 param_5, vec4 param_6, vec3 d) {\\n vec4 q_2 = vec4(d, 0.0);\\n return vec3(dot(param_4, q_2), dot(param_5, q_2), dot(param_6, q_2));\\n}\\n\",\"\\nhighp uvec4 draw_record(highp uint param_7) {\\n highp uvec4 _e3 = _group_1_binding_0_vs.items[0];\\n return _e3;\\n}\\n\",\"\\nvoid instance_of(highp uvec4 record, highp uint instance, inout vec4 param_8, inout vec4 param_9, inout vec4 param_10, inout highp uint param_11, inout highp uint param_12, inout highp uint param_13, inout bool param_14, inout highp uint param_15, inout bool param_16) {\\n highp uint source = 0u;\\n vec4 local_13 = vec4(0.0);\\n vec4 local_14 = vec4(0.0);\\n vec4 local_15 = vec4(0.0);\\n highp uint local_16 = 0u;\\n highp uint local_17 = 0u;\\n highp uint local_18 = 0u;\\n bool local_19 = false;\\n highp uint local_20 = 0u;\\n bool local_21 = false;\\n highp uint shift = record.w;\\n highp uint slot = (record.x + (instance >> shift));\\n highp uvec4 _e13 = texelFetch(_group_2_binding_2_vs, ivec2(uvec2((slot & 2047u), (slot >> INDEX_ROW_SHIFT))), 0);\\n highp uint entry = _e13.x;\\n source = (entry & 8388607u);\\n if ((shift != 0u)) {\\n highp uint _e20 = source;\\n highp uint place = ((_e20 << shift) | (instance & ((1u << shift) - 1u)));\\n highp uvec4 _e34 = texelFetch(_group_2_binding_3_vs, ivec2(uvec2((place & 2047u), (place >> INDEX_ROW_SHIFT))), 0);\\n source = _e34.x;\\n }\\n highp uint _e45 = source;\\n local_19 = (_e45 != NO_ROW);\\n highp uint _e48 = source;\\n bool _e49 = local_19;\\n highp uint row = (_e49 ? _e48 : 0u);\\n highp uvec2 at = uvec2(((row & 511u) * 3u), (row >> MATRIX_ROW_SHIFT));\\n if ((record.z == 0u)) {\\n vec4 _e64 = texelFetch(_group_2_binding_0_vs, ivec2(at), 0);\\n local_13 = _e64;\\n vec4 _e71 = texelFetch(_group_2_binding_0_vs, ivec2((at + uvec2(1u, 0u))), 0);\\n local_14 = _e71;\\n vec4 _e78 = texelFetch(_group_2_binding_0_vs, ivec2((at + uvec2(2u, 0u))), 0);\\n local_15 = _e78;\\n } else {\\n vec4 _e81 = texelFetch(_group_2_binding_1_vs, ivec2(at), 0);\\n local_13 = _e81;\\n vec4 _e88 = texelFetch(_group_2_binding_1_vs, ivec2((at + uvec2(1u, 0u))), 0);\\n local_14 = _e88;\\n vec4 _e95 = texelFetch(_group_2_binding_1_vs, ivec2((at + uvec2(2u, 0u))), 0);\\n local_15 = _e95;\\n }\\n vec4 offset = _group_0_binding_2_vs.items[(entry >> CELL_SHIFT)];\\n float _e103 = local_13.w;\\n local_13.w = (_e103 + offset.x);\\n float _e107 = local_14.w;\\n local_14.w = (_e107 + offset.y);\\n float _e111 = local_15.w;\\n local_15.w = (_e111 + offset.z);\\n local_16 = record.y;\\n local_20 = row;\\n local_21 = (record.z != 0u);\\n local_17 = 0u;\\n local_18 = 0u;\\n vec4 _e121 = local_13;\\n vec4 _e123 = local_14;\\n vec4 _e125 = local_15;\\n highp uint _e127 = local_16;\\n highp uint _e129 = local_17;\\n highp uint _e131 = local_18;\\n bool _e133 = local_19;\\n highp uint _e135 = local_20;\\n bool _e137 = local_21;\\n param_8 = _e121;\\n param_9 = _e123;\\n param_10 = _e125;\\n param_11 = _e127;\\n param_12 = _e129;\\n param_13 = _e131;\\n param_14 = _e133;\\n param_15 = _e135;\\n param_16 = _e137;\\n return;\\n}\\n\",\"\\nvoid find_instance(highp uint param_17, inout vec4 param_18, inout vec4 param_19, inout vec4 param_20, inout highp uint param_21, inout highp uint param_22, inout highp uint param_23, inout bool param_24, inout highp uint param_25, inout bool param_26) {\\n vec4 local_22 = vec4(0.0);\\n vec4 local_23 = vec4(0.0);\\n vec4 local_24 = vec4(0.0);\\n highp uint local_25 = 0u;\\n highp uint local_26 = 0u;\\n highp uint local_27 = 0u;\\n bool local_28 = false;\\n highp uint local_29 = 0u;\\n bool local_30 = false;\\n highp uvec4 _e1 = draw_record(param_17);\\n instance_of(_e1, param_17, local_22, local_23, local_24, local_25, local_26, local_27, local_28, local_29, local_30);\\n vec4 _e13 = local_22;\\n vec4 _e15 = local_23;\\n vec4 _e17 = local_24;\\n highp uint _e19 = local_25;\\n highp uint _e21 = local_26;\\n highp uint _e23 = local_27;\\n bool _e25 = local_28;\\n highp uint _e27 = local_29;\\n bool _e29 = local_30;\\n param_18 = _e13;\\n param_19 = _e15;\\n param_20 = _e17;\\n param_21 = _e19;\\n param_22 = _e21;\\n param_23 = _e23;\\n param_24 = _e25;\\n param_25 = _e27;\\n param_26 = _e29;\\n return;\\n}\\n\",\"\\nvec4 clip_of(vec4 param_27, vec4 param_28, vec4 param_29, highp uint param_30, highp uint param_31, highp uint param_32, bool param_33, highp uint param_34, bool param_35, vec3 relative) {\\n if (!(param_33)) {\\n return OUTSIDE_CLIP;\\n }\\n mat4x4 _e108 = _group_0_binding_0_vs.view_proj;\\n vec4 _e206 = _group_0_binding_0_vs.jitter;\\n vec4 _e209 = clip_with_jitter(_e108, _e206.xy, relative);\\n return _e209;\\n}\\n\",\"\\nvoid transform_of(vec4 param_36, vec4 param_37, vec4 param_38, highp uint param_39, highp uint param_40, highp uint param_41, bool param_42, highp uint param_43, bool param_44, inout vec4 param_45, inout vec4 param_46, inout vec4 param_47) {\\n param_45 = param_36;\\n param_46 = param_37;\\n param_47 = param_38;\\n return;\\n}\\n\",\"\\nvec3 relative_position_1(vec4 param_48, vec4 param_49, vec4 param_50, highp uint param_51, highp uint param_52, highp uint param_53, bool param_54, highp uint param_55, bool param_56, vec3 position_1) {\\n vec4 local_31 = vec4(0.0);\\n vec4 local_32 = vec4(0.0);\\n vec4 local_33 = vec4(0.0);\\n transform_of(param_48, param_49, param_50, param_51, param_52, param_53, param_54, param_55, param_56, local_31, local_32, local_33);\\n vec4 _e19 = local_31;\\n vec4 _e21 = local_32;\\n vec4 _e23 = local_33;\\n vec3 _e25 = transform_point(_e19, _e21, _e23, position_1);\\n return _e25;\\n}\\n\",\"\\nvec3 world_direction(vec4 param_57, vec4 param_58, vec4 param_59, highp uint param_60, highp uint param_61, highp uint param_62, bool param_63, highp uint param_64, bool param_65, vec3 direction_1) {\\n vec4 local_34 = vec4(0.0);\\n vec4 local_35 = vec4(0.0);\\n vec4 local_36 = vec4(0.0);\\n transform_of(param_57, param_58, param_59, param_60, param_61, param_62, param_63, param_64, param_65, local_34, local_35, local_36);\\n vec4 _e19 = local_34;\\n vec4 _e21 = local_35;\\n vec4 _e23 = local_36;\\n vec3 _e25 = transform_direction(_e19, _e21, _e23, direction_1);\\n return _e25;\\n}\\n\",\"\\nvec3 mesh_position(vec3 p_1) {\\n return (p_1 * position_scale);\\n}\\n\",\"\\nvoid fill_builtins(vec3 origin) {\\n vec4 clock = _group_0_binding_0_vs.clock;\\n vec4 _e195 = _group_0_binding_0_vs.camera_world;\\n vec3 world = _e195.xyz;\\n vec4 _e298 = _group_0_binding_0_vs.camera_target;\\n frame_null3d_builtins_0_ = clock.x;\\n frame_null3d_builtins_1_ = clock.y;\\n frame_null3d_builtins_2_ = floatBitsToUint(clock.z);\\n frame_null3d_builtins_3_ = false;\\n frame_null3d_builtins_4_ = _e298.xy;\\n vec4 range = _group_0_binding_0_vs.camera_range;\\n mat4x4 _e501 = _group_0_binding_0_vs.camera_view_proj;\\n mat4x4 _e599 = _group_0_binding_0_vs.view;\\n mat4x4 _e697 = _group_0_binding_0_vs.projection;\\n camera_0_ = world;\\n camera_1_ = _e501;\\n camera_2_ = _e599;\\n camera_3_ = _e697;\\n camera_4_ = range.x;\\n camera_5_ = range.y;\\n object_0_ = (world + origin);\\n object_1_ = vec4(0.0);\\n object_2_ = mat4x4(0.0);\\n object_3_ = mat3x3(0.0);\\n object_4_ = 0u;\\n return;\\n}\\n\",\"\\nvec3 turned(vec4 q, vec3 v) {\\n vec3 u = q.xyz;\\n float s = q.w;\\n return ((2.0 * ((dot(u, v) * u) + (s * cross(u, v)))) + (((s * s) - dot(u, u)) * v));\\n}\\n\",\"\\nvoid main() {\\n vec3 position = _p2vs_location0;\\n vec3 normal = _p2vs_location1;\\n vec2 uv0_ = _p2vs_location2;\\n vec4 tangent = _p2vs_location4;\\n vec4 color = _p2vs_location5;\\n highp uint param = (uint(gl_InstanceID) + naga_vs_first_instance);\\n vec2 direction = vec2(0.0);\\n vec4 local = vec4(0.0);\\n vec4 local_1 = vec4(0.0);\\n vec4 local_2 = vec4(0.0);\\n highp uint local_3 = 0u;\\n highp uint local_4 = 0u;\\n highp uint local_5 = 0u;\\n bool local_6 = false;\\n highp uint local_7 = 0u;\\n bool local_8 = false;\\n vec4 local_9 = vec4(0.0);\\n vec2 local_10 = vec2(0.0);\\n vec3 local_11 = vec3(0.0);\\n vec4 local_12 = vec4(0.0);\\n find_instance(param, local, local_1, local_2, local_3, local_4, local_5, local_6, local_7, local_8);\\n vec3 _e29 = mesh_position(position);\\n vec4 _e31 = local;\\n vec4 _e33 = local_1;\\n vec4 _e35 = local_2;\\n highp uint _e37 = local_3;\\n highp uint _e39 = local_4;\\n highp uint _e41 = local_5;\\n bool _e43 = local_6;\\n highp uint _e45 = local_7;\\n bool _e47 = local_8;\\n vec3 _e48 = relative_position_1(_e31, _e33, _e35, _e37, _e39, _e41, _e43, _e45, _e47, _e29);\\n vec4 _e52 = local;\\n vec4 _e54 = local_1;\\n vec4 _e56 = local_2;\\n highp uint _e58 = local_3;\\n highp uint _e60 = local_4;\\n highp uint _e62 = local_5;\\n bool _e64 = local_6;\\n highp uint _e66 = local_7;\\n bool _e68 = local_8;\\n vec3 _e69 = relative_position_1(_e52, _e54, _e56, _e58, _e60, _e62, _e64, _e66, _e68, vec3(0.0));\\n fill_builtins(_e69);\\n vec3 _e76 = turned(tangent, vec3(normal.x, 0.0, 0.0));\\n vec3 _e81 = turned(tangent, vec3(0.0, normal.y, 0.0));\\n vec3 _e86 = turned(tangent, vec3(0.0, 0.0, normal.z));\\n vec4 _e88 = local;\\n vec4 _e90 = local_1;\\n vec4 _e92 = local_2;\\n highp uint _e94 = local_3;\\n highp uint _e96 = local_4;\\n highp uint _e98 = local_5;\\n bool _e100 = local_6;\\n highp uint _e102 = local_7;\\n bool _e104 = local_8;\\n vec3 _e105 = world_direction(_e88, _e90, _e92, _e94, _e96, _e98, _e100, _e102, _e104, _e76);\\n vec4 _e107 = local;\\n vec4 _e109 = local_1;\\n vec4 _e111 = local_2;\\n highp uint _e113 = local_3;\\n highp uint _e115 = local_4;\\n highp uint _e117 = local_5;\\n bool _e119 = local_6;\\n highp uint _e121 = local_7;\\n bool _e123 = local_8;\\n vec3 _e124 = world_direction(_e107, _e109, _e111, _e113, _e115, _e117, _e119, _e121, _e123, _e81);\\n vec4 _e126 = local;\\n vec4 _e128 = local_1;\\n vec4 _e130 = local_2;\\n highp uint _e132 = local_3;\\n highp uint _e134 = local_4;\\n highp uint _e136 = local_5;\\n bool _e138 = local_6;\\n highp uint _e140 = local_7;\\n bool _e142 = local_8;\\n vec3 _e143 = world_direction(_e126, _e128, _e130, _e132, _e134, _e136, _e138, _e140, _e142, _e86);\\n mat4x4 view = camera_2_;\\n vec3 center_view = (view * vec4(_e48, 1.0)).xyz;\\n float depth = -(center_view.z);\\n local_10 = vec2(0.0);\\n local_11 = vec3(0.0);\\n local_12 = color;\\n vec4 _e167 = local;\\n vec4 _e169 = local_1;\\n vec4 _e171 = local_2;\\n highp uint _e173 = local_3;\\n highp uint _e175 = local_4;\\n highp uint _e177 = local_5;\\n bool _e179 = local_6;\\n highp uint _e181 = local_7;\\n bool _e183 = local_8;\\n vec4 _e184 = clip_of(_e167, _e169, _e171, _e173, _e175, _e177, _e179, _e181, _e183, _e48);\\n local_9 = _e184;\\n float _e191 = camera_4_;\\n if ((depth <= _e191)) {\\n vec4 _e194 = local_9;\\n vec2 _e196 = local_10;\\n vec3 _e198 = local_11;\\n vec4 _e200 = local_12;\\n gl_Position = _e194;\\n _vs2fs_location0 = _e196;\\n _vs2fs_location1 = _e198;\\n _vs2fs_location2 = _e200;\\n gl_Position.z = gl_Position.z * null3d_depth_mapping.x + gl_Position.w * null3d_depth_mapping.y;\\n return;\\n }\\n vec2 res = frame_null3d_builtins_4_;\\n float _e216 = camera_3_[0][0];\\n float fx = (((_e216 * res.x) * 0.5) / depth);\\n float _e230 = camera_3_[1][1];\\n float fy = (((_e230 * res.y) * 0.5) / depth);\\n vec3 jx = vec3(fx, 0.0, ((-(fx) * center_view.x) / depth));\\n vec3 jy = vec3(0.0, -(fy), ((fy * center_view.y) / depth));\\n vec3 va = (view * vec4(_e105, 0.0)).xyz;\\n vec3 vb = (view * vec4(_e124, 0.0)).xyz;\\n vec3 vc = (view * vec4(_e143, 0.0)).xyz;\\n vec2 ca = vec2(dot(jx, va), dot(jy, va));\\n vec2 cb = vec2(dot(jx, vb), dot(jy, vb));\\n vec2 cc = vec2(dot(jx, vc), dot(jy, vc));\\n float sxx = ((((ca.x * ca.x) + (cb.x * cb.x)) + (cc.x * cc.x)) + BLUR);\\n float sxy = (((ca.x * ca.y) + (cb.x * cb.y)) + (cc.x * cc.y));\\n float syy = ((((ca.y * ca.y) + (cb.y * cb.y)) + (cc.y * cc.y)) + BLUR);\\n float det = ((sxx * syy) - (sxy * sxy));\\n if ((det <= 1e-12)) {\\n vec4 _e312 = local_9;\\n vec2 _e314 = local_10;\\n vec3 _e316 = local_11;\\n vec4 _e318 = local_12;\\n gl_Position = _e312;\\n _vs2fs_location0 = _e314;\\n _vs2fs_location1 = _e316;\\n _vs2fs_location2 = _e318;\\n gl_Position.z = gl_Position.z * null3d_depth_mapping.x + gl_Position.w * null3d_depth_mapping.y;\\n return;\\n }\\n local_11 = (vec3(syy, -(sxy), sxx) / vec3(det));\\n float mid = (0.5 * (sxx + syy));\\n float spread = sqrt(max((((0.25 * (sxx - syy)) * (sxx - syy)) + (sxy * sxy)), 0.0));\\n float major = (mid + spread);\\n float minor = max((mid - spread), 0.0);\\n vec2 from_x = vec2((major - syy), sxy);\\n vec2 from_y = vec2(sxy, (major - sxx));\\n direction = ((dot(from_x, from_x) >= dot(from_y, from_y)) ? from_x : from_y);\\n vec2 _e350 = direction;\\n vec2 _e351 = direction;\\n float length2_ = dot(_e350, _e351);\\n vec2 _e356 = direction;\\n direction = ((length2_ > 1e-20) ? (_e356 * inversesqrt(length2_)) : vec2(1.0, 0.0));\\n vec2 _e362 = direction;\\n vec2 axis_x = (_e362 * sqrt(major));\\n float _e366 = direction.y;\\n float _e369 = direction.x;\\n vec2 axis_y = (vec2(-(_e366), _e369) * sqrt(minor));\\n vec2 corner = ((uv0_ * 2.0) - vec2(1.0));\\n local_10 = (EXTENT * ((corner.x * axis_x) + (corner.y * axis_y)));\\n vec3 right = vec3(view[0].x, view[1].x, view[2].x);\\n vec3 up = vec3(view[0].y, view[1].y, view[2].y);\\n float _e410 = camera_3_[1][1];\\n float meters = ((2.0 * depth) / (_e410 * res.y));\\n float _e415 = local_10.x;\\n float _e418 = local_10.y;\\n vec3 place_1 = (_e48 + (((right * _e415) - (up * _e418)) * meters));\\n vec4 _e424 = local;\\n vec4 _e426 = local_1;\\n vec4 _e428 = local_2;\\n highp uint _e430 = local_3;\\n highp uint _e432 = local_4;\\n highp uint _e434 = local_5;\\n bool _e436 = local_6;\\n highp uint _e438 = local_7;\\n bool _e440 = local_8;\\n vec4 _e441 = clip_of(_e424, _e426, _e428, _e430, _e432, _e434, _e436, _e438, _e440, place_1);\\n local_9 = _e441;\\n vec4 _e443 = local_9;\\n vec2 _e445 = local_10;\\n vec3 _e447 = local_11;\\n vec4 _e449 = local_12;\\n gl_Position = _e443;\\n _vs2fs_location0 = _e445;\\n _vs2fs_location1 = _e447;\\n _vs2fs_location2 = _e449;\\n gl_Position.z = gl_Position.z * null3d_depth_mapping.x + gl_Position.w * null3d_depth_mapping.y;\\n return;\\n}\\n\",\"#version 300 es\\n\",\"\\nconst float CUTOFF = 0.003921569;\\n\",\"\\nlayout(std140) uniform Frame_block_0Fragment { Frame _group_0_binding_0_fs; };\\n\",\"\\nsmooth in vec2 _vs2fs_location0;\",\"\\nflat in vec3 _vs2fs_location1;\",\"\\nflat in vec4 _vs2fs_location2;\",\"\\nlayout(location = 0) out vec4 _fs2p_location0;\\n\",\"\\nvec3 limit_hdr(vec3 c) {\\n bvec3 nan = greaterThan((floatBitsToUint(c) & uvec3(2147483647u)), uvec3(2139095040u));\\n return mix(min(c, vec3(65472.0)), vec3(0.0), nan);\\n}\\n\",\"\\nvec4 finish_null3d_tonemap(vec3 c_1, vec2 pixel, float target_height, float param_4, highp uint param_5, highp uint param_6, highp uint param_7, vec2 size, vec4 shape) {\\n vec3 _e1 = limit_hdr(c_1);\\n return vec4(_e1, 1.0);\\n}\\n\",\"\\nvec3 exposed(vec3 c_2) {\\n float _e97 = _group_0_binding_0_fs.output_.exposure;\\n return (c_2 * _e97);\\n}\\n\",\"\\nvec4 finish_exposed(vec3 c_3, vec2 pixel_1) {\\n float _e98 = _group_0_binding_0_fs.occlusion.y;\\n vec4 _e305 = _group_0_binding_0_fs.target_size;\\n vec4 _e404 = _group_0_binding_0_fs.vignette;\\n float _e409 = _group_0_binding_0_fs.output_.exposure;\\n highp uint _e412 = _group_0_binding_0_fs.output_.tone_mapping;\\n highp uint _e415 = _group_0_binding_0_fs.output_.flags;\\n highp uint _e418 = _group_0_binding_0_fs.output_.render_size;\\n vec4 _e419 = finish_null3d_tonemap(c_3, pixel_1, _e98, _e409, _e412, _e415, _e418, _e305.xy, _e404);\\n return _e419;\\n}\\n\",\"\\nvec4 finish_null3d_mesh(vec3 c_4, vec2 pixel_2) {\\n vec3 _e1 = exposed(c_4);\\n vec4 _e3 = finish_exposed(_e1, pixel_2);\\n return _e3;\\n}\\n\",\"\\nvoid fill_builtins(vec3 origin) {\\n vec4 clock = _group_0_binding_0_fs.clock;\\n vec4 _e195 = _group_0_binding_0_fs.camera_world;\\n vec3 world = _e195.xyz;\\n vec4 _e298 = _group_0_binding_0_fs.camera_target;\\n frame_null3d_builtins_0_ = clock.x;\\n frame_null3d_builtins_1_ = clock.y;\\n frame_null3d_builtins_2_ = floatBitsToUint(clock.z);\\n frame_null3d_builtins_3_ = false;\\n frame_null3d_builtins_4_ = _e298.xy;\\n vec4 range = _group_0_binding_0_fs.camera_range;\\n mat4x4 _e501 = _group_0_binding_0_fs.camera_view_proj;\\n mat4x4 _e599 = _group_0_binding_0_fs.view;\\n mat4x4 _e697 = _group_0_binding_0_fs.projection;\\n camera_0_ = world;\\n camera_1_ = _e501;\\n camera_2_ = _e599;\\n camera_3_ = _e697;\\n camera_4_ = range.x;\\n camera_5_ = range.y;\\n object_0_ = (world + origin);\\n object_1_ = vec4(0.0);\\n object_2_ = mat4x4(0.0);\\n object_3_ = mat3x3(0.0);\\n object_4_ = 0u;\\n return;\\n}\\n\",\"\\nvoid main() {\\n vec4 param = gl_FragCoord;\\n vec2 param_1 = _vs2fs_location0;\\n vec3 param_2 = _vs2fs_location1;\\n vec4 param_3 = _vs2fs_location2;\\n fill_builtins(vec3(0.0));\\n float power = (0.5 * ((((param_2.x * param_1.x) * param_1.x) + (((2.0 * param_2.y) * param_1.x) * param_1.y)) + ((param_2.z * param_1.y) * param_1.y)));\\n float alpha = clamp((param_3.w * exp(-(power))), 0.0, 1.0);\\n if ((alpha < CUTOFF)) {\\n discard;\\n }\\n vec4 _e38 = finish_null3d_mesh(param_3.xyz, param.xy);\\n _fs2p_location0 = vec4((_e38.xyz * alpha), alpha);\\n return;\\n}\\n\"],\"lists\":[[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72],[73,2,3,5,6,7,8,9,10,16,17,18,19,74,75,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,76,77,78,79,80,81,82,83,84,85,86]]}"].map((json) => ({ json })));
|
|
5
|
+
const sourceOf = (n) => {
|
|
6
|
+
const path = paths[n < 0 ? 1 : 0];
|
|
7
|
+
const tables = path.tables || (path.tables = JSON.parse(path.json));
|
|
8
|
+
return tables.lists[n < 0 ? -1 - n : n].map((block) => tables.blocks[block]).join('');
|
|
9
|
+
};
|
|
10
|
+
const walk = (item) => {
|
|
11
|
+
for (const key in item) {
|
|
12
|
+
const field = item[key];
|
|
13
|
+
if (key === "source" && typeof field === 'number')
|
|
14
|
+
Object.defineProperty(item, key, { get: () => sourceOf(field), enumerable: true });
|
|
15
|
+
else if (field !== null && typeof field === 'object') walk(field);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const shader = JSON.parse(text);
|
|
19
|
+
walk(shader);
|
|
20
|
+
if (hot !== undefined) shader.hot = hot;
|
|
21
|
+
if (load !== undefined)
|
|
22
|
+
shader.builds = (target, set) => load(kind, target, set).then((module) => module.default[index] || {});
|
|
23
|
+
return shader;
|
|
24
|
+
}
|