@plastic-software/three 0.182.0 → 0.183.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (298) hide show
  1. package/LICENSE +1 -1
  2. package/build/three.cjs +11520 -10877
  3. package/build/three.core.js +11732 -11340
  4. package/build/three.core.min.js +2 -2
  5. package/build/three.module.js +509 -262
  6. package/build/three.module.min.js +2 -2
  7. package/build/three.tsl.js +7 -11
  8. package/build/three.tsl.min.js +2 -2
  9. package/build/three.webgpu.js +3072 -2607
  10. package/build/three.webgpu.min.js +2 -2
  11. package/build/three.webgpu.nodes.js +3071 -2607
  12. package/build/three.webgpu.nodes.min.js +2 -2
  13. package/examples/jsm/Addons.js +0 -3
  14. package/examples/jsm/animation/CCDIKSolver.js +2 -2
  15. package/examples/jsm/controls/ArcballControls.js +3 -3
  16. package/examples/jsm/controls/OrbitControls.js +103 -0
  17. package/examples/jsm/effects/AnaglyphEffect.js +102 -7
  18. package/examples/jsm/environments/ColorEnvironment.js +59 -0
  19. package/examples/jsm/environments/RoomEnvironment.js +1 -0
  20. package/examples/jsm/exporters/EXRExporter.js +1 -1
  21. package/examples/jsm/exporters/GLTFExporter.js +131 -4
  22. package/examples/jsm/exporters/USDZExporter.js +22 -3
  23. package/examples/jsm/helpers/AnimationPathHelper.js +302 -0
  24. package/examples/jsm/helpers/ViewHelper.js +67 -8
  25. package/examples/jsm/inspector/Inspector.js +21 -5
  26. package/examples/jsm/inspector/tabs/Console.js +39 -5
  27. package/examples/jsm/inspector/tabs/Parameters.js +16 -0
  28. package/examples/jsm/inspector/ui/Style.js +25 -1
  29. package/examples/jsm/libs/meshopt_decoder.module.js +6 -5
  30. package/examples/jsm/lines/LineMaterial.js +6 -0
  31. package/examples/jsm/loaders/3MFLoader.js +2 -2
  32. package/examples/jsm/loaders/AMFLoader.js +2 -2
  33. package/examples/jsm/loaders/ColladaLoader.js +24 -4026
  34. package/examples/jsm/loaders/EXRLoader.js +5 -5
  35. package/examples/jsm/loaders/FBXLoader.js +2 -2
  36. package/examples/jsm/loaders/GCodeLoader.js +34 -8
  37. package/examples/jsm/loaders/GLTFLoader.js +122 -171
  38. package/examples/jsm/loaders/KMZLoader.js +5 -5
  39. package/examples/jsm/loaders/KTX2Loader.js +5 -5
  40. package/examples/jsm/loaders/LWOLoader.js +7 -39
  41. package/examples/jsm/loaders/NRRDLoader.js +2 -2
  42. package/examples/jsm/loaders/PCDLoader.js +3 -2
  43. package/examples/jsm/loaders/USDLoader.js +100 -40
  44. package/examples/jsm/loaders/UltraHDRLoader.js +182 -30
  45. package/examples/jsm/loaders/VRMLLoader.js +77 -0
  46. package/examples/jsm/loaders/VTKLoader.js +37 -24
  47. package/examples/jsm/loaders/collada/ColladaComposer.js +2950 -0
  48. package/examples/jsm/loaders/collada/ColladaParser.js +1962 -0
  49. package/examples/jsm/loaders/usd/USDAParser.js +447 -366
  50. package/examples/jsm/loaders/usd/USDCParser.js +1841 -6
  51. package/examples/jsm/loaders/usd/USDComposer.js +4041 -0
  52. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +2 -2
  53. package/examples/jsm/objects/LensflareMesh.js +1 -1
  54. package/examples/jsm/objects/Sky.js +76 -4
  55. package/examples/jsm/objects/SkyMesh.js +114 -7
  56. package/examples/jsm/objects/Water.js +4 -3
  57. package/examples/jsm/objects/Water2.js +5 -3
  58. package/examples/jsm/objects/WaterMesh.js +5 -7
  59. package/examples/jsm/physics/JoltPhysics.js +7 -5
  60. package/examples/jsm/physics/RapierPhysics.js +6 -4
  61. package/examples/jsm/postprocessing/EffectComposer.js +7 -5
  62. package/examples/jsm/postprocessing/RenderTransitionPass.js +1 -1
  63. package/examples/jsm/renderers/CSS3DRenderer.js +1 -1
  64. package/examples/jsm/renderers/SVGRenderer.js +2 -2
  65. package/examples/jsm/shaders/GTAOShader.js +19 -6
  66. package/examples/jsm/shaders/HalftoneShader.js +12 -1
  67. package/examples/jsm/shaders/PoissonDenoiseShader.js +6 -2
  68. package/examples/jsm/shaders/SAOShader.js +17 -4
  69. package/examples/jsm/shaders/SSAOShader.js +11 -1
  70. package/examples/jsm/shaders/SSRShader.js +6 -5
  71. package/examples/jsm/shaders/VignetteShader.js +1 -1
  72. package/examples/jsm/tsl/display/AfterImageNode.js +1 -1
  73. package/examples/jsm/tsl/display/AnaglyphPassNode.js +456 -16
  74. package/examples/jsm/tsl/display/AnamorphicNode.js +1 -1
  75. package/examples/jsm/tsl/display/BilateralBlurNode.js +364 -0
  76. package/examples/jsm/tsl/display/BloomNode.js +5 -5
  77. package/examples/jsm/tsl/display/CRT.js +150 -0
  78. package/examples/jsm/tsl/display/DenoiseNode.js +1 -1
  79. package/examples/jsm/tsl/display/DepthOfFieldNode.js +1 -1
  80. package/examples/jsm/tsl/display/DotScreenNode.js +1 -1
  81. package/examples/jsm/tsl/display/FXAANode.js +2 -2
  82. package/examples/jsm/tsl/display/GTAONode.js +2 -2
  83. package/examples/jsm/tsl/display/GaussianBlurNode.js +11 -2
  84. package/examples/jsm/tsl/display/GodraysNode.js +624 -0
  85. package/examples/jsm/tsl/display/LensflareNode.js +1 -1
  86. package/examples/jsm/tsl/display/Lut3DNode.js +1 -1
  87. package/examples/jsm/tsl/display/OutlineNode.js +3 -3
  88. package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +2 -2
  89. package/examples/jsm/tsl/display/PixelationPassNode.js +5 -5
  90. package/examples/jsm/tsl/display/RGBShiftNode.js +2 -2
  91. package/examples/jsm/tsl/display/RetroPassNode.js +263 -0
  92. package/examples/jsm/tsl/display/SMAANode.js +2 -2
  93. package/examples/jsm/tsl/display/SSAAPassNode.js +2 -2
  94. package/examples/jsm/tsl/display/SSGINode.js +2 -2
  95. package/examples/jsm/tsl/display/SSRNode.js +7 -7
  96. package/examples/jsm/tsl/display/SSSNode.js +2 -2
  97. package/examples/jsm/tsl/display/Shape.js +29 -0
  98. package/examples/jsm/tsl/display/SobelOperatorNode.js +2 -2
  99. package/examples/jsm/tsl/display/StereoPassNode.js +1 -2
  100. package/examples/jsm/tsl/display/TRAANode.js +9 -12
  101. package/examples/jsm/tsl/display/TransitionNode.js +1 -1
  102. package/examples/jsm/tsl/display/depthAwareBlend.js +80 -0
  103. package/examples/jsm/tsl/math/Bayer.js +40 -1
  104. package/examples/jsm/utils/LDrawUtils.js +1 -1
  105. package/package.json +11 -19
  106. package/src/Three.Core.js +1 -1
  107. package/src/Three.TSL.js +5 -9
  108. package/src/Three.WebGPU.Nodes.js +2 -0
  109. package/src/Three.WebGPU.js +3 -0
  110. package/src/Three.js +1 -0
  111. package/src/animation/AnimationAction.js +1 -1
  112. package/src/animation/AnimationClip.js +1 -1
  113. package/src/animation/AnimationMixer.js +6 -0
  114. package/src/animation/KeyframeTrack.js +46 -7
  115. package/src/animation/PropertyMixer.js +4 -4
  116. package/src/audio/Audio.js +1 -1
  117. package/src/audio/AudioListener.js +5 -3
  118. package/src/cameras/Camera.js +32 -2
  119. package/src/cameras/CubeCamera.js +20 -0
  120. package/src/constants.js +30 -1
  121. package/src/core/Clock.js +7 -0
  122. package/src/core/Object3D.js +56 -4
  123. package/src/core/RenderTarget.js +3 -4
  124. package/src/extras/PMREMGenerator.js +4 -8
  125. package/src/geometries/TorusGeometry.js +8 -3
  126. package/src/helpers/CameraHelper.js +3 -0
  127. package/src/helpers/DirectionalLightHelper.js +4 -1
  128. package/src/helpers/HemisphereLightHelper.js +3 -0
  129. package/src/helpers/PointLightHelper.js +0 -24
  130. package/src/helpers/SpotLightHelper.js +3 -0
  131. package/src/lights/LightShadow.js +15 -3
  132. package/src/lights/webgpu/IESSpotLight.js +2 -1
  133. package/src/loaders/Cache.js +28 -0
  134. package/src/loaders/FileLoader.js +1 -1
  135. package/src/loaders/ImageBitmapLoader.js +8 -3
  136. package/src/loaders/Loader.js +6 -0
  137. package/src/loaders/ObjectLoader.js +18 -1
  138. package/src/materials/MeshLambertMaterial.js +9 -0
  139. package/src/materials/MeshPhongMaterial.js +9 -0
  140. package/src/materials/nodes/Line2NodeMaterial.js +5 -5
  141. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +2 -0
  142. package/src/materials/nodes/NodeMaterial.js +15 -24
  143. package/src/materials/nodes/manager/NodeMaterialObserver.js +9 -3
  144. package/src/math/Line3.js +3 -5
  145. package/src/math/MathUtils.js +10 -10
  146. package/src/math/Matrix4.js +35 -26
  147. package/src/math/Quaternion.js +3 -29
  148. package/src/math/Vector3.js +3 -3
  149. package/src/math/interpolants/BezierInterpolant.js +108 -0
  150. package/src/nodes/Nodes.js +87 -68
  151. package/src/nodes/TSL.js +2 -5
  152. package/src/nodes/accessors/Arrays.js +1 -1
  153. package/src/nodes/accessors/Bitangent.js +5 -5
  154. package/src/nodes/accessors/BufferAttributeNode.js +1 -1
  155. package/src/nodes/accessors/Camera.js +149 -28
  156. package/src/nodes/accessors/InstanceNode.js +105 -40
  157. package/src/nodes/accessors/Normal.js +9 -9
  158. package/src/nodes/accessors/Position.js +34 -2
  159. package/src/nodes/accessors/SceneProperties.js +53 -0
  160. package/src/nodes/accessors/SkinningNode.js +12 -24
  161. package/src/nodes/accessors/StorageBufferNode.js +0 -19
  162. package/src/nodes/accessors/StorageTextureNode.js +37 -1
  163. package/src/nodes/accessors/Tangent.js +3 -3
  164. package/src/nodes/accessors/Texture3DNode.js +6 -34
  165. package/src/nodes/accessors/TextureNode.js +58 -22
  166. package/src/nodes/accessors/UniformArrayNode.js +2 -0
  167. package/src/nodes/core/MRTNode.js +48 -2
  168. package/src/nodes/core/Node.js +29 -3
  169. package/src/nodes/core/NodeBuilder.js +115 -40
  170. package/src/nodes/core/NodeError.js +28 -0
  171. package/src/nodes/core/NodeUtils.js +5 -3
  172. package/src/nodes/core/OutputStructNode.js +12 -10
  173. package/src/nodes/core/ParameterNode.js +2 -1
  174. package/src/nodes/core/StackNode.js +9 -8
  175. package/src/nodes/core/StackTrace.js +139 -0
  176. package/src/nodes/core/StructNode.js +15 -0
  177. package/src/nodes/core/SubBuildNode.js +1 -1
  178. package/src/nodes/core/UniformNode.js +2 -1
  179. package/src/nodes/core/VarNode.js +1 -1
  180. package/src/nodes/core/VaryingNode.js +1 -18
  181. package/src/nodes/display/BlendModes.js +0 -64
  182. package/src/nodes/display/ColorAdjustment.js +17 -0
  183. package/src/nodes/display/ColorSpaceNode.js +3 -3
  184. package/src/nodes/display/NormalMapNode.js +2 -2
  185. package/src/nodes/display/PassNode.js +21 -2
  186. package/src/nodes/display/RenderOutputNode.js +3 -3
  187. package/src/nodes/display/ScreenNode.js +2 -1
  188. package/src/nodes/display/ToneMappingNode.js +1 -1
  189. package/src/nodes/display/ToonOutlinePassNode.js +2 -2
  190. package/src/nodes/display/ViewportDepthNode.js +52 -4
  191. package/src/nodes/display/ViewportTextureNode.js +21 -4
  192. package/src/nodes/fog/Fog.js +18 -35
  193. package/src/nodes/functions/PhysicalLightingModel.js +25 -3
  194. package/src/nodes/geometry/RangeNode.js +4 -2
  195. package/src/nodes/gpgpu/ComputeNode.js +5 -4
  196. package/src/nodes/gpgpu/WorkgroupInfoNode.js +2 -1
  197. package/src/nodes/lighting/EnvironmentNode.js +28 -3
  198. package/src/nodes/lighting/PointShadowNode.js +24 -12
  199. package/src/nodes/lighting/ShadowFilterNode.js +15 -43
  200. package/src/nodes/lighting/ShadowNode.js +54 -32
  201. package/src/nodes/math/ConditionalNode.js +2 -2
  202. package/src/nodes/math/MathNode.js +3 -40
  203. package/src/nodes/math/OperatorNode.js +2 -1
  204. package/src/nodes/pmrem/PMREMUtils.js +9 -15
  205. package/src/nodes/tsl/TSLCore.js +13 -10
  206. package/src/nodes/utils/DebugNode.js +11 -11
  207. package/src/nodes/utils/JoinNode.js +2 -2
  208. package/src/nodes/utils/LoopNode.js +1 -1
  209. package/src/nodes/utils/MemberNode.js +1 -1
  210. package/src/nodes/utils/RTTNode.js +1 -1
  211. package/src/nodes/utils/ReflectorNode.js +2 -3
  212. package/src/nodes/utils/SpriteSheetUV.js +35 -0
  213. package/src/nodes/utils/UVUtils.js +4 -2
  214. package/src/objects/BatchedMesh.js +22 -12
  215. package/src/objects/InstancedMesh.js +11 -0
  216. package/src/renderers/WebGLRenderer.js +34 -60
  217. package/src/renderers/common/Backend.js +21 -0
  218. package/src/renderers/common/Background.js +7 -4
  219. package/src/renderers/common/BindGroup.js +1 -9
  220. package/src/renderers/common/Bindings.js +20 -5
  221. package/src/renderers/common/BlendMode.js +143 -0
  222. package/src/renderers/common/BundleGroup.js +1 -1
  223. package/src/renderers/common/CubeRenderTarget.js +50 -6
  224. package/src/renderers/common/Geometries.js +17 -3
  225. package/src/renderers/common/Lighting.js +5 -21
  226. package/src/renderers/common/Pipelines.js +4 -4
  227. package/src/renderers/common/PostProcessing.js +8 -206
  228. package/src/renderers/common/RenderBundles.js +2 -1
  229. package/src/renderers/common/RenderContext.js +16 -0
  230. package/src/renderers/common/RenderContexts.js +33 -56
  231. package/src/renderers/common/RenderLists.js +2 -1
  232. package/src/renderers/common/RenderObject.js +2 -3
  233. package/src/renderers/common/RenderObjectPipeline.js +40 -0
  234. package/src/renderers/common/RenderObjects.js +18 -2
  235. package/src/renderers/common/RenderPipeline.js +203 -17
  236. package/src/renderers/common/Renderer.js +207 -40
  237. package/src/renderers/common/Sampler.js +4 -4
  238. package/src/renderers/common/StorageBuffer.js +13 -1
  239. package/src/renderers/common/Textures.js +16 -0
  240. package/src/renderers/common/TimestampQueryPool.js +5 -3
  241. package/src/renderers/common/Uniform.js +8 -0
  242. package/src/renderers/common/UniformsGroup.js +60 -0
  243. package/src/renderers/common/XRManager.js +2 -2
  244. package/src/renderers/common/nodes/NodeBuilderState.js +1 -1
  245. package/src/renderers/common/nodes/{Nodes.js → NodeManager.js} +18 -6
  246. package/src/renderers/common/nodes/NodeStorageBuffer.js +13 -2
  247. package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +2 -2
  248. package/src/renderers/shaders/ShaderChunk/color_fragment.glsl.js +1 -5
  249. package/src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl.js +1 -5
  250. package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +1 -5
  251. package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +8 -10
  252. package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +7 -11
  253. package/src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js +6 -0
  254. package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +6 -2
  255. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +23 -1
  256. package/src/renderers/shaders/ShaderChunk/packing.glsl.js +20 -4
  257. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +55 -24
  258. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +2 -0
  259. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +2 -0
  260. package/src/renderers/shaders/ShaderLib/shadow.glsl.js +1 -0
  261. package/src/renderers/shaders/ShaderLib.js +4 -2
  262. package/src/renderers/shaders/UniformsLib.js +0 -3
  263. package/src/renderers/webgl/WebGLBackground.js +2 -2
  264. package/src/renderers/webgl/WebGLBindingStates.js +99 -27
  265. package/src/renderers/webgl/WebGLEnvironments.js +228 -0
  266. package/src/renderers/webgl/WebGLGeometries.js +10 -7
  267. package/src/renderers/webgl/WebGLMaterials.js +12 -0
  268. package/src/renderers/webgl/WebGLObjects.js +3 -1
  269. package/src/renderers/webgl/WebGLProgram.js +2 -2
  270. package/src/renderers/webgl/WebGLPrograms.js +10 -4
  271. package/src/renderers/webgl/WebGLRenderLists.js +15 -0
  272. package/src/renderers/webgl/WebGLShadowMap.js +5 -4
  273. package/src/renderers/webgl/WebGLState.js +12 -17
  274. package/src/renderers/webgl-fallback/WebGLBackend.js +71 -7
  275. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +98 -29
  276. package/src/renderers/webgl-fallback/utils/WebGLState.js +168 -7
  277. package/src/renderers/webgpu/WebGPUBackend.js +58 -9
  278. package/src/renderers/webgpu/WebGPURenderer.js +1 -0
  279. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +257 -45
  280. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +8 -19
  281. package/src/renderers/webgpu/utils/WebGPUConstants.js +1 -1
  282. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +56 -31
  283. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +152 -200
  284. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +25 -25
  285. package/src/renderers/webgpu/utils/WebGPUUtils.js +10 -6
  286. package/src/renderers/webxr/WebXRManager.js +2 -2
  287. package/src/textures/Texture.js +2 -2
  288. package/src/utils.js +246 -3
  289. package/examples/jsm/materials/MeshGouraudMaterial.js +0 -433
  290. package/examples/jsm/materials/MeshPostProcessingMaterial.js +0 -167
  291. package/examples/jsm/shaders/GodRaysShader.js +0 -333
  292. package/src/nodes/accessors/SceneNode.js +0 -145
  293. package/src/nodes/code/ScriptableNode.js +0 -726
  294. package/src/nodes/code/ScriptableValueNode.js +0 -253
  295. package/src/nodes/display/PosterizeNode.js +0 -65
  296. package/src/nodes/utils/SpriteSheetUVNode.js +0 -90
  297. package/src/renderers/webgl/WebGLCubeMaps.js +0 -99
  298. package/src/renderers/webgl/WebGLCubeUVMaps.js +0 -134
