@adatechnology/game-vfx-three 0.11.1 → 0.11.2

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.
@@ -1233,11 +1233,11 @@ var GameVfxThree = (() => {
1233
1233
  this.spare.push(record);
1234
1234
  }
1235
1235
  /** Keeps the records `keep` accepts, in the same order, without allocating. `context` goes to `keep` so no closure is needed per frame. */
1236
- compact(keep, context) {
1236
+ compact(keep2, context) {
1237
1237
  let write = 0;
1238
1238
  for (let read = 0; read < this.items.length; read++) {
1239
1239
  const record = this.items[read];
1240
- if (keep(record, context)) {
1240
+ if (keep2(record, context)) {
1241
1241
  this.items[write++] = record;
1242
1242
  continue;
1243
1243
  }
@@ -1487,12 +1487,13 @@ var GameVfxThree = (() => {
1487
1487
  function streamFor(eventSeed) {
1488
1488
  return lehmer(mixEventSeed(eventSeed));
1489
1489
  }
1490
+ var MAX_PAD = 0.45;
1490
1491
  var SKIN = 5e-3;
1491
1492
  var Solids = class {
1492
1493
  constructor() {
1493
1494
  __publicField(this, "queries", /* @__PURE__ */ new Map());
1494
1495
  __publicField(this, "list", []);
1495
- __publicField(this, "hit", { x: 0, y: 0, z: 0, nx: 0, ny: 0, nz: 0 });
1496
+ __publicField(this, "hit", { x: 0.5, y: 0.5, z: 0.5, nx: 0.5, ny: 0.5, nz: 0.5, d: 0.5 });
1496
1497
  }
1497
1498
  get empty() {
1498
1499
  return this.list.length === 0;
@@ -1508,18 +1509,19 @@ var GameVfxThree = (() => {
1508
1509
  this.list = [];
1509
1510
  }
1510
1511
  /**
1511
- * Stops a step that goes into a solid: `out` gets the nearest hit, put back `pad` metres off the surface (never behind where the step began) and
1512
+ * Stops a step that goes into a solid: `out` gets the nearest hit, put back the step's `pad` metres (at most `MAX_PAD`) off the surface (never behind where the step began) and
1512
1513
  * the surface's normal. Answers whether the step was stopped.
1513
1514
  */
1514
- stop(move, pad, out) {
1515
+ stop(move, out) {
1515
1516
  const dx = move.x1 - move.x0;
1516
1517
  const dy = move.y1 - move.y0;
1517
1518
  const dz = move.z1 - move.z0;
1518
- const length = Math.hypot(dx, dy, dz);
1519
+ const length = Math.sqrt(dx * dx + dy * dy + dz * dz);
1519
1520
  if (!(length > 0)) return false;
1520
1521
  let nearest = Infinity;
1521
- for (const query2 of this.list) {
1522
- if (!query2(move, this.hit)) continue;
1522
+ const list = this.list;
1523
+ for (let index = 0; index < list.length; index++) {
1524
+ if (!list[index](move, this.hit)) continue;
1523
1525
  const reached = ((this.hit.x - move.x0) * dx + (this.hit.y - move.y0) * dy + (this.hit.z - move.z0) * dz) / length;
1524
1526
  if (reached >= nearest) continue;
1525
1527
  nearest = reached;
@@ -1531,15 +1533,24 @@ var GameVfxThree = (() => {
1531
1533
  out.nz = this.hit.nz;
1532
1534
  }
1533
1535
  if (nearest === Infinity) return false;
1534
- const back = Math.min(Math.max(pad, 0) + SKIN, Math.max(nearest, 0));
1536
+ const hitX2 = out.x;
1537
+ const hitY2 = out.y;
1538
+ const hitZ = out.z;
1539
+ out.d = out.nx * hitX2 + out.ny * hitY2 + out.nz * hitZ;
1540
+ const back = Math.min(Math.min(Math.max(move.pad, 0), MAX_PAD) + SKIN, Math.max(nearest, 0));
1535
1541
  out.x -= dx / length * back;
1536
1542
  out.y -= dy / length * back;
1537
1543
  out.z -= dz / length * back;
1544
+ const off = (out.x - hitX2) * out.nx + (out.y - hitY2) * out.ny + (out.z - hitZ) * out.nz;
1545
+ if (off < SKIN) {
1546
+ out.x += out.nx * (SKIN - off);
1547
+ out.y += out.ny * (SKIN - off);
1548
+ out.z += out.nz * (SKIN - off);
1549
+ }
1538
1550
  return true;
1539
1551
  }
1540
1552
  };
1541
1553
  var SKIN2 = 5e-3;
1542
- var MAX_PAD = 0.45;
1543
1554
  function rotation(q) {
1544
1555
  const [x, y, z, w] = q ?? [0, 0, 0, 1];
1545
1556
  const n = Math.hypot(x, y, z, w) || 1;
@@ -1564,7 +1575,7 @@ var GameVfxThree = (() => {
1564
1575
  __publicField(this, "spaces", /* @__PURE__ */ new Map());
1565
1576
  __publicField(this, "list", []);
1566
1577
  __publicField(this, "random");
1567
- __publicField(this, "out", { x: 0, y: 0, z: 0, nx: 0, ny: 0, nz: 0 });
1578
+ __publicField(this, "out", { x: 0.5, y: 0.5, z: 0.5, nx: 0.5, ny: 0.5, nz: 0.5, d: 0.5 });
1568
1579
  __publicField(this, "l0", new Float64Array(3));
1569
1580
  __publicField(this, "l1", new Float64Array(3));
1570
1581
  __publicField(this, "q", new Float64Array(3));
@@ -1639,7 +1650,7 @@ var GameVfxThree = (() => {
1639
1650
  }
1640
1651
  /** Passes at `rate` per second. */
1641
1652
  chance(rate, dt) {
1642
- return rate > 0 && this.random.next() < 1 - Math.exp(-rate * dt);
1653
+ return rate > 0 && dt > 0 && this.random.next() < 1 - Math.exp(-rate * dt);
1643
1654
  }
1644
1655
  /** The opening the wall point `q` (local) is in lets it through now. */
1645
1656
  through(s, q, dt) {
@@ -1662,7 +1673,7 @@ var GameVfxThree = (() => {
1662
1673
  }
1663
1674
  confineMove(move, dt) {
1664
1675
  if (this.confineSpaces(move, dt)) return true;
1665
- return !this.solids.empty && this.solids.stop(move, Math.min(Math.max(0, move.pad), MAX_PAD), this.out);
1676
+ return !this.solids.empty && this.solids.stop(move, this.out);
1666
1677
  }
1667
1678
  confineSpaces(move, dt) {
1668
1679
  const list = this.list;
@@ -1732,6 +1743,7 @@ var GameVfxThree = (() => {
1732
1743
  out.nx = r[axis2] * sign;
1733
1744
  out.ny = r[3 + axis2] * sign;
1734
1745
  out.nz = r[6 + axis2] * sign;
1746
+ out.d = out.nx * s.cx + out.ny * s.cy + out.nz * s.cz + (in0 ? -h[axis2] : h[axis2]);
1735
1747
  return true;
1736
1748
  }
1737
1749
  return false;
@@ -1749,6 +1761,127 @@ var GameVfxThree = (() => {
1749
1761
  if (into >= 0) return [vx2, vy2, vz2];
1750
1762
  return [vx2 - into * out.nx, vy2 - into * out.ny, vz2 - into * out.nz];
1751
1763
  }
1764
+ var PUFF_REACH = 1.28;
1765
+ var PROBES = [{ x: 1, y: 0, z: 0 }, { x: -1, y: 0, z: 0 }, { x: 0, y: 0, z: 1 }, { x: 0, y: 0, z: -1 }, { x: 0, y: 1, z: 0 }];
1766
+ var PROBES_PER_SECOND = 60;
1767
+ var FRAMES_PER_PROBE = 3;
1768
+ var GROUND_FACING = 0.7;
1769
+ var SAME_WALL = 0.9;
1770
+ var PROBE = { x0: 0.5, y0: 0.5, z0: 0.5, x1: 0.5, y1: 0.5, z1: 0.5, pad: 0.5 };
1771
+ var KeptCut = class {
1772
+ constructor() {
1773
+ __publicField(this, "on", false);
1774
+ __publicField(this, "nx", 0.5);
1775
+ __publicField(this, "ny", 0.5);
1776
+ __publicField(this, "nz", 0.5);
1777
+ __publicField(this, "d", 0.5);
1778
+ }
1779
+ };
1780
+ function createCut() {
1781
+ return new KeptCut();
1782
+ }
1783
+ function clearCuts(puff3) {
1784
+ puff3.cuts[0].on = false;
1785
+ puff3.cuts[1].on = false;
1786
+ }
1787
+ var WrittenWay = class {
1788
+ constructor() {
1789
+ __publicField(this, "x", 0.5);
1790
+ __publicField(this, "y", 0.5);
1791
+ __publicField(this, "z", 0.5);
1792
+ }
1793
+ };
1794
+ var WAY = new WrittenWay();
1795
+ function probe(confiner, puff3, way) {
1796
+ const reach = puff3.size * PUFF_REACH;
1797
+ if (!(reach > 0)) return false;
1798
+ PROBE.x0 = puff3.x;
1799
+ PROBE.y0 = puff3.y;
1800
+ PROBE.z0 = puff3.z;
1801
+ PROBE.x1 = puff3.x + way.x * reach;
1802
+ PROBE.y1 = puff3.y + way.y * reach;
1803
+ PROBE.z1 = puff3.z + way.z * reach;
1804
+ PROBE.pad = 0;
1805
+ return confiner.confineMove(PROBE, 0) && confiner.out.ny <= GROUND_FACING;
1806
+ }
1807
+ var isFartherFrom = (puff3, a, b) => a.nx * puff3.x + a.ny * puff3.y + a.nz * puff3.z - a.d > b.nx * puff3.x + b.ny * puff3.y + b.nz * puff3.z - b.d;
1808
+ var isBehind = (puff3, face) => face.nx * puff3.x + face.ny * puff3.y + face.nz * puff3.z < face.d;
1809
+ var sameWall = (cut, face) => cut.on && cut.nx * face.nx + cut.ny * face.ny + cut.nz * face.nz > SAME_WALL;
1810
+ function cutFor(puff3, face) {
1811
+ const first = puff3.cuts[0];
1812
+ const second = puff3.cuts[1];
1813
+ if (sameWall(first, face)) return first;
1814
+ if (sameWall(second, face)) return second;
1815
+ if (!first.on) return first;
1816
+ if (!second.on) return second;
1817
+ const farther = isFartherFrom(puff3, first, second) ? first : second;
1818
+ return isFartherFrom(puff3, farther, face) ? farther : void 0;
1819
+ }
1820
+ function cutAtFace(puff3, face) {
1821
+ if (face.ny > GROUND_FACING) return;
1822
+ const cut = cutFor(puff3, face);
1823
+ if (!cut) return;
1824
+ cut.on = true;
1825
+ cut.nx = face.nx;
1826
+ cut.ny = face.ny;
1827
+ cut.nz = face.nz;
1828
+ cut.d = face.d;
1829
+ }
1830
+ function cutFrom(puff3, out) {
1831
+ cutAtFace(puff3, out);
1832
+ }
1833
+ function cutAt(confiner, puff3, way) {
1834
+ if (!probe(confiner, puff3, way)) return false;
1835
+ cutAtFace(puff3, confiner.out);
1836
+ return true;
1837
+ }
1838
+ function backward(puff3) {
1839
+ const speed = Math.sqrt(puff3.vx * puff3.vx + puff3.vy * puff3.vy + puff3.vz * puff3.vz);
1840
+ if (!(speed > 0)) return null;
1841
+ WAY.x = -puff3.vx / speed;
1842
+ WAY.y = -puff3.vy / speed;
1843
+ WAY.z = -puff3.vz / speed;
1844
+ return WAY;
1845
+ }
1846
+ function along(cut, sign) {
1847
+ WAY.x = sign * cut.nx;
1848
+ WAY.y = sign * cut.ny;
1849
+ WAY.z = sign * cut.nz;
1850
+ return WAY;
1851
+ }
1852
+ function dropPassed(confiner, puff3) {
1853
+ for (let i = 0; i < 2; i++) {
1854
+ const cut = puff3.cuts[i];
1855
+ if (!cut.on || !isBehind(puff3, cut)) continue;
1856
+ cut.on = false;
1857
+ cutAt(confiner, puff3, along(cut, 1));
1858
+ }
1859
+ }
1860
+ function keep(confiner, puff3, cut) {
1861
+ if (!cut.on) return;
1862
+ if (!probe(confiner, puff3, along(cut, -1))) {
1863
+ cut.on = false;
1864
+ return;
1865
+ }
1866
+ cut.d = confiner.out.d;
1867
+ }
1868
+ function lookForWalls(confiner, puff3) {
1869
+ dropPassed(confiner, puff3);
1870
+ const turn = Math.round(puff3.t * PROBES_PER_SECOND);
1871
+ if (turn <= 1) {
1872
+ const back = backward(puff3);
1873
+ if (back) cutAt(confiner, puff3, back);
1874
+ for (let i = 0; i < PROBES.length; i++) cutAt(confiner, puff3, PROBES[i]);
1875
+ return;
1876
+ }
1877
+ if (turn % FRAMES_PER_PROBE !== 0) return;
1878
+ const slot = turn / FRAMES_PER_PROBE % (PROBES.length + 3);
1879
+ if (slot < 2) keep(confiner, puff3, puff3.cuts[slot]);
1880
+ else if (slot === 2) {
1881
+ const back = backward(puff3);
1882
+ if (back) cutAt(confiner, puff3, back);
1883
+ } else cutAt(confiner, puff3, PROBES[slot - 3]);
1884
+ }
1752
1885
  var FLOOR_FRACTION = 0.4;
1753
1886
  var FLOOR_BOUNCE = -0.2;
1754
1887
  var ARRIVAL_FRAME = 30;
@@ -1788,7 +1921,8 @@ var GameVfxThree = (() => {
1788
1921
  age: 0,
1789
1922
  heat: 0,
1790
1923
  size: 0,
1791
- source: void 0
1924
+ source: void 0,
1925
+ cuts: [createCut(), createCut()]
1792
1926
  }));
1793
1927
  }
1794
1928
  function spawnPuff(pool, random, init) {
@@ -1822,6 +1956,7 @@ var GameVfxThree = (() => {
1822
1956
  puff3.heat = 0;
1823
1957
  puff3.size = 0;
1824
1958
  puff3.source = init.source;
1959
+ clearCuts(puff3);
1825
1960
  return puff3;
1826
1961
  }
1827
1962
  function ageOrKeep2(puff3, dt) {
@@ -1871,17 +2006,21 @@ var GameVfxThree = (() => {
1871
2006
  MOVE.z0 = puff3.z;
1872
2007
  if (puff3.ring) moveOnRing(puff3, puff3.ring, wind);
1873
2008
  else moveFree(puff3, dt, age, heat, wind);
1874
- if (confining && CARRIED_KINDS[puff3.kind] && confine(confiner, puff3, dt)) {
2009
+ const carried = confining && CARRIED_KINDS[puff3.kind];
2010
+ if (carried && confine(confiner, puff3, dt)) {
1875
2011
  const out = confiner.out;
1876
2012
  puff3.x = out.x;
1877
2013
  puff3.y = out.y;
1878
2014
  puff3.z = out.z;
1879
2015
  slideInto(out, puff3);
2016
+ cutFrom(puff3, out);
1880
2017
  }
1881
2018
  const size = puff3.s0 + (puff3.s1 - puff3.s0) * (1 - Math.exp(-puff3.t * puff3.gk)) + puff3.sg * Math.min(puff3.t, GROWTH_CAP_SECONDS);
1882
2019
  puff3.size = size * Math.min(1, puff3.t * ARRIVAL_FRAME + ARRIVAL_BASE);
1883
2020
  puff3.age = age;
1884
2021
  puff3.heat = heat;
2022
+ if (carried) lookForWalls(confiner, puff3);
2023
+ else clearCuts(puff3);
1885
2024
  }
1886
2025
  }
1887
2026
  var GROUND_LIFT = 0.02;
@@ -4852,10 +4991,10 @@ var GameVfxThree = (() => {
4852
4991
  var MAX_SCALE = 3;
4853
4992
  var MIN_SCALE = 0.6;
4854
4993
  function reflected(direction, normal) {
4855
- const along = direction[0] * normal[0] + direction[1] * normal[1] + direction[2] * normal[2];
4856
- const out = [direction[0] - 2 * along * normal[0], direction[1] - 2 * along * normal[1], direction[2] - 2 * along * normal[2]];
4994
+ const along2 = direction[0] * normal[0] + direction[1] * normal[1] + direction[2] * normal[2];
4995
+ const out = [direction[0] - 2 * along2 * normal[0], direction[1] - 2 * along2 * normal[1], direction[2] - 2 * along2 * normal[2]];
4857
4996
  const length = Math.hypot(out[0], out[1], out[2]);
4858
- if (length < 1e-6 || Math.abs(along) > 0.98) return normal;
4997
+ if (length < 1e-6 || Math.abs(along2) > 0.98) return normal;
4859
4998
  return [out[0] / length, out[1] / length, out[2] / length];
4860
4999
  }
4861
5000
  var numberOr = (value, fallback2) => typeof value === "number" && Number.isFinite(value) ? value : fallback2;
@@ -5807,7 +5946,7 @@ var GameVfxThree = (() => {
5807
5946
  spawnShock(core.shocks, spec);
5808
5947
  }
5809
5948
  function composeDust(context) {
5810
- const { core, def, random, x, z, size, scale } = context;
5949
+ const { core, def, random, x, y, z, size, scale } = context;
5811
5950
  if (!core.layers.smoke || !def.dust.count || !(scale > 0.15)) return;
5812
5951
  const count = Math.round(def.dust.count * scale);
5813
5952
  const color = hexToLinearRgb(def.dust.color);
@@ -5837,7 +5976,7 @@ var GameVfxThree = (() => {
5837
5976
  color,
5838
5977
  kind: 1
5839
5978
  });
5840
- bornFrom(core, dust, x, 0.15, z);
5979
+ bornFrom(core, dust, x, y, z);
5841
5980
  }
5842
5981
  }
5843
5982
  function coneAngle(context) {
@@ -6168,6 +6307,9 @@ var GameVfxThree = (() => {
6168
6307
  state.beat *= Math.exp(-DECAY.beat * dt);
6169
6308
  }
6170
6309
  var PAD_OF_SIZE2 = 0.35;
6310
+ var STEP = { x0: 0.5, y0: 0.5, z0: 0.5, x1: 0.5, y1: 0.5, z1: 0.5, pad: 0.5 };
6311
+ var GROUND_RESAMPLE = 0.1;
6312
+ var VELOCITY = { vx: 0.5, vy: 0.5, vz: 0.5 };
6171
6313
  var clamp4 = (v, lo, hi) => v < lo ? lo : v > hi ? hi : v;
6172
6314
  var lerp4 = (a, b, t) => a + (b - a) * t;
6173
6315
  function rgb(hex) {
@@ -6214,6 +6356,7 @@ var GameVfxThree = (() => {
6214
6356
  __publicField(this, "bounced");
6215
6357
  __publicField(this, "floor");
6216
6358
  __publicField(this, "riseMul");
6359
+ __publicField(this, "ground");
6217
6360
  const n = Math.max(1, capacity);
6218
6361
  this.position = new Float32Array(n * 3);
6219
6362
  this.color = new Float32Array(n * 3);
@@ -6236,6 +6379,7 @@ var GameVfxThree = (() => {
6236
6379
  this.bounced = new Uint8Array(n);
6237
6380
  this.floor = new Float32Array(n);
6238
6381
  this.riseMul = new Float32Array(n);
6382
+ this.ground = new Float32Array(n * 3);
6239
6383
  }
6240
6384
  spawn(kind, p, v, random, options) {
6241
6385
  if (this.capacity <= 0) return;
@@ -6263,6 +6407,7 @@ var GameVfxThree = (() => {
6263
6407
  this.bounced[i] = 0;
6264
6408
  this.floor[i] = options?.floor ?? Number.NaN;
6265
6409
  this.riseMul[i] = options?.rise ?? 1;
6410
+ this.ground[i * 3] = Number.NaN;
6266
6411
  this.size[i] = this.size0[i];
6267
6412
  this.alpha[i] = 0;
6268
6413
  }
@@ -6356,18 +6501,36 @@ var GameVfxThree = (() => {
6356
6501
  let z = this.position[i3 + 2] + vz2 * dt;
6357
6502
  const confiner = host.confiner;
6358
6503
  if (def.carried && confiner && !confiner.empty) {
6359
- const pad = this.size0[i] * lerp4(1, def.grow, t) * PAD_OF_SIZE2;
6360
- if (confiner.confine(this.position[i3], this.position[i3 + 1], this.position[i3 + 2], x, y, z, pad, dt)) {
6504
+ STEP.x0 = this.position[i3];
6505
+ STEP.y0 = this.position[i3 + 1];
6506
+ STEP.z0 = this.position[i3 + 2];
6507
+ STEP.x1 = x;
6508
+ STEP.y1 = y;
6509
+ STEP.z1 = z;
6510
+ STEP.pad = this.size0[i] * (1 + (def.grow - 1) * t) * PAD_OF_SIZE2;
6511
+ if (confiner.confineMove(STEP, dt)) {
6361
6512
  const out = confiner.out;
6362
6513
  x = out.x;
6363
6514
  y = out.y;
6364
6515
  z = out.z;
6365
- [vx2, vy2, vz2] = slideAlong(out, vx2, vy2, vz2);
6516
+ VELOCITY.vx = vx2;
6517
+ VELOCITY.vy = vy2;
6518
+ VELOCITY.vz = vz2;
6519
+ slideInto(out, VELOCITY);
6520
+ vx2 = VELOCITY.vx;
6521
+ vy2 = VELOCITY.vy;
6522
+ vz2 = VELOCITY.vz;
6366
6523
  }
6367
6524
  }
6368
6525
  if (def.ground !== "none") {
6369
6526
  const own = this.floor[i];
6370
- const gy = Number.isNaN(own) ? host.groundAt(x, z) + 5e-3 : own;
6527
+ const ground = this.ground;
6528
+ if (Number.isNaN(own) && !(Math.abs(x - ground[i3]) < GROUND_RESAMPLE && Math.abs(z - ground[i3 + 1]) < GROUND_RESAMPLE)) {
6529
+ ground[i3] = x;
6530
+ ground[i3 + 1] = z;
6531
+ ground[i3 + 2] = host.groundAt(x, z);
6532
+ }
6533
+ const gy = Number.isNaN(own) ? ground[i3 + 2] + 5e-3 : own;
6371
6534
  if (y < gy) {
6372
6535
  if (def.ground === "land") {
6373
6536
  const tag = this.tag[i];
@@ -7213,10 +7376,10 @@ var GameVfxThree = (() => {
7213
7376
  if (particle.fade) particle.opacity = Math.max(0, particle.startOpacity * (1 - particle.age / particle.life));
7214
7377
  particle.vy -= particle.gravity * dt;
7215
7378
  if (particle.drag) {
7216
- const keep = Math.max(0, 1 - particle.drag * dt);
7217
- particle.vx *= keep;
7218
- particle.vy *= keep;
7219
- particle.vz *= keep;
7379
+ const keep2 = Math.max(0, 1 - particle.drag * dt);
7380
+ particle.vx *= keep2;
7381
+ particle.vy *= keep2;
7382
+ particle.vz *= keep2;
7220
7383
  }
7221
7384
  if (particle.carried) this.ride(particle, dt);
7222
7385
  else {
@@ -8060,10 +8223,10 @@ var GameVfxThree = (() => {
8060
8223
  for (let index = fires.items.length - 1; index >= 0; index--) if (fires.items[index].handle === handle) fires.removeAt(index);
8061
8224
  },
8062
8225
  clearSource(source) {
8063
- const keep = (record, gone) => record.source !== gone;
8226
+ const keep2 = (record, gone) => record.source !== gone;
8064
8227
  const drop = (pool) => {
8065
8228
  const before = pool.count;
8066
- pool.compact(keep, source);
8229
+ pool.compact(keep2, source);
8067
8230
  return before - pool.count;
8068
8231
  };
8069
8232
  return drop(core.fires) + drop(core.puffs) + drop(core.sparks) + drop(core.chunks) + drop(core.glows) + spriteSystem.clearSource(source);
@@ -8989,23 +9152,24 @@ float vn(vec3 x){vec3 i=floor(x),f=fract(x);f=f*f*(3.-2.*f);
8989
9152
  `;
8990
9153
 
8991
9154
  // src/shaders/puff.ts
9155
+ var PUFF_BASE = (PUFF_REACH - 0.5).toFixed(2);
8992
9156
  var PUFF_VERTEX = `${GL_NOISE}
8993
- attribute vec4 aP;attribute vec4 aD;attribute vec3 aC;
9157
+ attribute vec4 aP;attribute vec4 aD;attribute vec3 aC;attribute vec4 aK;attribute vec4 aK2;varying vec4 vK;varying vec4 vK2;
8994
9158
  varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;
8995
9159
  void main(){
8996
9160
  vec3 p=position;
8997
9161
  float s=aD.z;
8998
9162
  float n=vn(p*1.6+vec3(s*11.0,s*7.0,s*3.0));
8999
- p*=0.78+0.5*n;
9163
+ p*=${PUFF_BASE}+0.5*n;
9000
9164
  float a=s*6.2831;float c=cos(a),si=sin(a);p.xz=mat2(c,-si,si,c)*p.xz;
9001
9165
  vL=p;
9002
9166
  vec3 wp=aP.xyz+p*aP.w;
9003
- vWP=wp;vD=aD;vC=aC;
9167
+ vWP=wp;vD=aD;vC=aC;vK=aK;vK2=aK2;
9004
9168
  gl_Position=projectionMatrix*viewMatrix*vec4(wp,1.0);
9005
9169
  }`;
9006
9170
  var PUFF_FRAGMENT = `${GL_NOISE}
9007
9171
  uniform vec3 uLight;uniform vec3 uSky;uniform vec3 uGround;uniform vec3 uGlowPos;uniform vec3 uGlowCol;uniform float uGlowI;
9008
- varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;
9172
+ varying vec4 vK;varying vec4 vK2;varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;
9009
9173
  vec3 L(vec3 c){return pow(c,vec3(2.2));}
9010
9174
  vec3 ramp(float h){
9011
9175
  vec3 c0=L(vec3(.36,.07,.03)),c1=L(vec3(.76,.21,.1)),c2=L(vec3(1.,.54,.16)),c3=L(vec3(1.,.83,.42)),c4=L(vec3(1.,.96,.84));
@@ -9015,6 +9179,8 @@ vec3 ramp(float h){
9015
9179
  return mix(c3,c4,clamp((h-.8)/.4,0.,1.));
9016
9180
  }
9017
9181
  void main(){
9182
+ // cut at the face of a wall within reach (Puff.cuts): smoke flattens on the wall, it does not show through on its other side
9183
+ if(dot(vWP,vK.xyz)<vK.w||dot(vWP,vK2.xyz)<vK2.w)discard;
9018
9184
  vec3 N=normalize(cross(dFdx(vWP),dFdy(vWP)));
9019
9185
  float age=vD.x,heat=vD.y,kind=vD.w;
9020
9186
  float n=vn(vL*2.4+vD.z*13.0);
@@ -9043,23 +9209,23 @@ void main(){
9043
9209
  #include <colorspace_fragment>
9044
9210
  }`;
9045
9211
  var SOFT_PUFF_VERTEX = `${GL_NOISE}
9046
- attribute vec4 aP;attribute vec4 aD;attribute vec3 aC;
9212
+ attribute vec4 aP;attribute vec4 aD;attribute vec3 aC;attribute vec4 aK;attribute vec4 aK2;varying vec4 vK;varying vec4 vK2;
9047
9213
  varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;varying vec3 vN;
9048
9214
  void main(){
9049
9215
  vec3 p=position;
9050
9216
  vec3 q=normalize(position);
9051
9217
  float s=aD.z;
9052
9218
  float n=vn(p*1.6+vec3(s*11.0,s*7.0,s*3.0));
9053
- p*=0.78+0.5*n;
9219
+ p*=${PUFF_BASE}+0.5*n;
9054
9220
  float a=s*6.2831;float c=cos(a),si=sin(a);p.xz=mat2(c,-si,si,c)*p.xz;q.xz=mat2(c,-si,si,c)*q.xz;
9055
9221
  vL=p;vN=q;
9056
9222
  vec3 wp=aP.xyz+p*aP.w;
9057
- vWP=wp;vD=aD;vC=aC;
9223
+ vWP=wp;vD=aD;vC=aC;vK=aK;vK2=aK2;
9058
9224
  gl_Position=projectionMatrix*viewMatrix*vec4(wp,1.0);
9059
9225
  }`;
9060
9226
  var SOFT_PUFF_FRAGMENT = `${GL_NOISE}
9061
9227
  uniform vec3 uLight;uniform vec3 uSky;uniform vec3 uGround;uniform vec3 uGlowPos;uniform vec3 uGlowCol;uniform float uGlowI;
9062
- varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;varying vec3 vN;
9228
+ varying vec4 vK;varying vec4 vK2;varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;varying vec3 vN;
9063
9229
  vec3 L(vec3 c){return pow(c,vec3(2.2));}
9064
9230
  vec3 ramp(float h){
9065
9231
  vec3 c0=L(vec3(.36,.07,.03)),c1=L(vec3(.76,.21,.1)),c2=L(vec3(1.,.54,.16)),c3=L(vec3(1.,.83,.42)),c4=L(vec3(1.,.96,.84));
@@ -9069,6 +9235,8 @@ vec3 ramp(float h){
9069
9235
  return mix(c3,c4,clamp((h-.8)/.4,0.,1.));
9070
9236
  }
9071
9237
  void main(){
9238
+ // cut at the face of a wall within reach (Puff.cuts): smoke flattens on the wall, it does not show through on its other side
9239
+ if(dot(vWP,vK.xyz)<vK.w||dot(vWP,vK2.xyz)<vK2.w)discard;
9072
9240
  float age=vD.x,heat=vD.y,kind=vD.w;
9073
9241
  float n=vn(vL*2.4+vD.z*13.0);
9074
9242
  // the sphere's own normal, roughened by the noise: a billowing cloud, never facets
@@ -9136,6 +9304,13 @@ void main(){
9136
9304
  function dynamic(THREE, array, size) {
9137
9305
  return new THREE.InstancedBufferAttribute(array, size).setUsage(THREE.DynamicDrawUsage);
9138
9306
  }
9307
+ var NO_CUT = -1e9;
9308
+ function writeCut(into, n, cut) {
9309
+ into[n * 4] = cut.on ? cut.nx : 0;
9310
+ into[n * 4 + 1] = cut.on ? cut.ny : 0;
9311
+ into[n * 4 + 2] = cut.on ? cut.nz : 0;
9312
+ into[n * 4 + 3] = cut.on ? cut.d : NO_CUT;
9313
+ }
9139
9314
  var PUFF_DETAIL = { faceted: 1, soft: 2 };
9140
9315
  function createPuffLayer(THREE, pool, uniforms, style = "faceted") {
9141
9316
  const capacity = pool.capacity;
@@ -9144,10 +9319,14 @@ void main(){
9144
9319
  const a = new Float32Array(capacity * 4);
9145
9320
  const d = new Float32Array(capacity * 4);
9146
9321
  const c = new Float32Array(capacity * 3);
9147
- const attributes = [dynamic(THREE, a, 4), dynamic(THREE, d, 4), dynamic(THREE, c, 3)];
9322
+ const k = new Float32Array(capacity * 4);
9323
+ const k2 = new Float32Array(capacity * 4);
9324
+ const attributes = [dynamic(THREE, a, 4), dynamic(THREE, d, 4), dynamic(THREE, c, 3), dynamic(THREE, k, 4), dynamic(THREE, k2, 4)];
9148
9325
  geometry.setAttribute("aP", attributes[0]);
9149
9326
  geometry.setAttribute("aD", attributes[1]);
9150
9327
  geometry.setAttribute("aC", attributes[2]);
9328
+ geometry.setAttribute("aK", attributes[3]);
9329
+ geometry.setAttribute("aK2", attributes[4]);
9151
9330
  geometry.instanceCount = 0;
9152
9331
  const material2 = style === "faceted" ? new THREE.ShaderMaterial({ uniforms, vertexShader: PUFF_VERTEX, fragmentShader: PUFF_FRAGMENT }) : new THREE.ShaderMaterial({ uniforms, vertexShader: SOFT_PUFF_VERTEX, fragmentShader: SOFT_PUFF_FRAGMENT, transparent: true, depthWrite: false });
9153
9332
  const mesh2 = new THREE.Mesh(geometry, material2);
@@ -9169,6 +9348,8 @@ void main(){
9169
9348
  c[n * 3] = p.color[0];
9170
9349
  c[n * 3 + 1] = p.color[1];
9171
9350
  c[n * 3 + 2] = p.color[2];
9351
+ writeCut(k, n, p.cuts[0]);
9352
+ writeCut(k2, n, p.cuts[1]);
9172
9353
  n++;
9173
9354
  }
9174
9355
  geometry.instanceCount = n;