@plastic-software/three 0.181.2 → 0.182.0

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 (253) hide show
  1. package/README.md +3 -4
  2. package/build/three.cjs +1192 -522
  3. package/build/three.core.js +345 -219
  4. package/build/three.core.min.js +1 -1
  5. package/build/three.module.js +864 -328
  6. package/build/three.module.min.js +1 -1
  7. package/build/three.tsl.js +15 -3
  8. package/build/three.tsl.min.js +1 -1
  9. package/build/three.webgpu.js +3660 -1545
  10. package/build/three.webgpu.min.js +1 -1
  11. package/build/three.webgpu.nodes.js +3659 -1544
  12. package/build/three.webgpu.nodes.min.js +1 -1
  13. package/examples/jsm/controls/MapControls.js +55 -1
  14. package/examples/jsm/controls/OrbitControls.js +6 -6
  15. package/examples/jsm/controls/TrackballControls.js +6 -6
  16. package/examples/jsm/csm/CSM.js +2 -1
  17. package/examples/jsm/environments/RoomEnvironment.js +2 -0
  18. package/examples/jsm/geometries/DecalGeometry.js +1 -1
  19. package/examples/jsm/helpers/LightProbeHelperGPU.js +1 -1
  20. package/examples/jsm/helpers/TextureHelperGPU.js +1 -1
  21. package/examples/jsm/inspector/Inspector.js +53 -9
  22. package/examples/jsm/inspector/RendererInspector.js +12 -2
  23. package/examples/jsm/inspector/tabs/Console.js +2 -2
  24. package/examples/jsm/inspector/tabs/Parameters.js +2 -2
  25. package/examples/jsm/inspector/tabs/Performance.js +2 -2
  26. package/examples/jsm/inspector/tabs/Viewer.js +4 -4
  27. package/examples/jsm/inspector/ui/Profiler.js +1836 -31
  28. package/examples/jsm/inspector/ui/Style.js +948 -13
  29. package/examples/jsm/inspector/ui/Tab.js +188 -1
  30. package/examples/jsm/inspector/ui/Values.js +17 -1
  31. package/examples/jsm/loaders/3DMLoader.js +5 -4
  32. package/examples/jsm/loaders/DRACOLoader.js +5 -5
  33. package/examples/jsm/loaders/FBXLoader.js +0 -2
  34. package/examples/jsm/loaders/HDRLoader.js +0 -1
  35. package/examples/jsm/loaders/KTX2Loader.js +16 -0
  36. package/examples/jsm/loaders/LDrawLoader.js +2 -3
  37. package/examples/jsm/loaders/PCDLoader.js +1 -0
  38. package/examples/jsm/loaders/SVGLoader.js +1 -1
  39. package/examples/jsm/loaders/TDSLoader.js +0 -2
  40. package/examples/jsm/loaders/TGALoader.js +0 -2
  41. package/examples/jsm/loaders/UltraHDRLoader.js +110 -137
  42. package/examples/jsm/loaders/VOXLoader.js +660 -117
  43. package/examples/jsm/loaders/VRMLLoader.js +2 -2
  44. package/examples/jsm/loaders/usd/USDCParser.js +1 -1
  45. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +1 -1
  46. package/examples/jsm/materials/MeshGouraudMaterial.js +0 -1
  47. package/examples/jsm/materials/WoodNodeMaterial.js +11 -11
  48. package/examples/jsm/math/Octree.js +131 -1
  49. package/examples/jsm/misc/Volume.js +0 -1
  50. package/examples/jsm/misc/VolumeSlice.js +0 -1
  51. package/examples/jsm/objects/SkyMesh.js +13 -3
  52. package/examples/jsm/physics/AmmoPhysics.js +12 -7
  53. package/examples/jsm/physics/JoltPhysics.js +3 -1
  54. package/examples/jsm/physics/RapierPhysics.js +3 -1
  55. package/examples/jsm/postprocessing/OutputPass.js +9 -0
  56. package/examples/jsm/postprocessing/RenderPass.js +10 -0
  57. package/examples/jsm/postprocessing/UnrealBloomPass.js +48 -18
  58. package/examples/jsm/renderers/Projector.js +268 -30
  59. package/examples/jsm/renderers/SVGRenderer.js +191 -58
  60. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +2 -4
  61. package/examples/jsm/transpiler/AST.js +44 -0
  62. package/examples/jsm/transpiler/GLSLDecoder.js +61 -4
  63. package/examples/jsm/transpiler/ShaderToyDecoder.js +2 -0
  64. package/examples/jsm/transpiler/TSLEncoder.js +46 -3
  65. package/examples/jsm/transpiler/TranspilerUtils.js +3 -3
  66. package/examples/jsm/transpiler/WGSLEncoder.js +27 -0
  67. package/examples/jsm/tsl/display/AnaglyphPassNode.js +2 -0
  68. package/examples/jsm/tsl/display/BloomNode.js +11 -1
  69. package/examples/jsm/tsl/display/GTAONode.js +3 -2
  70. package/examples/jsm/tsl/display/PixelationPassNode.js +2 -1
  71. package/examples/jsm/tsl/display/SSGINode.js +7 -19
  72. package/examples/jsm/tsl/display/SSRNode.js +1 -1
  73. package/examples/jsm/tsl/display/SSSNode.js +4 -2
  74. package/examples/jsm/tsl/display/StereoCompositePassNode.js +8 -1
  75. package/examples/jsm/tsl/display/TRAANode.js +265 -114
  76. package/examples/jsm/tsl/display/radialBlur.js +68 -0
  77. package/examples/jsm/utils/ShadowMapViewer.js +24 -10
  78. package/examples/jsm/utils/ShadowMapViewerGPU.js +1 -1
  79. package/examples/jsm/utils/WebGPUTextureUtils.js +1 -1
  80. package/package.json +14 -12
  81. package/src/Three.Core.js +1 -0
  82. package/src/Three.TSL.js +14 -2
  83. package/src/animation/AnimationUtils.js +1 -12
  84. package/src/animation/KeyframeTrack.js +1 -1
  85. package/src/animation/tracks/BooleanKeyframeTrack.js +1 -1
  86. package/src/animation/tracks/ColorKeyframeTrack.js +1 -1
  87. package/src/animation/tracks/NumberKeyframeTrack.js +1 -1
  88. package/src/animation/tracks/QuaternionKeyframeTrack.js +1 -1
  89. package/src/animation/tracks/StringKeyframeTrack.js +1 -1
  90. package/src/animation/tracks/VectorKeyframeTrack.js +1 -1
  91. package/src/constants.js +61 -5
  92. package/src/core/BufferGeometry.js +14 -2
  93. package/src/core/Raycaster.js +2 -2
  94. package/src/extras/PMREMGenerator.js +3 -10
  95. package/src/extras/TextureUtils.js +5 -1
  96. package/src/geometries/ExtrudeGeometry.js +2 -2
  97. package/src/geometries/PolyhedronGeometry.js +1 -1
  98. package/src/helpers/PointLightHelper.js +1 -1
  99. package/src/lights/DirectionalLight.js +13 -0
  100. package/src/lights/HemisphereLight.js +10 -0
  101. package/src/lights/Light.js +1 -11
  102. package/src/lights/LightProbe.js +0 -15
  103. package/src/lights/LightShadow.js +0 -3
  104. package/src/lights/PointLight.js +15 -0
  105. package/src/lights/PointLightShadow.js +0 -86
  106. package/src/lights/SpotLight.js +22 -1
  107. package/src/loaders/MaterialLoader.js +2 -1
  108. package/src/loaders/ObjectLoader.js +3 -1
  109. package/src/loaders/nodes/NodeLoader.js +2 -2
  110. package/src/materials/Material.js +2 -0
  111. package/src/materials/ShaderMaterial.js +20 -1
  112. package/src/materials/nodes/Line2NodeMaterial.js +2 -2
  113. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +3 -2
  114. package/src/materials/nodes/MeshStandardNodeMaterial.js +5 -4
  115. package/src/materials/nodes/NodeMaterial.js +59 -3
  116. package/src/materials/nodes/manager/NodeMaterialObserver.js +1 -1
  117. package/src/math/Matrix4.js +40 -40
  118. package/src/math/Sphere.js +1 -1
  119. package/src/math/Vector3.js +0 -2
  120. package/src/nodes/TSL.js +4 -1
  121. package/src/nodes/accessors/BatchNode.js +10 -10
  122. package/src/nodes/accessors/BufferAttributeNode.js +98 -12
  123. package/src/nodes/accessors/BufferNode.js +29 -2
  124. package/src/nodes/accessors/ClippingNode.js +4 -4
  125. package/src/nodes/accessors/CubeTextureNode.js +20 -1
  126. package/src/nodes/accessors/InstanceNode.js +69 -29
  127. package/src/nodes/accessors/MaterialNode.js +9 -1
  128. package/src/nodes/accessors/MaterialReferenceNode.js +1 -2
  129. package/src/nodes/accessors/ModelNode.js +1 -1
  130. package/src/nodes/accessors/Normal.js +2 -2
  131. package/src/nodes/accessors/ReferenceBaseNode.js +4 -4
  132. package/src/nodes/accessors/ReferenceNode.js +4 -4
  133. package/src/nodes/accessors/RendererReferenceNode.js +1 -2
  134. package/src/nodes/accessors/SkinningNode.js +15 -2
  135. package/src/nodes/accessors/StorageBufferNode.js +4 -2
  136. package/src/nodes/accessors/Tangent.js +1 -11
  137. package/src/nodes/accessors/Texture3DNode.js +26 -1
  138. package/src/nodes/accessors/UniformArrayNode.js +2 -2
  139. package/src/nodes/accessors/UserDataNode.js +1 -2
  140. package/src/nodes/accessors/VertexColorNode.js +1 -2
  141. package/src/nodes/code/FunctionNode.js +1 -2
  142. package/src/nodes/core/ArrayNode.js +20 -1
  143. package/src/nodes/core/AssignNode.js +2 -2
  144. package/src/nodes/core/AttributeNode.js +2 -2
  145. package/src/nodes/core/ContextNode.js +103 -4
  146. package/src/nodes/core/NodeBuilder.js +56 -14
  147. package/src/nodes/core/NodeFrame.js +12 -4
  148. package/src/nodes/core/NodeUtils.js +5 -5
  149. package/src/nodes/core/ParameterNode.js +1 -2
  150. package/src/nodes/core/PropertyNode.js +19 -3
  151. package/src/nodes/core/StackNode.js +56 -8
  152. package/src/nodes/core/StructNode.js +1 -2
  153. package/src/nodes/core/StructTypeNode.js +11 -17
  154. package/src/nodes/core/UniformNode.js +19 -4
  155. package/src/nodes/core/VarNode.js +46 -21
  156. package/src/nodes/display/NormalMapNode.js +37 -2
  157. package/src/nodes/display/PassNode.js +77 -7
  158. package/src/nodes/display/ScreenNode.js +1 -0
  159. package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +3 -3
  160. package/src/nodes/functions/BSDF/DFGLUT.js +56 -0
  161. package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
  162. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +1 -1
  163. package/src/nodes/functions/PhysicalLightingModel.js +102 -43
  164. package/src/nodes/gpgpu/ComputeBuiltinNode.js +1 -2
  165. package/src/nodes/gpgpu/SubgroupFunctionNode.js +1 -1
  166. package/src/nodes/gpgpu/WorkgroupInfoNode.js +2 -3
  167. package/src/nodes/lighting/AnalyticLightNode.js +53 -0
  168. package/src/nodes/lighting/LightsNode.js +2 -2
  169. package/src/nodes/lighting/PointShadowNode.js +141 -140
  170. package/src/nodes/lighting/ShadowFilterNode.js +53 -37
  171. package/src/nodes/lighting/ShadowNode.js +53 -19
  172. package/src/nodes/math/BitcountNode.js +433 -0
  173. package/src/nodes/math/PackFloatNode.js +98 -0
  174. package/src/nodes/math/UnpackFloatNode.js +96 -0
  175. package/src/nodes/pmrem/PMREMNode.js +1 -1
  176. package/src/nodes/tsl/TSLCore.js +4 -4
  177. package/src/nodes/utils/ArrayElementNode.js +13 -0
  178. package/src/nodes/utils/EventNode.js +1 -2
  179. package/src/nodes/utils/Packing.js +13 -1
  180. package/src/nodes/utils/PostProcessingUtils.js +33 -1
  181. package/src/nodes/utils/ReflectorNode.js +1 -1
  182. package/src/nodes/utils/SampleNode.js +1 -1
  183. package/src/nodes/utils/UVUtils.js +26 -0
  184. package/src/objects/BatchedMesh.js +5 -2
  185. package/src/objects/Line.js +1 -1
  186. package/src/objects/Mesh.js +1 -1
  187. package/src/objects/Points.js +1 -1
  188. package/src/objects/Skeleton.js +9 -0
  189. package/src/renderers/WebGLRenderer.js +145 -33
  190. package/src/renderers/common/Backend.js +8 -0
  191. package/src/renderers/common/Background.js +19 -9
  192. package/src/renderers/common/Binding.js +11 -0
  193. package/src/renderers/common/Bindings.js +7 -7
  194. package/src/renderers/common/Buffer.js +40 -0
  195. package/src/renderers/common/ChainMap.js +30 -6
  196. package/src/renderers/common/Geometries.js +12 -0
  197. package/src/renderers/common/RenderContexts.js +8 -1
  198. package/src/renderers/common/RenderObject.js +14 -1
  199. package/src/renderers/common/Renderer.js +53 -35
  200. package/src/renderers/common/Textures.js +1 -1
  201. package/src/renderers/common/UniformsGroup.js +1 -0
  202. package/src/renderers/common/XRManager.js +1 -0
  203. package/src/renderers/common/extras/PMREMGenerator.js +2 -8
  204. package/src/renderers/common/nodes/NodeUniformBuffer.js +52 -0
  205. package/src/renderers/shaders/DFGLUTData.js +19 -34
  206. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +5 -2
  207. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +8 -4
  208. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +90 -51
  209. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +194 -186
  210. package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +1 -1
  211. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
  212. package/src/renderers/shaders/ShaderChunk.js +3 -3
  213. package/src/renderers/shaders/ShaderLib/depth.glsl.js +3 -0
  214. package/src/renderers/shaders/ShaderLib/{distanceRGBA.glsl.js → distance.glsl.js} +1 -2
  215. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +0 -1
  216. package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +1 -2
  217. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +0 -1
  218. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -9
  219. package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +0 -1
  220. package/src/renderers/shaders/ShaderLib/shadow.glsl.js +0 -1
  221. package/src/renderers/shaders/ShaderLib/vsm.glsl.js +4 -6
  222. package/src/renderers/shaders/ShaderLib.js +3 -3
  223. package/src/renderers/webgl/WebGLCapabilities.js +3 -4
  224. package/src/renderers/webgl/WebGLLights.js +18 -1
  225. package/src/renderers/webgl/WebGLOutput.js +267 -0
  226. package/src/renderers/webgl/WebGLProgram.js +43 -107
  227. package/src/renderers/webgl/WebGLPrograms.js +35 -45
  228. package/src/renderers/webgl/WebGLShadowMap.js +188 -25
  229. package/src/renderers/webgl/WebGLState.js +20 -20
  230. package/src/renderers/webgl/WebGLTextures.js +89 -28
  231. package/src/renderers/webgl/WebGLUniforms.js +40 -3
  232. package/src/renderers/webgl/WebGLUtils.js +6 -2
  233. package/src/renderers/webgl-fallback/WebGLBackend.js +79 -13
  234. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +59 -7
  235. package/src/renderers/webgl-fallback/utils/WebGLState.js +18 -3
  236. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +5 -3
  237. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +9 -9
  238. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +6 -2
  239. package/src/renderers/webgpu/WebGPUBackend.js +61 -4
  240. package/src/renderers/webgpu/WebGPURenderer.js +1 -1
  241. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +65 -23
  242. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +4 -17
  243. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +354 -186
  244. package/src/renderers/webgpu/utils/WebGPUConstants.js +2 -0
  245. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +20 -7
  246. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +40 -17
  247. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +7 -7
  248. package/src/renderers/webgpu/utils/WebGPUUtils.js +7 -5
  249. package/src/textures/CubeDepthTexture.js +76 -0
  250. package/src/textures/Source.js +1 -1
  251. package/src/textures/Texture.js +1 -1
  252. package/src/utils.js +13 -1
  253. package/src/nodes/functions/BSDF/DFGApprox.js +0 -71
