super-three 0.169.1 → 0.170.1

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 (255) hide show
  1. package/build/three.cjs +24628 -24228
  2. package/build/three.core.js +37002 -0
  3. package/build/three.core.min.js +6 -0
  4. package/build/three.module.js +10519 -47108
  5. package/build/three.module.min.js +1 -1
  6. package/build/three.tsl.js +533 -0
  7. package/build/three.tsl.min.js +6 -0
  8. package/build/three.webgpu.js +17071 -53583
  9. package/build/three.webgpu.min.js +1 -1
  10. package/build/three.webgpu.nodes.js +17134 -53623
  11. package/build/three.webgpu.nodes.min.js +1 -1
  12. package/examples/jsm/Addons.js +3 -3
  13. package/examples/jsm/animation/MMDAnimationHelper.js +2 -0
  14. package/examples/jsm/animation/MMDPhysics.js +2 -0
  15. package/examples/jsm/capabilities/WebGPU.js +1 -10
  16. package/examples/jsm/controls/ArcballControls.js +25 -21
  17. package/examples/jsm/controls/OrbitControls.js +41 -9
  18. package/examples/jsm/controls/PointerLockControls.js +2 -5
  19. package/examples/jsm/controls/TransformControls.js +22 -6
  20. package/examples/jsm/csm/CSM.js +2 -2
  21. package/examples/jsm/csm/CSMFrustum.js +7 -4
  22. package/examples/jsm/csm/CSMHelper.js +2 -0
  23. package/examples/jsm/csm/CSMShadowNode.js +437 -0
  24. package/examples/jsm/curves/NURBSCurve.js +34 -3
  25. package/examples/jsm/exporters/GLTFExporter.js +138 -71
  26. package/examples/jsm/exporters/KTX2Exporter.js +35 -12
  27. package/examples/jsm/exporters/MMDExporter.js +6 -0
  28. package/examples/jsm/exporters/USDZExporter.js +21 -3
  29. package/examples/jsm/geometries/DecalGeometry.js +70 -21
  30. package/examples/jsm/geometries/InstancedPointsGeometry.js +2 -0
  31. package/examples/jsm/helpers/TextureHelperGPU.js +175 -0
  32. package/examples/jsm/interactive/HTMLMesh.js +1 -0
  33. package/examples/jsm/lighting/TiledLighting.js +18 -0
  34. package/examples/jsm/lights/RectAreaLightTexturesLib.js +1 -1
  35. package/examples/jsm/lines/LineGeometry.js +25 -0
  36. package/examples/jsm/lines/LineMaterial.js +0 -1
  37. package/examples/jsm/lines/LineSegmentsGeometry.js +2 -0
  38. package/examples/jsm/lines/webgpu/Line2.js +2 -1
  39. package/examples/jsm/lines/webgpu/LineSegments2.js +2 -16
  40. package/examples/jsm/lines/webgpu/Wireframe.js +57 -0
  41. package/examples/jsm/loaders/3DMLoader.js +1 -0
  42. package/examples/jsm/loaders/3MFLoader.js +91 -0
  43. package/examples/jsm/loaders/FBXLoader.js +12 -2
  44. package/examples/jsm/loaders/GLTFLoader.js +2 -0
  45. package/examples/jsm/loaders/KTX2Loader.js +143 -49
  46. package/examples/jsm/loaders/LDrawLoader.js +22 -136
  47. package/examples/jsm/loaders/LottieLoader.js +1 -0
  48. package/examples/jsm/loaders/MMDLoader.js +3 -0
  49. package/examples/jsm/loaders/MaterialXLoader.js +2 -2
  50. package/examples/jsm/materials/LDrawConditionalLineMaterial.js +143 -0
  51. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +114 -0
  52. package/examples/jsm/math/ColorSpaces.js +76 -0
  53. package/examples/jsm/misc/ProgressiveLightMap.js +52 -40
  54. package/examples/jsm/misc/ProgressiveLightMapGPU.js +293 -0
  55. package/examples/jsm/misc/VolumeSlice.js +1 -0
  56. package/examples/jsm/objects/InstancedPoints.js +2 -4
  57. package/examples/jsm/objects/LensflareMesh.js +4 -2
  58. package/examples/jsm/objects/SkyMesh.js +5 -3
  59. package/examples/jsm/objects/Water2Mesh.js +7 -3
  60. package/examples/jsm/objects/WaterMesh.js +12 -10
  61. package/examples/jsm/postprocessing/AfterimagePass.js +14 -3
  62. package/examples/jsm/postprocessing/SSRPass.js +6 -0
  63. package/examples/jsm/renderers/CSS2DRenderer.js +6 -3
  64. package/examples/jsm/renderers/CSS3DRenderer.js +7 -4
  65. package/examples/jsm/shaders/FXAAShader.js +225 -224
  66. package/examples/jsm/transpiler/AST.js +2 -2
  67. package/examples/jsm/transpiler/GLSLDecoder.js +57 -25
  68. package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
  69. package/examples/jsm/transpiler/TSLEncoder.js +11 -6
  70. package/{src/nodes → examples/jsm/tsl}/display/AfterImageNode.js +18 -21
  71. package/{src/nodes → examples/jsm/tsl}/display/AnaglyphPassNode.js +2 -6
  72. package/{src/nodes → examples/jsm/tsl}/display/AnamorphicNode.js +12 -18
  73. package/{src/nodes → examples/jsm/tsl}/display/BleachBypass.js +1 -3
  74. package/{src/nodes → examples/jsm/tsl}/display/BloomNode.js +12 -41
  75. package/{src/nodes → examples/jsm/tsl}/display/DenoiseNode.js +60 -47
  76. package/{src/nodes → examples/jsm/tsl}/display/DepthOfFieldNode.js +4 -9
  77. package/{src/nodes → examples/jsm/tsl}/display/DotScreenNode.js +2 -9
  78. package/examples/jsm/tsl/display/FXAANode.js +316 -0
  79. package/{src/nodes → examples/jsm/tsl}/display/FilmNode.js +4 -7
  80. package/{src/nodes → examples/jsm/tsl}/display/GTAONode.js +73 -78
  81. package/{src/nodes → examples/jsm/tsl}/display/GaussianBlurNode.js +78 -42
  82. package/examples/jsm/tsl/display/LensflareNode.js +161 -0
  83. package/{src/nodes → examples/jsm/tsl}/display/Lut3DNode.js +3 -5
  84. package/{src/nodes → examples/jsm/tsl}/display/MotionBlur.js +2 -3
  85. package/examples/jsm/tsl/display/OutlineNode.js +434 -0
  86. package/{src/nodes → examples/jsm/tsl}/display/ParallaxBarrierPassNode.js +2 -5
  87. package/{src/nodes → examples/jsm/tsl}/display/PixelationPassNode.js +5 -17
  88. package/{src/nodes → examples/jsm/tsl}/display/RGBShiftNode.js +2 -6
  89. package/examples/jsm/tsl/display/SMAANode.js +620 -0
  90. package/{src/nodes → examples/jsm/tsl}/display/SSAAPassNode.js +10 -25
  91. package/examples/jsm/tsl/display/SSRNode.js +366 -0
  92. package/{src/nodes → examples/jsm/tsl}/display/Sepia.js +1 -2
  93. package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +4 -12
  94. package/{src/nodes → examples/jsm/tsl}/display/StereoCompositePassNode.js +9 -11
  95. package/{src/nodes → examples/jsm/tsl}/display/StereoPassNode.js +10 -11
  96. package/examples/jsm/tsl/display/TRAAPassNode.js +355 -0
  97. package/{src/nodes → examples/jsm/tsl}/display/TransitionNode.js +3 -7
  98. package/examples/jsm/tsl/display/hashBlur.js +24 -0
  99. package/examples/jsm/tsl/lighting/TiledLightsNode.js +389 -0
  100. package/examples/jsm/utils/SceneOptimizer.js +410 -0
  101. package/examples/jsm/utils/UVsDebug.js +1 -1
  102. package/examples/jsm/utils/{TextureUtilsGPU.js → WebGPUTextureUtils.js} +2 -1
  103. package/examples/jsm/webxr/OculusHandPointerModel.js +21 -21
  104. package/examples/jsm/webxr/Text2D.js +6 -6
  105. package/package.json +4 -4
  106. package/src/Three.Core.js +178 -0
  107. package/src/Three.TSL.js +526 -0
  108. package/src/Three.WebGPU.Nodes.js +9 -186
  109. package/src/Three.WebGPU.js +8 -186
  110. package/src/Three.js +1 -177
  111. package/src/animation/AnimationClip.js +2 -2
  112. package/src/animation/AnimationObjectGroup.js +2 -2
  113. package/src/audio/Audio.js +38 -0
  114. package/src/cameras/PerspectiveCamera.js +6 -6
  115. package/src/cameras/StereoCamera.js +2 -2
  116. package/src/constants.js +1 -6
  117. package/src/core/BufferGeometry.js +48 -8
  118. package/src/core/InterleavedBuffer.js +4 -4
  119. package/src/core/Object3D.js +2 -2
  120. package/src/extras/core/Curve.js +3 -3
  121. package/src/extras/core/Shape.js +2 -2
  122. package/src/geometries/CylinderGeometry.js +2 -2
  123. package/src/geometries/EdgesGeometry.js +2 -2
  124. package/src/geometries/LatheGeometry.js +2 -2
  125. package/src/lights/SpotLightShadow.js +2 -2
  126. package/src/materials/LineDashedMaterial.js +0 -1
  127. package/src/materials/Material.js +2 -2
  128. package/src/materials/MeshPhongMaterial.js +1 -1
  129. package/src/materials/MeshPhysicalMaterial.js +2 -2
  130. package/src/materials/MeshStandardMaterial.js +2 -2
  131. package/src/materials/nodes/Line2NodeMaterial.js +32 -13
  132. package/src/materials/nodes/LineDashedNodeMaterial.js +4 -2
  133. package/src/materials/nodes/NodeMaterial.js +93 -23
  134. package/src/materials/nodes/SpriteNodeMaterial.js +11 -2
  135. package/src/materials/nodes/manager/NodeMaterialObserver.js +119 -7
  136. package/src/math/ColorManagement.js +143 -102
  137. package/src/math/Line3.js +2 -2
  138. package/src/math/Quaternion.js +2 -2
  139. package/src/math/Spherical.js +3 -3
  140. package/src/math/Vector2.js +7 -7
  141. package/src/math/Vector3.js +9 -9
  142. package/src/math/Vector4.js +22 -9
  143. package/src/nodes/Nodes.js +2 -21
  144. package/src/nodes/TSL.js +9 -25
  145. package/src/nodes/accessors/Arrays.js +27 -0
  146. package/src/nodes/accessors/BuiltinNode.js +26 -0
  147. package/src/nodes/accessors/Camera.js +0 -1
  148. package/src/nodes/accessors/ClippingNode.js +76 -42
  149. package/src/nodes/accessors/InstanceNode.js +17 -20
  150. package/src/nodes/accessors/InstancedMeshNode.js +26 -0
  151. package/src/nodes/accessors/Lights.js +32 -0
  152. package/src/nodes/accessors/SceneNode.js +35 -1
  153. package/src/nodes/accessors/StorageBufferNode.js +61 -19
  154. package/src/nodes/accessors/StorageTextureNode.js +10 -4
  155. package/src/nodes/accessors/TextureNode.js +1 -1
  156. package/src/nodes/accessors/VelocityNode.js +13 -3
  157. package/src/nodes/code/FunctionCallNode.js +16 -5
  158. package/src/nodes/code/ScriptableNode.js +4 -4
  159. package/src/nodes/core/Node.js +1 -0
  160. package/src/nodes/core/NodeBuilder.js +31 -14
  161. package/src/nodes/core/NodeUtils.js +28 -0
  162. package/src/nodes/core/VarNode.js +15 -3
  163. package/src/nodes/core/constants.js +6 -0
  164. package/src/nodes/display/BlendModes.js +99 -0
  165. package/src/nodes/display/ColorAdjustment.js +53 -4
  166. package/src/nodes/display/ColorSpaceFunctions.js +5 -5
  167. package/src/nodes/display/ColorSpaceNode.js +27 -39
  168. package/src/nodes/display/PassNode.js +6 -4
  169. package/src/nodes/display/ToneMappingNode.js +1 -1
  170. package/src/nodes/display/ToonOutlinePassNode.js +3 -3
  171. package/src/nodes/display/ViewportDepthNode.js +48 -1
  172. package/src/nodes/functions/PhysicalLightingModel.js +21 -15
  173. package/src/nodes/functions/material/getAlphaHashThreshold.js +70 -0
  174. package/src/nodes/functions/material/getGeometryRoughness.js +8 -2
  175. package/src/nodes/functions/material/getParallaxCorrectNormal.js +22 -0
  176. package/src/nodes/gpgpu/ComputeNode.js +9 -1
  177. package/src/nodes/lighting/AnalyticLightNode.js +23 -419
  178. package/src/nodes/lighting/LightsNode.js +24 -12
  179. package/src/nodes/lighting/PointLightNode.js +41 -22
  180. package/src/nodes/lighting/PointShadowNode.js +254 -0
  181. package/src/nodes/lighting/RectAreaLightNode.js +3 -0
  182. package/src/nodes/lighting/ShadowNode.js +593 -0
  183. package/src/nodes/lighting/SpotLightNode.js +14 -2
  184. package/src/nodes/utils/LoopNode.js +2 -2
  185. package/src/nodes/utils/Oscillators.js +6 -0
  186. package/src/nodes/utils/PostProcessingUtils.js +89 -0
  187. package/src/nodes/utils/RTTNode.js +9 -1
  188. package/src/nodes/utils/ReflectorNode.js +101 -15
  189. package/src/nodes/utils/StorageArrayElementNode.js +2 -2
  190. package/src/nodes/utils/Timer.js +29 -0
  191. package/src/objects/BatchedMesh.js +472 -296
  192. package/src/objects/ClippingGroup.js +19 -0
  193. package/src/objects/Skeleton.js +2 -2
  194. package/src/renderers/WebGLRenderer.js +183 -109
  195. package/src/renderers/common/Animation.js +23 -11
  196. package/src/renderers/common/Attributes.js +4 -0
  197. package/src/renderers/common/Backend.js +2 -0
  198. package/src/renderers/common/Background.js +15 -5
  199. package/src/renderers/common/Bindings.js +23 -6
  200. package/src/renderers/common/ClippingContext.js +77 -85
  201. package/src/renderers/common/Constants.js +2 -1
  202. package/src/renderers/common/Geometries.js +20 -0
  203. package/src/renderers/common/IndirectStorageBufferAttribute.js +15 -0
  204. package/src/renderers/common/Lighting.js +45 -0
  205. package/src/renderers/common/PostProcessingUtils.js +86 -0
  206. package/src/renderers/common/RenderList.js +48 -17
  207. package/src/renderers/common/RenderLists.js +4 -2
  208. package/src/renderers/common/RenderObject.js +45 -28
  209. package/src/renderers/common/RenderObjects.js +12 -6
  210. package/src/renderers/common/Renderer.js +222 -77
  211. package/src/renderers/common/Textures.js +41 -17
  212. package/src/renderers/common/UniformsGroup.js +16 -4
  213. package/src/renderers/common/extras/PMREMGenerator.js +89 -13
  214. package/src/renderers/common/nodes/NodeLibrary.js +2 -15
  215. package/src/renderers/common/nodes/NodeStorageBuffer.js +2 -3
  216. package/src/renderers/common/nodes/NodeUniform.js +42 -0
  217. package/src/renderers/common/nodes/Nodes.js +2 -2
  218. package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
  219. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
  220. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
  221. package/src/renderers/webgl/WebGLBackground.js +20 -1
  222. package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
  223. package/src/renderers/webgl/WebGLCapabilities.js +0 -7
  224. package/src/renderers/webgl/WebGLGeometries.js +0 -28
  225. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
  226. package/src/renderers/webgl/WebGLProgram.js +24 -28
  227. package/src/renderers/webgl/WebGLPrograms.js +5 -2
  228. package/src/renderers/webgl/WebGLState.js +37 -1
  229. package/src/renderers/webgl/WebGLTextures.js +29 -12
  230. package/src/renderers/webgl-fallback/WebGLBackend.js +111 -37
  231. package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +2 -7
  232. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +43 -12
  233. package/src/renderers/webgl-fallback/utils/WebGLState.js +26 -1
  234. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +37 -9
  235. package/src/renderers/webgpu/WebGPUBackend.js +152 -56
  236. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +1 -1
  237. package/src/renderers/webgpu/WebGPURenderer.js +1 -1
  238. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +0 -8
  239. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +13 -34
  240. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +192 -92
  241. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +12 -4
  242. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +15 -2
  243. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +72 -7
  244. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +29 -9
  245. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +29 -7
  246. package/src/renderers/webgpu/utils/WebGPUUtils.js +0 -1
  247. package/src/renderers/webxr/WebXRManager.js +4 -4
  248. package/src/textures/Source.js +2 -2
  249. package/src/textures/Texture.js +2 -2
  250. package/examples/jsm/cameras/CinematicCamera.js +0 -208
  251. package/src/nodes/display/BlendMode.js +0 -54
  252. package/src/nodes/display/FXAANode.js +0 -332
  253. package/src/nodes/utils/OscNode.js +0 -85
  254. package/src/nodes/utils/TimerNode.js +0 -97
  255. /package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +0 -0