@@ -80,13 +80,13 @@ class ViewportTextureNode extends TextureNode {
80
80
  this.isOutputTextureNode = true;
81
81
 
82
82
  /**
83
- * The `updateBeforeType` is set to `NodeUpdateType.FRAME` since the node renders the
84
- * scene once per frame in its {@link ViewportTextureNode#updateBefore} method.
83
+ * The `updateBeforeType` is set to `NodeUpdateType.RENDER` since the node should extract
84
+ * the current contents of the bound framebuffer for each render call.
85
85
  *
86
86
  * @type {string}
87
- * @default 'frame'
87
+ * @default 'render'
88
88
  */
89
- this.updateBeforeType = NodeUpdateType.FRAME;
89
+ this.updateBeforeType = NodeUpdateType.RENDER;
90
90
 
91
91
  /**
92
92
  * The framebuffer texture for the current renderer context.
@@ -226,3 +226,20 @@ export const viewportTexture = /*@__PURE__*/ nodeProxy( ViewportTextureNode ).se
226
226
  * @returns {ViewportTextureNode}
227
227
  */
228
228
  export const viewportMipTexture = /*@__PURE__*/ nodeProxy( ViewportTextureNode, null, null, { generateMipmaps: true } ).setParameterLength( 0, 3 );
229
+
230
+ // Singleton instances for common usage
231
+ const _singletonOpaqueViewportTextureNode = /*@__PURE__*/ viewportMipTexture();
232
+
233
+ /**
234
+ * TSL function for creating a viewport texture node with enabled mipmap generation.
235
+ * The texture should only contain the opaque rendering objects.
236
+ *
237
+ * This should be used just in transparent or transmissive materials.
238
+ *
239
+ * @tsl
240
+ * @function
241
+ * @param {?Node} [uv=screenUV] - The uv node.
242
+ * @param {?Node} [level=null] - The level node.
243
+ * @returns {ViewportTextureNode}
244
+ */
245
+ export const viewportOpaqueMipTexture = ( uv = screenUV, level = null ) => _singletonOpaqueViewportTextureNode.sample( uv, level ); // TODO: Use once() when sample() supports it
@@ -1,7 +1,6 @@
1
- import { positionView } from '../accessors/Position.js';
1
+ import { positionView, positionWorld } from '../accessors/Position.js';
2
2
  import { smoothstep } from '../math/MathNode.js';
3
3
  import { Fn, output, vec4 } from '../tsl/TSLBase.js';
4
- import { warn } from '../../utils.js';
5
4
 
6
5
  /**
7
6
  * Returns a node that represents the `z` coordinate in view space
@@ -64,51 +63,35 @@ export const densityFogFactor = Fn( ( [ density ], builder ) => {
64
63
  } );
65
64
 
66
65
  /**
67
- * This class can be used to configure a fog for the scene.
68
- * Nodes of this type are assigned to `Scene.fogNode`.
66
+ * Constructs a new height fog factor node. This fog factor requires a Y-up coordinate system.
69
67
  *
70
68
  * @tsl
71
69
  * @function
72
- * @param {Node} color - Defines the color of the fog.
73
- * @param {Node} factor - Defines how the fog is factored in the scene.
70
+ * @param {Node} density - Defines the fog density.
71
+ * @param {Node} height - The height threshold in world space. Everything below this y-coordinate is affected by fog.
74
72
  */
75
- export const fog = Fn( ( [ color, factor ] ) => {
76
-
77
- return vec4( factor.toFloat().mix( output.rgb, color.toVec3() ), output.a );
78
-
79
- } );
73
+ export const exponentialHeightFogFactor = Fn( ( [ density, height ], builder ) => {
80
74
 
81
- // Deprecated
75
+ const viewZ = getViewZNode( builder );
82
76
 
83
- /**
84
- * @tsl
85
- * @function
86
- * @deprecated since r171. Use `fog( color, rangeFogFactor( near, far ) )` instead.
87
- *
88
- * @param {Node} color
89
- * @param {Node} near
90
- * @param {Node} far
91
- * @returns {Function}
92
- */
93
- export function rangeFog( color, near, far ) { // @deprecated, r171
77
+ const distance = height.sub( positionWorld.y ).max( 0 ).toConst();
78
+ const m = distance.mul( viewZ ).toConst();
94
79
 
95
- warn( 'TSL: "rangeFog( color, near, far )" is deprecated. Use "fog( color, rangeFogFactor( near, far ) )" instead.' );
96
- return fog( color, rangeFogFactor( near, far ) );
80
+ return density.mul( density, m, m ).negate().exp().oneMinus();
97
81
 
98
- }
82
+ } );
99
83
 
100
84
  /**
85
+ * This class can be used to configure a fog for the scene.
86
+ * Nodes of this type are assigned to `Scene.fogNode`.
87
+ *
101
88
  * @tsl
102
89
  * @function
103
- * @deprecated since r171. Use `fog( color, densityFogFactor( density ) )` instead.
104
- *
105
- * @param {Node} color
106
- * @param {Node} density
107
- * @returns {Function}
90
+ * @param {Node} color - Defines the color of the fog.
91
+ * @param {Node} factor - Defines how the fog is factored in the scene.
108
92
  */
109
- export function densityFog( color, density ) { // @deprecated, r171
93
+ export const fog = Fn( ( [ color, factor ] ) => {
110
94
 
111
- warn( 'TSL: "densityFog( color, density )" is deprecated. Use "fog( color, densityFogFactor( density ) )" instead.' );
112
- return fog( color, densityFogFactor( density ) );
95
+ return vec4( factor.toFloat().mix( output.rgb, color.toVec3() ), output.a );
113
96
 
114
- }
97
+ } );
@@ -17,7 +17,7 @@ import { div } from '../math/OperatorNode.js';
17
17
  import { cameraPosition, cameraProjectionMatrix, cameraViewMatrix } from '../accessors/Camera.js';
18
18
  import { modelWorldMatrix } from '../accessors/ModelNode.js';
19
19
  import { screenSize } from '../display/ScreenNode.js';
20
- import { viewportMipTexture } from '../display/ViewportTextureNode.js';
20
+ import { viewportMipTexture, viewportOpaqueMipTexture } from '../display/ViewportTextureNode.js';
21
21
  import { textureBicubicLevel } from '../accessors/TextureBicubic.js';
22
22
  import { Loop } from '../utils/LoopNode.js';
23
23
  import { BackSide } from '../../constants.js';
@@ -69,7 +69,7 @@ const applyIorToRoughness = /*@__PURE__*/ Fn( ( [ roughness, ior ] ) => {
69
69
  } );
70
70
 
71
71
  const viewportBackSideTexture = /*@__PURE__*/ viewportMipTexture();
72
- const viewportFrontSideTexture = /*@__PURE__*/ viewportMipTexture();
72
+ const viewportFrontSideTexture = /*@__PURE__*/ viewportOpaqueMipTexture();
73
73
 
74
74
  const getTransmissionSample = /*@__PURE__*/ Fn( ( [ fragCoord, roughness, ior ], { material } ) => {
75
75
 
@@ -658,12 +658,34 @@ class PhysicalLightingModel extends LightingModel {
658
658
 
659
659
  // LTC Fresnel Approximation by Stephen Hill
660
660
  // http://blog.selfshadow.com/publications/s2016-advances/s2016_ltc_fresnel.pdf
661
- const fresnel = specularColorBlended.mul( t2.x ).add( specularColorBlended.oneMinus().mul( t2.y ) ).toVar();
661
+ const fresnel = specularColorBlended.mul( t2.x ).add( specularF90.sub( specularColorBlended ).mul( t2.y ) ).toVar();
662
662
 
663
663
  reflectedLight.directSpecular.addAssign( lightColor.mul( fresnel ).mul( LTC_Evaluate( { N, V, P, mInv, p0, p1, p2, p3 } ) ) );
664
664
 
665
665
  reflectedLight.directDiffuse.addAssign( lightColor.mul( diffuseContribution ).mul( LTC_Evaluate( { N, V, P, mInv: mat3( 1, 0, 0, 0, 1, 0, 0, 0, 1 ), p0, p1, p2, p3 } ) ) );
666
666
 
667
+ if ( this.clearcoat === true ) {
668
+
669
+ const Ncc = clearcoatNormalView;
670
+
671
+ const uvClearcoat = LTC_Uv( { N: Ncc, V, roughness: clearcoatRoughness } );
672
+
673
+ const t1Clearcoat = ltc_1.sample( uvClearcoat );
674
+ const t2Clearcoat = ltc_2.sample( uvClearcoat );
675
+
676
+ const mInvClearcoat = mat3(
677
+ vec3( t1Clearcoat.x, 0, t1Clearcoat.y ),
678
+ vec3( 0, 1, 0 ),
679
+ vec3( t1Clearcoat.z, 0, t1Clearcoat.w )
680
+ );
681
+
682
+ // LTC Fresnel Approximation for clearcoat
683
+ const fresnelClearcoat = clearcoatF0.mul( t2Clearcoat.x ).add( clearcoatF90.sub( clearcoatF0 ).mul( t2Clearcoat.y ) );
684
+
685
+ this.clearcoatSpecularDirect.addAssign( lightColor.mul( fresnelClearcoat ).mul( LTC_Evaluate( { N: Ncc, V, P, mInv: mInvClearcoat, p0, p1, p2, p3 } ) ) );
686
+
687
+ }
688
+
667
689
  }
668
690
 
669
691
  /**
@@ -1,4 +1,5 @@
1
1
  import Node from '../core/Node.js';
2
+ import NodeError from '../core/NodeError.js';
2
3
  import { getValueType } from '../core/NodeUtils.js';
3
4
  import { buffer } from '../accessors/BufferNode.js';
4
5
  import { instancedBufferAttribute } from '../accessors/BufferAttributeNode.js';
@@ -111,7 +112,7 @@ class RangeNode extends Node {
111
112
 
112
113
  if ( output === null ) {
113
114
 
114
- throw new Error( 'THREE.TSL: No "ConstNode" found in node graph.' );
115
+ throw new NodeError( 'THREE.TSL: No "ConstNode" found in node graph.', this.stackTrace );
115
116
 
116
117
  }
117
118
 
@@ -167,8 +168,9 @@ class RangeNode extends Node {
167
168
  }
168
169
 
169
170
  const nodeType = this.getNodeType( builder );
171
+ const uniformBufferSize = object.count * 4 * 4; // count * 4 components * 4 bytes (float)
170
172
 
171
- if ( object.count <= 4096 ) {
173
+ if ( uniformBufferSize <= builder.getUniformBufferLimit() ) {
172
174
 
173
175
  output = buffer( array, 'vec4', object.count ).element( instanceIndex ).convert( nodeType );
174
176
 
@@ -1,4 +1,5 @@
1
1
  import Node from '../core/Node.js';
2
+ import StackTrace from '../core/StackTrace.js';
2
3
  import { NodeUpdateType } from '../core/constants.js';
3
4
  import { addMethodChaining, nodeObject } from '../tsl/TSLCore.js';
4
5
  import { warn, error } from '../../utils.js';
@@ -148,7 +149,7 @@ class ComputeNode extends Node {
148
149
  */
149
150
  label( name ) {
150
151
 
151
- warn( 'TSL: "label()" has been deprecated. Use "setName()" instead.' ); // @deprecated r179
152
+ warn( 'TSL: "label()" has been deprecated. Use "setName()" instead.', new StackTrace() ); // @deprecated r179
152
153
 
153
154
  return this.setName( name );
154
155
 
@@ -242,7 +243,7 @@ export const computeKernel = ( node, workgroupSize = [ 64 ] ) => {
242
243
 
243
244
  if ( workgroupSize.length === 0 || workgroupSize.length > 3 ) {
244
245
 
245
- error( 'TSL: compute() workgroupSize must have 1, 2, or 3 elements' );
246
+ error( 'TSL: compute() workgroupSize must have 1, 2, or 3 elements', new StackTrace() );
246
247
 
247
248
  }
248
249
 
@@ -252,7 +253,7 @@ export const computeKernel = ( node, workgroupSize = [ 64 ] ) => {
252
253
 
253
254
  if ( typeof val !== 'number' || val <= 0 || ! Number.isInteger( val ) ) {
254
255
 
255
- error( `TSL: compute() workgroupSize element at index [ ${ i } ] must be a positive integer` );
256
+ error( `TSL: compute() workgroupSize element at index [ ${ i } ] must be a positive integer`, new StackTrace() );
256
257
 
257
258
  }
258
259
 
@@ -264,7 +265,7 @@ export const computeKernel = ( node, workgroupSize = [ 64 ] ) => {
264
265
 
265
266
  //
266
267
 
267
- return nodeObject( new ComputeNode( nodeObject( node ), workgroupSize ) );
268
+ return new ComputeNode( nodeObject( node ), workgroupSize );
268
269
 
269
270
  };
270
271
 
@@ -1,6 +1,7 @@
1
1
  import ArrayElementNode from '../utils/ArrayElementNode.js';
2
2
  import Node from '../core/Node.js';
3
3
  import { warn } from '../../utils.js';
4
+ import StackTrace from '../core/StackTrace.js';
4
5
 
5
6
  /**
6
7
  * Represents an element of a 'workgroup' scoped buffer.
@@ -149,7 +150,7 @@ class WorkgroupInfoNode extends Node {
149
150
  */
150
151
  label( name ) {
151
152
 
152
- warn( 'TSL: "label()" has been deprecated. Use "setName()" instead.' ); // @deprecated r179
153
+ warn( 'TSL: "label()" has been deprecated. Use "setName()" instead.', new StackTrace() ); // @deprecated r179
153
154
 
154
155
  return this.setName( name );
155
156
 
@@ -9,7 +9,7 @@ import { bentNormalView } from '../accessors/AccessorsUtils.js';
9
9
  import { pmremTexture } from '../pmrem/PMREMNode.js';
10
10
  import { materialEnvIntensity } from '../accessors/MaterialProperties.js';
11
11
 
12
- const _envNodeCache = new WeakMap();
12
+ const _rendererCache = new WeakMap();
13
13
 
14
14
  /**
15
15
  * Represents a physical model for Image-based lighting (IBL). The environment
@@ -55,13 +55,15 @@ class EnvironmentNode extends LightingNode {
55
55
 
56
56
  const value = ( envNode.isTextureNode ) ? envNode.value : material[ envNode.property ];
57
57
 
58
- let cacheEnvNode = _envNodeCache.get( value );
58
+ const cache = this._getPMREMNodeCache( builder.renderer );
59
+
60
+ let cacheEnvNode = cache.get( value );
59
61
 
60
62
  if ( cacheEnvNode === undefined ) {
61
63
 
62
64
  cacheEnvNode = pmremTexture( value );
63
65
 
64
- _envNodeCache.set( value, cacheEnvNode );
66
+ cache.set( value, cacheEnvNode );
65
67
 
66
68
  }
67
69
 
@@ -101,6 +103,29 @@ class EnvironmentNode extends LightingNode {
101
103
 
102
104
  }
103
105
 
106
+ /**
107
+ * Returns the PMREM node cache of the current renderer.
108
+ *
109
+ * @private
110
+ * @param {Renderer} renderer - The current renderer.
111
+ * @return {WeakMap} The node cache.
112
+ */
113
+ _getPMREMNodeCache( renderer ) {
114
+
115
+ let pmremCache = _rendererCache.get( renderer );
116
+
117
+ if ( pmremCache === undefined ) {
118
+
119
+ pmremCache = new WeakMap();
120
+
121
+ _rendererCache.set( renderer, pmremCache );
122
+
123
+ }
124
+
125
+ return pmremCache;
126
+
127
+ }
128
+
104
129
  }
105
130
 
106
131
  export default EnvironmentNode;
@@ -7,11 +7,12 @@ import { renderGroup } from '../core/UniformGroupNode.js';
7
7
  import { Matrix4 } from '../../math/Matrix4.js';
8
8
  import { Vector3 } from '../../math/Vector3.js';
9
9
  import { Color } from '../../math/Color.js';
10
- import { BasicShadowMap, LessCompare, WebGPUCoordinateSystem } from '../../constants.js';
10
+ import { BasicShadowMap, GreaterEqualCompare, LessEqualCompare, WebGPUCoordinateSystem } from '../../constants.js';
11
11
  import { CubeDepthTexture } from '../../textures/CubeDepthTexture.js';
12
12
  import { screenCoordinate } from '../display/ScreenNode.js';
13
13
  import { interleavedGradientNoise, vogelDiskSample } from '../utils/PostProcessingUtils.js';
14
14
  import { abs, normalize, cross } from '../math/MathNode.js';
15
+ import { viewZToPerspectiveDepth, viewZToReversedPerspectiveDepth } from '../display/ViewportDepthNode.js';
15
16
 
16
17
  const _clearColor = /*@__PURE__*/ new Color();
17
18
  const _projScreenMatrix = /*@__PURE__*/ new Matrix4();
@@ -93,27 +94,38 @@ export const PointShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, bd3D, dp, s
93
94
 
94
95
  } );
95
96
 
96
- const pointShadowFilter = /*@__PURE__*/ Fn( ( { filterFn, depthTexture, shadowCoord, shadow } ) => {
97
+ const pointShadowFilter = /*@__PURE__*/ Fn( ( { filterFn, depthTexture, shadowCoord, shadow }, builder ) => {
97
98
 
98
99
  // for point lights, the uniform @vShadowCoord is re-purposed to hold
99
100
  // the vector from the light to the world-space position of the fragment.
100
- const lightToPosition = shadowCoord.xyz.toVar();
101
- const lightToPositionLength = lightToPosition.length();
101
+ const shadowPosition = shadowCoord.xyz.toConst();
102
+ const shadowPositionAbs = shadowPosition.abs().toConst();
103
+ const viewZ = shadowPositionAbs.x.max( shadowPositionAbs.y ).max( shadowPositionAbs.z );
102
104
 
103
- const cameraNearLocal = uniform( 'float' ).setGroup( renderGroup ).onRenderUpdate( () => shadow.camera.near );
104
- const cameraFarLocal = uniform( 'float' ).setGroup( renderGroup ).onRenderUpdate( () => shadow.camera.far );
105
+ const shadowCameraNear = uniform( 'float' ).setGroup( renderGroup ).onRenderUpdate( () => shadow.camera.near );
106
+ const shadowCameraFar = uniform( 'float' ).setGroup( renderGroup ).onRenderUpdate( () => shadow.camera.far );
105
107
  const bias = reference( 'bias', 'float', shadow ).setGroup( renderGroup );
106
108
 
107
109
  const result = float( 1.0 ).toVar();
108
110
 
109
- If( lightToPositionLength.sub( cameraFarLocal ).lessThanEqual( 0.0 ).and( lightToPositionLength.sub( cameraNearLocal ).greaterThanEqual( 0.0 ) ), () => {
111
+ If( viewZ.sub( shadowCameraFar ).lessThanEqual( 0.0 ).and( viewZ.sub( shadowCameraNear ).greaterThanEqual( 0.0 ) ), () => {
110
112
 
111
- // dp = normalized distance from light to fragment position
112
- const dp = lightToPositionLength.sub( cameraNearLocal ).div( cameraFarLocal.sub( cameraNearLocal ) ).toVar(); // need to clamp?
113
- dp.addAssign( bias );
113
+ let dp;
114
+
115
+ if ( builder.renderer.reversedDepthBuffer ) {
116
+
117
+ dp = viewZToReversedPerspectiveDepth( viewZ.negate(), shadowCameraNear, shadowCameraFar );
118
+ dp.subAssign( bias );
119
+
120
+ } else {
121
+
122
+ dp = viewZToPerspectiveDepth( viewZ.negate(), shadowCameraNear, shadowCameraFar );
123
+ dp.addAssign( bias );
124
+
125
+ }
114
126
 
115
127
  // bd3D = base direction 3D (direction from light to fragment)
116
- const bd3D = lightToPosition.normalize();
128
+ const bd3D = shadowPosition.normalize();
117
129
 
118
130
  // percentage-closer filtering using cube texture sampling
119
131
  result.assign( filterFn( { depthTexture, bd3D, dp, shadow } ) );
@@ -205,7 +217,7 @@ class PointShadowNode extends ShadowNode {
205
217
 
206
218
  const depthTexture = new CubeDepthTexture( shadow.mapSize.width );
207
219
  depthTexture.name = 'PointShadowDepthTexture';
208
- depthTexture.compareFunction = LessCompare;
220
+ depthTexture.compareFunction = builder.renderer.reversedDepthBuffer ? GreaterEqualCompare : LessEqualCompare;
209
221
 
210
222
  const shadowMap = builder.createCubeRenderTarget( shadow.mapSize.width );
211
223
  shadowMap.texture.name = 'PointShadowMap';
@@ -5,10 +5,9 @@ import { mix, fract, step, max, clamp } from '../math/MathNode.js';
5
5
  import { add, sub } from '../math/OperatorNode.js';
6
6
  import { renderGroup } from '../core/UniformGroupNode.js';
7
7
  import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
8
- import { objectPosition } from '../accessors/Object3DNode.js';
9
- import { positionWorld } from '../accessors/Position.js';
10
8
  import { screenCoordinate } from '../display/ScreenNode.js';
11
9
  import { interleavedGradientNoise, vogelDiskSample } from '../utils/PostProcessingUtils.js';
10
+ import { NoBlending } from '../../constants.js';
12
11
 
13
12
  const shadowMaterialLib = /*@__PURE__*/ new WeakMap();
14
13
 
@@ -174,7 +173,7 @@ export const PCFSoftShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, shadowCoo
174
173
  * @param {Node<vec3>} inputs.shadowCoord - The shadow coordinates.
175
174
  * @return {Node<float>} The filtering result.
176
175
  */
177
- export const VSMShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, shadowCoord, depthLayer } ) => {
176
+ export const VSMShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, shadowCoord, depthLayer }, builder ) => {
178
177
 
179
178
  let distribution = texture( depthTexture ).sample( shadowCoord.xy );
180
179
 
@@ -189,53 +188,28 @@ export const VSMShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, shadowCoord,
189
188
  const mean = distribution.x;
190
189
  const variance = max( 0.0000001, distribution.y.mul( distribution.y ) );
191
190
 
192
- const hardShadow = step( shadowCoord.z, mean );
191
+ const hardShadow = ( builder.renderer.reversedDepthBuffer ) ? step( mean, shadowCoord.z ) : step( shadowCoord.z, mean );
193
192
 
194
- // Early return if fully lit
195
- If( hardShadow.equal( 1.0 ), () => {
193
+ const output = float( 1 ).toVar(); // default, fully lit
196
194
 
197
- return float( 1.0 );
195
+ If( hardShadow.notEqual( 1.0 ), () => {
198
196
 
199
- } );
200
-
201
- // Distance from mean
202
- const d = shadowCoord.z.sub( mean );
203
-
204
- // Chebyshev's inequality for upper bound on probability
205
- let p_max = variance.div( variance.add( d.mul( d ) ) );
206
-
207
- // Reduce light bleeding by remapping [amount, 1] to [0, 1]
208
- p_max = clamp( sub( p_max, 0.3 ).div( 0.65 ) );
197
+ // Distance from mean
198
+ const d = shadowCoord.z.sub( mean );
209
199
 
210
- return max( hardShadow, p_max );
200
+ // Chebyshev's inequality for upper bound on probability
201
+ let p_max = variance.div( variance.add( d.mul( d ) ) );
211
202
 
212
- } );
213
-
214
- //
203
+ // Reduce light bleeding by remapping [amount, 1] to [0, 1]
204
+ p_max = clamp( sub( p_max, 0.3 ).div( 0.65 ) );
215
205
 
216
- const linearDistance = /*@__PURE__*/ Fn( ( [ position, cameraNear, cameraFar ] ) => {
206
+ output.assign( max( hardShadow, p_max ) );
217
207
 
218
- let dist = positionWorld.sub( position ).length();
219
- dist = dist.sub( cameraNear ).div( cameraFar.sub( cameraNear ) );
220
- dist = dist.saturate(); // clamp to [ 0, 1 ]
221
-
222
- return dist;
208
+ } );
209
+ return output;
223
210
 
224
211
  } );
225
212
 
226
- const linearShadowDistance = ( light ) => {
227
-
228
- const camera = light.shadow.camera;
229
-
230
- const nearDistance = reference( 'near', 'float', camera ).setGroup( renderGroup );
231
- const farDistance = reference( 'far', 'float', camera ).setGroup( renderGroup );
232
-
233
- const referencePosition = objectPosition( light );
234
-
235
- return linearDistance( referencePosition, nearDistance, farDistance );
236
-
237
- };
238
-
239
213
  /**
240
214
  * Retrieves or creates a shadow material for the given light source.
241
215
  *
@@ -256,13 +230,11 @@ export const getShadowMaterial = ( light ) => {
256
230
 
257
231
  if ( material === undefined ) {
258
232
 
259
- const depthNode = light.isPointLight ? linearShadowDistance( light ) : null;
260
-
261
233
  material = new NodeMaterial();
262
234
  material.colorNode = vec4( 0, 0, 0, 1 );
263
- material.depthNode = depthNode;
264
235
  material.isShadowPassMaterial = true; // Use to avoid other overrideMaterial override material.colorNode unintentionally when using material.shadowNode
265
236
  material.name = 'ShadowMaterial';
237
+ material.blending = NoBlending;
266
238
  material.fog = false;
267
239
 
268
240
  shadowMaterialLib.set( light, material );
@@ -11,7 +11,7 @@ import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
11
11
  import QuadMesh from '../../renderers/common/QuadMesh.js';
12
12
  import { Loop } from '../utils/LoopNode.js';
13
13
  import { screenCoordinate } from '../display/ScreenNode.js';
14
- import { HalfFloatType, LessCompare, RGFormat, VSMShadowMap, WebGPUCoordinateSystem } from '../../constants.js';
14
+ import { Compatibility, GreaterEqualCompare, HalfFloatType, LessEqualCompare, LinearFilter, NearestFilter, PCFShadowMap, PCFSoftShadowMap, RGFormat, VSMShadowMap } from '../../constants.js';
15
15
  import { renderGroup } from '../core/UniformGroupNode.js';
16
16
  import { viewZToLogarithmicDepth } from '../display/ViewportDepthNode.js';
17
17
  import { lightShadowMatrix } from '../accessors/Lights.js';
@@ -19,7 +19,6 @@ import { resetRendererAndSceneState, restoreRendererAndSceneState } from '../../
19
19
  import { getDataFromObject } from '../core/NodeUtils.js';
20
20
  import { getShadowMaterial, disposeShadowMaterial, BasicShadowFilter, PCFShadowFilter, PCFSoftShadowFilter, VSMShadowFilter } from './ShadowFilterNode.js';
21
21
  import ChainMap from '../../renderers/common/ChainMap.js';
22
- import { warn } from '../../utils.js';
23
22
  import { textureSize } from '../accessors/TextureSizeNode.js';
24
23
  import { uv } from '../accessors/UV.js';
25
24
 
@@ -342,7 +341,7 @@ class ShadowNode extends ShadowBaseNode {
342
341
  const { shadow } = this;
343
342
  const { renderer } = builder;
344
343
 
345
- const bias = reference( 'bias', 'float', shadow ).setGroup( renderGroup );
344
+ const bias = shadow.biasNode || reference( 'bias', 'float', shadow ).setGroup( renderGroup );
346
345
 
347
346
  let shadowCoord = shadowPosition;
348
347
  let coordZ;
@@ -353,12 +352,6 @@ class ShadowNode extends ShadowBaseNode {
353
352
 
354
353
  coordZ = shadowCoord.z;
355
354
 
356
- if ( renderer.coordinateSystem === WebGPUCoordinateSystem ) {
357
-
358
- coordZ = coordZ.mul( 2 ).sub( 1 ); // WebGPU: Conversion [ 0, 1 ] to [ - 1, 1 ]
359
-
360
- }
361
-
362
355
  } else {
363
356
 
364
357
  const w = shadowCoord.w;
@@ -377,7 +370,7 @@ class ShadowNode extends ShadowBaseNode {
377
370
  shadowCoord = vec3(
378
371
  shadowCoord.x,
379
372
  shadowCoord.y.oneMinus(), // follow webgpu standards
380
- coordZ.add( bias )
373
+ renderer.reversedDepthBuffer ? coordZ.sub( bias ) : coordZ.add( bias )
381
374
  );
382
375
 
383
376
  return shadowCoord;
@@ -401,7 +394,7 @@ class ShadowNode extends ShadowBaseNode {
401
394
 
402
395
  const depthTexture = new DepthTexture( shadow.mapSize.width, shadow.mapSize.height );
403
396
  depthTexture.name = 'ShadowDepthTexture';
404
- depthTexture.compareFunction = LessCompare;
397
+ depthTexture.compareFunction = builder.renderer.reversedDepthBuffer ? GreaterEqualCompare : LessEqualCompare;
405
398
 
406
399
  const shadowMap = builder.createRenderTarget( shadow.mapSize.width, shadow.mapSize.height );
407
400
  shadowMap.texture.name = 'ShadowMap';
@@ -424,9 +417,22 @@ class ShadowNode extends ShadowBaseNode {
424
417
 
425
418
  const { light, shadow } = this;
426
419
 
420
+ const { depthTexture, shadowMap } = this.setupRenderTarget( shadow, builder );
421
+
427
422
  const shadowMapType = renderer.shadowMap.type;
423
+ const hasTextureCompare = renderer.hasCompatibility( Compatibility.TEXTURE_COMPARE );
428
424
 
429
- const { depthTexture, shadowMap } = this.setupRenderTarget( shadow, builder );
425
+ if ( ( shadowMapType === PCFShadowMap || shadowMapType === PCFSoftShadowMap ) && hasTextureCompare ) {
426
+
427
+ depthTexture.minFilter = LinearFilter;
428
+ depthTexture.magFilter = LinearFilter;
429
+
430
+ } else {
431
+
432
+ depthTexture.minFilter = NearestFilter;
433
+ depthTexture.magFilter = NearestFilter;
434
+
435
+ }
430
436
 
431
437
  shadow.camera.coordinateSystem = camera.coordinateSystem;
432
438
  shadow.camera.updateProjectionMatrix();
@@ -519,24 +525,40 @@ class ShadowNode extends ShadowBaseNode {
519
525
 
520
526
  let shadowColor;
521
527
 
522
- if ( shadowMap.texture.isCubeTexture ) {
528
+ if ( renderer.shadowMap.transmitted === true ) {
523
529
 
524
- // For cube shadow maps (point lights), use cubeTexture with vec3 coordinates
525
- shadowColor = cubeTexture( shadowMap.texture, shadowCoord.xyz );
530
+ if ( shadowMap.texture.isCubeTexture ) {
526
531
 
527
- } else {
532
+ // For cube shadow maps (point lights), use cubeTexture with vec3 coordinates
533
+ shadowColor = cubeTexture( shadowMap.texture, shadowCoord.xyz );
534
+
535
+ } else {
528
536
 
529
- shadowColor = texture( shadowMap.texture, shadowCoord );
537
+ shadowColor = texture( shadowMap.texture, shadowCoord );
530
538
 
531
- if ( depthTexture.isArrayTexture ) {
539
+ if ( depthTexture.isArrayTexture ) {
532
540
 
533
- shadowColor = shadowColor.depth( this.depthLayer );
541
+ shadowColor = shadowColor.depth( this.depthLayer );
542
+
543
+ }
534
544
 
535
545
  }
536
546
 
537
547
  }
538
548
 
539
- const shadowOutput = mix( 1, shadowNode.rgb.mix( shadowColor, 1 ), shadowIntensity.mul( shadowColor.a ) ).toVar();
549
+ //
550
+
551
+ let shadowOutput;
552
+
553
+ if ( shadowColor ) {
554
+
555
+ shadowOutput = mix( 1, shadowNode.rgb.mix( shadowColor, 1 ), shadowIntensity.mul( shadowColor.a ) ).toVar();
556
+
557
+ } else {
558
+
559
+ shadowOutput = mix( 1, shadowNode, shadowIntensity ).toVar();
560
+
561
+ }
540
562
 
541
563
  this.shadowMap = shadowMap;
542
564
  this.shadow.map = shadowMap;
@@ -545,17 +567,23 @@ class ShadowNode extends ShadowBaseNode {
545
567
 
546
568
  const inspectName = `${ this.light.type } Shadow [ ${ this.light.name || 'ID: ' + this.light.id } ]`;
547
569
 
548
- return shadowOutput.toInspector( `${ inspectName } / Color`, () => {
570
+ if ( shadowColor ) {
549
571
 
550
- if ( this.shadowMap.texture.isCubeTexture ) {
572
+ shadowOutput.toInspector( `${ inspectName } / Color`, () => {
551
573
 
552
- return cubeTexture( this.shadowMap.texture );
574
+ if ( this.shadowMap.texture.isCubeTexture ) {
553
575
 
554
- }
576
+ return cubeTexture( this.shadowMap.texture );
555
577
 
556
- return texture( this.shadowMap.texture );
578
+ }
579
+
580
+ return texture( this.shadowMap.texture );
581
+
582
+ } );
583
+
584
+ }
557
585
 
558
- } ).toInspector( `${ inspectName } / Depth`, () => {
586
+ return shadowOutput.toInspector( `${ inspectName } / Depth`, () => {
559
587
 
560
588
  // TODO: Use linear depth
561
589
 
@@ -604,12 +632,6 @@ class ShadowNode extends ShadowBaseNode {
604
632
 
605
633
  }
606
634
 
607
- if ( builder.material.shadowNode ) { // @deprecated, r171
608
-
609
- warn( 'NodeMaterial: ".shadowNode" is deprecated. Use ".castShadowNode" instead.' );
610
-
611
- }
612
-
613
635
  if ( builder.material.receivedShadowNode ) {
614
636
 
615
637
  node = builder.material.receivedShadowNode( node );