@onerjs/core 8.55.9 → 8.56.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 (265) hide show
  1. package/AudioV2/webAudio/webAudioEngine.d.ts +7 -0
  2. package/AudioV2/webAudio/webAudioEngine.js +6 -5
  3. package/AudioV2/webAudio/webAudioEngine.js.map +1 -1
  4. package/Cameras/arcRotateCamera.pure.js +24 -0
  5. package/Cameras/arcRotateCamera.pure.js.map +1 -1
  6. package/Culling/Helper/boundingInfoHelper.js +8 -4
  7. package/Culling/Helper/boundingInfoHelper.js.map +1 -1
  8. package/Engines/AbstractEngine/abstractEngine.textureLoaders.d.ts +5 -1
  9. package/Engines/AbstractEngine/abstractEngine.textureLoaders.js +7 -3
  10. package/Engines/AbstractEngine/abstractEngine.textureLoaders.js.map +1 -1
  11. package/Engines/AbstractEngine/abstractEngine.textureLoaders.pure.d.ts +6 -0
  12. package/Engines/AbstractEngine/abstractEngine.textureLoaders.pure.js +16 -0
  13. package/Engines/AbstractEngine/abstractEngine.textureLoaders.pure.js.map +1 -0
  14. package/Engines/AbstractEngine/pure.d.ts +1 -0
  15. package/Engines/AbstractEngine/pure.js +1 -0
  16. package/Engines/AbstractEngine/pure.js.map +1 -1
  17. package/Engines/IDrawContext.d.ts +2 -0
  18. package/Engines/IDrawContext.js.map +1 -1
  19. package/Engines/WebGPU/webgpuDrawContext.d.ts +8 -0
  20. package/Engines/WebGPU/webgpuDrawContext.js +15 -0
  21. package/Engines/WebGPU/webgpuDrawContext.js.map +1 -1
  22. package/Engines/abstractEngine.pure.js +2 -2
  23. package/Engines/abstractEngine.pure.js.map +1 -1
  24. package/Engines/constants.d.ts +5 -0
  25. package/Engines/constants.js +5 -0
  26. package/Engines/constants.js.map +1 -1
  27. package/Engines/engine.d.ts +11 -3
  28. package/Engines/webgpuEngine.d.ts +1 -0
  29. package/Engines/webgpuEngine.js +1 -0
  30. package/Engines/webgpuEngine.js.map +1 -1
  31. package/Engines/webgpuEngine.pure.d.ts +10 -0
  32. package/Engines/webgpuEngine.pure.js +15 -1
  33. package/Engines/webgpuEngine.pure.js.map +1 -1
  34. package/FrameGraph/Node/Blocks/Rendering/geometryRendererBlock.pure.d.ts +4 -0
  35. package/FrameGraph/Node/Blocks/Rendering/geometryRendererBlock.pure.js +12 -0
  36. package/FrameGraph/Node/Blocks/Rendering/geometryRendererBlock.pure.js.map +1 -1
  37. package/FrameGraph/Node/Blocks/inputBlock.pure.js +2 -1
  38. package/FrameGraph/Node/Blocks/inputBlock.pure.js.map +1 -1
  39. package/FrameGraph/Node/Types/nodeRenderGraphTypes.d.ts +2 -0
  40. package/FrameGraph/Node/Types/nodeRenderGraphTypes.js +2 -0
  41. package/FrameGraph/Node/Types/nodeRenderGraphTypes.js.map +1 -1
  42. package/FrameGraph/Tasks/Rendering/geometryRendererTask.d.ts +21 -0
  43. package/FrameGraph/Tasks/Rendering/geometryRendererTask.js +45 -0
  44. package/FrameGraph/Tasks/Rendering/geometryRendererTask.js.map +1 -1
  45. package/FrameGraph/Tasks/Rendering/iblShadowsRendererTask.pure.js +2 -5
  46. package/FrameGraph/Tasks/Rendering/iblShadowsRendererTask.pure.js.map +1 -1
  47. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.pure.d.ts +1 -0
  48. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.pure.js +18 -3
  49. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.pure.js.map +1 -1
  50. package/Materials/Node/Blocks/Fragment/imageProcessingBlock.pure.js +2 -0
  51. package/Materials/Node/Blocks/Fragment/imageProcessingBlock.pure.js.map +1 -1
  52. package/Materials/Node/Blocks/Fragment/prePassOutputBlock.pure.js +5 -21
  53. package/Materials/Node/Blocks/Fragment/prePassOutputBlock.pure.js.map +1 -1
  54. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.pure.js +1 -0
  55. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.pure.js.map +1 -1
  56. package/Materials/Node/Blocks/powBlock.pure.js +2 -1
  57. package/Materials/Node/Blocks/powBlock.pure.js.map +1 -1
  58. package/Materials/Node/Blocks/triPlanarBlock.pure.js +14 -12
  59. package/Materials/Node/Blocks/triPlanarBlock.pure.js.map +1 -1
  60. package/Materials/Node/nodeMaterial.pure.d.ts +11 -0
  61. package/Materials/Node/nodeMaterial.pure.js +11 -0
  62. package/Materials/Node/nodeMaterial.pure.js.map +1 -1
  63. package/Materials/Node/nodeMaterialBuildState.d.ts +4 -3
  64. package/Materials/Node/nodeMaterialBuildState.js +7 -1
  65. package/Materials/Node/nodeMaterialBuildState.js.map +1 -1
  66. package/Materials/PBR/openpbrMaterial.pure.d.ts +4 -0
  67. package/Materials/PBR/pbrBaseMaterial.pure.d.ts +4 -0
  68. package/Materials/Textures/index.d.ts +1 -0
  69. package/Materials/Textures/index.js +1 -0
  70. package/Materials/Textures/index.js.map +1 -1
  71. package/Materials/Textures/textureProcessor.d.ts +29 -6
  72. package/Materials/Textures/textureProcessor.js +22 -16
  73. package/Materials/Textures/textureProcessor.js.map +1 -1
  74. package/Materials/drawWrapper.js +3 -0
  75. package/Materials/drawWrapper.js.map +1 -1
  76. package/Materials/imageProcessingConfiguration.defines.d.ts +3 -0
  77. package/Materials/imageProcessingConfiguration.defines.js +2 -0
  78. package/Materials/imageProcessingConfiguration.defines.js.map +1 -1
  79. package/Materials/imageProcessingConfiguration.functions.js +3 -0
  80. package/Materials/imageProcessingConfiguration.functions.js.map +1 -1
  81. package/Materials/imageProcessingConfiguration.pure.d.ts +58 -0
  82. package/Materials/imageProcessingConfiguration.pure.js +123 -2
  83. package/Materials/imageProcessingConfiguration.pure.js.map +1 -1
  84. package/Materials/materialHelper.geometryrendering.d.ts +19 -0
  85. package/Materials/materialHelper.geometryrendering.js +29 -1
  86. package/Materials/materialHelper.geometryrendering.js.map +1 -1
  87. package/Materials/prepass.defines.d.ts +3 -0
  88. package/Materials/prepass.defines.js +3 -0
  89. package/Materials/prepass.defines.js.map +1 -1
  90. package/Materials/standardMaterial.pure.d.ts +4 -0
  91. package/Materials/uniformBuffer.d.ts +29 -0
  92. package/Materials/uniformBuffer.js +146 -0
  93. package/Materials/uniformBuffer.js.map +1 -1
  94. package/Maths/colorTemperature.functions.d.ts +29 -0
  95. package/Maths/colorTemperature.functions.js +196 -0
  96. package/Maths/colorTemperature.functions.js.map +1 -0
  97. package/Maths/index.d.ts +1 -0
  98. package/Maths/index.js +1 -0
  99. package/Maths/index.js.map +1 -1
  100. package/Maths/math.vector.pure.d.ts +1 -5
  101. package/Maths/math.vector.pure.js.map +1 -1
  102. package/Maths/pure.d.ts +1 -0
  103. package/Maths/pure.js +1 -0
  104. package/Maths/pure.js.map +1 -1
  105. package/Misc/filesInput.d.ts +15 -0
  106. package/Misc/filesInput.js +156 -74
  107. package/Misc/filesInput.js.map +1 -1
  108. package/Misc/observable.pure.js +1 -3
  109. package/Misc/observable.pure.js.map +1 -1
  110. package/Misc/tools.pure.js +1 -1
  111. package/Misc/tools.pure.js.map +1 -1
  112. package/PostProcesses/imageProcessingPostProcess.d.ts +41 -1
  113. package/PostProcesses/imageProcessingPostProcess.js +41 -1
  114. package/PostProcesses/imageProcessingPostProcess.js.map +1 -1
  115. package/PostProcesses/thinImageProcessingPostProcess.d.ts +50 -0
  116. package/PostProcesses/thinImageProcessingPostProcess.js +65 -0
  117. package/PostProcesses/thinImageProcessingPostProcess.js.map +1 -1
  118. package/Rendering/IBLShadows/iblShadowsMaterialCompatibility.pure.d.ts +12 -0
  119. package/Rendering/IBLShadows/iblShadowsMaterialCompatibility.pure.js +22 -0
  120. package/Rendering/IBLShadows/iblShadowsMaterialCompatibility.pure.js.map +1 -0
  121. package/Rendering/IBLShadows/iblShadowsPluginMaterial.pure.d.ts +1 -0
  122. package/Rendering/IBLShadows/iblShadowsPluginMaterial.pure.js +39 -0
  123. package/Rendering/IBLShadows/iblShadowsPluginMaterial.pure.js.map +1 -1
  124. package/Rendering/IBLShadows/iblShadowsRenderPipeline.pure.js +2 -4
  125. package/Rendering/IBLShadows/iblShadowsRenderPipeline.pure.js.map +1 -1
  126. package/Rendering/IBLShadows/pure.d.ts +1 -0
  127. package/Rendering/IBLShadows/pure.js +1 -0
  128. package/Rendering/IBLShadows/pure.js.map +1 -1
  129. package/Rendering/fluidRenderer/fluidRenderingObject.d.ts +11 -0
  130. package/Rendering/fluidRenderer/fluidRenderingObject.js +36 -14
  131. package/Rendering/fluidRenderer/fluidRenderingObject.js.map +1 -1
  132. package/Rendering/fluidRenderer/fluidRenderingObjectCustomParticles.d.ts +5 -0
  133. package/Rendering/fluidRenderer/fluidRenderingObjectCustomParticles.js +16 -3
  134. package/Rendering/fluidRenderer/fluidRenderingObjectCustomParticles.js.map +1 -1
  135. package/Rendering/fluidRenderer/fluidRenderingObjectParticleSystem.d.ts +5 -0
  136. package/Rendering/fluidRenderer/fluidRenderingObjectParticleSystem.js +12 -0
  137. package/Rendering/fluidRenderer/fluidRenderingObjectParticleSystem.js.map +1 -1
  138. package/Rendering/geometryBufferRenderer.pure.d.ts +30 -0
  139. package/Rendering/geometryBufferRenderer.pure.js +84 -0
  140. package/Rendering/geometryBufferRenderer.pure.js.map +1 -1
  141. package/Rendering/iblCdfGenerator.js +10 -1
  142. package/Rendering/iblCdfGenerator.js.map +1 -1
  143. package/Shaders/ShadersInclude/hdrFilteringFunctions.js +1 -1
  144. package/Shaders/ShadersInclude/hdrFilteringFunctions.js.map +1 -1
  145. package/Shaders/ShadersInclude/helperFunctions.js +2 -2
  146. package/Shaders/ShadersInclude/helperFunctions.js.map +1 -1
  147. package/Shaders/ShadersInclude/imageProcessingDeclaration.js +3 -0
  148. package/Shaders/ShadersInclude/imageProcessingDeclaration.js.map +1 -1
  149. package/Shaders/ShadersInclude/imageProcessingFunctions.js +3 -0
  150. package/Shaders/ShadersInclude/imageProcessingFunctions.js.map +1 -1
  151. package/Shaders/ShadersInclude/objectIdFunctions.d.ts +5 -0
  152. package/Shaders/ShadersInclude/objectIdFunctions.js +22 -0
  153. package/Shaders/ShadersInclude/objectIdFunctions.js.map +1 -0
  154. package/Shaders/ShadersInclude/openpbrBlockPrePass.js +3 -0
  155. package/Shaders/ShadersInclude/openpbrBlockPrePass.js.map +1 -1
  156. package/Shaders/ShadersInclude/openpbrDirectLighting.js +34 -4
  157. package/Shaders/ShadersInclude/openpbrDirectLighting.js.map +1 -1
  158. package/Shaders/ShadersInclude/openpbrIblFunctions.js +8 -2
  159. package/Shaders/ShadersInclude/openpbrIblFunctions.js.map +1 -1
  160. package/Shaders/ShadersInclude/pbrBlockPrePass.js +3 -0
  161. package/Shaders/ShadersInclude/pbrBlockPrePass.js.map +1 -1
  162. package/Shaders/ShadersInclude/pbrDirectLightingFunctions.js +5 -0
  163. package/Shaders/ShadersInclude/pbrDirectLightingFunctions.js.map +1 -1
  164. package/Shaders/ShadersInclude/prePassDeclaration.d.ts +1 -0
  165. package/Shaders/ShadersInclude/prePassDeclaration.js +5 -0
  166. package/Shaders/ShadersInclude/prePassDeclaration.js.map +1 -1
  167. package/Shaders/default.fragment.js +5 -1
  168. package/Shaders/default.fragment.js.map +1 -1
  169. package/Shaders/fluidRenderingParticleDepth.vertex.js +7 -1
  170. package/Shaders/fluidRenderingParticleDepth.vertex.js.map +1 -1
  171. package/Shaders/fluidRenderingParticleDiffuse.vertex.js +7 -1
  172. package/Shaders/fluidRenderingParticleDiffuse.vertex.js.map +1 -1
  173. package/Shaders/fluidRenderingParticleThickness.vertex.js +7 -1
  174. package/Shaders/fluidRenderingParticleThickness.vertex.js.map +1 -1
  175. package/Shaders/geometry.fragment.js +9 -1
  176. package/Shaders/geometry.fragment.js.map +1 -1
  177. package/Shaders/openpbr.fragment.js +2 -1
  178. package/Shaders/openpbr.fragment.js.map +1 -1
  179. package/Shaders/pbr.fragment.js +2 -1
  180. package/Shaders/pbr.fragment.js.map +1 -1
  181. package/ShadersWGSL/ShadersInclude/imageProcessingDeclaration.js +3 -0
  182. package/ShadersWGSL/ShadersInclude/imageProcessingDeclaration.js.map +1 -1
  183. package/ShadersWGSL/ShadersInclude/imageProcessingFunctions.js +3 -0
  184. package/ShadersWGSL/ShadersInclude/imageProcessingFunctions.js.map +1 -1
  185. package/ShadersWGSL/ShadersInclude/objectIdFunctions.d.ts +5 -0
  186. package/ShadersWGSL/ShadersInclude/objectIdFunctions.js +22 -0
  187. package/ShadersWGSL/ShadersInclude/objectIdFunctions.js.map +1 -0
  188. package/ShadersWGSL/ShadersInclude/openpbrBlockPrePass.js +3 -0
  189. package/ShadersWGSL/ShadersInclude/openpbrBlockPrePass.js.map +1 -1
  190. package/ShadersWGSL/ShadersInclude/openpbrDirectLighting.js +35 -5
  191. package/ShadersWGSL/ShadersInclude/openpbrDirectLighting.js.map +1 -1
  192. package/ShadersWGSL/ShadersInclude/openpbrDirectLightingInit.js +1 -1
  193. package/ShadersWGSL/ShadersInclude/openpbrDirectLightingInit.js.map +1 -1
  194. package/ShadersWGSL/ShadersInclude/openpbrIblFunctions.js +8 -2
  195. package/ShadersWGSL/ShadersInclude/openpbrIblFunctions.js.map +1 -1
  196. package/ShadersWGSL/ShadersInclude/pbrBlockPrePass.js +3 -0
  197. package/ShadersWGSL/ShadersInclude/pbrBlockPrePass.js.map +1 -1
  198. package/ShadersWGSL/ShadersInclude/pbrDirectLightingFunctions.js +5 -0
  199. package/ShadersWGSL/ShadersInclude/pbrDirectLightingFunctions.js.map +1 -1
  200. package/ShadersWGSL/ShadersInclude/prePassDeclaration.d.ts +1 -0
  201. package/ShadersWGSL/ShadersInclude/prePassDeclaration.js +5 -0
  202. package/ShadersWGSL/ShadersInclude/prePassDeclaration.js.map +1 -1
  203. package/ShadersWGSL/default.fragment.js +5 -1
  204. package/ShadersWGSL/default.fragment.js.map +1 -1
  205. package/ShadersWGSL/fluidRenderingParticleDepth.vertex.js +16 -4
  206. package/ShadersWGSL/fluidRenderingParticleDepth.vertex.js.map +1 -1
  207. package/ShadersWGSL/fluidRenderingParticleDiffuse.vertex.js +15 -3
  208. package/ShadersWGSL/fluidRenderingParticleDiffuse.vertex.js.map +1 -1
  209. package/ShadersWGSL/fluidRenderingParticleThickness.vertex.js +15 -3
  210. package/ShadersWGSL/fluidRenderingParticleThickness.vertex.js.map +1 -1
  211. package/ShadersWGSL/geometry.fragment.js +9 -1
  212. package/ShadersWGSL/geometry.fragment.js.map +1 -1
  213. package/ShadersWGSL/openpbr.fragment.js +2 -1
  214. package/ShadersWGSL/openpbr.fragment.js.map +1 -1
  215. package/ShadersWGSL/pbr.fragment.js +2 -1
  216. package/ShadersWGSL/pbr.fragment.js.map +1 -1
  217. package/XR/features/Layers/WebXRCompositionLayer.d.ts +52 -0
  218. package/XR/features/Layers/WebXRCompositionLayer.js +80 -0
  219. package/XR/features/Layers/WebXRCompositionLayer.js.map +1 -1
  220. package/XR/features/WebXRControllerPointerSelection.pure.js +2 -1
  221. package/XR/features/WebXRControllerPointerSelection.pure.js.map +1 -1
  222. package/XR/features/WebXRControllerTeleportation.pure.js +2 -1
  223. package/XR/features/WebXRControllerTeleportation.pure.js.map +1 -1
  224. package/XR/features/WebXRDepthSensing.pure.d.ts +21 -0
  225. package/XR/features/WebXRDepthSensing.pure.js +42 -0
  226. package/XR/features/WebXRDepthSensing.pure.js.map +1 -1
  227. package/XR/features/WebXRHandTracking.pure.js +2 -0
  228. package/XR/features/WebXRHandTracking.pure.js.map +1 -1
  229. package/XR/features/WebXRLayers.pure.d.ts +12 -0
  230. package/XR/features/WebXRLayers.pure.js +31 -1
  231. package/XR/features/WebXRLayers.pure.js.map +1 -1
  232. package/XR/features/WebXRTrackedSources.d.ts +5 -0
  233. package/XR/features/WebXRTrackedSources.js +8 -0
  234. package/XR/features/WebXRTrackedSources.js.map +1 -0
  235. package/XR/features/WebXRTrackedSources.pure.d.ts +70 -0
  236. package/XR/features/WebXRTrackedSources.pure.js +153 -0
  237. package/XR/features/WebXRTrackedSources.pure.js.map +1 -0
  238. package/XR/features/index.d.ts +1 -0
  239. package/XR/features/index.js +1 -0
  240. package/XR/features/index.js.map +1 -1
  241. package/XR/features/pure.d.ts +1 -0
  242. package/XR/features/pure.js +1 -0
  243. package/XR/features/pure.js.map +1 -1
  244. package/XR/motionController/webXRAbstractMotionController.d.ts +53 -1
  245. package/XR/motionController/webXRAbstractMotionController.js +61 -0
  246. package/XR/motionController/webXRAbstractMotionController.js.map +1 -1
  247. package/XR/webXRDefaultExperience.js +8 -4
  248. package/XR/webXRDefaultExperience.js.map +1 -1
  249. package/XR/webXRExperienceHelper.js +86 -44
  250. package/XR/webXRExperienceHelper.js.map +1 -1
  251. package/XR/webXRFeaturesManager.d.ts +9 -0
  252. package/XR/webXRFeaturesManager.js +4 -0
  253. package/XR/webXRFeaturesManager.js.map +1 -1
  254. package/XR/webXRGraphicsBinding.d.ts +29 -0
  255. package/XR/webXRGraphicsBinding.js +40 -0
  256. package/XR/webXRGraphicsBinding.js.map +1 -1
  257. package/XR/webXRInputSource.js +1 -1
  258. package/XR/webXRInputSource.js.map +1 -1
  259. package/XR/webXRLayerWrapper.d.ts +7 -5
  260. package/XR/webXRLayerWrapper.js +10 -7
  261. package/XR/webXRLayerWrapper.js.map +1 -1
  262. package/XR/webXRSessionManager.d.ts +45 -0
  263. package/XR/webXRSessionManager.js +174 -29
  264. package/XR/webXRSessionManager.js.map +1 -1
  265. package/package.json +1 -1
