super-three 0.158.0 → 0.160.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 (191) hide show
  1. package/build/three.cjs +1720 -380
  2. package/build/three.js +1720 -380
  3. package/build/three.min.js +1 -1
  4. package/build/three.module.js +1719 -381
  5. package/build/three.module.min.js +1 -1
  6. package/examples/jsm/Addons.js +2 -1
  7. package/examples/jsm/controls/OrbitControls.js +50 -40
  8. package/examples/jsm/csm/CSMShader.js +52 -47
  9. package/examples/jsm/exporters/GLTFExporter.js +79 -1
  10. package/examples/jsm/exporters/USDZExporter.js +27 -19
  11. package/examples/jsm/helpers/TextureHelper.js +237 -0
  12. package/examples/jsm/interactive/HTMLMesh.js +9 -2
  13. package/examples/jsm/lines/LineMaterial.js +16 -33
  14. package/examples/jsm/loaders/ColladaLoader.js +0 -6
  15. package/examples/jsm/loaders/DRACOLoader.js +4 -3
  16. package/examples/jsm/loaders/FBXLoader.js +294 -124
  17. package/examples/jsm/loaders/GLTFLoader.js +71 -3
  18. package/examples/jsm/loaders/MaterialXLoader.js +73 -54
  19. package/examples/jsm/loaders/NRRDLoader.js +0 -13
  20. package/examples/jsm/loaders/SVGLoader.js +4 -4
  21. package/examples/jsm/loaders/USDZLoader.js +3 -17
  22. package/examples/jsm/math/Octree.js +15 -4
  23. package/examples/jsm/misc/Timer.js +119 -0
  24. package/examples/jsm/misc/TubePainter.js +3 -6
  25. package/examples/jsm/modifiers/CurveModifier.js +20 -2
  26. package/examples/jsm/nodes/Nodes.js +11 -7
  27. package/examples/jsm/nodes/accessors/CameraNode.js +18 -2
  28. package/examples/jsm/nodes/accessors/CubeTextureNode.js +5 -73
  29. package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +11 -2
  30. package/examples/jsm/nodes/accessors/ModelNode.js +1 -1
  31. package/examples/jsm/nodes/accessors/ModelViewProjectionNode.js +12 -3
  32. package/examples/jsm/nodes/accessors/MorphNode.js +191 -16
  33. package/examples/jsm/nodes/accessors/ReferenceNode.js +25 -1
  34. package/examples/jsm/nodes/accessors/TextureNode.js +122 -36
  35. package/examples/jsm/nodes/code/CodeNode.js +3 -3
  36. package/examples/jsm/nodes/core/AttributeNode.js +7 -1
  37. package/examples/jsm/nodes/core/CacheNode.js +4 -1
  38. package/examples/jsm/nodes/core/ConstNode.js +1 -1
  39. package/examples/jsm/nodes/core/Node.js +6 -3
  40. package/examples/jsm/nodes/core/NodeBuilder.js +84 -27
  41. package/examples/jsm/nodes/core/NodeFrame.js +10 -8
  42. package/examples/jsm/nodes/core/NodeUniform.js +12 -0
  43. package/examples/jsm/nodes/core/NodeUtils.js +3 -7
  44. package/examples/jsm/nodes/core/OutputStructNode.js +3 -3
  45. package/examples/jsm/nodes/core/PropertyNode.js +17 -2
  46. package/examples/jsm/nodes/core/StructTypeNode.js +4 -4
  47. package/examples/jsm/nodes/core/UniformGroup.js +13 -0
  48. package/examples/jsm/nodes/core/UniformGroupNode.js +36 -0
  49. package/examples/jsm/nodes/core/UniformNode.js +17 -0
  50. package/examples/jsm/nodes/core/VarNode.js +2 -0
  51. package/examples/jsm/nodes/core/VaryingNode.js +1 -7
  52. package/examples/jsm/nodes/display/BumpMapNode.js +1 -1
  53. package/examples/jsm/nodes/display/ColorAdjustmentNode.js +6 -10
  54. package/examples/jsm/nodes/display/GaussianBlurNode.js +170 -0
  55. package/examples/jsm/nodes/display/PassNode.js +182 -0
  56. package/examples/jsm/nodes/display/ViewportDepthNode.js +31 -3
  57. package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +2 -2
  58. package/examples/jsm/nodes/display/ViewportNode.js +5 -8
  59. package/examples/jsm/nodes/functions/PhysicalLightingModel.js +1 -1
  60. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +52 -17
  61. package/examples/jsm/nodes/lighting/EnvironmentNode.js +8 -12
  62. package/examples/jsm/nodes/lighting/LightsNode.js +34 -32
  63. package/examples/jsm/nodes/materials/InstancedPointsNodeMaterial.js +1 -1
  64. package/examples/jsm/nodes/materials/Line2NodeMaterial.js +12 -12
  65. package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +1 -0
  66. package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +1 -1
  67. package/examples/jsm/nodes/materials/NodeMaterial.js +66 -41
  68. package/examples/jsm/nodes/materials/PointsNodeMaterial.js +0 -10
  69. package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +0 -7
  70. package/examples/jsm/nodes/materialx/MaterialXNodes.js +10 -10
  71. package/examples/jsm/nodes/materialx/lib/mx_hsv.js +128 -54
  72. package/examples/jsm/nodes/materialx/lib/mx_noise.js +1430 -618
  73. package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +24 -14
  74. package/examples/jsm/nodes/math/MathNode.js +2 -0
  75. package/examples/jsm/nodes/math/OperatorNode.js +19 -6
  76. package/examples/jsm/nodes/shadernode/ShaderNode.js +32 -3
  77. package/examples/jsm/nodes/utils/FunctionOverloadingNode.js +95 -0
  78. package/examples/jsm/nodes/utils/RemapNode.js +2 -2
  79. package/examples/jsm/nodes/utils/SplitNode.js +8 -2
  80. package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +3 -3
  81. package/examples/jsm/objects/QuadMesh.js +60 -0
  82. package/examples/jsm/postprocessing/GTAOPass.js +572 -0
  83. package/examples/jsm/postprocessing/OutputPass.js +2 -0
  84. package/examples/jsm/renderers/common/Animation.js +10 -21
  85. package/examples/jsm/renderers/common/Backend.js +19 -3
  86. package/examples/jsm/renderers/common/Background.js +20 -22
  87. package/examples/jsm/renderers/common/Bindings.js +30 -21
  88. package/examples/jsm/renderers/common/ChainMap.js +3 -3
  89. package/examples/jsm/renderers/common/Color4.js +37 -0
  90. package/examples/jsm/renderers/common/Geometries.js +4 -4
  91. package/examples/jsm/renderers/common/Info.js +12 -2
  92. package/examples/jsm/renderers/common/Pipelines.js +3 -51
  93. package/examples/jsm/renderers/common/PostProcessing.js +25 -0
  94. package/examples/jsm/renderers/common/RenderContext.js +1 -1
  95. package/examples/jsm/renderers/common/RenderContexts.js +1 -1
  96. package/examples/jsm/renderers/common/RenderObject.js +13 -1
  97. package/examples/jsm/renderers/common/RenderObjects.js +4 -2
  98. package/examples/jsm/renderers/common/Renderer.js +137 -37
  99. package/examples/jsm/renderers/common/StorageTexture.js +1 -0
  100. package/examples/jsm/renderers/common/Textures.js +4 -1
  101. package/examples/jsm/renderers/common/nodes/NodeBuilderState.js +10 -2
  102. package/examples/jsm/renderers/common/nodes/NodeUniformsGroup.js +44 -0
  103. package/examples/jsm/renderers/common/nodes/Nodes.js +74 -7
  104. package/examples/jsm/renderers/webgl/WebGLBackend.js +91 -33
  105. package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +100 -31
  106. package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +57 -5
  107. package/examples/jsm/renderers/webgl/utils/WebGLCapabilities.js +36 -0
  108. package/examples/jsm/renderers/webgl/utils/WebGLExtensions.js +11 -1
  109. package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +71 -2
  110. package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +42 -0
  111. package/examples/jsm/renderers/webgl-legacy/nodes/SlotNode.js +1 -1
  112. package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +33 -3
  113. package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js +4 -14
  114. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +186 -137
  115. package/examples/jsm/renderers/webgpu/WebGPURenderer.js +1 -1
  116. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +209 -90
  117. package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +15 -10
  118. package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +11 -3
  119. package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +2 -3
  120. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +88 -6
  121. package/examples/jsm/shaders/FXAAShader.js +133 -133
  122. package/examples/jsm/shaders/GTAOShader.js +424 -0
  123. package/examples/jsm/shaders/OutputShader.js +4 -0
  124. package/examples/jsm/shaders/PoissonDenoiseShader.js +226 -0
  125. package/examples/jsm/shaders/SAOShader.js +2 -3
  126. package/examples/jsm/shaders/SSAOShader.js +2 -3
  127. package/examples/jsm/transpiler/AST.js +40 -1
  128. package/examples/jsm/transpiler/GLSLDecoder.js +50 -8
  129. package/examples/jsm/transpiler/ShaderToyDecoder.js +4 -4
  130. package/examples/jsm/transpiler/TSLEncoder.js +124 -20
  131. package/examples/jsm/utils/SortUtils.js +158 -0
  132. package/examples/jsm/utils/TextureUtils.js +33 -21
  133. package/examples/jsm/webxr/ARButton.js +14 -0
  134. package/examples/jsm/webxr/VRButton.js +23 -8
  135. package/examples/jsm/webxr/XRButton.js +25 -11
  136. package/package.json +5 -6
  137. package/src/Three.js +1 -0
  138. package/src/constants.js +2 -1
  139. package/src/core/BufferAttribute.js +21 -2
  140. package/src/core/InterleavedBuffer.js +21 -1
  141. package/src/core/Object3D.js +60 -12
  142. package/src/core/UniformsGroup.js +7 -1
  143. package/src/extras/curves/LineCurve3.js +4 -0
  144. package/src/loaders/AudioLoader.js +1 -1
  145. package/src/loaders/BufferGeometryLoader.js +0 -7
  146. package/src/loaders/ImageBitmapLoader.js +25 -1
  147. package/src/loaders/ObjectLoader.js +49 -0
  148. package/src/materials/ShaderMaterial.js +2 -1
  149. package/src/math/ColorManagement.js +0 -16
  150. package/src/math/Quaternion.js +5 -4
  151. package/src/math/Sphere.js +2 -0
  152. package/src/math/Triangle.js +17 -5
  153. package/src/objects/BatchedMesh.js +1020 -0
  154. package/src/objects/Skeleton.js +1 -3
  155. package/src/renderers/WebGL3DRenderTarget.js +2 -2
  156. package/src/renderers/WebGLArrayRenderTarget.js +2 -2
  157. package/src/renderers/WebGLRenderer.js +24 -19
  158. package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +19 -0
  159. package/src/renderers/shaders/ShaderChunk/batching_vertex.glsl.js +5 -0
  160. package/src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl.js +0 -5
  161. package/src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl.js +31 -4
  162. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +9 -4
  163. package/src/renderers/shaders/ShaderChunk/project_vertex.glsl.js +6 -0
  164. package/src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl.js +9 -17
  165. package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +84 -0
  166. package/src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl.js +6 -0
  167. package/src/renderers/shaders/ShaderChunk.js +4 -0
  168. package/src/renderers/shaders/ShaderLib/depth.glsl.js +2 -0
  169. package/src/renderers/shaders/ShaderLib/distanceRGBA.glsl.js +2 -0
  170. package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +2 -0
  171. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +2 -0
  172. package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +3 -0
  173. package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +2 -0
  174. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +2 -0
  175. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +2 -0
  176. package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +2 -0
  177. package/src/renderers/shaders/ShaderLib/shadow.glsl.js +3 -0
  178. package/src/renderers/webgl/WebGLAttributes.js +39 -5
  179. package/src/renderers/webgl/WebGLBufferRenderer.js +31 -0
  180. package/src/renderers/webgl/WebGLCubeMaps.js +1 -1
  181. package/src/renderers/webgl/WebGLExtensions.js +1 -0
  182. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +31 -0
  183. package/src/renderers/webgl/WebGLLights.js +11 -2
  184. package/src/renderers/webgl/WebGLProgram.js +20 -1
  185. package/src/renderers/webgl/WebGLPrograms.js +5 -0
  186. package/src/renderers/webgl/WebGLShadowMap.js +35 -0
  187. package/src/renderers/webgl/WebGLTextures.js +7 -11
  188. package/src/renderers/webgl/WebGLUniforms.js +11 -1
  189. package/src/renderers/webgl/WebGLUniformsGroups.js +72 -93
  190. package/src/renderers/webxr/WebXRManager.js +16 -0
  191. package/examples/jsm/objects/BatchedMesh.js +0 -586
