@aura3d/rendering 1.4.0 → 1.4.2

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 (308) hide show
  1. package/package.json +38 -4
  2. package/AGENTS.md +0 -46
  3. package/src/ArchitecturalLightingFixtures.ts +0 -241
  4. package/src/ArchitecturalMaterialCatalog.ts +0 -130
  5. package/src/ArchitecturalMeasurementFixtures.ts +0 -155
  6. package/src/BRDFLut.ts +0 -47
  7. package/src/CameraFraming.ts +0 -200
  8. package/src/CanonicalSceneFixtures.ts +0 -95
  9. package/src/CascadedShadowMaps.ts +0 -449
  10. package/src/ColorManagement.ts +0 -127
  11. package/src/CullingFixtures.ts +0 -280
  12. package/src/DecalGeometry.ts +0 -26
  13. package/src/DepthPass.ts +0 -110
  14. package/src/EnvironmentBackgroundPass.ts +0 -194
  15. package/src/EnvironmentBackgroundResources.ts +0 -309
  16. package/src/EnvironmentLighting.ts +0 -96
  17. package/src/EnvironmentMapResources.ts +0 -1026
  18. package/src/EnvironmentPipeline.ts +0 -69
  19. package/src/EnvironmentPlatform.ts +0 -1306
  20. package/src/EnvironmentPreset.ts +0 -155
  21. package/src/Exposure.ts +0 -66
  22. package/src/ExternalParityRenderPreset.ts +0 -725
  23. package/src/ForwardPass.ts +0 -1668
  24. package/src/FrameVisualMetrics.ts +0 -301
  25. package/src/Geometry.ts +0 -461
  26. package/src/GeometryPrimitives.ts +0 -2
  27. package/src/HDRRenderPipeline.ts +0 -94
  28. package/src/IBL.ts +0 -86
  29. package/src/IndexBuffer.ts +0 -57
  30. package/src/InstancedPBRMaterial.ts +0 -186
  31. package/src/InstancedUnlitMaterial.ts +0 -60
  32. package/src/Instancing.ts +0 -19
  33. package/src/LightCollector.ts +0 -82
  34. package/src/LightUniforms.ts +0 -47
  35. package/src/LightingDebug.ts +0 -80
  36. package/src/LightingDefaults.ts +0 -79
  37. package/src/LightingRig.ts +0 -301
  38. package/src/LineGeometry.ts +0 -2
  39. package/src/Material.ts +0 -209
  40. package/src/MaterialBinding.ts +0 -131
  41. package/src/MaterialInstance.ts +0 -59
  42. package/src/MaterialPresets.ts +0 -272
  43. package/src/MorphTarget.ts +0 -124
  44. package/src/MorphTargetPlan.ts +0 -178
  45. package/src/MorphUnlitMaterial.ts +0 -60
  46. package/src/NormalMappedPBRMaterial.ts +0 -188
  47. package/src/OceanFixtures.ts +0 -318
  48. package/src/PBRLightingDefaults.ts +0 -12
  49. package/src/PBRMaterial.ts +0 -442
  50. package/src/PMREM.ts +0 -53
  51. package/src/PbrReference.ts +0 -681
  52. package/src/PostProcessPass.ts +0 -2507
  53. package/src/ProceduralTextureFixtures.ts +0 -393
  54. package/src/ProductTurntableFixtures.ts +0 -815
  55. package/src/Raycaster.ts +0 -21
  56. package/src/ReflectionProbe.ts +0 -13
  57. package/src/ReflectionSurfaces.ts +0 -219
  58. package/src/RenderBackend.ts +0 -43
  59. package/src/RenderDebugViews.ts +0 -138
  60. package/src/RenderDevice.ts +0 -836
  61. package/src/RenderGraph.ts +0 -194
  62. package/src/RenderPass.ts +0 -27
  63. package/src/RenderPipeline.ts +0 -101
  64. package/src/RenderQueue.ts +0 -12
  65. package/src/RenderState.ts +0 -12
  66. package/src/Renderer.ts +0 -2631
  67. package/src/RendererDebugOverlay.ts +0 -80
  68. package/src/RendererFeatureGates.ts +0 -150
  69. package/src/RendererPostprocessPlan.ts +0 -279
  70. package/src/RendererTiming.ts +0 -251
  71. package/src/RendererVisualPipelineReport.ts +0 -836
  72. package/src/ResourceLifecycle.ts +0 -21
  73. package/src/Sampler.ts +0 -37
  74. package/src/SceneOptimization.ts +0 -518
  75. package/src/ShaderChunks.ts +0 -393
  76. package/src/ShaderLibrary.ts +0 -2766
  77. package/src/ShaderModule.ts +0 -36
  78. package/src/ShaderPreprocessor.ts +0 -260
  79. package/src/ShaderReflection.ts +0 -201
  80. package/src/ShadowMap.ts +0 -237
  81. package/src/ShadowPass.ts +0 -198
  82. package/src/ShadowProjection.ts +0 -115
  83. package/src/SkinnedLitMaterial.ts +0 -397
  84. package/src/SkinnedUnlitMaterial.ts +0 -63
  85. package/src/SkinningBounds.ts +0 -131
  86. package/src/SpaceEnvironmentFixtures.ts +0 -200
  87. package/src/SpriteGeometry.ts +0 -21
  88. package/src/StereoCameraRig.ts +0 -127
  89. package/src/StereoEffects.ts +0 -274
  90. package/src/TerrainFixtures.ts +0 -180
  91. package/src/Texture.ts +0 -307
  92. package/src/TextureBinding.ts +0 -91
  93. package/src/TexturedPBRMaterial.ts +0 -1112
  94. package/src/TexturedUnlitMaterial.ts +0 -67
  95. package/src/ToneMapping.ts +0 -105
  96. package/src/UniformBinder.ts +0 -16
  97. package/src/UniformLayout.ts +0 -129
  98. package/src/UnlitMaterial.ts +0 -75
  99. package/src/VegetationFixtures.ts +0 -314
  100. package/src/VertexBuffer.ts +0 -120
  101. package/src/VertexFormat.ts +0 -171
  102. package/src/VoxelWorldFixtures.ts +0 -280
  103. package/src/WeatherFixtures.ts +0 -223
  104. package/src/WebGL2Device.ts +0 -2280
  105. package/src/WebGL2StateCache.ts +0 -330
  106. package/src/WebGPUDevice.ts +0 -2877
  107. package/src/WebGPURenderToTextureProof.ts +0 -139
  108. package/src/advanced-runtime/AdvancedRenderer.ts +0 -73
  109. package/src/advanced-runtime/index.ts +0 -9
  110. package/src/animation/AnimationMaterialStyle.ts +0 -32
  111. package/src/animation/AnimationRenderPreset.ts +0 -45
  112. package/src/animation/AnimationToonMaterial.ts +0 -387
  113. package/src/animation/AnimationVisualQuality.ts +0 -71
  114. package/src/animation/applyAnimationRenderPreset.ts +0 -180
  115. package/src/animation/index.ts +0 -5
  116. package/src/cinematic/BloomPass.ts +0 -26
  117. package/src/cinematic/CinematicDepthComposition.ts +0 -30
  118. package/src/cinematic/CinematicEvidence.ts +0 -123
  119. package/src/cinematic/CinematicLightingRig.ts +0 -144
  120. package/src/cinematic/CinematicMaterialPresets.ts +0 -130
  121. package/src/cinematic/CinematicPostProcess.ts +0 -83
  122. package/src/cinematic/DepthHazePass.ts +0 -30
  123. package/src/cinematic/EmissivePracticalLightSystem.ts +0 -45
  124. package/src/cinematic/FilmGrainPass.ts +0 -24
  125. package/src/cinematic/FogVolumeSystem.ts +0 -30
  126. package/src/cinematic/GlowCardSystem.ts +0 -44
  127. package/src/cinematic/RainParticleSystem.ts +0 -151
  128. package/src/cinematic/VignettePass.ts +0 -25
  129. package/src/cinematic/WetReflectionApproximation.ts +0 -27
  130. package/src/cinematic/index.ts +0 -14
  131. package/src/effects/CollisionModule.ts +0 -64
  132. package/src/effects/ColorModule.ts +0 -60
  133. package/src/effects/ForceModule.ts +0 -25
  134. package/src/effects/GPUParticleBackend.ts +0 -569
  135. package/src/effects/Particle.ts +0 -108
  136. package/src/effects/ParticleDiagnostics.ts +0 -224
  137. package/src/effects/ParticleEffectPresets.ts +0 -147
  138. package/src/effects/ParticleEmitter.ts +0 -326
  139. package/src/effects/ParticleModule.ts +0 -26
  140. package/src/effects/ParticleRenderPass.ts +0 -117
  141. package/src/effects/ParticleRenderer.ts +0 -132
  142. package/src/effects/ParticleSystem.ts +0 -333
  143. package/src/effects/SizeModule.ts +0 -56
  144. package/src/effects/TrailModule.ts +0 -72
  145. package/src/effects/VelocityModule.ts +0 -75
  146. package/src/effects/index.ts +0 -15
  147. package/src/index.ts +0 -925
  148. package/src/materials/AlphaSorting.ts +0 -30
  149. package/src/materials/MaterialExtensions.ts +0 -42
  150. package/src/materials/PhysicalMaterial.ts +0 -133
  151. package/src/materials/TransmissionPass.ts +0 -51
  152. package/src/performance/BVH.ts +0 -18
  153. package/src/performance/Batcher.ts +0 -2
  154. package/src/performance/FrustumCuller.ts +0 -9
  155. package/src/performance/LOD.ts +0 -20
  156. package/src/performance/Octree.ts +0 -10
  157. package/src/performance/RenderItemSorting.ts +0 -170
  158. package/src/performance/RendererStats.ts +0 -43
  159. package/src/performance/ResourceBudget.ts +0 -44
  160. package/src/postprocess/BloomPass.ts +0 -28
  161. package/src/postprocess/CinematicDiagnostics.ts +0 -642
  162. package/src/postprocess/ColorGradingPass.ts +0 -24
  163. package/src/postprocess/DepthOfFieldPass.ts +0 -12
  164. package/src/postprocess/EffectComposer.ts +0 -349
  165. package/src/postprocess/SSAOPass.ts +0 -20
  166. package/src/postprocess/index.ts +0 -34
  167. package/src/production-runtime/AnimationControlsPipeline.ts +0 -77
  168. package/src/production-runtime/PBRHDRPipeline.ts +0 -381
  169. package/src/production-runtime/ProductionEffectsPipeline.ts +0 -85
  170. package/src/production-runtime/ProductionRendererTypes.ts +0 -136
  171. package/src/production-runtime/ProductionRuntimeRenderer.ts +0 -172
  172. package/src/production-runtime/ProductionWebGL2Renderer.ts +0 -313
  173. package/src/production-runtime/ProductionWebGPURenderer.ts +0 -396
  174. package/src/production-runtime/TransmissionBackdropCapture.ts +0 -130
  175. package/src/production-runtime/animation/MorphTargetRenderer.ts +0 -2
  176. package/src/production-runtime/animation/SkinningRenderer.ts +0 -2
  177. package/src/production-runtime/backends/RendererBackend.ts +0 -17
  178. package/src/production-runtime/backends/WebGL2RendererBackend.ts +0 -30
  179. package/src/production-runtime/backends/WebGPURendererBackend.ts +0 -24
  180. package/src/production-runtime/backends/webgl2/WebGL2Buffer.ts +0 -2
  181. package/src/production-runtime/backends/webgl2/WebGL2Capabilities.ts +0 -2
  182. package/src/production-runtime/backends/webgl2/WebGL2RenderTarget.ts +0 -2
  183. package/src/production-runtime/backends/webgl2/WebGL2Shader.ts +0 -2
  184. package/src/production-runtime/backends/webgl2/WebGL2StateCache.ts +0 -1
  185. package/src/production-runtime/backends/webgl2/WebGL2Texture.ts +0 -2
  186. package/src/production-runtime/backends/webgpu/WebGPUBuffer.ts +0 -2
  187. package/src/production-runtime/backends/webgpu/WebGPUCapabilities.ts +0 -2
  188. package/src/production-runtime/backends/webgpu/WebGPURenderTarget.ts +0 -2
  189. package/src/production-runtime/backends/webgpu/WebGPUShader.ts +0 -2
  190. package/src/production-runtime/backends/webgpu/WebGPUTexture.ts +0 -2
  191. package/src/production-runtime/color/ColorManagement.ts +0 -3
  192. package/src/production-runtime/color/ToneMapping.ts +0 -7
  193. package/src/production-runtime/diagnostics/FrameCapture.ts +0 -2
  194. package/src/production-runtime/diagnostics/GPUCapabilities.ts +0 -2
  195. package/src/production-runtime/diagnostics/RendererStats.ts +0 -2
  196. package/src/production-runtime/environment/EnvironmentMap.ts +0 -1
  197. package/src/production-runtime/environment/HDRLoader.ts +0 -57
  198. package/src/production-runtime/environment/PMREMGenerator.ts +0 -713
  199. package/src/production-runtime/framegraph/FrameGraph.ts +0 -18
  200. package/src/production-runtime/framegraph/RenderPass.ts +0 -15
  201. package/src/production-runtime/geometry/ProjectedDecalGeometry.ts +0 -439
  202. package/src/production-runtime/index.ts +0 -127
  203. package/src/production-runtime/lights/LightManager.ts +0 -7
  204. package/src/production-runtime/lights/ShadowMapRenderer.ts +0 -5
  205. package/src/production-runtime/materials/GLTFMaterialAdapter.ts +0 -6
  206. package/src/production-runtime/materials/GLTFPBRMaterialAdapter.ts +0 -2
  207. package/src/production-runtime/materials/MaterialCompiler.ts +0 -7
  208. package/src/production-runtime/materials/MaterialTextureBindings.ts +0 -5
  209. package/src/production-runtime/materials/PBRMaterial.ts +0 -2
  210. package/src/production-runtime/materials/PBRShaderFeatures.ts +0 -2
  211. package/src/production-runtime/passes/ContactShadowPass.ts +0 -184
  212. package/src/production-runtime/passes/DepthPrepass.ts +0 -7
  213. package/src/production-runtime/passes/OpaquePass.ts +0 -7
  214. package/src/production-runtime/passes/ShadowPass.ts +0 -7
  215. package/src/production-runtime/passes/SkyboxPass.ts +0 -7
  216. package/src/production-runtime/passes/ToneMappingPass.ts +0 -7
  217. package/src/production-runtime/passes/TransparentPass.ts +0 -7
  218. package/src/production-runtime/postprocess/BloomPass.ts +0 -51
  219. package/src/production-runtime/postprocess/ColorGradingPass.ts +0 -49
  220. package/src/production-runtime/postprocess/DOFPass.ts +0 -47
  221. package/src/production-runtime/postprocess/FXAAPass.ts +0 -53
  222. package/src/production-runtime/postprocess/ProductionEffectComposer.ts +0 -78
  223. package/src/production-runtime/postprocess/ProductionPostProcessTypes.ts +0 -174
  224. package/src/production-runtime/postprocess/SSAOPass.ts +0 -45
  225. package/src/production-runtime/resources/GPUBuffer.ts +0 -2
  226. package/src/production-runtime/resources/GPUTexture.ts +0 -2
  227. package/src/production-runtime/resources/RenderTarget.ts +0 -3
  228. package/src/production-runtime/resources/ResourceCache.ts +0 -7
  229. package/src/production-runtime/scene/Camera.ts +0 -1
  230. package/src/production-runtime/scene/Lights.ts +0 -2
  231. package/src/production-runtime/scene/RenderableMesh.ts +0 -2
  232. package/src/production-runtime/scene/RenderablePrimitive.ts +0 -1
  233. package/src/production-runtime/scene/RenderableScene.ts +0 -4
  234. package/src/production-runtime/shaders/ShaderProgramLibrary.ts +0 -7
  235. package/src/production-runtime/shaders/chunks/brdf.glsl +0 -2
  236. package/src/production-runtime/shaders/chunks/ibl.glsl +0 -3
  237. package/src/production-runtime/shaders/chunks/pbr.frag.glsl +0 -47
  238. package/src/production-runtime/shaders/chunks/pbr.vert.glsl +0 -8
  239. package/src/production-runtime/shaders/chunks/shadows.glsl +0 -2
  240. package/src/production-runtime/shaders/wgsl/pbr.wgsl +0 -3
  241. package/src/production-runtime/shaders/wgsl/postprocess.wgsl +0 -2
  242. package/src/production-runtime/shaders/wgsl/skybox.wgsl +0 -2
  243. package/src/shaders/depth.frag.glsl +0 -5
  244. package/src/shaders/depth.vert.glsl +0 -8
  245. package/src/shaders/pbr-direct.frag.glsl +0 -687
  246. package/src/shaders/pbr-direct.vert.glsl +0 -18
  247. package/src/shaders/unlit.frag.glsl +0 -18
  248. package/src/shaders/unlit.vert.glsl +0 -13
  249. package/src/shadows/CascadedShadowPipeline.ts +0 -53
  250. package/src/shadows/ContactShadows.ts +0 -106
  251. package/src/shadows/ShadowDebugViews.ts +0 -46
  252. package/src/threejs-compatibility/InstancingSystem.ts +0 -17
  253. package/src/threejs-compatibility/LightingSystem.ts +0 -22
  254. package/src/threejs-compatibility/MaterialSystem.ts +0 -9
  255. package/src/threejs-compatibility/RenderTargetSystem.ts +0 -35
  256. package/src/threejs-compatibility/RendererDiagnostics.ts +0 -61
  257. package/src/threejs-compatibility/SceneRenderer.ts +0 -34
  258. package/src/threejs-compatibility/ShadowSystem.ts +0 -19
  259. package/src/threejs-compatibility/TextureSystem.ts +0 -19
  260. package/src/threejs-compatibility/ThreeCompatRenderer.ts +0 -90
  261. package/src/threejs-compatibility/TransparencySystem.ts +0 -19
  262. package/src/threejs-compatibility/index.ts +0 -29
  263. package/src/threejs-compatibility/performance/BVH.ts +0 -14
  264. package/src/threejs-compatibility/performance/FrustumCulling.ts +0 -10
  265. package/src/threejs-compatibility/performance/Instancing.ts +0 -4
  266. package/src/threejs-compatibility/performance/LODSystem.ts +0 -16
  267. package/src/threejs-compatibility/performance/OcclusionCulling.ts +0 -6
  268. package/src/threejs-compatibility/performance/RaycastAcceleration.ts +0 -12
  269. package/src/threejs-compatibility/performance/RendererProfiler.ts +0 -19
  270. package/src/threejs-compatibility/performance/TextureStreaming.ts +0 -4
  271. package/src/threejs-compatibility/performance/index.ts +0 -12
  272. package/src/threejs-compatibility/postprocess/BloomPass.ts +0 -16
  273. package/src/threejs-compatibility/postprocess/ColorGradingPass.ts +0 -16
  274. package/src/threejs-compatibility/postprocess/DepthOfFieldPass.ts +0 -21
  275. package/src/threejs-compatibility/postprocess/EffectComposer.ts +0 -14
  276. package/src/threejs-compatibility/postprocess/FXAAPass.ts +0 -15
  277. package/src/threejs-compatibility/postprocess/MotionBlurPass.ts +0 -20
  278. package/src/threejs-compatibility/postprocess/OutlinePass.ts +0 -21
  279. package/src/threejs-compatibility/postprocess/PostProcessTypes.ts +0 -169
  280. package/src/threejs-compatibility/postprocess/RenderPass.ts +0 -9
  281. package/src/threejs-compatibility/postprocess/SMAAPass.ts +0 -15
  282. package/src/threejs-compatibility/postprocess/SSAOPass.ts +0 -21
  283. package/src/threejs-compatibility/postprocess/ShaderPass.ts +0 -7
  284. package/src/threejs-compatibility/postprocess/TAAPass.ts +0 -15
  285. package/src/threejs-compatibility/postprocess/VignettePass.ts +0 -16
  286. package/src/threejs-compatibility/postprocess/index.ts +0 -15
  287. package/src/threejs-compatibility/shaders/NodeMaterial.ts +0 -21
  288. package/src/threejs-compatibility/shaders/RawShaderMaterial.ts +0 -6
  289. package/src/threejs-compatibility/shaders/ShaderDiagnostics.ts +0 -17
  290. package/src/threejs-compatibility/shaders/ShaderMaterial.ts +0 -18
  291. package/src/threejs-compatibility/shaders/ThreeCompatShaderChunks.ts +0 -6
  292. package/src/threejs-compatibility/shaders/Uniforms.ts +0 -18
  293. package/src/threejs-compatibility/shaders/index.ts +0 -9
  294. package/src/threejs-compatibility/vfx/GPUPointCloud.ts +0 -7
  295. package/src/threejs-compatibility/vfx/LineRenderer.ts +0 -13
  296. package/src/threejs-compatibility/vfx/ParticleSystem.ts +0 -23
  297. package/src/threejs-compatibility/vfx/SpriteSystem.ts +0 -14
  298. package/src/threejs-compatibility/vfx/TrailRenderer.ts +0 -8
  299. package/src/threejs-compatibility/vfx/VFXDiagnostics.ts +0 -23
  300. package/src/threejs-compatibility/vfx/index.ts +0 -9
  301. package/src/threejs-example-parity/index.ts +0 -205
  302. package/src/webgpu/WebGPUBuffer.ts +0 -1
  303. package/src/webgpu/WebGPUCompute.ts +0 -2
  304. package/src/webgpu/WebGPUPipelineCache.ts +0 -15
  305. package/src/webgpu/WebGPUPostProcess.ts +0 -2
  306. package/src/webgpu/WebGPUTexture.ts +0 -2
  307. package/tsconfig.json +0 -26
  308. package/vitest.config.ts +0 -20
