@nova-lab/core 1.0.0-dev.19 → 1.1.0-dev.229

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 (501) hide show
  1. package/README.md +1035 -10
  2. package/THIRD_PARTY_NOTICES.md +26 -0
  3. package/dist/2d/accessibility.d.ts +2 -0
  4. package/dist/2d/accessibility.js +171 -0
  5. package/dist/2d/commands.d.ts +2 -0
  6. package/dist/2d/commands.js +80 -0
  7. package/dist/2d/effects.d.ts +10 -0
  8. package/dist/2d/effects.js +566 -0
  9. package/dist/2d/ktx2.d.ts +5 -0
  10. package/dist/2d/ktx2.js +542 -0
  11. package/dist/2d/lighting.d.ts +3 -0
  12. package/dist/2d/lighting.js +495 -0
  13. package/dist/2d/lottie.d.ts +3 -0
  14. package/dist/2d/lottie.js +254 -0
  15. package/dist/2d/meshes.d.ts +4 -0
  16. package/dist/2d/meshes.js +451 -0
  17. package/dist/2d/primitives.d.ts +3 -0
  18. package/dist/2d/primitives.js +85 -0
  19. package/dist/2d/render-textures.d.ts +3 -0
  20. package/dist/2d/render-textures.js +539 -0
  21. package/dist/2d/svg/documents.d.ts +5 -0
  22. package/dist/2d/svg/documents.js +7 -0
  23. package/dist/2d/svg/renderer.d.ts +3 -0
  24. package/dist/2d/svg/renderer.js +222 -0
  25. package/dist/2d/svg.d.ts +3 -0
  26. package/dist/2d/svg.js +4 -0
  27. package/dist/2d/tools.d.ts +2 -0
  28. package/dist/2d/tools.js +100 -0
  29. package/dist/2d/video.d.ts +5 -0
  30. package/dist/2d/video.js +90 -0
  31. package/dist/2d.d.ts +2 -0
  32. package/dist/2d.js +220 -0
  33. package/dist/3d/animation.d.ts +8 -0
  34. package/dist/3d/animation.js +1396 -0
  35. package/dist/3d/area-lights.d.ts +2 -0
  36. package/dist/3d/area-lights.js +19 -0
  37. package/dist/3d/audio.d.ts +4 -0
  38. package/dist/3d/audio.js +500 -0
  39. package/dist/3d/character.d.ts +2 -0
  40. package/dist/3d/character.js +136 -0
  41. package/dist/3d/collision.d.ts +3 -0
  42. package/dist/3d/collision.js +387 -0
  43. package/dist/3d/commands.d.ts +2 -0
  44. package/dist/3d/commands.js +108 -0
  45. package/dist/3d/controls.d.ts +8 -0
  46. package/dist/3d/controls.js +1041 -0
  47. package/dist/3d/documents.d.ts +5 -0
  48. package/dist/3d/documents.js +227 -0
  49. package/dist/3d/effects.d.ts +5 -0
  50. package/dist/3d/effects.js +1986 -0
  51. package/dist/3d/export.d.ts +4 -0
  52. package/dist/3d/export.js +347 -0
  53. package/dist/3d/fbx.d.ts +2 -0
  54. package/dist/3d/fbx.js +784 -0
  55. package/dist/3d/gltf.d.ts +2 -0
  56. package/dist/3d/gltf.js +5 -0
  57. package/dist/3d/helpers.d.ts +5 -0
  58. package/dist/3d/helpers.js +191 -0
  59. package/dist/3d/ik.d.ts +9 -0
  60. package/dist/3d/ik.js +777 -0
  61. package/dist/3d/loaders.d.ts +17 -0
  62. package/dist/3d/loaders.js +1406 -0
  63. package/dist/3d/nodes.d.ts +8 -0
  64. package/dist/3d/nodes.js +49 -0
  65. package/dist/3d/particles.d.ts +5 -0
  66. package/dist/3d/particles.js +1574 -0
  67. package/dist/3d/physics/backend.d.ts +7 -0
  68. package/dist/3d/physics/backend.js +1 -0
  69. package/dist/3d/physics/rapier.d.ts +3 -0
  70. package/dist/3d/physics/rapier.js +765 -0
  71. package/dist/3d/physics.d.ts +5 -0
  72. package/dist/3d/physics.js +3346 -0
  73. package/dist/3d/splats.d.ts +7 -0
  74. package/dist/3d/splats.js +862 -0
  75. package/dist/3d/text.d.ts +5 -0
  76. package/dist/3d/text.js +1043 -0
  77. package/dist/3d/tiles.d.ts +24 -0
  78. package/dist/3d/tiles.js +1705 -0
  79. package/dist/3d/tools.d.ts +12 -0
  80. package/dist/3d/tools.js +338 -0
  81. package/dist/3d/usdz.d.ts +2 -0
  82. package/dist/3d/usdz.js +634 -0
  83. package/dist/3d/xr.d.ts +2 -0
  84. package/dist/3d/xr.js +202 -0
  85. package/dist/3d-B4jWF8Qb.js +5591 -0
  86. package/dist/3d.d.ts +40 -0
  87. package/dist/3d.js +44 -0
  88. package/dist/Capsule-BFVpZfvc.js +44 -0
  89. package/dist/Clip-CAN7t03k.js +204 -0
  90. package/dist/Color-vuv9UnoY.js +34 -0
  91. package/dist/DeformedMesh-CPi0P_vc.js +280 -0
  92. package/dist/Document-DCVEZSvM.js +415 -0
  93. package/dist/Errors-B2ekO9bZ.js +30 -0
  94. package/dist/Features-BsjmePtc.js +557 -0
  95. package/dist/GLTFResourceIO-CYJyCUTt.js +124 -0
  96. package/dist/GPUParticleState-CQlNpoDa.js +545 -0
  97. package/dist/Geometry-DytO490z.js +227 -0
  98. package/dist/Inflate-DWw0V-Up.js +42 -0
  99. package/dist/InstancedMesh-DPrgrw5z.js +527 -0
  100. package/dist/Limits-Bw5XQdFr.js +20 -0
  101. package/dist/LineHelper-Ad0z9uDi.js +131 -0
  102. package/dist/LoaderIO-BwrM84OM.js +114 -0
  103. package/dist/Material-BpfLPmK9.js +777 -0
  104. package/dist/Mesh-BaRxAAJq.js +209 -0
  105. package/dist/Node-QfgAE2_v.js +877 -0
  106. package/dist/NovaAssetRegistry-p2QlCwvT.js +1168 -0
  107. package/dist/NovaNode-CBZ-Ol-W.js +2016 -0
  108. package/dist/NovaRenderCommandWriter-CWQRa42y.js +1949 -0
  109. package/dist/NovaTextSelectionService-CipuujCT.js +18526 -0
  110. package/dist/NovaWebGLProgram-BO250QNF.js +97 -0
  111. package/dist/Options-CajE7LLJ.js +15 -0
  112. package/dist/PolygonMesh-D4PnnfIo.js +657 -0
  113. package/dist/Ready-BzyhRtjD.js +21 -0
  114. package/dist/Scene-CDfNgf9I.js +911 -0
  115. package/dist/Shader-b6_HDndT.js +48 -0
  116. package/dist/SplatShader-wJ6GJ3vo.js +130 -0
  117. package/dist/Texture-dTKMlTpK.js +267 -0
  118. package/dist/TextureLoader-CfDzdy2m.js +411 -0
  119. package/dist/Textures-CGL4Kf-8.js +651 -0
  120. package/dist/ToneMapping-D9IWvN0u.js +46 -0
  121. package/dist/WebGPURenderer-DjD0IxVC.js +4921 -0
  122. package/dist/ZipReader-C-MSEsSr.js +84 -0
  123. package/dist/core.js +218 -24024
  124. package/dist/domain/types/base.types.d.ts +18 -9
  125. package/dist/domain/types/component.types.d.ts +5 -5
  126. package/dist/domain/types/cursor.types.d.ts +1 -1
  127. package/dist/domain/types/diagnostics.types.d.ts +2 -0
  128. package/dist/domain/types/export.types.d.ts +2 -2
  129. package/dist/domain/types/hit-test.types.d.ts +1 -1
  130. package/dist/domain/types/motion.types.d.ts +2 -2
  131. package/dist/domain/types/renderer.types.d.ts +88 -4
  132. package/dist/domain/types/rendering/index.d.ts +29 -4
  133. package/dist/domain/types/sound.types.d.ts +1 -1
  134. package/dist/domain/types/theme.types.d.ts +1 -1
  135. package/dist/domain/utils/bounds.d.ts +1 -1
  136. package/dist/domain/utils/nova-text.d.ts +9 -0
  137. package/dist/domain/utils/schemaBounds.d.ts +2 -2
  138. package/dist/export-svg-document-ChaNXMaG.js +668 -0
  139. package/dist/features/3d/Errors.d.ts +57 -0
  140. package/dist/features/3d/Nova3DApp.d.ts +429 -0
  141. package/dist/features/3d/animation/Animator.d.ts +260 -0
  142. package/dist/features/3d/animation/Clip.d.ts +74 -0
  143. package/dist/features/3d/animation/Graph.d.ts +158 -0
  144. package/dist/features/3d/animation/Mask.d.ts +40 -0
  145. package/dist/features/3d/audio/Audio.d.ts +114 -0
  146. package/dist/features/3d/audio/Sound.d.ts +133 -0
  147. package/dist/features/3d/character/CharacterController.d.ts +61 -0
  148. package/dist/features/3d/collision/Capsule.d.ts +25 -0
  149. package/dist/features/3d/collision/Octree.d.ts +94 -0
  150. package/dist/features/3d/controls/CameraMotionControls.d.ts +154 -0
  151. package/dist/features/3d/controls/CameraOrientation.d.ts +47 -0
  152. package/dist/features/3d/controls/OrbitControls.d.ts +73 -0
  153. package/dist/features/3d/controls/PointerGesture.d.ts +25 -0
  154. package/dist/features/3d/controls/PointerLock.d.ts +36 -0
  155. package/dist/features/3d/controls/Snapping.d.ts +32 -0
  156. package/dist/features/3d/controls/TransformGizmo.d.ts +79 -0
  157. package/dist/features/3d/deformation/DeformationGPU.d.ts +52 -0
  158. package/dist/features/3d/deformation/DeformationShader.d.ts +2 -0
  159. package/dist/features/3d/deformation/DeformedMesh.d.ts +36 -0
  160. package/dist/features/3d/deformation/GeometryDeformation.d.ts +25 -0
  161. package/dist/features/3d/documents/Document.d.ts +59 -0
  162. package/dist/features/3d/documents/DocumentCommands.d.ts +45 -0
  163. package/dist/features/3d/documents/DocumentSchema.d.ts +18 -0
  164. package/dist/features/3d/documents/DocumentTransform.d.ts +4 -0
  165. package/dist/features/3d/documents/DocumentTypes.d.ts +182 -0
  166. package/dist/features/3d/documents/DocumentValidation.d.ts +18 -0
  167. package/dist/features/3d/documents/Projection.d.ts +65 -0
  168. package/dist/features/3d/effects/CubeLUT.d.ts +24 -0
  169. package/dist/features/3d/effects/Effects.d.ts +32 -0
  170. package/dist/features/3d/effects/EffectsGPU.d.ts +80 -0
  171. package/dist/features/3d/effects/EffectsPlan.d.ts +268 -0
  172. package/dist/features/3d/effects/EffectsShaders.d.ts +35 -0
  173. package/dist/features/3d/export/GLTFExporter.d.ts +49 -0
  174. package/dist/features/3d/export/ThreeMFExporter.d.ts +19 -0
  175. package/dist/features/3d/export/ZipWriter.d.ts +9 -0
  176. package/dist/features/3d/fbx/FBXLoader.d.ts +26 -0
  177. package/dist/features/3d/fbx/FBXParser.d.ts +35 -0
  178. package/dist/features/3d/fbx/FBXScene.d.ts +20 -0
  179. package/dist/features/3d/gltf/GLTFLoader.d.ts +16 -0
  180. package/dist/features/3d/gltf/GLTFTypes.d.ts +64 -0
  181. package/dist/features/3d/gltf/services/GLTFBinary.d.ts +21 -0
  182. package/dist/features/3d/gltf/services/GLTFGeometry.d.ts +14 -0
  183. package/dist/features/3d/gltf/services/GLTFResourceIO.d.ts +64 -0
  184. package/dist/features/3d/helpers/LineHelper.d.ts +51 -0
  185. package/dist/features/3d/helpers/StaticHelpers.d.ts +47 -0
  186. package/dist/features/3d/helpers/TrackedHelpers.d.ts +84 -0
  187. package/dist/features/3d/ik/ChainIK.d.ts +44 -0
  188. package/dist/features/3d/ik/IKChain.d.ts +92 -0
  189. package/dist/features/3d/ik/IKMath.d.ts +49 -0
  190. package/dist/features/3d/ik/IKSolver.d.ts +97 -0
  191. package/dist/features/3d/ik/LookAtIK.d.ts +58 -0
  192. package/dist/features/3d/ik/TwoBoneIK.d.ts +57 -0
  193. package/dist/features/3d/import/ImportAnimation.d.ts +20 -0
  194. package/dist/features/3d/import/ImportMath.d.ts +42 -0
  195. package/dist/features/3d/import/ImportedModel.d.ts +135 -0
  196. package/dist/features/3d/import/Inflate.d.ts +5 -0
  197. package/dist/features/3d/import/ModelAsset.d.ts +149 -0
  198. package/dist/features/3d/import/PolygonMesh.d.ts +54 -0
  199. package/dist/features/3d/lights/AreaLightTables.d.ts +8 -0
  200. package/dist/features/3d/lights/AreaLights.d.ts +11 -0
  201. package/dist/features/3d/loaders/EXRCompression.d.ts +13 -0
  202. package/dist/features/3d/loaders/EXRLoader.d.ts +39 -0
  203. package/dist/features/3d/loaders/HDRLoader.d.ts +26 -0
  204. package/dist/features/3d/loaders/Limits.d.ts +70 -0
  205. package/dist/features/3d/loaders/LoaderBuffers.d.ts +42 -0
  206. package/dist/features/3d/loaders/LoaderIO.d.ts +81 -0
  207. package/dist/features/3d/loaders/LoaderModel.d.ts +80 -0
  208. package/dist/features/3d/loaders/LoaderText.d.ts +27 -0
  209. package/dist/features/3d/loaders/MTLLoader.d.ts +105 -0
  210. package/dist/features/3d/loaders/OBJLoader.d.ts +70 -0
  211. package/dist/features/3d/loaders/PLYLoader.d.ts +47 -0
  212. package/dist/features/3d/loaders/STLLoader.d.ts +27 -0
  213. package/dist/features/3d/model/Camera.d.ts +33 -0
  214. package/dist/features/3d/model/Environment.d.ts +31 -0
  215. package/dist/features/3d/model/Geometry.d.ts +59 -0
  216. package/dist/features/3d/model/InstancedMesh.d.ts +134 -0
  217. package/dist/features/3d/model/LOD.d.ts +31 -0
  218. package/dist/features/3d/model/Light.d.ts +200 -0
  219. package/dist/features/3d/model/Material.d.ts +308 -0
  220. package/dist/features/3d/model/MaterialExtensions.d.ts +200 -0
  221. package/dist/features/3d/model/Mesh.d.ts +92 -0
  222. package/dist/features/3d/model/Node.d.ts +87 -0
  223. package/dist/features/3d/model/ReflectionProbe.d.ts +45 -0
  224. package/dist/features/3d/model/RenderTarget.d.ts +41 -0
  225. package/dist/features/3d/model/Scene.d.ts +173 -0
  226. package/dist/features/3d/model/Texture.d.ts +143 -0
  227. package/dist/features/3d/nodes/Nodes.d.ts +8 -0
  228. package/dist/features/3d/nodes/ShaderNode.d.ts +240 -0
  229. package/dist/features/3d/particles/GPUParticleSchedule.d.ts +67 -0
  230. package/dist/features/3d/particles/GPUParticleShaders.d.ts +19 -0
  231. package/dist/features/3d/particles/GPUParticleState.d.ts +106 -0
  232. package/dist/features/3d/particles/GPUParticleSystem.d.ts +192 -0
  233. package/dist/features/3d/particles/ParticleCurves.d.ts +34 -0
  234. package/dist/features/3d/particles/ParticleOptions.d.ts +78 -0
  235. package/dist/features/3d/particles/ParticleSystem.d.ts +368 -0
  236. package/dist/features/3d/physics/PhysicsBackend.d.ts +352 -0
  237. package/dist/features/3d/physics/PhysicsDebug.d.ts +24 -0
  238. package/dist/features/3d/physics/PhysicsWorld.d.ts +352 -0
  239. package/dist/features/3d/physics/basic/BasicCollision.d.ts +75 -0
  240. package/dist/features/3d/physics/basic/BasicPhysics.d.ts +24 -0
  241. package/dist/features/3d/physics/basic/BasicShapes.d.ts +103 -0
  242. package/dist/features/3d/physics/rapier/ContactBuffer.d.ts +32 -0
  243. package/dist/features/3d/physics/rapier/RapierBackend.d.ts +17 -0
  244. package/dist/features/3d/physics/rapier/RapierShapes.d.ts +4 -0
  245. package/dist/features/3d/physics/rapier/RapierWorld.d.ts +198 -0
  246. package/dist/features/3d/physics/rapier/Validation.d.ts +8 -0
  247. package/dist/features/3d/services/Background.d.ts +22 -0
  248. package/dist/features/3d/services/BasicShader.d.ts +55 -0
  249. package/dist/features/3d/services/ClusteredLights.d.ts +69 -0
  250. package/dist/features/3d/services/DrawOrder.d.ts +37 -0
  251. package/dist/features/3d/services/EffectsProcessor.d.ts +38 -0
  252. package/dist/features/3d/services/EnvironmentBRDF.d.ts +35 -0
  253. package/dist/features/3d/services/EnvironmentMaps.d.ts +55 -0
  254. package/dist/features/3d/services/FogShader.d.ts +6 -0
  255. package/dist/features/3d/services/Frustum.d.ts +7 -0
  256. package/dist/features/3d/services/GLState.d.ts +86 -0
  257. package/dist/features/3d/services/GPUPicker.d.ts +31 -0
  258. package/dist/features/3d/services/InstanceShader.d.ts +3 -0
  259. package/dist/features/3d/services/LineProgram.d.ts +32 -0
  260. package/dist/features/3d/services/PBRProgram.d.ts +115 -0
  261. package/dist/features/3d/services/Renderer.d.ts +50 -0
  262. package/dist/features/3d/services/Shader.d.ts +22 -0
  263. package/dist/features/3d/services/ShaderProgram.d.ts +38 -0
  264. package/dist/features/3d/services/ShadowMaps.d.ts +97 -0
  265. package/dist/features/3d/services/SpatialIndex.d.ts +16 -0
  266. package/dist/features/3d/services/TextureLoader.d.ts +40 -0
  267. package/dist/features/3d/services/TextureMipmaps.d.ts +42 -0
  268. package/dist/features/3d/services/ToneMapping.d.ts +12 -0
  269. package/dist/features/3d/services/WebGLRenderer.d.ts +261 -0
  270. package/dist/features/3d/splats/SplatData.d.ts +136 -0
  271. package/dist/features/3d/splats/SplatLoaders.d.ts +64 -0
  272. package/dist/features/3d/splats/SplatShader.d.ts +14 -0
  273. package/dist/features/3d/splats/SplatSort.d.ts +69 -0
  274. package/dist/features/3d/splats/Splats.d.ts +116 -0
  275. package/dist/features/3d/text/FontAtlas.d.ts +246 -0
  276. package/dist/features/3d/text/SDF.d.ts +28 -0
  277. package/dist/features/3d/text/Text.d.ts +179 -0
  278. package/dist/features/3d/text/TextLayout.d.ts +73 -0
  279. package/dist/features/3d/text/TextShader.d.ts +12 -0
  280. package/dist/features/3d/tiles/BoundingVolume.d.ts +43 -0
  281. package/dist/features/3d/tiles/Geodesy.d.ts +106 -0
  282. package/dist/features/3d/tiles/GlobeControls.d.ts +147 -0
  283. package/dist/features/3d/tiles/TileContent.d.ts +35 -0
  284. package/dist/features/3d/tiles/TileFormats.d.ts +77 -0
  285. package/dist/features/3d/tiles/Tiles3D.d.ts +236 -0
  286. package/dist/features/3d/tiles/Tileset.d.ts +81 -0
  287. package/dist/features/3d/tools/BatchedMesh.d.ts +74 -0
  288. package/dist/features/3d/tools/CanvasSurface.d.ts +81 -0
  289. package/dist/features/3d/tools/Color.d.ts +11 -0
  290. package/dist/features/3d/tools/MergeGeometries.d.ts +22 -0
  291. package/dist/features/3d/tools/Options.d.ts +15 -0
  292. package/dist/features/3d/tools/Polyhedra.d.ts +30 -0
  293. package/dist/features/3d/tools/PrimitiveBuffers.d.ts +42 -0
  294. package/dist/features/3d/tools/Primitives.d.ts +164 -0
  295. package/dist/features/3d/tools/Ready.d.ts +12 -0
  296. package/dist/features/3d/tools/SpatialMath.d.ts +57 -0
  297. package/dist/features/3d/tools/SphericalHarmonics.d.ts +9 -0
  298. package/dist/features/3d/tools/math/mat3.d.ts +7 -0
  299. package/dist/features/3d/tools/math/mat4.d.ts +19 -0
  300. package/dist/features/3d/tools/math/quat.d.ts +6 -0
  301. package/dist/features/3d/tools/math/vec3.d.ts +16 -0
  302. package/dist/features/3d/tools/math/vec4.d.ts +5 -0
  303. package/dist/features/3d/types.d.ts +359 -0
  304. package/dist/features/3d/usdz/USDAParser.d.ts +50 -0
  305. package/dist/features/3d/usdz/USDScene.d.ts +20 -0
  306. package/dist/features/3d/usdz/USDZLoader.d.ts +27 -0
  307. package/dist/features/3d/usdz/ZipReader.d.ts +16 -0
  308. package/dist/features/3d/webgpu/Backend.d.ts +40 -0
  309. package/dist/features/3d/webgpu/BasicShader.d.ts +10 -0
  310. package/dist/features/3d/webgpu/Constants.d.ts +32 -0
  311. package/dist/features/3d/webgpu/Deformation.d.ts +71 -0
  312. package/dist/features/3d/webgpu/Environment.d.ts +66 -0
  313. package/dist/features/3d/webgpu/Features.d.ts +68 -0
  314. package/dist/features/3d/webgpu/Layouts.d.ts +27 -0
  315. package/dist/features/3d/webgpu/Lines.d.ts +40 -0
  316. package/dist/features/3d/webgpu/LitExtras.d.ts +46 -0
  317. package/dist/features/3d/webgpu/LitFeatures.d.ts +41 -0
  318. package/dist/features/3d/webgpu/LitScene.d.ts +60 -0
  319. package/dist/features/3d/webgpu/LitShader.d.ts +68 -0
  320. package/dist/features/3d/webgpu/Particles.d.ts +114 -0
  321. package/dist/features/3d/webgpu/Picking.d.ts +59 -0
  322. package/dist/features/3d/webgpu/PipelineKey.d.ts +33 -0
  323. package/dist/features/3d/webgpu/Points.d.ts +41 -0
  324. package/dist/features/3d/webgpu/Probes.d.ts +45 -0
  325. package/dist/features/3d/webgpu/ShaderChunks.d.ts +18 -0
  326. package/dist/features/3d/webgpu/ShaderMaterial.d.ts +57 -0
  327. package/dist/features/3d/webgpu/ShaderMaterialSource.d.ts +5 -0
  328. package/dist/features/3d/webgpu/Shadows.d.ts +49 -0
  329. package/dist/features/3d/webgpu/Splats.d.ts +47 -0
  330. package/dist/features/3d/webgpu/Textures.d.ts +52 -0
  331. package/dist/features/3d/webgpu/Transmission.d.ts +30 -0
  332. package/dist/features/3d/webgpu/UniformLayout.d.ts +30 -0
  333. package/dist/features/3d/webgpu/UtilityShaders.d.ts +38 -0
  334. package/dist/features/3d/webgpu/WebGPURenderer.d.ts +327 -0
  335. package/dist/features/3d/webgpu/effects/EffectsShaders.d.ts +74 -0
  336. package/dist/features/3d/webgpu/effects/WebGPUEffects.d.ts +140 -0
  337. package/dist/features/3d/xr/XR.d.ts +100 -0
  338. package/dist/gltf-By-n0qEg.js +960 -0
  339. package/dist/index.d.ts +86 -81
  340. package/dist/model/document-actions/document-commands.d.ts +18 -0
  341. package/dist/model/documents/svg/create-svg-document-renderer.d.ts +32 -0
  342. package/dist/model/documents/svg/export-svg-document.d.ts +5 -0
  343. package/dist/model/documents/svg/import-svg-document.d.ts +6 -0
  344. package/dist/model/documents/svg/svg-document.types.d.ts +111 -0
  345. package/dist/model/documents/svg/svg-values.d.ts +16 -0
  346. package/dist/model/documents/svg/svg-xml.d.ts +18 -0
  347. package/dist/model/input/NovaInputProxy_Adapter.d.ts +2 -1
  348. package/dist/model/input/NovaInputValidationController.d.ts +1 -1
  349. package/dist/model/input/NovaTextInputController.d.ts +1 -1
  350. package/dist/model/input/NovaTextLayoutEngine.d.ts +2 -6
  351. package/dist/model/input/index.d.ts +7 -7
  352. package/dist/model/input/nova-input.types.d.ts +1 -1
  353. package/dist/model/lighting/LightingRenderer2D.d.ts +58 -0
  354. package/dist/model/lighting/NovaLighting2D.d.ts +56 -0
  355. package/dist/model/lighting/lighting-shaders.d.ts +3 -0
  356. package/dist/model/lighting/lighting-state.d.ts +27 -0
  357. package/dist/model/lighting/lighting.types.d.ts +107 -0
  358. package/dist/model/lottie/LottieNode.d.ts +4 -0
  359. package/dist/model/lottie/lottie.types.d.ts +83 -0
  360. package/dist/model/lottie/prepare-lottie.d.ts +3 -0
  361. package/dist/model/lottie/sample-position.d.ts +9 -0
  362. package/dist/model/motion/NovaMotionEngine.d.ts +3 -3
  363. package/dist/model/motion/nova-motion-easing.d.ts +1 -1
  364. package/dist/model/motion/nova-motion-interpolation.d.ts +1 -1
  365. package/dist/model/motion/nova-motion-presets.d.ts +2 -2
  366. package/dist/model/motion/nova-motion-timeline.d.ts +1 -1
  367. package/dist/model/platform/NovaCanvas.d.ts +7 -6
  368. package/dist/model/primitives/NovaPrimitiveUnsupportedError.d.ts +13 -0
  369. package/dist/model/primitives/definePrimitive.d.ts +5 -0
  370. package/dist/model/primitives/primitive.types.d.ts +28 -0
  371. package/dist/model/render/backends/canvas2d/NovaCanvas2DTargetManager.d.ts +3 -3
  372. package/dist/model/render/backends/canvas2d/NovaRenderer2D.d.ts +61 -15
  373. package/dist/model/render/backends/canvas2d/nova-canvas-blend.d.ts +5 -0
  374. package/dist/model/render/backends/nova-render-backend-factory.d.ts +6 -6
  375. package/dist/model/render/backends/nova-render-backend.d.ts +8 -2
  376. package/dist/model/render/backends/webgl/NovaRendererWebGL.d.ts +32 -11
  377. package/dist/model/render/backends/webgl/NovaStreamCacheIdleLedger.d.ts +12 -1
  378. package/dist/model/render/backends/webgl/NovaWebGLBatcher.d.ts +1 -1
  379. package/dist/model/render/backends/webgl/NovaWebGLCircleImagePass.d.ts +23 -0
  380. package/dist/model/render/backends/webgl/NovaWebGLCompositionPass.d.ts +9 -0
  381. package/dist/model/render/backends/webgl/NovaWebGLDevice.d.ts +3 -1
  382. package/dist/model/render/backends/webgl/NovaWebGLDiagnostics.d.ts +1 -1
  383. package/dist/model/render/backends/webgl/NovaWebGLFrameRenderer.d.ts +162 -53
  384. package/dist/model/render/backends/webgl/NovaWebGLPathClipPass.d.ts +13 -0
  385. package/dist/model/render/backends/webgl/NovaWebGLPathUnion.d.ts +23 -0
  386. package/dist/model/render/compiler/NovaRenderBuilder.d.ts +24 -10
  387. package/dist/model/render/compiler/NovaRenderCommandWriter.d.ts +10 -5
  388. package/dist/model/render/compiler/NovaRenderCompiler.d.ts +7 -6
  389. package/dist/model/render/compiler/NovaRenderFrameBuilder.d.ts +4 -3
  390. package/dist/model/render/effects/blur.d.ts +8 -0
  391. package/dist/model/render/effects/color-matrix.d.ts +8 -0
  392. package/dist/model/render/effects/drop-shadow.d.ts +18 -0
  393. package/dist/model/render/effects/nova-effect-registry.d.ts +66 -0
  394. package/dist/model/render/effects/nova-gaussian-kernel.d.ts +7 -0
  395. package/dist/model/render/effects/nova-gaussian-textures.d.ts +11 -0
  396. package/dist/model/render/effects/shader-effect.d.ts +64 -0
  397. package/dist/model/render/geometry/nova-alpha-mask.d.ts +5 -0
  398. package/dist/model/render/geometry/nova-composition.d.ts +9 -0
  399. package/dist/model/render/geometry/nova-node-clip.d.ts +17 -0
  400. package/dist/model/render/geometry/nova-path-geometry.d.ts +24 -0
  401. package/dist/model/render/geometry/nova-path-tessellation.d.ts +7 -0
  402. package/dist/model/render/geometry/nova-polygon-triangulation.d.ts +1 -1
  403. package/dist/model/render/graph/NovaRectBatchBuffer.d.ts +58 -0
  404. package/dist/model/render/graph/NovaRenderGraph.d.ts +40 -6
  405. package/dist/model/render/graph/NovaRenderHitIndex.d.ts +1 -1
  406. package/dist/model/render/graph/nova-auto-rect.d.ts +1 -1
  407. package/dist/model/render/graph/nova-linear-rect-repack.d.ts +4 -4
  408. package/dist/model/render/graph/nova-linear-rect-transition.d.ts +2 -2
  409. package/dist/model/render/graph/nova-render-culling.d.ts +2 -2
  410. package/dist/model/render/graph/nova-render-dirty-items.d.ts +1 -1
  411. package/dist/model/render/graph/nova-render-group.d.ts +1 -1
  412. package/dist/model/render/graph/nova-render-item.d.ts +2 -2
  413. package/dist/model/render/graph/nova-render-layer.d.ts +1 -1
  414. package/dist/model/render/graph/nova-render-payload-snapshot.d.ts +3 -1
  415. package/dist/model/render/graph/nova-render-program.d.ts +5 -3
  416. package/dist/model/render/graph/nova-render-sequence.d.ts +1 -1
  417. package/dist/model/render/graph/nova-render-stream.d.ts +2 -2
  418. package/dist/model/render/ktx2/BasisSession.d.ts +45 -0
  419. package/dist/model/render/ktx2/KTX2Container.d.ts +26 -0
  420. package/dist/model/render/ktx2/KTX2Loader.d.ts +55 -0
  421. package/dist/model/render/meshes/MeshNode.d.ts +13 -0
  422. package/dist/model/render/meshes/NovaMeshWebGLDevice.d.ts +27 -0
  423. package/dist/model/render/meshes/geometry.d.ts +7 -0
  424. package/dist/model/render/meshes/mesh.d.ts +3 -0
  425. package/dist/model/render/meshes/mesh.types.d.ts +116 -0
  426. package/dist/model/render/meshes/nova-mesh-registry.d.ts +55 -0
  427. package/dist/model/render/orchestration/NovaRenderOrchestrator.d.ts +25 -3
  428. package/dist/model/render/policy/nova-render-policy.d.ts +1 -1
  429. package/dist/model/render/resources/NovaGlyphAtlasManager.d.ts +2 -2
  430. package/dist/model/render/resources/NovaTextAtlasManager.d.ts +3 -3
  431. package/dist/model/render/resources/NovaTextLayoutEngine.d.ts +1 -1
  432. package/dist/model/render/resources/nova-bitmap-upload.d.ts +10 -0
  433. package/dist/model/render/schema/NovaRenderContext.d.ts +6 -4
  434. package/dist/model/render/schema/nova-style-compiler.d.ts +5 -2
  435. package/dist/model/render/targets/NovaNodeRenderTextureSource.d.ts +29 -0
  436. package/dist/model/render/targets/NovaRenderTargetManager.d.ts +1 -1
  437. package/dist/model/render/targets/NovaRenderTexture.d.ts +57 -0
  438. package/dist/model/render/targets/nova-render-target-refs.d.ts +5 -0
  439. package/dist/model/render/targets/nova-render-target-resource.d.ts +1 -1
  440. package/dist/model/render/targets/nova-render-texture-runtime.d.ts +71 -0
  441. package/dist/model/render/textures/nova-compressed-image.d.ts +20 -0
  442. package/dist/model/render/utils/nova-icon-rendering.d.ts +3 -1
  443. package/dist/model/render/utils/nova-image-geometry.d.ts +11 -0
  444. package/dist/model/render/utils/nova-markdown-layout.d.ts +19 -0
  445. package/dist/model/render/utils/nova-text-paint.d.ts +26 -0
  446. package/dist/model/render/utils/nova-wrapped-text-layout.d.ts +19 -0
  447. package/dist/model/runtime/app/Nova.d.ts +35 -35
  448. package/dist/model/runtime/app/NovaApp.d.ts +58 -30
  449. package/dist/model/runtime/app/NovaRaphRuntime.d.ts +2 -2
  450. package/dist/model/runtime/app/createNovaRaphRuntime.d.ts +3 -3
  451. package/dist/model/runtime/assets/NovaAssetRegistry.d.ts +89 -2
  452. package/dist/model/runtime/assets/NovaVideoTexture.d.ts +38 -0
  453. package/dist/model/runtime/assets/nova-render-texture-image-identity.d.ts +4 -0
  454. package/dist/model/runtime/commands/NovaCommandBus.d.ts +1 -1
  455. package/dist/model/runtime/components/NovaComponentNode.d.ts +6 -6
  456. package/dist/model/runtime/components/NovaComponentRegistry.d.ts +1 -1
  457. package/dist/model/runtime/components/NovaSchemaRegistry.d.ts +7 -6
  458. package/dist/model/runtime/components/nova-component-metadata.d.ts +1 -1
  459. package/dist/model/runtime/components/nova-component.decorator.d.ts +2 -2
  460. package/dist/model/runtime/components/nova-defined-component.d.ts +3 -3
  461. package/dist/model/runtime/context/nova-context.d.ts +1 -1
  462. package/dist/model/runtime/cursor/NovaCursorManager.d.ts +3 -3
  463. package/dist/model/runtime/diagnostics/NovaDiagnostics_Module.d.ts +3 -3
  464. package/dist/model/runtime/interaction/NovaEvents.d.ts +16 -6
  465. package/dist/model/runtime/interaction/NovaHitIndex.d.ts +1 -1
  466. package/dist/model/runtime/interaction/NovaSpatialIndex.d.ts +2 -2
  467. package/dist/model/runtime/scene/NovaScene.d.ts +3 -3
  468. package/dist/model/runtime/scene/nova-scene-components.d.ts +6 -6
  469. package/dist/model/runtime/state/nova-store-decorators.d.ts +1 -1
  470. package/dist/model/runtime/state/nova-store-runtime.d.ts +1 -1
  471. package/dist/model/runtime/state/nova-store-tracking.d.ts +7 -3
  472. package/dist/model/runtime/sync/NovaSyncScope.d.ts +11 -2
  473. package/dist/model/runtime/sync/nova-sync-context.d.ts +2 -2
  474. package/dist/model/runtime/sync/nova-sync-ports.d.ts +2 -2
  475. package/dist/model/runtime/sync/nova-sync.types.d.ts +15 -3
  476. package/dist/model/runtime/template/NovaTemplateRuntime.d.ts +6 -6
  477. package/dist/model/runtime/tree/NovaContainer.d.ts +4 -4
  478. package/dist/model/runtime/tree/NovaNode.d.ts +58 -18
  479. package/dist/model/runtime/tree/NovaRaphNode.d.ts +8 -2
  480. package/dist/model/runtime/tree/NovaSurface.d.ts +32 -10
  481. package/dist/model/runtime/tree/nova-node-capture-invalidation.d.ts +11 -0
  482. package/dist/model/semantic/NovaSemanticService.d.ts +1 -1
  483. package/dist/model/semantic/browser/createAccessibilityBridge.d.ts +29 -0
  484. package/dist/model/sound/NovaSoundEngine.d.ts +3 -2
  485. package/dist/model/text-selection/NovaTextSelectionService.d.ts +2 -2
  486. package/dist/model/text-selection/index.d.ts +2 -2
  487. package/dist/model/text-selection/nova-text-selection.types.d.ts +1 -1
  488. package/dist/model/theme/NovaGlobalThemeRegistry.d.ts +2 -2
  489. package/dist/model/theme/NovaThemeService.d.ts +5 -3
  490. package/dist/model/theme/createTokenTheme.d.ts +15 -0
  491. package/dist/model/tools/transform-tools.d.ts +43 -0
  492. package/dist/nodes--Ds4IS2h.js +621 -0
  493. package/dist/nova-color-parser-BCN_rFRN.js +250 -0
  494. package/dist/nova-compressed-image-CE2Ya9Xa.js +46 -0
  495. package/dist/nova-mesh-registry-B7Xz5mhU.js +24 -0
  496. package/dist/nova-render-texture-image-identity-DQ09XFKs.js +15 -0
  497. package/dist/nova-text-paint-CcntsRjI.js +48 -0
  498. package/dist/tokens.d.ts +2 -0
  499. package/dist/tokens.js +50 -0
  500. package/dist/vec4-BTNv1fUp.js +20 -0
  501. package/package.json +223 -4
