@multiplekex/shallot 0.1.12 → 0.2.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.
Files changed (62) hide show
  1. package/package.json +3 -4
  2. package/src/core/builder.ts +71 -32
  3. package/src/core/component.ts +25 -11
  4. package/src/core/index.ts +14 -13
  5. package/src/core/math.ts +135 -0
  6. package/src/core/runtime.ts +0 -1
  7. package/src/core/state.ts +9 -68
  8. package/src/core/xml.ts +381 -265
  9. package/src/editor/format.ts +5 -0
  10. package/src/editor/index.ts +101 -0
  11. package/src/extras/arrows/index.ts +28 -69
  12. package/src/extras/gradient/index.ts +36 -52
  13. package/src/extras/lines/index.ts +51 -122
  14. package/src/extras/orbit/index.ts +40 -15
  15. package/src/extras/text/font.ts +546 -0
  16. package/src/extras/text/index.ts +158 -204
  17. package/src/extras/text/sdf.ts +429 -0
  18. package/src/standard/activity/index.ts +172 -0
  19. package/src/standard/compute/graph.ts +23 -23
  20. package/src/standard/compute/index.ts +76 -61
  21. package/src/standard/defaults.ts +8 -5
  22. package/src/standard/index.ts +1 -0
  23. package/src/standard/input/index.ts +30 -19
  24. package/src/standard/loading/index.ts +18 -13
  25. package/src/standard/render/bvh/blas.ts +752 -0
  26. package/src/standard/render/bvh/radix.ts +476 -0
  27. package/src/standard/render/bvh/structs.ts +167 -0
  28. package/src/standard/render/bvh/tlas.ts +886 -0
  29. package/src/standard/render/bvh/traverse.ts +467 -0
  30. package/src/standard/render/camera.ts +302 -27
  31. package/src/standard/render/data.ts +93 -0
  32. package/src/standard/render/depth.ts +117 -0
  33. package/src/standard/render/forward/index.ts +259 -0
  34. package/src/standard/render/forward/raster.ts +228 -0
  35. package/src/standard/render/index.ts +443 -70
  36. package/src/standard/render/indirect.ts +40 -0
  37. package/src/standard/render/instance.ts +214 -0
  38. package/src/standard/render/intersection.ts +72 -0
  39. package/src/standard/render/light.ts +16 -16
  40. package/src/standard/render/mesh/index.ts +67 -75
  41. package/src/standard/render/mesh/unified.ts +96 -0
  42. package/src/standard/render/{transparent.ts → overlay.ts} +14 -15
  43. package/src/standard/render/pass.ts +10 -4
  44. package/src/standard/render/postprocess.ts +142 -64
  45. package/src/standard/render/ray.ts +61 -0
  46. package/src/standard/render/scene.ts +38 -164
  47. package/src/standard/render/shaders.ts +484 -0
  48. package/src/standard/render/surface/compile.ts +3 -10
  49. package/src/standard/render/surface/index.ts +60 -30
  50. package/src/standard/render/surface/noise.ts +45 -0
  51. package/src/standard/render/surface/structs.ts +60 -19
  52. package/src/standard/render/surface/wgsl.ts +573 -0
  53. package/src/standard/render/triangle.ts +84 -0
  54. package/src/standard/transforms/index.ts +4 -6
  55. package/src/standard/tween/index.ts +10 -1
  56. package/src/standard/tween/sequence.ts +24 -16
  57. package/src/standard/tween/tween.ts +67 -16
  58. package/src/core/types.ts +0 -37
  59. package/src/standard/compute/inspect.ts +0 -201
  60. package/src/standard/compute/pass.ts +0 -23
  61. package/src/standard/compute/timing.ts +0 -139
  62. package/src/standard/render/forward.ts +0 -273
@@ -1,6 +1,9 @@
1
- export const SCENE_UNIFORM_SIZE = 288; // viewProj (64) + cameraWorld (64) + ambient (16) + sunDir (16) + sunColor (16) + camera params (16) + frustum planes (96)
1
+ export const SCENE_UNIFORM_SIZE = 512;
2
2
  export const DEPTH_FORMAT: GPUTextureFormat = "depth24plus";
3
+ export const LINEAR_DEPTH_FORMAT: GPUTextureFormat = "r32float";
3
4
  export const MASK_FORMAT: GPUTextureFormat = "r8unorm";
5
+ export const EID_FORMAT: GPUTextureFormat = "r32uint";
6
+ export const COLOR_FORMAT: GPUTextureFormat = "rgba8unorm";
4
7
 
