@plastic-software/three 0.182.0 → 0.183.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 (298) hide show
  1. package/LICENSE +1 -1
  2. package/build/three.cjs +11520 -10877
  3. package/build/three.core.js +11732 -11340
  4. package/build/three.core.min.js +2 -2
  5. package/build/three.module.js +509 -262
  6. package/build/three.module.min.js +2 -2
  7. package/build/three.tsl.js +7 -11
  8. package/build/three.tsl.min.js +2 -2
  9. package/build/three.webgpu.js +3072 -2607
  10. package/build/three.webgpu.min.js +2 -2
  11. package/build/three.webgpu.nodes.js +3071 -2607
  12. package/build/three.webgpu.nodes.min.js +2 -2
  13. package/examples/jsm/Addons.js +0 -3
  14. package/examples/jsm/animation/CCDIKSolver.js +2 -2
  15. package/examples/jsm/controls/ArcballControls.js +3 -3
  16. package/examples/jsm/controls/OrbitControls.js +103 -0
  17. package/examples/jsm/effects/AnaglyphEffect.js +102 -7
  18. package/examples/jsm/environments/ColorEnvironment.js +59 -0
  19. package/examples/jsm/environments/RoomEnvironment.js +1 -0
  20. package/examples/jsm/exporters/EXRExporter.js +1 -1
  21. package/examples/jsm/exporters/GLTFExporter.js +131 -4
  22. package/examples/jsm/exporters/USDZExporter.js +22 -3
  23. package/examples/jsm/helpers/AnimationPathHelper.js +302 -0
  24. package/examples/jsm/helpers/ViewHelper.js +67 -8
  25. package/examples/jsm/inspector/Inspector.js +21 -5
  26. package/examples/jsm/inspector/tabs/Console.js +39 -5
  27. package/examples/jsm/inspector/tabs/Parameters.js +16 -0
  28. package/examples/jsm/inspector/ui/Style.js +25 -1
  29. package/examples/jsm/libs/meshopt_decoder.module.js +6 -5
  30. package/examples/jsm/lines/LineMaterial.js +6 -0
  31. package/examples/jsm/loaders/3MFLoader.js +2 -2
  32. package/examples/jsm/loaders/AMFLoader.js +2 -2
  33. package/examples/jsm/loaders/ColladaLoader.js +24 -4026
  34. package/examples/jsm/loaders/EXRLoader.js +5 -5
  35. package/examples/jsm/loaders/FBXLoader.js +2 -2
  36. package/examples/jsm/loaders/GCodeLoader.js +34 -8
  37. package/examples/jsm/loaders/GLTFLoader.js +122 -171
  38. package/examples/jsm/loaders/KMZLoader.js +5 -5
  39. package/examples/jsm/loaders/KTX2Loader.js +5 -5
  40. package/examples/jsm/loaders/LWOLoader.js +7 -39
  41. package/examples/jsm/loaders/NRRDLoader.js +2 -2
  42. package/examples/jsm/loaders/PCDLoader.js +3 -2
  43. package/examples/jsm/loaders/USDLoader.js +100 -40
  44. package/examples/jsm/loaders/UltraHDRLoader.js +182 -30
  45. package/examples/jsm/loaders/VRMLLoader.js +77 -0
  46. package/examples/jsm/loaders/VTKLoader.js +37 -24
  47. package/examples/jsm/loaders/collada/ColladaComposer.js +2950 -0
  48. package/examples/jsm/loaders/collada/ColladaParser.js +1962 -0
  49. package/examples/jsm/loaders/usd/USDAParser.js +447 -366
  50. package/examples/jsm/loaders/usd/USDCParser.js +1841 -6
  51. package/examples/jsm/loaders/usd/USDComposer.js +4041 -0
  52. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +2 -2
  53. package/examples/jsm/objects/LensflareMesh.js +1 -1
  54. package/examples/jsm/objects/Sky.js +76 -4
  55. package/examples/jsm/objects/SkyMesh.js +114 -7
  56. package/examples/jsm/objects/Water.js +4 -3
  57. package/examples/jsm/objects/Water2.js +5 -3
  58. package/examples/jsm/objects/WaterMesh.js +5 -7
  59. package/examples/jsm/physics/JoltPhysics.js +7 -5
  60. package/examples/jsm/physics/RapierPhysics.js +6 -4
  61. package/examples/jsm/postprocessing/EffectComposer.js +7 -5
  62. package/examples/jsm/postprocessing/RenderTransitionPass.js +1 -1
  63. package/examples/jsm/renderers/CSS3DRenderer.js +1 -1
  64. package/examples/jsm/renderers/SVGRenderer.js +2 -2
  65. package/examples/jsm/shaders/GTAOShader.js +19 -6
  66. package/examples/jsm/shaders/HalftoneShader.js +12 -1
  67. package/examples/jsm/shaders/PoissonDenoiseShader.js +6 -2
  68. package/examples/jsm/shaders/SAOShader.js +17 -4
  69. package/examples/jsm/shaders/SSAOShader.js +11 -1
  70. package/examples/jsm/shaders/SSRShader.js +6 -5
  71. package/examples/jsm/shaders/VignetteShader.js +1 -1
  72. package/examples/jsm/tsl/display/AfterImageNode.js +1 -1
  73. package/examples/jsm/tsl/display/AnaglyphPassNode.js +456 -16
  74. package/examples/jsm/tsl/display/AnamorphicNode.js +1 -1
  75. package/examples/jsm/tsl/display/BilateralBlurNode.js +364 -0
  76. package/examples/jsm/tsl/display/BloomNode.js +5 -5
  77. package/examples/jsm/tsl/display/CRT.js +150 -0
  78. package/examples/jsm/tsl/display/DenoiseNode.js +1 -1
  79. package/examples/jsm/tsl/display/DepthOfFieldNode.js +1 -1
  80. package/examples/jsm/tsl/display/DotScreenNode.js +1 -1
  81. package/examples/jsm/tsl/display/FXAANode.js +2 -2
  82. package/examples/jsm/tsl/display/GTAONode.js +2 -2
  83. package/examples/jsm/tsl/display/GaussianBlurNode.js +11 -2
  84. package/examples/jsm/tsl/display/GodraysNode.js +624 -0
  85. package/examples/jsm/tsl/display/LensflareNode.js +1 -1
  86. package/examples/jsm/tsl/display/Lut3DNode.js +1 -1
  87. package/examples/jsm/tsl/display/OutlineNode.js +3 -3
  88. package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +2 -2
  89. package/examples/jsm/tsl/display/PixelationPassNode.js +5 -5
  90. package/examples/jsm/tsl/display/RGBShiftNode.js +2 -2
  91. package/examples/jsm/tsl/display/RetroPassNode.js +263 -0
  92. package/examples/jsm/tsl/display/SMAANode.js +2 -2
  93. package/examples/jsm/tsl/display/SSAAPassNode.js +2 -2
  94. package/examples/jsm/tsl/display/SSGINode.js +2 -2
  95. package/examples/jsm/tsl/display/SSRNode.js +7 -7
  96. package/examples/jsm/tsl/display/SSSNode.js +2 -2
  97. package/examples/jsm/tsl/display/Shape.js +29 -0
  98. package/examples/jsm/tsl/display/SobelOperatorNode.js +2 -2
  99. package/examples/jsm/tsl/display/StereoPassNode.js +1 -2
  100. package/examples/jsm/tsl/display/TRAANode.js +9 -12
  101. package/examples/jsm/tsl/display/TransitionNode.js +1 -1
  102. package/examples/jsm/tsl/display/depthAwareBlend.js +80 -0
  103. package/examples/jsm/tsl/math/Bayer.js +40 -1
  104. package/examples/jsm/utils/LDrawUtils.js +1 -1
  105. package/package.json +11 -19
  106. package/src/Three.Core.js +1 -1
  107. package/src/Three.TSL.js +5 -9
  108. package/src/Three.WebGPU.Nodes.js +2 -0
  109. package/src/Three.WebGPU.js +3 -0
  110. package/src/Three.js +1 -0
  111. package/src/animation/AnimationAction.js +1 -1
  112. package/src/animation/AnimationClip.js +1 -1
  113. package/src/animation/AnimationMixer.js +6 -0
  114. package/src/animation/KeyframeTrack.js +46 -7
  115. package/src/animation/PropertyMixer.js +4 -4
  116. package/src/audio/Audio.js +1 -1
  117. package/src/audio/AudioListener.js +5 -3
  118. package/src/cameras/Camera.js +32 -2
  119. package/src/cameras/CubeCamera.js +20 -0
  120. package/src/constants.js +30 -1
  121. package/src/core/Clock.js +7 -0
  122. package/src/core/Object3D.js +56 -4
  123. package/src/core/RenderTarget.js +3 -4
  124. package/src/extras/PMREMGenerator.js +4 -8
  125. package/src/geometries/TorusGeometry.js +8 -3
  126. package/src/helpers/CameraHelper.js +3 -0
  127. package/src/helpers/DirectionalLightHelper.js +4 -1
  128. package/src/helpers/HemisphereLightHelper.js +3 -0
  129. package/src/helpers/PointLightHelper.js +0 -24
  130. package/src/helpers/SpotLightHelper.js +3 -0
  131. package/src/lights/LightShadow.js +15 -3
  132. package/src/lights/webgpu/IESSpotLight.js +2 -1
  133. package/src/loaders/Cache.js +28 -0
  134. package/src/loaders/FileLoader.js +1 -1
  135. package/src/loaders/ImageBitmapLoader.js +8 -3
  136. package/src/loaders/Loader.js +6 -0
  137. package/src/loaders/ObjectLoader.js +18 -1
  138. package/src/materials/MeshLambertMaterial.js +9 -0
  139. package/src/materials/MeshPhongMaterial.js +9 -0
  140. package/src/materials/nodes/Line2NodeMaterial.js +5 -5
  141. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +2 -0
  142. package/src/materials/nodes/NodeMaterial.js +15 -24
  143. package/src/materials/nodes/manager/NodeMaterialObserver.js +9 -3
  144. package/src/math/Line3.js +3 -5
  145. package/src/math/MathUtils.js +10 -10
  146. package/src/math/Matrix4.js +35 -26
  147. package/src/math/Quaternion.js +3 -29
  148. package/src/math/Vector3.js +3 -3
  149. package/src/math/interpolants/BezierInterpolant.js +108 -0
  150. package/src/nodes/Nodes.js +87 -68
  151. package/src/nodes/TSL.js +2 -5
  152. package/src/nodes/accessors/Arrays.js +1 -1
  153. package/src/nodes/accessors/Bitangent.js +5 -5
  154. package/src/nodes/accessors/BufferAttributeNode.js +1 -1
  155. package/src/nodes/accessors/Camera.js +149 -28
  156. package/src/nodes/accessors/InstanceNode.js +105 -40
  157. package/src/nodes/accessors/Normal.js +9 -9
  158. package/src/nodes/accessors/Position.js +34 -2
  159. package/src/nodes/accessors/SceneProperties.js +53 -0
  160. package/src/nodes/accessors/SkinningNode.js +12 -24
  161. package/src/nodes/accessors/StorageBufferNode.js +0 -19
  162. package/src/nodes/accessors/StorageTextureNode.js +37 -1
  163. package/src/nodes/accessors/Tangent.js +3 -3
  164. package/src/nodes/accessors/Texture3DNode.js +6 -34
  165. package/src/nodes/accessors/TextureNode.js +58 -22
  166. package/src/nodes/accessors/UniformArrayNode.js +2 -0
  167. package/src/nodes/core/MRTNode.js +48 -2
  168. package/src/nodes/core/Node.js +29 -3
  169. package/src/nodes/core/NodeBuilder.js +115 -40
  170. package/src/nodes/core/NodeError.js +28 -0
  171. package/src/nodes/core/NodeUtils.js +5 -3
  172. package/src/nodes/core/OutputStructNode.js +12 -10
  173. package/src/nodes/core/ParameterNode.js +2 -1
  174. package/src/nodes/core/StackNode.js +9 -8
  175. package/src/nodes/core/StackTrace.js +139 -0
  176. package/src/nodes/core/StructNode.js +15 -0
  177. package/src/nodes/core/SubBuildNode.js +1 -1
  178. package/src/nodes/core/UniformNode.js +2 -1
  179. package/src/nodes/core/VarNode.js +1 -1
  180. package/src/nodes/core/VaryingNode.js +1 -18
  181. package/src/nodes/display/BlendModes.js +0 -64
  182. package/src/nodes/display/ColorAdjustment.js +17 -0
  183. package/src/nodes/display/ColorSpaceNode.js +3 -3
  184. package/src/nodes/display/NormalMapNode.js +2 -2
  185. package/src/nodes/display/PassNode.js +21 -2
  186. package/src/nodes/display/RenderOutputNode.js +3 -3
  187. package/src/nodes/display/ScreenNode.js +2 -1
  188. package/src/nodes/display/ToneMappingNode.js +1 -1
  189. package/src/nodes/display/ToonOutlinePassNode.js +2 -2
  190. package/src/nodes/display/ViewportDepthNode.js +52 -4
  191. package/src/nodes/display/ViewportTextureNode.js +21 -4
  192. package/src/nodes/fog/Fog.js +18 -35
  193. package/src/nodes/functions/PhysicalLightingModel.js +25 -3
  194. package/src/nodes/geometry/RangeNode.js +4 -2
  195. package/src/nodes/gpgpu/ComputeNode.js +5 -4
  196. package/src/nodes/gpgpu/WorkgroupInfoNode.js +2 -1
  197. package/src/nodes/lighting/EnvironmentNode.js +28 -3
  198. package/src/nodes/lighting/PointShadowNode.js +24 -12
  199. package/src/nodes/lighting/ShadowFilterNode.js +15 -43
  200. package/src/nodes/lighting/ShadowNode.js +54 -32
  201. package/src/nodes/math/ConditionalNode.js +2 -2
  202. package/src/nodes/math/MathNode.js +3 -40
  203. package/src/nodes/math/OperatorNode.js +2 -1
  204. package/src/nodes/pmrem/PMREMUtils.js +9 -15
  205. package/src/nodes/tsl/TSLCore.js +13 -10
  206. package/src/nodes/utils/DebugNode.js +11 -11
  207. package/src/nodes/utils/JoinNode.js +2 -2
  208. package/src/nodes/utils/LoopNode.js +1 -1
  209. package/src/nodes/utils/MemberNode.js +1 -1
  210. package/src/nodes/utils/RTTNode.js +1 -1
  211. package/src/nodes/utils/ReflectorNode.js +2 -3
  212. package/src/nodes/utils/SpriteSheetUV.js +35 -0
  213. package/src/nodes/utils/UVUtils.js +4 -2
  214. package/src/objects/BatchedMesh.js +22 -12
  215. package/src/objects/InstancedMesh.js +11 -0
  216. package/src/renderers/WebGLRenderer.js +34 -60
  217. package/src/renderers/common/Backend.js +21 -0
  218. package/src/renderers/common/Background.js +7 -4
  219. package/src/renderers/common/BindGroup.js +1 -9
  220. package/src/renderers/common/Bindings.js +20 -5
  221. package/src/renderers/common/BlendMode.js +143 -0
  222. package/src/renderers/common/BundleGroup.js +1 -1
  223. package/src/renderers/common/CubeRenderTarget.js +50 -6
  224. package/src/renderers/common/Geometries.js +17 -3
  225. package/src/renderers/common/Lighting.js +5 -21
  226. package/src/renderers/common/Pipelines.js +4 -4
  227. package/src/renderers/common/PostProcessing.js +8 -206
  228. package/src/renderers/common/RenderBundles.js +2 -1
  229. package/src/renderers/common/RenderContext.js +16 -0
  230. package/src/renderers/common/RenderContexts.js +33 -56
  231. package/src/renderers/common/RenderLists.js +2 -1
  232. package/src/renderers/common/RenderObject.js +2 -3
  233. package/src/renderers/common/RenderObjectPipeline.js +40 -0
  234. package/src/renderers/common/RenderObjects.js +18 -2
  235. package/src/renderers/common/RenderPipeline.js +203 -17
  236. package/src/renderers/common/Renderer.js +207 -40
  237. package/src/renderers/common/Sampler.js +4 -4
  238. package/src/renderers/common/StorageBuffer.js +13 -1
  239. package/src/renderers/common/Textures.js +16 -0
  240. package/src/renderers/common/TimestampQueryPool.js +5 -3
  241. package/src/renderers/common/Uniform.js +8 -0
  242. package/src/renderers/common/UniformsGroup.js +60 -0
  243. package/src/renderers/common/XRManager.js +2 -2
  244. package/src/renderers/common/nodes/NodeBuilderState.js +1 -1
  245. package/src/renderers/common/nodes/{Nodes.js → NodeManager.js} +18 -6
  246. package/src/renderers/common/nodes/NodeStorageBuffer.js +13 -2
  247. package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +2 -2
  248. package/src/renderers/shaders/ShaderChunk/color_fragment.glsl.js +1 -5
  249. package/src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl.js +1 -5
  250. package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +1 -5
  251. package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +8 -10
  252. package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +7 -11
  253. package/src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js +6 -0
  254. package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +6 -2
  255. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +23 -1
  256. package/src/renderers/shaders/ShaderChunk/packing.glsl.js +20 -4
  257. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +55 -24
  258. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +2 -0
  259. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +2 -0
  260. package/src/renderers/shaders/ShaderLib/shadow.glsl.js +1 -0
  261. package/src/renderers/shaders/ShaderLib.js +4 -2
  262. package/src/renderers/shaders/UniformsLib.js +0 -3
  263. package/src/renderers/webgl/WebGLBackground.js +2 -2
  264. package/src/renderers/webgl/WebGLBindingStates.js +99 -27
  265. package/src/renderers/webgl/WebGLEnvironments.js +228 -0
  266. package/src/renderers/webgl/WebGLGeometries.js +10 -7
  267. package/src/renderers/webgl/WebGLMaterials.js +12 -0
  268. package/src/renderers/webgl/WebGLObjects.js +3 -1
  269. package/src/renderers/webgl/WebGLProgram.js +2 -2
  270. package/src/renderers/webgl/WebGLPrograms.js +10 -4
  271. package/src/renderers/webgl/WebGLRenderLists.js +15 -0
  272. package/src/renderers/webgl/WebGLShadowMap.js +5 -4
  273. package/src/renderers/webgl/WebGLState.js +12 -17
  274. package/src/renderers/webgl-fallback/WebGLBackend.js +71 -7
  275. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +98 -29
  276. package/src/renderers/webgl-fallback/utils/WebGLState.js +168 -7
  277. package/src/renderers/webgpu/WebGPUBackend.js +58 -9
  278. package/src/renderers/webgpu/WebGPURenderer.js +1 -0
  279. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +257 -45
  280. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +8 -19
  281. package/src/renderers/webgpu/utils/WebGPUConstants.js +1 -1
  282. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +56 -31
  283. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +152 -200
  284. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +25 -25
  285. package/src/renderers/webgpu/utils/WebGPUUtils.js +10 -6
  286. package/src/renderers/webxr/WebXRManager.js +2 -2
  287. package/src/textures/Texture.js +2 -2
  288. package/src/utils.js +246 -3
  289. package/examples/jsm/materials/MeshGouraudMaterial.js +0 -433
  290. package/examples/jsm/materials/MeshPostProcessingMaterial.js +0 -167
  291. package/examples/jsm/shaders/GodRaysShader.js +0 -333
  292. package/src/nodes/accessors/SceneNode.js +0 -145
  293. package/src/nodes/code/ScriptableNode.js +0 -726
  294. package/src/nodes/code/ScriptableValueNode.js +0 -253
  295. package/src/nodes/display/PosterizeNode.js +0 -65
  296. package/src/nodes/utils/SpriteSheetUVNode.js +0 -90
  297. package/src/renderers/webgl/WebGLCubeMaps.js +0 -99
  298. package/src/renderers/webgl/WebGLCubeUVMaps.js +0 -134
