phoria2 1.3.0 → 1.4.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 (56) hide show
  1. package/README.md +9 -6
  2. package/dist/bloom.js +4 -4
  3. package/dist/bloom.js.map +1 -1
  4. package/dist/charts.js +436 -436
  5. package/dist/charts.js.map +1 -1
  6. package/dist/core.js +1223 -862
  7. package/dist/core.js.map +1 -1
  8. package/dist/debug.js +297 -0
  9. package/dist/debug.js.map +1 -0
  10. package/dist/edit.js +40 -40
  11. package/dist/edit.js.map +1 -1
  12. package/dist/explain.js +32 -13
  13. package/dist/explain.js.map +1 -1
  14. package/dist/gltf.js +128 -128
  15. package/dist/gltf.js.map +1 -1
  16. package/dist/keyboard.js +19 -19
  17. package/dist/keyboard.js.map +1 -1
  18. package/dist/motion.js +35 -35
  19. package/dist/motion.js.map +1 -1
  20. package/dist/particles.js +36 -36
  21. package/dist/particles.js.map +1 -1
  22. package/dist/passes.js +116 -104
  23. package/dist/passes.js.map +1 -1
  24. package/dist/phoria2.js +1 -1
  25. package/dist/picking.js +88 -71
  26. package/dist/picking.js.map +1 -1
  27. package/dist/snapshot.js +1 -1
  28. package/dist/tooltip.js +1 -1
  29. package/dist/types/View.d.ts +16 -0
  30. package/dist/types/debug.d.ts +74 -0
  31. package/dist/types/explain.d.ts +4 -0
  32. package/dist/types/frame.d.ts +5 -0
  33. package/dist/types/material/Material.d.ts +52 -0
  34. package/dist/types/watch.d.ts +8 -1
  35. package/dist/types/webgl/hooks.d.ts +48 -0
  36. package/dist/types/webgl/passes.d.ts +4 -0
  37. package/dist/types/webgl/programs.d.ts +15 -5
  38. package/dist/types/webgl/shaders.d.ts +36 -5
  39. package/llms-full.txt +227 -0
  40. package/llms.txt +1 -1
  41. package/package.json +1 -1
  42. package/schema/scene.schema.json +27 -0
  43. package/src/View.js +105 -7
  44. package/src/debug.js +283 -0
  45. package/src/explain.js +19 -0
  46. package/src/frame.js +7 -2
  47. package/src/material/Material.js +121 -2
  48. package/src/scene/drawables.js +21 -4
  49. package/src/watch.js +18 -2
  50. package/src/webgl/WebGLRenderer.js +19 -2
  51. package/src/webgl/hooks.js +121 -0
  52. package/src/webgl/passes.js +17 -2
  53. package/src/webgl/picking.js +23 -2
  54. package/src/webgl/programs.js +20 -9
  55. package/src/webgl/resources.js +1 -1
  56. package/src/webgl/shaders.js +443 -35
package/dist/passes.js CHANGED
@@ -1,6 +1,6 @@
1
- import { A as e, C as t, E as n, It as r, Lt as i, O as a, Pt as o, S as s, T as c, bt as l, w as u, x as d, xt as f, yt as p } from "./core.js";
1
+ import { Bt as e, C as t, Ct as n, D as r, E as i, N as a, O as o, Rt as s, S as c, T as l, Tt as u, Vt as d, j as f, k as p, w as m, wt as h, x as g } from "./core.js";
2
2
  // src/irradiance.js
