super-three 0.169.1 → 0.170.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 (193) hide show
  1. package/build/three.cjs +974 -562
  2. package/build/three.module.js +975 -559
  3. package/build/three.module.min.js +1 -1
  4. package/build/three.webgpu.js +8398 -9842
  5. package/build/three.webgpu.min.js +1 -1
  6. package/build/three.webgpu.nodes.js +8398 -9842
  7. package/build/three.webgpu.nodes.min.js +1 -1
  8. package/examples/jsm/Addons.js +3 -3
  9. package/examples/jsm/animation/MMDAnimationHelper.js +2 -0
  10. package/examples/jsm/animation/MMDPhysics.js +2 -0
  11. package/examples/jsm/controls/TransformControls.js +22 -6
  12. package/examples/jsm/csm/CSM.js +2 -2
  13. package/examples/jsm/csm/CSMFrustum.js +7 -4
  14. package/examples/jsm/csm/CSMHelper.js +2 -0
  15. package/examples/jsm/csm/CSMShadowNode.js +435 -0
  16. package/examples/jsm/curves/NURBSCurve.js +34 -3
  17. package/examples/jsm/exporters/GLTFExporter.js +138 -71
  18. package/examples/jsm/exporters/KTX2Exporter.js +35 -12
  19. package/examples/jsm/exporters/MMDExporter.js +6 -0
  20. package/examples/jsm/exporters/USDZExporter.js +21 -3
  21. package/examples/jsm/geometries/DecalGeometry.js +65 -20
  22. package/examples/jsm/geometries/InstancedPointsGeometry.js +2 -0
  23. package/examples/jsm/helpers/TextureHelperGPU.js +175 -0
  24. package/examples/jsm/interactive/HTMLMesh.js +1 -0
  25. package/examples/jsm/lighting/TiledLighting.js +18 -0
  26. package/examples/jsm/lights/RectAreaLightTexturesLib.js +1 -1
  27. package/examples/jsm/lines/LineMaterial.js +7 -2
  28. package/examples/jsm/lines/LineSegmentsGeometry.js +2 -0
  29. package/examples/jsm/lines/webgpu/LineSegments2.js +0 -15
  30. package/examples/jsm/lines/webgpu/Wireframe.js +56 -0
  31. package/examples/jsm/loaders/3DMLoader.js +1 -0
  32. package/examples/jsm/loaders/3MFLoader.js +91 -0
  33. package/examples/jsm/loaders/FBXLoader.js +12 -2
  34. package/examples/jsm/loaders/GLTFLoader.js +2 -0
  35. package/examples/jsm/loaders/KTX2Loader.js +140 -49
  36. package/examples/jsm/loaders/LDrawLoader.js +22 -136
  37. package/examples/jsm/loaders/LottieLoader.js +1 -0
  38. package/examples/jsm/loaders/MMDLoader.js +9 -2
  39. package/examples/jsm/materials/LDrawConditionalLineMaterial.js +143 -0
  40. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +114 -0
  41. package/examples/jsm/materials/MeshGouraudMaterial.js +6 -2
  42. package/examples/jsm/math/ColorSpaces.js +76 -0
  43. package/examples/jsm/misc/ProgressiveLightMap.js +52 -40
  44. package/examples/jsm/misc/ProgressiveLightMapGPU.js +293 -0
  45. package/examples/jsm/misc/VolumeSlice.js +1 -0
  46. package/examples/jsm/objects/WaterMesh.js +8 -8
  47. package/examples/jsm/postprocessing/AfterimagePass.js +14 -3
  48. package/examples/jsm/postprocessing/SSRPass.js +6 -0
  49. package/examples/jsm/renderers/CSS2DRenderer.js +6 -3
  50. package/examples/jsm/renderers/CSS3DRenderer.js +7 -4
  51. package/examples/jsm/shaders/FXAAShader.js +225 -224
  52. package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
  53. package/{src/nodes → examples/jsm/tsl}/display/AfterImageNode.js +17 -20
  54. package/{src/nodes → examples/jsm/tsl}/display/AnaglyphPassNode.js +2 -6
  55. package/{src/nodes → examples/jsm/tsl}/display/AnamorphicNode.js +12 -18
  56. package/{src/nodes → examples/jsm/tsl}/display/BleachBypass.js +1 -3
  57. package/{src/nodes → examples/jsm/tsl}/display/BloomNode.js +11 -40
  58. package/{src/nodes → examples/jsm/tsl}/display/DenoiseNode.js +18 -41
  59. package/{src/nodes → examples/jsm/tsl}/display/DepthOfFieldNode.js +2 -8
  60. package/{src/nodes → examples/jsm/tsl}/display/DotScreenNode.js +2 -9
  61. package/examples/jsm/tsl/display/FXAANode.js +316 -0
  62. package/{src/nodes → examples/jsm/tsl}/display/FilmNode.js +2 -6
  63. package/{src/nodes → examples/jsm/tsl}/display/GTAONode.js +30 -70
  64. package/{src/nodes → examples/jsm/tsl}/display/GaussianBlurNode.js +74 -36
  65. package/examples/jsm/tsl/display/LensflareNode.js +161 -0
  66. package/{src/nodes → examples/jsm/tsl}/display/Lut3DNode.js +1 -4
  67. package/{src/nodes → examples/jsm/tsl}/display/MotionBlur.js +2 -3
  68. package/examples/jsm/tsl/display/OutlineNode.js +434 -0
  69. package/{src/nodes → examples/jsm/tsl}/display/ParallaxBarrierPassNode.js +1 -5
  70. package/{src/nodes → examples/jsm/tsl}/display/PixelationPassNode.js +3 -15
  71. package/{src/nodes → examples/jsm/tsl}/display/RGBShiftNode.js +1 -6
  72. package/examples/jsm/tsl/display/SMAANode.js +620 -0
  73. package/{src/nodes → examples/jsm/tsl}/display/SSAAPassNode.js +10 -25
  74. package/examples/jsm/tsl/display/SSRNode.js +343 -0
  75. package/{src/nodes → examples/jsm/tsl}/display/Sepia.js +1 -2
  76. package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +3 -11
  77. package/{src/nodes → examples/jsm/tsl}/display/StereoCompositePassNode.js +9 -11
  78. package/{src/nodes → examples/jsm/tsl}/display/StereoPassNode.js +10 -11
  79. package/examples/jsm/tsl/display/TRAAPassNode.js +355 -0
  80. package/{src/nodes → examples/jsm/tsl}/display/TransitionNode.js +1 -6
  81. package/examples/jsm/tsl/display/hashBlur.js +24 -0
  82. package/examples/jsm/tsl/lighting/TiledLightsNode.js +392 -0
  83. package/examples/jsm/utils/{TextureUtilsGPU.js → WebGPUTextureUtils.js} +2 -1
  84. package/examples/jsm/webxr/OculusHandPointerModel.js +21 -21
  85. package/examples/jsm/webxr/Text2D.js +6 -6
  86. package/package.json +2 -2
  87. package/src/Three.WebGPU.Nodes.js +4 -0
  88. package/src/Three.WebGPU.js +4 -0
  89. package/src/constants.js +1 -6
  90. package/src/core/BufferGeometry.js +44 -6
  91. package/src/geometries/CylinderGeometry.js +2 -2
  92. package/src/materials/LineBasicMaterial.js +6 -2
  93. package/src/materials/LineDashedMaterial.js +6 -2
  94. package/src/materials/Material.js +14 -1
  95. package/src/materials/MeshBasicMaterial.js +6 -2
  96. package/src/materials/MeshDepthMaterial.js +6 -2
  97. package/src/materials/MeshDistanceMaterial.js +6 -2
  98. package/src/materials/MeshLambertMaterial.js +6 -2
  99. package/src/materials/MeshMatcapMaterial.js +6 -2
  100. package/src/materials/MeshNormalMaterial.js +6 -2
  101. package/src/materials/MeshPhongMaterial.js +6 -2
  102. package/src/materials/MeshPhysicalMaterial.js +6 -2
  103. package/src/materials/MeshStandardMaterial.js +6 -2
  104. package/src/materials/MeshToonMaterial.js +6 -2
  105. package/src/materials/PointsMaterial.js +6 -2
  106. package/src/materials/RawShaderMaterial.js +6 -2
  107. package/src/materials/ShaderMaterial.js +6 -2
  108. package/src/materials/ShadowMaterial.js +6 -2
  109. package/src/materials/SpriteMaterial.js +6 -2
  110. package/src/materials/nodes/NodeMaterial.js +31 -9
  111. package/src/materials/nodes/SpriteNodeMaterial.js +11 -2
  112. package/src/materials/nodes/manager/NodeMaterialObserver.js +111 -2
  113. package/src/math/ColorManagement.js +118 -85
  114. package/src/math/Vector4.js +11 -0
  115. package/src/nodes/Nodes.js +1 -21
  116. package/src/nodes/TSL.js +6 -24
  117. package/src/nodes/accessors/Camera.js +0 -1
  118. package/src/nodes/accessors/SceneNode.js +35 -1
  119. package/src/nodes/accessors/StorageBufferNode.js +32 -10
  120. package/src/nodes/accessors/VelocityNode.js +13 -3
  121. package/src/nodes/code/FunctionCallNode.js +16 -5
  122. package/src/nodes/code/ScriptableNode.js +4 -4
  123. package/src/nodes/core/Node.js +1 -0
  124. package/src/nodes/core/NodeBuilder.js +29 -5
  125. package/src/nodes/core/VarNode.js +15 -3
  126. package/src/nodes/display/ColorAdjustment.js +53 -4
  127. package/src/nodes/display/ColorSpaceFunctions.js +5 -5
  128. package/src/nodes/display/ColorSpaceNode.js +27 -39
  129. package/src/nodes/display/PassNode.js +6 -4
  130. package/src/nodes/display/ToneMappingNode.js +1 -1
  131. package/src/nodes/display/ViewportDepthNode.js +33 -1
  132. package/src/nodes/functions/PhysicalLightingModel.js +21 -15
  133. package/src/nodes/functions/material/getAlphaHashThreshold.js +64 -0
  134. package/src/nodes/functions/material/getGeometryRoughness.js +8 -2
  135. package/src/nodes/functions/material/getParallaxCorrectNormal.js +22 -0
  136. package/src/nodes/gpgpu/ComputeNode.js +9 -1
  137. package/src/nodes/lighting/AnalyticLightNode.js +12 -416
  138. package/src/nodes/lighting/LightsNode.js +24 -12
  139. package/src/nodes/lighting/PointLightNode.js +36 -26
  140. package/src/nodes/lighting/RectAreaLightNode.js +3 -0
  141. package/src/nodes/lighting/ShadowNode.js +484 -0
  142. package/src/nodes/utils/LoopNode.js +2 -2
  143. package/src/nodes/utils/Oscillators.js +6 -0
  144. package/src/nodes/utils/PostProcessingUtils.js +89 -0
  145. package/src/nodes/utils/ReflectorNode.js +101 -15
  146. package/src/nodes/utils/Timer.js +29 -0
  147. package/src/objects/BatchedMesh.js +458 -241
  148. package/src/renderers/WebGLRenderer.js +120 -117
  149. package/src/renderers/common/Attributes.js +4 -0
  150. package/src/renderers/common/Backend.js +2 -0
  151. package/src/renderers/common/Background.js +14 -4
  152. package/src/renderers/common/Bindings.js +3 -2
  153. package/src/renderers/common/Constants.js +2 -1
  154. package/src/renderers/common/Geometries.js +20 -0
  155. package/src/renderers/common/IndirectStorageBufferAttribute.js +15 -0
  156. package/src/renderers/common/Lighting.js +45 -0
  157. package/src/renderers/common/PostProcessingUtils.js +86 -0
  158. package/src/renderers/common/RenderList.js +39 -11
  159. package/src/renderers/common/RenderLists.js +4 -2
  160. package/src/renderers/common/RenderObject.js +18 -1
  161. package/src/renderers/common/Renderer.js +165 -26
  162. package/src/renderers/common/Textures.js +30 -14
  163. package/src/renderers/common/nodes/NodeLibrary.js +1 -14
  164. package/src/renderers/common/nodes/Nodes.js +2 -2
  165. package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
  166. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
  167. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
  168. package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
  169. package/src/renderers/webgl/WebGLCapabilities.js +0 -7
  170. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
  171. package/src/renderers/webgl/WebGLProgram.js +24 -28
  172. package/src/renderers/webgl/WebGLPrograms.js +5 -2
  173. package/src/renderers/webgl/WebGLState.js +37 -1
  174. package/src/renderers/webgl/WebGLTextures.js +29 -12
  175. package/src/renderers/webgl-fallback/WebGLBackend.js +98 -31
  176. package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +2 -7
  177. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +33 -8
  178. package/src/renderers/webgpu/WebGPUBackend.js +105 -25
  179. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +1 -1
  180. package/src/renderers/webgpu/WebGPURenderer.js +1 -1
  181. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +0 -8
  182. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +0 -8
  183. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +10 -20
  184. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +12 -4
  185. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +29 -9
  186. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +24 -6
  187. package/src/renderers/webgpu/utils/WebGPUUtils.js +0 -1
  188. package/src/renderers/webxr/WebXRManager.js +4 -4
  189. package/examples/jsm/cameras/CinematicCamera.js +0 -208
  190. package/src/nodes/display/FXAANode.js +0 -332
  191. package/src/nodes/utils/OscNode.js +0 -85
  192. package/src/nodes/utils/TimerNode.js +0 -97
  193. /package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +0 -0