package/src/ShadowMap.ts DELETED
@@ -1,237 +0,0 @@
1
- import { Texture } from "./Texture";
2
-
3
- export type ShadowFilterMode = "none" | "pcf";
4
- export type ShadowFilterDistribution = "grid" | "poisson";
5
-
6
- export interface ShadowFilterSample {
7
- readonly x: number;
8
- readonly y: number;
9
- readonly weight: number;
10
- }
11
-
12
- export interface ShadowFilterKernel {
13
- readonly mode: ShadowFilterMode;
14
- readonly distribution: ShadowFilterDistribution;
15
- readonly radius: number;
16
- readonly samples: readonly ShadowFilterSample[];
17
- }
18
-
19
- export interface ShadowMapOptions {
20
- readonly size?: number;
21
- readonly bias?: number;
22
- readonly filter?: ShadowFilterMode;
23
- readonly pcfRadius?: number;
24
- readonly pcfSamples?: number;
25
- readonly pcfDistribution?: ShadowFilterDistribution;
26
- readonly label?: string;
27
- }
28
-
29
- export interface ShadowAtlasRequest {
30
- readonly id: string;
31
- readonly size: number;
32
- readonly cascadeIndex?: number;
33
- }
34
-
35
- export interface ShadowAtlasAllocation extends ShadowAtlasRequest {
36
- readonly x: number;
37
- readonly y: number;
38
- readonly width: number;
39
- readonly height: number;
40
- }
41
-
42
- export interface ShadowAtlasLayout {
43
- readonly atlasSize: number;
44
- readonly allocations: readonly ShadowAtlasAllocation[];
45
- readonly utilization: number;
46
- }
47
-
48
- export class ShadowMap {
49
- public readonly texture: Texture;
50
- public readonly bias: number;
51
- public readonly filterKernel: ShadowFilterKernel;
52
-
53
- constructor(options: ShadowMapOptions = {}) {
54
- const size = options.size ?? 1024;
55
- if (!Number.isInteger(size) || size <= 0) {
56
- throw new RangeError("ShadowMap size must be a positive integer");
57
- }
58
- const bias = options.bias ?? 0.001;
59
- if (!Number.isFinite(bias) || bias < 0) {
60
- throw new RangeError("ShadowMap bias must be finite and non-negative");
61
- }
62
- this.bias = bias;
63
- this.filterKernel = createShadowFilterKernel(options);
64
- this.texture = new Texture({ width: size, height: size, format: "depth24", label: options.label ?? "shadow-map" });
65
- }
66
-
67
- get size(): number {
68
- return this.texture.width;
69
- }
70
-
71
- resize(size: number): ShadowMap {
72
- this.dispose();
73
- return new ShadowMap({
74
- size,
75
- bias: this.bias,
76
- filter: this.filterKernel.mode,
77
- pcfRadius: this.filterKernel.radius,
78
- pcfSamples: this.filterKernel.samples.length,
79
- pcfDistribution: this.filterKernel.distribution,
80
- label: this.texture.label
81
- });
82
- }
83
-
84
- dispose(): void {
85
- this.texture.dispose();
86
- }
87
- }
88
-
89
- export function createShadowAtlasLayout(requests: readonly ShadowAtlasRequest[], atlasSize: number): ShadowAtlasLayout {
90
- if (!Number.isInteger(atlasSize) || atlasSize <= 0) {
91
- throw new RangeError("Shadow atlas size must be a positive integer");
92
- }
93
- const normalized = requests.map((request) => {
94
- if (!request.id.trim()) throw new Error("Shadow atlas request id is required");
95
- if (!Number.isInteger(request.size) || request.size <= 0) throw new RangeError("Shadow atlas request size must be a positive integer");
96
- if (request.size > atlasSize) throw new RangeError("Shadow atlas request size cannot exceed atlas size");
97
- if (request.cascadeIndex !== undefined && (!Number.isInteger(request.cascadeIndex) || request.cascadeIndex < 0)) {
98
- throw new RangeError("Shadow atlas cascadeIndex must be a non-negative integer when provided");
99
- }
100
- return request;
101
- }).sort((left, right) => {
102
- const leftCascade = left.cascadeIndex ?? Number.MAX_SAFE_INTEGER;
103
- const rightCascade = right.cascadeIndex ?? Number.MAX_SAFE_INTEGER;
104
- if (leftCascade !== rightCascade) return leftCascade - rightCascade;
105
- if (left.size !== right.size) return right.size - left.size;
106
- return left.id.localeCompare(right.id);
107
- });
108
-
109
- const allocations: ShadowAtlasAllocation[] = [];
110
- let cursorX = 0;
111
- let cursorY = 0;
112
- let rowHeight = 0;
113
- for (const request of normalized) {
114
- if (cursorX + request.size > atlasSize) {
115
- cursorX = 0;
116
- cursorY += rowHeight;
117
- rowHeight = 0;
118
- }
119
- if (cursorY + request.size > atlasSize) {
120
- throw new RangeError("Shadow atlas requests do not fit in the atlas");
121
- }
122
- allocations.push({
123
- ...request,
124
- x: cursorX,
125
- y: cursorY,
126
- width: request.size,
127
- height: request.size
128
- });
129
- cursorX += request.size;
130
- rowHeight = Math.max(rowHeight, request.size);
131
- }
132
- const usedArea = allocations.reduce((sum, allocation) => sum + allocation.width * allocation.height, 0);
133
- return {
134
- atlasSize,
135
- allocations,
136
- utilization: Number((usedArea / (atlasSize * atlasSize)).toFixed(6))
137
- };
138
- }
139
-
140
- export function createShadowFilterKernel(options: Pick<ShadowMapOptions, "filter" | "pcfRadius" | "pcfSamples" | "pcfDistribution"> = {}): ShadowFilterKernel {
141
- const mode = options.filter ?? "none";
142
- if (mode !== "none" && mode !== "pcf") {
143
- throw new RangeError(`Unsupported shadow filter mode: ${String(mode)}`);
144
- }
145
- if (mode === "none") {
146
- return {
147
- mode,
148
- distribution: "grid",
149
- radius: 0,
150
- samples: [{ x: 0, y: 0, weight: 1 }]
151
- };
152
- }
153
-
154
- const radius = options.pcfRadius ?? 1;
155
- if (!Number.isFinite(radius) || radius <= 0 || radius > 8) {
156
- throw new RangeError("ShadowMap pcfRadius must be finite and greater than zero up to 8 texels");
157
- }
158
-
159
- const sampleCount = options.pcfSamples ?? 9;
160
- const distribution = options.pcfDistribution ?? "grid";
161
- if (distribution !== "grid" && distribution !== "poisson") {
162
- throw new RangeError(`Unsupported shadow filter distribution: ${String(distribution)}`);
163
- }
164
- if (distribution === "poisson") {
165
- return {
166
- mode,
167
- distribution,
168
- radius,
169
- samples: createPoissonDiskShadowKernel(sampleCount, radius)
170
- };
171
- }
172
- const gridSize = Math.sqrt(sampleCount);
173
- if (!Number.isInteger(sampleCount) || sampleCount <= 0 || !Number.isInteger(gridSize) || gridSize < 2 || gridSize > 5) {
174
- throw new RangeError("ShadowMap pcfSamples must be a square grid sample count between 4 and 25");
175
- }
176
-
177
- const half = (gridSize - 1) / 2;
178
- const unweighted: ShadowFilterSample[] = [];
179
- for (let y = 0; y < gridSize; y += 1) {
180
- for (let x = 0; x < gridSize; x += 1) {
181
- unweighted.push({
182
- x: (x - half) * radius,
183
- y: (y - half) * radius,
184
- weight: 1 / sampleCount
185
- });
186
- }
187
- }
188
- return {
189
- mode,
190
- distribution,
191
- radius,
192
- samples: unweighted
193
- };
194
- }
195
-
196
- export function createPoissonDiskShadowKernel(sampleCount = 16, radius = 1): readonly ShadowFilterSample[] {
197
- if (!Number.isInteger(sampleCount) || sampleCount < 4 || sampleCount > 32) {
198
- throw new RangeError("Poisson shadow sample count must be an integer from 4 to 32");
199
- }
200
- if (!Number.isFinite(radius) || radius <= 0 || radius > 8) {
201
- throw new RangeError("Poisson shadow radius must be finite and greater than zero up to 8 texels");
202
- }
203
- const poisson16 = [
204
- [-0.94201624, -0.39906216], [0.94558609, -0.76890725], [-0.0941841, -0.9293887], [0.34495938, 0.2938776],
205
- [-0.91588581, 0.45771432], [-0.81544232, -0.87912464], [-0.38277543, 0.27676845], [0.97484398, 0.75648379],
206
- [0.44323325, -0.97511554], [0.53742981, -0.4737342], [-0.26496911, -0.41893023], [0.79197514, 0.19090188],
207
- [-0.2418884, 0.99706507], [-0.81409955, 0.9143759], [0.19984126, 0.78641367], [0.14383161, -0.1410079]
208
- ] as const;
209
- const poisson32 = [
210
- [-0.975402, -0.0711386], [-0.920347, -0.441282], [-0.883908, 0.217872], [-0.884518, 0.568041],
211
- [-0.811945, -0.790709], [-0.792474, 0.0130608], [-0.644704, -0.569165], [-0.634888, 0.682157],
212
- [-0.624807, -0.238616], [-0.590539, 0.327366], [-0.504396, -0.863621], [-0.454499, 0.875562],
213
- [-0.416458, -0.0370163], [-0.345554, -0.670523], [-0.272745, 0.535116], [-0.238006, -0.369068],
214
- [-0.190885, 0.918882], [-0.149278, 0.0543955], [0.00910668, -0.869337], [0.0293372, 0.358103],
215
- [0.0968844, -0.0888426], [0.185344, -0.536082], [0.239055, 0.717623], [0.301938, -0.281269],
216
- [0.392248, 0.0857121], [0.487048, -0.733963], [0.549342, 0.478623], [0.625366, -0.0596615],
217
- [0.688151, -0.462789], [0.736279, 0.253616], [0.816755, 0.604563], [0.897866, -0.192168]
218
- ] as const;
219
- const base = sampleCount <= 16 ? poisson16 : poisson32;
220
- const weight = 1 / sampleCount;
221
- return base.slice(0, sampleCount).map(([x, y]) => ({ x: Number((x * radius).toFixed(6)), y: Number((y * radius).toFixed(6)), weight }));
222
- }
223
-
224
- export function computeShadowDepthBias(options: {
225
- readonly baseBias: number;
226
- readonly slopeScale?: number;
227
- readonly normalDotLight: number;
228
- readonly texelSize?: number;
229
- }): number {
230
- const slopeScale = options.slopeScale ?? 1;
231
- const texelSize = options.texelSize ?? 1;
232
- if (!Number.isFinite(options.baseBias) || options.baseBias < 0) throw new RangeError("Shadow baseBias must be finite and non-negative");
233
- if (!Number.isFinite(slopeScale) || slopeScale < 0) throw new RangeError("Shadow slopeScale must be finite and non-negative");
234
- if (!Number.isFinite(texelSize) || texelSize <= 0) throw new RangeError("Shadow texelSize must be finite and positive");
235
- const grazing = 1 - Math.max(0, Math.min(1, options.normalDotLight));
236
- return Number((options.baseBias + grazing * slopeScale * texelSize).toFixed(8));
237
- }
package/src/ShadowPass.ts DELETED
@@ -1,198 +0,0 @@
1
- import { Light } from "@aura3d/scene";
2
- import { DepthPass } from "./DepthPass";
3
- import { type ForwardShadowMapOptions, type RenderItem } from "./ForwardPass";
4
- import { Material } from "./Material";
5
- import { MaterialInstance } from "./MaterialInstance";
6
- import { type RenderDeviceDiagnostics, type RenderTarget } from "./RenderDevice";
7
- import { type RenderPassContext } from "./RenderPass";
8
- import { Sampler } from "./Sampler";
9
- import { ShadowMap } from "./ShadowMap";
10
- import { type ShaderLibrary } from "./ShaderLibrary";
11
- import { TextureBinding } from "./TextureBinding";
12
-
13
- export interface ShadowPassOptions {
14
- readonly light: Light | null;
15
- readonly casters: readonly RenderItem[];
16
- readonly shadowMap?: ShadowMap;
17
- readonly shaderLibrary?: ShaderLibrary;
18
- readonly viewProjectionMatrix?: Float32Array | readonly number[];
19
- }
20
-
21
- export interface ShadowPassResult {
22
- readonly rendered: boolean;
23
- readonly reason: ShadowPassReason;
24
- readonly casterCount: number;
25
- readonly skippedTransparentCasters: number;
26
- readonly targetBacked: boolean;
27
- readonly shadowTextureLabel?: string;
28
- readonly shadowTextureKind?: ShadowTextureKind;
29
- readonly diagnostics: RenderDeviceDiagnostics;
30
- }
31
-
32
- export type ShadowPassReason = "rendered" | "no-light" | "light-disabled" | "not-shadow-casting" | "no-casters" | "no-opaque-casters";
33
- export type ShadowTextureKind = "depth-texture" | "encoded-color-depth";
34
-
35
- export class ShadowPass {
36
- public readonly shadowMap: ShadowMap;
37
- private lastResult: ShadowPassResult | null = null;
38
- private renderTarget: RenderTarget | null = null;
39
-
40
- constructor(private readonly options: ShadowPassOptions) {
41
- this.shadowMap = options.shadowMap ?? new ShadowMap();
42
- }
43
-
44
- execute(context: RenderPassContext): ShadowPassResult {
45
- const skipReason = this.getSkipReason();
46
- if (skipReason) {
47
- this.lastResult = {
48
- rendered: false,
49
- reason: skipReason,
50
- casterCount: 0,
51
- skippedTransparentCasters: 0,
52
- targetBacked: false,
53
- diagnostics: context.device.getDiagnostics()
54
- };
55
- return this.lastResult;
56
- }
57
-
58
- const opaqueCasters = this.options.casters.filter((caster) => !isTransparentCaster(caster));
59
- const skippedTransparentCasters = this.options.casters.length - opaqueCasters.length;
60
- if (opaqueCasters.length === 0) {
61
- this.lastResult = {
62
- rendered: false,
63
- reason: "no-opaque-casters",
64
- casterCount: 0,
65
- skippedTransparentCasters,
66
- targetBacked: false,
67
- diagnostics: context.device.getDiagnostics()
68
- };
69
- return this.lastResult;
70
- }
71
-
72
- const ownsFrame = context.device.captureState().get("frameActive") === false;
73
- if (ownsFrame) {
74
- context.device.beginFrame(context.width, context.height);
75
- }
76
- try {
77
- return this.executeWithinFrame(context, opaqueCasters, skippedTransparentCasters);
78
- } finally {
79
- if (ownsFrame) {
80
- context.device.endFrame();
81
- }
82
- }
83
- }
84
-
85
- private executeWithinFrame(context: RenderPassContext, opaqueCasters: readonly RenderItem[], skippedTransparentCasters: number): ShadowPassResult {
86
- const target = this.ensureRenderTarget(context);
87
- context.device.setRenderTarget(target);
88
- initializeShadowTarget(context, target);
89
- const depthOptions = this.options.shaderLibrary
90
- ? { casters: opaqueCasters, shaderLibrary: this.options.shaderLibrary, viewProjectionMatrix: this.options.viewProjectionMatrix }
91
- : { casters: opaqueCasters, viewProjectionMatrix: this.options.viewProjectionMatrix };
92
- const pass = new DepthPass(depthOptions);
93
- pass.execute(context);
94
- context.device.setRenderTarget(null);
95
- this.lastResult = {
96
- rendered: true,
97
- reason: "rendered",
98
- casterCount: opaqueCasters.length,
99
- skippedTransparentCasters,
100
- targetBacked: true,
101
- shadowTextureLabel: shadowTextureForTarget(target).label,
102
- shadowTextureKind: target.depthTexture ? "depth-texture" : "encoded-color-depth",
103
- diagnostics: context.device.getDiagnostics()
104
- };
105
- return this.lastResult;
106
- }
107
-
108
- getLastResult(): ShadowPassResult | null {
109
- return this.lastResult;
110
- }
111
-
112
- getRenderTarget(): RenderTarget | null {
113
- return this.renderTarget;
114
- }
115
-
116
- getForwardShadowMap(options: Omit<ForwardShadowMapOptions, "texture" | "bias" | "filterKernel"> & {
117
- readonly bias?: number;
118
- readonly filterKernel?: ForwardShadowMapOptions["filterKernel"];
119
- }): ForwardShadowMapOptions | null {
120
- if (!this.renderTarget || !this.lastResult?.rendered) {
121
- return null;
122
- }
123
- return {
124
- ...options,
125
- bias: options.bias ?? this.shadowMap.bias,
126
- filterKernel: options.filterKernel ?? this.shadowMap.filterKernel,
127
- texture: new TextureBinding({
128
- name: "u_shadowMapTexture",
129
- texture: shadowTextureForTarget(this.renderTarget),
130
- sampler: new Sampler({ minFilter: "nearest", magFilter: "nearest", addressU: "clamp-to-edge", addressV: "clamp-to-edge" }),
131
- required: true
132
- })
133
- };
134
- }
135
-
136
- dispose(): void {
137
- this.renderTarget?.dispose();
138
- this.renderTarget = null;
139
- this.shadowMap.dispose();
140
- }
141
-
142
- private ensureRenderTarget(context: RenderPassContext): RenderTarget {
143
- if (this.renderTarget && !this.renderTarget.disposed && this.renderTarget.width === this.shadowMap.size && this.renderTarget.height === this.shadowMap.size) {
144
- return this.renderTarget;
145
- }
146
- this.renderTarget?.dispose();
147
- this.renderTarget = context.device.createRenderTarget({
148
- width: this.shadowMap.size,
149
- height: this.shadowMap.size,
150
- label: `${this.shadowMap.texture.label}-depth-color`,
151
- format: "rgba8",
152
- depth: context.device.info.capabilities?.includes("depth-textures") ? "texture" : true
153
- });
154
- return this.renderTarget;
155
- }
156
-
157
- private getSkipReason(): ShadowPassResult["reason"] | null {
158
- const light = this.options.light;
159
- if (!light) {
160
- return "no-light";
161
- }
162
- if (!light.visible) {
163
- return "light-disabled";
164
- }
165
- if (!light.castsShadow) {
166
- return "not-shadow-casting";
167
- }
168
- if (this.options.casters.length === 0) {
169
- return "no-casters";
170
- }
171
- return null;
172
- }
173
- }
174
-
175
- function shadowTextureForTarget(target: RenderTarget) {
176
- return target.depthTexture ?? target.colorTexture;
177
- }
178
-
179
- function initializeShadowTarget(context: RenderPassContext, target: RenderTarget): void {
180
- context.device.setRenderTarget(target);
181
- if (context.device.clearRenderTarget) {
182
- context.device.clearRenderTarget([1, 1, 1, 1]);
183
- } else {
184
- context.device.clear([1, 1, 1, 1]);
185
- }
186
- }
187
-
188
- function isTransparentCaster(caster: RenderItem): boolean {
189
- if (!caster.material) {
190
- return false;
191
- }
192
- const material = getBaseMaterial(caster.material);
193
- return material.renderState.blend;
194
- }
195
-
196
- function getBaseMaterial(material: Material | MaterialInstance): Material {
197
- return material instanceof MaterialInstance ? material.baseMaterial : material;
198
- }
@@ -1,115 +0,0 @@
1
- import { type Bounds3 } from "./Geometry";
2
-
3
- export type Vec3Tuple = readonly [number, number, number];
4
-
5
- export interface ShadowProjectionOptions {
6
- readonly casterBounds: Bounds3;
7
- readonly lightDirection: Vec3Tuple;
8
- readonly receiverPlaneY?: number;
9
- }
10
-
11
- export interface ShadowProjection {
12
- readonly points: readonly Vec3Tuple[];
13
- readonly bounds: Bounds3;
14
- }
15
-
16
- const epsilon = 1e-6;
17
-
18
- export class ShadowProjectionBuilder {
19
- projectBounds(options: ShadowProjectionOptions): ShadowProjection {
20
- const receiverPlaneY = options.receiverPlaneY ?? 0;
21
- const direction = normalize(options.lightDirection);
22
- if (Math.abs(direction[1]) < epsilon) {
23
- throw new Error("Shadow projection requires a light direction that intersects the receiver plane.");
24
- }
25
-
26
- const projected = corners(options.casterBounds)
27
- .map((point) => projectPointToPlane(point, direction, receiverPlaneY))
28
- .filter((point) => isFiniteVec3(point));
29
- if (projected.length === 0) {
30
- throw new Error("Shadow projection produced no finite points.");
31
- }
32
-
33
- const hull2d = convexHull(projected.map((point) => [point[0], point[2]] as const));
34
- const points = hull2d.map(([x, z]) => [x, receiverPlaneY, z] as const);
35
- return {
36
- points,
37
- bounds: boundsFromPoints(points)
38
- };
39
- }
40
- }
41
-
42
- function projectPointToPlane(point: Vec3Tuple, direction: Vec3Tuple, receiverPlaneY: number): Vec3Tuple {
43
- const t = (receiverPlaneY - point[1]) / direction[1];
44
- return [point[0] + direction[0] * t, receiverPlaneY, point[2] + direction[2] * t];
45
- }
46
-
47
- function corners(bounds: Bounds3): readonly Vec3Tuple[] {
48
- const min = bounds.min;
49
- const max = bounds.max;
50
- return [
51
- [min[0], min[1], min[2]],
52
- [max[0], min[1], min[2]],
53
- [max[0], max[1], min[2]],
54
- [min[0], max[1], min[2]],
55
- [min[0], min[1], max[2]],
56
- [max[0], min[1], max[2]],
57
- [max[0], max[1], max[2]],
58
- [min[0], max[1], max[2]]
59
- ];
60
- }
61
-
62
- function boundsFromPoints(points: readonly Vec3Tuple[]): Bounds3 {
63
- const min: [number, number, number] = [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY];
64
- const max: [number, number, number] = [Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY];
65
- for (const point of points) {
66
- min[0] = Math.min(min[0], point[0]);
67
- min[1] = Math.min(min[1], point[1]);
68
- min[2] = Math.min(min[2], point[2]);
69
- max[0] = Math.max(max[0], point[0]);
70
- max[1] = Math.max(max[1], point[1]);
71
- max[2] = Math.max(max[2], point[2]);
72
- }
73
- return { min, max };
74
- }
75
-
76
- function convexHull(points: readonly (readonly [number, number])[]): readonly (readonly [number, number])[] {
77
- const sorted = [...new Map(points.map((point) => [`${point[0]},${point[1]}`, point] as const)).values()].sort(
78
- (a, b) => a[0] - b[0] || a[1] - b[1]
79
- );
80
- if (sorted.length <= 1) {
81
- return sorted;
82
- }
83
- const lower: (readonly [number, number])[] = [];
84
- for (const point of sorted) {
85
- while (lower.length >= 2 && cross(lower[lower.length - 2]!, lower[lower.length - 1]!, point) <= 0) {
86
- lower.pop();
87
- }
88
- lower.push(point);
89
- }
90
- const upper: (readonly [number, number])[] = [];
91
- for (let index = sorted.length - 1; index >= 0; index -= 1) {
92
- const point = sorted[index]!;
93
- while (upper.length >= 2 && cross(upper[upper.length - 2]!, upper[upper.length - 1]!, point) <= 0) {
94
- upper.pop();
95
- }
96
- upper.push(point);
97
- }
98
- return [...lower.slice(0, -1), ...upper.slice(0, -1)];
99
- }
100
-
101
- function cross(origin: readonly [number, number], a: readonly [number, number], b: readonly [number, number]): number {
102
- return (a[0] - origin[0]) * (b[1] - origin[1]) - (a[1] - origin[1]) * (b[0] - origin[0]);
103
- }
104
-
105
- function normalize(value: Vec3Tuple): Vec3Tuple {
106
- const length = Math.hypot(value[0], value[1], value[2]);
107
- if (length <= epsilon) {
108
- throw new Error("Shadow projection light direction cannot be zero.");
109
- }
110
- return [value[0] / length, value[1] / length, value[2] / length];
111
- }
112
-
113
- function isFiniteVec3(value: Vec3Tuple): boolean {
114
- return Number.isFinite(value[0]) && Number.isFinite(value[1]) && Number.isFinite(value[2]);
115
- }