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