@aura3d/rendering 1.3.3 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (314) hide show
  1. package/dist/ForwardPass.js +7 -1
  2. package/dist/ForwardPass.js.map +1 -1
  3. package/dist/MorphTarget.d.ts +1 -0
  4. package/dist/MorphTarget.d.ts.map +1 -1
  5. package/dist/MorphTarget.js.map +1 -1
  6. package/dist/Renderer.js +7 -1
  7. package/dist/Renderer.js.map +1 -1
  8. package/package.json +38 -4
  9. package/src/ArchitecturalLightingFixtures.ts +0 -241
  10. package/src/ArchitecturalMaterialCatalog.ts +0 -130
  11. package/src/ArchitecturalMeasurementFixtures.ts +0 -155
  12. package/src/BRDFLut.ts +0 -47
  13. package/src/CameraFraming.ts +0 -200
  14. package/src/CanonicalSceneFixtures.ts +0 -95
  15. package/src/CascadedShadowMaps.ts +0 -449
  16. package/src/ColorManagement.ts +0 -127
  17. package/src/CullingFixtures.ts +0 -280
  18. package/src/DecalGeometry.ts +0 -26
  19. package/src/DepthPass.ts +0 -110
  20. package/src/EnvironmentBackgroundPass.ts +0 -194
  21. package/src/EnvironmentBackgroundResources.ts +0 -309
  22. package/src/EnvironmentLighting.ts +0 -96
  23. package/src/EnvironmentMapResources.ts +0 -1026
  24. package/src/EnvironmentPipeline.ts +0 -69
  25. package/src/EnvironmentPlatform.ts +0 -1306
  26. package/src/EnvironmentPreset.ts +0 -155
  27. package/src/Exposure.ts +0 -66
  28. package/src/ExternalParityRenderPreset.ts +0 -725
  29. package/src/ForwardPass.ts +0 -1663
  30. package/src/FrameVisualMetrics.ts +0 -301
  31. package/src/Geometry.ts +0 -461
  32. package/src/GeometryPrimitives.ts +0 -2
  33. package/src/HDRRenderPipeline.ts +0 -94
  34. package/src/IBL.ts +0 -86
  35. package/src/IndexBuffer.ts +0 -57
  36. package/src/InstancedPBRMaterial.ts +0 -186
  37. package/src/InstancedUnlitMaterial.ts +0 -60
  38. package/src/Instancing.ts +0 -19
  39. package/src/LightCollector.ts +0 -82
  40. package/src/LightUniforms.ts +0 -47
  41. package/src/LightingDebug.ts +0 -80
  42. package/src/LightingDefaults.ts +0 -79
  43. package/src/LightingRig.ts +0 -301
  44. package/src/LineGeometry.ts +0 -2
  45. package/src/Material.ts +0 -209
  46. package/src/MaterialBinding.ts +0 -131
  47. package/src/MaterialInstance.ts +0 -59
  48. package/src/MaterialPresets.ts +0 -272
  49. package/src/MorphTarget.ts +0 -123
  50. package/src/MorphTargetPlan.ts +0 -178
  51. package/src/MorphUnlitMaterial.ts +0 -60
  52. package/src/NormalMappedPBRMaterial.ts +0 -188
  53. package/src/OceanFixtures.ts +0 -318
  54. package/src/PBRLightingDefaults.ts +0 -12
  55. package/src/PBRMaterial.ts +0 -442
  56. package/src/PMREM.ts +0 -53
  57. package/src/PbrReference.ts +0 -681
  58. package/src/PostProcessPass.ts +0 -2507
  59. package/src/ProceduralTextureFixtures.ts +0 -393
  60. package/src/ProductTurntableFixtures.ts +0 -815
  61. package/src/Raycaster.ts +0 -21
  62. package/src/ReflectionProbe.ts +0 -13
  63. package/src/ReflectionSurfaces.ts +0 -219
  64. package/src/RenderBackend.ts +0 -43
  65. package/src/RenderDebugViews.ts +0 -138
  66. package/src/RenderDevice.ts +0 -836
  67. package/src/RenderGraph.ts +0 -194
  68. package/src/RenderPass.ts +0 -27
  69. package/src/RenderPipeline.ts +0 -101
  70. package/src/RenderQueue.ts +0 -12
  71. package/src/RenderState.ts +0 -12
  72. package/src/Renderer.ts +0 -2626
  73. package/src/RendererDebugOverlay.ts +0 -80
  74. package/src/RendererFeatureGates.ts +0 -150
  75. package/src/RendererPostprocessPlan.ts +0 -279
  76. package/src/RendererTiming.ts +0 -251
  77. package/src/RendererVisualPipelineReport.ts +0 -836
  78. package/src/ResourceLifecycle.ts +0 -21
  79. package/src/Sampler.ts +0 -37
  80. package/src/SceneOptimization.ts +0 -518
  81. package/src/ShaderChunks.ts +0 -393
  82. package/src/ShaderLibrary.ts +0 -2766
  83. package/src/ShaderModule.ts +0 -36
  84. package/src/ShaderPreprocessor.ts +0 -260
  85. package/src/ShaderReflection.ts +0 -201
  86. package/src/ShadowMap.ts +0 -237
  87. package/src/ShadowPass.ts +0 -198
  88. package/src/ShadowProjection.ts +0 -115
  89. package/src/SkinnedLitMaterial.ts +0 -397
  90. package/src/SkinnedUnlitMaterial.ts +0 -63
  91. package/src/SkinningBounds.ts +0 -131
  92. package/src/SpaceEnvironmentFixtures.ts +0 -200
  93. package/src/SpriteGeometry.ts +0 -21
  94. package/src/StereoCameraRig.ts +0 -127
  95. package/src/StereoEffects.ts +0 -274
  96. package/src/TerrainFixtures.ts +0 -180
  97. package/src/Texture.ts +0 -307
  98. package/src/TextureBinding.ts +0 -91
  99. package/src/TexturedPBRMaterial.ts +0 -1112
  100. package/src/TexturedUnlitMaterial.ts +0 -67
  101. package/src/ToneMapping.ts +0 -105
  102. package/src/UniformBinder.ts +0 -16
  103. package/src/UniformLayout.ts +0 -129
  104. package/src/UnlitMaterial.ts +0 -75
  105. package/src/VegetationFixtures.ts +0 -314
  106. package/src/VertexBuffer.ts +0 -120
  107. package/src/VertexFormat.ts +0 -171
  108. package/src/VoxelWorldFixtures.ts +0 -280
  109. package/src/WeatherFixtures.ts +0 -223
  110. package/src/WebGL2Device.ts +0 -2280
  111. package/src/WebGL2StateCache.ts +0 -330
  112. package/src/WebGPUDevice.ts +0 -2877
  113. package/src/WebGPURenderToTextureProof.ts +0 -139
  114. package/src/advanced-runtime/AdvancedRenderer.ts +0 -73
  115. package/src/advanced-runtime/index.ts +0 -9
  116. package/src/animation/AnimationMaterialStyle.ts +0 -32
  117. package/src/animation/AnimationRenderPreset.ts +0 -45
  118. package/src/animation/AnimationToonMaterial.ts +0 -387
  119. package/src/animation/AnimationVisualQuality.ts +0 -71
  120. package/src/animation/applyAnimationRenderPreset.ts +0 -180
  121. package/src/animation/index.ts +0 -5
  122. package/src/cinematic/BloomPass.ts +0 -26
  123. package/src/cinematic/CinematicDepthComposition.ts +0 -30
  124. package/src/cinematic/CinematicEvidence.ts +0 -123
  125. package/src/cinematic/CinematicLightingRig.ts +0 -144
  126. package/src/cinematic/CinematicMaterialPresets.ts +0 -130
  127. package/src/cinematic/CinematicPostProcess.ts +0 -83
  128. package/src/cinematic/DepthHazePass.ts +0 -30
  129. package/src/cinematic/EmissivePracticalLightSystem.ts +0 -45
  130. package/src/cinematic/FilmGrainPass.ts +0 -24
  131. package/src/cinematic/FogVolumeSystem.ts +0 -30
  132. package/src/cinematic/GlowCardSystem.ts +0 -44
  133. package/src/cinematic/RainParticleSystem.ts +0 -151
  134. package/src/cinematic/VignettePass.ts +0 -25
  135. package/src/cinematic/WetReflectionApproximation.ts +0 -27
  136. package/src/cinematic/index.ts +0 -14
  137. package/src/effects/CollisionModule.ts +0 -64
  138. package/src/effects/ColorModule.ts +0 -60
  139. package/src/effects/ForceModule.ts +0 -25
  140. package/src/effects/GPUParticleBackend.ts +0 -569
  141. package/src/effects/Particle.ts +0 -108
  142. package/src/effects/ParticleDiagnostics.ts +0 -224
  143. package/src/effects/ParticleEffectPresets.ts +0 -147
  144. package/src/effects/ParticleEmitter.ts +0 -326
  145. package/src/effects/ParticleModule.ts +0 -26
  146. package/src/effects/ParticleRenderPass.ts +0 -117
  147. package/src/effects/ParticleRenderer.ts +0 -132
  148. package/src/effects/ParticleSystem.ts +0 -333
  149. package/src/effects/SizeModule.ts +0 -56
  150. package/src/effects/TrailModule.ts +0 -72
  151. package/src/effects/VelocityModule.ts +0 -75
  152. package/src/effects/index.ts +0 -15
  153. package/src/index.ts +0 -925
  154. package/src/materials/AlphaSorting.ts +0 -30
  155. package/src/materials/MaterialExtensions.ts +0 -42
  156. package/src/materials/PhysicalMaterial.ts +0 -133
  157. package/src/materials/TransmissionPass.ts +0 -51
  158. package/src/performance/BVH.ts +0 -18
  159. package/src/performance/Batcher.ts +0 -2
  160. package/src/performance/FrustumCuller.ts +0 -9
  161. package/src/performance/LOD.ts +0 -20
  162. package/src/performance/Octree.ts +0 -10
  163. package/src/performance/RenderItemSorting.ts +0 -170
  164. package/src/performance/RendererStats.ts +0 -43
  165. package/src/performance/ResourceBudget.ts +0 -44
  166. package/src/postprocess/BloomPass.ts +0 -28
  167. package/src/postprocess/CinematicDiagnostics.ts +0 -642
  168. package/src/postprocess/ColorGradingPass.ts +0 -24
  169. package/src/postprocess/DepthOfFieldPass.ts +0 -12
  170. package/src/postprocess/EffectComposer.ts +0 -349
  171. package/src/postprocess/SSAOPass.ts +0 -20
  172. package/src/postprocess/index.ts +0 -34
  173. package/src/production-runtime/AnimationControlsPipeline.ts +0 -77
  174. package/src/production-runtime/PBRHDRPipeline.ts +0 -381
  175. package/src/production-runtime/ProductionEffectsPipeline.ts +0 -85
  176. package/src/production-runtime/ProductionRendererTypes.ts +0 -136
  177. package/src/production-runtime/ProductionRuntimeRenderer.ts +0 -172
  178. package/src/production-runtime/ProductionWebGL2Renderer.ts +0 -313
  179. package/src/production-runtime/ProductionWebGPURenderer.ts +0 -396
  180. package/src/production-runtime/TransmissionBackdropCapture.ts +0 -130
  181. package/src/production-runtime/animation/MorphTargetRenderer.ts +0 -2
  182. package/src/production-runtime/animation/SkinningRenderer.ts +0 -2
  183. package/src/production-runtime/backends/RendererBackend.ts +0 -17
  184. package/src/production-runtime/backends/WebGL2RendererBackend.ts +0 -30
  185. package/src/production-runtime/backends/WebGPURendererBackend.ts +0 -24
  186. package/src/production-runtime/backends/webgl2/WebGL2Buffer.ts +0 -2
  187. package/src/production-runtime/backends/webgl2/WebGL2Capabilities.ts +0 -2
  188. package/src/production-runtime/backends/webgl2/WebGL2RenderTarget.ts +0 -2
  189. package/src/production-runtime/backends/webgl2/WebGL2Shader.ts +0 -2
  190. package/src/production-runtime/backends/webgl2/WebGL2StateCache.ts +0 -1
  191. package/src/production-runtime/backends/webgl2/WebGL2Texture.ts +0 -2
  192. package/src/production-runtime/backends/webgpu/WebGPUBuffer.ts +0 -2
  193. package/src/production-runtime/backends/webgpu/WebGPUCapabilities.ts +0 -2
  194. package/src/production-runtime/backends/webgpu/WebGPURenderTarget.ts +0 -2
  195. package/src/production-runtime/backends/webgpu/WebGPUShader.ts +0 -2
  196. package/src/production-runtime/backends/webgpu/WebGPUTexture.ts +0 -2
  197. package/src/production-runtime/color/ColorManagement.ts +0 -3
  198. package/src/production-runtime/color/ToneMapping.ts +0 -7
  199. package/src/production-runtime/diagnostics/FrameCapture.ts +0 -2
  200. package/src/production-runtime/diagnostics/GPUCapabilities.ts +0 -2
  201. package/src/production-runtime/diagnostics/RendererStats.ts +0 -2
  202. package/src/production-runtime/environment/EnvironmentMap.ts +0 -1
  203. package/src/production-runtime/environment/HDRLoader.ts +0 -57
  204. package/src/production-runtime/environment/PMREMGenerator.ts +0 -713
  205. package/src/production-runtime/framegraph/FrameGraph.ts +0 -18
  206. package/src/production-runtime/framegraph/RenderPass.ts +0 -15
  207. package/src/production-runtime/geometry/ProjectedDecalGeometry.ts +0 -439
  208. package/src/production-runtime/index.ts +0 -127
  209. package/src/production-runtime/lights/LightManager.ts +0 -7
  210. package/src/production-runtime/lights/ShadowMapRenderer.ts +0 -5
  211. package/src/production-runtime/materials/GLTFMaterialAdapter.ts +0 -6
  212. package/src/production-runtime/materials/GLTFPBRMaterialAdapter.ts +0 -2
  213. package/src/production-runtime/materials/MaterialCompiler.ts +0 -7
  214. package/src/production-runtime/materials/MaterialTextureBindings.ts +0 -5
  215. package/src/production-runtime/materials/PBRMaterial.ts +0 -2
  216. package/src/production-runtime/materials/PBRShaderFeatures.ts +0 -2
  217. package/src/production-runtime/passes/ContactShadowPass.ts +0 -184
  218. package/src/production-runtime/passes/DepthPrepass.ts +0 -7
  219. package/src/production-runtime/passes/OpaquePass.ts +0 -7
  220. package/src/production-runtime/passes/ShadowPass.ts +0 -7
  221. package/src/production-runtime/passes/SkyboxPass.ts +0 -7
  222. package/src/production-runtime/passes/ToneMappingPass.ts +0 -7
  223. package/src/production-runtime/passes/TransparentPass.ts +0 -7
  224. package/src/production-runtime/postprocess/BloomPass.ts +0 -51
  225. package/src/production-runtime/postprocess/ColorGradingPass.ts +0 -49
  226. package/src/production-runtime/postprocess/DOFPass.ts +0 -47
  227. package/src/production-runtime/postprocess/FXAAPass.ts +0 -53
  228. package/src/production-runtime/postprocess/ProductionEffectComposer.ts +0 -78
  229. package/src/production-runtime/postprocess/ProductionPostProcessTypes.ts +0 -174
  230. package/src/production-runtime/postprocess/SSAOPass.ts +0 -45
  231. package/src/production-runtime/resources/GPUBuffer.ts +0 -2
  232. package/src/production-runtime/resources/GPUTexture.ts +0 -2
  233. package/src/production-runtime/resources/RenderTarget.ts +0 -3
  234. package/src/production-runtime/resources/ResourceCache.ts +0 -7
  235. package/src/production-runtime/scene/Camera.ts +0 -1
  236. package/src/production-runtime/scene/Lights.ts +0 -2
  237. package/src/production-runtime/scene/RenderableMesh.ts +0 -2
  238. package/src/production-runtime/scene/RenderablePrimitive.ts +0 -1
  239. package/src/production-runtime/scene/RenderableScene.ts +0 -4
  240. package/src/production-runtime/shaders/ShaderProgramLibrary.ts +0 -7
  241. package/src/production-runtime/shaders/chunks/brdf.glsl +0 -2
  242. package/src/production-runtime/shaders/chunks/ibl.glsl +0 -3
  243. package/src/production-runtime/shaders/chunks/pbr.frag.glsl +0 -47
  244. package/src/production-runtime/shaders/chunks/pbr.vert.glsl +0 -8
  245. package/src/production-runtime/shaders/chunks/shadows.glsl +0 -2
  246. package/src/production-runtime/shaders/wgsl/pbr.wgsl +0 -3
  247. package/src/production-runtime/shaders/wgsl/postprocess.wgsl +0 -2
  248. package/src/production-runtime/shaders/wgsl/skybox.wgsl +0 -2
  249. package/src/shaders/depth.frag.glsl +0 -5
  250. package/src/shaders/depth.vert.glsl +0 -8
  251. package/src/shaders/pbr-direct.frag.glsl +0 -687
  252. package/src/shaders/pbr-direct.vert.glsl +0 -18
  253. package/src/shaders/unlit.frag.glsl +0 -18
  254. package/src/shaders/unlit.vert.glsl +0 -13
  255. package/src/shadows/CascadedShadowPipeline.ts +0 -53
  256. package/src/shadows/ContactShadows.ts +0 -106
  257. package/src/shadows/ShadowDebugViews.ts +0 -46
  258. package/src/threejs-compatibility/InstancingSystem.ts +0 -17
  259. package/src/threejs-compatibility/LightingSystem.ts +0 -22
  260. package/src/threejs-compatibility/MaterialSystem.ts +0 -9
  261. package/src/threejs-compatibility/RenderTargetSystem.ts +0 -35
  262. package/src/threejs-compatibility/RendererDiagnostics.ts +0 -61
  263. package/src/threejs-compatibility/SceneRenderer.ts +0 -34
  264. package/src/threejs-compatibility/ShadowSystem.ts +0 -19
  265. package/src/threejs-compatibility/TextureSystem.ts +0 -19
  266. package/src/threejs-compatibility/ThreeCompatRenderer.ts +0 -90
  267. package/src/threejs-compatibility/TransparencySystem.ts +0 -19
  268. package/src/threejs-compatibility/index.ts +0 -29
  269. package/src/threejs-compatibility/performance/BVH.ts +0 -14
  270. package/src/threejs-compatibility/performance/FrustumCulling.ts +0 -10
  271. package/src/threejs-compatibility/performance/Instancing.ts +0 -4
  272. package/src/threejs-compatibility/performance/LODSystem.ts +0 -16
  273. package/src/threejs-compatibility/performance/OcclusionCulling.ts +0 -6
  274. package/src/threejs-compatibility/performance/RaycastAcceleration.ts +0 -12
  275. package/src/threejs-compatibility/performance/RendererProfiler.ts +0 -19
  276. package/src/threejs-compatibility/performance/TextureStreaming.ts +0 -4
  277. package/src/threejs-compatibility/performance/index.ts +0 -12
  278. package/src/threejs-compatibility/postprocess/BloomPass.ts +0 -16
  279. package/src/threejs-compatibility/postprocess/ColorGradingPass.ts +0 -16
  280. package/src/threejs-compatibility/postprocess/DepthOfFieldPass.ts +0 -21
  281. package/src/threejs-compatibility/postprocess/EffectComposer.ts +0 -14
  282. package/src/threejs-compatibility/postprocess/FXAAPass.ts +0 -15
  283. package/src/threejs-compatibility/postprocess/MotionBlurPass.ts +0 -20
  284. package/src/threejs-compatibility/postprocess/OutlinePass.ts +0 -21
  285. package/src/threejs-compatibility/postprocess/PostProcessTypes.ts +0 -169
  286. package/src/threejs-compatibility/postprocess/RenderPass.ts +0 -9
  287. package/src/threejs-compatibility/postprocess/SMAAPass.ts +0 -15
  288. package/src/threejs-compatibility/postprocess/SSAOPass.ts +0 -21
  289. package/src/threejs-compatibility/postprocess/ShaderPass.ts +0 -7
  290. package/src/threejs-compatibility/postprocess/TAAPass.ts +0 -15
  291. package/src/threejs-compatibility/postprocess/VignettePass.ts +0 -16
  292. package/src/threejs-compatibility/postprocess/index.ts +0 -15
  293. package/src/threejs-compatibility/shaders/NodeMaterial.ts +0 -21
  294. package/src/threejs-compatibility/shaders/RawShaderMaterial.ts +0 -6
  295. package/src/threejs-compatibility/shaders/ShaderDiagnostics.ts +0 -17
  296. package/src/threejs-compatibility/shaders/ShaderMaterial.ts +0 -18
  297. package/src/threejs-compatibility/shaders/ThreeCompatShaderChunks.ts +0 -6
  298. package/src/threejs-compatibility/shaders/Uniforms.ts +0 -18
  299. package/src/threejs-compatibility/shaders/index.ts +0 -9
  300. package/src/threejs-compatibility/vfx/GPUPointCloud.ts +0 -7
  301. package/src/threejs-compatibility/vfx/LineRenderer.ts +0 -13
  302. package/src/threejs-compatibility/vfx/ParticleSystem.ts +0 -23
  303. package/src/threejs-compatibility/vfx/SpriteSystem.ts +0 -14
  304. package/src/threejs-compatibility/vfx/TrailRenderer.ts +0 -8
  305. package/src/threejs-compatibility/vfx/VFXDiagnostics.ts +0 -23
  306. package/src/threejs-compatibility/vfx/index.ts +0 -9
  307. package/src/threejs-example-parity/index.ts +0 -205
  308. package/src/webgpu/WebGPUBuffer.ts +0 -1
  309. package/src/webgpu/WebGPUCompute.ts +0 -2
  310. package/src/webgpu/WebGPUPipelineCache.ts +0 -15
  311. package/src/webgpu/WebGPUPostProcess.ts +0 -2
  312. package/src/webgpu/WebGPUTexture.ts +0 -2
  313. package/tsconfig.json +0 -26
  314. package/vitest.config.ts +0 -20