@@ -1,4 +1,4 @@
1
- import * as THREE from 'three';
1
+ import { DoubleSide, FloatType, HalfFloatType, Mesh, MeshBasicMaterial, MeshPhongMaterial, PlaneGeometry, Scene, WebGLRenderTarget } from 'three';
2
2
  import { potpack } from '../libs/potpack.module.js';
3
3
 
4
4
  /**
@@ -14,8 +14,8 @@ import { potpack } from '../libs/potpack.module.js';
14
14
  * your objects, so you can start jittering lighting to achieve
15
15
  * the texture-space effect you're looking for.
16
16
  *
17
- * @param {WebGLRenderer} renderer A WebGL Rendering Context
18
- * @param {number} res The side-long dimension of you total lightmap
17
+ * @param {WebGLRenderer} renderer An instance of WebGLRenderer.
18
+ * @param {number} res The side-long dimension of you total lightmap.
19
19
  */
20
20
  class ProgressiveLightMap {
21
21
 
@@ -24,22 +24,20 @@ class ProgressiveLightMap {
24
24
  this.renderer = renderer;
25
25
  this.res = res;
26
26
  this.lightMapContainers = [];
27
- this.compiled = false;
28
- this.scene = new THREE.Scene();
29
- this.scene.background = null;
30
- this.tinyTarget = new THREE.WebGLRenderTarget( 1, 1 );
27
+ this.scene = new Scene();
31
28
  this.buffer1Active = false;
32
29
  this.firstUpdate = true;
33
- this.warned = false;
30
+ this.labelMesh = null;
31
+ this.blurringPlane = null;
34
32
 
35
33
  // Create the Progressive LightMap Texture
36
- const format = /(Android|iPad|iPhone|iPod)/g.test( navigator.userAgent ) ? THREE.HalfFloatType : THREE.FloatType;
37
- this.progressiveLightMap1 = new THREE.WebGLRenderTarget( this.res, this.res, { type: format } );
38
- this.progressiveLightMap2 = new THREE.WebGLRenderTarget( this.res, this.res, { type: format } );
34
+ const format = /(Android|iPad|iPhone|iPod)/g.test( navigator.userAgent ) ? HalfFloatType : FloatType;
35
+ this.progressiveLightMap1 = new WebGLRenderTarget( this.res, this.res, { type: format } );
36
+ this.progressiveLightMap2 = new WebGLRenderTarget( this.res, this.res, { type: format } );
39
37
  this.progressiveLightMap2.texture.channel = 1;
40
38
 
41
39
  // Inject some spicy new logic into a standard phong material
42
- this.uvMat = new THREE.MeshPhongMaterial();
40
+ this.uvMat = new MeshPhongMaterial();
43
41
  this.uvMat.uniforms = {};
44
42
  this.uvMat.onBeforeCompile = ( shader ) => {
45
43
 
@@ -71,8 +69,6 @@ class ProgressiveLightMap {
71
69
  // Set the new Shader to this
72
70
  this.uvMat.userData.shader = shader;
73
71
 
74
- this.compiled = true;
75
-
76
72
  };
77
73
 
78
74
  }
@@ -97,13 +93,13 @@ class ProgressiveLightMap {
97
93
 
98
94
  }
99
95
 
100
- if ( ! object.geometry.hasAttribute( 'uv' ) ) {
96
+ if ( object.geometry.hasAttribute( 'uv' ) === false ) {
101
97
 
102
- console.warn( 'All lightmap objects need UVs!' ); continue;
98
+ console.warn( 'THREE.ProgressiveLightMap: All lightmap objects need uvs.' ); continue;
103
99
 
104
100
  }
105
101
 
106
- if ( this.blurringPlane == null ) {
102
+ if ( this.blurringPlane === null ) {
107
103
 
108
104
  this._initializeBlurPlane( this.res, this.progressiveLightMap1 );
109
105
 
@@ -123,8 +119,6 @@ class ProgressiveLightMap {
123
119
 
124
120
  this.lightMapContainers.push( { basicMat: object.material, object: object } );
125
121
 
126
- this.compiled = false;
127
-
128
122
  }
129
123
 
130
124
  // Pack the objects' lightmap UVs into the same global space
@@ -154,7 +148,7 @@ class ProgressiveLightMap {
154
148
  */
155
149
  update( camera, blendWindow = 100, blurEdges = true ) {
156
150
 
157
- if ( this.blurringPlane == null ) {
151
+ if ( this.blurringPlane === null ) {
158
152
 
159
153
  return;
160
154
 
@@ -175,11 +169,10 @@ class ProgressiveLightMap {
175
169
 
176
170
  }
177
171
 
178
- // Render once normally to initialize everything
179
- if ( this.firstUpdate ) {
172
+ // Initialize everything
173
+ if ( this.firstUpdate === true ) {
180
174
 
181
- this.renderer.setRenderTarget( this.tinyTarget ); // Tiny for Speed
182
- this.renderer.render( this.scene, camera );
175
+ this.renderer.compile( this.scene, camera );
183
176
  this.firstUpdate = false;
184
177
 
185
178
  }
@@ -228,30 +221,25 @@ class ProgressiveLightMap {
228
221
  */
229
222
  showDebugLightmap( visible, position = undefined ) {
230
223
 
231
- if ( this.lightMapContainers.length == 0 ) {
232
-
233
- if ( ! this.warned ) {
224
+ if ( this.lightMapContainers.length === 0 ) {
234
225
 
235
- console.warn( 'Call this after adding the objects!' ); this.warned = true;
236
-
237
- }
226
+ console.warn( 'THREE.ProgressiveLightMap: Call .showDebugLightmap() after adding the objects.' );
238
227
 
239
228
  return;
240
229
 
241
230
  }
242
231
 
243
- if ( this.labelMesh == null ) {
232
+ if ( this.labelMesh === null ) {
244
233
 
245
- this.labelMaterial = new THREE.MeshBasicMaterial(
246
- { map: this.progressiveLightMap1.texture, side: THREE.DoubleSide } );
247
- this.labelPlane = new THREE.PlaneGeometry( 100, 100 );
248
- this.labelMesh = new THREE.Mesh( this.labelPlane, this.labelMaterial );
234
+ const labelMaterial = new MeshBasicMaterial( { map: this.progressiveLightMap1.texture, side: DoubleSide } );
235
+ const labelGeometry = new PlaneGeometry( 100, 100 );
236
+ this.labelMesh = new Mesh( labelGeometry, labelMaterial );
249
237
  this.labelMesh.position.y = 250;
250
238
  this.lightMapContainers[ 0 ].object.parent.add( this.labelMesh );
251
239
 
252
240
  }
253
241
 
254
- if ( position != undefined ) {
242
+ if ( position !== undefined ) {
255
243
 
256
244
  this.labelMesh.position.copy( position );
257
245
 
@@ -268,7 +256,7 @@ class ProgressiveLightMap {
268
256
  */
269
257
  _initializeBlurPlane( res, lightMap = null ) {
270
258
 
271
- const blurMaterial = new THREE.MeshBasicMaterial();
259
+ const blurMaterial = new MeshBasicMaterial();
272
260
  blurMaterial.uniforms = { previousShadowMap: { value: null },
273
261
  pixelOffset: { value: 1.0 / res },
274
262
  polygonOffset: true, polygonOffsetFactor: - 1, polygonOffsetUnits: 3.0 };
@@ -306,11 +294,9 @@ class ProgressiveLightMap {
306
294
  // Set the new Shader to this
307
295
  blurMaterial.userData.shader = shader;
308
296
 
309
- this.compiled = true;
310
-
311
297
  };
312
298
 
313
- this.blurringPlane = new THREE.Mesh( new THREE.PlaneGeometry( 1, 1 ), blurMaterial );
299
+ this.blurringPlane = new Mesh( new PlaneGeometry( 1, 1 ), blurMaterial );
314
300
  this.blurringPlane.name = 'Blurring Plane';
315
301
  this.blurringPlane.frustumCulled = false;
316
302
  this.blurringPlane.renderOrder = 0;
@@ -319,6 +305,32 @@ class ProgressiveLightMap {
319
305
 
320
306
  }
321
307
 
308
+ /**
309
+ * Frees all internal resources.
310
+ */
311
+ dispose() {
312
+
313
+ this.progressiveLightMap1.dispose();
314
+ this.progressiveLightMap2.dispose();
315
+
316
+ this.uvMat.dispose();
317
+
318
+ if ( this.blurringPlane !== null ) {
319
+
320
+ this.blurringPlane.geometry.dispose();
321
+ this.blurringPlane.material.dispose();
322
+
323
+ }
324
+
325
+ if ( this.labelMesh !== null ) {
326
+
327
+ this.labelMesh.geometry.dispose();
328
+ this.labelMesh.material.dispose();
329
+
330
+ }
331
+
332
+ }
333
+
322
334
  }
323
335
 
324
336
  export { ProgressiveLightMap };
@@ -0,0 +1,293 @@
1
+ import { DoubleSide, FloatType, HalfFloatType, PlaneGeometry, Mesh, RenderTarget, Scene } from 'three';
2
+ import { add, float, mix, MeshPhongNodeMaterial, NodeMaterial, output, sub, texture, uniform, uv, vec2, vec4 } from 'three/tsl';
3
+
4
+ import { potpack } from '../libs/potpack.module.js';
5
+
6
+ /**
7
+ * Progressive Light Map Accumulator, by [zalo](https://github.com/zalo/)
8
+ *
9
+ * To use, simply construct a `ProgressiveLightMap` object,
10
+ * `plmap.addObjectsToLightMap(object)` an array of semi-static
11
+ * objects and lights to the class once, and then call
12
+ * `plmap.update(camera)` every frame to begin accumulating
13
+ * lighting samples.
14
+ *
15
+ * This should begin accumulating lightmaps which apply to
16
+ * your objects, so you can start jittering lighting to achieve
17
+ * the texture-space effect you're looking for.
18
+ *
19
+ * @param {WebGPURenderer} renderer An instance of WebGPURenderer.
20
+ * @param {number} resolution The side-long dimension of you total lightmap.
21
+ */
22
+ class ProgressiveLightMap {
23
+
24
+ constructor( renderer, resolution = 1024 ) {
25
+
26
+ this.renderer = renderer;
27
+ this.resolution = resolution;
28
+
29
+ this._lightMapContainers = [];
30
+ this._scene = new Scene();
31
+ this._buffer1Active = false;
32
+ this._labelMesh = null;
33
+ this._blurringPlane = null;
34
+
35
+ // Create the Progressive LightMap Texture
36
+
37
+ const type = /(Android|iPad|iPhone|iPod)/g.test( navigator.userAgent ) ? HalfFloatType : FloatType;
38
+ this._progressiveLightMap1 = new RenderTarget( this.resolution, this.resolution, { type: type } );
39
+ this._progressiveLightMap2 = new RenderTarget( this.resolution, this.resolution, { type: type } );
40
+ this._progressiveLightMap2.texture.channel = 1;
41
+
42
+ // uniforms
43
+
44
+ this._averagingWindow = uniform( 100 );
45
+ this._previousShadowMap = texture( this._progressiveLightMap1.texture );
46
+
47
+ // materials
48
+
49
+ const uvNode = uv( 1 ).flipY();
50
+
51
+ this._uvMat = new MeshPhongNodeMaterial();
52
+ this._uvMat.vertexNode = vec4( sub( uvNode, vec2( 0.5 ) ).mul( 2 ), 1, 1 );
53
+ this._uvMat.outputNode = vec4( mix( this._previousShadowMap.uv( uv( 1 ) ), output, float( 1 ).div( this._averagingWindow ) ) );
54
+
55
+ }
56
+
57
+ /**
58
+ * Sets these objects' materials' lightmaps and modifies their uv1's.
59
+ * @param {Object3D} objects An array of objects and lights to set up your lightmap.
60
+ */
61
+ addObjectsToLightMap( objects ) {
62
+
63
+ // Prepare list of UV bounding boxes for packing later...
64
+ const uv_boxes = [];
65
+
66
+ const padding = 3 / this.resolution;
67
+
68
+ for ( let ob = 0; ob < objects.length; ob ++ ) {
69
+
70
+ const object = objects[ ob ];
71
+
72
+ // If this object is a light, simply add it to the internal scene
73
+ if ( object.isLight ) {
74
+
75
+ this._scene.attach( object ); continue;
76
+
77
+ }
78
+
79
+ if ( object.geometry.hasAttribute( 'uv' ) === false ) {
80
+
81
+ console.warn( 'THREE.ProgressiveLightMap: All lightmap objects need uvs.' ); continue;
82
+
83
+ }
84
+
85
+ if ( this._blurringPlane === null ) {
86
+
87
+ this._initializeBlurPlane();
88
+
89
+ }
90
+
91
+ // Apply the lightmap to the object
92
+ object.material.lightMap = this._progressiveLightMap2.texture;
93
+ object.material.dithering = true;
94
+ object.castShadow = true;
95
+ object.receiveShadow = true;
96
+ object.renderOrder = 1000 + ob;
97
+
98
+ // Prepare UV boxes for potpack
99
+ // TODO: Size these by object surface area
100
+ uv_boxes.push( { w: 1 + ( padding * 2 ), h: 1 + ( padding * 2 ), index: ob } );
101
+
102
+ this._lightMapContainers.push( { basicMat: object.material, object: object } );
103
+
104
+ }
105
+
106
+ // Pack the objects' lightmap UVs into the same global space
107
+ const dimensions = potpack( uv_boxes );
108
+ uv_boxes.forEach( ( box ) => {
109
+
110
+ const uv1 = objects[ box.index ].geometry.getAttribute( 'uv' ).clone();
111
+ for ( let i = 0; i < uv1.array.length; i += uv1.itemSize ) {
112
+
113
+ uv1.array[ i ] = ( uv1.array[ i ] + box.x + padding ) / dimensions.w;
114
+ uv1.array[ i + 1 ] = 1 - ( ( uv1.array[ i + 1 ] + box.y + padding ) / dimensions.h );
115
+
116
+ }
117
+
118
+ objects[ box.index ].geometry.setAttribute( 'uv1', uv1 );
119
+ objects[ box.index ].geometry.getAttribute( 'uv1' ).needsUpdate = true;
120
+
121
+ } );
122
+
123
+ }
124
+
125
+ /**
126
+ * Frees all internal resources.
127
+ */
128
+ dispose() {
129
+
130
+ this._progressiveLightMap1.dispose();
131
+ this._progressiveLightMap2.dispose();
132
+
133
+ this._uvMat.dispose();
134
+
135
+ if ( this._blurringPlane !== null ) {
136
+
137
+ this._blurringPlane.geometry.dispose();
138
+ this._blurringPlane.material.dispose();
139
+
140
+ }
141
+
142
+ if ( this._labelMesh !== null ) {
143
+
144
+ this._labelMesh.geometry.dispose();
145
+ this._labelMesh.material.dispose();
146
+
147
+ }
148
+
149
+ }
150
+
151
+ /**
152
+ * This function renders each mesh one at a time into their respective surface maps
153
+ * @param {Camera} camera Standard Rendering Camera
154
+ * @param {number} blendWindow When >1, samples will accumulate over time.
155
+ * @param {boolean} blurEdges Whether to fix UV Edges via blurring
156
+ */
157
+ update( camera, blendWindow = 100, blurEdges = true ) {
158
+
159
+ if ( this._blurringPlane === null ) {
160
+
161
+ return;
162
+
163
+ }
164
+
165
+ // Store the original Render Target
166
+ const currentRenderTarget = this.renderer.getRenderTarget();
167
+
168
+ // The blurring plane applies blur to the seams of the lightmap
169
+ this._blurringPlane.visible = blurEdges;
170
+
171
+ // Steal the Object3D from the real world to our special dimension
172
+ for ( let l = 0; l < this._lightMapContainers.length; l ++ ) {
173
+
174
+ this._lightMapContainers[ l ].object.oldScene = this._lightMapContainers[ l ].object.parent;
175
+ this._scene.attach( this._lightMapContainers[ l ].object );
176
+
177
+ }
178
+
179
+ // Set each object's material to the UV Unwrapped Surface Mapping Version
180
+ for ( let l = 0; l < this._lightMapContainers.length; l ++ ) {
181
+
182
+ this._averagingWindow.value = blendWindow;
183
+ this._lightMapContainers[ l ].object.material = this._uvMat;
184
+ this._lightMapContainers[ l ].object.oldFrustumCulled = this._lightMapContainers[ l ].object.frustumCulled;
185
+ this._lightMapContainers[ l ].object.frustumCulled = false;
186
+
187
+ }
188
+
189
+ // Ping-pong two surface buffers for reading/writing
190
+ const activeMap = this._buffer1Active ? this._progressiveLightMap1 : this._progressiveLightMap2;
191
+ const inactiveMap = this._buffer1Active ? this._progressiveLightMap2 : this._progressiveLightMap1;
192
+
193
+ // Render the object's surface maps
194
+ this.renderer.setRenderTarget( activeMap );
195
+ this._previousShadowMap.value = inactiveMap.texture;
196
+
197
+ this._buffer1Active = ! this._buffer1Active;
198
+ this.renderer.render( this._scene, camera );
199
+
200
+ // Restore the object's Real-time Material and add it back to the original world
201
+ for ( let l = 0; l < this._lightMapContainers.length; l ++ ) {
202
+
203
+ this._lightMapContainers[ l ].object.frustumCulled = this._lightMapContainers[ l ].object.oldFrustumCulled;
204
+ this._lightMapContainers[ l ].object.material = this._lightMapContainers[ l ].basicMat;
205
+ this._lightMapContainers[ l ].object.oldScene.attach( this._lightMapContainers[ l ].object );
206
+
207
+ }
208
+
209
+ // Restore the original Render Target
210
+ this.renderer.setRenderTarget( currentRenderTarget );
211
+
212
+ }
213
+
214
+ /**
215
+ * Draw the lightmap in the main scene. Call this after adding the objects to it.
216
+ * @param {boolean} visible Whether the debug plane should be visible.
217
+ * @param {Vector3} position Where the debug plane should be drawn.
218
+ */
219
+ showDebugLightmap( visible, position = null ) {
220
+
221
+ if ( this._lightMapContainers.length === 0 ) {
222
+
223
+ console.warn( 'THREE.ProgressiveLightMap: Call .showDebugLightmap() after adding the objects.' );
224
+
225
+ return;
226
+
227
+ }
228
+
229
+ if ( this._labelMesh === null ) {
230
+
231
+ const labelMaterial = new NodeMaterial();
232
+ labelMaterial.colorNode = texture( this._progressiveLightMap1.texture ).uv( uv().flipY() );
233
+ labelMaterial.side = DoubleSide;
234
+
235
+ const labelGeometry = new PlaneGeometry( 100, 100 );
236
+
237
+ this._labelMesh = new Mesh( labelGeometry, labelMaterial );
238
+ this._labelMesh.position.y = 250;
239
+
240
+ this._lightMapContainers[ 0 ].object.parent.add( this._labelMesh );
241
+
242
+ }
243
+
244
+ if ( position !== null ) {
245
+
246
+ this._labelMesh.position.copy( position );
247
+
248
+ }
249
+
250
+ this._labelMesh.visible = visible;
251
+
252
+ }
253
+
254
+ /**
255
+ * Creates the Blurring Plane.
256
+ */
257
+ _initializeBlurPlane() {
258
+
259
+ const blurMaterial = new NodeMaterial();
260
+ blurMaterial.polygonOffset = true;
261
+ blurMaterial.polygonOffsetFactor = - 1;
262
+ blurMaterial.polygonOffsetUnits = 3;
263
+
264
+ blurMaterial.vertexNode = vec4( sub( uv(), vec2( 0.5 ) ).mul( 2 ), 1, 1 );
265
+
266
+ const uvNode = uv().flipY().toVar();
267
+ const pixelOffset = float( 0.5 ).div( float( this.resolution ) ).toVar();
268
+
269
+ const color = add(
270
+ this._previousShadowMap.uv( uvNode.add( vec2( pixelOffset, 0 ) ) ),
271
+ this._previousShadowMap.uv( uvNode.add( vec2( 0, pixelOffset ) ) ),
272
+ this._previousShadowMap.uv( uvNode.add( vec2( 0, pixelOffset.negate() ) ) ),
273
+ this._previousShadowMap.uv( uvNode.add( vec2( pixelOffset.negate(), 0 ) ) ),
274
+ this._previousShadowMap.uv( uvNode.add( vec2( pixelOffset, pixelOffset ) ) ),
275
+ this._previousShadowMap.uv( uvNode.add( vec2( pixelOffset.negate(), pixelOffset ) ) ),
276
+ this._previousShadowMap.uv( uvNode.add( vec2( pixelOffset, pixelOffset.negate() ) ) ),
277
+ this._previousShadowMap.uv( uvNode.add( vec2( pixelOffset.negate(), pixelOffset.negate() ) ) ),
278
+ ).div( 8 );
279
+
280
+ blurMaterial.fragmentNode = color;
281
+
282
+ this._blurringPlane = new Mesh( new PlaneGeometry( 1, 1 ), blurMaterial );
283
+ this._blurringPlane.name = 'Blurring Plane';
284
+ this._blurringPlane.frustumCulled = false;
285
+ this._blurringPlane.renderOrder = 0;
286
+ this._blurringPlane.material.depthWrite = false;
287
+ this._scene.add( this._blurringPlane );
288
+
289
+ }
290
+
291
+ }
292
+
293
+ export { ProgressiveLightMap };
@@ -68,6 +68,7 @@ class VolumeSlice {
68
68
 
69
69
  const canvasMap = new Texture( this.canvas );
70
70
  canvasMap.minFilter = LinearFilter;
71
+ canvasMap.generateMipmaps = false;
71
72
  canvasMap.wrapS = canvasMap.wrapT = ClampToEdgeWrapping;
72
73
  canvasMap.colorSpace = SRGBColorSpace;
73
74
  const material = new MeshBasicMaterial( { map: canvasMap, side: DoubleSide, transparent: true } );
@@ -3,7 +3,7 @@ import {
3
3
  Mesh,
4
4
  Vector3
5
5
  } from 'three';
6
- import { Fn, NodeMaterial, add, cameraPosition, div, normalize, positionWorld, sub, timerLocal, texture, vec2, vec3, vec4, max, dot, reflect, pow, length, float, uniform, reflector, mul, mix } from 'three/tsl';
6
+ import { Fn, NodeMaterial, add, cameraPosition, div, normalize, positionWorld, sub, time, texture, vec2, vec3, vec4, max, dot, reflect, pow, length, float, uniform, reflector, mul, mix } from 'three/tsl';
7
7
 
8
8
  /**
9
9
  * Work based on :
@@ -36,14 +36,14 @@ class WaterMesh extends Mesh {
36
36
 
37
37
  // TSL
38
38
 
39
- const timeNode = timerLocal();
40
-
41
39
  const getNoise = Fn( ( [ uv ] ) => {
42
40
 
43
- const uv0 = add( div( uv, 103 ), vec2( div( timeNode, 17 ), div( timeNode, 29 ) ) ).toVar();
44
- const uv1 = div( uv, 107 ).sub( vec2( div( timeNode, - 19 ), div( timeNode, 31 ) ) ).toVar();
45
- const uv2 = add( div( uv, vec2( 8907.0, 9803.0 ) ), vec2( div( timeNode, 101 ), div( timeNode, 97 ) ) ).toVar();
46
- const uv3 = sub( div( uv, vec2( 1091.0, 1027.0 ) ), vec2( div( timeNode, 109 ), div( timeNode, - 113 ) ) ).toVar();
41
+ const offset = time;
42
+
43
+ const uv0 = add( div( uv, 103 ), vec2( div( offset, 17 ), div( offset, 29 ) ) ).toVar();
44
+ const uv1 = div( uv, 107 ).sub( vec2( div( offset, - 19 ), div( offset, 31 ) ) ).toVar();
45
+ const uv2 = add( div( uv, vec2( 8907.0, 9803.0 ) ), vec2( div( offset, 101 ), div( offset, 97 ) ) ).toVar();
46
+ const uv3 = sub( div( uv, vec2( 1091.0, 1027.0 ) ), vec2( div( offset, 109 ), div( offset, - 113 ) ) ).toVar();
47
47
 
48
48
  const sample0 = this.waterNormals.uv( uv0 );
49
49
  const sample1 = this.waterNormals.uv( uv1 );
@@ -74,7 +74,7 @@ class WaterMesh extends Mesh {
74
74
 
75
75
  const distance = length( worldToEye );
76
76
 
77
- const distortion = surfaceNormal.xy.mul( float( 0.001 ).add( float( 1.0 ).div( distance ) ) ).mul( this.distortionScale );
77
+ const distortion = surfaceNormal.xz.mul( float( 0.001 ).add( float( 1.0 ).div( distance ) ) ).mul( this.distortionScale );
78
78
 
79
79
  const mirrorSampler = reflector();
80
80
  mirrorSampler.uvNode = mirrorSampler.uvNode.add( distortion );
@@ -1,12 +1,13 @@
1
1
  import {
2
2
  HalfFloatType,
3
- MeshBasicMaterial,
4
3
  NearestFilter,
4
+ NoBlending,
5
5
  ShaderMaterial,
6
6
  UniformsUtils,
7
7
  WebGLRenderTarget
8
8
  } from 'three';
9
9
  import { Pass, FullScreenQuad } from './Pass.js';
10
+ import { CopyShader } from '../shaders/CopyShader.js';
10
11
  import { AfterimageShader } from '../shaders/AfterimageShader.js';
11
12
 
12
13
  class AfterimagePass extends Pass {
@@ -41,7 +42,17 @@ class AfterimagePass extends Pass {
41
42
 
42
43
  this.compFsQuad = new FullScreenQuad( this.compFsMaterial );
43
44
 
44
- this.copyFsMaterial = new MeshBasicMaterial();
45
+ const copyShader = CopyShader;
46
+
47
+ this.copyFsMaterial = new ShaderMaterial( {
48
+ uniforms: UniformsUtils.clone( copyShader.uniforms ),
49
+ vertexShader: copyShader.vertexShader,
50
+ fragmentShader: copyShader.fragmentShader,
51
+ blending: NoBlending,
52
+ depthTest: false,
53
+ depthWrite: false
54
+ } );
55
+
45
56
  this.copyFsQuad = new FullScreenQuad( this.copyFsMaterial );
46
57
 
47
58
  }
@@ -54,7 +65,7 @@ class AfterimagePass extends Pass {
54
65
  renderer.setRenderTarget( this.textureComp );
55
66
  this.compFsQuad.render( renderer );
56
67
 
57
- this.copyFsQuad.material.map = this.textureComp.texture;
68
+ this.copyFsQuad.material.uniforms.tDiffuse.value = this.textureComp.texture;
58
69
 
59
70
  if ( this.renderToScreen ) {
60
71
 
@@ -558,9 +558,13 @@ class SSRPass extends Pass {
558
558
  this.originalClearColor.copy( renderer.getClearColor( this.tempColor ) );
559
559
  const originalClearAlpha = renderer.getClearAlpha( this.tempColor );
560
560
  const originalAutoClear = renderer.autoClear;
561
+ const originalBackground = this.scene.background;
562
+ const originalFog = this.scene.fog;
561
563
 
562
564
  renderer.setRenderTarget( renderTarget );
563
565
  renderer.autoClear = false;
566
+ this.scene.background = null;
567
+ this.scene.fog = null;
564
568
 
565
569
  clearColor = overrideMaterial.clearColor || clearColor;
566
570
  clearAlpha = overrideMaterial.clearAlpha || clearAlpha;
@@ -599,6 +603,8 @@ class SSRPass extends Pass {
599
603
  renderer.autoClear = originalAutoClear;
600
604
  renderer.setClearColor( this.originalClearColor );
601
605
  renderer.setClearAlpha( originalClearAlpha );
606
+ this.scene.background = originalBackground;
607
+ this.scene.fog = originalFog;
602
608
 
603
609
  }
604
610
 
@@ -26,9 +26,12 @@ class CSS2DObject extends Object3D {
26
26
 
27
27
  this.traverse( function ( object ) {
28
28
 
29
- if ( object.element instanceof Element && object.element.parentNode !== null ) {
29
+ if (
30
+ object.element instanceof object.element.ownerDocument.defaultView.Element &&
31
+ object.element.parentNode !== null
32
+ ) {
30
33
 
31
- object.element.parentNode.removeChild( object.element );
34
+ object.element.remove();
32
35
 
33
36
  }
34
37
 
@@ -135,7 +138,7 @@ class CSS2DRenderer {
135
138
  return;
136
139
 
137
140
  }
138
-
141
+
139
142
  if ( object.isCSS2DObject ) {
140
143
 
141
144
  _vector.setFromMatrixPosition( object.matrixWorld );
@@ -32,9 +32,12 @@ class CSS3DObject extends Object3D {
32
32
 
33
33
  this.traverse( function ( object ) {
34
34
 
35
- if ( object.element instanceof Element && object.element.parentNode !== null ) {
35
+ if (
36
+ object.element instanceof object.element.ownerDocument.defaultView.Element &&
37
+ object.element.parentNode !== null
38
+ ) {
36
39
 
37
- object.element.parentNode.removeChild( object.element );
40
+ object.element.remove();
38
41
 
39
42
  }
40
43
 
@@ -254,10 +257,10 @@ class CSS3DRenderer {
254
257
  function hideObject( object ) {
255
258
 
256
259
  if ( object.isCSS3DObject ) object.element.style.display = 'none';
257
-
260
+
258
261
  for ( let i = 0, l = object.children.length; i < l; i ++ ) {
259
262
 
260
- hideObject( object.children[ i ] );
263
+ hideObject( object.children[ i ] );
261
264
 
262
265
  }
263
266