@@ -1,13 +1,5 @@
1
1
  import { LightShadow } from './LightShadow.js';
2
2
  import { PerspectiveCamera } from '../cameras/PerspectiveCamera.js';
3
- import { Matrix4 } from '../math/Matrix4.js';
4
- import { Vector2 } from '../math/Vector2.js';
5
- import { Vector3 } from '../math/Vector3.js';
6
- import { Vector4 } from '../math/Vector4.js';
7
-
8
- const _projScreenMatrix = /*@__PURE__*/ new Matrix4();
9
- const _lightPositionWorld = /*@__PURE__*/ new Vector3();
10
- const _lookTarget = /*@__PURE__*/ new Vector3();
11
3
 
12
4
  /**
13
5
  * Represents the shadow configuration of point lights.
@@ -32,84 +24,6 @@ class PointLightShadow extends LightShadow {
32
24
  */
33
25
  this.isPointLightShadow = true;
34
26
 
35
- this._frameExtents = new Vector2( 4, 2 );
36
-
37
- this._viewportCount = 6;
38
-
39
- this._viewports = [
40
- // These viewports map a cube-map onto a 2D texture with the
41
- // following orientation:
42
- //
43
- // xzXZ
44
- // y Y
45
- //
46
- // X - Positive x direction
47
- // x - Negative x direction
48
- // Y - Positive y direction
49
- // y - Negative y direction
50
- // Z - Positive z direction
51
- // z - Negative z direction
52
-
53
- // positive X
54
- new Vector4( 2, 1, 1, 1 ),
55
- // negative X
56
- new Vector4( 0, 1, 1, 1 ),
57
- // positive Z
58
- new Vector4( 3, 1, 1, 1 ),
59
- // negative Z
60
- new Vector4( 1, 1, 1, 1 ),
61
- // positive Y
62
- new Vector4( 3, 0, 1, 1 ),
63
- // negative Y
64
- new Vector4( 1, 0, 1, 1 )
65
- ];
66
-
67
- this._cubeDirections = [
68
- new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
69
- new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
70
- ];
71
-
72
- this._cubeUps = [
73
- new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
74
- new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
75
- ];
76
-
77
- }
78
-
79
- /**
80
- * Update the matrices for the camera and shadow, used internally by the renderer.
81
- *
82
- * @param {Light} light - The light for which the shadow is being rendered.
83
- * @param {number} [viewportIndex=0] - The viewport index.
84
- */
85
- updateMatrices( light, viewportIndex = 0 ) {
86
-
87
- const camera = this.camera;
88
- const shadowMatrix = this.matrix;
89
-
90
- const far = light.distance || camera.far;
91
-
92
- if ( far !== camera.far ) {
93
-
94
- camera.far = far;
95
- camera.updateProjectionMatrix();
96
-
97
- }
98
-
99
- _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
100
- camera.position.copy( _lightPositionWorld );
101
-
102
- _lookTarget.copy( camera.position );
103
- _lookTarget.add( this._cubeDirections[ viewportIndex ] );
104
- camera.up.copy( this._cubeUps[ viewportIndex ] );
105
- camera.lookAt( _lookTarget );
106
- camera.updateMatrixWorld();
107
-
108
- shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
109
-
110
- _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
111
- this._frustum.setFromProjectionMatrix( _projScreenMatrix, camera.coordinateSystem, camera.reversedDepth );
112
-
113
27
  }
