super-three 0.184.0 → 0.185.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 (366) hide show
  1. package/build/three.cjs +1260 -927
  2. package/build/three.core.js +1104 -829
  3. package/build/three.core.min.js +1 -1
  4. package/build/three.module.js +156 -98
  5. package/build/three.module.min.js +1 -1
  6. package/build/three.tsl.js +11 -4
  7. package/build/three.tsl.min.js +1 -1
  8. package/build/three.webgpu.js +7538 -3367
  9. package/build/three.webgpu.min.js +1 -1
  10. package/build/three.webgpu.nodes.js +7538 -3366
  11. package/build/three.webgpu.nodes.min.js +1 -1
  12. package/examples/jsm/Addons.js +3 -0
  13. package/examples/jsm/controls/ArcballControls.js +6 -2
  14. package/examples/jsm/controls/FirstPersonControls.js +79 -42
  15. package/examples/jsm/controls/TransformControls.js +68 -15
  16. package/examples/jsm/csm/CSMFrustum.js +31 -6
  17. package/examples/jsm/csm/CSMShadowNode.js +4 -1
  18. package/examples/jsm/effects/AsciiEffect.js +14 -1
  19. package/examples/jsm/exporters/DRACOExporter.js +27 -6
  20. package/examples/jsm/exporters/GLTFExporter.js +114 -12
  21. package/examples/jsm/exporters/PLYExporter.js +286 -73
  22. package/examples/jsm/exporters/USDZExporter.js +347 -112
  23. package/examples/jsm/generators/CityGenerator.js +346 -0
  24. package/examples/jsm/generators/ForestGenerator.js +347 -0
  25. package/examples/jsm/generators/TerrainGenerator.js +504 -0
  26. package/examples/jsm/generators/TreeGenerator.js +377 -0
  27. package/examples/jsm/generators/city/SidewalkGenerator.js +253 -0
  28. package/examples/jsm/generators/city/SkyscraperGenerator.js +1357 -0
  29. package/examples/jsm/geometries/LoftGeometry.js +355 -0
  30. package/examples/jsm/helpers/LightProbeGridHelper.js +1 -1
  31. package/examples/jsm/helpers/LightProbeHelper.js +5 -4
  32. package/examples/jsm/helpers/ViewHelper.js +16 -6
  33. package/examples/jsm/inspector/Inspector.js +53 -15
  34. package/examples/jsm/inspector/RendererInspector.js +152 -36
  35. package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphEditor.js +1 -1
  36. package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphLoader.js +1 -1
  37. package/examples/jsm/inspector/tabs/Console.js +200 -18
  38. package/examples/jsm/inspector/tabs/Memory.js +8 -0
  39. package/examples/jsm/inspector/tabs/Parameters.js +64 -4
  40. package/examples/jsm/inspector/tabs/Performance.js +21 -6
  41. package/examples/jsm/inspector/tabs/Settings.js +51 -9
  42. package/examples/jsm/inspector/tabs/Timeline.js +178 -93
  43. package/examples/jsm/inspector/tabs/Viewer.js +628 -16
  44. package/examples/jsm/inspector/ui/Graph.js +162 -25
  45. package/examples/jsm/inspector/ui/Item.js +92 -13
  46. package/examples/jsm/inspector/ui/List.js +1 -1
  47. package/examples/jsm/inspector/ui/Profiler.js +90 -45
  48. package/examples/jsm/inspector/ui/Style.js +1788 -1401
  49. package/examples/jsm/inspector/ui/Tab.js +5 -3
  50. package/examples/jsm/inspector/ui/Values.js +71 -6
  51. package/examples/jsm/inspector/ui/utils.js +130 -10
  52. package/examples/jsm/libs/basis/README.md +0 -1
  53. package/examples/jsm/libs/demuxer_mp4.js +3 -3
  54. package/examples/jsm/libs/draco/README.md +0 -1
  55. package/examples/jsm/libs/meshopt_clusterizer.module.js +421 -0
  56. package/examples/jsm/libs/meshopt_simplifier.module.js +627 -0
  57. package/examples/jsm/libs/mikktspace.module.js +34 -9
  58. package/examples/jsm/lighting/ClusteredLighting.js +55 -0
  59. package/examples/jsm/lighting/LightProbeGrid.js +106 -76
  60. package/examples/jsm/lines/LineMaterial.js +38 -15
  61. package/examples/jsm/lines/LineSegments2.js +8 -0
  62. package/examples/jsm/lines/webgpu/LineSegments2.js +8 -0
  63. package/examples/jsm/loaders/3DMLoader.js +1 -1
  64. package/examples/jsm/loaders/DRACOLoader.js +46 -13
  65. package/examples/jsm/loaders/EXRLoader.js +27 -55
  66. package/examples/jsm/loaders/HDRLoader.js +6 -28
  67. package/examples/jsm/loaders/KTX2Loader.js +31 -12
  68. package/examples/jsm/loaders/LDrawLoader.js +8 -8
  69. package/examples/jsm/loaders/LUT3dlLoader.js +2 -2
  70. package/examples/jsm/loaders/LUTCubeLoader.js +2 -2
  71. package/examples/jsm/loaders/LWOLoader.js +4 -0
  72. package/examples/jsm/loaders/LottieLoader.js +1 -1
  73. package/examples/jsm/loaders/MaterialXLoader.js +31 -9
  74. package/examples/jsm/loaders/NRRDLoader.js +3 -3
  75. package/examples/jsm/loaders/PCDLoader.js +7 -7
  76. package/examples/jsm/loaders/PLYLoader.js +218 -55
  77. package/examples/jsm/loaders/SVGLoader.js +547 -495
  78. package/examples/jsm/loaders/TTFLoader.js +1 -1
  79. package/examples/jsm/loaders/USDLoader.js +33 -9
  80. package/examples/jsm/loaders/VRMLLoader.js +1 -1
  81. package/examples/jsm/loaders/usd/USDAParser.js +93 -20
  82. package/examples/jsm/loaders/usd/USDCParser.js +1 -1
  83. package/examples/jsm/loaders/usd/USDComposer.js +52 -19
  84. package/examples/jsm/misc/TileCreasedNormalsPlugin.js +270 -0
  85. package/examples/jsm/misc/Volume.js +2 -2
  86. package/examples/jsm/objects/GroundedSkybox.js +1 -1
  87. package/examples/jsm/objects/Reflector.js +2 -3
  88. package/examples/jsm/objects/Water2Mesh.js +1 -1
  89. package/examples/jsm/physics/AmmoPhysics.js +15 -8
  90. package/examples/jsm/physics/RapierPhysics.js +27 -2
  91. package/examples/jsm/shaders/VolumeShader.js +31 -44
  92. package/examples/jsm/transpiler/GLSLDecoder.js +6 -6
  93. package/examples/jsm/transpiler/Linker.js +1 -1
  94. package/examples/jsm/tsl/display/BloomNode.js +59 -19
  95. package/examples/jsm/tsl/display/DepthOfFieldNode.js +2 -2
  96. package/examples/jsm/tsl/display/FXAANode.js +11 -12
  97. package/examples/jsm/tsl/display/GTAONode.js +34 -13
  98. package/examples/jsm/tsl/display/GodraysNode.js +1 -1
  99. package/examples/jsm/tsl/display/ImportanceSampledEnvironment.js +560 -0
  100. package/examples/jsm/tsl/display/PixelationPassNode.js +2 -2
  101. package/examples/jsm/tsl/display/RecurrentDenoiseNode.js +912 -0
  102. package/examples/jsm/tsl/display/SSAAPassNode.js +13 -25
  103. package/examples/jsm/tsl/display/SSGINode.js +89 -39
  104. package/examples/jsm/tsl/display/SSRNode.js +829 -132
  105. package/examples/jsm/tsl/display/SSSNode.js +2 -2
  106. package/examples/jsm/tsl/display/TemporalReprojectNode.js +1023 -0
  107. package/examples/jsm/tsl/lighting/ClusteredLightsNode.js +622 -0
  108. package/examples/jsm/tsl/lighting/DynamicLightsNode.js +1 -1
  109. package/examples/jsm/tsl/math/curlNoise.js +107 -0
  110. package/examples/jsm/tsl/shadows/TileShadowNode.js +1 -1
  111. package/examples/jsm/tsl/shadows/TileShadowNodeHelper.js +3 -3
  112. package/examples/jsm/tsl/utils/GroundedSkybox.js +62 -0
  113. package/examples/jsm/tsl/utils/RNoise.js +51 -0
  114. package/examples/jsm/tsl/utils/SpecularHelpers.js +325 -0
  115. package/examples/jsm/utils/BufferGeometryUtils.js +126 -59
  116. package/examples/jsm/utils/GeometryCompressionUtils.js +1 -1
  117. package/examples/jsm/utils/SceneOptimizer.js +1 -1
  118. package/examples/jsm/webxr/ARButton.js +1 -1
  119. package/examples/jsm/webxr/WebGLXRFallback.js +89 -0
  120. package/examples/jsm/webxr/XRControllerModelFactory.js +2 -2
  121. package/package.json +7 -7
  122. package/src/Three.TSL.js +10 -3
  123. package/src/Three.WebGPU.js +4 -0
  124. package/src/animation/AnimationAction.js +15 -11
  125. package/src/animation/AnimationClip.js +0 -139
  126. package/src/animation/KeyframeTrack.js +2 -2
  127. package/src/animation/PropertyBinding.js +2 -2
  128. package/src/cameras/Camera.js +2 -2
  129. package/src/cameras/StereoCamera.js +5 -2
  130. package/src/constants.js +1 -1
  131. package/src/core/BufferGeometry.js +29 -7
  132. package/src/core/Object3D.js +17 -7
  133. package/src/core/Raycaster.js +1 -1
  134. package/src/core/RenderTarget.js +15 -2
  135. package/src/extras/PMREMGenerator.js +6 -4
  136. package/src/extras/TextureUtils.js +1 -1
  137. package/src/extras/core/ShapePath.js +149 -160
  138. package/src/geometries/SphereGeometry.js +8 -3
  139. package/src/helpers/DirectionalLightHelper.js +2 -0
  140. package/src/helpers/HemisphereLightHelper.js +2 -0
  141. package/src/helpers/PointLightHelper.js +2 -0
  142. package/src/helpers/SpotLightHelper.js +1 -1
  143. package/src/loaders/DataTextureLoader.js +69 -38
  144. package/src/loaders/LoadingManager.js +5 -0
  145. package/src/loaders/MaterialLoader.js +36 -266
  146. package/src/loaders/ObjectLoader.js +3 -1
  147. package/src/materials/LineBasicMaterial.js +4 -0
  148. package/src/materials/Material.js +196 -1
  149. package/src/materials/MeshBasicMaterial.js +24 -0
  150. package/src/materials/MeshDepthMaterial.js +10 -0
  151. package/src/materials/MeshDistanceMaterial.js +10 -0
  152. package/src/materials/MeshLambertMaterial.js +40 -1
  153. package/src/materials/MeshMatcapMaterial.js +25 -1
  154. package/src/materials/MeshNormalMaterial.js +9 -1
  155. package/src/materials/MeshPhongMaterial.js +40 -1
  156. package/src/materials/MeshPhysicalMaterial.js +38 -0
  157. package/src/materials/MeshStandardMaterial.js +42 -1
  158. package/src/materials/MeshToonMaterial.js +34 -1
  159. package/src/materials/PointsMaterial.js +7 -0
  160. package/src/materials/ShaderMaterial.js +86 -0
  161. package/src/materials/SpriteMaterial.js +7 -0
  162. package/src/materials/nodes/Line2NodeMaterial.js +378 -322
  163. package/src/materials/nodes/MeshBasicNodeMaterial.js +2 -2
  164. package/src/materials/nodes/MeshNormalNodeMaterial.js +2 -2
  165. package/src/materials/nodes/MeshPhongNodeMaterial.js +0 -9
  166. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +0 -30
  167. package/src/materials/nodes/MeshSSSNodeMaterial.js +0 -13
  168. package/src/materials/nodes/MeshStandardNodeMaterial.js +0 -11
  169. package/src/materials/nodes/NodeMaterial.js +115 -71
  170. package/src/materials/nodes/SpriteNodeMaterial.js +0 -10
  171. package/src/materials/nodes/manager/NodeMaterialObserver.js +49 -20
  172. package/src/math/Box3.js +5 -0
  173. package/src/math/FrustumArray.js +103 -133
  174. package/src/math/Interpolant.js +1 -1
  175. package/src/math/MathUtils.js +2 -2
  176. package/src/math/Matrix3.js +11 -0
  177. package/src/math/Matrix4.js +28 -3
  178. package/src/math/Vector2.js +2 -2
  179. package/src/math/Vector3.js +2 -2
  180. package/src/math/Vector4.js +2 -2
  181. package/src/math/interpolants/BezierInterpolant.js +4 -6
  182. package/src/nodes/Nodes.js +2 -5
  183. package/src/nodes/TSL.js +8 -6
  184. package/src/nodes/accessors/Arrays.js +4 -4
  185. package/src/nodes/accessors/Batch.js +108 -0
  186. package/src/nodes/accessors/Bitangent.js +2 -2
  187. package/src/nodes/accessors/BufferAttributeNode.js +13 -2
  188. package/src/nodes/accessors/Camera.js +7 -7
  189. package/src/nodes/accessors/ClippingNode.js +1 -1
  190. package/src/nodes/accessors/Instance.js +264 -0
  191. package/src/nodes/accessors/MaterialNode.js +18 -2
  192. package/src/nodes/accessors/MaterialProperties.js +4 -3
  193. package/src/nodes/accessors/{MorphNode.js → Morph.js} +99 -112
  194. package/src/nodes/accessors/Normal.js +13 -13
  195. package/src/nodes/accessors/Position.js +5 -1
  196. package/src/nodes/accessors/ReferenceNode.js +1 -0
  197. package/src/nodes/accessors/ReflectVector.js +3 -3
  198. package/src/nodes/accessors/SceneProperties.js +1 -1
  199. package/src/nodes/accessors/Skinning.js +263 -0
  200. package/src/nodes/accessors/StorageBufferNode.js +2 -2
  201. package/src/nodes/accessors/StorageTexture3DNode.js +100 -0
  202. package/src/nodes/accessors/StorageTextureNode.js +39 -7
  203. package/src/nodes/accessors/Tangent.js +4 -4
  204. package/src/nodes/accessors/TextureNode.js +60 -5
  205. package/src/nodes/code/FunctionNode.js +2 -16
  206. package/src/nodes/core/MRTNode.js +7 -2
  207. package/src/nodes/core/Node.js +39 -2
  208. package/src/nodes/core/NodeBuilder.js +201 -41
  209. package/src/nodes/core/NodeUtils.js +13 -13
  210. package/src/nodes/core/OutputStructNode.js +1 -1
  211. package/src/nodes/core/OverrideContextNode.js +153 -0
  212. package/src/nodes/core/PropertyNode.js +51 -5
  213. package/src/nodes/core/StackNode.js +56 -34
  214. package/src/nodes/core/StructNode.js +4 -6
  215. package/src/nodes/core/StructTypeNode.js +6 -6
  216. package/src/nodes/core/VarNode.js +8 -0
  217. package/src/nodes/core/VaryingNode.js +12 -2
  218. package/src/nodes/display/BlendModes.js +1 -41
  219. package/src/nodes/display/BumpMapNode.js +6 -1
  220. package/src/nodes/display/ColorAdjustment.js +10 -9
  221. package/src/nodes/display/FrontFacingNode.js +38 -9
  222. package/src/nodes/display/NormalMapNode.js +2 -2
  223. package/src/nodes/display/PassNode.js +35 -43
  224. package/src/nodes/display/PremultiplyAlphaFunctions.js +39 -0
  225. package/src/nodes/display/RenderOutputNode.js +12 -3
  226. package/src/nodes/functions/VolumetricLightingModel.js +40 -7
  227. package/src/nodes/gpgpu/WorkgroupInfoNode.js +1 -1
  228. package/src/nodes/lighting/EnvironmentNode.js +2 -2
  229. package/src/nodes/lighting/IESSpotLightNode.js +40 -2
  230. package/src/nodes/lighting/LightingContextNode.js +10 -2
  231. package/src/nodes/lighting/LightsNode.js +90 -37
  232. package/src/nodes/lighting/PointShadowNode.js +6 -1
  233. package/src/nodes/lighting/ShadowFilterNode.js +21 -52
  234. package/src/nodes/lighting/ShadowNode.js +34 -14
  235. package/src/nodes/materialx/lib/mx_noise.js +2 -2
  236. package/src/nodes/math/ConditionalNode.js +3 -3
  237. package/src/nodes/math/MathNode.js +39 -11
  238. package/src/nodes/math/OperatorNode.js +23 -23
  239. package/src/nodes/parsers/GLSLNodeFunction.js +1 -1
  240. package/src/nodes/pmrem/PMREMNode.js +33 -2
  241. package/src/nodes/tsl/TSLCore.js +63 -18
  242. package/src/nodes/utils/EquirectUV.js +30 -5
  243. package/src/nodes/utils/FunctionOverloadingNode.js +1 -1
  244. package/src/nodes/utils/Packing.js +35 -4
  245. package/src/nodes/utils/RTTNode.js +40 -24
  246. package/src/nodes/utils/ReflectorNode.js +1 -0
  247. package/src/nodes/utils/StorageArrayElementNode.js +1 -1
  248. package/src/objects/BatchedMesh.js +22 -14
  249. package/src/objects/InstancedMesh.js +0 -11
  250. package/src/objects/Skeleton.js +0 -9
  251. package/src/renderers/WebGLRenderer.js +19 -15
  252. package/src/renderers/common/Backend.js +49 -5
  253. package/src/renderers/common/Bindings.js +114 -45
  254. package/src/renderers/common/Buffer.js +9 -0
  255. package/src/renderers/common/ClippingContext.js +10 -2
  256. package/src/renderers/common/Info.js +63 -22
  257. package/src/renderers/common/Lighting.js +53 -5
  258. package/src/renderers/common/RenderList.js +41 -4
  259. package/src/renderers/common/RenderObject.js +73 -13
  260. package/src/renderers/common/Renderer.js +281 -108
  261. package/src/renderers/common/Sampler.js +16 -48
  262. package/src/renderers/common/Textures.js +32 -5
  263. package/src/renderers/common/TimestampQueryPool.js +1 -1
  264. package/src/renderers/common/UniformsGroup.js +31 -9
  265. package/src/renderers/common/XRManager.js +340 -22
  266. package/src/renderers/common/extras/PMREMGenerator.js +15 -38
  267. package/src/renderers/common/nodes/NodeBuilderState.js +9 -1
  268. package/src/renderers/common/nodes/NodeLibrary.js +4 -4
  269. package/src/renderers/common/nodes/NodeManager.js +63 -14
  270. package/src/renderers/common/nodes/NodeUniformBuffer.js +13 -0
  271. package/src/renderers/shaders/ShaderChunk/common.glsl.js +13 -4
  272. package/src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl.js +0 -6
  273. package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +1 -1
  274. package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +2 -2
  275. package/src/renderers/shaders/ShaderChunk/envmap_vertex.glsl.js +1 -1
  276. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +1 -1
  277. package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +1 -1
  278. package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +2 -2
  279. package/src/renderers/shaders/ShaderChunk/normal_vertex.glsl.js +6 -0
  280. package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +1 -1
  281. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
  282. package/src/renderers/shaders/ShaderLib/distance.glsl.js +1 -1
  283. package/src/renderers/webgl/WebGLOutput.js +2 -1
  284. package/src/renderers/webgl/WebGLProgram.js +5 -4
  285. package/src/renderers/webgl/WebGLPrograms.js +12 -5
  286. package/src/renderers/webgl/WebGLRenderLists.js +9 -1
  287. package/src/renderers/webgl/WebGLShaderCache.js +5 -11
  288. package/src/renderers/webgl/WebGLTextures.js +20 -7
  289. package/src/renderers/webgl/WebGLUniformsGroups.js +66 -38
  290. package/src/renderers/webgl-fallback/WebGLBackend.js +84 -25
  291. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +138 -8
  292. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +1 -1
  293. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +52 -22
  294. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +4 -2
  295. package/src/renderers/webgpu/WebGPUBackend.js +480 -169
  296. package/src/renderers/webgpu/descriptors/GPUBindGroupDescriptor.js +48 -0
  297. package/src/renderers/webgpu/descriptors/GPUBufferDescriptor.js +57 -0
  298. package/src/renderers/webgpu/descriptors/GPUCommandEncoderDescriptor.js +30 -0
  299. package/src/renderers/webgpu/descriptors/GPUComputePassDescriptor.js +38 -0
  300. package/src/renderers/webgpu/descriptors/GPUComputePipelineDescriptor.js +48 -0
  301. package/src/renderers/webgpu/descriptors/GPUCopyExternalImageDestInfo.js +47 -0
  302. package/src/renderers/webgpu/descriptors/GPUCopyExternalImageSourceInfo.js +50 -0
  303. package/src/renderers/webgpu/descriptors/GPUExtent3D.js +51 -0
  304. package/src/renderers/webgpu/descriptors/GPUPipelineLayoutDescriptor.js +39 -0
  305. package/src/renderers/webgpu/descriptors/GPUQuerySetDescriptor.js +47 -0
  306. package/src/renderers/webgpu/descriptors/GPURenderBundleEncoderDescriptor.js +74 -0
  307. package/src/renderers/webgpu/descriptors/GPURenderPassColorAttachment.js +72 -0
  308. package/src/renderers/webgpu/descriptors/GPURenderPassDepthStencilAttachment.js +99 -0
  309. package/src/renderers/webgpu/descriptors/GPURenderPassDescriptor.js +72 -0
  310. package/src/renderers/webgpu/descriptors/GPURenderPassTimestampWrites.js +49 -0
  311. package/src/renderers/webgpu/descriptors/GPURenderPipelineDescriptor.js +130 -0
  312. package/src/renderers/webgpu/descriptors/GPUSamplerDescriptor.js +119 -0
  313. package/src/renderers/webgpu/descriptors/GPUShaderModuleDescriptor.js +46 -0
  314. package/src/renderers/webgpu/descriptors/GPUTexelCopyBufferInfo.js +57 -0
  315. package/src/renderers/webgpu/descriptors/GPUTexelCopyBufferLayout.js +48 -0
  316. package/src/renderers/webgpu/descriptors/GPUTexelCopyTextureInfo.js +61 -0
  317. package/src/renderers/webgpu/descriptors/GPUTextureDescriptor.js +99 -0
  318. package/src/renderers/webgpu/descriptors/GPUTextureViewDescriptor.js +108 -0
  319. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +0 -1
  320. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +164 -7
  321. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +1 -1
  322. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +98 -38
  323. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +72 -68
  324. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +164 -69
  325. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +158 -95
  326. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +297 -141
  327. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +33 -18
  328. package/src/renderers/webgpu/utils/WebGPUUtils.js +38 -3
  329. package/src/textures/DepthTexture.js +1 -1
  330. package/src/textures/ExternalTexture.js +0 -3
  331. package/examples/fonts/LICENSE +0 -13
  332. package/examples/fonts/MPLUSRounded1c/MPLUSRounded1c-Regular.typeface.json.zip +0 -0
  333. package/examples/fonts/MPLUSRounded1c/OFL.txt +0 -91
  334. package/examples/fonts/README.md +0 -11
  335. package/examples/fonts/droid/NOTICE +0 -190
  336. package/examples/fonts/droid/README.txt +0 -18
  337. package/examples/fonts/droid/droid_sans_bold.typeface.json +0 -1
  338. package/examples/fonts/droid/droid_sans_mono_regular.typeface.json +0 -1
  339. package/examples/fonts/droid/droid_sans_regular.typeface.json +0 -1
  340. package/examples/fonts/droid/droid_serif_bold.typeface.json +0 -1
  341. package/examples/fonts/droid/droid_serif_regular.typeface.json +0 -1
  342. package/examples/fonts/gentilis_bold.typeface.json +0 -1
  343. package/examples/fonts/gentilis_regular.typeface.json +0 -1
  344. package/examples/fonts/helvetiker_bold.typeface.json +0 -1
  345. package/examples/fonts/helvetiker_regular.typeface.json +0 -1
  346. package/examples/fonts/optimer_bold.typeface.json +0 -1
  347. package/examples/fonts/optimer_regular.typeface.json +0 -1
  348. package/examples/fonts/ttf/README.md +0 -9
  349. package/examples/fonts/ttf/kenpixel.ttf +0 -0
  350. package/examples/jsm/inspector/extensions/extensions.json +0 -6
  351. package/examples/jsm/libs/ammo.wasm.js +0 -822
  352. package/examples/jsm/libs/ammo.wasm.wasm +0 -0
  353. package/examples/jsm/libs/draco/draco_encoder.js +0 -33
  354. package/examples/jsm/libs/draco/gltf/draco_encoder.js +0 -33
  355. package/examples/jsm/libs/lottie_canvas.module.js +0 -14849
  356. package/examples/jsm/libs/opentype.module.js +0 -14506
  357. package/examples/jsm/libs/rhino3dm/rhino3dm.js +0 -21
  358. package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +0 -16
  359. package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
  360. package/examples/jsm/lighting/TiledLighting.js +0 -42
  361. package/examples/jsm/tsl/display/AnamorphicNode.js +0 -293
  362. package/examples/jsm/tsl/lighting/TiledLightsNode.js +0 -442
  363. package/src/nodes/accessors/BatchNode.js +0 -163
  364. package/src/nodes/accessors/InstanceNode.js +0 -349
  365. package/src/nodes/accessors/InstancedMeshNode.js +0 -50
  366. package/src/nodes/accessors/SkinningNode.js +0 -328
