super-three 0.170.1 → 0.172.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 (413) hide show
  1. package/README.md +1 -1
  2. package/build/three.cjs +157 -49
  3. package/build/three.core.js +104 -42
  4. package/build/three.core.min.js +1 -1
  5. package/build/three.module.js +53 -8
  6. package/build/three.module.min.js +1 -1
  7. package/build/three.tsl.js +10 -5
  8. package/build/three.tsl.min.js +1 -1
  9. package/build/three.webgpu.js +21191 -1008
  10. package/build/three.webgpu.min.js +1 -1
  11. package/build/three.webgpu.nodes.js +21189 -1008
  12. package/build/three.webgpu.nodes.min.js +1 -1
  13. package/examples/jsm/Addons.js +0 -5
  14. package/examples/jsm/animation/CCDIKSolver.js +3 -2
  15. package/examples/jsm/controls/ArcballControls.js +28 -19
  16. package/examples/jsm/controls/OrbitControls.js +5 -4
  17. package/examples/jsm/csm/CSMShadowNode.js +16 -11
  18. package/examples/jsm/curves/NURBSCurve.js +1 -1
  19. package/examples/jsm/curves/NURBSUtils.js +3 -0
  20. package/examples/jsm/effects/OutlineEffect.js +1 -1
  21. package/examples/jsm/exporters/GLTFExporter.js +11 -7
  22. package/examples/jsm/exporters/KTX2Exporter.js +1 -1
  23. package/examples/jsm/exporters/PLYExporter.js +2 -2
  24. package/examples/jsm/helpers/TextureHelperGPU.js +15 -5
  25. package/examples/jsm/helpers/VertexNormalsHelper.js +2 -0
  26. package/examples/jsm/lights/LightProbeGenerator.js +3 -3
  27. package/examples/jsm/lines/webgpu/LineSegments2.js +15 -6
  28. package/examples/jsm/loaders/3MFLoader.js +6 -3
  29. package/examples/jsm/loaders/BVHLoader.js +1 -1
  30. package/examples/jsm/loaders/ColladaLoader.js +5 -5
  31. package/examples/jsm/loaders/DDSLoader.js +42 -0
  32. package/examples/jsm/loaders/GCodeLoader.js +1 -1
  33. package/examples/jsm/loaders/GLTFLoader.js +22 -2
  34. package/examples/jsm/loaders/KTX2Loader.js +6 -1
  35. package/examples/jsm/loaders/KTXLoader.js +4 -4
  36. package/examples/jsm/loaders/LDrawLoader.js +1 -1
  37. package/examples/jsm/loaders/LottieLoader.js +1 -1
  38. package/examples/jsm/loaders/MTLLoader.js +1 -0
  39. package/examples/jsm/loaders/NRRDLoader.js +1 -1
  40. package/examples/jsm/loaders/PLYLoader.js +7 -7
  41. package/examples/jsm/loaders/PVRLoader.js +1 -1
  42. package/examples/jsm/loaders/SVGLoader.js +2 -2
  43. package/examples/jsm/loaders/TDSLoader.js +1 -1
  44. package/examples/jsm/loaders/VRMLLoader.js +7 -7
  45. package/examples/jsm/loaders/lwo/IFFParser.js +4 -4
  46. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +1 -1
  47. package/examples/jsm/math/ConvexHull.js +1 -1
  48. package/examples/jsm/math/OBB.js +17 -0
  49. package/examples/jsm/misc/ProgressiveLightMapGPU.js +10 -10
  50. package/examples/jsm/misc/Volume.js +20 -12
  51. package/examples/jsm/misc/VolumeSlice.js +2 -2
  52. package/examples/jsm/modifiers/CurveModifier.js +10 -8
  53. package/examples/jsm/modifiers/CurveModifierGPU.js +9 -7
  54. package/examples/jsm/modifiers/SimplifyModifier.js +2 -2
  55. package/examples/jsm/objects/GroundedSkybox.js +4 -4
  56. package/examples/jsm/objects/Sky.js +2 -2
  57. package/examples/jsm/objects/SkyMesh.js +3 -3
  58. package/examples/jsm/objects/Water2.js +1 -1
  59. package/examples/jsm/objects/Water2Mesh.js +2 -2
  60. package/examples/jsm/objects/WaterMesh.js +4 -4
  61. package/examples/jsm/postprocessing/BloomPass.js +2 -2
  62. package/examples/jsm/postprocessing/EffectComposer.js +1 -2
  63. package/examples/jsm/postprocessing/OutlinePass.js +4 -4
  64. package/examples/jsm/postprocessing/SAOPass.js +1 -2
  65. package/examples/jsm/postprocessing/SMAAPass.js +1 -3
  66. package/examples/jsm/postprocessing/SSAOPass.js +2 -4
  67. package/examples/jsm/postprocessing/SSRPass.js +2 -4
  68. package/examples/jsm/postprocessing/UnrealBloomPass.js +2 -2
  69. package/examples/jsm/renderers/SVGRenderer.js +6 -4
  70. package/examples/jsm/shaders/BokehShader2.js +1 -1
  71. package/examples/jsm/shaders/GodRaysShader.js +3 -3
  72. package/examples/jsm/shaders/SobelOperatorShader.js +1 -1
  73. package/examples/jsm/tsl/display/AfterImageNode.js +93 -4
  74. package/examples/jsm/tsl/display/AnaglyphPassNode.js +46 -2
  75. package/examples/jsm/tsl/display/AnamorphicNode.js +118 -5
  76. package/examples/jsm/tsl/display/BleachBypass.js +10 -0
  77. package/examples/jsm/tsl/display/BloomNode.js +233 -26
  78. package/examples/jsm/tsl/display/DenoiseNode.js +141 -25
  79. package/examples/jsm/tsl/display/DepthOfFieldNode.js +80 -1
  80. package/examples/jsm/tsl/display/DotScreenNode.js +50 -5
  81. package/examples/jsm/tsl/display/FXAANode.js +52 -3
  82. package/examples/jsm/tsl/display/FilmNode.js +47 -1
  83. package/examples/jsm/tsl/display/GTAONode.js +210 -14
  84. package/examples/jsm/tsl/display/GaussianBlurNode.js +152 -8
  85. package/examples/jsm/tsl/display/LensflareNode.js +131 -13
  86. package/examples/jsm/tsl/display/Lut3DNode.js +55 -1
  87. package/examples/jsm/tsl/display/MotionBlur.js +12 -2
  88. package/examples/jsm/tsl/display/OutlineNode.js +343 -26
  89. package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +36 -2
  90. package/examples/jsm/tsl/display/PixelationPassNode.js +142 -9
  91. package/examples/jsm/tsl/display/RGBShiftNode.js +49 -2
  92. package/examples/jsm/tsl/display/SMAANode.js +187 -46
  93. package/examples/jsm/tsl/display/SSAAPassNode.js +110 -25
  94. package/examples/jsm/tsl/display/SSRNode.js +194 -21
  95. package/examples/jsm/tsl/display/Sepia.js +9 -0
  96. package/examples/jsm/tsl/display/SobelOperatorNode.js +54 -4
  97. package/examples/jsm/tsl/display/StereoCompositePassNode.js +79 -3
  98. package/examples/jsm/tsl/display/StereoPassNode.js +41 -3
  99. package/examples/jsm/tsl/display/TRAAPassNode.js +116 -21
  100. package/examples/jsm/tsl/display/TransitionNode.js +71 -6
  101. package/examples/jsm/tsl/display/hashBlur.js +14 -3
  102. package/examples/jsm/tsl/lighting/TiledLightsNode.js +40 -34
  103. package/examples/jsm/utils/BufferGeometryUtils.js +1 -1
  104. package/examples/jsm/utils/CameraUtils.js +4 -1
  105. package/examples/jsm/utils/GeometryUtils.js +22 -19
  106. package/examples/jsm/utils/SceneUtils.js +2 -2
  107. package/examples/jsm/webxr/XRControllerModelFactory.js +6 -1
  108. package/examples/jsm/webxr/XREstimatedLight.js +1 -1
  109. package/package.json +8 -3
  110. package/src/Three.Core.js +2 -0
  111. package/src/Three.Legacy.js +0 -21
  112. package/src/Three.TSL.js +9 -4
  113. package/src/Three.WebGPU.Nodes.js +2 -2
  114. package/src/Three.WebGPU.js +2 -2
  115. package/src/animation/PropertyBinding.js +2 -2
  116. package/src/cameras/PerspectiveCamera.js +18 -2
  117. package/src/constants.js +1 -1
  118. package/src/core/RenderTarget.js +18 -0
  119. package/src/core/RenderTarget3D.js +22 -0
  120. package/src/core/RenderTargetArray.js +22 -0
  121. package/src/extras/Earcut.js +1 -1
  122. package/src/extras/PMREMGenerator.js +20 -0
  123. package/src/extras/TextureUtils.js +6 -0
  124. package/src/helpers/CameraHelper.js +16 -13
  125. package/src/loaders/nodes/NodeLoader.js +59 -0
  126. package/src/loaders/nodes/NodeMaterialLoader.js +45 -0
  127. package/src/loaders/nodes/NodeObjectLoader.js +61 -0
  128. package/src/materials/nodes/InstancedPointsNodeMaterial.js +72 -19
  129. package/src/materials/nodes/Line2NodeMaterial.js +128 -34
  130. package/src/materials/nodes/LineBasicNodeMaterial.js +17 -2
  131. package/src/materials/nodes/LineDashedNodeMaterial.js +78 -5
  132. package/src/materials/nodes/MeshBasicNodeMaterial.js +56 -0
  133. package/src/materials/nodes/MeshLambertNodeMaterial.js +35 -0
  134. package/src/materials/nodes/MeshMatcapNodeMaterial.js +22 -2
  135. package/src/materials/nodes/MeshNormalNodeMaterial.js +21 -2
  136. package/src/materials/nodes/MeshPhongNodeMaterial.js +64 -1
  137. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +269 -0
  138. package/src/materials/nodes/MeshSSSNodeMaterial.js +97 -6
  139. package/src/materials/nodes/MeshStandardNodeMaterial.js +78 -0
  140. package/src/materials/nodes/MeshToonNodeMaterial.js +28 -0
  141. package/src/materials/nodes/NodeMaterial.js +474 -21
  142. package/src/materials/nodes/PointsNodeMaterial.js +22 -13
  143. package/src/materials/nodes/ShadowNodeMaterial.js +29 -0
  144. package/src/materials/nodes/SpriteNodeMaterial.js +77 -19
  145. package/src/materials/nodes/VolumeNodeMaterial.js +80 -4
  146. package/src/materials/nodes/manager/NodeMaterialObserver.js +87 -0
  147. package/src/nodes/Nodes.js +1 -6
  148. package/src/nodes/TSL.js +2 -3
  149. package/src/nodes/accessors/AccessorsUtils.js +27 -0
  150. package/src/nodes/accessors/Arrays.js +24 -5
  151. package/src/nodes/accessors/BatchNode.js +39 -3
  152. package/src/nodes/accessors/Bitangent.js +37 -0
  153. package/src/nodes/accessors/BufferAttributeNode.js +178 -5
  154. package/src/nodes/accessors/BufferNode.js +63 -0
  155. package/src/nodes/accessors/BuiltinNode.js +38 -0
  156. package/src/nodes/accessors/Camera.js +49 -0
  157. package/src/nodes/accessors/ClippingNode.js +71 -2
  158. package/src/nodes/accessors/CubeTextureNode.js +64 -0
  159. package/src/nodes/accessors/InstanceNode.js +85 -2
  160. package/src/nodes/accessors/InstancedMeshNode.js +28 -3
  161. package/src/nodes/accessors/InstancedPointsMaterialNode.js +13 -0
  162. package/src/nodes/accessors/Lights.js +50 -1
  163. package/src/nodes/accessors/MaterialNode.js +302 -8
  164. package/src/nodes/accessors/MaterialProperties.js +7 -0
  165. package/src/nodes/accessors/MaterialReferenceNode.js +53 -13
  166. package/src/nodes/accessors/ModelNode.js +100 -5
  167. package/src/nodes/accessors/ModelViewProjectionNode.js +10 -38
  168. package/src/nodes/accessors/MorphNode.js +48 -4
  169. package/src/nodes/accessors/Normal.js +59 -3
  170. package/src/nodes/accessors/Object3DNode.js +102 -1
  171. package/src/nodes/accessors/PointUVNode.js +26 -0
  172. package/src/nodes/accessors/Position.js +53 -4
  173. package/src/nodes/accessors/ReferenceBaseNode.js +188 -0
  174. package/src/nodes/accessors/ReferenceNode.js +202 -2
  175. package/src/nodes/accessors/ReflectVector.js +24 -0
  176. package/src/nodes/accessors/RendererReferenceNode.js +46 -1
  177. package/src/nodes/accessors/SceneNode.js +54 -0
  178. package/src/nodes/accessors/SkinningNode.js +127 -1
  179. package/src/nodes/accessors/StorageBufferNode.js +168 -4
  180. package/src/nodes/accessors/StorageTextureNode.js +118 -0
  181. package/src/nodes/accessors/Tangent.js +36 -0
  182. package/src/nodes/accessors/Texture3DNode.js +89 -5
  183. package/src/nodes/accessors/TextureBicubic.js +12 -2
  184. package/src/nodes/accessors/TextureNode.js +309 -10
  185. package/src/nodes/accessors/TextureSizeNode.js +42 -0
  186. package/src/nodes/accessors/UV.js +10 -1
  187. package/src/nodes/accessors/UniformArrayNode.js +223 -23
  188. package/src/nodes/accessors/UserDataNode.js +46 -0
  189. package/src/nodes/accessors/VelocityNode.js +82 -0
  190. package/src/nodes/accessors/VertexColorNode.js +39 -2
  191. package/src/nodes/code/CodeNode.js +95 -1
  192. package/src/nodes/code/ExpressionNode.js +28 -0
  193. package/src/nodes/code/FunctionCallNode.js +37 -0
  194. package/src/nodes/code/FunctionNode.js +45 -0
  195. package/src/nodes/code/ScriptableNode.js +223 -1
  196. package/src/nodes/code/ScriptableValueNode.js +85 -1
  197. package/src/nodes/core/AssignNode.js +48 -2
  198. package/src/nodes/core/AttributeNode.js +43 -0
  199. package/src/nodes/core/BypassNode.js +47 -2
  200. package/src/nodes/core/CacheNode.js +53 -2
  201. package/src/nodes/core/ConstNode.js +24 -0
  202. package/src/nodes/core/ContextNode.js +65 -0
  203. package/src/nodes/core/IndexNode.js +68 -7
  204. package/src/nodes/core/InputNode.js +48 -0
  205. package/src/nodes/core/LightingModel.js +60 -0
  206. package/src/nodes/core/MRTNode.js +66 -0
  207. package/src/nodes/core/Node.js +337 -12
  208. package/src/nodes/core/NodeAttribute.js +38 -0
  209. package/src/nodes/core/NodeBuilder.js +945 -15
  210. package/src/nodes/core/NodeCache.js +41 -2
  211. package/src/nodes/core/NodeCode.js +31 -0
  212. package/src/nodes/core/NodeFrame.js +123 -2
  213. package/src/nodes/core/NodeFunction.js +46 -0
  214. package/src/nodes/core/NodeFunctionInput.js +44 -0
  215. package/src/nodes/core/NodeParser.js +11 -0
  216. package/src/nodes/core/NodeUniform.js +52 -0
  217. package/src/nodes/core/NodeUtils.js +141 -0
  218. package/src/nodes/core/NodeVar.js +30 -0
  219. package/src/nodes/core/NodeVarying.js +28 -0
  220. package/src/nodes/core/OutputStructNode.js +33 -2
  221. package/src/nodes/core/ParameterNode.js +28 -0
  222. package/src/nodes/core/PropertyNode.js +232 -0
  223. package/src/nodes/core/StackNode.js +78 -0
  224. package/src/nodes/core/StructTypeNode.js +39 -1
  225. package/src/nodes/core/TempNode.js +30 -4
  226. package/src/nodes/core/UniformGroupNode.js +82 -7
  227. package/src/nodes/core/UniformNode.js +66 -0
  228. package/src/nodes/core/VarNode.js +52 -0
  229. package/src/nodes/core/VaryingNode.js +83 -2
  230. package/src/nodes/core/constants.js +36 -0
  231. package/src/nodes/display/BumpMapNode.js +37 -0
  232. package/src/nodes/display/ColorAdjustment.js +53 -11
  233. package/src/nodes/display/ColorSpaceFunctions.js +16 -0
  234. package/src/nodes/display/ColorSpaceNode.js +82 -0
  235. package/src/nodes/display/FrontFacingNode.js +29 -0
  236. package/src/nodes/display/NormalMapNode.js +43 -0
  237. package/src/nodes/display/PassNode.js +298 -7
  238. package/src/nodes/display/PosterizeNode.js +33 -0
  239. package/src/nodes/display/RenderOutputNode.js +66 -1
  240. package/src/nodes/display/ScreenNode.js +87 -0
  241. package/src/nodes/display/ToneMappingFunctions.js +58 -10
  242. package/src/nodes/display/ToneMappingNode.js +55 -2
  243. package/src/nodes/display/ToonOutlinePassNode.js +73 -0
  244. package/src/nodes/display/ViewportDepthNode.js +122 -8
  245. package/src/nodes/display/ViewportDepthTextureNode.js +23 -0
  246. package/src/nodes/display/ViewportSharedTextureNode.js +23 -0
  247. package/src/nodes/display/ViewportTextureNode.js +57 -0
  248. package/src/nodes/fog/Fog.js +93 -0
  249. package/src/nodes/functions/BasicLightingModel.js +24 -0
  250. package/src/nodes/functions/PhongLightingModel.js +34 -2
  251. package/src/nodes/functions/PhysicalLightingModel.js +167 -8
  252. package/src/nodes/functions/ShadowMaskModel.js +23 -0
  253. package/src/nodes/functions/ToonLightingModel.js +20 -0
  254. package/src/nodes/functions/material/getAlphaHashThreshold.js +1 -3
  255. package/src/nodes/functions/material/getParallaxCorrectNormal.js +16 -1
  256. package/src/nodes/geometry/RangeNode.js +54 -2
  257. package/src/nodes/gpgpu/AtomicFunctionNode.js +157 -1
  258. package/src/nodes/gpgpu/BarrierNode.js +47 -0
  259. package/src/nodes/gpgpu/ComputeBuiltinNode.js +126 -0
  260. package/src/nodes/gpgpu/ComputeNode.js +106 -2
  261. package/src/nodes/gpgpu/WorkgroupInfoNode.js +115 -6
  262. package/src/nodes/lighting/AONode.js +18 -0
  263. package/src/nodes/lighting/AmbientLightNode.js +10 -0
  264. package/src/nodes/lighting/AnalyticLightNode.js +97 -2
  265. package/src/nodes/lighting/BasicEnvironmentNode.js +19 -0
  266. package/src/nodes/lighting/BasicLightMapNode.js +17 -0
  267. package/src/nodes/lighting/DirectionalLightNode.js +10 -0
  268. package/src/nodes/lighting/EnvironmentNode.js +18 -0
  269. package/src/nodes/lighting/HemisphereLightNode.js +31 -0
  270. package/src/nodes/lighting/IESSpotLightNode.js +11 -0
  271. package/src/nodes/lighting/IrradianceNode.js +17 -0
  272. package/src/nodes/lighting/LightProbeNode.js +20 -0
  273. package/src/nodes/lighting/LightUtils.js +12 -0
  274. package/src/nodes/lighting/LightingContextNode.js +48 -0
  275. package/src/nodes/lighting/LightingNode.js +15 -6
  276. package/src/nodes/lighting/LightsNode.js +132 -1
  277. package/src/nodes/lighting/PointLightNode.js +32 -1
  278. package/src/nodes/lighting/PointShadowNode.js +54 -1
  279. package/src/nodes/lighting/RectAreaLightNode.js +44 -6
  280. package/src/nodes/lighting/ShadowBaseNode.js +93 -0
  281. package/src/nodes/lighting/ShadowNode.js +240 -34
  282. package/src/nodes/lighting/SpotLightNode.js +43 -0
  283. package/src/nodes/math/ConditionalNode.js +70 -3
  284. package/src/nodes/math/Hash.js +9 -0
  285. package/src/nodes/math/MathNode.js +614 -11
  286. package/src/nodes/math/MathUtils.js +45 -1
  287. package/src/nodes/math/OperatorNode.js +233 -0
  288. package/src/nodes/math/TriNoise3D.js +18 -7
  289. package/src/nodes/parsers/GLSLNodeFunction.js +16 -0
  290. package/src/nodes/parsers/GLSLNodeParser.js +11 -0
  291. package/src/nodes/pmrem/PMREMNode.js +133 -0
  292. package/src/nodes/pmrem/PMREMUtils.js +1 -1
  293. package/src/nodes/procedural/Checker.js +9 -0
  294. package/src/nodes/tsl/TSLBase.js +2 -2
  295. package/src/nodes/utils/ArrayElementNode.js +38 -2
  296. package/src/nodes/utils/ConvertNode.js +31 -0
  297. package/src/nodes/utils/CubeMapNode.js +78 -0
  298. package/src/nodes/utils/Discard.js +16 -0
  299. package/src/nodes/utils/EquirectUVNode.js +31 -1
  300. package/src/nodes/utils/FlipNode.js +38 -0
  301. package/src/nodes/utils/FunctionOverloadingNode.js +53 -1
  302. package/src/nodes/utils/JoinNode.js +25 -0
  303. package/src/nodes/utils/LoopNode.js +74 -1
  304. package/src/nodes/utils/MatcapUVNode.js +17 -0
  305. package/src/nodes/utils/MaxMipLevelNode.js +49 -0
  306. package/src/nodes/utils/Oscillators.js +33 -0
  307. package/src/nodes/utils/Packing.js +17 -0
  308. package/src/nodes/utils/PostProcessingUtils.js +28 -23
  309. package/src/nodes/utils/RTTNode.js +123 -2
  310. package/src/nodes/utils/ReflectorNode.js +174 -4
  311. package/src/nodes/utils/RemapNode.js +79 -0
  312. package/src/nodes/utils/RotateNode.js +41 -0
  313. package/src/nodes/utils/SetNode.js +44 -1
  314. package/src/nodes/utils/SplitNode.js +55 -3
  315. package/src/nodes/utils/SpriteSheetUVNode.js +46 -0
  316. package/src/nodes/utils/SpriteUtils.js +17 -0
  317. package/src/nodes/utils/StorageArrayElementNode.js +40 -0
  318. package/src/nodes/utils/Timer.js +19 -0
  319. package/src/nodes/utils/TriplanarTexturesNode.js +84 -0
  320. package/src/nodes/utils/UVUtils.js +20 -0
  321. package/src/nodes/utils/ViewportUtils.js +13 -0
  322. package/src/objects/BatchedMesh.js +1 -2
  323. package/src/objects/ClippingGroup.js +49 -0
  324. package/src/renderers/WebGLRenderer.js +23 -4
  325. package/src/renderers/common/Animation.js +63 -0
  326. package/src/renderers/common/Attributes.js +36 -0
  327. package/src/renderers/common/Backend.js +467 -52
  328. package/src/renderers/common/Background.js +34 -1
  329. package/src/renderers/common/BindGroup.js +43 -0
  330. package/src/renderers/common/Binding.js +35 -0
  331. package/src/renderers/common/Bindings.js +93 -1
  332. package/src/renderers/common/Buffer.js +49 -0
  333. package/src/renderers/common/BufferUtils.js +27 -0
  334. package/src/renderers/common/BundleGroup.js +57 -0
  335. package/src/renderers/common/ChainMap.js +38 -1
  336. package/src/renderers/common/ClippingContext.js +107 -14
  337. package/src/renderers/common/Color4.js +36 -0
  338. package/src/renderers/common/ComputePipeline.js +24 -0
  339. package/src/renderers/common/CubeRenderTarget.js +13 -0
  340. package/src/renderers/common/DataMap.js +37 -1
  341. package/src/renderers/common/Geometries.js +98 -0
  342. package/src/renderers/common/IndirectStorageBufferAttribute.js +25 -2
  343. package/src/renderers/common/Info.js +87 -0
  344. package/src/renderers/common/Lighting.js +26 -0
  345. package/src/renderers/common/Pipeline.js +22 -0
  346. package/src/renderers/common/Pipelines.js +148 -5
  347. package/src/renderers/common/PostProcessing.js +75 -3
  348. package/src/renderers/common/ProgrammableStage.js +60 -2
  349. package/src/renderers/common/QuadMesh.js +54 -5
  350. package/src/renderers/common/RenderBundle.js +14 -8
  351. package/src/renderers/common/RenderBundles.js +33 -10
  352. package/src/renderers/common/RenderContext.js +169 -4
  353. package/src/renderers/common/RenderContexts.js +42 -2
  354. package/src/renderers/common/RenderList.js +178 -0
  355. package/src/renderers/common/RenderLists.js +31 -0
  356. package/src/renderers/common/RenderObject.js +328 -4
  357. package/src/renderers/common/RenderObjects.js +101 -7
  358. package/src/renderers/common/RenderPipeline.js +24 -0
  359. package/src/renderers/common/Renderer.js +1096 -31
  360. package/src/renderers/common/RendererUtils.js +193 -0
  361. package/src/renderers/common/SampledTexture.js +121 -0
  362. package/src/renderers/common/Sampler.js +30 -0
  363. package/src/renderers/common/StorageBuffer.js +24 -0
  364. package/src/renderers/common/StorageBufferAttribute.js +31 -2
  365. package/src/renderers/common/StorageInstancedBufferAttribute.js +31 -2
  366. package/src/renderers/common/StorageTexture.js +38 -0
  367. package/src/renderers/common/Textures.js +83 -0
  368. package/src/renderers/common/Uniform.js +188 -2
  369. package/src/renderers/common/UniformBuffer.js +19 -0
  370. package/src/renderers/common/UniformsGroup.js +139 -2
  371. package/src/renderers/common/extras/PMREMGenerator.js +24 -3
  372. package/src/renderers/common/nodes/NodeBuilderState.js +95 -1
  373. package/src/renderers/common/nodes/NodeLibrary.js +89 -0
  374. package/src/renderers/common/nodes/NodeSampledTexture.js +91 -2
  375. package/src/renderers/common/nodes/NodeSampler.js +28 -0
  376. package/src/renderers/common/nodes/NodeStorageBuffer.js +35 -0
  377. package/src/renderers/common/nodes/NodeUniform.js +189 -0
  378. package/src/renderers/common/nodes/NodeUniformBuffer.js +29 -0
  379. package/src/renderers/common/nodes/NodeUniformsGroup.js +31 -18
  380. package/src/renderers/common/nodes/Nodes.js +327 -60
  381. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +2 -2
  382. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +7 -7
  383. package/src/renderers/webgl-fallback/WebGLBackend.js +547 -29
  384. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +0 -1
  385. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +1 -1
  386. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +1 -1
  387. package/src/renderers/webgpu/WebGPUBackend.js +480 -49
  388. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +34 -0
  389. package/src/renderers/webgpu/WebGPURenderer.js +35 -0
  390. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +20 -8
  391. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +21 -8
  392. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +59 -11
  393. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +17 -0
  394. package/src/renderers/webgpu/nodes/WGSLNodeParser.js +11 -0
  395. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +10 -8
  396. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +9 -1
  397. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +5 -9
  398. package/src/renderers/webgpu/utils/WebGPUUtils.js +30 -0
  399. package/src/renderers/webxr/WebXRDepthSensing.js +1 -1
  400. package/src/renderers/webxr/WebXRManager.js +7 -1
  401. package/src/textures/Data3DTexture.js +2 -2
  402. package/src/textures/Texture.js +4 -0
  403. package/examples/jsm/animation/MMDAnimationHelper.js +0 -1209
  404. package/examples/jsm/animation/MMDPhysics.js +0 -1408
  405. package/examples/jsm/exporters/MMDExporter.js +0 -223
  406. package/examples/jsm/libs/mmdparser.module.js +0 -11530
  407. package/examples/jsm/loaders/MMDLoader.js +0 -2298
  408. package/examples/jsm/shaders/MMDToonShader.js +0 -134
  409. package/src/nodes/core/UniformGroup.js +0 -13
  410. package/src/nodes/fog/FogExp2Node.js +0 -35
  411. package/src/nodes/fog/FogNode.js +0 -50
  412. package/src/nodes/fog/FogRangeNode.js +0 -36
  413. package/src/renderers/common/PostProcessingUtils.js +0 -86