@@ -0,0 +1,26 @@
1
+ import Node from '../core/Node.js';
2
+ import { nodeProxy } from '../tsl/TSLBase.js';
3
+
4
+ class BuiltinNode extends Node {
5
+
6
+ constructor( name ) {
7
+
8
+ super( 'float' );
9
+
10
+ this.name = name;
11
+
12
+ this.isBuiltinNode = true;
13
+
14
+ }
15
+
16
+ generate( /* builder */ ) {
17
+
18
+ return this.name;
19
+
20
+ }
21
+
22
+ }
23
+
24
+ export default BuiltinNode;
25
+
26
+ export const builtin = nodeProxy( BuiltinNode );
@@ -4,7 +4,6 @@ import { Vector3 } from '../../math/Vector3.js';
4
4
 
5
5
  export const cameraNear = /*@__PURE__*/ uniform( 'float' ).label( 'cameraNear' ).setGroup( renderGroup ).onRenderUpdate( ( { camera } ) => camera.near );
6
6
  export const cameraFar = /*@__PURE__*/ uniform( 'float' ).label( 'cameraFar' ).setGroup( renderGroup ).onRenderUpdate( ( { camera } ) => camera.far );
7
- export const cameraLogDepth = /*@__PURE__*/ uniform( 'float' ).label( 'cameraLogDepth' ).setGroup( renderGroup ).onRenderUpdate( ( { camera } ) => 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
8
7
  export const cameraProjectionMatrix = /*@__PURE__*/ uniform( 'mat4' ).label( 'cameraProjectionMatrix' ).setGroup( renderGroup ).onRenderUpdate( ( { camera } ) => camera.projectionMatrix );
9
8
  export const cameraProjectionMatrixInverse = /*@__PURE__*/ uniform( 'mat4' ).label( 'cameraProjectionMatrixInverse' ).setGroup( renderGroup ).onRenderUpdate( ( { camera } ) => camera.projectionMatrixInverse );
10
9
  export const cameraViewMatrix = /*@__PURE__*/ uniform( 'mat4' ).label( 'cameraViewMatrix' ).setGroup( renderGroup ).onRenderUpdate( ( { camera } ) => camera.matrixWorldInverse );
@@ -1,12 +1,12 @@
1
1
 
2
2
  import Node from '../core/Node.js';
3
- import { nodeObject } from '../tsl/TSLBase.js';
3
+ import { nodeObject, Fn, bool, float } from '../tsl/TSLBase.js';
4
4
  import { positionView } from './Position.js';
5
- import { diffuseColor, property } from '../core/PropertyNode.js';
6
- import { Fn } from '../tsl/TSLBase.js';
5
+ import { diffuseColor } from '../core/PropertyNode.js';
7
6
  import { Loop } from '../utils/LoopNode.js';
8
7
  import { smoothstep } from '../math/MathNode.js';
9
8
  import { uniformArray } from './UniformArrayNode.js';
9
+ import { builtin } from './BuiltinNode.js';
10
10
 
11
11
  class ClippingNode extends Node {
12
12
 
@@ -29,69 +29,73 @@ class ClippingNode extends Node {
29
29
  super.setup( builder );
30
30
 
31
31
  const clippingContext = builder.clippingContext;
32
- const { localClipIntersection, localClippingCount, globalClippingCount } = clippingContext;
32
+ const { intersectionPlanes, unionPlanes } = clippingContext;
33
33
 
34
- const numClippingPlanes = globalClippingCount + localClippingCount;
35
- const numUnionClippingPlanes = localClipIntersection ? numClippingPlanes - localClippingCount : numClippingPlanes;
34
+ this.hardwareClipping = builder.material.hardwareClipping;
36
35
 
37
36
  if ( this.scope === ClippingNode.ALPHA_TO_COVERAGE ) {
38
37
 
39
- return this.setupAlphaToCoverage( clippingContext.planes, numClippingPlanes, numUnionClippingPlanes );
38
+ return this.setupAlphaToCoverage( intersectionPlanes, unionPlanes );
39
+
40
+ } else if ( this.scope === ClippingNode.HARDWARE ) {
41
+
42
+ return this.setupHardwareClipping( unionPlanes, builder );
40
43
 
41
44
  } else {
42
45
 
43
- return this.setupDefault( clippingContext.planes, numClippingPlanes, numUnionClippingPlanes );
46
+ return this.setupDefault( intersectionPlanes, unionPlanes );
44
47
 
45
48
  }
46
49
 
47
50
  }
48
51
 
49
- setupAlphaToCoverage( planes, numClippingPlanes, numUnionClippingPlanes ) {
52
+ setupAlphaToCoverage( intersectionPlanes, unionPlanes ) {
50
53
 
51
54
  return Fn( () => {
52
55
 
53
- const clippingPlanes = uniformArray( planes );
56
+ const distanceToPlane = float().toVar( 'distanceToPlane' );
57
+ const distanceGradient = float().toVar( 'distanceToGradient' );
54
58
 
55
- const distanceToPlane = property( 'float', 'distanceToPlane' );
56
- const distanceGradient = property( 'float', 'distanceToGradient' );
59
+ const clipOpacity = float( 1 ).toVar( 'clipOpacity' );
57
60
 
58
- const clipOpacity = property( 'float', 'clipOpacity' );
61
+ const numUnionPlanes = unionPlanes.length;
59
62
 
60
- clipOpacity.assign( 1 );
63
+ if ( ! this.hardwareClipping && numUnionPlanes > 0 ) {
61
64
 
62
- let plane;
65
+ const clippingPlanes = uniformArray( unionPlanes );
63
66
 
64
- Loop( numUnionClippingPlanes, ( { i } ) => {
67
+ Loop( numUnionPlanes, ( { i } ) => {
65
68
 
66
- plane = clippingPlanes.element( i );
69
+ const plane = clippingPlanes.element( i );
67
70
 
68
- distanceToPlane.assign( positionView.dot( plane.xyz ).negate().add( plane.w ) );
69
- distanceGradient.assign( distanceToPlane.fwidth().div( 2.0 ) );
71
+ distanceToPlane.assign( positionView.dot( plane.xyz ).negate().add( plane.w ) );
72
+ distanceGradient.assign( distanceToPlane.fwidth().div( 2.0 ) );
70
73
 
71
- clipOpacity.mulAssign( smoothstep( distanceGradient.negate(), distanceGradient, distanceToPlane ) );
74
+ clipOpacity.mulAssign( smoothstep( distanceGradient.negate(), distanceGradient, distanceToPlane ) );
72
75
 
73
- clipOpacity.equal( 0.0 ).discard();
76
+ } );
74
77
 
75
- } );
78
+ }
76
79
 
77
- if ( numUnionClippingPlanes < numClippingPlanes ) {
80
+ const numIntersectionPlanes = intersectionPlanes.length;
78
81
 
79
- const unionClipOpacity = property( 'float', 'unionclipOpacity' );
82
+ if ( numIntersectionPlanes > 0 ) {
80
83
 
81
- unionClipOpacity.assign( 1 );
84
+ const clippingPlanes = uniformArray( intersectionPlanes );
85
+ const intersectionClipOpacity = float( 1 ).toVar( 'intersectionClipOpacity' );
82
86
 
83
- Loop( { start: numUnionClippingPlanes, end: numClippingPlanes }, ( { i } ) => {
87
+ Loop( numIntersectionPlanes, ( { i } ) => {
84
88
 
85
- plane = clippingPlanes.element( i );
89
+ const plane = clippingPlanes.element( i );
86
90
 
87
91
  distanceToPlane.assign( positionView.dot( plane.xyz ).negate().add( plane.w ) );
88
92
  distanceGradient.assign( distanceToPlane.fwidth().div( 2.0 ) );
89
93
 
90
- unionClipOpacity.mulAssign( smoothstep( distanceGradient.negate(), distanceGradient, distanceToPlane ).oneMinus() );
94
+ intersectionClipOpacity.mulAssign( smoothstep( distanceGradient.negate(), distanceGradient, distanceToPlane ).oneMinus() );
91
95
 
92
96
  } );
93
97
 
94
- clipOpacity.mulAssign( unionClipOpacity.oneMinus() );
98
+ clipOpacity.mulAssign( intersectionClipOpacity.oneMinus() );
95
99
 
96
100
  }
97
101
 
@@ -103,30 +107,35 @@ class ClippingNode extends Node {
103
107
 
104
108
  }
105
109
 
106
- setupDefault( planes, numClippingPlanes, numUnionClippingPlanes ) {
110
+ setupDefault( intersectionPlanes, unionPlanes ) {
107
111
 
108
112
  return Fn( () => {
109
113
 
110
- const clippingPlanes = uniformArray( planes );
114
+ const numUnionPlanes = unionPlanes.length;
111
115
 
112
- let plane;
116
+ if ( ! this.hardwareClipping && numUnionPlanes > 0 ) {
113
117
 
114
- Loop( numUnionClippingPlanes, ( { i } ) => {
118
+ const clippingPlanes = uniformArray( unionPlanes );
115
119
 
116
- plane = clippingPlanes.element( i );
117
- positionView.dot( plane.xyz ).greaterThan( plane.w ).discard();
120
+ Loop( numUnionPlanes, ( { i } ) => {
118
121
 
119
- } );
122
+ const plane = clippingPlanes.element( i );
123
+ positionView.dot( plane.xyz ).greaterThan( plane.w ).discard();
124
+
125
+ } );
120
126
 
121
- if ( numUnionClippingPlanes < numClippingPlanes ) {
127
+ }
122
128
 
123
- const clipped = property( 'bool', 'clipped' );
129
+ const numIntersectionPlanes = intersectionPlanes.length;
124
130
 
125
- clipped.assign( true );
131
+ if ( numIntersectionPlanes > 0 ) {
126
132
 
127
- Loop( { start: numUnionClippingPlanes, end: numClippingPlanes }, ( { i } ) => {
133
+ const clippingPlanes = uniformArray( intersectionPlanes );
134
+ const clipped = bool( true ).toVar( 'clipped' );
128
135
 
129
- plane = clippingPlanes.element( i );
136
+ Loop( numIntersectionPlanes, ( { i } ) => {
137
+
138
+ const plane = clippingPlanes.element( i );
130
139
  clipped.assign( positionView.dot( plane.xyz ).greaterThan( plane.w ).and( clipped ) );
131
140
 
132
141
  } );
@@ -139,13 +148,38 @@ class ClippingNode extends Node {
139
148
 
140
149
  }
141
150
 
151
+ setupHardwareClipping( unionPlanes, builder ) {
152
+
153
+ const numUnionPlanes = unionPlanes.length;
154
+
155
+ builder.enableHardwareClipping( numUnionPlanes );
156
+
157
+ return Fn( () => {
158
+
159
+ const clippingPlanes = uniformArray( unionPlanes );
160
+ const hw_clip_distances = builtin( builder.getClipDistance() );
161
+
162
+ Loop( numUnionPlanes, ( { i } ) => {
163
+
164
+ const plane = clippingPlanes.element( i );
165
+
166
+ const distance = positionView.dot( plane.xyz ).sub( plane.w ).negate();
167
+ hw_clip_distances.element( i ).assign( distance );
168
+
169
+ } );
170
+
171
+ } )();
172
+
173
+ }
174
+
142
175
  }
143
176
 
144
177
  ClippingNode.ALPHA_TO_COVERAGE = 'alphaToCoverage';
145
178
  ClippingNode.DEFAULT = 'default';
179
+ ClippingNode.HARDWARE = 'hardware';
146
180
 
147
181
  export default ClippingNode;
148
182
 
149
183
  export const clipping = () => nodeObject( new ClippingNode() );
150
-
151
184
  export const clippingAlpha = () => nodeObject( new ClippingNode( ClippingNode.ALPHA_TO_COVERAGE ) );
185
+ export const hardwareClipping = () => nodeObject( new ClippingNode( ClippingNode.HARDWARE ) );
@@ -20,11 +20,13 @@ class InstanceNode extends Node {
20
20
 
21
21
  }
22
22
 
23
- constructor( instanceMesh ) {
23
+ constructor( count, instanceMatrix, instanceColor ) {
24
24
 
25
25
  super( 'void' );
26
26
 
27
- this.instanceMesh = instanceMesh;
27
+ this.count = count;
28
+ this.instanceMatrix = instanceMatrix;
29
+ this.instanceColor = instanceColor;
28
30
 
29
31
  this.instanceMatrixNode = null;
30
32
 
@@ -39,28 +41,25 @@ class InstanceNode extends Node {
39
41
 
40
42
  setup( builder ) {
41
43
 
42
- let instanceMatrixNode = this.instanceMatrixNode;
43
- let instanceColorNode = this.instanceColorNode;
44
+ const { count, instanceMatrix, instanceColor } = this;
44
45
 
45
- const instanceMesh = this.instanceMesh;
46
+ let { instanceMatrixNode, instanceColorNode } = this;
46
47
 
47
48
  if ( instanceMatrixNode === null ) {
48
49
 
49
- const instanceAttribute = instanceMesh.instanceMatrix;
50
-
51
50
  // Both WebGPU and WebGL backends have UBO max limited to 64kb. Matrix count number bigger than 1000 ( 16 * 4 * 1000 = 64kb ) will fallback to attribute.
52
51
 
53
- if ( instanceMesh.count <= 1000 ) {
52
+ if ( count <= 1000 ) {
54
53
 
55
- instanceMatrixNode = buffer( instanceAttribute.array, 'mat4', Math.max( instanceMesh.count, 1 ) ).element( instanceIndex );
54
+ instanceMatrixNode = buffer( instanceMatrix.array, 'mat4', Math.max( count, 1 ) ).element( instanceIndex );
56
55
 
57
56
  } else {
58
57
 
59
- const buffer = new InstancedInterleavedBuffer( instanceAttribute.array, 16, 1 );
58
+ const buffer = new InstancedInterleavedBuffer( instanceMatrix.array, 16, 1 );
60
59
 
61
60
  this.buffer = buffer;
62
61
 
63
- const bufferFn = instanceAttribute.usage === DynamicDrawUsage ? instancedDynamicBufferAttribute : instancedBufferAttribute;
62
+ const bufferFn = instanceMatrix.usage === DynamicDrawUsage ? instancedDynamicBufferAttribute : instancedBufferAttribute;
64
63
 
65
64
  const instanceBuffers = [
66
65
  // F.Signature -> bufferAttribute( array, type, stride, offset )
@@ -78,13 +77,11 @@ class InstanceNode extends Node {
78
77
 
79
78
  }
80
79
 
81
- const instanceColorAttribute = instanceMesh.instanceColor;
82
-
83
- if ( instanceColorAttribute && instanceColorNode === null ) {
80
+ if ( instanceColor && instanceColorNode === null ) {
84
81
 
85
- const buffer = new InstancedBufferAttribute( instanceColorAttribute.array, 3 );
82
+ const buffer = new InstancedBufferAttribute( instanceColor.array, 3 );
86
83
 
87
- const bufferFn = instanceColorAttribute.usage === DynamicDrawUsage ? instancedDynamicBufferAttribute : instancedBufferAttribute;
84
+ const bufferFn = instanceColor.usage === DynamicDrawUsage ? instancedDynamicBufferAttribute : instancedBufferAttribute;
88
85
 
89
86
  this.bufferColor = buffer;
90
87
 
@@ -123,15 +120,15 @@ class InstanceNode extends Node {
123
120
 
124
121
  update( /*frame*/ ) {
125
122
 
126
- if ( this.instanceMesh.instanceMatrix.usage !== DynamicDrawUsage && this.buffer != null && this.instanceMesh.instanceMatrix.version !== this.buffer.version ) {
123
+ if ( this.instanceMatrix.usage !== DynamicDrawUsage && this.buffer != null && this.instanceMatrix.version !== this.buffer.version ) {
127
124
 
128
- this.buffer.version = this.instanceMesh.instanceMatrix.version;
125
+ this.buffer.version = this.instanceMatrix.version;
129
126
 
130
127
  }
131
128
 
132
- if ( this.instanceMesh.instanceColor && this.instanceMesh.instanceColor.usage !== DynamicDrawUsage && this.bufferColor != null && this.instanceMesh.instanceColor.version !== this.bufferColor.version ) {
129
+ if ( this.instanceColor && this.instanceColor.usage !== DynamicDrawUsage && this.bufferColor != null && this.instanceColor.version !== this.bufferColor.version ) {
133
130
 
134
- this.bufferColor.version = this.instanceMesh.instanceColor.version;
131
+ this.bufferColor.version = this.instanceColor.version;
135
132
 
136
133
  }
137
134
 
@@ -0,0 +1,26 @@
1
+ import InstanceNode from './InstanceNode.js';
2
+ import { nodeProxy } from '../tsl/TSLBase.js';
3
+
4
+ class InstancedMeshNode extends InstanceNode {
5
+
6
+ static get type() {
7
+
8
+ return 'InstancedMeshNode';
9
+
10
+ }
11
+
12
+ constructor( instanceMesh ) {
13
+
14
+ const { count, instanceMatrix, instanceColor } = instanceMesh;
15
+
16
+ super( count, instanceMatrix, instanceColor );
17
+
18
+ this.instanceMesh = instanceMesh;
19
+
20
+ }
21
+
22
+ }
23
+
24
+ export default InstancedMeshNode;
25
+
26
+ export const instancedMesh = /*@__PURE__*/ nodeProxy( InstancedMeshNode );
@@ -2,6 +2,7 @@ import { uniform } from '../core/UniformNode.js';
2
2
  import { renderGroup } from '../core/UniformGroupNode.js';
3
3
  import { Vector3 } from '../../math/Vector3.js';
4
4
  import { cameraViewMatrix } from './Camera.js';
5
+ import { positionWorld } from './Position.js';
5
6
 
6
7
  let uniformsLib;
7
8
 
@@ -17,6 +18,37 @@ function getLightData( light ) {
17
18
 
18
19
  }
19
20
 
21
+ export function lightShadowMatrix( light ) {
22
+
23
+ const data = getLightData( light );
24
+
25
+ return data.shadowMatrix || ( data.shadowMatrix = uniform( 'mat4' ).setGroup( renderGroup ).onRenderUpdate( () => {
26
+
27
+ light.shadow.updateMatrices( light );
28
+
29
+ return light.shadow.matrix;
30
+
31
+ } ) );
32
+
33
+ }
34
+
35
+ export function lightProjectionUV( light ) {
36
+
37
+ const data = getLightData( light );
38
+
39
+ if ( data.projectionUV === undefined ) {
40
+
41
+ const spotLightCoord = lightShadowMatrix( light ).mul( positionWorld );
42
+
43
+ data.projectionUV = spotLightCoord.xyz.div( spotLightCoord.w );
44
+
45
+
46
+ }
47
+
48
+ return data.projectionUV;
49
+
50
+ }
51
+
20
52
  export function lightPosition( light ) {
21
53
 
22
54
  const data = getLightData( light );
@@ -1,7 +1,14 @@
1
+ import { UVMapping } from '../../constants.js';
2
+ import { Euler } from '../../math/Euler.js';
3
+ import { Matrix4 } from '../../math/Matrix4.js';
1
4
  import Node from '../core/Node.js';
2
- import { nodeImmutable } from '../tsl/TSLBase.js';
5
+ import { renderGroup } from '../core/UniformGroupNode.js';
6
+ import { nodeImmutable, uniform } from '../tsl/TSLBase.js';
3
7
  import { reference } from './ReferenceNode.js';
4
8
 
9
+ const _e1 = /*@__PURE__*/ new Euler();
10
+ const _m1 = /*@__PURE__*/ new Matrix4();
11
+
5
12
  class SceneNode extends Node {
6
13
 
7
14
  static get type() {
@@ -34,6 +41,31 @@ class SceneNode extends Node {
34
41
 
35
42
  output = reference( 'backgroundIntensity', 'float', scene );
36
43
 
44
+ } else if ( scope === SceneNode.BACKGROUND_ROTATION ) {
45
+
46
+ output = uniform( 'mat4' ).label( 'backgroundRotation' ).setGroup( renderGroup ).onRenderUpdate( () => {
47
+
48
+ const background = scene.background;
49
+
50
+ if ( background !== null && background.isTexture && background.mapping !== UVMapping ) {
51
+
52
+ _e1.copy( scene.backgroundRotation );
53
+
54
+ // accommodate left-handed frame
55
+ _e1.x *= - 1; _e1.y *= - 1; _e1.z *= - 1;
56
+
57
+ _m1.makeRotationFromEuler( _e1 );
58
+
59
+ } else {
60
+
61
+ _m1.identity();
62
+
63
+ }
64
+
65
+ return _m1;
66
+
67
+ } );
68
+
37
69
  } else {
38
70
 
39
71
  console.error( 'THREE.SceneNode: Unknown scope:', scope );
@@ -48,8 +80,10 @@ class SceneNode extends Node {
48
80
 
49
81
  SceneNode.BACKGROUND_BLURRINESS = 'backgroundBlurriness';
50
82
  SceneNode.BACKGROUND_INTENSITY = 'backgroundIntensity';
83
+ SceneNode.BACKGROUND_ROTATION = 'backgroundRotation';
51
84
 
52
85
  export default SceneNode;
53
86
 
54
87
  export const backgroundBlurriness = /*@__PURE__*/ nodeImmutable( SceneNode, SceneNode.BACKGROUND_BLURRINESS );
55
88
  export const backgroundIntensity = /*@__PURE__*/ nodeImmutable( SceneNode, SceneNode.BACKGROUND_INTENSITY );
89
+ export const backgroundRotation = /*@__PURE__*/ nodeImmutable( SceneNode, SceneNode.BACKGROUND_ROTATION );
@@ -2,7 +2,8 @@ import BufferNode from './BufferNode.js';
2
2
  import { bufferAttribute } from './BufferAttributeNode.js';
3
3
  import { nodeObject, varying } from '../tsl/TSLBase.js';
4
4
  import { storageElement } from '../utils/StorageArrayElementNode.js';
5
- import { GPUBufferBindingType } from '../../renderers/webgpu/utils/WebGPUConstants.js';
5
+ import { NodeAccess } from '../core/constants.js';
6
+ import { getTypeFromLength } from '../core/NodeUtils.js';
6
7
 
7
8
  class StorageBufferNode extends BufferNode {
8
9
 
@@ -12,16 +13,23 @@ class StorageBufferNode extends BufferNode {
12
13
 
13
14
  }
14
15
 
15
- constructor( value, bufferType, bufferCount = 0 ) {
16
+ constructor( value, bufferType = null, bufferCount = 0 ) {
17
+
18
+ if ( bufferType === null && ( value.isStorageBufferAttribute || value.isStorageInstancedBufferAttribute ) ) {
19
+
20
+ bufferType = getTypeFromLength( value.itemSize );
21
+ bufferCount = value.count;
22
+
23
+ }
16
24
 
17
25
  super( value, bufferType, bufferCount );
18
26
 
19
27
  this.isStorageBufferNode = true;
20
28
 
21
- this.access = GPUBufferBindingType.Storage;
29
+ this.access = NodeAccess.READ_WRITE;
22
30
  this.isAtomic = false;
31
+ this.isPBO = false;
23
32
 
24
- this.bufferObject = false;
25
33
  this.bufferCount = bufferCount;
26
34
 
27
35
  this._attribute = null;
@@ -66,7 +74,7 @@ class StorageBufferNode extends BufferNode {
66
74
 
67
75
  getInputType( /*builder*/ ) {
68
76
 
69
- return 'storageBuffer';
77
+ return this.value.isIndirectStorageBufferAttribute ? 'indirectStorageBuffer' : 'storageBuffer';
70
78
 
71
79
  }
72
80
 
@@ -76,14 +84,20 @@ class StorageBufferNode extends BufferNode {
76
84
 
77
85
  }
78
86
 
79
- setBufferObject( value ) {
87
+ setPBO( value ) {
80
88
 
81
- this.bufferObject = value;
89
+ this.isPBO = value;
82
90
 
83
91
  return this;
84
92
 
85
93
  }
86
94
 
95
+ getPBO() {
96
+
97
+ return this.isPBO;
98
+
99
+ }
100
+
87
101
  setAccess( value ) {
88
102
 
89
103
  this.access = value;
@@ -94,7 +108,7 @@ class StorageBufferNode extends BufferNode {
94
108
 
95
109
  toReadOnly() {
96
110
 
97
- return this.setAccess( GPUBufferBindingType.ReadOnlyStorage );
111
+ return this.setAccess( NodeAccess.READ_ONLY );
98
112
 
99
113
  }
100
114
 
@@ -112,27 +126,49 @@ class StorageBufferNode extends BufferNode {
112
126
 
113
127
  }
114
128
 
115
- generate( builder ) {
129
+ getAttributeData() {
116
130
 
117
- if ( builder.isAvailable( 'storageBuffer' ) ) {
131
+ if ( this._attribute === null ) {
118
132
 
119
- return super.generate( builder );
133
+ this._attribute = bufferAttribute( this.value );
134
+ this._varying = varying( this._attribute );
120
135
 
121
136
  }
122
137
 
123
- const nodeType = this.getNodeType( builder );
138
+ return {
139
+ attribute: this._attribute,
140
+ varying: this._varying
141
+ };
124
142
 
125
- if ( this._attribute === null ) {
143
+ }
126
144
 
127
- this._attribute = bufferAttribute( this.value );
128
- this._varying = varying( this._attribute );
145
+ getNodeType( builder ) {
146
+
147
+ if ( builder.isAvailable( 'storageBuffer' ) || builder.isAvailable( 'indirectStorageBuffer' ) ) {
148
+
149
+ return super.getNodeType( builder );
129
150
 
130
151
  }
131
152
 
153
+ const { attribute } = this.getAttributeData();
132
154
 
133
- const output = this._varying.build( builder, nodeType );
155
+ return attribute.getNodeType( builder );
134
156
 
135
- builder.registerTransform( output, this._attribute );
157
+ }
158
+
159
+ generate( builder ) {
160
+
161
+ if ( builder.isAvailable( 'storageBuffer' ) || builder.isAvailable( 'indirectStorageBuffer' ) ) {
162
+
163
+ return super.generate( builder );
164
+
165
+ }
166
+
167
+ const { attribute, varying } = this.getAttributeData();
168
+
169
+ const output = varying.build( builder );
170
+
171
+ builder.registerTransform( output, attribute );
136
172
 
137
173
  return output;
138
174
 
@@ -142,6 +178,12 @@ class StorageBufferNode extends BufferNode {
142
178
 
143
179
  export default StorageBufferNode;
144
180
 
145
- // Read-Write Storage
146
181
  export const storage = ( value, type, count ) => nodeObject( new StorageBufferNode( value, type, count ) );
147
- export const storageObject = ( value, type, count ) => nodeObject( new StorageBufferNode( value, type, count ).setBufferObject( true ) );
182
+
183
+ export const storageObject = ( value, type, count ) => { // @deprecated, r171
184
+
185
+ console.warn( 'THREE.TSL: "storageObject()" is deprecated. Use "storage().setPBO( true )" instead.' );
186
+
187
+ return storage( value, type, count ).setPBO( true );
188
+
189
+ };
@@ -1,6 +1,6 @@
1
1
  import TextureNode from './TextureNode.js';
2
2
  import { nodeProxy } from '../tsl/TSLBase.js';
3
- import { GPUStorageTextureAccess } from '../../renderers/webgpu/utils/WebGPUConstants.js';
3
+ import { NodeAccess } from '../core/constants.js';
4
4
 
5
5
  class StorageTextureNode extends TextureNode {
6
6
 
@@ -18,7 +18,7 @@ class StorageTextureNode extends TextureNode {
18
18
 
19
19
  this.isStorageTextureNode = true;
20
20
 
21
- this.access = GPUStorageTextureAccess.WriteOnly;
21
+ this.access = NodeAccess.WRITE_ONLY;
22
22
 
23
23
  }
24
24
 
@@ -62,15 +62,21 @@ class StorageTextureNode extends TextureNode {
62
62
 
63
63
  }
64
64
 
65
+ toReadWrite() {
66
+
67
+ return this.setAccess( NodeAccess.READ_WRITE );
68
+
69
+ }
70
+
65
71
  toReadOnly() {
66
72
 
67
- return this.setAccess( GPUStorageTextureAccess.ReadOnly );
73
+ return this.setAccess( NodeAccess.READ_ONLY );
68
74
 
69
75
  }
70
76
 
71
77
  toWriteOnly() {
72
78
 
73
- return this.setAccess( GPUStorageTextureAccess.WriteOnly );
79
+ return this.setAccess( NodeAccess.WRITE_ONLY );
74
80
 
75
81
  }
76
82
 
@@ -126,7 +126,7 @@ class TextureNode extends UniformNode {
126
126
 
127
127
  const texture = this.value;
128
128
 
129
- if ( builder.isFlipY() && ( texture.isRenderTargetTexture === true || texture.isFramebufferTexture === true || texture.isDepthTexture === true ) ) {
129
+ if ( builder.isFlipY() && ( ( texture.image instanceof ImageBitmap && texture.flipY === true ) || texture.isRenderTargetTexture === true || texture.isFramebufferTexture === true || texture.isDepthTexture === true ) ) {
130
130
 
131
131
  if ( this.sampler ) {
132
132