super-three 0.171.0 → 0.173.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 (455) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/build/three.cjs +594 -427
  4. package/build/three.core.js +515 -81
  5. package/build/three.core.min.js +2 -2
  6. package/build/three.module.js +79 -350
  7. package/build/three.module.min.js +2 -2
  8. package/build/three.tsl.js +20 -7
  9. package/build/three.tsl.min.js +2 -2
  10. package/build/three.webgpu.js +29362 -3427
  11. package/build/three.webgpu.min.js +2 -2
  12. package/build/three.webgpu.nodes.js +29361 -3427
  13. package/build/three.webgpu.nodes.min.js +2 -2
  14. package/examples/jsm/Addons.js +0 -5
  15. package/examples/jsm/animation/CCDIKSolver.js +9 -7
  16. package/examples/jsm/capabilities/WebGPU.js +1 -1
  17. package/examples/jsm/controls/ArcballControls.js +48 -37
  18. package/examples/jsm/controls/OrbitControls.js +5 -4
  19. package/examples/jsm/csm/CSMShadowNode.js +16 -11
  20. package/examples/jsm/curves/NURBSCurve.js +1 -1
  21. package/examples/jsm/curves/NURBSUtils.js +3 -0
  22. package/examples/jsm/effects/OutlineEffect.js +1 -1
  23. package/examples/jsm/exporters/GLTFExporter.js +34 -29
  24. package/examples/jsm/exporters/KTX2Exporter.js +1 -1
  25. package/examples/jsm/exporters/PLYExporter.js +2 -2
  26. package/examples/jsm/geometries/TextGeometry.js +1 -12
  27. package/examples/jsm/helpers/TextureHelperGPU.js +15 -5
  28. package/examples/jsm/helpers/VertexNormalsHelper.js +2 -0
  29. package/examples/jsm/interactive/InteractiveGroup.js +108 -51
  30. package/examples/jsm/libs/demuxer_mp4.js +109 -0
  31. package/examples/jsm/lights/LightProbeGenerator.js +3 -3
  32. package/examples/jsm/lines/webgpu/LineSegments2.js +15 -6
  33. package/examples/jsm/loaders/3MFLoader.js +6 -3
  34. package/examples/jsm/loaders/BVHLoader.js +1 -1
  35. package/examples/jsm/loaders/ColladaLoader.js +5 -5
  36. package/examples/jsm/loaders/DDSLoader.js +42 -0
  37. package/examples/jsm/loaders/GCodeLoader.js +4 -2
  38. package/examples/jsm/loaders/GLTFLoader.js +22 -4
  39. package/examples/jsm/loaders/KTX2Loader.js +6 -1
  40. package/examples/jsm/loaders/KTXLoader.js +4 -4
  41. package/examples/jsm/loaders/LDrawLoader.js +1 -1
  42. package/examples/jsm/loaders/LottieLoader.js +1 -1
  43. package/examples/jsm/loaders/MTLLoader.js +1 -0
  44. package/examples/jsm/loaders/NRRDLoader.js +1 -1
  45. package/examples/jsm/loaders/PLYLoader.js +7 -7
  46. package/examples/jsm/loaders/PVRLoader.js +1 -1
  47. package/examples/jsm/loaders/SVGLoader.js +2 -2
  48. package/examples/jsm/loaders/TDSLoader.js +1 -2
  49. package/examples/jsm/loaders/VRMLLoader.js +7 -7
  50. package/examples/jsm/loaders/lwo/IFFParser.js +4 -4
  51. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +1 -1
  52. package/examples/jsm/materials/MeshGouraudMaterial.js +2 -0
  53. package/examples/jsm/math/ConvexHull.js +1 -1
  54. package/examples/jsm/math/OBB.js +17 -0
  55. package/examples/jsm/misc/GPUComputationRenderer.js +6 -7
  56. package/examples/jsm/misc/ProgressiveLightMap.js +4 -3
  57. package/examples/jsm/misc/ProgressiveLightMapGPU.js +14 -13
  58. package/examples/jsm/misc/Volume.js +27 -17
  59. package/examples/jsm/misc/VolumeSlice.js +7 -5
  60. package/examples/jsm/modifiers/CurveModifier.js +10 -8
  61. package/examples/jsm/modifiers/CurveModifierGPU.js +9 -7
  62. package/examples/jsm/modifiers/SimplifyModifier.js +2 -2
  63. package/examples/jsm/objects/GroundedSkybox.js +4 -4
  64. package/examples/jsm/objects/Sky.js +2 -2
  65. package/examples/jsm/objects/SkyMesh.js +3 -3
  66. package/examples/jsm/objects/Water2.js +1 -1
  67. package/examples/jsm/objects/Water2Mesh.js +2 -2
  68. package/examples/jsm/objects/WaterMesh.js +29 -24
  69. package/examples/jsm/physics/JoltPhysics.js +7 -7
  70. package/examples/jsm/physics/RapierPhysics.js +4 -4
  71. package/examples/jsm/postprocessing/BloomPass.js +2 -2
  72. package/examples/jsm/postprocessing/EffectComposer.js +1 -2
  73. package/examples/jsm/postprocessing/OutlinePass.js +4 -4
  74. package/examples/jsm/postprocessing/OutputPass.js +2 -0
  75. package/examples/jsm/postprocessing/SAOPass.js +1 -2
  76. package/examples/jsm/postprocessing/SMAAPass.js +1 -3
  77. package/examples/jsm/postprocessing/SSAOPass.js +2 -4
  78. package/examples/jsm/postprocessing/SSRPass.js +2 -4
  79. package/examples/jsm/postprocessing/UnrealBloomPass.js +2 -2
  80. package/examples/jsm/renderers/SVGRenderer.js +6 -4
  81. package/examples/jsm/shaders/BokehShader2.js +1 -1
  82. package/examples/jsm/shaders/GodRaysShader.js +3 -3
  83. package/examples/jsm/shaders/OutputShader.js +5 -1
  84. package/examples/jsm/shaders/SobelOperatorShader.js +1 -1
  85. package/examples/jsm/transpiler/GLSLDecoder.js +2 -2
  86. package/examples/jsm/transpiler/TSLEncoder.js +2 -0
  87. package/examples/jsm/tsl/display/AfterImageNode.js +93 -4
  88. package/examples/jsm/tsl/display/AnaglyphPassNode.js +46 -2
  89. package/examples/jsm/tsl/display/AnamorphicNode.js +118 -5
  90. package/examples/jsm/tsl/display/BleachBypass.js +10 -0
  91. package/examples/jsm/tsl/display/BloomNode.js +233 -26
  92. package/examples/jsm/tsl/display/DenoiseNode.js +141 -25
  93. package/examples/jsm/tsl/display/DepthOfFieldNode.js +80 -1
  94. package/examples/jsm/tsl/display/DotScreenNode.js +50 -5
  95. package/examples/jsm/tsl/display/FXAANode.js +52 -3
  96. package/examples/jsm/tsl/display/FilmNode.js +47 -1
  97. package/examples/jsm/tsl/display/GTAONode.js +210 -14
  98. package/examples/jsm/tsl/display/GaussianBlurNode.js +152 -8
  99. package/examples/jsm/tsl/display/LensflareNode.js +131 -13
  100. package/examples/jsm/tsl/display/Lut3DNode.js +55 -1
  101. package/examples/jsm/tsl/display/MotionBlur.js +12 -2
  102. package/examples/jsm/tsl/display/OutlineNode.js +343 -26
  103. package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +36 -2
  104. package/examples/jsm/tsl/display/PixelationPassNode.js +142 -9
  105. package/examples/jsm/tsl/display/RGBShiftNode.js +49 -2
  106. package/examples/jsm/tsl/display/SMAANode.js +187 -46
  107. package/examples/jsm/tsl/display/SSAAPassNode.js +110 -25
  108. package/examples/jsm/tsl/display/SSRNode.js +194 -21
  109. package/examples/jsm/tsl/display/Sepia.js +9 -0
  110. package/examples/jsm/tsl/display/SobelOperatorNode.js +54 -4
  111. package/examples/jsm/tsl/display/StereoCompositePassNode.js +79 -3
  112. package/examples/jsm/tsl/display/StereoPassNode.js +41 -3
  113. package/examples/jsm/tsl/display/TRAAPassNode.js +116 -21
  114. package/examples/jsm/tsl/display/TransitionNode.js +71 -6
  115. package/examples/jsm/tsl/display/hashBlur.js +14 -3
  116. package/examples/jsm/tsl/lighting/TiledLightsNode.js +40 -34
  117. package/examples/jsm/utils/BufferGeometryUtils.js +1 -1
  118. package/examples/jsm/utils/CameraUtils.js +4 -1
  119. package/examples/jsm/utils/GeometryUtils.js +22 -19
  120. package/examples/jsm/utils/SceneUtils.js +2 -2
  121. package/examples/jsm/webxr/XRControllerModelFactory.js +6 -1
  122. package/examples/jsm/webxr/XREstimatedLight.js +1 -1
  123. package/package.json +8 -3
  124. package/src/Three.Core.js +4 -0
  125. package/src/Three.Legacy.js +0 -21
  126. package/src/Three.TSL.js +18 -5
  127. package/src/Three.WebGPU.Nodes.js +2 -2
  128. package/src/Three.WebGPU.js +2 -2
  129. package/src/animation/PropertyBinding.js +2 -2
  130. package/src/cameras/ArrayCamera.js +1 -0
  131. package/src/cameras/PerspectiveCamera.js +18 -2
  132. package/src/constants.js +6 -1
  133. package/src/core/BufferAttribute.js +4 -0
  134. package/src/core/EventDispatcher.js +8 -6
  135. package/src/core/RenderTarget.js +18 -0
  136. package/src/core/RenderTarget3D.js +22 -0
  137. package/src/core/RenderTargetArray.js +22 -0
  138. package/src/extras/Earcut.js +1 -1
  139. package/src/extras/ImageUtils.js +1 -11
  140. package/src/extras/PMREMGenerator.js +20 -0
  141. package/src/extras/TextureUtils.js +6 -0
  142. package/src/helpers/CameraHelper.js +16 -13
  143. package/src/loaders/nodes/NodeLoader.js +59 -0
  144. package/src/loaders/nodes/NodeMaterialLoader.js +45 -0
  145. package/src/loaders/nodes/NodeObjectLoader.js +61 -0
  146. package/src/materials/nodes/Line2NodeMaterial.js +128 -34
  147. package/src/materials/nodes/LineBasicNodeMaterial.js +17 -2
  148. package/src/materials/nodes/LineDashedNodeMaterial.js +78 -5
  149. package/src/materials/nodes/MeshBasicNodeMaterial.js +56 -0
  150. package/src/materials/nodes/MeshLambertNodeMaterial.js +35 -0
  151. package/src/materials/nodes/MeshMatcapNodeMaterial.js +22 -2
  152. package/src/materials/nodes/MeshNormalNodeMaterial.js +21 -2
  153. package/src/materials/nodes/MeshPhongNodeMaterial.js +64 -1
  154. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +269 -0
  155. package/src/materials/nodes/MeshSSSNodeMaterial.js +97 -6
  156. package/src/materials/nodes/MeshStandardNodeMaterial.js +78 -0
  157. package/src/materials/nodes/MeshToonNodeMaterial.js +28 -0
  158. package/src/materials/nodes/NodeMaterial.js +476 -23
  159. package/src/materials/nodes/NodeMaterials.js +0 -1
  160. package/src/materials/nodes/PointsNodeMaterial.js +121 -10
  161. package/src/materials/nodes/ShadowNodeMaterial.js +29 -0
  162. package/src/materials/nodes/SpriteNodeMaterial.js +78 -20
  163. package/src/materials/nodes/VolumeNodeMaterial.js +80 -4
  164. package/src/materials/nodes/manager/NodeMaterialObserver.js +95 -0
  165. package/src/nodes/Nodes.js +5 -6
  166. package/src/nodes/TSL.js +6 -3
  167. package/src/nodes/accessors/AccessorsUtils.js +27 -0
  168. package/src/nodes/accessors/Arrays.js +47 -6
  169. package/src/nodes/accessors/BatchNode.js +42 -6
  170. package/src/nodes/accessors/Bitangent.js +37 -0
  171. package/src/nodes/accessors/BufferAttributeNode.js +178 -5
  172. package/src/nodes/accessors/BufferNode.js +63 -0
  173. package/src/nodes/accessors/BuiltinNode.js +38 -0
  174. package/src/nodes/accessors/Camera.js +113 -3
  175. package/src/nodes/accessors/ClippingNode.js +71 -2
  176. package/src/nodes/accessors/CubeTextureNode.js +64 -0
  177. package/src/nodes/accessors/InstanceNode.js +85 -2
  178. package/src/nodes/accessors/InstancedMeshNode.js +28 -3
  179. package/src/nodes/accessors/Lights.js +50 -1
  180. package/src/nodes/accessors/MaterialNode.js +306 -12
  181. package/src/nodes/accessors/MaterialProperties.js +7 -0
  182. package/src/nodes/accessors/MaterialReferenceNode.js +53 -13
  183. package/src/nodes/accessors/ModelNode.js +100 -5
  184. package/src/nodes/accessors/ModelViewProjectionNode.js +10 -38
  185. package/src/nodes/accessors/MorphNode.js +48 -4
  186. package/src/nodes/accessors/Normal.js +65 -5
  187. package/src/nodes/accessors/Object3DNode.js +101 -1
  188. package/src/nodes/accessors/PointUVNode.js +26 -0
  189. package/src/nodes/accessors/Position.js +56 -7
  190. package/src/nodes/accessors/ReferenceBaseNode.js +186 -0
  191. package/src/nodes/accessors/ReferenceNode.js +201 -2
  192. package/src/nodes/accessors/ReflectVector.js +24 -0
  193. package/src/nodes/accessors/RendererReferenceNode.js +46 -1
  194. package/src/nodes/accessors/SceneNode.js +54 -0
  195. package/src/nodes/accessors/SkinningNode.js +127 -1
  196. package/src/nodes/accessors/StorageBufferNode.js +209 -8
  197. package/src/nodes/accessors/StorageTextureNode.js +118 -0
  198. package/src/nodes/accessors/Tangent.js +38 -2
  199. package/src/nodes/accessors/Texture3DNode.js +91 -7
  200. package/src/nodes/accessors/TextureBicubic.js +12 -2
  201. package/src/nodes/accessors/TextureNode.js +316 -10
  202. package/src/nodes/accessors/TextureSizeNode.js +42 -0
  203. package/src/nodes/accessors/UV.js +10 -1
  204. package/src/nodes/accessors/UniformArrayNode.js +231 -25
  205. package/src/nodes/accessors/UserDataNode.js +46 -0
  206. package/src/nodes/accessors/VelocityNode.js +80 -0
  207. package/src/nodes/accessors/VertexColorNode.js +39 -2
  208. package/src/nodes/code/CodeNode.js +95 -1
  209. package/src/nodes/code/ExpressionNode.js +28 -0
  210. package/src/nodes/code/FunctionCallNode.js +37 -0
  211. package/src/nodes/code/FunctionNode.js +45 -0
  212. package/src/nodes/code/ScriptableNode.js +223 -1
  213. package/src/nodes/code/ScriptableValueNode.js +85 -1
  214. package/src/nodes/core/ArrayNode.js +125 -0
  215. package/src/nodes/core/AssignNode.js +48 -2
  216. package/src/nodes/core/AttributeNode.js +43 -0
  217. package/src/nodes/core/BypassNode.js +47 -2
  218. package/src/nodes/core/CacheNode.js +53 -2
  219. package/src/nodes/core/ConstNode.js +32 -0
  220. package/src/nodes/core/ContextNode.js +65 -0
  221. package/src/nodes/core/IndexNode.js +68 -7
  222. package/src/nodes/core/InputNode.js +48 -0
  223. package/src/nodes/core/LightingModel.js +60 -0
  224. package/src/nodes/core/MRTNode.js +66 -0
  225. package/src/nodes/core/Node.js +350 -12
  226. package/src/nodes/core/NodeAttribute.js +38 -0
  227. package/src/nodes/core/NodeBuilder.js +1166 -26
  228. package/src/nodes/core/NodeCache.js +41 -2
  229. package/src/nodes/core/NodeCode.js +31 -0
  230. package/src/nodes/core/NodeFrame.js +123 -2
  231. package/src/nodes/core/NodeFunction.js +46 -0
  232. package/src/nodes/core/NodeFunctionInput.js +44 -0
  233. package/src/nodes/core/NodeParser.js +11 -0
  234. package/src/nodes/core/NodeUniform.js +52 -0
  235. package/src/nodes/core/NodeUtils.js +152 -1
  236. package/src/nodes/core/NodeVar.js +47 -1
  237. package/src/nodes/core/NodeVarying.js +28 -0
  238. package/src/nodes/core/OutputStructNode.js +51 -10
  239. package/src/nodes/core/ParameterNode.js +28 -0
  240. package/src/nodes/core/PropertyNode.js +232 -0
  241. package/src/nodes/core/StackNode.js +98 -1
  242. package/src/nodes/core/StructNode.js +121 -0
  243. package/src/nodes/core/StructType.js +13 -0
  244. package/src/nodes/core/StructTypeNode.js +105 -6
  245. package/src/nodes/core/TempNode.js +31 -5
  246. package/src/nodes/core/UniformGroupNode.js +82 -7
  247. package/src/nodes/core/UniformNode.js +66 -0
  248. package/src/nodes/core/VarNode.js +146 -7
  249. package/src/nodes/core/VaryingNode.js +100 -3
  250. package/src/nodes/core/constants.js +36 -0
  251. package/src/nodes/display/BlendModes.js +88 -1
  252. package/src/nodes/display/BumpMapNode.js +37 -0
  253. package/src/nodes/display/ColorAdjustment.js +53 -11
  254. package/src/nodes/display/ColorSpaceFunctions.js +16 -0
  255. package/src/nodes/display/ColorSpaceNode.js +82 -0
  256. package/src/nodes/display/FrontFacingNode.js +29 -0
  257. package/src/nodes/display/NormalMapNode.js +43 -0
  258. package/src/nodes/display/PassNode.js +300 -7
  259. package/src/nodes/display/PosterizeNode.js +33 -0
  260. package/src/nodes/display/RenderOutputNode.js +66 -1
  261. package/src/nodes/display/ScreenNode.js +96 -0
  262. package/src/nodes/display/ToneMappingFunctions.js +58 -10
  263. package/src/nodes/display/ToneMappingNode.js +55 -2
  264. package/src/nodes/display/ToonOutlinePassNode.js +73 -0
  265. package/src/nodes/display/ViewportDepthNode.js +122 -8
  266. package/src/nodes/display/ViewportDepthTextureNode.js +23 -0
  267. package/src/nodes/display/ViewportSharedTextureNode.js +23 -0
  268. package/src/nodes/display/ViewportTextureNode.js +57 -0
  269. package/src/nodes/fog/Fog.js +110 -0
  270. package/src/nodes/functions/BasicLightingModel.js +24 -0
  271. package/src/nodes/functions/PhongLightingModel.js +34 -2
  272. package/src/nodes/functions/PhysicalLightingModel.js +167 -8
  273. package/src/nodes/functions/ShadowMaskModel.js +23 -0
  274. package/src/nodes/functions/ToonLightingModel.js +20 -0
  275. package/src/nodes/functions/material/getAlphaHashThreshold.js +1 -3
  276. package/src/nodes/functions/material/getParallaxCorrectNormal.js +16 -1
  277. package/src/nodes/geometry/RangeNode.js +54 -2
  278. package/src/nodes/gpgpu/AtomicFunctionNode.js +174 -2
  279. package/src/nodes/gpgpu/BarrierNode.js +47 -0
  280. package/src/nodes/gpgpu/ComputeBuiltinNode.js +134 -0
  281. package/src/nodes/gpgpu/ComputeNode.js +106 -2
  282. package/src/nodes/gpgpu/WorkgroupInfoNode.js +115 -6
  283. package/src/nodes/lighting/AONode.js +18 -0
  284. package/src/nodes/lighting/AmbientLightNode.js +10 -0
  285. package/src/nodes/lighting/AnalyticLightNode.js +97 -2
  286. package/src/nodes/lighting/BasicEnvironmentNode.js +19 -0
  287. package/src/nodes/lighting/BasicLightMapNode.js +17 -0
  288. package/src/nodes/lighting/DirectionalLightNode.js +10 -0
  289. package/src/nodes/lighting/EnvironmentNode.js +18 -0
  290. package/src/nodes/lighting/HemisphereLightNode.js +31 -0
  291. package/src/nodes/lighting/IESSpotLightNode.js +11 -0
  292. package/src/nodes/lighting/IrradianceNode.js +17 -0
  293. package/src/nodes/lighting/LightProbeNode.js +20 -0
  294. package/src/nodes/lighting/LightUtils.js +12 -0
  295. package/src/nodes/lighting/LightingContextNode.js +48 -0
  296. package/src/nodes/lighting/LightingNode.js +15 -6
  297. package/src/nodes/lighting/LightsNode.js +132 -1
  298. package/src/nodes/lighting/PointLightNode.js +32 -1
  299. package/src/nodes/lighting/PointShadowNode.js +54 -1
  300. package/src/nodes/lighting/RectAreaLightNode.js +44 -6
  301. package/src/nodes/lighting/ShadowBaseNode.js +93 -0
  302. package/src/nodes/lighting/ShadowNode.js +241 -35
  303. package/src/nodes/lighting/SpotLightNode.js +43 -0
  304. package/src/nodes/math/ConditionalNode.js +78 -4
  305. package/src/nodes/math/Hash.js +9 -0
  306. package/src/nodes/math/MathNode.js +627 -11
  307. package/src/nodes/math/MathUtils.js +45 -1
  308. package/src/nodes/math/OperatorNode.js +329 -18
  309. package/src/nodes/math/TriNoise3D.js +18 -7
  310. package/src/nodes/parsers/GLSLNodeFunction.js +16 -0
  311. package/src/nodes/parsers/GLSLNodeParser.js +11 -0
  312. package/src/nodes/pmrem/PMREMNode.js +133 -0
  313. package/src/nodes/pmrem/PMREMUtils.js +2 -2
  314. package/src/nodes/procedural/Checker.js +9 -0
  315. package/src/nodes/shapes/Shapes.js +33 -0
  316. package/src/nodes/tsl/TSLBase.js +3 -2
  317. package/src/nodes/tsl/TSLCore.js +22 -2
  318. package/src/nodes/utils/ArrayElementNode.js +39 -3
  319. package/src/nodes/utils/ConvertNode.js +31 -0
  320. package/src/nodes/utils/CubeMapNode.js +78 -0
  321. package/src/nodes/utils/Discard.js +16 -0
  322. package/src/nodes/utils/EquirectUVNode.js +31 -1
  323. package/src/nodes/utils/FlipNode.js +38 -0
  324. package/src/nodes/utils/FunctionOverloadingNode.js +53 -1
  325. package/src/nodes/utils/JoinNode.js +25 -0
  326. package/src/nodes/utils/LoopNode.js +82 -2
  327. package/src/nodes/utils/MatcapUVNode.js +17 -0
  328. package/src/nodes/utils/MaxMipLevelNode.js +49 -0
  329. package/src/nodes/utils/MemberNode.js +68 -0
  330. package/src/nodes/utils/Oscillators.js +33 -0
  331. package/src/nodes/utils/Packing.js +17 -0
  332. package/src/nodes/utils/PostProcessingUtils.js +28 -23
  333. package/src/nodes/utils/RTTNode.js +123 -2
  334. package/src/nodes/utils/ReflectorNode.js +174 -4
  335. package/src/nodes/utils/RemapNode.js +79 -0
  336. package/src/nodes/utils/RotateNode.js +41 -0
  337. package/src/nodes/utils/SetNode.js +44 -1
  338. package/src/nodes/utils/SplitNode.js +55 -3
  339. package/src/nodes/utils/SpriteSheetUVNode.js +46 -0
  340. package/src/nodes/utils/SpriteUtils.js +17 -0
  341. package/src/nodes/utils/StorageArrayElementNode.js +54 -0
  342. package/src/nodes/utils/Timer.js +40 -0
  343. package/src/nodes/utils/TriplanarTexturesNode.js +84 -0
  344. package/src/nodes/utils/UVUtils.js +20 -0
  345. package/src/nodes/utils/ViewportUtils.js +13 -0
  346. package/src/objects/BatchedMesh.js +2 -3
  347. package/src/objects/ClippingGroup.js +49 -0
  348. package/src/objects/Line.js +6 -6
  349. package/src/renderers/WebGLRenderer.js +30 -4
  350. package/src/renderers/common/Animation.js +85 -0
  351. package/src/renderers/common/Attributes.js +36 -0
  352. package/src/renderers/common/Backend.js +502 -44
  353. package/src/renderers/common/Background.js +48 -1
  354. package/src/renderers/common/BindGroup.js +43 -0
  355. package/src/renderers/common/Binding.js +35 -0
  356. package/src/renderers/common/Bindings.js +93 -1
  357. package/src/renderers/common/Buffer.js +49 -0
  358. package/src/renderers/common/BufferUtils.js +27 -0
  359. package/src/renderers/common/BundleGroup.js +57 -0
  360. package/src/renderers/common/ChainMap.js +45 -6
  361. package/src/renderers/common/ClippingContext.js +108 -15
  362. package/src/renderers/common/Color4.js +40 -0
  363. package/src/renderers/common/ComputePipeline.js +24 -0
  364. package/src/renderers/common/CubeRenderTarget.js +13 -0
  365. package/src/renderers/common/DataMap.js +37 -1
  366. package/src/renderers/common/Geometries.js +91 -14
  367. package/src/renderers/common/IndirectStorageBufferAttribute.js +25 -2
  368. package/src/renderers/common/Info.js +78 -35
  369. package/src/renderers/common/Lighting.js +34 -6
  370. package/src/renderers/common/Pipeline.js +22 -0
  371. package/src/renderers/common/Pipelines.js +148 -5
  372. package/src/renderers/common/PostProcessing.js +99 -11
  373. package/src/renderers/common/ProgrammableStage.js +60 -2
  374. package/src/renderers/common/QuadMesh.js +54 -5
  375. package/src/renderers/common/RenderBundle.js +14 -8
  376. package/src/renderers/common/RenderBundles.js +39 -10
  377. package/src/renderers/common/RenderContext.js +201 -2
  378. package/src/renderers/common/RenderContexts.js +59 -6
  379. package/src/renderers/common/RenderList.js +178 -0
  380. package/src/renderers/common/RenderLists.js +40 -3
  381. package/src/renderers/common/RenderObject.js +400 -17
  382. package/src/renderers/common/RenderObjects.js +103 -7
  383. package/src/renderers/common/RenderPipeline.js +24 -0
  384. package/src/renderers/common/Renderer.js +1170 -86
  385. package/src/renderers/common/RendererUtils.js +193 -0
  386. package/src/renderers/common/SampledTexture.js +120 -0
  387. package/src/renderers/common/Sampler.js +30 -0
  388. package/src/renderers/common/StorageBuffer.js +24 -0
  389. package/src/renderers/common/StorageBufferAttribute.js +31 -2
  390. package/src/renderers/common/StorageInstancedBufferAttribute.js +31 -2
  391. package/src/renderers/common/StorageTexture.js +38 -0
  392. package/src/renderers/common/Textures.js +97 -7
  393. package/src/renderers/common/TimestampQueryPool.js +39 -0
  394. package/src/renderers/common/Uniform.js +225 -3
  395. package/src/renderers/common/UniformBuffer.js +19 -0
  396. package/src/renderers/common/UniformsGroup.js +141 -2
  397. package/src/renderers/common/XRManager.js +1193 -0
  398. package/src/renderers/common/XRRenderTarget.js +74 -0
  399. package/src/renderers/common/extras/PMREMGenerator.js +76 -10
  400. package/src/renderers/common/nodes/NodeBuilderState.js +99 -5
  401. package/src/renderers/common/nodes/NodeLibrary.js +89 -0
  402. package/src/renderers/common/nodes/NodeSampledTexture.js +90 -2
  403. package/src/renderers/common/nodes/NodeSampler.js +28 -0
  404. package/src/renderers/common/nodes/NodeStorageBuffer.js +35 -0
  405. package/src/renderers/common/nodes/NodeUniform.js +243 -2
  406. package/src/renderers/common/nodes/NodeUniformBuffer.js +29 -0
  407. package/src/renderers/common/nodes/NodeUniformsGroup.js +31 -18
  408. package/src/renderers/common/nodes/Nodes.js +352 -78
  409. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +2 -2
  410. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +7 -7
  411. package/src/renderers/webgl/WebGLBackground.js +4 -0
  412. package/src/renderers/webgl-fallback/WebGLBackend.js +819 -116
  413. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +347 -18
  414. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +58 -1
  415. package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +28 -0
  416. package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +45 -0
  417. package/src/renderers/webgl-fallback/utils/WebGLState.js +323 -11
  418. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +168 -22
  419. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +359 -0
  420. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +43 -0
  421. package/src/renderers/webgpu/WebGPUBackend.js +578 -164
  422. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +36 -0
  423. package/src/renderers/webgpu/WebGPURenderer.js +36 -0
  424. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +20 -8
  425. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +21 -8
  426. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +674 -52
  427. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +17 -0
  428. package/src/renderers/webgpu/nodes/WGSLNodeParser.js +11 -0
  429. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +95 -14
  430. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +94 -1
  431. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +102 -3
  432. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +98 -1
  433. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +262 -18
  434. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +274 -0
  435. package/src/renderers/webgpu/utils/WebGPUUtils.js +116 -4
  436. package/src/renderers/webxr/WebXRDepthSensing.js +1 -1
  437. package/src/renderers/webxr/WebXRManager.js +19 -2
  438. package/src/textures/Data3DTexture.js +2 -2
  439. package/src/textures/Texture.js +4 -0
  440. package/src/textures/VideoFrameTexture.js +35 -0
  441. package/examples/jsm/animation/MMDAnimationHelper.js +0 -1209
  442. package/examples/jsm/animation/MMDPhysics.js +0 -1408
  443. package/examples/jsm/exporters/MMDExporter.js +0 -223
  444. package/examples/jsm/geometries/InstancedPointsGeometry.js +0 -176
  445. package/examples/jsm/libs/mmdparser.module.js +0 -11530
  446. package/examples/jsm/loaders/MMDLoader.js +0 -2298
  447. package/examples/jsm/objects/InstancedPoints.js +0 -19
  448. package/examples/jsm/shaders/MMDToonShader.js +0 -134
  449. package/src/materials/nodes/InstancedPointsNodeMaterial.js +0 -156
  450. package/src/nodes/accessors/InstancedPointsMaterialNode.js +0 -24
  451. package/src/nodes/core/UniformGroup.js +0 -13
  452. package/src/nodes/fog/FogExp2Node.js +0 -35
  453. package/src/nodes/fog/FogNode.js +0 -50
  454. package/src/nodes/fog/FogRangeNode.js +0 -36
  455. package/src/renderers/common/PostProcessingUtils.js +0 -86
