@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
@@ -1,301 +0,0 @@
1
- import { DirectionalLight, Light, PointLight, SpotLight } from "@aura3d/scene";
2
- import type { CollectedLight, CollectedLightKind } from "./LightCollector";
3
-
4
- export type LightingRigPreset =
5
- | "key-fill-rim"
6
- | "studio-softbox"
7
- | "sun"
8
- | "industrial"
9
- | "urban-neon"
10
- | "product-detail"
11
- | "product-shot";
12
-
13
- export type LightingRigUnsupportedFeature =
14
- | "rectangular-area-light"
15
- | "ies-photometric-profile"
16
- | "contact-shadow-map"
17
- | "cascaded-shadow-map"
18
- | "global-illumination";
19
-
20
- export interface LightingRigLightDescriptor {
21
- readonly id: string;
22
- readonly kind: CollectedLightKind;
23
- readonly role: "key" | "fill" | "rim" | "sun" | "accent" | "practical" | "ambient-proxy";
24
- readonly color: readonly [number, number, number];
25
- readonly intensity: number;
26
- readonly position: readonly [number, number, number];
27
- readonly direction: readonly [number, number, number];
28
- readonly range: number;
29
- readonly spotAngle: number;
30
- readonly penumbra: number;
31
- readonly castsShadow: boolean;
32
- readonly claimBoundary: string;
33
- }
34
-
35
- export interface LightingRigSoftboxDescriptor {
36
- readonly id: string;
37
- readonly role: "key" | "fill" | "rim";
38
- readonly color: readonly [number, number, number];
39
- readonly intensity: number;
40
- readonly position: readonly [number, number, number];
41
- readonly direction: readonly [number, number, number];
42
- readonly size: readonly [number, number];
43
- readonly linkedLightIds: readonly string[];
44
- readonly claimBoundary: string;
45
- }
46
-
47
- export interface LightingRigDiagnostics {
48
- readonly preset: LightingRigPreset;
49
- readonly lightCount: number;
50
- readonly shadowCastingLightCount: number;
51
- readonly softboxProxyCount: number;
52
- readonly unsupportedFeatures: readonly LightingRigUnsupportedFeature[];
53
- readonly disclosures: readonly string[];
54
- readonly claimBoundary: string;
55
- }
56
-
57
- export interface LightingRig {
58
- readonly preset: LightingRigPreset;
59
- readonly lights: readonly LightingRigLightDescriptor[];
60
- readonly softboxes: readonly LightingRigSoftboxDescriptor[];
61
- readonly collectedLights: readonly CollectedLight[];
62
- readonly diagnostics: LightingRigDiagnostics;
63
- }
64
-
65
- export interface LightingRigOptions {
66
- readonly preset?: LightingRigPreset;
67
- readonly intensityScale?: number;
68
- readonly shadows?: boolean;
69
- readonly includeUnsupportedDiagnostics?: boolean;
70
- }
71
-
72
- export function createLightingRig(options: LightingRigOptions = {}): LightingRig {
73
- const preset = options.preset ?? "key-fill-rim";
74
- const intensityScale = positive(options.intensityScale ?? 1, "lighting rig intensityScale");
75
- const shadows = options.shadows ?? true;
76
- const lights = lightingRigDescriptors(preset).map((light) => ({
77
- ...light,
78
- intensity: round3(light.intensity * intensityScale),
79
- castsShadow: shadows && light.castsShadow
80
- }));
81
- const softboxes = lightingRigSoftboxes(preset).map((softbox) => ({
82
- ...softbox,
83
- intensity: round3(softbox.intensity * intensityScale)
84
- }));
85
- const unsupportedFeatures = unsupportedFeaturesForRig(preset, options.includeUnsupportedDiagnostics ?? true);
86
- return {
87
- preset,
88
- lights,
89
- softboxes,
90
- collectedLights: lights.map(toCollectedLight),
91
- diagnostics: {
92
- preset,
93
- lightCount: lights.length,
94
- shadowCastingLightCount: lights.filter((light) => light.castsShadow).length,
95
- softboxProxyCount: softboxes.length,
96
- unsupportedFeatures,
97
- disclosures: unsupportedFeatures.map(lightingDisclosure),
98
- claimBoundary: "Lighting rigs are reusable direct-light descriptors for A3D ForwardPass; true area lights, IES profiles, GI, contact shadows, and cascaded-shadow production claims require separate renderer evidence."
99
- }
100
- };
101
- }
102
-
103
- export function listLightingRigPresets(): readonly LightingRigPreset[] {
104
- return ["key-fill-rim", "studio-softbox", "sun", "industrial", "urban-neon", "product-detail", "product-shot"];
105
- }
106
-
107
- function lightingRigDescriptors(preset: LightingRigPreset): readonly LightingRigLightDescriptor[] {
108
- switch (preset) {
109
- case "studio-softbox":
110
- return [
111
- light("studio-key", "directional", "key", [1, 0.95, 0.88], 1.25, [-3, 5, 4], [0.45, -0.72, -0.53], 0, 0, 0, true, "Softbox represented as a broad directional key plus fill accents, not a physical rectangular area light."),
112
- light("studio-fill", "directional", "fill", [0.68, 0.78, 1], 0.38, [4, 3, 2], [-0.76, -0.42, -0.5], 0, 0, 0, false, "Fill is a direct-light approximation."),
113
- light("studio-rim", "spot", "rim", [0.78, 0.9, 1], 0.72, [0, 3.2, -4], [0, -0.42, 0.91], 9, Math.PI / 5, 0.45, false, "Rim light is a bounded spot helper.")
114
- ];
115
- case "sun":
116
- return [
117
- light("sun-main", "directional", "sun", [1, 0.92, 0.78], 2.4, [-8, 9, 4], [0.62, -0.68, -0.38], 0, 0, 0, true, "Sun preset is a directional light and does not imply physical atmosphere or cascaded shadow proof."),
118
- light("sky-fill", "directional", "fill", [0.45, 0.58, 0.85], 0.28, [4, 6, -3], [-0.25, -0.8, 0.54], 0, 0, 0, false, "Sky fill is an approximation.")
119
- ];
120
- case "industrial":
121
- return [
122
- light("industrial-key", "spot", "key", [1, 0.88, 0.68], 1.45, [-2.5, 5.5, 2.5], [0.36, -0.86, -0.36], 11, Math.PI / 6, 0.35, true, "Overhead industrial fixture represented as spot light."),
123
- light("industrial-practical-a", "point", "practical", [1, 0.72, 0.48], 0.56, [3, 2.8, -2], [0, -1, 0], 7, 0, 0, false, "Point practical has no IES profile."),
124
- light("industrial-fill", "directional", "fill", [0.45, 0.58, 0.72], 0.24, [5, 3, 4], [-0.64, -0.48, -0.6], 0, 0, 0, false, "Fill is a direct-light approximation.")
125
- ];
126
- case "urban-neon":
127
- return [
128
- light("neon-key", "spot", "key", [0.42, 0.86, 1], 1.05, [-3, 4, 2.5], [0.5, -0.68, -0.54], 10, Math.PI / 5, 0.55, true, "Neon key is a colored spot helper, not emissive GI."),
129
- light("neon-magenta", "point", "accent", [1, 0.2, 0.66], 0.75, [3.2, 2.1, -1.2], [-1, -0.2, 0.1], 6, 0, 0, false, "Neon accent does not bounce light globally."),
130
- light("neon-rim", "directional", "rim", [0.64, 0.72, 1], 0.4, [1, 5, -5], [-0.2, -0.44, 0.88], 0, 0, 0, false, "Rim is a direct-light approximation.")
131
- ];
132
- case "product-detail":
133
- return [
134
- light("product-detail-key", "directional", "key", [1, 0.9, 0.78], 1.48, [-4.8, 3.3, 3.2], [0.7, -0.48, -0.52], 0, 0, 0, true, "Product detail key is a low glancing directional softbox approximation for normal/AO inspection."),
135
- light("product-detail-cool-edge", "spot", "rim", [0.64, 0.78, 1], 1.15, [2.9, 2.6, -3.6], [-0.42, -0.34, 0.84], 8, Math.PI / 5.5, 0.38, false, "Cool edge strip is a bounded spot helper for product silhouette separation."),
136
- light("product-detail-warm-edge", "point", "accent", [1, 0.55, 0.28], 0.54, [-2.4, 1.1, -1.2], [0.3, -0.18, 0.72], 4.8, 0, 0, false, "Warm practical accent adds bounded hue separation; it is not emissive bounce or GI."),
137
- light("product-detail-fill", "directional", "fill", [0.48, 0.56, 0.68], 0.16, [4.2, 2.4, 3.6], [-0.68, -0.34, -0.64], 0, 0, 0, false, "Low fill preserves product material contrast.")
138
- ];
139
- case "product-shot":
140
- return [
141
- light("product-key", "directional", "key", [1, 0.95, 0.88], 1.55, [-4, 5, 4], [0.52, -0.64, -0.56], 0, 0, 0, true, "Product key approximates a large softbox."),
142
- light("product-fill", "directional", "fill", [0.7, 0.78, 0.9], 0.3, [4, 3, 3], [-0.68, -0.46, -0.57], 0, 0, 0, false, "Product fill is direct lighting."),
143
- light("product-rim", "spot", "rim", [0.85, 0.92, 1], 0.78, [0.5, 3.2, -4.5], [-0.08, -0.36, 0.93], 8, Math.PI / 6, 0.42, false, "Rim light is a bounded spot helper.")
144
- ];
145
- case "key-fill-rim":
146
- return [
147
- light("key", "directional", "key", [1, 0.94, 0.86], 1.2, [-3, 4, 3], [0.5, -0.66, -0.56], 0, 0, 0, true, "Reusable key light descriptor."),
148
- light("fill", "directional", "fill", [0.62, 0.72, 1], 0.35, [4, 3, 2], [-0.75, -0.42, -0.51], 0, 0, 0, false, "Reusable fill light descriptor."),
149
- light("rim", "directional", "rim", [0.72, 0.86, 1], 0.55, [0, 3, -4], [0, -0.45, 0.89], 0, 0, 0, false, "Reusable rim light descriptor.")
150
- ];
151
- }
152
- }
153
-
154
- function lightingRigSoftboxes(preset: LightingRigPreset): readonly LightingRigSoftboxDescriptor[] {
155
- switch (preset) {
156
- case "studio-softbox":
157
- return [
158
- softbox("studio-key-softbox", "key", [1, 0.95, 0.88], 1.25, [-2.6, 3.4, 2.6], [0.45, -0.72, -0.53], [2.2, 1.2], ["studio-key"], "Large studio key softbox proxy used for panel placement and diagnostics only."),
159
- softbox("studio-fill-card", "fill", [0.68, 0.78, 1], 0.42, [2.8, 2.5, 1.8], [-0.76, -0.42, -0.5], [1.8, 1.1], ["studio-fill"], "Cool fill card proxy; not a physical rectangular area light."),
160
- softbox("studio-rim-strip", "rim", [0.78, 0.9, 1], 0.72, [0, 2.9, -3.4], [0, -0.42, 0.91], [1.6, 0.42], ["studio-rim"], "Rim strip proxy coupled to a spot helper.")
161
- ];
162
- case "product-shot":
163
- return [
164
- softbox("product-key-softbox", "key", [1, 0.95, 0.88], 1.55, [-3.2, 3.8, 3.1], [0.52, -0.64, -0.56], [2.4, 1.35], ["product-key"], "Product key softbox proxy; renderer still receives direct light descriptors."),
165
- softbox("product-fill-card", "fill", [0.7, 0.78, 0.9], 0.32, [3.1, 2.2, 2.4], [-0.68, -0.46, -0.57], [1.65, 1.0], ["product-fill"], "Low-intensity fill card proxy for product studio reports."),
166
- softbox("product-rim-strip", "rim", [0.85, 0.92, 1], 0.78, [0.5, 2.8, -3.7], [-0.08, -0.36, 0.93], [1.85, 0.38], ["product-rim"], "Rear strip proxy for product edge separation; not GI or area-light shading.")
167
- ];
168
- case "product-detail":
169
- return [
170
- softbox("product-detail-key-strip", "key", [1, 0.9, 0.78], 1.48, [-4.0, 2.7, 2.7], [0.7, -0.48, -0.52], [1.9, 0.58], ["product-detail-key"], "Low glancing key strip proxy for product material inspection; renderer still receives direct lights."),
171
- softbox("product-detail-cool-rim", "rim", [0.64, 0.78, 1], 1.15, [2.5, 2.3, -3.0], [-0.42, -0.34, 0.84], [1.55, 0.34], ["product-detail-cool-edge"], "Cool rim proxy for edge separation; not GI or physical area lighting."),
172
- softbox("product-detail-fill-card", "fill", [0.48, 0.56, 0.68], 0.16, [3.2, 2.0, 2.7], [-0.68, -0.34, -0.64], [1.3, 0.9], ["product-detail-fill"], "Low fill proxy keeps material contrast bounded.")
173
- ];
174
- default:
175
- return [];
176
- }
177
- }
178
-
179
- function softbox(
180
- id: string,
181
- role: LightingRigSoftboxDescriptor["role"],
182
- color: readonly [number, number, number],
183
- intensity: number,
184
- position: readonly [number, number, number],
185
- direction: readonly [number, number, number],
186
- size: readonly [number, number],
187
- linkedLightIds: readonly string[],
188
- claimBoundary: string
189
- ): LightingRigSoftboxDescriptor {
190
- return {
191
- id,
192
- role,
193
- color,
194
- intensity,
195
- position,
196
- direction: normalize(direction),
197
- size,
198
- linkedLightIds,
199
- claimBoundary
200
- };
201
- }
202
-
203
- function light(
204
- id: string,
205
- kind: CollectedLightKind,
206
- role: LightingRigLightDescriptor["role"],
207
- color: readonly [number, number, number],
208
- intensity: number,
209
- position: readonly [number, number, number],
210
- direction: readonly [number, number, number],
211
- range: number,
212
- spotAngle: number,
213
- penumbra: number,
214
- castsShadow: boolean,
215
- claimBoundary: string
216
- ): LightingRigLightDescriptor {
217
- return { id, kind, role, color, intensity, position, direction: normalize(direction), range, spotAngle, penumbra, castsShadow, claimBoundary };
218
- }
219
-
220
- function toCollectedLight(light: LightingRigLightDescriptor): CollectedLight {
221
- const source = createSourceLight(light);
222
- return {
223
- kind: light.kind,
224
- color: light.color,
225
- intensity: light.intensity,
226
- position: light.position,
227
- direction: light.direction,
228
- range: light.range,
229
- spotAngle: light.spotAngle,
230
- penumbra: light.penumbra,
231
- castsShadow: light.castsShadow,
232
- layerMask: 0xffffffff,
233
- source
234
- };
235
- }
236
-
237
- function createSourceLight(light: LightingRigLightDescriptor): Light {
238
- const source = light.kind === "directional"
239
- ? new DirectionalLight(light.id)
240
- : light.kind === "point"
241
- ? new PointLight(light.id)
242
- : new SpotLight(light.id);
243
- source.color = [...light.color];
244
- source.intensity = light.intensity;
245
- source.castsShadow = light.castsShadow;
246
- source.transform.setPosition(light.position[0], light.position[1], light.position[2]);
247
- if (source instanceof PointLight || source instanceof SpotLight) source.range = Math.max(0.001, light.range);
248
- if (source instanceof SpotLight) {
249
- source.angle = clamp(light.spotAngle || Math.PI / 5, 0.001, Math.PI / 2 - 0.001);
250
- source.penumbra = clamp(light.penumbra, 0, 1);
251
- }
252
- return source;
253
- }
254
-
255
- function unsupportedFeaturesForRig(
256
- preset: LightingRigPreset,
257
- includeUnsupportedDiagnostics: boolean
258
- ): readonly LightingRigUnsupportedFeature[] {
259
- if (!includeUnsupportedDiagnostics) return [];
260
- const base: LightingRigUnsupportedFeature[] = ["ies-photometric-profile", "contact-shadow-map", "global-illumination"];
261
- if (preset === "studio-softbox" || preset === "product-shot" || preset === "product-detail") base.unshift("rectangular-area-light");
262
- if (preset === "sun") base.push("cascaded-shadow-map");
263
- return base;
264
- }
265
-
266
- function lightingDisclosure(feature: LightingRigUnsupportedFeature): string {
267
- switch (feature) {
268
- case "rectangular-area-light":
269
- return "Rectangular/area lights are represented by direct-light and emissive-panel approximations until physical area-light shading exists.";
270
- case "ies-photometric-profile":
271
- return "IES photometric profiles are unsupported; point and spot practicals use bounded cone/range descriptors only.";
272
- case "contact-shadow-map":
273
- return "Contact shadows require the separate contact-shadow pipeline and visual grounding evidence; direct-light rigs do not claim it.";
274
- case "cascaded-shadow-map":
275
- return "Cascaded shadow maps are a separate shadow pipeline and are not implied by the sun lighting preset.";
276
- case "global-illumination":
277
- return "Global illumination/light bounce is unsupported; rigs expose direct lights plus environment-light approximations only.";
278
- }
279
- }
280
-
281
- function normalize(value: readonly [number, number, number]): readonly [number, number, number] {
282
- const length = Math.hypot(value[0], value[1], value[2]);
283
- return length === 0 ? [0, -1, 0] : [round5(value[0] / length), round5(value[1] / length), round5(value[2] / length)];
284
- }
285
-
286
- function positive(value: number, label: string): number {
287
- if (!Number.isFinite(value) || value <= 0) throw new RangeError(`${label} must be finite and positive.`);
288
- return value;
289
- }
290
-
291
- function clamp(value: number, min: number, max: number): number {
292
- return Math.max(min, Math.min(max, Number.isFinite(value) ? value : min));
293
- }
294
-
295
- function round3(value: number): number {
296
- return Number(value.toFixed(3));
297
- }
298
-
299
- function round5(value: number): number {
300
- return Number(value.toFixed(5));
301
- }
@@ -1,2 +0,0 @@
1
- export { Geometry } from "./Geometry";
2
- export type { WideLineSegment } from "./Geometry";
package/src/Material.ts DELETED
@@ -1,209 +0,0 @@
1
- import { type UniformValue } from "./RenderDevice";
2
- import { TextureBinding } from "./TextureBinding";
3
-
4
- export type CullMode = "none" | "back" | "front";
5
- export type DepthCompare = "always" | "less-equal";
6
- export type ColorWriteMask = readonly [boolean, boolean, boolean, boolean];
7
- export type StencilCompare = "never" | "less" | "less-equal" | "greater" | "greater-equal" | "equal" | "not-equal" | "always";
8
- export type StencilOperation = "keep" | "zero" | "replace" | "increment" | "decrement" | "invert" | "increment-wrap" | "decrement-wrap";
9
-
10
- export interface ScissorRect {
11
- readonly x: number;
12
- readonly y: number;
13
- readonly width: number;
14
- readonly height: number;
15
- }
16
-
17
- export interface PolygonOffsetState {
18
- readonly factor: number;
19
- readonly units: number;
20
- }
21
-
22
- export interface StencilState {
23
- readonly compare?: StencilCompare;
24
- readonly reference?: number;
25
- readonly readMask?: number;
26
- readonly writeMask?: number;
27
- readonly fail?: StencilOperation;
28
- readonly depthFail?: StencilOperation;
29
- readonly depthPass?: StencilOperation;
30
- }
31
-
32
- export interface RenderState {
33
- readonly depthTest: boolean;
34
- readonly depthWrite: boolean;
35
- readonly cullMode: CullMode;
36
- readonly blend: boolean;
37
- readonly depthCompare: DepthCompare;
38
- readonly colorWrite: ColorWriteMask;
39
- readonly scissor?: ScissorRect | null;
40
- readonly polygonOffset?: PolygonOffsetState | null;
41
- readonly stencil?: StencilState | null;
42
- }
43
-
44
- export type MaterialUniformKind = "any" | "float" | "vec2" | "vec3" | "vec4" | "mat4" | "texture2d" | "textureCube";
45
-
46
- export interface MaterialUniformDescriptor {
47
- readonly name: string;
48
- readonly kind: MaterialUniformKind;
49
- readonly required?: boolean;
50
- }
51
-
52
- export interface MaterialDescriptor {
53
- readonly name?: string;
54
- readonly shaderKey: string;
55
- readonly shaderVariant?: string;
56
- readonly renderState?: Partial<RenderState>;
57
- readonly parameters?: Readonly<Record<string, UniformValue>>;
58
- readonly requiredAttributes?: readonly string[];
59
- readonly requiredUniforms?: readonly string[];
60
- readonly uniformSchema?: readonly MaterialUniformDescriptor[];
61
- }
62
-
63
- export const DEFAULT_RENDER_STATE: RenderState = {
64
- depthTest: true,
65
- depthWrite: true,
66
- cullMode: "back",
67
- blend: false,
68
- depthCompare: "less-equal",
69
- colorWrite: [true, true, true, true],
70
- scissor: null,
71
- polygonOffset: null,
72
- stencil: null
73
- };
74
-
75
- export class Material {
76
- public disposed = false;
77
- public readonly name: string;
78
- public readonly shaderKey: string;
79
- public readonly shaderVariant?: string;
80
- public readonly renderState: RenderState;
81
- public readonly requiredAttributes: readonly string[];
82
- public readonly requiredUniforms: readonly string[];
83
- public readonly uniformSchema: readonly MaterialUniformDescriptor[];
84
- protected readonly parameters = new Map<string, UniformValue>();
85
- private dirty = true;
86
- private revision = 0;
87
-
88
- constructor(descriptor: MaterialDescriptor) {
89
- if (!descriptor.shaderKey.trim()) {
90
- throw new Error("Material shaderKey is required");
91
- }
92
- this.name = descriptor.name ?? descriptor.shaderKey;
93
- this.shaderKey = descriptor.shaderKey;
94
- this.shaderVariant = validateShaderVariant(descriptor.shaderVariant);
95
- this.renderState = validateRenderState({ ...DEFAULT_RENDER_STATE, ...(descriptor.renderState ?? {}) });
96
- this.requiredAttributes = descriptor.requiredAttributes ?? [];
97
- this.uniformSchema = validateUniformSchema(descriptor.uniformSchema ?? deriveRequiredUniformSchema(descriptor.requiredUniforms ?? []));
98
- this.requiredUniforms = descriptor.requiredUniforms ?? this.uniformSchema.filter((uniform) => uniform.required !== false).map((uniform) => uniform.name);
99
- for (const [key, value] of Object.entries(descriptor.parameters ?? {})) {
100
- this.setParameter(key, value);
101
- }
102
- }
103
-
104
- setParameter(name: string, value: UniformValue): void {
105
- this.assertAlive();
106
- if (!name.trim()) {
107
- throw new Error("Material parameter name is required");
108
- }
109
- this.parameters.set(name, cloneUniformValue(value));
110
- this.dirty = true;
111
- this.revision += 1;
112
- }
113
-
114
- getParameter(name: string): UniformValue | undefined {
115
- this.assertAlive();
116
- const value = this.parameters.get(name);
117
- return value === undefined ? undefined : cloneUniformValue(value);
118
- }
119
-
120
- getParameters(): ReadonlyMap<string, UniformValue> {
121
- this.assertAlive();
122
- const output = new Map<string, UniformValue>();
123
- for (const [key, value] of this.parameters) {
124
- output.set(key, cloneUniformValue(value));
125
- }
126
- return output;
127
- }
128
-
129
- isDirty(): boolean {
130
- return this.dirty;
131
- }
132
-
133
- getRevision(): number {
134
- return this.revision;
135
- }
136
-
137
- markClean(): void {
138
- this.assertAlive();
139
- this.dirty = false;
140
- }
141
-
142
- dispose(): void {
143
- if (this.disposed) return;
144
- this.parameters.clear();
145
- this.dirty = false;
146
- this.disposed = true;
147
- }
148
-
149
- private assertAlive(): void {
150
- if (this.disposed) {
151
- throw new Error(`Material ${this.name} is disposed`);
152
- }
153
- }
154
- }
155
-
156
- function validateShaderVariant(variant: string | undefined): string | undefined {
157
- if (variant === undefined) return undefined;
158
- const trimmed = variant.trim();
159
- if (!trimmed) {
160
- throw new Error("Material shaderVariant must be non-empty when provided");
161
- }
162
- return trimmed;
163
- }
164
-
165
- export function validateRenderState(state: RenderState): RenderState {
166
- if (state.blend && state.depthWrite) {
167
- throw new Error("Transparent blended materials must disable depthWrite");
168
- }
169
- if (state.scissor) {
170
- if (state.scissor.width < 0 || state.scissor.height < 0) {
171
- throw new Error("RenderState scissor width and height must be non-negative");
172
- }
173
- }
174
- if (state.stencil) {
175
- const reference = state.stencil.reference ?? 0;
176
- if (!Number.isInteger(reference) || reference < 0) {
177
- throw new Error("RenderState stencil reference must be a non-negative integer");
178
- }
179
- }
180
- return state;
181
- }
182
-
183
- function deriveRequiredUniformSchema(requiredUniforms: readonly string[]): readonly MaterialUniformDescriptor[] {
184
- return requiredUniforms.map((name) => ({ name, kind: "any", required: true }));
185
- }
186
-
187
- function validateUniformSchema(schema: readonly MaterialUniformDescriptor[]): readonly MaterialUniformDescriptor[] {
188
- const seen = new Set<string>();
189
- return schema.map((uniform) => {
190
- if (!uniform.name.trim()) {
191
- throw new Error("Material uniform schema name is required");
192
- }
193
- if (seen.has(uniform.name)) {
194
- throw new Error(`Duplicate material uniform schema entry: ${uniform.name}`);
195
- }
196
- seen.add(uniform.name);
197
- return { ...uniform, required: uniform.required ?? true };
198
- });
199
- }
200
-
201
- function cloneUniformValue(value: UniformValue): UniformValue {
202
- if (typeof value === "number") {
203
- return value;
204
- }
205
- if (value instanceof TextureBinding) {
206
- return value;
207
- }
208
- return ArrayBuffer.isView(value) ? new (value.constructor as Float32ArrayConstructor)(value as Float32Array) : [...value];
209
- }
@@ -1,131 +0,0 @@
1
- import { Material } from "./Material";
2
- import { MaterialInstance } from "./MaterialInstance";
3
- import { type RenderShaderProgram, type UniformValue } from "./RenderDevice";
4
- import { TextureBinding } from "./TextureBinding";
5
-
6
- export interface MaterialBindingResult {
7
- readonly shader: RenderShaderProgram;
8
- readonly uniforms: ReadonlyMap<string, UniformValue>;
9
- readonly diagnostics: readonly string[];
10
- readonly warnings: readonly string[];
11
- }
12
-
13
- export class MaterialBinding {
14
- bind(materialLike: Material | MaterialInstance, shader: RenderShaderProgram): MaterialBindingResult {
15
- const material = materialLike instanceof MaterialInstance ? materialLike.baseMaterial : materialLike;
16
- const uniforms = materialLike.getParameters();
17
- const diagnostics: string[] = [];
18
- const warnings: string[] = [];
19
-
20
- for (const attribute of material.requiredAttributes) {
21
- if (!shader.reflection.attributes.has(attribute)) {
22
- diagnostics.push(`Missing shader attribute: ${attribute}`);
23
- }
24
- }
25
- for (const uniform of material.requiredUniforms) {
26
- if (!shader.reflection.uniforms.has(uniform)) {
27
- diagnostics.push(`Missing shader uniform: ${uniform}`);
28
- }
29
- if (!uniforms.has(uniform)) {
30
- diagnostics.push(`Missing material parameter: ${uniform}`);
31
- }
32
- }
33
- for (const uniform of material.uniformSchema) {
34
- if (uniform.required !== false && !shader.reflection.uniforms.has(uniform.name)) {
35
- diagnostics.push(`Missing shader uniform declared by material schema: ${uniform.name}`);
36
- }
37
- const value = uniforms.get(uniform.name);
38
- if (value === undefined) {
39
- if (uniform.required !== false) {
40
- diagnostics.push(`Missing material parameter declared by schema: ${uniform.name}`);
41
- }
42
- continue;
43
- }
44
- const typeDiagnostic = validateUniformSchemaValue(uniform.name, uniform.kind, value);
45
- if (typeDiagnostic) {
46
- diagnostics.push(typeDiagnostic);
47
- }
48
- }
49
- for (const [name, value] of uniforms) {
50
- if (value instanceof TextureBinding) {
51
- const validation = value.validate();
52
- diagnostics.push(...validation.diagnostics);
53
- warnings.push(...validation.warnings);
54
- } else {
55
- const valueDiagnostics = uniformValueDiagnostics(name, value);
56
- if (valueDiagnostics.length > 0) {
57
- diagnostics.push(...valueDiagnostics);
58
- }
59
- }
60
- }
61
- if (diagnostics.length > 0) {
62
- throw new MaterialBindingError("Material binding validation failed", diagnostics);
63
- }
64
- return { shader, uniforms, diagnostics: warnings, warnings };
65
- }
66
- }
67
-
68
- export class MaterialBindingError extends Error {
69
- constructor(
70
- message: string,
71
- public readonly diagnostics: readonly string[]
72
- ) {
73
- super(message);
74
- this.name = "MaterialBindingError";
75
- }
76
- }
77
-
78
- function uniformValueDiagnostics(name: string, value: unknown): readonly string[] {
79
- if (typeof value === "number") {
80
- return Number.isFinite(value) ? [] : [`Unsupported uniform value for ${name}: non-finite number`];
81
- }
82
- if (ArrayBuffer.isView(value)) {
83
- const values = Array.from(value as Float32Array | Int32Array | Uint32Array);
84
- return values.every(Number.isFinite) ? [] : [`Unsupported uniform value for ${name}: typed array contains non-finite values`];
85
- }
86
- if (Array.isArray(value)) {
87
- return value.every((entry) => typeof entry === "number" && Number.isFinite(entry))
88
- ? []
89
- : [`Unsupported uniform value for ${name}: array must contain finite numbers`];
90
- }
91
- return [`Unsupported uniform value for ${name}`];
92
- }
93
-
94
- function validateUniformSchemaValue(name: string, kind: string, value: UniformValue): string | null {
95
- if (kind === "any") {
96
- return null;
97
- }
98
- if (kind === "texture2d" || kind === "textureCube") {
99
- return value instanceof TextureBinding ? null : `Material uniform ${name} must be ${kind}`;
100
- }
101
- if (value instanceof TextureBinding) {
102
- return `Material uniform ${name} must be ${kind}, got texture binding`;
103
- }
104
- const numbers = typeof value === "number"
105
- ? [value]
106
- : ArrayBuffer.isView(value)
107
- ? Array.from(value as Float32Array | Int32Array | Uint32Array)
108
- : Array.from(value);
109
- const expected = scalarCount(kind);
110
- if (numbers.length !== expected) {
111
- return `Material uniform ${name} must be ${kind} with ${expected} scalar values, got ${numbers.length}`;
112
- }
113
- return numbers.every(Number.isFinite) ? null : `Material uniform ${name} must contain finite ${kind} scalar values`;
114
- }
115
-
116
- function scalarCount(kind: string): number {
117
- switch (kind) {
118
- case "float":
119
- return 1;
120
- case "vec2":
121
- return 2;
122
- case "vec3":
123
- return 3;
124
- case "vec4":
125
- return 4;
126
- case "mat4":
127
- return 16;
128
- default:
129
- return 0;
130
- }
131
- }