super-three 0.169.0 → 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 (195) hide show
  1. package/build/three.cjs +989 -1131
  2. package/build/three.module.js +990 -1128
  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 +121 -126
  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/src/renderers/webvr/WebVRManager.js +0 -495
  194. package/src/renderers/webvr/WebVRUtils.js +0 -66
  195. /package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +0 -0
@@ -0,0 +1,392 @@
1
+ import {
2
+ storageObject, nodeProxy, int, float, vec2, ivec2, ivec4, uniform, Break, Loop,
3
+ Fn, If, Return, textureLoad, instanceIndex, screenCoordinate, directPointLight
4
+ } from 'three/tsl';
5
+
6
+ import { DataTexture, FloatType, LightsNode, NodeUpdateType, RGBAFormat, StorageBufferAttribute, Vector2, Vector3 } from 'three';
7
+
8
+ export const circleIntersectsAABB = /*@__PURE__*/ Fn( ( [ circleCenter, radius, minBounds, maxBounds ] ) => {
9
+
10
+ // Find the closest point on the AABB to the circle's center using method chaining
11
+ const closestX = minBounds.x.max( circleCenter.x.min( maxBounds.x ) );
12
+ const closestY = minBounds.y.max( circleCenter.y.min( maxBounds.y ) );
13
+
14
+ // Compute the distance between the circle's center and the closest point
15
+ const distX = circleCenter.x.sub( closestX );
16
+ const distY = circleCenter.y.sub( closestY );
17
+
18
+ // Calculate the squared distance
19
+ const distSquared = distX.mul( distX ).add( distY.mul( distY ) );
20
+
21
+ return distSquared.lessThanEqual( radius.mul( radius ) );
22
+
23
+ } ).setLayout( {
24
+ name: 'circleIntersectsAABB',
25
+ type: 'bool',
26
+ inputs: [
27
+ { name: 'circleCenter', type: 'vec2' },
28
+ { name: 'radius', type: 'float' },
29
+ { name: 'minBounds', type: 'vec2' },
30
+ { name: 'maxBounds', type: 'vec2' }
31
+ ]
32
+ } );
33
+
34
+ const _vector3 = /*@__PURE__*/ new Vector3();
35
+ const _size = /*@__PURE__*/ new Vector2();
36
+
37
+ class TiledLightsNode extends LightsNode {
38
+
39
+ static get type() {
40
+
41
+ return 'TiledLightsNode';
42
+
43
+ }
44
+
45
+ constructor( maxLights = 1024, tileSize = 32 ) {
46
+
47
+ super();
48
+
49
+ this.materialLights = [];
50
+ this.tiledLights = [];
51
+
52
+ this.maxLights = maxLights;
53
+ this.tileSize = tileSize;
54
+
55
+ this.bufferSize = null;
56
+ this.lightIndexes = null;
57
+ this.screenTileIndex = null;
58
+ this.compute = null;
59
+ this.lightsTexture = null;
60
+
61
+ this.lightsCount = uniform( 0, 'int' );
62
+ this.tileLightCount = 8;
63
+ this.screenSize = uniform( new Vector2() );
64
+ this.cameraProjectionMatrix = uniform( 'mat4' );
65
+ this.cameraViewMatrix = uniform( 'mat4' );
66
+
67
+ this.updateBeforeType = NodeUpdateType.RENDER;
68
+
69
+ }
70
+
71
+ updateLightsTexture() {
72
+
73
+ const { lightsTexture, tiledLights } = this;
74
+
75
+ const data = lightsTexture.image.data;
76
+ const lineSize = lightsTexture.image.width * 4;
77
+
78
+ this.lightsCount.value = tiledLights.length;
79
+
80
+ for ( let i = 0; i < tiledLights.length; i ++ ) {
81
+
82
+ const light = tiledLights[ i ];
83
+
84
+ // world position
85
+
86
+ _vector3.setFromMatrixPosition( light.matrixWorld );
87
+
88
+ // store data
89
+
90
+ const offset = i * 4;
91
+
92
+ data[ offset + 0 ] = _vector3.x;
93
+ data[ offset + 1 ] = _vector3.y;
94
+ data[ offset + 2 ] = _vector3.z;
95
+ data[ offset + 3 ] = light.distance;
96
+
97
+ data[ lineSize + offset + 0 ] = light.color.r * light.intensity;
98
+ data[ lineSize + offset + 1 ] = light.color.g * light.intensity;
99
+ data[ lineSize + offset + 2 ] = light.color.b * light.intensity;
100
+ data[ lineSize + offset + 3 ] = light.decay;
101
+
102
+ }
103
+
104
+ lightsTexture.needsUpdate = true;
105
+
106
+ }
107
+
108
+ updateBefore( frame ) {
109
+
110
+ const { renderer, camera } = frame;
111
+
112
+ this.updateProgram( renderer );
113
+
114
+ this.updateLightsTexture( camera );
115
+
116
+ this.cameraProjectionMatrix.value = camera.projectionMatrix;
117
+ this.cameraViewMatrix.value = camera.matrixWorldInverse;
118
+
119
+ renderer.getDrawingBufferSize( _size );
120
+ this.screenSize.value.copy( _size );
121
+
122
+ renderer.compute( this.compute );
123
+
124
+ }
125
+
126
+ setLights( lights ) {
127
+
128
+ const { tiledLights, materialLights } = this;
129
+
130
+ let materialindex = 0;
131
+ let tiledIndex = 0;
132
+
133
+ for ( const light of lights ) {
134
+
135
+ if ( light.isPointLight === true ) {
136
+
137
+ tiledLights[ tiledIndex ++ ] = light;
138
+
139
+ } else {
140
+
141
+ materialLights[ materialindex ++ ] = light;
142
+
143
+ }
144
+
145
+ }
146
+
147
+ materialLights.length = materialindex;
148
+ tiledLights.length = tiledIndex;
149
+
150
+ return super.setLights( materialLights );
151
+
152
+ }
153
+
154
+ getBlock( block = 0 ) {
155
+
156
+ return this.lightIndexes.element( this.screenTileIndex.mul( int( 2 ).add( int( block ) ) ) );
157
+
158
+ }
159
+
160
+ getTile( element ) {
161
+
162
+ element = int( element );
163
+
164
+ const stride = int( 4 );
165
+ const tileOffset = element.div( stride );
166
+ const tileIndex = this.screenTileIndex.mul( int( 2 ) ).add( tileOffset );
167
+
168
+ return this.lightIndexes.element( tileIndex ).element( element.modInt( stride ) );
169
+
170
+ }
171
+
172
+ getLightData( index ) {
173
+
174
+ index = int( index );
175
+
176
+ const dataA = textureLoad( this.lightsTexture, ivec2( index, 0 ) );
177
+ const dataB = textureLoad( this.lightsTexture, ivec2( index, 1 ) );
178
+
179
+ const position = dataA.xyz;
180
+ const viewPosition = this.cameraViewMatrix.mul( position );
181
+ const distance = dataA.w;
182
+ const color = dataB.rgb;
183
+ const decay = dataB.w;
184
+
185
+ return {
186
+ position,
187
+ viewPosition,
188
+ distance,
189
+ color,
190
+ decay
191
+ };
192
+
193
+ }
194
+
195
+ setupLights( builder, lightNodes ) {
196
+
197
+ this.updateProgram( builder.renderer );
198
+
199
+ //
200
+
201
+ const lightingModel = builder.context.reflectedLight;
202
+
203
+ // force declaration order, before of the loop
204
+ lightingModel.directDiffuse.append();
205
+ lightingModel.directSpecular.append();
206
+
207
+ Fn( () => {
208
+
209
+ Loop( this.tileLightCount, ( { i } ) => {
210
+
211
+ const lightIndex = this.getTile( i );
212
+
213
+ If( lightIndex.equal( int( 0 ) ), () => {
214
+
215
+ Break();
216
+
217
+ } );
218
+
219
+ const { color, decay, viewPosition, distance } = this.getLightData( lightIndex.sub( 1 ) );
220
+
221
+ directPointLight( {
222
+ color,
223
+ lightViewPosition: viewPosition,
224
+ cutoffDistance: distance,
225
+ decayExponent: decay
226
+ } ).append();
227
+
228
+ } );
229
+
230
+ } )().append();
231
+
232
+ // others lights
233
+
234
+ super.setupLights( builder, lightNodes );
235
+
236
+ }
237
+
238
+ getBufferFitSize( value ) {
239
+
240
+ const multiple = this.tileSize;
241
+
242
+ return Math.ceil( value / multiple ) * multiple;
243
+
244
+ }
245
+
246
+ setSize( width, height ) {
247
+
248
+ width = this.getBufferFitSize( width );
249
+ height = this.getBufferFitSize( height );
250
+
251
+ if ( ! this.bufferSize || this.bufferSize.width !== width || this.bufferSize.height !== height ) {
252
+
253
+ this.create( width, height );
254
+
255
+ }
256
+
257
+ return this;
258
+
259
+ }
260
+
261
+ updateProgram( renderer ) {
262
+
263
+ renderer.getDrawingBufferSize( _size );
264
+
265
+ const width = this.getBufferFitSize( _size.width );
266
+ const height = this.getBufferFitSize( _size.height );
267
+
268
+ if ( this.bufferSize === null ) {
269
+
270
+ this.create( width, height );
271
+
272
+ } else if ( this.bufferSize.width !== width || this.bufferSize.height !== height ) {
273
+
274
+ this.create( width, height );
275
+
276
+ }
277
+
278
+ }
279
+
280
+ create( width, height ) {
281
+
282
+ const { tileSize, maxLights } = this;
283
+
284
+ const bufferSize = new Vector2( width, height );
285
+ const lineSize = Math.floor( bufferSize.width / tileSize );
286
+ const count = Math.floor( ( bufferSize.width * bufferSize.height ) / tileSize );
287
+
288
+ // buffers
289
+
290
+ const lightsData = new Float32Array( maxLights * 4 * 2 ); // 2048 lights, 4 elements(rgba), 2 components, 1 component per line (position, distance, color, decay)
291
+ const lightsTexture = new DataTexture( lightsData, lightsData.length / 8, 2, RGBAFormat, FloatType );
292
+
293
+ const lightIndexesArray = new Int32Array( count * 4 * 2 );
294
+ const lightIndexesAttribute = new StorageBufferAttribute( lightIndexesArray, 4 );
295
+ const lightIndexes = storageObject( lightIndexesAttribute, 'ivec4', lightIndexesAttribute.count ).label( 'lightIndexes' );
296
+
297
+ // compute
298
+
299
+ const getBlock = ( index ) => {
300
+
301
+ const tileIndex = instanceIndex.mul( int( 2 ) ).add( int( index ) );
302
+
303
+ return lightIndexes.element( tileIndex );
304
+
305
+ };
306
+
307
+ const getTile = ( elementIndex ) => {
308
+
309
+ elementIndex = int( elementIndex );
310
+
311
+ const stride = int( 4 );
312
+ const tileOffset = elementIndex.div( stride );
313
+ const tileIndex = instanceIndex.mul( int( 2 ) ).add( tileOffset );
314
+
315
+ return lightIndexes.element( tileIndex ).element( elementIndex.modInt( stride ) );
316
+
317
+ };
318
+
319
+ const compute = Fn( () => {
320
+
321
+ const { cameraProjectionMatrix, bufferSize, screenSize } = this;
322
+
323
+ const tiledBufferSize = bufferSize.clone().divideScalar( tileSize ).floor();
324
+
325
+ const tileScreen = vec2(
326
+ instanceIndex.modInt( tiledBufferSize.width ),
327
+ instanceIndex.div( tiledBufferSize.width )
328
+ ).mul( tileSize ).div( screenSize );
329
+
330
+ const blockSize = float( tileSize ).div( screenSize );
331
+ const minBounds = tileScreen;
332
+ const maxBounds = minBounds.add( blockSize );
333
+
334
+ const index = int( 0 ).toVar();
335
+
336
+ getBlock( 0 ).assign( ivec4( 0 ) );
337
+ getBlock( 1 ).assign( ivec4( 0 ) );
338
+
339
+ Loop( this.maxLights, ( { i } ) => {
340
+
341
+ If( index.greaterThanEqual( this.tileLightCount ).or( int( i ).greaterThanEqual( int( this.lightsCount ) ) ), () => {
342
+
343
+ Return();
344
+
345
+ } );
346
+
347
+ const { viewPosition, distance } = this.getLightData( i );
348
+
349
+ const projectedPosition = cameraProjectionMatrix.mul( viewPosition );
350
+ const ndc = projectedPosition.div( projectedPosition.w );
351
+ const screenPosition = ndc.xy.mul( 0.5 ).add( 0.5 ).flipY();
352
+
353
+ const distanceFromCamera = viewPosition.z;
354
+ const pointRadius = distance.div( distanceFromCamera );
355
+
356
+ If( circleIntersectsAABB( screenPosition, pointRadius, minBounds, maxBounds ), () => {
357
+
358
+ getTile( index ).assign( i.add( int( 1 ) ) );
359
+ index.addAssign( int( 1 ) );
360
+
361
+ } );
362
+
363
+ } );
364
+
365
+ } )().compute( count );
366
+
367
+ // screen coordinate lighting indexes
368
+
369
+ const screenTile = screenCoordinate.div( tileSize ).floor().toVar();
370
+ const screenTileIndex = screenTile.x.add( screenTile.y.mul( lineSize ) );
371
+
372
+ // assigns
373
+
374
+ this.bufferSize = bufferSize;
375
+ this.lightIndexes = lightIndexes;
376
+ this.screenTileIndex = screenTileIndex;
377
+ this.compute = compute;
378
+ this.lightsTexture = lightsTexture;
379
+
380
+ }
381
+
382
+ get hasLights() {
383
+
384
+ return super.hasLights || this.tiledLights.length > 0;
385
+
386
+ }
387
+
388
+ }
389
+
390
+ export default TiledLightsNode;
391
+
392
+ export const tiledLights = /*@__PURE__*/ nodeProxy( TiledLightsNode );
@@ -19,7 +19,8 @@ export async function decompress( blitTexture, maxTextureSize = Infinity, render
19
19
  }