114
28
 
115
29
  }
@@ -147,6 +147,8 @@ class SpotLight extends Light {
147
147
 
148
148
  dispose() {
149
149
 
150
+ super.dispose();
151
+
150
152
  this.shadow.dispose();
151
153
 
152
154
  }
@@ -161,13 +163,32 @@ class SpotLight extends Light {
161
163
  this.decay = source.decay;
162
164
 
163
165
  this.target = source.target.clone();
164
-
166
+ this.map = source.map;
165
167
  this.shadow = source.shadow.clone();
166
168
 
167
169
  return this;
168
170
 
169
171
  }
170
172
 
173
+ toJSON( meta ) {
174
+
175
+ const data = super.toJSON( meta );
176
+
177
+ data.object.distance = this.distance;
178
+ data.object.angle = this.angle;
179
+ data.object.decay = this.decay;
180
+ data.object.penumbra = this.penumbra;
181
+
182
+ data.object.target = this.target.uuid;
183
+
184
+ if ( this.map && this.map.isTexture ) data.object.map = this.map.toJSON( meta ).uuid;
185
+
186
+ data.object.shadow = this.shadow.toJSON();
187
+
188
+ return data;
189
+
190
+ }
191
+
171
192
  }
172
193
 
173
194
  export { SpotLight };
