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.
Files changed (176) hide show
  1. package/README.md +252 -44
  2. package/dist/ActiveColor-YvuQq44O.js +13 -0
  3. package/dist/ArchiveImporter-Hn35o6Z5.js +5145 -0
  4. package/dist/AssetConfig-DSEntE65.js +30 -0
  5. package/dist/BidirectionalIntegrator-CBw8hkeu.js +946 -0
  6. package/dist/BufferLayout-D_IBo2ci.js +150 -0
  7. package/dist/ColorManagement-oeEk7oSu.js +1488 -0
  8. package/dist/EngineEvents-Ci8dVWCP.js +73 -0
  9. package/dist/EngineIssues-CIZnXHsF.js +72 -0
  10. package/dist/FileFormats-sPGJeCRc.js +102 -0
  11. package/dist/Logger-dDDGj9Av.js +97 -0
  12. package/dist/{NeuralRetouch-CYgkQY8Z.js → NeuralRetouch-BzNpiVHZ.js} +8 -6
  13. package/dist/{NeuralSuperRes-PkgDLQcD.js → NeuralSuperRes-Bk7bHg2B.js} +55 -120
  14. package/dist/PathTracer-72XufKAr.js +29976 -0
  15. package/dist/PhysicalSky-BgjdV88k.js +1219 -0
  16. package/dist/RayzeeRenderer-1QRO97eq.js +3551 -0
  17. package/dist/SolarLimb-CPaeZVwz.js +721 -0
  18. package/dist/ToneMapGPU-CjU3osDd.js +177 -0
  19. package/dist/ViewTransforms-CYN7bq2w.js +255 -0
  20. package/dist/WorkingMatrix-C6y233hT.js +27 -0
  21. package/dist/ZipReader-gDSWr0I5.js +98 -0
  22. package/dist/addons/archives.es.js +3 -0
  23. package/dist/addons/bidirectional.es.js +2 -0
  24. package/dist/addons/color.es.js +3 -0
  25. package/dist/addons/formats.es.js +2 -0
  26. package/dist/addons/physical-sky.es.js +2 -0
  27. package/dist/addons/storage.es.js +3 -0
  28. package/dist/archiveFormats-tnAoUL1j.js +94 -0
  29. package/dist/identity-DrQsGT2o.js +39 -0
  30. package/dist/openStorage-DwcBRUj7.js +820 -0
  31. package/dist/rayzee-core.es.js +12 -0
  32. package/dist/rayzee.es.js +2551 -44024
  33. package/dist/rayzee.umd.js +528 -487
  34. package/dist/sceneCachePolicy-C67jbci-.js +443 -0
  35. package/dist/shared-BGBcSxBQ.js +17 -0
  36. package/package.json +23 -2
  37. package/src/Color/ActiveColor.js +34 -0
  38. package/src/Color/BasicColor.js +147 -0
  39. package/src/Color/ColorManagement.js +7 -31
  40. package/src/Color/ViewTransforms.js +5 -1
  41. package/src/EngineDefaults.js +62 -1029
  42. package/src/EngineEvents.js +2 -0
  43. package/src/EngineIssues.js +2 -0
  44. package/src/Headless.js +6 -5
  45. package/src/Passes/AIUpscaler.js +58 -141
  46. package/src/Passes/OIDNDenoiser.js +92 -65
  47. package/src/Passes/OIDNTemporalHistory.js +1 -1
  48. package/src/PathTracerApp.js +620 -4026
  49. package/src/Pipeline/PipelineContext.js +0 -4
  50. package/src/Platform.js +36 -0
  51. package/src/Processor/ArchiveCache.js +20 -7
  52. package/src/Processor/ArchiveImporter.js +1265 -0
  53. package/src/Processor/ArchiveReader.js +22 -4
  54. package/src/Processor/AssetLoader.js +327 -1763
  55. package/src/Processor/AtmosphereModel.js +1 -2
  56. package/src/Processor/BVHBuilder.js +14 -126
  57. package/src/Processor/BVHLeafFold.js +4 -6
  58. package/src/Processor/BVHRefitter.js +67 -46
  59. package/src/Processor/BufferLayout.js +291 -0
  60. package/src/Processor/EmissiveTriangleBuilder.js +1 -1
  61. package/src/Processor/EnvironmentExactTable.js +187 -0
  62. package/src/Processor/EquirectHDRInfo.js +30 -223
  63. package/src/Processor/FileFormats.js +116 -0
  64. package/src/Processor/GLTFDecoders.js +85 -0
  65. package/src/Processor/GLTFDiffuseTransmission.js +63 -0
  66. package/src/Processor/GeometryExtractor.js +15 -5
  67. package/src/Processor/HostMemory.js +7 -1
  68. package/src/Processor/IESParser.js +47 -35
  69. package/src/Processor/InstanceTable.js +1 -1
  70. package/src/Processor/KernelManager.js +35 -2
  71. package/src/Processor/MaterialPacking.js +10 -8
  72. package/src/Processor/PBRT/PBRTMaterials.js +254 -42
  73. package/src/Processor/PBRT/PBRTParser.js +49 -19
  74. package/src/Processor/PBRT/PBRTScattering.js +93 -0
  75. package/src/Processor/PBRT/PBRTSceneBuilder.js +1050 -75
  76. package/src/Processor/PBRT/PBRTTextureBake.js +179 -0
  77. package/src/Processor/PBRT/PFM.js +59 -0
  78. package/src/Processor/PackedRayBuffer.js +116 -9
  79. package/src/Processor/ParallelBVHBuilder.js +3 -6
  80. package/src/Processor/PhysicalSky.js +5 -4
  81. package/src/Processor/PlatformImageLoader.js +50 -6
  82. package/src/Processor/QueueManager.js +39 -5
  83. package/src/Processor/ReinsertionOptimizer.js +2 -2
  84. package/src/Processor/SceneMetadata.js +30 -5
  85. package/src/Processor/SceneProcessor.js +53 -62
  86. package/src/Processor/ShaderBuilder.js +6 -16
  87. package/src/Processor/SimpleSky.js +1 -62
  88. package/src/Processor/SolarLimb.js +3 -0
  89. package/src/Processor/SplitBLAS.js +1 -1
  90. package/src/Processor/StorageTexturePool.js +22 -1
  91. package/src/Processor/TLASBuilder.js +1 -3
  92. package/src/Processor/TextureBuckets.js +237 -0
  93. package/src/Processor/TextureCreator.js +181 -8
  94. package/src/Processor/ToneMapGPU.js +64 -15
  95. package/src/Processor/Workers/BVHRefitWorker.js +5 -2
  96. package/src/Processor/Workers/BVHSubtreeWorker.js +1 -34
  97. package/src/Processor/Workers/BVHWorker.js +5 -18
  98. package/src/Processor/Workers/CDFWorker.js +6 -183
  99. package/src/Processor/Workers/TexturesWorker.js +103 -18
  100. package/src/Processor/archiveFormats.js +7 -0
  101. package/src/Processor/utils.js +2 -1
  102. package/src/RayzeeRenderer.js +3900 -0
  103. package/src/RenderSettings.js +68 -62
  104. package/src/Stages/ASVGF.js +13 -14
  105. package/src/Stages/AutoExposure.js +17 -17
  106. package/src/Stages/BilateralFilter.js +2 -1
  107. package/src/Stages/Compositor.js +8 -23
  108. package/src/Stages/DenoiserSettings.js +182 -0
  109. package/src/Stages/EdgeFilter.js +2 -1
  110. package/src/Stages/MotionVector.js +1 -1
  111. package/src/Stages/NRD.js +11 -5
  112. package/src/Stages/NormalDepth.js +12 -8
  113. package/src/Stages/PathTracer.js +336 -43
  114. package/src/Stages/PathTracerStage.js +69 -66
  115. package/src/Stages/Variance.js +1 -1
  116. package/src/Storage/BLASCache.js +1 -1
  117. package/src/Storage/CDFCache.js +18 -17
  118. package/src/Storage/DownloadCache.js +1 -1
  119. package/src/Storage/SceneGraphCodec.js +46 -3
  120. package/src/Storage/SpillStore.js +1 -1
  121. package/src/Storage/StorageManager.js +45 -9
  122. package/src/Storage/areas.js +4 -0
  123. package/src/TSL/BVHTraversal.js +50 -25
  124. package/src/TSL/Bidirectional.js +208 -0
  125. package/src/TSL/BidirectionalLamps.js +132 -0
  126. package/src/TSL/Clearcoat.js +15 -6
  127. package/src/TSL/Common.js +20 -15
  128. package/src/TSL/ConnectKernel.js +167 -0
  129. package/src/TSL/Debugger.js +1 -1
  130. package/src/TSL/Displacement.js +4 -3
  131. package/src/TSL/EmissiveSampling.js +65 -18
  132. package/src/TSL/Environment.js +77 -106
  133. package/src/TSL/EnvironmentCDF.js +85 -39
  134. package/src/TSL/ExtendKernel.js +8 -3
  135. package/src/TSL/FinalWriteKernel.js +4 -4
  136. package/src/TSL/GenerateKernel.js +18 -4
  137. package/src/TSL/HitFacet.js +35 -5
  138. package/src/TSL/LightBVHSampling.js +40 -9
  139. package/src/TSL/LightGenerateKernel.js +293 -0
  140. package/src/TSL/LightGuide.js +198 -0
  141. package/src/TSL/LightSplatKernel.js +180 -0
  142. package/src/TSL/LightVisibility.js +111 -0
  143. package/src/TSL/LightsCore.js +13 -38
  144. package/src/TSL/LightsDirect.js +28 -29
  145. package/src/TSL/LightsIndirect.js +3 -1
  146. package/src/TSL/LightsSampling.js +239 -51
  147. package/src/TSL/MaterialEvaluation.js +113 -31
  148. package/src/TSL/MaterialProperties.js +44 -17
  149. package/src/TSL/MaterialTransmission.js +52 -47
  150. package/src/TSL/MergeKernel.js +224 -0
  151. package/src/TSL/PathTracerCore.js +65 -29
  152. package/src/TSL/Random.js +5 -1
  153. package/src/TSL/SceneResources.js +51 -0
  154. package/src/TSL/ShadeKernel.js +985 -101
  155. package/src/TSL/Struct.js +10 -0
  156. package/src/TSL/Sun.js +1 -1
  157. package/src/TSL/TextureSampling.js +66 -61
  158. package/src/addons/archives.js +14 -0
  159. package/src/addons/bidirectional.js +13 -0
  160. package/src/addons/color.js +32 -0
  161. package/src/addons/formats.js +16 -0
  162. package/src/addons/physicalSky.js +14 -0
  163. package/src/addons/storage.js +19 -0
  164. package/src/core.js +31 -0
  165. package/src/index.js +13 -23
  166. package/src/integrators/BidirectionalIntegrator.js +838 -0
  167. package/src/managers/AnimationManager.js +88 -6
  168. package/src/managers/CameraManager.js +103 -46
  169. package/src/managers/DenoisingManager.js +14 -10
  170. package/src/managers/EnvironmentManager.js +125 -103
  171. package/src/managers/GoboManager.js +9 -0
  172. package/src/managers/MaterialDataManager.js +48 -37
  173. package/src/managers/UniformManager.js +32 -10
  174. package/dist/ToneMapGPU-B6XIe3DU.js +0 -544
  175. package/dist/rolldown-runtime-CAFD8bLK.js +0 -11
  176. package/src/Processor/TreeletOptimizer.js +0 -574