@@ -4,7 +4,7 @@ import { NormalBlending } from '../../constants.js';
4
4
  import { getNodeChildren, getCacheKey } from '../../nodes/core/NodeUtils.js';
5
5
  import { attribute } from '../../nodes/core/AttributeNode.js';
6
6
  import { output, diffuseColor, emissive, varyingProperty } from '../../nodes/core/PropertyNode.js';
7
- import { materialAlphaTest, materialColor, materialOpacity, materialEmissive, materialNormal, materialLightMap, materialAOMap } from '../../nodes/accessors/MaterialNode.js';
7
+ import { materialAlphaTest, materialColor, materialOpacity, materialEmissive, materialNormal, materialLightMap, materialAO } from '../../nodes/accessors/MaterialNode.js';
8
8
  import { modelViewProjection } from '../../nodes/accessors/ModelViewProjectionNode.js';
9
9
  import { normalLocal } from '../../nodes/accessors/Normal.js';
10
10
  import { instancedMesh } from '../../nodes/accessors/InstancedMeshNode.js';
@@ -19,11 +19,17 @@ import AONode from '../../nodes/lighting/AONode.js';
19
19
  import { lightingContext } from '../../nodes/lighting/LightingContextNode.js';
20
20
  import IrradianceNode from '../../nodes/lighting/IrradianceNode.js';
