@aura3d/rendering 1.0.6

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 (1433) hide show
  1. package/README.md +18 -0
  2. package/dist/ArchitecturalLightingFixtures.d.ts +40 -0
  3. package/dist/ArchitecturalLightingFixtures.d.ts.map +1 -0
  4. package/dist/ArchitecturalLightingFixtures.js +171 -0
  5. package/dist/ArchitecturalLightingFixtures.js.map +1 -0
  6. package/dist/ArchitecturalMaterialCatalog.d.ts +30 -0
  7. package/dist/ArchitecturalMaterialCatalog.d.ts.map +1 -0
  8. package/dist/ArchitecturalMaterialCatalog.js +90 -0
  9. package/dist/ArchitecturalMaterialCatalog.js.map +1 -0
  10. package/dist/ArchitecturalMeasurementFixtures.d.ts +30 -0
  11. package/dist/ArchitecturalMeasurementFixtures.d.ts.map +1 -0
  12. package/dist/ArchitecturalMeasurementFixtures.js +115 -0
  13. package/dist/ArchitecturalMeasurementFixtures.js.map +1 -0
  14. package/dist/BRDFLut.d.ts +13 -0
  15. package/dist/BRDFLut.d.ts.map +1 -0
  16. package/dist/BRDFLut.js +34 -0
  17. package/dist/BRDFLut.js.map +1 -0
  18. package/dist/CameraFraming.d.ts +31 -0
  19. package/dist/CameraFraming.d.ts.map +1 -0
  20. package/dist/CameraFraming.js +143 -0
  21. package/dist/CameraFraming.js.map +1 -0
  22. package/dist/CanonicalSceneFixtures.d.ts +13 -0
  23. package/dist/CanonicalSceneFixtures.d.ts.map +1 -0
  24. package/dist/CanonicalSceneFixtures.js +78 -0
  25. package/dist/CanonicalSceneFixtures.js.map +1 -0
  26. package/dist/CascadedShadowMaps.d.ts +121 -0
  27. package/dist/CascadedShadowMaps.d.ts.map +1 -0
  28. package/dist/CascadedShadowMaps.js +315 -0
  29. package/dist/CascadedShadowMaps.js.map +1 -0
  30. package/dist/ColorManagement.d.ts +33 -0
  31. package/dist/ColorManagement.d.ts.map +1 -0
  32. package/dist/ColorManagement.js +71 -0
  33. package/dist/ColorManagement.js.map +1 -0
  34. package/dist/CullingFixtures.d.ts +70 -0
  35. package/dist/CullingFixtures.d.ts.map +1 -0
  36. package/dist/CullingFixtures.js +191 -0
  37. package/dist/CullingFixtures.js.map +1 -0
  38. package/dist/DecalGeometry.d.ts +3 -0
  39. package/dist/DecalGeometry.d.ts.map +1 -0
  40. package/dist/DecalGeometry.js +2 -0
  41. package/dist/DecalGeometry.js.map +1 -0
  42. package/dist/DepthPass.d.ts +23 -0
  43. package/dist/DepthPass.d.ts.map +1 -0
  44. package/dist/DepthPass.js +99 -0
  45. package/dist/DepthPass.js.map +1 -0
  46. package/dist/EnvironmentBackgroundPass.d.ts +27 -0
  47. package/dist/EnvironmentBackgroundPass.d.ts.map +1 -0
  48. package/dist/EnvironmentBackgroundPass.js +167 -0
  49. package/dist/EnvironmentBackgroundPass.js.map +1 -0
  50. package/dist/EnvironmentBackgroundResources.d.ts +31 -0
  51. package/dist/EnvironmentBackgroundResources.d.ts.map +1 -0
  52. package/dist/EnvironmentBackgroundResources.js +237 -0
  53. package/dist/EnvironmentBackgroundResources.js.map +1 -0
  54. package/dist/EnvironmentLighting.d.ts +10 -0
  55. package/dist/EnvironmentLighting.d.ts.map +1 -0
  56. package/dist/EnvironmentLighting.js +64 -0
  57. package/dist/EnvironmentLighting.js.map +1 -0
  58. package/dist/EnvironmentMapResources.d.ts +98 -0
  59. package/dist/EnvironmentMapResources.d.ts.map +1 -0
  60. package/dist/EnvironmentMapResources.js +794 -0
  61. package/dist/EnvironmentMapResources.js.map +1 -0
  62. package/dist/EnvironmentPipeline.d.ts +21 -0
  63. package/dist/EnvironmentPipeline.d.ts.map +1 -0
  64. package/dist/EnvironmentPipeline.js +43 -0
  65. package/dist/EnvironmentPipeline.js.map +1 -0
  66. package/dist/EnvironmentPlatform.d.ts +185 -0
  67. package/dist/EnvironmentPlatform.d.ts.map +1 -0
  68. package/dist/EnvironmentPlatform.js +922 -0
  69. package/dist/EnvironmentPlatform.js.map +1 -0
  70. package/dist/EnvironmentPreset.d.ts +35 -0
  71. package/dist/EnvironmentPreset.d.ts.map +1 -0
  72. package/dist/EnvironmentPreset.js +96 -0
  73. package/dist/EnvironmentPreset.js.map +1 -0
  74. package/dist/Exposure.d.ts +19 -0
  75. package/dist/Exposure.d.ts.map +1 -0
  76. package/dist/Exposure.js +34 -0
  77. package/dist/Exposure.js.map +1 -0
  78. package/dist/ExternalParityRenderPreset.d.ts +149 -0
  79. package/dist/ExternalParityRenderPreset.d.ts.map +1 -0
  80. package/dist/ExternalParityRenderPreset.js +519 -0
  81. package/dist/ExternalParityRenderPreset.js.map +1 -0
  82. package/dist/ForwardPass.d.ts +122 -0
  83. package/dist/ForwardPass.d.ts.map +1 -0
  84. package/dist/ForwardPass.js +1352 -0
  85. package/dist/ForwardPass.js.map +1 -0
  86. package/dist/FrameVisualMetrics.d.ts +60 -0
  87. package/dist/FrameVisualMetrics.d.ts.map +1 -0
  88. package/dist/FrameVisualMetrics.js +146 -0
  89. package/dist/FrameVisualMetrics.js.map +1 -0
  90. package/dist/Geometry.d.ts +50 -0
  91. package/dist/Geometry.d.ts.map +1 -0
  92. package/dist/Geometry.js +385 -0
  93. package/dist/Geometry.js.map +1 -0
  94. package/dist/GeometryPrimitives.d.ts +3 -0
  95. package/dist/GeometryPrimitives.d.ts.map +1 -0
  96. package/dist/GeometryPrimitives.js +2 -0
  97. package/dist/GeometryPrimitives.js.map +1 -0
  98. package/dist/HDRRenderPipeline.d.ts +27 -0
  99. package/dist/HDRRenderPipeline.d.ts.map +1 -0
  100. package/dist/HDRRenderPipeline.js +67 -0
  101. package/dist/HDRRenderPipeline.js.map +1 -0
  102. package/dist/IBL.d.ts +37 -0
  103. package/dist/IBL.d.ts.map +1 -0
  104. package/dist/IBL.js +48 -0
  105. package/dist/IBL.js.map +1 -0
  106. package/dist/IndexBuffer.d.ts +15 -0
  107. package/dist/IndexBuffer.d.ts.map +1 -0
  108. package/dist/IndexBuffer.js +51 -0
  109. package/dist/IndexBuffer.js.map +1 -0
  110. package/dist/InstancedPBRMaterial.d.ts +33 -0
  111. package/dist/InstancedPBRMaterial.d.ts.map +1 -0
  112. package/dist/InstancedPBRMaterial.js +147 -0
  113. package/dist/InstancedPBRMaterial.js.map +1 -0
  114. package/dist/InstancedUnlitMaterial.d.ts +11 -0
  115. package/dist/InstancedUnlitMaterial.d.ts.map +1 -0
  116. package/dist/InstancedUnlitMaterial.js +50 -0
  117. package/dist/InstancedUnlitMaterial.js.map +1 -0
  118. package/dist/Instancing.d.ts +7 -0
  119. package/dist/Instancing.d.ts.map +1 -0
  120. package/dist/Instancing.js +14 -0
  121. package/dist/Instancing.js.map +1 -0
  122. package/dist/LightCollector.d.ts +24 -0
  123. package/dist/LightCollector.d.ts.map +1 -0
  124. package/dist/LightCollector.js +56 -0
  125. package/dist/LightCollector.js.map +1 -0
  126. package/dist/LightUniforms.d.ts +14 -0
  127. package/dist/LightUniforms.d.ts.map +1 -0
  128. package/dist/LightUniforms.js +37 -0
  129. package/dist/LightUniforms.js.map +1 -0
  130. package/dist/LightingDebug.d.ts +13 -0
  131. package/dist/LightingDebug.d.ts.map +1 -0
  132. package/dist/LightingDebug.js +69 -0
  133. package/dist/LightingDebug.js.map +1 -0
  134. package/dist/LightingDefaults.d.ts +13 -0
  135. package/dist/LightingDefaults.d.ts.map +1 -0
  136. package/dist/LightingDefaults.js +64 -0
  137. package/dist/LightingDefaults.js.map +1 -0
  138. package/dist/LightingRig.d.ts +53 -0
  139. package/dist/LightingRig.d.ts.map +1 -0
  140. package/dist/LightingRig.js +197 -0
  141. package/dist/LightingRig.js.map +1 -0
  142. package/dist/LineGeometry.d.ts +3 -0
  143. package/dist/LineGeometry.d.ts.map +1 -0
  144. package/dist/LineGeometry.js +2 -0
  145. package/dist/LineGeometry.js.map +1 -0
  146. package/dist/Material.d.ts +77 -0
  147. package/dist/Material.d.ts.map +1 -0
  148. package/dist/Material.js +137 -0
  149. package/dist/Material.js.map +1 -0
  150. package/dist/MaterialBinding.d.ts +17 -0
  151. package/dist/MaterialBinding.d.ts.map +1 -0
  152. package/dist/MaterialBinding.js +119 -0
  153. package/dist/MaterialBinding.js.map +1 -0
  154. package/dist/MaterialInstance.d.ts +16 -0
  155. package/dist/MaterialInstance.d.ts.map +1 -0
  156. package/dist/MaterialInstance.js +53 -0
  157. package/dist/MaterialInstance.js.map +1 -0
  158. package/dist/MaterialPresets.d.ts +31 -0
  159. package/dist/MaterialPresets.d.ts.map +1 -0
  160. package/dist/MaterialPresets.js +219 -0
  161. package/dist/MaterialPresets.js.map +1 -0
  162. package/dist/MorphTarget.d.ts +10 -0
  163. package/dist/MorphTarget.d.ts.map +1 -0
  164. package/dist/MorphTarget.js +101 -0
  165. package/dist/MorphTarget.js.map +1 -0
  166. package/dist/MorphUnlitMaterial.d.ts +11 -0
  167. package/dist/MorphUnlitMaterial.d.ts.map +1 -0
  168. package/dist/MorphUnlitMaterial.js +45 -0
  169. package/dist/MorphUnlitMaterial.js.map +1 -0
  170. package/dist/NormalMappedPBRMaterial.d.ts +37 -0
  171. package/dist/NormalMappedPBRMaterial.d.ts.map +1 -0
  172. package/dist/NormalMappedPBRMaterial.js +148 -0
  173. package/dist/NormalMappedPBRMaterial.js.map +1 -0
  174. package/dist/OceanFixtures.d.ts +62 -0
  175. package/dist/OceanFixtures.d.ts.map +1 -0
  176. package/dist/OceanFixtures.js +240 -0
  177. package/dist/OceanFixtures.js.map +1 -0
  178. package/dist/PBRLightingDefaults.d.ts +4 -0
  179. package/dist/PBRLightingDefaults.d.ts.map +1 -0
  180. package/dist/PBRLightingDefaults.js +10 -0
  181. package/dist/PBRLightingDefaults.js.map +1 -0
  182. package/dist/PBRMaterial.d.ts +84 -0
  183. package/dist/PBRMaterial.d.ts.map +1 -0
  184. package/dist/PBRMaterial.js +349 -0
  185. package/dist/PBRMaterial.js.map +1 -0
  186. package/dist/PMREM.d.ts +26 -0
  187. package/dist/PMREM.d.ts.map +1 -0
  188. package/dist/PMREM.js +26 -0
  189. package/dist/PMREM.js.map +1 -0
  190. package/dist/PbrReference.d.ts +153 -0
  191. package/dist/PbrReference.d.ts.map +1 -0
  192. package/dist/PbrReference.js +500 -0
  193. package/dist/PbrReference.js.map +1 -0
  194. package/dist/PostProcessPass.d.ts +439 -0
  195. package/dist/PostProcessPass.d.ts.map +1 -0
  196. package/dist/PostProcessPass.js +1834 -0
  197. package/dist/PostProcessPass.js.map +1 -0
  198. package/dist/ProceduralTextureFixtures.d.ts +27 -0
  199. package/dist/ProceduralTextureFixtures.d.ts.map +1 -0
  200. package/dist/ProceduralTextureFixtures.js +336 -0
  201. package/dist/ProceduralTextureFixtures.js.map +1 -0
  202. package/dist/ProductTurntableFixtures.d.ts +96 -0
  203. package/dist/ProductTurntableFixtures.d.ts.map +1 -0
  204. package/dist/ProductTurntableFixtures.js +559 -0
  205. package/dist/ProductTurntableFixtures.js.map +1 -0
  206. package/dist/Raycaster.d.ts +14 -0
  207. package/dist/Raycaster.d.ts.map +1 -0
  208. package/dist/Raycaster.js +10 -0
  209. package/dist/Raycaster.js.map +1 -0
  210. package/dist/ReflectionProbe.d.ts +8 -0
  211. package/dist/ReflectionProbe.d.ts.map +1 -0
  212. package/dist/ReflectionProbe.js +10 -0
  213. package/dist/ReflectionProbe.js.map +1 -0
  214. package/dist/ReflectionSurfaces.d.ts +35 -0
  215. package/dist/ReflectionSurfaces.d.ts.map +1 -0
  216. package/dist/ReflectionSurfaces.js +155 -0
  217. package/dist/ReflectionSurfaces.js.map +1 -0
  218. package/dist/RenderBackend.d.ts +14 -0
  219. package/dist/RenderBackend.d.ts.map +1 -0
  220. package/dist/RenderBackend.js +33 -0
  221. package/dist/RenderBackend.js.map +1 -0
  222. package/dist/RenderDebugViews.d.ts +26 -0
  223. package/dist/RenderDebugViews.d.ts.map +1 -0
  224. package/dist/RenderDebugViews.js +97 -0
  225. package/dist/RenderDebugViews.js.map +1 -0
  226. package/dist/RenderDevice.d.ts +280 -0
  227. package/dist/RenderDevice.d.ts.map +1 -0
  228. package/dist/RenderDevice.js +561 -0
  229. package/dist/RenderDevice.js.map +1 -0
  230. package/dist/RenderGraph.d.ts +22 -0
  231. package/dist/RenderGraph.d.ts.map +1 -0
  232. package/dist/RenderGraph.js +159 -0
  233. package/dist/RenderGraph.js.map +1 -0
  234. package/dist/RenderPass.d.ts +23 -0
  235. package/dist/RenderPass.d.ts.map +1 -0
  236. package/dist/RenderPass.js +14 -0
  237. package/dist/RenderPass.js.map +1 -0
  238. package/dist/RenderPipeline.d.ts +39 -0
  239. package/dist/RenderPipeline.d.ts.map +1 -0
  240. package/dist/RenderPipeline.js +67 -0
  241. package/dist/RenderPipeline.js.map +1 -0
  242. package/dist/RenderQueue.d.ts +3 -0
  243. package/dist/RenderQueue.d.ts.map +1 -0
  244. package/dist/RenderQueue.js +2 -0
  245. package/dist/RenderQueue.js.map +1 -0
  246. package/dist/RenderState.d.ts +3 -0
  247. package/dist/RenderState.d.ts.map +1 -0
  248. package/dist/RenderState.js +2 -0
  249. package/dist/RenderState.js.map +1 -0
  250. package/dist/Renderer.d.ts +265 -0
  251. package/dist/Renderer.d.ts.map +1 -0
  252. package/dist/Renderer.js +2094 -0
  253. package/dist/Renderer.js.map +1 -0
  254. package/dist/RendererDebugOverlay.d.ts +20 -0
  255. package/dist/RendererDebugOverlay.d.ts.map +1 -0
  256. package/dist/RendererDebugOverlay.js +54 -0
  257. package/dist/RendererDebugOverlay.js.map +1 -0
  258. package/dist/RendererFeatureGates.d.ts +17 -0
  259. package/dist/RendererFeatureGates.d.ts.map +1 -0
  260. package/dist/RendererFeatureGates.js +92 -0
  261. package/dist/RendererFeatureGates.js.map +1 -0
  262. package/dist/RendererPostprocessPlan.d.ts +59 -0
  263. package/dist/RendererPostprocessPlan.d.ts.map +1 -0
  264. package/dist/RendererPostprocessPlan.js +155 -0
  265. package/dist/RendererPostprocessPlan.js.map +1 -0
  266. package/dist/RendererTiming.d.ts +53 -0
  267. package/dist/RendererTiming.d.ts.map +1 -0
  268. package/dist/RendererTiming.js +186 -0
  269. package/dist/RendererTiming.js.map +1 -0
  270. package/dist/RendererVisualPipelineReport.d.ts +224 -0
  271. package/dist/RendererVisualPipelineReport.d.ts.map +1 -0
  272. package/dist/RendererVisualPipelineReport.js +499 -0
  273. package/dist/RendererVisualPipelineReport.js.map +1 -0
  274. package/dist/ResourceLifecycle.d.ts +8 -0
  275. package/dist/ResourceLifecycle.d.ts.map +1 -0
  276. package/dist/ResourceLifecycle.js +18 -0
  277. package/dist/ResourceLifecycle.js.map +1 -0
  278. package/dist/Sampler.d.ts +20 -0
  279. package/dist/Sampler.d.ts.map +1 -0
  280. package/dist/Sampler.js +19 -0
  281. package/dist/Sampler.js.map +1 -0
  282. package/dist/SceneOptimization.d.ts +127 -0
  283. package/dist/SceneOptimization.d.ts.map +1 -0
  284. package/dist/SceneOptimization.js +342 -0
  285. package/dist/SceneOptimization.js.map +1 -0
  286. package/dist/ShaderChunks.d.ts +8 -0
  287. package/dist/ShaderChunks.d.ts.map +1 -0
  288. package/dist/ShaderChunks.js +386 -0
  289. package/dist/ShaderChunks.js.map +1 -0
  290. package/dist/ShaderLibrary.d.ts +63 -0
  291. package/dist/ShaderLibrary.d.ts.map +1 -0
  292. package/dist/ShaderLibrary.js +2707 -0
  293. package/dist/ShaderLibrary.js.map +1 -0
  294. package/dist/ShaderModule.d.ts +14 -0
  295. package/dist/ShaderModule.d.ts.map +1 -0
  296. package/dist/ShaderModule.js +33 -0
  297. package/dist/ShaderModule.js.map +1 -0
  298. package/dist/ShaderPreprocessor.d.ts +19 -0
  299. package/dist/ShaderPreprocessor.d.ts.map +1 -0
  300. package/dist/ShaderPreprocessor.js +212 -0
  301. package/dist/ShaderPreprocessor.js.map +1 -0
  302. package/dist/ShaderReflection.d.ts +23 -0
  303. package/dist/ShaderReflection.d.ts.map +1 -0
  304. package/dist/ShaderReflection.js +134 -0
  305. package/dist/ShaderReflection.js.map +1 -0
  306. package/dist/ShadowMap.d.ts +58 -0
  307. package/dist/ShadowMap.d.ts.map +1 -0
  308. package/dist/ShadowMap.js +183 -0
  309. package/dist/ShadowMap.js.map +1 -0
  310. package/dist/ShadowPass.d.ts +44 -0
  311. package/dist/ShadowPass.d.ts.map +1 -0
  312. package/dist/ShadowPass.js +162 -0
  313. package/dist/ShadowPass.js.map +1 -0
  314. package/dist/ShadowProjection.d.ts +15 -0
  315. package/dist/ShadowProjection.d.ts.map +1 -0
  316. package/dist/ShadowProjection.js +90 -0
  317. package/dist/ShadowProjection.js.map +1 -0
  318. package/dist/SkinnedLitMaterial.d.ts +63 -0
  319. package/dist/SkinnedLitMaterial.d.ts.map +1 -0
  320. package/dist/SkinnedLitMaterial.js +296 -0
  321. package/dist/SkinnedLitMaterial.js.map +1 -0
  322. package/dist/SkinnedUnlitMaterial.d.ts +13 -0
  323. package/dist/SkinnedUnlitMaterial.d.ts.map +1 -0
  324. package/dist/SkinnedUnlitMaterial.js +52 -0
  325. package/dist/SkinnedUnlitMaterial.js.map +1 -0
  326. package/dist/SkinningBounds.d.ts +10 -0
  327. package/dist/SkinningBounds.d.ts.map +1 -0
  328. package/dist/SkinningBounds.js +107 -0
  329. package/dist/SkinningBounds.js.map +1 -0
  330. package/dist/SpaceEnvironmentFixtures.d.ts +59 -0
  331. package/dist/SpaceEnvironmentFixtures.d.ts.map +1 -0
  332. package/dist/SpaceEnvironmentFixtures.js +132 -0
  333. package/dist/SpaceEnvironmentFixtures.js.map +1 -0
  334. package/dist/SpriteGeometry.d.ts +3 -0
  335. package/dist/SpriteGeometry.d.ts.map +1 -0
  336. package/dist/SpriteGeometry.js +21 -0
  337. package/dist/SpriteGeometry.js.map +1 -0
  338. package/dist/StereoCameraRig.d.ts +34 -0
  339. package/dist/StereoCameraRig.d.ts.map +1 -0
  340. package/dist/StereoCameraRig.js +79 -0
  341. package/dist/StereoCameraRig.js.map +1 -0
  342. package/dist/StereoEffects.d.ts +90 -0
  343. package/dist/StereoEffects.d.ts.map +1 -0
  344. package/dist/StereoEffects.js +171 -0
  345. package/dist/StereoEffects.js.map +1 -0
  346. package/dist/TerrainFixtures.d.ts +36 -0
  347. package/dist/TerrainFixtures.d.ts.map +1 -0
  348. package/dist/TerrainFixtures.js +143 -0
  349. package/dist/TerrainFixtures.js.map +1 -0
  350. package/dist/Texture.d.ts +64 -0
  351. package/dist/Texture.d.ts.map +1 -0
  352. package/dist/Texture.js +257 -0
  353. package/dist/Texture.js.map +1 -0
  354. package/dist/TextureBinding.d.ts +38 -0
  355. package/dist/TextureBinding.d.ts.map +1 -0
  356. package/dist/TextureBinding.js +66 -0
  357. package/dist/TextureBinding.js.map +1 -0
  358. package/dist/TexturedPBRMaterial.d.ts +206 -0
  359. package/dist/TexturedPBRMaterial.d.ts.map +1 -0
  360. package/dist/TexturedPBRMaterial.js +842 -0
  361. package/dist/TexturedPBRMaterial.js.map +1 -0
  362. package/dist/TexturedUnlitMaterial.d.ts +19 -0
  363. package/dist/TexturedUnlitMaterial.d.ts.map +1 -0
  364. package/dist/TexturedUnlitMaterial.js +52 -0
  365. package/dist/TexturedUnlitMaterial.js.map +1 -0
  366. package/dist/ToneMapping.d.ts +19 -0
  367. package/dist/ToneMapping.d.ts.map +1 -0
  368. package/dist/ToneMapping.js +53 -0
  369. package/dist/ToneMapping.js.map +1 -0
  370. package/dist/UniformBinder.d.ts +7 -0
  371. package/dist/UniformBinder.d.ts.map +1 -0
  372. package/dist/UniformBinder.js +14 -0
  373. package/dist/UniformBinder.js.map +1 -0
  374. package/dist/UniformLayout.d.ts +19 -0
  375. package/dist/UniformLayout.d.ts.map +1 -0
  376. package/dist/UniformLayout.js +107 -0
  377. package/dist/UniformLayout.js.map +1 -0
  378. package/dist/UnlitMaterial.d.ts +16 -0
  379. package/dist/UnlitMaterial.d.ts.map +1 -0
  380. package/dist/UnlitMaterial.js +60 -0
  381. package/dist/UnlitMaterial.js.map +1 -0
  382. package/dist/VegetationFixtures.d.ts +68 -0
  383. package/dist/VegetationFixtures.d.ts.map +1 -0
  384. package/dist/VegetationFixtures.js +241 -0
  385. package/dist/VegetationFixtures.js.map +1 -0
  386. package/dist/VertexBuffer.d.ts +29 -0
  387. package/dist/VertexBuffer.d.ts.map +1 -0
  388. package/dist/VertexBuffer.js +106 -0
  389. package/dist/VertexBuffer.js.map +1 -0
  390. package/dist/VertexFormat.d.ts +36 -0
  391. package/dist/VertexFormat.d.ts.map +1 -0
  392. package/dist/VertexFormat.js +127 -0
  393. package/dist/VertexFormat.js.map +1 -0
  394. package/dist/VoxelWorldFixtures.d.ts +54 -0
  395. package/dist/VoxelWorldFixtures.d.ts.map +1 -0
  396. package/dist/VoxelWorldFixtures.js +186 -0
  397. package/dist/VoxelWorldFixtures.js.map +1 -0
  398. package/dist/WeatherFixtures.d.ts +46 -0
  399. package/dist/WeatherFixtures.d.ts.map +1 -0
  400. package/dist/WeatherFixtures.js +142 -0
  401. package/dist/WeatherFixtures.js.map +1 -0
  402. package/dist/WebGL2Device.d.ts +137 -0
  403. package/dist/WebGL2Device.d.ts.map +1 -0
  404. package/dist/WebGL2Device.js +2107 -0
  405. package/dist/WebGL2Device.js.map +1 -0
  406. package/dist/WebGL2StateCache.d.ts +89 -0
  407. package/dist/WebGL2StateCache.d.ts.map +1 -0
  408. package/dist/WebGL2StateCache.js +265 -0
  409. package/dist/WebGL2StateCache.js.map +1 -0
  410. package/dist/WebGPUDevice.d.ts +287 -0
  411. package/dist/WebGPUDevice.d.ts.map +1 -0
  412. package/dist/WebGPUDevice.js +2403 -0
  413. package/dist/WebGPUDevice.js.map +1 -0
  414. package/dist/WebGPURenderToTextureProof.d.ts +29 -0
  415. package/dist/WebGPURenderToTextureProof.d.ts.map +1 -0
  416. package/dist/WebGPURenderToTextureProof.js +96 -0
  417. package/dist/WebGPURenderToTextureProof.js.map +1 -0
  418. package/dist/advanced-runtime/AdvancedRenderer.d.ts +23 -0
  419. package/dist/advanced-runtime/AdvancedRenderer.d.ts.map +1 -0
  420. package/dist/advanced-runtime/AdvancedRenderer.js +45 -0
  421. package/dist/advanced-runtime/AdvancedRenderer.js.map +1 -0
  422. package/dist/advanced-runtime/index.d.ts +10 -0
  423. package/dist/advanced-runtime/index.d.ts.map +1 -0
  424. package/dist/advanced-runtime/index.js +9 -0
  425. package/dist/advanced-runtime/index.js.map +1 -0
  426. package/dist/cinematic/BloomPass.d.ts +10 -0
  427. package/dist/cinematic/BloomPass.d.ts.map +1 -0
  428. package/dist/cinematic/BloomPass.js +18 -0
  429. package/dist/cinematic/BloomPass.js.map +1 -0
  430. package/dist/cinematic/CinematicDepthComposition.d.ts +12 -0
  431. package/dist/cinematic/CinematicDepthComposition.d.ts.map +1 -0
  432. package/dist/cinematic/CinematicDepthComposition.js +22 -0
  433. package/dist/cinematic/CinematicDepthComposition.js.map +1 -0
  434. package/dist/cinematic/CinematicEvidence.d.ts +43 -0
  435. package/dist/cinematic/CinematicEvidence.d.ts.map +1 -0
  436. package/dist/cinematic/CinematicEvidence.js +55 -0
  437. package/dist/cinematic/CinematicEvidence.js.map +1 -0
  438. package/dist/cinematic/CinematicLightingRig.d.ts +32 -0
  439. package/dist/cinematic/CinematicLightingRig.d.ts.map +1 -0
  440. package/dist/cinematic/CinematicLightingRig.js +90 -0
  441. package/dist/cinematic/CinematicLightingRig.js.map +1 -0
  442. package/dist/cinematic/CinematicMaterialPresets.d.ts +16 -0
  443. package/dist/cinematic/CinematicMaterialPresets.d.ts.map +1 -0
  444. package/dist/cinematic/CinematicMaterialPresets.js +114 -0
  445. package/dist/cinematic/CinematicMaterialPresets.js.map +1 -0
  446. package/dist/cinematic/CinematicPostProcess.d.ts +25 -0
  447. package/dist/cinematic/CinematicPostProcess.d.ts.map +1 -0
  448. package/dist/cinematic/CinematicPostProcess.js +64 -0
  449. package/dist/cinematic/CinematicPostProcess.js.map +1 -0
  450. package/dist/cinematic/DepthHazePass.d.ts +12 -0
  451. package/dist/cinematic/DepthHazePass.d.ts.map +1 -0
  452. package/dist/cinematic/DepthHazePass.js +20 -0
  453. package/dist/cinematic/DepthHazePass.js.map +1 -0
  454. package/dist/cinematic/EmissivePracticalLightSystem.d.ts +18 -0
  455. package/dist/cinematic/EmissivePracticalLightSystem.d.ts.map +1 -0
  456. package/dist/cinematic/EmissivePracticalLightSystem.js +25 -0
  457. package/dist/cinematic/EmissivePracticalLightSystem.js.map +1 -0
  458. package/dist/cinematic/FilmGrainPass.d.ts +9 -0
  459. package/dist/cinematic/FilmGrainPass.d.ts.map +1 -0
  460. package/dist/cinematic/FilmGrainPass.js +17 -0
  461. package/dist/cinematic/FilmGrainPass.js.map +1 -0
  462. package/dist/cinematic/FogVolumeSystem.d.ts +12 -0
  463. package/dist/cinematic/FogVolumeSystem.d.ts.map +1 -0
  464. package/dist/cinematic/FogVolumeSystem.js +20 -0
  465. package/dist/cinematic/FogVolumeSystem.js.map +1 -0
  466. package/dist/cinematic/GlowCardSystem.d.ts +17 -0
  467. package/dist/cinematic/GlowCardSystem.d.ts.map +1 -0
  468. package/dist/cinematic/GlowCardSystem.js +28 -0
  469. package/dist/cinematic/GlowCardSystem.js.map +1 -0
  470. package/dist/cinematic/RainParticleSystem.d.ts +22 -0
  471. package/dist/cinematic/RainParticleSystem.d.ts.map +1 -0
  472. package/dist/cinematic/RainParticleSystem.js +114 -0
  473. package/dist/cinematic/RainParticleSystem.js.map +1 -0
  474. package/dist/cinematic/VignettePass.d.ts +10 -0
  475. package/dist/cinematic/VignettePass.d.ts.map +1 -0
  476. package/dist/cinematic/VignettePass.js +17 -0
  477. package/dist/cinematic/VignettePass.js.map +1 -0
  478. package/dist/cinematic/WetReflectionApproximation.d.ts +13 -0
  479. package/dist/cinematic/WetReflectionApproximation.d.ts.map +1 -0
  480. package/dist/cinematic/WetReflectionApproximation.js +18 -0
  481. package/dist/cinematic/WetReflectionApproximation.js.map +1 -0
  482. package/dist/cinematic/index.d.ts +15 -0
  483. package/dist/cinematic/index.d.ts.map +1 -0
  484. package/dist/cinematic/index.js +15 -0
  485. package/dist/cinematic/index.js.map +1 -0
  486. package/dist/effects/CollisionModule.d.ts +15 -0
  487. package/dist/effects/CollisionModule.d.ts.map +1 -0
  488. package/dist/effects/CollisionModule.js +46 -0
  489. package/dist/effects/CollisionModule.js.map +1 -0
  490. package/dist/effects/ColorModule.d.ts +15 -0
  491. package/dist/effects/ColorModule.d.ts.map +1 -0
  492. package/dist/effects/ColorModule.js +45 -0
  493. package/dist/effects/ColorModule.js.map +1 -0
  494. package/dist/effects/ForceModule.d.ts +11 -0
  495. package/dist/effects/ForceModule.d.ts.map +1 -0
  496. package/dist/effects/ForceModule.js +17 -0
  497. package/dist/effects/ForceModule.js.map +1 -0
  498. package/dist/effects/GPUParticleBackend.d.ts +153 -0
  499. package/dist/effects/GPUParticleBackend.d.ts.map +1 -0
  500. package/dist/effects/GPUParticleBackend.js +397 -0
  501. package/dist/effects/GPUParticleBackend.js.map +1 -0
  502. package/dist/effects/Particle.d.ts +49 -0
  503. package/dist/effects/Particle.d.ts.map +1 -0
  504. package/dist/effects/Particle.js +56 -0
  505. package/dist/effects/Particle.js.map +1 -0
  506. package/dist/effects/ParticleDiagnostics.d.ts +58 -0
  507. package/dist/effects/ParticleDiagnostics.d.ts.map +1 -0
  508. package/dist/effects/ParticleDiagnostics.js +145 -0
  509. package/dist/effects/ParticleDiagnostics.js.map +1 -0
  510. package/dist/effects/ParticleEffectPresets.d.ts +8 -0
  511. package/dist/effects/ParticleEffectPresets.d.ts.map +1 -0
  512. package/dist/effects/ParticleEffectPresets.js +137 -0
  513. package/dist/effects/ParticleEffectPresets.js.map +1 -0
  514. package/dist/effects/ParticleEmitter.d.ts +87 -0
  515. package/dist/effects/ParticleEmitter.d.ts.map +1 -0
  516. package/dist/effects/ParticleEmitter.js +254 -0
  517. package/dist/effects/ParticleEmitter.js.map +1 -0
  518. package/dist/effects/ParticleModule.d.ts +15 -0
  519. package/dist/effects/ParticleModule.d.ts.map +1 -0
  520. package/dist/effects/ParticleModule.js +6 -0
  521. package/dist/effects/ParticleModule.js.map +1 -0
  522. package/dist/effects/ParticleRenderPass.d.ts +35 -0
  523. package/dist/effects/ParticleRenderPass.d.ts.map +1 -0
  524. package/dist/effects/ParticleRenderPass.js +91 -0
  525. package/dist/effects/ParticleRenderPass.js.map +1 -0
  526. package/dist/effects/ParticleRenderer.d.ts +34 -0
  527. package/dist/effects/ParticleRenderer.d.ts.map +1 -0
  528. package/dist/effects/ParticleRenderer.js +93 -0
  529. package/dist/effects/ParticleRenderer.js.map +1 -0
  530. package/dist/effects/ParticleSystem.d.ts +51 -0
  531. package/dist/effects/ParticleSystem.d.ts.map +1 -0
  532. package/dist/effects/ParticleSystem.js +261 -0
  533. package/dist/effects/ParticleSystem.js.map +1 -0
  534. package/dist/effects/SizeModule.d.ts +14 -0
  535. package/dist/effects/SizeModule.d.ts.map +1 -0
  536. package/dist/effects/SizeModule.js +42 -0
  537. package/dist/effects/SizeModule.js.map +1 -0
  538. package/dist/effects/TrailModule.d.ts +22 -0
  539. package/dist/effects/TrailModule.d.ts.map +1 -0
  540. package/dist/effects/TrailModule.js +50 -0
  541. package/dist/effects/TrailModule.js.map +1 -0
  542. package/dist/effects/VelocityModule.d.ts +15 -0
  543. package/dist/effects/VelocityModule.d.ts.map +1 -0
  544. package/dist/effects/VelocityModule.js +57 -0
  545. package/dist/effects/VelocityModule.js.map +1 -0
  546. package/dist/effects/index.d.ts +16 -0
  547. package/dist/effects/index.d.ts.map +1 -0
  548. package/dist/effects/index.js +16 -0
  549. package/dist/effects/index.js.map +1 -0
  550. package/dist/index.d.ts +260 -0
  551. package/dist/index.d.ts.map +1 -0
  552. package/dist/index.js +155 -0
  553. package/dist/index.js.map +1 -0
  554. package/dist/materials/AlphaSorting.d.ts +8 -0
  555. package/dist/materials/AlphaSorting.d.ts.map +1 -0
  556. package/dist/materials/AlphaSorting.js +26 -0
  557. package/dist/materials/AlphaSorting.js.map +1 -0
  558. package/dist/materials/MaterialExtensions.d.ts +10 -0
  559. package/dist/materials/MaterialExtensions.d.ts.map +1 -0
  560. package/dist/materials/MaterialExtensions.js +20 -0
  561. package/dist/materials/MaterialExtensions.js.map +1 -0
  562. package/dist/materials/PhysicalMaterial.d.ts +36 -0
  563. package/dist/materials/PhysicalMaterial.d.ts.map +1 -0
  564. package/dist/materials/PhysicalMaterial.js +79 -0
  565. package/dist/materials/PhysicalMaterial.js.map +1 -0
  566. package/dist/materials/TransmissionPass.d.ts +16 -0
  567. package/dist/materials/TransmissionPass.d.ts.map +1 -0
  568. package/dist/materials/TransmissionPass.js +30 -0
  569. package/dist/materials/TransmissionPass.js.map +1 -0
  570. package/dist/performance/BVH.d.ts +3 -0
  571. package/dist/performance/BVH.d.ts.map +1 -0
  572. package/dist/performance/BVH.js +2 -0
  573. package/dist/performance/BVH.js.map +1 -0
  574. package/dist/performance/Batcher.d.ts +3 -0
  575. package/dist/performance/Batcher.d.ts.map +1 -0
  576. package/dist/performance/Batcher.js +2 -0
  577. package/dist/performance/Batcher.js.map +1 -0
  578. package/dist/performance/FrustumCuller.d.ts +3 -0
  579. package/dist/performance/FrustumCuller.d.ts.map +1 -0
  580. package/dist/performance/FrustumCuller.js +5 -0
  581. package/dist/performance/FrustumCuller.js.map +1 -0
  582. package/dist/performance/LOD.d.ts +8 -0
  583. package/dist/performance/LOD.d.ts.map +1 -0
  584. package/dist/performance/LOD.js +15 -0
  585. package/dist/performance/LOD.js.map +1 -0
  586. package/dist/performance/Octree.d.ts +7 -0
  587. package/dist/performance/Octree.d.ts.map +1 -0
  588. package/dist/performance/Octree.js +4 -0
  589. package/dist/performance/Octree.js.map +1 -0
  590. package/dist/performance/RenderItemSorting.d.ts +43 -0
  591. package/dist/performance/RenderItemSorting.d.ts.map +1 -0
  592. package/dist/performance/RenderItemSorting.js +111 -0
  593. package/dist/performance/RenderItemSorting.js.map +1 -0
  594. package/dist/performance/RendererStats.d.ts +23 -0
  595. package/dist/performance/RendererStats.d.ts.map +1 -0
  596. package/dist/performance/RendererStats.js +23 -0
  597. package/dist/performance/RendererStats.js.map +1 -0
  598. package/dist/performance/ResourceBudget.d.ts +19 -0
  599. package/dist/performance/ResourceBudget.d.ts.map +1 -0
  600. package/dist/performance/ResourceBudget.js +21 -0
  601. package/dist/performance/ResourceBudget.js.map +1 -0
  602. package/dist/postprocess/BloomPass.d.ts +11 -0
  603. package/dist/postprocess/BloomPass.d.ts.map +1 -0
  604. package/dist/postprocess/BloomPass.js +14 -0
  605. package/dist/postprocess/BloomPass.js.map +1 -0
  606. package/dist/postprocess/CinematicDiagnostics.d.ts +112 -0
  607. package/dist/postprocess/CinematicDiagnostics.d.ts.map +1 -0
  608. package/dist/postprocess/CinematicDiagnostics.js +492 -0
  609. package/dist/postprocess/CinematicDiagnostics.js.map +1 -0
  610. package/dist/postprocess/ColorGradingPass.d.ts +4 -0
  611. package/dist/postprocess/ColorGradingPass.d.ts.map +1 -0
  612. package/dist/postprocess/ColorGradingPass.js +15 -0
  613. package/dist/postprocess/ColorGradingPass.js.map +1 -0
  614. package/dist/postprocess/DepthOfFieldPass.d.ts +3 -0
  615. package/dist/postprocess/DepthOfFieldPass.d.ts.map +1 -0
  616. package/dist/postprocess/DepthOfFieldPass.js +7 -0
  617. package/dist/postprocess/DepthOfFieldPass.js.map +1 -0
  618. package/dist/postprocess/EffectComposer.d.ts +110 -0
  619. package/dist/postprocess/EffectComposer.d.ts.map +1 -0
  620. package/dist/postprocess/EffectComposer.js +249 -0
  621. package/dist/postprocess/EffectComposer.js.map +1 -0
  622. package/dist/postprocess/SSAOPass.d.ts +6 -0
  623. package/dist/postprocess/SSAOPass.d.ts.map +1 -0
  624. package/dist/postprocess/SSAOPass.js +18 -0
  625. package/dist/postprocess/SSAOPass.js.map +1 -0
  626. package/dist/postprocess/index.d.ts +11 -0
  627. package/dist/postprocess/index.d.ts.map +1 -0
  628. package/dist/postprocess/index.js +7 -0
  629. package/dist/postprocess/index.js.map +1 -0
  630. package/dist/production-runtime/AnimationControlsPipeline.d.ts +37 -0
  631. package/dist/production-runtime/AnimationControlsPipeline.d.ts.map +1 -0
  632. package/dist/production-runtime/AnimationControlsPipeline.js +41 -0
  633. package/dist/production-runtime/AnimationControlsPipeline.js.map +1 -0
  634. package/dist/production-runtime/PBRHDRPipeline.d.ts +81 -0
  635. package/dist/production-runtime/PBRHDRPipeline.d.ts.map +1 -0
  636. package/dist/production-runtime/PBRHDRPipeline.js +279 -0
  637. package/dist/production-runtime/PBRHDRPipeline.js.map +1 -0
  638. package/dist/production-runtime/ProductionEffectsPipeline.d.ts +20 -0
  639. package/dist/production-runtime/ProductionEffectsPipeline.d.ts.map +1 -0
  640. package/dist/production-runtime/ProductionEffectsPipeline.js +65 -0
  641. package/dist/production-runtime/ProductionEffectsPipeline.js.map +1 -0
  642. package/dist/production-runtime/ProductionRendererTypes.d.ts +97 -0
  643. package/dist/production-runtime/ProductionRendererTypes.d.ts.map +1 -0
  644. package/dist/production-runtime/ProductionRendererTypes.js +29 -0
  645. package/dist/production-runtime/ProductionRendererTypes.js.map +1 -0
  646. package/dist/production-runtime/ProductionRuntimeRenderer.d.ts +36 -0
  647. package/dist/production-runtime/ProductionRuntimeRenderer.d.ts.map +1 -0
  648. package/dist/production-runtime/ProductionRuntimeRenderer.js +124 -0
  649. package/dist/production-runtime/ProductionRuntimeRenderer.js.map +1 -0
  650. package/dist/production-runtime/ProductionWebGL2Renderer.d.ts +51 -0
  651. package/dist/production-runtime/ProductionWebGL2Renderer.d.ts.map +1 -0
  652. package/dist/production-runtime/ProductionWebGL2Renderer.js +269 -0
  653. package/dist/production-runtime/ProductionWebGL2Renderer.js.map +1 -0
  654. package/dist/production-runtime/ProductionWebGPURenderer.d.ts +69 -0
  655. package/dist/production-runtime/ProductionWebGPURenderer.d.ts.map +1 -0
  656. package/dist/production-runtime/ProductionWebGPURenderer.js +313 -0
  657. package/dist/production-runtime/ProductionWebGPURenderer.js.map +1 -0
  658. package/dist/production-runtime/TransmissionBackdropCapture.d.ts +11 -0
  659. package/dist/production-runtime/TransmissionBackdropCapture.d.ts.map +1 -0
  660. package/dist/production-runtime/TransmissionBackdropCapture.js +119 -0
  661. package/dist/production-runtime/TransmissionBackdropCapture.js.map +1 -0
  662. package/dist/production-runtime/animation/MorphTargetRenderer.d.ts +7 -0
  663. package/dist/production-runtime/animation/MorphTargetRenderer.d.ts.map +1 -0
  664. package/dist/production-runtime/animation/MorphTargetRenderer.js +2 -0
  665. package/dist/production-runtime/animation/MorphTargetRenderer.js.map +1 -0
  666. package/dist/production-runtime/animation/SkinningRenderer.d.ts +7 -0
  667. package/dist/production-runtime/animation/SkinningRenderer.d.ts.map +1 -0
  668. package/dist/production-runtime/animation/SkinningRenderer.js +2 -0
  669. package/dist/production-runtime/animation/SkinningRenderer.js.map +1 -0
  670. package/dist/production-runtime/backends/RendererBackend.d.ts +16 -0
  671. package/dist/production-runtime/backends/RendererBackend.d.ts.map +1 -0
  672. package/dist/production-runtime/backends/RendererBackend.js +2 -0
  673. package/dist/production-runtime/backends/RendererBackend.js.map +1 -0
  674. package/dist/production-runtime/backends/WebGL2RendererBackend.d.ts +15 -0
  675. package/dist/production-runtime/backends/WebGL2RendererBackend.d.ts.map +1 -0
  676. package/dist/production-runtime/backends/WebGL2RendererBackend.js +25 -0
  677. package/dist/production-runtime/backends/WebGL2RendererBackend.js.map +1 -0
  678. package/dist/production-runtime/backends/WebGPURendererBackend.d.ts +20 -0
  679. package/dist/production-runtime/backends/WebGPURendererBackend.d.ts.map +1 -0
  680. package/dist/production-runtime/backends/WebGPURendererBackend.js +19 -0
  681. package/dist/production-runtime/backends/WebGPURendererBackend.js.map +1 -0
  682. package/dist/production-runtime/backends/webgl2/WebGL2Buffer.d.ts +11 -0
  683. package/dist/production-runtime/backends/webgl2/WebGL2Buffer.d.ts.map +1 -0
  684. package/dist/production-runtime/backends/webgl2/WebGL2Buffer.js +8 -0
  685. package/dist/production-runtime/backends/webgl2/WebGL2Buffer.js.map +1 -0
  686. package/dist/production-runtime/backends/webgl2/WebGL2Capabilities.d.ts +11 -0
  687. package/dist/production-runtime/backends/webgl2/WebGL2Capabilities.d.ts.map +1 -0
  688. package/dist/production-runtime/backends/webgl2/WebGL2Capabilities.js +8 -0
  689. package/dist/production-runtime/backends/webgl2/WebGL2Capabilities.js.map +1 -0
  690. package/dist/production-runtime/backends/webgl2/WebGL2RenderTarget.d.ts +11 -0
  691. package/dist/production-runtime/backends/webgl2/WebGL2RenderTarget.d.ts.map +1 -0
  692. package/dist/production-runtime/backends/webgl2/WebGL2RenderTarget.js +8 -0
  693. package/dist/production-runtime/backends/webgl2/WebGL2RenderTarget.js.map +1 -0
  694. package/dist/production-runtime/backends/webgl2/WebGL2Shader.d.ts +11 -0
  695. package/dist/production-runtime/backends/webgl2/WebGL2Shader.d.ts.map +1 -0
  696. package/dist/production-runtime/backends/webgl2/WebGL2Shader.js +8 -0
  697. package/dist/production-runtime/backends/webgl2/WebGL2Shader.js.map +1 -0
  698. package/dist/production-runtime/backends/webgl2/WebGL2StateCache.d.ts +2 -0
  699. package/dist/production-runtime/backends/webgl2/WebGL2StateCache.d.ts.map +1 -0
  700. package/dist/production-runtime/backends/webgl2/WebGL2StateCache.js +2 -0
  701. package/dist/production-runtime/backends/webgl2/WebGL2StateCache.js.map +1 -0
  702. package/dist/production-runtime/backends/webgl2/WebGL2Texture.d.ts +11 -0
  703. package/dist/production-runtime/backends/webgl2/WebGL2Texture.d.ts.map +1 -0
  704. package/dist/production-runtime/backends/webgl2/WebGL2Texture.js +8 -0
  705. package/dist/production-runtime/backends/webgl2/WebGL2Texture.js.map +1 -0
  706. package/dist/production-runtime/backends/webgpu/WebGPUBuffer.d.ts +11 -0
  707. package/dist/production-runtime/backends/webgpu/WebGPUBuffer.d.ts.map +1 -0
  708. package/dist/production-runtime/backends/webgpu/WebGPUBuffer.js +8 -0
  709. package/dist/production-runtime/backends/webgpu/WebGPUBuffer.js.map +1 -0
  710. package/dist/production-runtime/backends/webgpu/WebGPUCapabilities.d.ts +11 -0
  711. package/dist/production-runtime/backends/webgpu/WebGPUCapabilities.d.ts.map +1 -0
  712. package/dist/production-runtime/backends/webgpu/WebGPUCapabilities.js +8 -0
  713. package/dist/production-runtime/backends/webgpu/WebGPUCapabilities.js.map +1 -0
  714. package/dist/production-runtime/backends/webgpu/WebGPURenderTarget.d.ts +11 -0
  715. package/dist/production-runtime/backends/webgpu/WebGPURenderTarget.d.ts.map +1 -0
  716. package/dist/production-runtime/backends/webgpu/WebGPURenderTarget.js +8 -0
  717. package/dist/production-runtime/backends/webgpu/WebGPURenderTarget.js.map +1 -0
  718. package/dist/production-runtime/backends/webgpu/WebGPUShader.d.ts +11 -0
  719. package/dist/production-runtime/backends/webgpu/WebGPUShader.d.ts.map +1 -0
  720. package/dist/production-runtime/backends/webgpu/WebGPUShader.js +8 -0
  721. package/dist/production-runtime/backends/webgpu/WebGPUShader.js.map +1 -0
  722. package/dist/production-runtime/backends/webgpu/WebGPUTexture.d.ts +11 -0
  723. package/dist/production-runtime/backends/webgpu/WebGPUTexture.d.ts.map +1 -0
  724. package/dist/production-runtime/backends/webgpu/WebGPUTexture.js +8 -0
  725. package/dist/production-runtime/backends/webgpu/WebGPUTexture.js.map +1 -0
  726. package/dist/production-runtime/color/ColorManagement.d.ts +4 -0
  727. package/dist/production-runtime/color/ColorManagement.d.ts.map +1 -0
  728. package/dist/production-runtime/color/ColorManagement.js +3 -0
  729. package/dist/production-runtime/color/ColorManagement.js.map +1 -0
  730. package/dist/production-runtime/color/ToneMapping.d.ts +3 -0
  731. package/dist/production-runtime/color/ToneMapping.d.ts.map +1 -0
  732. package/dist/production-runtime/color/ToneMapping.js +9 -0
  733. package/dist/production-runtime/color/ToneMapping.js.map +1 -0
  734. package/dist/production-runtime/diagnostics/FrameCapture.d.ts +7 -0
  735. package/dist/production-runtime/diagnostics/FrameCapture.d.ts.map +1 -0
  736. package/dist/production-runtime/diagnostics/FrameCapture.js +2 -0
  737. package/dist/production-runtime/diagnostics/FrameCapture.js.map +1 -0
  738. package/dist/production-runtime/diagnostics/GPUCapabilities.d.ts +9 -0
  739. package/dist/production-runtime/diagnostics/GPUCapabilities.d.ts.map +1 -0
  740. package/dist/production-runtime/diagnostics/GPUCapabilities.js +2 -0
  741. package/dist/production-runtime/diagnostics/GPUCapabilities.js.map +1 -0
  742. package/dist/production-runtime/diagnostics/RendererStats.d.ts +9 -0
  743. package/dist/production-runtime/diagnostics/RendererStats.d.ts.map +1 -0
  744. package/dist/production-runtime/diagnostics/RendererStats.js +2 -0
  745. package/dist/production-runtime/diagnostics/RendererStats.js.map +1 -0
  746. package/dist/production-runtime/environment/EnvironmentMap.d.ts +8 -0
  747. package/dist/production-runtime/environment/EnvironmentMap.d.ts.map +1 -0
  748. package/dist/production-runtime/environment/EnvironmentMap.js +2 -0
  749. package/dist/production-runtime/environment/EnvironmentMap.js.map +1 -0
  750. package/dist/production-runtime/environment/HDRLoader.d.ts +19 -0
  751. package/dist/production-runtime/environment/HDRLoader.d.ts.map +1 -0
  752. package/dist/production-runtime/environment/HDRLoader.js +22 -0
  753. package/dist/production-runtime/environment/HDRLoader.js.map +1 -0
  754. package/dist/production-runtime/environment/PMREMGenerator.d.ts +99 -0
  755. package/dist/production-runtime/environment/PMREMGenerator.d.ts.map +1 -0
  756. package/dist/production-runtime/environment/PMREMGenerator.js +534 -0
  757. package/dist/production-runtime/environment/PMREMGenerator.js.map +1 -0
  758. package/dist/production-runtime/framegraph/FrameGraph.d.ts +8 -0
  759. package/dist/production-runtime/framegraph/FrameGraph.d.ts.map +1 -0
  760. package/dist/production-runtime/framegraph/FrameGraph.js +14 -0
  761. package/dist/production-runtime/framegraph/FrameGraph.js.map +1 -0
  762. package/dist/production-runtime/framegraph/RenderPass.d.ts +14 -0
  763. package/dist/production-runtime/framegraph/RenderPass.d.ts.map +1 -0
  764. package/dist/production-runtime/framegraph/RenderPass.js +2 -0
  765. package/dist/production-runtime/framegraph/RenderPass.js.map +1 -0
  766. package/dist/production-runtime/geometry/ProjectedDecalGeometry.d.ts +53 -0
  767. package/dist/production-runtime/geometry/ProjectedDecalGeometry.d.ts.map +1 -0
  768. package/dist/production-runtime/geometry/ProjectedDecalGeometry.js +340 -0
  769. package/dist/production-runtime/geometry/ProjectedDecalGeometry.js.map +1 -0
  770. package/dist/production-runtime/index.d.ts +73 -0
  771. package/dist/production-runtime/index.d.ts.map +1 -0
  772. package/dist/production-runtime/index.js +67 -0
  773. package/dist/production-runtime/index.js.map +1 -0
  774. package/dist/production-runtime/lights/LightManager.d.ts +8 -0
  775. package/dist/production-runtime/lights/LightManager.d.ts.map +1 -0
  776. package/dist/production-runtime/lights/LightManager.js +7 -0
  777. package/dist/production-runtime/lights/LightManager.js.map +1 -0
  778. package/dist/production-runtime/lights/ShadowMapRenderer.d.ts +8 -0
  779. package/dist/production-runtime/lights/ShadowMapRenderer.d.ts.map +1 -0
  780. package/dist/production-runtime/lights/ShadowMapRenderer.js +4 -0
  781. package/dist/production-runtime/lights/ShadowMapRenderer.js.map +1 -0
  782. package/dist/production-runtime/materials/GLTFMaterialAdapter.d.ts +14 -0
  783. package/dist/production-runtime/materials/GLTFMaterialAdapter.d.ts.map +1 -0
  784. package/dist/production-runtime/materials/GLTFMaterialAdapter.js +5 -0
  785. package/dist/production-runtime/materials/GLTFMaterialAdapter.js.map +1 -0
  786. package/dist/production-runtime/materials/GLTFPBRMaterialAdapter.d.ts +3 -0
  787. package/dist/production-runtime/materials/GLTFPBRMaterialAdapter.d.ts.map +1 -0
  788. package/dist/production-runtime/materials/GLTFPBRMaterialAdapter.js +2 -0
  789. package/dist/production-runtime/materials/GLTFPBRMaterialAdapter.js.map +1 -0
  790. package/dist/production-runtime/materials/MaterialCompiler.d.ts +9 -0
  791. package/dist/production-runtime/materials/MaterialCompiler.d.ts.map +1 -0
  792. package/dist/production-runtime/materials/MaterialCompiler.js +5 -0
  793. package/dist/production-runtime/materials/MaterialCompiler.js.map +1 -0
  794. package/dist/production-runtime/materials/MaterialTextureBindings.d.ts +8 -0
  795. package/dist/production-runtime/materials/MaterialTextureBindings.d.ts.map +1 -0
  796. package/dist/production-runtime/materials/MaterialTextureBindings.js +4 -0
  797. package/dist/production-runtime/materials/MaterialTextureBindings.js.map +1 -0
  798. package/dist/production-runtime/materials/PBRMaterial.d.ts +23 -0
  799. package/dist/production-runtime/materials/PBRMaterial.d.ts.map +1 -0
  800. package/dist/production-runtime/materials/PBRMaterial.js +2 -0
  801. package/dist/production-runtime/materials/PBRMaterial.js.map +1 -0
  802. package/dist/production-runtime/materials/PBRShaderFeatures.d.ts +13 -0
  803. package/dist/production-runtime/materials/PBRShaderFeatures.d.ts.map +1 -0
  804. package/dist/production-runtime/materials/PBRShaderFeatures.js +2 -0
  805. package/dist/production-runtime/materials/PBRShaderFeatures.js.map +1 -0
  806. package/dist/production-runtime/passes/ContactShadowPass.d.ts +40 -0
  807. package/dist/production-runtime/passes/ContactShadowPass.d.ts.map +1 -0
  808. package/dist/production-runtime/passes/ContactShadowPass.js +126 -0
  809. package/dist/production-runtime/passes/ContactShadowPass.js.map +1 -0
  810. package/dist/production-runtime/passes/DepthPrepass.d.ts +8 -0
  811. package/dist/production-runtime/passes/DepthPrepass.d.ts.map +1 -0
  812. package/dist/production-runtime/passes/DepthPrepass.js +7 -0
  813. package/dist/production-runtime/passes/DepthPrepass.js.map +1 -0
  814. package/dist/production-runtime/passes/OpaquePass.d.ts +8 -0
  815. package/dist/production-runtime/passes/OpaquePass.d.ts.map +1 -0
  816. package/dist/production-runtime/passes/OpaquePass.js +7 -0
  817. package/dist/production-runtime/passes/OpaquePass.js.map +1 -0
  818. package/dist/production-runtime/passes/ShadowPass.d.ts +8 -0
  819. package/dist/production-runtime/passes/ShadowPass.d.ts.map +1 -0
  820. package/dist/production-runtime/passes/ShadowPass.js +7 -0
  821. package/dist/production-runtime/passes/ShadowPass.js.map +1 -0
  822. package/dist/production-runtime/passes/SkyboxPass.d.ts +8 -0
  823. package/dist/production-runtime/passes/SkyboxPass.d.ts.map +1 -0
  824. package/dist/production-runtime/passes/SkyboxPass.js +7 -0
  825. package/dist/production-runtime/passes/SkyboxPass.js.map +1 -0
  826. package/dist/production-runtime/passes/ToneMappingPass.d.ts +8 -0
  827. package/dist/production-runtime/passes/ToneMappingPass.d.ts.map +1 -0
  828. package/dist/production-runtime/passes/ToneMappingPass.js +7 -0
  829. package/dist/production-runtime/passes/ToneMappingPass.js.map +1 -0
  830. package/dist/production-runtime/passes/TransparentPass.d.ts +8 -0
  831. package/dist/production-runtime/passes/TransparentPass.d.ts.map +1 -0
  832. package/dist/production-runtime/passes/TransparentPass.js +7 -0
  833. package/dist/production-runtime/passes/TransparentPass.js.map +1 -0
  834. package/dist/production-runtime/postprocess/BloomPass.d.ts +15 -0
  835. package/dist/production-runtime/postprocess/BloomPass.d.ts.map +1 -0
  836. package/dist/production-runtime/postprocess/BloomPass.js +37 -0
  837. package/dist/production-runtime/postprocess/BloomPass.js.map +1 -0
  838. package/dist/production-runtime/postprocess/ColorGradingPass.d.ts +16 -0
  839. package/dist/production-runtime/postprocess/ColorGradingPass.d.ts.map +1 -0
  840. package/dist/production-runtime/postprocess/ColorGradingPass.js +34 -0
  841. package/dist/production-runtime/postprocess/ColorGradingPass.js.map +1 -0
  842. package/dist/production-runtime/postprocess/DOFPass.d.ts +16 -0
  843. package/dist/production-runtime/postprocess/DOFPass.d.ts.map +1 -0
  844. package/dist/production-runtime/postprocess/DOFPass.js +31 -0
  845. package/dist/production-runtime/postprocess/DOFPass.js.map +1 -0
  846. package/dist/production-runtime/postprocess/FXAAPass.d.ts +16 -0
  847. package/dist/production-runtime/postprocess/FXAAPass.d.ts.map +1 -0
  848. package/dist/production-runtime/postprocess/FXAAPass.js +39 -0
  849. package/dist/production-runtime/postprocess/FXAAPass.js.map +1 -0
  850. package/dist/production-runtime/postprocess/ProductionEffectComposer.d.ts +21 -0
  851. package/dist/production-runtime/postprocess/ProductionEffectComposer.d.ts.map +1 -0
  852. package/dist/production-runtime/postprocess/ProductionEffectComposer.js +53 -0
  853. package/dist/production-runtime/postprocess/ProductionEffectComposer.js.map +1 -0
  854. package/dist/production-runtime/postprocess/ProductionPostProcessTypes.d.ts +37 -0
  855. package/dist/production-runtime/postprocess/ProductionPostProcessTypes.d.ts.map +1 -0
  856. package/dist/production-runtime/postprocess/ProductionPostProcessTypes.js +124 -0
  857. package/dist/production-runtime/postprocess/ProductionPostProcessTypes.js.map +1 -0
  858. package/dist/production-runtime/postprocess/SSAOPass.d.ts +15 -0
  859. package/dist/production-runtime/postprocess/SSAOPass.d.ts.map +1 -0
  860. package/dist/production-runtime/postprocess/SSAOPass.js +30 -0
  861. package/dist/production-runtime/postprocess/SSAOPass.js.map +1 -0
  862. package/dist/production-runtime/resources/GPUBuffer.d.ts +10 -0
  863. package/dist/production-runtime/resources/GPUBuffer.d.ts.map +1 -0
  864. package/dist/production-runtime/resources/GPUBuffer.js +7 -0
  865. package/dist/production-runtime/resources/GPUBuffer.js.map +1 -0
  866. package/dist/production-runtime/resources/GPUTexture.d.ts +12 -0
  867. package/dist/production-runtime/resources/GPUTexture.d.ts.map +1 -0
  868. package/dist/production-runtime/resources/GPUTexture.js +7 -0
  869. package/dist/production-runtime/resources/GPUTexture.js.map +1 -0
  870. package/dist/production-runtime/resources/RenderTarget.d.ts +11 -0
  871. package/dist/production-runtime/resources/RenderTarget.d.ts.map +1 -0
  872. package/dist/production-runtime/resources/RenderTarget.js +7 -0
  873. package/dist/production-runtime/resources/RenderTarget.js.map +1 -0
  874. package/dist/production-runtime/resources/ResourceCache.d.ts +8 -0
  875. package/dist/production-runtime/resources/ResourceCache.d.ts.map +1 -0
  876. package/dist/production-runtime/resources/ResourceCache.js +8 -0
  877. package/dist/production-runtime/resources/ResourceCache.js.map +1 -0
  878. package/dist/production-runtime/scene/Camera.d.ts +8 -0
  879. package/dist/production-runtime/scene/Camera.d.ts.map +1 -0
  880. package/dist/production-runtime/scene/Camera.js +2 -0
  881. package/dist/production-runtime/scene/Camera.js.map +1 -0
  882. package/dist/production-runtime/scene/Lights.d.ts +9 -0
  883. package/dist/production-runtime/scene/Lights.d.ts.map +1 -0
  884. package/dist/production-runtime/scene/Lights.js +2 -0
  885. package/dist/production-runtime/scene/Lights.js.map +1 -0
  886. package/dist/production-runtime/scene/RenderableMesh.d.ts +8 -0
  887. package/dist/production-runtime/scene/RenderableMesh.d.ts.map +1 -0
  888. package/dist/production-runtime/scene/RenderableMesh.js +2 -0
  889. package/dist/production-runtime/scene/RenderableMesh.js.map +1 -0
  890. package/dist/production-runtime/scene/RenderablePrimitive.d.ts +8 -0
  891. package/dist/production-runtime/scene/RenderablePrimitive.d.ts.map +1 -0
  892. package/dist/production-runtime/scene/RenderablePrimitive.js +2 -0
  893. package/dist/production-runtime/scene/RenderablePrimitive.js.map +1 -0
  894. package/dist/production-runtime/scene/RenderableScene.d.ts +11 -0
  895. package/dist/production-runtime/scene/RenderableScene.d.ts.map +1 -0
  896. package/dist/production-runtime/scene/RenderableScene.js +2 -0
  897. package/dist/production-runtime/scene/RenderableScene.js.map +1 -0
  898. package/dist/production-runtime/shaders/ShaderProgramLibrary.d.ts +12 -0
  899. package/dist/production-runtime/shaders/ShaderProgramLibrary.d.ts.map +1 -0
  900. package/dist/production-runtime/shaders/ShaderProgramLibrary.js +7 -0
  901. package/dist/production-runtime/shaders/ShaderProgramLibrary.js.map +1 -0
  902. package/dist/shadows/CascadedShadowPipeline.d.ts +25 -0
  903. package/dist/shadows/CascadedShadowPipeline.d.ts.map +1 -0
  904. package/dist/shadows/CascadedShadowPipeline.js +31 -0
  905. package/dist/shadows/CascadedShadowPipeline.js.map +1 -0
  906. package/dist/shadows/ContactShadows.d.ts +37 -0
  907. package/dist/shadows/ContactShadows.d.ts.map +1 -0
  908. package/dist/shadows/ContactShadows.js +68 -0
  909. package/dist/shadows/ContactShadows.js.map +1 -0
  910. package/dist/shadows/ShadowDebugViews.d.ts +12 -0
  911. package/dist/shadows/ShadowDebugViews.d.ts.map +1 -0
  912. package/dist/shadows/ShadowDebugViews.js +35 -0
  913. package/dist/shadows/ShadowDebugViews.js.map +1 -0
  914. package/dist/threejs-compatibility/InstancingSystem.d.ts +10 -0
  915. package/dist/threejs-compatibility/InstancingSystem.d.ts.map +1 -0
  916. package/dist/threejs-compatibility/InstancingSystem.js +11 -0
  917. package/dist/threejs-compatibility/InstancingSystem.js.map +1 -0
  918. package/dist/threejs-compatibility/LightingSystem.d.ts +11 -0
  919. package/dist/threejs-compatibility/LightingSystem.d.ts.map +1 -0
  920. package/dist/threejs-compatibility/LightingSystem.js +14 -0
  921. package/dist/threejs-compatibility/LightingSystem.js.map +1 -0
  922. package/dist/threejs-compatibility/MaterialSystem.d.ts +6 -0
  923. package/dist/threejs-compatibility/MaterialSystem.d.ts.map +1 -0
  924. package/dist/threejs-compatibility/MaterialSystem.js +7 -0
  925. package/dist/threejs-compatibility/MaterialSystem.js.map +1 -0
  926. package/dist/threejs-compatibility/RenderTargetSystem.d.ts +16 -0
  927. package/dist/threejs-compatibility/RenderTargetSystem.d.ts.map +1 -0
  928. package/dist/threejs-compatibility/RenderTargetSystem.js +23 -0
  929. package/dist/threejs-compatibility/RenderTargetSystem.js.map +1 -0
  930. package/dist/threejs-compatibility/RendererDiagnostics.d.ts +27 -0
  931. package/dist/threejs-compatibility/RendererDiagnostics.d.ts.map +1 -0
  932. package/dist/threejs-compatibility/RendererDiagnostics.js +41 -0
  933. package/dist/threejs-compatibility/RendererDiagnostics.js.map +1 -0
  934. package/dist/threejs-compatibility/SceneRenderer.d.ts +19 -0
  935. package/dist/threejs-compatibility/SceneRenderer.d.ts.map +1 -0
  936. package/dist/threejs-compatibility/SceneRenderer.js +18 -0
  937. package/dist/threejs-compatibility/SceneRenderer.js.map +1 -0
  938. package/dist/threejs-compatibility/ShadowSystem.d.ts +11 -0
  939. package/dist/threejs-compatibility/ShadowSystem.d.ts.map +1 -0
  940. package/dist/threejs-compatibility/ShadowSystem.js +12 -0
  941. package/dist/threejs-compatibility/ShadowSystem.js.map +1 -0
  942. package/dist/threejs-compatibility/TextureSystem.d.ts +9 -0
  943. package/dist/threejs-compatibility/TextureSystem.d.ts.map +1 -0
  944. package/dist/threejs-compatibility/TextureSystem.js +14 -0
  945. package/dist/threejs-compatibility/TextureSystem.js.map +1 -0
  946. package/dist/threejs-compatibility/ThreeCompatRenderer.d.ts +37 -0
  947. package/dist/threejs-compatibility/ThreeCompatRenderer.d.ts.map +1 -0
  948. package/dist/threejs-compatibility/ThreeCompatRenderer.js +77 -0
  949. package/dist/threejs-compatibility/ThreeCompatRenderer.js.map +1 -0
  950. package/dist/threejs-compatibility/TransparencySystem.d.ts +11 -0
  951. package/dist/threejs-compatibility/TransparencySystem.d.ts.map +1 -0
  952. package/dist/threejs-compatibility/TransparencySystem.js +12 -0
  953. package/dist/threejs-compatibility/TransparencySystem.js.map +1 -0
  954. package/dist/threejs-compatibility/index.d.ts +25 -0
  955. package/dist/threejs-compatibility/index.d.ts.map +1 -0
  956. package/dist/threejs-compatibility/index.js +15 -0
  957. package/dist/threejs-compatibility/index.js.map +1 -0
  958. package/dist/threejs-compatibility/performance/BVH.d.ts +11 -0
  959. package/dist/threejs-compatibility/performance/BVH.d.ts.map +1 -0
  960. package/dist/threejs-compatibility/performance/BVH.js +10 -0
  961. package/dist/threejs-compatibility/performance/BVH.js.map +1 -0
  962. package/dist/threejs-compatibility/performance/FrustumCulling.d.ts +7 -0
  963. package/dist/threejs-compatibility/performance/FrustumCulling.d.ts.map +1 -0
  964. package/dist/threejs-compatibility/performance/FrustumCulling.js +5 -0
  965. package/dist/threejs-compatibility/performance/FrustumCulling.js.map +1 -0
  966. package/dist/threejs-compatibility/performance/Instancing.d.ts +7 -0
  967. package/dist/threejs-compatibility/performance/Instancing.d.ts.map +1 -0
  968. package/dist/threejs-compatibility/performance/Instancing.js +10 -0
  969. package/dist/threejs-compatibility/performance/Instancing.js.map +1 -0
  970. package/dist/threejs-compatibility/performance/LODSystem.d.ts +9 -0
  971. package/dist/threejs-compatibility/performance/LODSystem.d.ts.map +1 -0
  972. package/dist/threejs-compatibility/performance/LODSystem.js +11 -0
  973. package/dist/threejs-compatibility/performance/LODSystem.js.map +1 -0
  974. package/dist/threejs-compatibility/performance/OcclusionCulling.d.ts +3 -0
  975. package/dist/threejs-compatibility/performance/OcclusionCulling.d.ts.map +1 -0
  976. package/dist/threejs-compatibility/performance/OcclusionCulling.js +5 -0
  977. package/dist/threejs-compatibility/performance/OcclusionCulling.js.map +1 -0
  978. package/dist/threejs-compatibility/performance/RaycastAcceleration.d.ts +8 -0
  979. package/dist/threejs-compatibility/performance/RaycastAcceleration.d.ts.map +1 -0
  980. package/dist/threejs-compatibility/performance/RaycastAcceleration.js +11 -0
  981. package/dist/threejs-compatibility/performance/RaycastAcceleration.js.map +1 -0
  982. package/dist/threejs-compatibility/performance/RendererProfiler.d.ts +11 -0
  983. package/dist/threejs-compatibility/performance/RendererProfiler.d.ts.map +1 -0
  984. package/dist/threejs-compatibility/performance/RendererProfiler.js +10 -0
  985. package/dist/threejs-compatibility/performance/RendererProfiler.js.map +1 -0
  986. package/dist/threejs-compatibility/performance/TextureStreaming.d.ts +7 -0
  987. package/dist/threejs-compatibility/performance/TextureStreaming.d.ts.map +1 -0
  988. package/dist/threejs-compatibility/performance/TextureStreaming.js +10 -0
  989. package/dist/threejs-compatibility/performance/TextureStreaming.js.map +1 -0
  990. package/dist/threejs-compatibility/performance/index.d.ts +13 -0
  991. package/dist/threejs-compatibility/performance/index.d.ts.map +1 -0
  992. package/dist/threejs-compatibility/performance/index.js +9 -0
  993. package/dist/threejs-compatibility/performance/index.js.map +1 -0
  994. package/dist/threejs-compatibility/postprocess/BloomPass.d.ts +9 -0
  995. package/dist/threejs-compatibility/postprocess/BloomPass.d.ts.map +1 -0
  996. package/dist/threejs-compatibility/postprocess/BloomPass.js +14 -0
  997. package/dist/threejs-compatibility/postprocess/BloomPass.js.map +1 -0
  998. package/dist/threejs-compatibility/postprocess/ColorGradingPass.d.ts +10 -0
  999. package/dist/threejs-compatibility/postprocess/ColorGradingPass.d.ts.map +1 -0
  1000. package/dist/threejs-compatibility/postprocess/ColorGradingPass.js +16 -0
  1001. package/dist/threejs-compatibility/postprocess/ColorGradingPass.js.map +1 -0
  1002. package/dist/threejs-compatibility/postprocess/DepthOfFieldPass.d.ts +9 -0
  1003. package/dist/threejs-compatibility/postprocess/DepthOfFieldPass.d.ts.map +1 -0
  1004. package/dist/threejs-compatibility/postprocess/DepthOfFieldPass.js +19 -0
  1005. package/dist/threejs-compatibility/postprocess/DepthOfFieldPass.js.map +1 -0
  1006. package/dist/threejs-compatibility/postprocess/EffectComposer.d.ts +7 -0
  1007. package/dist/threejs-compatibility/postprocess/EffectComposer.d.ts.map +1 -0
  1008. package/dist/threejs-compatibility/postprocess/EffectComposer.js +11 -0
  1009. package/dist/threejs-compatibility/postprocess/EffectComposer.js.map +1 -0
  1010. package/dist/threejs-compatibility/postprocess/FXAAPass.d.ts +7 -0
  1011. package/dist/threejs-compatibility/postprocess/FXAAPass.d.ts.map +1 -0
  1012. package/dist/threejs-compatibility/postprocess/FXAAPass.js +10 -0
  1013. package/dist/threejs-compatibility/postprocess/FXAAPass.js.map +1 -0
  1014. package/dist/threejs-compatibility/postprocess/MotionBlurPass.d.ts +9 -0
  1015. package/dist/threejs-compatibility/postprocess/MotionBlurPass.d.ts.map +1 -0
  1016. package/dist/threejs-compatibility/postprocess/MotionBlurPass.js +18 -0
  1017. package/dist/threejs-compatibility/postprocess/MotionBlurPass.js.map +1 -0
  1018. package/dist/threejs-compatibility/postprocess/OutlinePass.d.ts +9 -0
  1019. package/dist/threejs-compatibility/postprocess/OutlinePass.d.ts.map +1 -0
  1020. package/dist/threejs-compatibility/postprocess/OutlinePass.js +19 -0
  1021. package/dist/threejs-compatibility/postprocess/OutlinePass.js.map +1 -0
  1022. package/dist/threejs-compatibility/postprocess/PostProcessTypes.d.ts +42 -0
  1023. package/dist/threejs-compatibility/postprocess/PostProcessTypes.d.ts.map +1 -0
  1024. package/dist/threejs-compatibility/postprocess/PostProcessTypes.js +123 -0
  1025. package/dist/threejs-compatibility/postprocess/PostProcessTypes.js.map +1 -0
  1026. package/dist/threejs-compatibility/postprocess/RenderPass.d.ts +7 -0
  1027. package/dist/threejs-compatibility/postprocess/RenderPass.d.ts.map +1 -0
  1028. package/dist/threejs-compatibility/postprocess/RenderPass.js +8 -0
  1029. package/dist/threejs-compatibility/postprocess/RenderPass.js.map +1 -0
  1030. package/dist/threejs-compatibility/postprocess/SMAAPass.d.ts +7 -0
  1031. package/dist/threejs-compatibility/postprocess/SMAAPass.d.ts.map +1 -0
  1032. package/dist/threejs-compatibility/postprocess/SMAAPass.js +10 -0
  1033. package/dist/threejs-compatibility/postprocess/SMAAPass.js.map +1 -0
  1034. package/dist/threejs-compatibility/postprocess/SSAOPass.d.ts +9 -0
  1035. package/dist/threejs-compatibility/postprocess/SSAOPass.d.ts.map +1 -0
  1036. package/dist/threejs-compatibility/postprocess/SSAOPass.js +19 -0
  1037. package/dist/threejs-compatibility/postprocess/SSAOPass.js.map +1 -0
  1038. package/dist/threejs-compatibility/postprocess/ShaderPass.d.ts +9 -0
  1039. package/dist/threejs-compatibility/postprocess/ShaderPass.d.ts.map +1 -0
  1040. package/dist/threejs-compatibility/postprocess/ShaderPass.js +11 -0
  1041. package/dist/threejs-compatibility/postprocess/ShaderPass.js.map +1 -0
  1042. package/dist/threejs-compatibility/postprocess/TAAPass.d.ts +7 -0
  1043. package/dist/threejs-compatibility/postprocess/TAAPass.d.ts.map +1 -0
  1044. package/dist/threejs-compatibility/postprocess/TAAPass.js +10 -0
  1045. package/dist/threejs-compatibility/postprocess/TAAPass.js.map +1 -0
  1046. package/dist/threejs-compatibility/postprocess/VignettePass.d.ts +9 -0
  1047. package/dist/threejs-compatibility/postprocess/VignettePass.d.ts.map +1 -0
  1048. package/dist/threejs-compatibility/postprocess/VignettePass.js +14 -0
  1049. package/dist/threejs-compatibility/postprocess/VignettePass.js.map +1 -0
  1050. package/dist/threejs-compatibility/postprocess/index.d.ts +16 -0
  1051. package/dist/threejs-compatibility/postprocess/index.d.ts.map +1 -0
  1052. package/dist/threejs-compatibility/postprocess/index.js +15 -0
  1053. package/dist/threejs-compatibility/postprocess/index.js.map +1 -0
  1054. package/dist/threejs-compatibility/shaders/NodeMaterial.d.ts +14 -0
  1055. package/dist/threejs-compatibility/shaders/NodeMaterial.d.ts.map +1 -0
  1056. package/dist/threejs-compatibility/shaders/NodeMaterial.js +15 -0
  1057. package/dist/threejs-compatibility/shaders/NodeMaterial.js.map +1 -0
  1058. package/dist/threejs-compatibility/shaders/RawShaderMaterial.d.ts +6 -0
  1059. package/dist/threejs-compatibility/shaders/RawShaderMaterial.d.ts.map +1 -0
  1060. package/dist/threejs-compatibility/shaders/RawShaderMaterial.js +6 -0
  1061. package/dist/threejs-compatibility/shaders/RawShaderMaterial.js.map +1 -0
  1062. package/dist/threejs-compatibility/shaders/ShaderDiagnostics.d.ts +7 -0
  1063. package/dist/threejs-compatibility/shaders/ShaderDiagnostics.d.ts.map +1 -0
  1064. package/dist/threejs-compatibility/shaders/ShaderDiagnostics.js +12 -0
  1065. package/dist/threejs-compatibility/shaders/ShaderDiagnostics.js.map +1 -0
  1066. package/dist/threejs-compatibility/shaders/ShaderMaterial.d.ts +12 -0
  1067. package/dist/threejs-compatibility/shaders/ShaderMaterial.d.ts.map +1 -0
  1068. package/dist/threejs-compatibility/shaders/ShaderMaterial.js +20 -0
  1069. package/dist/threejs-compatibility/shaders/ShaderMaterial.js.map +1 -0
  1070. package/dist/threejs-compatibility/shaders/ThreeCompatShaderChunks.d.ts +7 -0
  1071. package/dist/threejs-compatibility/shaders/ThreeCompatShaderChunks.d.ts.map +1 -0
  1072. package/dist/threejs-compatibility/shaders/ThreeCompatShaderChunks.js +7 -0
  1073. package/dist/threejs-compatibility/shaders/ThreeCompatShaderChunks.js.map +1 -0
  1074. package/dist/threejs-compatibility/shaders/Uniforms.d.ts +8 -0
  1075. package/dist/threejs-compatibility/shaders/Uniforms.d.ts.map +1 -0
  1076. package/dist/threejs-compatibility/shaders/Uniforms.js +14 -0
  1077. package/dist/threejs-compatibility/shaders/Uniforms.js.map +1 -0
  1078. package/dist/threejs-compatibility/shaders/index.d.ts +10 -0
  1079. package/dist/threejs-compatibility/shaders/index.d.ts.map +1 -0
  1080. package/dist/threejs-compatibility/shaders/index.js +7 -0
  1081. package/dist/threejs-compatibility/shaders/index.js.map +1 -0
  1082. package/dist/threejs-compatibility/vfx/GPUPointCloud.d.ts +7 -0
  1083. package/dist/threejs-compatibility/vfx/GPUPointCloud.d.ts.map +1 -0
  1084. package/dist/threejs-compatibility/vfx/GPUPointCloud.js +12 -0
  1085. package/dist/threejs-compatibility/vfx/GPUPointCloud.js.map +1 -0
  1086. package/dist/threejs-compatibility/vfx/LineRenderer.d.ts +10 -0
  1087. package/dist/threejs-compatibility/vfx/LineRenderer.d.ts.map +1 -0
  1088. package/dist/threejs-compatibility/vfx/LineRenderer.js +7 -0
  1089. package/dist/threejs-compatibility/vfx/LineRenderer.js.map +1 -0
  1090. package/dist/threejs-compatibility/vfx/ParticleSystem.d.ts +12 -0
  1091. package/dist/threejs-compatibility/vfx/ParticleSystem.d.ts.map +1 -0
  1092. package/dist/threejs-compatibility/vfx/ParticleSystem.js +15 -0
  1093. package/dist/threejs-compatibility/vfx/ParticleSystem.js.map +1 -0
  1094. package/dist/threejs-compatibility/vfx/SpriteSystem.d.ts +11 -0
  1095. package/dist/threejs-compatibility/vfx/SpriteSystem.d.ts.map +1 -0
  1096. package/dist/threejs-compatibility/vfx/SpriteSystem.js +7 -0
  1097. package/dist/threejs-compatibility/vfx/SpriteSystem.js.map +1 -0
  1098. package/dist/threejs-compatibility/vfx/TrailRenderer.d.ts +5 -0
  1099. package/dist/threejs-compatibility/vfx/TrailRenderer.d.ts.map +1 -0
  1100. package/dist/threejs-compatibility/vfx/TrailRenderer.js +9 -0
  1101. package/dist/threejs-compatibility/vfx/TrailRenderer.js.map +1 -0
  1102. package/dist/threejs-compatibility/vfx/VFXDiagnostics.d.ts +21 -0
  1103. package/dist/threejs-compatibility/vfx/VFXDiagnostics.d.ts.map +1 -0
  1104. package/dist/threejs-compatibility/vfx/VFXDiagnostics.js +12 -0
  1105. package/dist/threejs-compatibility/vfx/VFXDiagnostics.js.map +1 -0
  1106. package/dist/threejs-compatibility/vfx/index.d.ts +10 -0
  1107. package/dist/threejs-compatibility/vfx/index.d.ts.map +1 -0
  1108. package/dist/threejs-compatibility/vfx/index.js +7 -0
  1109. package/dist/threejs-compatibility/vfx/index.js.map +1 -0
  1110. package/dist/threejs-example-parity/index.d.ts +57 -0
  1111. package/dist/threejs-example-parity/index.d.ts.map +1 -0
  1112. package/dist/threejs-example-parity/index.js +139 -0
  1113. package/dist/threejs-example-parity/index.js.map +1 -0
  1114. package/dist/webgpu/WebGPUBuffer.d.ts +2 -0
  1115. package/dist/webgpu/WebGPUBuffer.d.ts.map +1 -0
  1116. package/dist/webgpu/WebGPUBuffer.js +2 -0
  1117. package/dist/webgpu/WebGPUBuffer.js.map +1 -0
  1118. package/dist/webgpu/WebGPUCompute.d.ts +3 -0
  1119. package/dist/webgpu/WebGPUCompute.d.ts.map +1 -0
  1120. package/dist/webgpu/WebGPUCompute.js +2 -0
  1121. package/dist/webgpu/WebGPUCompute.js.map +1 -0
  1122. package/dist/webgpu/WebGPUPipelineCache.d.ts +6 -0
  1123. package/dist/webgpu/WebGPUPipelineCache.d.ts.map +1 -0
  1124. package/dist/webgpu/WebGPUPipelineCache.js +15 -0
  1125. package/dist/webgpu/WebGPUPipelineCache.js.map +1 -0
  1126. package/dist/webgpu/WebGPUPostProcess.d.ts +3 -0
  1127. package/dist/webgpu/WebGPUPostProcess.d.ts.map +1 -0
  1128. package/dist/webgpu/WebGPUPostProcess.js +2 -0
  1129. package/dist/webgpu/WebGPUPostProcess.js.map +1 -0
  1130. package/dist/webgpu/WebGPUTexture.d.ts +3 -0
  1131. package/dist/webgpu/WebGPUTexture.d.ts.map +1 -0
  1132. package/dist/webgpu/WebGPUTexture.js +2 -0
  1133. package/dist/webgpu/WebGPUTexture.js.map +1 -0
  1134. package/package.json +18 -0
  1135. package/src/ArchitecturalLightingFixtures.ts +241 -0
  1136. package/src/ArchitecturalMaterialCatalog.ts +130 -0
  1137. package/src/ArchitecturalMeasurementFixtures.ts +155 -0
  1138. package/src/BRDFLut.ts +47 -0
  1139. package/src/CameraFraming.ts +200 -0
  1140. package/src/CanonicalSceneFixtures.ts +95 -0
  1141. package/src/CascadedShadowMaps.ts +449 -0
  1142. package/src/ColorManagement.ts +127 -0
  1143. package/src/CullingFixtures.ts +280 -0
  1144. package/src/DecalGeometry.ts +26 -0
  1145. package/src/DepthPass.ts +110 -0
  1146. package/src/EnvironmentBackgroundPass.ts +194 -0
  1147. package/src/EnvironmentBackgroundResources.ts +309 -0
  1148. package/src/EnvironmentLighting.ts +96 -0
  1149. package/src/EnvironmentMapResources.ts +1026 -0
  1150. package/src/EnvironmentPipeline.ts +69 -0
  1151. package/src/EnvironmentPlatform.ts +1306 -0
  1152. package/src/EnvironmentPreset.ts +155 -0
  1153. package/src/Exposure.ts +66 -0
  1154. package/src/ExternalParityRenderPreset.ts +725 -0
  1155. package/src/ForwardPass.ts +1639 -0
  1156. package/src/FrameVisualMetrics.ts +218 -0
  1157. package/src/Geometry.ts +461 -0
  1158. package/src/GeometryPrimitives.ts +2 -0
  1159. package/src/HDRRenderPipeline.ts +94 -0
  1160. package/src/IBL.ts +86 -0
  1161. package/src/IndexBuffer.ts +57 -0
  1162. package/src/InstancedPBRMaterial.ts +186 -0
  1163. package/src/InstancedUnlitMaterial.ts +60 -0
  1164. package/src/Instancing.ts +19 -0
  1165. package/src/LightCollector.ts +82 -0
  1166. package/src/LightUniforms.ts +47 -0
  1167. package/src/LightingDebug.ts +80 -0
  1168. package/src/LightingDefaults.ts +79 -0
  1169. package/src/LightingRig.ts +301 -0
  1170. package/src/LineGeometry.ts +2 -0
  1171. package/src/Material.ts +209 -0
  1172. package/src/MaterialBinding.ts +131 -0
  1173. package/src/MaterialInstance.ts +59 -0
  1174. package/src/MaterialPresets.ts +272 -0
  1175. package/src/MorphTarget.ts +123 -0
  1176. package/src/MorphUnlitMaterial.ts +54 -0
  1177. package/src/NormalMappedPBRMaterial.ts +188 -0
  1178. package/src/OceanFixtures.ts +318 -0
  1179. package/src/PBRLightingDefaults.ts +12 -0
  1180. package/src/PBRMaterial.ts +442 -0
  1181. package/src/PMREM.ts +53 -0
  1182. package/src/PbrReference.ts +681 -0
  1183. package/src/PostProcessPass.ts +2507 -0
  1184. package/src/ProceduralTextureFixtures.ts +393 -0
  1185. package/src/ProductTurntableFixtures.ts +815 -0
  1186. package/src/Raycaster.ts +21 -0
  1187. package/src/ReflectionProbe.ts +13 -0
  1188. package/src/ReflectionSurfaces.ts +219 -0
  1189. package/src/RenderBackend.ts +43 -0
  1190. package/src/RenderDebugViews.ts +138 -0
  1191. package/src/RenderDevice.ts +836 -0
  1192. package/src/RenderGraph.ts +194 -0
  1193. package/src/RenderPass.ts +27 -0
  1194. package/src/RenderPipeline.ts +101 -0
  1195. package/src/RenderQueue.ts +12 -0
  1196. package/src/RenderState.ts +12 -0
  1197. package/src/Renderer.ts +2626 -0
  1198. package/src/RendererDebugOverlay.ts +80 -0
  1199. package/src/RendererFeatureGates.ts +150 -0
  1200. package/src/RendererPostprocessPlan.ts +279 -0
  1201. package/src/RendererTiming.ts +251 -0
  1202. package/src/RendererVisualPipelineReport.ts +836 -0
  1203. package/src/ResourceLifecycle.ts +21 -0
  1204. package/src/Sampler.ts +37 -0
  1205. package/src/SceneOptimization.ts +518 -0
  1206. package/src/ShaderChunks.ts +393 -0
  1207. package/src/ShaderLibrary.ts +2738 -0
  1208. package/src/ShaderModule.ts +36 -0
  1209. package/src/ShaderPreprocessor.ts +260 -0
  1210. package/src/ShaderReflection.ts +201 -0
  1211. package/src/ShadowMap.ts +237 -0
  1212. package/src/ShadowPass.ts +198 -0
  1213. package/src/ShadowProjection.ts +115 -0
  1214. package/src/SkinnedLitMaterial.ts +366 -0
  1215. package/src/SkinnedUnlitMaterial.ts +63 -0
  1216. package/src/SkinningBounds.ts +131 -0
  1217. package/src/SpaceEnvironmentFixtures.ts +200 -0
  1218. package/src/SpriteGeometry.ts +21 -0
  1219. package/src/StereoCameraRig.ts +127 -0
  1220. package/src/StereoEffects.ts +274 -0
  1221. package/src/TerrainFixtures.ts +180 -0
  1222. package/src/Texture.ts +307 -0
  1223. package/src/TextureBinding.ts +91 -0
  1224. package/src/TexturedPBRMaterial.ts +1112 -0
  1225. package/src/TexturedUnlitMaterial.ts +67 -0
  1226. package/src/ToneMapping.ts +105 -0
  1227. package/src/UniformBinder.ts +16 -0
  1228. package/src/UniformLayout.ts +129 -0
  1229. package/src/UnlitMaterial.ts +75 -0
  1230. package/src/VegetationFixtures.ts +314 -0
  1231. package/src/VertexBuffer.ts +120 -0
  1232. package/src/VertexFormat.ts +171 -0
  1233. package/src/VoxelWorldFixtures.ts +280 -0
  1234. package/src/WeatherFixtures.ts +223 -0
  1235. package/src/WebGL2Device.ts +2280 -0
  1236. package/src/WebGL2StateCache.ts +330 -0
  1237. package/src/WebGPUDevice.ts +2806 -0
  1238. package/src/WebGPURenderToTextureProof.ts +139 -0
  1239. package/src/advanced-runtime/AdvancedRenderer.ts +73 -0
  1240. package/src/advanced-runtime/index.ts +9 -0
  1241. package/src/cinematic/BloomPass.ts +26 -0
  1242. package/src/cinematic/CinematicDepthComposition.ts +30 -0
  1243. package/src/cinematic/CinematicEvidence.ts +123 -0
  1244. package/src/cinematic/CinematicLightingRig.ts +144 -0
  1245. package/src/cinematic/CinematicMaterialPresets.ts +130 -0
  1246. package/src/cinematic/CinematicPostProcess.ts +83 -0
  1247. package/src/cinematic/DepthHazePass.ts +30 -0
  1248. package/src/cinematic/EmissivePracticalLightSystem.ts +45 -0
  1249. package/src/cinematic/FilmGrainPass.ts +24 -0
  1250. package/src/cinematic/FogVolumeSystem.ts +30 -0
  1251. package/src/cinematic/GlowCardSystem.ts +44 -0
  1252. package/src/cinematic/RainParticleSystem.ts +151 -0
  1253. package/src/cinematic/VignettePass.ts +25 -0
  1254. package/src/cinematic/WetReflectionApproximation.ts +27 -0
  1255. package/src/cinematic/index.ts +14 -0
  1256. package/src/effects/CollisionModule.ts +64 -0
  1257. package/src/effects/ColorModule.ts +60 -0
  1258. package/src/effects/ForceModule.ts +25 -0
  1259. package/src/effects/GPUParticleBackend.ts +569 -0
  1260. package/src/effects/Particle.ts +108 -0
  1261. package/src/effects/ParticleDiagnostics.ts +224 -0
  1262. package/src/effects/ParticleEffectPresets.ts +147 -0
  1263. package/src/effects/ParticleEmitter.ts +326 -0
  1264. package/src/effects/ParticleModule.ts +26 -0
  1265. package/src/effects/ParticleRenderPass.ts +117 -0
  1266. package/src/effects/ParticleRenderer.ts +132 -0
  1267. package/src/effects/ParticleSystem.ts +333 -0
  1268. package/src/effects/SizeModule.ts +56 -0
  1269. package/src/effects/TrailModule.ts +72 -0
  1270. package/src/effects/VelocityModule.ts +75 -0
  1271. package/src/effects/index.ts +15 -0
  1272. package/src/index.ts +914 -0
  1273. package/src/materials/AlphaSorting.ts +30 -0
  1274. package/src/materials/MaterialExtensions.ts +42 -0
  1275. package/src/materials/PhysicalMaterial.ts +133 -0
  1276. package/src/materials/TransmissionPass.ts +51 -0
  1277. package/src/performance/BVH.ts +18 -0
  1278. package/src/performance/Batcher.ts +2 -0
  1279. package/src/performance/FrustumCuller.ts +9 -0
  1280. package/src/performance/LOD.ts +20 -0
  1281. package/src/performance/Octree.ts +10 -0
  1282. package/src/performance/RenderItemSorting.ts +167 -0
  1283. package/src/performance/RendererStats.ts +43 -0
  1284. package/src/performance/ResourceBudget.ts +44 -0
  1285. package/src/postprocess/BloomPass.ts +28 -0
  1286. package/src/postprocess/CinematicDiagnostics.ts +642 -0
  1287. package/src/postprocess/ColorGradingPass.ts +24 -0
  1288. package/src/postprocess/DepthOfFieldPass.ts +12 -0
  1289. package/src/postprocess/EffectComposer.ts +349 -0
  1290. package/src/postprocess/SSAOPass.ts +20 -0
  1291. package/src/postprocess/index.ts +34 -0
  1292. package/src/production-runtime/AnimationControlsPipeline.ts +77 -0
  1293. package/src/production-runtime/PBRHDRPipeline.ts +381 -0
  1294. package/src/production-runtime/ProductionEffectsPipeline.ts +85 -0
  1295. package/src/production-runtime/ProductionRendererTypes.ts +136 -0
  1296. package/src/production-runtime/ProductionRuntimeRenderer.ts +172 -0
  1297. package/src/production-runtime/ProductionWebGL2Renderer.ts +313 -0
  1298. package/src/production-runtime/ProductionWebGPURenderer.ts +396 -0
  1299. package/src/production-runtime/TransmissionBackdropCapture.ts +130 -0
  1300. package/src/production-runtime/animation/MorphTargetRenderer.ts +2 -0
  1301. package/src/production-runtime/animation/SkinningRenderer.ts +2 -0
  1302. package/src/production-runtime/backends/RendererBackend.ts +17 -0
  1303. package/src/production-runtime/backends/WebGL2RendererBackend.ts +30 -0
  1304. package/src/production-runtime/backends/WebGPURendererBackend.ts +24 -0
  1305. package/src/production-runtime/backends/webgl2/WebGL2Buffer.ts +2 -0
  1306. package/src/production-runtime/backends/webgl2/WebGL2Capabilities.ts +2 -0
  1307. package/src/production-runtime/backends/webgl2/WebGL2RenderTarget.ts +2 -0
  1308. package/src/production-runtime/backends/webgl2/WebGL2Shader.ts +2 -0
  1309. package/src/production-runtime/backends/webgl2/WebGL2StateCache.ts +1 -0
  1310. package/src/production-runtime/backends/webgl2/WebGL2Texture.ts +2 -0
  1311. package/src/production-runtime/backends/webgpu/WebGPUBuffer.ts +2 -0
  1312. package/src/production-runtime/backends/webgpu/WebGPUCapabilities.ts +2 -0
  1313. package/src/production-runtime/backends/webgpu/WebGPURenderTarget.ts +2 -0
  1314. package/src/production-runtime/backends/webgpu/WebGPUShader.ts +2 -0
  1315. package/src/production-runtime/backends/webgpu/WebGPUTexture.ts +2 -0
  1316. package/src/production-runtime/color/ColorManagement.ts +3 -0
  1317. package/src/production-runtime/color/ToneMapping.ts +7 -0
  1318. package/src/production-runtime/diagnostics/FrameCapture.ts +2 -0
  1319. package/src/production-runtime/diagnostics/GPUCapabilities.ts +2 -0
  1320. package/src/production-runtime/diagnostics/RendererStats.ts +2 -0
  1321. package/src/production-runtime/environment/EnvironmentMap.ts +1 -0
  1322. package/src/production-runtime/environment/HDRLoader.ts +57 -0
  1323. package/src/production-runtime/environment/PMREMGenerator.ts +713 -0
  1324. package/src/production-runtime/framegraph/FrameGraph.ts +18 -0
  1325. package/src/production-runtime/framegraph/RenderPass.ts +15 -0
  1326. package/src/production-runtime/geometry/ProjectedDecalGeometry.ts +439 -0
  1327. package/src/production-runtime/index.ts +127 -0
  1328. package/src/production-runtime/lights/LightManager.ts +7 -0
  1329. package/src/production-runtime/lights/ShadowMapRenderer.ts +5 -0
  1330. package/src/production-runtime/materials/GLTFMaterialAdapter.ts +6 -0
  1331. package/src/production-runtime/materials/GLTFPBRMaterialAdapter.ts +2 -0
  1332. package/src/production-runtime/materials/MaterialCompiler.ts +7 -0
  1333. package/src/production-runtime/materials/MaterialTextureBindings.ts +5 -0
  1334. package/src/production-runtime/materials/PBRMaterial.ts +2 -0
  1335. package/src/production-runtime/materials/PBRShaderFeatures.ts +2 -0
  1336. package/src/production-runtime/passes/ContactShadowPass.ts +184 -0
  1337. package/src/production-runtime/passes/DepthPrepass.ts +7 -0
  1338. package/src/production-runtime/passes/OpaquePass.ts +7 -0
  1339. package/src/production-runtime/passes/ShadowPass.ts +7 -0
  1340. package/src/production-runtime/passes/SkyboxPass.ts +7 -0
  1341. package/src/production-runtime/passes/ToneMappingPass.ts +7 -0
  1342. package/src/production-runtime/passes/TransparentPass.ts +7 -0
  1343. package/src/production-runtime/postprocess/BloomPass.ts +51 -0
  1344. package/src/production-runtime/postprocess/ColorGradingPass.ts +49 -0
  1345. package/src/production-runtime/postprocess/DOFPass.ts +47 -0
  1346. package/src/production-runtime/postprocess/FXAAPass.ts +53 -0
  1347. package/src/production-runtime/postprocess/ProductionEffectComposer.ts +78 -0
  1348. package/src/production-runtime/postprocess/ProductionPostProcessTypes.ts +174 -0
  1349. package/src/production-runtime/postprocess/SSAOPass.ts +45 -0
  1350. package/src/production-runtime/resources/GPUBuffer.ts +2 -0
  1351. package/src/production-runtime/resources/GPUTexture.ts +2 -0
  1352. package/src/production-runtime/resources/RenderTarget.ts +3 -0
  1353. package/src/production-runtime/resources/ResourceCache.ts +7 -0
  1354. package/src/production-runtime/scene/Camera.ts +1 -0
  1355. package/src/production-runtime/scene/Lights.ts +2 -0
  1356. package/src/production-runtime/scene/RenderableMesh.ts +2 -0
  1357. package/src/production-runtime/scene/RenderablePrimitive.ts +1 -0
  1358. package/src/production-runtime/scene/RenderableScene.ts +4 -0
  1359. package/src/production-runtime/shaders/ShaderProgramLibrary.ts +7 -0
  1360. package/src/production-runtime/shaders/chunks/brdf.glsl +2 -0
  1361. package/src/production-runtime/shaders/chunks/ibl.glsl +3 -0
  1362. package/src/production-runtime/shaders/chunks/pbr.frag.glsl +47 -0
  1363. package/src/production-runtime/shaders/chunks/pbr.vert.glsl +8 -0
  1364. package/src/production-runtime/shaders/chunks/shadows.glsl +2 -0
  1365. package/src/production-runtime/shaders/wgsl/pbr.wgsl +3 -0
  1366. package/src/production-runtime/shaders/wgsl/postprocess.wgsl +2 -0
  1367. package/src/production-runtime/shaders/wgsl/skybox.wgsl +2 -0
  1368. package/src/shaders/depth.frag.glsl +5 -0
  1369. package/src/shaders/depth.vert.glsl +8 -0
  1370. package/src/shaders/pbr-direct.frag.glsl +687 -0
  1371. package/src/shaders/pbr-direct.vert.glsl +18 -0
  1372. package/src/shaders/unlit.frag.glsl +18 -0
  1373. package/src/shaders/unlit.vert.glsl +13 -0
  1374. package/src/shadows/CascadedShadowPipeline.ts +53 -0
  1375. package/src/shadows/ContactShadows.ts +106 -0
  1376. package/src/shadows/ShadowDebugViews.ts +46 -0
  1377. package/src/threejs-compatibility/InstancingSystem.ts +17 -0
  1378. package/src/threejs-compatibility/LightingSystem.ts +22 -0
  1379. package/src/threejs-compatibility/MaterialSystem.ts +9 -0
  1380. package/src/threejs-compatibility/RenderTargetSystem.ts +35 -0
  1381. package/src/threejs-compatibility/RendererDiagnostics.ts +61 -0
  1382. package/src/threejs-compatibility/SceneRenderer.ts +34 -0
  1383. package/src/threejs-compatibility/ShadowSystem.ts +19 -0
  1384. package/src/threejs-compatibility/TextureSystem.ts +19 -0
  1385. package/src/threejs-compatibility/ThreeCompatRenderer.ts +90 -0
  1386. package/src/threejs-compatibility/TransparencySystem.ts +19 -0
  1387. package/src/threejs-compatibility/index.ts +29 -0
  1388. package/src/threejs-compatibility/performance/BVH.ts +14 -0
  1389. package/src/threejs-compatibility/performance/FrustumCulling.ts +10 -0
  1390. package/src/threejs-compatibility/performance/Instancing.ts +4 -0
  1391. package/src/threejs-compatibility/performance/LODSystem.ts +16 -0
  1392. package/src/threejs-compatibility/performance/OcclusionCulling.ts +6 -0
  1393. package/src/threejs-compatibility/performance/RaycastAcceleration.ts +12 -0
  1394. package/src/threejs-compatibility/performance/RendererProfiler.ts +19 -0
  1395. package/src/threejs-compatibility/performance/TextureStreaming.ts +4 -0
  1396. package/src/threejs-compatibility/performance/index.ts +12 -0
  1397. package/src/threejs-compatibility/postprocess/BloomPass.ts +16 -0
  1398. package/src/threejs-compatibility/postprocess/ColorGradingPass.ts +16 -0
  1399. package/src/threejs-compatibility/postprocess/DepthOfFieldPass.ts +21 -0
  1400. package/src/threejs-compatibility/postprocess/EffectComposer.ts +14 -0
  1401. package/src/threejs-compatibility/postprocess/FXAAPass.ts +15 -0
  1402. package/src/threejs-compatibility/postprocess/MotionBlurPass.ts +20 -0
  1403. package/src/threejs-compatibility/postprocess/OutlinePass.ts +21 -0
  1404. package/src/threejs-compatibility/postprocess/PostProcessTypes.ts +169 -0
  1405. package/src/threejs-compatibility/postprocess/RenderPass.ts +9 -0
  1406. package/src/threejs-compatibility/postprocess/SMAAPass.ts +15 -0
  1407. package/src/threejs-compatibility/postprocess/SSAOPass.ts +21 -0
  1408. package/src/threejs-compatibility/postprocess/ShaderPass.ts +7 -0
  1409. package/src/threejs-compatibility/postprocess/TAAPass.ts +15 -0
  1410. package/src/threejs-compatibility/postprocess/VignettePass.ts +16 -0
  1411. package/src/threejs-compatibility/postprocess/index.ts +15 -0
  1412. package/src/threejs-compatibility/shaders/NodeMaterial.ts +21 -0
  1413. package/src/threejs-compatibility/shaders/RawShaderMaterial.ts +6 -0
  1414. package/src/threejs-compatibility/shaders/ShaderDiagnostics.ts +17 -0
  1415. package/src/threejs-compatibility/shaders/ShaderMaterial.ts +18 -0
  1416. package/src/threejs-compatibility/shaders/ThreeCompatShaderChunks.ts +6 -0
  1417. package/src/threejs-compatibility/shaders/Uniforms.ts +18 -0
  1418. package/src/threejs-compatibility/shaders/index.ts +9 -0
  1419. package/src/threejs-compatibility/vfx/GPUPointCloud.ts +7 -0
  1420. package/src/threejs-compatibility/vfx/LineRenderer.ts +13 -0
  1421. package/src/threejs-compatibility/vfx/ParticleSystem.ts +23 -0
  1422. package/src/threejs-compatibility/vfx/SpriteSystem.ts +14 -0
  1423. package/src/threejs-compatibility/vfx/TrailRenderer.ts +8 -0
  1424. package/src/threejs-compatibility/vfx/VFXDiagnostics.ts +23 -0
  1425. package/src/threejs-compatibility/vfx/index.ts +9 -0
  1426. package/src/threejs-example-parity/index.ts +205 -0
  1427. package/src/webgpu/WebGPUBuffer.ts +1 -0
  1428. package/src/webgpu/WebGPUCompute.ts +2 -0
  1429. package/src/webgpu/WebGPUPipelineCache.ts +15 -0
  1430. package/src/webgpu/WebGPUPostProcess.ts +2 -0
  1431. package/src/webgpu/WebGPUTexture.ts +2 -0
  1432. package/tsconfig.json +26 -0
  1433. package/vitest.config.ts +20 -0