@@ -2,7 +2,7 @@ import Node from '../core/Node.js';
2
2
  import { varyingProperty } from '../core/PropertyNode.js';
3
3
  import { instancedBufferAttribute, instancedDynamicBufferAttribute } from './BufferAttributeNode.js';
4
4
  import { normalLocal, transformNormal } from './Normal.js';
5
- import { positionLocal } from './Position.js';
5
+ import { positionLocal, positionPrevious } from './Position.js';
6
6
  import { nodeProxy, vec3, mat4 } from '../tsl/TSLBase.js';
7
7
  import { NodeUpdateType } from '../core/constants.js';
8
8
  import { buffer } from '../accessors/BufferNode.js';
@@ -99,6 +99,14 @@ class InstanceNode extends Node {
99
99
  */
100
100
  this.bufferColor = null;
101
101
 
102
+ /**
103
+ * The previous instance matrices. Required for computing motion vectors.
104
+ *
105
+ * @type {?Node}
106
+ * @default null
107
+ */
108
+ this.previousInstanceMatrixNode = null;
109
+
102
110
  }
103
111
 
104
112
  /**
@@ -136,51 +144,22 @@ class InstanceNode extends Node {
136
144
  */
137
145
  setup( builder ) {
138
146
 
139
- const { instanceMatrix, instanceColor, isStorageMatrix, isStorageColor } = this;
140
-
141
- const { count } = instanceMatrix;
142
-
143
147
  let { instanceMatrixNode, instanceColorNode } = this;
144
148
 
145
- if ( instanceMatrixNode === null ) {
146
-
147
- if ( isStorageMatrix ) {
148
-
149
- instanceMatrixNode = storage( instanceMatrix, 'mat4', Math.max( count, 1 ) ).element( instanceIndex );
150
-
151
- } else {
152
-
153
- // Both backends have ~64kb UBO limit; fallback to attributes above 1000 matrices.
154
-
155
- if ( count <= 1000 ) {
156
-
157
- instanceMatrixNode = buffer( instanceMatrix.array, 'mat4', Math.max( count, 1 ) ).element( instanceIndex );
158
-
159
- } else {
160
-
161
- const interleaved = new InstancedInterleavedBuffer( instanceMatrix.array, 16, 1 );
162
-
163
- this.buffer = interleaved;
149
+ // instance matrix
164
150
 
165
- const bufferFn = instanceMatrix.usage === DynamicDrawUsage ? instancedDynamicBufferAttribute : instancedBufferAttribute;
166
-
167
- const instanceBuffers = [
168
- bufferFn( interleaved, 'vec4', 16, 0 ),
169
- bufferFn( interleaved, 'vec4', 16, 4 ),
170
- bufferFn( interleaved, 'vec4', 16, 8 ),
171
- bufferFn( interleaved, 'vec4', 16, 12 )
172
- ];
173
-
174
- instanceMatrixNode = mat4( ...instanceBuffers );
175
-
176
- }
151
+ if ( instanceMatrixNode === null ) {
177
152
 
178
- }
153
+ instanceMatrixNode = this._createInstanceMatrixNode( true, builder );
179
154
 
180
155
  this.instanceMatrixNode = instanceMatrixNode;
181
156
 
182
157
  }
183
158
 
159
+ // instance color
160
+
161
+ const { instanceColor, isStorageColor } = this;
162
+
184
163
  if ( instanceColor && instanceColorNode === null ) {
185
164
 
186
165
  if ( isStorageColor ) {
@@ -208,6 +187,12 @@ class InstanceNode extends Node {
208
187
  const instancePosition = instanceMatrixNode.mul( positionLocal ).xyz;
209
188
  positionLocal.assign( instancePosition );
210
189
 
190
+ if ( builder.needsPreviousData() ) {
191
+
192
+ positionPrevious.assign( this.getPreviousInstancedPosition( builder ) );
193
+
194
+ }
195
+
211
196
  // NORMAL
212
197
 
213
198
  if ( builder.hasGeometryAttribute( 'normal' ) ) {
@@ -235,7 +220,7 @@ class InstanceNode extends Node {
235
220
  *
236
221
  * @param {NodeFrame} frame - The current node frame.
237
222
  */
238
- update( /*frame*/ ) {
223
+ update( frame ) {
239
224
 
240
225
  if ( this.buffer !== null && this.isStorageMatrix !== true ) {
241
226
 
@@ -244,7 +229,7 @@ class InstanceNode extends Node {
244
229
 
245
230
  // update version if necessary
246
231
 
247
- if ( this.instanceMatrix.usage !== DynamicDrawUsage && this.instanceMatrix.version !== this.buffer.version ) {
232
+ if ( this.instanceMatrix.version !== this.buffer.version ) {
248
233
 
249
234
  this.buffer.version = this.instanceMatrix.version;
250
235
 
@@ -257,7 +242,7 @@ class InstanceNode extends Node {
257
242
  this.bufferColor.clearUpdateRanges();
258
243
  this.bufferColor.updateRanges.push( ... this.instanceColor.updateRanges );
259
244
 
260
- if ( this.instanceColor.usage !== DynamicDrawUsage && this.instanceColor.version !== this.bufferColor.version ) {
245
+ if ( this.instanceColor.version !== this.bufferColor.version ) {
261
246
 
262
247
  this.bufferColor.version = this.instanceColor.version;
263
248
 
@@ -265,6 +250,86 @@ class InstanceNode extends Node {
265
250
 
266
251
  }
267
252
 
253
+ if ( this.previousInstanceMatrixNode !== null ) {
254
+
255
+ frame.object.previousInstanceMatrix.array.set( this.instanceMatrix.array );
256
+
257
+ }
258
+
259
+ }
260
+
261
+ /**
262
+ * Computes the transformed/instanced vertex position of the previous frame.
263
+ *
264
+ * @param {NodeBuilder} builder - The current node builder.
265
+ * @return {Node<vec3>} The instanced position from the previous frame.
266
+ */
267
+ getPreviousInstancedPosition( builder ) {
268
+
269
+ const instancedMesh = builder.object;
270
+
271
+ if ( this.previousInstanceMatrixNode === null ) {
272
+
273
+ instancedMesh.previousInstanceMatrix = this.instanceMatrix.clone();
274
+
275
+ this.previousInstanceMatrixNode = this._createInstanceMatrixNode( false, builder );
276
+
277
+ }
278
+
279
+ return this.previousInstanceMatrixNode.mul( positionPrevious ).xyz;
280
+
281
+ }
282
+
283
+ /**
284
+ * Creates a node representing the instance matrix data.
285
+ *
286
+ * @private
287
+ * @param {boolean} assignBuffer - Whether the created interleaved buffer should be assigned to the `buffer` member or not.
288
+ * @param {NodeBuilder} builder - A reference to the current node builder.
289
+ * @return {Node} The instance matrix node.
290
+ */
291
+ _createInstanceMatrixNode( assignBuffer, builder ) {
292
+
293
+ let instanceMatrixNode;
294
+
295
+ const { instanceMatrix } = this;
296
+ const { count } = instanceMatrix;
297
+
298
+ if ( this.isStorageMatrix ) {
299
+
300
+ instanceMatrixNode = storage( instanceMatrix, 'mat4', Math.max( count, 1 ) ).element( instanceIndex );
301
+
302
+ } else {
303
+
304
+ const uniformBufferSize = count * 16 * 4; // count * 16 components * 4 bytes (float)
305
+
306
+ if ( uniformBufferSize <= builder.getUniformBufferLimit() ) {
307
+
308
+ instanceMatrixNode = buffer( instanceMatrix.array, 'mat4', Math.max( count, 1 ) ).element( instanceIndex );
309
+
310
+ } else {
311
+
312
+ const interleaved = new InstancedInterleavedBuffer( instanceMatrix.array, 16, 1 );
313
+
314
+ if ( assignBuffer === true ) this.buffer = interleaved;
315
+
316
+ const bufferFn = instanceMatrix.usage === DynamicDrawUsage ? instancedDynamicBufferAttribute : instancedBufferAttribute;
317
+
318
+ const instanceBuffers = [
319
+ bufferFn( interleaved, 'vec4', 16, 0 ),
320
+ bufferFn( interleaved, 'vec4', 16, 4 ),
321
+ bufferFn( interleaved, 'vec4', 16, 8 ),
322
+ bufferFn( interleaved, 'vec4', 16, 12 )
323
+ ];
324
+
325
+ instanceMatrixNode = mat4( ...instanceBuffers );
326
+
327
+ }
328
+
329
+ }
330
+
331
+ return instanceMatrixNode;
332
+
268
333
  }
269
334
 
270
335
  }
@@ -52,7 +52,7 @@ export const normalViewGeometry = /*@__PURE__*/ ( Fn( ( builder ) => {
52
52
 
53
53
  let node;
54
54
 
55
- if ( builder.material.flatShading === true ) {
55
+ if ( builder.isFlatShading() ) {
56
56
 
57
57
  node = normalFlat;
58
58
 
@@ -76,7 +76,7 @@ export const normalWorldGeometry = /*@__PURE__*/ ( Fn( ( builder ) => {
76
76
 
77
77
  let normal = normalViewGeometry.transformDirection( cameraViewMatrix );
78
78
 
79
- if ( builder.material.flatShading !== true ) {
79
+ if ( builder.isFlatShading() !== true ) {
80
80
 
81
81
  normal = normal.toVarying( 'v_normalWorldGeometry' );
82
82
 
@@ -92,15 +92,15 @@ export const normalWorldGeometry = /*@__PURE__*/ ( Fn( ( builder ) => {
92
92
  * @tsl
93
93
  * @type {Node<vec3>}
94
94
  */
95
- export const normalView = /*@__PURE__*/ ( Fn( ( { subBuildFn, material, context } ) => {
95
+ export const normalView = /*@__PURE__*/ ( Fn( ( builder ) => {
96
96
 
97
97
  let node;
98
98
 
99
- if ( subBuildFn === 'NORMAL' || subBuildFn === 'VERTEX' ) {
99
+ if ( builder.subBuildFn === 'NORMAL' || builder.subBuildFn === 'VERTEX' ) {
100
100
 
101
101
  node = normalViewGeometry;
102
102
 
103
- if ( material.flatShading !== true ) {
103
+ if ( builder.isFlatShading() !== true ) {
104
104
 
105
105
  node = directionToFaceDirection( node );
106
106
 
@@ -108,9 +108,9 @@ export const normalView = /*@__PURE__*/ ( Fn( ( { subBuildFn, material, context
108
108
 
109
109
  } else {
110
110
 
111
- // Use getUV context to avoid side effects from nodes overwriting getUV in the context (e.g. EnvironmentNode)
111
+ // Use custom context to avoid side effects from nodes overwriting getUV, getTextureLevel in the context (e.g. EnvironmentNode)
112
112
 
113
- node = context.setupNormal().context( { getUV: null } );
113
+ node = builder.context.setupNormal().context( { getUV: null, getTextureLevel: null } );
114
114
 
115
115
  }
116
116
 
@@ -142,9 +142,9 @@ export const clearcoatNormalView = /*@__PURE__*/ ( Fn( ( { subBuildFn, context }
142
142
 
143
143
  } else {
144
144
 
145
- // Use getUV context to avoid side effects from nodes overwriting getUV in the context (e.g. EnvironmentNode)
145
+ // Use custom context to avoid side effects from nodes overwriting getUV, getTextureLevel in the context (e.g. EnvironmentNode)
146
146
 
147
- node = context.setupClearcoatNormal().context( { getUV: null } );
147
+ node = context.setupClearcoatNormal().context( { getUV: null, getTextureLevel: null } );
148
148
 
149
149
  }
150
150
 
@@ -1,6 +1,28 @@
1
1
  import { attribute } from '../core/AttributeNode.js';
2
- import { Fn, vec3 } from '../tsl/TSLCore.js';
2
+ import { Fn, vec3, vec4 } from '../tsl/TSLCore.js';
3
3
  import { modelWorldMatrix } from './ModelNode.js';
4
+ import { cameraProjectionMatrixInverse } from './Camera.js';
5
+ import { warnOnce } from '../../utils.js';
6
+
7
+ /**
8
+ * TSL object that represents the clip space position of the current rendered object.
9
+ *
10
+ * @tsl
11
+ * @type {VaryingNode<vec4>}
12
+ */
13
+ export const clipSpace = /*@__PURE__*/ ( Fn( ( builder ) => {
14
+
15
+ if ( builder.shaderStage !== 'fragment' ) {
16
+
17
+ warnOnce( 'TSL: `clipSpace` is only available in fragment stage.' );
18
+
19
+ return vec4();
20
+
21
+ }
22
+
23
+ return builder.context.clipSpace.toVarying( 'v_clipSpace' );
24
+
25
+ } ).once() )();
4
26
 
5
27
  /**
6
28
  * TSL object that represents the position attribute of the current rendered object.
@@ -61,9 +83,19 @@ export const positionWorldDirection = /*@__PURE__*/ ( Fn( () => {
61
83
  */
62
84
  export const positionView = /*@__PURE__*/ ( Fn( ( builder ) => {
63
85
 
86
+ if ( builder.shaderStage === 'fragment' && builder.material.vertexNode ) {
87
+
88
+ // reconstruct view position from clip space
89
+
90
+ const viewPos = cameraProjectionMatrixInverse.mul( clipSpace );
91
+
92
+ return viewPos.xyz.div( viewPos.w ).toVar( 'positionView' );
93
+
94
+ }
95
+
64
96
  return builder.context.setupPositionView().toVarying( 'v_positionView' );
65
97
 
66
- }, 'vec3' ).once( [ 'POSITION' ] ) )();
98
+ }, 'vec3' ).once( [ 'POSITION', 'VERTEX' ] ) )();
67
99
 
68
100
  /**
69
101
  * TSL object that represents the position view direction of the current rendered object.
@@ -0,0 +1,53 @@
1
+ import { UVMapping } from '../../constants.js';
2
+ import { Euler } from '../../math/Euler.js';
3
+ import { Matrix4 } from '../../math/Matrix4.js';
4
+ import { renderGroup } from '../core/UniformGroupNode.js';
5
+ import { uniform } from '../tsl/TSLBase.js';
6
+
7
+ const _e1 = /*@__PURE__*/ new Euler();
8
+ const _m1 = /*@__PURE__*/ new Matrix4();
9
+
10
+ /**
11
+ * TSL object that represents the scene's background blurriness.
12
+ *
13
+ * @tsl
14
+ * @type {Node<float>}
15
+ */
16
+ export const backgroundBlurriness = /*@__PURE__*/ uniform( 0 ).setGroup( renderGroup ).onRenderUpdate( ( { scene } ) => scene.backgroundBlurriness );
17
+
18
+ /**
19
+ * TSL object that represents the scene's background intensity.
20
+ *
21
+ * @tsl
22
+ * @type {Node<float>}
23
+ */
24
+ export const backgroundIntensity = /*@__PURE__*/ uniform( 1 ).setGroup( renderGroup ).onRenderUpdate( ( { scene } ) => scene.backgroundIntensity );
25
+
26
+ /**
27
+ * TSL object that represents the scene's background rotation.
28
+ *
29
+ * @tsl
30
+ * @type {Node<mat4>}
31
+ */
32
+ export const backgroundRotation = /*@__PURE__*/ uniform( new Matrix4() ).setGroup( renderGroup ).onRenderUpdate( ( { scene } ) => {
33
+
34
+ const background = scene.background;
35
+
36
+ if ( background !== null && background.isTexture && background.mapping !== UVMapping ) {
37
+
38
+ _e1.copy( scene.backgroundRotation );
39
+
40
+ // accommodate left-handed frame
41
+ _e1.x *= - 1; _e1.y *= - 1; _e1.z *= - 1;
42
+
43
+ _m1.makeRotationFromEuler( _e1 );
44
+
45
+ } else {
46
+
47
+ _m1.identity();
48
+
49
+ }
50
+
51
+ return _m1;
52
+
53
+ } );
@@ -9,7 +9,6 @@ import { positionLocal, positionPrevious } from './Position.js';
9
9
  import { tangentLocal } from './Tangent.js';
10
10
  import { uniform } from '../core/UniformNode.js';
11
11
  import { buffer } from './BufferNode.js';
12
- import { getDataFromObject } from '../core/NodeUtils.js';
13
12
  import { storage } from './StorageBufferNode.js';
14
13
  import { InstancedBufferAttribute } from '../../core/InstancedBufferAttribute.js';
15
14
  import { instanceIndex } from '../core/IndexNode.js';
@@ -147,13 +146,14 @@ class SkinningNode extends Node {
147
146
  }
148
147
 
149
148
  /**
150
- * Transforms the given vertex normal via skinning.
149
+ * Transforms the given vertex normal and tangent via skinning.
151
150
  *
152
151
  * @param {Node} [boneMatrices=this.boneMatricesNode] - The bone matrices
153
152
  * @param {Node<vec3>} [normal=normalLocal] - The vertex normal in local space.
154
- * @return {Node<vec3>} The transformed vertex normal.
153
+ * @param {Node<vec3>} [tangent=tangentLocal] - The vertex tangent in local space.
154
+ * @return {{skinNormal: Node<vec3>, skinTangent:Node<vec3>}} The transformed vertex normal and tangent.
155
155
  */
156
- getSkinnedNormal( boneMatrices = this.boneMatricesNode, normal = normalLocal ) {
156
+ getSkinnedNormalAndTangent( boneMatrices = this.boneMatricesNode, normal = normalLocal, tangent = tangentLocal ) {
157
157
 
158
158
  const { skinIndexNode, skinWeightNode, bindMatrixNode, bindMatrixInverseNode } = this;
159
159
 
@@ -162,7 +162,7 @@ class SkinningNode extends Node {
162
162
  const boneMatZ = boneMatrices.element( skinIndexNode.z );
163
163
  const boneMatW = boneMatrices.element( skinIndexNode.w );
164
164
 
165
- // NORMAL
165
+ // NORMAL and TANGENT
166
166
 
167
167
  let skinMatrix = add(
168
168
  skinWeightNode.x.mul( boneMatX ),
@@ -173,7 +173,10 @@ class SkinningNode extends Node {
173
173
 
174
174
  skinMatrix = bindMatrixInverseNode.mul( skinMatrix ).mul( bindMatrixNode );
175
175
 
176
- return skinMatrix.transformDirection( normal ).xyz;
176
+ const skinNormal = skinMatrix.transformDirection( normal ).xyz;
177
+ const skinTangent = skinMatrix.transformDirection( tangent ).xyz;
178
+
179
+ return { skinNormal, skinTangent };
177
180
 
178
181
  }
179
182
 
@@ -199,21 +202,6 @@ class SkinningNode extends Node {
199
202
 
200
203
  }
201
204
 
202
- /**
203
- * Returns `true` if bone matrices from the previous frame are required. Relevant
204
- * when computing motion vectors with {@link VelocityNode}.
205
- *
206
- * @param {NodeBuilder} builder - The current node builder.
207
- * @return {boolean} Whether bone matrices from the previous frame are required or not.
208
- */
209
- needsPreviousBoneMatrices( builder ) {
210
-
211
- const mrt = builder.renderer.getMRT();
212
-
213
- return ( mrt && mrt.has( 'velocity' ) ) || getDataFromObject( builder.object ).useVelocity === true;
214
-
215
- }
216
-
217
205
  /**
218
206
  * Setups the skinning node by assigning the transformed vertex data to predefined node variables.
219
207
  *
@@ -222,7 +210,7 @@ class SkinningNode extends Node {
222
210
  */
223
211
  setup( builder ) {
224
212
 
225
- if ( this.needsPreviousBoneMatrices( builder ) ) {
213
+ if ( builder.needsPreviousData() ) {
226
214
 
227
215
  positionPrevious.assign( this.getPreviousSkinnedPosition( builder ) );
228
216
 
@@ -236,13 +224,13 @@ class SkinningNode extends Node {
236
224
 
237
225
  if ( builder.hasGeometryAttribute( 'normal' ) ) {
238
226
 
239
- const skinNormal = this.getSkinnedNormal();
227
+ const { skinNormal, skinTangent } = this.getSkinnedNormalAndTangent();
240
228
 
241
229
  normalLocal.assign( skinNormal );
242
230
 
243
231
  if ( builder.hasGeometryAttribute( 'tangent' ) ) {
244
232
 
245
- tangentLocal.assign( skinNormal );
233
+ tangentLocal.assign( skinTangent );
246
234
 
247
235
  }
248
236
 
@@ -4,7 +4,6 @@ import { varying } from '../tsl/TSLBase.js';
4
4
  import { storageElement } from '../utils/StorageArrayElementNode.js';
5
5
  import { NodeAccess } from '../core/constants.js';
6
6
  import { getTypeFromLength } from '../core/NodeUtils.js';
7
- import { warn } from '../../utils.js';
8
7
 
9
8
  /**
10
9
  * This node is used in context of compute shaders and allows to define a
@@ -398,21 +397,3 @@ export default StorageBufferNode;
398
397
  * @returns {StorageBufferNode}
399
398
  */
400
399
  export const storage = ( value, type = null, count = 0 ) => new StorageBufferNode( value, type, count );
401
-
402
- /**
403
- * @tsl
404
- * @function
405
- * @deprecated since r171. Use `storage().setPBO( true )` instead.
406
- *
407
- * @param {StorageBufferAttribute|StorageInstancedBufferAttribute|BufferAttribute} value - The buffer data.
408
- * @param {?string} type - The buffer type (e.g. `'vec3'`).
409
- * @param {number} count - The buffer count.
410
- * @returns {StorageBufferNode}
411
- */
412
- export const storageObject = ( value, type, count ) => { // @deprecated, r171
413
-
414
- warn( 'TSL: "storageObject()" is deprecated. Use "storage().setPBO( true )" instead.' );
415
-
416
- return storage( value, type, count ).setPBO( true );
417
-
418
- };
@@ -162,6 +162,28 @@ class StorageTextureNode extends TextureNode {
162
162
 
163
163
  }
164
164
 
165
+ /**
166
+ * Generates the snippet for the storage texture.
167
+ *
168
+ * @param {NodeBuilder} builder - The current node builder.
169
+ * @param {string} textureProperty - The texture property.
170
+ * @param {string} uvSnippet - The uv snippet.
171
+ * @param {?string} levelSnippet - The level snippet.
172
+ * @param {?string} biasSnippet - The bias snippet.
173
+ * @param {?string} depthSnippet - The depth snippet.
174
+ * @param {?string} compareSnippet - The compare snippet.
175
+ * @param {?Array<string>} gradSnippet - The grad snippet.
176
+ * @param {?string} offsetSnippet - The offset snippet.
177
+ * @return {string} The generated code snippet.
178
+ */
179
+ generateSnippet( builder, textureProperty, uvSnippet, levelSnippet, biasSnippet, depthSnippet, compareSnippet, gradSnippet, offsetSnippet ) {
180
+
181
+ const texture = this.value;
182
+
183
+ return builder.generateStorageTextureLoad( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet, offsetSnippet );
184
+
185
+ }
186
+
165
187
  /**
166
188
  * Convenience method for configuring a read/write node access.
167
189
  *
@@ -222,6 +244,7 @@ class StorageTextureNode extends TextureNode {
222
244
  const newNode = super.clone();
223
245
  newNode.storeNode = this.storeNode;
224
246
  newNode.mipLevel = this.mipLevel;
247
+ newNode.access = this.access;
225
248
  return newNode;
226
249
 
227
250
  }
@@ -255,7 +278,20 @@ export const storageTexture = /*@__PURE__*/ nodeProxy( StorageTextureNode ).setP
255
278
  */
256
279
  export const textureStore = ( value, uvNode, storeNode ) => {
257
280
 
258
- const node = storageTexture( value, uvNode, storeNode );
281
+ let node;
282
+
283
+ if ( value.isStorageTextureNode === true ) {
284
+
285
+ // Derive new storage texture node from existing one
286
+ node = value.clone();
287
+ node.uvNode = uvNode;
288
+ node.storeNode = storeNode;
289
+
290
+ } else {
291
+
292
+ node = storageTexture( value, uvNode, storeNode );
293
+
294
+ }
259
295
 
260
296
  if ( storeNode !== null ) node.toStack();
261
297
 
@@ -27,11 +27,11 @@ export const tangentLocal = /*@__PURE__*/ tangentGeometry.xyz.toVar( 'tangentLoc
27
27
  * @tsl
28
28
  * @type {Node<vec3>}
29
29
  */
30
- export const tangentView = /*@__PURE__*/ ( Fn( ( { subBuildFn, geometry, material } ) => {
30
+ export const tangentView = /*@__PURE__*/ ( Fn( ( builder ) => {
31
31
 
32
32
  let node;
33
33
 
34
- if ( subBuildFn === 'VERTEX' || geometry.hasAttribute( 'tangent' ) ) {
34
+ if ( builder.subBuildFn === 'VERTEX' || builder.geometry.hasAttribute( 'tangent' ) ) {
35
35
 
36
36
  node = modelViewMatrix.mul( vec4( tangentLocal, 0 ) ).xyz.toVarying( 'v_tangentView' ).normalize();
37
37
 
@@ -41,7 +41,7 @@ export const tangentView = /*@__PURE__*/ ( Fn( ( { subBuildFn, geometry, materia
41
41
 
42
42
  }
43
43
 
44
- if ( material.flatShading !== true ) {
44
+ if ( builder.isFlatShading() !== true ) {
45
45
 
46
46
  node = directionToFaceDirection( node );
47
47
 
@@ -1,6 +1,5 @@
1
1
  import TextureNode from './TextureNode.js';
2
- import { nodeProxy, vec3, Fn, If, int } from '../tsl/TSLBase.js';
3
- import { textureSize } from './TextureSizeNode.js';
2
+ import { nodeProxy, vec3, Fn, If } from '../tsl/TSLBase.js';
4
3
 
5
4
  const normal = Fn( ( { texture, uv } ) => {
6
5
 
@@ -115,35 +114,6 @@ class Texture3DNode extends TextureNode {
115
114
  */
116
115
  setUpdateMatrix( /*value*/ ) { } // Ignore .updateMatrix for 3d TextureNode
117
116
 
118
- /**
119
- * Overwrites the default implementation to return the unmodified uv node.
120
- *
121
- * @param {NodeBuilder} builder - The current node builder.
122
- * @param {Node} uvNode - The uv node to setup.
123
- * @return {Node} The unmodified uv node.
124
- */
125
- setupUV( builder, uvNode ) {
126
-
127
- const texture = this.value;
128
-
129
- if ( builder.isFlipY() && ( texture.isRenderTargetTexture === true || texture.isFramebufferTexture === true ) ) {
130
-
131
- if ( this.sampler ) {
132
-
133
- uvNode = uvNode.flipY();
134
-
135
- } else {
136
-
137
- uvNode = uvNode.setY( int( textureSize( this, this.levelNode ).y ).sub( uvNode.y ).sub( 1 ) );
138
-
139
- }
140
-
141
- }
142
-
143
- return uvNode;
144
-
145
- }
146
-
147
117
  /**
148
118
  * Generates the uv code snippet.
149
119
  *
@@ -171,10 +141,12 @@ class Texture3DNode extends TextureNode {
171
141
  }
172
142
 
173
143
  /**
174
- * TODO.
144
+ * Computes the normal for the given uv. These texture coordiantes represent a
145
+ * position inside the 3D texture. Unlike geometric normals, this normal
146
+ * represents a slope or gradient of scalar data inside the 3D texture.
175
147
  *
176
- * @param {Node<vec3>} uvNode - The uv node .
177
- * @return {Node<vec3>} TODO.
148
+ * @param {Node<vec3>} uvNode - The uv node that defines a position in the 3D texture.
149
+ * @return {Node<vec3>} The normal representing the slope/gradient in the data.
178
150
  */
179
151
  normal( uvNode ) {
180
152