@plastic-software/three 0.181.3 → 0.182.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 (253) hide show
  1. package/README.md +3 -4
  2. package/build/three.cjs +1192 -522
  3. package/build/three.core.js +345 -219
  4. package/build/three.core.min.js +1 -1
  5. package/build/three.module.js +864 -328
  6. package/build/three.module.min.js +1 -1
  7. package/build/three.tsl.js +15 -3
  8. package/build/three.tsl.min.js +1 -1
  9. package/build/three.webgpu.js +3660 -1545
  10. package/build/three.webgpu.min.js +1 -1
  11. package/build/three.webgpu.nodes.js +3659 -1544
  12. package/build/three.webgpu.nodes.min.js +1 -1
  13. package/examples/jsm/controls/MapControls.js +55 -1
  14. package/examples/jsm/controls/OrbitControls.js +6 -6
  15. package/examples/jsm/controls/TrackballControls.js +6 -6
  16. package/examples/jsm/csm/CSM.js +2 -1
  17. package/examples/jsm/environments/RoomEnvironment.js +2 -0
  18. package/examples/jsm/geometries/DecalGeometry.js +1 -1
  19. package/examples/jsm/helpers/LightProbeHelperGPU.js +1 -1
  20. package/examples/jsm/helpers/TextureHelperGPU.js +1 -1
  21. package/examples/jsm/inspector/Inspector.js +53 -9
  22. package/examples/jsm/inspector/RendererInspector.js +12 -2
  23. package/examples/jsm/inspector/tabs/Console.js +2 -2
  24. package/examples/jsm/inspector/tabs/Parameters.js +2 -2
  25. package/examples/jsm/inspector/tabs/Performance.js +2 -2
  26. package/examples/jsm/inspector/tabs/Viewer.js +4 -4
  27. package/examples/jsm/inspector/ui/Profiler.js +1836 -31
  28. package/examples/jsm/inspector/ui/Style.js +948 -13
  29. package/examples/jsm/inspector/ui/Tab.js +188 -1
  30. package/examples/jsm/inspector/ui/Values.js +17 -1
  31. package/examples/jsm/loaders/3DMLoader.js +5 -4
  32. package/examples/jsm/loaders/DRACOLoader.js +5 -5
  33. package/examples/jsm/loaders/FBXLoader.js +0 -2
  34. package/examples/jsm/loaders/HDRLoader.js +0 -1
  35. package/examples/jsm/loaders/KTX2Loader.js +16 -0
  36. package/examples/jsm/loaders/LDrawLoader.js +2 -3
  37. package/examples/jsm/loaders/PCDLoader.js +1 -0
  38. package/examples/jsm/loaders/SVGLoader.js +1 -1
  39. package/examples/jsm/loaders/TDSLoader.js +0 -2
  40. package/examples/jsm/loaders/TGALoader.js +0 -2
  41. package/examples/jsm/loaders/UltraHDRLoader.js +110 -137
  42. package/examples/jsm/loaders/VOXLoader.js +660 -117
  43. package/examples/jsm/loaders/VRMLLoader.js +2 -2
  44. package/examples/jsm/loaders/usd/USDCParser.js +1 -1
  45. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +1 -1
  46. package/examples/jsm/materials/MeshGouraudMaterial.js +0 -1
  47. package/examples/jsm/materials/WoodNodeMaterial.js +11 -11
  48. package/examples/jsm/math/Octree.js +131 -1
  49. package/examples/jsm/misc/Volume.js +0 -1
  50. package/examples/jsm/misc/VolumeSlice.js +0 -1
  51. package/examples/jsm/objects/SkyMesh.js +13 -3
  52. package/examples/jsm/physics/AmmoPhysics.js +12 -7
  53. package/examples/jsm/physics/JoltPhysics.js +3 -1
  54. package/examples/jsm/physics/RapierPhysics.js +3 -1
  55. package/examples/jsm/postprocessing/OutputPass.js +9 -0
  56. package/examples/jsm/postprocessing/RenderPass.js +10 -0
  57. package/examples/jsm/postprocessing/UnrealBloomPass.js +48 -18
  58. package/examples/jsm/renderers/Projector.js +268 -30
  59. package/examples/jsm/renderers/SVGRenderer.js +191 -58
  60. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +2 -4
  61. package/examples/jsm/transpiler/AST.js +44 -0
  62. package/examples/jsm/transpiler/GLSLDecoder.js +61 -4
  63. package/examples/jsm/transpiler/ShaderToyDecoder.js +2 -0
  64. package/examples/jsm/transpiler/TSLEncoder.js +46 -3
  65. package/examples/jsm/transpiler/TranspilerUtils.js +3 -3
  66. package/examples/jsm/transpiler/WGSLEncoder.js +27 -0
  67. package/examples/jsm/tsl/display/AnaglyphPassNode.js +2 -0
  68. package/examples/jsm/tsl/display/BloomNode.js +11 -1
  69. package/examples/jsm/tsl/display/GTAONode.js +3 -2
  70. package/examples/jsm/tsl/display/PixelationPassNode.js +2 -1
  71. package/examples/jsm/tsl/display/SSGINode.js +7 -19
  72. package/examples/jsm/tsl/display/SSRNode.js +1 -1
  73. package/examples/jsm/tsl/display/SSSNode.js +4 -2
  74. package/examples/jsm/tsl/display/StereoCompositePassNode.js +8 -1
  75. package/examples/jsm/tsl/display/TRAANode.js +265 -114
  76. package/examples/jsm/tsl/display/radialBlur.js +68 -0
  77. package/examples/jsm/utils/ShadowMapViewer.js +24 -10
  78. package/examples/jsm/utils/ShadowMapViewerGPU.js +1 -1
  79. package/examples/jsm/utils/WebGPUTextureUtils.js +1 -1
  80. package/package.json +14 -12
  81. package/src/Three.Core.js +1 -0
  82. package/src/Three.TSL.js +14 -2
  83. package/src/animation/AnimationUtils.js +1 -12
  84. package/src/animation/KeyframeTrack.js +1 -1
  85. package/src/animation/tracks/BooleanKeyframeTrack.js +1 -1
  86. package/src/animation/tracks/ColorKeyframeTrack.js +1 -1
  87. package/src/animation/tracks/NumberKeyframeTrack.js +1 -1
  88. package/src/animation/tracks/QuaternionKeyframeTrack.js +1 -1
  89. package/src/animation/tracks/StringKeyframeTrack.js +1 -1
  90. package/src/animation/tracks/VectorKeyframeTrack.js +1 -1
  91. package/src/constants.js +61 -5
  92. package/src/core/BufferGeometry.js +14 -2
  93. package/src/core/Raycaster.js +2 -2
  94. package/src/extras/PMREMGenerator.js +3 -10
  95. package/src/extras/TextureUtils.js +5 -1
  96. package/src/geometries/ExtrudeGeometry.js +2 -2
  97. package/src/geometries/PolyhedronGeometry.js +1 -1
  98. package/src/helpers/PointLightHelper.js +1 -1
  99. package/src/lights/DirectionalLight.js +13 -0
  100. package/src/lights/HemisphereLight.js +10 -0
  101. package/src/lights/Light.js +1 -11
  102. package/src/lights/LightProbe.js +0 -15
  103. package/src/lights/LightShadow.js +0 -3
  104. package/src/lights/PointLight.js +15 -0
  105. package/src/lights/PointLightShadow.js +0 -86
  106. package/src/lights/SpotLight.js +22 -1
  107. package/src/loaders/MaterialLoader.js +2 -1
  108. package/src/loaders/ObjectLoader.js +3 -1
  109. package/src/loaders/nodes/NodeLoader.js +2 -2
  110. package/src/materials/Material.js +2 -0
  111. package/src/materials/ShaderMaterial.js +20 -1
  112. package/src/materials/nodes/Line2NodeMaterial.js +2 -2
  113. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +3 -2
  114. package/src/materials/nodes/MeshStandardNodeMaterial.js +5 -4
  115. package/src/materials/nodes/NodeMaterial.js +59 -3
  116. package/src/materials/nodes/manager/NodeMaterialObserver.js +1 -1
  117. package/src/math/Matrix4.js +40 -40
  118. package/src/math/Sphere.js +1 -1
  119. package/src/math/Vector3.js +0 -2
  120. package/src/nodes/TSL.js +4 -1
  121. package/src/nodes/accessors/BatchNode.js +10 -10
  122. package/src/nodes/accessors/BufferAttributeNode.js +98 -12
  123. package/src/nodes/accessors/BufferNode.js +29 -2
  124. package/src/nodes/accessors/ClippingNode.js +4 -4
  125. package/src/nodes/accessors/CubeTextureNode.js +20 -1
  126. package/src/nodes/accessors/InstanceNode.js +69 -29
  127. package/src/nodes/accessors/MaterialNode.js +9 -1
  128. package/src/nodes/accessors/MaterialReferenceNode.js +1 -2
  129. package/src/nodes/accessors/ModelNode.js +1 -1
  130. package/src/nodes/accessors/Normal.js +2 -2
  131. package/src/nodes/accessors/ReferenceBaseNode.js +4 -4
  132. package/src/nodes/accessors/ReferenceNode.js +4 -4
  133. package/src/nodes/accessors/RendererReferenceNode.js +1 -2
  134. package/src/nodes/accessors/SkinningNode.js +15 -2
  135. package/src/nodes/accessors/StorageBufferNode.js +4 -2
  136. package/src/nodes/accessors/Tangent.js +1 -11
  137. package/src/nodes/accessors/Texture3DNode.js +26 -1
  138. package/src/nodes/accessors/UniformArrayNode.js +2 -2
  139. package/src/nodes/accessors/UserDataNode.js +1 -2
  140. package/src/nodes/accessors/VertexColorNode.js +1 -2
  141. package/src/nodes/code/FunctionNode.js +1 -2
  142. package/src/nodes/core/ArrayNode.js +20 -1
  143. package/src/nodes/core/AssignNode.js +2 -2
  144. package/src/nodes/core/AttributeNode.js +2 -2
  145. package/src/nodes/core/ContextNode.js +103 -4
  146. package/src/nodes/core/NodeBuilder.js +56 -14
  147. package/src/nodes/core/NodeFrame.js +12 -4
  148. package/src/nodes/core/NodeUtils.js +5 -5
  149. package/src/nodes/core/ParameterNode.js +1 -2
  150. package/src/nodes/core/PropertyNode.js +19 -3
  151. package/src/nodes/core/StackNode.js +56 -8
  152. package/src/nodes/core/StructNode.js +1 -2
  153. package/src/nodes/core/StructTypeNode.js +11 -17
  154. package/src/nodes/core/UniformNode.js +19 -4
  155. package/src/nodes/core/VarNode.js +46 -21
  156. package/src/nodes/display/NormalMapNode.js +37 -2
  157. package/src/nodes/display/PassNode.js +77 -7
  158. package/src/nodes/display/ScreenNode.js +1 -0
  159. package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +3 -3
  160. package/src/nodes/functions/BSDF/DFGLUT.js +56 -0
  161. package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
  162. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +1 -1
  163. package/src/nodes/functions/PhysicalLightingModel.js +102 -43
  164. package/src/nodes/gpgpu/ComputeBuiltinNode.js +1 -2
  165. package/src/nodes/gpgpu/SubgroupFunctionNode.js +1 -1
  166. package/src/nodes/gpgpu/WorkgroupInfoNode.js +2 -3
  167. package/src/nodes/lighting/AnalyticLightNode.js +53 -0
  168. package/src/nodes/lighting/LightsNode.js +2 -2
  169. package/src/nodes/lighting/PointShadowNode.js +141 -140
  170. package/src/nodes/lighting/ShadowFilterNode.js +53 -37
  171. package/src/nodes/lighting/ShadowNode.js +53 -19
  172. package/src/nodes/math/BitcountNode.js +433 -0
  173. package/src/nodes/math/PackFloatNode.js +98 -0
  174. package/src/nodes/math/UnpackFloatNode.js +96 -0
  175. package/src/nodes/pmrem/PMREMNode.js +1 -1
  176. package/src/nodes/tsl/TSLCore.js +4 -4
  177. package/src/nodes/utils/ArrayElementNode.js +13 -0
  178. package/src/nodes/utils/EventNode.js +1 -2
  179. package/src/nodes/utils/Packing.js +13 -1
  180. package/src/nodes/utils/PostProcessingUtils.js +33 -1
  181. package/src/nodes/utils/ReflectorNode.js +1 -1
  182. package/src/nodes/utils/SampleNode.js +1 -1
  183. package/src/nodes/utils/UVUtils.js +26 -0
  184. package/src/objects/BatchedMesh.js +5 -2
  185. package/src/objects/Line.js +1 -1
  186. package/src/objects/Mesh.js +1 -1
  187. package/src/objects/Points.js +1 -1
  188. package/src/objects/Skeleton.js +9 -0
  189. package/src/renderers/WebGLRenderer.js +145 -33
  190. package/src/renderers/common/Backend.js +8 -0
  191. package/src/renderers/common/Background.js +19 -9
  192. package/src/renderers/common/Binding.js +11 -0
  193. package/src/renderers/common/Bindings.js +7 -7
  194. package/src/renderers/common/Buffer.js +40 -0
  195. package/src/renderers/common/ChainMap.js +30 -6
  196. package/src/renderers/common/Geometries.js +12 -0
  197. package/src/renderers/common/RenderContexts.js +8 -1
  198. package/src/renderers/common/RenderObject.js +14 -1
  199. package/src/renderers/common/Renderer.js +53 -35
  200. package/src/renderers/common/Textures.js +1 -1
  201. package/src/renderers/common/UniformsGroup.js +1 -0
  202. package/src/renderers/common/XRManager.js +1 -0
  203. package/src/renderers/common/extras/PMREMGenerator.js +2 -8
  204. package/src/renderers/common/nodes/NodeUniformBuffer.js +52 -0
  205. package/src/renderers/shaders/DFGLUTData.js +19 -34
  206. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +5 -2
  207. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +8 -4
  208. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +90 -51
  209. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +194 -186
  210. package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +1 -1
  211. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
  212. package/src/renderers/shaders/ShaderChunk.js +3 -3
  213. package/src/renderers/shaders/ShaderLib/depth.glsl.js +3 -0
  214. package/src/renderers/shaders/ShaderLib/{distanceRGBA.glsl.js → distance.glsl.js} +1 -2
  215. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +0 -1
  216. package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +1 -2
  217. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +0 -1
  218. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -9
  219. package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +0 -1
  220. package/src/renderers/shaders/ShaderLib/shadow.glsl.js +0 -1
  221. package/src/renderers/shaders/ShaderLib/vsm.glsl.js +4 -6
  222. package/src/renderers/shaders/ShaderLib.js +3 -3
  223. package/src/renderers/webgl/WebGLCapabilities.js +3 -4
  224. package/src/renderers/webgl/WebGLLights.js +18 -1
  225. package/src/renderers/webgl/WebGLOutput.js +267 -0
  226. package/src/renderers/webgl/WebGLProgram.js +43 -107
  227. package/src/renderers/webgl/WebGLPrograms.js +35 -45
  228. package/src/renderers/webgl/WebGLShadowMap.js +188 -25
  229. package/src/renderers/webgl/WebGLState.js +20 -20
  230. package/src/renderers/webgl/WebGLTextures.js +89 -28
  231. package/src/renderers/webgl/WebGLUniforms.js +40 -3
  232. package/src/renderers/webgl/WebGLUtils.js +6 -2
  233. package/src/renderers/webgl-fallback/WebGLBackend.js +79 -13
  234. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +59 -7
  235. package/src/renderers/webgl-fallback/utils/WebGLState.js +18 -3
  236. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +5 -3
  237. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +9 -9
  238. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +6 -2
  239. package/src/renderers/webgpu/WebGPUBackend.js +61 -4
  240. package/src/renderers/webgpu/WebGPURenderer.js +1 -1
  241. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +65 -23
  242. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +4 -17
  243. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +354 -186
  244. package/src/renderers/webgpu/utils/WebGPUConstants.js +2 -0
  245. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +20 -7
  246. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +40 -17
  247. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +7 -7
  248. package/src/renderers/webgpu/utils/WebGPUUtils.js +7 -5
  249. package/src/textures/CubeDepthTexture.js +76 -0
  250. package/src/textures/Source.js +1 -1
  251. package/src/textures/Texture.js +1 -1
  252. package/src/utils.js +13 -1
  253. package/src/nodes/functions/BSDF/DFGApprox.js +0 -71