@@ -0,0 +1,2806 @@
1
+ import {
2
+ type BufferUsage,
3
+ type DrawCommand,
4
+ type RenderBuffer,
5
+ type RenderDevice,
6
+ RenderDeviceError,
7
+ type RenderDeviceDiagnostics,
8
+ type RenderDeviceInfo,
9
+ type RenderShaderProgram,
10
+ type RenderTarget,
11
+ type RenderTargetDescriptor,
12
+ type ShaderReflection,
13
+ type ShaderSources,
14
+ type UniformValue,
15
+ viewBytes
16
+ } from "./RenderDevice";
17
+ import { reflectShaderSources } from "./ShaderReflection";
18
+ import type { Sampler, TextureMagFilter, TextureMinFilter } from "./Sampler";
19
+ import { Texture, bytesPerPixel, isCompressedTextureFormat, type TextureFormat } from "./Texture";
20
+ import { TextureBinding } from "./TextureBinding";
21
+ import { type VertexFormat } from "./VertexFormat";
22
+
23
+ const BUFFER_USAGE = {
24
+ MAP_READ: 0x0001,
25
+ COPY_SRC: 0x0004,
26
+ COPY_DST: 0x0008,
27
+ INDEX: 0x0010,
28
+ VERTEX: 0x0020,
29
+ UNIFORM: 0x0040
30
+ } as const;
31
+ const MAP_MODE = {
32
+ READ: 0x0001
33
+ } as const;
34
+
35
+ const TEXTURE_USAGE = {
36
+ RENDER_ATTACHMENT: 0x0010,
37
+ COPY_SRC: 0x0001,
38
+ COPY_DST: 0x0002,
39
+ TEXTURE_BINDING: 0x0004
40
+ } as const;
41
+ const DEPTH_TEXTURE_FORMAT = "depth24plus";
42
+
43
+ interface ForwardShadowUniforms {
44
+ readonly texture: TextureBinding;
45
+ readonly matrix: readonly number[];
46
+ readonly strength: number;
47
+ readonly bias: number;
48
+ }
49
+
50
+ export interface WebGPULike {
51
+ requestAdapter(): Promise<WebGPUAdapterLike | null>;
52
+ getPreferredCanvasFormat?(): string;
53
+ }
54
+
55
+ export interface WebGPUAdapterLike {
56
+ requestDevice(): Promise<WebGPUDeviceLike>;
57
+ readonly name?: string;
58
+ readonly info?: {
59
+ readonly vendor?: string;
60
+ readonly architecture?: string;
61
+ readonly device?: string;
62
+ readonly description?: string;
63
+ };
64
+ }
65
+
66
+ export interface WebGPUDeviceLike {
67
+ readonly queue: WebGPUQueueLike;
68
+ readonly lost?: Promise<WebGPUDeviceLostInfoLike>;
69
+ createBuffer(descriptor: WebGPUBufferDescriptorLike): WebGPUBufferLike;
70
+ createShaderModule?(descriptor: { readonly label?: string; readonly code: string }): unknown;
71
+ createRenderPipeline?(descriptor: WebGPURenderPipelineDescriptorLike): WebGPURenderPipelineLike;
72
+ createBindGroup?(descriptor: WebGPUBindGroupDescriptorLike): WebGPUBindGroupLike;
73
+ createTexture?(descriptor: WebGPUTextureDescriptorLike): WebGPUTextureLike;
74
+ createSampler?(descriptor?: WebGPUSamplerDescriptorLike): WebGPUSamplerLike;
75
+ createCommandEncoder?(descriptor?: { readonly label?: string }): WebGPUCommandEncoderLike;
76
+ destroy?(): void;
77
+ }
78
+
79
+ export interface WebGPUDeviceLostInfoLike {
80
+ readonly reason?: string;
81
+ readonly message?: string;
82
+ }
83
+
84
+ export interface WebGPUQueueLike {
85
+ writeBuffer(buffer: WebGPUBufferLike, offset: number, data: ArrayBuffer | ArrayBufferView, dataOffset?: number, size?: number): void;
86
+ writeTexture?(destination: WebGPUImageCopyTextureLike, data: ArrayBuffer | ArrayBufferView, dataLayout: WebGPUImageDataLayoutLike, size: WebGPUExtent3DLike): void;
87
+ copyExternalImageToTexture?(source: WebGPUImageCopyExternalImageLike, destination: WebGPUImageCopyTextureLike, size: WebGPUExtent3DLike): void;
88
+ submit(commands: readonly unknown[]): void;
89
+ }
90
+
91
+ export interface WebGPUBufferDescriptorLike {
92
+ readonly label?: string;
93
+ readonly size: number;
94
+ readonly usage: number;
95
+ readonly mappedAtCreation?: boolean;
96
+ }
97
+
98
+ export interface WebGPUBufferLike {
99
+ mapAsync?(mode: number): Promise<void>;
100
+ getMappedRange?(): ArrayBuffer;
101
+ unmap?(): void;
102
+ destroy(): void;
103
+ }
104
+
105
+ export interface WebGPUTextureDescriptorLike {
106
+ readonly label?: string;
107
+ readonly size: readonly [number, number, number?] | { readonly width: number; readonly height: number; readonly depthOrArrayLayers?: number };
108
+ readonly format: string;
109
+ readonly usage: number;
110
+ readonly mipLevelCount?: number;
111
+ }
112
+
113
+ export interface WebGPUTextureLike {
114
+ createView(): unknown;
115
+ destroy(): void;
116
+ }
117
+
118
+ export interface WebGPUSamplerDescriptorLike {
119
+ readonly minFilter?: "nearest" | "linear";
120
+ readonly magFilter?: "nearest" | "linear";
121
+ readonly mipmapFilter?: "nearest" | "linear";
122
+ readonly addressModeU?: "clamp-to-edge" | "repeat" | "mirror-repeat";
123
+ readonly addressModeV?: "clamp-to-edge" | "repeat" | "mirror-repeat";
124
+ readonly maxAnisotropy?: number;
125
+ }
126
+
127
+ export interface WebGPUSamplerLike {}
128
+
129
+ export interface WebGPUCanvasContextLike {
130
+ configure(configuration: WebGPUCanvasConfigurationLike): void;
131
+ getCurrentTexture(): WebGPUTextureLike;
132
+ unconfigure?(): void;
133
+ }
134
+
135
+ export interface WebGPUCanvasConfigurationLike {
136
+ readonly device: WebGPUDeviceLike;
137
+ readonly format: string;
138
+ readonly alphaMode?: "opaque" | "premultiplied";
139
+ }
140
+
141
+ export interface WebGPURenderPipelineDescriptorLike {
142
+ readonly label?: string;
143
+ readonly layout: "auto";
144
+ readonly vertex: {
145
+ readonly module: unknown;
146
+ readonly entryPoint: string;
147
+ readonly buffers?: readonly WebGPUVertexBufferLayoutLike[];
148
+ };
149
+ readonly fragment?: {
150
+ readonly module: unknown;
151
+ readonly entryPoint: string;
152
+ readonly targets: readonly [{ readonly format: string }];
153
+ };
154
+ readonly primitive: {
155
+ readonly topology: "triangle-list" | "line-list" | "point-list";
156
+ };
157
+ readonly depthStencil?: {
158
+ readonly format: string;
159
+ readonly depthWriteEnabled: boolean;
160
+ readonly depthCompare: "less-equal" | "always";
161
+ };
162
+ }
163
+
164
+ export interface WebGPUVertexBufferLayoutLike {
165
+ readonly arrayStride: number;
166
+ readonly attributes: readonly WebGPUVertexAttributeLike[];
167
+ }
168
+
169
+ export interface WebGPUVertexAttributeLike {
170
+ readonly shaderLocation: number;
171
+ readonly offset: number;
172
+ readonly format: "float32" | "float32x2" | "float32x3" | "float32x4";
173
+ }
174
+
175
+ export interface WebGPUBindGroupDescriptorLike {
176
+ readonly label?: string;
177
+ readonly layout: unknown;
178
+ readonly entries: readonly WebGPUBindGroupEntryLike[];
179
+ }
180
+
181
+ export interface WebGPUBindGroupEntryLike {
182
+ readonly binding: number;
183
+ readonly resource: unknown;
184
+ }
185
+
186
+ export interface WebGPUBindGroupLike {}
187
+
188
+ export interface WebGPURenderPipelineLike {
189
+ getBindGroupLayout?(index: number): unknown;
190
+ }
191
+
192
+ export interface WebGPUCommandEncoderLike {
193
+ beginRenderPass(descriptor: WebGPURenderPassDescriptorLike): WebGPURenderPassEncoderLike;
194
+ copyTextureToBuffer?(source: WebGPUImageCopyTextureLike, destination: WebGPUImageCopyBufferLike, size: WebGPUExtent3DLike): void;
195
+ finish(): unknown;
196
+ }
197
+
198
+ export interface WebGPUImageCopyTextureLike {
199
+ readonly texture: WebGPUTextureLike;
200
+ readonly mipLevel?: number;
201
+ readonly origin?: {
202
+ readonly x?: number;
203
+ readonly y?: number;
204
+ readonly z?: number;
205
+ };
206
+ }
207
+
208
+ export interface WebGPUImageCopyExternalImageLike {
209
+ readonly source: TexImageSource;
210
+ readonly origin?: {
211
+ readonly x?: number;
212
+ readonly y?: number;
213
+ };
214
+ readonly flipY?: boolean;
215
+ }
216
+
217
+ export interface WebGPUImageCopyBufferLike {
218
+ readonly buffer: WebGPUBufferLike;
219
+ readonly bytesPerRow: number;
220
+ readonly rowsPerImage?: number;
221
+ }
222
+
223
+ export interface WebGPUImageDataLayoutLike {
224
+ readonly offset?: number;
225
+ readonly bytesPerRow: number;
226
+ readonly rowsPerImage?: number;
227
+ }
228
+
229
+ export type WebGPUExtent3DLike =
230
+ | readonly [number, number, number?]
231
+ | {
232
+ readonly width: number;
233
+ readonly height: number;
234
+ readonly depthOrArrayLayers?: number;
235
+ };
236
+
237
+ export interface WebGPURenderPassDescriptorLike {
238
+ readonly label?: string;
239
+ readonly colorAttachments: readonly [{
240
+ readonly view: unknown;
241
+ readonly clearValue?: readonly [number, number, number, number];
242
+ readonly loadOp: "clear" | "load";
243
+ readonly storeOp: "store";
244
+ }];
245
+ readonly depthStencilAttachment?: {
246
+ readonly view: unknown;
247
+ readonly depthClearValue?: number;
248
+ readonly depthLoadOp: "clear" | "load";
249
+ readonly depthStoreOp: "store";
250
+ };
251
+ }
252
+
253
+ export interface WebGPURenderPassEncoderLike {
254
+ setPipeline(pipeline: WebGPURenderPipelineLike): void;
255
+ setVertexBuffer(slot: number, buffer: WebGPUBufferLike): void;
256
+ setBindGroup?(index: number, bindGroup: WebGPUBindGroupLike): void;
257
+ setIndexBuffer?(buffer: WebGPUBufferLike, indexFormat: "uint16" | "uint32"): void;
258
+ draw(vertexCount: number, instanceCount?: number, firstVertex?: number): void;
259
+ drawIndexed?(indexCount: number, instanceCount?: number, firstIndex?: number): void;
260
+ end(): void;
261
+ }
262
+
263
+ export interface WebGPUDeviceOptions {
264
+ readonly gpu?: WebGPULike;
265
+ readonly adapter?: WebGPUAdapterLike;
266
+ readonly device?: WebGPUDeviceLike;
267
+ readonly canvas?: HTMLCanvasElement | OffscreenCanvas;
268
+ readonly presentationFormat?: string;
269
+ }
270
+
271
+ class WebGPURenderBuffer implements RenderBuffer {
272
+ public disposed = false;
273
+ public readonly bytes: Uint8Array;
274
+
275
+ constructor(
276
+ public readonly id: number,
277
+ public readonly usage: BufferUsage,
278
+ public readonly byteLength: number,
279
+ public readonly nativeByteLength: number,
280
+ public readonly handle: WebGPUBufferLike,
281
+ initialData?: ArrayBufferView
282
+ ) {
283
+ this.bytes = new Uint8Array(byteLength);
284
+ if (initialData) this.bytes.set(viewBytes(initialData), 0);
285
+ }
286
+
287
+ dispose(): void {
288
+ if (!this.disposed) {
289
+ this.handle.destroy();
290
+ this.disposed = true;
291
+ }
292
+ }
293
+ }
294
+
295
+ type NativeUniformLayout =
296
+ | "generated-basic"
297
+ | "generated-texture"
298
+ | "generated-pbr"
299
+ | "generated-textured-pbr"
300
+ | "generated-instanced-pbr"
301
+ | "generated-skinned-unlit"
302
+ | "generated-morph-unlit"
303
+ | "passthrough";
304
+
305
+ class WebGPUShaderProgram implements RenderShaderProgram {
306
+ public disposed = false;
307
+ public readonly renderPipelines = new Map<string, WebGPURenderPipelineLike>();
308
+
309
+ constructor(
310
+ public readonly id: number,
311
+ public readonly label: string,
312
+ public readonly marker: string,
313
+ public readonly reflection: ShaderReflection,
314
+ public readonly modules: readonly unknown[],
315
+ public readonly entryPoints: readonly [string, string],
316
+ public readonly nativeUniformLayout: NativeUniformLayout
317
+ ) {}
318
+
319
+ dispose(): void {
320
+ this.disposed = true;
321
+ }
322
+ }
323
+
324
+ class WebGPURenderTarget implements RenderTarget {
325
+ public disposed = false;
326
+ public nativeNeedsClear = true;
327
+ public nativeClearColor: readonly [number, number, number, number] = [0, 0, 0, 1];
328
+ public readonly colorPixels: Uint8Array;
329
+ public readonly colorFloatPixels: Float32Array | null;
330
+ public readonly depthPixels: Float32Array | null;
331
+
332
+ constructor(
333
+ public readonly id: number,
334
+ public readonly width: number,
335
+ public readonly height: number,
336
+ public readonly label: string,
337
+ public readonly colorTexture: Texture,
338
+ public readonly depthTexture: Texture | undefined,
339
+ public readonly nativeTexture: WebGPUTextureLike | null,
340
+ public readonly nativeView: unknown | null,
341
+ public readonly nativeDepthTexture: WebGPUTextureLike | null,
342
+ public readonly nativeDepthView: unknown | null,
343
+ public readonly hasDepth: boolean
344
+ ) {
345
+ this.colorPixels = new Uint8Array(width * height * 4);
346
+ this.colorFloatPixels = colorTexture.format === "rgba16f" || colorTexture.format === "rgba32f"
347
+ ? new Float32Array(width * height * 4)
348
+ : null;
349
+ this.depthPixels = hasDepth ? new Float32Array(width * height).fill(1) : null;
350
+ }
351
+
352
+ dispose(): void {
353
+ if (!this.disposed) {
354
+ this.nativeTexture?.destroy();
355
+ this.nativeDepthTexture?.destroy();
356
+ this.colorTexture.dispose();
357
+ this.depthTexture?.dispose();
358
+ this.disposed = true;
359
+ }
360
+ }
361
+ }
362
+
363
+ export class WebGPUDevice implements RenderDevice {
364
+ public readonly kind = "webgpu";
365
+ public readonly info: RenderDeviceInfo;
366
+ public disposed = false;
367
+ public contextLost = false;
368
+
369
+ private nextId = 1;
370
+ private frameActive = false;
371
+ private drawCalls = 0;
372
+ private viewportWidth = 0;
373
+ private viewportHeight = 0;
374
+ private clearColor: readonly [number, number, number, number] = [0, 0, 0, 1];
375
+ private lastError: string | null = null;
376
+ private nativeSubmissions = 0;
377
+ private nativeTextureBindings = 0;
378
+ private nativeGeneratedBasicSubmissions = 0;
379
+ private nativeGeneratedTextureSubmissions = 0;
380
+ private nativePassthroughSubmissions = 0;
381
+ private nativePbrSubmissions = 0;
382
+ private nativeInstancedSubmissions = 0;
383
+ private nativeSkinnedSubmissions = 0;
384
+ private nativeMorphSubmissions = 0;
385
+ private nativeEnvironmentBindings = 0;
386
+ private nativeShadowMapBindings = 0;
387
+ private canvasSubmissions = 0;
388
+ private readonly buffers = new Set<WebGPURenderBuffer>();
389
+ private readonly shaders = new Set<WebGPUShaderProgram>();
390
+ private readonly renderTargets = new Set<WebGPURenderTarget>();
391
+ private readonly nativeSampledTextures = new Map<Texture, { readonly texture: WebGPUTextureLike; readonly view: unknown }>();
392
+ private activeRenderTarget: WebGPURenderTarget | null = null;
393
+ private backbufferPixels: Uint8Array | null = null;
394
+ private backbufferWidth = 0;
395
+ private backbufferHeight = 0;
396
+ private canvasDepthTexture: WebGPUTextureLike | null = null;
397
+ private canvasDepthView: unknown | null = null;
398
+ private canvasDepthWidth = 0;
399
+ private canvasDepthHeight = 0;
400
+
401
+ static async create(options: WebGPUDeviceOptions = {}): Promise<WebGPUDevice> {
402
+ const gpu = options.gpu ?? readWebGPU(globalThis);
403
+ const adapter = options.adapter ?? (await requestAdapter(gpu));
404
+ if (!adapter) {
405
+ throw new RenderDeviceError("WebGPU adapter request did not return a device owner", "WEBGPU_ADAPTER_MISSING");
406
+ }
407
+ const device = validateWebGPUDevice(await requestDevice(adapter, options.device));
408
+ const canvasContext = options.canvas ? acquireWebGPUCanvasContext(options.canvas) : null;
409
+ const presentationFormat = options.presentationFormat ?? gpu?.getPreferredCanvasFormat?.() ?? "bgra8unorm";
410
+ if (canvasContext) {
411
+ canvasContext.configure({
412
+ device,
413
+ format: presentationFormat,
414
+ alphaMode: "opaque"
415
+ });
416
+ }
417
+ return new WebGPUDevice(adapter, device, canvasContext, presentationFormat);
418
+ }
419
+
420
+ private constructor(
421
+ private readonly adapter: WebGPUAdapterLike,
422
+ private readonly device: WebGPUDeviceLike,
423
+ private readonly canvasContext: WebGPUCanvasContextLike | null,
424
+ private readonly presentationFormat: string
425
+ ) {
426
+ const supportsNativeRenderPipeline = hasNativeRenderPipeline(device);
427
+ const supportsNativeTextureReadback = hasNativeTextureReadback(device);
428
+ const supportsCanvasSurface = supportsNativeRenderPipeline && canvasContext !== null;
429
+ this.info = {
430
+ backend: "webgpu",
431
+ vendor: adapter.info?.vendor ?? "webgpu",
432
+ renderer: describeAdapter(adapter) ?? "webgpu-render-device",
433
+ capabilities: [
434
+ "buffers",
435
+ "buffer-readback",
436
+ "shader-validation",
437
+ "render-targets",
438
+ "pixel-readback",
439
+ "postprocess-presentation",
440
+ "hdr-render-targets",
441
+ "float-readback",
442
+ "draw-validation",
443
+ "rasterization",
444
+ "depth-render-targets",
445
+ "spot-shadow-maps",
446
+ "point-shadow-maps",
447
+ "hdr-image-based-lighting",
448
+ ...(supportsNativeRenderPipeline ? ["native-render-pipeline" as const] : []),
449
+ ...(hasNativeSampledTextureBinding(device) ? ["native-sampled-textures" as const] : []),
450
+ ...(supportsNativeTextureReadback ? ["native-texture-readback" as const] : []),
451
+ ...(supportsCanvasSurface ? ["canvas-surface" as const] : [])
452
+ ],
453
+ limitations: [
454
+ "Synchronous readPixels remains CPU-shadowed for deterministic tests; use readPixelsAsync for native WebGPU texture-to-buffer readback when available.",
455
+ "Renderer.render() stays synchronous and uses CPU-shadowed readback for deterministic compatibility; use Renderer.renderAsync() when renderer-owned WebGPU postprocess must read native render targets.",
456
+ "Sampleable WebGPU depth render-target textures are not advertised until native texture binding and depth readback evidence exists.",
457
+ ...(supportsNativeRenderPipeline ? [] : ["native WebGPU render-pipeline submission requires createRenderPipeline, createTexture, and createCommandEncoder."]),
458
+ ...(hasNativeSampledTextureBinding(device) ? [] : ["native WebGPU sampled texture binding requires createSampler, createTexture, and queue.writeTexture."]),
459
+ ...(supportsNativeTextureReadback ? [] : ["native WebGPU texture readback requires copyTextureToBuffer plus mappable readback buffers."]),
460
+ ...(canvasContext ? [] : ["Canvas presentation requires a canvas that exposes a webgpu context."])
461
+ ]
462
+ };
463
+ this.observeDeviceLost();
464
+ }
465
+
466
+ createBuffer(usage: BufferUsage, byteLength: number, initialData?: ArrayBufferView): RenderBuffer {
467
+ this.assertAlive();
468
+ if (byteLength <= 0 || !Number.isInteger(byteLength)) {
469
+ throw new RenderDeviceError("Buffer byteLength must be a positive integer", "INVALID_BUFFER_SIZE", { byteLength });
470
+ }
471
+ if (initialData && initialData.byteLength > byteLength) {
472
+ throw new RenderDeviceError("Initial data exceeds buffer size", "BUFFER_OVERFLOW", {
473
+ byteLength,
474
+ dataByteLength: initialData.byteLength
475
+ });
476
+ }
477
+
478
+ const handle = this.device.createBuffer({
479
+ label: `aura3d-${usage}-${this.nextId}`,
480
+ size: alignTo(byteLength, 4),
481
+ usage: bufferUsageFlags(usage)
482
+ });
483
+ const buffer = new WebGPURenderBuffer(this.nextId++, usage, byteLength, alignTo(byteLength, 4), handle, initialData);
484
+ this.buffers.add(buffer);
485
+ if (initialData) writeAlignedQueueBuffer(this.device.queue, handle, 0, initialData, buffer.nativeByteLength);
486
+ return buffer;
487
+ }
488
+
489
+ updateBuffer(buffer: RenderBuffer, byteOffset: number, data: ArrayBufferView): void {
490
+ this.assertAlive();
491
+ const webgpuBuffer = this.requireBuffer(buffer);
492
+ if (byteOffset < 0 || byteOffset + data.byteLength > webgpuBuffer.byteLength) {
493
+ throw new RenderDeviceError("Buffer update range is out of bounds", "BUFFER_RANGE_OUT_OF_BOUNDS", {
494
+ byteOffset,
495
+ dataByteLength: data.byteLength,
496
+ byteLength: webgpuBuffer.byteLength
497
+ });
498
+ }
499
+ webgpuBuffer.bytes.set(viewBytes(data), byteOffset);
500
+ writeAlignedQueueBuffer(this.device.queue, webgpuBuffer.handle, byteOffset, webgpuBuffer.bytes.subarray(byteOffset, byteOffset + data.byteLength), webgpuBuffer.nativeByteLength);
501
+ }
502
+
503
+ readBuffer(buffer: RenderBuffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset): Uint8Array {
504
+ this.assertAlive();
505
+ const webgpuBuffer = this.requireBuffer(buffer);
506
+ if (byteOffset < 0 || byteLength < 0 || byteOffset + byteLength > webgpuBuffer.byteLength) {
507
+ throw new RenderDeviceError("Buffer read range is out of bounds", "BUFFER_RANGE_OUT_OF_BOUNDS", {
508
+ byteOffset,
509
+ byteLength,
510
+ bufferByteLength: webgpuBuffer.byteLength
511
+ });
512
+ }
513
+ return webgpuBuffer.bytes.slice(byteOffset, byteOffset + byteLength);
514
+ }
515
+
516
+ createShaderProgram(sources: ShaderSources): RenderShaderProgram {
517
+ this.assertAlive();
518
+ if (!sources.vertex.includes(sources.marker) || !sources.fragment.includes(sources.marker)) {
519
+ throw new RenderDeviceError("Shader source marker is missing from compiled sources", "SHADER_MARKER_MISSING", {
520
+ label: sources.label,
521
+ marker: sources.marker
522
+ });
523
+ }
524
+ const nativeSources = createNativeShaderSources(sources);
525
+ const modules = this.device.createShaderModule
526
+ ? [
527
+ this.device.createShaderModule({ label: `${sources.label}-vertex`, code: nativeSources.vertex }),
528
+ this.device.createShaderModule({ label: `${sources.label}-fragment`, code: nativeSources.fragment })
529
+ ]
530
+ : [];
531
+ const shader = new WebGPUShaderProgram(
532
+ this.nextId++,
533
+ sources.label,
534
+ sources.marker,
535
+ reflectShaderSources(sources),
536
+ modules,
537
+ nativeSources.entryPoints,
538
+ nativeSources.uniformLayout
539
+ );
540
+ this.shaders.add(shader);
541
+ return shader;
542
+ }
543
+
544
+ createRenderTarget(descriptor: RenderTargetDescriptor): RenderTarget {
545
+ this.assertAlive();
546
+ if (
547
+ !Number.isInteger(descriptor.width) ||
548
+ descriptor.width <= 0 ||
549
+ !Number.isInteger(descriptor.height) ||
550
+ descriptor.height <= 0
551
+ ) {
552
+ throw new RenderDeviceError("Render target dimensions must be positive integers", "INVALID_RENDER_TARGET_SIZE", {
553
+ width: descriptor.width,
554
+ height: descriptor.height,
555
+ label: descriptor.label
556
+ });
557
+ }
558
+ const nativeTexture = this.device.createTexture?.({
559
+ label: descriptor.label ?? "aura3d-webgpu-render-target",
560
+ size: [descriptor.width, descriptor.height],
561
+ format: webgpuTextureFormat(descriptor.format ?? "rgba8"),
562
+ usage: TEXTURE_USAGE.RENDER_ATTACHMENT | TEXTURE_USAGE.COPY_SRC | TEXTURE_USAGE.COPY_DST | TEXTURE_USAGE.TEXTURE_BINDING
563
+ }) ?? null;
564
+ const hasDepth = descriptor.depth !== false;
565
+ const hasSampleableDepth = descriptor.depth === "texture";
566
+ const nativeDepthTexture = hasDepth
567
+ ? this.device.createTexture?.({
568
+ label: `${descriptor.label ?? "aura3d-webgpu-render-target"}-depth`,
569
+ size: [descriptor.width, descriptor.height],
570
+ format: DEPTH_TEXTURE_FORMAT,
571
+ usage: TEXTURE_USAGE.RENDER_ATTACHMENT | (hasSampleableDepth ? TEXTURE_USAGE.TEXTURE_BINDING : 0)
572
+ }) ?? null
573
+ : null;
574
+ const depthTexture = hasSampleableDepth
575
+ ? new Texture({ width: descriptor.width, height: descriptor.height, format: "depth24", label: `${descriptor.label ?? "render-target"}-depth` })
576
+ : undefined;
577
+ const target = new WebGPURenderTarget(
578
+ this.nextId++,
579
+ descriptor.width,
580
+ descriptor.height,
581
+ descriptor.label ?? "render-target",
582
+ new Texture({ width: descriptor.width, height: descriptor.height, format: descriptor.format ?? "rgba8", label: descriptor.label ?? "render-target-color" }),
583
+ depthTexture,
584
+ nativeTexture,
585
+ nativeTexture?.createView() ?? null,
586
+ nativeDepthTexture,
587
+ nativeDepthTexture?.createView() ?? null,
588
+ hasDepth
589
+ );
590
+ this.renderTargets.add(target);
591
+ return target;
592
+ }
593
+
594
+ setRenderTarget(target: RenderTarget | null): void {
595
+ this.assertAlive();
596
+ if (target === null) {
597
+ this.activeRenderTarget = null;
598
+ return;
599
+ }
600
+ if (!(target instanceof WebGPURenderTarget) || !this.renderTargets.has(target) || target.disposed) {
601
+ throw new RenderDeviceError("Render target is not a live WebGPU resource owned by this device", "INVALID_RESOURCE", {
602
+ targetId: target.id
603
+ });
604
+ }
605
+ this.activeRenderTarget = target;
606
+ }
607
+
608
+ writeRenderTargetPixels(target: RenderTarget, pixels: Uint8Array): void {
609
+ this.assertAlive();
610
+ const webgpuTarget = this.requireRenderTarget(target);
611
+ const expectedLength = webgpuTarget.width * webgpuTarget.height * 4;
612
+ if (pixels.length !== expectedLength) {
613
+ throw new RenderDeviceError("Render target pixel upload length does not match target dimensions", "INVALID_RENDER_TARGET_PIXELS", {
614
+ targetId: target.id,
615
+ expectedLength,
616
+ actualLength: pixels.length
617
+ });
618
+ }
619
+ webgpuTarget.colorPixels.set(pixels);
620
+ if (webgpuTarget.colorFloatPixels) {
621
+ for (let index = 0; index < pixels.length; index += 1) {
622
+ webgpuTarget.colorFloatPixels[index] = pixels[index]! / 255;
623
+ }
624
+ }
625
+ if (webgpuTarget.nativeTexture && webgpuTarget.colorTexture.format === "rgba8" && hasNativeTextureUpload(this.device)) {
626
+ this.device.queue.writeTexture(
627
+ { texture: webgpuTarget.nativeTexture },
628
+ pixels,
629
+ { bytesPerRow: webgpuTarget.width * 4, rowsPerImage: webgpuTarget.height },
630
+ { width: webgpuTarget.width, height: webgpuTarget.height, depthOrArrayLayers: 1 }
631
+ );
632
+ webgpuTarget.nativeNeedsClear = false;
633
+ }
634
+ }
635
+
636
+ presentRenderTarget(source: RenderTarget): void {
637
+ this.assertAlive();
638
+ const target = this.requireRenderTarget(source);
639
+ if (target.colorTexture.format !== "rgba8") {
640
+ throw new RenderDeviceError("WebGPU backbuffer presentation currently requires rgba8 source pixels", "PRESENT_FORMAT_UNSUPPORTED", {
641
+ source: source.label,
642
+ format: target.colorTexture.format
643
+ });
644
+ }
645
+ this.backbufferPixels = target.colorPixels.slice();
646
+ this.backbufferWidth = target.width;
647
+ this.backbufferHeight = target.height;
648
+ this.activeRenderTarget = null;
649
+ this.canvasSubmissions += 1;
650
+ }
651
+
652
+ readPixels(x: number, y: number, width: number, height: number): Uint8Array {
653
+ this.assertAlive();
654
+ if (![x, y, width, height].every(Number.isInteger) || x < 0 || y < 0 || width <= 0 || height <= 0) {
655
+ throw new RenderDeviceError("Readback rectangle must be positive and in bounds", "INVALID_READBACK_RECT", { x, y, width, height });
656
+ }
657
+ const boundsWidth = this.activeRenderTarget?.width ?? (this.backbufferPixels ? this.backbufferWidth : this.viewportWidth);
658
+ const boundsHeight = this.activeRenderTarget?.height ?? (this.backbufferPixels ? this.backbufferHeight : this.viewportHeight);
659
+ if (x + width > boundsWidth || y + height > boundsHeight) {
660
+ throw new RenderDeviceError("Readback rectangle exceeds framebuffer bounds", "READBACK_OUT_OF_BOUNDS", {
661
+ x,
662
+ y,
663
+ width,
664
+ height,
665
+ boundsWidth,
666
+ boundsHeight
667
+ });
668
+ }
669
+ const output = new Uint8Array(width * height * 4);
670
+ const target = this.activeRenderTarget;
671
+ if (!target) {
672
+ if (this.backbufferPixels) {
673
+ for (let row = 0; row < height; row += 1) {
674
+ const sourceOffset = ((y + row) * this.backbufferWidth + x) * 4;
675
+ const destOffset = row * width * 4;
676
+ output.set(this.backbufferPixels.subarray(sourceOffset, sourceOffset + width * 4), destOffset);
677
+ }
678
+ return output;
679
+ }
680
+ const bytes = rgbaBytes(this.clearColor);
681
+ for (let index = 0; index < output.length; index += 4) output.set(bytes, index);
682
+ return output;
683
+ }
684
+ for (let row = 0; row < height; row += 1) {
685
+ const sourceOffset = ((y + row) * target.width + x) * 4;
686
+ const destOffset = row * width * 4;
687
+ output.set(target.colorPixels.subarray(sourceOffset, sourceOffset + width * 4), destOffset);
688
+ }
689
+ return output;
690
+ }
691
+
692
+ async readPixelsAsync(x: number, y: number, width: number, height: number): Promise<Uint8Array> {
693
+ this.assertAlive();
694
+ if (![x, y, width, height].every(Number.isInteger) || x < 0 || y < 0 || width <= 0 || height <= 0) {
695
+ throw new RenderDeviceError("Readback rectangle must be positive and in bounds", "INVALID_READBACK_RECT", { x, y, width, height });
696
+ }
697
+ const target = this.activeRenderTarget;
698
+ if (!target || !target.nativeTexture) {
699
+ throw new RenderDeviceError("Native WebGPU readback requires an active native render target", "NATIVE_READBACK_TARGET_MISSING", {
700
+ x,
701
+ y,
702
+ width,
703
+ height,
704
+ renderTarget: target?.label ?? null
705
+ });
706
+ }
707
+ if (target.colorTexture.format !== "rgba8") {
708
+ throw new RenderDeviceError("Native WebGPU readback currently supports rgba8 render targets", "NATIVE_READBACK_FORMAT_UNSUPPORTED", {
709
+ format: target.colorTexture.format,
710
+ renderTarget: target.label
711
+ });
712
+ }
713
+ if (x + width > target.width || y + height > target.height) {
714
+ throw new RenderDeviceError("Readback rectangle exceeds framebuffer bounds", "READBACK_OUT_OF_BOUNDS", {
715
+ x,
716
+ y,
717
+ width,
718
+ height,
719
+ boundsWidth: target.width,
720
+ boundsHeight: target.height
721
+ });
722
+ }
723
+ if (!hasNativeTextureReadback(this.device)) {
724
+ throw new RenderDeviceError("WebGPU device does not expose native texture-to-buffer readback", "NATIVE_READBACK_UNSUPPORTED");
725
+ }
726
+ this.flushNativeRenderTargetClear(target);
727
+
728
+ const bytesPerPixel = 4;
729
+ const unpaddedBytesPerRow = width * bytesPerPixel;
730
+ const bytesPerRow = alignTo(unpaddedBytesPerRow, 256);
731
+ const bufferSize = bytesPerRow * height;
732
+ const readback = this.device.createBuffer({
733
+ label: `${target.label}-native-readback`,
734
+ size: bufferSize,
735
+ usage: BUFFER_USAGE.MAP_READ | BUFFER_USAGE.COPY_DST
736
+ });
737
+ const encoder = this.device.createCommandEncoder({ label: `${target.label}-native-readback-encoder` });
738
+ const copyTextureToBuffer = encoder.copyTextureToBuffer;
739
+ if (!copyTextureToBuffer) {
740
+ readback.destroy();
741
+ throw new RenderDeviceError("WebGPU command encoder does not expose texture-to-buffer copy", "NATIVE_READBACK_UNSUPPORTED");
742
+ }
743
+ copyTextureToBuffer.call(
744
+ encoder,
745
+ { texture: target.nativeTexture, origin: { x, y, z: 0 } },
746
+ { buffer: readback, bytesPerRow, rowsPerImage: height },
747
+ { width, height, depthOrArrayLayers: 1 }
748
+ );
749
+ this.device.queue.submit([encoder.finish()]);
750
+
751
+ try {
752
+ const mapAsync = readback.mapAsync;
753
+ const getMappedRange = readback.getMappedRange;
754
+ const unmap = readback.unmap;
755
+ if (!mapAsync || !getMappedRange || !unmap) {
756
+ throw new RenderDeviceError("WebGPU readback buffer does not expose mapped readback APIs", "NATIVE_READBACK_UNSUPPORTED");
757
+ }
758
+ await mapAsync.call(readback, MAP_MODE.READ);
759
+ const mapped = new Uint8Array(getMappedRange.call(readback));
760
+ const output = new Uint8Array(width * height * bytesPerPixel);
761
+ for (let row = 0; row < height; row += 1) {
762
+ const sourceOffset = row * bytesPerRow;
763
+ const destOffset = (height - 1 - row) * unpaddedBytesPerRow;
764
+ output.set(mapped.subarray(sourceOffset, sourceOffset + unpaddedBytesPerRow), destOffset);
765
+ }
766
+ unmap.call(readback);
767
+ return output;
768
+ } finally {
769
+ readback.destroy();
770
+ }
771
+ }
772
+
773
+ async readFloatPixelsAsync(x: number, y: number, width: number, height: number): Promise<Float32Array> {
774
+ this.assertAlive();
775
+ if (![x, y, width, height].every(Number.isInteger) || x < 0 || y < 0 || width <= 0 || height <= 0) {
776
+ throw new RenderDeviceError("Float readback rectangle must be positive and in bounds", "INVALID_READBACK_RECT", { x, y, width, height });
777
+ }
778
+ const target = this.activeRenderTarget;
779
+ if (!target || !target.nativeTexture) {
780
+ throw new RenderDeviceError("Native WebGPU float readback requires an active native render target", "NATIVE_READBACK_TARGET_MISSING", {
781
+ x,
782
+ y,
783
+ width,
784
+ height,
785
+ renderTarget: target?.label ?? null
786
+ });
787
+ }
788
+ if (x + width > target.width || y + height > target.height) {
789
+ throw new RenderDeviceError("Float readback rectangle exceeds framebuffer bounds", "READBACK_OUT_OF_BOUNDS", {
790
+ x,
791
+ y,
792
+ width,
793
+ height,
794
+ boundsWidth: target.width,
795
+ boundsHeight: target.height
796
+ });
797
+ }
798
+ if (!hasNativeTextureReadback(this.device)) {
799
+ throw new RenderDeviceError("WebGPU device does not expose native texture-to-buffer readback", "NATIVE_READBACK_UNSUPPORTED");
800
+ }
801
+ this.flushNativeRenderTargetClear(target);
802
+
803
+ const format = target.colorTexture.format;
804
+ const bytesPerPixel = format === "rgba32f" ? 16 : format === "rgba16f" ? 8 : 4;
805
+ const unpaddedBytesPerRow = width * bytesPerPixel;
806
+ const bytesPerRow = alignTo(unpaddedBytesPerRow, 256);
807
+ const bufferSize = bytesPerRow * height;
808
+ const readback = this.device.createBuffer({
809
+ label: `${target.label}-native-float-readback`,
810
+ size: bufferSize,
811
+ usage: BUFFER_USAGE.MAP_READ | BUFFER_USAGE.COPY_DST
812
+ });
813
+ const encoder = this.device.createCommandEncoder({ label: `${target.label}-native-float-readback-encoder` });
814
+ const copyTextureToBuffer = encoder.copyTextureToBuffer;
815
+ if (!copyTextureToBuffer) {
816
+ readback.destroy();
817
+ throw new RenderDeviceError("WebGPU command encoder does not expose texture-to-buffer copy", "NATIVE_READBACK_UNSUPPORTED");
818
+ }
819
+ copyTextureToBuffer.call(
820
+ encoder,
821
+ { texture: target.nativeTexture, origin: { x, y, z: 0 } },
822
+ { buffer: readback, bytesPerRow, rowsPerImage: height },
823
+ { width, height, depthOrArrayLayers: 1 }
824
+ );
825
+ this.device.queue.submit([encoder.finish()]);
826
+
827
+ try {
828
+ const mapAsync = readback.mapAsync;
829
+ const getMappedRange = readback.getMappedRange;
830
+ const unmap = readback.unmap;
831
+ if (!mapAsync || !getMappedRange || !unmap) {
832
+ throw new RenderDeviceError("WebGPU readback buffer does not expose mapped readback APIs", "NATIVE_READBACK_UNSUPPORTED");
833
+ }
834
+ await mapAsync.call(readback, MAP_MODE.READ);
835
+ const mapped = new Uint8Array(getMappedRange.call(readback));
836
+ const view = new DataView(mapped.buffer, mapped.byteOffset, mapped.byteLength);
837
+ const output = new Float32Array(width * height * 4);
838
+ for (let row = 0; row < height; row += 1) {
839
+ const destRow = height - 1 - row;
840
+ for (let column = 0; column < width; column += 1) {
841
+ const sourceOffset = row * bytesPerRow + column * bytesPerPixel;
842
+ const destOffset = (destRow * width + column) * 4;
843
+ if (format === "rgba32f") {
844
+ output[destOffset] = view.getFloat32(sourceOffset, true);
845
+ output[destOffset + 1] = view.getFloat32(sourceOffset + 4, true);
846
+ output[destOffset + 2] = view.getFloat32(sourceOffset + 8, true);
847
+ output[destOffset + 3] = view.getFloat32(sourceOffset + 12, true);
848
+ } else if (format === "rgba16f") {
849
+ output[destOffset] = halfFloatToNumber(view.getUint16(sourceOffset, true));
850
+ output[destOffset + 1] = halfFloatToNumber(view.getUint16(sourceOffset + 2, true));
851
+ output[destOffset + 2] = halfFloatToNumber(view.getUint16(sourceOffset + 4, true));
852
+ output[destOffset + 3] = halfFloatToNumber(view.getUint16(sourceOffset + 6, true));
853
+ } else {
854
+ output[destOffset] = (mapped[sourceOffset] ?? 0) / 255;
855
+ output[destOffset + 1] = (mapped[sourceOffset + 1] ?? 0) / 255;
856
+ output[destOffset + 2] = (mapped[sourceOffset + 2] ?? 0) / 255;
857
+ output[destOffset + 3] = (mapped[sourceOffset + 3] ?? 0) / 255;
858
+ }
859
+ }
860
+ }
861
+ unmap.call(readback);
862
+ return output;
863
+ } finally {
864
+ readback.destroy();
865
+ }
866
+ }
867
+
868
+ readFloatPixels(x: number, y: number, width: number, height: number): Float32Array {
869
+ this.assertAlive();
870
+ if (![x, y, width, height].every(Number.isInteger) || x < 0 || y < 0 || width <= 0 || height <= 0) {
871
+ throw new RenderDeviceError("Float readback rectangle must be positive and in bounds", "INVALID_READBACK_RECT", { x, y, width, height });
872
+ }
873
+ const boundsWidth = this.activeRenderTarget?.width ?? (this.backbufferPixels ? this.backbufferWidth : this.viewportWidth);
874
+ const boundsHeight = this.activeRenderTarget?.height ?? (this.backbufferPixels ? this.backbufferHeight : this.viewportHeight);
875
+ if (x + width > boundsWidth || y + height > boundsHeight) {
876
+ throw new RenderDeviceError("Float readback rectangle exceeds framebuffer bounds", "READBACK_OUT_OF_BOUNDS", {
877
+ x,
878
+ y,
879
+ width,
880
+ height,
881
+ boundsWidth,
882
+ boundsHeight
883
+ });
884
+ }
885
+ const output = new Float32Array(width * height * 4);
886
+ const target = this.activeRenderTarget;
887
+ if (!target) {
888
+ if (this.backbufferPixels) {
889
+ const bytes = this.readPixels(x, y, width, height);
890
+ for (let index = 0; index < bytes.length; index += 1) output[index] = bytes[index]! / 255;
891
+ return output;
892
+ }
893
+ for (let index = 0; index < output.length; index += 4) {
894
+ output[index] = this.clearColor[0];
895
+ output[index + 1] = this.clearColor[1];
896
+ output[index + 2] = this.clearColor[2];
897
+ output[index + 3] = this.clearColor[3];
898
+ }
899
+ return output;
900
+ }
901
+ if (target.colorFloatPixels) {
902
+ for (let row = 0; row < height; row += 1) {
903
+ const sourceOffset = ((y + row) * target.width + x) * 4;
904
+ const destOffset = row * width * 4;
905
+ output.set(target.colorFloatPixels.subarray(sourceOffset, sourceOffset + width * 4), destOffset);
906
+ }
907
+ return output;
908
+ }
909
+ const bytes = this.readPixels(x, y, width, height);
910
+ for (let index = 0; index < bytes.length; index += 1) output[index] = bytes[index]! / 255;
911
+ return output;
912
+ }
913
+
914
+ beginFrame(width: number, height: number): void {
915
+ this.assertAlive();
916
+ if (this.frameActive) {
917
+ throw new RenderDeviceError("Frame is already active", "FRAME_ALREADY_ACTIVE");
918
+ }
919
+ if (width <= 0 || height <= 0) {
920
+ throw new RenderDeviceError("Frame dimensions must be positive", "INVALID_FRAME_SIZE", { width, height });
921
+ }
922
+ this.frameActive = true;
923
+ this.drawCalls = 0;
924
+ this.lastError = null;
925
+ this.viewportWidth = width;
926
+ this.viewportHeight = height;
927
+ this.ensureCanvasDepthAttachment(width, height);
928
+ }
929
+
930
+ clear(color: readonly [number, number, number, number]): void {
931
+ this.assertFrame();
932
+ this.clearColor = color;
933
+ if (this.activeRenderTarget) {
934
+ this.clearActiveRenderTarget(color);
935
+ }
936
+ }
937
+
938
+ clearRenderTarget(color: readonly [number, number, number, number]): void {
939
+ this.assertFrame();
940
+ if (!this.activeRenderTarget) {
941
+ this.clearColor = color;
942
+ return;
943
+ }
944
+ this.clearActiveRenderTarget(color);
945
+ }
946
+
947
+ draw(command: DrawCommand): void {
948
+ this.assertFrame();
949
+ const vertexBuffer = this.requireBuffer(command.vertexBuffer);
950
+ if (vertexBuffer.disposed) {
951
+ throw new RenderDeviceError("Cannot draw with a disposed vertex buffer", "DISPOSED_RESOURCE", {
952
+ bufferId: command.vertexBuffer.id
953
+ });
954
+ }
955
+ if (command.indexBuffer) {
956
+ const indexBuffer = this.requireBuffer(command.indexBuffer);
957
+ if (indexBuffer.disposed) {
958
+ throw new RenderDeviceError("Cannot draw with a disposed index buffer", "DISPOSED_RESOURCE", {
959
+ bufferId: command.indexBuffer.id
960
+ });
961
+ }
962
+ }
963
+ if (command.shader) this.requireShader(command.shader);
964
+ if (command.vertexCount <= 0) {
965
+ throw new RenderDeviceError("Draw command must have a positive vertex count", "INVALID_DRAW_COMMAND", {
966
+ vertexCount: command.vertexCount,
967
+ label: command.label
968
+ });
969
+ }
970
+ if (command.firstVertex !== undefined && (!Number.isInteger(command.firstVertex) || command.firstVertex < 0)) {
971
+ throw new RenderDeviceError("Draw command firstVertex must be a non-negative integer", "INVALID_DRAW_COMMAND", {
972
+ firstVertex: command.firstVertex,
973
+ label: command.label
974
+ });
975
+ }
976
+ if (command.indexBuffer && (command.indexCount === undefined || command.indexCount <= 0)) {
977
+ throw new RenderDeviceError("Indexed draw command must have a positive index count", "INVALID_DRAW_COMMAND", {
978
+ indexCount: command.indexCount,
979
+ label: command.label
980
+ });
981
+ }
982
+ if (command.firstIndex !== undefined && (!Number.isInteger(command.firstIndex) || command.firstIndex < 0)) {
983
+ throw new RenderDeviceError("Draw command firstIndex must be a non-negative integer", "INVALID_DRAW_COMMAND", {
984
+ firstIndex: command.firstIndex,
985
+ label: command.label
986
+ });
987
+ }
988
+ if (command.instanceCount !== undefined && (!Number.isInteger(command.instanceCount) || command.instanceCount <= 0)) {
989
+ throw new RenderDeviceError("Draw command instanceCount must be a positive integer", "INVALID_DRAW_COMMAND", {
990
+ instanceCount: command.instanceCount,
991
+ label: command.label
992
+ });
993
+ }
994
+ this.submitNativeRenderPass(command, vertexBuffer);
995
+ this.rasterizeDraw(command, vertexBuffer);
996
+ this.drawCalls += 1;
997
+ }
998
+
999
+ endFrame(): void {
1000
+ this.assertFrame();
1001
+ this.frameActive = false;
1002
+ this.device.queue.submit([]);
1003
+ }
1004
+
1005
+ captureState(): ReadonlyMap<string, string | number | boolean | null> {
1006
+ return new Map<string, string | number | boolean | null>([
1007
+ ["backend", this.kind],
1008
+ ["disposed", this.disposed],
1009
+ ["contextLost", this.contextLost],
1010
+ ["frameActive", this.frameActive],
1011
+ ["viewportWidth", this.viewportWidth],
1012
+ ["viewportHeight", this.viewportHeight],
1013
+ ["renderTarget", this.activeRenderTarget?.label ?? null],
1014
+ ["presentationFormat", this.presentationFormat],
1015
+ ["drawCalls", this.drawCalls],
1016
+ ["nativeSubmissions", this.nativeSubmissions],
1017
+ ["nativeTextureBindings", this.nativeTextureBindings],
1018
+ ["nativeGeneratedBasicSubmissions", this.nativeGeneratedBasicSubmissions],
1019
+ ["nativeGeneratedTextureSubmissions", this.nativeGeneratedTextureSubmissions],
1020
+ ["nativePassthroughSubmissions", this.nativePassthroughSubmissions],
1021
+ ["nativePbrSubmissions", this.nativePbrSubmissions],
1022
+ ["nativeInstancedSubmissions", this.nativeInstancedSubmissions],
1023
+ ["nativeSkinnedSubmissions", this.nativeSkinnedSubmissions],
1024
+ ["nativeMorphSubmissions", this.nativeMorphSubmissions],
1025
+ ["nativeEnvironmentBindings", this.nativeEnvironmentBindings],
1026
+ ["nativeShadowMapBindings", this.nativeShadowMapBindings],
1027
+ ["canvasSubmissions", this.canvasSubmissions]
1028
+ ]);
1029
+ }
1030
+
1031
+ getDiagnostics(): RenderDeviceDiagnostics {
1032
+ const liveRenderTargets = [...this.renderTargets].filter((target) => !target.disposed);
1033
+ const bufferBytes = [...this.buffers].filter((buffer) => !buffer.disposed).reduce((total, buffer) => total + buffer.byteLength, 0);
1034
+ const textureBytes = liveRenderTargets.reduce((total, target) => total + target.colorTexture.byteLength + (target.depthTexture?.byteLength ?? 0), 0);
1035
+ return {
1036
+ drawCalls: this.drawCalls,
1037
+ buffers: [...this.buffers].filter((buffer) => !buffer.disposed).length,
1038
+ shaders: [...this.shaders].filter((shader) => !shader.disposed).length,
1039
+ renderTargets: liveRenderTargets.length,
1040
+ textures: liveRenderTargets.length,
1041
+ bufferBytes,
1042
+ textureBytes,
1043
+ approximateGpuMemoryBytes: bufferBytes + textureBytes,
1044
+ compressedTextures: 0,
1045
+ compressedTextureBytes: 0,
1046
+ textureFallbacks: 0,
1047
+ textureFallbackBytes: 0,
1048
+ disposedBuffers: [...this.buffers].filter((buffer) => buffer.disposed).length,
1049
+ disposedShaders: [...this.shaders].filter((shader) => shader.disposed).length,
1050
+ disposedRenderTargets: [...this.renderTargets].filter((target) => target.disposed).length,
1051
+ disposedTextures: [...this.renderTargets].reduce((total, target) => total + (target.colorTexture.disposed ? 1 : 0) + (target.depthTexture?.disposed ? 1 : 0), 0),
1052
+ nativeSubmissions: this.nativeSubmissions,
1053
+ nativeTextureBindings: this.nativeTextureBindings,
1054
+ nativeGeneratedBasicSubmissions: this.nativeGeneratedBasicSubmissions,
1055
+ nativeGeneratedTextureSubmissions: this.nativeGeneratedTextureSubmissions,
1056
+ nativePassthroughSubmissions: this.nativePassthroughSubmissions,
1057
+ nativePbrSubmissions: this.nativePbrSubmissions,
1058
+ nativeInstancedSubmissions: this.nativeInstancedSubmissions,
1059
+ nativeSkinnedSubmissions: this.nativeSkinnedSubmissions,
1060
+ nativeMorphSubmissions: this.nativeMorphSubmissions,
1061
+ nativeEnvironmentBindings: this.nativeEnvironmentBindings,
1062
+ nativeShadowMapBindings: this.nativeShadowMapBindings,
1063
+ lastError: this.lastError,
1064
+ contextLost: this.contextLost
1065
+ };
1066
+ }
1067
+
1068
+ dispose(): void {
1069
+ if (this.disposed) return;
1070
+ for (const buffer of this.buffers) buffer.dispose();
1071
+ for (const shader of this.shaders) shader.dispose();
1072
+ for (const target of this.renderTargets) target.dispose();
1073
+ for (const resource of this.nativeSampledTextures.values()) resource.texture.destroy();
1074
+ this.nativeSampledTextures.clear();
1075
+ this.canvasDepthTexture?.destroy();
1076
+ this.canvasDepthTexture = null;
1077
+ this.canvasDepthView = null;
1078
+ this.canvasContext?.unconfigure?.();
1079
+ this.device.destroy?.();
1080
+ this.frameActive = false;
1081
+ this.disposed = true;
1082
+ }
1083
+
1084
+ private assertAlive(): void {
1085
+ if (this.disposed) {
1086
+ throw new RenderDeviceError("Render device is disposed", "DISPOSED_DEVICE");
1087
+ }
1088
+ if (this.contextLost) {
1089
+ throw new RenderDeviceError("Render context is lost", "CONTEXT_LOST");
1090
+ }
1091
+ }
1092
+
1093
+ private assertFrame(): void {
1094
+ this.assertAlive();
1095
+ if (!this.frameActive) {
1096
+ throw new RenderDeviceError("No active frame", "NO_ACTIVE_FRAME");
1097
+ }
1098
+ }
1099
+
1100
+ private observeDeviceLost(): void {
1101
+ const lost = this.device.lost;
1102
+ if (!lost || typeof lost.then !== "function") return;
1103
+ void lost.then((info) => {
1104
+ if (this.disposed) return;
1105
+ this.contextLost = true;
1106
+ const detail = [info.reason, info.message].filter(Boolean).join(": ");
1107
+ this.lastError = detail ? `WebGPU device lost: ${detail}` : "WebGPU device lost";
1108
+ }).catch((error: unknown) => {
1109
+ if (this.disposed) return;
1110
+ this.contextLost = true;
1111
+ this.lastError = `WebGPU device lost promise rejected: ${error instanceof Error ? error.message : String(error)}`;
1112
+ });
1113
+ }
1114
+
1115
+ private requireBuffer(buffer: RenderBuffer): WebGPURenderBuffer {
1116
+ if (!(buffer instanceof WebGPURenderBuffer) || !this.buffers.has(buffer)) {
1117
+ throw new RenderDeviceError("Buffer was not created by this WebGPU device", "FOREIGN_RESOURCE", {
1118
+ bufferId: buffer.id
1119
+ });
1120
+ }
1121
+ if (buffer.disposed) {
1122
+ throw new RenderDeviceError("Cannot use a disposed buffer", "DISPOSED_RESOURCE", { bufferId: buffer.id });
1123
+ }
1124
+ return buffer;
1125
+ }
1126
+
1127
+ private requireShader(shader: RenderShaderProgram): WebGPUShaderProgram {
1128
+ if (!(shader instanceof WebGPUShaderProgram) || !this.shaders.has(shader)) {
1129
+ throw new RenderDeviceError("Shader was not created by this WebGPU device", "FOREIGN_RESOURCE", {
1130
+ shaderId: shader.id
1131
+ });
1132
+ }
1133
+ if (shader.disposed) {
1134
+ throw new RenderDeviceError("Cannot use a disposed shader", "DISPOSED_RESOURCE", { shaderId: shader.id });
1135
+ }
1136
+ return shader;
1137
+ }
1138
+
1139
+ private requireRenderTarget(target: RenderTarget): WebGPURenderTarget {
1140
+ if (!(target instanceof WebGPURenderTarget) || !this.renderTargets.has(target)) {
1141
+ throw new RenderDeviceError("Render target was not created by this WebGPU device", "FOREIGN_RESOURCE", {
1142
+ targetId: target.id
1143
+ });
1144
+ }
1145
+ if (target.disposed) {
1146
+ throw new RenderDeviceError("Cannot use a disposed render target", "DISPOSED_RESOURCE", { targetId: target.id });
1147
+ }
1148
+ return target;
1149
+ }
1150
+
1151
+ private rasterizeDraw(command: DrawCommand, vertexBuffer: WebGPURenderBuffer): void {
1152
+ if (!this.activeRenderTarget || !command.vertexFormat?.hasAttribute("position")) return;
1153
+ const position = command.vertexFormat.getAttribute("position");
1154
+ const colorAttribute = command.vertexFormat.hasAttribute("color") ? command.vertexFormat.getAttribute("color") : null;
1155
+ const uvAttribute = command.vertexFormat.hasAttribute("uv") ? command.vertexFormat.getAttribute("uv") : null;
1156
+ if (position.components < 2) return;
1157
+ const indices = this.indicesFor(command);
1158
+ const color = uniformColor(command.uniforms);
1159
+ const texture = uniformBaseColorTextureBinding(command.uniforms);
1160
+ const shadow = uniformForwardShadow(command.uniforms);
1161
+ const instanceMatrices = uniformRasterMatrices(command.uniforms, command.instanceCount ?? 1);
1162
+ const modelMatrices = uniformRasterModelMatrices(command.uniforms, command.instanceCount ?? 1);
1163
+ const depthTest = command.renderState?.depthTest !== false && this.activeRenderTarget.depthPixels !== null;
1164
+ const depthWrite = command.renderState?.depthWrite !== false;
1165
+ for (let instanceIndex = 0; instanceIndex < instanceMatrices.length; instanceIndex += 1) {
1166
+ const matrix = instanceMatrices[instanceIndex] ?? identityMatrix();
1167
+ const modelMatrix = modelMatrices[instanceIndex] ?? identityMatrix();
1168
+ if (command.topology === "triangles") {
1169
+ for (let offset = 0; offset + 2 < indices.length; offset += 3) {
1170
+ const indexA = indices[offset]!;
1171
+ const indexB = indices[offset + 1]!;
1172
+ const indexC = indices[offset + 2]!;
1173
+ const localA = readMorphedPosition(vertexBuffer.bytes, command.vertexFormat.stride, position.offset, indexA, command.uniforms);
1174
+ const localB = readMorphedPosition(vertexBuffer.bytes, command.vertexFormat.stride, position.offset, indexB, command.uniforms);
1175
+ const localC = readMorphedPosition(vertexBuffer.bytes, command.vertexFormat.stride, position.offset, indexC, command.uniforms);
1176
+ const a = transformPosition(localA, matrix);
1177
+ const b = transformPosition(localB, matrix);
1178
+ const c = transformPosition(localC, matrix);
1179
+ const worldA = transformPosition(localA, modelMatrix);
1180
+ const worldB = transformPosition(localB, modelMatrix);
1181
+ const worldC = transformPosition(localC, modelMatrix);
1182
+ const colorA = readVertexColor(vertexBuffer.bytes, command.vertexFormat.stride, colorAttribute?.offset, indexA);
1183
+ const colorB = readVertexColor(vertexBuffer.bytes, command.vertexFormat.stride, colorAttribute?.offset, indexB);
1184
+ const colorC = readVertexColor(vertexBuffer.bytes, command.vertexFormat.stride, colorAttribute?.offset, indexC);
1185
+ const uvA = readVertexUv(vertexBuffer.bytes, command.vertexFormat.stride, uvAttribute?.offset, indexA);
1186
+ const uvB = readVertexUv(vertexBuffer.bytes, command.vertexFormat.stride, uvAttribute?.offset, indexB);
1187
+ const uvC = readVertexUv(vertexBuffer.bytes, command.vertexFormat.stride, uvAttribute?.offset, indexC);
1188
+ rasterizeTriangle(this.activeRenderTarget, a, b, c, worldA, worldB, worldC, color, colorA, colorB, colorC, uvA, uvB, uvC, texture, shadow, depthTest, depthWrite);
1189
+ }
1190
+ } else if (command.topology === "lines") {
1191
+ for (let offset = 0; offset + 1 < indices.length; offset += 2) {
1192
+ const indexA = indices[offset]!;
1193
+ const indexB = indices[offset + 1]!;
1194
+ const a = transformPosition(readMorphedPosition(vertexBuffer.bytes, command.vertexFormat.stride, position.offset, indexA, command.uniforms), matrix);
1195
+ const b = transformPosition(readMorphedPosition(vertexBuffer.bytes, command.vertexFormat.stride, position.offset, indexB, command.uniforms), matrix);
1196
+ const colorA = readVertexColor(vertexBuffer.bytes, command.vertexFormat.stride, colorAttribute?.offset, indexA);
1197
+ const colorB = readVertexColor(vertexBuffer.bytes, command.vertexFormat.stride, colorAttribute?.offset, indexB);
1198
+ rasterizeLine(this.activeRenderTarget, a, b, color, colorA, colorB, depthTest, depthWrite);
1199
+ }
1200
+ } else {
1201
+ for (const index of indices) {
1202
+ const point = transformPosition(readMorphedPosition(vertexBuffer.bytes, command.vertexFormat.stride, position.offset, index, command.uniforms), matrix);
1203
+ const vertexColor = readVertexColor(vertexBuffer.bytes, command.vertexFormat.stride, colorAttribute?.offset, index);
1204
+ rasterizePoint(this.activeRenderTarget, point, multiplyColor(color, vertexColor), depthTest, depthWrite);
1205
+ }
1206
+ }
1207
+ }
1208
+ }
1209
+
1210
+ private submitNativeRenderPass(command: DrawCommand, vertexBuffer: WebGPURenderBuffer): void {
1211
+ const nativeView = this.activeRenderTarget?.nativeView ?? this.currentCanvasView();
1212
+ if (!nativeView || !command.shader) return;
1213
+ if (!hasNativeRenderPipeline(this.device)) return;
1214
+ const shader = this.requireShader(command.shader);
1215
+ const vertexModule = shader.modules[0];
1216
+ const fragmentModule = shader.modules[1] ?? vertexModule;
1217
+ if (!vertexModule || !fragmentModule) return;
1218
+ const topology = command.topology === "lines" ? "line-list" : command.topology === "points" ? "point-list" : "triangle-list";
1219
+ const targetFormat = this.activeRenderTarget ? webgpuTextureFormat(this.activeRenderTarget.colorTexture.format) : this.presentationFormat;
1220
+ const vertexBuffers = command.vertexFormat ? [vertexBufferLayout(command.vertexFormat)] : undefined;
1221
+ const shouldClear = this.activeRenderTarget ? this.activeRenderTarget.nativeNeedsClear : this.drawCalls === 0;
1222
+ const depthView = this.activeRenderTarget?.nativeDepthView ?? this.canvasDepthView;
1223
+ const depthEnabled = depthView !== null &&
1224
+ depthView !== undefined &&
1225
+ command.renderState?.depthTest !== false;
1226
+ const depthWriteEnabled = command.renderState?.depthWrite ?? true;
1227
+ const depthCompare = command.renderState?.depthCompare ?? "less-equal";
1228
+ const blendEnabled = command.renderState?.blend === true;
1229
+ const pipelineKey = `${shader.nativeUniformLayout}:${topology}:${targetFormat}:${blendEnabled ? "blend" : "opaque"}:${depthEnabled ? `${depthWriteEnabled}:${depthCompare}` : "nodepth"}:${command.vertexFormat?.stride ?? 0}:${command.vertexFormat?.attributes.map((attribute) => `${attribute.shaderLocation}/${attribute.offset}/${attribute.components}`).join(",") ?? "none"}`;
1230
+ let pipeline = shader.renderPipelines.get(pipelineKey);
1231
+ if (!pipeline) {
1232
+ pipeline = this.device.createRenderPipeline({
1233
+ label: `${shader.label}-pipeline`,
1234
+ layout: "auto",
1235
+ vertex: { module: vertexModule, entryPoint: shader.entryPoints[0], ...(vertexBuffers ? { buffers: vertexBuffers } : {}) },
1236
+ fragment: {
1237
+ module: fragmentModule,
1238
+ entryPoint: shader.entryPoints[1],
1239
+ targets: [{
1240
+ format: targetFormat,
1241
+ ...(blendEnabled
1242
+ ? {
1243
+ blend: {
1244
+ color: { srcFactor: "src-alpha", dstFactor: "one-minus-src-alpha", operation: "add" },
1245
+ alpha: { srcFactor: "one", dstFactor: "one-minus-src-alpha", operation: "add" }
1246
+ }
1247
+ }
1248
+ : {})
1249
+ }]
1250
+ },
1251
+ primitive: { topology },
1252
+ ...(depthEnabled
1253
+ ? {
1254
+ depthStencil: {
1255
+ format: DEPTH_TEXTURE_FORMAT,
1256
+ depthWriteEnabled,
1257
+ depthCompare
1258
+ }
1259
+ }
1260
+ : {})
1261
+ });
1262
+ shader.renderPipelines.set(pipelineKey, pipeline);
1263
+ }
1264
+ const encoder = this.device.createCommandEncoder({ label: `${command.label ?? "draw"}-encoder` });
1265
+ const uniformBuffer = usesNativeDrawUniforms(shader.nativeUniformLayout) ? this.createNativeDrawUniformBuffer(command) : null;
1266
+ const sampledTexture = shader.nativeUniformLayout === "generated-texture" ? this.createNativeSampledTextureBinding(uniformBaseColorTextureBinding(command.uniforms)) : null;
1267
+ const materialTextures = usesNativePbrTextureBindings(shader.nativeUniformLayout) ? this.createNativePbrTextureBindings(command) : null;
1268
+ if (shader.nativeUniformLayout === "generated-texture" && !sampledTexture) {
1269
+ uniformBuffer?.destroy();
1270
+ return;
1271
+ }
1272
+ if (usesNativePbrTextureBindings(shader.nativeUniformLayout) && !materialTextures) {
1273
+ uniformBuffer?.destroy();
1274
+ return;
1275
+ }
1276
+ const bindGroup = uniformBuffer && pipeline.getBindGroupLayout && this.device.createBindGroup
1277
+ ? this.device.createBindGroup({
1278
+ label: `${command.label ?? "draw"}-draw-bind-group`,
1279
+ layout: pipeline.getBindGroupLayout(0),
1280
+ entries: [
1281
+ { binding: 0, resource: { buffer: uniformBuffer } },
1282
+ ...(sampledTexture ? [
1283
+ { binding: 1, resource: sampledTexture.sampler },
1284
+ { binding: 2, resource: sampledTexture.view }
1285
+ ] : []),
1286
+ ...(materialTextures ? [
1287
+ { binding: 1, resource: materialTextures.base.sampler },
1288
+ { binding: 2, resource: materialTextures.base.view },
1289
+ { binding: 3, resource: materialTextures.environment.sampler },
1290
+ { binding: 4, resource: materialTextures.environment.view },
1291
+ { binding: 5, resource: materialTextures.brdf.sampler },
1292
+ { binding: 6, resource: materialTextures.brdf.view },
1293
+ { binding: 7, resource: materialTextures.shadow.sampler },
1294
+ { binding: 8, resource: materialTextures.shadow.view },
1295
+ { binding: 9, resource: materialTextures.normal.sampler },
1296
+ { binding: 10, resource: materialTextures.normal.view },
1297
+ { binding: 11, resource: materialTextures.metallicRoughness.sampler },
1298
+ { binding: 12, resource: materialTextures.metallicRoughness.view },
1299
+ { binding: 13, resource: materialTextures.occlusion.sampler },
1300
+ { binding: 14, resource: materialTextures.occlusion.view }
1301
+ ] : [])
1302
+ ]
1303
+ })
1304
+ : null;
1305
+ const pass = encoder.beginRenderPass({
1306
+ label: `${command.label ?? "draw"}-pass`,
1307
+ colorAttachments: [{
1308
+ view: nativeView,
1309
+ clearValue: this.activeRenderTarget?.nativeClearColor ?? this.clearColor,
1310
+ loadOp: shouldClear ? "clear" : "load",
1311
+ storeOp: "store"
1312
+ }],
1313
+ ...(depthEnabled
1314
+ ? {
1315
+ depthStencilAttachment: {
1316
+ view: depthView,
1317
+ depthClearValue: 1,
1318
+ depthLoadOp: shouldClear ? "clear" as const : "load" as const,
1319
+ depthStoreOp: "store" as const
1320
+ }
1321
+ }
1322
+ : {})
1323
+ });
1324
+ pass.setPipeline(pipeline);
1325
+ pass.setVertexBuffer(0, vertexBuffer.handle);
1326
+ if (bindGroup) pass.setBindGroup?.(0, bindGroup);
1327
+ if (command.indexBuffer) {
1328
+ if (!pass.setIndexBuffer || !pass.drawIndexed) {
1329
+ pass.end();
1330
+ uniformBuffer?.destroy();
1331
+ this.lastError = "Native WebGPU indexed draw skipped because the render-pass encoder does not expose indexed draw APIs.";
1332
+ return;
1333
+ }
1334
+ const indexBuffer = this.requireBuffer(command.indexBuffer);
1335
+ pass.setIndexBuffer(indexBuffer.handle, command.indexType ?? "uint16");
1336
+ pass.drawIndexed(command.indexCount ?? this.indicesFor(command).length, command.instanceCount ?? 1, command.firstIndex ?? 0);
1337
+ } else {
1338
+ pass.draw(command.vertexCount, command.instanceCount ?? 1, command.firstVertex ?? 0);
1339
+ }
1340
+ pass.end();
1341
+ this.device.queue.submit([encoder.finish()]);
1342
+ if (this.activeRenderTarget) this.activeRenderTarget.nativeNeedsClear = false;
1343
+ uniformBuffer?.destroy();
1344
+ this.nativeSubmissions += 1;
1345
+ if (sampledTexture) this.nativeTextureBindings += 1;
1346
+ if (shader.nativeUniformLayout === "generated-basic") this.nativeGeneratedBasicSubmissions += 1;
1347
+ if (shader.nativeUniformLayout === "generated-texture") this.nativeGeneratedTextureSubmissions += 1;
1348
+ if (shader.nativeUniformLayout === "passthrough") this.nativePassthroughSubmissions += 1;
1349
+ if (shader.nativeUniformLayout === "generated-pbr" || shader.nativeUniformLayout === "generated-textured-pbr" || shader.nativeUniformLayout === "generated-instanced-pbr") this.nativePbrSubmissions += 1;
1350
+ if (shader.nativeUniformLayout === "generated-instanced-pbr") this.nativeInstancedSubmissions += 1;
1351
+ if (shader.nativeUniformLayout === "generated-skinned-unlit") this.nativeSkinnedSubmissions += 1;
1352
+ if (shader.nativeUniformLayout === "generated-morph-unlit") this.nativeMorphSubmissions += 1;
1353
+ if (materialTextures?.actualBaseColor) this.nativeTextureBindings += 1;
1354
+ if (materialTextures?.actualNormal) this.nativeTextureBindings += 1;
1355
+ if (materialTextures?.actualMetallicRoughness) this.nativeTextureBindings += 1;
1356
+ if (materialTextures?.actualOcclusion) this.nativeTextureBindings += 1;
1357
+ if (materialTextures?.actualEnvironment) this.nativeEnvironmentBindings += 1;
1358
+ if (materialTextures?.actualBrdf) this.nativeEnvironmentBindings += 1;
1359
+ if (materialTextures?.actualShadow) this.nativeShadowMapBindings += 1;
1360
+ if (!this.activeRenderTarget) this.canvasSubmissions += 1;
1361
+ }
1362
+
1363
+ private flushNativeRenderTargetClear(target: WebGPURenderTarget): void {
1364
+ if (!target.nativeNeedsClear || !target.nativeView || !this.device.createCommandEncoder) return;
1365
+ const encoder = this.device.createCommandEncoder({ label: `${target.label}-native-clear` });
1366
+ const pass = encoder.beginRenderPass({
1367
+ label: `${target.label}-native-clear-pass`,
1368
+ colorAttachments: [{
1369
+ view: target.nativeView,
1370
+ clearValue: target.nativeClearColor,
1371
+ loadOp: "clear",
1372
+ storeOp: "store"
1373
+ }],
1374
+ ...(target.nativeDepthView
1375
+ ? {
1376
+ depthStencilAttachment: {
1377
+ view: target.nativeDepthView,
1378
+ depthClearValue: 1,
1379
+ depthLoadOp: "clear" as const,
1380
+ depthStoreOp: "store" as const
1381
+ }
1382
+ }
1383
+ : {})
1384
+ });
1385
+ pass.end();
1386
+ this.device.queue.submit([encoder.finish()]);
1387
+ target.nativeNeedsClear = false;
1388
+ }
1389
+
1390
+ private createNativeSampledTextureBinding(binding: TextureBinding | null): { readonly view: unknown; readonly sampler: WebGPUSamplerLike; readonly actual: boolean } | null {
1391
+ if (!binding?.texture || binding.texture.disposed || !binding.validate().ok || !hasNativeSampledTextureBinding(this.device)) return null;
1392
+ const texture = binding.texture;
1393
+ let resource = this.nativeSampledTextures.get(texture);
1394
+ if (!resource) {
1395
+ if (texture.source) {
1396
+ const sourceLevels = nativeTextureSourceLevels(texture);
1397
+ if (sourceLevels.length === 0) return null;
1398
+ const nativeTexture = this.device.createTexture({
1399
+ label: texture.label,
1400
+ size: { width: texture.width, height: texture.height, depthOrArrayLayers: 1 },
1401
+ format: webgpuSampledTextureFormat(texture, "rgba8"),
1402
+ usage: TEXTURE_USAGE.TEXTURE_BINDING | TEXTURE_USAGE.COPY_DST,
1403
+ mipLevelCount: sourceLevels.length
1404
+ });
1405
+ const writeTexture = this.device.queue.writeTexture;
1406
+ if (!writeTexture) return null;
1407
+ sourceLevels.forEach((level, mipLevel) => {
1408
+ writeTexture.call(
1409
+ this.device.queue,
1410
+ { texture: nativeTexture, mipLevel },
1411
+ level.data,
1412
+ { bytesPerRow: level.bytesPerRow, rowsPerImage: level.height },
1413
+ { width: level.width, height: level.height, depthOrArrayLayers: 1 }
1414
+ );
1415
+ });
1416
+ resource = { texture: nativeTexture, view: nativeTexture.createView() };
1417
+ } else {
1418
+ const sampledTexture = nativeSampledTextureLevels(texture);
1419
+ if (!sampledTexture) return null;
1420
+ const { levels, format } = sampledTexture;
1421
+ const baseLevel = levels[0];
1422
+ if (!baseLevel) return null;
1423
+ const levelBytesPerPixel = bytesPerPixel(format);
1424
+ if (levels.some((level) => level.data.byteLength < level.width * level.height * levelBytesPerPixel)) return null;
1425
+ const nativeTexture = this.device.createTexture({
1426
+ label: texture.label,
1427
+ size: { width: baseLevel.width, height: baseLevel.height, depthOrArrayLayers: 1 },
1428
+ format: webgpuSampledTextureFormat(texture, format),
1429
+ usage: TEXTURE_USAGE.TEXTURE_BINDING | TEXTURE_USAGE.COPY_DST,
1430
+ mipLevelCount: levels.length
1431
+ });
1432
+ for (const [mipLevel, level] of levels.entries()) {
1433
+ this.device.queue.writeTexture(
1434
+ { texture: nativeTexture, mipLevel },
1435
+ level.data,
1436
+ { bytesPerRow: level.width * levelBytesPerPixel, rowsPerImage: level.height },
1437
+ { width: level.width, height: level.height, depthOrArrayLayers: 1 }
1438
+ );
1439
+ }
1440
+ resource = { texture: nativeTexture, view: nativeTexture.createView() };
1441
+ }
1442
+ this.nativeSampledTextures.set(texture, resource);
1443
+ }
1444
+ return {
1445
+ view: resource.view,
1446
+ sampler: this.device.createSampler(webgpuSamplerDescriptor(binding.sampler)),
1447
+ actual: true
1448
+ };
1449
+ }
1450
+
1451
+ private createNativePbrTextureBindings(command: DrawCommand): {
1452
+ readonly base: { readonly view: unknown; readonly sampler: WebGPUSamplerLike; readonly actual: boolean };
1453
+ readonly environment: { readonly view: unknown; readonly sampler: WebGPUSamplerLike; readonly actual: boolean };
1454
+ readonly brdf: { readonly view: unknown; readonly sampler: WebGPUSamplerLike; readonly actual: boolean };
1455
+ readonly shadow: { readonly view: unknown; readonly sampler: WebGPUSamplerLike; readonly actual: boolean };
1456
+ readonly normal: { readonly view: unknown; readonly sampler: WebGPUSamplerLike; readonly actual: boolean };
1457
+ readonly metallicRoughness: { readonly view: unknown; readonly sampler: WebGPUSamplerLike; readonly actual: boolean };
1458
+ readonly occlusion: { readonly view: unknown; readonly sampler: WebGPUSamplerLike; readonly actual: boolean };
1459
+ readonly actualBaseColor: boolean;
1460
+ readonly actualEnvironment: boolean;
1461
+ readonly actualBrdf: boolean;
1462
+ readonly actualShadow: boolean;
1463
+ readonly actualNormal: boolean;
1464
+ readonly actualMetallicRoughness: boolean;
1465
+ readonly actualOcclusion: boolean;
1466
+ } | null {
1467
+ if (!hasNativeSampledTextureBinding(this.device)) return null;
1468
+ const baseBinding = uniformBaseColorTextureBinding(command.uniforms);
1469
+ const environmentBinding = uniformTextureBinding(command.uniforms, "u_environmentMapTexture");
1470
+ const brdfBinding = uniformTextureBinding(command.uniforms, "u_environmentBrdfLutTexture");
1471
+ const shadowBinding = uniformTextureBinding(command.uniforms, "u_shadowMapTexture");
1472
+ const normalBinding = uniformTextureBinding(command.uniforms, "u_normalTexture");
1473
+ const metallicRoughnessBinding = uniformTextureBinding(command.uniforms, "u_metallicRoughnessTexture");
1474
+ const occlusionBinding = uniformTextureBinding(command.uniforms, "u_occlusionTexture");
1475
+ const base = this.createNativeSampledTextureBinding(baseBinding) ?? this.createNativeFallbackSampledTextureBinding("white-srgb", [255, 255, 255, 255], "srgb");
1476
+ const environment = this.createNativeSampledTextureBinding(environmentBinding) ?? this.createNativeFallbackSampledTextureBinding("environment-srgb", [92, 116, 156, 255], "srgb");
1477
+ const brdf = this.createNativeSampledTextureBinding(brdfBinding) ?? this.createNativeFallbackSampledTextureBinding("brdf-linear", [180, 180, 255, 255], "linear");
1478
+ const shadow = this.createNativeSampledTextureBinding(shadowBinding) ?? this.createNativeFallbackSampledTextureBinding("shadow-lit-linear", [255, 255, 255, 255], "linear");
1479
+ const normal = this.createNativeSampledTextureBinding(normalBinding) ?? this.createNativeFallbackSampledTextureBinding("flat-normal-linear", [128, 128, 255, 255], "linear");
1480
+ const metallicRoughness = this.createNativeSampledTextureBinding(metallicRoughnessBinding) ?? this.createNativeFallbackSampledTextureBinding("metallic-roughness-linear", [255, 255, 255, 255], "linear");
1481
+ const occlusion = this.createNativeSampledTextureBinding(occlusionBinding) ?? this.createNativeFallbackSampledTextureBinding("occlusion-linear", [255, 255, 255, 255], "linear");
1482
+ if (!base || !environment || !brdf || !shadow || !normal || !metallicRoughness || !occlusion) return null;
1483
+ return {
1484
+ base,
1485
+ environment,
1486
+ brdf,
1487
+ shadow,
1488
+ normal,
1489
+ metallicRoughness,
1490
+ occlusion,
1491
+ actualBaseColor: baseBinding !== null && base.actual,
1492
+ actualEnvironment: environmentBinding !== null && environment.actual,
1493
+ actualBrdf: brdfBinding !== null && brdf.actual,
1494
+ actualShadow: shadowBinding !== null && shadow.actual,
1495
+ actualNormal: normalBinding !== null && normal.actual,
1496
+ actualMetallicRoughness: metallicRoughnessBinding !== null && metallicRoughness.actual,
1497
+ actualOcclusion: occlusionBinding !== null && occlusion.actual
1498
+ };
1499
+ }
1500
+
1501
+ private createNativeFallbackSampledTextureBinding(key: string, rgba: readonly [number, number, number, number], colorSpace: Texture["colorSpace"]): { readonly view: unknown; readonly sampler: WebGPUSamplerLike; readonly actual: boolean } | null {
1502
+ if (!hasNativeSampledTextureBinding(this.device)) return null;
1503
+ let resource = this.nativeSampledTextures.get(`fallback:${key}` as unknown as Texture);
1504
+ if (!resource) {
1505
+ const nativeTexture = this.device.createTexture({
1506
+ label: `aura3d-native-${key}`,
1507
+ size: { width: 1, height: 1, depthOrArrayLayers: 1 },
1508
+ format: colorSpace === "srgb" ? "rgba8unorm-srgb" : "rgba8unorm",
1509
+ usage: TEXTURE_USAGE.TEXTURE_BINDING | TEXTURE_USAGE.COPY_DST
1510
+ });
1511
+ this.device.queue.writeTexture(
1512
+ { texture: nativeTexture },
1513
+ new Uint8Array(rgba),
1514
+ { bytesPerRow: 4, rowsPerImage: 1 },
1515
+ { width: 1, height: 1, depthOrArrayLayers: 1 }
1516
+ );
1517
+ resource = { texture: nativeTexture, view: nativeTexture.createView() };
1518
+ this.nativeSampledTextures.set(`fallback:${key}` as unknown as Texture, resource);
1519
+ }
1520
+ return {
1521
+ view: resource.view,
1522
+ sampler: this.device.createSampler({
1523
+ minFilter: "nearest",
1524
+ magFilter: "nearest",
1525
+ addressModeU: "clamp-to-edge",
1526
+ addressModeV: "clamp-to-edge"
1527
+ }),
1528
+ actual: false
1529
+ };
1530
+ }
1531
+
1532
+ private createNativeDrawUniformBuffer(command: DrawCommand): WebGPUBufferLike | null {
1533
+ if (!this.device.createBindGroup) return null;
1534
+ const data = new Float32Array(188);
1535
+ const baseColorBinding = uniformBaseColorTextureBinding(command.uniforms);
1536
+ const environmentBinding = uniformTextureBinding(command.uniforms, "u_environmentMapTexture");
1537
+ const normalBinding = uniformTextureBinding(command.uniforms, "u_normalTexture");
1538
+ const metallicRoughnessBinding = uniformTextureBinding(command.uniforms, "u_metallicRoughnessTexture");
1539
+ const occlusionBinding = uniformTextureBinding(command.uniforms, "u_occlusionTexture");
1540
+ data.set(uniformMat4(command.uniforms?.get("u_modelViewProjection")) ?? identityMatrix(), 0);
1541
+ data.set(uniformColor(command.uniforms), 16);
1542
+ data[20] = uniformNumber(command.uniforms?.get("u_metallic"), 0);
1543
+ data[21] = uniformNumber(command.uniforms?.get("u_roughness"), 0.5);
1544
+ data[22] = uniformNumber(command.uniforms?.get("u_environmentIntensity"), 0);
1545
+ data[23] = uniformNumber(command.uniforms?.get("u_environmentMapTextureIntensity"), 0);
1546
+ data[24] = uniformNumber(command.uniforms?.get("u_baseColorTextureEnabled"), baseColorBinding ? 1 : 0);
1547
+ data[25] = uniformNumber(command.uniforms?.get("u_shadowMapEnabled"), 0);
1548
+ data[26] = uniformNumber(command.uniforms?.get("u_shadowMapStrength"), 0.65);
1549
+ data[27] = uniformNumber(command.uniforms?.get("u_environmentMapTextureEnabled"), environmentBinding ? 1 : 0);
1550
+ const morphWeights = command.uniforms?.get("u_morphWeights");
1551
+ data[28] = morphWeights instanceof Float32Array || Array.isArray(morphWeights) ? Number(morphWeights[0] ?? 0) : 0;
1552
+ data[29] = uniformNumber(command.uniforms?.get("u_morphTargetCount"), 0);
1553
+ data[30] = uniformNumber(command.uniforms?.get("u_environmentMapTextureMipCount"), 1);
1554
+ data[31] = uniformNumber(command.uniforms?.get("u_environmentMapTextureSpecularIntensity"), 0)
1555
+ * uniformNumber(command.uniforms?.get("u_materialEnvironmentSpecularScale"), 1);
1556
+ data[128] = uniformNumber(command.uniforms?.get("u_normalTextureEnabled"), normalBinding ? 1 : 0);
1557
+ data[129] = uniformNumber(command.uniforms?.get("u_normalScale"), 1);
1558
+ data[130] = uniformNumber(command.uniforms?.get("u_occlusionStrength"), 1);
1559
+ data[160] = uniformNumber(command.uniforms?.get("u_alphaCutoff"), 0);
1560
+ data[161] = uniformNumber(command.uniforms?.get("u_transmissionFactor"), 0);
1561
+ data[162] = uniformNumber(command.uniforms?.get("u_diffuseTransmissionFactor"), 0);
1562
+ data.set(uniformVec3(command.uniforms?.get("u_cameraPosition")) ?? [0, 0, 1], 164);
1563
+ data[167] = 1;
1564
+ data[168] = uniformNumber(command.uniforms?.get("u_metallicRoughnessTextureEnabled"), metallicRoughnessBinding ? 1 : 0);
1565
+ data[169] = uniformNumber(command.uniforms?.get("u_occlusionTextureEnabled"), occlusionBinding ? 1 : 0);
1566
+ data[170] = uniformNumber(command.uniforms?.get("u_productColorSmoothing"), 0);
1567
+ data.set(uniformMat4(command.uniforms?.get("u_normalMatrix")) ?? identityMatrix(), 172);
1568
+ const modelMatrix = uniformMat4(command.uniforms?.get("u_modelMatrix")) ?? identityMatrix();
1569
+ const instanceMatrixValue = command.uniforms?.get("u_instanceMatrices");
1570
+ const instanceMatrixNumbers = instanceMatrixValue instanceof Float32Array || Array.isArray(instanceMatrixValue) ? Array.from(instanceMatrixValue) : [];
1571
+ const hasInstanceMatrices = instanceMatrixNumbers.length >= 16 && instanceMatrixNumbers.slice(0, 16).every(Number.isFinite);
1572
+ const instanceMatrices = hasInstanceMatrices ? uniformMat4Array(instanceMatrixValue, 4) : [];
1573
+ for (let index = 0; index < 4; index += 1) {
1574
+ data.set(instanceMatrices[index] ?? (index === 0 ? modelMatrix : identityMatrix()), 32 + index * 16);
1575
+ }
1576
+ const jointMatrices = uniformMat4Array(command.uniforms?.get("u_jointMatrices"), 2);
1577
+ for (let index = 0; index < 2; index += 1) {
1578
+ data.set(jointMatrices[index] ?? identityMatrix(), 96 + index * 16);
1579
+ }
1580
+ const morphDeltas = command.uniforms?.get("u_morphPositionDeltas");
1581
+ const morphNumbers = morphDeltas instanceof Float32Array || Array.isArray(morphDeltas) ? Array.from(morphDeltas).slice(0, 32) : [];
1582
+ if (morphNumbers.length > 0) data.set(morphNumbers, 128);
1583
+ const buffer = this.device.createBuffer({
1584
+ label: `${command.label ?? "draw"}-draw-uniforms`,
1585
+ size: data.byteLength,
1586
+ usage: BUFFER_USAGE.UNIFORM | BUFFER_USAGE.COPY_DST
1587
+ });
1588
+ this.device.queue.writeBuffer(buffer, 0, data);
1589
+ return buffer;
1590
+ }
1591
+
1592
+ private currentCanvasView(): unknown | null {
1593
+ if (!this.canvasContext) return null;
1594
+ return this.canvasContext.getCurrentTexture().createView();
1595
+ }
1596
+
1597
+ private ensureCanvasDepthAttachment(width: number, height: number): void {
1598
+ if (!this.canvasContext || !this.device.createTexture) return;
1599
+ if (
1600
+ this.canvasDepthTexture &&
1601
+ this.canvasDepthView &&
1602
+ this.canvasDepthWidth === width &&
1603
+ this.canvasDepthHeight === height
1604
+ ) {
1605
+ return;
1606
+ }
1607
+ this.canvasDepthTexture?.destroy();
1608
+ this.canvasDepthTexture = this.device.createTexture({
1609
+ label: "aura3d-webgpu-canvas-depth",
1610
+ size: [width, height],
1611
+ format: DEPTH_TEXTURE_FORMAT,
1612
+ usage: TEXTURE_USAGE.RENDER_ATTACHMENT
1613
+ });
1614
+ this.canvasDepthView = this.canvasDepthTexture.createView();
1615
+ this.canvasDepthWidth = width;
1616
+ this.canvasDepthHeight = height;
1617
+ }
1618
+
1619
+ private clearActiveRenderTarget(color: readonly [number, number, number, number]): void {
1620
+ if (!this.activeRenderTarget) return;
1621
+ const bytes = rgbaBytes(color);
1622
+ for (let index = 0; index < this.activeRenderTarget.colorPixels.length; index += 4) {
1623
+ this.activeRenderTarget.colorPixels.set(bytes, index);
1624
+ }
1625
+ this.activeRenderTarget.nativeNeedsClear = true;
1626
+ this.activeRenderTarget.nativeClearColor = color;
1627
+ this.activeRenderTarget.depthPixels?.fill(1);
1628
+ if (this.activeRenderTarget.colorFloatPixels) {
1629
+ for (let index = 0; index < this.activeRenderTarget.colorFloatPixels.length; index += 4) {
1630
+ this.activeRenderTarget.colorFloatPixels[index] = color[0];
1631
+ this.activeRenderTarget.colorFloatPixels[index + 1] = color[1];
1632
+ this.activeRenderTarget.colorFloatPixels[index + 2] = color[2];
1633
+ this.activeRenderTarget.colorFloatPixels[index + 3] = color[3];
1634
+ }
1635
+ }
1636
+ }
1637
+
1638
+ private indicesFor(command: DrawCommand): readonly number[] {
1639
+ if (!command.indexBuffer) {
1640
+ const firstVertex = command.firstVertex ?? 0;
1641
+ return Array.from({ length: command.vertexCount }, (_, index) => firstVertex + index);
1642
+ }
1643
+ const indexBuffer = this.requireBuffer(command.indexBuffer);
1644
+ const indexCount = command.indexCount ?? Math.floor(indexBuffer.byteLength / (command.indexType === "uint32" ? 4 : 2));
1645
+ const indices: number[] = [];
1646
+ const view = new DataView(indexBuffer.bytes.buffer, indexBuffer.bytes.byteOffset, indexBuffer.bytes.byteLength);
1647
+ const firstIndex = command.firstIndex ?? 0;
1648
+ for (let index = 0; index < indexCount; index += 1) {
1649
+ const byteOffset = (firstIndex + index) * (command.indexType === "uint32" ? 4 : 2);
1650
+ indices.push(command.indexType === "uint32" ? view.getUint32(byteOffset, true) : view.getUint16(byteOffset, true));
1651
+ }
1652
+ return indices;
1653
+ }
1654
+ }
1655
+
1656
+ async function requestAdapter(gpu: WebGPULike | undefined): Promise<WebGPUAdapterLike | null> {
1657
+ if (!gpu) {
1658
+ throw new RenderDeviceError("WebGPU runtime is missing from the current environment", "WEBGPU_RUNTIME_MISSING");
1659
+ }
1660
+ return gpu.requestAdapter();
1661
+ }
1662
+
1663
+ async function requestDevice(adapter: WebGPUAdapterLike, injectedDevice?: WebGPUDeviceLike): Promise<WebGPUDeviceLike> {
1664
+ if (injectedDevice) {
1665
+ return injectedDevice;
1666
+ }
1667
+ try {
1668
+ return await adapter.requestDevice();
1669
+ } catch (error) {
1670
+ throw new RenderDeviceError("WebGPU adapter failed to create a device", "WEBGPU_DEVICE_REQUEST_FAILED", {
1671
+ adapter: describeAdapter(adapter),
1672
+ reason: error instanceof Error ? error.message : String(error)
1673
+ });
1674
+ }
1675
+ }
1676
+
1677
+ function validateWebGPUDevice(device: WebGPUDeviceLike): WebGPUDeviceLike {
1678
+ const missing: string[] = [];
1679
+ if (!device || typeof device !== "object") missing.push("device");
1680
+ if (typeof device?.createBuffer !== "function") missing.push("createBuffer");
1681
+ if (typeof device?.queue?.writeBuffer !== "function") missing.push("queue.writeBuffer");
1682
+ if (typeof device?.queue?.submit !== "function") missing.push("queue.submit");
1683
+
1684
+ if (missing.length > 0) {
1685
+ throw new RenderDeviceError("WebGPU device is missing required render-device capabilities", "WEBGPU_DEVICE_INVALID", {
1686
+ missing
1687
+ });
1688
+ }
1689
+ return device;
1690
+ }
1691
+
1692
+ function hasNativeRenderPipeline(device: WebGPUDeviceLike): device is WebGPUDeviceLike & Required<Pick<WebGPUDeviceLike, "createBindGroup" | "createCommandEncoder" | "createRenderPipeline" | "createTexture">> {
1693
+ return typeof device.createCommandEncoder === "function" &&
1694
+ typeof device.createRenderPipeline === "function" &&
1695
+ typeof device.createBindGroup === "function" &&
1696
+ typeof device.createTexture === "function";
1697
+ }
1698
+
1699
+ function hasNativeSampledTextureBinding(device: WebGPUDeviceLike): device is WebGPUDeviceLike & Required<Pick<WebGPUDeviceLike, "createTexture" | "createSampler">> & { readonly queue: WebGPUQueueLike & Required<Pick<WebGPUQueueLike, "writeTexture">> } {
1700
+ return typeof device.createTexture === "function" &&
1701
+ typeof device.createSampler === "function" &&
1702
+ typeof device.queue.writeTexture === "function";
1703
+ }
1704
+
1705
+ function hasNativeTextureUpload(device: WebGPUDeviceLike): device is WebGPUDeviceLike & { readonly queue: WebGPUQueueLike & Required<Pick<WebGPUQueueLike, "writeTexture">> } {
1706
+ return typeof device.queue.writeTexture === "function";
1707
+ }
1708
+
1709
+ function hasNativeTextureReadback(device: WebGPUDeviceLike): device is WebGPUDeviceLike & Required<Pick<WebGPUDeviceLike, "createCommandEncoder" | "createTexture">> {
1710
+ if (typeof device.createCommandEncoder !== "function" || typeof device.createTexture !== "function") return false;
1711
+ const probe = device.createBuffer({
1712
+ label: "aura3d-native-readback-capability-probe",
1713
+ size: 4,
1714
+ usage: BUFFER_USAGE.MAP_READ | BUFFER_USAGE.COPY_DST
1715
+ });
1716
+ const supported = typeof probe.mapAsync === "function" &&
1717
+ typeof probe.getMappedRange === "function" &&
1718
+ typeof probe.unmap === "function" &&
1719
+ typeof device.createCommandEncoder({ label: "aura3d-native-readback-capability-probe" }).copyTextureToBuffer === "function";
1720
+ probe.destroy();
1721
+ return supported;
1722
+ }
1723
+
1724
+ function alignTo(value: number, alignment: number): number {
1725
+ return Math.ceil(value / alignment) * alignment;
1726
+ }
1727
+
1728
+ function readWebGPU(globalScope: Pick<typeof globalThis, "navigator">): WebGPULike | undefined {
1729
+ return (globalScope.navigator as Navigator & { gpu?: WebGPULike } | undefined)?.gpu;
1730
+ }
1731
+
1732
+ function acquireWebGPUCanvasContext(canvas: HTMLCanvasElement | OffscreenCanvas): WebGPUCanvasContextLike {
1733
+ const getContext = (canvas as HTMLCanvasElement & {
1734
+ getContext(type: "webgpu"): WebGPUCanvasContextLike | null;
1735
+ }).getContext;
1736
+ if (typeof getContext !== "function") {
1737
+ throw new RenderDeviceError("WebGPU canvas presentation requires getContext(\"webgpu\")", "WEBGPU_CANVAS_CONTEXT_MISSING");
1738
+ }
1739
+ const context = getContext.call(canvas, "webgpu");
1740
+ if (!context || typeof context.configure !== "function" || typeof context.getCurrentTexture !== "function") {
1741
+ throw new RenderDeviceError("Canvas did not provide a usable WebGPU presentation context", "WEBGPU_CANVAS_CONTEXT_INVALID");
1742
+ }
1743
+ return context;
1744
+ }
1745
+
1746
+ function describeAdapter(adapter: WebGPUAdapterLike): string | undefined {
1747
+ if (adapter.name) return adapter.name;
1748
+ const parts = [adapter.info?.vendor, adapter.info?.architecture, adapter.info?.device, adapter.info?.description].filter(Boolean);
1749
+ return parts.length > 0 ? parts.join(" ") : undefined;
1750
+ }
1751
+
1752
+ function bufferUsageFlags(usage: BufferUsage): number {
1753
+ if (usage === "vertex") return BUFFER_USAGE.VERTEX | BUFFER_USAGE.COPY_DST | BUFFER_USAGE.COPY_SRC;
1754
+ if (usage === "index") return BUFFER_USAGE.INDEX | BUFFER_USAGE.COPY_DST | BUFFER_USAGE.COPY_SRC;
1755
+ if (usage === "uniform") return BUFFER_USAGE.UNIFORM | BUFFER_USAGE.COPY_DST | BUFFER_USAGE.COPY_SRC;
1756
+ return BUFFER_USAGE.MAP_READ | BUFFER_USAGE.COPY_DST;
1757
+ }
1758
+
1759
+ function webgpuTextureFormat(format: "rgba8" | "rgba16f" | "rgba32f" | string): string {
1760
+ if (format === "rgba16f") return "rgba16float";
1761
+ if (format === "rgba32f") return "rgba32float";
1762
+ return "rgba8unorm";
1763
+ }
1764
+
1765
+ function nativeSampledTextureLevels(texture: Texture): { readonly levels: readonly { readonly width: number; readonly height: number; readonly data: ArrayBufferView }[]; readonly format: TextureFormat } | null {
1766
+ if (isCompressedTextureFormat(texture.format)) {
1767
+ const fallback = texture.fallbackTextureLevels;
1768
+ return fallback.length > 0 ? { levels: fallback, format: "rgba8" } : null;
1769
+ }
1770
+ if (texture.format === "depth24") return null;
1771
+ const levels = texture.textureLevels;
1772
+ return levels.length > 0 ? { levels, format: texture.format } : null;
1773
+ }
1774
+
1775
+ function nativeTextureSourceLevels(texture: Texture): readonly {
1776
+ readonly width: number;
1777
+ readonly height: number;
1778
+ readonly bytesPerRow: number;
1779
+ readonly data: Uint8Array;
1780
+ }[] {
1781
+ const source = texture.source;
1782
+ if (!source || typeof globalThis === "undefined") return [];
1783
+ const width = Math.max(1, Math.round(texture.width));
1784
+ const height = Math.max(1, Math.round(texture.height));
1785
+ const mipCount = Math.max(1, Math.floor(Math.log2(Math.max(width, height))) + 1);
1786
+ const levels: {
1787
+ readonly width: number;
1788
+ readonly height: number;
1789
+ readonly bytesPerRow: number;
1790
+ readonly data: Uint8Array;
1791
+ }[] = [];
1792
+ for (let level = 0; level < mipCount; level += 1) {
1793
+ const levelWidth = Math.max(1, width >> level);
1794
+ const levelHeight = Math.max(1, height >> level);
1795
+ const canvas = createTextureReadbackCanvas(levelWidth, levelHeight);
1796
+ if (!canvas) return levels;
1797
+ const context = canvas.getContext("2d", { willReadFrequently: true }) as CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D | null;
1798
+ if (!context) return levels;
1799
+ context.clearRect(0, 0, levelWidth, levelHeight);
1800
+ context.drawImage(source as CanvasImageSource, 0, 0, levelWidth, levelHeight);
1801
+ const pixels = context.getImageData(0, 0, levelWidth, levelHeight).data;
1802
+ const sourceBytesPerRow = levelWidth * 4;
1803
+ const bytesPerRow = alignTo(sourceBytesPerRow, 256);
1804
+ if (bytesPerRow === sourceBytesPerRow) {
1805
+ levels.push({ width: levelWidth, height: levelHeight, bytesPerRow, data: new Uint8Array(pixels.buffer.slice(pixels.byteOffset, pixels.byteOffset + pixels.byteLength)) });
1806
+ continue;
1807
+ }
1808
+ const data = new Uint8Array(bytesPerRow * levelHeight);
1809
+ for (let row = 0; row < levelHeight; row += 1) {
1810
+ data.set(pixels.subarray(row * sourceBytesPerRow, (row + 1) * sourceBytesPerRow), row * bytesPerRow);
1811
+ }
1812
+ levels.push({ width: levelWidth, height: levelHeight, bytesPerRow, data });
1813
+ }
1814
+ return levels;
1815
+ }
1816
+
1817
+ function createTextureReadbackCanvas(width: number, height: number): OffscreenCanvas | HTMLCanvasElement | null {
1818
+ const offscreenCanvas = (globalThis as unknown as { OffscreenCanvas?: typeof OffscreenCanvas }).OffscreenCanvas;
1819
+ if (offscreenCanvas) return new offscreenCanvas(width, height);
1820
+ if (typeof document === "undefined") return null;
1821
+ const canvas = document.createElement("canvas");
1822
+ canvas.width = width;
1823
+ canvas.height = height;
1824
+ return canvas;
1825
+ }
1826
+
1827
+ function webgpuSampledTextureFormat(texture: Texture, format: TextureFormat): string {
1828
+ if (format === "rgba16f") return "rgba16float";
1829
+ if (format === "rgba32f") return "rgba32float";
1830
+ return texture.colorSpace === "srgb" ? "rgba8unorm-srgb" : "rgba8unorm";
1831
+ }
1832
+
1833
+ function webgpuMinFilter(filter: TextureMinFilter): TextureMagFilter {
1834
+ if (filter === "nearest" || filter === "nearest-mipmap-nearest" || filter === "nearest-mipmap-linear") return "nearest";
1835
+ return "linear";
1836
+ }
1837
+
1838
+ function webgpuMagFilter(filter: TextureMagFilter): TextureMagFilter {
1839
+ return filter;
1840
+ }
1841
+
1842
+ function webgpuMipmapFilter(filter: TextureMinFilter): TextureMagFilter | undefined {
1843
+ if (filter === "nearest-mipmap-nearest" || filter === "linear-mipmap-nearest") return "nearest";
1844
+ if (filter === "nearest-mipmap-linear" || filter === "linear-mipmap-linear") return "linear";
1845
+ return undefined;
1846
+ }
1847
+
1848
+ function webgpuSamplerDescriptor(sampler: Sampler): WebGPUSamplerDescriptorLike {
1849
+ const minFilter = webgpuMinFilter(sampler.minFilter);
1850
+ const magFilter = webgpuMagFilter(sampler.magFilter);
1851
+ const mipmapFilter = webgpuMipmapFilter(sampler.minFilter);
1852
+ const descriptor: WebGPUSamplerDescriptorLike = {
1853
+ minFilter,
1854
+ magFilter,
1855
+ ...(mipmapFilter ? { mipmapFilter } : {}),
1856
+ addressModeU: sampler.addressU,
1857
+ addressModeV: sampler.addressV
1858
+ };
1859
+ const maxAnisotropy = webgpuMaxAnisotropy(sampler.maxAnisotropy, minFilter, magFilter, mipmapFilter);
1860
+ return maxAnisotropy === undefined ? descriptor : { ...descriptor, maxAnisotropy };
1861
+ }
1862
+
1863
+ function webgpuMaxAnisotropy(
1864
+ maxAnisotropy: number,
1865
+ minFilter: TextureMagFilter,
1866
+ magFilter: TextureMagFilter,
1867
+ mipmapFilter: TextureMagFilter | undefined
1868
+ ): number | undefined {
1869
+ if (maxAnisotropy <= 1) return undefined;
1870
+ if (minFilter !== "linear" || magFilter !== "linear" || mipmapFilter !== "linear") return undefined;
1871
+ return Math.min(16, Math.max(1, Math.floor(maxAnisotropy)));
1872
+ }
1873
+
1874
+ function usesNativeDrawUniforms(layout: NativeUniformLayout): boolean {
1875
+ return layout !== "passthrough";
1876
+ }
1877
+
1878
+ function usesNativePbrTextureBindings(layout: NativeUniformLayout): boolean {
1879
+ return layout === "generated-pbr" ||
1880
+ layout === "generated-textured-pbr" ||
1881
+ layout === "generated-instanced-pbr";
1882
+ }
1883
+
1884
+ function writeAlignedQueueBuffer(
1885
+ queue: WebGPUQueueLike,
1886
+ buffer: WebGPUBufferLike,
1887
+ byteOffset: number,
1888
+ data: ArrayBufferView,
1889
+ nativeByteLength: number
1890
+ ): void {
1891
+ const bytes = viewBytes(data);
1892
+ if (byteOffset % 4 === 0 && bytes.byteLength % 4 === 0) {
1893
+ queue.writeBuffer(buffer, byteOffset, bytes);
1894
+ return;
1895
+ }
1896
+ const alignedOffset = Math.floor(byteOffset / 4) * 4;
1897
+ const alignedEnd = alignTo(byteOffset + bytes.byteLength, 4);
1898
+ if (alignedEnd > nativeByteLength) {
1899
+ throw new RenderDeviceError("Aligned WebGPU buffer write exceeds native buffer allocation", "BUFFER_RANGE_OUT_OF_BOUNDS", {
1900
+ byteOffset,
1901
+ dataByteLength: bytes.byteLength,
1902
+ alignedOffset,
1903
+ alignedEnd,
1904
+ nativeByteLength
1905
+ });
1906
+ }
1907
+ const padded = new Uint8Array(alignedEnd - alignedOffset);
1908
+ padded.set(bytes, byteOffset - alignedOffset);
1909
+ queue.writeBuffer(buffer, alignedOffset, padded);
1910
+ }
1911
+
1912
+ function rgbaBytes(color: readonly [number, number, number, number]): Uint8Array {
1913
+ return new Uint8Array(color.map((channel) => Math.round(Math.max(0, Math.min(1, channel)) * 255)));
1914
+ }
1915
+
1916
+ function halfFloatToNumber(bits: number): number {
1917
+ const sign = (bits & 0x8000) ? -1 : 1;
1918
+ const exponent = (bits >> 10) & 0x1f;
1919
+ const fraction = bits & 0x03ff;
1920
+ if (exponent === 0) {
1921
+ return sign * 2 ** -14 * (fraction / 1024);
1922
+ }
1923
+ if (exponent === 0x1f) {
1924
+ return fraction === 0 ? sign * Infinity : Number.NaN;
1925
+ }
1926
+ return sign * 2 ** (exponent - 15) * (1 + fraction / 1024);
1927
+ }
1928
+
1929
+ function uniformColor(uniforms: DrawCommand["uniforms"]): readonly [number, number, number, number] {
1930
+ const value = uniforms?.get("u_baseColor") ?? uniforms?.get("u_color") ?? uniforms?.get("color");
1931
+ const components = value instanceof Float32Array || Array.isArray(value) ? Array.from(value).slice(0, 4) : [];
1932
+ if (components.length >= 3 && components.every((component) => Number.isFinite(component))) {
1933
+ return [
1934
+ components[0] ?? 1,
1935
+ components[1] ?? 1,
1936
+ components[2] ?? 1,
1937
+ components[3] ?? 1
1938
+ ];
1939
+ }
1940
+ return [1, 1, 1, 1];
1941
+ }
1942
+
1943
+ function uniformBaseColorTextureBinding(uniforms: DrawCommand["uniforms"]): TextureBinding | null {
1944
+ if (!uniforms) return null;
1945
+ const direct = uniforms.get("u_texture") ?? uniforms.get("u_baseColorTexture") ?? uniforms.get("baseColorTexture");
1946
+ if (direct instanceof TextureBinding && direct.texture && !direct.texture.disposed && direct.validate().ok) {
1947
+ return direct;
1948
+ }
1949
+ return null;
1950
+ }
1951
+
1952
+ function uniformTextureBinding(uniforms: DrawCommand["uniforms"], name: string): TextureBinding | null {
1953
+ const value = uniforms?.get(name);
1954
+ return value instanceof TextureBinding && value.texture && !value.texture.disposed && value.validate().ok ? value : null;
1955
+ }
1956
+
1957
+ function uniformNumber(value: UniformValue | undefined, fallback: number): number {
1958
+ return typeof value === "number" && Number.isFinite(value) ? value : fallback;
1959
+ }
1960
+
1961
+ function uniformVec3(value: UniformValue | undefined): readonly [number, number, number] | null {
1962
+ const components = value instanceof Float32Array || Array.isArray(value) ? Array.from(value).slice(0, 3) : [];
1963
+ return components.length === 3 && components.every(Number.isFinite)
1964
+ ? [components[0]!, components[1]!, components[2]!]
1965
+ : null;
1966
+ }
1967
+
1968
+ function uniformMat4Array(value: UniformValue | undefined, count: number): readonly (readonly number[])[] {
1969
+ const numbers = value instanceof Float32Array || Array.isArray(value) ? Array.from(value) : [];
1970
+ return Array.from({ length: count }, (_, index) => {
1971
+ const start = index * 16;
1972
+ const matrix = numbers.slice(start, start + 16);
1973
+ return matrix.length === 16 && matrix.every(Number.isFinite) ? matrix : identityMatrix();
1974
+ });
1975
+ }
1976
+
1977
+ function uniformRasterMatrices(uniforms: DrawCommand["uniforms"], instanceCount: number): readonly (readonly number[])[] {
1978
+ const modelViewProjection = uniformMat4(uniforms?.get("u_modelViewProjection")) ?? identityMatrix();
1979
+ const value = uniforms?.get("u_instanceMatrices");
1980
+ const numbers = value instanceof Float32Array || Array.isArray(value) ? Array.from(value) : [];
1981
+ if (numbers.length < instanceCount * 16 || !numbers.slice(0, instanceCount * 16).every(Number.isFinite)) {
1982
+ return Array.from({ length: instanceCount }, () => modelViewProjection);
1983
+ }
1984
+ return Array.from({ length: instanceCount }, (_, index) => multiplyMat4(modelViewProjection, numbers.slice(index * 16, index * 16 + 16)));
1985
+ }
1986
+
1987
+ function uniformRasterModelMatrices(uniforms: DrawCommand["uniforms"], instanceCount: number): readonly (readonly number[])[] {
1988
+ const modelMatrix = uniformMat4(uniforms?.get("u_modelMatrix")) ?? identityMatrix();
1989
+ const value = uniforms?.get("u_instanceMatrices");
1990
+ const numbers = value instanceof Float32Array || Array.isArray(value) ? Array.from(value) : [];
1991
+ if (numbers.length < instanceCount * 16 || !numbers.slice(0, instanceCount * 16).every(Number.isFinite)) {
1992
+ return Array.from({ length: instanceCount }, () => modelMatrix);
1993
+ }
1994
+ return Array.from({ length: instanceCount }, (_, index) => multiplyMat4(modelMatrix, numbers.slice(index * 16, index * 16 + 16)));
1995
+ }
1996
+
1997
+ function uniformForwardShadow(uniforms: DrawCommand["uniforms"]): ForwardShadowUniforms | null {
1998
+ if (!uniforms) return null;
1999
+ const enabled = uniforms.get("u_shadowMapEnabled");
2000
+ if (typeof enabled !== "number" || enabled < 0.5) return null;
2001
+ const texture = uniforms.get("u_shadowMapTexture");
2002
+ const matrix = uniformMat4(uniforms.get("u_shadowMapMatrix")) ?? identityMatrix();
2003
+ if (!(texture instanceof TextureBinding) || !texture.texture || texture.texture.disposed || !texture.validate().ok) {
2004
+ return null;
2005
+ }
2006
+ const strengthValue = uniforms.get("u_shadowMapStrength");
2007
+ const biasValue = uniforms.get("u_shadowMapBias");
2008
+ const strength = typeof strengthValue === "number" && Number.isFinite(strengthValue) ? Math.max(0, Math.min(1, strengthValue)) : 0.65;
2009
+ const bias = typeof biasValue === "number" && Number.isFinite(biasValue) ? Math.max(0, biasValue) : 0.001;
2010
+ return { texture, matrix, strength, bias };
2011
+ }
2012
+
2013
+ function uniformMat4(value: UniformValue | undefined): readonly number[] | null {
2014
+ const numbers = value instanceof Float32Array || Array.isArray(value) ? Array.from(value) : [];
2015
+ return numbers.length === 16 && numbers.every(Number.isFinite) ? numbers : null;
2016
+ }
2017
+
2018
+ function multiplyMat4(left: readonly number[], right: readonly number[]): readonly number[] {
2019
+ const out = new Array<number>(16);
2020
+ for (let row = 0; row < 4; row += 1) {
2021
+ for (let column = 0; column < 4; column += 1) {
2022
+ out[column * 4 + row] =
2023
+ (left[0 * 4 + row] ?? 0) * (right[column * 4 + 0] ?? 0) +
2024
+ (left[1 * 4 + row] ?? 0) * (right[column * 4 + 1] ?? 0) +
2025
+ (left[2 * 4 + row] ?? 0) * (right[column * 4 + 2] ?? 0) +
2026
+ (left[3 * 4 + row] ?? 0) * (right[column * 4 + 3] ?? 0);
2027
+ }
2028
+ }
2029
+ return out;
2030
+ }
2031
+
2032
+ function transformPosition(position: readonly [number, number, number], matrix: readonly number[]): readonly [number, number, number] {
2033
+ const x = (matrix[0] ?? 1) * position[0] + (matrix[4] ?? 0) * position[1] + (matrix[8] ?? 0) * position[2] + (matrix[12] ?? 0);
2034
+ const y = (matrix[1] ?? 0) * position[0] + (matrix[5] ?? 1) * position[1] + (matrix[9] ?? 0) * position[2] + (matrix[13] ?? 0);
2035
+ const z = (matrix[2] ?? 0) * position[0] + (matrix[6] ?? 0) * position[1] + (matrix[10] ?? 1) * position[2] + (matrix[14] ?? 0);
2036
+ const w = (matrix[3] ?? 0) * position[0] + (matrix[7] ?? 0) * position[1] + (matrix[11] ?? 0) * position[2] + (matrix[15] ?? 1);
2037
+ const inverseW = Math.abs(w) > 1e-8 ? 1 / w : 1;
2038
+ return [
2039
+ x * inverseW,
2040
+ y * inverseW,
2041
+ z * inverseW
2042
+ ];
2043
+ }
2044
+
2045
+ function toDepth(ndcZ: number): number {
2046
+ return Math.max(0, Math.min(1, ndcZ * 0.5 + 0.5));
2047
+ }
2048
+
2049
+ function passesDepthTest(target: WebGPURenderTarget, pixelIndex: number, depth: number, enabled: boolean, write: boolean): boolean {
2050
+ if (!enabled || !target.depthPixels) return true;
2051
+ if (depth > (target.depthPixels[pixelIndex] ?? 1) + 1e-6) return false;
2052
+ if (write) target.depthPixels[pixelIndex] = depth;
2053
+ return true;
2054
+ }
2055
+
2056
+ function readPosition(bytes: Uint8Array, stride: number, offset: number, vertexIndex: number): readonly [number, number, number] {
2057
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
2058
+ const base = vertexIndex * stride + offset;
2059
+ return [
2060
+ view.getFloat32(base, true),
2061
+ view.getFloat32(base + 4, true),
2062
+ view.getFloat32(base + 8, true)
2063
+ ];
2064
+ }
2065
+
2066
+ function readMorphedPosition(bytes: Uint8Array, stride: number, offset: number, vertexIndex: number, uniforms: DrawCommand["uniforms"]): readonly [number, number, number] {
2067
+ const basePosition = readPosition(bytes, stride, offset, vertexIndex);
2068
+ const packed = uniforms?.get("u_morphPositionDeltas");
2069
+ const weights = uniforms?.get("u_morphWeights");
2070
+ const targetCountValue = uniforms?.get("u_morphTargetCount");
2071
+ if (!(packed instanceof Float32Array) || !(weights instanceof Float32Array) || typeof targetCountValue !== "number") {
2072
+ return basePosition;
2073
+ }
2074
+ const targetCount = Math.max(0, Math.min(weights.length, Math.floor(targetCountValue)));
2075
+ let x = basePosition[0];
2076
+ let y = basePosition[1];
2077
+ let z = basePosition[2];
2078
+ for (let target = 0; target < targetCount; target += 1) {
2079
+ const weight = weights[target] ?? 0;
2080
+ const deltaOffset = (target * 64 + vertexIndex) * 4;
2081
+ x += (packed[deltaOffset] ?? 0) * weight;
2082
+ y += (packed[deltaOffset + 1] ?? 0) * weight;
2083
+ z += (packed[deltaOffset + 2] ?? 0) * weight;
2084
+ }
2085
+ return [x, y, z];
2086
+ }
2087
+
2088
+ function toPixel(position: readonly [number, number, number], width: number, height: number): readonly [number, number, number] {
2089
+ return [
2090
+ (position[0] * 0.5 + 0.5) * (width - 1),
2091
+ (1 - (position[1] * 0.5 + 0.5)) * (height - 1),
2092
+ toDepth(position[2])
2093
+ ];
2094
+ }
2095
+
2096
+ function identityMatrix(): readonly number[] {
2097
+ return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
2098
+ }
2099
+
2100
+ function readVertexColor(bytes: Uint8Array, stride: number, offset: number | undefined, vertexIndex: number): readonly [number, number, number, number] {
2101
+ if (offset === undefined) return [1, 1, 1, 1];
2102
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
2103
+ const base = vertexIndex * stride + offset;
2104
+ return [
2105
+ view.getFloat32(base, true),
2106
+ view.getFloat32(base + 4, true),
2107
+ view.getFloat32(base + 8, true),
2108
+ view.getFloat32(base + 12, true)
2109
+ ];
2110
+ }
2111
+
2112
+ function readVertexUv(bytes: Uint8Array, stride: number, offset: number | undefined, vertexIndex: number): readonly [number, number] {
2113
+ if (offset === undefined) return [0, 0];
2114
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
2115
+ const base = vertexIndex * stride + offset;
2116
+ return [view.getFloat32(base, true), view.getFloat32(base + 4, true)];
2117
+ }
2118
+
2119
+ function rasterizeTriangle(
2120
+ target: WebGPURenderTarget,
2121
+ a: readonly [number, number, number],
2122
+ b: readonly [number, number, number],
2123
+ c: readonly [number, number, number],
2124
+ worldA: readonly [number, number, number],
2125
+ worldB: readonly [number, number, number],
2126
+ worldC: readonly [number, number, number],
2127
+ color: readonly [number, number, number, number],
2128
+ colorA: readonly [number, number, number, number],
2129
+ colorB: readonly [number, number, number, number],
2130
+ colorC: readonly [number, number, number, number],
2131
+ uvA: readonly [number, number],
2132
+ uvB: readonly [number, number],
2133
+ uvC: readonly [number, number],
2134
+ texture: TextureBinding | null,
2135
+ shadow: ForwardShadowUniforms | null,
2136
+ depthTest: boolean,
2137
+ depthWrite: boolean
2138
+ ): void {
2139
+ const pa = toPixel(a, target.width, target.height);
2140
+ const pb = toPixel(b, target.width, target.height);
2141
+ const pc = toPixel(c, target.width, target.height);
2142
+ const minX = clampInt(Math.floor(Math.min(pa[0], pb[0], pc[0])), 0, target.width - 1);
2143
+ const maxX = clampInt(Math.ceil(Math.max(pa[0], pb[0], pc[0])), 0, target.width - 1);
2144
+ const minY = clampInt(Math.floor(Math.min(pa[1], pb[1], pc[1])), 0, target.height - 1);
2145
+ const maxY = clampInt(Math.ceil(Math.max(pa[1], pb[1], pc[1])), 0, target.height - 1);
2146
+ const area = edge(pa, pb, pc);
2147
+ if (Math.abs(area) < 1e-6) return;
2148
+ for (let y = minY; y <= maxY; y += 1) {
2149
+ for (let x = minX; x <= maxX; x += 1) {
2150
+ const p = [x + 0.5, y + 0.5] as const;
2151
+ const w0 = edge(pb, pc, p);
2152
+ const w1 = edge(pc, pa, p);
2153
+ const w2 = edge(pa, pb, p);
2154
+ if ((w0 >= 0 && w1 >= 0 && w2 >= 0) || (w0 <= 0 && w1 <= 0 && w2 <= 0)) {
2155
+ const invArea = 1 / area;
2156
+ const wa = w0 * invArea;
2157
+ const wb = w1 * invArea;
2158
+ const wc = w2 * invArea;
2159
+ const uv: readonly [number, number] = [
2160
+ uvA[0] * wa + uvB[0] * wb + uvC[0] * wc,
2161
+ uvA[1] * wa + uvB[1] * wb + uvC[1] * wc
2162
+ ];
2163
+ const worldPosition: readonly [number, number, number] = [
2164
+ worldA[0] * wa + worldB[0] * wb + worldC[0] * wc,
2165
+ worldA[1] * wa + worldB[1] * wb + worldC[1] * wc,
2166
+ worldA[2] * wa + worldB[2] * wb + worldC[2] * wc
2167
+ ];
2168
+ const pixelIndex = y * target.width + x;
2169
+ const depth = pa[2] * wa + pb[2] * wb + pc[2] * wc;
2170
+ if (!passesDepthTest(target, pixelIndex, depth, depthTest, depthWrite)) continue;
2171
+ const shadedColor = multiplyColor(
2172
+ multiplyColor(color, interpolateColor(colorA, colorB, colorC, wa, wb, wc)),
2173
+ texture ? sampleTextureBinding(texture, uv) : [1, 1, 1, 1]
2174
+ );
2175
+ target.colorPixels.set(rgbaBytes(multiplyColor(shadedColor, shadowFactor(shadow, worldPosition))), pixelIndex * 4);
2176
+ }
2177
+ }
2178
+ }
2179
+ }
2180
+
2181
+ function rasterizeLine(
2182
+ target: WebGPURenderTarget,
2183
+ a: readonly [number, number, number],
2184
+ b: readonly [number, number, number],
2185
+ color: readonly [number, number, number, number],
2186
+ colorA: readonly [number, number, number, number],
2187
+ colorB: readonly [number, number, number, number],
2188
+ depthTest: boolean,
2189
+ depthWrite: boolean
2190
+ ): void {
2191
+ const pa = toPixel(a, target.width, target.height);
2192
+ const pb = toPixel(b, target.width, target.height);
2193
+ const x0 = clampInt(Math.round(pa[0]), 0, target.width - 1);
2194
+ const y0 = clampInt(Math.round(pa[1]), 0, target.height - 1);
2195
+ const x1 = clampInt(Math.round(pb[0]), 0, target.width - 1);
2196
+ const y1 = clampInt(Math.round(pb[1]), 0, target.height - 1);
2197
+ const dx = Math.abs(x1 - x0);
2198
+ const dy = Math.abs(y1 - y0);
2199
+ const steps = Math.max(dx, dy, 1);
2200
+ const shadedA = multiplyColor(color, colorA);
2201
+ const shadedB = multiplyColor(color, colorB);
2202
+ for (let step = 0; step <= steps; step += 1) {
2203
+ const t = step / steps;
2204
+ const x = clampInt(Math.round(x0 + (x1 - x0) * t), 0, target.width - 1);
2205
+ const y = clampInt(Math.round(y0 + (y1 - y0) * t), 0, target.height - 1);
2206
+ const pixelIndex = y * target.width + x;
2207
+ const depth = pa[2] + (pb[2] - pa[2]) * t;
2208
+ if (!passesDepthTest(target, pixelIndex, depth, depthTest, depthWrite)) continue;
2209
+ const shaded = lerpColor(shadedA, shadedB, t);
2210
+ target.colorPixels.set(rgbaBytes(shaded), pixelIndex * 4);
2211
+ }
2212
+ }
2213
+
2214
+ function rasterizePoint(
2215
+ target: WebGPURenderTarget,
2216
+ point: readonly [number, number, number],
2217
+ color: readonly [number, number, number, number],
2218
+ depthTest: boolean,
2219
+ depthWrite: boolean
2220
+ ): void {
2221
+ const pixel = toPixel(point, target.width, target.height);
2222
+ const centerX = clampInt(Math.round(pixel[0]), 0, target.width - 1);
2223
+ const centerY = clampInt(Math.round(pixel[1]), 0, target.height - 1);
2224
+ const bytes = rgbaBytes(color);
2225
+ for (let y = centerY - 2; y <= centerY + 2; y += 1) {
2226
+ if (y < 0 || y >= target.height) continue;
2227
+ for (let x = centerX - 2; x <= centerX + 2; x += 1) {
2228
+ if (x < 0 || x >= target.width) continue;
2229
+ const pixelIndex = y * target.width + x;
2230
+ if (!passesDepthTest(target, pixelIndex, pixel[2], depthTest, depthWrite)) continue;
2231
+ target.colorPixels.set(bytes, pixelIndex * 4);
2232
+ }
2233
+ }
2234
+ }
2235
+
2236
+ function sampleTextureBinding(binding: TextureBinding, uv: readonly [number, number]): readonly [number, number, number, number] {
2237
+ const texture = binding.texture;
2238
+ if (!texture || texture.disposed) return [1, 1, 1, 1];
2239
+ const level = texture.textureLevels[0] ?? texture.fallbackTextureLevels[0];
2240
+ if (!level || level.data.length < level.width * level.height * 4) return [1, 1, 1, 1];
2241
+ const transformed = binding.transformUV(uv);
2242
+ const u = addressCoordinate(transformed[0], binding.sampler.addressU);
2243
+ const v = addressCoordinate(transformed[1], binding.sampler.addressV);
2244
+ const x = clampInt(Math.round(u * (level.width - 1)), 0, level.width - 1);
2245
+ const y = clampInt(Math.round(v * (level.height - 1)), 0, level.height - 1);
2246
+ const offset = (y * level.width + x) * 4;
2247
+ const r = (level.data[offset] ?? 255) / 255;
2248
+ const g = (level.data[offset + 1] ?? 255) / 255;
2249
+ const b = (level.data[offset + 2] ?? 255) / 255;
2250
+ return [
2251
+ texture.colorSpace === "srgb" ? srgbToLinear(r) : r,
2252
+ texture.colorSpace === "srgb" ? srgbToLinear(g) : g,
2253
+ texture.colorSpace === "srgb" ? srgbToLinear(b) : b,
2254
+ (level.data[offset + 3] ?? 255) / 255
2255
+ ];
2256
+ }
2257
+
2258
+ function srgbToLinear(value: number): number {
2259
+ return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
2260
+ }
2261
+
2262
+ function shadowFactor(shadow: ForwardShadowUniforms | null, worldPosition: readonly [number, number, number]): readonly [number, number, number, number] {
2263
+ if (!shadow) return [1, 1, 1, 1];
2264
+ const projected = transformPosition(worldPosition, shadow.matrix);
2265
+ if (projected[0] < -1 || projected[0] > 1 || projected[1] < -1 || projected[1] > 1 || projected[2] < -1 || projected[2] > 1) {
2266
+ return [1, 1, 1, 1];
2267
+ }
2268
+ const uv: readonly [number, number] = [projected[0] * 0.5 + 0.5, projected[1] * 0.5 + 0.5];
2269
+ const storedDepth = sampleTextureBinding(shadow.texture, uv)[0];
2270
+ const receiverDepth = projected[2] * 0.5 + 0.5 - shadow.bias;
2271
+ const visibility = receiverDepth > storedDepth ? 1 - shadow.strength : 1;
2272
+ return [visibility, visibility, visibility, 1];
2273
+ }
2274
+
2275
+ function addressCoordinate(value: number, mode: "clamp-to-edge" | "repeat" | "mirror-repeat"): number {
2276
+ if (mode === "repeat") return value - Math.floor(value);
2277
+ if (mode === "mirror-repeat") {
2278
+ const repeated = value - Math.floor(value);
2279
+ return Math.floor(value) % 2 === 0 ? repeated : 1 - repeated;
2280
+ }
2281
+ return Math.min(1, Math.max(0, value));
2282
+ }
2283
+
2284
+ function lerpColor(
2285
+ a: readonly [number, number, number, number],
2286
+ b: readonly [number, number, number, number],
2287
+ t: number
2288
+ ): readonly [number, number, number, number] {
2289
+ return [
2290
+ a[0] + (b[0] - a[0]) * t,
2291
+ a[1] + (b[1] - a[1]) * t,
2292
+ a[2] + (b[2] - a[2]) * t,
2293
+ a[3] + (b[3] - a[3]) * t
2294
+ ];
2295
+ }
2296
+
2297
+ function interpolateColor(
2298
+ a: readonly [number, number, number, number],
2299
+ b: readonly [number, number, number, number],
2300
+ c: readonly [number, number, number, number],
2301
+ wa: number,
2302
+ wb: number,
2303
+ wc: number
2304
+ ): readonly [number, number, number, number] {
2305
+ return [
2306
+ a[0] * wa + b[0] * wb + c[0] * wc,
2307
+ a[1] * wa + b[1] * wb + c[1] * wc,
2308
+ a[2] * wa + b[2] * wb + c[2] * wc,
2309
+ a[3] * wa + b[3] * wb + c[3] * wc
2310
+ ];
2311
+ }
2312
+
2313
+ function multiplyColor(
2314
+ a: readonly [number, number, number, number],
2315
+ b: readonly [number, number, number, number]
2316
+ ): readonly [number, number, number, number] {
2317
+ return [a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3]];
2318
+ }
2319
+
2320
+ function edge(a: readonly number[], b: readonly number[], c: readonly number[]): number {
2321
+ return (c[0] - a[0]) * (b[1] - a[1]) - (c[1] - a[1]) * (b[0] - a[0]);
2322
+ }
2323
+
2324
+ function clampInt(value: number, min: number, max: number): number {
2325
+ return Math.min(max, Math.max(min, value));
2326
+ }
2327
+
2328
+ function createNativeShaderSources(sources: ShaderSources): {
2329
+ readonly vertex: string;
2330
+ readonly fragment: string;
2331
+ readonly entryPoints: readonly [string, string];
2332
+ readonly uniformLayout: NativeUniformLayout;
2333
+ } {
2334
+ const vertexEntry = inferWGSLVertexEntryPoint(sources.vertex) ?? "vs_main";
2335
+ const fragmentEntry = inferWGSLFragmentEntryPoint(sources.fragment) ?? "fs_main";
2336
+ if (/\@(vertex|fragment|compute)\b/.test(sources.vertex) || /\@(vertex|fragment|compute)\b/.test(sources.fragment)) {
2337
+ return { vertex: sources.vertex, fragment: sources.fragment, entryPoints: [vertexEntry, fragmentEntry], uniformLayout: "passthrough" };
2338
+ }
2339
+ if (sources.marker.includes("instanced-pbr")) {
2340
+ return { ...nativeInstancedPbrShader(vertexEntry, fragmentEntry, sources.marker), entryPoints: [vertexEntry, fragmentEntry], uniformLayout: "generated-instanced-pbr" };
2341
+ }
2342
+ if (sources.marker.includes("pbr-textured")) {
2343
+ return { ...nativeTexturedPbrShader(vertexEntry, fragmentEntry, sources.marker, nativeShaderUsesTangent(sources.vertex)), entryPoints: [vertexEntry, fragmentEntry], uniformLayout: "generated-textured-pbr" };
2344
+ }
2345
+ if (sources.marker.includes("pbr-direct")) {
2346
+ return sources.fragment.includes("u_baseColorTexture")
2347
+ ? { ...nativeTexturedPbrShader(vertexEntry, fragmentEntry, sources.marker, nativeShaderUsesTangent(sources.vertex)), entryPoints: [vertexEntry, fragmentEntry], uniformLayout: "generated-textured-pbr" }
2348
+ : { ...nativePbrShader(vertexEntry, fragmentEntry, sources.marker), entryPoints: [vertexEntry, fragmentEntry], uniformLayout: "generated-pbr" };
2349
+ }
2350
+ if (sources.marker.includes("skinned-unlit")) {
2351
+ return { ...nativeSkinnedUnlitShader(vertexEntry, fragmentEntry, sources.marker), entryPoints: [vertexEntry, fragmentEntry], uniformLayout: "generated-skinned-unlit" };
2352
+ }
2353
+ if (sources.marker.includes("morph-unlit")) {
2354
+ return { ...nativeMorphUnlitShader(vertexEntry, fragmentEntry, sources.marker), entryPoints: [vertexEntry, fragmentEntry], uniformLayout: "generated-morph-unlit" };
2355
+ }
2356
+ if (/sampler2D/.test(sources.fragment) && /layout\s*\(\s*location\s*=\s*2\s*\)\s*in\s+vec2/.test(sources.vertex)) {
2357
+ return {
2358
+ vertex: `// ${sources.marker}\nstruct DrawUniforms {\n modelViewProjection: mat4x4<f32>,\n color: vec4<f32>,\n};\n\nstruct VertexOutput {\n @builtin(position) position: vec4<f32>,\n @location(0) uv: vec2<f32>,\n};\n\n@group(0) @binding(0) var<uniform> u_draw: DrawUniforms;\n\n@vertex\nfn ${vertexEntry}(@location(0) position: vec3<f32>, @location(2) uv: vec2<f32>) -> VertexOutput {\n var output: VertexOutput;\n let clipPosition = u_draw.modelViewProjection * vec4<f32>(position, 1.0);
2359
+ output.position = vec4<f32>(clipPosition.x, clipPosition.y, clipPosition.z * 0.5 + clipPosition.w * 0.5, clipPosition.w);\n output.uv = uv;\n return output;\n}\n`,
2360
+ fragment: `// ${sources.marker}\nstruct DrawUniforms {\n modelViewProjection: mat4x4<f32>,\n color: vec4<f32>,\n};\n\nstruct VertexOutput {\n @builtin(position) position: vec4<f32>,\n @location(0) uv: vec2<f32>,\n};\n\n@group(0) @binding(0) var<uniform> u_draw: DrawUniforms;\n@group(0) @binding(1) var u_textureSampler: sampler;\n@group(0) @binding(2) var u_texture: texture_2d<f32>;\n\n@fragment\nfn ${fragmentEntry}(input: VertexOutput) -> @location(0) vec4<f32> {\n return u_draw.color * textureSample(u_texture, u_textureSampler, input.uv);\n}\n`,
2361
+ entryPoints: [vertexEntry, fragmentEntry],
2362
+ uniformLayout: "generated-texture"
2363
+ };
2364
+ }
2365
+ return {
2366
+ vertex: `// ${sources.marker}\nstruct DrawUniforms {\n modelViewProjection: mat4x4<f32>,\n color: vec4<f32>,\n};\n\nstruct VertexOutput {\n @builtin(position) position: vec4<f32>,\n};\n\n@group(0) @binding(0) var<uniform> u_draw: DrawUniforms;\n\n@vertex\nfn ${vertexEntry}(@location(0) position: vec3<f32>) -> VertexOutput {\n var output: VertexOutput;\n let clipPosition = u_draw.modelViewProjection * vec4<f32>(position, 1.0);
2367
+ output.position = vec4<f32>(clipPosition.x, clipPosition.y, clipPosition.z * 0.5 + clipPosition.w * 0.5, clipPosition.w);\n return output;\n}\n`,
2368
+ fragment: `// ${sources.marker}\nstruct DrawUniforms {\n modelViewProjection: mat4x4<f32>,\n color: vec4<f32>,\n};\n\n@group(0) @binding(0) var<uniform> u_draw: DrawUniforms;\n\n@fragment\nfn ${fragmentEntry}() -> @location(0) vec4<f32> {\n return u_draw.color;\n}\n`,
2369
+ entryPoints: [vertexEntry, fragmentEntry],
2370
+ uniformLayout: "generated-basic"
2371
+ };
2372
+ }
2373
+
2374
+ function nativeUniformStruct(): string {
2375
+ return `struct DrawUniforms {
2376
+ modelViewProjection: mat4x4<f32>,
2377
+ color: vec4<f32>,
2378
+ params: vec4<f32>,
2379
+ flags: vec4<f32>,
2380
+ reserved0: vec4<f32>,
2381
+ instance0: mat4x4<f32>,
2382
+ instance1: mat4x4<f32>,
2383
+ instance2: mat4x4<f32>,
2384
+ instance3: mat4x4<f32>,
2385
+ joint0: mat4x4<f32>,
2386
+ joint1: mat4x4<f32>,
2387
+ morph0: vec4<f32>,
2388
+ morph1: vec4<f32>,
2389
+ morph2: vec4<f32>,
2390
+ morph3: vec4<f32>,
2391
+ morph4: vec4<f32>,
2392
+ morph5: vec4<f32>,
2393
+ morph6: vec4<f32>,
2394
+ morph7: vec4<f32>,
2395
+ material: vec4<f32>,
2396
+ camera: vec4<f32>,
2397
+ materialFlags: vec4<f32>,
2398
+ normalMatrix: mat4x4<f32>,
2399
+ };
2400
+
2401
+ @group(0) @binding(0) var<uniform> u_draw: DrawUniforms;
2402
+
2403
+ fn a3dWebGPUClipPosition(clipPosition: vec4<f32>) -> vec4<f32> {
2404
+ return vec4<f32>(clipPosition.x, clipPosition.y, clipPosition.z * 0.5 + clipPosition.w * 0.5, clipPosition.w);
2405
+ }
2406
+ `;
2407
+ }
2408
+
2409
+ function nativeShaderUsesTangent(vertexSource: string): boolean {
2410
+ return /\ba_tangent\b/.test(vertexSource) || /layout\s*\(\s*location\s*=\s*3\s*\)\s*in\s+vec4/.test(vertexSource);
2411
+ }
2412
+
2413
+ function nativePbrFragmentPrelude(marker: string): string {
2414
+ return `// ${marker}
2415
+ ${nativeUniformStruct()}
2416
+ @group(0) @binding(1) var u_baseSampler: sampler;
2417
+ @group(0) @binding(2) var u_baseTexture: texture_2d<f32>;
2418
+ @group(0) @binding(3) var u_environmentSampler: sampler;
2419
+ @group(0) @binding(4) var u_environmentTexture: texture_2d<f32>;
2420
+ @group(0) @binding(5) var u_brdfSampler: sampler;
2421
+ @group(0) @binding(6) var u_brdfTexture: texture_2d<f32>;
2422
+ @group(0) @binding(7) var u_shadowSampler: sampler;
2423
+ @group(0) @binding(8) var u_shadowTexture: texture_2d<f32>;
2424
+ @group(0) @binding(9) var u_normalSampler: sampler;
2425
+ @group(0) @binding(10) var u_normalTexture: texture_2d<f32>;
2426
+ @group(0) @binding(11) var u_metallicRoughnessSampler: sampler;
2427
+ @group(0) @binding(12) var u_metallicRoughnessTexture: texture_2d<f32>;
2428
+ @group(0) @binding(13) var u_occlusionSampler: sampler;
2429
+ @group(0) @binding(14) var u_occlusionTexture: texture_2d<f32>;
2430
+
2431
+ struct VertexOutput {
2432
+ @builtin(position) position: vec4<f32>,
2433
+ @location(0) normal: vec3<f32>,
2434
+ @location(1) uv: vec2<f32>,
2435
+ @location(2) worldPosition: vec3<f32>,
2436
+ @location(3) tangent: vec4<f32>,
2437
+ };
2438
+
2439
+ fn fresnelSchlick(cosTheta: f32, f0: vec3<f32>) -> vec3<f32> {
2440
+ return f0 + (vec3<f32>(1.0, 1.0, 1.0) - f0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
2441
+ }
2442
+
2443
+ fn fresnelSchlickRoughness(cosTheta: f32, f0: vec3<f32>, roughness: f32) -> vec3<f32> {
2444
+ let smoothness = 1.0 - clamp(roughness, 0.0, 1.0);
2445
+ return f0 + (max(vec3<f32>(smoothness, smoothness, smoothness), f0) - f0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
2446
+ }
2447
+
2448
+ fn ggxDistribution(nDotH: f32, roughness: f32) -> f32 {
2449
+ let a = max(roughness * roughness, 0.045);
2450
+ let a2 = a * a;
2451
+ let denom = max((nDotH * nDotH) * (a2 - 1.0) + 1.0, 0.001);
2452
+ return a2 / max(3.14159265 * denom * denom, 0.001);
2453
+ }
2454
+
2455
+ fn ggxVisibilitySmithCorrelated(nDotV: f32, nDotL: f32, roughness: f32) -> f32 {
2456
+ let a = max(roughness * roughness, 0.045);
2457
+ let a2 = a * a;
2458
+ let lambdaV = nDotL * sqrt(max((nDotV - a2 * nDotV) * nDotV + a2, 0.00001));
2459
+ let lambdaL = nDotV * sqrt(max((nDotL - a2 * nDotL) * nDotL + a2, 0.00001));
2460
+ return 0.5 / max(lambdaV + lambdaL, 0.00001);
2461
+ }
2462
+
2463
+ fn diffuseBurley(nDotV: f32, nDotL: f32, lDotH: f32, roughness: f32) -> f32 {
2464
+ let energyBias = mix(0.0, 0.5, roughness);
2465
+ let energyFactor = mix(1.0, 1.0 / 1.51, roughness);
2466
+ let fd90 = energyBias + 2.0 * lDotH * lDotH * roughness;
2467
+ let lightScatter = 1.0 + (fd90 - 1.0) * pow(clamp(1.0 - nDotL, 0.0, 1.0), 5.0);
2468
+ let viewScatter = 1.0 + (fd90 - 1.0) * pow(clamp(1.0 - nDotV, 0.0, 1.0), 5.0);
2469
+ return lightScatter * viewScatter * energyFactor;
2470
+ }
2471
+
2472
+ fn encodePbrOutput(linearColor: vec3<f32>) -> vec3<f32> {
2473
+ let color = max(linearColor, vec3<f32>(0.0, 0.0, 0.0));
2474
+ let filmic = clamp((color * (2.51 * color + vec3<f32>(0.03, 0.03, 0.03))) / (color * (2.43 * color + vec3<f32>(0.59, 0.59, 0.59)) + vec3<f32>(0.14, 0.14, 0.14)), vec3<f32>(0.0, 0.0, 0.0), vec3<f32>(1.0, 1.0, 1.0));
2475
+ return pow(filmic, vec3<f32>(1.0 / 2.2, 1.0 / 2.2, 1.0 / 2.2));
2476
+ }
2477
+
2478
+ fn productPropBodyGate(baseColor: vec3<f32>, strength: f32) -> f32 {
2479
+ let maxChannel = max(max(baseColor.r, baseColor.g), baseColor.b);
2480
+ let minChannel = min(min(baseColor.r, baseColor.g), baseColor.b);
2481
+ let normalized = baseColor / max(maxChannel, 0.001);
2482
+ let warm = clamp(strength, 0.0, 1.0)
2483
+ * smoothstep(0.18, 0.42, maxChannel)
2484
+ * smoothstep(0.04, 0.2, maxChannel - minChannel)
2485
+ * smoothstep(0.64, 0.84, normalized.r)
2486
+ * (1.0 - smoothstep(0.12, 0.32, normalized.b));
2487
+ return warm * smoothstep(0.46, 0.64, normalized.g) * (1.0 - smoothstep(0.74, 0.94, normalized.b));
2488
+ }
2489
+
2490
+ fn productPropOrangeGate(baseColor: vec3<f32>, strength: f32) -> f32 {
2491
+ let maxChannel = max(max(baseColor.r, baseColor.g), baseColor.b);
2492
+ let minChannel = min(min(baseColor.r, baseColor.g), baseColor.b);
2493
+ let normalized = baseColor / max(maxChannel, 0.001);
2494
+ let warm = clamp(strength, 0.0, 1.0)
2495
+ * smoothstep(0.32, 0.58, maxChannel)
2496
+ * smoothstep(0.05, 0.24, maxChannel - minChannel)
2497
+ * smoothstep(0.68, 0.88, normalized.r)
2498
+ * (1.0 - smoothstep(0.1, 0.28, normalized.b));
2499
+ return warm * (1.0 - smoothstep(0.34, 0.58, normalized.g)) * smoothstep(0.012, 0.08, baseColor.g);
2500
+ }
2501
+
2502
+ fn productPropAlbedo(baseColor: vec3<f32>, strength: f32) -> vec3<f32> {
2503
+ let orangeGate = productPropOrangeGate(baseColor, strength);
2504
+ let bodyGate = productPropBodyGate(baseColor, strength) * (1.0 - orangeGate * 0.92);
2505
+ let maxChannel = max(max(baseColor.r, baseColor.g), baseColor.b);
2506
+ let bodyLuma = mix(0.98, 1.03, smoothstep(0.24, 0.9, maxChannel));
2507
+ let beakLuma = mix(0.94, 1.02, smoothstep(0.2, 0.82, maxChannel));
2508
+ var color = mix(baseColor, vec3<f32>(1.0, 0.88, 0.012) * bodyLuma, clamp(bodyGate * 0.995, 0.0, 0.995));
2509
+ color = mix(color, vec3<f32>(1.0, 0.24, 0.018) * beakLuma, clamp(orangeGate * 0.99, 0.0, 0.99));
2510
+ return color;
2511
+ }
2512
+
2513
+ fn perturbNormal(normalInput: vec3<f32>, tangentFrame: vec4<f32>, normalSample: vec3<f32>, normalScale: f32) -> vec3<f32> {
2514
+ let n = normalize(normalInput);
2515
+ let tangent = normalize(tangentFrame.xyz);
2516
+ let bitangent = normalize(cross(n, tangent) * tangentFrame.w);
2517
+ let mapped = vec3<f32>((normalSample.xy * 2.0 - vec2<f32>(1.0, 1.0)) * max(normalScale, 0.0), normalSample.z * 2.0 - 1.0);
2518
+ return normalize(tangent * mapped.x + bitangent * mapped.y + n * max(mapped.z, 0.001));
2519
+ }
2520
+
2521
+ fn shadePbr(normalInput: vec3<f32>, tangentFrame: vec4<f32>, uv: vec2<f32>, worldPosition: vec3<f32>) -> vec4<f32> {
2522
+ var normal = normalize(normalInput);
2523
+ if (u_draw.morph0.x > 0.5) {
2524
+ normal = perturbNormal(normal, tangentFrame, textureSample(u_normalTexture, u_normalSampler, uv).rgb, u_draw.morph0.y);
2525
+ }
2526
+ let viewDirection = normalize(u_draw.camera.xyz - worldPosition);
2527
+ let lightDirection = normalize(vec3<f32>(0.36, 0.52, 0.78));
2528
+ let halfVector = normalize(lightDirection + viewDirection);
2529
+ var baseColor = u_draw.color.rgb;
2530
+ var materialAlpha = u_draw.color.a;
2531
+ if (u_draw.flags.x > 0.5) {
2532
+ let baseSample = textureSample(u_baseTexture, u_baseSampler, uv);
2533
+ baseColor = baseColor * baseSample.rgb;
2534
+ materialAlpha = materialAlpha * baseSample.a;
2535
+ }
2536
+ let sourceProductBaseColor = baseColor;
2537
+ let productOrangeGate = productPropOrangeGate(sourceProductBaseColor, u_draw.materialFlags.z);
2538
+ let productBodyGate = productPropBodyGate(sourceProductBaseColor, u_draw.materialFlags.z) * (1.0 - productOrangeGate * 0.92);
2539
+ let productSurfaceGate = clamp(productBodyGate + productOrangeGate * 0.72, 0.0, 1.0);
2540
+ baseColor = productPropAlbedo(sourceProductBaseColor, u_draw.materialFlags.z);
2541
+ if (materialAlpha < u_draw.material.x) {
2542
+ discard;
2543
+ }
2544
+ let transmission = clamp(max(u_draw.material.y, u_draw.material.z), 0.0, 1.0);
2545
+ let metallicRoughnessSample = textureSample(u_metallicRoughnessTexture, u_metallicRoughnessSampler, uv);
2546
+ let metallicRoughnessEnabled = step(0.5, u_draw.materialFlags.x);
2547
+ let occlusionEnabled = step(0.5, u_draw.materialFlags.y);
2548
+ let sampledMetallic = clamp(u_draw.params.x * metallicRoughnessSample.b, 0.0, 1.0);
2549
+ let sampledRoughness = clamp(u_draw.params.y * metallicRoughnessSample.g, 0.045, 1.0);
2550
+ let sampledOcclusion = mix(1.0, textureSample(u_occlusionTexture, u_occlusionSampler, uv).r, clamp(u_draw.morph0.z, 0.0, 1.0));
2551
+ let metallic = mix(clamp(u_draw.params.x, 0.0, 1.0), sampledMetallic, metallicRoughnessEnabled);
2552
+ let roughness = mix(clamp(u_draw.params.y, 0.045, 1.0), sampledRoughness, metallicRoughnessEnabled);
2553
+ let occlusion = mix(1.0, sampledOcclusion, occlusionEnabled);
2554
+ let smoothedProductNormal = normalize(vec3<f32>(normal.x * 0.42, max(normal.y, 0.28), normal.z * 0.42));
2555
+ normal = normalize(mix(normal, smoothedProductNormal, productBodyGate * 0.46 + productOrangeGate * 0.84));
2556
+ let nDotL = max(dot(normal, lightDirection), 0.0);
2557
+ let nDotV = max(dot(normal, viewDirection), 0.001);
2558
+ let nDotH = max(dot(normal, halfVector), 0.001);
2559
+ let vDotH = max(dot(viewDirection, halfVector), 0.001);
2560
+ let f0 = mix(vec3<f32>(0.04, 0.04, 0.04), baseColor, metallic);
2561
+ let fresnel = fresnelSchlick(vDotH, f0);
2562
+ let distribution = ggxDistribution(nDotH, roughness);
2563
+ let visibility = ggxVisibilitySmithCorrelated(nDotV, nDotL, roughness);
2564
+ let lDotH = max(dot(lightDirection, halfVector), 0.0);
2565
+ let kd = (vec3<f32>(1.0, 1.0, 1.0) - fresnel) * (1.0 - metallic);
2566
+ let specular = fresnel * distribution * visibility;
2567
+ let diffuse = kd * baseColor * diffuseBurley(nDotV, nDotL, lDotH, roughness) / 3.14159265;
2568
+ var environment = baseColor * u_draw.params.z * (0.28 + 0.72 * clamp(normal.y * 0.5 + 0.5, 0.0, 1.0)) * occlusion;
2569
+ var environmentSpecularContribution = vec3<f32>(0.0, 0.0, 0.0);
2570
+ if (u_draw.flags.w > 0.5) {
2571
+ let reflectionDirection = reflect(-viewDirection, normal);
2572
+ let diffuseUv = vec2<f32>(fract(atan2(normal.z, normal.x) / 6.2831853 + 0.5), acos(clamp(normal.y, -1.0, 1.0)) / 3.14159265);
2573
+ let specularUv = vec2<f32>(fract(atan2(reflectionDirection.z, reflectionDirection.x) / 6.2831853 + 0.5), acos(clamp(reflectionDirection.y, -1.0, 1.0)) / 3.14159265);
2574
+ let environmentMipCount = max(u_draw.reserved0.z, 1.0);
2575
+ let diffuseEnv = textureSampleLevel(u_environmentTexture, u_environmentSampler, diffuseUv, max(environmentMipCount - 1.0, 0.0)).rgb;
2576
+ let specularEnv = textureSampleLevel(u_environmentTexture, u_environmentSampler, specularUv, roughness * max(environmentMipCount - 1.0, 0.0)).rgb;
2577
+ let brdf = textureSampleLevel(u_brdfTexture, u_brdfSampler, vec2<f32>(nDotV, roughness), 0.0).rg;
2578
+ let environmentFresnel = fresnelSchlickRoughness(nDotV, f0, roughness);
2579
+ let environmentDiffuse = (vec3<f32>(1.0, 1.0, 1.0) - environmentFresnel) * (1.0 - metallic) * diffuseEnv * baseColor * u_draw.params.w * occlusion;
2580
+ let environmentSpecular = specularEnv * (f0 * brdf.x + vec3<f32>(brdf.y, brdf.y, brdf.y)) * max(u_draw.reserved0.w, 0.0);
2581
+ environmentSpecularContribution = environmentSpecular;
2582
+ environment = environment + environmentDiffuse + environmentSpecular;
2583
+ }
2584
+ var shadow = 1.0;
2585
+ if (u_draw.flags.y > 0.5) {
2586
+ let shadowDepth = textureSampleLevel(u_shadowTexture, u_shadowSampler, vec2<f32>(0.5, 0.5), 0.0).r;
2587
+ shadow = mix(1.0, shadowDepth, clamp(u_draw.flags.z, 0.0, 1.0));
2588
+ }
2589
+ let litOpaqueLinearColor = environment + (diffuse + specular) * nDotL * 2.25 * shadow;
2590
+ let smoothedBodyColor = mix(baseColor, vec3<f32>(1.0, 0.88, 0.012), productBodyGate * 0.32);
2591
+ let smoothedBeakColor = mix(baseColor, vec3<f32>(1.0, 0.24, 0.018), productOrangeGate * 0.82);
2592
+ let softBodyProduct = smoothedBodyColor * (1.5 + 0.06 * nDotL) + specular * nDotL * 0.018;
2593
+ let softBeakProduct = smoothedBeakColor * (1.08 + 0.05 * nDotL) + specular * nDotL * 0.018;
2594
+ var opaqueLinearColor = mix(litOpaqueLinearColor, softBodyProduct, productBodyGate * 0.78);
2595
+ opaqueLinearColor = mix(opaqueLinearColor, softBeakProduct, productOrangeGate * 0.95);
2596
+ let transmittedTint = baseColor * u_draw.params.w * (0.18 + 0.42 * clamp(1.0 - roughness, 0.0, 1.0)) + environmentSpecularContribution * 1.35;
2597
+ let linearColor = mix(opaqueLinearColor, opaqueLinearColor * 0.22 + transmittedTint, transmission);
2598
+ let outputAlpha = mix(materialAlpha, min(materialAlpha, 0.22), transmission);
2599
+ return vec4<f32>(encodePbrOutput(linearColor), outputAlpha);
2600
+ }
2601
+ `;
2602
+ }
2603
+
2604
+ function nativePbrShader(vertexEntry: string, fragmentEntry: string, marker: string): { readonly vertex: string; readonly fragment: string } {
2605
+ return {
2606
+ vertex: `// ${marker}
2607
+ ${nativeUniformStruct()}
2608
+ struct VertexOutput {
2609
+ @builtin(position) position: vec4<f32>,
2610
+ @location(0) normal: vec3<f32>,
2611
+ @location(1) uv: vec2<f32>,
2612
+ @location(2) worldPosition: vec3<f32>,
2613
+ @location(3) tangent: vec4<f32>,
2614
+ };
2615
+
2616
+ @vertex
2617
+ fn ${vertexEntry}(@location(0) position: vec3<f32>, @location(1) normal: vec3<f32>) -> VertexOutput {
2618
+ var output: VertexOutput;
2619
+ let worldPosition = (u_draw.instance0 * vec4<f32>(position, 1.0)).xyz;
2620
+ output.position = a3dWebGPUClipPosition(u_draw.modelViewProjection * vec4<f32>(position, 1.0));
2621
+ output.normal = normalize((u_draw.normalMatrix * vec4<f32>(normal, 0.0)).xyz);
2622
+ output.uv = vec2<f32>(0.5, 0.5);
2623
+ output.worldPosition = worldPosition;
2624
+ output.tangent = vec4<f32>(1.0, 0.0, 0.0, 1.0);
2625
+ return output;
2626
+ }
2627
+ `,
2628
+ fragment: `${nativePbrFragmentPrelude(marker)}
2629
+ @fragment
2630
+ fn ${fragmentEntry}(input: VertexOutput) -> @location(0) vec4<f32> {
2631
+ return shadePbr(input.normal, input.tangent, input.uv, input.worldPosition);
2632
+ }
2633
+ `
2634
+ };
2635
+ }
2636
+
2637
+ function nativeTexturedPbrShader(vertexEntry: string, fragmentEntry: string, marker: string, usesTangent: boolean): { readonly vertex: string; readonly fragment: string } {
2638
+ return {
2639
+ vertex: `// ${marker}
2640
+ ${nativeUniformStruct()}
2641
+ struct VertexOutput {
2642
+ @builtin(position) position: vec4<f32>,
2643
+ @location(0) normal: vec3<f32>,
2644
+ @location(1) uv: vec2<f32>,
2645
+ @location(2) worldPosition: vec3<f32>,
2646
+ @location(3) tangent: vec4<f32>,
2647
+ };
2648
+
2649
+ @vertex
2650
+ fn ${vertexEntry}(@location(0) position: vec3<f32>, @location(1) normal: vec3<f32>, @location(2) uv: vec2<f32>${usesTangent ? ", @location(3) tangent: vec4<f32>" : ""}) -> VertexOutput {
2651
+ var output: VertexOutput;
2652
+ let worldPosition = (u_draw.instance0 * vec4<f32>(position, 1.0)).xyz;
2653
+ output.position = a3dWebGPUClipPosition(u_draw.modelViewProjection * vec4<f32>(position, 1.0));
2654
+ output.normal = normalize((u_draw.normalMatrix * vec4<f32>(normal, 0.0)).xyz);
2655
+ output.uv = uv;
2656
+ output.worldPosition = worldPosition;
2657
+ ${usesTangent ? "output.tangent = vec4<f32>(normalize((u_draw.normalMatrix * vec4<f32>(tangent.xyz, 0.0)).xyz), tangent.w);" : "output.tangent = vec4<f32>(1.0, 0.0, 0.0, 1.0);"}
2658
+ return output;
2659
+ }
2660
+ `,
2661
+ fragment: `${nativePbrFragmentPrelude(marker)}
2662
+ @fragment
2663
+ fn ${fragmentEntry}(input: VertexOutput) -> @location(0) vec4<f32> {
2664
+ return shadePbr(input.normal, input.tangent, input.uv, input.worldPosition);
2665
+ }
2666
+ `
2667
+ };
2668
+ }
2669
+
2670
+ function nativeInstancedPbrShader(vertexEntry: string, fragmentEntry: string, marker: string): { readonly vertex: string; readonly fragment: string } {
2671
+ return {
2672
+ vertex: `// ${marker}
2673
+ ${nativeUniformStruct()}
2674
+ struct VertexOutput {
2675
+ @builtin(position) position: vec4<f32>,
2676
+ @location(0) normal: vec3<f32>,
2677
+ @location(1) uv: vec2<f32>,
2678
+ @location(2) worldPosition: vec3<f32>,
2679
+ @location(3) tangent: vec4<f32>,
2680
+ };
2681
+
2682
+ fn instanceMatrix(index: u32) -> mat4x4<f32> {
2683
+ if (index == 1u) { return u_draw.instance1; }
2684
+ if (index == 2u) { return u_draw.instance2; }
2685
+ if (index == 3u) { return u_draw.instance3; }
2686
+ return u_draw.instance0;
2687
+ }
2688
+
2689
+ @vertex
2690
+ fn ${vertexEntry}(@location(0) position: vec3<f32>, @location(1) normal: vec3<f32>, @builtin(instance_index) instanceIndex: u32) -> VertexOutput {
2691
+ var output: VertexOutput;
2692
+ let model = instanceMatrix(instanceIndex);
2693
+ let worldPosition = (model * vec4<f32>(position, 1.0)).xyz;
2694
+ output.position = a3dWebGPUClipPosition(u_draw.modelViewProjection * model * vec4<f32>(position, 1.0));
2695
+ output.normal = normalize((model * vec4<f32>(normal, 0.0)).xyz);
2696
+ output.uv = vec2<f32>(0.5, 0.5);
2697
+ output.worldPosition = worldPosition;
2698
+ output.tangent = vec4<f32>(1.0, 0.0, 0.0, 1.0);
2699
+ return output;
2700
+ }
2701
+ `,
2702
+ fragment: `${nativePbrFragmentPrelude(marker)}
2703
+ @fragment
2704
+ fn ${fragmentEntry}(input: VertexOutput) -> @location(0) vec4<f32> {
2705
+ return shadePbr(input.normal, input.tangent, input.uv, input.worldPosition);
2706
+ }
2707
+ `
2708
+ };
2709
+ }
2710
+
2711
+ function nativeSkinnedUnlitShader(vertexEntry: string, fragmentEntry: string, marker: string): { readonly vertex: string; readonly fragment: string } {
2712
+ return {
2713
+ vertex: `// ${marker}
2714
+ ${nativeUniformStruct()}
2715
+ struct VertexOutput {
2716
+ @builtin(position) position: vec4<f32>,
2717
+ };
2718
+
2719
+ fn jointMatrix(index: f32) -> mat4x4<f32> {
2720
+ if (index > 0.5) { return u_draw.joint1; }
2721
+ return u_draw.joint0;
2722
+ }
2723
+
2724
+ @vertex
2725
+ fn ${vertexEntry}(@location(0) position: vec3<f32>, @location(5) joints: vec4<f32>, @location(6) weights: vec4<f32>) -> VertexOutput {
2726
+ var output: VertexOutput;
2727
+ let skin = jointMatrix(joints.x) * weights.x + jointMatrix(joints.y) * weights.y + jointMatrix(joints.z) * weights.z + jointMatrix(joints.w) * weights.w;
2728
+ let weightSum = weights.x + weights.y + weights.z + weights.w;
2729
+ let skinned = select(vec4<f32>(position, 1.0), skin * vec4<f32>(position, 1.0), weightSum > 0.0001);
2730
+ output.position = a3dWebGPUClipPosition(u_draw.modelViewProjection * skinned);
2731
+ return output;
2732
+ }
2733
+ `,
2734
+ fragment: `// ${marker}
2735
+ ${nativeUniformStruct()}
2736
+ @fragment
2737
+ fn ${fragmentEntry}() -> @location(0) vec4<f32> {
2738
+ return u_draw.color;
2739
+ }
2740
+ `
2741
+ };
2742
+ }
2743
+
2744
+ function nativeMorphUnlitShader(vertexEntry: string, fragmentEntry: string, marker: string): { readonly vertex: string; readonly fragment: string } {
2745
+ return {
2746
+ vertex: `// ${marker}
2747
+ ${nativeUniformStruct()}
2748
+ struct VertexOutput {
2749
+ @builtin(position) position: vec4<f32>,
2750
+ };
2751
+
2752
+ fn morphDelta(index: u32) -> vec3<f32> {
2753
+ if (index == 0u) { return u_draw.morph0.xyz; }
2754
+ if (index == 1u) { return u_draw.morph1.xyz; }
2755
+ if (index == 2u) { return u_draw.morph2.xyz; }
2756
+ if (index == 3u) { return u_draw.morph3.xyz; }
2757
+ if (index == 4u) { return u_draw.morph4.xyz; }
2758
+ if (index == 5u) { return u_draw.morph5.xyz; }
2759
+ if (index == 6u) { return u_draw.morph6.xyz; }
2760
+ return u_draw.morph7.xyz;
2761
+ }
2762
+
2763
+ @vertex
2764
+ fn ${vertexEntry}(@location(0) position: vec3<f32>, @builtin(vertex_index) vertexIndex: u32) -> VertexOutput {
2765
+ var output: VertexOutput;
2766
+ let enabled = min(u_draw.reserved0.y, 1.0);
2767
+ let morphed = position + morphDelta(min(vertexIndex, 7u)) * u_draw.reserved0.x * enabled;
2768
+ output.position = a3dWebGPUClipPosition(u_draw.modelViewProjection * vec4<f32>(morphed, 1.0));
2769
+ return output;
2770
+ }
2771
+ `,
2772
+ fragment: `// ${marker}
2773
+ ${nativeUniformStruct()}
2774
+ @fragment
2775
+ fn ${fragmentEntry}() -> @location(0) vec4<f32> {
2776
+ return u_draw.color;
2777
+ }
2778
+ `
2779
+ };
2780
+ }
2781
+
2782
+ function inferWGSLVertexEntryPoint(source: string): string | undefined {
2783
+ return /@vertex\s+fn\s+([A-Za-z_]\w*)/.exec(source)?.[1];
2784
+ }
2785
+
2786
+ function inferWGSLFragmentEntryPoint(source: string): string | undefined {
2787
+ return /@fragment\s+fn\s+([A-Za-z_]\w*)/.exec(source)?.[1];
2788
+ }
2789
+
2790
+ function vertexBufferLayout(format: VertexFormat): WebGPUVertexBufferLayoutLike {
2791
+ return {
2792
+ arrayStride: format.stride,
2793
+ attributes: format.attributes.map((attribute) => ({
2794
+ shaderLocation: attribute.shaderLocation,
2795
+ offset: attribute.offset,
2796
+ format: vertexAttributeFormat(attribute.components)
2797
+ }))
2798
+ };
2799
+ }
2800
+
2801
+ function vertexAttributeFormat(components: 1 | 2 | 3 | 4): WebGPUVertexAttributeLike["format"] {
2802
+ if (components === 1) return "float32";
2803
+ if (components === 2) return "float32x2";
2804
+ if (components === 3) return "float32x3";
2805
+ return "float32x4";
2806
+ }