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