@@ -13,15 +13,15 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
13
13
  const _customShaders = new WebGLShaderCache();
14
14
  const _activeChannels = new Set();
15
15
  const programs = [];
16
+ const programsMap = new Map();
16
17
 
17
18
  const logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
18
- const SUPPORTS_VERTEX_TEXTURES = capabilities.vertexTextures;
19
19
 
20
20
  let precision = capabilities.precision;
21
21
 
22
22
  const shaderIDs = {
23
23
  MeshDepthMaterial: 'depth',
24
- MeshDistanceMaterial: 'distanceRGBA',
24
+ MeshDistanceMaterial: 'distance',
25
25
  MeshNormalMaterial: 'normal',
26
26
  MeshBasicMaterial: 'basic',
27
27
  MeshLambertMaterial: 'lambert',
@@ -200,7 +200,6 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
200
200
  instancingColor: IS_INSTANCEDMESH && object.instanceColor !== null,
201
201
  instancingMorph: IS_INSTANCEDMESH && object.morphTexture !== null,
202
202
 
203
- supportsVertexTextures: SUPPORTS_VERTEX_TEXTURES,
204
203
  outputColorSpace: ( currentRenderTarget === null ) ? renderer.outputColorSpace : ( currentRenderTarget.isXRRenderTarget === true ? currentRenderTarget.texture.colorSpace : LinearSRGBColorSpace ),
205
204
  alphaToCoverage: !! material.alphaToCoverage,
206
205
 
@@ -213,7 +212,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
213
212
  lightMap: HAS_LIGHTMAP,
214
213
  bumpMap: HAS_BUMPMAP,
215
214
  normalMap: HAS_NORMALMAP,
216
- displacementMap: SUPPORTS_VERTEX_TEXTURES && HAS_DISPLACEMENTMAP,
215
+ displacementMap: HAS_DISPLACEMENTMAP,
217
216
  emissiveMap: HAS_EMISSIVEMAP,
218
217
 
219
218
  normalMapObjectSpace: HAS_NORMALMAP && material.normalMapType === ObjectSpaceNormalMap,
@@ -487,54 +486,52 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
487
486
 
488
487
  _programLayers.disableAll();
489
488
 
490
- if ( parameters.supportsVertexTextures )
491
- _programLayers.enable( 0 );
492
489
  if ( parameters.instancing )
493
- _programLayers.enable( 1 );
490
+ _programLayers.enable( 0 );
494
491
  if ( parameters.instancingColor )
495
- _programLayers.enable( 2 );
492
+ _programLayers.enable( 1 );
496
493
  if ( parameters.instancingMorph )
497
- _programLayers.enable( 3 );
494
+ _programLayers.enable( 2 );
498
495
  if ( parameters.matcap )
499
- _programLayers.enable( 4 );
496
+ _programLayers.enable( 3 );
500
497
  if ( parameters.envMap )
501
- _programLayers.enable( 5 );
498
+ _programLayers.enable( 4 );
502
499
  if ( parameters.normalMapObjectSpace )
503
- _programLayers.enable( 6 );
500
+ _programLayers.enable( 5 );
504
501
  if ( parameters.normalMapTangentSpace )
505
- _programLayers.enable( 7 );
502
+ _programLayers.enable( 6 );
506
503
  if ( parameters.clearcoat )
507
- _programLayers.enable( 8 );
504
+ _programLayers.enable( 7 );
508
505
  if ( parameters.iridescence )
509
- _programLayers.enable( 9 );
506
+ _programLayers.enable( 8 );
510
507
  if ( parameters.alphaTest )
511
- _programLayers.enable( 10 );
508
+ _programLayers.enable( 9 );
512
509
  if ( parameters.vertexColors )
513
- _programLayers.enable( 11 );
510
+ _programLayers.enable( 10 );
514
511
  if ( parameters.vertexAlphas )
515
- _programLayers.enable( 12 );
512
+ _programLayers.enable( 11 );
516
513
  if ( parameters.vertexUv1s )
517
- _programLayers.enable( 13 );
514
+ _programLayers.enable( 12 );
518
515
  if ( parameters.vertexUv2s )
519
- _programLayers.enable( 14 );
516
+ _programLayers.enable( 13 );
520
517
  if ( parameters.vertexUv3s )
521
- _programLayers.enable( 15 );
518
+ _programLayers.enable( 14 );
522
519
  if ( parameters.vertexTangents )
523
- _programLayers.enable( 16 );
520
+ _programLayers.enable( 15 );
524
521
  if ( parameters.anisotropy )
525
- _programLayers.enable( 17 );
522
+ _programLayers.enable( 16 );
526
523
  if ( parameters.alphaHash )
527
- _programLayers.enable( 18 );
524
+ _programLayers.enable( 17 );
528
525
  if ( parameters.batching )
529
- _programLayers.enable( 19 );
526
+ _programLayers.enable( 18 );
530
527
  if ( parameters.dispersion )
531
- _programLayers.enable( 20 );
528
+ _programLayers.enable( 19 );
532
529
  if ( parameters.batchingColor )
533
- _programLayers.enable( 21 );
530
+ _programLayers.enable( 20 );
534
531
  if ( parameters.gradientMap )
535
- _programLayers.enable( 22 );
532
+ _programLayers.enable( 21 );
536
533
  if ( parameters.batchingMatrix )
537
- _programLayers.enable( 23 );
534
+ _programLayers.enable( 22 );
538
535
 
539
536
  array.push( _programLayers.mask );
540
537
  _programLayers.disableAll();
@@ -610,29 +607,19 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
610
607
 
611
608
  function acquireProgram( parameters, cacheKey ) {
612
609
 
613
- let program;
614
-
615
- // Check if code has been already compiled
616
- for ( let p = 0, pl = programs.length; p < pl; p ++ ) {
617
-
618
- const preexistingProgram = programs[ p ];
619
-
620
- if ( preexistingProgram.cacheKey === cacheKey ) {
610
+ let program = programsMap.get( cacheKey );
621
611
 
622
- program = preexistingProgram;
623
- ++ program.usedTimes;
612
+ if ( program !== undefined ) {
624
613
 
625
- break;
614
+ ++ program.usedTimes;
626
615
 
627
- }
628
-
629
- }
630
-
631
- if ( program === undefined ) {
616
+ } else {
632
617
 
633
618
  program = new WebGLProgram( renderer, cacheKey, parameters, bindingStates );
634
619
  programs.push( program );
635
620
 
621
+ programsMap.set( cacheKey, program );
622
+
636
623
  }
637
624
 
638
625
  return program;
@@ -648,6 +635,9 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
648
635
  programs[ i ] = programs[ programs.length - 1 ];
649
636
  programs.pop();
650
637
 
638
+ // Remove from map
639
+ programsMap.delete( program.cacheKey );
640
+
651
641
  // Free WebGL resources
652
642
  program.destroy();
653
643
 
@@ -1,5 +1,6 @@
1
- import { FrontSide, BackSide, DoubleSide, NearestFilter, PCFShadowMap, VSMShadowMap, RGBADepthPacking, NoBlending } from '../../constants.js';
1
+ import { FrontSide, BackSide, DoubleSide, NearestFilter, LinearFilter, PCFShadowMap, VSMShadowMap, NoBlending, LessEqualCompare, GreaterEqualCompare, DepthFormat, UnsignedIntType, RGFormat, HalfFloatType, FloatType, PCFSoftShadowMap } from '../../constants.js';
2
2
  import { WebGLRenderTarget } from '../WebGLRenderTarget.js';
3
+ import { WebGLCubeRenderTarget } from '../WebGLCubeRenderTarget.js';
3
4
  import { MeshDepthMaterial } from '../../materials/MeshDepthMaterial.js';
4
5
  import { MeshDistanceMaterial } from '../../materials/MeshDistanceMaterial.js';
5
6
  import { ShaderMaterial } from '../../materials/ShaderMaterial.js';
@@ -8,10 +9,28 @@ import { BufferGeometry } from '../../core/BufferGeometry.js';
8
9
  import { Mesh } from '../../objects/Mesh.js';
9
10
  import { Vector4 } from '../../math/Vector4.js';
10
11
  import { Vector2 } from '../../math/Vector2.js';
12
+ import { Matrix4 } from '../../math/Matrix4.js';
11
13
  import { Frustum } from '../../math/Frustum.js';
14
+ import { DepthTexture } from '../../textures/DepthTexture.js';
15
+ import { CubeDepthTexture } from '../../textures/CubeDepthTexture.js';
12
16
 
13
17
  import * as vsm from '../shaders/ShaderLib/vsm.glsl.js';
14
18
  import { warn } from '../../utils.js';
19
+ import { Vector3 } from '../../math/Vector3.js';
20
+
21
+ const _cubeDirections = [
22
+ /*@__PURE__*/ new Vector3( 1, 0, 0 ), /*@__PURE__*/ new Vector3( - 1, 0, 0 ), /*@__PURE__*/ new Vector3( 0, 1, 0 ),
23
+ /*@__PURE__*/ new Vector3( 0, - 1, 0 ), /*@__PURE__*/ new Vector3( 0, 0, 1 ), /*@__PURE__*/ new Vector3( 0, 0, - 1 )
24
+ ];
25
+
26
+ const _cubeUps = [
27
+ /*@__PURE__*/ new Vector3( 0, - 1, 0 ), /*@__PURE__*/ new Vector3( 0, - 1, 0 ), /*@__PURE__*/ new Vector3( 0, 0, 1 ),
28
+ /*@__PURE__*/ new Vector3( 0, 0, - 1 ), /*@__PURE__*/ new Vector3( 0, - 1, 0 ), /*@__PURE__*/ new Vector3( 0, - 1, 0 )
29
+ ];
30
+
31
+ const _projScreenMatrix = /*@__PURE__*/ new Matrix4();
32
+ const _lightPositionWorld = /*@__PURE__*/ new Vector3();
33
+ const _lookTarget = /*@__PURE__*/ new Vector3();
15
34
 
16
35
  function WebGLShadowMap( renderer, objects, capabilities ) {
17
36
 
@@ -22,7 +41,7 @@ function WebGLShadowMap( renderer, objects, capabilities ) {
22
41
 
23
42
  _viewport = new Vector4(),
24
43
 
25
- _depthMaterial = new MeshDepthMaterial( { depthPacking: RGBADepthPacking } ),
44
+ _depthMaterial = new MeshDepthMaterial(),
26
45
  _distanceMaterial = new MeshDistanceMaterial(),
27
46
 
28
47
  _materialCache = {},
@@ -77,6 +96,13 @@ function WebGLShadowMap( renderer, objects, capabilities ) {
77
96
 
78
97
  if ( lights.length === 0 ) return;
79
98
 
99
+ if ( lights.type === PCFSoftShadowMap ) {
100
+
101
+ warn( 'WebGLShadowMap: PCFSoftShadowMap has been deprecated. Using PCFShadowMap instead.' );
102
+ lights.type = PCFShadowMap;
103
+
104
+ }
105
+
80
106
  const currentRenderTarget = renderer.getRenderTarget();
81
107
  const activeCubeFace = renderer.getActiveCubeFace();
82
108
  const activeMipmapLevel = renderer.getActiveMipmapLevel();
@@ -101,8 +127,31 @@ function WebGLShadowMap( renderer, objects, capabilities ) {
101
127
 
102
128
  // check for shadow map type changes
103
129
 
104
- const toVSM = ( _previousType !== VSMShadowMap && this.type === VSMShadowMap );
105
- const fromVSM = ( _previousType === VSMShadowMap && this.type !== VSMShadowMap );
130
+ const typeChanged = _previousType !== this.type;
131
+
132
+ // When shadow map type changes, materials need recompilation because sampler types change
133
+ // (sampler2DShadow for PCF vs sampler2D for Basic)
134
+ if ( typeChanged ) {
135
+
136
+ scene.traverse( function ( object ) {
137
+
138
+ if ( object.material ) {
139
+
140
+ if ( Array.isArray( object.material ) ) {
141
+
142
+ object.material.forEach( mat => mat.needsUpdate = true );
143
+
144
+ } else {
145
+
146
+ object.material.needsUpdate = true;
147
+
148
+ }
149
+
150
+ }
151
+
152
+ } );
153
+
154
+ }
106
155
 
107
156
  // render depth map
108
157
 
@@ -148,42 +197,153 @@ function WebGLShadowMap( renderer, objects, capabilities ) {
148
197
 
149
198
  }
150
199
 
151
- if ( shadow.map === null || toVSM === true || fromVSM === true ) {
152
-
153
- const pars = ( this.type !== VSMShadowMap ) ? { minFilter: NearestFilter, magFilter: NearestFilter } : {};
200
+ if ( shadow.map === null || typeChanged === true ) {
154
201
 
155
202
  if ( shadow.map !== null ) {
156
203
 
204
+ if ( shadow.map.depthTexture !== null ) {
205
+
206
+ shadow.map.depthTexture.dispose();
207
+ shadow.map.depthTexture = null;
208
+
209
+ }
210
+
157
211
  shadow.map.dispose();
158
212
 
159
213
  }
160
214
 
161
- shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
162
- shadow.map.texture.name = light.name + '.shadowMap';
215
+ if ( this.type === VSMShadowMap ) {
216
+
217
+ if ( light.isPointLight ) {
218
+
219
+ warn( 'WebGLShadowMap: VSM shadow maps are not supported for PointLights. Use PCF or BasicShadowMap instead.' );
220
+ continue;
221
+
222
+ }
223
+
224
+ shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, {
225
+ format: RGFormat,
226
+ type: HalfFloatType,
227
+ minFilter: LinearFilter,
228
+ magFilter: LinearFilter,
229
+ generateMipmaps: false
230
+ } );
231
+ shadow.map.texture.name = light.name + '.shadowMap';
232
+
233
+ // Native depth texture for VSM - depth is captured here, then blurred into the color texture
234
+ shadow.map.depthTexture = new DepthTexture( _shadowMapSize.x, _shadowMapSize.y, FloatType );
235
+ shadow.map.depthTexture.name = light.name + '.shadowMapDepth';
236
+ shadow.map.depthTexture.format = DepthFormat;
237
+ shadow.map.depthTexture.compareFunction = null; // For regular sampling (not shadow comparison)
238
+ shadow.map.depthTexture.minFilter = NearestFilter;
239
+ shadow.map.depthTexture.magFilter = NearestFilter;
240
+
241
+ } else {
242
+
243
+ if ( light.isPointLight ) {
244
+
245
+ shadow.map = new WebGLCubeRenderTarget( _shadowMapSize.x );
246
+ shadow.map.depthTexture = new CubeDepthTexture( _shadowMapSize.x, UnsignedIntType );
247
+
248
+ } else {
249
+
250
+ shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y );
251
+ shadow.map.depthTexture = new DepthTexture( _shadowMapSize.x, _shadowMapSize.y, UnsignedIntType );
252
+
253
+ }
254
+
255
+ shadow.map.depthTexture.name = light.name + '.shadowMap';
256
+ shadow.map.depthTexture.format = DepthFormat;
257
+
258
+ const reversedDepthBuffer = renderer.state.buffers.depth.getReversed();
259
+
260
+ if ( this.type === PCFShadowMap ) {
261
+
262
+ shadow.map.depthTexture.compareFunction = reversedDepthBuffer ? GreaterEqualCompare : LessEqualCompare;
263
+ shadow.map.depthTexture.minFilter = LinearFilter;
264
+ shadow.map.depthTexture.magFilter = LinearFilter;
265
+
266
+ } else {
267
+
268
+ shadow.map.depthTexture.compareFunction = null;
269
+ shadow.map.depthTexture.minFilter = NearestFilter;
270
+ shadow.map.depthTexture.magFilter = NearestFilter;
271
+
272
+ }
273
+
274
+ }
163
275
 
164
276
  shadow.camera.updateProjectionMatrix();
165
277
 
166
278
  }
167
279
 
168
- renderer.setRenderTarget( shadow.map );
169
- renderer.clear();
280
+ // For cube render targets (PointLights), render all 6 faces. Otherwise, render once.
281
+ const faceCount = shadow.map.isWebGLCubeRenderTarget ? 6 : 1;
282
+
283
+ for ( let face = 0; face < faceCount; face ++ ) {
170
284
 
171
- const viewportCount = shadow.getViewportCount();
285
+ // For cube render targets, render to each face separately
286
+ if ( shadow.map.isWebGLCubeRenderTarget ) {
172
287
 
173
- for ( let vp = 0; vp < viewportCount; vp ++ ) {
288
+ renderer.setRenderTarget( shadow.map, face );
289
+ renderer.clear();
174
290
 
175
- const viewport = shadow.getViewport( vp );
291
+ } else {
292
+
293
+ // For 2D render targets, use viewports
294
+ if ( face === 0 ) {
295
+
296
+ renderer.setRenderTarget( shadow.map );
297
+ renderer.clear();
298
+
299
+ }
176
300
 
177
- _viewport.set(
178
- _viewportSize.x * viewport.x,
179
- _viewportSize.y * viewport.y,
180
- _viewportSize.x * viewport.z,
181
- _viewportSize.y * viewport.w
182
- );
301
+ const viewport = shadow.getViewport( face );
183
302
 
184
- _state.viewport( _viewport );
303
+ _viewport.set(
304
+ _viewportSize.x * viewport.x,
305
+ _viewportSize.y * viewport.y,
306
+ _viewportSize.x * viewport.z,
307
+ _viewportSize.y * viewport.w
308
+ );
185
309
 
186
- shadow.updateMatrices( light, vp );
310
+ _state.viewport( _viewport );
311
+
312
+ }
313
+
314
+ if ( light.isPointLight ) {
315
+
316
+ const camera = shadow.camera;
317
+ const shadowMatrix = shadow.matrix;
318
+
319
+ const far = light.distance || camera.far;
320
+
321
+ if ( far !== camera.far ) {
322
+
323
+ camera.far = far;
324
+ camera.updateProjectionMatrix();
325
+
326
+ }
327
+
328
+ _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
329
+ camera.position.copy( _lightPositionWorld );
330
+
331
+ _lookTarget.copy( camera.position );
332
+ _lookTarget.add( _cubeDirections[ face ] );
333
+ camera.up.copy( _cubeUps[ face ] );
334
+ camera.lookAt( _lookTarget );
335
+ camera.updateMatrixWorld();
336
+
337
+ shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
338
+
339
+ _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
340
+ shadow._frustum.setFromProjectionMatrix( _projScreenMatrix, camera.coordinateSystem, camera.reversedDepth );
341
+
342
+ } else {
343
+
344
+ shadow.updateMatrices( light );
345
+
346
+ }
187
347
 
188
348
  _frustum = shadow.getFrustum();
189
349
 
@@ -227,13 +387,16 @@ function WebGLShadowMap( renderer, objects, capabilities ) {
227
387
 
228
388
  if ( shadow.mapPass === null ) {
229
389
 
230
- shadow.mapPass = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y );
390
+ shadow.mapPass = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, {
391
+ format: RGFormat,
392
+ type: HalfFloatType
393
+ } );
231
394
 
232
395
  }
233
396
 
234
- // vertical pass
397
+ // vertical pass - read from native depth texture
235
398
 
236
- shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
399
+ shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.depthTexture;
237
400
  shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
238
401
  shadowMaterialVertical.uniforms.radius.value = shadow.radius;
239
402
  renderer.setRenderTarget( shadow.mapPass );
@@ -983,9 +983,9 @@ function WebGLState( gl, extensions ) {
983
983
 
984
984
  gl.compressedTexImage2D( ...arguments );
985
985
 
986
- } catch ( error ) {
986
+ } catch ( e ) {
987
987
 
988
- error( 'WebGLState:', error );
988
+ error( 'WebGLState:', e );
989
989
 
990
990
  }
991
991
 
@@ -997,9 +997,9 @@ function WebGLState( gl, extensions ) {
997
997
 
998
998
  gl.compressedTexImage3D( ...arguments );
999
999
 
1000
- } catch ( error ) {
1000
+ } catch ( e ) {
1001
1001
 
1002
- error( 'WebGLState:', error );
1002
+ error( 'WebGLState:', e );
1003
1003
 
1004
1004
  }
1005
1005
 
@@ -1011,9 +1011,9 @@ function WebGLState( gl, extensions ) {
1011
1011
 
1012
1012
  gl.texSubImage2D( ...arguments );
1013
1013
 
1014
- } catch ( error ) {
1014
+ } catch ( e ) {
1015
1015
 
1016
- error( 'WebGLState:', error );
1016
+ error( 'WebGLState:', e );
1017
1017
 
1018
1018
  }
1019
1019
 
@@ -1025,9 +1025,9 @@ function WebGLState( gl, extensions ) {
1025
1025
 
1026
1026
  gl.texSubImage3D( ...arguments );
1027
1027
 
1028
- } catch ( error ) {
1028
+ } catch ( e ) {
1029
1029
 
1030
- error( 'WebGLState:', error );
1030
+ error( 'WebGLState:', e );
1031
1031
 
1032
1032
  }
1033
1033
 
@@ -1039,9 +1039,9 @@ function WebGLState( gl, extensions ) {
1039
1039
 
1040
1040
  gl.compressedTexSubImage2D( ...arguments );
1041
1041
 
1042
- } catch ( error ) {
1042
+ } catch ( e ) {
1043
1043
 
1044
- error( 'WebGLState:', error );
1044
+ error( 'WebGLState:', e );
1045
1045
 
1046
1046
  }
1047
1047
 
@@ -1053,9 +1053,9 @@ function WebGLState( gl, extensions ) {
1053
1053
 
1054
1054
  gl.compressedTexSubImage3D( ...arguments );
1055
1055
 
1056
- } catch ( error ) {
1056
+ } catch ( e ) {
1057
1057
 
1058
- error( 'WebGLState:', error );
1058
+ error( 'WebGLState:', e );
1059
1059
 
1060
1060
  }
1061
1061
 
@@ -1067,9 +1067,9 @@ function WebGLState( gl, extensions ) {
1067
1067
 
1068
1068
  gl.texStorage2D( ...arguments );
1069
1069
 
1070
- } catch ( error ) {
1070
+ } catch ( e ) {
1071
1071
 
1072
- error( 'WebGLState:', error );
1072
+ error( 'WebGLState:', e );
1073
1073
 
1074
1074
  }
1075
1075
 
@@ -1081,9 +1081,9 @@ function WebGLState( gl, extensions ) {
1081
1081
 
1082
1082
  gl.texStorage3D( ...arguments );
1083
1083
 
1084
- } catch ( error ) {
1084
+ } catch ( e ) {
1085
1085
 
1086
- error( 'WebGLState:', error );
1086
+ error( 'WebGLState:', e );
1087
1087
 
1088
1088
  }
1089
1089
 
@@ -1095,9 +1095,9 @@ function WebGLState( gl, extensions ) {
1095
1095
 
1096
1096
  gl.texImage2D( ...arguments );
1097
1097
 
1098
- } catch ( error ) {
1098
+ } catch ( e ) {
1099
1099
 
1100
- error( 'WebGLState:', error );
1100
+ error( 'WebGLState:', e );
1101
1101
 
1102
1102
  }
1103
1103
 
@@ -1109,9 +1109,9 @@ function WebGLState( gl, extensions ) {
1109
1109
 
1110
1110
  gl.texImage3D( ...arguments );
1111
1111
 
1112
- } catch ( error ) {
1112
+ } catch ( e ) {
1113
1113
 
1114
- error( 'WebGLState:', error );
1114
+ error( 'WebGLState:', e );
1115
1115
 
1116
1116
  }
1117
1117