@@ -1,6 +1,6 @@
1
1
  import { NoColorSpace, FloatType } from 'three';
2
2
 
3
- import UniformsGroup from '../../common/UniformsGroup.js';
3
+ import NodeUniformsGroup from '../../common/nodes/NodeUniformsGroup.js';
4
4
 
5
5
  import NodeSampler from '../../common/nodes/NodeSampler.js';
6
6
  import { NodeSampledTexture, NodeSampledCubeTexture } from '../../common/nodes/NodeSampledTexture.js';
@@ -9,7 +9,7 @@ import UniformBuffer from '../../common/UniformBuffer.js';
9
9
  import StorageBuffer from '../../common/StorageBuffer.js';
10
10
  import { getVectorLength, getStrideLength } from '../../common/BufferUtils.js';
11
11
 
12
- import { NodeBuilder, CodeNode, NodeMaterial, FunctionNode } from '../../../nodes/Nodes.js';
12
+ import { NodeBuilder, CodeNode, NodeMaterial } from '../../../nodes/Nodes.js';
13
13
 
14
14
  import { getFormat } from '../utils/WebGPUTextureUtils.js';
15
15
 
@@ -25,6 +25,10 @@ const supports = {
25
25
  instance: true
26
26
  };
27
27
 
28
+ const wgslFnOpLib = {
29
+ '^^': 'threejs_xor'
30
+ };
31
+
28
32
  const wgslTypeLib = {
29
33
  float: 'f32',
30
34
  int: 'i32',
@@ -63,15 +67,31 @@ const wgslMethods = {
63
67
  dFdy: '- dpdy',
64
68
  mod: 'threejs_mod',
65
69
  lessThanEqual: 'threejs_lessThanEqual',
66
- inversesqrt: 'inverseSqrt'
70
+ greaterThan: 'threejs_greaterThan',
71
+ inversesqrt: 'inverseSqrt',
72
+ bitcast: 'bitcast<f32>'
67
73
  };
68
74
 
69
75
  const wgslPolyfill = {
76
+ threejs_xor: new CodeNode( `
77
+ fn threejs_xor( a : bool, b : bool ) -> bool {
78
+
79
+ return ( a || b ) && !( a && b );
80
+
81
+ }
82
+ ` ),
70
83
  lessThanEqual: new CodeNode( `
71
84
  fn threejs_lessThanEqual( a : vec3<f32>, b : vec3<f32> ) -> vec3<bool> {
72
85
 
73
86
  return vec3<bool>( a.x <= b.x, a.y <= b.y, a.z <= b.z );
74
87
 
88
+ }
89
+ ` ),
90
+ greaterThan: new CodeNode( `
91
+ fn threejs_greaterThan( a : vec3<f32>, b : vec3<f32> ) -> vec3<bool> {
92
+
93
+ return vec3<bool>( a.x > b.x, a.y > b.y, a.z > b.z );
94
+
75
95
  }
76
96
  ` ),
77
97
  mod: new CodeNode( `
@@ -98,14 +118,9 @@ class WGSLNodeBuilder extends NodeBuilder {
98
118
 
99
119
  super( object, renderer, new WGSLNodeParser(), scene );
100
120
 
101
- this.uniformsGroup = {};
121
+ this.uniformGroups = {};
102
122
 
103
- this.builtins = {
104
- vertex: new Map(),
105
- fragment: new Map(),
106
- compute: new Map(),
107
- attribute: new Map()
108
- };
123
+ this.builtins = {};
109
124
 
110
125
  }
111
126
 
@@ -133,25 +148,33 @@ class WGSLNodeBuilder extends NodeBuilder {
133
148
 
134
149
  }
135
150
 
136
- _getSampler( texture, textureProperty, uvSnippet, shaderStage = this.shaderStage ) {
151
+ _generateTextureSample( texture, textureProperty, uvSnippet, depthSnippet, shaderStage = this.shaderStage ) {
137
152
 
138
153
  if ( shaderStage === 'fragment' ) {
139
154
 
140
- return `textureSample( ${textureProperty}, ${textureProperty}_sampler, ${uvSnippet} )`;
155
+ if ( depthSnippet ) {
156
+
157
+ return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet } )`;
158
+
159
+ } else {
160
+
161
+ return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet } )`;
162
+
163
+ }
141
164
 
142
165
  } else {
143
166
 
144
- return this.getTextureLoad( texture, textureProperty, uvSnippet );
167
+ return this.generateTextureLod( texture, textureProperty, uvSnippet );
145
168
 
146
169
  }
147
170
 
148
171
  }
149
172
 
150
- _getVideoSampler( textureProperty, uvSnippet, shaderStage = this.shaderStage ) {
173
+ _generateVideoSample( textureProperty, uvSnippet, shaderStage = this.shaderStage ) {
151
174
 
152
175
  if ( shaderStage === 'fragment' ) {
153
176
 
154
- return `textureSampleBaseClampToEdge( ${textureProperty}, ${textureProperty}_sampler, vec2<f32>( ${uvSnippet}.x, 1.0 - ${uvSnippet}.y ) )`;
177
+ return `textureSampleBaseClampToEdge( ${ textureProperty }, ${ textureProperty }_sampler, vec2<f32>( ${ uvSnippet }.x, 1.0 - ${ uvSnippet }.y ) )`;
155
178
 
156
179
  } else {
157
180
 
@@ -161,27 +184,41 @@ class WGSLNodeBuilder extends NodeBuilder {
161
184
 
162
185
  }
163
186
 
164
- _getSamplerLevel( texture, textureProperty, uvSnippet, biasSnippet, shaderStage = this.shaderStage ) {
187
+ _generateTextureSampleLevel( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet, shaderStage = this.shaderStage ) {
165
188
 
166
189
  if ( shaderStage === 'fragment' && this.isUnfilterable( texture ) === false ) {
167
190
 
168
- return `textureSampleLevel( ${textureProperty}, ${textureProperty}_sampler, ${uvSnippet}, ${biasSnippet} )`;
191
+ return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet } )`;
169
192
 
170
193
  } else {
171
194
 
172
- return this.getTextureLoad( texture, textureProperty, uvSnippet, biasSnippet );
195
+ return this.generateTextureLod( texture, textureProperty, uvSnippet, levelSnippet );
173
196
 
174
197
  }
