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