20
20
 
21
21
  const material = new NodeMaterial();
22
- material.fragmentNode = texture( blitTexture ).uv( uv().flipY() );
22
+
23
+ material.fragmentNode = texture( blitTexture, uv().flipY() );
23
24
 
24
25
  const width = Math.min( blitTexture.image.width, maxTextureSize );
25
26
  const height = Math.min( blitTexture.image.height, maxTextureSize );
@@ -1,4 +1,4 @@
1
- import * as THREE from 'three';
1
+ import { BufferGeometry, Float32BufferAttribute, Matrix4, Mesh, MeshBasicMaterial, Object3D, Raycaster, SphereGeometry, Vector3 } from 'three';
2
2
 
3
3
  const PINCH_MAX = 0.05;
4
4
  const PINCH_THRESHOLD = 0.02;
@@ -13,13 +13,13 @@ const POINTER_LENGTH = 0.035;
13
13
  const POINTER_SEGMENTS = 16;
14
14
  const POINTER_RINGS = 12;
15
15
  const POINTER_HEMISPHERE_ANGLE = 110;
16
- const YAXIS = /* @__PURE__ */ new THREE.Vector3( 0, 1, 0 );
17
- const ZAXIS = /* @__PURE__ */ new THREE.Vector3( 0, 0, 1 );
16
+ const YAXIS = /* @__PURE__ */ new Vector3( 0, 1, 0 );
17
+ const ZAXIS = /* @__PURE__ */ new Vector3( 0, 0, 1 );
18
18
 