@@ -1,5 +1,4 @@
1
- import Node from '../core/Node.js';
2
- import { NodeUpdateType } from '../core/constants.js';
1
+ import ShadowBaseNode, { shadowPositionWorld } from './ShadowBaseNode.js';
3
2
  import { float, vec2, vec3, vec4, If, int, Fn, nodeObject } from '../tsl/TSLBase.js';
4
3
  import { reference } from '../accessors/ReferenceNode.js';
5
4
  import { texture } from '../accessors/TextureNode.js';
@@ -12,15 +11,17 @@ import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
12
11
  import QuadMesh from '../../renderers/common/QuadMesh.js';
13
12
  import { Loop } from '../utils/LoopNode.js';
14
13
  import { screenCoordinate } from '../display/ScreenNode.js';
15
- import { HalfFloatType, LessCompare, NoBlending, RGFormat, VSMShadowMap, WebGPUCoordinateSystem } from '../../constants.js';
14
+ import { HalfFloatType, LessCompare, RGFormat, VSMShadowMap, WebGPUCoordinateSystem } from '../../constants.js';
16
15
  import { renderGroup } from '../core/UniformGroupNode.js';
17
16
  import { viewZToLogarithmicDepth } from '../display/ViewportDepthNode.js';
18
17
  import { objectPosition } from '../accessors/Object3DNode.js';