@@ -0,0 +1,196 @@
1
+ import { Clamp } from "./math.scalar.functions.js";
2
+ import { Matrix, Vector2, Vector3 } from "./math.vector.pure.js";
3
+ /**
4
+ * Tabulated Planckian locus in CIE 1960 UCS (u, v) space, with the local isotherm slope `t` used to offset
5
+ * a chromaticity along the tint axis. Source: Wyszecki & Stiles, "Color Science", 2nd ed., 1982, pp. 227-228.
6
+ * Each row is [mired, u, v, t].
7
+ */
8
+ const PlanckianLocusTable = [
9
+ [0, 0.18006, 0.26352, -0.24341],
10
+ [10, 0.18066, 0.26589, -0.25479],
11
+ [20, 0.18133, 0.26846, -0.26876],
12
+ [30, 0.18208, 0.27119, -0.28539],
13
+ [40, 0.18293, 0.27407, -0.3047],
14
+ [50, 0.18388, 0.27709, -0.32675],
15
+ [60, 0.18494, 0.28021, -0.35156],
16
+ [70, 0.18611, 0.28342, -0.37915],
17
+ [80, 0.1874, 0.28668, -0.40955],
18
+ [90, 0.1888, 0.28997, -0.44278],
19
+ [100, 0.19032, 0.29326, -0.47888],
20
+ [125, 0.19462, 0.30141, -0.58204],
21
+ [150, 0.19962, 0.30921, -0.70471],
22
+ [175, 0.20525, 0.31647, -0.84901],
23
+ [200, 0.21142, 0.32312, -1.0182],
24
+ [225, 0.21807, 0.32909, -1.2168],
25
+ [250, 0.22511, 0.33439, -1.4512],
26
+ [275, 0.23247, 0.33904, -1.7298],
27
+ [300, 0.2401, 0.34308, -2.0637],
28
+ [325, 0.24792, 0.34655, -2.4681],
29
+ [350, 0.25591, 0.34951, -2.9641],
30
+ [375, 0.264, 0.352, -3.5814],
31
+ [400, 0.27218, 0.35407, -4.3633],
32
+ [425, 0.28039, 0.35577, -5.3762],
33
+ [450, 0.28863, 0.35714, -6.7262],
34
+ [475, 0.29685, 0.35823, -8.5955],
35
+ [500, 0.30505, 0.35907, -11.324],
36
+ [525, 0.3132, 0.35968, -15.628],
37
+ [550, 0.32129, 0.36011, -23.325],
38
+ [575, 0.32931, 0.36038, -40.77],
39
+ [600, 0.33724, 0.36051, -116.45],
40
+ ];
41
+ /**
42
+ * The minimum correlated color temperature, in Kelvin, representable by {@link TemperatureTintToXyz} (there is no
43
+ * upper bound: increasingly high temperatures approach mired 0, already within the tabulated range).
44
+ */
45
+ export const MinTemperatureKelvin = 1e6 / PlanckianLocusTable[PlanckianLocusTable.length - 1][0];
46
+ /**
47
+ * The maximum magnitude of the tint offset accepted by {@link TemperatureTintToXyz}, in either direction.
48
+ */
49
+ export const MaxTintMagnitude = 150;
50
+ /**
51
+ * Converts a correlated color temperature and tint offset into the CIE XYZ (Y = 1) coordinates of the
52
+ * corresponding illuminant white point, using a tabulated approximation of the Planckian locus in CIE 1960 UCS
53
+ * (u, v) space.
54
+ * @param temperatureKelvin The correlated color temperature of the illuminant, in Kelvin
55
+ * @param tint An offset perpendicular to the Planckian locus (the green/magenta axis), in the range
56
+ * [-{@link MaxTintMagnitude}, {@link MaxTintMagnitude}]
57
+ * @returns The CIE XYZ (Y = 1) coordinates of the illuminant white point
58
+ */
59
+ export function TemperatureTintToXyz(temperatureKelvin, tint) {
60
+ // Clamp before taking the reciprocal: a non-positive or NaN Kelvin value has no valid reciprocal-mired
61
+ // representation, and taking 1e6 / temperatureKelvin first (before clamping the result) would map negative
62
+ // inputs to the *hottest* end of the table instead of the coldest/minimum one.
63
+ const safeTemperatureKelvin = Number.isNaN(temperatureKelvin) ? MinTemperatureKelvin : Math.max(temperatureKelvin, MinTemperatureKelvin);
64
+ const mired = Clamp(1e6 / safeTemperatureKelvin, PlanckianLocusTable[0][0], PlanckianLocusTable[PlanckianLocusTable.length - 1][0]);
65
+ // Binary search for the table row pair bracketing `mired` (the table is sorted ascending by mired).
66
+ let low = 0;
67
+ let high = PlanckianLocusTable.length - 1;
68
+ while (high - low > 1) {
69
+ const mid = (low + high) >> 1;
70
+ if (PlanckianLocusTable[mid][0] <= mired) {
71
+ low = mid;
72
+ }
73
+ else {
74
+ high = mid;
75
+ }
76
+ }
77
+ const index = low;
78
+ const [lowMired, lowU, lowV, lowT] = PlanckianLocusTable[index];
79
+ const [highMired, highU, highV, highT] = PlanckianLocusTable[index + 1];
80
+ const f = (mired - lowMired) / (highMired - lowMired);
81
+ const uv = Vector2.Lerp(new Vector2(lowU, lowV), new Vector2(highU, highV), f);
82
+ const isothermLow = Vector2.Normalize(new Vector2(1, lowT));
83
+ const isothermHigh = Vector2.Normalize(new Vector2(1, highT));
84
+ const isotherm = Vector2.Normalize(Vector2.Lerp(isothermLow, isothermHigh, f));
85
+ const clampedTint = Clamp(tint, -MaxTintMagnitude, MaxTintMagnitude);
86
+ uv.subtractInPlace(isotherm.scale(clampedTint / 3000));
87
+ // CIE 1960 (u, v) -> CIE xyY (Y = 1) -> CIE XYZ.
88
+ const denom = 2 * uv.x - 8 * uv.y + 4;
89
+ const x = (3 * uv.x) / denom;
90
+ const y = (2 * uv.y) / denom;
91
+ return new Vector3(x / y, 1, (1 - x - y) / y);
92
+ }
93
+ // `Matrix.FromArray` reads values column-major, so each 3x3 matrix below is written column-by-column, not row-by-row.
94
+ /**
95
+ * The Bradford cone-response matrix used for chromatic adaptation.
96
+ */
97
+ // prettier-ignore
98
+ const BradfordMatrix = Matrix.FromArray([
99
+ 0.8951, -0.7502, 0.0389, 0,
100
+ 0.2664, 1.7135, -0.0685, 0,
101
+ -0.1614, 0.0367, 1.0296, 0,
102
+ 0, 0, 0, 1,
103
+ ]);
104
+ const InverseBradfordMatrix = Matrix.Invert(BradfordMatrix);
105
+ /**
106
+ * Computes a per-channel Bradford adaptation ratio, clamped to avoid extreme temperature/tint combinations
107
+ * blowing up the resulting matrix when a cone-response component approaches zero.
108
+ * @param destComponent The destination white's cone-response component
109
+ * @param sourceComponent The source white's cone-response component
110
+ * @returns The ratio to use for this channel, clamped to [0.1, 10]
111
+ */
112
+ function ClampedAdaptationRatio(destComponent, sourceComponent) {
113
+ const ratio = sourceComponent > 0 ? destComponent / sourceComponent : 10;
114
+ return Clamp(ratio, 0.1, 10);
115
+ }
116
+ /**
117
+ * Computes the Bradford chromatic-adaptation matrix that maps CIE XYZ values from `sourceWhiteXYZ` to `destWhiteXYZ`.
118
+ * @param sourceWhiteXYZ The CIE XYZ (Y = 1) coordinates of the source reference white
119
+ * @param destWhiteXYZ The CIE XYZ (Y = 1) coordinates of the destination reference white
120
+ * @returns A matrix mapping source-referenced XYZ to destination-referenced XYZ
121
+ */
122
+ function BradfordAdapt(sourceWhiteXYZ, destWhiteXYZ) {
123
+ const sourceLMS = Vector3.TransformNormal(sourceWhiteXYZ, BradfordMatrix);
124
+ const destLMS = Vector3.TransformNormal(destWhiteXYZ, BradfordMatrix);
125
+ // prettier-ignore
126
+ const scale = Matrix.FromArray([
127
+ ClampedAdaptationRatio(destLMS.x, sourceLMS.x), 0, 0, 0,
128
+ 0, ClampedAdaptationRatio(destLMS.y, sourceLMS.y), 0, 0,
129
+ 0, 0, ClampedAdaptationRatio(destLMS.z, sourceLMS.z), 0,
130
+ 0, 0, 0, 1,
131
+ ]);
132
+ // adapt = InverseBradfordMatrix * scale * BradfordMatrix, written back-to-front since `A.multiply(B)` computes `B x A`.
133
+ const scaledByBradford = BradfordMatrix.multiply(scale);
134
+ return scaledByBradford.multiply(InverseBradfordMatrix);
135
+ }
136
+ /**
137
+ * The standard CIE Illuminant D65 white point, in CIE XYZ (Y = 1).
138
+ */
139
+ const StandardD65Xyz = new Vector3(0.95047, 1.0, 1.08883);
140
+ /**
141
+ * The standard sRGB / Rec.709 linear RGB to CIE XYZ matrix, calibrated to the externally-standardized CIE
142
+ * Illuminant D65 chromaticity - i.e. `StandardRgbToXyzD65 * (1, 1, 1) = StandardD65Xyz` exactly.
143
+ */
144
+ // prettier-ignore
145
+ const StandardRgbToXyzD65 = Matrix.FromArray([
146
+ 0.4124564, 0.2126729, 0.0193339, 0,
147
+ 0.3575761, 0.7151522, 0.119192, 0,
148
+ 0.1804375, 0.072175, 0.9503041, 0,
149
+ 0, 0, 0, 1,
150
+ ]);
151
+ /**
152
+ * The linear RGB to CIE XYZ matrix actually used by {@link GetWhiteBalanceMatrix}, recalibrated from
153
+ * {@link StandardRgbToXyzD65} via a single Bradford adaptation step so that neutral (1, 1, 1) maps exactly onto
154
+ * this module's own Planckian-locus approximation of 6500 K (see {@link TemperatureTintToXyz}) instead of the
155
+ * externally-standardized CIE D65 chromaticity. Those two are close but never exactly equal, by definition: D65
156
+ * is defined via the CIE daylight locus, a model fit to measured daylight spectra, which deliberately deviates
157
+ * from the Planckian locus (real daylight isn't quite blackbody radiation) - no table or precision fix can close
158
+ * that gap without distorting temperature/tint for every other illuminant.
159
+ *
160
+ * This is what lets `GetWhiteBalanceMatrix(6500, 0)` be exactly the identity matrix - the default "no adjustment"
161
+ * temperature/tint are a true no-op - without needing to special-case that one input: the reverse adaptation is
162
+ * applied once, here, to the matrix itself, rather than to every call's result.
163
+ */
164
+ const RgbToXyzD65 = StandardRgbToXyzD65.multiply(BradfordAdapt(StandardD65Xyz, TemperatureTintToXyz(6500, 0)));
165
+ /**
166
+ * The CIE XYZ to linear RGB matrix, the inverse of {@link RgbToXyzD65}.
167
+ */
168
+ const XyzToRgbD65 = Matrix.Invert(RgbToXyzD65);
169
+ /**
170
+ * The working color space's reference white, in CIE XYZ (Y = 1) - what neutral (1, 1, 1) linear RGB maps to
171
+ * through {@link RgbToXyzD65}. Since that matrix is itself calibrated to this module's own 6500 K point (see
172
+ * above), this is exactly `TemperatureTintToXyz(6500, 0)`. Deriving it as "whatever (1, 1, 1) maps to" (rather
173
+ * than calling `TemperatureTintToXyz` a second time) keeps the invariant self-documenting: a fully white-balanced
174
+ * neutral patch round-trips back to exactly (1, 1, 1) for any input illuminant, because the adaptation target is
175
+ * always tied directly to whatever the working color space itself already treats as neutral.
176
+ */
177
+ const ReferenceWhiteXyz = Vector3.TransformNormal(new Vector3(1, 1, 1), RgbToXyzD65);
178
+ /**
179
+ * Computes the linear RGB (sRGB / Rec.709 primaries) color-correction matrix that white-balances the given
180
+ * illuminant, by chromatically adapting its white point (see {@link TemperatureTintToXyz}) to the working
181
+ * color space's reference white using the Bradford transform.
182
+ * @param temperatureKelvin The correlated color temperature of the illuminant to neutralize, in Kelvin
183
+ * @param tint An offset perpendicular to the Planckian locus (the green/magenta axis), in the range [-150, 150]
184
+ * @returns A column-major 3x3 matrix (9 values), ready to be bound as a `mat3` shader uniform
185
+ */
186
+ export function GetWhiteBalanceMatrix(temperatureKelvin, tint) {
187
+ const targetWhiteXYZ = TemperatureTintToXyz(temperatureKelvin, tint);
188
+ const adapt = BradfordAdapt(targetWhiteXYZ, ReferenceWhiteXyz);
189
+ // finalMatrix = XyzToRgbD65 * adapt * RgbToXyzD65, written back-to-front (see BradfordAdapt).
190
+ const adaptedFromRgb = RgbToXyzD65.multiply(adapt);
191
+ const finalMatrix = adaptedFromRgb.multiply(XyzToRgbD65);
192
+ // `Matrix` stores its values column-major, matching the layout GLSL/WGSL `mat3` uniforms expect,
193
+ // so the upper-left 3x3 block can be extracted directly with no transpose.
194
+ return Matrix.GetAsMatrix3x3(finalMatrix);
195
+ }
196
+ //# sourceMappingURL=colorTemperature.functions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colorTemperature.functions.js","sourceRoot":"","sources":["../../../../dev/core/src/Maths/colorTemperature.functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE9D;;;;GAIG;AACH,MAAM,mBAAmB,GAA6D;IAClF,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,OAAO,CAAC;IAC/B,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,OAAO,CAAC;IAChC,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,OAAO,CAAC;IAChC,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,OAAO,CAAC;IAChC,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC;IAC/B,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,OAAO,CAAC;IAChC,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,OAAO,CAAC;IAChC,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,OAAO,CAAC;IAChC,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,OAAO,CAAC;IAC/B,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,OAAO,CAAC;IAC/B,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO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AE,WAAW,CAAC,CAAC;AAErF;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAC,iBAAyB,EAAE,IAAY;IACzE,MAAM,cAAc,GAAG,oBAAoB,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;IACrE,MAAM,KAAK,GAAG,aAAa,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAC;IAE/D,8FAA8F;IAC9F,MAAM,cAAc,GAAG,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACnD,MAAM,WAAW,GAAG,cAAc,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAEzD,iGAAiG;IACjG,2EAA2E;IAC3E,OAAO,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;AAC9C,CAAC","sourcesContent":["import { Clamp } from \"./math.scalar.functions\";\nimport { Matrix, Vector2, Vector3 } from \"./math.vector.pure\";\n\n/**\n * Tabulated Planckian locus in CIE 1960 UCS (u, v) space, with the local isotherm slope `t` used to offset\n * a chromaticity along the tint axis. Source: Wyszecki &amp; Stiles, \"Color Science\", 2nd ed., 1982, pp. 227-228.\n * Each row is [mired, u, v, t].\n */\nconst PlanckianLocusTable: ReadonlyArray<readonly [number, number, number, number]> = [\n [0, 0.18006, 0.26352, -0.24341],\n [10, 0.18066, 0.26589, -0.25479],\n [20, 0.18133, 0.26846, -0.26876],\n [30, 0.18208, 0.27119, -0.28539],\n [40, 0.18293, 0.27407, -0.3047],\n [50, 0.18388, 0.27709, -0.32675],\n [60, 0.18494, 0.28021, -0.35156],\n [70, 0.18611, 0.28342, -0.37915],\n [80, 0.1874, 0.28668, -0.40955],\n [90, 0.1888, 0.28997, -0.44278],\n [100, 0.19032, 0.29326, -0.47888],\n [125, 0.19462, 0.30141, -0.58204],\n [150, 0.19962, 0.30921, -0.70471],\n [175, 0.20525, 0.31647, -0.84901],\n [200, 0.21142, 0.32312, -1.0182],\n [225, 0.21807, 0.32909, -1.2168],\n [250, 0.22511, 0.33439, -1.4512],\n [275, 0.23247, 0.33904, -1.7298],\n [300, 0.2401, 0.34308, -2.0637],\n [325, 0.24792, 0.34655, -2.4681],\n [350, 0.25591, 0.34951, -2.9641],\n [375, 0.264, 0.352, -3.5814],\n [400, 0.27218, 0.35407, -4.3633],\n [425, 0.28039, 0.35577, -5.3762],\n [450, 0.28863, 0.35714, -6.7262],\n [475, 0.29685, 0.35823, -8.5955],\n [500, 0.30505, 0.35907, -11.324],\n [525, 0.3132, 0.35968, -15.628],\n [550, 0.32129, 0.36011, -23.325],\n [575, 0.32931, 0.36038, -40.77],\n [600, 0.33724, 0.36051, -116.45],\n];\n\n/**\n * The minimum correlated color temperature, in Kelvin, representable by {@link TemperatureTintToXyz} (there is no\n * upper bound: increasingly high temperatures approach mired 0, already within the tabulated range).\n */\nexport const MinTemperatureKelvin = 1e6 / PlanckianLocusTable[PlanckianLocusTable.length - 1][0];\n\n/**\n * The maximum magnitude of the tint offset accepted by {@link TemperatureTintToXyz}, in either direction.\n */\nexport const MaxTintMagnitude = 150;\n\n/**\n * Converts a correlated color temperature and tint offset into the CIE XYZ (Y = 1) coordinates of the\n * corresponding illuminant white point, using a tabulated approximation of the Planckian locus in CIE 1960 UCS\n * (u, v) space.\n * @param temperatureKelvin The correlated color temperature of the illuminant, in Kelvin\n * @param tint An offset perpendicular to the Planckian locus (the green/magenta axis), in the range\n * [-{@link MaxTintMagnitude}, {@link MaxTintMagnitude}]\n * @returns The CIE XYZ (Y = 1) coordinates of the illuminant white point\n */\nexport function TemperatureTintToXyz(temperatureKelvin: number, tint: number): Vector3 {\n // Clamp before taking the reciprocal: a non-positive or NaN Kelvin value has no valid reciprocal-mired\n // representation, and taking 1e6 / temperatureKelvin first (before clamping the result) would map negative\n // inputs to the *hottest* end of the table instead of the coldest/minimum one.\n const safeTemperatureKelvin = Number.isNaN(temperatureKelvin) ? MinTemperatureKelvin : Math.max(temperatureKelvin, MinTemperatureKelvin);\n const mired = Clamp(1e6 / safeTemperatureKelvin, PlanckianLocusTable[0][0], PlanckianLocusTable[PlanckianLocusTable.length - 1][0]);\n\n // Binary search for the table row pair bracketing `mired` (the table is sorted ascending by mired).\n let low = 0;\n let high = PlanckianLocusTable.length - 1;\n while (high - low > 1) {\n const mid = (low + high) >> 1;\n if (PlanckianLocusTable[mid][0] <= mired) {\n low = mid;\n } else {\n high = mid;\n }\n }\n const index = low;\n\n const [lowMired, lowU, lowV, lowT] = PlanckianLocusTable[index];\n const [highMired, highU, highV, highT] = PlanckianLocusTable[index + 1];\n const f = (mired - lowMired) / (highMired - lowMired);\n\n const uv = Vector2.Lerp(new Vector2(lowU, lowV), new Vector2(highU, highV), f);\n\n const isothermLow = Vector2.Normalize(new Vector2(1, lowT));\n const isothermHigh = Vector2.Normalize(new Vector2(1, highT));\n const isotherm = Vector2.Normalize(Vector2.Lerp(isothermLow, isothermHigh, f));\n\n const clampedTint = Clamp(tint, -MaxTintMagnitude, MaxTintMagnitude);\n uv.subtractInPlace(isotherm.scale(clampedTint / 3000));\n\n // CIE 1960 (u, v) -> CIE xyY (Y = 1) -> CIE XYZ.\n const denom = 2 * uv.x - 8 * uv.y + 4;\n const x = (3 * uv.x) / denom;\n const y = (2 * uv.y) / denom;\n\n return new Vector3(x / y, 1, (1 - x - y) / y);\n}\n\n// `Matrix.FromArray` reads values column-major, so each 3x3 matrix below is written column-by-column, not row-by-row.\n\n/**\n * The Bradford cone-response matrix used for chromatic adaptation.\n */\n// prettier-ignore\nconst BradfordMatrix = Matrix.FromArray([\n 0.8951, -0.7502, 0.0389, 0,\n 0.2664, 1.7135, -0.0685, 0,\n -0.1614, 0.0367, 1.0296, 0,\n 0, 0, 0, 1,\n]);\n\nconst InverseBradfordMatrix = Matrix.Invert(BradfordMatrix);\n\n/**\n * Computes a per-channel Bradford adaptation ratio, clamped to avoid extreme temperature/tint combinations\n * blowing up the resulting matrix when a cone-response component approaches zero.\n * @param destComponent The destination white's cone-response component\n * @param sourceComponent The source white's cone-response component\n * @returns The ratio to use for this channel, clamped to [0.1, 10]\n */\nfunction ClampedAdaptationRatio(destComponent: number, sourceComponent: number): number {\n const ratio = sourceComponent > 0 ? destComponent / sourceComponent : 10;\n return Clamp(ratio, 0.1, 10);\n}\n\n/**\n * Computes the Bradford chromatic-adaptation matrix that maps CIE XYZ values from `sourceWhiteXYZ` to `destWhiteXYZ`.\n * @param sourceWhiteXYZ The CIE XYZ (Y = 1) coordinates of the source reference white\n * @param destWhiteXYZ The CIE XYZ (Y = 1) coordinates of the destination reference white\n * @returns A matrix mapping source-referenced XYZ to destination-referenced XYZ\n */\nfunction BradfordAdapt(sourceWhiteXYZ: Vector3, destWhiteXYZ: Vector3): Matrix {\n const sourceLMS = Vector3.TransformNormal(sourceWhiteXYZ, BradfordMatrix);\n const destLMS = Vector3.TransformNormal(destWhiteXYZ, BradfordMatrix);\n\n // prettier-ignore\n const scale = Matrix.FromArray([\n ClampedAdaptationRatio(destLMS.x, sourceLMS.x), 0, 0, 0,\n 0, ClampedAdaptationRatio(destLMS.y, sourceLMS.y), 0, 0,\n 0, 0, ClampedAdaptationRatio(destLMS.z, sourceLMS.z), 0,\n 0, 0, 0, 1,\n ]);\n\n // adapt = InverseBradfordMatrix * scale * BradfordMatrix, written back-to-front since `A.multiply(B)` computes `B x A`.\n const scaledByBradford = BradfordMatrix.multiply(scale);\n return scaledByBradford.multiply(InverseBradfordMatrix);\n}\n\n/**\n * The standard CIE Illuminant D65 white point, in CIE XYZ (Y = 1).\n */\nconst StandardD65Xyz = new Vector3(0.95047, 1.0, 1.08883);\n\n/**\n * The standard sRGB / Rec.709 linear RGB to CIE XYZ matrix, calibrated to the externally-standardized CIE\n * Illuminant D65 chromaticity - i.e. `StandardRgbToXyzD65 * (1, 1, 1) = StandardD65Xyz` exactly.\n */\n// prettier-ignore\nconst StandardRgbToXyzD65 = Matrix.FromArray([\n 0.4124564, 0.2126729, 0.0193339, 0,\n 0.3575761, 0.7151522, 0.119192, 0,\n 0.1804375, 0.072175, 0.9503041, 0,\n 0, 0, 0, 1,\n]);\n\n/**\n * The linear RGB to CIE XYZ matrix actually used by {@link GetWhiteBalanceMatrix}, recalibrated from\n * {@link StandardRgbToXyzD65} via a single Bradford adaptation step so that neutral (1, 1, 1) maps exactly onto\n * this module's own Planckian-locus approximation of 6500 K (see {@link TemperatureTintToXyz}) instead of the\n * externally-standardized CIE D65 chromaticity. Those two are close but never exactly equal, by definition: D65\n * is defined via the CIE daylight locus, a model fit to measured daylight spectra, which deliberately deviates\n * from the Planckian locus (real daylight isn't quite blackbody radiation) - no table or precision fix can close\n * that gap without distorting temperature/tint for every other illuminant.\n *\n * This is what lets `GetWhiteBalanceMatrix(6500, 0)` be exactly the identity matrix - the default \"no adjustment\"\n * temperature/tint are a true no-op - without needing to special-case that one input: the reverse adaptation is\n * applied once, here, to the matrix itself, rather than to every call's result.\n */\nconst RgbToXyzD65 = StandardRgbToXyzD65.multiply(BradfordAdapt(StandardD65Xyz, TemperatureTintToXyz(6500, 0)));\n\n/**\n * The CIE XYZ to linear RGB matrix, the inverse of {@link RgbToXyzD65}.\n */\nconst XyzToRgbD65 = Matrix.Invert(RgbToXyzD65);\n\n/**\n * The working color space's reference white, in CIE XYZ (Y = 1) - what neutral (1, 1, 1) linear RGB maps to\n * through {@link RgbToXyzD65}. Since that matrix is itself calibrated to this module's own 6500 K point (see\n * above), this is exactly `TemperatureTintToXyz(6500, 0)`. Deriving it as \"whatever (1, 1, 1) maps to\" (rather\n * than calling `TemperatureTintToXyz` a second time) keeps the invariant self-documenting: a fully white-balanced\n * neutral patch round-trips back to exactly (1, 1, 1) for any input illuminant, because the adaptation target is\n * always tied directly to whatever the working color space itself already treats as neutral.\n */\nconst ReferenceWhiteXyz = Vector3.TransformNormal(new Vector3(1, 1, 1), RgbToXyzD65);\n\n/**\n * Computes the linear RGB (sRGB / Rec.709 primaries) color-correction matrix that white-balances the given\n * illuminant, by chromatically adapting its white point (see {@link TemperatureTintToXyz}) to the working\n * color space's reference white using the Bradford transform.\n * @param temperatureKelvin The correlated color temperature of the illuminant to neutralize, in Kelvin\n * @param tint An offset perpendicular to the Planckian locus (the green/magenta axis), in the range [-150, 150]\n * @returns A column-major 3x3 matrix (9 values), ready to be bound as a `mat3` shader uniform\n */\nexport function GetWhiteBalanceMatrix(temperatureKelvin: number, tint: number): Float32Array | Array<number> {\n const targetWhiteXYZ = TemperatureTintToXyz(temperatureKelvin, tint);\n const adapt = BradfordAdapt(targetWhiteXYZ, ReferenceWhiteXyz);\n\n // finalMatrix = XyzToRgbD65 * adapt * RgbToXyzD65, written back-to-front (see BradfordAdapt).\n const adaptedFromRgb = RgbToXyzD65.multiply(adapt);\n const finalMatrix = adaptedFromRgb.multiply(XyzToRgbD65);\n\n // `Matrix` stores its values column-major, matching the layout GLSL/WGSL `mat3` uniforms expect,\n // so the upper-left 3x3 block can be extracted directly with no transpose.\n return Matrix.GetAsMatrix3x3(finalMatrix);\n}\n"]}
package/Maths/index.d.ts CHANGED
@@ -18,3 +18,4 @@ export * from "./ThinMaths/index.js";
18
18
  export * from "./math.scalar.functions.js";