19
19
  const CURSOR_RADIUS = 0.02;
20
20
  const CURSOR_MAX_DISTANCE = 1.5;
21
21
 
22
- class OculusHandPointerModel extends THREE.Object3D {
22
+ class OculusHandPointerModel extends Object3D {
23
23
 
24
24
  constructor( hand, controller ) {
25
25
 
@@ -96,7 +96,7 @@ class OculusHandPointerModel extends THREE.Object3D {
96
96
 
97
97
  const vertices = this.pointerGeometry.attributes.position.array;
98
98
  // first ring for front face
99
- const frontFaceBase = new THREE.Vector3(
99
+ const frontFaceBase = new Vector3(
100
100
  POINTER_FRONT_RADIUS,
101
101
  0,
102
102
  - 1 * ( POINTER_LENGTH - rearRadius )
@@ -104,7 +104,7 @@ class OculusHandPointerModel extends THREE.Object3D {
104
104
  this._drawVerticesRing( vertices, frontFaceBase, 0 );
105
105
 
106
106
  // rings for rear hemisphere
107
- const rearBase = new THREE.Vector3(
107
+ const rearBase = new Vector3(
108
108
  Math.sin( ( Math.PI * POINTER_HEMISPHERE_ANGLE ) / 180 ) * rearRadius,
109
109
  Math.cos( ( Math.PI * POINTER_HEMISPHERE_ANGLE ) / 180 ) * rearRadius,
110
110
  0
@@ -122,7 +122,7 @@ class OculusHandPointerModel extends THREE.Object3D {
122
122
  // front and rear face center vertices
123
123
  const frontCenterIndex = POINTER_SEGMENTS * ( 1 + POINTER_RINGS );
124
124
  const rearCenterIndex = POINTER_SEGMENTS * ( 1 + POINTER_RINGS ) + 1;
125
- const frontCenter = new THREE.Vector3(
125
+ const frontCenter = new Vector3(
126
126
  0,
127
127
  0,
128
128
  - 1 * ( POINTER_LENGTH - rearRadius )
@@ -130,14 +130,14 @@ class OculusHandPointerModel extends THREE.Object3D {
130
130
  vertices[ frontCenterIndex * 3 ] = frontCenter.x;
131
131
  vertices[ frontCenterIndex * 3 + 1 ] = frontCenter.y;
132
132
  vertices[ frontCenterIndex * 3 + 2 ] = frontCenter.z;
133
- const rearCenter = new THREE.Vector3( 0, 0, rearRadius );
133
+ const rearCenter = new Vector3( 0, 0, rearRadius );
134
134
  vertices[ rearCenterIndex * 3 ] = rearCenter.x;
135
135
  vertices[ rearCenterIndex * 3 + 1 ] = rearCenter.y;
136
136
  vertices[ rearCenterIndex * 3 + 2 ] = rearCenter.z;
137
137
 
138
138
  this.pointerGeometry.setAttribute(
139
139
  'position',
140
- new THREE.Float32BufferAttribute( vertices, 3 )
140
+ new Float32BufferAttribute( vertices, 3 )
141
141
  );
142
142
  // verticesNeedUpdate = true;
143
143
 
@@ -151,11 +151,11 @@ class OculusHandPointerModel extends THREE.Object3D {
151
151
  ).fill( 0 );
152
152
  // const vertices = [];
153
153
  const indices = [];
154
- this.pointerGeometry = new THREE.BufferGeometry();
154
+ this.pointerGeometry = new BufferGeometry();
155
155
 
156
156
  this.pointerGeometry.setAttribute(
157
157
  'position',
158
- new THREE.Float32BufferAttribute( vertices, 3 )
158
+ new Float32BufferAttribute( vertices, 3 )
159
159
  );
160
160
 
161
161
  this._updatePointerVertices( POINTER_REAR_RADIUS );
@@ -213,27 +213,27 @@ class OculusHandPointerModel extends THREE.Object3D {
213
213
  POINTER_SEGMENTS * POINTER_RINGS
214
214
  );
215
215
 
216
- const material = new THREE.MeshBasicMaterial();
216
+ const material = new MeshBasicMaterial();
217
217
  material.transparent = true;
218
218
  material.opacity = POINTER_OPACITY_MIN;
219
219
 
220
220
  this.pointerGeometry.setIndex( indices );
221
221
 
222
- this.pointerMesh = new THREE.Mesh( this.pointerGeometry, material );
222
+ this.pointerMesh = new Mesh( this.pointerGeometry, material );
223
223
 
224
224
  this.pointerMesh.position.set( 0, 0, - 1 * POINTER_REAR_RADIUS );
225
- this.pointerObject = new THREE.Object3D();
225
+ this.pointerObject = new Object3D();
226
226
  this.pointerObject.add( this.pointerMesh );
227
227
 
228
- this.raycaster = new THREE.Raycaster();
228
+ this.raycaster = new Raycaster();
229
229
 
230
230
  // create cursor
231
- const cursorGeometry = new THREE.SphereGeometry( CURSOR_RADIUS, 10, 10 );
232
- const cursorMaterial = new THREE.MeshBasicMaterial();
231
+ const cursorGeometry = new SphereGeometry( CURSOR_RADIUS, 10, 10 );
232
+ const cursorMaterial = new MeshBasicMaterial();
233
233
  cursorMaterial.transparent = true;
234
234
  cursorMaterial.opacity = POINTER_OPACITY_MIN;
235
235
 
236
- this.cursorObject = new THREE.Mesh( cursorGeometry, cursorMaterial );
236
+ this.cursorObject = new Mesh( cursorGeometry, cursorMaterial );
237
237
  this.pointerObject.add( this.cursorObject );
238
238
 
239
239
  this.add( this.pointerObject );
@@ -245,7 +245,7 @@ class OculusHandPointerModel extends THREE.Object3D {
245
245
  if ( this.raycaster ) {
246
246
 
247
247
  const pointerMatrix = this.pointerObject.matrixWorld;
248
- const tempMatrix = new THREE.Matrix4();
248
+ const tempMatrix = new Matrix4();
249
249
  tempMatrix.identity().extractRotation( pointerMatrix );
250
250
  this.raycaster.ray.origin.setFromMatrixPosition( pointerMatrix );
251
251
  this.raycaster.ray.direction.set( 0, 0, - 1 ).applyMatrix4( tempMatrix );
@@ -372,7 +372,7 @@ class OculusHandPointerModel extends THREE.Object3D {
372
372
  if ( this.raycaster && ! this.attached ) {
373
373
 
374
374
  const intersections = this.raycaster.intersectObjects( objects, recursive );
375
- const direction = new THREE.Vector3( 0, 0, - 1 );
375
+ const direction = new Vector3( 0, 0, - 1 );
376
376
  if ( intersections.length > 0 ) {
377
377
 
378
378
  const intersection = intersections[ 0 ];
@@ -391,7 +391,7 @@ class OculusHandPointerModel extends THREE.Object3D {
391
391
 
392
392
  setCursor( distance ) {
393
393
 
394
- const direction = new THREE.Vector3( 0, 0, - 1 );
394
+ const direction = new Vector3( 0, 0, - 1 );
395
395
  if ( this.raycaster && ! this.attached ) {
396
396
 
397
397
  this.cursorObject.position.copy( direction.multiplyScalar( distance ) );
@@ -1,4 +1,4 @@
1
- import * as THREE from 'three';
1
+ import { DoubleSide, Mesh, MeshBasicMaterial, PlaneGeometry, Texture } from 'three';
2
2
 
3
3
  function createText( message, height ) {
4
4
 
@@ -17,20 +17,20 @@ function createText( message, height ) {
17
17
  context.fillStyle = '#ffffff';
18
18
  context.fillText( message, textWidth / 2, textHeight / 2 );
19
19
 
20
- const texture = new THREE.Texture( canvas );
20
+ const texture = new Texture( canvas );
21
21
  texture.needsUpdate = true;
22
22
 
23
- const material = new THREE.MeshBasicMaterial( {
23
+ const material = new MeshBasicMaterial( {
24
24
  color: 0xffffff,
25
- side: THREE.DoubleSide,
25
+ side: DoubleSide,
26
26
  map: texture,
27
27
  transparent: true,
28
28
  } );
29
- const geometry = new THREE.PlaneGeometry(
29
+ const geometry = new PlaneGeometry(
30
30
  ( height * textWidth ) / textHeight,
31
31
  height
32
32
  );
33
- const plane = new THREE.Mesh( geometry, material );
33
+ const plane = new Mesh( geometry, material );
34
34
  return plane;
35
35
 
36
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "super-three",
3
- "version": "0.169.0",
3
+ "version": "0.170.0",
4
4
  "description": "JavaScript 3D library",
5
5
  "type": "module",
6
6
  "main": "./build/three.cjs",
@@ -109,7 +109,7 @@
109
109
  "rollup": "^4.6.0",
110
110
  "rollup-plugin-filesize": "^10.0.0",
111
111
  "rollup-plugin-visualizer": "^5.9.0",
112
- "servez": "^2.0.0"
112
+ "servez": "^2.2.4"
113
113
  },
114
114
  "overrides": {
115
115
  "jpeg-js": "^0.4.4"
@@ -164,12 +164,16 @@ export * from './Three.Legacy.js';
164
164
 
165
165
  export * from './materials/nodes/NodeMaterials.js';
166
166
  export { default as WebGPURenderer } from './renderers/webgpu/WebGPURenderer.Nodes.js';
167
+ export { default as Lighting } from './renderers/common/Lighting.js';
167
168
  export { default as QuadMesh } from './renderers/common/QuadMesh.js';
168
169
  export { default as PMREMGenerator } from './renderers/common/extras/PMREMGenerator.js';
169
170
  export { default as PostProcessing } from './renderers/common/PostProcessing.js';
171
+ import * as PostProcessingUtils from './renderers/common/PostProcessingUtils.js';
172
+ export { PostProcessingUtils };
170
173
  export { default as StorageTexture } from './renderers/common/StorageTexture.js';
171
174
  export { default as StorageBufferAttribute } from './renderers/common/StorageBufferAttribute.js';
172
175
  export { default as StorageInstancedBufferAttribute } from './renderers/common/StorageInstancedBufferAttribute.js';
176
+ export { default as IndirectStorageBufferAttribute } from './renderers/common/IndirectStorageBufferAttribute.js';
173
177
  export { default as IESSpotLight } from './lights/webgpu/IESSpotLight.js';
174
178
  export { default as NodeLoader } from './loaders/nodes/NodeLoader.js';
175
179
  export { default as NodeObjectLoader } from './loaders/nodes/NodeObjectLoader.js';
@@ -164,13 +164,17 @@ export * from './Three.Legacy.js';
164
164
 
165
165
  export * from './materials/nodes/NodeMaterials.js';
166
166
  export { default as WebGPURenderer } from './renderers/webgpu/WebGPURenderer.js';
167
+ export { default as Lighting } from './renderers/common/Lighting.js';
167
168
  export { default as BundleGroup } from './renderers/common/BundleGroup.js';
168
169
  export { default as QuadMesh } from './renderers/common/QuadMesh.js';
169
170
  export { default as PMREMGenerator } from './renderers/common/extras/PMREMGenerator.js';
170
171
  export { default as PostProcessing } from './renderers/common/PostProcessing.js';
172
+ import * as PostProcessingUtils from './renderers/common/PostProcessingUtils.js';
173
+ export { PostProcessingUtils };
171
174
  export { default as StorageTexture } from './renderers/common/StorageTexture.js';
172
175
  export { default as StorageBufferAttribute } from './renderers/common/StorageBufferAttribute.js';
173
176
  export { default as StorageInstancedBufferAttribute } from './renderers/common/StorageInstancedBufferAttribute.js';
177
+ export { default as IndirectStorageBufferAttribute } from './renderers/common/IndirectStorageBufferAttribute.js';
174
178
  export { default as IESSpotLight } from './lights/webgpu/IESSpotLight.js';
175
179
  export { default as NodeLoader } from './loaders/nodes/NodeLoader.js';
176
180
  export { default as NodeObjectLoader } from './loaders/nodes/NodeObjectLoader.js';
package/src/constants.js CHANGED
@@ -1,4 +1,4 @@
1
- export const REVISION = '169';
1
+ export const REVISION = '170';
2
2
 
3
3
  export const MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 };
4
4
  export const TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 };
@@ -163,15 +163,10 @@ export const ObjectSpaceNormalMap = 1;
163
163
  export const NoColorSpace = '';
164
164
  export const SRGBColorSpace = 'srgb';
165
165
  export const LinearSRGBColorSpace = 'srgb-linear';
166
- export const DisplayP3ColorSpace = 'display-p3';
167
- export const LinearDisplayP3ColorSpace = 'display-p3-linear';
168
166
 
169
167
  export const LinearTransfer = 'linear';
170
168
  export const SRGBTransfer = 'srgb';
171
169
 
172
- export const Rec709Primaries = 'rec709';
173
- export const P3Primaries = 'p3';
174
-
175
170
  export const ZeroStencilOp = 0;
176
171
  export const KeepStencilOp = 7680;
177
172
  export const ReplaceStencilOp = 7681;