175
198
 
176
199
  }
177
200
 
178
- getTextureLoad( texture, textureProperty, uvSnippet, biasSnippet = '0' ) {
201
+ generateTextureLod( texture, textureProperty, uvSnippet, levelSnippet = '0' ) {
179
202
 
180
203
  this._include( 'repeatWrapping' );
181
204
 
182
- const dimension = `textureDimensions( ${textureProperty}, 0 )`;
205
+ const dimension = `textureDimensions( ${ textureProperty }, 0 )`;
206
+
207
+ return `textureLoad( ${ textureProperty }, threejs_repeatWrapping( ${ uvSnippet }, ${ dimension } ), i32( ${ levelSnippet } ) )`;
208
+
209
+ }
210
+
211
+ generateTextureLoad( texture, textureProperty, uvIndexSnippet, depthSnippet, levelSnippet = '0u' ) {
212
+
213
+ if ( depthSnippet ) {
214
+
215
+ return `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, ${ depthSnippet }, ${ levelSnippet } )`;
183
216
 
184
- return `textureLoad( ${textureProperty}, threejs_repeatWrapping( ${uvSnippet}, ${dimension} ), i32( ${biasSnippet} ) )`;
217
+ } else {
218
+
219
+ return `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, ${ levelSnippet } )`;
220
+
221
+ }
185
222
 
186
223
  }
187
224
 
@@ -191,21 +228,21 @@ class WGSLNodeBuilder extends NodeBuilder {
191
228
 
192
229
  }
193
230
 
194
- getTexture( texture, textureProperty, uvSnippet, shaderStage = this.shaderStage ) {
231
+ generateTexture( texture, textureProperty, uvSnippet, depthSnippet, shaderStage = this.shaderStage ) {
195
232
 
196
233
  let snippet = null;
197
234
 
198
235
  if ( texture.isVideoTexture === true ) {
199
236
 
200
- snippet = this._getVideoSampler( textureProperty, uvSnippet, shaderStage );
237
+ snippet = this._generateVideoSample( textureProperty, uvSnippet, shaderStage );
201
238
 
202
239
  } else if ( this.isUnfilterable( texture ) ) {
203
240
 
204
- snippet = this.getTextureLoad( texture, textureProperty, uvSnippet );
241
+ snippet = this.generateTextureLod( texture, textureProperty, uvSnippet, '0', depthSnippet, shaderStage );
205
242
 
206
243
  } else {
207
244
 
208
- snippet = this._getSampler( texture, textureProperty, uvSnippet, shaderStage );
245
+ snippet = this._generateTextureSample( texture, textureProperty, uvSnippet, depthSnippet, shaderStage );
209
246
 
210
247
  }
211
248
 
@@ -213,11 +250,11 @@ class WGSLNodeBuilder extends NodeBuilder {
213
250
 
214
251
  }
215
252
 
216
- getTextureCompare( texture, textureProperty, uvSnippet, compareSnippet, shaderStage = this.shaderStage ) {
253
+ generateTextureCompare( texture, textureProperty, uvSnippet, compareSnippet, depthSnippet, shaderStage = this.shaderStage ) {
217
254
 
218
255
  if ( shaderStage === 'fragment' ) {
219
256
 
220
- return `textureSampleCompare( ${textureProperty}, ${textureProperty}_sampler, ${uvSnippet}, ${compareSnippet} )`;
257
+ return `textureSampleCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ compareSnippet } )`;
221
258
 
222
259
  } else {
223
260
 
@@ -227,17 +264,17 @@ class WGSLNodeBuilder extends NodeBuilder {
227
264
 
228
265
  }
229
266
 
230
- getTextureLevel( texture, textureProperty, uvSnippet, biasSnippet, shaderStage = this.shaderStage ) {
267
+ generateTextureLevel( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet, shaderStage = this.shaderStage ) {
231
268
 
232
269
  let snippet = null;
233
270
 
234
271
  if ( texture.isVideoTexture === true ) {
235
272
 
236
- snippet = this._getVideoSampler( textureProperty, uvSnippet, shaderStage );
273
+ snippet = this._generateVideoSample( textureProperty, uvSnippet, shaderStage );
237
274
 
238
275
  } else {
239
276
 
240
- snippet = this._getSamplerLevel( texture, textureProperty, uvSnippet, biasSnippet, shaderStage );
277
+ snippet = this._generateTextureSampleLevel( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet, shaderStage );
241
278
 
242
279
  }
243
280
 
@@ -251,7 +288,7 @@ class WGSLNodeBuilder extends NodeBuilder {
251
288
 
252
289
  if ( shaderStage === 'vertex' ) {
253
290
 
254
- return `NodeVaryings.${ node.name }`;
291
+ return `varyings.${ node.name }`;
255
292
 
256
293
  }
257
294
 
@@ -266,11 +303,11 @@ class WGSLNodeBuilder extends NodeBuilder {
266
303
 
267
304
  } else if ( type === 'buffer' || type === 'storageBuffer' ) {
268
305
 
269
- return `NodeBuffer_${node.node.id}.${name}`;
306
+ return `NodeBuffer_${ node.id }.${name}`;
270
307
 
271
308
  } else {
272
309
 
273
- return `NodeUniforms.${name}`;
310
+ return node.groupNode.name + '.' + name;
274
311
 
275
312
  }
276
313
 
@@ -280,10 +317,32 @@ class WGSLNodeBuilder extends NodeBuilder {
280
317
 
281
318
  }
282
319
 
320
+ _getUniformGroupCount( shaderStage ) {
321
+
322
+ return Object.keys( this.uniforms[ shaderStage ] ).length;
323
+
324
+ }
325
+
326
+ getFunctionOperator( op ) {
327
+
328
+ const fnOp = wgslFnOpLib[ op ];
329
+
330
+ if ( fnOp !== undefined ) {
331
+
332
+ this._include( fnOp );
333
+
334
+ return fnOp;
335
+
336
+ }
337
+
338
+ return null;
339
+
340
+ }
341
+
283
342
  getUniformFromNode( node, type, shaderStage, name = null ) {
284
343
 
285
344
  const uniformNode = super.getUniformFromNode( node, type, shaderStage, name );
286
- const nodeData = this.getDataFromNode( node, shaderStage );
345
+ const nodeData = this.getDataFromNode( node, shaderStage, this.globalCache );
287
346
 
288
347
  if ( nodeData.uniformGPU === undefined ) {
289
348
 
@@ -308,22 +367,18 @@ class WGSLNodeBuilder extends NodeBuilder {
308
367
  texture.store = node.isStoreTextureNode === true;
309
368
  texture.setVisibility( gpuShaderStageLib[ shaderStage ] );
310
369
 
311
- // add first textures in sequence and group for last
312
- const lastBinding = bindings[ bindings.length - 1 ];
313
- const index = lastBinding && lastBinding.isUniformsGroup ? bindings.length - 1 : bindings.length;
314
-
315
370
  if ( shaderStage === 'fragment' && this.isUnfilterable( node.value ) === false && texture.store === false ) {
316
371
 
317
372
  const sampler = new NodeSampler( `${uniformNode.name}_sampler`, uniformNode.node );
318
373
  sampler.setVisibility( gpuShaderStageLib[ shaderStage ] );
319
374
 
320
- bindings.splice( index, 0, sampler, texture );
375
+ bindings.push( sampler, texture );
321
376
 
322
377
  uniformGPU = [ sampler, texture ];
323
378
 
324
379
  } else {
325
380
 
326
- bindings.splice( index, 0, texture );
381
+ bindings.push( texture );
327
382
 
328
383
  uniformGPU = [ texture ];
329
384
 
@@ -335,24 +390,25 @@ class WGSLNodeBuilder extends NodeBuilder {
335
390
  const buffer = new bufferClass( 'NodeBuffer_' + node.id, node.value );
336
391
  buffer.setVisibility( gpuShaderStageLib[ shaderStage ] );
337
392
 
338
- // add first textures in sequence and group for last
339
- const lastBinding = bindings[ bindings.length - 1 ];
340
- const index = lastBinding && lastBinding.isUniformsGroup ? bindings.length - 1 : bindings.length;
341
-
342
- bindings.splice( index, 0, buffer );
393
+ bindings.push( buffer );
343
394
 
344
395
  uniformGPU = buffer;
345
396
 
346
397
  } else {
347
398
 
348
- let uniformsGroup = this.uniformsGroup[ shaderStage ];
399
+ const group = node.groupNode;
400
+ const groupName = group.name;
401
+
402
+ const uniformsStage = this.uniformGroups[ shaderStage ] || ( this.uniformGroups[ shaderStage ] = {} );
403
+
404
+ let uniformsGroup = uniformsStage[ groupName ];
349
405
 
350
406
  if ( uniformsGroup === undefined ) {
351
407
 
352
- uniformsGroup = new UniformsGroup( 'nodeUniforms' );
408
+ uniformsGroup = new NodeUniformsGroup( groupName, group );
353
409
  uniformsGroup.setVisibility( gpuShaderStageLib[ shaderStage ] );
354
410
 
355
- this.uniformsGroup[ shaderStage ] = uniformsGroup;
411
+ uniformsStage[ groupName ] = uniformsGroup;
356
412
 
357
413
  bindings.push( uniformsGroup );
358
414
 
@@ -402,13 +458,13 @@ class WGSLNodeBuilder extends NodeBuilder {
402
458
 
403
459
  isReference( type ) {
404
460
 
405
- return super.isReference( type ) || type === 'texture_2d' || type === 'texture_cube' || type === 'texture_storage_2d';
461
+ return super.isReference( type ) || type === 'texture_2d' || type === 'texture_cube' || type === 'texture_depth_2d' || type === 'texture_storage_2d';
406
462
 
407
463
  }
408
464
 
409
465
  getBuiltin( name, property, type, shaderStage = this.shaderStage ) {
410
466
 
411
- const map = this.builtins[ shaderStage ];
467
+ const map = this.builtins[ shaderStage ] || ( this.builtins[ shaderStage ] = new Map() );
412
468
 
413
469
  if ( map.has( name ) === false ) {
414
470
 
@@ -436,7 +492,7 @@ class WGSLNodeBuilder extends NodeBuilder {
436
492
 
437
493
  }
438
494
 
439
- buildFunctionNode( shaderNode ) {
495
+ buildFunctionCode( shaderNode ) {
440
496
 
441
497
  const layout = shaderNode.layout;
442
498
  const flowData = this.flowShaderNode( shaderNode );
@@ -460,7 +516,7 @@ ${ flowData.code }
460
516
 
461
517
  //
462
518
 
463
- return new FunctionNode( code );
519
+ return code;
464
520
 
465
521
  }
466
522
 
@@ -484,7 +540,13 @@ ${ flowData.code }
484
540
 
485
541
  getFragCoord() {
486
542
 
487
- return this.getBuiltin( 'position', 'fragCoord', 'vec4<f32>', 'fragment' );
543
+ return this.getBuiltin( 'position', 'fragCoord', 'vec4<f32>' ) + '.xy';
544
+
545
+ }
546
+
547
+ getFragDepth() {
548
+
549
+ return 'output.' + this.getBuiltin( 'frag_depth', 'depth', 'f32', 'output' );
488
550
 
489
551
  }
490
552
 
@@ -494,6 +556,25 @@ ${ flowData.code }
494
556
 
495
557
  }
496
558
 
559
+ getBuiltins( shaderStage ) {
560
+
561
+ const snippets = [];
562
+ const builtins = this.builtins[ shaderStage ];
563
+
564
+ if ( builtins !== undefined ) {
565
+
566
+ for ( const { name, property, type } of builtins.values() ) {
567
+
568
+ snippets.push( `@builtin( ${name} ) ${property} : ${type}` );
569
+
570
+ }
571
+
572
+ }
573
+
574
+ return snippets.join( ',\n\t' );
575
+
576
+ }
577
+
497
578
  getAttributes( shaderStage ) {
498
579
 
499
580
  const snippets = [];
@@ -506,11 +587,9 @@ ${ flowData.code }
506
587
 
507
588
  if ( shaderStage === 'vertex' || shaderStage === 'compute' ) {
508
589
 
509
- for ( const { name, property, type } of this.builtins.attribute.values() ) {
590
+ const builtins = this.getBuiltins( 'attribute' );
510
591
 
511
- snippets.push( `@builtin( ${name} ) ${property} : ${type}` );
512
-
513
- }
592
+ if ( builtins ) snippets.push( builtins );
514
593
 
515
594
  const attributes = this.getAttributesArray();
516
595
 
@@ -635,15 +714,13 @@ ${ flowData.code }
635
714
 
636
715
  }
637
716
 
638
- for ( const { name, property, type } of this.builtins[ shaderStage ].values() ) {
717
+ const builtins = this.getBuiltins( shaderStage );
639
718
 
640
- snippets.push( `@builtin( ${name} ) ${property} : ${type}` );
641
-
642
- }
719
+ if ( builtins ) snippets.push( builtins );
643
720
 
644
721
  const code = snippets.join( ',\n\t' );
645
722
 
646
- return shaderStage === 'vertex' ? this._getWGSLStruct( 'NodeVaryingsStruct', '\t' + code ) : code;
723
+ return shaderStage === 'vertex' ? this._getWGSLStruct( 'VaryingsStruct', '\t' + code ) : code;
647
724
 
648
725
  }
649
726
 
@@ -653,7 +730,8 @@ ${ flowData.code }
653
730
 
654
731
  const bindingSnippets = [];
655
732
  const bufferSnippets = [];
656
- const groupSnippets = [];
733
+ const structSnippets = [];
734
+ const uniformGroups = {};
657
735
 
658
736
  let index = this.bindingsOffset[ shaderStage ];
659
737
 
@@ -683,6 +761,10 @@ ${ flowData.code }
683
761
 
684
762
  textureType = 'texture_cube<f32>';
685
763
 
764
+ } else if ( texture.isDataArrayTexture === true ) {
765
+
766
+ textureType = 'texture_2d_array<f32>';
767
+
686
768
  } else if ( texture.isDepthTexture === true ) {
687
769
 
688
770
  textureType = 'texture_depth_2d';
@@ -720,16 +802,22 @@ ${ flowData.code }
720
802
  } else {
721
803
 
722
804
  const vectorType = this.getType( this.getVectorType( uniform.type ) );
805
+ const groupName = uniform.groupNode.name;
806
+
807
+ const group = uniformGroups[ groupName ] || ( uniformGroups[ groupName ] = {
808
+ index: index ++,
809
+ snippets: []
810
+ } );
723
811
 
724
812
  if ( Array.isArray( uniform.value ) === true ) {
725
813
 
726
814
  const length = uniform.value.length;
727
815
 
728
- groupSnippets.push( `uniform ${vectorType}[ ${length} ] ${uniform.name}` );
816
+ group.snippets.push( `uniform ${vectorType}[ ${length} ] ${uniform.name}` );
729
817
 
730
818
  } else {
731
819
 
732
- groupSnippets.push( `\t${uniform.name} : ${ vectorType}` );
820
+ group.snippets.push( `\t${uniform.name} : ${ vectorType}` );
733
821
 
734
822
  }
735
823
 
@@ -737,15 +825,18 @@ ${ flowData.code }
737
825
 
738
826
  }
739
827
 
740
- let code = bindingSnippets.join( '\n' );
741
- code += bufferSnippets.join( '\n' );
828
+ for ( const name in uniformGroups ) {
742
829
 
743
- if ( groupSnippets.length > 0 ) {
830
+ const group = uniformGroups[ name ];
744
831
 
745
- code += this._getWGSLStructBinding( 'NodeUniforms', groupSnippets.join( ',\n' ), 'uniform', index ++ );
832
+ structSnippets.push( this._getWGSLStructBinding( name, group.snippets.join( ',\n' ), 'uniform', group.index ) );
746
833
 
747
834
  }
748
835
 
836
+ let code = bindingSnippets.join( '\n' );
837
+ code += bufferSnippets.join( '\n' );
838
+ code += structSnippets.join( '\n' );
839
+
749
840
  return code;
750
841
 
751
842
  }
@@ -756,12 +847,25 @@ ${ flowData.code }
756
847
 
757
848
  for ( const shaderStage in shadersData ) {
758
849
 
850
+ const stageData = shadersData[ shaderStage ];
851
+ stageData.uniforms = this.getUniforms( shaderStage );
852
+ stageData.attributes = this.getAttributes( shaderStage );
853
+ stageData.varyings = this.getVaryings( shaderStage );
854
+ stageData.structs = this.getStructs( shaderStage );
855
+ stageData.vars = this.getVars( shaderStage );
856
+ stageData.codes = this.getCodes( shaderStage );
857
+
858
+ //
859
+
759
860
  let flow = '// code\n\n';
760
861
  flow += this.flowCode[ shaderStage ];
761
862
 
762
863
  const flowNodes = this.flowNodes[ shaderStage ];
763
864
  const mainNode = flowNodes[ flowNodes.length - 1 ];
764
865
 
866
+ const outputNode = mainNode.outputNode;
867
+ const isOutputStruct = ( outputNode !== undefined && outputNode.isOutputStructNode === true );
868
+
765
869
  for ( const node of flowNodes ) {
766
870
 
767
871
  const flowSlotData = this.getFlowData( node/*, shaderStage*/ );
@@ -779,34 +883,42 @@ ${ flowData.code }
779
883
 
780
884
  if ( node === mainNode && shaderStage !== 'compute' ) {
781
885
 
782
- flow += '// result\n\t';
886
+ flow += '// result\n\n\t';
783
887
 
784
888
  if ( shaderStage === 'vertex' ) {
785
889
 
786
- flow += 'NodeVaryings.Vertex = ';
890
+ flow += `varyings.Vertex = ${ flowSlotData.result };`;
787
891
 
788
892
  } else if ( shaderStage === 'fragment' ) {
789
893
 
790
- flow += 'return ';
894
+ if ( isOutputStruct ) {
791
895
 
792
- }
896
+ stageData.returnType = outputNode.nodeType;
897
+
898
+ flow += `return ${ flowSlotData.result };`;
899
+
900
+ } else {
901
+
902
+ let structSnippet = '\t@location(0) color: vec4<f32>';
903
+
904
+ const builtins = this.getBuiltins( 'output' );
793
905
 
794
- flow += `${ flowSlotData.result };`;
906
+ if ( builtins ) structSnippet += ',\n\t' + builtins;
907
+
908
+ stageData.returnType = 'OutputStruct';
909
+ stageData.structs += this._getWGSLStruct( 'OutputStruct', structSnippet );
910
+ stageData.structs += '\nvar<private> output : OutputStruct;\n\n';
911
+
912
+ flow += `output.color = ${ flowSlotData.result };\n\n\treturn output;`;
913
+
914
+ }
915
+
916
+ }
795
917
 
796
918
  }
797
919
 
798
920
  }
799
921
 
800
- const outputNode = mainNode.outputNode;
801
- const stageData = shadersData[ shaderStage ];
802
-
803
- stageData.uniforms = this.getUniforms( shaderStage );
804
- stageData.attributes = this.getAttributes( shaderStage );
805
- stageData.varyings = this.getVaryings( shaderStage );
806
- stageData.structs = this.getStructs( shaderStage );
807
- stageData.vars = this.getVars( shaderStage );
808
- stageData.codes = this.getCodes( shaderStage );
809
- stageData.returnType = ( outputNode !== undefined && outputNode.isOutputStructNode === true ) ? outputNode.nodeType : '@location( 0 ) vec4<f32>';
810
922
  stageData.flow = flow;
811
923
 
812
924
  }
@@ -850,7 +962,16 @@ ${ flowData.code }
850
962
 
851
963
  _include( name ) {
852
964
 
853
- wgslPolyfill[ name ].build( this );
965
+ const codeNode = wgslPolyfill[ name ];
966
+ codeNode.build( this );
967
+
968
+ if ( this.currentFunctionNode !== null ) {
969
+
970
+ this.currentFunctionNode.includes.push( codeNode );
971
+
972
+ }
973
+
974
+ return codeNode;
854
975
 
855
976
  }
856
977
 
@@ -863,15 +984,13 @@ ${shaderData.uniforms}
863
984
 
864
985
  // varyings
865
986
  ${shaderData.varyings}
987
+ var<private> varyings : VaryingsStruct;
866
988
 
867
989
  // codes
868
990
  ${shaderData.codes}
869
991
 
870
992
  @vertex
871
- fn main( ${shaderData.attributes} ) -> NodeVaryingsStruct {
872
-
873
- // system
874
- var NodeVaryings: NodeVaryingsStruct;
993
+ fn main( ${shaderData.attributes} ) -> VaryingsStruct {
875
994
 
876
995
  // vars
877
996
  ${shaderData.vars}
@@ -879,7 +998,7 @@ fn main( ${shaderData.attributes} ) -> NodeVaryingsStruct {
879
998
  // flow
880
999
  ${shaderData.flow}
881
1000
 
882
- return NodeVaryings;
1001
+ return varyings;
883
1002
 
884
1003
  }
885
1004
  `;
@@ -72,9 +72,9 @@ class WebGPUAttributeUtils {
72
72
  const buffer = backend.get( bufferAttribute ).buffer;
73
73
 
74
74
  const array = bufferAttribute.array;
75
- const updateRange = bufferAttribute.updateRange;
75
+ const updateRanges = bufferAttribute.updateRanges;
76
76
 
77
- if ( updateRange.count === - 1 ) {
77
+ if ( updateRanges.length === 0 ) {
78
78
 
79
79
  // Not using update ranges
80
80
 
@@ -87,15 +87,20 @@ class WebGPUAttributeUtils {
87
87
 
88
88
  } else {
89
89
 
90
- device.queue.writeBuffer(
91
- buffer,
92
- 0,
93
- array,
94
- updateRange.offset * array.BYTES_PER_ELEMENT,
95
- updateRange.count * array.BYTES_PER_ELEMENT
96
- );
90
+ for ( let i = 0, l = updateRanges.length; i < l; i ++ ) {
91
+
92
+ const range = updateRanges[ i ];
93
+ device.queue.writeBuffer(
94
+ buffer,
95
+ 0,
96
+ array,
97
+ range.start * array.BYTES_PER_ELEMENT,
98
+ range.count * array.BYTES_PER_ELEMENT
99
+ );
100
+
101
+ }
97
102
 
98
- updateRange.count = - 1; // reset range
103
+ bufferAttribute.clearUpdateRanges();
99
104
 
100
105
  }
101
106