@@ -19,6 +19,31 @@ const SHADER_NAMES = {
19
19
  cameraProjectionMatrix: 'ptCameraProjectionMatrix',
20
20
  };
21
21
 
22
+ /** Floats per light in each type's list (see LightSerializer). */
23
+ export const LIGHT_FLOATS = Object.freeze( {
24
+ directional: 12, // 8 light fields + gobo { index, signed intensity, scale, pad }
25
+ area: 16, // 13 base + normalize, spread, shape
26
+ point: 9,
27
+ spot: 20, // 14 light fields + gobo { index, signed intensity } + IES { index, intensity } + 2 reserved
28
+ } );
29
+
30
+ /** Lights a list holds before it has to grow. */
31
+ export const LIGHT_LIST_STEP = 16;
32
+
33
+ // A uniform array gives each float its own vec4; WebGPU guarantees 64 KiB a binding.
34
+ const MAX_UNIFORM_ELEMENTS = 65536 / 16;
35
+
36
+ /**
37
+ * Lights a list of this type must hold for `lights`: a whole number of steps, but never past what
38
+ * fits a binding unless `lights` alone already does — a count that did not fit never did.
39
+ */
40
+ export function lightListCapacity( type, lights ) {
41
+
42
+ const stepped = Math.ceil( lights / LIGHT_LIST_STEP ) * LIGHT_LIST_STEP;
43
+ return Math.max( lights, Math.min( stepped, Math.floor( MAX_UNIFORM_ELEMENTS / LIGHT_FLOATS[ type ] ) ) );
44
+
45
+ }
46
+
22
47
  export class UniformManager {
23
48
 
24
49
  constructor( width = 1920, height = 1080 ) {
@@ -193,12 +218,12 @@ export class UniformManager {
193
218
  // reset, and a camera move resets each frame of a drag, so the RNG redrew the identical
194
219
  // sequence and temporal denoising had nothing to average.
195
220
  u( 'seedFrame', 0, 'uint' );
196
- u( 'maxBounces', DEFAULT_STATE.bounces, 'int' );
221
+ u( 'maxBounces', DEFAULT_STATE.maxBounces, 'int' );
197
222
  u( 'maxSamples', DEFAULT_STATE.maxSamples, 'int' );
198
223
  u( 'transmissiveBounces', DEFAULT_STATE.transmissiveBounces, 'int' );
199
224
  u( 'maxSubsurfaceSteps', DEFAULT_STATE.maxSubsurfaceSteps, 'int' );
200
225
  u( 'maxTransparentBounces', DEFAULT_STATE.maxTransparentBounces, 'int' );
201
- u( 'visMode', DEFAULT_STATE.debugMode, 'int' );
226
+ u( 'visMode', DEFAULT_STATE.visMode, 'int' );
202
227
  u( 'debugVisScale', DEFAULT_STATE.debugVisScale, 'float' );
203
228
 
204
229
  // Tier-1 convergence early-stop (FinalWrite reads these; live-toggled, no shader rebuild)
@@ -240,7 +265,6 @@ export class UniformManager {
240
265
  ub( 'enableEnvironment', DEFAULT_STATE.enableEnvironment );
241
266
  u( 'environmentMatrix', new Matrix4(), 'mat4' );
242
267
  u( 'envTotalSum', 0.0, 'float' );
243
- u( 'envCompensationDelta', 0.0, 'float' );
244
268
  u( 'envResolution', new Vector2( 1, 1 ), 'vec2' );
245
269
  ub( 'groundProjectionEnabled', DEFAULT_STATE.groundProjectionEnabled );
246
270
  u( 'groundProjectionRadius', DEFAULT_STATE.groundProjectionRadius, 'float' );
@@ -266,13 +290,11 @@ export class UniformManager {
266
290
  u( 'numPointLights', 0, 'int' );
267
291
  u( 'numSpotLights', 0, 'int' );
268
292
 
269
- // Light buffer nodes - pre-allocate for up to 16 lights per type (shader hard cap)
270
- this._lightBuffers = {
271
- directional: uniformArray( new Float32Array( 12 * 16 ), 'float' ),
272
- area: uniformArray( new Float32Array( 16 * 16 ), 'float' ),
273
- point: uniformArray( new Float32Array( 9 * 16 ), 'float' ),
274
- spot: uniformArray( new Float32Array( 20 * 16 ), 'float' ),
275
- };
293
+ // The shader bakes each list's length, so lights are written into these in place and a list is
294
+ // only replaced when a scene has more lights than it holds (PathTracerStage._writeLightList).
295
+ this._lightBuffers = Object.fromEntries( Object.entries( LIGHT_FLOATS ).map(
296
+ ( [ type, floats ] ) => [ type, uniformArray( new Float32Array( floats * LIGHT_LIST_STEP ), 'float' ) ]
297
+ ) );
276
298
 
277
299
  // Camera matrices
278
300
  u( 'cameraWorldMatrix', new Matrix4(), 'mat4' );
@@ -1,544 +0,0 @@
1
- import { ACESFilmicToneMapping as e, AgXToneMapping as t, CineonToneMapping as n, LinearToneMapping as r, NeutralToneMapping as i, NoToneMapping as a, ReinhardToneMapping as o } from "three";
2
- //#region src/utils/Logger.js
3
- var s = {
4
- silent: 0,
5
- error: 1,
6
- warn: 2,
7
- info: 3,
8
- debug: 4
9
- }, c = "info", l = "rayzeeLogLevel", u = "rayzeeLogNamespaces", d = "color:#7c8494", f = "color:inherit", p = null, m = null;
10
- function h(e) {
11
- try {
12
- return globalThis.localStorage?.getItem(e) ?? null;
13
- } catch {
14
- return null;
15
- }
16
- }
17
- function g(e, t) {
18
- try {
19
- t === null ? globalThis.localStorage?.removeItem(e) : globalThis.localStorage?.setItem(e, t);
20
- } catch {}
21
- }
22
- function _() {
23
- if (p !== null) return p;
24
- let e = globalThis.__RAYZEE_LOG_LEVEL__;
25
- return e !== void 0 && e in s ? (p = s[e], p) : (p = s[h(l)] ?? s[c], p);
26
- }
27
- function v() {
28
- if (m !== null) return m;
29
- let e = globalThis.__RAYZEE_LOG_NS__ ?? h(u);
30
- return m = e ? String(e).split(",").map((e) => e.trim()).filter(Boolean) : [], m;
31
- }
32
- function y(e, t) {
33
- if (t < s.debug) return !0;
34
- let n = v();
35
- return n.length === 0 || n.some((t) => e === t || e.startsWith(`${t}:`));
36
- }
37
- function b(e, t, n) {
38
- if (e > _() || !y(t, e)) return;
39
- let r = e === s.error ? console.error : e === s.warn ? console.warn : console.log, i = `[${t}]`;
40
- typeof n[0] == "string" ? r(`%c${i}%c ${n[0]}`, d, f, ...n.slice(1)) : r(`%c${i}`, d, ...n);
41
- }
42
- var x = {
43
- n: (e) => Number(e).toLocaleString("en-US"),
44
- ms: (e) => e < 10 ? `${Number(e).toFixed(1)} ms` : `${Math.round(e)} ms`,
45
- mb: (e) => {
46
- let t = e / (1024 * 1024);
47
- return t < 10 ? `${t.toFixed(1)} MB` : `${Math.round(t)} MB`;
48
- },
49
- px: (e, t) => `${e}×${t}`,
50
- count: (e, t, n = `${t}s`) => `${x.n(e)} ${Number(e) === 1 ? t : n}`,
51
- list: (e) => e.filter(Boolean).join(" · ")
52
- }, S = {
53
- levels: s,
54
- setLevel(e) {
55
- return e in s ? (globalThis.__RAYZEE_LOG_LEVEL__ = e, p = s[e], g(l, e === c ? null : e), e) : (console.warn(`[log] unknown level '${e}' — expected one of ${Object.keys(s).join(", ")}`), this.getLevel());
56
- },
57
- getLevel() {
58
- let e = _();
59
- return Object.keys(s).find((t) => s[t] === e);
60
- },
61
- isEnabled(e) {
62
- return (s[e] ?? s.debug) <= _();
63
- },
64
- only(...e) {
65
- let t = e.flat().filter(Boolean);
66
- return m = t, globalThis.__RAYZEE_LOG_NS__ = t.join(","), g(u, t.length ? t.join(",") : null), t.length && this.setLevel("debug"), t;
67
- },
68
- refresh() {
69
- return p = null, m = null, this.getLevel();
70
- }
71
- };
72
- function C(e) {
73
- return {
74
- namespace: e,
75
- error: (...t) => b(s.error, e, t),
76
- warn: (...t) => b(s.warn, e, t),
77
- info: (...t) => b(s.info, e, t),
78
- debug: (...t) => b(s.debug, e, t),
79
- isEnabled: (e) => S.isEnabled(e),
80
- summary(t, n = []) {
81
- let r = n.filter(Boolean);
82
- if (r.length === 0 || !console.groupCollapsed) {
83
- b(s.info, e, [t]), r.forEach((t) => b(s.debug, e, [t]));
84
- return;
85
- }
86
- s.info > _() || ((_() >= s.debug && console.group ? console.group : console.groupCollapsed)(`%c[${e}]%c ${t}`, d, f), r.forEach((e) => console.log(e)), console.groupEnd());
87
- }
88
- };
89
- }
90
- var w = /* @__PURE__ */ new Set();
91
- function T(e, t, ...n) {
92
- w.has(t) || (w.add(t), e.warn(...n));
93
- }
94
- function E() {
95
- return S.getLevel();
96
- }
97
- //#endregion
98
- //#region src/AssetConfig.js
99
- var D = {
100
- ortRuntimeUrl: "https://cdn.jsdelivr.net/npm/onnxruntime-web@1.24.3/dist/ort.webgpu.bundle.min.mjs",
101
- ortWasmPaths: "https://cdn.jsdelivr.net/npm/onnxruntime-web@1.24.3/dist/",
102
- dracoDecoderPath: "https://www.gstatic.com/draco/v1/decoders/",
103
- ktx2TranscoderPath: "https://cdn.jsdelivr.net/npm/three@0.183.2/examples/jsm/libs/basis/",
104
- oidnWeightsBaseUrl: "https://assets.rayzee.atulmourya.com/oidn/denoiser-0.0.11/",
105
- ocioRuntimeFactory: null,
106
- ocioRuntimeUrl: null,
107
- ocioWasmUrl: null,
108
- upscalerModelBaseUrl: "https://huggingface.co/notaneimu/onnx-image-models/resolve/main/",
109
- neuralRuntimeUrl: "/neural/neural-runtime.js",
110
- neuralAssetBaseUrl: null,
111
- cacheNamespace: "rayzee",
112
- storage: "auto"
113
- }, O = /* @__PURE__ */ new Set();
114
- function k(e) {
115
- if (e) {
116
- Object.assign(D, e);
117
- for (let t of Object.keys(e)) O.add(t);
118
- }
119
- }
120
- function A(e) {
121
- return O.has(e);
122
- }
123
- function j() {
124
- return { ...D };
125
- }
126
- //#endregion
127
- //#region src/Color/BuiltinViews.js
128
- var M = (e) => Math.min(Math.max(e, 0), 1);
129
- function ee(e, t, n, r, i) {
130
- i[0] = M(e), i[1] = M(t), i[2] = M(n);
131
- }
132
- function te(e, t, n, r, i) {
133
- i[0] = M(e * r), i[1] = M(t * r), i[2] = M(n * r);
134
- }
135
- function ne(e, t, n, r, i) {
136
- e *= r, t *= r, n *= r, i[0] = M(e / (e + 1)), i[1] = M(t / (t + 1)), i[2] = M(n / (n + 1));
137
- }
138
- function re(e, t, n, r, i) {
139
- e = Math.max(e * r - .004, 0), t = Math.max(t * r - .004, 0), n = Math.max(n * r - .004, 0);
140
- let a = (e) => (e * (6.2 * e + .5) / (e * (6.2 * e + 1.7) + .06)) ** 2.2;
141
- i[0] = a(e), i[1] = a(t), i[2] = a(n);
142
- }
143
- function N(e, t, n, r, i) {
144
- e = e * r / .6, t = t * r / .6, n = n * r / .6;
145
- let a = .59719 * e + .35458 * t + .04823 * n, o = .076 * e + .90834 * t + .01566 * n, s = .0284 * e + .13383 * t + .83777 * n, c = (e) => (e * (e + .0245786) - 90537e-9) / (e * (.983729 * e + .432951) + .238081);
146
- a = c(a), o = c(o), s = c(s), i[0] = M(1.60475 * a - .53108 * o - .07367 * s), i[1] = M(-.10208 * a + 1.10813 * o - .00605 * s), i[2] = M(-.00327 * a - .07276 * o + 1.07602 * s);
147
- }
148
- function P(e, t, n, r, i) {
149
- e *= r, t *= r, n *= r;
150
- let a = .6274 * e + .3293 * t + .0433 * n, o = .0691 * e + .9195 * t + .0113 * n, s = .0164 * e + .088 * t + .8956 * n, c = .856627153315983 * a + .0951212405381588 * o + .0482516061458583 * s, l = .137318972929847 * a + .761241990602591 * o + .101439036467562 * s, u = .11189821299995 * a + .0767994186031903 * o + .811302368396859 * s, d = -12.47393, f = 4.026069 - d;
151
- c = M((Math.log2(Math.max(c, 1e-10)) - d) / f), l = M((Math.log2(Math.max(l, 1e-10)) - d) / f), u = M((Math.log2(Math.max(u, 1e-10)) - d) / f);
152
- let p = (e) => {
153
- let t = e * e, n = t * t;
154
- return 15.5 * n * t - 40.14 * n * e + 31.96 * n - 6.868 * t * e + .4298 * t + .1191 * e - .00232;
155
- };
156
- c = p(c), l = p(l), u = p(u);
157
- let m = 1.1271005818144368 * c - .11060664309660323 * l - .016493938717834573 * u, h = -.1413297634984383 * c + 1.157823702216272 * l - .016493938717834257 * u, g = -.14132976349843826 * c - .11060664309660294 * l + 1.2519364065950405 * u;
158
- m = Math.max(0, m) ** 2.2, h = Math.max(0, h) ** 2.2, g = Math.max(0, g) ** 2.2, i[0] = M(1.6605 * m - .5876 * h - .0728 * g), i[1] = M(-.1246 * m + 1.1329 * h - .0083 * g), i[2] = M(-.0182 * m - .1006 * h + 1.1187 * g);
159
- }
160
- function F(e, t, n, r, i) {
161
- let a = .76;
162
- e *= r, t *= r, n *= r;
163
- let o = Math.min(e, Math.min(t, n)), s = o < .08 ? o - 6.25 * o * o : .04;
164
- e -= s, t -= s, n -= s;
165
- let c = Math.max(e, Math.max(t, n));
166
- if (c < a) {
167
- i[0] = e, i[1] = t, i[2] = n;
168
- return;
169
- }
170
- let l = 1 - a, u = 1 - l * l / (c + l - a), d = u / c;
171
- e *= d, t *= d, n *= d;
172
- let f = 1 - 1 / (.15 * (c - u) + 1);
173
- i[0] = e + (u - e) * f, i[1] = t + (u - t) * f, i[2] = n + (u - n) * f;
174
- }
175
- var I = [
176
- {
177
- id: a,
178
- name: "None",
179
- wgslConst: "TM_NONE",
180
- cpu: ee,
181
- wgsl: null,
182
- call: null,
183
- appliesExposure: !1
184
- },
185
- {
186
- id: r,
187
- name: "Linear",
188
- wgslConst: "TM_LINEAR",
189
- cpu: te,
190
- wgsl: null,
191
- call: null
192
- },
193
- {
194
- id: o,
195
- name: "Reinhard",
196
- wgslConst: "TM_REINHARD",
197
- cpu: ne,
198
- wgsl: "\nfn tm_reinhard( c: vec3<f32> ) -> vec3<f32> {\n return clamp( c / ( c + vec3<f32>( 1.0 ) ), vec3<f32>( 0.0 ), vec3<f32>( 1.0 ) );\n}\n",
199
- call: "tm_reinhard( c )"
200
- },
201
- {
202
- id: n,
203
- name: "Cineon",
204
- wgslConst: "TM_CINEON",
205
- cpu: re,
206
- wgsl: "\nfn tm_cineon( c0: vec3<f32> ) -> vec3<f32> {\n let c = max( c0 - vec3<f32>( 0.004 ), vec3<f32>( 0.0 ) );\n let v = ( c * ( 6.2 * c + vec3<f32>( 0.5 ) ) ) / ( c * ( 6.2 * c + vec3<f32>( 1.7 ) ) + vec3<f32>( 0.06 ) );\n return pow( max( v, vec3<f32>( 0.0 ) ), vec3<f32>( 2.2 ) );\n}\n",
207
- call: "tm_cineon( c )"
208
- },
209
- {
210
- id: e,
211
- name: "ACES Filmic",
212
- wgslConst: "TM_ACES",
213
- cpu: N,
214
- wgsl: "\nfn tm_aces( c0: vec3<f32> ) -> vec3<f32> {\n let c = c0 / 0.6;\n let m_in = mat3x3<f32>(\n vec3<f32>( 0.59719, 0.07600, 0.02840 ),\n vec3<f32>( 0.35458, 0.90834, 0.13383 ),\n vec3<f32>( 0.04823, 0.01566, 0.83777 ) );\n let v = m_in * c;\n let a = v * ( v + vec3<f32>( 0.0245786 ) ) - vec3<f32>( 0.000090537 );\n let b = v * ( 0.983729 * v + vec3<f32>( 0.4329510 ) ) + vec3<f32>( 0.238081 );\n let m_out = mat3x3<f32>(\n vec3<f32>( 1.60475, -0.10208, -0.00327 ),\n vec3<f32>( -0.53108, 1.10813, -0.07276 ),\n vec3<f32>( -0.07367, -0.00605, 1.07602 ) );\n return clamp( m_out * ( a / b ), vec3<f32>( 0.0 ), vec3<f32>( 1.0 ) );\n}\n",
215
- call: "tm_aces( c )"
216
- },
217
- {
218
- id: t,
219
- name: "AgX",
220
- wgslConst: "TM_AGX",
221
- cpu: P,
222
- wgsl: "\nfn tm_agx( c0: vec3<f32> ) -> vec3<f32> {\n let m_in = mat3x3<f32>(\n vec3<f32>( 0.6274, 0.0691, 0.0164 ),\n vec3<f32>( 0.3293, 0.9195, 0.0880 ),\n vec3<f32>( 0.0433, 0.0113, 0.8956 ) );\n let m_agx = mat3x3<f32>(\n vec3<f32>( 0.856627153315983, 0.137318972929847, 0.11189821299995 ),\n vec3<f32>( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ),\n vec3<f32>( 0.0482516061458583, 0.101439036467562, 0.811302368396859 ) );\n\n var v = m_agx * ( m_in * c0 );\n\n let minEv = -12.47393;\n let maxEv = 4.026069;\n v = clamp( ( log2( max( v, vec3<f32>( 1e-10 ) ) ) - vec3<f32>( minEv ) ) / ( maxEv - minEv ),\n vec3<f32>( 0.0 ), vec3<f32>( 1.0 ) );\n\n let x2 = v * v;\n let x4 = x2 * x2;\n v = 15.5 * x4 * x2 - 40.14 * x4 * v + 31.96 * x4 - 6.868 * x2 * v + 0.4298 * x2 + 0.1191 * v\n - vec3<f32>( 0.00232 );\n\n let m_out = mat3x3<f32>(\n vec3<f32>( 1.1271005818144368, -0.1413297634984383, -0.14132976349843826 ),\n vec3<f32>( -0.11060664309660323, 1.157823702216272, -0.11060664309660294 ),\n vec3<f32>( -0.016493938717834573, -0.016493938717834257, 1.2519364065950405 ) );\n let o = pow( max( m_out * v, vec3<f32>( 0.0 ) ), vec3<f32>( 2.2 ) );\n\n let m_srgb = mat3x3<f32>(\n vec3<f32>( 1.6605, -0.1246, -0.0182 ),\n vec3<f32>( -0.5876, 1.1329, -0.1006 ),\n vec3<f32>( -0.0728, -0.0083, 1.1187 ) );\n return clamp( m_srgb * o, vec3<f32>( 0.0 ), vec3<f32>( 1.0 ) );\n}\n",
223
- call: "tm_agx( c )"
224
- },
225
- {
226
- id: i,
227
- name: "Neutral",
228
- wgslConst: "TM_NEUTRAL",
229
- cpu: F,
230
- wgsl: "\nfn tm_neutral( c0: vec3<f32> ) -> vec3<f32> {\n let startCompression = 0.8 - 0.04;\n let desaturation = 0.15;\n\n let x = min( c0.r, min( c0.g, c0.b ) );\n var offset = 0.04;\n if ( x < 0.08 ) { offset = x - 6.25 * x * x; }\n var c = c0 - vec3<f32>( offset );\n\n let peak = max( c.r, max( c.g, c.b ) );\n if ( peak < startCompression ) { return c; }\n\n let d = 1.0 - startCompression;\n let newPeak = 1.0 - d * d / ( peak + d - startCompression );\n c = c * ( newPeak / peak );\n let gFactor = 1.0 - 1.0 / ( desaturation * ( peak - newPeak ) + 1.0 );\n return mix( c, vec3<f32>( newPeak ), gFactor );\n}\n",
231
- call: "tm_neutral( c )"
232
- }
233
- ].map((e) => ({
234
- source: "builtin",
235
- outputEncoded: !1,
236
- appliesExposure: !0,
237
- ...e
238
- })), L = 200, R = 12, z = [...I], B = new Map(z.map((e) => [e.id, e])), V = 1, H = /* @__PURE__ */ new Set();
239
- function U() {
240
- V++;
241
- for (let e of H) e();
242
- }
243
- var W = B;
244
- function G() {
245
- return V;
246
- }
247
- function K(e) {
248
- return H.add(e), () => H.delete(e);
249
- }
250
- function q(e) {
251
- return B.get(e) ?? null;
252
- }
253
- function J() {
254
- return z.map((e) => ({
255
- id: e.id,
256
- name: e.name,
257
- source: e.source,
258
- display: e.ocio?.display ?? null,
259
- view: e.ocio?.view ?? null,
260
- look: e.ocio?.look ?? null
261
- }));
262
- }
263
- function Y() {
264
- return z.filter((e) => e.table).length;
265
- }
266
- function ie() {
267
- let e = 200;
268
- for (; B.has(e);) e++;
269
- return e;
270
- }
271
- function ae(e) {
272
- if (typeof e?.id != "number") throw Error("view transform needs a numeric id");
273
- if (typeof e.cpu != "function") throw Error(`view transform ${e.id} needs a cpu function`);
274
- if (!e.name) throw Error(`view transform ${e.id} needs a name`);
275
- if (!/^TM_[A-Z0-9_]+$/.test(e.wgslConst ?? "")) throw Error(`view transform ${e.id} needs a wgslConst like TM_SOMETHING`);
276
- let t = B.get(e.id);
277
- if (!t && e.table && Y() >= 12) throw Error(`cannot register "${e.name}": 12 table-backed view transforms already registered, and WebGPU only guarantees 16 sampled textures per stage. Remove one first.`);
278
- let n = {
279
- source: "custom",
280
- outputEncoded: !1,
281
- appliesExposure: !0,
282
- ...e
283
- };
284
- return t ? z[z.indexOf(t)] = n : z.push(n), B.set(n.id, n), U(), n;
285
- }
286
- function oe(e) {
287
- let t = B.get(e);
288
- return t ? (z.splice(z.indexOf(t), 1), B.delete(e), U(), !0) : !1;
289
- }
290
- function se(e = null) {
291
- let t = z.filter((t) => t.source === "ocio" && !e?.has(t.id)).map((e) => e.id);
292
- if (t.length === 0) return 0;
293
- for (let e of t) {
294
- let t = B.get(e);
295
- z.splice(z.indexOf(t), 1), B.delete(e);
296
- }
297
- return U(), t.length;
298
- }
299
- function ce(e) {
300
- let t = e?.library;
301
- if (!t?.addToneMapping) return 0;
302
- let n = 0;
303
- for (let e of z) e.tsl && (t.toneMappingNodes?.delete(e.id), t.addToneMapping(e.tsl, e.id), n++);
304
- return n;
305
- }
306
- function X({ group: e = 0, firstBinding: t = 3 } = {}) {
307
- let n = [], r = t, i = [], a = [];
308
- for (let t of z) {
309
- if (t.table) {
310
- let a = `${t.wgslConst.toLowerCase()}_tex`;
311
- i.push(`@group(${e}) @binding(${r}) var ${a}: texture_3d<f32>;`), n.push({
312
- index: r,
313
- transform: t,
314
- texName: a
315
- }), r += 1;
316
- }
317
- t.wgsl && a.push(t.wgsl);
318
- }
319
- let o = z.map((e) => `const ${e.wgslConst}: u32 = ${e.id}u;`).join("\n"), s = z.filter((e) => e.call).map((e) => `\tif ( mode == ${e.wgslConst} ) { return ${e.call}; }`).join("\n"), c = z.filter((e) => e.outputEncoded).map((e) => e.wgslConst), l = c.length ? c.map((e) => `mode == ${e}`).join(" || ") : "false", u = z.filter((e) => !e.appliesExposure).map((e) => e.wgslConst), d = u.length ? u.map((e) => `mode == ${e}`).join(" || ") : "false";
320
- return {
321
- wgsl: `
322
- ${o}
323
-
324
- ${i.join("\n")}
325
-
326
- ${a.join("\n")}
327
-
328
- // Three.js clamps the fragment output with max(0) before tone mapping, so the curves never see a
329
- // negative channel. The saturation grade drives channels below zero on much of a typical frame,
330
- // and AgX/Neutral mix negatives across channels instead of clipping them.
331
- fn rayzee_tone_curve( color: vec3<f32>, mode: u32 ) -> vec3<f32> {
332
- let c = max( color, vec3<f32>( 0.0 ) );
333
- ${s}
334
- return clamp( c, vec3<f32>( 0.0 ), vec3<f32>( 1.0 ) );
335
- }
336
-
337
- /** True when the curve already returned display-encoded colour. */
338
- fn rayzee_output_encoded( mode: u32 ) -> bool {
339
- return ${l};
340
- }
341
-
342
- fn rayzee_tone_map( linearRGB: vec3<f32>, mode: u32, exposure: f32, saturation: f32 ) -> vec3<f32> {
343
- // Three.js returns early for NoToneMapping without applying exposure, so a readback that
344
- // applied it would paint brighter than the viewport it replaces.
345
- var c = linearRGB * select( exposure, 1.0, ${d} );
346
- if ( saturation != 1.0 ) {
347
- let luma = vec3<f32>( dot( c, vec3<f32>( 0.2126, 0.7152, 0.0722 ) ) );
348
- c = luma + ( c - luma ) * saturation;
349
- }
350
- return rayzee_tone_curve( c, mode );
351
- }
352
-
353
- fn rayzee_linear_to_srgb( c: vec3<f32> ) -> vec3<f32> {
354
- return select(
355
- 1.055 * pow( max( c, vec3<f32>( 0.0 ) ), vec3<f32>( 1.0 / 2.4 ) ) - vec3<f32>( 0.055 ),
356
- 12.92 * c,
357
- c <= vec3<f32>( 0.0031308 ) );
358
- }
359
-
360
- /** The transfer step, skipped for a curve that already encoded its own output. */
361
- fn rayzee_encode( mapped: vec3<f32>, mode: u32 ) -> vec3<f32> {
362
- if ( rayzee_output_encoded( mode ) ) { return clamp( mapped, vec3<f32>( 0.0 ), vec3<f32>( 1.0 ) ); }
363
- return rayzee_linear_to_srgb( mapped );
364
- }
365
-
366
- fn rayzee_to_u8( srgb: vec3<f32> ) -> vec3<u32> {
367
- return vec3<u32>( clamp( round( srgb * 255.0 + vec3<f32>( 0.5 ) ), vec3<f32>( 0.0 ), vec3<f32>( 255.0 ) ) );
368
- }
369
- `,
370
- bindings: n
371
- };
372
- }
373
- function Z() {
374
- z.length = 0, z.push(...I), B.clear();
375
- for (let e of z) B.set(e.id, e);
376
- U();
377
- }
378
- var le = a, ue = 0, de = 3;
379
- function Q() {
380
- let { wgsl: e, bindings: t } = X({
381
- group: ue,
382
- firstBinding: de
383
- });
384
- return {
385
- wgsl: e,
386
- bindings: t,
387
- version: G()
388
- };
389
- }
390
- Q().wgsl;
391
- var fe = {
392
- packed: "\n@group(0) @binding(0) var<storage, read> src: array<u32>;\n\nfn rayzee_source( x: u32, y: u32 ) -> vec4<f32> {\n let a = ( y * params.width + x ) * 2u;\n return vec4<f32>( unpack2x16float( src[ a ] ), unpack2x16float( src[ a + 1u ] ) );\n}",
393
- texture: "\n@group(0) @binding(0) var src: texture_2d<f32>;\n\nfn rayzee_source( x: u32, y: u32 ) -> vec4<f32> {\n return textureLoad( src, vec2<u32>( x, y ), 0 );\n}"
394
- }, pe = (e, t) => `
395
- struct Params {
396
- width: u32,
397
- height: u32,
398
- mode: u32,
399
- flipY: u32,
400
- exposure: f32,
401
- saturation: f32,
402
- alpha: u32,
403
- };
404
-
405
- @group(0) @binding(1) var<storage, read_write> dst: array<u32>;
406
- @group(0) @binding(2) var<uniform> params: Params;
407
- ${fe[t]}
408
-
409
- ${e}
410
-
411
- @compute @workgroup_size(8, 8)
412
- fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
413
- if ( gid.x >= params.width || gid.y >= params.height ) { return; }
414
-
415
- var srcY = gid.y;
416
- if ( params.flipY == 1u ) { srcY = params.height - 1u - gid.y; }
417
-
418
- let linear = rayzee_source( gid.x, srcY );
419
- let mapped = rayzee_tone_map( linear.rgb, params.mode, params.exposure, params.saturation );
420
- let b8 = rayzee_to_u8( rayzee_encode( mapped, params.mode ) );
421
- var a8 = 255u;
422
- if ( params.alpha == 1u ) { a8 = rayzee_to_u8( vec3<f32>( linear.a ) ).x; }
423
- dst[ gid.y * params.width + gid.x ] = b8.x | ( b8.y << 8u ) | ( b8.z << 16u ) | ( a8 << 24u );
424
- }
425
- `, $ = 32, me = class {
426
- constructor(e, t = "rayzee:tonemap", { input: n = "packed" } = {}) {
427
- this.device = e, this.label = t, this.input = n, this.width = 0, this.height = 0, this._pipeline = null, this._storage = null, this._map = null, this._params = null, this._paramData = new ArrayBuffer($), this._paramU32 = new Uint32Array(this._paramData), this._paramF32 = new Float32Array(this._paramData), this._shaderVersion = -1, this._bindings = [], this._tables = /* @__PURE__ */ new Map(), this.disposed = !1;
428
- }
429
- _ensurePipeline() {
430
- let { wgsl: e, bindings: t, version: n } = Q();
431
- this._pipeline && this._shaderVersion === n || (this._bindings = t, this._shaderVersion = n, this._pipeline = this.device.createComputePipeline({
432
- label: this.label,
433
- layout: "auto",
434
- compute: {
435
- module: this.device.createShaderModule({
436
- label: this.label,
437
- code: pe(e, this.input)
438
- }),
439
- entryPoint: "main"
440
- }
441
- }));
442
- }
443
- _ensureTables() {
444
- let e = /* @__PURE__ */ new Set();
445
- for (let { index: t, transform: n } of this._bindings) {
446
- let { data: r, size: i } = n.table;
447
- e.add(t);
448
- let a = this._tables.get(t);
449
- if (a && a.data === r) continue;
450
- a?.texture.destroy();
451
- let o = this.device.createTexture({
452
- label: `${this.label}-${n.wgslConst}`,
453
- size: [
454
- i,
455
- i,
456
- i
457
- ],
458
- dimension: "3d",
459
- format: "rgba16float",
460
- usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST
461
- });
462
- this.device.queue.writeTexture({ texture: o }, r, {
463
- bytesPerRow: i * 8,
464
- rowsPerImage: i
465
- }, [
466
- i,
467
- i,
468
- i
469
- ]), this._tables.set(t, {
470
- texture: o,
471
- data: r,
472
- view: o.createView()
473
- });
474
- }
475
- for (let [t, n] of this._tables) e.has(t) || (n.texture.destroy(), this._tables.delete(t));
476
- }
477
- ensureSize(e, t) {
478
- if (this._ensurePipeline(), this._ensureTables(), this.width === e && this.height === t && this._storage) return;
479
- this._releaseBuffers();
480
- let n = e * t * 4;
481
- this._storage = this.device.createBuffer({
482
- label: `${this.label}-out`,
483
- size: n,
484
- usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC
485
- }), this._map = this.device.createBuffer({
486
- label: `${this.label}-map`,
487
- size: n,
488
- usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ
489
- }), this._params = this.device.createBuffer({
490
- label: `${this.label}-params`,
491
- size: $,
492
- usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
493
- }), this.width = e, this.height = t;
494
- }
495
- async toRGBA8(e, { exposure: t = 1, toneMapping: n = 0, saturation: r = 1, flipY: i = !1, preserveAlpha: a = !1 } = {}) {
496
- if (this.disposed) throw Error("PackedToneMapper: disposed");
497
- if (!this._storage) throw Error("PackedToneMapper: call ensureSize() first");
498
- this._ensurePipeline(), this._ensureTables();
499
- let { width: o, height: s } = this;
500
- this._paramU32[0] = o, this._paramU32[1] = s, this._paramU32[2] = n >>> 0, this._paramU32[3] = +!!i, this._paramF32[4] = t, this._paramF32[5] = r, this._paramU32[6] = +!!a, this.device.queue.writeBuffer(this._params, 0, this._paramData);
501
- let c = [...this._tables.entries()].map(([e, t]) => ({
502
- binding: e,
503
- resource: t.view
504
- })), l = this.device.createBindGroup({
505
- layout: this._pipeline.getBindGroupLayout(0),
506
- entries: [
507
- ...c,
508
- {
509
- binding: 0,
510
- resource: this.input === "texture" ? e.createView() : {
511
- buffer: e,
512
- size: o * s * 8
513
- }
514
- },
515
- {
516
- binding: 1,
517
- resource: { buffer: this._storage }
518
- },
519
- {
520
- binding: 2,
521
- resource: { buffer: this._params }
522
- }
523
- ]
524
- }), u = this.device.createCommandEncoder({ label: this.label }), d = u.beginComputePass();
525
- d.setPipeline(this._pipeline), d.setBindGroup(0, l), d.dispatchWorkgroups(Math.ceil(o / 8), Math.ceil(s / 8)), d.end(), u.copyBufferToBuffer(this._storage, 0, this._map, 0, o * s * 4), this.device.queue.submit([u.finish()]), await this._map.mapAsync(GPUMapMode.READ);
526
- let f = new Uint8ClampedArray(this._map.getMappedRange().slice(0));
527
- return this._map.unmap(), f;
528
- }
529
- release() {
530
- this._releaseBuffers(), this.width = this.height = 0;
531
- }
532
- _releaseBuffers() {
533
- this._storage?.destroy(), this._map?.destroy(), this._params?.destroy(), this._storage = null, this._map = null, this._params = null;
534
- }
535
- dispose() {
536
- if (!this.disposed) {
537
- this.disposed = !0, this._releaseBuffers();
538
- for (let e of this._tables.values()) e.texture.destroy();
539
- this._tables.clear(), this._pipeline = null;
540
- }
541
- }
542
- };
543
- //#endregion
544
- export { C, E, S, T, Z as _, W as a, A as b, Y as c, J as d, ie as f, oe as g, se as h, L as i, G as l, ce as m, le as n, ae as o, K as p, R as r, X as s, me as t, q as u, k as v, x as w, s as x, j as y };
@@ -1,11 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var e = Object.defineProperty, t = (t, n) => {
3
- let r = {};
4
- for (var i in t) e(r, i, {
5
- get: t[i],
6
- enumerable: !0
7
- });
8
- return n || e(r, Symbol.toStringTag, { value: "Module" }), r;
9
- };
10
- //#endregion
11
- export { t };