@tinypoly/gpu-renderer 0.0.0-stage → 0.0.1

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 (204) hide show
  1. package/ARCHITECTURE.md +339 -0
  2. package/LICENSE +21 -0
  3. package/README.md +284 -2
  4. package/dist/accumulator.d.ts +27 -0
  5. package/dist/accumulator.d.ts.map +1 -0
  6. package/dist/accumulator.js +57 -0
  7. package/dist/accumulator.js.map +1 -0
  8. package/dist/bvh.d.ts +26 -0
  9. package/dist/bvh.d.ts.map +1 -0
  10. package/dist/bvh.js +296 -0
  11. package/dist/bvh.js.map +1 -0
  12. package/dist/bvhBuilder.d.ts +72 -0
  13. package/dist/bvhBuilder.d.ts.map +1 -0
  14. package/dist/bvhBuilder.js +126 -0
  15. package/dist/bvhBuilder.js.map +1 -0
  16. package/dist/bvhWorker.d.ts +2 -0
  17. package/dist/bvhWorker.d.ts.map +1 -0
  18. package/dist/bvhWorker.js +8 -0
  19. package/dist/bvhWorker.js.map +1 -0
  20. package/dist/camera.d.ts +29 -0
  21. package/dist/camera.d.ts.map +1 -0
  22. package/dist/camera.js +48 -0
  23. package/dist/camera.js.map +1 -0
  24. package/dist/canvas.d.ts +9 -0
  25. package/dist/canvas.d.ts.map +1 -0
  26. package/dist/canvas.js +11 -0
  27. package/dist/canvas.js.map +1 -0
  28. package/dist/denoise.d.ts +69 -0
  29. package/dist/denoise.d.ts.map +1 -0
  30. package/dist/denoise.js +455 -0
  31. package/dist/denoise.js.map +1 -0
  32. package/dist/device.d.ts +37 -0
  33. package/dist/device.d.ts.map +1 -0
  34. package/dist/device.js +52 -0
  35. package/dist/device.js.map +1 -0
  36. package/dist/dispatchScheduler.d.ts +43 -0
  37. package/dist/dispatchScheduler.d.ts.map +1 -0
  38. package/dist/dispatchScheduler.js +49 -0
  39. package/dist/dispatchScheduler.js.map +1 -0
  40. package/dist/environment.d.ts +39 -0
  41. package/dist/environment.d.ts.map +1 -0
  42. package/dist/environment.js +168 -0
  43. package/dist/environment.js.map +1 -0
  44. package/dist/frameLayout.d.ts +4 -0
  45. package/dist/frameLayout.d.ts.map +1 -0
  46. package/dist/frameLayout.js +58 -0
  47. package/dist/frameLayout.js.map +1 -0
  48. package/dist/geometry.d.ts +75 -0
  49. package/dist/geometry.d.ts.map +1 -0
  50. package/dist/geometry.js +799 -0
  51. package/dist/geometry.js.map +1 -0
  52. package/dist/index.d.ts +27 -0
  53. package/dist/index.d.ts.map +1 -0
  54. package/dist/index.js +19 -0
  55. package/dist/index.js.map +1 -0
  56. package/dist/lights.d.ts +64 -0
  57. package/dist/lights.d.ts.map +1 -0
  58. package/dist/lights.js +264 -0
  59. package/dist/lights.js.map +1 -0
  60. package/dist/materialLayout.d.ts +143 -0
  61. package/dist/materialLayout.d.ts.map +1 -0
  62. package/dist/materialLayout.js +297 -0
  63. package/dist/materialLayout.js.map +1 -0
  64. package/dist/math.d.ts +10 -0
  65. package/dist/math.d.ts.map +1 -0
  66. package/dist/math.js +40 -0
  67. package/dist/math.js.map +1 -0
  68. package/dist/pathTracePass.d.ts +27 -0
  69. package/dist/pathTracePass.d.ts.map +1 -0
  70. package/dist/pathTracePass.js +83 -0
  71. package/dist/pathTracePass.js.map +1 -0
  72. package/dist/planarCapture.d.ts +38 -0
  73. package/dist/planarCapture.d.ts.map +1 -0
  74. package/dist/planarCapture.js +163 -0
  75. package/dist/planarCapture.js.map +1 -0
  76. package/dist/presentPass.d.ts +31 -0
  77. package/dist/presentPass.d.ts.map +1 -0
  78. package/dist/presentPass.js +78 -0
  79. package/dist/presentPass.js.map +1 -0
  80. package/dist/renderer.d.ts +209 -0
  81. package/dist/renderer.d.ts.map +1 -0
  82. package/dist/renderer.js +847 -0
  83. package/dist/renderer.js.map +1 -0
  84. package/dist/sceneAssets.d.ts +24 -0
  85. package/dist/sceneAssets.d.ts.map +1 -0
  86. package/dist/sceneAssets.js +77 -0
  87. package/dist/sceneAssets.js.map +1 -0
  88. package/dist/sceneUpload.d.ts +61 -0
  89. package/dist/sceneUpload.d.ts.map +1 -0
  90. package/dist/sceneUpload.js +98 -0
  91. package/dist/sceneUpload.js.map +1 -0
  92. package/dist/shaderModule.d.ts +7 -0
  93. package/dist/shaderModule.d.ts.map +1 -0
  94. package/dist/shaderModule.js +19 -0
  95. package/dist/shaderModule.js.map +1 -0
  96. package/dist/shaderProgram.d.ts +124 -0
  97. package/dist/shaderProgram.d.ts.map +1 -0
  98. package/dist/shaderProgram.js +1030 -0
  99. package/dist/shaderProgram.js.map +1 -0
  100. package/dist/structLayout.d.ts +28 -0
  101. package/dist/structLayout.d.ts.map +1 -0
  102. package/dist/structLayout.js +58 -0
  103. package/dist/structLayout.js.map +1 -0
  104. package/dist/texturePack.d.ts +54 -0
  105. package/dist/texturePack.d.ts.map +1 -0
  106. package/dist/texturePack.js +86 -0
  107. package/dist/texturePack.js.map +1 -0
  108. package/dist/upstream.d.ts +7 -0
  109. package/dist/upstream.d.ts.map +1 -0
  110. package/dist/upstream.js +11 -0
  111. package/dist/upstream.js.map +1 -0
  112. package/dist/volumetric.d.ts +10 -0
  113. package/dist/volumetric.d.ts.map +1 -0
  114. package/dist/volumetric.js +34 -0
  115. package/dist/volumetric.js.map +1 -0
  116. package/dist/wgsl/bsdf.wgsl.d.ts +13 -0
  117. package/dist/wgsl/bsdf.wgsl.d.ts.map +1 -0
  118. package/dist/wgsl/bsdf.wgsl.js +619 -0
  119. package/dist/wgsl/bsdf.wgsl.js.map +1 -0
  120. package/dist/wgsl/bvh.wgsl.d.ts +3 -0
  121. package/dist/wgsl/bvh.wgsl.d.ts.map +1 -0
  122. package/dist/wgsl/bvh.wgsl.js +218 -0
  123. package/dist/wgsl/bvh.wgsl.js.map +1 -0
  124. package/dist/wgsl/common.wgsl.d.ts +3 -0
  125. package/dist/wgsl/common.wgsl.d.ts.map +1 -0
  126. package/dist/wgsl/common.wgsl.js +193 -0
  127. package/dist/wgsl/common.wgsl.js.map +1 -0
  128. package/dist/wgsl/environment.wgsl.d.ts +10 -0
  129. package/dist/wgsl/environment.wgsl.d.ts.map +1 -0
  130. package/dist/wgsl/environment.wgsl.js +145 -0
  131. package/dist/wgsl/environment.wgsl.js.map +1 -0
  132. package/dist/wgsl/lights.wgsl.d.ts +10 -0
  133. package/dist/wgsl/lights.wgsl.d.ts.map +1 -0
  134. package/dist/wgsl/lights.wgsl.js +434 -0
  135. package/dist/wgsl/lights.wgsl.js.map +1 -0
  136. package/dist/wgsl/pathTrace.wgsl.d.ts +14 -0
  137. package/dist/wgsl/pathTrace.wgsl.d.ts.map +1 -0
  138. package/dist/wgsl/pathTrace.wgsl.js +1020 -0
  139. package/dist/wgsl/pathTrace.wgsl.js.map +1 -0
  140. package/dist/wgsl/present.wgsl.d.ts +7 -0
  141. package/dist/wgsl/present.wgsl.d.ts.map +1 -0
  142. package/dist/wgsl/present.wgsl.js +154 -0
  143. package/dist/wgsl/present.wgsl.js.map +1 -0
  144. package/dist/wgsl/random.wgsl.d.ts +9 -0
  145. package/dist/wgsl/random.wgsl.d.ts.map +1 -0
  146. package/dist/wgsl/random.wgsl.js +91 -0
  147. package/dist/wgsl/random.wgsl.js.map +1 -0
  148. package/dist/wgsl/sampling.wgsl.d.ts +3 -0
  149. package/dist/wgsl/sampling.wgsl.d.ts.map +1 -0
  150. package/dist/wgsl/sampling.wgsl.js +31 -0
  151. package/dist/wgsl/sampling.wgsl.js.map +1 -0
  152. package/dist/wgsl/shaderSupport.wgsl.d.ts +6 -0
  153. package/dist/wgsl/shaderSupport.wgsl.d.ts.map +1 -0
  154. package/dist/wgsl/shaderSupport.wgsl.js +120 -0
  155. package/dist/wgsl/shaderSupport.wgsl.js.map +1 -0
  156. package/dist/wgsl/surface.wgsl.d.ts +10 -0
  157. package/dist/wgsl/surface.wgsl.d.ts.map +1 -0
  158. package/dist/wgsl/surface.wgsl.js +794 -0
  159. package/dist/wgsl/surface.wgsl.js.map +1 -0
  160. package/dist/wgsl/texture.wgsl.d.ts +11 -0
  161. package/dist/wgsl/texture.wgsl.d.ts.map +1 -0
  162. package/dist/wgsl/texture.wgsl.js +132 -0
  163. package/dist/wgsl/texture.wgsl.js.map +1 -0
  164. package/package.json +77 -3
  165. package/src/accumulator.ts +64 -0
  166. package/src/bvh.ts +336 -0
  167. package/src/bvhBuilder.ts +178 -0
  168. package/src/bvhWorker.ts +13 -0
  169. package/src/camera.ts +77 -0
  170. package/src/canvas.ts +13 -0
  171. package/src/denoise.ts +514 -0
  172. package/src/device.ts +81 -0
  173. package/src/dispatchScheduler.ts +71 -0
  174. package/src/environment.ts +233 -0
  175. package/src/frameLayout.ts +59 -0
  176. package/src/geometry.ts +1067 -0
  177. package/src/index.ts +64 -0
  178. package/src/lights.ts +365 -0
  179. package/src/materialLayout.ts +408 -0
  180. package/src/math.ts +48 -0
  181. package/src/pathTracePass.ts +97 -0
  182. package/src/planarCapture.ts +225 -0
  183. package/src/presentPass.ts +99 -0
  184. package/src/renderer.ts +1145 -0
  185. package/src/sceneAssets.ts +118 -0
  186. package/src/sceneUpload.ts +185 -0
  187. package/src/shaderModule.ts +19 -0
  188. package/src/shaderProgram.ts +1370 -0
  189. package/src/structLayout.ts +93 -0
  190. package/src/texturePack.ts +152 -0
  191. package/src/upstream.ts +56 -0
  192. package/src/volumetric.ts +42 -0
  193. package/src/wgsl/bsdf.wgsl.ts +618 -0
  194. package/src/wgsl/bvh.wgsl.ts +217 -0
  195. package/src/wgsl/common.wgsl.ts +193 -0
  196. package/src/wgsl/environment.wgsl.ts +144 -0
  197. package/src/wgsl/lights.wgsl.ts +433 -0
  198. package/src/wgsl/pathTrace.wgsl.ts +1019 -0
  199. package/src/wgsl/present.wgsl.ts +153 -0
  200. package/src/wgsl/random.wgsl.ts +90 -0
  201. package/src/wgsl/sampling.wgsl.ts +30 -0
  202. package/src/wgsl/shaderSupport.wgsl.ts +119 -0
  203. package/src/wgsl/surface.wgsl.ts +793 -0
  204. package/src/wgsl/texture.wgsl.ts +131 -0
