rayzee 11.2.0 → 11.3.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/README.md +62 -33
- package/dist/ArchiveImporter-D735xX-4.js +7860 -0
- package/dist/BidirectionalIntegrator-M89c0AlP.js +954 -0
- package/dist/{BufferLayout-D_IBo2ci.js → BufferLayout-xPRH9jYD.js} +41 -5
- package/dist/{NeuralRetouch-DFGbnmLb.js → NeuralRetouch-DiBH63kz.js} +1 -1
- package/dist/{NeuralSuperRes-BtXvyJQl.js → NeuralSuperRes-CZNQP13W.js} +1 -1
- package/dist/{PathTracer-BHXGJtPN.js → PathTracer-BXCCVrPK.js} +4371 -4612
- package/dist/{PhysicalSky-DN6u8UX4.js → PhysicalSky-DqmaS0lb.js} +2 -2
- package/dist/{RayzeeRenderer-Dw1x8mVL.js → RayzeeRenderer-DUSMFhmc.js} +426 -363
- package/dist/SolarLimb-bZE6y63S.js +762 -0
- package/dist/addons/archives.es.js +1 -1
- package/dist/addons/bidirectional.es.js +1 -1
- package/dist/addons/physical-sky.es.js +1 -1
- package/dist/rayzee-core.es.js +7 -7
- package/dist/rayzee.es.js +472 -468
- package/dist/rayzee.umd.js +106 -105
- package/dist/sceneCachePolicy-BAib5fCp.js +1602 -0
- package/package.json +1 -1
- package/src/EngineDefaults.js +1 -1
- package/src/PathTracerApp.js +4 -3
- package/src/Processor/ArchiveImporter.js +173 -94
- package/src/Processor/ArchiveReader.js +20 -23
- package/src/Processor/AssetLoader.js +48 -1
- package/src/Processor/BVHRefitter.js +109 -13
- package/src/Processor/BufferLayout.js +115 -0
- package/src/Processor/ChunkedRecords.js +3 -2
- package/src/Processor/EmissiveTriangleBuilder.js +6 -6
- package/src/Processor/GeometryExtractor.js +189 -79
- package/src/Processor/HostMemory.js +39 -9
- package/src/Processor/InstanceTable.js +714 -42
- package/src/Processor/PBRT/PBRTCurves.js +224 -6
- package/src/Processor/PBRT/PBRTMaterials.js +3 -0
- package/src/Processor/PBRT/PBRTSceneBuilder.js +82 -25
- package/src/Processor/PackedRayBuffer.js +5 -2
- package/src/Processor/SceneProcessor.js +747 -141
- package/src/Processor/TLASBuilder.js +32 -17
- package/src/Processor/USD/USDLayer.js +1149 -0
- package/src/Processor/USD/USDScene.js +1655 -0
- package/src/Processor/USD/USDStage.js +682 -0
- package/src/Processor/USD/USDText.js +674 -0
- package/src/Processor/USD/index.js +138 -0
- package/src/Processor/Workers/BVHRefitWorker.js +3 -3
- package/src/RayzeeRenderer.js +168 -27
- package/src/Stages/NormalDepth.js +7 -12
- package/src/Stages/PathTracer.js +12 -17
- package/src/Stages/PathTracerStage.js +273 -96
- package/src/Storage/GeometrySpill.js +46 -14
- package/src/Storage/SceneGraphCodec.js +17 -3
- package/src/Storage/SpillStore.js +9 -0
- package/src/TSL/BVHTraversal.js +183 -7
- package/src/TSL/Common.js +57 -13
- package/src/TSL/ShadeKernel.js +3 -2
- package/src/TSL/TextureSampling.js +11 -8
- package/src/TSL/patches.js +84 -0
- package/src/integrators/BidirectionalIntegrator.js +20 -2
- package/src/managers/DenoisingManager.js +4 -4
- package/src/managers/InteractionManager.js +19 -6
- package/src/managers/MaterialDataManager.js +22 -5
- package/src/managers/UniformManager.js +3 -0
- package/dist/ArchiveImporter-eNlu0_6F.js +0 -5198
- package/dist/BidirectionalIntegrator-D1-6UySB.js +0 -946
- package/dist/SolarLimb-CPaeZVwz.js +0 -721
- package/dist/sceneCachePolicy-DA7iGoL4.js +0 -485
|
@@ -0,0 +1,954 @@
|
|
|
1
|
+
import { F as e, Ft as t, I as n, J as r, Jt as i, K as a, L as o, Mt as s, Qt as c, R as l, U as u, X as d, Y as f, Z as p, an as m, c as ee, ct as te, dt as ne, en as re, et as h, ft as g, i as _, in as ie, j as ae, jt as oe, k as se, lt as v, q as y, r as ce, wt as le, y as ue, zt as de } from "./SolarLimb-bZE6y63S.js";
|
|
2
|
+
import { A as b, C as x, Ct as fe, D as S, E as C, F as w, G as T, I as E, J as D, M as pe, O as me, S as he, St as O, T as ge, U as _e, V as ve, W as ye, Y as be, _ as k, a as xe, at as A, b as Se, bt as Ce, c as we, d as Te, f as Ee, g as j, h as De, i as Oe, it as M, j as N, k as ke, l as Ae, m as P, o as je, p as Me, q as Ne, r as Pe, rt as Fe, s as Ie, t as Le, u as F, v as Re, vt as ze, w as Be, x as Ve, xt as He, y as Ue, yt as I } from "./PathTracer-BXCCVrPK.js";
|
|
3
|
+
import { W as We } from "./sceneCachePolicy-BAib5fCp.js";
|
|
4
|
+
import { r as Ge } from "./BufferLayout-xPRH9jYD.js";
|
|
5
|
+
import { Break as Ke, Fn as L, If as R, Loop as qe, Return as z, abs as B, atomicAdd as Je, atomicFunc as Ye, atomicLoad as V, atomicStore as Xe, bool as Ze, cos as Qe, cross as $e, dot as H, exp2 as et, float as U, floor as tt, instanceIndex as nt, int as W, ivec2 as rt, ivec3 as it, length as at, localId as ot, log2 as st, max as G, min as ct, mix as lt, normalize as ut, sampler as dt, select as K, sin as ft, sqrt as pt, storage as mt, texture as ht, uint as q, uniform as J, uniformArray as gt, vec2 as _t, vec3 as Y, vec4 as vt, workgroupId as yt } from "three/tsl";
|
|
6
|
+
import { DataTexture as bt, FloatType as xt, RedFormat as St, Vector3 as Ct } from "three";
|
|
7
|
+
//#region \0rolldown/runtime.js
|
|
8
|
+
var wt = Object.defineProperty, Tt = (e, t) => {
|
|
9
|
+
let n = {};
|
|
10
|
+
for (var r in e) wt(n, r, {
|
|
11
|
+
get: e[r],
|
|
12
|
+
enumerable: !0
|
|
13
|
+
});
|
|
14
|
+
return t || wt(n, Symbol.toStringTag, { value: "Module" }), n;
|
|
15
|
+
}, Et = /* @__PURE__ */ Tt({
|
|
16
|
+
LampPick: () => Dt,
|
|
17
|
+
areaLightDirectPdfW: () => It,
|
|
18
|
+
directionalConeSolidAngle: () => Ft,
|
|
19
|
+
lampCount: () => Ot,
|
|
20
|
+
lampPickPdf: () => Nt,
|
|
21
|
+
lampTypeAt: () => kt,
|
|
22
|
+
pickLamp: () => Mt,
|
|
23
|
+
spotConeSolidAngle: () => Pt
|
|
24
|
+
}), Dt = m({
|
|
25
|
+
kind: "int",
|
|
26
|
+
index: "int",
|
|
27
|
+
pdf: "float",
|
|
28
|
+
total: "float"
|
|
29
|
+
}), Ot = (e) => e.numDirectional.add(e.numArea).add(e.numPoint).add(e.numSpot), kt = (e, t) => K(t.lessThan(e.numDirectional), W(0), K(t.lessThan(e.numDirectional.add(e.numArea)), W(1), K(t.lessThan(e.numDirectional.add(e.numArea).add(e.numPoint)), W(2), W(3)))), At = (e, t) => K(t.equal(W(0)), W(0), K(t.equal(W(1)), e.numDirectional, K(t.equal(W(2)), e.numDirectional.add(e.numArea), e.numDirectional.add(e.numArea).add(e.numPoint)))), jt = (e, t, n, r, i) => {
|
|
30
|
+
let a = (e, t, n) => R(t.greaterThan(W(0)), () => {
|
|
31
|
+
qe({
|
|
32
|
+
start: W(0),
|
|
33
|
+
end: t,
|
|
34
|
+
type: "int",
|
|
35
|
+
condition: "<"
|
|
36
|
+
}, ({ i: t }) => {
|
|
37
|
+
i(W(e), t, n(t).toVar());
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
a(0, e.numDirectional, (t) => Me(Ue.wrap(x(e.directional, t)), n, r, W(0))), a(1, e.numArea, (i) => {
|
|
41
|
+
let a = Re.wrap(he(e.area, i));
|
|
42
|
+
return K(a.intensity.greaterThan(0), j(a, t, n, r), U(0));
|
|
43
|
+
}), a(2, e.numPoint, (i) => P(Se.wrap(Be(e.point, i)), t, n, r)), a(3, e.numSpot, (i) => De(Ve.wrap(C(e.spot, i)), t, n, r));
|
|
44
|
+
};
|
|
45
|
+
function Mt(e, t, n, r, i, a) {
|
|
46
|
+
let o = W(-1).toVar(), s = W(-1).toVar(), c = U(0).toVar(), l = U(0).toVar();
|
|
47
|
+
jt(e, t, n, r, (t, n, r) => {
|
|
48
|
+
l.addAssign(r), R(r.greaterThan(0).and(a(W(I + 64).add(At(e, t)).add(n)).mul(l).lessThan(r)), () => {
|
|
49
|
+
o.assign(t), s.assign(n), c.assign(r);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
let u = Ot(e).toVar(), d = c.div(G(l, 1e-10)).toVar();
|
|
53
|
+
return R(l.lessThanEqual(0), () => {
|
|
54
|
+
let t = ct(W(i.mul(U(u))), u.sub(W(1))).toVar();
|
|
55
|
+
o.assign(kt(e, t)), s.assign(t.sub(At(e, o))), d.assign(U(1).div(G(U(u), 1)));
|
|
56
|
+
}), Dt({
|
|
57
|
+
kind: o,
|
|
58
|
+
index: s,
|
|
59
|
+
pdf: d,
|
|
60
|
+
total: l
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function Nt(e, t, n, r, i, a) {
|
|
64
|
+
let o = U(0).toVar(), s = U(0).toVar();
|
|
65
|
+
return jt(e, r, i, a, (e, r, i) => {
|
|
66
|
+
o.addAssign(i), R(e.equal(t).and(r.equal(n)), () => {
|
|
67
|
+
s.assign(i);
|
|
68
|
+
});
|
|
69
|
+
}), K(o.greaterThan(0), s.div(o), U(1).div(G(U(Ot(e)), 1)));
|
|
70
|
+
}
|
|
71
|
+
var Pt = (e) => U(2 * v).mul(G(U(1).sub(Qe(e.angle)), 1e-10)), Ft = (e) => U(2 * v).mul(G(U(1).sub(Qe(e.angle.mul(.5))), 1e-10)), It = (e, t, n, r) => {
|
|
72
|
+
let i = b(t, e.position.sub(e.u).sub(e.v), e.u.mul(2), e.v.mul(2)).toVar();
|
|
73
|
+
return K(e.shape.lessThan(.5).and(i.greaterThan(1e-5)), U(1).div(i), n.mul(n).div(G(e.area.mul(G(r, .001)), 1e-10)));
|
|
74
|
+
}, Lt = /* @__PURE__ */ Tt({
|
|
75
|
+
DIM_CONNECT_PATH: () => 16,
|
|
76
|
+
DIM_CONNECT_VERTEX: () => 17,
|
|
77
|
+
DIM_EMIT: () => X,
|
|
78
|
+
LIGHT_PIXEL_ROW_OFFSET: () => Rt,
|
|
79
|
+
PASS_TAG_BIT: () => Vt,
|
|
80
|
+
SOURCE: () => an,
|
|
81
|
+
SPLAT_MAX: () => Bt,
|
|
82
|
+
SPLAT_SCALE: () => zt,
|
|
83
|
+
STRATEGY: () => $t,
|
|
84
|
+
STRATEGY_ALONE: () => 8,
|
|
85
|
+
emitterAreaPdf: () => nn,
|
|
86
|
+
emitterSideProbability: () => tn,
|
|
87
|
+
facingSide: () => dn,
|
|
88
|
+
lampSource: () => sn,
|
|
89
|
+
lightEndCosine: () => fn,
|
|
90
|
+
lightPathPixel: () => Ut,
|
|
91
|
+
mergeEta: () => Yt,
|
|
92
|
+
mergeRadiusAt: () => Jt,
|
|
93
|
+
mergeVmAt: () => Xt,
|
|
94
|
+
mis: () => Q,
|
|
95
|
+
misMergePartial: () => Zt,
|
|
96
|
+
misOnHit: () => Wt,
|
|
97
|
+
misOnScatter: () => Kt,
|
|
98
|
+
misOnSpecular: () => Gt,
|
|
99
|
+
misPartial: () => qt,
|
|
100
|
+
misWeight: () => Qt,
|
|
101
|
+
resolveSurfaceMaterial: () => un,
|
|
102
|
+
sourceLampIndex: () => ln,
|
|
103
|
+
sourceLampType: () => cn,
|
|
104
|
+
sourcePick: () => on,
|
|
105
|
+
strategyWeight: () => en,
|
|
106
|
+
sunEmissionPdf: () => rn
|
|
107
|
+
}), X = I + 2048, Rt = 65536, zt = 16384, Bt = 4096, Vt = 2147483648, Ht = 1e30, Z = (e) => K(e.equal(e), e, U(0)).clamp(0, Ht), Ut = (e, t) => {
|
|
108
|
+
let n = q(t.x);
|
|
109
|
+
return _t(U(q(e).mod(n)).add(.5), U(q(e).div(n).add(q(Rt))).add(.5));
|
|
110
|
+
}, Q = (e) => e.mul(e), Wt = (e, t, n) => {
|
|
111
|
+
let r = G(n, 1e-6);
|
|
112
|
+
e.dVCM.assign(Z(e.dVCM.mul(Q(t.mul(t).div(r))))), e.dVC.assign(Z(e.dVC.div(Q(r))));
|
|
113
|
+
}, Gt = (e, t) => {
|
|
114
|
+
e.dVC.assign(Z(e.dVC.mul(Q(t)))), e.dVCM.assign(0);
|
|
115
|
+
}, Kt = (e, t, n, r) => {
|
|
116
|
+
let i = G(n, 1e-12), a = e.dVC.mul(Q(r)).add(e.dVCM);
|
|
117
|
+
e.dVC.assign(Z(Q(t.div(i)).mul(Z(e.vm ? a.add(e.vm) : a)))), e.dVCM.assign(Z(Q(U(1).div(i))));
|
|
118
|
+
}, qt = (e, t, n) => {
|
|
119
|
+
let r = t.dVCM.add(t.dVC.mul(Q(n)));
|
|
120
|
+
return Z(Z(Q(e)).mul(Z(t.vm ? r.add(t.vm) : r)));
|
|
121
|
+
}, Jt = (e, t) => G(e.mergeConst.add(e.mergeSlope.mul(at(t.sub(e.cameraPosition)))), e.mergeMin), Yt = (e, t) => t.mul(t).mul(Math.PI).mul(U(e.lightPaths)), Xt = (e, t) => {
|
|
122
|
+
let n = Yt(e, Jt(e, t)).mul(e.mergeTrust);
|
|
123
|
+
return n.mul(n);
|
|
124
|
+
}, Zt = (e, t, n) => Z(Z(e.dVCM.add(e.dVC.mul(Q(t)))).mul(n)), Qt = (e, t) => U(1).div(U(1).add(Z(e)).add(Z(t))), $t = {
|
|
125
|
+
ALL: 0,
|
|
126
|
+
HIT: 1,
|
|
127
|
+
NEE: 2,
|
|
128
|
+
CONNECT: 3,
|
|
129
|
+
LIGHT_TRACE: 4,
|
|
130
|
+
MERGE: 5
|
|
131
|
+
}, en = (e, t, n, r = U(1)) => K(e.equal(q($t.ALL)).or(e.equal(q(t))), n, K(e.equal(q(t + 8)), r, U(0))), tn = (e, t) => K(e.equal(W(2)), U(.5), K(e.equal(W(1)), K(t.lessThan(0), U(1), U(0)), K(t.greaterThan(0), U(1), U(0)))), nn = (e, t, n = 1) => G(H(e, ne), 0).div(G(t, 1e-10)).mul(n), rn = (e, t, n) => e.sunPick.mul(n).div(G(t.y, 1e-30)), an = {
|
|
132
|
+
SUN: 0,
|
|
133
|
+
EMITTERS: 1,
|
|
134
|
+
ENVIRONMENT: 2,
|
|
135
|
+
LAMPS: 3
|
|
136
|
+
}, on = (e, t) => {
|
|
137
|
+
let n = W(t);
|
|
138
|
+
return e.sourceCdf.element(n).sub(K(n.greaterThan(W(0)), e.sourceCdf.element(G(n.sub(W(1)), W(0))), U(0)));
|
|
139
|
+
}, sn = (e, t, n) => K(t.equal(W(0)), W(e.sourceOffsets[0]), K(t.equal(W(1)), W(e.sourceOffsets[1]), K(t.equal(W(2)), W(e.sourceOffsets[2]), W(e.sourceOffsets[3])))).add(n), cn = (e, t) => K(t.lessThan(W(e.sourceOffsets[1])), W(0), K(t.lessThan(W(e.sourceOffsets[2])), W(1), K(t.lessThan(W(e.sourceOffsets[3])), W(2), W(3)))), ln = (e, t, n) => t.sub(K(n.equal(W(0)), W(e.sourceOffsets[0]), K(n.equal(W(1)), W(e.sourceOffsets[1]), K(n.equal(W(2)), W(e.sourceOffsets[2]), W(e.sourceOffsets[3])))));
|
|
140
|
+
function un(e, t, n, r) {
|
|
141
|
+
let a = re.wrap(le(W(e), r)).toVar();
|
|
142
|
+
a.normalMapIndex.assign(W(-1)), a.bumpMapIndex.assign(W(-1)), a.displacementMapIndex.assign(W(-1));
|
|
143
|
+
let o = c.wrap(ve(a, t, n, vt(0))).toVar(), s = o.roughness.toVar();
|
|
144
|
+
a.color.assign(o.albedo), a.metalness.assign(o.metalness.clamp(0, 1)), a.roughness.assign(o.roughness.clamp(te, 1)), a.sheenRoughness.assign(a.sheenRoughness.clamp(.05, 1));
|
|
145
|
+
let l = w({
|
|
146
|
+
uv: t,
|
|
147
|
+
transform: a.albedoTransform
|
|
148
|
+
}).toVar();
|
|
149
|
+
R(a.anisotropyMapIndex.greaterThanEqual(W(0)), () => {
|
|
150
|
+
let e = E(a, l).toVar();
|
|
151
|
+
a.anisotropy.assign(e.x), a.anisotropyRotation.assign(e.y);
|
|
152
|
+
});
|
|
153
|
+
let u = i.wrap(pe(a, l)).toVar();
|
|
154
|
+
return a.transmission.assign(u.transmission), a.clearcoat.assign(u.clearcoat), a.clearcoatRoughness.assign(u.clearcoatRoughness), a.sheenColor.assign(u.sheenColor), a.sheenRoughness.assign(u.sheenRoughness), a.iridescence.assign(u.iridescence), a.iridescenceThicknessRange.assign(_t(a.iridescenceThicknessRange.x, u.iridescenceThickness)), a.specularIntensity.assign(u.specularIntensity), a.specularColor.assign(u.specularColor), a.diffuseTransmission.assign(u.diffuseTransmission), a.diffuseTransmissionColor.assign(u.diffuseTransmissionColor), R(s.lessThan(te).and(a.anisotropy.equal(0)).and(a.clearcoat.equal(0)).and(a.transmission.equal(0)).and(a.subsurface.equal(0)), () => {
|
|
155
|
+
a.roughness.assign(0);
|
|
156
|
+
}), a;
|
|
157
|
+
}
|
|
158
|
+
var dn = (e, t, n) => K(n.diffuseTransmission.greaterThan(0).and(H(e, t).lessThan(0)), e.negate(), e), fn = (e, t, n, r) => B(H(e, t)).mul(B(H(r, n))).div(G(B(H(e, n)), 1e-4)), pn = 4096, mn = pn + 1, hn = Math.ceil(mn * 4 / 256) * 64, gn = .2, _n = (e) => {
|
|
159
|
+
let t = ut($e(K(B(e.x).greaterThan(.9), Y(0, 1, 0), Y(1, 0, 0)), e)).toVar();
|
|
160
|
+
return {
|
|
161
|
+
u: t,
|
|
162
|
+
v: $e(e, t).toVar()
|
|
163
|
+
};
|
|
164
|
+
}, vn = (e) => {
|
|
165
|
+
let t = e.div(G(B(e.x).add(B(e.y)).add(B(e.z)), 1e-20)).toVar(), n = _t(t.x, t.z).toVar();
|
|
166
|
+
R(t.y.lessThan(0), () => {
|
|
167
|
+
n.assign(_t(U(1).sub(B(t.z)).mul(K(t.x.greaterThanEqual(0), 1, -1)), U(1).sub(B(t.x)).mul(K(t.z.greaterThanEqual(0), 1, -1))));
|
|
168
|
+
});
|
|
169
|
+
let r = tt(n.mul(.5).add(.5).mul(4)).clamp(0, 3);
|
|
170
|
+
return W(r.y).mul(4).add(W(r.x));
|
|
171
|
+
}, yn = (e, t, n) => {
|
|
172
|
+
let { u: r, v: i } = _n(t), a = n.sub(e.sceneCenter);
|
|
173
|
+
return _t(H(a, r), H(a, i)).div(e.sceneRadius);
|
|
174
|
+
}, bn = (e) => {
|
|
175
|
+
let t = e.mul(.5).add(.5).mul(64).toVar();
|
|
176
|
+
return K(t.x.greaterThanEqual(0).and(t.y.greaterThanEqual(0)).and(t.x.lessThan(64)).and(t.y.lessThan(64)), W(t.y).mul(64).add(W(t.x)), W(-1));
|
|
177
|
+
}, xn = (e, t, n) => e.guide.greaterThan(q(0)).and(t.load(rt(W(pn), n)).x.greaterThan(0)), Sn = (e, t, n, r) => {
|
|
178
|
+
let i = yn(e, n, r).toVar(), a = e.sceneRadius.mul(e.sceneRadius).toVar(), o = K(H(i, i).lessThanEqual(1), U(1).div(G(a.mul(Math.PI), 1e-30)), U(0)).toVar(), s = vn(n).toVar(), c = bn(i).toVar(), l = (e) => t.load(rt(G(e, W(0)), s)).x, u = K(c.greaterThanEqual(W(0)), l(c).sub(K(c.greaterThan(W(0)), l(c.sub(W(1))), U(0))), U(0)).mul(pn / 4).div(G(a, 1e-30));
|
|
179
|
+
return K(xn(e, t, s), lt(u, o, gn), o);
|
|
180
|
+
}, Cn = (e, t, n, r, i) => {
|
|
181
|
+
let { u: a, v: o } = _n(n), s = _t(0).toVar(), c = vn(n).toVar();
|
|
182
|
+
return R(xn(e, t, c).and(r.lessThan(1 - gn)), () => {
|
|
183
|
+
let e = r.div(1 - gn).toVar(), n = W(0).toVar(), a = W(pn - 1).toVar();
|
|
184
|
+
qe(n.lessThan(a), () => {
|
|
185
|
+
let r = n.add(a).div(2).toVar();
|
|
186
|
+
R(t.load(rt(r, c)).x.lessThanEqual(e), () => {
|
|
187
|
+
n.assign(r.add(1));
|
|
188
|
+
}).Else(() => {
|
|
189
|
+
a.assign(r);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
let o = _t(U(n.mod(W(64))), U(n.div(W(64))));
|
|
193
|
+
s.assign(o.add(i).div(64).mul(2).sub(1));
|
|
194
|
+
}).Else(() => {
|
|
195
|
+
let e = pt(i.x), t = i.y.mul(2 * Math.PI);
|
|
196
|
+
s.assign(_t(e.mul(Qe(t)), e.mul(ft(t))));
|
|
197
|
+
}), e.sceneCenter.add(n.mul(e.sceneRadius)).add(a.mul(s.x).add(o.mul(s.y)).mul(e.sceneRadius));
|
|
198
|
+
}, wn = (e, t, n, r) => {
|
|
199
|
+
let i = bn(yn(t, n, r)).toVar();
|
|
200
|
+
R(t.guideLearning.greaterThan(q(0)).and(i.greaterThanEqual(W(0))), () => {
|
|
201
|
+
Je(e.element(q(Fe.GUIDE).add(q(vn(n).mul(W(pn)).add(i)))), q(1));
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
function Tn({ counters: e, out: t }) {
|
|
205
|
+
return L(() => {
|
|
206
|
+
let n = nt;
|
|
207
|
+
R(n.greaterThanEqual(q(16)), () => {
|
|
208
|
+
z();
|
|
209
|
+
});
|
|
210
|
+
let r = q(Fe.GUIDE).add(n.mul(q(pn))).toVar(), i = U(0).toVar();
|
|
211
|
+
qe({
|
|
212
|
+
start: W(0),
|
|
213
|
+
end: W(pn),
|
|
214
|
+
type: "int",
|
|
215
|
+
condition: "<"
|
|
216
|
+
}, ({ i: t }) => {
|
|
217
|
+
i.addAssign(U(V(e.element(r.add(q(t))))));
|
|
218
|
+
});
|
|
219
|
+
let a = n.mul(q(hn)).toVar(), o = U(0).toVar();
|
|
220
|
+
qe({
|
|
221
|
+
start: W(0),
|
|
222
|
+
end: W(pn),
|
|
223
|
+
type: "int",
|
|
224
|
+
condition: "<"
|
|
225
|
+
}, ({ i: n }) => {
|
|
226
|
+
o.addAssign(U(V(e.element(r.add(q(n)))))), t.element(a.add(q(n))).assign(K(i.greaterThan(0), K(n.equal(W(pn - 1)), U(1), o.div(i)), U(0)));
|
|
227
|
+
}), t.element(a.add(q(pn))).assign(i);
|
|
228
|
+
})().compute(16, [16]);
|
|
229
|
+
}
|
|
230
|
+
function En({ counters: e }) {
|
|
231
|
+
return L(() => {
|
|
232
|
+
R(nt.lessThan(q(M)), () => {
|
|
233
|
+
Xe(e.element(q(Fe.GUIDE).add(nt)), q(0));
|
|
234
|
+
});
|
|
235
|
+
})().compute(M, [256]);
|
|
236
|
+
}
|
|
237
|
+
//#endregion
|
|
238
|
+
//#region src/TSL/LightGenerateKernel.js
|
|
239
|
+
function Dn(e) {
|
|
240
|
+
let { rayBufferRW: t, hitBufferRW: n, activeIndicesRW: i, counters: o, lightBuffer: c, triangleBuffer: l, bvhBuffer: m, emissiveTriangleCount: ee, emissiveVec4Offset: te, emissiveTotalPower: ne, emissiveBoost: re, sunDirection: h, sunRadiance: g, sunParams: _, environmentIntensity: ie, envTexture: ae, envCDFTexture: oe, envMatrix: se, envResolution: v, directionalLightsBuffer: ce, areaLightsBuffer: le, pointLightsBuffer: ue, spotLightsBuffer: b, bidirectional: w, resolution: E, frame: D, transmissiveBounces: pe } = e, { lightPaths: ve } = w;
|
|
241
|
+
return L(() => {
|
|
242
|
+
let e = nt;
|
|
243
|
+
R(e.equal(q(0)), () => {
|
|
244
|
+
Xe(o.element(q(Fe.ACTIVE_RAY_COUNT)), ve), Xe(o.element(q(Fe.ENTERING_COUNT)), ve);
|
|
245
|
+
}), R(e.greaterThanEqual(ve), () => {
|
|
246
|
+
z();
|
|
247
|
+
}), i.element(e).assign(e);
|
|
248
|
+
let k = Ut(e, E).toVar(), j = fe({ state: Ce({
|
|
249
|
+
pixelCoord: k,
|
|
250
|
+
rayIndex: W(3),
|
|
251
|
+
frame: D
|
|
252
|
+
}) }).toVar(), De = Y(0).toVar(), M = Y(0, 1, 0).toVar(), N = Y(0).toVar(), P = U(0).toVar(), Me = U(0).toVar(), Ne = W(-1).toVar(), Ie = W(0).toVar(), Le = U(1).toVar(), F = Ze(!1).toVar(), ze = He(k, W(0), W(X + 4), j, E, D).toVar(), I = W(0).toVar(), We = W(w.sourceCount - 1).toVar();
|
|
253
|
+
qe(I.lessThan(We), () => {
|
|
254
|
+
let e = I.add(We).div(2).toVar();
|
|
255
|
+
R(w.sourceCdf.element(e).lessThanEqual(ze), () => {
|
|
256
|
+
I.assign(e.add(1));
|
|
257
|
+
}).Else(() => {
|
|
258
|
+
We.assign(e);
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
let Ge = w.guideTexture, Ke = (e) => {
|
|
262
|
+
let t = Cn(w, Ge, e, He(k, W(0), W(X + 7), j, E, D), O(k, W(0), W(X + 6), j, E, D)).toVar();
|
|
263
|
+
return {
|
|
264
|
+
start: t,
|
|
265
|
+
pdf: Sn(w, Ge, e, t)
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
R(I.equal(W(an.SUN)), () => {
|
|
269
|
+
let e = Te(h, _, O(k, W(0), W(X + 5), j, E, D)).toVar(), t = Ee(e, h, g, _).mul(ie).toVar(), n = Ke(e), r = rn(w, _, n.pdf).toVar();
|
|
270
|
+
R(t.x.add(t.y).add(t.z).greaterThan(0).and(r.greaterThan(0)), () => {
|
|
271
|
+
De.assign(n.start), M.assign(e.negate()), N.assign(t.div(r)), P.assign(Q(U(1).div(_.y.mul(r)))), Me.assign(Q(U(1).div(r))), F.assign(!0);
|
|
272
|
+
});
|
|
273
|
+
}).ElseIf(I.equal(W(an.EMITTERS)), () => {
|
|
274
|
+
let e = Oe(c, te, ee, He(k, W(0), W(X), j, E, D)).toVar(), t = te.add(e.mul(W(2))), n = c.element(t).toVar(), r = c.element(t.add(W(1))).toVar();
|
|
275
|
+
Ne.assign(W(n.x)), Ie.assign(W(n.w));
|
|
276
|
+
let i = Pe.wrap(xe(Ne, l, m, Ie)).toVar(), a = je(i.v0, i.v1, i.v2, O(k, W(0), W(X + 1), j, E, D)).toVar(), o = ut($e(i.v1.sub(i.v0), i.v2.sub(i.v0))).toVar(), u = be(de(l, Ne, 4).z).toVar(), d = K(u.equal(W(1)).or(u.equal(W(2)).and(He(k, W(0), W(X + 3), j, E, D).lessThan(.5))).toVar(), o.negate(), o).toVar();
|
|
277
|
+
M.assign(_e(d, O(k, W(0), W(X + 2), j, E, D)));
|
|
278
|
+
let f = H(M, d).toVar(), p = G(n.y, 0).div(G(ne, 1e-10)).div(G(r.w, 1e-20)).mul(K(u.equal(W(2)), U(.5), U(1))).mul(w.emitterPick).toVar(), h = p.mul(f).div(Math.PI).toVar();
|
|
279
|
+
R(f.greaterThan(1e-6).and(h.greaterThan(0)), () => {
|
|
280
|
+
De.assign(s(a, d)), N.assign(r.xyz.mul(re).mul(Math.PI).div(p)), P.assign(Q(U(1).div(h))), Me.assign(Q(f.div(h))), Le.assign(f), F.assign(!0);
|
|
281
|
+
});
|
|
282
|
+
}).ElseIf(I.equal(W(an.ENVIRONMENT)), () => {
|
|
283
|
+
let e = T(oe, se, v, O(k, W(0), W(X + 5), j, E, D)), t = e.direction.toVar(), n = e.pdf.toVar(), r = ye({
|
|
284
|
+
tex: ae,
|
|
285
|
+
samp: dt(ae),
|
|
286
|
+
direction: t,
|
|
287
|
+
environmentMatrix: se,
|
|
288
|
+
environmentIntensity: ie,
|
|
289
|
+
enableEnvironmentLight: U(1)
|
|
290
|
+
}).xyz.toVar(), i = Ke(t), a = w.envPick.mul(n).mul(i.pdf).toVar();
|
|
291
|
+
R(r.x.add(r.y).add(r.z).greaterThan(0).and(a.greaterThan(0)), () => {
|
|
292
|
+
De.assign(i.start), M.assign(t.negate()), N.assign(r.div(a)), P.assign(Q(n.div(a))), Me.assign(Q(U(1).div(a))), Ne.assign(W(-1 - an.ENVIRONMENT)), F.assign(!0);
|
|
293
|
+
});
|
|
294
|
+
}).ElseIf(I.greaterThanEqual(W(an.LAMPS)), () => {
|
|
295
|
+
let e = on(w, I).toVar(), t = cn(w, I).toVar(), n = ln(w, I, t).toVar();
|
|
296
|
+
Ne.assign(W(-1).sub(I));
|
|
297
|
+
let r = U(0).toVar(), i = Y(0).toVar(), a = O(k, W(0), W(X + 2), j, E, D).toVar();
|
|
298
|
+
R(t.equal(W(0)), () => {
|
|
299
|
+
let t = Ue.wrap(x(ce, n)), a = ut(t.direction).toVar();
|
|
300
|
+
i.assign(t.color.mul(t.intensity)), r.assign(e), R(t.angle.greaterThan(0), () => {
|
|
301
|
+
let e = Ft(t).toVar();
|
|
302
|
+
a.assign(S(a, t.angle.mul(.5), O(k, W(0), W(X + 5), j, E, D))), i.divAssign(e), r.divAssign(e);
|
|
303
|
+
});
|
|
304
|
+
let o = Ke(a);
|
|
305
|
+
r.mulAssign(o.pdf), De.assign(o.start), M.assign(a.negate());
|
|
306
|
+
}).ElseIf(t.equal(W(1)), () => {
|
|
307
|
+
let t = Re.wrap(he(le, n)), o = t.shape.greaterThan(.5), s = O(k, W(0), W(X + 1), j, E, D).toVar(), c = pt(s.x), l = s.y.mul(2 * Math.PI);
|
|
308
|
+
De.assign(t.position.add(t.u.mul(K(o, c.mul(Qe(l)), s.x.mul(2).sub(1)))).add(t.v.mul(K(o, c.mul(ft(l)), s.y.mul(2).sub(1))))), M.assign(_e(t.normal, a));
|
|
309
|
+
let u = H(M, t.normal).toVar();
|
|
310
|
+
i.assign(K(t.area.greaterThan(0).and(u.greaterThan(1e-6)), we(t).mul(Ae(u, t.spread)).mul(u), Y(0))), r.assign(e.div(G(t.area, 1e-20)).mul(u).div(Math.PI)), Me.assign(Q(u.div(G(r, 1e-30))));
|
|
311
|
+
}).ElseIf(t.equal(W(2)), () => {
|
|
312
|
+
let t = Se.wrap(Be(ue, n));
|
|
313
|
+
De.assign(t.position), M.assign(S(Y(0, 1, 0), U(Math.PI), a)), i.assign(t.color.mul(t.intensity)), r.assign(e.div(4 * Math.PI));
|
|
314
|
+
}).Else(() => {
|
|
315
|
+
let t = Ve.wrap(C(b, n));
|
|
316
|
+
De.assign(t.position), M.assign(S(t.direction, t.angle, a));
|
|
317
|
+
let o = M.negate();
|
|
318
|
+
i.assign(t.color.mul(t.intensity).mul(ge({
|
|
319
|
+
coneCosine: Qe(t.angle),
|
|
320
|
+
blend: t.penumbra,
|
|
321
|
+
angleCosine: H(M, t.direction)
|
|
322
|
+
})).mul(ke(t, o)).mul(me(t, o))), r.assign(e.div(Pt(t)));
|
|
323
|
+
}), R(i.x.add(i.y).add(i.z).greaterThan(0).and(r.greaterThan(0)), () => {
|
|
324
|
+
N.assign(i.div(r)), P.assign(Q(U(1).div(r))), F.assign(!0);
|
|
325
|
+
});
|
|
326
|
+
}), R(F.not(), () => {
|
|
327
|
+
y(t, e, M, q(0)), z();
|
|
328
|
+
});
|
|
329
|
+
let L = G(G(G(N.x, N.y), N.z), 1e-20).toVar();
|
|
330
|
+
r(t, e, De, W(0), W(0)), y(t, e, M, q(A.ACTIVE | A.REDIRECTED | A.LIGHT_PATH | A.LIGHT_EMITTED)), d(t, e, N.div(L), U(0)), f(t, e, vt(Y(0), U(1))), a(t, e, q(0), q(pe), U(1), U(1), U(1)), p(n, e, j, P, Me), u(n, e, Ne, Ie, Le, L);
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
//#endregion
|
|
334
|
+
//#region src/TSL/ConnectKernel.js
|
|
335
|
+
function On(e) {
|
|
336
|
+
let { rayBufferRW: t, hitBufferRO: n, activeIndicesRO: r, counters: i, bvhBuffer: a, triangleBuffer: c, materialBuffer: u, resolution: d, frame: p, accumFrame: m, currentBounce: te, chunkRowBase: ne, lightPaths: re, slotsPerPath: h, lightTag: _, passTag: ie, strategyView: v, maxBounceCount: y, globalIlluminationIntensity: le, fireflyThreshold: de, mergeVm: b = null, diffuseTransmission: x = !0 } = e;
|
|
337
|
+
return L(() => {
|
|
338
|
+
let e = nt;
|
|
339
|
+
R(e.greaterThanEqual(V(i.element(q(Fe.ENTERING_COUNT)))), () => {
|
|
340
|
+
z();
|
|
341
|
+
});
|
|
342
|
+
let S = r.element(e).toVar(), C = ee(S);
|
|
343
|
+
R(l(n, C).notEqual(ie), () => {
|
|
344
|
+
z();
|
|
345
|
+
});
|
|
346
|
+
let w = o(n, C), T = {
|
|
347
|
+
...w,
|
|
348
|
+
vm: b?.(w.position) ?? null
|
|
349
|
+
}, E = W(T.extra).add(W(1)).toVar(), D = W(d.x), pe = W(S).add(ne.mul(D)), me = _t(U(pe.mod(D)).add(.5), U(pe.div(D)).add(.5)).toVar(), he = W(te).mul(W(32)), O = fe({ state: ae(n, S).bitXor(q(2654435769)) }).toVar(), ge = He(me, W(0), he.add(W(16)), O, d, p).toVar(), _e = He(me, W(0), he.add(W(17)), O, d, p).toVar(), ve = ct(q(U(re).mul(ge)), re.sub(q(1))).toVar().mul(h).toVar(), ye = ct(W(ue(n, ce(ve), _)), W(y).add(W(1)).sub(E)).toVar();
|
|
350
|
+
R(ye.lessThan(W(1)), () => {
|
|
351
|
+
z();
|
|
352
|
+
});
|
|
353
|
+
let be = ct(W(U(ye).mul(_e)), ye.sub(W(1))).toVar(), xe = o(n, ce(ve.add(q(be)))), A = {
|
|
354
|
+
...xe,
|
|
355
|
+
vm: b?.(xe.position) ?? null
|
|
356
|
+
}, Se = A.position.sub(T.position).toVar(), Ce = G(H(Se, Se), 1e-12).toVar(), we = Se.div(pt(Ce)).toVar(), Te = H(we, T.N).toVar(), Ee = H(we, T.facetN).toVar(), j = H(we, A.facetN).negate().toVar(), De = Te.greaterThan(0).and(Ee.greaterThan(0)).and(j.greaterThan(0)), Oe = Te.lessThan(0).and(Ee.lessThan(0)), M = j.lessThan(0);
|
|
357
|
+
R((x ? Oe.or(Te.greaterThan(0).and(Ee.greaterThan(0))).and(M.or(j.greaterThan(0))) : De).not(), () => {
|
|
358
|
+
z();
|
|
359
|
+
});
|
|
360
|
+
let ke = un(T.materialIndex, T.uv, T.N, u), Ae = un(A.materialIndex, A.uv, A.N, u), P = we.negate();
|
|
361
|
+
x && R(Oe.and(ke.diffuseTransmission.lessThanEqual(0)).or(M.and(Ae.diffuseTransmission.lessThanEqual(0))), () => {
|
|
362
|
+
z();
|
|
363
|
+
});
|
|
364
|
+
let je = (e) => x ? dn(T.N, e, ke) : T.N, Me = (e) => x ? dn(A.N, e, Ae) : A.N, Pe = N(T.V, we, T.N, ke).toVar(), Le = N(P, A.V, Me(P), Ae).toVar(), Re = (x ? B(Te) : Te).mul(fn(A.V, A.N, A.facetN, P)).div(Ce), ze = F(T.V, we, T.N, ke), Be = F(we, T.V, je(we), ke), Ve = F(A.V, P, A.N, Ae), Ue = F(P, A.V, Me(P), Ae), I = qt(ze.mul(x ? B(j) : j).div(Ce), A, Ue), We = qt(Ve.mul(x ? B(Ee) : Ee).div(Ce), T, Be), Ge = E.add(be).add(W(1)), Ke = en(v, $t.CONNECT, Qt(I, We), U(1).div(U(Ge.sub(W(1))))), L = Ie(T.throughput.mul(Pe).mul(Le).mul(A.throughput).mul(Re.mul(Ke).mul(U(ye)).mul(le)), U(Ge.sub(W(1))), de, W(m)).toVar();
|
|
365
|
+
R(oe(L).greaterThan(0), () => {
|
|
366
|
+
let e = s(T.position, x ? K(Oe, T.facetN.negate(), T.facetN) : T.facetN).toVar(), n = s(A.position, x ? K(M, A.facetN.negate(), A.facetN) : A.facetN).sub(e).toVar(), r = at(n).toVar(), i = k(e, n.div(r), r.mul(g), Ne, a, c, u);
|
|
367
|
+
R(i.greaterThan(0), () => {
|
|
368
|
+
let e = se(t, S).toVar();
|
|
369
|
+
f(t, S, vt(e.xyz.add(L.mul(i)), e.w));
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
var kn = 4294967295, An = 1024, jn = Math.log2(1.25), Mn = (e, t) => W(G(tt(st(t.div(e.mergeMin)).div(jn)), 0)), Nn = (e, t) => e.mergeMin.mul(et(U(t.add(W(1))).mul(jn))).mul(2).div(G(U(1).sub(e.mergeSlope), .5)), Pn = (e, t, n) => q(t.x).mul(q(73856093)).bitXor(q(t.y).mul(q(19349663))).bitXor(q(t.z).mul(q(83492791))).bitXor(q(e).mul(q(2654435761))).bitAnd(n), Fn = (e, t) => {
|
|
375
|
+
let n = Mn(e, Jt(e, t)).toVar();
|
|
376
|
+
return {
|
|
377
|
+
shell: n,
|
|
378
|
+
cell: it(tt(t.div(Nn(e, n)))).toVar()
|
|
379
|
+
};
|
|
380
|
+
};
|
|
381
|
+
function In({ head: e, hashSize: t }) {
|
|
382
|
+
return L(() => {
|
|
383
|
+
R(nt.lessThan(q(t)), () => {
|
|
384
|
+
Xe(e.element(nt), q(kn));
|
|
385
|
+
});
|
|
386
|
+
})().compute(Math.ceil(t / 256) * 256, [256]);
|
|
387
|
+
}
|
|
388
|
+
function Ln({ hitBufferRW: e, head: t, bidirectional: r }) {
|
|
389
|
+
let { lightPaths: i, slotsPerPath: a, lightTag: o, hashMask: s } = r;
|
|
390
|
+
return L(() => {
|
|
391
|
+
let c = nt.toVar();
|
|
392
|
+
R(c.greaterThanEqual(i.mul(a)), () => {
|
|
393
|
+
z();
|
|
394
|
+
});
|
|
395
|
+
let l = c.mod(a).toVar();
|
|
396
|
+
R(l.greaterThanEqual(ue(e, ce(c.sub(l)), o)), () => {
|
|
397
|
+
z();
|
|
398
|
+
});
|
|
399
|
+
let u = ce(c), { shell: d, cell: f } = Fn(r, n(e, u)), p = Pn(d, f, s);
|
|
400
|
+
h(e, u, Ye("atomicExchange", t.element(p), c));
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
function Rn(t) {
|
|
404
|
+
let { rayBufferRW: r, hitBufferRO: i, activeIndicesRO: a, counters: s, head: c, materialBuffer: u, bidirectional: d, maxBounceCount: p, globalIlluminationIntensity: m, fireflyThreshold: te, accumFrame: ne, diffuseTransmission: re = !0 } = t, { passTag: h, slotsPerPath: g, strategyView: _, hashMask: ie } = d;
|
|
405
|
+
return L(() => {
|
|
406
|
+
let t = nt;
|
|
407
|
+
R(t.greaterThanEqual(V(s.element(q(Fe.ENTERING_COUNT)))), () => {
|
|
408
|
+
z();
|
|
409
|
+
});
|
|
410
|
+
let ae = a.element(t).toVar(), v = ee(ae);
|
|
411
|
+
R(l(i, v).notEqual(h), () => {
|
|
412
|
+
z();
|
|
413
|
+
});
|
|
414
|
+
let y = o(i, v), le = W(y.extra).toVar(), ue = W(p).add(W(1)).sub(le).toVar(), de = un(y.materialIndex, y.uv, y.N, u), b = Y(0).toVar(), x = Jt(d, y.position).toVar(), fe = x.mul(x).toVar(), S = Yt(d, x).toVar(), C = S.mul(d.mergeTrust), w = U(1).div(G(C.mul(C), 1e-30)).toVar(), T = at(y.position.sub(d.cameraPosition)).toVar(), E = Mn(d, G(d.mergeConst.add(d.mergeSlope.mul(G(T.sub(x), 0))), d.mergeMin)).toVar(), D = ct(Mn(d, d.mergeConst.add(d.mergeSlope.mul(T.add(x)))), E.add(W(1))).toVar();
|
|
415
|
+
qe({
|
|
416
|
+
start: W(0),
|
|
417
|
+
end: W(16),
|
|
418
|
+
type: "int",
|
|
419
|
+
condition: "<"
|
|
420
|
+
}, ({ i: t }) => {
|
|
421
|
+
let r = E.add(t.shiftRight(W(3))).toVar();
|
|
422
|
+
R(r.greaterThan(D), () => {
|
|
423
|
+
Ke();
|
|
424
|
+
});
|
|
425
|
+
let a = Nn(d, r).toVar(), s = t.bitAnd(W(7)), l = it(tt(y.position.div(a).sub(.5))).add(it(s.bitAnd(W(1)), s.shiftRight(W(1)).bitAnd(W(1)), s.shiftRight(W(2)))).toVar(), u = V(c.element(Pn(r, l, ie))).toVar(), f = W(0).toVar();
|
|
426
|
+
qe(u.notEqual(q(kn)).and(f.lessThan(W(An))), () => {
|
|
427
|
+
let t = ce(u), a = n(i, t).toVar(), s = a.sub(y.position), c = W(u.mod(g)).add(W(1)).toVar();
|
|
428
|
+
R(H(s, s).lessThan(fe).and(c.lessThanEqual(ue)), () => {
|
|
429
|
+
let e = Fn(d, a);
|
|
430
|
+
R(e.shell.equal(r).and(e.cell.x.equal(l.x)).and(e.cell.y.equal(l.y)).and(e.cell.z.equal(l.z)), () => {
|
|
431
|
+
let e = o(i, t), n = H(e.V, y.N).toVar(), r = H(e.V, y.facetN).toVar(), a = n.greaterThan(0).and(r.greaterThan(0)), s = de.diffuseTransmission.greaterThan(0).and(n.lessThan(0)).and(r.lessThan(0));
|
|
432
|
+
R(re ? a.or(s) : a, () => {
|
|
433
|
+
let t = N(y.V, e.V, y.N, de), i = Zt(e, F(y.V, e.V, y.N, de), w), a = re ? dn(y.N, e.V, de) : y.N, o = Zt(y, F(e.V, y.V, a, de), w), s = le.add(c), l = en(_, $t.MERGE, Qt(i, o), U(1).div(U(s))), u = K(s.greaterThan(W(1)), m, U(1)), d = re ? B(n).div(G(B(r), 1e-4)) : n.div(G(r, 1e-4));
|
|
434
|
+
b.addAssign(Ie(y.throughput.mul(t).mul(e.throughput).mul(l.mul(d).div(S).mul(u)), U(s.sub(W(1))), te, W(ne)));
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
}), u.assign(e(i, t)), f.addAssign(W(1));
|
|
438
|
+
});
|
|
439
|
+
}), R(oe(b).greaterThan(0), () => {
|
|
440
|
+
let e = se(r, ae).toVar();
|
|
441
|
+
f(r, ae, vt(e.xyz.add(b), e.w));
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
function zn(e) {
|
|
446
|
+
let { hitBufferRO: n, splatBuffer: r, bvhBuffer: i, triangleBuffer: a, materialBuffer: c, lightPaths: l, slotsPerPath: u, lightTag: d, strategyView: f, cameraPosition: p, cameraForward: m, cameraViewMatrix: ee, cameraProjectionMatrix: te, pixelArea: ne, renderWidth: re, renderHeight: h, globalIlluminationIntensity: _, fireflyThreshold: ie, accumFrame: ae, frame: oe, mergeVm: se = null, diffuseTransmission: v = !0 } = e;
|
|
447
|
+
return L(() => {
|
|
448
|
+
let e = nt.toVar();
|
|
449
|
+
R(e.greaterThanEqual(l.mul(u)), () => {
|
|
450
|
+
z();
|
|
451
|
+
});
|
|
452
|
+
let y = e.mod(u).toVar(), le = ue(n, ce(e.sub(y)), d);
|
|
453
|
+
R(y.greaterThanEqual(le), () => {
|
|
454
|
+
z();
|
|
455
|
+
});
|
|
456
|
+
let de = o(n, ce(e)), b = {
|
|
457
|
+
...de,
|
|
458
|
+
vm: se?.(de.position) ?? null
|
|
459
|
+
}, x = p.sub(b.position).toVar(), S = G(H(x, x), 1e-12).toVar(), C = x.div(pt(S)).toVar(), w = H(C, b.facetN).toVar(), T = H(C, m).negate().toVar(), E = w.lessThan(0), pe = v ? K(E, b.extra.bitAnd(q(2)), b.extra.bitAnd(q(1))).notEqual(q(0)) : b.extra.notEqual(q(0));
|
|
460
|
+
R((v ? w.equal(0) : w.lessThanEqual(0)).or(T.lessThanEqual(1e-6)).or(pe), () => {
|
|
461
|
+
z();
|
|
462
|
+
});
|
|
463
|
+
let me = te.mul(ee.mul(vt(b.position, 1))).toVar();
|
|
464
|
+
R(me.w.lessThanEqual(0), () => {
|
|
465
|
+
z();
|
|
466
|
+
});
|
|
467
|
+
let he = tt(me.x.div(me.w).mul(.5).add(.5).mul(U(re))).toVar(), O = tt(U(.5).sub(me.y.div(me.w).mul(.5)).mul(U(h))).toVar();
|
|
468
|
+
R(he.lessThan(0).or(O.lessThan(0)).or(he.greaterThanEqual(U(re))).or(O.greaterThanEqual(U(h))), () => {
|
|
469
|
+
z();
|
|
470
|
+
});
|
|
471
|
+
let ge = un(b.materialIndex, b.uv, b.N, c);
|
|
472
|
+
v && R(E.and(ge.diffuseTransmission.lessThanEqual(0)), () => {
|
|
473
|
+
z();
|
|
474
|
+
});
|
|
475
|
+
let _e = v ? dn(b.N, C, ge) : b.N, ve = N(C, b.V, _e, ge).toVar(), ye = U(1).div(ne.mul(T).mul(T).mul(T)).div(S).toVar(), be = qt(ye.mul(v ? B(w) : w).div(U(l)), b, F(C, b.V, _e, ge)), xe = y.add(q(1)), A = U(1).toVar();
|
|
476
|
+
R(xe.greaterThan(q(1)), () => {
|
|
477
|
+
A.assign(_);
|
|
478
|
+
});
|
|
479
|
+
let Se = Ie(b.throughput.mul(ve).mul(fn(b.V, b.N, b.facetN, C)).mul(ye.div(U(l)).mul(en(f, $t.LIGHT_TRACE, Qt(be, U(0)))).mul(A)), U(y), ie, W(ae)).toVar(), Ce = s(b.position, v ? K(E, b.facetN.negate(), b.facetN) : b.facetN).toVar(), we = p.sub(Ce).toVar(), Te = at(we).toVar(), Ee = k(Ce, we.div(Te), Te.mul(g), D, i, a, c);
|
|
480
|
+
R(Ee.greaterThan(0), () => {
|
|
481
|
+
let n = ct(t(Se.mul(Ee)), Y(Bt)).mul(zt).toVar(), i = U(fe({ state: e.bitXor(q(oe).mul(q(2654435769))) }).shiftRight(q(8))).mul(1 / 16777216).toVar(), a = q(O).mul(q(re)).add(q(he)).mul(q(3)).toVar();
|
|
482
|
+
Je(r.element(a), q(tt(n.x.add(i)))), Je(r.element(a.add(q(1))), q(tt(n.y.add(i)))), Je(r.element(a.add(q(2))), q(tt(n.z.add(i))));
|
|
483
|
+
});
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
function Bn(e) {
|
|
487
|
+
let { rayBufferRW: t, splatBuffer: n, renderWidth: r, chunkRowBase: i, chunkRows: a } = e;
|
|
488
|
+
return L(() => {
|
|
489
|
+
let e = W(yt.x).mul(16).add(W(ot.x)), o = W(yt.y).mul(16).add(W(ot.y));
|
|
490
|
+
R(e.lessThan(r).and(o.lessThan(a)), () => {
|
|
491
|
+
let a = q(o.mul(r).add(e)), s = q(o.add(i).mul(r).add(e)).mul(q(3)).toVar(), c = V(n.element(s)).toVar(), l = V(n.element(s.add(q(1)))).toVar(), u = V(n.element(s.add(q(2)))).toVar();
|
|
492
|
+
R(c.bitOr(l).bitOr(u).notEqual(q(0)), () => {
|
|
493
|
+
Xe(n.element(s), q(0)), Xe(n.element(s.add(q(1))), q(0)), Xe(n.element(s.add(q(2))), q(0));
|
|
494
|
+
let e = se(t, a).toVar();
|
|
495
|
+
f(t, a, vt(e.xyz.add(Y(U(c), U(l), U(u)).div(zt)), e.w));
|
|
496
|
+
});
|
|
497
|
+
});
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
//#endregion
|
|
501
|
+
//#region src/integrators/BidirectionalIntegrator.js
|
|
502
|
+
var { PASS_TAG_BIT: Vn, STRATEGY: Hn, STRATEGY_ALONE: Un, SOURCE: $, mergeVmAt: Wn } = Lt, Gn = {
|
|
503
|
+
...Lt,
|
|
504
|
+
...Et,
|
|
505
|
+
guidedDiscPdf: Sn,
|
|
506
|
+
recordEscape: wn
|
|
507
|
+
}, Kn = 256 * 1024 * 1024, qn = .05, Jn = .5, Yn = (1 << 24) - 1, Xn = 1, Zn = .75, Qn = .25, $n = class {
|
|
508
|
+
constructor(e) {
|
|
509
|
+
this.pt = e, this.merging = !1, this._mergeRadiusPixels = Xn, this._mergeHeadAttr = null, this._lightCacheSlots = 0, this._splatAttr = null, this._lightTag = 0, this._passTag = 0, this._lightTraced = !1, this._lastLightBounceCounts = null, this._lastLightBounceEnergy = null, this._lastLightCurveKey = null, this._lightCurveKey = null, this.uniforms = {
|
|
510
|
+
lib: Gn,
|
|
511
|
+
lightPaths: J(0, "uint"),
|
|
512
|
+
slotsPerPath: J(1, "uint"),
|
|
513
|
+
lightTag: J(1, "uint"),
|
|
514
|
+
passTag: J(0, "uint"),
|
|
515
|
+
lightTrace: J(0, "uint"),
|
|
516
|
+
strategyView: J(0, "uint"),
|
|
517
|
+
pixelArea: J(1, "float"),
|
|
518
|
+
cameraPosition: J(new Ct(), "vec3"),
|
|
519
|
+
cameraForward: J(new Ct(0, 0, -1), "vec3"),
|
|
520
|
+
sunPick: J(0, "float"),
|
|
521
|
+
emitterPick: J(0, "float"),
|
|
522
|
+
envPick: J(0, "float"),
|
|
523
|
+
envTable: J(0, "uint"),
|
|
524
|
+
sourceCdf: gt(new Float32Array($.LAMPS), "float"),
|
|
525
|
+
sourceCount: $.LAMPS,
|
|
526
|
+
sourceOffsets: [
|
|
527
|
+
$.LAMPS,
|
|
528
|
+
$.LAMPS,
|
|
529
|
+
$.LAMPS,
|
|
530
|
+
$.LAMPS
|
|
531
|
+
],
|
|
532
|
+
sceneCenter: J(new Ct(), "vec3"),
|
|
533
|
+
sceneRadius: J(1, "float"),
|
|
534
|
+
guide: J(0, "uint"),
|
|
535
|
+
guideLearning: J(1, "uint"),
|
|
536
|
+
guideTexture: null,
|
|
537
|
+
merging: !1,
|
|
538
|
+
mergeConst: J(0, "float"),
|
|
539
|
+
mergeSlope: J(0, "float"),
|
|
540
|
+
mergeMin: J(1, "float"),
|
|
541
|
+
mergeTrust: J(Qn, "float"),
|
|
542
|
+
hashMask: J(0, "uint")
|
|
543
|
+
}, this._lightGuiding = !0, this._guideTexture = null, this._guideBuildAttr = null, this._u32Views = /* @__PURE__ */ new WeakMap();
|
|
544
|
+
}
|
|
545
|
+
get name() {
|
|
546
|
+
return this.merging ? "vcm" : "bidirectional";
|
|
547
|
+
}
|
|
548
|
+
select(e) {
|
|
549
|
+
this.merging = e === "vcm", this.uniforms.merging = this.merging, this._lastLightCurveKey = null;
|
|
550
|
+
}
|
|
551
|
+
get hitStride() {
|
|
552
|
+
return 7;
|
|
553
|
+
}
|
|
554
|
+
cacheBytes(e, t) {
|
|
555
|
+
let n = Math.floor(Math.min(Kn, e * .45, t * .05) / 64) * 64;
|
|
556
|
+
return this._lightCacheSlots = n / 64, n;
|
|
557
|
+
}
|
|
558
|
+
get lightVertices() {
|
|
559
|
+
return this._lightCacheSlots;
|
|
560
|
+
}
|
|
561
|
+
beforeKernelBuild() {
|
|
562
|
+
this._sizeSourceTable();
|
|
563
|
+
}
|
|
564
|
+
allocate(e) {
|
|
565
|
+
(!this._splatAttr || this._splatAttr.count < e * 3) && (_(this.pt.renderer, this._splatAttr), this._splatAttr = ie(e * 3, 1, Uint32Array));
|
|
566
|
+
let t = this.merging ? 2 ** Math.ceil(Math.log2(Math.max(this._lightCacheSlots, 1024))) : 0;
|
|
567
|
+
this._mergeHeadAttr?.count !== t && (_(this.pt.renderer, this._mergeHeadAttr), this._mergeHeadAttr = t > 0 ? ie(t, 1, Uint32Array) : null), this.uniforms.hashMask.value = Math.max(t - 1, 0), this._guideTexture || (this._guideTexture = new bt(null, mn, 16, St, xt), this._guideTexture.source.dataReady = !1, this._guideTexture.needsUpdate = !0, this._guideBuildAttr = ie(hn * 16, 1, Float32Array)), this.uniforms.guideTexture = ht(this._guideTexture), this.uniforms.guide.value = 0;
|
|
568
|
+
}
|
|
569
|
+
registerKernels(e) {
|
|
570
|
+
let { km: t, qm: n, pb: r, counters: i, bounceCountsBuf: a, wfCurrentBounce: o, copyReadB: s, copyWriteA: c, maxRays: l, w: u, own: d, freshLight: f, freshTri: p, freshBvh: m, freshMat: ee, freshEnvTex: te, freshEnvCDF: ne, materialLayers: re } = e, h = re?.diffuseTransmission ?? !0, g = this.uniforms, _ = n.MAX_BOUNCE_SNAPSHOTS, ie = (e) => {
|
|
571
|
+
let t = q(o).clamp(q(0), q(_ - 1));
|
|
572
|
+
a.element(t.add(q(2 * _))).assign(e), a.element(t.add(q(3 * _))).assign(V(i.element(q(Fe.ACTIVE_ENERGY)))), Xe(i.element(q(Fe.ENTERING_COUNT)), e);
|
|
573
|
+
};
|
|
574
|
+
if (t.register("lightSnapshot", L(() => {
|
|
575
|
+
ie(V(i.element(q(Fe.ACTIVE_RAY_COUNT))));
|
|
576
|
+
})().compute([
|
|
577
|
+
1,
|
|
578
|
+
1,
|
|
579
|
+
1
|
|
580
|
+
], [
|
|
581
|
+
1,
|
|
582
|
+
1,
|
|
583
|
+
1
|
|
584
|
+
])), t.register("lightCopyback", L(() => {
|
|
585
|
+
let e = nt, t = V(i.element(q(Fe.ACTIVE_RAY_COUNT)));
|
|
586
|
+
R(e.equal(q(0)), () => {
|
|
587
|
+
ie(t);
|
|
588
|
+
}), R(e.greaterThanEqual(t), () => {
|
|
589
|
+
z();
|
|
590
|
+
}), c.element(e).assign(s.element(e));
|
|
591
|
+
})().compute([
|
|
592
|
+
Math.ceil(l / 256),
|
|
593
|
+
1,
|
|
594
|
+
1
|
|
595
|
+
], [
|
|
596
|
+
256,
|
|
597
|
+
1,
|
|
598
|
+
1
|
|
599
|
+
])), t.register("guideClear", En({ counters: i })), t.register("guideBuild", Tn({
|
|
600
|
+
counters: i,
|
|
601
|
+
out: mt(this._guideBuildAttr, "float")
|
|
602
|
+
})), t.register("lightGenerate", d(Dn({
|
|
603
|
+
rayBufferRW: r.rayBuffer.rw,
|
|
604
|
+
hitBufferRW: r.hitBuffer.rw,
|
|
605
|
+
activeIndicesRW: n.activeIndices.a,
|
|
606
|
+
counters: i,
|
|
607
|
+
lightBuffer: f,
|
|
608
|
+
triangleBuffer: p,
|
|
609
|
+
bvhBuffer: m,
|
|
610
|
+
emissiveTriangleCount: this.pt.emissiveTriangleCount,
|
|
611
|
+
emissiveVec4Offset: this.pt.emissiveVec4Offset,
|
|
612
|
+
emissiveTotalPower: this.pt.emissiveTotalPower,
|
|
613
|
+
emissiveBoost: this.pt.emissiveBoost,
|
|
614
|
+
sunDirection: this.pt.sunDirection,
|
|
615
|
+
sunRadiance: this.pt.sunRadiance,
|
|
616
|
+
sunParams: this.pt.sunParams,
|
|
617
|
+
environmentIntensity: this.pt.environmentIntensity,
|
|
618
|
+
envTexture: te,
|
|
619
|
+
envCDFTexture: ne,
|
|
620
|
+
envMatrix: this.pt.environmentMatrix,
|
|
621
|
+
envResolution: this.pt.envResolution,
|
|
622
|
+
directionalLightsBuffer: this.pt.directionalLightsBufferNode,
|
|
623
|
+
areaLightsBuffer: this.pt.areaLightsBufferNode,
|
|
624
|
+
pointLightsBuffer: this.pt.pointLightsBufferNode,
|
|
625
|
+
spotLightsBuffer: this.pt.spotLightsBufferNode,
|
|
626
|
+
bidirectional: g,
|
|
627
|
+
resolution: this.pt.resolution,
|
|
628
|
+
frame: this.pt.seedFrame,
|
|
629
|
+
transmissiveBounces: this.pt.transmissiveBounces
|
|
630
|
+
})()).compute([
|
|
631
|
+
Math.ceil(l / 256),
|
|
632
|
+
1,
|
|
633
|
+
1
|
|
634
|
+
], [
|
|
635
|
+
256,
|
|
636
|
+
1,
|
|
637
|
+
1
|
|
638
|
+
])), t.register("connect", d(On({
|
|
639
|
+
rayBufferRW: r.rayBuffer.rw,
|
|
640
|
+
hitBufferRO: r.hitBuffer.ro,
|
|
641
|
+
activeIndicesRO: n.getActiveReadRO(),
|
|
642
|
+
counters: i,
|
|
643
|
+
bvhBuffer: m,
|
|
644
|
+
triangleBuffer: p,
|
|
645
|
+
materialBuffer: ee,
|
|
646
|
+
resolution: this.pt.resolution,
|
|
647
|
+
frame: this.pt.seedFrame,
|
|
648
|
+
accumFrame: this.pt.frame,
|
|
649
|
+
currentBounce: this.pt._wfCurrentBounce,
|
|
650
|
+
chunkRowBase: this.pt._wfChunkRowBase,
|
|
651
|
+
lightPaths: g.lightPaths,
|
|
652
|
+
slotsPerPath: g.slotsPerPath,
|
|
653
|
+
lightTag: g.lightTag,
|
|
654
|
+
passTag: g.passTag,
|
|
655
|
+
strategyView: g.strategyView,
|
|
656
|
+
maxBounceCount: this.pt.maxBounces,
|
|
657
|
+
globalIlluminationIntensity: this.pt.globalIlluminationIntensity,
|
|
658
|
+
fireflyThreshold: this.pt.fireflyThreshold,
|
|
659
|
+
mergeVm: g.merging ? (e) => Wn(g, e) : null,
|
|
660
|
+
diffuseTransmission: h
|
|
661
|
+
})()).compute([
|
|
662
|
+
Math.ceil(l / 256),
|
|
663
|
+
1,
|
|
664
|
+
1
|
|
665
|
+
], [
|
|
666
|
+
256,
|
|
667
|
+
1,
|
|
668
|
+
1
|
|
669
|
+
])), g.merging) {
|
|
670
|
+
let e = mt(this._mergeHeadAttr, "uint").toAtomic();
|
|
671
|
+
t.register("mergeClear", In({
|
|
672
|
+
head: e,
|
|
673
|
+
hashSize: this._mergeHeadAttr.count
|
|
674
|
+
})), t.register("mergeInsert", Ln({
|
|
675
|
+
hitBufferRW: r.hitBuffer.rw,
|
|
676
|
+
head: e,
|
|
677
|
+
bidirectional: g
|
|
678
|
+
})().compute([
|
|
679
|
+
Math.ceil(this._lightCacheSlots / 256),
|
|
680
|
+
1,
|
|
681
|
+
1
|
|
682
|
+
], [
|
|
683
|
+
256,
|
|
684
|
+
1,
|
|
685
|
+
1
|
|
686
|
+
])), t.register("merge", d(Rn({
|
|
687
|
+
rayBufferRW: r.rayBuffer.rw,
|
|
688
|
+
hitBufferRO: r.hitBuffer.ro,
|
|
689
|
+
activeIndicesRO: n.getActiveReadRO(),
|
|
690
|
+
counters: i,
|
|
691
|
+
head: e,
|
|
692
|
+
materialBuffer: ee,
|
|
693
|
+
bidirectional: g,
|
|
694
|
+
maxBounceCount: this.pt.maxBounces,
|
|
695
|
+
globalIlluminationIntensity: this.pt.globalIlluminationIntensity,
|
|
696
|
+
fireflyThreshold: this.pt.fireflyThreshold,
|
|
697
|
+
accumFrame: this.pt.frame,
|
|
698
|
+
diffuseTransmission: h
|
|
699
|
+
})()).compute([
|
|
700
|
+
Math.ceil(l / 256),
|
|
701
|
+
1,
|
|
702
|
+
1
|
|
703
|
+
], [
|
|
704
|
+
256,
|
|
705
|
+
1,
|
|
706
|
+
1
|
|
707
|
+
]));
|
|
708
|
+
}
|
|
709
|
+
let ae = mt(this._splatAttr, "uint").toAtomic();
|
|
710
|
+
t.register("lightSplat", d(zn({
|
|
711
|
+
hitBufferRO: r.hitBuffer.ro,
|
|
712
|
+
splatBuffer: ae,
|
|
713
|
+
bvhBuffer: m,
|
|
714
|
+
triangleBuffer: p,
|
|
715
|
+
materialBuffer: ee,
|
|
716
|
+
lightPaths: g.lightPaths,
|
|
717
|
+
slotsPerPath: g.slotsPerPath,
|
|
718
|
+
lightTag: g.lightTag,
|
|
719
|
+
strategyView: g.strategyView,
|
|
720
|
+
cameraPosition: g.cameraPosition,
|
|
721
|
+
cameraForward: g.cameraForward,
|
|
722
|
+
cameraViewMatrix: this.pt.cameraViewMatrix,
|
|
723
|
+
cameraProjectionMatrix: this.pt.cameraProjectionMatrix,
|
|
724
|
+
pixelArea: g.pixelArea,
|
|
725
|
+
renderWidth: this.pt._wfRenderWidth,
|
|
726
|
+
renderHeight: this.pt._wfRenderHeight,
|
|
727
|
+
globalIlluminationIntensity: this.pt.globalIlluminationIntensity,
|
|
728
|
+
fireflyThreshold: this.pt.fireflyThreshold,
|
|
729
|
+
accumFrame: this.pt.frame,
|
|
730
|
+
frame: this.pt.seedFrame,
|
|
731
|
+
mergeVm: g.merging ? (e) => Wn(g, e) : null,
|
|
732
|
+
diffuseTransmission: h
|
|
733
|
+
})()).compute([
|
|
734
|
+
Math.ceil(this._lightCacheSlots / 256),
|
|
735
|
+
1,
|
|
736
|
+
1
|
|
737
|
+
], [
|
|
738
|
+
256,
|
|
739
|
+
1,
|
|
740
|
+
1
|
|
741
|
+
])), t.register("splatResolve", Bn({
|
|
742
|
+
rayBufferRW: r.rayBuffer.rw,
|
|
743
|
+
splatBuffer: ae,
|
|
744
|
+
renderWidth: this.pt._wfRenderWidth,
|
|
745
|
+
chunkRowBase: this.pt._wfChunkRowBase,
|
|
746
|
+
chunkRows: this.pt._wfChunkRows
|
|
747
|
+
})().compute([
|
|
748
|
+
Math.ceil(u / 16),
|
|
749
|
+
Math.ceil(this.pt._chunkRows / 16),
|
|
750
|
+
1
|
|
751
|
+
], [
|
|
752
|
+
16,
|
|
753
|
+
16,
|
|
754
|
+
1
|
|
755
|
+
]));
|
|
756
|
+
}
|
|
757
|
+
beginFrame(e) {
|
|
758
|
+
let t = this._updateBidirectionalUniforms();
|
|
759
|
+
return this._lightTraced = t && this.uniforms.lightTrace.value > 0, t && (this._updateLightGuide(), this._traceLightPaths(e)), t;
|
|
760
|
+
}
|
|
761
|
+
beforeShade() {
|
|
762
|
+
this.uniforms.passTag.value = this._nextPassTag();
|
|
763
|
+
}
|
|
764
|
+
afterShade(e) {
|
|
765
|
+
e.dispatch("connect"), this.merging && e.dispatch("merge");
|
|
766
|
+
}
|
|
767
|
+
resolve(e) {
|
|
768
|
+
this._lightTraced && e.dispatch("splatResolve");
|
|
769
|
+
}
|
|
770
|
+
get curveKey() {
|
|
771
|
+
return this._lightCurveKey;
|
|
772
|
+
}
|
|
773
|
+
applyLightCurve(e, t, n) {
|
|
774
|
+
this._lastLightBounceCounts = e, this._lastLightBounceEnergy = t, this._lastLightCurveKey = n;
|
|
775
|
+
}
|
|
776
|
+
describe() {
|
|
777
|
+
return `${this.name}: ${this._lightCacheSlots.toLocaleString("en-US")} light vertex slots`;
|
|
778
|
+
}
|
|
779
|
+
gpuResources() {
|
|
780
|
+
return this._splatAttr ? [this._splatAttr, this._mergeHeadAttr].filter(Boolean) : null;
|
|
781
|
+
}
|
|
782
|
+
dispose() {
|
|
783
|
+
_(this.pt.renderer, this._splatAttr), this._splatAttr = null, _(this.pt.renderer, this._mergeHeadAttr), this._mergeHeadAttr = null, this._disposeLightGuide();
|
|
784
|
+
}
|
|
785
|
+
setBidirectionalStrategy(e = "all", { alone: t = !1 } = {}) {
|
|
786
|
+
let n = {
|
|
787
|
+
all: Hn.ALL,
|
|
788
|
+
hit: Hn.HIT,
|
|
789
|
+
nee: Hn.NEE,
|
|
790
|
+
connect: Hn.CONNECT,
|
|
791
|
+
lightTrace: Hn.LIGHT_TRACE,
|
|
792
|
+
merge: Hn.MERGE
|
|
793
|
+
}[e] ?? Hn.ALL;
|
|
794
|
+
this.uniforms.strategyView.value = n === Hn.ALL ? n : n + (t ? Un : 0);
|
|
795
|
+
}
|
|
796
|
+
setMergeRadius(e = Xn) {
|
|
797
|
+
this._mergeRadiusPixels = Math.max(e, .001);
|
|
798
|
+
}
|
|
799
|
+
setMergeTrust(e = Qn) {
|
|
800
|
+
this.uniforms.mergeTrust.value = Math.max(e, 1e-4);
|
|
801
|
+
}
|
|
802
|
+
_updateBidirectionalUniforms() {
|
|
803
|
+
let e = this.uniforms, t = this.pt._wfRenderWidth.value, n = this.pt._wfRenderHeight.value, r = this.pt.maxBounces.value + 1, i = this._updateSourceTable() > 0 ? Math.min(Math.ceil(t * n * Jn), this.pt._packedBuffers.capacity, Math.floor(this._lightCacheSlots / r)) : 0;
|
|
804
|
+
if (e.lightPaths.value = i, e.slotsPerPath.value = r, this._lightCurveKey = `${i}:${r}:${this.pt._bounceLoopBound()}`, i === 0) return e.lightTrace.value = 0, !1;
|
|
805
|
+
this._lightTag = this._lightTag % Yn + 1, e.lightTag.value = this._lightTag;
|
|
806
|
+
let a = this.pt.cameraWorldMatrix.value.elements;
|
|
807
|
+
e.cameraPosition.value.set(a[12], a[13], a[14]), e.cameraForward.value.set(-a[8], -a[9], -a[10]).normalize();
|
|
808
|
+
let o = this.pt.cameraProjectionMatrix.value.elements;
|
|
809
|
+
e.pixelArea.value = 4 / (o[0] * o[5] * t * n);
|
|
810
|
+
let s = this.pt.cameraProjection.value === We.perspective && !this.pt.enableDOF.value;
|
|
811
|
+
return e.lightTrace.value = +!!s, this.merging && this._updateMergeRadius(t, n), !0;
|
|
812
|
+
}
|
|
813
|
+
_updateMergeRadius(e, t) {
|
|
814
|
+
let n = this.uniforms, r = this._mergeRadiusPixels * (this.pt.frameCount + 1) ** ((Zn - 1) / 2), i = this.pt.cameraProjection.value, a = this.pt.cameraProjectionMatrix.value.elements, o = 0, s = 0;
|
|
815
|
+
i === We.orthographic ? s = r * 2 / (a[5] * t) : o = i === We.equirectangular ? r * 2 * Math.PI / e : r * Math.sqrt(n.pixelArea.value), n.mergeSlope.value = Math.min(o, .1), n.mergeConst.value = s, n.mergeMin.value = Math.max(s, o * .001 * n.sceneRadius.value, 1e-9);
|
|
816
|
+
}
|
|
817
|
+
_sizeSourceTable() {
|
|
818
|
+
let e = this.uniforms, t = $.LAMPS;
|
|
819
|
+
[
|
|
820
|
+
"directional",
|
|
821
|
+
"area",
|
|
822
|
+
"point",
|
|
823
|
+
"spot"
|
|
824
|
+
].forEach((n, r) => {
|
|
825
|
+
e.sourceOffsets[r] = t, t += this.pt[`${n}LightsBufferNode`].array.length / ze[n];
|
|
826
|
+
}), e.sourceCount = t, e.sourceCdf.array.length !== t && (e.sourceCdf.array = new Float32Array(t));
|
|
827
|
+
}
|
|
828
|
+
_updateSourceTable() {
|
|
829
|
+
let e = this.uniforms, t = e.sourceCdf.array, n = new Float64Array(t.length), r = (e, t) => Math.max(.2126 * e[t] + .7152 * e[t + 1] + .0722 * e[t + 2], 0), i = (e) => ({
|
|
830
|
+
a: this.pt[`${e}LightsBufferNode`].array,
|
|
831
|
+
n: this.pt[`num${e[0].toUpperCase()}${e.slice(1)}Lights`].value,
|
|
832
|
+
f: ze[e]
|
|
833
|
+
}), a = i("directional"), o = this.pt.enableEnvironment.value > 0, s = this.pt.environment.exactTable;
|
|
834
|
+
e.envTable.value = +!!s;
|
|
835
|
+
let c = o && (this.pt.hasSun.value > 0 || s) || a.n > 0, l = c || this.merging ? this._sceneDisc() : 0, u = c ? l * qn : 0;
|
|
836
|
+
if (o && s && (n[$.ENVIRONMENT] = Math.max(s.radianceIntegral, 0) * this.pt.environmentIntensity.value * u), this.pt.emissiveTriangleCount.value > 0 && (n[$.EMITTERS] = Math.PI * this.pt.emissiveBoost.value * this.pt.emissiveTotalPower.value), o && this.pt.hasSun.value > 0) {
|
|
837
|
+
let { x: e, y: t, z: r } = this.pt.sunRadiance.value;
|
|
838
|
+
n[$.SUN] = Math.max(.2126 * e + .7152 * t + .0722 * r, 0) * this.pt.environmentIntensity.value * this.pt.sunParams.value.y * u;
|
|
839
|
+
}
|
|
840
|
+
for (let t = 0; t < a.n; t++) n[e.sourceOffsets[0] + t] = r(a.a, t * a.f + 3) * a.a[t * a.f + 6] * u;
|
|
841
|
+
let d = i("area");
|
|
842
|
+
for (let t = 0; t < d.n; t++) {
|
|
843
|
+
let i = d.a, a = t * d.f, o = i[a + 4] * i[a + 8] - i[a + 5] * i[a + 7], s = i[a + 5] * i[a + 6] - i[a + 3] * i[a + 8], c = i[a + 3] * i[a + 7] - i[a + 4] * i[a + 6], l = 4 * Math.hypot(o, s, c) * (i[a + 15] > .5 ? Math.PI / 4 : 1);
|
|
844
|
+
n[e.sourceOffsets[1] + t] = l > 0 ? r(i, a + 9) * Math.max(i[a + 12], 0) * (i[a + 13] > .5 ? 1 : l) : 0;
|
|
845
|
+
}
|
|
846
|
+
let f = i("point");
|
|
847
|
+
for (let t = 0; t < f.n; t++) n[e.sourceOffsets[2] + t] = 4 * Math.PI * r(f.a, t * f.f + 3) * Math.max(f.a[t * f.f + 6], 0);
|
|
848
|
+
let p = i("spot");
|
|
849
|
+
for (let t = 0; t < p.n; t++) {
|
|
850
|
+
let i = t * p.f;
|
|
851
|
+
n[e.sourceOffsets[3] + t] = 2 * Math.PI * (1 - Math.cos(p.a[i + 10])) * r(p.a, i + 6) * Math.max(p.a[i + 9], 0);
|
|
852
|
+
}
|
|
853
|
+
let m = 0;
|
|
854
|
+
for (let e = 0; e < n.length; e++) m += Number.isFinite(n[e]) ? n[e] : 0;
|
|
855
|
+
let ee = 0;
|
|
856
|
+
for (let e = 0; e < n.length; e++) ee += Number.isFinite(n[e]) ? n[e] : 0, t[e] = m > 0 ? ee / m : 0;
|
|
857
|
+
m > 0 && (t[t.length - 1] = 1);
|
|
858
|
+
let te = (e) => Math.fround(t[e] - (e > 0 ? t[e - 1] : 0));
|
|
859
|
+
return e.sunPick.value = te($.SUN), e.emitterPick.value = te($.EMITTERS), e.envPick.value = te($.ENVIRONMENT), m;
|
|
860
|
+
}
|
|
861
|
+
_sceneDisc() {
|
|
862
|
+
let e = this.uniforms, t = this._visibleSceneBounds();
|
|
863
|
+
if (!t) return 0;
|
|
864
|
+
let [n, r, i] = t.min, [a, o, s] = t.max, c = .5 * Math.hypot(a - n, o - r, s - i);
|
|
865
|
+
return c > 0 && Number.isFinite(c) ? (e.sceneCenter.value.set((n + a) / 2, (r + o) / 2, (i + s) / 2), e.sceneRadius.value = c, Math.PI * c * c) : 0;
|
|
866
|
+
}
|
|
867
|
+
_visibleSceneBounds() {
|
|
868
|
+
let e = this.pt._bvhRecords, t = e ? null : this.pt.bvhStorageAttr?.array;
|
|
869
|
+
if (!e && !(t?.length >= 16)) return null;
|
|
870
|
+
let n = this.pt._instanceTable?.blasBase ?? 1;
|
|
871
|
+
if (e && !e.isResident(0, n)) return this.pt._whenTLASResident(() => {}), null;
|
|
872
|
+
let r = (e) => {
|
|
873
|
+
let t = this._u32Views.get(e);
|
|
874
|
+
return t || this._u32Views.set(e, t = new Uint32Array(e.buffer, e.byteOffset, e.length)), t;
|
|
875
|
+
}, i = (n) => {
|
|
876
|
+
let i = e ? e.chunkFor(n) : t;
|
|
877
|
+
return {
|
|
878
|
+
f: i,
|
|
879
|
+
u: r(i),
|
|
880
|
+
o: e ? e.baseOf(n) : n * 16
|
|
881
|
+
};
|
|
882
|
+
}, a = (e) => {
|
|
883
|
+
if (e.u[e.o + 3] !== Ge.CLUSTER_LEAF) return e.f[e.o + 2] !== 0;
|
|
884
|
+
let t = (e.u[e.o] >>> 28 & 3) + 1;
|
|
885
|
+
for (let n = 0; n < t; n++) if (!(e.u[e.o + 12 + n] & 2147483648)) return !0;
|
|
886
|
+
return !1;
|
|
887
|
+
}, o = i(0);
|
|
888
|
+
if (o.u[o.o + 3] >= 1073741824) return null;
|
|
889
|
+
let s = e ? e.recordCount : t.length / 16, c = [], l = [];
|
|
890
|
+
for (let e = 0; e < 3; e++) for (let t of [1, -1]) {
|
|
891
|
+
let n = (n, r) => t > 0 ? n.f[n.o + r * 8 + 4 + e] : -n.f[n.o + r * 8 + e], r = (e, t) => e.u[e.o + 3 + t * 4], u = -Infinity, d = [], f = (e) => {
|
|
892
|
+
let t = n(e, 0), i = n(e, 1), a = t <= i ? 0 : 1;
|
|
893
|
+
d.push(r(e, a), a === 0 ? t : i, r(e, 1 - a), a === 0 ? i : t);
|
|
894
|
+
};
|
|
895
|
+
f(o);
|
|
896
|
+
let p = 0;
|
|
897
|
+
for (; d.length;) {
|
|
898
|
+
let e = d.pop(), t = d.pop();
|
|
899
|
+
if (e <= u) continue;
|
|
900
|
+
if (t >= s || ++p > s) return null;
|
|
901
|
+
let n = i(t);
|
|
902
|
+
n.u[n.o + 3] >= 1073741824 ? a(n) && (u = e) : f(n);
|
|
903
|
+
}
|
|
904
|
+
if (u === -Infinity) return null;
|
|
905
|
+
(t > 0 ? l : c)[e] = t > 0 ? u : -u;
|
|
906
|
+
}
|
|
907
|
+
return {
|
|
908
|
+
min: c,
|
|
909
|
+
max: l
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
setLightGuiding(e) {
|
|
913
|
+
this._lightGuiding = e !== !1, this.uniforms.guide.value = 0, this.pt.reset();
|
|
914
|
+
}
|
|
915
|
+
_updateLightGuide() {
|
|
916
|
+
let e = this.uniforms, t = this.pt._kernelManager;
|
|
917
|
+
e.guideLearning.value = +!!this._lightGuiding;
|
|
918
|
+
let n = this.pt.frameCount;
|
|
919
|
+
if (n === 0) {
|
|
920
|
+
t.dispatch("guideClear"), e.guide.value = 0;
|
|
921
|
+
return;
|
|
922
|
+
}
|
|
923
|
+
if (!this._lightGuiding || !(n <= 32 ? !(n & n - 1) : n % 32 == 0)) return;
|
|
924
|
+
t.dispatch("guideBuild");
|
|
925
|
+
let r = this.pt.renderer.backend;
|
|
926
|
+
this.pt.renderer.initTexture(this._guideTexture);
|
|
927
|
+
let i = r.device.createCommandEncoder({ label: "LightGuide" });
|
|
928
|
+
i.copyBufferToTexture({
|
|
929
|
+
buffer: r.get(this._guideBuildAttr).buffer,
|
|
930
|
+
bytesPerRow: hn * 4,
|
|
931
|
+
rowsPerImage: 16
|
|
932
|
+
}, { texture: r.get(this._guideTexture).texture }, [mn, 16]), r.device.queue.submit([i.finish()]), e.guide.value = 1;
|
|
933
|
+
}
|
|
934
|
+
_disposeLightGuide() {
|
|
935
|
+
_(this.pt.renderer, this._guideBuildAttr), this._guideTexture?.dispose(), this._guideTexture = this._guideBuildAttr = null, this.uniforms.guideTexture = null;
|
|
936
|
+
}
|
|
937
|
+
_nextPassTag() {
|
|
938
|
+
return this._passTag = this._passTag + 1 & 2147483647, (Vn | this._passTag) >>> 0;
|
|
939
|
+
}
|
|
940
|
+
_traceLightPaths(e) {
|
|
941
|
+
let t = this.pt._kernelManager, n = this.uniforms.lightPaths.value;
|
|
942
|
+
this.pt._wfChunkRowBase.value = 0, this.pt._wfMaxRayCount.value = n, t.setDispatchForCount("lightGenerate", n), t.dispatch("lightGenerate");
|
|
943
|
+
let r = this.pt._useDynamicDispatch, i = this._lastLightCurveKey === this._lightCurveKey, a = i ? this._lastLightBounceCounts : null, o = i ? this._lastLightBounceEnergy : null, s = this.pt._bounceEarlyExitThreshold >= 0 ? this.pt._bounceEarlyExitThreshold * n * 64 : -1;
|
|
944
|
+
for (let i = 0; i <= e; i++) {
|
|
945
|
+
this.pt._wfCurrentBounce.value = i;
|
|
946
|
+
let c = i > 0 ? a?.[i - 1] : void 0, l = r && c > 0 ? Math.min(n, Math.ceil(c * 1.5) + 1024) : n;
|
|
947
|
+
for (let e of Le) t.setDispatchForCount(e, l);
|
|
948
|
+
if (r || t.dispatch("enterFull"), t.dispatch("extend"), this.pt._sortMaterials && (t.dispatch("resetGlobalHist"), t.dispatch("globalHist"), t.dispatch("globalPrefix"), t.dispatch("globalScatter")), t.dispatch("shade"), t.dispatch("compact"), t.dispatch(r ? "lightCopyback" : "lightSnapshot"), s >= 0 && i < e && o?.[i] !== void 0 && o[i] <= s) break;
|
|
949
|
+
}
|
|
950
|
+
this.uniforms.lightTrace.value > 0 && (t.setDispatchForCount("lightSplat", n * this.uniforms.slotsPerPath.value), t.dispatch("lightSplat")), this.merging && (t.dispatch("mergeClear"), t.setDispatchForCount("mergeInsert", n * this.uniforms.slotsPerPath.value), t.dispatch("mergeInsert"));
|
|
951
|
+
}
|
|
952
|
+
};
|
|
953
|
+
//#endregion
|
|
954
|
+
export { Tt as n, $n as t };
|