super-three 0.169.1 → 0.170.1

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 (255) hide show
  1. package/build/three.cjs +24628 -24228
  2. package/build/three.core.js +37002 -0
  3. package/build/three.core.min.js +6 -0
  4. package/build/three.module.js +10519 -47108
  5. package/build/three.module.min.js +1 -1
  6. package/build/three.tsl.js +533 -0
  7. package/build/three.tsl.min.js +6 -0
  8. package/build/three.webgpu.js +17071 -53583
  9. package/build/three.webgpu.min.js +1 -1
  10. package/build/three.webgpu.nodes.js +17134 -53623
  11. package/build/three.webgpu.nodes.min.js +1 -1
  12. package/examples/jsm/Addons.js +3 -3
  13. package/examples/jsm/animation/MMDAnimationHelper.js +2 -0
  14. package/examples/jsm/animation/MMDPhysics.js +2 -0
  15. package/examples/jsm/capabilities/WebGPU.js +1 -10
  16. package/examples/jsm/controls/ArcballControls.js +25 -21
  17. package/examples/jsm/controls/OrbitControls.js +41 -9
  18. package/examples/jsm/controls/PointerLockControls.js +2 -5
  19. package/examples/jsm/controls/TransformControls.js +22 -6
  20. package/examples/jsm/csm/CSM.js +2 -2
  21. package/examples/jsm/csm/CSMFrustum.js +7 -4
  22. package/examples/jsm/csm/CSMHelper.js +2 -0
  23. package/examples/jsm/csm/CSMShadowNode.js +437 -0
  24. package/examples/jsm/curves/NURBSCurve.js +34 -3
  25. package/examples/jsm/exporters/GLTFExporter.js +138 -71
  26. package/examples/jsm/exporters/KTX2Exporter.js +35 -12
  27. package/examples/jsm/exporters/MMDExporter.js +6 -0
  28. package/examples/jsm/exporters/USDZExporter.js +21 -3
  29. package/examples/jsm/geometries/DecalGeometry.js +70 -21
  30. package/examples/jsm/geometries/InstancedPointsGeometry.js +2 -0
  31. package/examples/jsm/helpers/TextureHelperGPU.js +175 -0
  32. package/examples/jsm/interactive/HTMLMesh.js +1 -0
  33. package/examples/jsm/lighting/TiledLighting.js +18 -0
  34. package/examples/jsm/lights/RectAreaLightTexturesLib.js +1 -1
  35. package/examples/jsm/lines/LineGeometry.js +25 -0
  36. package/examples/jsm/lines/LineMaterial.js +0 -1
  37. package/examples/jsm/lines/LineSegmentsGeometry.js +2 -0
  38. package/examples/jsm/lines/webgpu/Line2.js +2 -1
  39. package/examples/jsm/lines/webgpu/LineSegments2.js +2 -16
  40. package/examples/jsm/lines/webgpu/Wireframe.js +57 -0
  41. package/examples/jsm/loaders/3DMLoader.js +1 -0
  42. package/examples/jsm/loaders/3MFLoader.js +91 -0
  43. package/examples/jsm/loaders/FBXLoader.js +12 -2
  44. package/examples/jsm/loaders/GLTFLoader.js +2 -0
  45. package/examples/jsm/loaders/KTX2Loader.js +143 -49
  46. package/examples/jsm/loaders/LDrawLoader.js +22 -136
  47. package/examples/jsm/loaders/LottieLoader.js +1 -0
  48. package/examples/jsm/loaders/MMDLoader.js +3 -0
  49. package/examples/jsm/loaders/MaterialXLoader.js +2 -2
  50. package/examples/jsm/materials/LDrawConditionalLineMaterial.js +143 -0
  51. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +114 -0
  52. package/examples/jsm/math/ColorSpaces.js +76 -0
  53. package/examples/jsm/misc/ProgressiveLightMap.js +52 -40
  54. package/examples/jsm/misc/ProgressiveLightMapGPU.js +293 -0
  55. package/examples/jsm/misc/VolumeSlice.js +1 -0
  56. package/examples/jsm/objects/InstancedPoints.js +2 -4
  57. package/examples/jsm/objects/LensflareMesh.js +4 -2
  58. package/examples/jsm/objects/SkyMesh.js +5 -3
  59. package/examples/jsm/objects/Water2Mesh.js +7 -3
  60. package/examples/jsm/objects/WaterMesh.js +12 -10
  61. package/examples/jsm/postprocessing/AfterimagePass.js +14 -3
  62. package/examples/jsm/postprocessing/SSRPass.js +6 -0
  63. package/examples/jsm/renderers/CSS2DRenderer.js +6 -3
  64. package/examples/jsm/renderers/CSS3DRenderer.js +7 -4
  65. package/examples/jsm/shaders/FXAAShader.js +225 -224
  66. package/examples/jsm/transpiler/AST.js +2 -2
  67. package/examples/jsm/transpiler/GLSLDecoder.js +57 -25
  68. package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
  69. package/examples/jsm/transpiler/TSLEncoder.js +11 -6
  70. package/{src/nodes → examples/jsm/tsl}/display/AfterImageNode.js +18 -21
  71. package/{src/nodes → examples/jsm/tsl}/display/AnaglyphPassNode.js +2 -6
  72. package/{src/nodes → examples/jsm/tsl}/display/AnamorphicNode.js +12 -18
  73. package/{src/nodes → examples/jsm/tsl}/display/BleachBypass.js +1 -3
  74. package/{src/nodes → examples/jsm/tsl}/display/BloomNode.js +12 -41
  75. package/{src/nodes → examples/jsm/tsl}/display/DenoiseNode.js +60 -47
  76. package/{src/nodes → examples/jsm/tsl}/display/DepthOfFieldNode.js +4 -9
  77. package/{src/nodes → examples/jsm/tsl}/display/DotScreenNode.js +2 -9
  78. package/examples/jsm/tsl/display/FXAANode.js +316 -0
  79. package/{src/nodes → examples/jsm/tsl}/display/FilmNode.js +4 -7
  80. package/{src/nodes → examples/jsm/tsl}/display/GTAONode.js +73 -78
  81. package/{src/nodes → examples/jsm/tsl}/display/GaussianBlurNode.js +78 -42
  82. package/examples/jsm/tsl/display/LensflareNode.js +161 -0
  83. package/{src/nodes → examples/jsm/tsl}/display/Lut3DNode.js +3 -5
  84. package/{src/nodes → examples/jsm/tsl}/display/MotionBlur.js +2 -3
  85. package/examples/jsm/tsl/display/OutlineNode.js +434 -0
  86. package/{src/nodes → examples/jsm/tsl}/display/ParallaxBarrierPassNode.js +2 -5
  87. package/{src/nodes → examples/jsm/tsl}/display/PixelationPassNode.js +5 -17
  88. package/{src/nodes → examples/jsm/tsl}/display/RGBShiftNode.js +2 -6
  89. package/examples/jsm/tsl/display/SMAANode.js +620 -0
  90. package/{src/nodes → examples/jsm/tsl}/display/SSAAPassNode.js +10 -25
  91. package/examples/jsm/tsl/display/SSRNode.js +366 -0
  92. package/{src/nodes → examples/jsm/tsl}/display/Sepia.js +1 -2
  93. package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +4 -12
  94. package/{src/nodes → examples/jsm/tsl}/display/StereoCompositePassNode.js +9 -11
  95. package/{src/nodes → examples/jsm/tsl}/display/StereoPassNode.js +10 -11
  96. package/examples/jsm/tsl/display/TRAAPassNode.js +355 -0
  97. package/{src/nodes → examples/jsm/tsl}/display/TransitionNode.js +3 -7
  98. package/examples/jsm/tsl/display/hashBlur.js +24 -0
  99. package/examples/jsm/tsl/lighting/TiledLightsNode.js +389 -0
  100. package/examples/jsm/utils/SceneOptimizer.js +410 -0
  101. package/examples/jsm/utils/UVsDebug.js +1 -1
  102. package/examples/jsm/utils/{TextureUtilsGPU.js → WebGPUTextureUtils.js} +2 -1
  103. package/examples/jsm/webxr/OculusHandPointerModel.js +21 -21
  104. package/examples/jsm/webxr/Text2D.js +6 -6
  105. package/package.json +4 -4
  106. package/src/Three.Core.js +178 -0
  107. package/src/Three.TSL.js +526 -0
  108. package/src/Three.WebGPU.Nodes.js +9 -186
  109. package/src/Three.WebGPU.js +8 -186
  110. package/src/Three.js +1 -177
  111. package/src/animation/AnimationClip.js +2 -2
  112. package/src/animation/AnimationObjectGroup.js +2 -2
  113. package/src/audio/Audio.js +38 -0
  114. package/src/cameras/PerspectiveCamera.js +6 -6
  115. package/src/cameras/StereoCamera.js +2 -2
  116. package/src/constants.js +1 -6
  117. package/src/core/BufferGeometry.js +48 -8
  118. package/src/core/InterleavedBuffer.js +4 -4
  119. package/src/core/Object3D.js +2 -2
  120. package/src/extras/core/Curve.js +3 -3
  121. package/src/extras/core/Shape.js +2 -2
  122. package/src/geometries/CylinderGeometry.js +2 -2
  123. package/src/geometries/EdgesGeometry.js +2 -2
  124. package/src/geometries/LatheGeometry.js +2 -2
  125. package/src/lights/SpotLightShadow.js +2 -2
  126. package/src/materials/LineDashedMaterial.js +0 -1
  127. package/src/materials/Material.js +2 -2
  128. package/src/materials/MeshPhongMaterial.js +1 -1
  129. package/src/materials/MeshPhysicalMaterial.js +2 -2
  130. package/src/materials/MeshStandardMaterial.js +2 -2
  131. package/src/materials/nodes/Line2NodeMaterial.js +32 -13
  132. package/src/materials/nodes/LineDashedNodeMaterial.js +4 -2
  133. package/src/materials/nodes/NodeMaterial.js +93 -23
  134. package/src/materials/nodes/SpriteNodeMaterial.js +11 -2
  135. package/src/materials/nodes/manager/NodeMaterialObserver.js +119 -7
  136. package/src/math/ColorManagement.js +143 -102
  137. package/src/math/Line3.js +2 -2
  138. package/src/math/Quaternion.js +2 -2
  139. package/src/math/Spherical.js +3 -3
  140. package/src/math/Vector2.js +7 -7
  141. package/src/math/Vector3.js +9 -9
  142. package/src/math/Vector4.js +22 -9
  143. package/src/nodes/Nodes.js +2 -21
  144. package/src/nodes/TSL.js +9 -25
  145. package/src/nodes/accessors/Arrays.js +27 -0
  146. package/src/nodes/accessors/BuiltinNode.js +26 -0
  147. package/src/nodes/accessors/Camera.js +0 -1
  148. package/src/nodes/accessors/ClippingNode.js +76 -42
  149. package/src/nodes/accessors/InstanceNode.js +17 -20
  150. package/src/nodes/accessors/InstancedMeshNode.js +26 -0
  151. package/src/nodes/accessors/Lights.js +32 -0
  152. package/src/nodes/accessors/SceneNode.js +35 -1
  153. package/src/nodes/accessors/StorageBufferNode.js +61 -19
  154. package/src/nodes/accessors/StorageTextureNode.js +10 -4
  155. package/src/nodes/accessors/TextureNode.js +1 -1
  156. package/src/nodes/accessors/VelocityNode.js +13 -3
  157. package/src/nodes/code/FunctionCallNode.js +16 -5
  158. package/src/nodes/code/ScriptableNode.js +4 -4
  159. package/src/nodes/core/Node.js +1 -0
  160. package/src/nodes/core/NodeBuilder.js +31 -14
  161. package/src/nodes/core/NodeUtils.js +28 -0
  162. package/src/nodes/core/VarNode.js +15 -3
  163. package/src/nodes/core/constants.js +6 -0
  164. package/src/nodes/display/BlendModes.js +99 -0
  165. package/src/nodes/display/ColorAdjustment.js +53 -4
  166. package/src/nodes/display/ColorSpaceFunctions.js +5 -5
  167. package/src/nodes/display/ColorSpaceNode.js +27 -39
  168. package/src/nodes/display/PassNode.js +6 -4
  169. package/src/nodes/display/ToneMappingNode.js +1 -1
  170. package/src/nodes/display/ToonOutlinePassNode.js +3 -3
  171. package/src/nodes/display/ViewportDepthNode.js +48 -1
  172. package/src/nodes/functions/PhysicalLightingModel.js +21 -15
  173. package/src/nodes/functions/material/getAlphaHashThreshold.js +70 -0
  174. package/src/nodes/functions/material/getGeometryRoughness.js +8 -2
  175. package/src/nodes/functions/material/getParallaxCorrectNormal.js +22 -0
  176. package/src/nodes/gpgpu/ComputeNode.js +9 -1
  177. package/src/nodes/lighting/AnalyticLightNode.js +23 -419
  178. package/src/nodes/lighting/LightsNode.js +24 -12
  179. package/src/nodes/lighting/PointLightNode.js +41 -22
  180. package/src/nodes/lighting/PointShadowNode.js +254 -0
  181. package/src/nodes/lighting/RectAreaLightNode.js +3 -0
  182. package/src/nodes/lighting/ShadowNode.js +593 -0
  183. package/src/nodes/lighting/SpotLightNode.js +14 -2
  184. package/src/nodes/utils/LoopNode.js +2 -2
  185. package/src/nodes/utils/Oscillators.js +6 -0
  186. package/src/nodes/utils/PostProcessingUtils.js +89 -0
  187. package/src/nodes/utils/RTTNode.js +9 -1
  188. package/src/nodes/utils/ReflectorNode.js +101 -15
  189. package/src/nodes/utils/StorageArrayElementNode.js +2 -2
  190. package/src/nodes/utils/Timer.js +29 -0
  191. package/src/objects/BatchedMesh.js +472 -296
  192. package/src/objects/ClippingGroup.js +19 -0
  193. package/src/objects/Skeleton.js +2 -2
  194. package/src/renderers/WebGLRenderer.js +183 -109
  195. package/src/renderers/common/Animation.js +23 -11
  196. package/src/renderers/common/Attributes.js +4 -0
  197. package/src/renderers/common/Backend.js +2 -0
  198. package/src/renderers/common/Background.js +15 -5
  199. package/src/renderers/common/Bindings.js +23 -6
  200. package/src/renderers/common/ClippingContext.js +77 -85
  201. package/src/renderers/common/Constants.js +2 -1
  202. package/src/renderers/common/Geometries.js +20 -0
  203. package/src/renderers/common/IndirectStorageBufferAttribute.js +15 -0
  204. package/src/renderers/common/Lighting.js +45 -0
  205. package/src/renderers/common/PostProcessingUtils.js +86 -0
  206. package/src/renderers/common/RenderList.js +48 -17
  207. package/src/renderers/common/RenderLists.js +4 -2
  208. package/src/renderers/common/RenderObject.js +45 -28
  209. package/src/renderers/common/RenderObjects.js +12 -6
  210. package/src/renderers/common/Renderer.js +222 -77
  211. package/src/renderers/common/Textures.js +41 -17
  212. package/src/renderers/common/UniformsGroup.js +16 -4
  213. package/src/renderers/common/extras/PMREMGenerator.js +89 -13
  214. package/src/renderers/common/nodes/NodeLibrary.js +2 -15
  215. package/src/renderers/common/nodes/NodeStorageBuffer.js +2 -3
  216. package/src/renderers/common/nodes/NodeUniform.js +42 -0
  217. package/src/renderers/common/nodes/Nodes.js +2 -2
  218. package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
  219. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
  220. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
  221. package/src/renderers/webgl/WebGLBackground.js +20 -1
  222. package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
  223. package/src/renderers/webgl/WebGLCapabilities.js +0 -7
  224. package/src/renderers/webgl/WebGLGeometries.js +0 -28
  225. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
  226. package/src/renderers/webgl/WebGLProgram.js +24 -28
  227. package/src/renderers/webgl/WebGLPrograms.js +5 -2
  228. package/src/renderers/webgl/WebGLState.js +37 -1
  229. package/src/renderers/webgl/WebGLTextures.js +29 -12
  230. package/src/renderers/webgl-fallback/WebGLBackend.js +111 -37
  231. package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +2 -7
  232. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +43 -12
  233. package/src/renderers/webgl-fallback/utils/WebGLState.js +26 -1
  234. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +37 -9
  235. package/src/renderers/webgpu/WebGPUBackend.js +152 -56
  236. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +1 -1
  237. package/src/renderers/webgpu/WebGPURenderer.js +1 -1
  238. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +0 -8
  239. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +13 -34
  240. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +192 -92
  241. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +12 -4
  242. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +15 -2
  243. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +72 -7
  244. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +29 -9
  245. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +29 -7
  246. package/src/renderers/webgpu/utils/WebGPUUtils.js +0 -1
  247. package/src/renderers/webxr/WebXRManager.js +4 -4
  248. package/src/textures/Source.js +2 -2
  249. package/src/textures/Texture.js +2 -2
  250. package/examples/jsm/cameras/CinematicCamera.js +0 -208
  251. package/src/nodes/display/BlendMode.js +0 -54
  252. package/src/nodes/display/FXAANode.js +0 -332
  253. package/src/nodes/utils/OscNode.js +0 -85
  254. package/src/nodes/utils/TimerNode.js +0 -97
  255. /package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +0 -0