package/dist/device.js ADDED
@@ -0,0 +1,52 @@
1
+ /** Acquiring a device, and the questions a host asks before choosing this renderer at all. */
2
+ /**
3
+ * Whether this context exposes WebGPU at all. It is a cheap, synchronous check for a fallback decision;
4
+ * it does not prove that an adapter exists, which only `requestWebGpuSupport` can tell.
5
+ */
6
+ export function isWebGpuAvailable() {
7
+ return typeof navigator !== "undefined" && "gpu" in navigator && navigator.gpu != null;
8
+ }
9
+ /**
10
+ * Asks the platform for an adapter, which is the only honest answer to "can this machine render?".
11
+ * A browser can expose `navigator.gpu` and still hand back no adapter (a blocklisted driver, a headless session
12
+ * without a software fallback), so hosts deciding between renderers should await this one.
13
+ */
14
+ export async function requestWebGpuSupport() {
15
+ if (!isWebGpuAvailable())
16
+ return { supported: false, reason: "This browser does not expose WebGPU." };
17
+ try {
18
+ const adapter = await navigator.gpu.requestAdapter();
19
+ if (!adapter)
20
+ return { supported: false, reason: "WebGPU is exposed, but no adapter was available." };
21
+ return { supported: true, reason: "" };
22
+ }
23
+ catch (error) {
24
+ return { supported: false, reason: `Requesting a WebGPU adapter failed: ${error.message}` };
25
+ }
26
+ }
27
+ /**
28
+ * The device the renderer runs on, asking for everything the adapter offers. Scene geometry, the hierarchy and the
29
+ * accumulation buffer all live in storage buffers, so the default 128 MiB binding size is the first ceiling a real
30
+ * scene meets, and adapters routinely allow far more.
31
+ */
32
+ export async function requestRenderDevice(options = {}) {
33
+ if (!isWebGpuAvailable())
34
+ throw new Error("GPU renderer: this browser does not expose WebGPU.");
35
+ const adapter = await navigator.gpu.requestAdapter({ powerPreference: "high-performance" });
36
+ if (!adapter)
37
+ throw new Error("GPU renderer: no WebGPU adapter was available.");
38
+ const device = await adapter.requestDevice({
39
+ requiredLimits: {
40
+ maxStorageBufferBindingSize: adapter.limits.maxStorageBufferBindingSize,
41
+ maxBufferSize: adapter.limits.maxBufferSize,
42
+ },
43
+ });
44
+ void device.lost.then(info => options.onLost?.(info.message || String(info.reason)));
45
+ return {
46
+ adapter,
47
+ device,
48
+ maxStorageBufferBindingSize: device.limits.maxStorageBufferBindingSize,
49
+ maxBufferSize: device.limits.maxBufferSize,
50
+ };
51
+ }
52
+ //# sourceMappingURL=device.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"device.js","sourceRoot":"","sources":["../src/device.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAuB9F;;;GAGG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,OAAO,SAAS,KAAK,WAAW,IAAI,KAAK,IAAI,SAAS,IAAI,SAAS,CAAC,GAAG,IAAI,IAAI,CAAC;AACzF,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB;IACxC,IAAI,CAAC,iBAAiB,EAAE;QACtB,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,sCAAsC,EAAE,CAAC;IAE9E,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC;QAErD,IAAI,CAAC,OAAO;YAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,kDAAkD,EAAE,CAAC;QAEtG,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IACzC,CAAC;IAAC,OAAM,KAAK,EAAE,CAAC;QACd,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,uCAAwC,KAAe,CAAC,OAAO,EAAE,EAAE,CAAC;IACzG,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,UAA+B,EAAE;IACzE,IAAI,CAAC,iBAAiB,EAAE;QACtB,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IAExE,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,eAAe,EAAE,kBAAkB,EAAE,CAAC,CAAC;IAE5F,IAAI,CAAC,OAAO;QACV,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IAEpE,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,aAAa,CAAC;QACzC,cAAc,EAAE;YACd,2BAA2B,EAAE,OAAO,CAAC,MAAM,CAAC,2BAA2B;YACvE,aAAa,EAAE,OAAO,CAAC,MAAM,CAAC,aAAa;SAC5C;KACF,CAAC,CAAC;IAEH,KAAK,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAErF,OAAO;QACL,OAAO;QACP,MAAM;QACN,2BAA2B,EAAE,MAAM,CAAC,MAAM,CAAC,2BAA2B;QACtE,aAAa,EAAE,MAAM,CAAC,MAAM,CAAC,aAAa;KAC3C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * How many rows of pixels one submit covers. The system watchdog kills a command that runs too long (around two
3
+ * seconds on Windows), and a tab that submits the whole image at once stops answering, so the work is cut into bands
4
+ * and the band grows or shrinks towards a target time per submit.
5
+ *
6
+ * The first band of a new scene is deliberately small: nothing is known about the machine yet, and a slow integrated
7
+ * GPU should discover that on a band it survives.
8
+ */
9
+ export interface DispatchSchedulerOptions {
10
+ /** Milliseconds one submit should take. */
11
+ targetMs?: number;
12
+ /** Rows the first submit covers, before anything has been measured. */
13
+ initialRows?: number;
14
+ /** Rows in the whole image. */
15
+ maxRows: number;
16
+ }
17
+ export declare class DispatchScheduler {
18
+ private readonly targetMs;
19
+ private readonly initialRows;
20
+ private readonly maxRows;
21
+ private rows;
22
+ /** Rows a millisecond, as far as anything has shown. Zero until the first submit says something. */
23
+ private throughput;
24
+ constructor(options: DispatchSchedulerOptions);
25
+ /** Rows the next submit should cover, never more than what is left. */
26
+ next(remaining: number): number;
27
+ /**
28
+ * Feeds back how long the last submit took, which moves the band towards the target time.
29
+ *
30
+ * What it estimates is a rate, not a direction. Every submit also costs a fixed round trip to the device, and on a
31
+ * small or simple image that round trip is most of what the clock sees. A rule that only asked whether the submit
32
+ * came back late would then read every band as too slow and shrink until each one covered a single row, which is the
33
+ * worst possible way to spend that round trip and is a hole it could never climb out of. A rate notices instead that
34
+ * a wider band cost no more, and widens.
35
+ *
36
+ * The rate is measured from the rows actually submitted rather than from the current guess, so one band clamped by
37
+ * what was left of the image does not stop the next one from growing.
38
+ */
39
+ record(durationMs: number, rows: number): void;
40
+ /** Back to the unmeasured band, for a new scene or a new size. */
41
+ reset(): void;
42
+ }
43
+ //# sourceMappingURL=dispatchScheduler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispatchScheduler.d.ts","sourceRoot":"","sources":["../src/dispatchScheduler.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WAAW,wBAAwB;IACvC,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uEAAuE;IACvE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;CACjB;AAOD,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,IAAI,CAAS;IACrB,oGAAoG;IACpG,OAAO,CAAC,UAAU,CAAK;gBAEX,OAAO,EAAE,wBAAwB;IAO7C,uEAAuE;IACvE,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAI/B;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAWvC,kEAAkE;IAClE,KAAK;CAIN"}
@@ -0,0 +1,49 @@
1
+ /** The most one measurement may widen the band, so an unmeasured machine meets the watchdog gradually. */
2
+ const GROW = 4;
3
+ /** How quickly the estimate gives ground when submits come back slower than they used to. */
4
+ const DECAY = 0.8;
5
+ export class DispatchScheduler {
6
+ targetMs;
7
+ initialRows;
8
+ maxRows;
9
+ rows;
10
+ /** Rows a millisecond, as far as anything has shown. Zero until the first submit says something. */
11
+ throughput = 0;
12
+ constructor(options) {
13
+ this.targetMs = options.targetMs ?? 12;
14
+ this.maxRows = Math.max(1, Math.floor(options.maxRows));
15
+ this.initialRows = Math.max(1, Math.min(this.maxRows, Math.floor(options.initialRows ?? 16)));
16
+ this.rows = this.initialRows;
17
+ }
18
+ /** Rows the next submit should cover, never more than what is left. */
19
+ next(remaining) {
20
+ return Math.max(1, Math.min(Math.floor(this.rows), Math.floor(remaining)));
21
+ }
22
+ /**
23
+ * Feeds back how long the last submit took, which moves the band towards the target time.
24
+ *
25
+ * What it estimates is a rate, not a direction. Every submit also costs a fixed round trip to the device, and on a
26
+ * small or simple image that round trip is most of what the clock sees. A rule that only asked whether the submit
27
+ * came back late would then read every band as too slow and shrink until each one covered a single row, which is the
28
+ * worst possible way to spend that round trip and is a hole it could never climb out of. A rate notices instead that
29
+ * a wider band cost no more, and widens.
30
+ *
31
+ * The rate is measured from the rows actually submitted rather than from the current guess, so one band clamped by
32
+ * what was left of the image does not stop the next one from growing.
33
+ */
34
+ record(durationMs, rows) {
35
+ if (!Number.isFinite(durationMs) || durationMs <= 0 || rows <= 0)
36
+ return;
37
+ const observed = rows / durationMs;
38
+ // Good news is believed at once, since it can only mean the band was cheaper than the clock suggested. Bad news
39
+ // is taken gradually, so one submit that happened to land behind something else does not collapse the band.
40
+ this.throughput = observed > this.throughput ? observed : this.throughput * DECAY + observed * (1 - DECAY);
41
+ this.rows = Math.max(1, Math.min(this.maxRows, rows * GROW, this.targetMs * this.throughput));
42
+ }
43
+ /** Back to the unmeasured band, for a new scene or a new size. */
44
+ reset() {
45
+ this.rows = this.initialRows;
46
+ this.throughput = 0;
47
+ }
48
+ }
49
+ //# sourceMappingURL=disp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E,OAAO;QAEzE,MAAM,QAAQ,GAAG,IAAI,GAAG,UAAU,CAAC;QAEnC,gHAAgH;QAChH,4GAA4G;QAC5G,IAAI,CAAC,UAAU,GAAG,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,GAAG,KAAK,GAAG,QAAQ,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;QAC3G,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,IAAI,EAAE,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAChG,CAAC;IAED,kEAAkE;IAClE,KAAK;QACH,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC;IACtB,CAAC;CACF"}
@@ -0,0 +1,39 @@
1
+ import type { RenderEnvironment, SerializedTexture } from "./upstream.js";
2
+ /**
3
+ * The light that surrounds the scene. A gradient is three numbers the shader evaluates directly; an equirectangular
4
+ * image is a texture plus the tables that let a shadow ray aim at its bright parts.
5
+ *
6
+ * Without those tables a sun in an image is exactly the problem direct light sampling exists to solve: a tiny, very
7
+ * bright region that a cosine weighted bounce almost never finds. The construction is the one in `environment.js` of
8
+ * the CPU renderer: a cumulative distribution over rows weighted by luminance and the sine of the colatitude, then one
9
+ * over the columns of each row.
10
+ */
11
+ export interface PackedEnvironment {
12
+ /** The image itself, ready to join the scene's own textures. */
13
+ texture: SerializedTexture;
14
+ /** Rows, then each row's columns, then the luminance of every texel: `2 * width * height + height` floats. */
15
+ distribution: Float32Array;
16
+ width: number;
17
+ height: number;
18
+ /** The sum of luminance times the sine of the colatitude, which turns a texel's share into a density. */
19
+ total: number;
20
+ }
21
+ /**
22
+ * Cumulative distributions over the reduced image. A row is weighted by the sine of its colatitude, because a row near
23
+ * a pole covers far less of the sphere than one at the equator.
24
+ */
25
+ export declare function environmentDistribution(grid: Float32Array, width: number, height: number): {
26
+ distribution: Float32Array<ArrayBuffer>;
27
+ total: number;
28
+ } | null;
29
+ /**
30
+ * Loads an equirectangular image and builds everything the shader needs from it. Returns null for an environment that
31
+ * is not an image, or one whose file could not be read, which leaves the renderer on its gradient.
32
+ */
33
+ export declare function loadEnvironment(environment: RenderEnvironment): Promise<PackedEnvironment | null>;
34
+ /**
35
+ * An equirectangular image already in memory, linear RGBA floats with the zenith in the first row, made into an
36
+ * environment: a procedural sky baked by the CPU renderer's interpreter arrives this way.
37
+ */
38
+ export declare function environmentFromImage(data: Float32Array, sourceWidth: number, sourceHeight: number, id?: string): PackedEnvironment | null;
39
+ //# sourceMappingURL=environment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE1E;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB;IAChC,gEAAgE;IAChE,OAAO,EAAE,iBAAiB,CAAC;IAC3B,8GAA8G;IAC9G,YAAY,EAAE,YAAY,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,yGAAyG;IACzG,KAAK,EAAE,MAAM,CAAC;CACf;AAsFD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;SAuCxF;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAC,WAAW,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAqBvG;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,SAAgB,GAAG,iBAAiB,GAAG,IAAI,CAgD7G"}
@@ -0,0 +1,168 @@
1
+ import { HDRLoader } from "three/examples/jsm/loaders/HDRLoader.js";
2
+ /** The grid the distribution is built on, as in the CPU renderer. Finer than this buys nothing but memory. */
3
+ const GRID_WIDTH = 256;
4
+ const GRID_HEIGHT = 128;
5
+ /** How large an image is kept for the sharp lookup. A full resolution sky costs more memory than it adds detail here. */
6
+ const MAX_WIDTH = 1024;
7
+ const luminance = (r, g, b) => 0.2126 * r + 0.7152 * g + 0.0722 * b;
8
+ /** An area averaged reduction to `width` by `height`, which is what the distribution is built from. */
9
+ function reduce(source, sourceWidth, sourceHeight, width, height) {
10
+ const target = new Float32Array(width * height * 3);
11
+ const scaleX = sourceWidth / width, scaleY = sourceHeight / height;
12
+ for (let y = 0; y < height; y++) {
13
+ for (let x = 0; x < width; x++) {
14
+ const x0 = Math.floor(x * scaleX), x1 = Math.max(x0 + 1, Math.ceil((x + 1) * scaleX));
15
+ const y0 = Math.floor(y * scaleY), y1 = Math.max(y0 + 1, Math.ceil((y + 1) * scaleY));
16
+ let r = 0, g = 0, b = 0, n = 0;
17
+ for (let sy = y0; sy < Math.min(sourceHeight, y1); sy++) {
18
+ for (let sx = x0; sx < Math.min(sourceWidth, x1); sx++) {
19
+ const at = (sy * sourceWidth + sx) * 4;
20
+ r += source[at];
21
+ g += source[at + 1];
22
+ b += source[at + 2];
23
+ n++;
24
+ }
25
+ }
26
+ const at = (y * width + x) * 3;
27
+ const weight = n || 1;
28
+ target[at] = r / weight;
29
+ target[at + 1] = g / weight;
30
+ target[at + 2] = b / weight;
31
+ }
32
+ }
33
+ return target;
34
+ }
35
+ /** Never picked less often than this share of the average, so no direction is left without a density. */
36
+ const FLOOR = 0.02;
37
+ /**
38
+ * The luminance a direction is picked by. It is the neighbourhood's brightest rather than the texel's own, because the
39
+ * image is read back with a bilinear filter: that filter spreads a sun into the texels around it, and a direction the
40
+ * distribution gave no chance of being picked would arrive through the bounce alone, as a firefly. Taking the maximum
41
+ * over the neighbours keeps the density above what the filter can produce there.
42
+ */
43
+ function weights(grid, width, height) {
44
+ const raw = new Float32Array(width * height);
45
+ const spread = new Float32Array(width * height);
46
+ let sum = 0;
47
+ for (let index = 0; index < width * height; index++) {
48
+ raw[index] = luminance(grid[index * 3], grid[index * 3 + 1], grid[index * 3 + 2]);
49
+ sum += raw[index];
50
+ }
51
+ const floor = sum / (width * height) * FLOOR;
52
+ for (let y = 0; y < height; y++) {
53
+ for (let x = 0; x < width; x++) {
54
+ let peak = 0;
55
+ for (let dy = -1; dy <= 1; dy++) {
56
+ const row = Math.min(Math.max(y + dy, 0), height - 1);
57
+ for (let dx = -1; dx <= 1; dx++) {
58
+ // Longitude wraps around, so the texel left of the first column is the last one.
59
+ peak = Math.max(peak, raw[row * width + (x + dx + width) % width]);
60
+ }
61
+ }
62
+ spread[y * width + x] = peak + floor;
63
+ }
64
+ }
65
+ return spread;
66
+ }
67
+ /**
68
+ * Cumulative distributions over the reduced image. A row is weighted by the sine of its colatitude, because a row near
69
+ * a pole covers far less of the sphere than one at the equator.
70
+ */
71
+ export function environmentDistribution(grid, width, height) {
72
+ const rows = new Float32Array(height);
73
+ const columns = new Float32Array(width * height);
74
+ const values = weights(grid, width, height);
75
+ let total = 0;
76
+ for (let y = 0; y < height; y++) {
77
+ const sine = Math.sin((y + 0.5) / height * Math.PI);
78
+ let row = 0;
79
+ for (let x = 0; x < width; x++) {
80
+ const index = y * width + x;
81
+ row += values[index] * sine;
82
+ columns[index] = row;
83
+ }
84
+ for (let x = 0; x < width; x++) {
85
+ const index = y * width + x;
86
+ // A row with nothing in it is still chosen uniformly, so a search over it always terminates somewhere.
87
+ columns[index] = row > 0 ? columns[index] / row : (x + 1) / width;
88
+ }
89
+ total += row;
90
+ rows[y] = total;
91
+ }
92
+ if (!(total > 0))
93
+ return null;
94
+ for (let y = 0; y < height; y++)
95
+ rows[y] /= total;
96
+ const distribution = new Float32Array(height + width * height * 2);
97
+ distribution.set(rows, 0);
98
+ distribution.set(columns, height);
99
+ distribution.set(values, height + width * height);
100
+ return { distribution, total };
101
+ }
102
+ /**
103
+ * Loads an equirectangular image and builds everything the shader needs from it. Returns null for an environment that
104
+ * is not an image, or one whose file could not be read, which leaves the renderer on its gradient.
105
+ */
106
+ export async function loadEnvironment(environment) {
107
+ if (environment.kind !== "hdri" || !environment.url)
108
+ return null;
109
+ const loaded = await new Promise(resolve => {
110
+ new HDRLoader()
111
+ .setDataType(1015)
112
+ .load(environment.url, texture => {
113
+ const image = texture.image;
114
+ resolve(image?.data instanceof Float32Array ? image : null);
115
+ texture.dispose();
116
+ }, undefined, () => resolve(null));
117
+ });
118
+ if (!loaded || loaded.width < 1 || loaded.height < 1)
119
+ return null;
120
+ return environmentFromImage(loaded.data, loaded.width, loaded.height);
121
+ }
122
+ /**
123
+ * An equirectangular image already in memory, linear RGBA floats with the zenith in the first row, made into an
124
+ * environment: a procedural sky baked by the CPU renderer's interpreter arrives this way.
125
+ */
126
+ export function environmentFromImage(data, sourceWidth, sourceHeight, id = "environment") {
127
+ const loaded = { data, width: sourceWidth, height: sourceHeight };
128
+ if (loaded.width < 1 || loaded.height < 1 || data.length < loaded.width * loaded.height * 4)
129
+ return null;
130
+ // The sharp lookup keeps at most MAX_WIDTH across; the distribution is built on a much coarser grid either way.
131
+ const width = Math.min(loaded.width, MAX_WIDTH);
132
+ const height = Math.max(1, Math.round(loaded.height * (width / loaded.width)));
133
+ const scaled = width === loaded.width
134
+ ? loaded.data
135
+ : (() => {
136
+ const reduced = reduce(loaded.data, loaded.width, loaded.height, width, height);
137
+ const rgba = new Float32Array(width * height * 4);
138
+ for (let texel = 0; texel < width * height; texel++) {
139
+ rgba[texel * 4] = reduced[texel * 3];
140
+ rgba[texel * 4 + 1] = reduced[texel * 3 + 1];
141
+ rgba[texel * 4 + 2] = reduced[texel * 3 + 2];
142
+ rgba[texel * 4 + 3] = 1;
143
+ }
144
+ return rgba;
145
+ })();
146
+ const gridWidth = Math.min(GRID_WIDTH, width);
147
+ const gridHeight = Math.min(GRID_HEIGHT, height);
148
+ const built = environmentDistribution(reduce(scaled, width, height, gridWidth, gridHeight), gridWidth, gridHeight);
149
+ if (!built)
150
+ return null;
151
+ const texture = {
152
+ id,
153
+ width,
154
+ height,
155
+ data: scaled,
156
+ // An HDR file is linear already, and the loader hands back floats.
157
+ colorSpace: "srgb-linear",
158
+ // Longitude wraps around; latitude stops at the poles.
159
+ wrapS: 1000,
160
+ wrapT: 1001,
161
+ matrix: [1, 0, 0, 0, 1, 0, 0, 0, 1],
162
+ flipY: false,
163
+ channel: 0,
164
+ nearest: false,
165
+ };
166
+ return { texture, distribution: built.distribution, width: gridWidth, height: gridHeight, total: built.total };
167
+ }
168
+ //# sourceMappingURL=environment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"environment.js","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAuBpE,8GAA8G;AAC9G,MAAM,UAAU,GAAG,GAAG,CAAC;AACvB,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB,yHAAyH;AACzH,MAAM,SAAS,GAAG,IAAI,CAAC;AAEvB,MAAM,SAAS,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS,EAAE,EAAE,CAAC,MAAM,GAAG,CAAC,GAAG,MAAM,GAAG,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC;AAE5F,uGAAuG;AACvG,SAAS,MAAM,CAAC,MAAoB,EAAE,WAAmB,EAAE,YAAoB,EAAE,KAAa,EAAE,MAAc;IAC5G,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC;IACpD,MAAM,MAAM,GAAG,WAAW,GAAG,KAAK,EAAE,MAAM,GAAG,YAAY,GAAG,MAAM,CAAC;IAEnE,KAAK,IA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the device see it. */
2
+ export declare const FRAME_LAYOUT: import("./structLayout.js").StructLayout;
3
+ export declare const FRAME_WORDS: number;
4
+ //# sourceMappingURL=frameLayout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frameLayout.d.ts","sourceRoot":"","sources":["../src/frameLayout.ts"],"names":[],"mappings":"AAEA,6EAA6E;AAC7E,eAAO,MAAM,YAAY,0CAqDvB,CAAC;AAEH,eAAO,MAAM,WAAW,QAAqB,CAAC"}
@@ -0,0 +1,58 @@
1
+ import { layoutStruct } from "./structLayout.js";
2
+ /** The kernel's per dispatch uniform, as both sides of the device see it. */
3
+ export const FRAME_LAYOUT = layoutStruct("Frame", [
4
+ { name: "cameraToWorld", type: "mat4f" },
5
+ { name: "worldToCamera", type: "mat4f" },
6
+ { name: "projection", type: "mat4f" },
7
+ { name: "inverseProjection", type: "mat4f", doc: "Clip space to view space: every camera ray goes through it." },
8
+ { name: "environmentTop", type: "vec4f", doc: "rgb is the colour at the top of the gradient, w its exponent." },
9
+ { name: "environmentBottom", type: "vec4f", doc: "rgb is the colour at the bottom, w the environment's strength." },
10
+ { name: "ambientSky", type: "vec4f", doc: "An ambient or hemisphere light, as radiance along the axis and against it." },
11
+ { name: "ambientGround", type: "vec4f" },
12
+ { name: "ambientAxis", type: "vec4f" },
13
+ ...Array.from({ length: 9 }, (_, k) => ({
14
+ name: `probe${k}`,
15
+ type: "vec4f",
16
+ doc: k === 0 ? "Light probes: Three's nine spherical harmonic coefficients of radiance, summed." : undefined,
17
+ })),
18
+ { name: "fogColor", type: "vec4f", doc: "rgb is the fog colour, w its kind: 0 none, 1 linear, 2 exponential squared." },
19
+ { name: "fogParams", type: "vec4f", doc: "near, far, density, and 1 when the fog covers every surface." },
20
+ { name: "background", type: "vec4f", doc: "rgb is the colour, w the mode: 0 environment, 1 colour, 2 transparent." },
21
+ { name: "lens", type: "vec4f", doc: "Lens radius, focus distance, blade count; a radius of zero is a pinhole." },
22
+ { name: "resolution", type: "vec2u" },
23
+ { name: "bandOrigin", type: "vec2u" },
24
+ { name: "bandSize", type: "vec2u" },
25
+ { name: "sampleIndex", type: "u32" },
26
+ { name: "sampleCount", type: "u32" },
27
+ { name: "cameraKind", type: "u32", doc: "0 perspective, 1 orthographic." },
28
+ { name: "bounces", type: "u32" },
29
+ { name: "triangleCount", type: "u32" },
30
+ { name: "lightCount", type: "u32" },
31
+ { name: "areaLightCount", type: "u32", doc: "How many leading lights are emissive triangles." },
32
+ { name: "clampIndirect", type: "f32", doc: "Maximum luminance one indirect contribution may add; zero leaves it." },
33
+ { name: "shadowSpread", type: "f32", doc: "Tangent of half the angular diameter shadow rays spread over." },
34
+ { name: "shadowsEnabled", type: "u32" },
35
+ { name: "uvOffset", type: "u32", doc: "Where the UV sets start inside the attribute buffer." },
36
+ { name: "orderOffset", type: "u32", doc: "Where the hierarchy's triangle order starts inside the index buffer." },
37
+ { name: "colorOffset", type: "u32", doc: "Where vertex colours start inside the attribute buffer." },
38
+ { name: "hasColors", type: "u32" },
39
+ { name: "varyingOffset", type: "u32", doc: "Where shader varyings start inside the attribute buffer." },
40
+ { name: "environmentTexture", type: "u32", doc: "The surrounding image, or NO_TEXTURE for the gradient." },
41
+ { name: "environmentCdf", type: "u32" },
42
+ { name: "environmentCdfSize", type: "vec2u" },
43
+ { name: "environmentTotal", type: "f32" },
44
+ { name: "environmentRotation", type: "f32" },
45
+ { name: "environmentPick", type: "f32", doc: "How often direct sampling picks the environment over a light." },
46
+ { name: "skyProgram", type: "u32", doc: "A procedural sky's foreground program, or NO_PROGRAM." },
47
+ { name: "skyData", type: "u32" },
48
+ { name: "skyBackground", type: "u32", doc: "Whether a procedural sky paints the background (1) or leaves it black (0)." },
49
+ { name: "skyIntensity", type: "f32", doc: "The strength a procedural sky lights with, which its background ignores." },
50
+ { name: "pixelCount", type: "u32", doc: "Where the alpha half of the accumulation buffer starts." },
51
+ { name: "volumetricCount", type: "u32", doc: "Lights that scatter in the air, and where their records start." },
52
+ { name: "volumetricData", type: "u32" },
53
+ { name: "adaptiveMin", type: "u32", doc: "Samples a pixel takes before it may stop as converged; 0 never stops." },
54
+ { name: "adaptiveThreshold", type: "f32", doc: "The error under which a pixel and its neighbours count as converged." },
55
+ { name: "clipPlane", type: "vec4f", doc: "A plane the camera ray drops surfaces behind, for planar captures; w = 0 and xyz = 0 is none." },
56
+ ]);
57
+ export const FRAME_WORDS = FRAME_LAYOUT.words;
58
+ //# sourceMappingURL=frameLayout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frameLayout.js","sourceRoot":"","sources":["../src/frameLayout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,6EAA6E;AAC7E,MAAM,CAAC,MAAM,YAAY,GAAG,YAAY,CAAC,OAAO,EAAE;IAChD,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,OAAO,EAAE;IACxC,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,OAAO,EAAE;IACxC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE;IACrC,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,6DAA6D,EAAE;IAChH,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,+DAA+D,EAAE;IAC/G,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,gEAAgE,EAAE;IACnH,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,4EAA4E,EAAE;IACxH,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,OAAO,EAAE;IACxC,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,OAAO,EAAE;IACtC,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,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EAAE,eAAe,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,4EAA4E,EAAE;IACzH,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,0EAA0E,EAAE;IACtH,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,yDAAyD,EAAE;IACnG,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,gEAAgE,EAAE;IAC/G,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,KAAK,EAAE;IACvC,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,uEAAuE,EAAE;IAClH,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,sEAAsE,EAAE;IACvH,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,+FAA+F,EAAE;CAC3I,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,YAAY,CAAC,KAAK,CAAC"}
@@ -0,0 +1,75 @@
1
+ import { type CameraMatrices } from "./camera.js";
2
+ import { NO_PROGRAM, type MaterialPlacement, type MaterialProperties } from "./materialLayout.js";
3
+ import type { ShaderPrograms } from "./shaderProgram.js";
4
+ import type { SerializedMesh, SerializedScene, SerializedTexture, UniformValue } from "./upstream.js";
5
+ /** The flat, GPU ready form of a scene's triangles. Positions and normals are world space, three vertices per entry. */
6
+ export interface PackedGeometry {
7
+ /** Nine coordinates per triangle. */
8
+ positions: Float32Array;
9
+ /** Nine normal components per triangle, one per vertex. */
10
+ normals: Float32Array;
11
+ /** Twelve per triangle: two UV sets for each of the three vertices, which is what Three's map channels need. */
12
+ uvs: Float32Array;
13
+ /** Twelve per triangle, RGBA per vertex, when any material reads vertex colours; empty otherwise. */
14
+ colors: Float32Array;
15
+ /** Shader varyings, three corners per triangle of a shader material, laid out as each program asks. */
16
+ varyings: Float32Array;
17
+ /** One material index per triangle. */
18
+ materials: Uint32Array;
19
+ triangleCount: number;
20
+ /** Four floats per material: linear rgb and opacity. */
21
+ materialColors: Float32Array;
22
+ /** Four floats per material: linear emissive rgb and its intensity. */
23
+ materialEmissive: Float32Array;
24
+ /** Every material of the scene, resolved, in the order the triangle indices refer to them. */
25
+ materialProperties: MaterialProperties[];
26
+ /** The mesh specific half of each material entry. */
27
+ materialPlacements: MaterialPlacement[];
28
+ materialCount: number;
29
+ /** Words the materials keep in the texture buffer: clipping planes and shader uniforms. */
30
+ extraWords: Uint32Array;
31
+ /**
32
+ * Whether the triangles depend on the camera: points, lines and sprites face it, and a vertex shader projects through
33
+ * it. Such a scene is packed again whenever the camera or the image size changes.
34
+ */
35
+ cameraDependent: boolean;
36
+ }
37
+ export interface PackOptions {
38
+ /** The index in the texture table of each texture, by id. */
39
+ textures?: ReadonlyMap<string, number>;
40
+ /** The textures themselves, for the work done here on the CPU: displacement maps and vertex shaders. */
41
+ textureData?: ReadonlyMap<string, SerializedTexture>;
42
+ /** The camera and image size points, lines, sprites and vertex shaders are built for. */
43
+ camera?: CameraMatrices;
44
+ width?: number;
45
+ height?: number;
46
+ /** Translated fragment shaders, for the materials that have one. */
47
+ programs?: ShaderPrograms;
48
+ /** Where the extra words will start in the texture buffer, so the materials can point at them absolutely. */
49
+ extraBase?: number;
50
+ /** Scene fog, which a shader's fog uniforms read. */
51
+ fog?: SerializedScene["fog"];
52
+ }
53
+ /** The uniforms Three sets on every shader for this camera and mesh. */
54
+ export declare function builtinUniforms(camera: CameraMatrices | undefined, matrixWorld: readonly number[], fog?: SerializedScene["fog"]): Record<string, UniformValue>;
55
+ /**
56
+ * Flattens the scene into triangles, materials resolved and transforms applied. Every triangle carries its own three
57
+ * vertices: the path tracer reads a hit through its triangle index, and sharing vertices would cost an indirection on
58
+ * the hottest path of the kernel for memory that low poly scenes do not miss.
59
+ *
60
+ * Points, lines and sprites become triangles that face the camera, sized the way Three draws them, so a path has a
61
+ * surface to find; vertex shaders run here, on the CPU renderer's interpreter, and their varyings ride along per corner.
62
+ */
63
+ export declare function packGeometry(scene: SerializedScene, options?: PackOptions | ReadonlyMap<string, number>): PackedGeometry;
64
+ /**
65
+ * The attributes of an instanced geometry, which the snapshot keeps as plain attributes with one element per instance
66
+ * rather than per vertex, and how many instances there are.
67
+ */
68
+ export declare function instancedAttributes(mesh: SerializedMesh): {
69
+ names: Set<string>;
70
+ count: number;
71
+ } | null;
72
+ /** Flat shading for geometry that arrives without normals: the three vertices share the face normal. */
73
+ export declare function faceNormal(a: readonly number[], b: readonly number[], c: readonly number[]): number[];
74
+ export { NO_PROGRAM };
75
+ //# sourceMappingURL=geometry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../src/geometry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AACxF,OAAO,EAKL,UAAU,EACV,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACxB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,KAAK,EAAsB,cAAc,EAAE,eAAe,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE1H,wHAAwH;AACxH,MAAM,WAAW,cAAc;IAC7B,qCAAqC;IACrC,SAAS,EAAE,YAAY,CAAC;IACxB,2DAA2D;IAC3D,OAAO,EAAE,YAAY,CAAC;IACtB,gHAAgH;IAChH,GAAG,EAAE,YAAY,CAAC;IAClB,qGAAqG;IACrG,MAAM,EAAE,YAAY,CAAC;IACrB,uGAAuG;IACvG,QAAQ,EAAE,YAAY,CAAC;IACvB,uCAAuC;IACvC,SAAS,EAAE,WAAW,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,wDAAwD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