5
8
  export function createSceneBuffer(device: GPUDevice): GPUBuffer {
6
9
  return device.createBuffer({
@@ -10,9 +13,7 @@ export function createSceneBuffer(device: GPUDevice): GPUBuffer {
10
13
  });
11
14
  }
12
15
 
13
- export const ENTITY_ID_FORMAT: GPUTextureFormat = "r32uint";
14
-
15
- export function ensureRenderTextures(
16
+ export function ensureTextures(
16
17
  device: GPUDevice,
17
18
  format: GPUTextureFormat,
18
19
  width: number,
@@ -20,21 +21,42 @@ export function ensureRenderTextures(
20
21
  textures: Map<string, GPUTexture>,
21
22
  textureViews: Map<string, GPUTextureView>
22
23
  ): void {
23
- const existing = textures.get("scene");
24
+ const existing = textures.get("color");
24
25
  if (existing && existing.width === width && existing.height === height) return;
25
26
 
26
27
  existing?.destroy();
28
+ textures.get("linear-depth")?.destroy();
29
+ textures.get("eid")?.destroy();
27
30
  textures.get("depth")?.destroy();
28
31
  textures.get("mask")?.destroy();
29
- textures.get("entityId")?.destroy();
30
32
  textures.get("pingA")?.destroy();
31
33
  textures.get("pingB")?.destroy();
32
34
 
33
- const scene = device.createTexture({
34
- label: "scene",
35
+ const color = device.createTexture({
36
+ label: "color",
35
37
  size: { width, height },
36
- format,
37
- usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING,
38
+ format: COLOR_FORMAT,
39
+ usage:
40
+ GPUTextureUsage.STORAGE_BINDING |
41
+ GPUTextureUsage.RENDER_ATTACHMENT |
42
+ GPUTextureUsage.TEXTURE_BINDING,
43
+ });
44
+
45
+ const linearDepth = device.createTexture({
46
+ label: "linear-depth",
47
+ size: { width, height },
48
+ format: LINEAR_DEPTH_FORMAT,
49
+ usage: GPUTextureUsage.STORAGE_BINDING | GPUTextureUsage.TEXTURE_BINDING,
50
+ });
51
+
52
+ const eid = device.createTexture({
53
+ label: "eid",
54
+ size: { width, height },
55
+ format: EID_FORMAT,
56
+ usage:
57
+ GPUTextureUsage.STORAGE_BINDING |
58
+ GPUTextureUsage.RENDER_ATTACHMENT |
59
+ GPUTextureUsage.TEXTURE_BINDING,
38
60
  });
39
61
 
40
62
  const depth = device.createTexture({
@@ -51,13 +73,6 @@ export function ensureRenderTextures(
51
73
  usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING,
52
74
  });
53
75
 
54
- const entityId = device.createTexture({
55
- label: "entityId",
56
- size: { width, height },
57
- format: ENTITY_ID_FORMAT,
58
- usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING,
59
- });
60
-
61
76
  const pingA = device.createTexture({
62
77
  label: "pingA",
63
78
  size: { width, height },
@@ -72,159 +87,18 @@ export function ensureRenderTextures(
72
87
  usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING,
73
88
  });
74
89
 
75
- textures.set("scene", scene);
76
- textureViews.set("scene", scene.createView());
90
+ textures.set("color", color);
91
+ textureViews.set("color", color.createView());
92
+ textures.set("linear-depth", linearDepth);
93
+ textureViews.set("linear-depth", linearDepth.createView());
94
+ textures.set("eid", eid);
95
+ textureViews.set("eid", eid.createView());
77
96
  textures.set("depth", depth);
78
97
  textureViews.set("depth", depth.createView());
79
98
  textures.set("mask", mask);
80
99
  textureViews.set("mask", mask.createView());
81
- textures.set("entityId", entityId);
82
- textureViews.set("entityId", entityId.createView());
83
100
  textures.set("pingA", pingA);
84
101
  textureViews.set("pingA", pingA.createView());
85
102
  textures.set("pingB", pingB);
86
103
  textureViews.set("pingB", pingB.createView());
87
104
  }
88
-
89
- export function perspective(fov: number, aspect: number, near: number, far: number): Float32Array {
90
- if (fov <= 0) throw new Error(`Invalid FOV: ${fov} (must be > 0)`);
91
- if (aspect <= 0) throw new Error(`Invalid aspect ratio: ${aspect} (must be > 0)`);
92
- if (near === far) throw new Error(`Invalid depth planes: near === far (${near})`);
93
- const f = 1 / Math.tan((fov * Math.PI) / 360);
94
- const nf = 1 / (near - far);
95
- return new Float32Array([
96
- f / aspect,
97
- 0,
98
- 0,
99
- 0,
100
- 0,
101
- f,
102
- 0,
103
- 0,
104
- 0,
105
- 0,
106
- (far + near) * nf,
107
- -1,
108
- 0,
109
- 0,
110
- 2 * far * near * nf,
111
- 0,
112
- ]);
113
- }
114
-
115
- export function orthographic(
116
- size: number,
117
- aspect: number,
118
- near: number,
119
- far: number
120
- ): Float32Array {
121
- if (size <= 0) throw new Error(`Invalid orthographic size: ${size} (must be > 0)`);
122
- if (aspect <= 0) throw new Error(`Invalid aspect ratio: ${aspect} (must be > 0)`);
123
- if (near === far) throw new Error(`Invalid depth planes: near === far (${near})`);
124
- const lr = 1 / (size * aspect);
125
- const bt = 1 / size;
126
- const nf = 1 / (near - far);
127
- return new Float32Array([lr, 0, 0, 0, 0, bt, 0, 0, 0, 0, nf, 0, 0, 0, near * nf, 1]);
128
- }
129
-
130
- export function multiply(a: Float32Array, b: Float32Array): Float32Array {
131
- const out = new Float32Array(16);
132
- for (let i = 0; i < 4; i++) {
133
- for (let j = 0; j < 4; j++) {
134
- out[j * 4 + i] =
135
- a[i] * b[j * 4] +
136
- a[i + 4] * b[j * 4 + 1] +
137
- a[i + 8] * b[j * 4 + 2] +
138
- a[i + 12] * b[j * 4 + 3];
139
- }
140
- }
141
- return out;
142
- }
143
-
144
- export function invert(m: Float32Array): Float32Array {
145
- const out = new Float32Array(16);
146
- const r00 = m[0],
147
- r01 = m[1],
148
- r02 = m[2];
149
- const r10 = m[4],
150
- r11 = m[5],
151
- r12 = m[6];
152
- const r20 = m[8],
153
- r21 = m[9],
154
- r22 = m[10];
155
- const tx = m[12],
156
- ty = m[13],
157
- tz = m[14];
158
-
159
- out[0] = r00;
160
- out[1] = r10;
161
- out[2] = r20;
162
- out[3] = 0;
163
- out[4] = r01;
164
- out[5] = r11;
165
- out[6] = r21;
166
- out[7] = 0;
167
- out[8] = r02;
168
- out[9] = r12;
169
- out[10] = r22;
170
- out[11] = 0;
171
- out[12] = -(r00 * tx + r01 * ty + r02 * tz);
172
- out[13] = -(r10 * tx + r11 * ty + r12 * tz);
173
- out[14] = -(r20 * tx + r21 * ty + r22 * tz);
174
- out[15] = 1;
175
-
176
- return out;
177
- }
178
-
179
- export function extractFrustumPlanes(viewProj: Float32Array): Float32Array {
180
- const planes = new Float32Array(24);
181
- const m = viewProj;
182
-
183
- // Left: row4 + row1
184
- planes[0] = m[3] + m[0];
185
- planes[1] = m[7] + m[4];
186
- planes[2] = m[11] + m[8];
187
- planes[3] = m[15] + m[12];
188
-
189
- // Right: row4 - row1
190
- planes[4] = m[3] - m[0];
191
- planes[5] = m[7] - m[4];
192
- planes[6] = m[11] - m[8];
193
- planes[7] = m[15] - m[12];
194
-
195
- // Bottom: row4 + row2
196
- planes[8] = m[3] + m[1];
197
- planes[9] = m[7] + m[5];
198
- planes[10] = m[11] + m[9];
199
- planes[11] = m[15] + m[13];
200
-
201
- // Top: row4 - row2
202
- planes[12] = m[3] - m[1];
203
- planes[13] = m[7] - m[5];
204
- planes[14] = m[11] - m[9];
205
- planes[15] = m[15] - m[13];
206
-
207
- // Near: row3 (WebGPU uses 0-1 depth, so near plane is z_clip >= 0)
208
- planes[16] = m[2];
209
- planes[17] = m[6];
210
- planes[18] = m[10];
211
- planes[19] = m[14];
212
-
213
- // Far: row4 - row3
214
- planes[20] = m[3] - m[2];
215
- planes[21] = m[7] - m[6];
216
- planes[22] = m[11] - m[10];
217
- planes[23] = m[15] - m[14];
218
-
219
- // Normalize each plane
220
- for (let i = 0; i < 6; i++) {
221
- const len = Math.hypot(planes[i * 4], planes[i * 4 + 1], planes[i * 4 + 2]);
222
- if (len > 0) {
223
- planes[i * 4] /= len;
224
- planes[i * 4 + 1] /= len;
225
- planes[i * 4 + 2] /= len;
226
- planes[i * 4 + 3] /= len;
227
- }
228
- }
229
- return planes;
230
- }