19
18
  import { lightShadowMatrix } from '../accessors/Lights.js';
19
+ import { resetRendererAndSceneState, restoreRendererAndSceneState } from '../../renderers/common/RendererUtils.js';
20
+ import { getDataFromObject } from '../core/NodeUtils.js';
20
21
 
21
- const shadowMaterialLib = /*@__PURE__*/ new WeakMap();
22
- const shadowWorldPosition = /*@__PURE__*/ vec3().toVar( 'shadowWorldPosition' );
22
+ /** @module ShadowNode **/
23
23
 
24
+ const shadowMaterialLib = /*@__PURE__*/ new WeakMap();
24
25
  const linearDistance = /*@__PURE__*/ Fn( ( [ position, cameraNear, cameraFar ] ) => {
25
26
 
26
27
  let dist = positionWorld.sub( position ).length();
@@ -55,9 +56,9 @@ const getShadowMaterial = ( light ) => {
55
56
  material = new NodeMaterial();
56
57
  material.colorNode = vec4( 0, 0, 0, 1 );
57
58
  material.depthNode = depthNode;
58
- material.isShadowNodeMaterial = true; // Use to avoid other overrideMaterial override material.colorNode unintentionally when using material.shadowNode
59
- material.blending = NoBlending;
59
+ material.isShadowPassMaterial = true; // Use to avoid other overrideMaterial override material.colorNode unintentionally when using material.shadowNode
60
60
  material.name = 'ShadowMaterial';
61
+ material.fog = false;
61
62
 
62
63
  shadowMaterialLib.set( light, material );
63
64
 
@@ -67,12 +68,32 @@ const getShadowMaterial = ( light ) => {
67
68
 
68
69
  };
69
70
 
71
+ /**
72
+ * A shadow filtering function performing basic filtering. This is in fact an unfiltered version of the shadow map
73
+ * with a binary `[0,1]` result.
74
+ *
75
+ * @method
76
+ * @param {Object} inputs - The input parameter object.
77
+ * @param {DepthTexture} inputs.depthTexture - A reference to the shadow map's texture data.
78
+ * @param {Node<vec3>} inputs.shadowCoord - The shadow coordinates.
79
+ * @return {Node<float>} The filtering result.
80
+ */
70
81
  export const BasicShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, shadowCoord } ) => {
71
82
 
72
83
  return texture( depthTexture, shadowCoord.xy ).compare( shadowCoord.z );
73
84
 
74
85
  } );