@@ -32,7 +32,7 @@ class Bindings extends DataMap {
32
32
 
33
33
  this._init( bindGroup );
34
34
 
35
- this.backend.createBindings( bindGroup, bindings );
35
+ this.backend.createBindings( bindGroup, bindings, 0 );
36
36
 
37
37
  groupData.bindGroup = bindGroup;
38
38
 
@@ -56,7 +56,7 @@ class Bindings extends DataMap {
56
56
 
57
57
  this._init( bindGroup );
58
58
 
59
- this.backend.createBindings( bindGroup, bindings );
59
+ this.backend.createBindings( bindGroup, bindings, 0 );
60
60
 
61
61
  groupData.bindGroup = bindGroup;
62
62
 
@@ -101,8 +101,9 @@ class Bindings extends DataMap {
101
101
  } else if ( binding.isStorageBuffer ) {
102
102
 
103
103
  const attribute = binding.attribute;
104
+ const attributeType = attribute.isIndirectStorageBufferAttribute ? AttributeType.INDIRECT : AttributeType.STORAGE;
104
105
 
105
- this.attributes.update( attribute, AttributeType.STORAGE );
106
+ this.attributes.update( attribute, attributeType );
106
107
 
107
108
  }
108
109
 
@@ -115,6 +116,9 @@ class Bindings extends DataMap {
115
116
  const { backend } = this;
116
117
 
117
118
  let needsBindingsUpdate = false;
119
+ let cacheBindings = true;
120
+ let cacheIndex = 0;
121
+ let version = 0;
118
122
 
119
123
  // iterate over all bindings and check if buffer updates or a new binding group is required
120
124
 
@@ -144,7 +148,9 @@ class Bindings extends DataMap {
144
148
 
145
149
  } else if ( binding.isSampledTexture ) {
146
150
 
147
- if ( binding.needsBindingsUpdate( this.textures.get( binding.texture ).generation ) ) needsBindingsUpdate = true;
151
+ const texturesTextureData = this.textures.get( binding.texture );
152
+
153
+ if ( binding.needsBindingsUpdate( texturesTextureData.generation ) ) needsBindingsUpdate = true;
148
154
 
149
155
  const updated = binding.update();
150
156
 
@@ -158,6 +164,17 @@ class Bindings extends DataMap {
158
164
 
159
165
  const textureData = backend.get( texture );
160
166
 
167
+ if ( textureData.externalTexture !== undefined || texturesTextureData.isDefaultTexture ) {
168
+
169
+ cacheBindings = false;
170
+
171
+ } else {
172
+
173
+ cacheIndex = cacheIndex * 10 + texture.id;
174
+ version += texture.version;
175
+
176
+ }
177
+
161
178
  if ( backend.isWebGPUBackend === true && textureData.texture === undefined && textureData.externalTexture === undefined ) {
162
179
 
163
180
  // TODO: Remove this once we found why updated === false isn't bound to a texture in the WebGPU backend
@@ -176,7 +193,7 @@ class Bindings extends DataMap {
176
193
 
177
194
  textureData.needsMipmap = true;
178
195
 
179
- } else if ( texture.generateMipmaps === true && this.textures.needsMipmaps( texture ) && textureData.needsMipmap === true ) {
196
+ } else if ( this.textures.needsMipmaps( texture ) && textureData.needsMipmap === true ) {
180
197
 
181
198
  this.backend.generateMipmaps( texture );
182
199
 
@@ -192,7 +209,7 @@ class Bindings extends DataMap {
192
209
 
193
210
  if ( needsBindingsUpdate === true ) {
194
211
 
195
- this.backend.updateBindings( bindGroup, bindings );
212
+ this.backend.updateBindings( bindGroup, bindings, cacheBindings ? cacheIndex : 0, version );
196
213
 
197
214
  }
198
215
 
@@ -1,40 +1,53 @@
1
1
  import { Matrix3 } from '../../math/Matrix3.js';
2
2
  import { Plane } from '../../math/Plane.js';
3
3
  import { Vector4 } from '../../math/Vector4.js';
4
- import { hash } from '../../nodes/core/NodeUtils.js';
5
4
 
6
5
  const _plane = /*@__PURE__*/ new Plane();
7
6
 
8
7
  class ClippingContext {
9
8
 
10
- constructor() {
9
+ constructor( parentContext = null ) {
11
10
 
12
11
  this.version = 0;
13
12
 
14
- this.globalClippingCount = 0;
13
+ this.clipIntersection = null;
14
+ this.cacheKey = '';
15
15
 
16
- this.localClippingCount = 0;
17
- this.localClippingEnabled = false;
18
- this.localClipIntersection = false;
19
16
 
20
- this.planes = [];
17
+ if ( parentContext === null ) {
21
18
 
22
- this.parentVersion = 0;
23
- this.viewNormalMatrix = new Matrix3();
24
- this.cacheKey = 0;
19
+ this.intersectionPlanes = [];
20
+ this.unionPlanes = [];
21
+
22
+ this.viewNormalMatrix = new Matrix3();
23
+ this.clippingGroupContexts = new WeakMap();
24
+
25
+ this.shadowPass = false;
26
+
27
+ } else {
28
+
29
+ this.viewNormalMatrix = parentContext.viewNormalMatrix;
30
+ this.clippingGroupContexts = parentContext.clippingGroupContexts;
31
+
32
+ this.shadowPass = parentContext.shadowPass;
33
+
34
+ this.viewMatrix = parentContext.viewMatrix;
35
+
36
+ }
37
+
38
+ this.parentVersion = null;
25
39
 
26
40
  }
27
41
 
28
- projectPlanes( source, offset ) {
42
+ projectPlanes( source, destination, offset ) {
29
43
 
30
44
  const l = source.length;
31
- const planes = this.planes;
32
45
 
33
46
  for ( let i = 0; i < l; i ++ ) {
34
47
 
35
48
  _plane.copy( source[ i ] ).applyMatrix4( this.viewMatrix, this.viewNormalMatrix );
36
49
 
37
- const v = planes[ offset + i ];
50
+ const v = destination[ offset + i ];
38
51
  const normal = _plane.normal;
39
52
 
40
53
  v.x = - normal.x;
@@ -46,129 +59,108 @@ class ClippingContext {
46
59
 
47
60
  }
48
61
 
49
- updateGlobal( renderer, camera ) {
62
+ updateGlobal( scene, camera ) {
50
63
 
51
- const rendererClippingPlanes = renderer.clippingPlanes;
64
+ this.shadowPass = ( scene.overrideMaterial !== null && scene.overrideMaterial.isShadowNodeMaterial );
52
65
  this.viewMatrix = camera.matrixWorldInverse;
53
66
 
54
67
  this.viewNormalMatrix.getNormalMatrix( this.viewMatrix );
55
68
 
56
- let update = false;
57
-
58
- if ( Array.isArray( rendererClippingPlanes ) && rendererClippingPlanes.length !== 0 ) {
69
+ }
59
70
 
60
- const l = rendererClippingPlanes.length;
71
+ update( parentContext, clippingGroup ) {
61
72
 
62
- if ( l !== this.globalClippingCount ) {
73
+ let update = false;
63
74
 
64
- const planes = [];
75
+ if ( parentContext.version !== this.parentVersion ) {
65
76
 
66
- for ( let i = 0; i < l; i ++ ) {
77
+ this.intersectionPlanes = Array.from( parentContext.intersectionPlanes );
78
+ this.unionPlanes = Array.from( parentContext.unionPlanes );
79
+ this.parentVersion = parentContext.version;
67
80
 
68
- planes.push( new Vector4() );
81
+ }
69
82
 
70
- }
83
+ if ( this.clipIntersection !== clippingGroup.clipIntersection ) {
71
84
 
72
- this.globalClippingCount = l;
73
- this.planes = planes;
85
+ this.clipIntersection = clippingGroup.clipIntersection;
74
86
 
75
- update = true;
87
+ if ( this.clipIntersection ) {
76
88
 
77
- }
89
+ this.unionPlanes.length = parentContext.unionPlanes.length;
78
90
 
79
- this.projectPlanes( rendererClippingPlanes, 0 );
91
+ } else {
80
92
 
81
- } else if ( this.globalClippingCount !== 0 ) {
93
+ this.intersectionPlanes.length = parentContext.intersectionPlanes.length;
82
94
 
83
- this.globalClippingCount = 0;
84
- this.planes = [];
85
- update = true;
95
+ }
86
96
 
87
97
  }
88
98
 
89
- if ( renderer.localClippingEnabled !== this.localClippingEnabled ) {
99
+ const srcClippingPlanes = clippingGroup.clippingPlanes;
100
+ const l = srcClippingPlanes.length;
90
101
 
91
- this.localClippingEnabled = renderer.localClippingEnabled;
92
- update = true;
102
+ let dstClippingPlanes;
103
+ let offset;
93
104
 
94
- }
105
+ if ( this.clipIntersection ) {
95
106
 
96
- if ( update ) {
107
+ dstClippingPlanes = this.intersectionPlanes;
108
+ offset = parentContext.intersectionPlanes.length;
97
109
 
98
- this.version ++;
99
- this.cacheKey = hash( this.globalClippingCount, this.localClippingEnabled === true ? 1 : 0 );
110
+ } else {
111
+
112
+ dstClippingPlanes = this.unionPlanes;
113
+ offset = parentContext.unionPlanes.length;
100
114
 
101
115
  }
102
116
 
103
- }
117
+ if ( dstClippingPlanes.length !== offset + l ) {
104
118
 
105
- update( parent, material ) {
119
+ dstClippingPlanes.length = offset + l;
106
120
 
107
- let update = false;
121
+ for ( let i = 0; i < l; i ++ ) {
108
122
 
109
- if ( this !== parent && parent.version !== this.parentVersion ) {
123
+ dstClippingPlanes[ offset + i ] = new Vector4();
110
124
 
111
- this.globalClippingCount = material.isShadowNodeMaterial ? 0 : parent.globalClippingCount;
112
- this.localClippingEnabled = parent.localClippingEnabled;
113
- this.planes = Array.from( parent.planes );
114
- this.parentVersion = parent.version;
115
- this.viewMatrix = parent.viewMatrix;
116
- this.viewNormalMatrix = parent.viewNormalMatrix;
125
+ }
117
126
 
118
127
  update = true;
119
128
 
120
129
  }
121
130
 
122
- if ( this.localClippingEnabled ) {
123
-
124
- const localClippingPlanes = material.clippingPlanes;
125
-
126
- if ( ( Array.isArray( localClippingPlanes ) && localClippingPlanes.length !== 0 ) ) {
127
-
128
- const l = localClippingPlanes.length;
129
- const planes = this.planes;
130
- const offset = this.globalClippingCount;
131
+ this.projectPlanes( srcClippingPlanes, dstClippingPlanes, offset );
131
132
 
132
- if ( update || l !== this.localClippingCount ) {
133
-
134
- planes.length = offset + l;
135
-
136
- for ( let i = 0; i < l; i ++ ) {
137
-
138
- planes[ offset + i ] = new Vector4();
139
-
140
- }
133
+ if ( update ) {
141
134
 
142
- this.localClippingCount = l;
143
- update = true;
135
+ this.version ++;
136
+ this.cacheKey = `${ this.intersectionPlanes.length }:${ this.unionPlanes.length }`;
144
137
 
145
- }
138
+ }
146
139
 
147
- this.projectPlanes( localClippingPlanes, offset );
140
+ }
148
141
 
142
+ getGroupContext( clippingGroup ) {
149
143
 
150
- } else if ( this.localClippingCount !== 0 ) {
144
+ if ( this.shadowPass && ! clippingGroup.clipShadows ) return this;
151
145
 
152
- this.localClippingCount = 0;
153
- update = true;
146
+ let context = this.clippingGroupContexts.get( clippingGroup );
154
147
 
155
- }
148
+ if ( context === undefined ) {
156
149
 
157
- if ( this.localClipIntersection !== material.clipIntersection ) {
150
+ context = new ClippingContext( this );
151
+ this.clippingGroupContexts.set( clippingGroup, context );
158
152
 
159
- this.localClipIntersection = material.clipIntersection;
160
- update = true;
153
+ }
161
154
 
162
- }
155
+ context.update( this, clippingGroup );
163
156
 
164
- }
157
+ return context;
165
158
 
166
- if ( update ) {
159
+ }
167
160
 
168
- this.version += parent.version;
169
- this.cacheKey = hash( parent.cacheKey, this.localClippingCount, this.localClipIntersection === true ? 1 : 0 );
161
+ get unionClippingCount() {
170
162
 
171
- }
163
+ return this.unionPlanes.length;
172
164
 
173
165
  }
174
166
 
@@ -1,7 +1,8 @@
1
1
  export const AttributeType = {
2
2
  VERTEX: 1,
3
3
  INDEX: 2,
4
- STORAGE: 4
4
+ STORAGE: 3,
5
+ INDIRECT: 4
5
6
  };
6
7
 
7
8
  // size of a chunk in bytes (STD140 layout)
@@ -144,6 +144,8 @@ class Geometries extends DataMap {
144
144
 
145
145
  updateAttributes( renderObject ) {
146
146
 
147
+ // attributes
148
+
147
149
  const attributes = renderObject.getAttributes();
148
150
 
149
151
  for ( const attribute of attributes ) {
@@ -160,6 +162,8 @@ class Geometries extends DataMap {
160
162
 
161
163
  }
162
164
 
165
+ // indexes
166
+
163
167
  const index = this.getIndex( renderObject );
164
168
 
165
169
  if ( index !== null ) {
@@ -168,6 +172,16 @@ class Geometries extends DataMap {
168
172
 
169
173
  }
170
174
 
175
+ // indirect
176
+
177
+ const indirect = renderObject.geometry.indirect;
178
+
179
+ if ( indirect !== null ) {
180
+
181
+ this.updateAttribute( indirect, AttributeType.INDIRECT );
182
+
183
+ }
184
+
171
185
  }
172
186
 
173
187
  updateAttribute( attribute, type ) {
@@ -206,6 +220,12 @@ class Geometries extends DataMap {
206
220
 
207
221
  }
208
222
 
223
+ getIndirect( renderObject ) {
224
+
225
+ return renderObject.geometry.indirect;
226
+
227
+ }
228
+
209
229
  getIndex( renderObject ) {
210
230
 
211
231
  const { geometry, material } = renderObject;
@@ -0,0 +1,15 @@
1
+ import StorageBufferAttribute from './StorageBufferAttribute.js';
2
+
3
+ class IndirectStorageBufferAttribute extends StorageBufferAttribute {
4
+
5
+ constructor( array, itemSize ) {
6
+
7
+ super( array, itemSize, Uint32Array );
8
+
9
+ this.isIndirectStorageBufferAttribute = true;
10
+
11
+ }
12
+
13
+ }
14
+
15
+ export default IndirectStorageBufferAttribute;
@@ -0,0 +1,45 @@
1
+ import { LightsNode } from '../../nodes/Nodes.js';
2
+ import ChainMap from './ChainMap.js';
3
+
4
+ const _defaultLights = /*@__PURE__*/ new LightsNode();
5
+
6
+ class Lighting extends ChainMap {
7
+
8
+ constructor() {
9
+
10
+ super();
11
+
12
+ }
13
+
14
+ createNode( lights = [] ) {
15
+
16
+ return new LightsNode().setLights( lights );
17
+
18
+ }
19
+
20
+ getNode( scene, camera ) {
21
+
22
+ // ignore post-processing
23
+
24
+ if ( scene.isQuadMesh ) return _defaultLights;
25
+
26
+ // tiled lighting
27
+
28
+ const keys = [ scene, camera ];
29
+
30
+ let node = this.get( keys );
31
+
32
+ if ( node === undefined ) {
33
+
34
+ node = this.createNode();
35
+ this.set( keys, node );
36
+
37
+ }
38
+
39
+ return node;
40
+
41
+ }
42
+
43
+ }
44
+
45
+ export default Lighting;
@@ -0,0 +1,86 @@
1
+ import { Color } from '../../math/Color.js';
2
+
3
+ // renderer state
4
+
5
+ export function saveRendererState( renderer, state = {} ) {
6
+
7
+ state.toneMapping = renderer.toneMapping;
8
+ state.toneMappingExposure = renderer.toneMappingExposure;
9
+ state.outputColorSpace = renderer.outputColorSpace;
10
+ state.renderTarget = renderer.getRenderTarget();
11
+ state.activeCubeFace = renderer.getActiveCubeFace();
12
+ state.activeMipmapLevel = renderer.getActiveMipmapLevel();
13
+ state.renderObjectFunction = renderer.getRenderObjectFunction();
14
+ state.pixelRatio = renderer.getPixelRatio();
15
+ state.mrt = renderer.getMRT();
16
+ state.clearColor = renderer.getClearColor( state.clearColor || new Color() );
17
+ state.clearAlpha = renderer.getClearAlpha();
18
+ state.autoClear = renderer.autoClear;
19
+ state.scissorTest = renderer.getScissorTest();
20
+
21
+ return state;
22
+
23
+ }
24
+
25
+ export function resetRendererState( renderer, state ) {
26
+
27
+ state = saveRendererState( renderer, state );
28
+
29
+ renderer.setMRT( null );
30
+ renderer.setRenderObjectFunction( null );
31
+ renderer.setClearColor( 0x000000, 1 );
32
+ renderer.autoClear = true;
33
+
34
+ return state;
35
+
36
+ }
37
+
38
+ export function restoreRendererState( renderer, state ) {
39
+
40
+ renderer.toneMapping = state.toneMapping;
41
+ renderer.toneMappingExposure = state.toneMappingExposure;
42
+ renderer.outputColorSpace = state.outputColorSpace;
43
+ renderer.setRenderTarget( state.renderTarget, state.activeCubeFace, state.activeMipmapLevel );
44
+ renderer.setRenderObjectFunction( state.renderObjectFunction );
45
+ renderer.setPixelRatio( state.pixelRatio );
46
+ renderer.setMRT( state.mrt );
47
+ renderer.setClearColor( state.clearColor, state.clearAlpha );
48
+ renderer.autoClear = state.autoClear;
49
+ renderer.setScissorTest( state.scissorTest );
50
+
51
+ }
52
+
53
+ // renderer and scene state
54
+
55
+ export function saveRendererAndSceneState( renderer, scene, state = {} ) {
56
+
57
+ state = saveRendererState( renderer, state );
58
+ state.background = scene.background;
59
+ state.backgroundNode = scene.backgroundNode;
60
+ state.overrideMaterial = scene.overrideMaterial;
61
+
62
+ return state;
63
+
64
+ }
65
+
66
+ export function resetRendererAndSceneState( renderer, scene, state ) {
67
+
68
+ state = saveRendererAndSceneState( renderer, scene, state );
69
+
70
+ scene.background = null;
71
+ scene.backgroundNode = null;
72
+ scene.overrideMaterial = null;
73
+
74
+ return state;
75
+
76
+ }
77
+
78
+ export function restoreRendererAndSceneState( renderer, scene, state ) {
79
+
80
+ restoreRendererState( renderer, state );
81
+
82
+ scene.background = state.background;
83
+ scene.backgroundNode = state.backgroundNode;
84
+ scene.overrideMaterial = state.overrideMaterial;
85
+
86
+ }
@@ -1,4 +1,4 @@
1
- import { LightsNode } from '../../nodes/Nodes.js';
1
+ import { DoubleSide } from '../../constants.js';
2
2
 
3
3
  function painterSortStable( a, b ) {
4
4
 
@@ -48,20 +48,32 @@ function reversePainterSortStable( a, b ) {
48
48
 
49
49
  }
50
50
 
51
+ function needsDoublePass( material ) {
52
+
53
+ const hasTransmission = material.transmission > 0 || material.transmissionNode;
54
+
55
+ return hasTransmission && material.side === DoubleSide && material.forceSinglePass === false;
56
+
57
+ }
58
+
51
59
  class RenderList {
52
60
 
53
- constructor() {
61
+ constructor( lighting, scene, camera ) {
54
62
 
55
63
  this.renderItems = [];
56
64
  this.renderItemsIndex = 0;
57
65
 
58
66
  this.opaque = [];
67
+ this.transparentDoublePass = [];
59
68
  this.transparent = [];
60
69
  this.bundles = [];
61
70
 
62
- this.lightsNode = new LightsNode( [] );
71
+ this.lightsNode = lighting.getNode( scene, camera );
63
72
  this.lightsArray = [];
64
73
 
74
+ this.scene = scene;
75
+ this.camera = camera;
76
+
65
77
  this.occlusionQueryCount = 0;
66
78
 
67
79
  }
@@ -71,6 +83,7 @@ class RenderList {
71
83
  this.renderItemsIndex = 0;
72
84
 
73
85
  this.opaque.length = 0;
86
+ this.transparentDoublePass.length = 0;
74
87
  this.transparent.length = 0;
75
88
  this.bundles.length = 0;
76
89
 
@@ -82,7 +95,7 @@ class RenderList {
82
95
 
83
96
  }
84
97
 
85
- getNextRenderItem( object, geometry, material, groupOrder, z, group ) {
98
+ getNextRenderItem( object, geometry, material, groupOrder, z, group, clippingContext ) {
86
99
 
87
100
  let renderItem = this.renderItems[ this.renderItemsIndex ];
88
101
 
@@ -96,7 +109,8 @@ class RenderList {
96
109
  groupOrder: groupOrder,
97
110
  renderOrder: object.renderOrder,
98
111
  z: z,
99
- group: group
112
+ group: group,
113
+ clippingContext: clippingContext
100
114
  };
101
115
 
102
116
  this.renderItems[ this.renderItemsIndex ] = renderItem;
@@ -111,6 +125,7 @@ class RenderList {
111
125
  renderItem.renderOrder = object.renderOrder;
112
126
  renderItem.z = z;
113
127
  renderItem.group = group;
128
+ renderItem.clippingContext = clippingContext;
114
129
 
115
130
  }
116
131
 
@@ -120,21 +135,41 @@ class RenderList {
120
135
 
121
136
  }
122
137
 
123
- push( object, geometry, material, groupOrder, z, group ) {
138
+ push( object, geometry, material, groupOrder, z, group, clippingContext ) {
124
139
 
125
- const renderItem = this.getNextRenderItem( object, geometry, material, groupOrder, z, group );
140
+ const renderItem = this.getNextRenderItem( object, geometry, material, groupOrder, z, group, clippingContext );
126
141
 
127
142
  if ( object.occlusionTest === true ) this.occlusionQueryCount ++;
128
143
 
129
- ( material.transparent === true || material.transmission > 0 ? this.transparent : this.opaque ).push( renderItem );
144
+ if ( material.transparent === true || material.transmission > 0 ) {
145
+
146
+ if ( needsDoublePass( material ) ) this.transparentDoublePass.push( renderItem );
147
+
148
+ this.transparent.push( renderItem );
149
+
150
+ } else {
151
+
152
+ this.opaque.push( renderItem );
153
+
154
+ }
130
155
 
131
156
  }
132
157
 
133
- unshift( object, geometry, material, groupOrder, z, group ) {
158
+ unshift( object, geometry, material, groupOrder, z, group, clippingContext ) {
159
+
160
+ const renderItem = this.getNextRenderItem( object, geometry, material, groupOrder, z, group, clippingContext );
161
+
162
+ if ( material.transparent === true || material.transmission > 0 ) {
163
+
164
+ if ( needsDoublePass( material ) ) this.transparentDoublePass.unshift( renderItem );
165
+
166
+ this.transparent.unshift( renderItem );
167
+
168
+ } else {
134
169
 
135
- const renderItem = this.getNextRenderItem( object, geometry, material, groupOrder, z, group );
170
+ this.opaque.unshift( renderItem );
136
171
 
137
- ( material.transparent === true ? this.transparent : this.opaque ).unshift( renderItem );
172
+ }
138
173
 
139
174
  }
140
175
 
@@ -150,15 +185,10 @@ class RenderList {
150
185
 
151
186
  }
152
187
 
153
- getLightsNode() {
154
-
155
- return this.lightsNode.fromLights( this.lightsArray );
156
-
157
- }
158
-
159
188
  sort( customOpaqueSort, customTransparentSort ) {
160
189
 
161
190
  if ( this.opaque.length > 1 ) this.opaque.sort( customOpaqueSort || painterSortStable );
191
+ if ( this.transparentDoublePass.length > 1 ) this.transparentDoublePass.sort( customTransparentSort || reversePainterSortStable );
162
192
  if ( this.transparent.length > 1 ) this.transparent.sort( customTransparentSort || reversePainterSortStable );
163
193
 
164
194
  }
@@ -185,6 +215,7 @@ class RenderList {
185
215
  renderItem.renderOrder = null;
186
216
  renderItem.z = null;
187
217
  renderItem.group = null;
218
+ renderItem.clippingContext = null;
188
219
 
189
220
  }
190
221