@@ -1,21 +0,0 @@
1
- import type { DisposableResource } from "./RenderDevice";
2
-
3
- export class ResourceLifecycle {
4
- private readonly resources = new Set<DisposableResource>();
5
-
6
- track<T extends DisposableResource>(resource: T): T {
7
- this.resources.add(resource);
8
- return resource;
9
- }
10
-
11
- dispose(): void {
12
- for (const resource of this.resources) {
13
- if (!resource.disposed) resource.dispose();
14
- }
15
- this.resources.clear();
16
- }
17
-
18
- leakCount(): number {
19
- return [...this.resources].filter((resource) => !resource.disposed).length;
20
- }
21
- }
package/src/Sampler.ts DELETED
@@ -1,37 +0,0 @@
1
- export type TextureMagFilter = "nearest" | "linear";
2
- export type TextureMinFilter =
3
- | TextureMagFilter
4
- | "nearest-mipmap-nearest"
5
- | "linear-mipmap-nearest"
6
- | "nearest-mipmap-linear"
7
- | "linear-mipmap-linear";
8
- export type TextureFilter = TextureMinFilter;
9
- export type TextureAddressMode = "clamp-to-edge" | "repeat" | "mirror-repeat";
10
-
11
- export interface SamplerDescriptor {
12
- readonly minFilter?: TextureMinFilter;
13
- readonly magFilter?: TextureMagFilter;
14
- readonly addressU?: TextureAddressMode;
15
- readonly addressV?: TextureAddressMode;
16
- readonly maxAnisotropy?: number;
17
- }
18
-
19
- export class Sampler {
20
- public readonly minFilter: TextureMinFilter;
21
- public readonly magFilter: TextureMagFilter;
22
- public readonly addressU: TextureAddressMode;
23
- public readonly addressV: TextureAddressMode;
24
- public readonly maxAnisotropy: number;
25
-
26
- constructor(descriptor: SamplerDescriptor = {}) {
27
- this.minFilter = descriptor.minFilter ?? "linear";
28
- this.magFilter = descriptor.magFilter ?? "linear";
29
- this.addressU = descriptor.addressU ?? "clamp-to-edge";
30
- this.addressV = descriptor.addressV ?? "clamp-to-edge";
31
- const maxAnisotropy = descriptor.maxAnisotropy ?? 1;
32
- if (!Number.isFinite(maxAnisotropy) || maxAnisotropy < 1) {
33
- throw new RangeError("Sampler maxAnisotropy must be finite and at least 1");
34
- }
35
- this.maxAnisotropy = maxAnisotropy;
36
- }
37
- }
@@ -1,518 +0,0 @@
1
- import { Box3, Ray, Vector3 } from "@aura3d/math";
2
- import { Geometry } from "./Geometry";
3
- import { MAX_GPU_INSTANCES, type RenderItem, type RenderMaterial } from "./ForwardPass";
4
-
5
- export interface LodLevel {
6
- readonly name: string;
7
- readonly geometry: Geometry;
8
- readonly material?: RenderMaterial;
9
- readonly maxDistance?: number;
10
- readonly minScreenSize?: number;
11
- }
12
-
13
- export interface LodSelectionInput {
14
- readonly distance: number;
15
- readonly screenSize: number;
16
- readonly levels: readonly LodLevel[];
17
- }
18
-
19
- export interface LodSelection {
20
- readonly level: LodLevel;
21
- readonly levelIndex: number;
22
- readonly reason: "distance" | "screen-size" | "fallback";
23
- }
24
-
25
- export interface StaticBatchInput {
26
- readonly geometry: Geometry;
27
- readonly material: RenderMaterial;
28
- readonly modelMatrix: Float32Array | readonly number[];
29
- readonly batchKey: string;
30
- readonly label?: string;
31
- }
32
-
33
- export interface StaticBatchOptions {
34
- readonly maxInstancesPerBatch?: number;
35
- readonly labelPrefix?: string;
36
- }
37
-
38
- export interface StaticBatchResult {
39
- readonly renderItems: readonly RenderItem[];
40
- readonly logicalItems: number;
41
- readonly submittedItems: number;
42
- readonly batches: number;
43
- readonly unbatchedItems: number;
44
- readonly maxInstancesPerBatch: number;
45
- readonly drawCallReduction: number;
46
- }
47
-
48
- export interface StaticSpatialItem<T = unknown> {
49
- readonly id: string;
50
- readonly bounds: StaticSpatialBounds;
51
- readonly payload?: T;
52
- }
53
-
54
- export interface StaticSpatialBounds {
55
- readonly min: readonly [number, number, number];
56
- readonly max: readonly [number, number, number];
57
- }
58
-
59
- export interface StaticBoundsIntersector {
60
- intersectsBox(box: Box3): boolean;
61
- }
62
-
63
- export interface StaticBoundsBvhOptions {
64
- readonly maxLeafSize?: number;
65
- readonly maxDepth?: number;
66
- }
67
-
68
- export interface StaticBoundsBvh<T = unknown> {
69
- readonly root: StaticBoundsBvhNode;
70
- readonly items: readonly StaticSpatialItem<T>[];
71
- readonly diagnostics: StaticBoundsBvhBuildDiagnostics;
72
- }
73
-
74
- export interface StaticBoundsBvhNode {
75
- readonly id: number;
76
- readonly bounds: StaticSpatialBounds;
77
- readonly depth: number;
78
- readonly itemCount: number;
79
- readonly itemIndices?: readonly number[];
80
- readonly left?: StaticBoundsBvhNode;
81
- readonly right?: StaticBoundsBvhNode;
82
- }
83
-
84
- export interface StaticBoundsBvhBuildDiagnostics {
85
- readonly objectCount: number;
86
- readonly bvhNodes: number;
87
- readonly leafNodes: number;
88
- readonly maxDepth: number;
89
- readonly buildTimeMs: number;
90
- }
91
-
92
- export interface StaticBoundsBvhQueryOptions {
93
- readonly bounds?: StaticSpatialBounds;
94
- readonly frustum?: StaticBoundsIntersector;
95
- }
96
-
97
- export interface StaticBoundsBvhQueryResult<T = unknown> {
98
- readonly items: readonly StaticSpatialItem<T>[];
99
- readonly diagnostics: StaticBoundsBvhTraversalDiagnostics;
100
- }
101
-
102
- export interface StaticBoundsBvhTraversalDiagnostics {
103
- readonly totalObjects: number;
104
- readonly visibleObjects: number;
105
- readonly culledObjects: number;
106
- readonly bvhNodes: number;
107
- readonly visitedNodes: number;
108
- readonly rejectedNodes: number;
109
- readonly boundsTests: number;
110
- readonly leafTests: number;
111
- readonly traversalTimeMs: number;
112
- }
113
-
114
- export interface StaticBoundsBvhUpdateResult<T = unknown> {
115
- readonly bvh: StaticBoundsBvh<T>;
116
- readonly updatedObjects: number;
117
- readonly strategy: "rebuild";
118
- }
119
-
120
- export interface StaticBoundsBvhRaycastHit<T = unknown> {
121
- readonly item: StaticSpatialItem<T>;
122
- readonly distance: number;
123
- readonly point: readonly [number, number, number];
124
- }
125
-
126
- export interface StaticBoundsBvhRaycastResult<T = unknown> {
127
- readonly hits: readonly StaticBoundsBvhRaycastHit<T>[];
128
- readonly diagnostics: StaticBoundsBvhRaycastDiagnostics;
129
- }
130
-
131
- export interface StaticBoundsBvhRaycastDiagnostics {
132
- readonly totalObjects: number;
133
- readonly hitObjects: number;
134
- readonly bvhNodes: number;
135
- readonly visitedNodes: number;
136
- readonly rejectedNodes: number;
137
- readonly boundsTests: number;
138
- readonly leafTests: number;
139
- readonly traversalTimeMs: number;
140
- }
141
-
142
- export function selectLodLevel(input: LodSelectionInput): LodSelection {
143
- if (input.levels.length === 0) {
144
- throw new Error("LOD selection requires at least one level.");
145
- }
146
- if (!Number.isFinite(input.distance) || input.distance < 0) {
147
- throw new Error("LOD distance must be finite and non-negative.");
148
- }
149
- if (!Number.isFinite(input.screenSize) || input.screenSize < 0) {
150
- throw new Error("LOD screen size must be finite and non-negative.");
151
- }
152
-
153
- for (let index = 0; index < input.levels.length; index += 1) {
154
- const level = input.levels[index]!;
155
- if (level.maxDistance !== undefined && input.distance <= level.maxDistance) {
156
- return { level, levelIndex: index, reason: "distance" };
157
- }
158
- if (level.minScreenSize !== undefined && input.screenSize >= level.minScreenSize) {
159
- return { level, levelIndex: index, reason: "screen-size" };
160
- }
161
- }
162
-
163
- const levelIndex = input.levels.length - 1;
164
- return { level: input.levels[levelIndex]!, levelIndex, reason: "fallback" };
165
- }
166
-
167
- export function batchStaticRenderItems(items: readonly StaticBatchInput[], options: StaticBatchOptions = {}): StaticBatchResult {
168
- const maxInstancesPerBatch = options.maxInstancesPerBatch ?? MAX_GPU_INSTANCES;
169
- if (!Number.isInteger(maxInstancesPerBatch) || maxInstancesPerBatch <= 0 || maxInstancesPerBatch > MAX_GPU_INSTANCES) {
170
- throw new Error(`Static batch maxInstancesPerBatch must be an integer in [1, ${MAX_GPU_INSTANCES}].`);
171
- }
172
-
173
- const groups = new Map<string, StaticBatchInput[]>();
174
- for (const item of items) {
175
- const matrix = Array.from(item.modelMatrix);
176
- if (matrix.length !== 16 || !matrix.every(Number.isFinite)) {
177
- throw new Error(`Static batch item ${item.label ?? item.batchKey} must provide a finite mat4 modelMatrix.`);
178
- }
179
- const group = groups.get(item.batchKey);
180
- if (group) {
181
- group.push(item);
182
- } else {
183
- groups.set(item.batchKey, [item]);
184
- }
185
- }
186
-
187
- const renderItems: RenderItem[] = [];
188
- let unbatchedItems = 0;
189
- const labelPrefix = options.labelPrefix ?? "static-batch";
190
-
191
- for (const [batchKey, group] of groups) {
192
- for (let start = 0; start < group.length; start += maxInstancesPerBatch) {
193
- const chunk = group.slice(start, start + maxInstancesPerBatch);
194
- if (chunk.length === 1) {
195
- const item = chunk[0]!;
196
- renderItems.push({
197
- geometry: item.geometry,
198
- material: item.material,
199
- modelMatrix: item.modelMatrix,
200
- label: item.label ?? `${labelPrefix}-${batchKey}-${start}`
201
- });
202
- unbatchedItems += 1;
203
- continue;
204
- }
205
-
206
- const transforms = new Float32Array(chunk.length * 16);
207
- for (let index = 0; index < chunk.length; index += 1) {
208
- transforms.set(Array.from(chunk[index]!.modelMatrix), index * 16);
209
- }
210
- renderItems.push({
211
- geometry: chunk[0]!.geometry,
212
- material: chunk[0]!.material,
213
- modelMatrix: identityMatrix(),
214
- instanceTransforms: transforms,
215
- label: `${labelPrefix}-${batchKey}-${Math.floor(start / maxInstancesPerBatch)}`
216
- });
217
- }
218
- }
219
-
220
- return {
221
- renderItems,
222
- logicalItems: items.length,
223
- submittedItems: renderItems.length,
224
- batches: renderItems.length - unbatchedItems,
225
- unbatchedItems,
226
- maxInstancesPerBatch,
227
- drawCallReduction: items.length - renderItems.length
228
- };
229
- }
230
-
231
- export function buildStaticBoundsBvh<T = unknown>(
232
- items: readonly StaticSpatialItem<T>[],
233
- options: StaticBoundsBvhOptions = {}
234
- ): StaticBoundsBvh<T> {
235
- const startedAt = performanceNow();
236
- const maxLeafSize = options.maxLeafSize ?? 8;
237
- const maxDepth = options.maxDepth ?? 32;
238
- if (!Number.isInteger(maxLeafSize) || maxLeafSize <= 0) {
239
- throw new Error("Static bounds BVH maxLeafSize must be a positive integer.");
240
- }
241
- if (!Number.isInteger(maxDepth) || maxDepth <= 0) {
242
- throw new Error("Static bounds BVH maxDepth must be a positive integer.");
243
- }
244
- if (items.length === 0) {
245
- throw new Error("Static bounds BVH requires at least one item.");
246
- }
247
-
248
- const copiedItems = items.map((item, index) => validateSpatialItem(item, index));
249
- let nextNodeId = 1;
250
- let nodeCount = 0;
251
- let leafCount = 0;
252
- let deepest = 0;
253
-
254
- const buildNode = (indices: readonly number[], depth: number): StaticBoundsBvhNode => {
255
- nodeCount += 1;
256
- deepest = Math.max(deepest, depth);
257
- const bounds = mergeStaticBounds(indices.map((index) => copiedItems[index]!.bounds));
258
- if (indices.length <= maxLeafSize || depth >= maxDepth) {
259
- leafCount += 1;
260
- return {
261
- id: nextNodeId++,
262
- bounds,
263
- depth,
264
- itemCount: indices.length,
265
- itemIndices: [...indices]
266
- };
267
- }
268
-
269
- const axis = longestBoundsAxis(bounds);
270
- const sorted = [...indices].sort((a, b) => boundsCenter(copiedItems[a]!.bounds, axis) - boundsCenter(copiedItems[b]!.bounds, axis));
271
- const split = Math.max(1, Math.floor(sorted.length / 2));
272
- const left = buildNode(sorted.slice(0, split), depth + 1);
273
- const right = buildNode(sorted.slice(split), depth + 1);
274
- return {
275
- id: nextNodeId++,
276
- bounds,
277
- depth,
278
- itemCount: indices.length,
279
- left,
280
- right
281
- };
282
- };
283
-
284
- const root = buildNode(copiedItems.map((_, index) => index), 0);
285
- return {
286
- root,
287
- items: copiedItems,
288
- diagnostics: {
289
- objectCount: copiedItems.length,
290
- bvhNodes: nodeCount,
291
- leafNodes: leafCount,
292
- maxDepth: deepest,
293
- buildTimeMs: performanceNow() - startedAt
294
- }
295
- };
296
- }
297
-
298
- export function queryStaticBoundsBvh<T = unknown>(
299
- bvh: StaticBoundsBvh<T>,
300
- options: StaticBoundsBvhQueryOptions = {}
301
- ): StaticBoundsBvhQueryResult<T> {
302
- const startedAt = performanceNow();
303
- const queryBounds = options.bounds ? validateBounds(options.bounds, "query bounds") : undefined;
304
- const result: StaticSpatialItem<T>[] = [];
305
- let visitedNodes = 0;
306
- let rejectedNodes = 0;
307
- let boundsTests = 0;
308
- let leafTests = 0;
309
- let culledObjects = 0;
310
-
311
- const intersects = (bounds: StaticSpatialBounds): boolean => {
312
- boundsTests += 1;
313
- if (queryBounds && !boundsIntersect(bounds, queryBounds)) return false;
314
- if (options.frustum && !options.frustum.intersectsBox(toBox3(bounds))) return false;
315
- return true;
316
- };
317
-
318
- const visit = (node: StaticBoundsBvhNode): void => {
319
- visitedNodes += 1;
320
- if (!intersects(node.bounds)) {
321
- rejectedNodes += 1;
322
- culledObjects += node.itemCount;
323
- return;
324
- }
325
- if (node.itemIndices) {
326
- for (const index of node.itemIndices) {
327
- leafTests += 1;
328
- const item = bvh.items[index]!;
329
- if (intersects(item.bounds)) {
330
- result.push(item);
331
- } else {
332
- culledObjects += 1;
333
- }
334
- }
335
- return;
336
- }
337
- if (node.left) visit(node.left);
338
- if (node.right) visit(node.right);
339
- };
340
-
341
- visit(bvh.root);
342
- return {
343
- items: result,
344
- diagnostics: {
345
- totalObjects: bvh.items.length,
346
- visibleObjects: result.length,
347
- culledObjects,
348
- bvhNodes: bvh.diagnostics.bvhNodes,
349
- visitedNodes,
350
- rejectedNodes,
351
- boundsTests,
352
- leafTests,
353
- traversalTimeMs: performanceNow() - startedAt
354
- }
355
- };
356
- }
357
-
358
- export function updateStaticBoundsBvh<T = unknown>(
359
- bvh: StaticBoundsBvh<T>,
360
- updatedItems: readonly StaticSpatialItem<T>[],
361
- options: StaticBoundsBvhOptions = {}
362
- ): StaticBoundsBvhUpdateResult<T> {
363
- return {
364
- bvh: buildStaticBoundsBvh(updatedItems, options),
365
- updatedObjects: countUpdatedSpatialItems(bvh.items, updatedItems),
366
- strategy: "rebuild"
367
- };
368
- }
369
-
370
- export function raycastStaticBoundsBvh<T = unknown>(
371
- bvh: StaticBoundsBvh<T>,
372
- ray: Ray
373
- ): StaticBoundsBvhRaycastResult<T> {
374
- const startedAt = performanceNow();
375
- const hits: StaticBoundsBvhRaycastHit<T>[] = [];
376
- let visitedNodes = 0;
377
- let rejectedNodes = 0;
378
- let boundsTests = 0;
379
- let leafTests = 0;
380
-
381
- const intersectBounds = (bounds: StaticSpatialBounds): { readonly distance: number; readonly point: readonly [number, number, number] } | undefined => {
382
- boundsTests += 1;
383
- const point = ray.intersectBox(toBox3(bounds));
384
- if (!point) return undefined;
385
- return { distance: point.distanceTo(ray.origin), point: point.toArray() };
386
- };
387
-
388
- const visit = (node: StaticBoundsBvhNode): void => {
389
- visitedNodes += 1;
390
- if (!intersectBounds(node.bounds)) {
391
- rejectedNodes += 1;
392
- return;
393
- }
394
- if (node.itemIndices) {
395
- for (const index of node.itemIndices) {
396
- leafTests += 1;
397
- const item = bvh.items[index]!;
398
- const hit = intersectBounds(item.bounds);
399
- if (hit) {
400
- hits.push({ item, distance: hit.distance, point: hit.point });
401
- }
402
- }
403
- return;
404
- }
405
- if (node.left) visit(node.left);
406
- if (node.right) visit(node.right);
407
- };
408
-
409
- visit(bvh.root);
410
- hits.sort((a, b) => a.distance - b.distance);
411
- return {
412
- hits,
413
- diagnostics: {
414
- totalObjects: bvh.items.length,
415
- hitObjects: hits.length,
416
- bvhNodes: bvh.diagnostics.bvhNodes,
417
- visitedNodes,
418
- rejectedNodes,
419
- boundsTests,
420
- leafTests,
421
- traversalTimeMs: performanceNow() - startedAt
422
- }
423
- };
424
- }
425
-
426
- function identityMatrix(): readonly number[] {
427
- return [
428
- 1, 0, 0, 0,
429
- 0, 1, 0, 0,
430
- 0, 0, 1, 0,
431
- 0, 0, 0, 1
432
- ];
433
- }
434
-
435
- function validateSpatialItem<T>(item: StaticSpatialItem<T>, index: number): StaticSpatialItem<T> {
436
- if (!item.id) {
437
- throw new Error(`Static bounds BVH item ${index} requires an id.`);
438
- }
439
- return {
440
- ...item,
441
- bounds: validateBounds(item.bounds, item.id)
442
- };
443
- }
444
-
445
- function validateBounds(bounds: StaticSpatialBounds, label: string): StaticSpatialBounds {
446
- const values = [...bounds.min, ...bounds.max];
447
- if (bounds.min.length !== 3 || bounds.max.length !== 3 || !values.every(Number.isFinite)) {
448
- throw new Error(`Static bounds BVH ${label} bounds must contain finite min/max vec3 values.`);
449
- }
450
- if (bounds.max[0] < bounds.min[0] || bounds.max[1] < bounds.min[1] || bounds.max[2] < bounds.min[2]) {
451
- throw new Error(`Static bounds BVH ${label} bounds max must be greater than or equal to min.`);
452
- }
453
- return {
454
- min: [bounds.min[0], bounds.min[1], bounds.min[2]],
455
- max: [bounds.max[0], bounds.max[1], bounds.max[2]]
456
- };
457
- }
458
-
459
- function mergeStaticBounds(bounds: readonly StaticSpatialBounds[]): StaticSpatialBounds {
460
- const merged = bounds.reduce((box, current) => box.union(toBox3(current)), new Box3());
461
- return fromBox3(merged);
462
- }
463
-
464
- function boundsIntersect(a: StaticSpatialBounds, b: StaticSpatialBounds): boolean {
465
- return !(b.max[0] < a.min[0] || b.min[0] > a.max[0] ||
466
- b.max[1] < a.min[1] || b.min[1] > a.max[1] ||
467
- b.max[2] < a.min[2] || b.min[2] > a.max[2]);
468
- }
469
-
470
- function longestBoundsAxis(bounds: StaticSpatialBounds): 0 | 1 | 2 {
471
- const sizes = [
472
- bounds.max[0] - bounds.min[0],
473
- bounds.max[1] - bounds.min[1],
474
- bounds.max[2] - bounds.min[2]
475
- ];
476
- if (sizes[1]! >= sizes[0]! && sizes[1]! >= sizes[2]!) return 1;
477
- if (sizes[2]! >= sizes[0]! && sizes[2]! >= sizes[1]!) return 2;
478
- return 0;
479
- }
480
-
481
- function boundsCenter(bounds: StaticSpatialBounds, axis: 0 | 1 | 2): number {
482
- return (bounds.min[axis] + bounds.max[axis]) / 2;
483
- }
484
-
485
- function toBox3(bounds: StaticSpatialBounds): Box3 {
486
- return new Box3(
487
- new Vector3(bounds.min[0], bounds.min[1], bounds.min[2]),
488
- new Vector3(bounds.max[0], bounds.max[1], bounds.max[2])
489
- );
490
- }
491
-
492
- function fromBox3(box: Box3): StaticSpatialBounds {
493
- return {
494
- min: [box.min.x, box.min.y, box.min.z],
495
- max: [box.max.x, box.max.y, box.max.z]
496
- };
497
- }
498
-
499
- function countUpdatedSpatialItems<T>(previous: readonly StaticSpatialItem<T>[], next: readonly StaticSpatialItem<T>[]): number {
500
- const previousById = new Map(previous.map((item) => [item.id, item.bounds] as const));
501
- let changed = 0;
502
- for (const item of next) {
503
- const oldBounds = previousById.get(item.id);
504
- if (!oldBounds || !sameBounds(oldBounds, item.bounds)) {
505
- changed += 1;
506
- }
507
- }
508
- return changed;
509
- }
510
-
511
- function sameBounds(a: StaticSpatialBounds, b: StaticSpatialBounds): boolean {
512
- return a.min[0] === b.min[0] && a.min[1] === b.min[1] && a.min[2] === b.min[2] &&
513
- a.max[0] === b.max[0] && a.max[1] === b.max[1] && a.max[2] === b.max[2];
514
- }
515
-
516
- function performanceNow(): number {
517
- return typeof performance !== "undefined" && typeof performance.now === "function" ? performance.now() : Date.now();
518
- }