@@ -29,7 +29,7 @@ import {
29
29
  import { error, warn } from '../utils.js';
30
30
 
31
31
  /**
32
- * Class for loading geometries. The files are internally
32
+ * Class for loading materials. The files are internally
33
33
  * loaded via {@link FileLoader}.
34
34
  *
35
35
  * ```js
@@ -203,6 +203,7 @@ class MaterialLoader extends Loader {
203
203
  if ( json.alphaToCoverage !== undefined ) material.alphaToCoverage = json.alphaToCoverage;
204
204
  if ( json.premultipliedAlpha !== undefined ) material.premultipliedAlpha = json.premultipliedAlpha;
205
205
  if ( json.forceSinglePass !== undefined ) material.forceSinglePass = json.forceSinglePass;
206
+ if ( json.allowOverride !== undefined ) material.allowOverride = json.allowOverride;
206
207
 
207
208
  if ( json.visible !== undefined ) material.visible = json.visible;
208
209
 
@@ -64,6 +64,7 @@ import * as Geometries from '../geometries/Geometries.js';
64
64
  import { getTypedArray, error, warn } from '../utils.js';
65
65
  import { Box3 } from '../math/Box3.js';
66
66
  import { Sphere } from '../math/Sphere.js';
67
+ import { SphericalHarmonics3 } from '../math/SphericalHarmonics3.js';
67
68
 
68
69
  /**
69
70
  * A loader for loading a JSON resource in the [JSON Object/Scene format](https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4).
@@ -922,7 +923,8 @@ class ObjectLoader extends Loader {
922
923
 
923
924
  case 'LightProbe':
924
925
 
925
- object = new LightProbe().fromJSON( data );
926
+ const sh = new SphericalHarmonics3().fromArray( data.sh );
927
+ object = new LightProbe( sh, data.intensity );
926
928
 
927
929
  break;
928
930
 
@@ -1,4 +1,4 @@
1
- import { nodeObject, float } from '../../nodes/tsl/TSLBase.js';
1
+ import { float } from '../../nodes/tsl/TSLBase.js';
2
2
 
3
3
  import { Loader } from '../Loader.js';
4
4
  import { FileLoader } from '../../loaders/FileLoader.js';
@@ -185,7 +185,7 @@ class NodeLoader extends Loader {
185
185
 
186
186
  }
187
187
 
188
- return nodeObject( new this.nodes[ type ]() );
188
+ return new this.nodes[ type ]();
189
189
 
190
190
  }
191
191
 
@@ -832,6 +832,7 @@ class Material extends EventDispatcher {
832
832
  if ( this.alphaToCoverage === true ) data.alphaToCoverage = true;
833
833
  if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = true;
834
834
  if ( this.forceSinglePass === true ) data.forceSinglePass = true;
835
+ if ( this.allowOverride === false ) data.allowOverride = false;
835
836
 
836
837
  if ( this.wireframe === true ) data.wireframe = true;
837
838
  if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
@@ -967,6 +968,7 @@ class Material extends EventDispatcher {
967
968
  this.alphaToCoverage = source.alphaToCoverage;
968
969
  this.premultipliedAlpha = source.premultipliedAlpha;
969
970
  this.forceSinglePass = source.forceSinglePass;
971
+ this.allowOverride = source.allowOverride;
970
972
 
971
973
  this.visible = source.visible;
972
974
 
@@ -158,9 +158,22 @@ class ShaderMaterial extends Material {
158
158
  this.wireframeLinewidth = 1;
159
159
 
160
160
  /**
161
- * Define whether the material color is affected by global fog settings; `true`
161
+ * Defines whether the material color is affected by global fog settings; `true`
162
162
  * to pass fog uniforms to the shader.
163
163
  *
164
+ * Setting this property to `true` requires the definition of fog uniforms. It is
165
+ * recommended to use `UniformsUtils.merge()` to combine the custom shader uniforms
166
+ * with predefined fog uniforms.
167
+ *
168
+ * ```js
169
+ * const material = new ShaderMaterial( {
170
+ * uniforms: UniformsUtils.merge( [ UniformsLib[ 'fog' ], shaderUniforms ] );
171
+ * vertexShader: vertexShader,
172
+ * fragmentShader: fragmentShader,
173
+ * fog: true
174
+ * } );
175
+ * ```
176
+ *
164
177
  * @type {boolean}
165
178
  * @default false
166
179
  */
@@ -279,6 +292,12 @@ class ShaderMaterial extends Material {
279
292
 
280
293
  this.glslVersion = source.glslVersion;
281
294
 
295
+ this.defaultAttributeValues = Object.assign( {}, source.defaultAttributeValues );
296
+
297
+ this.index0AttributeName = source.index0AttributeName;
298
+
299
+ this.uniformsNeedUpdate = source.uniformsNeedUpdate;
300
+
282
301
  return this;
283
302
 
284
303
  }
@@ -8,7 +8,7 @@ import { positionGeometry } from '../../nodes/accessors/Position.js';
8
8
  import { mix, smoothstep } from '../../nodes/math/MathNode.js';
9
9
  import { Fn, float, vec2, vec3, vec4, If } from '../../nodes/tsl/TSLBase.js';
10
10
  import { uv } from '../../nodes/accessors/UV.js';
11
- import { viewport } from '../../nodes/display/ScreenNode.js';
11
+ import { screenDPR, viewport } from '../../nodes/display/ScreenNode.js';
12
12
  import { viewportSharedTexture } from '../../nodes/display/ViewportSharedTextureNode.js';
13
13
 
14
14
  import { LineDashedMaterial } from '../LineDashedMaterial.js';
@@ -300,7 +300,7 @@ class Line2NodeMaterial extends NodeMaterial {
300
300
  offset.assign( offset.mul( materialLineWidth ) );
301
301
 
302
302
  // adjust for clip-space to screen-space conversion // maybe resolution should be based on viewport ...
303
- offset.assign( offset.div( viewport.w ) );
303
+ offset.assign( offset.div( viewport.w.div( screenDPR ) ) );
304
304
 
305
305
  // select end
306
306
  clip.assign( positionGeometry.y.lessThan( 0.5 ).select( clipStart, clipEnd ) );
@@ -1,4 +1,4 @@
1
- import { clearcoat, clearcoatRoughness, sheen, sheenRoughness, iridescence, iridescenceIOR, iridescenceThickness, specularColor, specularF90, diffuseColor, metalness, roughness, anisotropy, alphaT, anisotropyT, anisotropyB, ior, transmission, thickness, attenuationDistance, attenuationColor, dispersion } from '../../nodes/core/PropertyNode.js';
1
+ import { clearcoat, clearcoatRoughness, sheen, sheenRoughness, iridescence, iridescenceIOR, iridescenceThickness, specularColor, specularColorBlended, specularF90, diffuseColor, metalness, roughness, anisotropy, alphaT, anisotropyT, anisotropyB, ior, transmission, thickness, attenuationDistance, attenuationColor, dispersion } from '../../nodes/core/PropertyNode.js';
2
2
  import { materialClearcoat, materialClearcoatRoughness, materialClearcoatNormal, materialSheen, materialSheenRoughness, materialIridescence, materialIridescenceIOR, materialIridescenceThickness, materialSpecularIntensity, materialSpecularColor, materialAnisotropy, materialIOR, materialTransmission, materialThickness, materialAttenuationDistance, materialAttenuationColor, materialDispersion } from '../../nodes/accessors/MaterialNode.js';
3
3
  import { float, vec2, vec3, If } from '../../nodes/tsl/TSLBase.js';
4
4
  import getRoughness from '../../nodes/functions/material/getRoughness.js';
@@ -350,7 +350,8 @@ class MeshPhysicalNodeMaterial extends MeshStandardNodeMaterial {
350
350
  const iorNode = this.iorNode ? float( this.iorNode ) : materialIOR;
351
351
 
352
352
  ior.assign( iorNode );
353
- specularColor.assign( mix( min( pow2( ior.sub( 1.0 ).div( ior.add( 1.0 ) ) ).mul( materialSpecularColor ), vec3( 1.0 ) ).mul( materialSpecularIntensity ), diffuseColor.rgb, metalness ) );
353
+ specularColor.assign( min( pow2( ior.sub( 1.0 ).div( ior.add( 1.0 ) ) ).mul( materialSpecularColor ), vec3( 1.0 ) ).mul( materialSpecularIntensity ) );
354
+ specularColorBlended.assign( mix( specularColor, diffuseColor.rgb, metalness ) );
354
355
  specularF90.assign( mix( materialSpecularIntensity, 1.0, metalness ) );
355
356
 
356
357
  }
@@ -1,11 +1,11 @@
1
1
  import NodeMaterial from './NodeMaterial.js';
2
- import { diffuseColor, metalness, roughness, specularColor, specularF90 } from '../../nodes/core/PropertyNode.js';
2
+ import { diffuseColor, diffuseContribution, metalness, roughness, specularColor, specularColorBlended, specularF90 } from '../../nodes/core/PropertyNode.js';
3
3
  import { mix } from '../../nodes/math/MathNode.js';
4
4
  import { materialRoughness, materialMetalness } from '../../nodes/accessors/MaterialNode.js';
5
5
  import getRoughness from '../../nodes/functions/material/getRoughness.js';
6
6
  import PhysicalLightingModel from '../../nodes/functions/PhysicalLightingModel.js';
7
7
  import EnvironmentNode from '../../nodes/lighting/EnvironmentNode.js';
8
- import { float, vec3, vec4 } from '../../nodes/tsl/TSLBase.js';
8
+ import { float, vec3 } from '../../nodes/tsl/TSLBase.js';
9
9
 
10
10
  import { MeshStandardMaterial } from '../MeshStandardMaterial.js';
11
11
 
@@ -135,7 +135,8 @@ class MeshStandardNodeMaterial extends NodeMaterial {
135
135
 
136
136
  const specularColorNode = mix( vec3( 0.04 ), diffuseColor.rgb, metalness );
137
137
 
138
- specularColor.assign( specularColorNode );
138
+ specularColor.assign( vec3( 0.04 ) );
139
+ specularColorBlended.assign( specularColorNode );
139
140
  specularF90.assign( 1.0 );
140
141
 
141
142
  }
@@ -166,7 +167,7 @@ class MeshStandardNodeMaterial extends NodeMaterial {
166
167
 
167
168
  // DIFFUSE COLOR
168
169
 
169
- diffuseColor.assign( vec4( diffuseColor.rgb.mul( metalnessNode.oneMinus() ), diffuseColor.a ) );
170
+ diffuseContribution.assign( diffuseColor.rgb.mul( metalnessNode.oneMinus() ) );
170
171
 
171
172
  }
172
173
 
@@ -25,7 +25,7 @@ import { modelViewMatrix } from '../../nodes/accessors/ModelNode.js';
25
25
  import { vertexColor } from '../../nodes/accessors/VertexColorNode.js';
26
26
  import { premultiplyAlpha } from '../../nodes/display/BlendModes.js';
27
27
  import { subBuild } from '../../nodes/core/SubBuildNode.js';
28
- import { warn } from '../../utils.js';
28
+ import { error, warn } from '../../utils.js';
29
29
 
30
30
  /**
31
31
  * Base class for all node materials.
@@ -382,6 +382,14 @@ class NodeMaterial extends Material {
382
382
  */
383
383
  this.vertexNode = null;
384
384
 
385
+ /**
386
+ * This node can be used as a global context management component for this material.
387
+ *
388
+ * @type {?ContextNode}
389
+ * @default null
390
+ */
391
+ this.contextNode = null;
392
+
385
393
  // Deprecated properties
386
394
 
387
395
  Object.defineProperty( this, 'shadowPositionNode', { // @deprecated, r176
@@ -489,6 +497,32 @@ class NodeMaterial extends Material {
489
497
  const renderer = builder.renderer;
490
498
  const renderTarget = renderer.getRenderTarget();
491
499
 
500
+ // < CONTEXT >
501
+
502
+ if ( renderer.contextNode.isContextNode === true ) {
503
+
504
+ builder.context = { ...builder.context, ...renderer.contextNode.getFlowContextData() };
505
+
506
+ } else {
507
+
508
+ error( 'NodeMaterial: "renderer.contextNode" must be an instance of `context()`.' );
509
+
510
+ }
511
+
512
+ if ( this.contextNode !== null ) {
513
+
514
+ if ( this.contextNode.isContextNode === true ) {
515
+
516
+ builder.context = { ...builder.context, ...this.contextNode.getFlowContextData() };
517
+
518
+ } else {
519
+
520
+ error( 'NodeMaterial: "material.contextNode" must be an instance of `context()`.' );
521
+
522
+ }
523
+
524
+ }
525
+
492
526
  // < VERTEX STAGE >
493
527
 
494
528
  builder.addStack();
@@ -558,6 +592,14 @@ class NodeMaterial extends Material {
558
592
 
559
593
  if ( isCustomOutput ) resultNode = this.outputNode;
560
594
 
595
+ //
596
+
597
+ if ( builder.context.getOutput ) {
598
+
599
+ resultNode = builder.context.getOutput( resultNode, builder );
600
+
601
+ }
602
+
561
603
  // MRT
562
604
 
563
605
  if ( renderTarget !== null ) {
@@ -1018,9 +1060,21 @@ class NodeMaterial extends Material {
1018
1060
 
1019
1061
  }
1020
1062
 
1021
- if ( this.aoNode !== null || builder.material.aoMap ) {
1063
+ let aoNode = this.aoNode;
1022
1064
 
1023
- const aoNode = this.aoNode !== null ? this.aoNode : materialAO;
1065
+ if ( aoNode === null && builder.material.aoMap ) {
1066
+
1067
+ aoNode = materialAO;
1068
+
1069
+ }
1070
+
1071
+ if ( builder.context.getAO ) {
1072
+
1073
+ aoNode = builder.context.getAO( aoNode, builder );
1074
+
1075
+ }
1076
+
1077
+ if ( aoNode ) {
1024
1078
 
1025
1079
  materialLightsNode.push( new AONode( aoNode ) );
1026
1080
 
@@ -1301,6 +1355,8 @@ class NodeMaterial extends Material {
1301
1355
  this.fragmentNode = source.fragmentNode;
1302
1356
  this.vertexNode = source.vertexNode;
1303
1357
 
1358
+ this.contextNode = source.contextNode;
1359
+
1304
1360
  return super.copy( source );
1305
1361
 
1306
1362
  }
@@ -259,7 +259,7 @@ class NodeMaterialObserver {
259
259
 
260
260
  }
261
261
 
262
- if ( builder.renderer.overrideNodes.modelViewMatrix !== null || builder.renderer.overrideNodes.modelNormalViewMatrix !== null )
262
+ if ( builder.context.modelViewMatrix || builder.context.modelNormalViewMatrix || builder.context.getAO || builder.context.getShadow )
263
263
  return true;
264
264
 
265
265
  return false;
@@ -234,6 +234,16 @@ class Matrix4 {
234
234
  */
235
235
  extractBasis( xAxis, yAxis, zAxis ) {
236
236
 
237
+ if ( this.determinant() === 0 ) {
238
+
239
+ xAxis.set( 1, 0, 0 );
240
+ yAxis.set( 0, 1, 0 );
241
+ zAxis.set( 0, 0, 1 );
242
+
243
+ return this;
244
+
245
+ }
246
+
237
247
  xAxis.setFromMatrixColumn( this, 0 );
238
248
  yAxis.setFromMatrixColumn( this, 1 );
239
249
  zAxis.setFromMatrixColumn( this, 2 );
@@ -274,6 +284,12 @@ class Matrix4 {
274
284
  */
275
285
  extractRotation( m ) {
276
286
 
287
+ if ( m.determinant() === 0 ) {
288
+
289
+ return this.identity();
290
+
291
+ }
292
+
277
293
  const te = this.elements;
278
294
  const me = m.elements;
279
295
 
@@ -614,43 +630,18 @@ class Matrix4 {
614
630
  const n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
615
631
  const n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
616
632
 
617
- //TODO: make this more efficient
618
-
619
- return (
620
- n41 * (
621
- + n14 * n23 * n32
622
- - n13 * n24 * n32
623
- - n14 * n22 * n33
624
- + n12 * n24 * n33
625
- + n13 * n22 * n34
626
- - n12 * n23 * n34
627
- ) +
628
- n42 * (
629
- + n11 * n23 * n34
630
- - n11 * n24 * n33
631
- + n14 * n21 * n33
632
- - n13 * n21 * n34
633
- + n13 * n24 * n31
634
- - n14 * n23 * n31
635
- ) +
636
- n43 * (
637
- + n11 * n24 * n32
638
- - n11 * n22 * n34
639
- - n14 * n21 * n32
640
- + n12 * n21 * n34
641
- + n14 * n22 * n31
642
- - n12 * n24 * n31
643
- ) +
644
- n44 * (
645
- - n13 * n22 * n31
646
- - n11 * n23 * n32
647
- + n11 * n22 * n33
648
- + n13 * n21 * n32
649
- - n12 * n21 * n33
650
- + n12 * n23 * n31
651
- )
633
+ const t11 = n23 * n34 - n24 * n33;
634
+ const t12 = n22 * n34 - n24 * n32;
635
+ const t13 = n22 * n33 - n23 * n32;
652
636
 
653
- );
637
+ const t21 = n21 * n34 - n24 * n31;
638
+ const t22 = n21 * n33 - n23 * n31;
639
+ const t23 = n21 * n32 - n22 * n31;
640
+
641
+ return n11 * ( n42 * t11 - n43 * t12 + n44 * t13 ) -
642
+ n12 * ( n41 * t11 - n43 * t21 + n44 * t22 ) +
643
+ n13 * ( n41 * t12 - n42 * t21 + n44 * t23 ) -
644
+ n14 * ( n41 * t13 - n42 * t22 + n43 * t23 );
654
645
 
655
646
  }
656
647
 
@@ -1051,6 +1042,19 @@ class Matrix4 {
1051
1042
 
1052
1043
  const te = this.elements;
1053
1044
 
1045
+ position.x = te[ 12 ];
1046
+ position.y = te[ 13 ];
1047
+ position.z = te[ 14 ];
1048
+
1049
+ if ( this.determinant() === 0 ) {
1050
+
1051
+ scale.set( 1, 1, 1 );
1052
+ quaternion.identity();
1053
+
1054
+ return this;
1055
+
1056
+ }
1057
+
1054
1058
  let sx = _v1.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
1055
1059
  const sy = _v1.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
1056
1060
  const sz = _v1.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
@@ -1059,10 +1063,6 @@ class Matrix4 {
1059
1063
  const det = this.determinant();
1060
1064
  if ( det < 0 ) sx = - sx;
1061
1065
 
1062
- position.x = te[ 12 ];
1063
- position.y = te[ 13 ];
1064
- position.z = te[ 14 ];
1065
-
1066
1066
  // scale the rotation part
1067
1067
  _m1.copy( this );
1068
1068
 
@@ -405,7 +405,7 @@ class Sphere {
405
405
  * Returns a serialized structure of the bounding sphere.
406
406
  *
407
407
  * @param {Object} json - The serialized json to set the sphere from.
408
- * @return {Box3} A reference to this bounding sphere.
408
+ * @return {Sphere} A reference to this bounding sphere.
409
409
  */
410
410
  fromJSON( json ) {
411
411
 
@@ -744,8 +744,6 @@ class Vector3 {
744
744
 
745
745
  }
746
746
 
747
- // TODO lengthSquared?
748
-
749
747
  /**
750
748
  * Computes the square of the Euclidean length (straight-line length) from
751
749
  * (0, 0, 0) to (x, y, z). If you are comparing the lengths of vectors, you should
package/src/nodes/TSL.js CHANGED
@@ -20,8 +20,11 @@ export * from './core/MRTNode.js';
20
20
 
21
21
  // math
22
22
  export * from './math/BitcastNode.js';
23
+ export * from './math/BitcountNode.js';
23
24
  export * from './math/Hash.js';
24
25
  export * from './math/MathUtils.js';
26
+ export * from './math/PackFloatNode.js';
27
+ export * from './math/UnpackFloatNode.js';
25
28
  export * from './math/TriNoise3D.js';
26
29
 
27
30
  // utils
@@ -160,7 +163,7 @@ export * from './materialx/MaterialXNodes.js';
160
163
  export { default as BRDF_GGX } from './functions/BSDF/BRDF_GGX.js';
161
164
  export { default as BRDF_Lambert } from './functions/BSDF/BRDF_Lambert.js';
162
165
  export { default as D_GGX } from './functions/BSDF/D_GGX.js';
163
- export { default as DFGApprox } from './functions/BSDF/DFGApprox.js';
166
+ export { default as DFGLUT } from './functions/BSDF/DFGLUT.js';
164
167
  export { default as F_Schlick } from './functions/BSDF/F_Schlick.js';
165
168
  export { default as Schlick_to_F0 } from './functions/BSDF/Schlick_to_F0.js';
166
169
  export { default as V_GGX_SmithCorrelated } from './functions/BSDF/V_GGX_SmithCorrelated.js';
@@ -74,9 +74,9 @@ class BatchNode extends Node {
74
74
 
75
75
  const getIndirectIndex = Fn( ( [ id ] ) => {
76
76
 
77
- const size = int( textureSize( textureLoad( this.batchMesh._indirectTexture ), 0 ).x );
78
- const x = int( id ).mod( size );
79
- const y = int( id ).div( size );
77
+ const size = int( textureSize( textureLoad( this.batchMesh._indirectTexture ), 0 ).x ).toConst();
78
+ const x = int( id ).mod( size ).toConst();
79
+ const y = int( id ).div( size ).toConst();
80
80
  return textureLoad( this.batchMesh._indirectTexture, ivec2( x, y ) ).x;
81
81
 
82
82
  } ).setLayout( {
@@ -91,11 +91,11 @@ class BatchNode extends Node {
91
91
 
92
92
  const matricesTexture = this.batchMesh._matricesTexture;
93
93
 
94
- const size = int( textureSize( textureLoad( matricesTexture ), 0 ).x );
95
- const j = float( indirectId ).mul( 4 ).toInt().toVar();
94
+ const size = int( textureSize( textureLoad( matricesTexture ), 0 ).x ).toConst();
95
+ const j = float( indirectId ).mul( 4 ).toInt().toConst();
96
96
 
97
- const x = j.mod( size );
98
- const y = j.div( size );
97
+ const x = j.mod( size ).toConst();
98
+ const y = j.div( size ).toConst();
99
99
  const batchingMatrix = mat4(
100
100
  textureLoad( matricesTexture, ivec2( x, y ) ),
101
101
  textureLoad( matricesTexture, ivec2( x.add( 1 ), y ) ),
@@ -110,10 +110,10 @@ class BatchNode extends Node {
110
110
 
111
111
  const getBatchingColor = Fn( ( [ id ] ) => {
112
112
 
113
- const size = int( textureSize( textureLoad( colorsTexture ), 0 ).x );
113
+ const size = int( textureSize( textureLoad( colorsTexture ), 0 ).x ).toConst();
114
114
  const j = id;
115
- const x = j.mod( size );
116
- const y = j.div( size );
115
+ const x = j.mod( size ).toConst();
116
+ const y = j.div( size ).toConst();
117
117
  return textureLoad( colorsTexture, ivec2( x, y ) ).rgb;
118
118
 
119
119
  } ).setLayout( {