@@ -0,0 +1,560 @@
1
+ /**
2
+ * HDR environment importance sampling (CDF tables + MIS) for screen-space effects.
3
+ *
4
+ * CDF precomputation and the MIS env-miss estimator are adapted from
5
+ * [three-gpu-pathtracer](https://github.com/gkjohnson/three-gpu-pathtracer).
6
+ *
7
+ * @see {@link https://github.com/gkjohnson/three-gpu-pathtracer}
8
+ */
9
+
10
+ import { If, dot, equirectUV, float, luminance, max, normalize, texture, uniform, vec2, vec4 } from 'three/tsl';
11
+ import { ClampToEdgeWrapping, DataTexture, DataUtils, FloatType, HalfFloatType, LinearFilter, RedFormat, RepeatWrapping, Source, Vector2 } from 'three/webgpu';
12
+ import { D_GTR, F_Schlick, GeometryTerm, SmithG, equirectDirPdf, misPowerHeuristic } from '../utils/SpecularHelpers.js';
13
+
14
+ function colorToLuminance( r, g, b ) {
15
+
16
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
17
+
18
+ }
19
+
20
+ function binarySearchFindClosestIndexOf( array, targetValue, offset = 0, count = array.length ) {
21
+
22
+ let lower = offset;
23
+ let upper = offset + count - 1;
24
+
25
+ while ( lower < upper ) {
26
+
27
+ const mid = ( lower + upper ) >> 1;
28
+
29
+ if ( array[ mid ] < targetValue ) {
30
+
31
+ lower = mid + 1;
32
+
33
+ } else {
34
+
35
+ upper = mid;
36
+
37
+ }
38
+
39
+ }
40
+
41
+ return lower - offset;
42
+
43
+ }
44
+
45
+ function preprocessEnvMap( envMap ) {
46
+
47
+ const map = envMap.clone();
48
+ map.source = new Source( { ...map.image } );
49
+ const { width, height, data } = map.image;
50
+
51
+ let newData = data;
52
+
53
+ if ( map.type !== HalfFloatType ) {
54
+
55
+ newData = new Uint16Array( data.length );
56
+
57
+ let maxIntValue;
58
+ if ( data instanceof Int8Array || data instanceof Int16Array || data instanceof Int32Array ) {
59
+
60
+ maxIntValue = 2 ** ( 8 * data.BYTES_PER_ELEMENT - 1 ) - 1;
61
+
62
+ } else {
63
+
64
+ maxIntValue = 2 ** ( 8 * data.BYTES_PER_ELEMENT ) - 1;
65
+
66
+ }
67
+
68
+ for ( let i = 0, l = data.length; i < l; i ++ ) {
69
+
70
+ let v = data[ i ];
71
+
72
+ if ( map.type === HalfFloatType ) {
73
+
74
+ v = DataUtils.fromHalfFloat( data[ i ] );
75
+
76
+ }
77
+
78
+ if ( map.type !== FloatType && map.type !== HalfFloatType ) {
79
+
80
+ v /= maxIntValue;
81
+
82
+ }
83
+
84
+ newData[ i ] = DataUtils.toHalfFloat( v );
85
+
86
+ }
87
+
88
+ map.image.data = newData;
89
+ map.type = HalfFloatType;
90
+
91
+ }
92
+
93
+ if ( map.flipY ) {
94
+
95
+ const ogData = newData;
96
+ newData = newData.slice();
97
+
98
+ for ( let y = 0; y < height; y ++ ) {
99
+
100
+ for ( let x = 0; x < width; x ++ ) {
101
+
102
+ const newY = height - y - 1;
103
+ const ogIndex = 4 * ( y * width + x );
104
+ const newIndex = 4 * ( newY * width + x );
105
+
106
+ newData[ newIndex + 0 ] = ogData[ ogIndex + 0 ];
107
+ newData[ newIndex + 1 ] = ogData[ ogIndex + 1 ];
108
+ newData[ newIndex + 2 ] = ogData[ ogIndex + 2 ];
109
+ newData[ newIndex + 3 ] = ogData[ ogIndex + 3 ];
110
+
111
+ }
112
+
113
+ }
114
+
115
+ map.flipY = false;
116
+ map.image.data = newData;
117
+
118
+ }
119
+
120
+ return map;
121
+
122
+ }
123
+
124
+ /**
125
+ * Precomputes marginal and conditional CDF textures from an equirectangular HDR environment map
126
+ * for luminance importance sampling.
127
+ */
128
+ class EnvMapCDFGenerator {
129
+
130
+ constructor() {
131
+
132
+ this.map = null;
133
+ this.marginalWeights = null;
134
+ this.conditionalWeights = null;
135
+ this.totalSum = 0;
136
+
137
+ }
138
+
139
+ updateFrom( hdr ) {
140
+
141
+ this.updateMapOnly( hdr );
142
+
143
+ const { width, height, data } = this.map.image;
144
+
145
+ const pdfConditional = new Float32Array( width * height );
146
+ const cdfConditional = new Float32Array( width * height );
147
+ const pdfMarginal = new Float32Array( height );
148
+ const cdfMarginal = new Float32Array( height );
149
+
150
+ let totalSumValue = 0.0;
151
+ let cumulativeWeightMarginal = 0.0;
152
+
153
+ for ( let y = 0; y < height; y ++ ) {
154
+
155
+ let cumulativeRowWeight = 0.0;
156
+
157
+ for ( let x = 0; x < width; x ++ ) {
158
+
159
+ const i = y * width + x;
160
+ const r = DataUtils.fromHalfFloat( data[ 4 * i + 0 ] );
161
+ const g = DataUtils.fromHalfFloat( data[ 4 * i + 1 ] );
162
+ const b = DataUtils.fromHalfFloat( data[ 4 * i + 2 ] );
163
+
164
+ const weight = colorToLuminance( r, g, b );
165
+ cumulativeRowWeight += weight;
166
+ totalSumValue += weight;
167
+
168
+ pdfConditional[ i ] = weight;
169
+ cdfConditional[ i ] = cumulativeRowWeight;
170
+
171
+ }
172
+
173
+ if ( cumulativeRowWeight !== 0 ) {
174
+
175
+ for ( let i = y * width, l = y * width + width; i < l; i ++ ) {
176
+
177
+ pdfConditional[ i ] /= cumulativeRowWeight;
178
+ cdfConditional[ i ] /= cumulativeRowWeight;
179
+
180
+ }
181
+
182
+ }
183
+
184
+ cumulativeWeightMarginal += cumulativeRowWeight;
185
+ pdfMarginal[ y ] = cumulativeRowWeight;
186
+ cdfMarginal[ y ] = cumulativeWeightMarginal;
187
+
188
+ }
189
+
190
+ if ( cumulativeWeightMarginal !== 0 ) {
191
+
192
+ for ( let i = 0, l = pdfMarginal.length; i < l; i ++ ) {
193
+
194
+ pdfMarginal[ i ] /= cumulativeWeightMarginal;
195
+ cdfMarginal[ i ] /= cumulativeWeightMarginal;
196
+
197
+ }
198
+
199
+ }
200
+
201
+ const marginalDataArray = new Uint16Array( height );
202
+ const conditionalDataArray = new Uint16Array( width * height );
203
+
204
+ for ( let i = 0; i < height; i ++ ) {
205
+
206
+ const dist = ( i + 1 ) / height;
207
+ const row = binarySearchFindClosestIndexOf( cdfMarginal, dist );
208
+ marginalDataArray[ i ] = DataUtils.toHalfFloat( ( row + 0.5 ) / height );
209
+
210
+ }
211
+
212
+ for ( let y = 0; y < height; y ++ ) {
213
+
214
+ for ( let x = 0; x < width; x ++ ) {
215
+
216
+ const i = y * width + x;
217
+ const dist = ( x + 1 ) / width;
218
+ const col = binarySearchFindClosestIndexOf( cdfConditional, dist, y * width, width );
219
+ conditionalDataArray[ i ] = DataUtils.toHalfFloat( ( col + 0.5 ) / width );
220
+
221
+ }
222
+
223
+ }
224
+
225
+ if ( this.marginalWeights ) {
226
+
227
+ this.marginalWeights.dispose();
228
+
229
+ }
230
+
231
+ if ( this.conditionalWeights ) {
232
+
233
+ this.conditionalWeights.dispose();
234
+
235
+ }
236
+
237
+ this.marginalWeights = new DataTexture( marginalDataArray, height, 1 );
238
+ this.marginalWeights.type = HalfFloatType;
239
+ this.marginalWeights.format = RedFormat;
240
+ this.marginalWeights.minFilter = LinearFilter;
241
+ this.marginalWeights.magFilter = LinearFilter;
242
+ this.marginalWeights.wrapS = ClampToEdgeWrapping;
243
+ this.marginalWeights.wrapT = ClampToEdgeWrapping;
244
+ this.marginalWeights.generateMipmaps = false;
245
+ this.marginalWeights.needsUpdate = true;
246
+
247
+ this.conditionalWeights = new DataTexture( conditionalDataArray, width, height );
248
+ this.conditionalWeights.type = HalfFloatType;
249
+ this.conditionalWeights.format = RedFormat;
250
+ this.conditionalWeights.minFilter = LinearFilter;
251
+ this.conditionalWeights.magFilter = LinearFilter;
252
+ this.conditionalWeights.wrapS = ClampToEdgeWrapping;
253
+ this.conditionalWeights.wrapT = ClampToEdgeWrapping;
254
+ this.conditionalWeights.generateMipmaps = false;
255
+ this.conditionalWeights.needsUpdate = true;
256
+
257
+ this.totalSum = totalSumValue;
258
+
259
+ }
260
+
261
+ updateMapOnly( hdr ) {
262
+
263
+ if ( this.map ) {
264
+
265
+ this.map.dispose();
266
+
267
+ }
268
+
269
+ const map = preprocessEnvMap( hdr );
270
+ map.wrapS = RepeatWrapping;
271
+ map.wrapT = ClampToEdgeWrapping;
272
+
273
+ this.map = map;
274
+ this.totalSum = 0;
275
+
276
+ }
277
+
278
+ dispose() {
279
+
280
+ if ( this.marginalWeights ) {
281
+
282
+ this.marginalWeights.dispose();
283
+ this.marginalWeights = null;
284
+
285
+ }
286
+
287
+ if ( this.conditionalWeights ) {
288
+
289
+ this.conditionalWeights.dispose();
290
+ this.conditionalWeights = null;
291
+
292
+ }
293
+
294
+ if ( this.map ) {
295
+
296
+ this.map.dispose();
297
+ this.map = null;
298
+
299
+ }
300
+
301
+ }
302
+
303
+ }
304
+
305
+ /**
306
+ * Manages a preprocessed HDR environment map (CDF textures, uniforms) and exposes
307
+ * TSL helpers for BRDF-direction lookups and MIS importance sampling.
308
+ *
309
+ * @see {@link https://github.com/gkjohnson/three-gpu-pathtracer}
310
+ */
311
+ class ImportanceSampledEnvironment {
312
+
313
+ /**
314
+ * @param {boolean} [importanceSampling=false] - When `true`, builds luminance CDF tables and enables MIS env sampling.
315
+ */
316
+ constructor( importanceSampling = false ) {
317
+
318
+ this._importanceSampling = importanceSampling;
319
+ this._cdf = new EnvMapCDFGenerator();
320
+
321
+ this._totalSum = uniform( 0.0, 'float' );
322
+ this._size = uniform( new Vector2( 1, 1 ) );
323
+ this.intensity = uniform( 1.0, 'float' );
324
+
325
+ this._mapNode = null;
326
+ this._marginalNode = null;
327
+ this._conditionalNode = null;
328
+
329
+ }
330
+
331
+ /**
332
+ * @param {Texture} hdr - Equirectangular HDR environment map.
333
+ */
334
+ updateFrom( hdr ) {
335
+
336
+ if ( this._importanceSampling ) {
337
+
338
+ this._cdf.updateFrom( hdr );
339
+ this._totalSum.value = this._cdf.totalSum;
340
+
341
+ } else {
342
+
343
+ this._cdf.updateMapOnly( hdr );
344
+
345
+ }
346
+
347
+ this._size.value.set( this._cdf.map.image.width, this._cdf.map.image.height );
348
+
349
+ if ( this._mapNode === null ) {
350
+
351
+ this._mapNode = texture( this._cdf.map );
352
+
353
+ if ( this._importanceSampling ) {
354
+
355
+ this._marginalNode = texture( this._cdf.marginalWeights );
356
+ this._conditionalNode = texture( this._cdf.conditionalWeights );
357
+
358
+ }
359
+
360
+ } else {
361
+
362
+ this._mapNode.value = this._cdf.map;
363
+
364
+ if ( this._importanceSampling ) {
365
+
366
+ this._marginalNode.value = this._cdf.marginalWeights;
367
+ this._conditionalNode.value = this._cdf.conditionalWeights;
368
+
369
+ }
370
+
371
+ }
372
+
373
+ }
374
+
375
+ clear() {
376
+
377
+ this.dispose();
378
+ this._cdf = new EnvMapCDFGenerator();
379
+ this._mapNode = null;
380
+ this._marginalNode = null;
381
+ this._conditionalNode = null;
382
+ this._totalSum.value = 0;
383
+ this._size.value.set( 1, 1 );
384
+
385
+ }
386
+
387
+ /**
388
+ * Simple environment lookup along the reflected direction (no MIS).
389
+ *
390
+ * @param {Object} params
391
+ * @param {UniformNode<Matrix4>} params.cameraWorldMatrix
392
+ * @param {Node<vec3>} params.viewReflectDir
393
+ * @param {Node<float>} [params.sampleWeight] - Optional radiance scale (defaults to 1).
394
+ * @return {Node<vec3>}
395
+ */
396
+ sampleReflect( { cameraWorldMatrix, viewReflectDir, sampleWeight = float( 1 ) } ) {
397
+
398
+ const worldReflectDir = cameraWorldMatrix.mul( vec4( viewReflectDir, float( 0 ) ) ).xyz.normalize();
399
+ const envUV = equirectUV( worldReflectDir );
400
+
401
+ // Explicit LOD 0: the per-pixel reflected direction is discontinuous at the equirect pole/seam
402
+ // (atan is undefined at the poles), so derivative-driven mip selection collapses to the coarsest
403
+ // (near-average) mip there and produces a bright streak. Roughness is handled via direction sampling.
404
+ return texture( this._mapNode, envUV ).level( 0 ).rgb.mul( this.intensity ).mul( sampleWeight );
405
+
406
+ }
407
+
408
+ /**
409
+ * Environment reflection for a screen-space miss using only the BRDF / reflected-ray direction.
410
+ *
411
+ * @param {Object} params
412
+ * @param {UniformNode<Matrix4>} params.cameraWorldMatrix
413
+ * @param {Node<vec3>} params.viewReflectDir - View-space GGX-sampled reflected ray.
414
+ * @param {Node<vec3>} params.N - View-space shading normal.
415
+ * @param {Node<vec3>} params.V - View-space direction to camera.
416
+ * @param {Node<float>} params.alpha - GGX roughness (alpha).
417
+ * @param {Node<vec3>} params.f0
418
+ * @return {Node<vec3>}
419
+ */
420
+ sampleEnvironmentBRDF( {
421
+ cameraWorldMatrix,
422
+ viewReflectDir,
423
+ N,
424
+ V,
425
+ alpha,
426
+ f0
427
+ } ) {
428
+
429
+ const worldNormal = cameraWorldMatrix.mul( vec4( N, 0 ) ).xyz.normalize().toVar();
430
+ const worldV = cameraWorldMatrix.mul( vec4( V, 0 ) ).xyz.normalize().toVar();
431
+ const NdotV = max( float( 0 ), dot( worldNormal, worldV ) ).toVar();
432
+
433
+ const L1 = cameraWorldMatrix.mul( vec4( viewReflectDir, float( 0 ) ) ).xyz.normalize().toVar();
434
+ // Explicit LOD 0: the equirect mapping is singular at the poles (atan undefined when the reflected
435
+ // ray points straight up/down, e.g. a flat floor under a top-down camera), so derivative-driven mip
436
+ // selection picks the coarsest, near-average mip and yields a bright streak. Sample full-res instead.
437
+ const brdfEnvColor = texture( this._mapNode, equirectUV( L1 ) ).level( 0 ).rgb;
438
+
439
+ const H1 = normalize( worldV.add( L1 ) ).toVar();
440
+ const NdotL1 = max( float( 0 ), dot( worldNormal, L1 ) ).toVar();
441
+ const VdotH1 = max( float( 0 ), dot( worldV, H1 ) ).toVar();
442
+
443
+ const W1 = F_Schlick( f0, VdotH1 ).mul( GeometryTerm( NdotL1, NdotV, alpha ) ).div( SmithG( NdotV, alpha ).max( float( 1e-4 ) ) );
444
+
445
+ return brdfEnvColor.mul( W1 ).mul( this.intensity );
446
+
447
+ }
448
+
449
+ /**
450
+ * Environment reflection for a screen-space miss, estimated with multiple importance
451
+ * sampling (MIS) between the BRDF / reflected-ray direction and the env-luminance CDF
452
+ * direction. Both techniques use consistent solid-angle PDFs (`D·G1(N·V)/(4·N·V)`), so
453
+ * the power heuristic is unbiased. Adapted from three-gpu-pathtracer.
454
+ *
455
+ * @see {@link https://github.com/gkjohnson/three-gpu-pathtracer}
456
+ *
457
+ * @param {Object} params
458
+ * @param {UniformNode<Matrix4>} params.cameraWorldMatrix
459
+ * @param {Node<vec3>} params.viewReflectDir - View-space GGX-sampled reflected ray.
460
+ * @param {Node<vec3>} params.N - View-space shading normal.
461
+ * @param {Node<vec3>} params.V - View-space direction to camera.
462
+ * @param {Node<float>} params.alpha - GGX roughness (alpha).
463
+ * @param {Node<vec3>} params.f0
464
+ * @param {Node<vec4>} params.Xi2 - Second blue-noise sample (zw used for the CDF).
465
+ * @return {Node<vec3>}
466
+ */
467
+ sampleEnvironmentMIS( {
468
+ cameraWorldMatrix,
469
+ viewReflectDir,
470
+ N,
471
+ V,
472
+ alpha,
473
+ f0,
474
+ Xi2
475
+ } ) {
476
+
477
+ const mapNode = this._mapNode;
478
+ const marginalNode = this._marginalNode;
479
+ const conditionalNode = this._conditionalNode;
480
+ const totalSum = this._totalSum;
481
+ const envW = this._size.x;
482
+ const envH = this._size.y;
483
+ const envMapIntensity = this.intensity;
484
+
485
+ const worldNormal = cameraWorldMatrix.mul( vec4( N, 0 ) ).xyz.normalize().toVar();
486
+ const worldV = cameraWorldMatrix.mul( vec4( V, 0 ) ).xyz.normalize().toVar();
487
+ const NdotV = max( float( 0 ), dot( worldNormal, worldV ) ).toVar();
488
+
489
+ // MIS sample 1: the BRDF / reflected-ray direction
490
+ const L1 = cameraWorldMatrix.mul( vec4( viewReflectDir, float( 0 ) ) ).xyz.normalize().toVar();
491
+ const brdfEnvColor = texture( mapNode, equirectUV( L1 ) ).level( 0 ).rgb;
492
+
493
+ const H1 = normalize( worldV.add( L1 ) ).toVar();
494
+ const NdotL1 = max( float( 0 ), dot( worldNormal, L1 ) ).toVar();
495
+ const NdotH1 = max( float( 0 ), dot( worldNormal, H1 ) ).toVar();
496
+ const VdotH1 = max( float( 0 ), dot( worldV, H1 ) ).toVar();
497
+
498
+ // Solid-angle PDF of the reflected ray for the BRDF technique: D(H)·G1(N·V)/(4·N·V).
499
+ const pdfBrdf1 = D_GTR( alpha, NdotH1, float( 2 ) ).mul( SmithG( NdotV, alpha ) ).div( max( float( 1e-6 ), float( 4 ).mul( NdotV ) ) ).max( float( 1e-8 ) );
500
+ // Env-luminance CDF PDF evaluated at the same direction.
501
+ const pdfEnv1 = envW.mul( envH ).mul( luminance( brdfEnvColor ).div( totalSum ) ).mul( equirectDirPdf( L1 ) ).max( float( 1e-8 ) );
502
+ const w1 = misPowerHeuristic( pdfBrdf1, pdfEnv1 );
503
+
504
+ // Monte-Carlo weight f·cosθ/pdfBrdf1 = F·G1(N·L) (GGX D cancels analytically — stable at low
505
+ // roughness). G2 and the pdf's G1 must use the same alpha for the cancellation to hold.
506
+ const W1 = F_Schlick( f0, VdotH1 ).mul( GeometryTerm( NdotL1, NdotV, alpha ) ).div( SmithG( NdotV, alpha ).max( float( 1e-4 ) ) );
507
+ const result = brdfEnvColor.mul( W1 ).mul( w1 ).toVar();
508
+
509
+ // MIS sample 2: the env-luminance CDF direction
510
+ // Mitigates noise on high-dynamic-range environments (the CDF lands samples on bright regions
511
+ // the BRDF lobe rarely hits). Skipped for near-mirror lobes (alpha ≲ 0.01, i.e. roughness ≲ 0.1):
512
+ // a global CDF direction almost never lands inside such a tight specular lobe.
513
+ If( alpha.greaterThan( 0.01 ), () => {
514
+
515
+ const r_env = vec2( Xi2.z, Xi2.w );
516
+ const v_cdf = texture( marginalNode, vec2( r_env.x, float( 0 ) ) ).r;
517
+ const u_cdf = texture( conditionalNode, vec2( r_env.y, v_cdf ) ).r;
518
+ const isEnvUV = vec2( u_cdf, v_cdf );
519
+ const envDirWS = equirectUV( isEnvUV );
520
+
521
+ const envHalf = normalize( worldV.add( envDirWS ) );
522
+ const envNdotL = max( float( 0 ), dot( worldNormal, envDirWS ) );
523
+ const envNdotH = max( float( 0 ), dot( worldNormal, envHalf ) );
524
+ const envVdotH = max( float( 0 ), dot( worldV, envHalf ) );
525
+
526
+ If( envNdotL.greaterThan( 0.001 ), () => {
527
+
528
+ // GGX normal-distribution term, shared by the BRDF pdf and the specular BRDF
529
+ // (both evaluate D(envNdotH)) so the pow is computed once.
530
+ const D = D_GTR( alpha, envNdotH, float( 2 ) ).toVar();
531
+
532
+ const sampledColor = texture( mapNode, isEnvUV ).level( 0 ).rgb;
533
+ const pdfEnv2 = envW.mul( envH ).mul( luminance( sampledColor ).div( totalSum ) ).mul( equirectDirPdf( envDirWS ) ).max( float( 1e-8 ) );
534
+ // BRDF technique pdf at the env direction — same solid-angle form as pdfBrdf1 (no V·H).
535
+ const pdfBrdf2 = D.mul( SmithG( NdotV, alpha ) ).div( max( float( 1e-6 ), float( 4 ).mul( NdotV ) ) ).max( float( 1e-8 ) );
536
+ const w2 = misPowerHeuristic( pdfEnv2, pdfBrdf2 );
537
+
538
+ // Specular BRDF (without Fresnel): D·G2 / (4·N·L·N·V), reusing D. Same GGX alpha as the pdf.
539
+ const envBrdfSpec = D.mul( GeometryTerm( envNdotL, NdotV, alpha ) ).div( max( float( 1e-6 ), float( 4 ).mul( envNdotL ).mul( NdotV ) ) );
540
+ const envFresnelWeight = F_Schlick( f0, envVdotH ); // vec3 — chromatic metal tint
541
+
542
+ result.addAssign( sampledColor.mul( envBrdfSpec ).mul( envFresnelWeight ).mul( envNdotL ).div( pdfEnv2 ).mul( w2 ) );
543
+
544
+ } );
545
+
546
+ } );
547
+
548
+ return result.mul( envMapIntensity );
549
+
550
+ }
551
+
552
+ dispose() {
553
+
554
+ this._cdf.dispose();
555
+
556
+ }
557
+
558
+ }
559
+
560
+ export default ImportanceSampledEnvironment;
@@ -1,5 +1,5 @@
1
1
  import { NearestFilter, Vector4, TempNode, NodeUpdateType, PassNode } from 'three/webgpu';
2
- import { nodeObject, Fn, float, uv, uniform, convertToTexture, vec2, vec3, clamp, floor, dot, smoothstep, If, sign, step, mrt, output, normalView, property } from 'three/tsl';
2
+ import { nodeObject, Fn, float, uv, uniform, convertToTexture, vec2, vec3, clamp, floor, dot, smoothstep, If, sign, step, mrt, output, normalView, property, vec4 } from 'three/tsl';
3
3
 
4
4
  /**
5
5
  * A inner node definition that implements the actual pixelation TSL code.
@@ -202,7 +202,7 @@ class PixelationNode extends TempNode {
202
202
 
203
203
  const strength = dei.greaterThan( 0 ).select( float( 1.0 ).sub( dei.mul( this.depthEdgeStrength ) ), nei.mul( this.normalEdgeStrength ).add( 1 ) );
204
204
 
205
- return texel.mul( strength );
205
+ return vec4( texel.mul( strength ).rgb, texel.a );
206
206
 
207
207
  } );
208
208