3
- function m({ data: e, width: t, height: n }) {
3
+ function _({ data: e, width: t, height: n }) {
4
4
  let r = /* @__PURE__ */ new Float64Array(27), i = Math.max(1, Math.floor(t / 128)), a = Math.max(1, Math.floor(n / 64)), o = 2 * Math.PI * i / t, s = Math.PI * a / n;
5
5
  for (let c = 0; c < n; c += a) {
6
6
  let l = (c + .5 * a) / n * Math.PI, u = Math.sin(l), d = Math.cos(l), f = o * s * u;
@@ -47,7 +47,7 @@ function m({ data: e, width: t, height: n }) {
47
47
  return u;
48
48
  }
49
49
  // src/webgl/passes.js
50
- var h = `precision highp float;
50
+ var v = `precision highp float;
51
51
  in vec2 vUv;
52
52
  uniform mat4 uInverseViewProjection;
53
53
  uniform vec3 uCameraPosition;
@@ -56,9 +56,9 @@ uniform float uLod;
56
56
  uniform float uIntensity;
57
57
  uniform int uHdr;
58
58
  out vec4 fragColor;
59
- ${u}
60
- ${c}
61
- ${e}
59
+ ${r}
60
+ ${o}
61
+ ${a}
62
62
  void main() {
63
63
  vec4 far = uInverseViewProjection * vec4(vUv * 2.0 - 1.0, 1.0, 1.0);
64
64
  vec3 d = normalize(far.xyz / far.w - uCameraPosition);
@@ -66,14 +66,14 @@ vec3 c = textureLod(uBackground, equirectUv(d), uLod).rgb * uIntensity;
66
66
  if (uHdr == 1) c = toneMap(c);
67
67
  fragColor = vec4(linearToSrgb(c), 1.0);
68
68
  }
69
- `, g = `precision highp float;
69
+ `, y = `precision highp float;
70
70
  in vec2 vUv;
71
71
  uniform sampler2D uSource;
72
72
  uniform float uRoughness;
73
73
  uniform float uSourceTexels;
74
74
  uniform float uCopyLod;
75
75
  out vec4 fragColor;
76
- ${c}
76
+ ${o}
77
77
  const float PI = 3.14159265359;
78
78
  const uint SAMPLES = 192u;
79
79
  vec2 hammersley(uint i) {
@@ -114,74 +114,74 @@ weight += NoL;
114
114
  }
115
115
  fragColor = vec4(sum / max(weight, 1e-4), 1.0);
116
116
  }
117
- `, _ = `precision highp float;
117
+ `, b = `precision highp float;
118
118
  in vec3 vWorldPosition;
119
119
  uniform vec4 uMask;
120
120
  out vec4 fragColor;
121
- ${s}
121
+ ${l}
122
122
  void main() {
123
123
  clipAway(vWorldPosition);
124
124
  fragColor = uMask;
125
125
  }
126
- `, v = 16, y = `uniform sampler2D uSource;
126
+ `, x = 16, S = `uniform sampler2D uSource;
127
127
  uniform vec2 uStep;
128
128
  uniform int uRadius;
129
129
  vec4 widened(vec2 uv) {
130
130
  vec4 best = vec4(0.0);
131
131
  float nearest = 1e9;
132
- for (int i = -${v}; i <= ${v}; i++) {
132
+ for (int i = -${x}; i <= ${x}; i++) {
133
133
  float d = abs(float(i));
134
134
  if (d > float(uRadius)) continue;
135
135
  vec4 s = texture(uSource, uv + uStep * float(i));
136
- if (s.a > 0.0 && d <= s.a * ${v}.0 && d < nearest) {
136
+ if (s.a > 0.0 && d <= s.a * ${x}.0 && d < nearest) {
137
137
  best = s;
138
138
  nearest = d;
139
139
  }
140
140
  }
141
141
  return best;
142
142
  }
143
- `, b = `precision highp float;
143
+ `, C = `precision highp float;
144
144
  in vec2 vUv;
145
145
  out vec4 fragColor;
146
- ${y}
146
+ ${S}
147
147
  void main() {
148
148
  fragColor = widened(vUv);
149
149
  }
150
- `, x = `precision highp float;
150
+ `, w = `precision highp float;
151
151
  in vec2 vUv;
152
152
  uniform sampler2D uMask;
153
153
  out vec4 fragColor;
154
- ${u}
155
- ${y}
154
+ ${r}
155
+ ${S}
156
156
  void main() {
157
157
  if (texture(uMask, vUv).a > 0.0) discard;
158
158
  vec4 ring = widened(vUv);
159
159
  if (ring.a <= 0.0) discard;
160
160
  fragColor = vec4(linearToSrgb(ring.rgb), 1.0);
161
161
  }
162
- `, S = `precision highp float;
162
+ `, T = `precision highp float;
163
163
  in vec3 vWorldPosition;
164
164
  uniform vec4 uMask;
165
165
  layout(location = 0) out vec4 fragColor;
166
166
  layout(location = 1) out vec4 fragCoverage;
167
- ${s}
167
+ ${l}
168
168
  void main() {
169
169
  clipAway(vWorldPosition);
170
170
  fragColor = uMask;
171
171
  fragCoverage = vec4(1.0);
172
172
  }
173
- `, C = `uniform sampler2D uMask;
173
+ `, E = `uniform sampler2D uMask;
174
174
  uniform sampler2D uCoverage;
175
175
  uniform vec2 uTexel;
176
176
  uniform int uRadius;
177
177
  vec4 masked(vec2 uv, float coverage) {
178
178
  vec4 m = texture(uMask, uv) / coverage;
179
- return vec4(m.rgb, m.a * ${v}.0);
179
+ return vec4(m.rgb, m.a * ${x}.0);
180
180
  }
181
- `, w = `precision highp float;
181
+ `, D = `precision highp float;
182
182
  in vec2 vUv;
183
183
  out vec4 fragColor;
184
- ${C}
184
+ ${E}
185
185
  void main() {
186
186
  float nearest = 1e9;
187
187
  int at = 0;
@@ -200,12 +200,12 @@ found = true;
200
200
  }
201
201
  fragColor = found ? vec4(float(at + 32) / 255.0, 0.0, 0.0, 1.0) : vec4(0.0);
202
202
  }
203
- `, T = `precision highp float;
203
+ `, O = `precision highp float;
204
204
  in vec2 vUv;
205
205
  uniform sampler2D uNearest;
206
206
  out vec4 fragColor;
207
- ${u}
208
- ${C}
207
+ ${r}
208
+ ${E}
209
209
  void main() {
210
210
  float here = texture(uCoverage, vUv).r;
211
211
  if (here >= 1.0) discard;
@@ -229,7 +229,13 @@ float alpha = clamp(ring.a - nearest + 0.5, 0.0, 1.0) * (1.0 - here);
229
229
  if (alpha <= 0.0) discard;
230
230
  fragColor = vec4(linearToSrgb(ring.rgb) * alpha, alpha);
231
231
  }
232
- `, E = [a, _], D = [n, b], O = [n, x], k = [a, S], A = [n, w], j = [n, T], M = [a, t], N = [n, h], P = [n, g], F = 512, I = 6, L = class {
232
+ `, k = [f, b], A = [p, C], j = [p, w], M = [f, T], N = [p, D], P = [p, O], F = [f, i], I = [p, v], L = [p, y], R = 512, z = 6, B = class {
233
+ time = 0;
234
+ cameraPosition = [
235
+ 0,
236
+ 0,
237
+ 0
238
+ ];
233
239
  #e = /* @__PURE__ */ new WeakMap();
234
240
  #t = null;
235
241
  #n = null;
@@ -253,33 +259,33 @@ fragColor = vec4(linearToSrgb(ring.rgb) * alpha, alpha);
253
259
  });
254
260
  let r = e.image, i = this.#d(r.width, r.height, Math.floor(Math.log2(Math.max(r.width, r.height))) + 1);
255
261
  n.texSubImage2D(n.TEXTURE_2D, 0, 0, 0, r.width, r.height, n.RGBA, n.FLOAT, r.data), n.generateMipmap(n.TEXTURE_2D);
256
- let a = this.#d(F, F / 2, I), o = this.programs.ready("prefilter", [], P);
262
+ let a = this.#d(R, R / 2, z), o = this.programs.ready("prefilter", [], L);
257
263
  n.useProgram(o.program), o.set("uSource", i), o.set("uSourceTexels", r.width * r.height);
258
264
  let s = n.createFramebuffer();
259
265
  n.bindFramebuffer(n.FRAMEBUFFER, s), n.disable(n.DEPTH_TEST), n.disable(n.BLEND), n.disable(n.CULL_FACE);
260
- for (let e = 0; e < I; e++) {
261
- let t = F >> e;
266
+ for (let e = 0; e < z; e++) {
267
+ let t = R >> e;
262
268
  n.framebufferTexture2D(n.FRAMEBUFFER, n.COLOR_ATTACHMENT0, n.TEXTURE_2D, a, e), n.viewport(0, 0, t, t / 2), o.set("uRoughness", e / 5), o.set("uCopyLod", Math.max(0, Math.log2(r.width / t))), this.programs.drawFullscreen();
263
269
  }
264
270
  return n.bindFramebuffer(n.FRAMEBUFFER, null), n.deleteFramebuffer(s), n.enable(n.DEPTH_TEST), t = {
265
271
  source: i,
266
272
  prefiltered: a,
267
273
  maxLod: 5,
268
- sh: m(r),
274
+ sh: _(r),
269
275
  version: e.version
270
276
  }, this.#e.set(e, t), t;
271
277
  }
272
- background(e, t, n) {
273
- let i = this.gl, a = t.isHDR, s = a ? this.environment(t) : null;
274
- if (a && !s) return;
275
- let c = this.programs.ready("background", [], N);
278
+ background(t, n, r) {
279
+ let i = this.gl, a = n.isHDR, o = a ? this.environment(n) : null;
280
+ if (a && !o) return;
281
+ let c = this.programs.ready("background", [], I);
276
282
  i.useProgram(c.program);
277
- let l = Math.min(Math.max(e.backgroundBlur, 0), 1);
278
- s ? (c.set("uBackground", l > 0 ? s.prefiltered : s.source), c.set("uLod", l * s.maxLod), c.set("uIntensity", e.environment === t ? e.environmentIntensity : 1)) : (c.set("uBackground", this.resources.texture(t)), c.set("uLod", l * 6), c.set("uIntensity", 1)), c.set("uHdr", +!!a), c.set("uExposure", n.exposure), c.set("uToneMapping", n.toneMapping), c.set("uInverseViewProjection", r(o(), e.camera.viewProjection)), c.set("uCameraPosition", e.camera.position), i.disable(i.DEPTH_TEST), i.disable(i.BLEND), i.disable(i.CULL_FACE), i.depthMask(!1), this.programs.drawFullscreen(), i.depthMask(!0), i.enable(i.DEPTH_TEST);
283
+ let l = Math.min(Math.max(t.backgroundBlur, 0), 1);
284
+ o ? (c.set("uBackground", l > 0 ? o.prefiltered : o.source), c.set("uLod", l * o.maxLod), c.set("uIntensity", t.environment === n ? t.environmentIntensity : 1)) : (c.set("uBackground", this.resources.texture(n)), c.set("uLod", l * 6), c.set("uIntensity", 1)), c.set("uHdr", +!!a), c.set("uExposure", r.exposure), c.set("uToneMapping", r.toneMapping), c.set("uInverseViewProjection", e(s(), t.camera.viewProjection)), c.set("uCameraPosition", t.camera.position), i.disable(i.DEPTH_TEST), i.disable(i.BLEND), i.disable(i.CULL_FACE), i.depthMask(!1), this.programs.drawFullscreen(), i.depthMask(!0), i.enable(i.DEPTH_TEST);
279
285
  }
280
286
  shadowMap(e) {
281
287
  let t = this.gl;
282
- this.#t ??= this.#l(l), t.bindFramebuffer(t.FRAMEBUFFER, this.#t.framebuffer), t.viewport(0, 0, l, l), this.#a(), this.#s(e.casters, e.viewProjection), this.#o();
288
+ this.#t ??= this.#l(h), t.bindFramebuffer(t.FRAMEBUFFER, this.#t.framebuffer), t.viewport(0, 0, h, h), this.#a(), this.#s(e.casters, e.viewProjection), this.#o();
283
289
  let n = new Float32Array([
284
290
  .5,
285
291
  0,
@@ -303,20 +309,20 @@ fragColor = vec4(linearToSrgb(ring.rgb) * alpha, alpha);
303
309
  sampler: "uShadowMap",
304
310
  texture: this.#t.texture,
305
311
  uniforms: {
306
- uShadowMatrix: i(/* @__PURE__ */ new Float32Array(16), n, e.viewProjection),
307
- uShadowTexel: 1 / l,
312
+ uShadowMatrix: d(/* @__PURE__ */ new Float32Array(16), n, e.viewProjection),
313
+ uShadowTexel: 1 / h,
308
314
  uShadowBias: e.texelSize * 1.5
309
315
  }
310
316
  };
311
317
  }
312
318
  spotShadowMaps(e) {
313
319
  let t = this.gl;
314
- this.#n ??= this.#l(f), t.bindFramebuffer(t.FRAMEBUFFER, this.#n.framebuffer), t.viewport(0, 0, f, f), this.#a();
315
- let n = /* @__PURE__ */ new Float32Array(64), r = /* @__PURE__ */ new Float32Array(16), a = /* @__PURE__ */ new Float32Array(4), o = f / 2;
316
- for (let s of e) {
317
- let e = s.tile % 2, c = Math.floor(s.tile / 2);
318
- t.viewport(e * o, c * o, o, o), this.#s(s.casters, s.viewProjection);
319
- let l = new Float32Array([
320
+ this.#n ??= this.#l(u), t.bindFramebuffer(t.FRAMEBUFFER, this.#n.framebuffer), t.viewport(0, 0, u, u), this.#a();
321
+ let n = /* @__PURE__ */ new Float32Array(64), r = /* @__PURE__ */ new Float32Array(16), i = /* @__PURE__ */ new Float32Array(4), a = u / 2;
322
+ for (let o of e) {
323
+ let e = o.tile % 2, s = Math.floor(o.tile / 2);
324
+ t.viewport(e * a, s * a, a, a), this.#s(o.casters, o.viewProjection);
325
+ let c = new Float32Array([
320
326
  .25,
321
327
  0,
322
328
  0,
@@ -330,16 +336,16 @@ fragColor = vec4(linearToSrgb(ring.rgb) * alpha, alpha);
330
336
  .5,
331
337
  0,
332
338
  e * .5 + .25,
333
- c * .5 + .25,
339
+ s * .5 + .25,
334
340
  .5,
335
341
  1
336
342
  ]);
337
- n.set(i(/* @__PURE__ */ new Float32Array(16), l, s.viewProjection), s.tile * 16), r.set([
343
+ n.set(d(/* @__PURE__ */ new Float32Array(16), c, o.viewProjection), o.tile * 16), r.set([
338
344
  e * .5,
339
- c * .5,
345
+ s * .5,
340
346
  e * .5 + .5,
341
- c * .5 + .5
342
- ], s.tile * 4), a[s.tile] = s.texelAngle * 1.5;
347
+ s * .5 + .5
348
+ ], o.tile * 4), i[o.tile] = o.texelAngle * 1.5;
343
349
  }
344
350
  return this.#o(), {
345
351
  define: "SPOT_SHADOWS",
@@ -348,15 +354,15 @@ fragColor = vec4(linearToSrgb(ring.rgb) * alpha, alpha);
348
354
  uniforms: {
349
355
  uSpotShadowMatrix: n,
350
356
  uSpotShadowTile: r,
351
- uSpotShadowBias: a,
352
- uSpotShadowTexel: 1 / f
357
+ uSpotShadowBias: i,
358
+ uSpotShadowTexel: 1 / u
353
359
  }
354
360
  };
355
361
  }
356
362
  pointShadowMap(e) {
357
363
  let t = this.gl;
358
- return this.#r ??= this.#u(p), e.faces.forEach((e, n) => {
359
- t.bindFramebuffer(t.FRAMEBUFFER, this.#r.framebuffers[n]), t.viewport(0, 0, p, p), this.#a(), this.#s(e.casters, e.viewProjection);
364
+ return this.#r ??= this.#u(n), e.faces.forEach((e, r) => {
365
+ t.bindFramebuffer(t.FRAMEBUFFER, this.#r.framebuffers[r]), t.viewport(0, 0, n, n), this.#a(), this.#s(e.casters, e.viewProjection);
360
366
  }), this.#o(), {
361
367
  define: "POINT_SHADOW",
362
368
  sampler: "uPointShadowMap",
@@ -376,68 +382,74 @@ fragColor = vec4(linearToSrgb(ring.rgb) * alpha, alpha);
376
382
  let e = this.gl;
377
383
  e.disable(e.POLYGON_OFFSET_FILL), e.bindFramebuffer(e.FRAMEBUFFER, null);
378
384
  }
379
- #s(e, t) {
380
- let n = this.gl;
381
- for (let r of e) {
382
- let e = r.instances, i = e ? ["INSTANCED"] : [];
383
- r.clip && i.push("CLIP");
384
- let a = r.material, o = a.alphaTest > 0, s = o && !!a.map && a.triplanar > 0;
385
- o && i.push("ALPHA_TEST", ...a.map ? ["MAP"] : [], ...s ? ["TRIPLANAR"] : []), o && a.map?.uvSet === 1 && r.geometry.uvs2 && i.push("UV2", "uMapSet vUv2");
386
- let c = this.programs.ready("depth", i, M);
387
- if (n.useProgram(c.program), c.set("uViewProjection", t), c.set("uModel", r.worldMatrix), r.clip && c.set("uClipPlane", r.clip.plane), o) {
388
- c.set("uOpacity", a.opacity), c.set("uAlphaTest", a.alphaTest);
389
- let e = a.map;
390
- e && (c.set("uMapUv", d(e)), c.set("uMap", this.resources.texture(e))), s && c.set("uTriplanar", a.triplanar);
385
+ #s(e, n) {
386
+ let r = this.gl;
387
+ for (let i of e) {
388
+ let e = i.instances, a = e ? ["INSTANCED"] : [];
389
+ i.clip && a.push("CLIP");
390
+ let o = i.material, s = o.alphaTest > 0, l = s && !!o.map && o.triplanar > 0;
391
+ s && a.push("ALPHA_TEST", ...o.map ? ["MAP"] : [], ...l ? ["TRIPLANAR"] : []), s && o.map?.uvSet === 1 && i.geometry.uvs2 && a.push("UV2", "uMapSet vUv2");
392
+ let u = c(o);
393
+ u && a.push(...t(u, !0));
394
+ let d = this.programs.ready("depth", a, F, u?.source);
395
+ if (!d.failed) {
396
+ if (r.useProgram(d.program), u && m(d, o, this.time, this.cameraPosition, (e) => this.resources.texture(e)), d.set("uViewProjection", n), d.set("uModel", i.worldMatrix), i.clip && d.set("uClipPlane", i.clip.plane), s) {
397
+ d.set("uOpacity", o.opacity), d.set("uAlphaTest", o.alphaTest);
398
+ let e = o.map;
399
+ e && (d.set("uMapUv", g(e)), d.set("uMap", this.resources.texture(e))), l && d.set("uTriplanar", o.triplanar);
400
+ }
401
+ this.resources.drawTriangles(i.geometry, e);
391
402
  }
392
- this.resources.drawTriangles(r.geometry, e);
393
403
  }
394
404
  }
395
- outlineMask(e, t, n, r, i, a) {
396
- let o = this.gl, s = this.#c(n, r, a);
397
- o.bindFramebuffer(o.FRAMEBUFFER, s.msaa ? s.msaa.framebuffer : s.mask.framebuffer), s.msaa && o.drawBuffers([o.COLOR_ATTACHMENT0, o.COLOR_ATTACHMENT1]), o.viewport(0, 0, n, r), o.clearColor(0, 0, 0, 0), o.clear(o.COLOR_BUFFER_BIT), o.disable(o.DEPTH_TEST), o.disable(o.BLEND), o.disable(o.CULL_FACE), o.depthMask(!1);
398
- let c = 1;
399
- for (let n of e) {
400
- let e = Math.min(v, Math.max(1, Math.round(n.width * i)));
401
- c = Math.max(c, e);
402
- for (let r of n.items) {
403
- let i = r.instances ? ["INSTANCED"] : [];
404
- r.clip && i.push("CLIP");
405
- let s = a ? this.programs.ready("outline-cover", i, k) : this.programs.ready("outline-mask", i, E);
406
- o.useProgram(s.program), s.set("uViewProjection", t.camera.viewProjection), s.set("uModel", r.worldMatrix), s.set("uMask", [
407
- n.color[0],
408
- n.color[1],
409
- n.color[2],
410
- e / v
411
- ]), r.clip && s.set("uClipPlane", r.clip.plane), this.resources.drawTriangles(r.geometry, r.instances);
405
+ outlineMask(e, n, r, i, a, o) {
406
+ let s = this.gl, l = this.#c(r, i, o);
407
+ s.bindFramebuffer(s.FRAMEBUFFER, l.msaa ? l.msaa.framebuffer : l.mask.framebuffer), l.msaa && s.drawBuffers([s.COLOR_ATTACHMENT0, s.COLOR_ATTACHMENT1]), s.viewport(0, 0, r, i), s.clearColor(0, 0, 0, 0), s.clear(s.COLOR_BUFFER_BIT), s.disable(s.DEPTH_TEST), s.disable(s.BLEND), s.disable(s.CULL_FACE), s.depthMask(!1);
408
+ let u = 1;
409
+ for (let r of e) {
410
+ let e = Math.min(x, Math.max(1, Math.round(r.width * a)));
411
+ u = Math.max(u, e);
412
+ for (let i of r.items) {
413
+ let a = i.instances ? ["INSTANCED"] : [];
414
+ i.clip && a.push("CLIP");
415
+ let l = c(i.material);
416
+ l && a.push(...t(l, !1));
417
+ let u = o ? this.programs.ready("outline-cover", a, M, l?.source) : this.programs.ready("outline-mask", a, k, l?.source);
418
+ u.failed || (s.useProgram(u.program), l && m(u, i.material, n.time ?? 0, n.camera.position, (e) => this.resources.texture(e)), u.set("uViewProjection", n.camera.viewProjection), u.set("uModel", i.worldMatrix), u.set("uMask", [
419
+ r.color[0],
420
+ r.color[1],
421
+ r.color[2],
422
+ e / x
423
+ ]), i.clip && u.set("uClipPlane", i.clip.plane), this.resources.drawTriangles(i.geometry, i.instances));
412
424
  }
413
425
  }
414
- if (s.msaa && s.coverage) {
415
- o.bindFramebuffer(o.READ_FRAMEBUFFER, s.msaa.framebuffer);
416
- for (let [e, t] of [[o.COLOR_ATTACHMENT0, s.mask], [o.COLOR_ATTACHMENT1, s.coverage]]) o.readBuffer(e), o.bindFramebuffer(o.DRAW_FRAMEBUFFER, t.framebuffer), o.blitFramebuffer(0, 0, n, r, 0, 0, n, r, o.COLOR_BUFFER_BIT, o.NEAREST);
426
+ if (l.msaa && l.coverage) {
427
+ s.bindFramebuffer(s.READ_FRAMEBUFFER, l.msaa.framebuffer);
428
+ for (let [e, t] of [[s.COLOR_ATTACHMENT0, l.mask], [s.COLOR_ATTACHMENT1, l.coverage]]) s.readBuffer(e), s.bindFramebuffer(s.DRAW_FRAMEBUFFER, t.framebuffer), s.blitFramebuffer(0, 0, r, i, 0, 0, r, i, s.COLOR_BUFFER_BIT, s.NEAREST);
417
429
  }
418
- if (o.bindFramebuffer(o.FRAMEBUFFER, s.wide.framebuffer), o.clear(o.COLOR_BUFFER_BIT), s.coverage) {
419
- let e = this.programs.ready("outline-smooth-widen", [], A);
420
- o.useProgram(e.program), e.set("uMask", s.mask.texture), e.set("uCoverage", s.coverage.texture), e.set("uTexel", [1 / n, 1 / r]), e.set("uRadius", c);
430
+ if (s.bindFramebuffer(s.FRAMEBUFFER, l.wide.framebuffer), s.clear(s.COLOR_BUFFER_BIT), l.coverage) {
431
+ let e = this.programs.ready("outline-smooth-widen", [], N);
432
+ s.useProgram(e.program), e.set("uMask", l.mask.texture), e.set("uCoverage", l.coverage.texture), e.set("uTexel", [1 / r, 1 / i]), e.set("uRadius", u);
421
433
  } else {
422
- let e = this.programs.ready("outline-widen", [], D);
423
- o.useProgram(e.program), e.set("uSource", s.mask.texture), e.set("uStep", [1 / n, 0]), e.set("uRadius", c);
434
+ let e = this.programs.ready("outline-widen", [], A);
435
+ s.useProgram(e.program), e.set("uSource", l.mask.texture), e.set("uStep", [1 / r, 0]), e.set("uRadius", u);
424
436
  }
425
- return this.programs.drawFullscreen(), o.depthMask(!0), o.enable(o.DEPTH_TEST), o.bindFramebuffer(o.FRAMEBUFFER, null), {
426
- mask: s.mask.texture,
427
- wide: s.wide.texture,
428
- coverage: s.coverage?.texture ?? null,
429
- radius: c,
430
- width: n,
431
- height: r
437
+ return this.programs.drawFullscreen(), s.depthMask(!0), s.enable(s.DEPTH_TEST), s.bindFramebuffer(s.FRAMEBUFFER, null), {
438
+ mask: l.mask.texture,
439
+ wide: l.wide.texture,
440
+ coverage: l.coverage?.texture ?? null,
441
+ radius: u,
442
+ width: r,
443
+ height: i
432
444
  };
433
445
  }
434
446
  outlineComposite(e) {
435
447
  let t = this.gl;
436
448
  if (e.coverage) {
437
- let n = this.programs.ready("outline-smooth-composite", [], j);
449
+ let n = this.programs.ready("outline-smooth-composite", [], P);
438
450
  t.useProgram(n.program), n.set("uNearest", e.wide), n.set("uMask", e.mask), n.set("uCoverage", e.coverage), n.set("uTexel", [1 / e.width, 1 / e.height]), n.set("uRadius", e.radius);
439
451
  } else {
440
- let n = this.programs.ready("outline-composite", [], O);
452
+ let n = this.programs.ready("outline-composite", [], j);
441
453
  t.useProgram(n.program), n.set("uSource", e.wide), n.set("uMask", e.mask), n.set("uStep", [0, 1 / e.height]), n.set("uRadius", e.radius);
442
454
  }
443
455
  t.disable(t.DEPTH_TEST), t.disable(t.CULL_FACE), t.depthMask(!1), t.enable(t.BLEND), t.blendFunc(t.ONE, t.ONE_MINUS_SRC_ALPHA), this.programs.drawFullscreen(), t.depthMask(!0), t.enable(t.DEPTH_TEST);
@@ -519,6 +531,6 @@ fragColor = vec4(linearToSrgb(ring.rgb) * alpha, alpha);
519
531
  return r.activeTexture(r.TEXTURE15), r.bindTexture(r.TEXTURE_2D, i), r.texStorage2D(r.TEXTURE_2D, n, r.RGBA16F, e, t), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_WRAP_S, r.REPEAT), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_WRAP_T, r.CLAMP_TO_EDGE), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_MIN_FILTER, r.LINEAR_MIPMAP_LINEAR), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_MAG_FILTER, r.LINEAR), r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL, !1), i;
520
532
  }
521
533
  };
522
- export { L as Passes };
534
+ export { B as Passes };
523
535
 
524
536
  //# sourceMappingURL=passes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"passes.js","names":["mat4.invert","mat4.create","mat4.multiply","TONE_MAP","CLIP_ONLY_FRAGMENT","FULLSCREEN_VERTEX","invert","multiply","MESH_VERTEX","create","CLIP","EQUIRECT","SHADOW_MAP_SIZE","COMMON","uvMatrix","SPOT_ATLAS_SIZE","POINT_SHADOW_SIZE","irradianceSH","sh","sx","width","sy","height","dPhi","dTheta","y","theta","sinT","dy","weight","x","phi","dx","dz","basis","i","k","w","data","norm","band","out","c","BACKGROUND_FRAGMENT","PREFILTER_FRAGMENT","OUTLINE_MASK_FRAGMENT","OUTLINE_MAX","WIDEN","OUTLINE_WIDEN_FRAGMENT","OUTLINE_COMPOSITE_FRAGMENT","OUTLINE_COVER_FRAGMENT","SMOOTH","OUTLINE_SMOOTH_WIDEN_FRAGMENT","OUTLINE_SMOOTH_COMPOSITE_FRAGMENT","OUTLINE_MASK","OUTLINE_WIDEN","OUTLINE_COMPOSITE","OUTLINE_COVER","OUTLINE_SMOOTH_WIDEN","OUTLINE_SMOOTH_COMPOSITE","DEPTH","BACKGROUND","PREFILTER","ENV_WIDTH","ENV_LEVELS","Passes","gl","programs","resources","#environments","#shadow","#spotShadow","#pointShadow","#outline","texture","env","e","image","source","#floatTexture","prefiltered","program","framebuffer","level","hdr","blur","frame","tone","#depthTarget","#beginDepth","#drawDepth","shadow","#endDepth","toTexture","matrices","tiles","bias","half","spot","spots","toTile","#depthCube","point","face","item","casters","instances","defines","material","cutout","triplanar","viewProjection","map","targets","#outlineTargets","smooth","radius","outline","outlines","px","pixelRatio","attachment","target","widen","t","buffer","make","format","msaa","samples","size","framebuffers","levels"],"sources":["../src/irradiance.js"],"sourcesContent":["// Diffuse light from an environment image, for the renderer: computed once per environment.\n\n/** @import { DataImage } from './material/Texture.js' */\n\n/**\n * Diffuse light from an equirectangular environment, as nine spherical harmonic coefficients (RGB\n * each, flattened), scaled so the shader evaluates them with plain polynomial terms and gets\n * irradiance divided by PI - the light a white matte surface facing that way reflects.\n * @param {DataImage} image linear RGBA floats\n * @returns {Float32Array} 27 numbers\n */\nexport function irradianceSH({ data, width, height }) {\n const sh = new Float64Array(27)\n // sample a grid of at most 128 x 64 - plenty for the lowest frequencies\n const sx = Math.max(1, Math.floor(width / 128)), sy = Math.max(1, Math.floor(height / 64))\n const dPhi = (2 * Math.PI * sx) / width, dTheta = (Math.PI * sy) / height\n for (let y = 0; y < height; y += sy) {\n const theta = ((y + 0.5 * sy) / height) * Math.PI\n const sinT = Math.sin(theta), dy = Math.cos(theta)\n const weight = dPhi * dTheta * sinT\n for (let x = 0; x < width; x += sx) {\n const phi = ((x + 0.5 * sx) / width - 0.5) * 2 * Math.PI\n const dx = Math.cos(phi) * sinT, dz = Math.sin(phi) * sinT\n const basis = [1, dy, dz, dx, dx * dy, dy * dz, 3 * dz * dz - 1, dx * dz, dx * dx - dy * dy]\n const i = (y * width + x) * 4\n for (let k = 0; k < 9; k++) {\n const w = basis[k] * weight\n sh[k * 3] += data[i] * w\n sh[k * 3 + 1] += data[i + 1] * w\n sh[k * 3 + 2] += data[i + 2] * w\n }\n }\n }\n // projection uses the normalised basis Y = norm * polynomial, and evaluation multiplies by the\n // cosine lobe's band factors (PI, 2PI/3, PI/4) and norm again; then divide by PI\n const norm = [0.282095, 0.488603, 0.488603, 0.488603, 1.092548, 1.092548, 0.315392, 1.092548, 0.546274]\n const band = [1, 2 / 3, 2 / 3, 2 / 3, 1 / 4, 1 / 4, 1 / 4, 1 / 4, 1 / 4]\n const out = new Float32Array(27)\n for (let k = 0; k < 9; k++) {\n for (let c = 0; c < 3; c++) out[k * 3 + c] = sh[k * 3 + c] * norm[k] * norm[k] * band[k]\n }\n return out\n}\n"],"mappings":";;AAWA,SAAgBiB,EAAa,EAAE,SAAM,UAAO,aAAU;CACpD,IAAMC,oBAAK,IAAI,aAAa,EAAE,GAExBC,IAAK,KAAK,IAAI,GAAG,KAAK,MAAMC,IAAQ,GAAG,CAAC,GAAGC,IAAK,KAAK,IAAI,GAAG,KAAK,MAAMC,IAAS,EAAE,CAAC,GACnFC,IAAQ,IAAI,KAAK,KAAKJ,IAAMC,GAAOI,IAAU,KAAK,KAAKH,IAAMC;CACnE,KAAK,IAAIG,IAAI,GAAGA,IAAIH,GAAQ,KAAKD,GAAI;EACnC,IAAMK,KAAUD,IAAI,KAAMJ,KAAMC,IAAU,KAAK,IACzCK,IAAO,KAAK,IAAID,CAAK,GAAGE,IAAK,KAAK,IAAIF,CAAK,GAC3CG,IAASN,IAAOC,IAASG;EAC/B,KAAK,IAAIG,IAAI,GAAGA,IAAIV,GAAO,KAAKD,GAAI;GAClC,IAAMY,MAAQD,IAAI,KAAMX,KAAMC,IAAQ,MAAO,IAAI,KAAK,IAChDY,IAAK,KAAK,IAAID,CAAG,IAAIJ,GAAMM,IAAK,KAAK,IAAIF,CAAG,IAAIJ,GAChDO,IAAQ;IAAC;IAAGN;IAAIK;IAAID;IAAIA,IAAKJ;IAAIA,IAAKK;IAAI,IAAIA,IAAKA,IAAK;IAAGD,IAAKC;IAAID,IAAKA,IAAKJ,IAAKA;GAAE,GACrFO,KAAKV,IAAIL,IAAQU,KAAK;GAC5B,KAAK,IAAIM,IAAI,GAAGA,IAAI,GAAG,KAAK;IAC1B,IAAMC,IAAIH,EAAME,KAAKP;IAGrB,AAFA,EAAGO,IAAI,MAAME,EAAKH,KAAKE,GACvB,EAAGD,IAAI,IAAI,MAAME,EAAKH,IAAI,KAAKE,GAC/B,EAAGD,IAAI,IAAI,MAAME,EAAKH,IAAI,KAAKE;GACjC;EACF;CACF;CAGA,IAAME,IAAO;EAAC;EAAU;EAAU;EAAU;EAAU;EAAU;EAAU;EAAU;EAAU;CAAQ,GAChGC,IAAO;EAAC;EAAG,IAAI;EAAG,IAAI;EAAG,IAAI;EAAG,IAAI;EAAG,IAAI;EAAG,IAAI;EAAG,IAAI;EAAG,IAAI;CAAC,GACjEC,oBAAM,IAAI,aAAa,EAAE;CAC/B,KAAK,IAAIL,IAAI,GAAGA,IAAI,GAAG,KACrB,KAAK,IAAIM,IAAI,GAAGA,IAAI,GAAG,KAAK,EAAIN,IAAI,IAAIM,KAAKxB,EAAGkB,IAAI,IAAIM,KAAKH,EAAKH,KAAKG,EAAKH,KAAKI,EAAKJ;CAExF,OAAOK;AACT"}
1
+ {"version":3,"file":"passes.js","names":["mat4.invert","mat4.create","mat4.multiply","invert","passDefines","POINT_SHADOW_SIZE","COMMON","CLIP_ONLY_FRAGMENT","TONE_MAP","EQUIRECT","create","hookFor","CLIP","SPOT_ATLAS_SIZE","multiply","MESH_VERTEX","FULLSCREEN_VERTEX","setHookUniforms","SHADOW_MAP_SIZE","uvMatrix","irradianceSH","sh","sx","width","sy","height","dPhi","dTheta","y","theta","sinT","dy","weight","x","phi","dx","dz","basis","i","k","w","data","norm","band","out","c","BACKGROUND_FRAGMENT","PREFILTER_FRAGMENT","OUTLINE_MASK_FRAGMENT","OUTLINE_MAX","WIDEN","OUTLINE_WIDEN_FRAGMENT","OUTLINE_COMPOSITE_FRAGMENT","OUTLINE_COVER_FRAGMENT","SMOOTH","OUTLINE_SMOOTH_WIDEN_FRAGMENT","OUTLINE_SMOOTH_COMPOSITE_FRAGMENT","OUTLINE_MASK","OUTLINE_WIDEN","OUTLINE_COMPOSITE","OUTLINE_COVER","OUTLINE_SMOOTH_WIDEN","OUTLINE_SMOOTH_COMPOSITE","DEPTH","BACKGROUND","PREFILTER","ENV_WIDTH","ENV_LEVELS","Passes","gl","programs","resources","#environments","#shadow","#spotShadow","#pointShadow","#outline","texture","env","e","image","source","#floatTexture","prefiltered","program","framebuffer","level","hdr","blur","frame","tone","#depthTarget","#beginDepth","#drawDepth","shadow","#endDepth","toTexture","matrices","tiles","bias","half","spot","spots","toTile","#depthCube","point","face","item","casters","instances","defines","material","cutout","triplanar","hook","t","viewProjection","map","targets","#outlineTargets","smooth","radius","outline","outlines","px","pixelRatio","attachment","target","widen","buffer","make","format","msaa","samples","size","framebuffers","levels"],"sources":["../src/irradiance.js"],"sourcesContent":["// Diffuse light from an environment image, for the renderer: computed once per environment.\n\n/** @import { DataImage } from './material/Texture.js' */\n\n/**\n * Diffuse light from an equirectangular environment, as nine spherical harmonic coefficients (RGB\n * each, flattened), scaled so the shader evaluates them with plain polynomial terms and gets\n * irradiance divided by PI - the light a white matte surface facing that way reflects.\n * @param {DataImage} image linear RGBA floats\n * @returns {Float32Array} 27 numbers\n */\nexport function irradianceSH({ data, width, height }) {\n const sh = new Float64Array(27)\n // sample a grid of at most 128 x 64 - plenty for the lowest frequencies\n const sx = Math.max(1, Math.floor(width / 128)), sy = Math.max(1, Math.floor(height / 64))\n const dPhi = (2 * Math.PI * sx) / width, dTheta = (Math.PI * sy) / height\n for (let y = 0; y < height; y += sy) {\n const theta = ((y + 0.5 * sy) / height) * Math.PI\n const sinT = Math.sin(theta), dy = Math.cos(theta)\n const weight = dPhi * dTheta * sinT\n for (let x = 0; x < width; x += sx) {\n const phi = ((x + 0.5 * sx) / width - 0.5) * 2 * Math.PI\n const dx = Math.cos(phi) * sinT, dz = Math.sin(phi) * sinT\n const basis = [1, dy, dz, dx, dx * dy, dy * dz, 3 * dz * dz - 1, dx * dz, dx * dx - dy * dy]\n const i = (y * width + x) * 4\n for (let k = 0; k < 9; k++) {\n const w = basis[k] * weight\n sh[k * 3] += data[i] * w\n sh[k * 3 + 1] += data[i + 1] * w\n sh[k * 3 + 2] += data[i + 2] * w\n }\n }\n }\n // projection uses the normalised basis Y = norm * polynomial, and evaluation multiplies by the\n // cosine lobe's band factors (PI, 2PI/3, PI/4) and norm again; then divide by PI\n const norm = [0.282095, 0.488603, 0.488603, 0.488603, 1.092548, 1.092548, 0.315392, 1.092548, 0.546274]\n const band = [1, 2 / 3, 2 / 3, 2 / 3, 1 / 4, 1 / 4, 1 / 4, 1 / 4, 1 / 4]\n const out = new Float32Array(27)\n for (let k = 0; k < 9; k++) {\n for (let c = 0; c < 3; c++) out[k * 3 + c] = sh[k * 3 + c] * norm[k] * norm[k] * band[k]\n }\n return out\n}\n"],"mappings":";;AAWA,SAAgBoB,EAAa,EAAE,SAAM,UAAO,aAAU;CACpD,IAAMC,oBAAK,IAAI,aAAa,EAAE,GAExBC,IAAK,KAAK,IAAI,GAAG,KAAK,MAAMC,IAAQ,GAAG,CAAC,GAAGC,IAAK,KAAK,IAAI,GAAG,KAAK,MAAMC,IAAS,EAAE,CAAC,GACnFC,IAAQ,IAAI,KAAK,KAAKJ,IAAMC,GAAOI,IAAU,KAAK,KAAKH,IAAMC;CACnE,KAAK,IAAIG,IAAI,GAAGA,IAAIH,GAAQ,KAAKD,GAAI;EACnC,IAAMK,KAAUD,IAAI,KAAMJ,KAAMC,IAAU,KAAK,IACzCK,IAAO,KAAK,IAAID,CAAK,GAAGE,IAAK,KAAK,IAAIF,CAAK,GAC3CG,IAASN,IAAOC,IAASG;EAC/B,KAAK,IAAIG,IAAI,GAAGA,IAAIV,GAAO,KAAKD,GAAI;GAClC,IAAMY,MAAQD,IAAI,KAAMX,KAAMC,IAAQ,MAAO,IAAI,KAAK,IAChDY,IAAK,KAAK,IAAID,CAAG,IAAIJ,GAAMM,IAAK,KAAK,IAAIF,CAAG,IAAIJ,GAChDO,IAAQ;IAAC;IAAGN;IAAIK;IAAID;IAAIA,IAAKJ;IAAIA,IAAKK;IAAI,IAAIA,IAAKA,IAAK;IAAGD,IAAKC;IAAID,IAAKA,IAAKJ,IAAKA;GAAE,GACrFO,KAAKV,IAAIL,IAAQU,KAAK;GAC5B,KAAK,IAAIM,IAAI,GAAGA,IAAI,GAAG,KAAK;IAC1B,IAAMC,IAAIH,EAAME,KAAKP;IAGrB,AAFA,EAAGO,IAAI,MAAME,EAAKH,KAAKE,GACvB,EAAGD,IAAI,IAAI,MAAME,EAAKH,IAAI,KAAKE,GAC/B,EAAGD,IAAI,IAAI,MAAME,EAAKH,IAAI,KAAKE;GACjC;EACF;CACF;CAGA,IAAME,IAAO;EAAC;EAAU;EAAU;EAAU;EAAU;EAAU;EAAU;EAAU;EAAU;CAAQ,GAChGC,IAAO;EAAC;EAAG,IAAI;EAAG,IAAI;EAAG,IAAI;EAAG,IAAI;EAAG,IAAI;EAAG,IAAI;EAAG,IAAI;EAAG,IAAI;CAAC,GACjEC,oBAAM,IAAI,aAAa,EAAE;CAC/B,KAAK,IAAIL,IAAI,GAAGA,IAAI,GAAG,KACrB,KAAK,IAAIM,IAAI,GAAGA,IAAI,GAAG,KAAK,EAAIN,IAAI,IAAIM,KAAKxB,EAAGkB,IAAI,IAAIM,KAAKH,EAAKH,KAAKG,EAAKH,KAAKI,EAAKJ;CAExF,OAAOK;AACT"}
package/dist/phoria2.js CHANGED
@@ -1 +1 @@
1
- export { j as AmbientLight, St as Box3, H as CAMERA_PRESETS, W as Camera, _t as Clip, vt as Color, r as Curve, M as DirectionalLight, X as Drawable, gt as Euler, R as Fog, lt as Geometry, rt as Group, N as HemisphereLight, Z as InstancedMesh, J as LIGHT_LIMITS, Q as Label, P as Light, $ as Lines, Ct as Mat4, ot as Material, et as Mesh, at as Node, Y as NullRenderer, q as OrbitControl, G as OrthographicCamera, K as PerspectiveCamera, Tt as PhoriaError, F as PointLight, tt as Points, ut as Quat, B as Ray, z as Raycaster, L as Scene, I as SpotLight, st as Texture, wt as Vec3, y as View, b as WebGLRenderer, c as axes, l as box, U as cameraPreset, t as create, i as curve, u as cylinder, d as edges, a as ellipse, f as extrude, o as fromPolygons, p as grid, m as icosphere, h as lathe, ct as loadTexture, s as outline, g as plane, n as registerType, _ as sphere, v as torus } from "./core.js";
1
+ export { P as AmbientLight, Et as Box3, G as CAMERA_PRESETS, q as Camera, xt as Clip, St as Color, r as Curve, F as DirectionalLight, et as Drawable, bt as Euler, V as Fog, pt as Geometry, st as Group, I as HemisphereLight, tt as InstancedMesh, Z as LIGHT_LIMITS, nt as Label, L as Light, rt as Lines, Dt as Mat4, ut as Material, it as Mesh, lt as Node, Q as NullRenderer, X as OrbitControl, J as OrthographicCamera, Y as PerspectiveCamera, kt as PhoriaError, R as PointLight, at as Points, mt as Quat, U as Ray, H as Raycaster, B as Scene, z as SpotLight, dt as Texture, Ot as Vec3, y as View, b as WebGLRenderer, c as axes, l as box, K as cameraPreset, t as create, i as curve, u as cylinder, d as edges, a as ellipse, f as extrude, o as fromPolygons, p as grid, m as icosphere, h as lathe, ft as loadTexture, s as outline, g as plane, n as registerType, _ as sphere, v as torus } from "./core.js";