19
19
  export * from "./math.geospatial.js";
20
20
  export * from "./math.geospatial.functions.js";
21
+ export * from "./colorTemperature.functions.js";
package/Maths/index.js CHANGED
@@ -19,4 +19,5 @@ export * from "./ThinMaths/index.js";
19
19
  export * from "./math.scalar.functions.js";
20
20
  export * from "./math.geospatial.js";
21
21
  export * from "./math.geospatial.functions.js";
22
+ export * from "./colorTemperature.functions.js";
22
23
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../dev/core/src/Maths/index.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC;AACvB,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-restricted-imports */\r\nexport * from \"./math.scalar\";\r\nexport * from \"./math.functions\";\r\nexport * from \"./math.polar\";\r\nexport * from \"./math.like\";\r\nexport * from \"./math.axis\";\r\nexport * from \"./math.constants\";\r\nexport * from \"./math.frustum\";\r\nexport * from \"./math.path\";\r\nexport * from \"./math.plane\";\r\nexport * from \"./math.size\";\r\nexport * from \"./math.vertexFormat\";\r\nexport * from \"./math.viewport\";\r\nexport * from \"./math\";\r\nexport * from \"./sphericalPolynomial\";\r\nexport * from \"./halton2DSequence\";\r\nexport * from \"./math.vector.functions\";\r\nexport * from \"./ThinMaths/index\";\r\nexport * from \"./math.scalar.functions\";\r\nexport * from \"./math.geospatial\";\r\nexport * from \"./math.geospatial.functions\";\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../dev/core/src/Maths/index.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC;AACvB,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-restricted-imports */\r\nexport * from \"./math.scalar\";\r\nexport * from \"./math.functions\";\r\nexport * from \"./math.polar\";\r\nexport * from \"./math.like\";\r\nexport * from \"./math.axis\";\r\nexport * from \"./math.constants\";\r\nexport * from \"./math.frustum\";\r\nexport * from \"./math.path\";\r\nexport * from \"./math.plane\";\r\nexport * from \"./math.size\";\r\nexport * from \"./math.vertexFormat\";\r\nexport * from \"./math.viewport\";\r\nexport * from \"./math\";\r\nexport * from \"./sphericalPolynomial\";\r\nexport * from \"./halton2DSequence\";\r\nexport * from \"./math.vector.functions\";\r\nexport * from \"./ThinMaths/index\";\r\nexport * from \"./math.scalar.functions\";\r\nexport * from \"./math.geospatial\";\r\nexport * from \"./math.geospatial.functions\";\r\nexport * from \"./colorTemperature.functions\";\r\n"]}
@@ -842,11 +842,7 @@ export declare class Vector3 implements Vector<Tuple<number, 3>, IVector3LikeInt
842
842
  * Intercept the x,y,z value change
843
843
  * @param interceptor
844
844
  */
845
- setInterceptor(interceptor?: (newValue: {
846
- x?: number;
847
- y?: number;
848
- z?: number;
849
- }) => boolean): void;
845
+ setInterceptor(interceptor?: VectorInterceptor): void;
850
846
  /**
851
847
  * Get the current interceptor
852
848
  * @returns the current vector interceptor