21
21
  import { depth, viewZToLogarithmicDepth, viewZToOrthographicDepth } from '../../nodes/display/ViewportDepthNode.js';
22
- import { cameraFar, cameraNear } from '../../nodes/accessors/Camera.js';
22
+ import { cameraFar, cameraNear, cameraProjectionMatrix } from '../../nodes/accessors/Camera.js';
23
23
  import { clipping, clippingAlpha, hardwareClipping } from '../../nodes/accessors/ClippingNode.js';
24
24
  import NodeMaterialObserver from './manager/NodeMaterialObserver.js';
25
25
  import getAlphaHashThreshold from '../../nodes/functions/material/getAlphaHashThreshold.js';
26
+ import { modelViewMatrix } from '../../nodes/accessors/ModelNode.js';
26
27
 
28
+ /**
29
+ * Base class for all node materials.
30
+ *
31
+ * @augments Material
32
+ */
27
33
  class NodeMaterial extends Material {
28
34
 
29
35
  static get type() {
@@ -32,6 +38,11 @@ class NodeMaterial extends Material {
32
38
 
33
39
  }
34
40
 
41
+ /**
42
+ * Represents the type of the node material.
43
+ *
44
+ * @type {String}
45
+ */
35
46
  get type() {
36
47
 
37
48
  return this.constructor.type;
@@ -40,66 +51,364 @@ class NodeMaterial extends Material {
40
51
 
41
52
  set type( _value ) { /* */ }
42
53
 
54
+ /**
55
+ * Constructs a new node material.
56
+ */
43
57
  constructor() {
44
58
 
45
59
  super();
46
60
 
61
+ /**
62
+ * This flag can be used for type testing.
63
+ *
64
+ * @type {Boolean}
65
+ * @readonly
66
+ * @default true
67
+ */
47
68
  this.isNodeMaterial = true;
48
69
 
49
- this.forceSinglePass = false;
50
-
70
+ /**
71
+ * Whether this material is affected by fog or not.
72
+ *
73
+ * @type {Boolean}
74
+ * @default true
75
+ */
51
76
  this.fog = true;
77
+
78
+ /**
79
+ * Whether this material is affected by lights or not.
80
+ *
81
+ * @type {Boolean}
82
+ * @default false
83
+ */
52
84
  this.lights = false;
85
+
86
+ /**
87
+ * Whether this material uses hardware clipping or not.
88
+ * This property is managed by the engine and should not be
89
+ * modified by apps.
90
+ *
91
+ * @type {Boolean}
92
+ * @default false
93
+ */
53
94
  this.hardwareClipping = false;
54
95
 
96
+ /**
97
+ * Node materials which set their `lights` property to `true`
98
+ * are affected by all lights of the scene. Sometimes selective
99
+ * lighting is wanted which means only _some_ lights in the scene
100
+ * affect a material. This can be achieved by creating an instance
101
+ * of {@link module:LightsNode~LightsNode} with a list of selective
102
+ * lights and assign the node to this property.
103
+ *
104
+ * ```js
105
+ * const customLightsNode = lights( [ light1, light2 ] );
106
+ * material.lightsNode = customLightsNode;
107
+ * ```
108
+ *
109
+ * @type {LightsNode?}
110
+ * @default null
111
+ */
55
112
  this.lightsNode = null;
113
+
114
+ /**
115
+ * The environment of node materials can be defined by an environment
116
+ * map assigned to the `envMap` property or by `Scene.environment`
117
+ * if the node material is a PBR material. This node property allows to overwrite
118
+ * the default behavior and define the environment with a custom node.
119
+ *
120
+ * ```js
121
+ * material.envNode = pmremTexture( renderTarget.texture );
122
+ * ```
123
+ *
124
+ * @type {Node<vec3>?}
125
+ * @default null
126
+ */
56
127
  this.envNode = null;
128
+
129
+ /**
130
+ * The lighting of node materials might be influenced by ambient occlusion.
131
+ * The default AO is inferred from an ambient occlusion map assigned to `aoMap`
132
+ * and the respective `aoMapIntensity`. This node property allows to overwrite
133
+ * the default and define the ambient occlusion with a custom node instead.
134
+ *
135
+ * If you don't want to overwrite the diffuse color but modify the existing
136
+ * values instead, use {@link module:MaterialNode.materialAO}.
137
+ *
138
+ * @type {Node<float>?}
139
+ * @default null
140
+ */
57
141
  this.aoNode = null;
58
142
 
143
+ /**
144
+ * The diffuse color of node materials is by default inferred from the
145
+ * `color` and `map` properties. This node property allows to overwrite the default
146
+ * and define the diffuse color with a node instead.
147
+ *
148
+ * ```js
149
+ * material.colorNode = color( 0xff0000 ); // define red color
150
+ * ```
151
+ *
152
+ * If you don't want to overwrite the diffuse color but modify the existing
153
+ * values instead, use {@link module:MaterialNode.materialColor}.
154
+ *
155
+ * ```js
156
+ * material.colorNode = materialColor.mul( color( 0xff0000 ) ); // give diffuse colors a red tint
157
+ * ```
158
+ *
159
+ * @type {Node<vec3>?}
160
+ * @default null
161
+ */
59
162
  this.colorNode = null;
163
+
164
+ /**
165
+ * The normals of node materials are by default inferred from the `normalMap`/`normalScale`
166
+ * or `bumpMap`/`bumpScale` properties. This node property allows to overwrite the default
167
+ * and define the normals with a node instead.
168
+ *
169
+ * If you don't want to overwrite the normals but modify the existing values instead,
170
+ * use {@link module:MaterialNode.materialNormal}.
171
+ *
172
+ * @type {Node<vec3>?}
173
+ * @default null
174
+ */
60
175
  this.normalNode = null;
176
+
177
+ /**
178
+ * The opacity of node materials is by default inferred from the `opacity`
179
+ * and `alphaMap` properties. This node property allows to overwrite the default
180
+ * and define the opacity with a node instead.
181
+ *
182
+ * If you don't want to overwrite the normals but modify the existing
183
+ * value instead, use {@link module:MaterialNode.materialOpacity}.
184
+ *
185
+ * @type {Node<float>?}
186
+ * @default null
187
+ */
61
188
  this.opacityNode = null;
189
+
190
+ /**
191
+ * This node can be used to to implement a variety of filter-like effects. The idea is
192
+ * to store the current rendering into a texture e.g. via `viewportSharedTexture()`, use it
193
+ * to create an arbitrary effect and then assign the node composition to this property.
194
+ * Everything behind the object using this material will now be affected by a filter.
195
+ *
196
+ * ```js
197
+ * const material = new NodeMaterial()
198
+ * material.transparent = true;
199
+ *
200
+ * // everything behind the object will be monochromatic
201
+ * material.backdropNode = viewportSharedTexture().rgb.saturation( 0 );
202
+ * ```
203
+ *
204
+ * Backdrop computations are part of the lighting so only lit materials can use this property.
205
+ *
206
+ * @type {Node<vec3>?}
207
+ * @default null
208
+ */
62
209
  this.backdropNode = null;
210
+
211
+ /**
212
+ * This node allows to modulate the influence of `backdropNode` to the outgoing light.
213
+ *
214
+ * @type {Node<float>?}
215
+ * @default null
216
+ */
63
217
  this.backdropAlphaNode = null;
218
+
219
+ /**
220
+ * The alpha test of node materials is by default inferred from the `alphaTest`
221
+ * property. This node property allows to overwrite the default and define the
222
+ * alpha test with a node instead.
223
+ *
224
+ * If you don't want to overwrite the alpha test but modify the existing
225
+ * value instead, use {@link module:MaterialNode.materialAlphaTest}.
226
+ *
227
+ * @type {Node<float>?}
228
+ * @default null
229
+ */
64
230
  this.alphaTestNode = null;
65
231
 
232
+ /**
233
+ * The local vertex positions are computed based on multiple factors like the
234
+ * attribute data, morphing or skinning. This node property allows to overwrite
235
+ * the default and define local vertex positions with nodes instead.
236
+ *
237
+ * If you don't want to overwrite the vertex positions but modify the existing
238
+ * values instead, use {@link module:Position.positionLocal}.
239
+ *
240
+ *```js
241
+ * material.positionNode = positionLocal.add( displace );
242
+ * ```
243
+ *
244
+ * @type {Node<vec3>?}
245
+ * @default null
246
+ */
66
247
  this.positionNode = null;
248
+
249
+ /**
250
+ * This node property is intended for logic which modifies geometry data once or per animation step.
251
+ * Apps usually place such logic randomly in initialization routines or in the animation loop.
252
+ * `geometryNode` is intended as a dedicated API so there is an intended spot where goemetry modiciations
253
+ * can be implemented.
254
+ *
255
+ * The idea is to assign a `Fn` definition that holds the geometry modification logic. A typical example
256
+ * would be a GPU based particle system that provides a node material for usage on app level. The particle
257
+ * simulation would be implemented as compute shaders and managed inside a `Fn` function. This function is
258
+ * eventually assigned to `geometryNode`.
259
+ *
260
+ * @type {Function}
261
+ * @default null
262
+ */
67
263
  this.geometryNode = null;
68
264
 
265
+ /**
266
+ * Allows to overwrite depth values in the fragment shader.
267
+ *
268
+ * @type {Node<float>?}
269
+ * @default null
270
+ */
69
271
  this.depthNode = null;
272
+
273
+ /**
274
+ * Allows to overwrite the position used for shadow map rendering which
275
+ * is by default {@link module:Position.positionWorld}, the vertex position
276
+ * in world space.
277
+ *
278
+ * @type {Node<float>?}
279
+ * @default null
280
+ */
70
281
  this.shadowPositionNode = null;
282
+
283
+ /**
284
+ * This node can be used to influence how an object using this node material
285
+ * receive shadows.
286
+ *
287
+ * ```js
288
+ * const totalShadows = float( 1 ).toVar();
289
+ * material.receivedShadowNode = Fn( ( [ shadow ] ) => {
290
+ * totalShadows.mulAssign( shadow );
291
+ * //return float( 1 ); // bypass received shadows
292
+ * return shadow.mix( color( 0xff0000 ), 1 ); // modify shadow color
293
+ * } );
294
+ *
295
+ * @type {Node<vec4>?}
296
+ * @default null
297
+ */
71
298
  this.receivedShadowNode = null;
299
+
300
+ /**
301
+ * This node can be used to influence how an object using this node material
302
+ * casts shadows. To apply a color to shadows, you can simply do:
303
+ *
304
+ * ```js
305
+ * material.castShadowNode = vec4( 1, 0, 0, 1 );
306
+ * ```
307
+ *
308
+ * Which can be nice to fake colored shadows of semi-transparent objects. It
309
+ * is also common to use the property with `Fn` function so checks are performed
310
+ * per fragment.
311
+ *
312
+ * ```js
313
+ * materialCustomShadow.castShadowNode = Fn( () => {
314
+ * hash( vertexIndex ).greaterThan( 0.5 ).discard();
315
+ * return materialColor;
316
+ * } )();
317
+ * ```
318
+ *
319
+ * @type {Node<vec4>?}
320
+ * @default null
321
+ */
72
322
  this.castShadowNode = null;
73
323
 
324
+ /**
325
+ * This node can be used to define the final output of the material.
326
+ *
327
+ * TODO: Explain the differences to `fragmentNode`.
328
+ *
329
+ * @type {Node<vec4>?}
330
+ * @default null
331
+ */
74
332
  this.outputNode = null;
333
+
334
+ /**
335
+ * MRT configuration is done on renderer or pass level. This node allows to
336
+ * overwrite what values are written into MRT targets on material level. This
337
+ * can be useful for implementing selective FX features that should only affect
338
+ * specific objects.
339
+ *
340
+ * @type {MRTNode?}
341
+ * @default null
342
+ */
75
343
  this.mrtNode = null;
76
344
 
345
+ /**
346
+ * This node property can be used if you need complete freedom in implementing
347
+ * the fragment shader. Assigning a node will replace the built-in material
348
+ * logic used in the fragment stage.
349
+ *
350
+ * @type {Node<vec4>?}
351
+ * @default null
352
+ */
77
353
  this.fragmentNode = null;
354
+
355
+ /**
356
+ * This node property can be used if you need complete freedom in implementing
357
+ * the vertex shader. Assigning a node will replace the built-in material logic
358
+ * used in the vertex stage.
359
+ *
360
+ * @type {Node<vec4>?}
361
+ * @default null
362
+ */
78
363
  this.vertexNode = null;
79
364
 
80
365
  }
81
366
 
367
+ /**
368
+ * Allows to define a custom cache key that influence the material key computation
369
+ * for render objects.
370
+ *
371
+ * @return {String} The custom cache key.
372
+ */
82
373
  customProgramCacheKey() {
83
374
 
84
375
  return this.type + getCacheKey( this );
85
376
 
86
377
  }
87
378
 
379
+ /**
380
+ * Builds this material with the given node builder.
381
+ *
382
+ * @param {NodeBuilder} builder - The current node builder.
383
+ */
88
384
  build( builder ) {
89
385
 
90
386
  this.setup( builder );
91
387
 
92
388
  }
93
389
 
390
+ /**
391
+ * Setups a node material observer with the given builder.
392
+ *
393
+ * @param {NodeBuilder} builder - The current node builder.
394
+ * @return {NodeMaterialObserver} The node material observer.
395
+ */
94
396
  setupObserver( builder ) {
95
397
 
96
398
  return new NodeMaterialObserver( builder );
97
399
 
98
400
  }
99
401
 
402
+ /**
403
+ * Setups the vertex and fragment stage of this node material.
404
+ *
405
+ * @param {NodeBuilder} builder - The current node builder.
406
+ */
100
407
  setup( builder ) {
101
408
 
102
409
  builder.context.setupNormal = () => this.setupNormal( builder );
410
+ builder.context.setupPositionView = () => this.setupPositionView( builder );
411
+ builder.context.setupModelViewProjection = () => this.setupModelViewProjection( builder );
103
412
 
104
413
  const renderer = builder.renderer;
105
414
  const renderTarget = renderer.getRenderTarget();
@@ -108,7 +417,11 @@ class NodeMaterial extends Material {
108
417
 
109
418
  builder.addStack();
110
419
 
111
- builder.stack.outputNode = this.vertexNode || this.setupPosition( builder );
420
+ const vertexNode = this.vertexNode || this.setupVertex( builder );
421
+
422
+ builder.stack.outputNode = vertexNode;
423
+
424
+ this.setupHardwareClipping( builder );
112
425
 
113
426
  if ( this.geometryNode !== null ) {
114
427
 
@@ -126,7 +439,7 @@ class NodeMaterial extends Material {
126
439
 
127
440
  const clippingNode = this.setupClipping( builder );
128
441
 
129
- if ( this.depthWrite === true ) {
442
+ if ( this.depthWrite === true || this.depthTest === true ) {
130
443
 
131
444
  // only write depth if depth buffer is configured
132
445
 
@@ -214,6 +527,12 @@ class NodeMaterial extends Material {
214
527
 
215
528
  }
216
529
 
530
+ /**
531
+ * Setups the clipping node.
532
+ *
533
+ * @param {NodeBuilder} builder - The current node builder.
534
+ * @return {ClippingNode} The clipping node.
535
+ */
217
536
  setupClipping( builder ) {
218
537
 
219
538
  if ( builder.clippingContext === null ) return null;
@@ -243,6 +562,11 @@ class NodeMaterial extends Material {
243
562
 
244
563
  }
245
564
 
565
+ /**
566
+ * Setups the hardware clipping if available on the current device.
567
+ *
568
+ * @param {NodeBuilder} builder - The current node builder.
569
+ */
246
570
  setupHardwareClipping( builder ) {
247
571
 
248
572
  this.hardwareClipping = false;
@@ -265,6 +589,11 @@ class NodeMaterial extends Material {
265
589
 
266
590
  }
267
591
 
592
+ /**
593
+ * Setups the depth of this material.
594
+ *
595
+ * @param {NodeBuilder} builder - The current node builder.
596
+ */
268
597
  setupDepth( builder ) {
269
598
 
270
599
  const { renderer, camera } = builder;
@@ -305,14 +634,58 @@ class NodeMaterial extends Material {
305
634
 
306
635
  }
307
636
 
308
- setupPosition( builder ) {
637
+ /**
638
+ * Setups the position node in view space. This method exists
639
+ * so derived node materials can modifiy the implementation e.g. sprite materials.
640
+ *
641
+ * @param {NodeBuilder} builder - The current node builder.
642
+ * @return {Node<vec3>} The position in view space.
643
+ */
644
+ setupPositionView( /*builder*/ ) {
645
+
646
+ return modelViewMatrix.mul( positionLocal ).xyz;
647
+
648
+ }
649
+
650
+ /**
651
+ * Setups the position in clip space.
652
+ *
653
+ * @param {NodeBuilder} builder - The current node builder.
654
+ * @return {Node<vec4>} The position in view space.
655
+ */
656
+ setupModelViewProjection( /*builder*/ ) {
657
+
658
+ return cameraProjectionMatrix.mul( positionView );
309
659
 
310
- const { object } = builder;
311
- const geometry = object.geometry;
660
+ }
661
+
662
+ /**
663
+ * Setups the logic for the vertex stage.
664
+ *
665
+ * @param {NodeBuilder} builder - The current node builder.
666
+ * @return {Node<vec4>} The position in clip space.
667
+ */
668
+ setupVertex( builder ) {
312
669
 
313
670
  builder.addStack();
314
671
 
315
- // Vertex
672
+ this.setupPosition( builder );
673
+
674
+ builder.context.vertex = builder.removeStack();
675
+
676
+ return modelViewProjection;
677
+
678
+ }
679
+
680
+ /**
681
+ * Setups the computation of the position in local space.
682
+ *
683
+ * @param {NodeBuilder} builder - The current node builder.
684
+ * @return {Node<vec3>} The position in local space.
685
+ */
686
+ setupPosition( builder ) {
687
+
688
+ const { object, geometry } = builder;
316
689
 
317
690
  if ( geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color ) {
318
691
 
@@ -350,21 +723,20 @@ class NodeMaterial extends Material {
350
723
 
351
724
  if ( this.positionNode !== null ) {
352
725
 
353
- positionLocal.assign( this.positionNode );
726
+ positionLocal.assign( this.positionNode.context( { isPositionNodeInput: true } ) );
354
727
 
355
728
  }
356
729
 
357
- this.setupHardwareClipping( builder );
358
-
359
- const mvp = modelViewProjection();
360
-
361
- builder.context.vertex = builder.removeStack();
362
- builder.context.mvp = mvp;
363
-
364
- return mvp;
730
+ return positionLocal;
365
731
 
366
732
  }
367
733
 
734
+ /**
735
+ * Setups the computation of the material's diffuse color.
736
+ *
737
+ * @param {NodeBuilder} builder - The current node builder.
738
+ * @param {BufferGeometry} geometry - The geometry.
739
+ */
368
740
  setupDiffuseColor( { object, geometry } ) {
369
741
 
370
742
  let colorNode = this.colorNode ? vec4( this.colorNode ) : materialColor;
@@ -431,24 +803,47 @@ class NodeMaterial extends Material {
431
803
 
432
804
  }
433
805
 
806
+ /**
807
+ * Abstract interface method that can be implemented by derived materials
808
+ * to setup material-specific node variables.
809
+ *
810
+ * @abstract
811
+ * @param {NodeBuilder} builder - The current node builder.
812
+ */
434
813
  setupVariants( /*builder*/ ) {
435
814
 
436
815
  // Interface function.
437
816
 
438
817
  }
439
818
 
819
+ /**
820
+ * Setups the outgoing light node variable
821
+ *
822
+ * @return {Node<vec3>} The outgoing light node.
823
+ */
440
824
  setupOutgoingLight() {
441
825
 
442
826
  return ( this.lights === true ) ? vec3( 0 ) : diffuseColor.rgb;
443
827
 
444
828
  }
445
829
 
830
+ /**
831
+ * Setups the normal node from the material.
832
+ *
833
+ * @return {Node<vec3>} The normal node.
834
+ */
446
835
  setupNormal() {
447
836
 
448
837
  return this.normalNode ? vec3( this.normalNode ) : materialNormal;
449
838
 
450
839
  }
451
840
 
841
+ /**
842
+ * Setups the environment node from the material.
843
+ *
844
+ * @param {NodeBuilder} builder - The current node builder.
845
+ * @return {Node<vec4>} The environment node.
846
+ */
452
847
  setupEnvironment( /*builder*/ ) {
453
848
 
454
849
  let node = null;
@@ -467,6 +862,12 @@ class NodeMaterial extends Material {
467
862
 
468
863
  }
469
864
 
865
+ /**
866
+ * Setups the light map node from the material.
867
+ *
868
+ * @param {NodeBuilder} builder - The current node builder.
869
+ * @return {Node<vec3>} The light map node.
870
+ */
470
871
  setupLightMap( builder ) {
471
872
 
472
873
  let node = null;
@@ -481,6 +882,12 @@ class NodeMaterial extends Material {
481
882
 
482
883
  }
483
884
 
885
+ /**
886
+ * Setups the lights node based on the scene, environment and material.
887
+ *
888
+ * @param {NodeBuilder} builder - The current node builder.
889
+ * @return {LightsNode} The lights node.
890
+ */
484
891
  setupLights( builder ) {
485
892
 
486
893
  const materialLightsNode = [];
@@ -505,7 +912,7 @@ class NodeMaterial extends Material {
505
912
 
506
913
  if ( this.aoNode !== null || builder.material.aoMap ) {
507
914
 
508
- const aoNode = this.aoNode !== null ? this.aoNode : materialAOMap;
915
+ const aoNode = this.aoNode !== null ? this.aoNode : materialAO;
509
916
 
510
917
  materialLightsNode.push( new AONode( aoNode ) );
511
918
 
@@ -523,12 +930,26 @@ class NodeMaterial extends Material {
523
930
 
524
931
  }
525
932
 
933
+ /**
934
+ * This method should be implemented by most derived materials
935
+ * since it defines the material's lighting model.
936
+ *
937
+ * @abstract
938
+ * @param {NodeBuilder} builder - The current node builder.
939
+ * @return {LightingModel} The lighting model.
940
+ */
526
941
  setupLightingModel( /*builder*/ ) {
527
942
 
528
943
  // Interface function.
529
944
 
530
945
  }
531
946
 
947
+ /**
948
+ * Setups the outgoing light node.
949
+ *
950
+ * @param {NodeBuilder} builder - The current node builder.
951
+ * @return {Node<vec3>} The outgoing light node.
952
+ */
532
953
  setupLighting( builder ) {
533
954
 
534
955
  const { material } = builder;
@@ -568,6 +989,13 @@ class NodeMaterial extends Material {
568
989
 
569
990
  }
570
991
 
992
+ /**
993
+ * Setups the output node.
994
+ *
995
+ * @param {NodeBuilder} builder - The current node builder.
996
+ * @param {Node<vec4>} outputNode - The existing output node.
997
+ * @return {Node<vec4>} The output node.
998
+ */
571
999
  setupOutput( builder, outputNode ) {
572
1000
 
573
1001
  // FOG
@@ -576,7 +1004,13 @@ class NodeMaterial extends Material {
576
1004
 
577
1005
  const fogNode = builder.fogNode;
578
1006
 
579
- if ( fogNode ) outputNode = vec4( fogNode.mix( outputNode.rgb, fogNode.colorNode ), outputNode.a );
1007
+ if ( fogNode ) {
1008
+
1009
+ output.assign( outputNode );
1010
+
1011
+ outputNode = vec4( fogNode );
1012
+
1013
+ }
580
1014
 
581
1015
  }
582
1016
 
@@ -584,6 +1018,13 @@ class NodeMaterial extends Material {
584
1018
 
585
1019
  }
586
1020
 
1021
+ /**
1022
+ * Most classic material types have a node pendant e.g. for `MeshBasicMaterial`
1023
+ * there is `MeshBasicNodeMaterial`. This utility method is intended for
1024
+ * defining all material properties of the classic type in the node type.
1025
+ *
1026
+ * @param {Material} material - The material to copy properties with their values to this node material.
1027
+ */
587
1028
  setDefaultValues( material ) {
588
1029
 
589
1030
  // This approach is to reuse the native refreshUniforms*
@@ -618,6 +1059,12 @@ class NodeMaterial extends Material {
618
1059
 
619
1060
  }
620
1061
 
1062
+ /**
1063
+ * Serializes this material to JSON.
1064
+ *
1065
+ * @param {(Object|String)?} meta - The meta information for serialization.
1066
+ * @return {Object} The serialized node.
1067
+ */
621
1068
  toJSON( meta ) {
622
1069
 
623
1070
  const isRoot = ( meta === undefined || typeof meta === 'string' );
@@ -677,6 +1124,12 @@ class NodeMaterial extends Material {
677
1124
 
678
1125
  }
679
1126
 
1127
+ /**
1128
+ * Copies the properties of the given node material to this instance.
1129
+ *
1130
+ * @param {NodeMaterial} source - The material to copy.
1131
+ * @return {NodeMaterial} A reference to this node material.
1132
+ */
680
1133
  copy( source ) {
681
1134
 
682
1135
  this.lightsNode = source.lightsNode;