75
86
 
87
+ /**
88
+ * A shadow filtering function performing PCF filtering.
89
+ *
90
+ * @method
91
+ * @param {Object} inputs - The input parameter object.
92
+ * @param {DepthTexture} inputs.depthTexture - A reference to the shadow map's texture data.
93
+ * @param {Node<vec3>} inputs.shadowCoord - The shadow coordinates.
94
+ * @param {LightShadow} inputs.shadow - The light shadow.
95
+ * @return {Node<float>} The filtering result.
96
+ */
76
97
  export const PCFShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, shadowCoord, shadow } ) => {
77
98
 
78
99
  const depthCompare = ( uv, compare ) => texture( depthTexture, uv ).compare( compare );
@@ -112,6 +133,16 @@ export const PCFShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, shadowCoord,
112
133
 
113
134
  } );
114
135
 
136
+ /**
137
+ * A shadow filtering function performing PCF soft filtering.
138
+ *
139
+ * @method
140
+ * @param {Object} inputs - The input parameter object.
141
+ * @param {DepthTexture} inputs.depthTexture - A reference to the shadow map's texture data.
142
+ * @param {Node<vec3>} inputs.shadowCoord - The shadow coordinates.
143
+ * @param {LightShadow} inputs.shadow - The light shadow.
144
+ * @return {Node<float>} The filtering result.
145
+ */
115
146
  export const PCFSoftShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, shadowCoord, shadow } ) => {
116
147
 
117
148
  const depthCompare = ( uv, compare ) => texture( depthTexture, uv ).compare( compare );
@@ -168,13 +199,20 @@ export const PCFSoftShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, shadowCoo
168
199
 
169
200
  } );