@@ -0,0 +1,1986 @@
1
+ import { N as d } from "../Errors-B2ekO9bZ.js";
2
+ import { N as se } from "../Mesh-BaRxAAJq.js";
3
+ import { a as re, p as oe, b as ne } from "../Color-vuv9UnoY.js";
4
+ import { N as ee } from "../InstancedMesh-DPrgrw5z.js";
5
+ import { b as M, E as R, r as $ } from "../Node-QfgAE2_v.js";
6
+ import { t as te, o as ae, S as E, T as k, h as ce, B as U } from "../Textures-CGL4Kf-8.js";
7
+ import { i as le, c as ue } from "../Features-BsjmePtc.js";
8
+ import { l as fe } from "../Shader-b6_HDndT.js";
9
+ import { t as he } from "../ToneMapping-D9IWvN0u.js";
10
+ function F(c, e) {
11
+ if (c.length !== 3)
12
+ throw new d("format", `[Nova3D] .cube line ${e} needs three numbers.`);
13
+ const t = c.map(Number);
14
+ if (!t.every(Number.isFinite))
15
+ throw new d("format", `[Nova3D] .cube line ${e} has a non-numeric value.`);
16
+ return t;
17
+ }
18
+ async function vt(c) {
19
+ if (typeof c != "string")
20
+ throw new d("invalid-option", "[Nova3D] parseCubeLUT expects text.");
21
+ let e = "", t = 0, s = [0, 0, 0], r = [1, 1, 1], i, o = 0;
22
+ const n = c.split(/\r?\n/);
23
+ for (let l = 0; l < n.length; l++) {
24
+ const f = n[l].trim();
25
+ if (f === "" || f.startsWith("#"))
26
+ continue;
27
+ const h = f.split(/\s+/), v = h[0];
28
+ if (/^[A-Z_]/.test(v)) {
29
+ if (i && o > 0)
30
+ throw new d("format", `[Nova3D] .cube keyword ${v} after table data.`);
31
+ if (v === "TITLE")
32
+ e = f.slice(5).trim().replace(/^"(.*)"$/, "$1");
33
+ else if (v === "LUT_3D_SIZE") {
34
+ if (t = Number(h[1]), !Number.isInteger(t) || t < 2 || t > 256 || h.length !== 2)
35
+ throw new d("format", "[Nova3D] .cube LUT_3D_SIZE must be an integer in [2, 256].");
36
+ i = new Float32Array(t * t * t * 4);
37
+ } else if (v === "DOMAIN_MIN")
38
+ s = F(h.slice(1), l + 1);
39
+ else if (v === "DOMAIN_MAX")
40
+ r = F(h.slice(1), l + 1);
41
+ else {
42
+ if (v === "LUT_1D_SIZE" || v === "LUT_1D_INPUT_RANGE")
43
+ throw new d("unsupported", "[Nova3D] 1D .cube tables are not supported.");
44
+ if (v === "LUT_3D_INPUT_RANGE") {
45
+ const m = F([...h.slice(1), "0"].slice(0, 3), l + 1);
46
+ s = [m[0], m[0], m[0]], r = [m[1], m[1], m[1]];
47
+ }
48
+ }
49
+ continue;
50
+ }
51
+ if (!i)
52
+ throw new d("format", "[Nova3D] .cube table data before LUT_3D_SIZE.");
53
+ if (o >= t * t * t)
54
+ throw new d("format", "[Nova3D] .cube table has more rows than LUT_3D_SIZE³.");
55
+ const _ = F(h, l + 1), p = o * 4;
56
+ i[p] = Math.min(65504, Math.max(0, _[0])), i[p + 1] = Math.min(65504, Math.max(0, _[1])), i[p + 2] = Math.min(65504, Math.max(0, _[2])), i[p + 3] = 1, o++;
57
+ }
58
+ if (!i || o !== t * t * t)
59
+ throw new d("format", `[Nova3D] .cube table needs LUT_3D_SIZE³ rows (${o} found).`);
60
+ if (r.some((l, f) => l <= s[f]))
61
+ throw new d("format", "[Nova3D] .cube DOMAIN_MAX must exceed DOMAIN_MIN.");
62
+ const a = { width: t, height: t, depth: t, dimension: "3d", format: "rgba16f", colorSpace: "linear", filter: "linear", wrap: "clamp", mipmaps: !1, data: i };
63
+ return Object.freeze({ title: e, size: t, domainMin: Object.freeze(s), domainMax: Object.freeze(r), texture: a });
64
+ }
65
+ const ve = ["stages", "budget"], pe = ["maxBytes", "maxTargets"], I = Object.freeze({ maxBytes: 256 * 1024 * 1024, maxTargets: 16 }), O = ["ssao", "ssr", "taa", "dof", "motion-blur", "bloom", "outline", "finish", "fxaa", "smaa", "display"], de = {
66
+ ssao: ["type", "radius", "intensity", "bias", "samples"],
67
+ ssr: ["type", "maxDistance", "thickness", "steps", "intensity", "edgeFade"],
68
+ taa: ["type", "feedback"],
69
+ dof: ["type", "focusDistance", "focalLength", "fStop", "maxBlur", "samples"],
70
+ "motion-blur": ["type", "intensity", "samples"],
71
+ bloom: ["type", "threshold", "strength"],
72
+ outline: ["type", "color", "hiddenColor", "thickness"],
73
+ finish: ["type", "chromaticAberration", "sharpen", "grain", "vignette", "lut"],
74
+ fxaa: ["type"],
75
+ smaa: ["type", "threshold"],
76
+ display: ["type"]
77
+ }, me = /* @__PURE__ */ new Set(["ssao", "ssr", "dof", "motion-blur", "bloom", "outline"]), _e = /* @__PURE__ */ new Set(["ssao", "ssr", "taa", "dof", "motion-blur", "outline"]);
78
+ function B(c, e, t) {
79
+ if (typeof c != "object" || c === null || Array.isArray(c))
80
+ throw new d("invalid-option", `[Nova3D] ${t} options must be an object.`);
81
+ for (const s of Object.keys(c))
82
+ if (!e.includes(s))
83
+ throw new d("invalid-option", `[Nova3D] Unknown ${t} option '${s}'.`);
84
+ }
85
+ function g(c, e, t, s, r, i = !1) {
86
+ const o = c ?? e;
87
+ if (typeof o != "number")
88
+ throw new d("invalid-option", `[Nova3D] ${r} must be a number.`);
89
+ if (!Number.isFinite(o) || o < t || o > s || i && o === t)
90
+ throw new d("invalid-option", `[Nova3D] ${r} must be in ${i ? "(" : "["}${t}, ${s}].`);
91
+ return o;
92
+ }
93
+ function P(c, e, t, s, r) {
94
+ const i = g(c, e, t, s, r);
95
+ if (!Number.isInteger(i))
96
+ throw new d("invalid-option", `[Nova3D] ${r} must be an integer in [${t}, ${s}].`);
97
+ return i;
98
+ }
99
+ function G(c, e, t, s, r) {
100
+ const i = c ?? e;
101
+ if (!Array.isArray(i) || i.length !== e.length)
102
+ throw new d("invalid-option", `[Nova3D] ${r} must be an array of ${e.length} numbers.`);
103
+ for (const o of i)
104
+ g(o, 0, t, s, r);
105
+ return Object.freeze([...i]);
106
+ }
107
+ function H(c, e) {
108
+ if (c === void 0)
109
+ return e;
110
+ const t = oe(c);
111
+ return Object.freeze([...ne(t), t[3]]);
112
+ }
113
+ function ge(c) {
114
+ const e = c;
115
+ if (!e || typeof e != "object" || typeof e._readSource != "function" || e.destroyed)
116
+ throw new d("invalid-option", "[Nova3D] Finish LUT requires a live Nova3DTexture.");
117
+ const t = e._readSource();
118
+ if (t.dimension !== "3d" || t.width !== t.height || t.width !== t.depth || t.width < 2)
119
+ throw new d("invalid-option", "[Nova3D] Finish LUT texture must be a cubic 3d texture of at least 2 texels.");
120
+ if (t.colorSpace !== "linear" || t.magFilter !== "linear" || t.minFilter !== "linear")
121
+ throw new d("invalid-option", "[Nova3D] Finish LUT texture requires linear colour space and linear filtering without mipmaps.");
122
+ return e;
123
+ }
124
+ function be(c) {
125
+ const e = g(c.chromaticAberration, 0, 0, 0.05, "Finish chromaticAberration"), t = g(c.sharpen, 0, 0, 1, "Finish sharpen"), s = g(c.grain, 0, 0, 1, "Finish grain");
126
+ let r;
127
+ c.vignette !== void 0 && (B(c.vignette, ["intensity", "radius", "softness", "color"], "vignette"), r = Object.freeze({
128
+ intensity: g(c.vignette.intensity, 0.5, 0, 1, "Vignette intensity"),
129
+ radius: g(c.vignette.radius, 0.75, 0, 2, "Vignette radius"),
130
+ softness: g(c.vignette.softness, 0.5, 0, 2, "Vignette softness", !0),
131
+ color: Object.freeze(re(c.vignette.color, [0, 0, 0]))
132
+ }));
133
+ let i;
134
+ if (c.lut !== void 0) {
135
+ B(c.lut, ["texture", "intensity", "domainMin", "domainMax"], "LUT");
136
+ const o = G(c.lut.domainMin, [0, 0, 0], -65504, 65504, "LUT domainMin"), n = G(c.lut.domainMax, [1, 1, 1], -65504, 65504, "LUT domainMax");
137
+ if (n.some((a, l) => a <= o[l]))
138
+ throw new d("invalid-option", "[Nova3D] LUT domainMax must exceed domainMin in every channel.");
139
+ i = Object.freeze({ texture: ge(c.lut.texture), intensity: g(c.lut.intensity, 1, 0, 1, "LUT intensity"), domainMin: o, domainMax: n });
140
+ }
141
+ return Object.freeze({ chromaticAberration: e, sharpen: t, grain: s, vignette: r, lut: i });
142
+ }
143
+ function X(c) {
144
+ if (B(c, ve, "effects"), !Array.isArray(c.stages) || c.stages.length < 1 || c.stages.length > O.length - 1)
145
+ throw new d("invalid-option", "[Nova3D] Effects require 1..10 explicit ordered stages.");
146
+ c.budget !== void 0 && B(c.budget, pe, "effects budget");
147
+ const e = { maxBytes: c.budget?.maxBytes ?? I.maxBytes, maxTargets: c.budget?.maxTargets ?? I.maxTargets };
148
+ if (!Number.isSafeInteger(e.maxBytes) || e.maxBytes < 1 || e.maxBytes > 256 * 1024 * 1024 || !Number.isInteger(e.maxTargets) || e.maxTargets < 1 || e.maxTargets > 16)
149
+ throw new d("invalid-option", "[Nova3D] Effects budget requires 1..256MiB and 1..16 color targets.");
150
+ const t = { stages: [], budget: Object.freeze({ ...e }), fxaa: !1, depth: !1, linearStages: 0 };
151
+ let s = -1;
152
+ const r = c.stages.map((i, o) => {
153
+ const n = i && typeof i == "object" ? O.indexOf(i.type) : -1;
154
+ if (n < 0)
155
+ throw new d("invalid-option", "[Nova3D] Unknown effect stage.");
156
+ if (n === s)
157
+ throw new d("invalid-option", "[Nova3D] Repeated effect stage.");
158
+ if (i.type === "display" && o !== c.stages.length - 1)
159
+ throw new d("invalid-option", "[Nova3D] Display must be the final stage.");
160
+ if ((i.type === "fxaa" || i.type === "smaa") && o !== c.stages.length - 2)
161
+ throw new d("invalid-option", "[Nova3D] FXAA/SMAA must be immediately before the final display stage.");
162
+ if (n < s)
163
+ throw new d("invalid-option", `[Nova3D] Effect stages must follow the order ${O.join(", ")}.`);
164
+ switch (s = n, B(i, de[i.type], `${i.type} stage`), t.depth ||= _e.has(i.type), t.linearStages += me.has(i.type) ? 1 : 0, i.type) {
165
+ case "ssao": {
166
+ const a = { radius: g(i.radius, 0.5, 0, 100, "SSAO radius", !0), intensity: g(i.intensity, 1, 0, 8, "SSAO intensity"), bias: g(i.bias, 0.025, 0, 10, "SSAO bias"), samples: P(i.samples, 16, 4, 32, "SSAO samples") };
167
+ return t.ssao = Object.freeze(a), Object.freeze({ type: i.type, ...a });
168
+ }
169
+ case "ssr": {
170
+ const a = { maxDistance: g(i.maxDistance, 10, 0, 1e3, "SSR maxDistance", !0), thickness: g(i.thickness, 0.2, 0, 100, "SSR thickness", !0), steps: P(i.steps, 32, 8, 128, "SSR steps"), intensity: g(i.intensity, 0.5, 0, 1, "SSR intensity"), edgeFade: g(i.edgeFade, 0.1, 0, 0.5, "SSR edgeFade") };
171
+ return t.ssr = Object.freeze(a), Object.freeze({ type: i.type, ...a });
172
+ }
173
+ case "taa": {
174
+ const a = { feedback: g(i.feedback, 0.9, 0, 0.98, "TAA feedback") };
175
+ return t.taa = Object.freeze(a), Object.freeze({ type: i.type, ...a });
176
+ }
177
+ case "dof": {
178
+ if (i.focusDistance === void 0)
179
+ throw new d("invalid-option", "[Nova3D] DOF requires focusDistance.");
180
+ const a = { focusDistance: g(i.focusDistance, 0, 0, 1e6, "DOF focusDistance", !0), focalLength: g(i.focalLength, 50, 1, 1e3, "DOF focalLength"), fStop: g(i.fStop, 2.8, 0.5, 64, "DOF fStop"), maxBlur: g(i.maxBlur, 0.01, 0, 0.05, "DOF maxBlur"), samples: P(i.samples, 32, 8, 64, "DOF samples") };
181
+ if (a.focusDistance <= a.focalLength / 1e3)
182
+ throw new d("invalid-option", "[Nova3D] DOF focusDistance must exceed the focal length.");
183
+ return t.dof = Object.freeze(a), Object.freeze({ type: i.type, ...a });
184
+ }
185
+ case "motion-blur": {
186
+ const a = { intensity: g(i.intensity, 1, 0, 4, "Motion blur intensity"), samples: P(i.samples, 8, 2, 32, "Motion blur samples") };
187
+ return t.motionBlur = Object.freeze(a), Object.freeze({ type: i.type, ...a });
188
+ }
189
+ case "bloom": {
190
+ const a = i.threshold ?? 1, l = i.strength ?? 0.8;
191
+ if (!Number.isFinite(a) || a < 0 || a > 65504 || !Number.isFinite(l) || l < 0 || l > 16)
192
+ throw new d("invalid-option", "[Nova3D] Bloom requires threshold 0..65504 and strength 0..16.");
193
+ return t.bloom = Object.freeze({ threshold: a, strength: l }), Object.freeze({ type: "bloom", threshold: a, strength: l });
194
+ }
195
+ case "outline": {
196
+ const a = { color: H(i.color, [1, 0.6, 0.1, 1]), hiddenColor: H(i.hiddenColor, [0.1, 0.04, 0.02, 1]), thickness: P(i.thickness, 2, 1, 8, "Outline thickness") };
197
+ return t.outline = Object.freeze(a), Object.freeze({ type: i.type, ...a });
198
+ }
199
+ case "finish": {
200
+ const a = be(i);
201
+ return t.finish = a, Object.freeze({ type: i.type, ...a });
202
+ }
203
+ case "smaa": {
204
+ const a = { threshold: g(i.threshold, 0.1, 0.01, 0.5, "SMAA threshold") };
205
+ return t.smaa = Object.freeze(a), Object.freeze({ type: i.type, ...a });
206
+ }
207
+ case "fxaa":
208
+ return t.fxaa = !0, Object.freeze({ type: i.type });
209
+ default:
210
+ return Object.freeze({ type: i.type });
211
+ }
212
+ });
213
+ if (r.at(-1)?.type !== "display")
214
+ throw new d("invalid-option", "[Nova3D] Effects require exactly one final display conversion.");
215
+ return t.stages = Object.freeze(r), Object.freeze(t);
216
+ }
217
+ const xe = { rgba16f: 8, rgba8: 4, rg8: 2, r8: 1 };
218
+ function z(c, e, t, s, r) {
219
+ if (!Number.isSafeInteger(e) || !Number.isSafeInteger(t) || e < 1 || t < 1 || !Number.isSafeInteger(s) || s < 0 || !Number.isInteger(r) || r < 1)
220
+ throw new d("invalid-option", "[Nova3D] Invalid effect target dimensions/layout.");
221
+ const i = [], o = (l, f, h, v) => i.push({ key: l, width: f, height: h, format: v, bytes: f * h * xe[v] });
222
+ c.ssao && (o("aoA", e, t, "r8"), o("aoB", e, t, "r8")), c.bloom && (o("bloomA", Math.ceil(e / 2), Math.ceil(t / 2), "rgba16f"), o("bloomB", Math.ceil(e / 2), Math.ceil(t / 2), "rgba16f")), c.taa && (o("historyA", e, t, "rgba16f"), o("historyB", e, t, "rgba16f")), c.outline && (o("maskA", e, t, "r8"), o("maskB", e, t, "r8")), c.linearStages > 0 && o("linear", e, t, "rgba16f"), c.linearStages > 1 && o("linearB", e, t, "rgba16f"), (c.fxaa || c.smaa) && o("encoded", e, t, "rgba8"), c.smaa && (o("edges", e, t, "rg8"), o("weights", e, t, "rgba8"));
223
+ const n = s + i.reduce((l, f) => l + f.bytes, 0), a = r + i.length;
224
+ if (!Number.isSafeInteger(n) || n > c.budget.maxBytes || a > c.budget.maxTargets)
225
+ throw new d("budget", `[Nova3D] Effects exceed target budget (${n} bytes/${a} colors).`);
226
+ return { targets: i, bytes: n, count: a };
227
+ }
228
+ const ie = `
229
+ struct Effect {
230
+ inverseProjection: mat4x4f,
231
+ projection: mat4x4f,
232
+ matrix: mat4x4f,
233
+ // xy: output size in pixels, zw: inverse size.
234
+ size: vec4f,
235
+ a: vec4f,
236
+ b: vec4f,
237
+ c: vec4f,
238
+ d: vec4f,
239
+ e: vec4f,
240
+ }
241
+ `, T = { inverseProjection: 0, projection: 16, matrix: 32, size: 48, a: 52, b: 56, c: 60, d: 64, e: 68 }, N = 288, L = 512;
242
+ function w(c) {
243
+ const e = c.map(([t, s], r) => `@group(0) @binding(${r + 2}) var ${t}: ${s === "depth" ? "texture_depth_2d" : s === "lut" ? "texture_3d<f32>" : "texture_2d<f32>"};`).join(`
244
+ `);
245
+ return `${ie}
246
+ @group(0) @binding(0) var<uniform> u: Effect;
247
+ @group(0) @binding(1) var effectSampler: sampler;
248
+ ${e}
249
+ struct Varyings {
250
+ @builtin(position) position: vec4f,
251
+ @location(0) uv: vec2f,
252
+ }
253
+ @vertex
254
+ fn vertexMain(@builtin(vertex_index) index: u32) -> Varyings {
255
+ let p = vec2f(f32((index << 1u) & 2u), f32(index & 2u));
256
+ var out: Varyings;
257
+ out.uv = p;
258
+ out.position = vec4f(p * 2.0 - 1.0, 0.0, 1.0);
259
+ return out;
260
+ }
261
+ fn finiteHalf(value: vec4f) -> vec4f {
262
+ return vec4f(clamp(value.rgb, vec3f(0.0), vec3f(65504.0)), clamp(value.a, 0.0, 1.0));
263
+ }
264
+
265
+ fn fragCoord(position: vec4f) -> vec2f {
266
+ return vec2f(position.x, u.size.y - position.y);
267
+ }
268
+
269
+ fn sampleAt(t: texture_2d<f32>, c: vec2f) -> vec4f {
270
+ return textureSampleLevel(t, effectSampler, vec2f(c.x, 1.0 - c.y), 0.0);
271
+ }
272
+
273
+ fn loadAt(t: texture_2d<f32>, p: vec2i) -> vec4f {
274
+ let limit = vec2i(textureDimensions(t)) - 1;
275
+ let q = clamp(p, vec2i(0), limit);
276
+ return textureLoad(t, vec2i(q.x, limit.y - q.y), 0);
277
+ }
278
+ `;
279
+ }
280
+ const C = `
281
+ fn sceneDepth(c: vec2f) -> f32 {
282
+ let size = vec2i(textureDimensions(depthMap));
283
+ let texel = clamp(vec2i(floor(vec2f(c.x, 1.0 - c.y) * vec2f(size))), vec2i(0), size - 1);
284
+ return textureLoad(depthMap, texel, 0);
285
+ }
286
+ fn viewPosition(c: vec2f, d: f32) -> vec3f {
287
+ let p = u.inverseProjection * vec4f(vec3f(c, d) * 2.0 - 1.0, 1.0);
288
+ return p.xyz / p.w;
289
+ }
290
+ fn viewZ(d: f32) -> f32 {
291
+ let v = u.inverseProjection[2].zw * (d * 2.0 - 1.0) + u.inverseProjection[3].zw;
292
+ return v.x / v.y;
293
+ }
294
+ fn viewNormal(c: vec2f, p: vec3f) -> vec3f {
295
+ let inverseSize = u.size.zw;
296
+ let l = viewPosition(c - vec2f(inverseSize.x, 0.0), sceneDepth(c - vec2f(inverseSize.x, 0.0)));
297
+ let r = viewPosition(c + vec2f(inverseSize.x, 0.0), sceneDepth(c + vec2f(inverseSize.x, 0.0)));
298
+ let b = viewPosition(c - vec2f(0.0, inverseSize.y), sceneDepth(c - vec2f(0.0, inverseSize.y)));
299
+ let t = viewPosition(c + vec2f(0.0, inverseSize.y), sceneDepth(c + vec2f(0.0, inverseSize.y)));
300
+
301
+ let dx = select(r - p, p - l, abs(l.z - p.z) < abs(r.z - p.z));
302
+ let dy = select(t - p, p - b, abs(b.z - p.z) < abs(t.z - p.z));
303
+ return normalize(cross(dx, dy));
304
+ }
305
+ fn gradientNoise(p: vec2f) -> f32 {
306
+ return fract(52.9829189 * fract(dot(p, vec2f(0.06711056, 0.00583715))));
307
+ }
308
+ `;
309
+ function ye(c) {
310
+ return `${w([["depthMap", "depth"]])}${C}
311
+ const SAMPLES: i32 = ${c};
312
+ @fragment
313
+ fn fragmentMain(in: Varyings) -> @location(0) vec4f {
314
+ let uv = in.uv;
315
+ let d = sceneDepth(uv);
316
+ if (d >= 1.0) {
317
+ return vec4f(1.0);
318
+ }
319
+ let radius = u.a.x;
320
+ let p = viewPosition(uv, d);
321
+ let n = viewNormal(uv, p);
322
+ let edge = u.projection * vec4f(p + vec3f(0.0, radius, 0.0), 1.0);
323
+ let centre = u.projection * vec4f(p, 1.0);
324
+ let screenRadius = min(abs(edge.y / edge.w - centre.y / centre.w) * 0.5, 0.25);
325
+ let aspect = u.size.z / u.size.w;
326
+ let angle = gradientNoise(fragCoord(in.position)) * 6.2831853;
327
+ let radius2 = radius * radius;
328
+ var sum = 0.0;
329
+ for (var i = 0; i < SAMPLES; i++) {
330
+ let t = (f32(i) + 0.5) / f32(SAMPLES);
331
+ let a = angle + t * 43.982297;
332
+ let c = uv + vec2f(cos(a) * aspect, sin(a)) * (t * screenRadius);
333
+ let v = viewPosition(c, sceneDepth(c)) - p;
334
+ let vv = dot(v, v);
335
+ let f = max(radius2 - vv, 0.0);
336
+ sum += f * f * f * max((dot(v, n) - u.a.z) / (0.01 + vv), 0.0);
337
+ }
338
+ let ao = max(0.0, 1.0 - sum * u.a.y / (radius2 * radius2 * radius2) * (5.0 / f32(SAMPLES)));
339
+ return vec4f(ao);
340
+ }
341
+ `;
342
+ }
343
+ function q(c) {
344
+ return `${w(c ? [["source", "float"], ["depthMap", "depth"], ["colorMap", "float"]] : [["source", "float"], ["depthMap", "depth"]])}${C}
345
+ @fragment
346
+ fn fragmentMain(in: Varyings) -> @location(0) vec4f {
347
+ let uv = in.uv;
348
+ let offset = u.b.xy;
349
+ let z = viewZ(sceneDepth(uv));
350
+ var sum = 0.0;
351
+ var total = 0.0;
352
+ for (var i = -4; i <= 4; i++) {
353
+ let c = uv + offset * f32(i);
354
+ let w = exp(-f32(i * i) / 8.0) * max(0.0, 1.0 - abs(viewZ(sceneDepth(c)) - z) / (u.a.x * 0.5));
355
+ sum += sampleAt(source, c).r * w;
356
+ total += w;
357
+ }
358
+ var ao = sampleAt(source, uv).r;
359
+ if (total > 0.0) {
360
+ ao = sum / total;
361
+ }
362
+ ${c ? ` let p = sampleAt(colorMap, uv);
363
+ return vec4f(p.rgb * ao, p.a);` : " return vec4f(ao);"}
364
+ }
365
+ `;
366
+ }
367
+ function we(c) {
368
+ return `${w([["source", "float"], ["depthMap", "depth"]])}${C}
369
+ const STEPS: i32 = ${c};
370
+ fn project(q: vec3f) -> vec2f {
371
+ let c = u.projection * vec4f(q, 1.0);
372
+ return c.xy / c.w * 0.5 + 0.5;
373
+ }
374
+ @fragment
375
+ fn fragmentMain(in: Varyings) -> @location(0) vec4f {
376
+ let uv = in.uv;
377
+ let color = sampleAt(source, uv);
378
+ let d = sceneDepth(uv);
379
+ if (d >= 1.0) {
380
+ return color;
381
+ }
382
+ let thickness = u.a.y;
383
+ let edgeFade = u.a.w;
384
+ let p = viewPosition(uv, d);
385
+ let n = viewNormal(uv, p);
386
+ var eye = vec3f(0.0, 0.0, -1.0);
387
+ if (u.projection[2].w != 0.0) {
388
+ eye = normalize(p);
389
+ }
390
+ let r = reflect(eye, n);
391
+ let stepVector = r * (u.a.x / f32(STEPS));
392
+ var q = p + stepVector * (0.5 + gradientNoise(fragCoord(in.position)));
393
+ var hit = vec2f(-1.0);
394
+ var travelled = 0.0;
395
+ for (var i = 0; i < STEPS; i++) {
396
+ let c = project(q);
397
+ if (c.x < 0.0 || c.x > 1.0 || c.y < 0.0 || c.y > 1.0) {
398
+ break;
399
+ }
400
+ let depthGap = viewZ(sceneDepth(c)) - q.z;
401
+ if (depthGap > 0.0 && depthGap < thickness) {
402
+ var a = q - stepVector;
403
+ var b = q;
404
+ for (var k = 0; k < 4; k++) {
405
+ let m = (a + b) * 0.5;
406
+ if (viewZ(sceneDepth(project(m))) - m.z > 0.0) {
407
+ b = m;
408
+ }
409
+ else {
410
+ a = m;
411
+ }
412
+ }
413
+ hit = project(b);
414
+ travelled = f32(i) / f32(STEPS);
415
+ break;
416
+ }
417
+ q += stepVector;
418
+ }
419
+ if (hit.x < 0.0) {
420
+ return color;
421
+ }
422
+ let border = min(hit, 1.0 - hit);
423
+ var fade = 1.0;
424
+ if (edgeFade > 0.0) {
425
+ fade = clamp(min(border.x, border.y) / edgeFade, 0.0, 1.0);
426
+ }
427
+ fade *= 1.0 - travelled * travelled;
428
+ return finiteHalf(mix(color, sampleAt(source, hit), u.a.z * fade));
429
+ }
430
+ `;
431
+ }
432
+ function Se(c) {
433
+ return `${w([["source", "float"], ["depthMap", "depth"]])}${C}
434
+ const SAMPLES: i32 = ${c};
435
+ fn coc(z: f32) -> f32 {
436
+ return min(abs(z - u.a.x) / max(z, 1e-4) * u.a.y, u.a.z);
437
+ }
438
+ @fragment
439
+ fn fragmentMain(in: Varyings) -> @location(0) vec4f {
440
+ let uv = in.uv;
441
+ let frag = fragCoord(in.position);
442
+ let maxBlur = u.a.z;
443
+ let centre = sampleAt(source, uv);
444
+ let centreZ = -viewZ(sceneDepth(uv));
445
+ let centreCoc = coc(centreZ);
446
+ var sum = centre;
447
+ var total = 1.0;
448
+ for (var i = 0; i < SAMPLES; i++) {
449
+ let t = (f32(i) + 0.5) / f32(SAMPLES);
450
+ let r = sqrt(t) * maxBlur;
451
+ let a = f32(i) * 2.39996323;
452
+
453
+ let texel = floor(frag + vec2f(cos(a), sin(a)) * r) + 0.5;
454
+ let c = texel * u.size.zw;
455
+ let gap = length(texel - frag);
456
+ let z = -viewZ(sceneDepth(c));
457
+ var size = coc(z);
458
+
459
+ if (z > centreZ) {
460
+ size = min(size, centreCoc * 2.0);
461
+ }
462
+ let w = smoothstep(gap - 0.5, gap + 0.5, size);
463
+ sum += sampleAt(source, c) * w;
464
+ total += w;
465
+ }
466
+ return finiteHalf(sum / total);
467
+ }
468
+ `;
469
+ }
470
+ function Ae(c) {
471
+ return `${w([["source", "float"], ["depthMap", "depth"]])}
472
+ const SAMPLES: i32 = ${c};
473
+ fn sceneDepth(c: vec2f) -> f32 {
474
+ let size = vec2i(textureDimensions(depthMap));
475
+ let texel = clamp(vec2i(floor(vec2f(c.x, 1.0 - c.y) * vec2f(size))), vec2i(0), size - 1);
476
+ return textureLoad(depthMap, texel, 0);
477
+ }
478
+ @fragment
479
+ fn fragmentMain(in: Varyings) -> @location(0) vec4f {
480
+ let uv = in.uv;
481
+ let previous = u.matrix * vec4f(vec3f(uv, sceneDepth(uv)) * 2.0 - 1.0, 1.0);
482
+ var velocity = (uv - (previous.xy / previous.w * 0.5 + 0.5)) * u.a.x;
483
+ let speed = length(velocity);
484
+ if (speed < 1e-5) {
485
+ return sampleAt(source, uv);
486
+ }
487
+ velocity *= min(1.0, 0.1 / speed);
488
+ var sum = vec4f(0.0);
489
+ for (var i = 0; i < SAMPLES; i++) {
490
+ sum += sampleAt(source, uv - velocity * (f32(i) / f32(SAMPLES - 1) - 0.5));
491
+ }
492
+ return finiteHalf(sum / f32(SAMPLES));
493
+ }
494
+ `;
495
+ }
496
+ const De = `${w([["source", "float"], ["depthMap", "depth"], ["historyMap", "float"]])}
497
+ fn sceneDepth(c: vec2f) -> f32 {
498
+ let size = vec2i(textureDimensions(depthMap));
499
+ let texel = clamp(vec2i(floor(vec2f(c.x, 1.0 - c.y) * vec2f(size))), vec2i(0), size - 1);
500
+ return textureLoad(depthMap, texel, 0);
501
+ }
502
+ @fragment
503
+ fn fragmentMain(in: Varyings) -> @location(0) vec4f {
504
+ let uv = in.uv;
505
+ let current = sampleAt(source, uv);
506
+ var low = current;
507
+ var high = current;
508
+ for (var y = -1; y <= 1; y++) {
509
+ for (var x = -1; x <= 1; x++) {
510
+ let neighbour = sampleAt(source, uv + vec2f(f32(x), f32(y)) * u.size.zw);
511
+ low = min(low, neighbour);
512
+ high = max(high, neighbour);
513
+ }
514
+ }
515
+ let previous = u.matrix * vec4f(vec3f(uv, sceneDepth(uv)) * 2.0 - 1.0, 1.0);
516
+ let previousUV = previous.xy / previous.w * 0.5 + 0.5;
517
+ if (u.a.y > 0.5 || any(previousUV < vec2f(0.0)) || any(previousUV > vec2f(1.0))) {
518
+ return finiteHalf(current);
519
+ }
520
+ let history = clamp(sampleAt(historyMap, previousUV), low, high);
521
+ return finiteHalf(mix(current, history, u.a.x));
522
+ }
523
+ `, Me = `${w([["source", "float"]])}
524
+ fn sampleBright(c: vec2f) -> vec4f {
525
+ let p = sampleAt(source, c);
526
+ if (u.a.y < 0.5) {
527
+ return p;
528
+ }
529
+ var straight = vec3f(0.0);
530
+ if (p.a > 0.0) {
531
+ straight = p.rgb / p.a;
532
+ }
533
+ let brightness = dot(straight, vec3f(0.2126, 0.7152, 0.0722));
534
+ return p * max(0.0, (brightness - u.a.x) / max(brightness, 1e-6));
535
+ }
536
+ @fragment
537
+ fn fragmentMain(in: Varyings) -> @location(0) vec4f {
538
+ let uv = in.uv;
539
+ let offset = u.b.xy;
540
+ var p = sampleBright(uv) * 0.2270270270;
541
+ p += (sampleBright(uv + offset) + sampleBright(uv - offset)) * 0.1945945946;
542
+ p += (sampleBright(uv + offset * 2.0) + sampleBright(uv - offset * 2.0)) * 0.1216216216;
543
+ p += (sampleBright(uv + offset * 3.0) + sampleBright(uv - offset * 3.0)) * 0.0540540541;
544
+ p += (sampleBright(uv + offset * 4.0) + sampleBright(uv - offset * 4.0)) * 0.0162162162;
545
+ return finiteHalf(p);
546
+ }
547
+ `, ze = `${w([["source", "float"], ["bloom", "float"]])}
548
+ @fragment
549
+ fn fragmentMain(in: Varyings) -> @location(0) vec4f {
550
+ return finiteHalf(sampleAt(source, in.uv) + sampleAt(bloom, in.uv) * u.a.x);
551
+ }
552
+ `;
553
+ function Z(c) {
554
+ return `${w(c ? [["source", "float"], ["colorMap", "float"], ["maskMap", "float"]] : [["source", "float"]])}
555
+ @fragment
556
+ fn fragmentMain(in: Varyings) -> @location(0) vec4f {
557
+ let uv = in.uv;
558
+ let thickness = i32(u.a.x);
559
+ var m = 0.0;
560
+ for (var i = -8; i <= 8; i++) {
561
+ if (i < -thickness || i > thickness) {
562
+ continue;
563
+ }
564
+ m = max(m, sampleAt(source, uv + u.b.xy * f32(i)).r);
565
+ }
566
+ ${c ? ` let p = sampleAt(colorMap, uv);
567
+ if (m < 0.25 || sampleAt(maskMap, uv).r > 0.25) {
568
+ return p;
569
+ }
570
+ var edge = u.d;
571
+ if (m > 0.75) {
572
+ edge = u.c;
573
+ }
574
+ return finiteHalf(vec4f(edge.rgb * edge.a, edge.a) + p * (1.0 - edge.a));` : " return vec4f(m);"}
575
+ }
576
+ `;
577
+ }
578
+ function Ee(c) {
579
+ return `${ie}
580
+ ${ae.wgsl}
581
+ @group(0) @binding(0) var<uniform> u: Effect;
582
+ @group(0) @binding(1) var depthMap: texture_depth_2d;
583
+ @group(2) @binding(0) var<uniform> object: ObjectData;
584
+ struct VertexInput {
585
+ @location(0) position: vec3f,
586
+ ${c ? ` @location(4) instance0: vec4f,
587
+ @location(5) instance1: vec4f,
588
+ @location(6) instance2: vec4f,
589
+ @location(7) instance3: vec4f,` : ""}
590
+ }
591
+ @vertex
592
+ fn vertexMain(input: VertexInput) -> @builtin(position) vec4f {
593
+ ${c ? " var clip = u.matrix * object.world * mat4x4f(input.instance0, input.instance1, input.instance2, input.instance3) * vec4f(input.position, 1.0);" : " var clip = u.matrix * object.world * vec4f(input.position, 1.0);"}
594
+ clip.z = 0.5 * (clip.z + clip.w);
595
+ return clip;
596
+ }
597
+ @fragment
598
+ fn fragmentMain(@builtin(position) position: vec4f) -> @location(0) vec4f {
599
+ let scene = textureLoad(depthMap, vec2i(position.xy), 0);
600
+ return vec4f(select(0.5, 1.0, position.z <= scene + 2e-4));
601
+ }
602
+ `;
603
+ }
604
+ function Pe(c) {
605
+ return `${w(c & 4 ? [["source", "float"], ["lut", "lut"]] : [["source", "float"]])}
606
+ ${te}
607
+ fn displayed(p: vec4f) -> vec3f {
608
+ if (p.a > 0.0) {
609
+ return novaToneMap(p.rgb / p.a, u.c.w, i32(u.d.w));
610
+ }
611
+ return vec3f(0.0);
612
+ }
613
+ fn encoded(p: vec4f) -> vec3f {
614
+ return novaEncodeSRGB(displayed(p));
615
+ }
616
+ fn straight(value: f32, alpha: f32) -> f32 {
617
+ if (alpha > 0.0) {
618
+ return value / alpha;
619
+ }
620
+ return 0.0;
621
+ }
622
+ @fragment
623
+ fn fragmentMain(in: Varyings) -> @location(0) vec4f {
624
+ let uv = in.uv;
625
+ var p = sampleAt(source, uv);
626
+ ${c & 1 ? ` let shift = (uv - 0.5) * u.a.x * 2.0;
627
+ let red = sampleAt(source, uv + shift);
628
+ let blue = sampleAt(source, uv - shift);
629
+ // Straight channels keep the centre coverage.
630
+ p = vec4f(vec3f(straight(red.r, red.a), straight(p.g, p.a), straight(blue.b, blue.a)) * p.a, p.a);` : ""}
631
+ var e = encoded(p);
632
+ ${c & 2 ? ` // AMD CAS on the encoded image.
633
+ let c = e;
634
+ let north = encoded(sampleAt(source, uv + vec2f(0.0, u.size.w)));
635
+ let south = encoded(sampleAt(source, uv - vec2f(0.0, u.size.w)));
636
+ let east = encoded(sampleAt(source, uv + vec2f(u.size.z, 0.0)));
637
+ let west = encoded(sampleAt(source, uv - vec2f(u.size.z, 0.0)));
638
+ let low = min(c, min(min(north, south), min(east, west)));
639
+ let high = max(c, max(max(north, south), max(east, west)));
640
+ let amplitude = sqrt(clamp(min(low, 1.0 - high) / max(high, vec3f(1e-5)), vec3f(0.0), vec3f(1.0)));
641
+ let weight = -amplitude / mix(8.0, 5.0, u.a.y);
642
+ e = clamp((c + (north + south + east + west) * weight) / (1.0 + 4.0 * weight), vec3f(0.0), vec3f(1.0));` : ""}
643
+ ${c & 4 ? " e = mix(e, textureSampleLevel(lut, effectSampler, clamp(e * u.d.xyz + u.e.xyz, vec3f(0.0), vec3f(1.0)), 0.0).rgb, u.b.w);" : ""}
644
+ ${c & 8 ? " e = mix(e, u.c.xyz, smoothstep(u.b.y, u.b.y + u.b.z, length(uv - 0.5) * 2.0) * u.b.x);" : ""}
645
+ ${c & 16 ? " e += (fract(sin(dot(fragCoord(in.position) + u.a.w, vec2f(12.9898, 78.233))) * 43758.5453) - 0.5) * u.a.z;" : ""}
646
+ return vec4f(clamp(e, vec3f(0.0), vec3f(1.0)) * p.a, p.a);
647
+ }
648
+ `;
649
+ }
650
+ const Te = `${w([["source", "float"]])}
651
+ ${te}
652
+ @fragment
653
+ fn fragmentMain(in: Varyings) -> @location(0) vec4f {
654
+ let p = textureLoad(source, vec2i(in.position.xy), 0);
655
+ var encoded = vec3f(0.0);
656
+ if (p.a > 0.0) {
657
+ encoded = novaEncodeSRGB(novaToneMap(p.rgb / p.a, u.c.w, i32(u.d.w)));
658
+ }
659
+ return vec4f(encoded * p.a, p.a);
660
+ }
661
+ `, je = `${w([["source", "float"]])}
662
+ fn edgeLuma(p: vec4f) -> f32 {
663
+ return dot(p.rgb, vec3f(0.299, 0.587, 0.114)) + 0.25 * p.a;
664
+ }
665
+ @fragment
666
+ fn fragmentMain(in: Varyings) -> @location(0) vec4f {
667
+ let uv = in.uv;
668
+ let inverseSize = u.size.zw;
669
+ let center = sampleAt(source, uv);
670
+ let m = edgeLuma(center);
671
+ let nw = edgeLuma(sampleAt(source, uv + inverseSize * vec2f(-1.0, -1.0)));
672
+ let ne = edgeLuma(sampleAt(source, uv + inverseSize * vec2f(1.0, -1.0)));
673
+ let sw = edgeLuma(sampleAt(source, uv + inverseSize * vec2f(-1.0, 1.0)));
674
+ let se = edgeLuma(sampleAt(source, uv + inverseSize * vec2f(1.0, 1.0)));
675
+ let low = min(m, min(min(nw, ne), min(sw, se)));
676
+ let high = max(m, max(max(nw, ne), max(sw, se)));
677
+ if (high - low < max(0.0312, high * 0.125)) {
678
+ return center;
679
+ }
680
+ var direction = vec2f(sw + se - nw - ne, nw + sw - ne - se);
681
+ let reduction = max((nw + ne + sw + se) * 0.03125, 1.0 / 128.0);
682
+ direction = clamp(direction / (min(abs(direction.x), abs(direction.y)) + reduction), vec2f(-8.0), vec2f(8.0)) * inverseSize;
683
+ let narrow = (sampleAt(source, uv - direction / 6.0) + sampleAt(source, uv + direction / 6.0)) * 0.5;
684
+ let wide = narrow * 0.5 + (sampleAt(source, uv - direction * 0.5) + sampleAt(source, uv + direction * 0.5)) * 0.25;
685
+ let candidate = edgeLuma(wide);
686
+ if (candidate < low || candidate > high) {
687
+ return narrow;
688
+ }
689
+ return wide;
690
+ }
691
+ `, Be = `fn luma(p: vec4f) -> f32 {
692
+ return dot(p.rgb, vec3f(0.2126, 0.7152, 0.0722)) + 0.25 * p.a;
693
+ }`, ke = `${w([["source", "float"]])}
694
+ ${Be}
695
+ fn at(uv: vec2f, o: vec2f) -> f32 {
696
+ return luma(sampleAt(source, uv + o * u.size.zw));
697
+ }
698
+ @fragment
699
+ fn fragmentMain(in: Varyings) -> @location(0) vec4f {
700
+ let uv = in.uv;
701
+ let l = at(uv, vec2f(0.0));
702
+ let left = at(uv, vec2f(-1.0, 0.0));
703
+ let bottom = at(uv, vec2f(0.0, -1.0));
704
+ let delta = abs(l - vec2f(left, bottom));
705
+ var edges = step(vec2f(u.a.x), delta);
706
+ if (edges.x + edges.y == 0.0) {
707
+ return vec4f(0.0);
708
+ }
709
+ var most = max(delta, abs(l - vec2f(at(uv, vec2f(1.0, 0.0)), at(uv, vec2f(0.0, 1.0)))));
710
+ most = max(most, abs(vec2f(left, bottom) - vec2f(at(uv, vec2f(-2.0, 0.0)), at(uv, vec2f(0.0, -2.0)))));
711
+ edges *= step(vec2f(max(most.x, most.y)), 2.0 * delta);
712
+ return vec4f(edges, 0.0, 1.0);
713
+ }
714
+ `, Fe = `${w([["source", "float"]])}
715
+ const MAX_SEARCH: i32 = 16;
716
+ var<private> limit: vec2i;
717
+ fn edgeAt(p: vec2i) -> vec2f {
718
+ let q = clamp(p, vec2i(0), limit);
719
+ return textureLoad(source, vec2i(q.x, limit.y - q.y), 0).rg;
720
+ }
721
+
722
+ fn segmentArea(p0: vec2f, p1: vec2f, lo: f32, hi: f32) -> vec2f {
723
+ let a = max(lo, p0.x);
724
+ let b = min(hi, p1.x);
725
+ if (b <= a) {
726
+ return vec2f(0.0);
727
+ }
728
+ let slope = (p1.y - p0.y) / (p1.x - p0.x);
729
+ let ya = p0.y + slope * (a - p0.x);
730
+ let yb = p0.y + slope * (b - p0.x);
731
+ if (ya * yb >= 0.0) {
732
+ let m = (ya + yb) * 0.5 * (b - a);
733
+ if (m > 0.0) {
734
+ return vec2f(m, 0.0);
735
+ }
736
+ return vec2f(0.0, -m);
737
+ }
738
+ let z = a + (b - a) * ya / (ya - yb);
739
+ let first = ya * (z - a) * 0.5;
740
+ let second = yb * (b - z) * 0.5;
741
+ return vec2f(max(first, 0.0) + max(second, 0.0), max(-first, 0.0) + max(-second, 0.0));
742
+ }
743
+ fn lineArea(h1: f32, h2: f32, len: f32, i: f32) -> vec2f {
744
+ if (h1 != 0.0 && h2 != 0.0 && h1 != h2) {
745
+ return segmentArea(vec2f(0.0, h1), vec2f(len, h2), i, i + 1.0);
746
+ }
747
+ var area = vec2f(0.0);
748
+ if (h1 != 0.0) {
749
+ area += segmentArea(vec2f(0.0, h1), vec2f(len * 0.5, 0.0), i, i + 1.0);
750
+ }
751
+ if (h2 != 0.0) {
752
+ area += segmentArea(vec2f(len * 0.5, 0.0), vec2f(len, h2), i, i + 1.0);
753
+ }
754
+ return area;
755
+ }
756
+ fn crossing(own: f32, other: f32) -> f32 {
757
+ if (own > 0.5 && other < 0.5) {
758
+ return 0.5;
759
+ }
760
+ if (other > 0.5 && own < 0.5) {
761
+ return -0.5;
762
+ }
763
+ return 0.0;
764
+ }
765
+ @fragment
766
+ fn fragmentMain(in: Varyings) -> @location(0) vec4f {
767
+ limit = vec2i(textureDimensions(source)) - 1;
768
+ let p = vec2i(fragCoord(in.position));
769
+ let e = edgeAt(p);
770
+ var vertical = vec2f(0.0);
771
+ var horizontal = vec2f(0.0);
772
+ if (e.x > 0.5) {
773
+ var up = 0;
774
+ var down = 0;
775
+ for (var k = 1; k <= MAX_SEARCH; k++) {
776
+ if (edgeAt(p + vec2i(0, k)).x < 0.5) {
777
+ break;
778
+ }
779
+ up = k;
780
+ }
781
+ for (var k = 1; k <= MAX_SEARCH; k++) {
782
+ if (edgeAt(p - vec2i(0, k)).x < 0.5) {
783
+ break;
784
+ }
785
+ down = k;
786
+ }
787
+ let bottom = p - vec2i(0, down);
788
+ let top = p + vec2i(0, up + 1);
789
+ var h1 = 0.0;
790
+ if (down != MAX_SEARCH) {
791
+ h1 = crossing(edgeAt(bottom).y, edgeAt(bottom - vec2i(1, 0)).y);
792
+ }
793
+ var h2 = 0.0;
794
+ if (up != MAX_SEARCH) {
795
+ h2 = crossing(edgeAt(top).y, edgeAt(top - vec2i(1, 0)).y);
796
+ }
797
+ vertical = lineArea(h1, h2, f32(up + down + 1), f32(down));
798
+ }
799
+ if (e.y > 0.5) {
800
+ var right = 0;
801
+ var left = 0;
802
+ for (var k = 1; k <= MAX_SEARCH; k++) {
803
+ if (edgeAt(p + vec2i(k, 0)).y < 0.5) {
804
+ break;
805
+ }
806
+ right = k;
807
+ }
808
+ for (var k = 1; k <= MAX_SEARCH; k++) {
809
+ if (edgeAt(p - vec2i(k, 0)).y < 0.5) {
810
+ break;
811
+ }
812
+ left = k;
813
+ }
814
+ let start = p - vec2i(left, 0);
815
+ let end = p + vec2i(right + 1, 0);
816
+ var h1 = 0.0;
817
+ if (left != MAX_SEARCH) {
818
+ h1 = crossing(edgeAt(start).x, edgeAt(start - vec2i(0, 1)).x);
819
+ }
820
+ var h2 = 0.0;
821
+ if (right != MAX_SEARCH) {
822
+ h2 = crossing(edgeAt(end).x, edgeAt(end - vec2i(0, 1)).x);
823
+ }
824
+ horizontal = lineArea(h1, h2, f32(left + right + 1), f32(left));
825
+ }
826
+ return vec4f(vertical, horizontal);
827
+ }
828
+ `, Ne = `${w([["source", "float"], ["weightMap", "float"]])}
829
+ @fragment
830
+ fn fragmentMain(in: Varyings) -> @location(0) vec4f {
831
+ let limit = vec2i(textureDimensions(source)) - 1;
832
+ let p = vec2i(fragCoord(in.position));
833
+ let w = loadAt(weightMap, p);
834
+ let left = w.r;
835
+ let right = loadAt(weightMap, min(p + vec2i(1, 0), limit)).g;
836
+ let below = w.b;
837
+ let above = loadAt(weightMap, min(p + vec2i(0, 1), limit)).a;
838
+ let c = loadAt(source, p);
839
+ if (max(left, right) + max(below, above) < 1e-5) {
840
+ return c;
841
+ }
842
+ if (max(left, right) >= max(below, above)) {
843
+ return c * (1.0 - left - right) + loadAt(source, max(p - vec2i(1, 0), vec2i(0))) * left + loadAt(source, min(p + vec2i(1, 0), limit)) * right;
844
+ }
845
+ return c * (1.0 - below - above) + loadAt(source, max(p - vec2i(0, 1), vec2i(0))) * below + loadAt(source, min(p + vec2i(0, 1), limit)) * above;
846
+ }
847
+ `, Le = `@group(0) @binding(0) var source: texture_depth_multisampled_2d;
848
+ @vertex
849
+ fn vertexMain(@builtin(vertex_index) index: u32) -> @builtin(position) vec4f {
850
+ let p = vec2f(f32((index << 1u) & 2u), f32(index & 2u));
851
+ return vec4f(p * 2.0 - 1.0, 0.0, 1.0);
852
+ }
853
+ @fragment
854
+ fn fragmentMain(@builtin(position) position: vec4f) -> @builtin(frag_depth) f32 {
855
+ let p = vec2i(position.xy);
856
+ let s0 = textureLoad(source, p, 0);
857
+ let s1 = textureLoad(source, p, 1);
858
+ let s2 = textureLoad(source, p, 2);
859
+ let s3 = textureLoad(source, p, 3);
860
+ if (abs(s0 + s3 - s1 - s2) <= 2e-6) {
861
+ return (s0 + s1 + s2 + s3) * 0.25;
862
+ }
863
+ return s0;
864
+ }
865
+ `, x = { ssao: 0, aoBlur: 1, aoApply: 2, ssr: 3, taa: 4, dof: 5, motion: 6, bloomBlur: 7, bloomComposite: 8, dilate: 9, outline: 10, finish: 11, display: 12, fxaa: 13, smaaEdges: 14, smaaWeights: 15, smaaBlend: 16 }, Re = [
866
+ { textures: () => ["depth"], source: ye },
867
+ { textures: () => ["float", "depth"], source: () => q(!1) },
868
+ { textures: () => ["float", "depth", "float"], source: () => q(!0) },
869
+ { textures: () => ["float", "depth"], source: we },
870
+ { textures: () => ["float", "depth", "float"], source: () => De },
871
+ { textures: () => ["float", "depth"], source: Se },
872
+ { textures: () => ["float", "depth"], source: Ae },
873
+ { textures: () => ["float"], source: () => Me },
874
+ { textures: () => ["float", "float"], source: () => ze },
875
+ { textures: () => ["float"], source: () => Z(!1) },
876
+ { textures: () => ["float", "float", "float"], source: () => Z(!0) },
877
+ { textures: (c) => c & 4 ? ["float", "lut"] : ["float"], source: Pe },
878
+ { textures: () => ["float"], source: () => Te },
879
+ { textures: () => ["float"], source: () => je },
880
+ { textures: () => ["float"], source: () => ke },
881
+ { textures: () => ["float"], source: () => Fe },
882
+ { textures: () => ["float", "float"], source: () => Ne }
883
+ ], u = { ssao: 0, aoBlur: 1, aoApply: 2, ssr: 3, taa: 4, dof: 5, motion: 6, bloomH: 7, bloomV: 8, bloomComposite: 9, mask: 10, dilate: 11, outline: 12, finish: 13, fxaa: 14, smaaEdges: 15, smaaWeights: 16, smaaBlend: 17 }, W = 18, D = L / 4, j = { rgba16f: "rgba16float", rgba8: "rgba8unorm", rg8: "rg8unorm", r8: "r8unorm" }, b = { rgba16f: 0, rgba8: 1, rg8: 2, r8: 3, canvas: 4 };
884
+ function Y(c, e) {
885
+ let t = 0, s = 1 / e;
886
+ for (let r = c; r > 0; r = Math.floor(r / e))
887
+ t += r % e * s, s /= e;
888
+ return t;
889
+ }
890
+ class $e {
891
+ constructor(e) {
892
+ this._plan = e;
893
+ }
894
+ _device = null;
895
+ _targets = /* @__PURE__ */ new Map();
896
+ _pipelines = /* @__PURE__ */ new Map();
897
+ _modules = /* @__PURE__ */ new Map();
898
+ _layouts = /* @__PURE__ */ new Map();
899
+ /** Bind groups by layout, uniform slot and texture views. */
900
+ _groups = /* @__PURE__ */ new Map();
901
+ _buffer = null;
902
+ _sampler = null;
903
+ _data = new Float32Array(W * D);
904
+ _mask;
905
+ _resolve;
906
+ _lut;
907
+ _attachment = { view: null, loadOp: "clear", storeOp: "store", clearValue: [0, 0, 0, 0] };
908
+ _pass = { colorAttachments: [this._attachment] };
909
+ _depthAttachment = { view: null, depthLoadOp: "clear", depthClearValue: 1, depthStoreOp: "store" };
910
+ _depthPass = { colorAttachments: [], depthStencilAttachment: this._depthAttachment };
911
+ _sourceView = null;
912
+ _depthView = null;
913
+ _bytes = 0;
914
+ _basePerPixel = 0;
915
+ _depthPerPixel = 0;
916
+ _baseColors = 1;
917
+ _width = 0;
918
+ _height = 0;
919
+ /** Size of the last validated canvas; configure() checks plans against it. */
920
+ _validWidth = 1;
921
+ _validHeight = 1;
922
+ _layoutPlan;
923
+ _layoutBase = -1;
924
+ _canvasFormat = "bgra8unorm";
925
+ _cameraStamp = -1;
926
+ _inverseProjection = new Float32Array(16);
927
+ _previous = new Float32Array(16);
928
+ _previousStamp = -1;
929
+ _reprojection = new Float32Array(16);
930
+ /** Projection of the current camera, a view of the renderer's frame record. */
931
+ _projection = this._inverseProjection;
932
+ _grainFrame = 0;
933
+ _selection = [];
934
+ _jitterIndex = 0;
935
+ _jitter = new Float32Array(2);
936
+ _historyParity = 0;
937
+ _historyValid = !1;
938
+ _taaPrevious = new Float32Array(16);
939
+ _taaReprojection = new Float32Array(16);
940
+ get bytes() {
941
+ return this._bytes;
942
+ }
943
+ get depth() {
944
+ return this._plan.depth;
945
+ }
946
+ /** Sub-pixel projection offset for the next frame (device pixels), or null without TAA. */
947
+ jitter() {
948
+ if (!this._plan.taa)
949
+ return null;
950
+ const e = this._jitterIndex++ % 8 + 1;
951
+ return this._jitter[0] = Y(e, 2) - 0.5, this._jitter[1] = Y(e, 3) - 0.5, this._jitter;
952
+ }
953
+ validateSize(e, t, s, r, i) {
954
+ z(this._plan, e, t, s + (this._plan.depth ? i : 0), r), this._basePerPixel = s / (e * t), this._depthPerPixel = i / (e * t), this._baseColors = r, this._validWidth = e, this._validHeight = t;
955
+ }
956
+ configure(e) {
957
+ const t = this._validWidth, s = this._validHeight, r = z(e, t, s, this._baseBytes(e, t, s), this._baseColors);
958
+ this._plan = e, this._previousStamp = -1, this._historyValid = !1, this._releaseStale(r.targets);
959
+ }
960
+ /** Replaces the outline selection; the array is owned by the caller's copy. */
961
+ select(e) {
962
+ this._selection = e;
963
+ }
964
+ present(e, t, s, r, i) {
965
+ this._device !== i.device && (this.reset(!0), this._device = i.device), this._ensureTargets(s, r), (t !== this._sourceView || i.depth !== this._depthView) && (this._groups = /* @__PURE__ */ new Map(), this._sourceView = t, this._depthView = i.depth);
966
+ const o = this._plan;
967
+ this._canvasFormat = i.format, this._projection = i.projection, i.scene && i.stamp !== this._cameraStamp && (M(this._inverseProjection, i.projection), this._cameraStamp = i.stamp);
968
+ const n = i.depth, a = i.scene !== null && n !== null;
969
+ a && i.depthSource && this._resolveDepth(e, i.depthSource, n);
970
+ let l = t, f = 0;
971
+ if (o.ssao && a) {
972
+ const p = this._next(l);
973
+ f += this._ssao(e, l, n, p), l = p.view;
974
+ }
975
+ if (o.ssr && a) {
976
+ const p = this._next(l);
977
+ this._ssr(e, l, n, p), l = p.view, f++;
978
+ }
979
+ if (o.taa && a ? (l = this._taa(e, l, n, i), f++) : o.taa && (this._historyValid = !1), o.dof && a) {
980
+ const p = this._next(l);
981
+ this._dof(e, l, n, i, p), l = p.view, f++;
982
+ }
983
+ if (o.motionBlur && a && this._motion(i)) {
984
+ const p = this._next(l);
985
+ this._motionBlur(e, l, n, p), l = p.view, f++;
986
+ }
987
+ if (o.bloom) {
988
+ const p = this._next(l);
989
+ f += this._bloom(e, l, p), l = p.view;
990
+ }
991
+ if (o.outline && a && this._selection.length > 0) {
992
+ const p = this._next(l), m = this._outline(e, l, n, i, p);
993
+ m > 0 && (l = p.view, f += m);
994
+ }
995
+ const h = o.fxaa || o.smaa ? this._targets.get("encoded") : null, v = h ? h.view : i.output, _ = h ? b.rgba8 : b.canvas;
996
+ return o.finish ? this._finish(e, l, v, _, s, r, i) : (this._uniforms(u.finish, s, r), this._data[u.finish * D + T.c + 3] = i.exposure, this._data[u.finish * D + T.d + 3] = i.toneMapping, this._run(e, x.display, 0, _, u.finish, v, l)), f++, o.fxaa ? (this._uniforms(u.fxaa, s, r), this._run(e, x.fxaa, 0, b.canvas, u.fxaa, i.output, h.view), f++) : o.smaa && (this._smaa(e, h, s, r, i.output), f += 3), this._device.queue.writeBuffer(this._buffer, 0, this._data), f;
997
+ }
998
+ reset(e) {
999
+ if (!e) {
1000
+ for (const t of this._targets.values())
1001
+ t.texture.destroy();
1002
+ this._buffer?.destroy(), this._lut?.gpu.destroy();
1003
+ }
1004
+ this._targets.clear(), this._pipelines.clear(), this._modules.clear(), this._layouts.clear(), this._groups = /* @__PURE__ */ new Map(), this._buffer = null, this._sampler = null, this._mask = void 0, this._resolve = void 0, this._lut = void 0, this._device = null, this._sourceView = null, this._depthView = null, this._bytes = 0, this._width = 0, this._height = 0, this._layoutPlan = void 0, this._cameraStamp = -1, this._previousStamp = -1, this._historyValid = !1;
1005
+ }
1006
+ /** Linear ping-pong target that does not hold `current`. */
1007
+ _next(e) {
1008
+ const t = this._targets.get("linear");
1009
+ return t.view === e ? this._targets.get("linearB") : t;
1010
+ }
1011
+ _baseBytes(e, t, s) {
1012
+ return t * s * (this._basePerPixel + (e.depth ? this._depthPerPixel : 0));
1013
+ }
1014
+ /** Writes the output size of a slot (xy) and its inverse (zw). */
1015
+ _uniforms(e, t, s) {
1016
+ const r = this._data, i = e * D + T.size;
1017
+ return r[i] = t, r[i + 1] = s, r[i + 2] = 1 / t, r[i + 3] = 1 / s, r;
1018
+ }
1019
+ _vector(e, t, s, r = 0, i = 0, o = 0) {
1020
+ const n = this._data, a = e * D + T[t];
1021
+ n[a] = s, n[a + 1] = r, n[a + 2] = i, n[a + 3] = o;
1022
+ }
1023
+ _matrix(e, t, s) {
1024
+ this._data.set(s, e * D + T[t]);
1025
+ }
1026
+ _module(e, t) {
1027
+ let s = this._modules.get(e);
1028
+ return s || (s = this._device.createShaderModule({ code: t(), label: "nova3d-effect" }), this._modules.set(e, s)), s;
1029
+ }
1030
+ _layout(e) {
1031
+ const t = e.join();
1032
+ let s = this._layouts.get(t);
1033
+ if (!s) {
1034
+ const r = E.FRAGMENT;
1035
+ s = this._device.createBindGroupLayout({
1036
+ label: "nova3d-effect",
1037
+ entries: [
1038
+ { binding: 0, visibility: r, buffer: { type: "uniform", minBindingSize: N } },
1039
+ { binding: 1, visibility: r, sampler: { type: "filtering" } },
1040
+ ...e.map((i, o) => ({ binding: o + 2, visibility: r, texture: i === "depth" ? { sampleType: "depth" } : i === "lut" ? { sampleType: "float", viewDimension: "3d" } : { sampleType: "float" } }))
1041
+ ]
1042
+ }), this._layouts.set(t, s);
1043
+ }
1044
+ return s;
1045
+ }
1046
+ _pipeline(e, t, s, r) {
1047
+ const i = (e * 256 + t) * 8 + s;
1048
+ let o = this._pipelines.get(i);
1049
+ if (!o) {
1050
+ const n = Re[e], a = this._module(e * 256 + t, () => n.source(t)), l = this._layout(n.textures(t)), f = this._device, h = s === b.canvas ? r : [j.rgba16f, j.rgba8, j.rg8, j.r8][s];
1051
+ o = {
1052
+ layout: l,
1053
+ pipeline: f.createRenderPipeline({
1054
+ label: "nova3d-effect",
1055
+ layout: f.createPipelineLayout({ bindGroupLayouts: [l] }),
1056
+ vertex: { module: a, entryPoint: "vertexMain" },
1057
+ fragment: { module: a, entryPoint: "fragmentMain", targets: [{ format: h }] },
1058
+ primitive: { topology: "triangle-list" }
1059
+ })
1060
+ }, this._pipelines.set(i, o);
1061
+ }
1062
+ return o;
1063
+ }
1064
+ /** Cached bind group of a layout, uniform slot and up to three texture views. */
1065
+ _group(e, t, s, r, i) {
1066
+ const o = this._branch(this._branch(this._branch(this._branch(this._groups, e), t), s), r);
1067
+ let n = o.get(i);
1068
+ if (!n) {
1069
+ const a = [
1070
+ { binding: 0, resource: { buffer: this._buffer, offset: t * L, size: N } },
1071
+ { binding: 1, resource: this._sampler },
1072
+ { binding: 2, resource: s }
1073
+ ];
1074
+ r && a.push({ binding: 3, resource: r }), i && a.push({ binding: 4, resource: i }), n = this._device.createBindGroup({ layout: e, entries: a, label: "nova3d-effect" }), o.set(i, n);
1075
+ }
1076
+ return n;
1077
+ }
1078
+ _branch(e, t) {
1079
+ let s = e.get(t);
1080
+ return s || (s = /* @__PURE__ */ new Map(), e.set(t, s)), s;
1081
+ }
1082
+ /** One full-screen pass into `output`. */
1083
+ _run(e, t, s, r, i, o, n, a = null, l = null) {
1084
+ const f = this._pipeline(t, s, r, this._canvasFormat), h = this._group(f.layout, i, n, a, l);
1085
+ this._attachment.view = o;
1086
+ const v = e.beginRenderPass(this._pass);
1087
+ v.setPipeline(f.pipeline), v.setBindGroup(0, h), v.draw(3), v.end();
1088
+ }
1089
+ _resolveDepth(e, t, s) {
1090
+ const r = this._device;
1091
+ if (!this._resolve) {
1092
+ const n = r.createBindGroupLayout({ label: "nova3d-depth-resolve", entries: [{ binding: 0, visibility: E.FRAGMENT, texture: { sampleType: "depth", multisampled: !0 } }] }), a = r.createShaderModule({ code: Le, label: "nova3d-depth-resolve" }), l = r.createRenderPipeline({
1093
+ label: "nova3d-depth-resolve",
1094
+ layout: r.createPipelineLayout({ bindGroupLayouts: [n] }),
1095
+ vertex: { module: a, entryPoint: "vertexMain" },
1096
+ fragment: { module: a, entryPoint: "fragmentMain", targets: [] },
1097
+ primitive: { topology: "triangle-list" },
1098
+ depthStencil: { format: "depth24plus", depthWriteEnabled: !0, depthCompare: "always" }
1099
+ });
1100
+ this._resolve = { layout: n, pipeline: l, source: null, group: null };
1101
+ }
1102
+ const i = this._resolve;
1103
+ i.source !== t && (i.group = r.createBindGroup({ layout: i.layout, entries: [{ binding: 0, resource: t }], label: "nova3d-depth-resolve" }), i.source = t), this._depthAttachment.view = s;
1104
+ const o = e.beginRenderPass(this._depthPass);
1105
+ o.setPipeline(i.pipeline), o.setBindGroup(0, i.group), o.draw(3), o.end();
1106
+ }
1107
+ _ssao(e, t, s, r) {
1108
+ const i = this._plan.ssao, o = this._targets.get("aoA"), n = this._targets.get("aoB");
1109
+ return this._uniforms(u.ssao, o.width, o.height), this._matrix(u.ssao, "inverseProjection", this._inverseProjection), this._matrix(u.ssao, "projection", this._projection), this._vector(u.ssao, "a", i.radius, i.intensity, i.bias), this._run(e, x.ssao, i.samples, b.r8, u.ssao, o.view, s), this._uniforms(u.aoBlur, n.width, n.height), this._matrix(u.aoBlur, "inverseProjection", this._inverseProjection), this._vector(u.aoBlur, "a", i.radius), this._vector(u.aoBlur, "b", 1 / n.width, 0), this._run(e, x.aoBlur, 0, b.r8, u.aoBlur, n.view, o.view, s), this._uniforms(u.aoApply, r.width, r.height), this._matrix(u.aoApply, "inverseProjection", this._inverseProjection), this._vector(u.aoApply, "a", i.radius), this._vector(u.aoApply, "b", 0, 1 / r.height), this._run(e, x.aoApply, 0, b.rgba16f, u.aoApply, r.view, n.view, s, t), 3;
1110
+ }
1111
+ _ssr(e, t, s, r) {
1112
+ const i = this._plan.ssr;
1113
+ this._uniforms(u.ssr, r.width, r.height), this._matrix(u.ssr, "inverseProjection", this._inverseProjection), this._matrix(u.ssr, "projection", this._projection), this._vector(u.ssr, "a", i.maxDistance, i.thickness, i.intensity, i.edgeFade), this._run(e, x.ssr, i.steps, b.rgba16f, u.ssr, r.view, t, s);
1114
+ }
1115
+ _dof(e, t, s, r, i) {
1116
+ const o = this._plan.dof, n = o.focalLength / 1e3, a = n * i.height * Math.abs(r.projection[5]) / (2 * o.fStop * (o.focusDistance - n));
1117
+ this._uniforms(u.dof, i.width, i.height), this._matrix(u.dof, "inverseProjection", this._inverseProjection), this._vector(u.dof, "a", o.focusDistance, a, o.maxBlur * i.height), this._run(e, x.dof, o.samples, b.rgba16f, u.dof, i.view, t, s);
1118
+ }
1119
+ _taa(e, t, s, r) {
1120
+ const i = this._targets.get(this._historyParity === 0 ? "historyA" : "historyB"), o = this._targets.get(this._historyParity === 0 ? "historyB" : "historyA"), n = this._taaReprojection;
1121
+ return !this._historyValid || !M(n, r.viewProjection) ? R(n) : $(n, this._taaPrevious, n), this._uniforms(u.taa, i.width, i.height), this._matrix(u.taa, "matrix", n), this._vector(u.taa, "a", this._plan.taa.feedback, this._historyValid ? 0 : 1), this._run(e, x.taa, 0, b.rgba16f, u.taa, i.view, t, s, o.view), this._taaPrevious.set(r.viewProjection), this._historyValid = !0, this._historyParity ^= 1, i.view;
1122
+ }
1123
+ /** Updates the reprojection; false when the camera did not move since the last frame. */
1124
+ _motion(e) {
1125
+ if (this._previousStamp === e.stamp)
1126
+ return !1;
1127
+ const t = this._previousStamp === -1;
1128
+ if (this._previousStamp = e.stamp, !t) {
1129
+ const s = this._reprojection;
1130
+ M(s, e.viewProjection) ? $(s, this._previous, s) : R(s);
1131
+ }
1132
+ return this._previous.set(e.viewProjection), !t;
1133
+ }
1134
+ _motionBlur(e, t, s, r) {
1135
+ const i = this._plan.motionBlur;
1136
+ this._uniforms(u.motion, r.width, r.height), this._matrix(u.motion, "matrix", this._reprojection), this._vector(u.motion, "a", i.intensity), this._run(e, x.motion, i.samples, b.rgba16f, u.motion, r.view, t, s);
1137
+ }
1138
+ _bloom(e, t, s) {
1139
+ const r = this._plan.bloom, i = this._targets.get("bloomA"), o = this._targets.get("bloomB");
1140
+ return this._uniforms(u.bloomH, i.width, i.height), this._vector(u.bloomH, "a", r.threshold, 1), this._vector(u.bloomH, "b", 1 / i.width, 0), this._run(e, x.bloomBlur, 0, b.rgba16f, u.bloomH, i.view, t), this._uniforms(u.bloomV, o.width, o.height), this._vector(u.bloomV, "a", r.threshold, 0), this._vector(u.bloomV, "b", 0, 1 / o.height), this._run(e, x.bloomBlur, 0, b.rgba16f, u.bloomV, o.view, i.view), this._uniforms(u.bloomComposite, s.width, s.height), this._vector(u.bloomComposite, "a", r.strength), this._run(e, x.bloomComposite, 0, b.rgba16f, u.bloomComposite, s.view, t, o.view), 3;
1141
+ }
1142
+ _outline(e, t, s, r, i) {
1143
+ const o = this._plan.outline, n = this._targets.get("maskA"), a = this._targets.get("maskB"), l = this._maskPipelines(r.objectLayout);
1144
+ this._uniforms(u.mask, n.width, n.height), this._matrix(u.mask, "matrix", r.viewProjection);
1145
+ const f = this._maskGroup(l.layout, s);
1146
+ this._attachment.view = n.view;
1147
+ const h = e.beginRenderPass(this._pass);
1148
+ h.setBindGroup(0, f), h.setBindGroup(1, l.empty);
1149
+ let v = 0, _ = -1;
1150
+ const p = this._selection;
1151
+ for (let m = 0; m < p.length; m++) {
1152
+ const y = p[m];
1153
+ if (y.destroyed || y.scene !== r.scene || !y._effective("visible") || y.geometry.topology !== "triangles")
1154
+ continue;
1155
+ const A = y instanceof ee ? 1 : 0;
1156
+ _ !== A && (h.setPipeline(l.pipelines[A]), _ = A), r.draw(h, y) && v++;
1157
+ }
1158
+ return h.end(), v === 0 ? 0 : (this._uniforms(u.dilate, a.width, a.height), this._vector(u.dilate, "a", o.thickness), this._vector(u.dilate, "b", 1 / a.width, 0), this._run(e, x.dilate, 0, b.r8, u.dilate, a.view, n.view), this._uniforms(u.outline, i.width, i.height), this._vector(u.outline, "a", o.thickness), this._vector(u.outline, "b", 0, 1 / i.height), this._vector(u.outline, "c", o.color[0], o.color[1], o.color[2], o.color[3]), this._vector(u.outline, "d", o.hiddenColor[0], o.hiddenColor[1], o.hiddenColor[2], o.hiddenColor[3]), this._run(e, x.outline, 0, b.rgba16f, u.outline, i.view, a.view, t, n.view), v + 2);
1159
+ }
1160
+ _maskPipelines(e) {
1161
+ if (this._mask?.objectLayout === e)
1162
+ return this._mask;
1163
+ const t = this._device, s = t.createBindGroupLayout({ label: "nova3d-outline-mask", entries: [
1164
+ { binding: 0, visibility: E.VERTEX | E.FRAGMENT, buffer: { type: "uniform", minBindingSize: N } },
1165
+ { binding: 1, visibility: E.FRAGMENT, texture: { sampleType: "depth" } }
1166
+ ] }), r = t.createBindGroupLayout({ entries: [] }), i = t.createPipelineLayout({ bindGroupLayouts: [s, r, e] }), o = { operation: "max", srcFactor: "one", dstFactor: "one" }, n = [!1, !0].map((a) => {
1167
+ const l = t.createShaderModule({ code: Ee(a), label: "nova3d-outline-mask" }), f = [{ arrayStride: 12, attributes: [{ shaderLocation: 0, offset: 0, format: "float32x3" }] }];
1168
+ return a && f.push({ arrayStride: 64, stepMode: "instance", attributes: [0, 1, 2, 3].map((h) => ({ shaderLocation: 4 + h, offset: h * 16, format: "float32x4" })) }), t.createRenderPipeline({
1169
+ label: "nova3d-outline-mask",
1170
+ layout: i,
1171
+ vertex: { module: l, entryPoint: "vertexMain", buffers: f },
1172
+ fragment: { module: l, entryPoint: "fragmentMain", targets: [{ format: "r8unorm", blend: { color: o, alpha: o } }] },
1173
+ primitive: { topology: "triangle-list", cullMode: "none" }
1174
+ });
1175
+ });
1176
+ return this._mask = { layout: s, empty: t.createBindGroup({ layout: r, entries: [] }), objectLayout: e, pipelines: n }, this._mask;
1177
+ }
1178
+ _maskGroup(e, t) {
1179
+ let s = this._groups.get(e);
1180
+ s || (s = /* @__PURE__ */ new Map(), this._groups.set(e, s));
1181
+ let r = s.get(t);
1182
+ return r || (r = this._device.createBindGroup({ layout: e, entries: [{ binding: 0, resource: { buffer: this._buffer, offset: u.mask * L, size: N } }, { binding: 1, resource: t }], label: "nova3d-outline-mask" }), s.set(t, r)), r;
1183
+ }
1184
+ _finish(e, t, s, r, i, o, n) {
1185
+ const a = this._plan.finish, l = a.lut && !a.lut.texture.destroyed ? a.lut : void 0, f = (a.chromaticAberration > 0 ? 1 : 0) | (a.sharpen > 0 ? 2 : 0) | (l ? 4 : 0) | (a.vignette && a.vignette.intensity > 0 ? 8 : 0) | (a.grain > 0 ? 16 : 0), h = u.finish;
1186
+ this._uniforms(h, i, o), f & 16 && (this._grainFrame = (this._grainFrame + 1) % 4096), this._vector(h, "a", a.chromaticAberration, a.sharpen, a.grain, this._grainFrame * 7.31);
1187
+ const v = a.vignette;
1188
+ this._vector(h, "b", v?.intensity ?? 0, v?.radius ?? 0, v?.softness ?? 1, l?.intensity ?? 0), this._vector(h, "c", v?.color[0] ?? 0, v?.color[1] ?? 0, v?.color[2] ?? 0, n.exposure);
1189
+ let _ = null;
1190
+ if (l) {
1191
+ _ = this._lutView(l.texture);
1192
+ const p = l.texture._readSource().width, m = (p - 1) / p, y = l.domainMin, A = l.domainMax;
1193
+ this._vector(h, "d", m / (A[0] - y[0]), m / (A[1] - y[1]), m / (A[2] - y[2]), n.toneMapping), this._vector(h, "e", 0.5 / p - y[0] * m / (A[0] - y[0]), 0.5 / p - y[1] * m / (A[1] - y[1]), 0.5 / p - y[2] * m / (A[2] - y[2]));
1194
+ } else
1195
+ this._vector(h, "d", 1, 1, 1, n.toneMapping);
1196
+ this._run(e, x.finish, f, r, h, s, t, _);
1197
+ }
1198
+ /** 3D copy of the LUT texture (the scene texture cache holds 2D textures only). */
1199
+ _lutView(e) {
1200
+ const t = this._lut;
1201
+ if (t?.texture === e && t.version === e.version && t.content === e._contentVersion)
1202
+ return t.view;
1203
+ t?.gpu.destroy();
1204
+ const s = e._readSource(), r = s.format === "rgba16f", i = this._device.createTexture({ size: [s.width, s.height, s.depth], dimension: "3d", format: r ? "rgba16float" : "rgba8unorm", usage: k.TEXTURE_BINDING | k.COPY_DST, label: "nova3d-lut" });
1205
+ let o;
1206
+ if (r) {
1207
+ const n = s.data;
1208
+ o = new Uint16Array(n.length);
1209
+ for (let a = 0; a < n.length; a++)
1210
+ o[a] = ce(n[a]);
1211
+ } else
1212
+ o = s.data;
1213
+ return this._device.queue.writeTexture({ texture: i }, o, { bytesPerRow: s.width * (r ? 8 : 4), rowsPerImage: s.height }, [s.width, s.height, s.depth]), this._lut = { texture: e, version: e.version, content: e._contentVersion, gpu: i, view: i.createView({ dimension: "3d" }) }, this._lut.view;
1214
+ }
1215
+ _smaa(e, t, s, r, i) {
1216
+ const o = this._targets.get("edges"), n = this._targets.get("weights");
1217
+ this._uniforms(u.smaaEdges, s, r), this._vector(u.smaaEdges, "a", this._plan.smaa.threshold), this._run(e, x.smaaEdges, 0, b.rg8, u.smaaEdges, o.view, t.view), this._uniforms(u.smaaWeights, s, r), this._run(e, x.smaaWeights, 0, b.rgba8, u.smaaWeights, n.view, o.view), this._uniforms(u.smaaBlend, s, r), this._run(e, x.smaaBlend, 0, b.canvas, u.smaaBlend, i, t.view, n.view);
1218
+ }
1219
+ _releaseStale(e) {
1220
+ for (const [t, s] of this._targets)
1221
+ e.some((r) => r.key === t && r.width === s.width && r.height === s.height && r.format === s.format) || (s.texture.destroy(), this._bytes -= s.bytes, this._targets.delete(t), this._groups = /* @__PURE__ */ new Map());
1222
+ }
1223
+ _ensureTargets(e, t) {
1224
+ const s = this._device;
1225
+ this._buffer || (this._buffer = s.createBuffer({ size: W * L, usage: U.UNIFORM | U.COPY_DST, label: "nova3d-effects" }), this._sampler = s.createSampler({ magFilter: "linear", minFilter: "linear", addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge", addressModeW: "clamp-to-edge" }));
1226
+ const r = this._baseBytes(this._plan, e, t);
1227
+ if (e === this._width && t === this._height && this._layoutPlan === this._plan && this._layoutBase === r)
1228
+ return;
1229
+ this._width = e, this._height = t, this._layoutPlan = void 0, this._historyValid = !1;
1230
+ const i = z(this._plan, e, t, r, this._baseColors);
1231
+ this._releaseStale(i.targets);
1232
+ for (const o of i.targets) {
1233
+ if (this._targets.has(o.key))
1234
+ continue;
1235
+ const n = s.createTexture({ size: [o.width, o.height], format: j[o.format], usage: k.RENDER_ATTACHMENT | k.TEXTURE_BINDING, label: `nova3d-effect-${o.key}` });
1236
+ this._targets.set(o.key, { ...o, texture: n, view: n.createView() }), this._bytes += o.bytes;
1237
+ }
1238
+ this._groups = /* @__PURE__ */ new Map(), this._layoutPlan = this._plan, this._layoutBase = r;
1239
+ }
1240
+ }
1241
+ const Ce = `#version 300 es
1242
+ out vec2 uv;
1243
+ void main(){vec2 p=vec2(float((gl_VertexID<<1)&2),float(gl_VertexID&2));uv=p;gl_Position=vec4(p*2.0-1.0,0.0,1.0);}
1244
+ `, S = `#version 300 es
1245
+ precision highp float;
1246
+ precision highp sampler2D;
1247
+ in vec2 uv;
1248
+ out vec4 result;
1249
+ uniform sampler2D source;
1250
+ vec4 finiteHalf(vec4 value){return vec4(clamp(value.rgb,vec3(0.0),vec3(65504.0)),clamp(value.a,0.0,1.0));}
1251
+ `, Ve = `${S}
1252
+ uniform vec2 offset;
1253
+ uniform bool extractBright;
1254
+ uniform float threshold;
1255
+ vec4 sampleBright(vec2 coordinate){
1256
+ vec4 p=texture(source,coordinate);if(!extractBright)return p;
1257
+ vec3 straight=p.a>0.0?p.rgb/p.a:vec3(0.0);
1258
+ float brightness=dot(straight,vec3(0.2126,0.7152,0.0722));
1259
+ return p*max(0.0,(brightness-threshold)/max(brightness,1e-6));
1260
+ }
1261
+ void main(){
1262
+ vec4 p=sampleBright(uv)*0.2270270270;
1263
+ p+=(sampleBright(uv+offset)+sampleBright(uv-offset))*0.1945945946;
1264
+ p+=(sampleBright(uv+offset*2.0)+sampleBright(uv-offset*2.0))*0.1216216216;
1265
+ p+=(sampleBright(uv+offset*3.0)+sampleBright(uv-offset*3.0))*0.0540540541;
1266
+ p+=(sampleBright(uv+offset*4.0)+sampleBright(uv-offset*4.0))*0.0162162162;
1267
+ result=finiteHalf(p);
1268
+ }
1269
+ `, Oe = `${S}
1270
+ uniform sampler2D bloom;
1271
+ uniform float strength;
1272
+ void main(){result=finiteHalf(texture(source,uv)+texture(bloom,uv)*strength);}
1273
+ `, Ue = `${S}
1274
+ uniform vec2 inverseSize;
1275
+ float edgeLuma(vec4 p){return dot(p.rgb,vec3(0.299,0.587,0.114))+0.25*p.a;}
1276
+ void main(){
1277
+ vec4 center=texture(source,uv);
1278
+ float m=edgeLuma(center);
1279
+ float nw=edgeLuma(texture(source,uv+inverseSize*vec2(-1.0,-1.0)));
1280
+ float ne=edgeLuma(texture(source,uv+inverseSize*vec2(1.0,-1.0)));
1281
+ float sw=edgeLuma(texture(source,uv+inverseSize*vec2(-1.0,1.0)));
1282
+ float se=edgeLuma(texture(source,uv+inverseSize*vec2(1.0,1.0)));
1283
+ float low=min(m,min(min(nw,ne),min(sw,se)));
1284
+ float high=max(m,max(max(nw,ne),max(sw,se)));
1285
+ if(high-low<max(0.0312,high*0.125)){result=center;return;}
1286
+ vec2 direction=vec2(sw+se-nw-ne,nw+sw-ne-se);
1287
+ float reduction=max((nw+ne+sw+se)*0.03125,1.0/128.0);
1288
+ direction=clamp(direction/(min(abs(direction.x),abs(direction.y))+reduction),vec2(-8.0),vec2(8.0))*inverseSize;
1289
+ vec4 narrow=(texture(source,uv-direction/6.0)+texture(source,uv+direction/6.0))*0.5;
1290
+ vec4 wide=narrow*0.5+(texture(source,uv-direction*0.5)+texture(source,uv+direction*0.5))*0.25;
1291
+ float candidate=edgeLuma(wide);
1292
+ result=candidate<low||candidate>high?narrow:wide;
1293
+ }
1294
+ `, V = `
1295
+ uniform sampler2D depthMap;
1296
+ uniform mat4 inverseProjection;
1297
+ uniform vec2 inverseSize;
1298
+ float sceneDepth(vec2 c){return texture(depthMap,c).r;}
1299
+ vec3 viewPosition(vec2 c,float d){vec4 p=inverseProjection*vec4(vec3(c,d)*2.0-1.0,1.0);return p.xyz/p.w;}
1300
+ float viewZ(float d){vec2 v=inverseProjection[2].zw*(d*2.0-1.0)+inverseProjection[3].zw;return v.x/v.y;}
1301
+ vec3 viewNormal(vec2 c,vec3 p){
1302
+ vec3 l=viewPosition(c-vec2(inverseSize.x,0.0),sceneDepth(c-vec2(inverseSize.x,0.0)));
1303
+ vec3 r=viewPosition(c+vec2(inverseSize.x,0.0),sceneDepth(c+vec2(inverseSize.x,0.0)));
1304
+ vec3 b=viewPosition(c-vec2(0.0,inverseSize.y),sceneDepth(c-vec2(0.0,inverseSize.y)));
1305
+ vec3 t=viewPosition(c+vec2(0.0,inverseSize.y),sceneDepth(c+vec2(0.0,inverseSize.y)));
1306
+
1307
+ vec3 dx=abs(l.z-p.z)<abs(r.z-p.z)?p-l:r-p;
1308
+ vec3 dy=abs(b.z-p.z)<abs(t.z-p.z)?p-b:t-p;
1309
+ return normalize(cross(dx,dy));
1310
+ }
1311
+ float gradientNoise(vec2 p){return fract(52.9829189*fract(dot(p,vec2(0.06711056,0.00583715))));}
1312
+ `;
1313
+ function Ie(c) {
1314
+ return `${S}#define SAMPLES ${c}
1315
+ ${V}
1316
+ uniform mat4 projection;
1317
+ uniform float radius;
1318
+ uniform float intensity;
1319
+ uniform float bias;
1320
+ void main(){
1321
+ float d=sceneDepth(uv);
1322
+ if(d>=1.0){result=vec4(1.0);return;}
1323
+ vec3 p=viewPosition(uv,d);
1324
+ vec3 n=viewNormal(uv,p);
1325
+ vec4 edge=projection*vec4(p+vec3(0.0,radius,0.0),1.0);
1326
+ vec4 centre=projection*vec4(p,1.0);
1327
+ float screenRadius=min(abs(edge.y/edge.w-centre.y/centre.w)*0.5,0.25);
1328
+ float aspect=inverseSize.x/inverseSize.y;
1329
+ float angle=gradientNoise(gl_FragCoord.xy)*6.2831853;
1330
+ float radius2=radius*radius;
1331
+ float sum=0.0;
1332
+ for(int i=0;i<SAMPLES;i++){
1333
+ float t=(float(i)+0.5)/float(SAMPLES);
1334
+ float a=angle+t*43.982297;
1335
+ vec2 c=uv+vec2(cos(a)*aspect,sin(a))*(t*screenRadius);
1336
+ vec3 v=viewPosition(c,sceneDepth(c))-p;
1337
+ float vv=dot(v,v);
1338
+ float f=max(radius2-vv,0.0);
1339
+ sum+=f*f*f*max((dot(v,n)-bias)/(0.01+vv),0.0);
1340
+ }
1341
+ float ao=max(0.0,1.0-sum*intensity/(radius2*radius2*radius2)*(5.0/float(SAMPLES)));
1342
+ result=vec4(ao);
1343
+ }
1344
+ `;
1345
+ }
1346
+ function K(c) {
1347
+ return `${S}${c ? `#define APPLY
1348
+ uniform sampler2D colorMap;` : ""}
1349
+ ${V}
1350
+ uniform vec2 offset;
1351
+ uniform float radius;
1352
+ void main(){
1353
+ float z=viewZ(sceneDepth(uv));
1354
+ float sum=0.0;
1355
+ float total=0.0;
1356
+ for(int i=-4;i<=4;i++){
1357
+ vec2 c=uv+offset*float(i);
1358
+ float w=exp(-float(i*i)/8.0)*max(0.0,1.0-abs(viewZ(sceneDepth(c))-z)/(radius*0.5));
1359
+ sum+=texture(source,c).r*w;
1360
+ total+=w;
1361
+ }
1362
+ float ao=total>0.0?sum/total:texture(source,uv).r;
1363
+ #ifdef APPLY
1364
+ vec4 p=texture(colorMap,uv);
1365
+ result=vec4(p.rgb*ao,p.a);
1366
+ #else
1367
+ result=vec4(ao);
1368
+ #endif
1369
+ }
1370
+ `;
1371
+ }
1372
+ function Ge(c) {
1373
+ return `${S}#define STEPS ${c}
1374
+ ${V}
1375
+ uniform mat4 projection;
1376
+ uniform float maxDistance;
1377
+ uniform float thickness;
1378
+ uniform float intensity;
1379
+ uniform float edgeFade;
1380
+ vec2 project(vec3 q){vec4 c=projection*vec4(q,1.0);return c.xy/c.w*0.5+0.5;}
1381
+ void main(){
1382
+ vec4 color=texture(source,uv);
1383
+ float d=sceneDepth(uv);
1384
+ if(d>=1.0){result=color;return;}
1385
+ vec3 p=viewPosition(uv,d);
1386
+ vec3 n=viewNormal(uv,p);
1387
+ vec3 view=projection[2].w==0.0?vec3(0.0,0.0,-1.0):normalize(p);
1388
+ vec3 r=reflect(view,n);
1389
+ vec3 stepVector=r*(maxDistance/float(STEPS));
1390
+ vec3 q=p+stepVector*(0.5+gradientNoise(gl_FragCoord.xy));
1391
+ vec2 hit=vec2(-1.0);
1392
+ float travelled=0.0;
1393
+ for(int i=0;i<STEPS;i++){
1394
+ vec2 c=project(q);
1395
+ if(c.x<0.0||c.x>1.0||c.y<0.0||c.y>1.0)break;
1396
+ float depthGap=viewZ(sceneDepth(c))-q.z;
1397
+ if(depthGap>0.0&&depthGap<thickness){
1398
+ vec3 a=q-stepVector;
1399
+ vec3 b=q;
1400
+ for(int k=0;k<4;k++){
1401
+ vec3 m=(a+b)*0.5;
1402
+ if(viewZ(sceneDepth(project(m)))-m.z>0.0)b=m;else a=m;
1403
+ }
1404
+ hit=project(b);
1405
+ travelled=float(i)/float(STEPS);
1406
+ break;
1407
+ }
1408
+ q+=stepVector;
1409
+ }
1410
+ if(hit.x<0.0){result=color;return;}
1411
+ vec2 border=min(hit,1.0-hit);
1412
+ float fade=(edgeFade>0.0?clamp(min(border.x,border.y)/edgeFade,0.0,1.0):1.0)*(1.0-travelled*travelled);
1413
+ result=finiteHalf(mix(color,texture(source,hit),intensity*fade));
1414
+ }
1415
+ `;
1416
+ }
1417
+ function He(c) {
1418
+ return `${S}#define SAMPLES ${c}
1419
+ ${V}
1420
+ uniform float focusDistance;
1421
+ uniform float cocScale;
1422
+ uniform float maxBlur;
1423
+ float coc(float z){return min(abs(z-focusDistance)/max(z,1e-4)*cocScale,maxBlur);}
1424
+ void main(){
1425
+ vec4 centre=texture(source,uv);
1426
+ float centreZ=-viewZ(sceneDepth(uv));
1427
+ float centreCoc=coc(centreZ);
1428
+ vec4 sum=centre;
1429
+ float total=1.0;
1430
+ for(int i=0;i<SAMPLES;i++){
1431
+ float t=(float(i)+0.5)/float(SAMPLES);
1432
+ float r=sqrt(t)*maxBlur;
1433
+ float a=float(i)*2.39996323;
1434
+
1435
+ vec2 texel=floor(gl_FragCoord.xy+vec2(cos(a),sin(a))*r)+0.5;
1436
+ vec2 c=texel*inverseSize;
1437
+ float distance=length(texel-gl_FragCoord.xy);
1438
+ float z=-viewZ(sceneDepth(c));
1439
+ float size=coc(z);
1440
+
1441
+ if(z>centreZ)size=min(size,centreCoc*2.0);
1442
+ float w=smoothstep(distance-0.5,distance+0.5,size);
1443
+ sum+=texture(source,c)*w;
1444
+ total+=w;
1445
+ }
1446
+ result=finiteHalf(sum/total);
1447
+ }
1448
+ `;
1449
+ }
1450
+ function Xe(c) {
1451
+ return `${S}#define SAMPLES ${c}
1452
+ uniform sampler2D depthMap;
1453
+ uniform mat4 reprojection;
1454
+ uniform float intensity;
1455
+ void main(){
1456
+ vec4 previous=reprojection*vec4(vec3(uv,texture(depthMap,uv).r)*2.0-1.0,1.0);
1457
+ vec2 velocity=(uv-(previous.xy/previous.w*0.5+0.5))*intensity;
1458
+ float speed=length(velocity);
1459
+ if(speed<1e-5){result=texture(source,uv);return;}
1460
+ velocity*=min(1.0,0.1/speed);
1461
+ vec4 sum=vec4(0.0);
1462
+ for(int i=0;i<SAMPLES;i++){
1463
+ sum+=texture(source,uv-velocity*(float(i)/float(SAMPLES-1)-0.5));
1464
+ }
1465
+ result=finiteHalf(sum/float(SAMPLES));
1466
+ }
1467
+ `;
1468
+ }
1469
+ const qe = `#version 300 es
1470
+ precision highp float;
1471
+ precision highp int;
1472
+ __INSTANCE__
1473
+ precision highp sampler2D;
1474
+ in vec2 texCoord;
1475
+ uniform sampler2D depthMap;
1476
+ uniform vec2 inverseSize;
1477
+ out vec4 result;
1478
+ void main(){cullInstance();result=vec4(gl_FragCoord.z<=texture(depthMap,gl_FragCoord.xy*inverseSize).r+2e-4?1.0:0.5);}
1479
+ `;
1480
+ function J(c) {
1481
+ return `${S}${c ? `#define COMPOSITE
1482
+ uniform sampler2D colorMap;
1483
+ uniform sampler2D maskMap;
1484
+ uniform vec4 color;
1485
+ uniform vec4 hiddenColor;` : ""}
1486
+ uniform vec2 offset;
1487
+ uniform int thickness;
1488
+ void main(){
1489
+ float m=0.0;
1490
+ for(int i=-8;i<=8;i++){
1491
+ if(i<-thickness||i>thickness)continue;
1492
+ m=max(m,texture(source,uv+offset*float(i)).r);
1493
+ }
1494
+ #ifdef COMPOSITE
1495
+ vec4 p=texture(colorMap,uv);
1496
+ if(m<0.25||texture(maskMap,uv).r>0.25){result=p;return;}
1497
+ vec4 edge=m>0.75?color:hiddenColor;
1498
+ result=finiteHalf(vec4(edge.rgb*edge.a,edge.a)+p*(1.0-edge.a));
1499
+ #else
1500
+ result=vec4(m);
1501
+ #endif
1502
+ }
1503
+ `;
1504
+ }
1505
+ function Ze(c, e) {
1506
+ const t = ["ABERRATION", "SHARPEN", "LUT", "VIGNETTE", "GRAIN"].filter((s, r) => c & 1 << r).map((s) => `#define ${s}
1507
+ `).join("");
1508
+ return `${S}${t}precision highp sampler3D;
1509
+ uniform float exposure;
1510
+ uniform int toneMapping;
1511
+ uniform vec2 inverseSize;
1512
+ uniform float aberration;
1513
+ uniform float sharpen;
1514
+ uniform sampler3D lut;
1515
+ uniform vec3 lutScale;
1516
+ uniform vec3 lutOffset;
1517
+ uniform float lutIntensity;
1518
+ uniform vec3 vignette;
1519
+ uniform vec3 vignetteColor;
1520
+ uniform float grain;
1521
+ uniform float seed;
1522
+ ${e}
1523
+ vec3 displayed(vec4 p){return p.a>0.0?novaToneMap(p.rgb/p.a,exposure,toneMapping):vec3(0.0);}
1524
+ vec3 encoded(vec4 p){return novaEncodeSRGB(displayed(p));}
1525
+ void main(){
1526
+ vec4 p=texture(source,uv);
1527
+ #ifdef ABERRATION
1528
+ vec2 shift=(uv-0.5)*aberration*2.0;
1529
+ vec4 red=texture(source,uv+shift);
1530
+ vec4 blue=texture(source,uv-shift);
1531
+
1532
+ p=vec4(vec3(red.a>0.0?red.r/red.a:0.0,p.a>0.0?p.g/p.a:0.0,blue.a>0.0?blue.b/blue.a:0.0)*p.a,p.a);
1533
+ #endif
1534
+ vec3 e=encoded(p);
1535
+ #ifdef SHARPEN
1536
+
1537
+ vec3 c=e;
1538
+ vec3 north=encoded(texture(source,uv+vec2(0.0,inverseSize.y)));
1539
+ vec3 south=encoded(texture(source,uv-vec2(0.0,inverseSize.y)));
1540
+ vec3 east=encoded(texture(source,uv+vec2(inverseSize.x,0.0)));
1541
+ vec3 west=encoded(texture(source,uv-vec2(inverseSize.x,0.0)));
1542
+ vec3 low=min(c,min(min(north,south),min(east,west)));
1543
+ vec3 high=max(c,max(max(north,south),max(east,west)));
1544
+ vec3 amplitude=sqrt(clamp(min(low,1.0-high)/max(high,vec3(1e-5)),0.0,1.0));
1545
+ vec3 weight=-amplitude/mix(8.0,5.0,sharpen);
1546
+ e=clamp((c+(north+south+east+west)*weight)/(1.0+4.0*weight),0.0,1.0);
1547
+ #endif
1548
+ #ifdef LUT
1549
+ e=mix(e,texture(lut,clamp(e*lutScale+lutOffset,0.0,1.0)).rgb,lutIntensity);
1550
+ #endif
1551
+ #ifdef VIGNETTE
1552
+ e=mix(e,vignetteColor,smoothstep(vignette.y,vignette.y+vignette.z,length(uv-0.5)*2.0)*vignette.x);
1553
+ #endif
1554
+ #ifdef GRAIN
1555
+ e+=(fract(sin(dot(gl_FragCoord.xy+seed,vec2(12.9898,78.233)))*43758.5453)-0.5)*grain;
1556
+ #endif
1557
+ result=vec4(clamp(e,0.0,1.0)*p.a,p.a);
1558
+ }
1559
+ `;
1560
+ }
1561
+ const We = "float luma(vec4 p){return dot(p.rgb,vec3(0.2126,0.7152,0.0722))+0.25*p.a;}", Ye = `${S}
1562
+ uniform vec2 inverseSize;
1563
+ uniform float threshold;
1564
+ ${We}
1565
+ float at(vec2 o){return luma(texture(source,uv+o*inverseSize));}
1566
+ void main(){
1567
+ float l=at(vec2(0.0));
1568
+ float left=at(vec2(-1.0,0.0));
1569
+ float bottom=at(vec2(0.0,-1.0));
1570
+ vec2 delta=abs(l-vec2(left,bottom));
1571
+ vec2 edges=step(threshold,delta);
1572
+ if(edges.x+edges.y==0.0){result=vec4(0.0);return;}
1573
+ vec2 most=max(delta,abs(l-vec2(at(vec2(1.0,0.0)),at(vec2(0.0,1.0)))));
1574
+ most=max(most,abs(vec2(left,bottom)-vec2(at(vec2(-2.0,0.0)),at(vec2(0.0,-2.0)))));
1575
+ edges*=step(max(most.x,most.y),2.0*delta);
1576
+ result=vec4(edges,0.0,1.0);
1577
+ }
1578
+ `, Ke = `${S}
1579
+ #define MAX_SEARCH 16
1580
+ ivec2 limit;
1581
+ vec2 edgeAt(ivec2 p){return texelFetch(source,clamp(p,ivec2(0),limit),0).rg;}
1582
+
1583
+ vec2 segmentArea(vec2 p0,vec2 p1,float a,float b){
1584
+ a=max(a,p0.x);b=min(b,p1.x);
1585
+ if(b<=a)return vec2(0.0);
1586
+ float slope=(p1.y-p0.y)/(p1.x-p0.x);
1587
+ float ya=p0.y+slope*(a-p0.x);
1588
+ float yb=p0.y+slope*(b-p0.x);
1589
+ if(ya*yb>=0.0){float m=(ya+yb)*0.5*(b-a);return m>0.0?vec2(m,0.0):vec2(0.0,-m);}
1590
+ float z=a+(b-a)*ya/(ya-yb);
1591
+ float first=ya*(z-a)*0.5;
1592
+ float second=yb*(b-z)*0.5;
1593
+ return vec2(max(first,0.0)+max(second,0.0),max(-first,0.0)+max(-second,0.0));
1594
+ }
1595
+ vec2 lineArea(float h1,float h2,float len,float i){
1596
+ if(h1!=0.0&&h2!=0.0&&h1!=h2)return segmentArea(vec2(0.0,h1),vec2(len,h2),i,i+1.0);
1597
+ vec2 area=vec2(0.0);
1598
+ if(h1!=0.0)area+=segmentArea(vec2(0.0,h1),vec2(len*0.5,0.0),i,i+1.0);
1599
+ if(h2!=0.0)area+=segmentArea(vec2(len*0.5,0.0),vec2(len,h2),i,i+1.0);
1600
+ return area;
1601
+ }
1602
+ float crossing(float own,float other){return own>0.5&&other<0.5?0.5:other>0.5&&own<0.5?-0.5:0.0;}
1603
+ void main(){
1604
+ limit=textureSize(source,0)-1;
1605
+ ivec2 p=ivec2(gl_FragCoord.xy);
1606
+ vec2 e=edgeAt(p);
1607
+ vec4 weights=vec4(0.0);
1608
+ if(e.x>0.5){
1609
+ int up=0;int down=0;
1610
+ for(int k=1;k<=MAX_SEARCH;k++){if(edgeAt(p+ivec2(0,k)).x<0.5)break;up=k;}
1611
+ for(int k=1;k<=MAX_SEARCH;k++){if(edgeAt(p-ivec2(0,k)).x<0.5)break;down=k;}
1612
+ ivec2 bottom=p-ivec2(0,down);
1613
+ ivec2 top=p+ivec2(0,up+1);
1614
+ float h1=down==MAX_SEARCH?0.0:crossing(edgeAt(bottom).y,edgeAt(bottom-ivec2(1,0)).y);
1615
+ float h2=up==MAX_SEARCH?0.0:crossing(edgeAt(top).y,edgeAt(top-ivec2(1,0)).y);
1616
+ weights.rg=lineArea(h1,h2,float(up+down+1),float(down));
1617
+ }
1618
+ if(e.y>0.5){
1619
+ int right=0;int left=0;
1620
+ for(int k=1;k<=MAX_SEARCH;k++){if(edgeAt(p+ivec2(k,0)).y<0.5)break;right=k;}
1621
+ for(int k=1;k<=MAX_SEARCH;k++){if(edgeAt(p-ivec2(k,0)).y<0.5)break;left=k;}
1622
+ ivec2 start=p-ivec2(left,0);
1623
+ ivec2 end=p+ivec2(right+1,0);
1624
+ float h1=left==MAX_SEARCH?0.0:crossing(edgeAt(start).x,edgeAt(start-ivec2(0,1)).x);
1625
+ float h2=right==MAX_SEARCH?0.0:crossing(edgeAt(end).x,edgeAt(end-ivec2(0,1)).x);
1626
+ weights.ba=lineArea(h1,h2,float(left+right+1),float(left));
1627
+ }
1628
+ result=weights;
1629
+ }
1630
+ `, Je = `${S}
1631
+ uniform sampler2D weightMap;
1632
+ void main(){
1633
+ ivec2 limit=textureSize(source,0)-1;
1634
+ ivec2 p=ivec2(gl_FragCoord.xy);
1635
+ vec4 w=texelFetch(weightMap,p,0);
1636
+ float left=w.r;
1637
+ float right=texelFetch(weightMap,min(p+ivec2(1,0),limit),0).g;
1638
+ float below=w.b;
1639
+ float above=texelFetch(weightMap,min(p+ivec2(0,1),limit),0).a;
1640
+ vec4 c=texelFetch(source,p,0);
1641
+ if(max(left,right)+max(below,above)<1e-5){result=c;return;}
1642
+ if(max(left,right)>=max(below,above)){
1643
+ result=c*(1.0-left-right)+texelFetch(source,max(p-ivec2(1,0),ivec2(0)),0)*left+texelFetch(source,min(p+ivec2(1,0),limit),0)*right;
1644
+ }
1645
+ else{
1646
+ result=c*(1.0-below-above)+texelFetch(source,max(p-ivec2(0,1),ivec2(0)),0)*below+texelFetch(source,min(p+ivec2(0,1),limit),0)*above;
1647
+ }
1648
+ }
1649
+ `, Qe = `${S}
1650
+ uniform sampler2D depthMap;
1651
+ uniform sampler2D colorMap;
1652
+ uniform mat4 reprojection;
1653
+ uniform vec2 inverseSize;
1654
+ uniform float feedback;
1655
+ uniform bool resetHistory;
1656
+ void main(){
1657
+ vec4 current=texture(source,uv);
1658
+ vec4 low=current,high=current;
1659
+ for(int y=-1;y<=1;y++){
1660
+ for(int x=-1;x<=1;x++){
1661
+ vec4 neighbour=texture(source,uv+vec2(float(x),float(y))*inverseSize);
1662
+ low=min(low,neighbour);
1663
+ high=max(high,neighbour);
1664
+ }
1665
+ }
1666
+ vec4 previous=reprojection*vec4(vec3(uv,texture(depthMap,uv).r)*2.0-1.0,1.0);
1667
+ vec2 previousUV=previous.xy/previous.w*0.5+0.5;
1668
+ if(resetHistory||any(lessThan(previousUV,vec2(0.0)))||any(greaterThan(previousUV,vec2(1.0)))){result=finiteHalf(current);return;}
1669
+ vec4 history=clamp(texture(colorMap,previousUV),low,high);
1670
+ result=finiteHalf(mix(current,history,feedback));
1671
+ }
1672
+ `, et = [["source", 0], ["depthMap", 1], ["colorMap", 2], ["bloom", 2], ["weightMap", 2], ["maskMap", 3], ["lut", 4]], tt = {
1673
+ rgba16f: ["RGBA16F", "RGBA", "HALF_FLOAT"],
1674
+ rgba8: ["RGBA8", "RGBA", "UNSIGNED_BYTE"],
1675
+ rg8: ["RG8", "RG", "UNSIGNED_BYTE"],
1676
+ r8: ["R8", "RED", "UNSIGNED_BYTE"]
1677
+ };
1678
+ function Q(c, e) {
1679
+ let t = 0, s = 1 / e;
1680
+ for (let r = c; r > 0; r = Math.floor(r / e))
1681
+ t += r % e * s, s /= e;
1682
+ return t;
1683
+ }
1684
+ class it {
1685
+ constructor(e, t) {
1686
+ this._gl = e, this._plan = t;
1687
+ }
1688
+ _targets = /* @__PURE__ */ new Map();
1689
+ _programs = /* @__PURE__ */ new Map();
1690
+ _bytes = 0;
1691
+ _basePerPixel = 0;
1692
+ _depthPerPixel = 0;
1693
+ _baseColors = 1;
1694
+ /** Advances on configure and on target size changes; static uniforms follow it. */
1695
+ _version = 0;
1696
+ _width = 0;
1697
+ _height = 0;
1698
+ /** Plan and base bytes the resident targets were last validated for at `_width`×`_height`. */
1699
+ _layoutPlan;
1700
+ _layoutBase = -1;
1701
+ /** Scene colour texture whose sampler was switched to linear filtering. */
1702
+ _linearSource;
1703
+ _cameraStamp = -1;
1704
+ _inverseProjection = new Float32Array(16);
1705
+ /** Motion blur: view-projection of the previous presented frame. */
1706
+ _previous = new Float32Array(16);
1707
+ _previousStamp = -1;
1708
+ _reprojection = new Float32Array(16);
1709
+ _grainFrame = 0;
1710
+ _selection = [];
1711
+ /** Projection of the current camera, a view of the renderer's frame record. */
1712
+ _projection = this._inverseProjection;
1713
+ /** Output of the most recent pass into an effect target. */
1714
+ _last;
1715
+ /** TAA: jitter sample index, history parity, previous unjittered view-projection. */
1716
+ _jitterIndex = 0;
1717
+ _jitter = new Float32Array(2);
1718
+ _historyParity = 0;
1719
+ _historyValid = !1;
1720
+ _taaPrevious = new Float32Array(16);
1721
+ _taaReprojection = new Float32Array(16);
1722
+ get bytes() {
1723
+ return this._bytes;
1724
+ }
1725
+ get depth() {
1726
+ return this._plan.depth;
1727
+ }
1728
+ /** Sub-pixel projection offset for the next frame (device pixels), or null without TAA. */
1729
+ jitter() {
1730
+ if (!this._plan.taa)
1731
+ return null;
1732
+ const e = this._jitterIndex++ % 8 + 1;
1733
+ return this._jitter[0] = Q(e, 2) - 0.5, this._jitter[1] = Q(e, 3) - 0.5, this._jitter;
1734
+ }
1735
+ validateSize(e, t, s, r, i) {
1736
+ z(this._plan, e, t, s + (this._plan.depth ? i : 0), r), this._basePerPixel = s / (e * t), this._depthPerPixel = i / (e * t), this._baseColors = r;
1737
+ }
1738
+ configure(e) {
1739
+ if (this._gl.isContextLost())
1740
+ throw new d("state", "[Nova3D] Configure effects after context restoration.");
1741
+ const t = this._gl.drawingBufferWidth, s = this._gl.drawingBufferHeight, r = z(e, t, s, this._baseBytes(e, t, s), this._baseColors);
1742
+ this._plan = e, this._version++, this._previousStamp = -1, this._historyValid = !1, this._releaseStale(r.targets);
1743
+ }
1744
+ /** Replaces the outline selection; the array is owned by the caller's copy. */
1745
+ select(e) {
1746
+ this._selection = e;
1747
+ }
1748
+ present(e, t, s, r, i) {
1749
+ this._ensureTargets(t, s);
1750
+ const o = this._gl, n = this._plan;
1751
+ this._linearSource !== e && (o.activeTexture(o.TEXTURE0), o.bindTexture(o.TEXTURE_2D, e), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MIN_FILTER, o.LINEAR), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MAG_FILTER, o.LINEAR), this._linearSource = e), this._projection = i.projection, i.scene && i.stamp !== this._cameraStamp && (M(this._inverseProjection, i.projection), this._cameraStamp = i.stamp, this._version++), this._common();
1752
+ const a = i.scene !== null && i.depth !== null;
1753
+ let l = e, f = 0;
1754
+ if (n.ssao && a && (f += this._ssao(l, i.depth, this._next(l)), l = this._last), n.ssr && a && (this._ssr(l, i.depth, this._next(l)), l = this._last, f++), n.taa && a ? (this._taa(l, i), l = this._last, f++) : n.taa && (this._historyValid = !1), n.dof && a && (this._dof(l, i, this._next(l)), l = this._last, f++), n.motionBlur && a && this._motion(i) && (this._motionBlur(l, i.depth, this._next(l)), l = this._last, f++), n.bloom && (f += this._bloom(l, this._next(l)), l = this._last), n.outline && a && this._selection.length > 0) {
1755
+ const v = this._outline(l, i, this._next(l));
1756
+ v > 0 && (l = this._last, f += v);
1757
+ }
1758
+ const h = n.fxaa || n.smaa ? this._targets.get("encoded") : null;
1759
+ return n.finish ? this._finish(l, h, t, s, i) : (r(l, h ? h.framebuffer : null), this._common()), f++, n.fxaa ? (this._fxaa(h, t, s), f++) : n.smaa && (this._smaa(h, t, s), f += 3), f;
1760
+ }
1761
+ reset(e) {
1762
+ if (!e) {
1763
+ for (const t of this._targets.values())
1764
+ this._release(t);
1765
+ for (const t of this._programs.values())
1766
+ this._gl.deleteProgram(t.program);
1767
+ }
1768
+ this._targets.clear(), this._programs.clear(), this._bytes = 0, this._layoutPlan = void 0, this._linearSource = void 0, this._cameraStamp = -1, this._previousStamp = -1, this._historyValid = !1;
1769
+ }
1770
+ /** Linear ping-pong target that does not hold `current`. */
1771
+ _next(e) {
1772
+ const t = this._targets.get("linear");
1773
+ return t.texture === e ? this._targets.get("linearB") : t;
1774
+ }
1775
+ _baseBytes(e, t, s) {
1776
+ return t * s * (this._basePerPixel + (e.depth ? this._depthPerPixel : 0));
1777
+ }
1778
+ _common() {
1779
+ const e = this._gl;
1780
+ e.disable(e.DEPTH_TEST), e.disable(e.BLEND), e.disable(e.CULL_FACE), e.disable(e.SCISSOR_TEST), e.colorMask(!0, !0, !0, !0), e.bindVertexArray(null);
1781
+ }
1782
+ _program(e, t, s = Ce) {
1783
+ let r = this._programs.get(e);
1784
+ if (!r) {
1785
+ const i = this._gl, o = fe(i, s, t());
1786
+ r = { program: o, locations: /* @__PURE__ */ new Map(), version: -1 }, i.useProgram(o);
1787
+ for (const [n, a] of et) {
1788
+ const l = i.getUniformLocation(o, n);
1789
+ l && i.uniform1i(l, a);
1790
+ }
1791
+ this._programs.set(e, r);
1792
+ }
1793
+ return r;
1794
+ }
1795
+ _u(e, t) {
1796
+ let s = e.locations.get(t);
1797
+ return s === void 0 && (s = this._gl.getUniformLocation(e.program, t), e.locations.set(t, s)), s;
1798
+ }
1799
+ /** Binds the output and program; returns true when static uniforms must be written. */
1800
+ _begin(e, t, s, r) {
1801
+ const i = this._gl;
1802
+ return i.bindFramebuffer(i.FRAMEBUFFER, t ? t.framebuffer : null), i.viewport(0, 0, t ? t.width : s, t ? t.height : r), i.useProgram(e.program), e.version !== this._version ? (e.version = this._version, !0) : !1;
1803
+ }
1804
+ _bind(e, t, s = this._gl.TEXTURE_2D) {
1805
+ const r = this._gl;
1806
+ r.activeTexture(r.TEXTURE0 + e), r.bindTexture(s, t);
1807
+ }
1808
+ _draw(e) {
1809
+ const t = this._gl;
1810
+ t.drawArrays(t.TRIANGLES, 0, 3), e && (this._last = e.texture);
1811
+ }
1812
+ /** Writes inverse size and inverse projection, shared by the depth helpers. */
1813
+ _depthUniforms(e, t, s) {
1814
+ const r = this._gl;
1815
+ r.uniform2f(this._u(e, "inverseSize"), 1 / t, 1 / s), r.uniformMatrix4fv(this._u(e, "inverseProjection"), !1, this._inverseProjection);
1816
+ }
1817
+ _ssao(e, t, s) {
1818
+ const r = this._gl, i = this._plan.ssao, o = this._targets.get("aoA"), n = this._targets.get("aoB"), a = this._program(`ssao${i.samples}`, () => Ie(i.samples));
1819
+ this._begin(a, o, 0, 0) && (this._depthUniforms(a, o.width, o.height), r.uniformMatrix4fv(this._u(a, "projection"), !1, this._projection), r.uniform1f(this._u(a, "radius"), i.radius), r.uniform1f(this._u(a, "intensity"), i.intensity), r.uniform1f(this._u(a, "bias"), i.bias)), this._bind(1, t), this._draw(o);
1820
+ const l = this._program("aoBlur", () => K(!1));
1821
+ this._begin(l, n, 0, 0) && (this._depthUniforms(l, n.width, n.height), r.uniform2f(this._u(l, "offset"), 1 / n.width, 0), r.uniform1f(this._u(l, "radius"), i.radius)), this._bind(0, o.texture), this._draw(n);
1822
+ const f = this._program("aoApply", () => K(!0));
1823
+ return this._begin(f, s, 0, 0) && (this._depthUniforms(f, s.width, s.height), r.uniform2f(this._u(f, "offset"), 0, 1 / s.height), r.uniform1f(this._u(f, "radius"), i.radius)), this._bind(0, n.texture), this._bind(2, e), this._draw(s), 3;
1824
+ }
1825
+ _ssr(e, t, s) {
1826
+ const r = this._gl, i = this._plan.ssr, o = this._program(`ssr${i.steps}`, () => Ge(i.steps));
1827
+ this._begin(o, s, 0, 0) && (this._depthUniforms(o, s.width, s.height), r.uniformMatrix4fv(this._u(o, "projection"), !1, this._projection), r.uniform1f(this._u(o, "maxDistance"), i.maxDistance), r.uniform1f(this._u(o, "thickness"), i.thickness), r.uniform1f(this._u(o, "intensity"), i.intensity), r.uniform1f(this._u(o, "edgeFade"), i.edgeFade)), this._bind(0, e), this._bind(1, t), this._draw(s);
1828
+ }
1829
+ _dof(e, t, s) {
1830
+ const r = this._gl, i = this._plan.dof, o = this._program(`dof${i.samples}`, () => He(i.samples));
1831
+ if (this._begin(o, s, 0, 0)) {
1832
+ this._depthUniforms(o, s.width, s.height);
1833
+ const n = i.focalLength / 1e3, a = n * s.height * Math.abs(t.projection[5]) / (2 * i.fStop * (i.focusDistance - n));
1834
+ r.uniform1f(this._u(o, "focusDistance"), i.focusDistance), r.uniform1f(this._u(o, "cocScale"), a), r.uniform1f(this._u(o, "maxBlur"), i.maxBlur * s.height);
1835
+ }
1836
+ this._bind(0, e), this._bind(1, t.depth), this._draw(s);
1837
+ }
1838
+ _taa(e, t) {
1839
+ const s = this._gl, r = this._targets.get(this._historyParity === 0 ? "historyA" : "historyB"), i = this._targets.get(this._historyParity === 0 ? "historyB" : "historyA"), o = this._taaReprojection;
1840
+ !this._historyValid || !M(o, t.viewProjection) ? R(o) : $(o, this._taaPrevious, o);
1841
+ const n = this._program("taa", () => Qe);
1842
+ this._begin(n, r, 0, 0) && (s.uniform2f(this._u(n, "inverseSize"), 1 / r.width, 1 / r.height), s.uniform1f(this._u(n, "feedback"), this._plan.taa.feedback)), s.uniformMatrix4fv(this._u(n, "reprojection"), !1, o), s.uniform1i(this._u(n, "resetHistory"), this._historyValid ? 0 : 1), this._bind(0, e), this._bind(1, t.depth), this._bind(2, i.texture), this._draw(r), this._taaPrevious.set(t.viewProjection), this._historyValid = !0, this._historyParity ^= 1;
1843
+ }
1844
+ /** Updates the reprojection; false when the camera did not move since the last frame. */
1845
+ _motion(e) {
1846
+ if (this._previousStamp === e.stamp)
1847
+ return !1;
1848
+ const t = this._previousStamp === -1;
1849
+ if (this._previousStamp = e.stamp, !t) {
1850
+ const s = this._reprojection;
1851
+ M(s, e.viewProjection) ? $(s, this._previous, s) : R(s);
1852
+ }
1853
+ return this._previous.set(e.viewProjection), !t;
1854
+ }
1855
+ _motionBlur(e, t, s) {
1856
+ const r = this._gl, i = this._plan.motionBlur, o = this._program(`motion${i.samples}`, () => Xe(i.samples));
1857
+ this._begin(o, s, 0, 0) && r.uniform1f(this._u(o, "intensity"), i.intensity), r.uniformMatrix4fv(this._u(o, "reprojection"), !1, this._reprojection), this._bind(0, e), this._bind(1, t), this._draw(s);
1858
+ }
1859
+ _bloom(e, t) {
1860
+ const s = this._gl, r = this._plan.bloom, i = this._targets.get("bloomA"), o = this._targets.get("bloomB"), n = this._program("blur", () => Ve);
1861
+ this._begin(n, i, 0, 0), this._bind(0, e), s.uniform2f(this._u(n, "offset"), 1 / i.width, 0), s.uniform1i(this._u(n, "extractBright"), 1), s.uniform1f(this._u(n, "threshold"), r.threshold), this._draw(i), this._begin(n, o, 0, 0), this._bind(0, i.texture), s.uniform2f(this._u(n, "offset"), 0, 1 / o.height), s.uniform1i(this._u(n, "extractBright"), 0), this._draw(o);
1862
+ const a = this._program("composite", () => Oe);
1863
+ return this._begin(a, t, 0, 0) && s.uniform1f(this._u(a, "strength"), r.strength), this._bind(0, e), this._bind(2, o.texture), this._draw(t), 3;
1864
+ }
1865
+ _outline(e, t, s) {
1866
+ const r = this._gl, i = this._plan.outline, o = this._targets.get("maskA"), n = this._targets.get("maskB"), a = this._program("outlineMask", () => qe.replace("__INSTANCE__", le), ue);
1867
+ let l = 0;
1868
+ r.bindFramebuffer(r.FRAMEBUFFER, o.framebuffer), r.viewport(0, 0, o.width, o.height), r.clearColor(0, 0, 0, 0), r.clear(r.COLOR_BUFFER_BIT), r.enable(r.BLEND), r.blendEquation(r.MAX);
1869
+ const f = this._selection;
1870
+ for (let _ = 0; _ < f.length; _++) {
1871
+ const p = f[_];
1872
+ p.destroyed || p.scene !== t.scene || !p._effective("visible") || (r.useProgram(a.program), l === 0 && (r.uniformMatrix4fv(this._u(a, "viewProjection"), !1, t.viewProjection), r.uniform2f(this._u(a, "inverseSize"), 1 / o.width, 1 / o.height), r.uniform1i(this._u(a, "surfaceSide"), 2), this._bind(1, t.depth)), r.uniformMatrix4fv(this._u(a, "world"), !1, p._renderMatrix()), r.uniform1i(this._u(a, "instanced"), p instanceof ee ? 1 : 0), t.draw(p, a.program), l++);
1873
+ }
1874
+ if (r.blendEquation(r.FUNC_ADD), this._common(), l === 0)
1875
+ return 0;
1876
+ const h = this._program("outlineDilate", () => J(!1));
1877
+ this._begin(h, n, 0, 0) && (r.uniform2f(this._u(h, "offset"), 1 / n.width, 0), r.uniform1i(this._u(h, "thickness"), i.thickness)), this._bind(0, o.texture), this._draw(n);
1878
+ const v = this._program("outlineComposite", () => J(!0));
1879
+ return this._begin(v, s, 0, 0) && (r.uniform2f(this._u(v, "offset"), 0, 1 / s.height), r.uniform1i(this._u(v, "thickness"), i.thickness), r.uniform4fv(this._u(v, "color"), i.color), r.uniform4fv(this._u(v, "hiddenColor"), i.hiddenColor)), this._bind(0, n.texture), this._bind(2, e), this._bind(3, o.texture), this._draw(s), l + 2;
1880
+ }
1881
+ _finish(e, t, s, r, i) {
1882
+ const o = this._gl, n = this._plan.finish, a = n.lut && !n.lut.texture.destroyed ? n.lut : void 0, l = (n.chromaticAberration > 0 ? 1 : 0) | (n.sharpen > 0 ? 2 : 0) | (a ? 4 : 0) | (n.vignette && n.vignette.intensity > 0 ? 8 : 0) | (n.grain > 0 ? 16 : 0), f = a ? i.texture(a.texture) : null, h = this._program(`finish${l}`, () => Ze(l, he));
1883
+ if (this._begin(h, t, s, r) && (o.uniform2f(this._u(h, "inverseSize"), 1 / s, 1 / r), o.uniform1f(this._u(h, "aberration"), n.chromaticAberration), o.uniform1f(this._u(h, "sharpen"), n.sharpen), o.uniform1f(this._u(h, "grain"), n.grain), n.vignette && (o.uniform3f(this._u(h, "vignette"), n.vignette.intensity, n.vignette.radius, n.vignette.softness), o.uniform3fv(this._u(h, "vignetteColor"), n.vignette.color)), a)) {
1884
+ const v = a.texture._readSource().width, _ = (v - 1) / v, p = a.domainMin, m = a.domainMax;
1885
+ o.uniform3f(this._u(h, "lutScale"), _ / (m[0] - p[0]), _ / (m[1] - p[1]), _ / (m[2] - p[2])), o.uniform3f(this._u(h, "lutOffset"), 0.5 / v - p[0] * _ / (m[0] - p[0]), 0.5 / v - p[1] * _ / (m[1] - p[1]), 0.5 / v - p[2] * _ / (m[2] - p[2])), o.uniform1f(this._u(h, "lutIntensity"), a.intensity);
1886
+ }
1887
+ o.uniform1f(this._u(h, "exposure"), i.exposure), o.uniform1i(this._u(h, "toneMapping"), i.toneMapping), l & 16 && (this._grainFrame = (this._grainFrame + 1) % 4096, o.uniform1f(this._u(h, "seed"), this._grainFrame * 7.31)), this._bind(0, e), f && this._bind(4, f, o.TEXTURE_3D), this._draw(t);
1888
+ }
1889
+ _fxaa(e, t, s) {
1890
+ const r = this._gl, i = this._program("fxaa", () => Ue);
1891
+ this._begin(i, null, t, s) && r.uniform2f(this._u(i, "inverseSize"), 1 / t, 1 / s), this._bind(0, e.texture), this._draw(null);
1892
+ }
1893
+ _smaa(e, t, s) {
1894
+ const r = this._gl, i = this._targets.get("edges"), o = this._targets.get("weights"), n = this._program("smaaEdges", () => Ye);
1895
+ this._begin(n, i, 0, 0) && (r.uniform2f(this._u(n, "inverseSize"), 1 / t, 1 / s), r.uniform1f(this._u(n, "threshold"), this._plan.smaa.threshold)), this._bind(0, e.texture), this._draw(i), this._begin(this._program("smaaWeights", () => Ke), o, 0, 0), this._bind(0, i.texture), this._draw(o), this._begin(this._program("smaaBlend", () => Je), null, t, s), this._bind(0, e.texture), this._bind(2, o.texture), this._draw(null);
1896
+ }
1897
+ _releaseStale(e) {
1898
+ for (const [t, s] of this._targets)
1899
+ e.some((r) => r.key === t && r.width === s.width && r.height === s.height && r.format === s.format) || (this._release(s), this._targets.delete(t));
1900
+ }
1901
+ _ensureTargets(e, t) {
1902
+ const s = this._baseBytes(this._plan, e, t);
1903
+ if (e === this._width && t === this._height && this._layoutPlan === this._plan && this._layoutBase === s)
1904
+ return;
1905
+ (e !== this._width || t !== this._height) && (this._width = e, this._height = t, this._version++), this._layoutPlan = void 0, this._historyValid = !1;
1906
+ const r = z(this._plan, e, t, s, this._baseColors);
1907
+ this._releaseStale(r.targets);
1908
+ const i = [];
1909
+ try {
1910
+ for (const o of r.targets) {
1911
+ if (this._targets.has(o.key))
1912
+ continue;
1913
+ const n = this._gl, a = n.createFramebuffer(), l = n.createTexture();
1914
+ if (!a || !l)
1915
+ throw n.deleteFramebuffer(a), n.deleteTexture(l), new d("gpu", "[Nova3D] Effect target allocation failed.");
1916
+ const f = { ...o, framebuffer: a, texture: l };
1917
+ i.push(f);
1918
+ const [h, v, _] = tt[o.format];
1919
+ if (n.activeTexture(n.TEXTURE0), n.bindTexture(n.TEXTURE_2D, l), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MIN_FILTER, n.LINEAR), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MAG_FILTER, n.LINEAR), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_S, n.CLAMP_TO_EDGE), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_T, n.CLAMP_TO_EDGE), n.texImage2D(n.TEXTURE_2D, 0, n[h], o.width, o.height, 0, n[v], n[_], null), n.bindFramebuffer(n.FRAMEBUFFER, a), n.framebufferTexture2D(n.FRAMEBUFFER, n.COLOR_ATTACHMENT0, n.TEXTURE_2D, l, 0), n.checkFramebufferStatus(n.FRAMEBUFFER) !== n.FRAMEBUFFER_COMPLETE || n.getError() !== n.NO_ERROR || n.isContextLost())
1920
+ throw new d("gpu", "[Nova3D] Effect framebuffer creation failed.");
1921
+ this._targets.set(o.key, f), this._bytes += f.bytes;
1922
+ }
1923
+ } catch (o) {
1924
+ for (const n of i)
1925
+ this._targets.get(n.key) === n && (this._targets.delete(n.key), this._bytes -= n.bytes), this._gl.deleteFramebuffer(n.framebuffer), this._gl.deleteTexture(n.texture);
1926
+ throw o;
1927
+ }
1928
+ this._layoutPlan = this._plan, this._layoutBase = s;
1929
+ }
1930
+ _release(e) {
1931
+ this._gl.deleteFramebuffer(e.framebuffer), this._gl.deleteTexture(e.texture), this._bytes -= e.bytes;
1932
+ }
1933
+ }
1934
+ class st {
1935
+ /** @internal */
1936
+ constructor(e, t) {
1937
+ this._app = e;
1938
+ const s = X(t);
1939
+ this._budget = s.budget;
1940
+ let r;
1941
+ e._installEffects(this, (i) => (r = new it(i, s), r), () => (r = new $e(s), r)), this._processor = r, this._cleanup = e._own(() => this.destroy());
1942
+ }
1943
+ _processor;
1944
+ _cleanup;
1945
+ _budget;
1946
+ _destroyed = !1;
1947
+ /** Replaces the whole ordered stage list; a rejected list leaves the active one unchanged. */
1948
+ setStages(e) {
1949
+ this._assertAlive(), this._processor.configure(X({ stages: e, budget: this._budget })), this._app._effectsChanged(this);
1950
+ }
1951
+ /**
1952
+ * Meshes drawn into the `outline` stage mask, in the scene of the first canvas
1953
+ * view. Destroyed, hidden or other-scene meshes are skipped while drawing.
1954
+ * The list is copied; at most 1024 meshes.
1955
+ * @experimental
1956
+ */
1957
+ setOutlineSelection(e) {
1958
+ if (this._assertAlive(), !Array.isArray(e))
1959
+ throw new d("invalid-option", "[Nova3D] Outline selection must be an array of meshes.");
1960
+ if (e.length > 1024)
1961
+ throw new d("invalid-option", "[Nova3D] Outline selection holds at most 1024 meshes.");
1962
+ for (const t of e)
1963
+ if (!(t instanceof se) || t.destroyed || !this._app._ownsScene(t.scene))
1964
+ throw new d("owner", "[Nova3D] Outline selection requires live meshes of this app.");
1965
+ this._processor.select(Object.freeze([...new Set(e)])), this._app._effectsChanged(this);
1966
+ }
1967
+ get destroyed() {
1968
+ return this._destroyed;
1969
+ }
1970
+ destroy() {
1971
+ this._destroyed || (this._destroyed = !0, this._app._removeEffects(this), this._cleanup());
1972
+ }
1973
+ _assertAlive() {
1974
+ if (this._destroyed || this._app.destroyed)
1975
+ throw new d("destroyed", "[Nova3D] Effects are destroyed.");
1976
+ }
1977
+ }
1978
+ function pt(c, e) {
1979
+ return new st(c, e);
1980
+ }
1981
+ export {
1982
+ st as Nova3DEffects,
1983
+ pt as createEffects,
1984
+ O as effectStageOrder,
1985
+ vt as parseCubeLUT
1986
+ };