170
201
 
171
- // VSM
172
-
202
+ /**
203
+ * A shadow filtering function performing VSM filtering.
204
+ *
205
+ * @method
206
+ * @param {Object} inputs - The input parameter object.
207
+ * @param {DepthTexture} inputs.depthTexture - A reference to the shadow map's texture data.
208
+ * @param {Node<vec3>} inputs.shadowCoord - The shadow coordinates.
209
+ * @return {Node<float>} The filtering result.
210
+ */
173
211
  export const VSMShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, shadowCoord } ) => {
174
212
 
175
213
  const occlusion = float( 1 ).toVar();
176
214
 
177
- const distribution = texture( depthTexture ).uv( shadowCoord.xy ).rg;
215
+ const distribution = texture( depthTexture ).sample( shadowCoord.xy ).rg;
178
216
 
179
217
  const hardShadow = step( shadowCoord.z, distribution.x );
180
218
 
@@ -192,6 +230,17 @@ export const VSMShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, shadowCoord }
192
230
 
193
231
  } );
194
232
 
233
+ /**
234
+ * Represents the shader code for the first VSM render pass.
235
+ *
236
+ * @method
237
+ * @param {Object} inputs - The input parameter object.
238
+ * @param {Node<float>} inputs.samples - The number of samples
239
+ * @param {Node<float>} inputs.radius - The radius.
240
+ * @param {Node<float>} inputs.size - The size.
241
+ * @param {TextureNode} inputs.shadowPass - A reference to the render target's depth data.
242
+ * @return {Node<vec2>} The VSM output.
243
+ */
195
244
  const VSMPassVertical = /*@__PURE__*/ Fn( ( { samples, radius, size, shadowPass } ) => {
196
245
 
197
246
  const mean = float( 0 ).toVar();
@@ -204,7 +253,7 @@ const VSMPassVertical = /*@__PURE__*/ Fn( ( { samples, radius, size, shadowPass
204
253
 
205
254
  const uvOffset = uvStart.add( float( i ).mul( uvStride ) );
206
255
 
207
- const depth = shadowPass.uv( add( screenCoordinate.xy, vec2( 0, uvOffset ).mul( radius ) ).div( size ) ).x;
256
+ const depth = shadowPass.sample( add( screenCoordinate.xy, vec2( 0, uvOffset ).mul( radius ) ).div( size ) ).x;
208
257
  mean.addAssign( depth );
209
258
  squaredMean.addAssign( depth.mul( depth ) );
210
259
 
@@ -218,6 +267,17 @@ const VSMPassVertical = /*@__PURE__*/ Fn( ( { samples, radius, size, shadowPass
218
267
 
219
268
  } );
220
269
 
270
+ /**
271
+ * Represents the shader code for the second VSM render pass.
272
+ *
273
+ * @method
274
+ * @param {Object} inputs - The input parameter object.
275
+ * @param {Node<float>} inputs.samples - The number of samples
276
+ * @param {Node<float>} inputs.radius - The radius.
277
+ * @param {Node<float>} inputs.size - The size.
278
+ * @param {TextureNode} inputs.shadowPass - The result of the first VSM render pass.
279
+ * @return {Node<vec2>} The VSM output.
280
+ */
221
281
  const VSMPassHorizontal = /*@__PURE__*/ Fn( ( { samples, radius, size, shadowPass } ) => {
222
282
 
223
283
  const mean = float( 0 ).toVar();
@@ -230,7 +290,7 @@ const VSMPassHorizontal = /*@__PURE__*/ Fn( ( { samples, radius, size, shadowPas
230
290
 
231
291
  const uvOffset = uvStart.add( float( i ).mul( uvStride ) );
232
292
 
233
- const distribution = shadowPass.uv( add( screenCoordinate.xy, vec2( uvOffset, 0 ).mul( radius ) ).div( size ) );
293
+ const distribution = shadowPass.sample( add( screenCoordinate.xy, vec2( uvOffset, 0 ).mul( radius ) ).div( size ) );
234
294
  mean.addAssign( distribution.x );
235
295
  squaredMean.addAssign( add( distribution.y.mul( distribution.y ), distribution.x.mul( distribution.x ) ) );
236
296
 
@@ -248,9 +308,15 @@ const _shadowFilterLib = [ BasicShadowFilter, PCFShadowFilter, PCFSoftShadowFilt
248
308
 
249
309
  //
250
310
 
311
+ let _rendererState;
251
312
  const _quadMesh = /*@__PURE__*/ new QuadMesh();
252
313
 
253
- class ShadowNode extends Node {
314
+ /**
315
+ * Represents the default shadow implementation for lighting nodes.
316
+ *
317
+ * @augments module:ShadowBaseNode~ShadowBaseNode
318
+ */
319
+ class ShadowNode extends ShadowBaseNode {
254
320
 
255
321
  static get type() {
256
322
 
@@ -258,28 +324,101 @@ class ShadowNode extends Node {
258
324
 
259
325
  }
260
326
 
327
+ /**
328
+ * Constructs a new shadow node.
329
+ *
330
+ * @param {Light} light - The shadow casting light.
331
+ * @param {LightShadow?} [shadow=null] - An optional light shadow.
332
+ */
261
333
  constructor( light, shadow = null ) {
262
334
 
263
- super();
335
+ super( light );
264
336
 
265
- this.light = light;
337
+ /**
338
+ * The light shadow which defines the properties light's
339
+ * shadow.
340
+ *
341
+ * @type {LightShadow?}
342
+ * @default null
343
+ */
266
344
  this.shadow = shadow || light.shadow;
267
345
 
346
+ /**
347
+ * A reference to the shadow map which is a render target.
348
+ *
349
+ * @type {RenderTarget?}
350
+ * @default null
351
+ */
268
352
  this.shadowMap = null;
269
353
 
354
+ /**
355
+ * Only relevant for VSM shadows. Render target for the
356
+ * first VSM render pass.
357
+ *
358
+ * @type {RenderTarget?}
359
+ * @default null
360
+ */
270
361
  this.vsmShadowMapVertical = null;
362
+
363
+ /**
364
+ * Only relevant for VSM shadows. Render target for the
365
+ * second VSM render pass.
366
+ *
367
+ * @type {RenderTarget?}
368
+ * @default null
369
+ */
271
370
  this.vsmShadowMapHorizontal = null;
272
371
 
372
+ /**
373
+ * Only relevant for VSM shadows. Node material which
374
+ * is used to render the first VSM pass.
375
+ *
376
+ * @type {NodeMaterial?}
377
+ * @default null
378
+ */
273
379
  this.vsmMaterialVertical = null;
380
+
381
+ /**
382
+ * Only relevant for VSM shadows. Node material which
383
+ * is used to render the second VSM pass.
384
+ *
385
+ * @type {NodeMaterial?}
386
+ * @default null
387
+ */
274
388
  this.vsmMaterialHorizontal = null;
275
389
 
276
- this.updateBeforeType = NodeUpdateType.RENDER;
390
+ /**
391
+ * A reference to the output node which defines the
392
+ * final result of this shadow node.
393
+ *
394
+ * @type {Node?}
395
+ * @private
396
+ * @default null
397
+ */
277
398
  this._node = null;
278
399
 
400
+ /**
401
+ * This flag can be used for type testing.
402
+ *
403
+ * @type {Boolean}
404
+ * @readonly
405
+ * @default true
406
+ */
279
407
  this.isShadowNode = true;
280
408
 
281
409
  }
282
410
 
411
+ /**
412
+ * Setups the shadow filtering.
413
+ *
414
+ * @param {NodeBuilder} builder - A reference to the current node builder.
415
+ * @param {Object} inputs - A configuration object that defines the shadow filtering.
416
+ * @param {Function} inputs.filterFn - This function defines the filtering type of the shadow map e.g. PCF.
417
+ * @param {DepthTexture} inputs.depthTexture - A reference to the shadow map's texture data.
418
+ * @param {Node<vec3>} inputs.shadowCoord - Shadow coordinates which are used to sample from the shadow map.
419
+ * @param {LightShadow} inputs.shadow - The light shadow.
420
+ * @return {Node<float>} The result node of the shadow filtering.
421
+ */
283
422
  setupShadowFilter( builder, { filterFn, depthTexture, shadowCoord, shadow } ) {
284
423
 
285
424
  const frustumTest = shadowCoord.x.greaterThanEqual( 0 )
@@ -294,6 +433,13 @@ class ShadowNode extends Node {
294
433
 
295
434
  }
296
435
 
436
+ /**
437
+ * Setups the shadow coordinates.
438
+ *
439
+ * @param {NodeBuilder} builder - A reference to the current node builder.
440
+ * @param {Node<vec3>} shadowPosition - A node representing the shadow position.
441
+ * @return {Node<vec3>} The shadow coordinates.
442
+ */
297
443
  setupShadowCoord( builder, shadowPosition ) {
298
444
 
299
445
  const { shadow } = this;
@@ -341,12 +487,24 @@ class ShadowNode extends Node {
341
487
 
342
488
  }
343
489
 
490
+ /**
491
+ * Returns the shadow filtering function for the given shadow type.
492
+ *
493
+ * @param {Number} type - The shadow type.
494
+ * @return {Function} The filtering function.
495
+ */
344
496
  getShadowFilterFn( type ) {
345
497
 
346
498
  return _shadowFilterLib[ type ];
347
499
 
348
500
  }
349
501
 
502
+ /**
503
+ * Setups the shadow output node.
504
+ *
505
+ * @param {NodeBuilder} builder - A reference to the current node builder.
506
+ * @return {Node<vec3>} The shadow output node.
507
+ */
350
508
  setupShadow( builder ) {
351
509
 
352
510
  const { renderer } = builder;
@@ -394,7 +552,7 @@ class ShadowNode extends Node {
394
552
  const shadowIntensity = reference( 'intensity', 'float', shadow ).setGroup( renderGroup );
395
553
  const normalBias = reference( 'normalBias', 'float', shadow ).setGroup( renderGroup );
396
554
 
397
- const shadowPosition = lightShadowMatrix( light ).mul( shadowWorldPosition.add( transformedNormalWorld.mul( normalBias ) ) );
555
+ const shadowPosition = lightShadowMatrix( light ).mul( shadowPositionWorld.add( transformedNormalWorld.mul( normalBias ) ) );
398
556
  const shadowCoord = this.setupShadowCoord( builder, shadowPosition );
399
557
 
400
558
  //
@@ -421,16 +579,23 @@ class ShadowNode extends Node {
421
579
 
422
580
  }
423
581
 
582
+ /**
583
+ * The implementation performs the setup of the output node. An output is only
584
+ * produces if shadow mapping is globally enabled in the renderer.
585
+ *
586
+ * @param {NodeBuilder} builder - A reference to the current node builder.
587
+ * @return {ShaderCallNodeInternal} The output node.
588
+ */
424
589
  setup( builder ) {
425
590
 
426
591
  if ( builder.renderer.shadowMap.enabled === false ) return;
427
592
 
428
- return Fn( ( { material } ) => {
429
-
430
- shadowWorldPosition.assign( material.shadowPositionNode || positionWorld );
593
+ return Fn( () => {
431
594
 
432
595
  let node = this._node;
433
596
 
597
+ this.setupShadowPosition( builder );
598
+
434
599
  if ( node === null ) {
435
600
 
436
601
  this._node = node = this.setupShadow( builder );
@@ -455,17 +620,32 @@ class ShadowNode extends Node {
455
620
 
456
621
  }
457
622
 
623
+ /**
624
+ * Renders the shadow. The logic of this function could be included
625
+ * into {@link ShadowNode#updateShadow} however more specialized shadow
626
+ * nodes might require a custom shadow map rendering. By having a
627
+ * dedicated method, it's easier to overwrite the default behavior.
628
+ *
629
+ * @param {NodeFrame} frame - A reference to the current node frame.
630
+ */
458
631
  renderShadow( frame ) {
459
632
 
460
- const { shadow, shadowMap } = this;
633
+ const { shadow, shadowMap, light } = this;
461
634
  const { renderer, scene } = frame;
462
635
 
636
+ shadow.updateMatrices( light );
637
+
463
638
  shadowMap.setSize( shadow.mapSize.width, shadow.mapSize.height );
464
639
 
465
640
  renderer.render( scene, shadow.camera );
466
641
 
467
642
  }
468
643
 
644
+ /**
645
+ * Updates the shadow.
646
+ *
647
+ * @param {NodeFrame} frame - A reference to the current node frame.
648
+ */
469
649
  updateShadow( frame ) {
470
650
 
471
651
  const { shadowMap, light, shadow } = this;
@@ -476,23 +656,32 @@ class ShadowNode extends Node {
476
656
  const depthVersion = shadowMap.depthTexture.version;
477
657
  this._depthVersionCached = depthVersion;
478
658
 
479
- const currentOverrideMaterial = scene.overrideMaterial;
480
-
481
- scene.overrideMaterial = getShadowMaterial( light );
482
-
483
659
  shadow.camera.layers.mask = camera.layers.mask;
484
660
 
485
- const currentRenderTarget = renderer.getRenderTarget();
486
661
  const currentRenderObjectFunction = renderer.getRenderObjectFunction();
662
+
487
663
  const currentMRT = renderer.getMRT();
664
+ const useVelocity = currentMRT ? currentMRT.has( 'velocity' ) : false;
665
+
666
+ _rendererState = resetRendererAndSceneState( renderer, scene, _rendererState );
488
667
 
489
- renderer.setMRT( null );
668
+ scene.overrideMaterial = getShadowMaterial( light );
490
669
 
491
- renderer.setRenderObjectFunction( ( object, ...params ) => {
670
+ renderer.setRenderObjectFunction( ( object, scene, _camera, geometry, material, group, ...params ) => {
492
671
 
493
672
  if ( object.castShadow === true || ( object.receiveShadow && shadowType === VSMShadowMap ) ) {
494
673
 
495
- renderer.renderObject( object, ...params );
674
+ if ( useVelocity ) {
675
+
676
+ getDataFromObject( object ).useVelocity = true;
677
+
678
+ }
679
+
680
+ object.onBeforeShadow( renderer, object, camera, shadow.camera, geometry, scene.overrideMaterial, group );
681
+
682
+ renderer.renderObject( object, scene, _camera, geometry, material, group, ...params );
683
+
684
+ object.onAfterShadow( renderer, object, camera, shadow.camera, geometry, scene.overrideMaterial, group );
496
685
 
497
686
  }
498
687
 
@@ -512,14 +701,15 @@ class ShadowNode extends Node {
512
701
 
513
702
  }
514
703
 
515
- renderer.setRenderTarget( currentRenderTarget );
516
-
517
- renderer.setMRT( currentMRT );
518
-
519
- scene.overrideMaterial = currentOverrideMaterial;
704
+ restoreRendererAndSceneState( renderer, scene, _rendererState );
520
705
 
521
706
  }
522
707
 
708
+ /**
709
+ * For VSM additional render passes are required.
710
+ *
711
+ * @param {Renderer} renderer - A reference to the current renderer.
712
+ */
523
713
  vsmPass( renderer ) {
524
714
 
525
715
  const { shadow } = this;
@@ -537,6 +727,9 @@ class ShadowNode extends Node {
537
727
 
538
728
  }
539
729
 
730
+ /**
731
+ * Frees the internal resources of this shadow node.
732
+ */
540
733
  dispose() {
541
734
 
542
735
  this.shadowMap.dispose();
@@ -562,10 +755,15 @@ class ShadowNode extends Node {
562
755
 
563
756
  }
564
757
 
565
- this.updateBeforeType = NodeUpdateType.NONE;
758
+ super.dispose();
566
759
 
567
760
  }
568
761
 
762
+ /**
763
+ * The implementation performs the update of the shadow map if necessary.
764
+ *
765
+ * @param {NodeFrame} frame - A reference to the current node frame.
766
+ */
569
767
  updateBefore( frame ) {
570
768
 
571
769
  const { shadow } = this;
@@ -590,4 +788,12 @@ class ShadowNode extends Node {
590
788
 
591
789
  export default ShadowNode;
592
790
 
791
+ /**
792
+ * TSL function for creating an instance of `ShadowNode`.
793
+ *
794
+ * @function
795
+ * @param {Light} light - The shadow casting light.
796
+ * @param {LightShadow} shadow - The light shadow.
797
+ * @return {ShadowNode} The created shadow node.
798
+ */
593
799
  export const shadow = ( light, shadow ) => nodeObject( new ShadowNode( light, shadow ) );
@@ -7,6 +7,11 @@ import { renderGroup } from '../core/UniformGroupNode.js';
7
7
  import { lightViewPosition, lightTargetDirection, lightProjectionUV } from '../accessors/Lights.js';
8
8
  import { texture } from '../accessors/TextureNode.js';
9
9
 
10
+ /**
11
+ * Module for representing spot lights as nodes.
12
+ *
13
+ * @augments AnalyticLightNode
14
+ */
10
15
  class SpotLightNode extends AnalyticLightNode {
11
16
 
12
17
  static get type() {
@@ -15,18 +20,50 @@ class SpotLightNode extends AnalyticLightNode {
15
20
 
16
21
  }
17
22
 
23
+ /**
24
+ * Constructs a new spot light node.
25
+ *
26
+ * @param {SpotLight?} [light=null] - The spot light source.
27
+ */
18
28
  constructor( light = null ) {
19
29
 
20
30
  super( light );
21
31
 
32
+ /**
33
+ * Uniform node representing the cone cosine.
34
+ *
35
+ * @type {UniformNode<float>}
36
+ */
22
37
  this.coneCosNode = uniform( 0 ).setGroup( renderGroup );
38
+
39
+ /**
40
+ * Uniform node representing the penumbra cosine.
41
+ *
42
+ * @type {UniformNode<float>}
43
+ */
23
44
  this.penumbraCosNode = uniform( 0 ).setGroup( renderGroup );
24
45
 
46
+ /**
47
+ * Uniform node representing the cutoff distance.
48
+ *
49
+ * @type {UniformNode<float>}
50
+ */
25
51
  this.cutoffDistanceNode = uniform( 0 ).setGroup( renderGroup );
52
+
53
+ /**
54
+ * Uniform node representing the decay exponent.
55
+ *
56
+ * @type {UniformNode<float>}
57
+ */
26
58
  this.decayExponentNode = uniform( 0 ).setGroup( renderGroup );
27
59
 
28
60
  }
29
61
 
62
+ /**
63
+ * Overwritten to updated spot light specific uniforms.
64
+ *
65
+ * @param {NodeFrame} frame - A reference to the current node frame.
66
+ */
30
67
  update( frame ) {
31
68
 
32
69
  super.update( frame );
@@ -41,6 +78,12 @@ class SpotLightNode extends AnalyticLightNode {
41
78
 
42
79
  }
43
80
 
81
+ /**
82
+ * Computes the spot attenuation for the given angle.
83
+ *
84
+ * @param {Node<float>} angleCosine - The angle to compute the spot attenuation for.
85
+ * @return {Node<float>} The spot attenuation.
86
+ */
44
87
  getSpotAttenuation( angleCosine ) {
45
88
 
46
89
  const { coneCosNode, penumbraCosNode } = this;
@@ -2,6 +2,21 @@ import Node from '../core/Node.js';
2
2
  import { property } from '../core/PropertyNode.js';
3
3
  import { addMethodChaining, nodeProxy } from '../tsl/TSLCore.js';
4
4
 
5
+ /** @module ConditionalNode **/
6
+
7
+ /**
8
+ * Represents a logical `if/else` statement. Can be used as an alternative
9
+ * to the `If()`/`Else()` syntax.
10
+ *
11
+ * The corresponding TSL `select()` looks like so:
12
+ * ```js
13
+ * velocity = position.greaterThanEqual( limit ).select( velocity.negate(), velocity );
14
+ * ```
15
+ * The `select()` method is called in a chaining fashion on a condition. The parameter nodes of `select()`
16
+ * determine the outcome of the entire statement.
17
+ *
18
+ * @augments Node
19
+ */
5
20
  class ConditionalNode extends Node {
6
21
 
7
22
  static get type() {
@@ -10,24 +25,67 @@ class ConditionalNode extends Node {
10
25
 
11
26
  }
12
27
 
28
+ /**
29
+ * Constructs a new conditional node.
30
+ *
31
+ * @param {Node} condNode - The node that defines the condition.
32
+ * @param {Node} ifNode - The node that is evaluate when the condition ends up `true`.
33
+ * @param {Node?} [elseNode=null] - The node that is evaluate when the condition ends up `false`.
34
+ */
13
35
  constructor( condNode, ifNode, elseNode = null ) {
14
36
 
15
37
  super();
16
38
 
39
+ /**
40
+ * The node that defines the condition.
41
+ *
42
+ * @type {Node}
43
+ */
17
44
  this.condNode = condNode;
18
45
 
46
+ /**
47
+ * The node that is evaluate when the condition ends up `true`.
48
+ *
49
+ * @type {Node}
50
+ */
19
51
  this.ifNode = ifNode;
52
+
53
+ /**
54
+ * The node that is evaluate when the condition ends up `false`.
55
+ *
56
+ * @type {Node?}
57
+ * @default null
58
+ */
20
59
  this.elseNode = elseNode;
21
60
 
22
61
  }
23
62
 
63
+ /**
64
+ * This method is overwritten since the node type is inferred from the if/else
65
+ * nodes.
66
+ *
67
+ * @param {NodeBuilder} builder - The current node builder.
68
+ * @return {String} The node type.
69
+ */
24
70
  getNodeType( builder ) {
25
71
 
26
- const ifType = this.ifNode.getNodeType( builder );
72
+ const { ifNode, elseNode } = builder.getNodeProperties( this );
73
+
74
+ if ( ifNode === undefined ) {
75
+
76
+ // fallback setup
77
+
78
+ this.setup( builder );
79
+
80
+ return this.getNodeType( builder );
27
81
 
28
- if ( this.elseNode !== null ) {
82
+ }
83
+
84
+ const ifType = ifNode.getNodeType( builder );
85
+
86
+ if ( elseNode !== null ) {
29
87
 
30
- const elseType = this.elseNode.getNodeType( builder );
88
+ const elseType = elseNode.getNodeType( builder );
31
89
 
32
90
  if ( builder.getTypeLength( elseType ) > builder.getTypeLength( ifType ) ) {
33
91
 
@@ -140,12 +198,28 @@ class ConditionalNode extends Node {
140
198
 
141
199
  export default ConditionalNode;
142
200
 
201
+ /**
202
+ * TSL function for creating a conditional node.
203
+ *
204
+ * @function
205
+ * @param {Node} condNode - The node that defines the condition.
206
+ * @param {Node} ifNode - The node that is evaluate when the condition ends up `true`.
207
+ * @param {Node?} [elseNode=null] - The node that is evaluate when the condition ends up `false`.
208
+ * @returns {ConditionalNode}
209
+ */
143
210
  export const select = /*@__PURE__*/ nodeProxy( ConditionalNode );
144
211
 
145
212
  addMethodChaining( 'select', select );
146
213
 
147
- //
214
+ // Deprecated
148
215
 
216
+ /**
217
+ * @function
218
+ * @deprecated since r168. Use {@link select} instead.
219
+ *
220
+ * @param {...any} params
221
+ * @returns {ConditionalNode}
222
+ */
149
223
  export const cond = ( ...params ) => { // @deprecated, r168
150
224
 
151
225
  console.warn( 'TSL.ConditionalNode: cond() has been renamed to select().' );
@@ -1,5 +1,14 @@
1
1
  import { Fn } from '../tsl/TSLBase.js';
2
2
 
3
+ /** @module Hash **/
4
+
5
+ /**
6
+ * Generates a hash value in the range `[0, 1]` from the given seed.
7
+ *
8
+ * @method
9
+ * @param {Node<float>} seed - The seed.
10
+ * @return {Node<float>} The hash value.
11
+ */
3
12
  export const hash = /*@__PURE__*/ Fn( ( [ seed ] ) => {
4
13
 
5
14
  // Taken from https://www.shadertoy.com/view/XlGcRh, originally from pcg-random.org