super-three 0.154.1 → 0.155.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 (106) hide show
  1. package/build/three.cjs +256 -38
  2. package/build/three.js +256 -38
  3. package/build/three.min.js +1 -1
  4. package/build/three.module.js +255 -39
  5. package/build/three.module.min.js +1 -1
  6. package/examples/jsm/controls/OrbitControls.js +143 -21
  7. package/examples/jsm/environments/RoomEnvironment.js +1 -1
  8. package/examples/jsm/exporters/USDZExporter.js +1 -0
  9. package/examples/jsm/interactive/SelectionHelper.js +7 -0
  10. package/examples/jsm/loaders/FBXLoader.js +1 -1
  11. package/examples/jsm/loaders/GLTFLoader.js +8 -3
  12. package/examples/jsm/loaders/KTX2Loader.js +4 -4
  13. package/examples/jsm/loaders/LDrawLoader.js +1 -1
  14. package/examples/jsm/loaders/NRRDLoader.js +3 -3
  15. package/examples/jsm/loaders/PLYLoader.js +1 -1
  16. package/examples/jsm/loaders/TGALoader.js +10 -10
  17. package/examples/jsm/loaders/VRMLLoader.js +1 -1
  18. package/examples/jsm/misc/GPUComputationRenderer.js +0 -9
  19. package/examples/jsm/misc/Volume.js +4 -6
  20. package/examples/jsm/nodes/Nodes.js +5 -6
  21. package/examples/jsm/nodes/accessors/BufferAttributeNode.js +1 -1
  22. package/examples/jsm/nodes/accessors/CubeTextureNode.js +2 -0
  23. package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +14 -1
  24. package/examples/jsm/nodes/accessors/InstanceNode.js +8 -8
  25. package/examples/jsm/nodes/accessors/MaterialNode.js +34 -44
  26. package/examples/jsm/nodes/accessors/SceneNode.js +6 -0
  27. package/examples/jsm/nodes/accessors/TextureNode.js +48 -7
  28. package/examples/jsm/nodes/core/LightingModel.js +7 -9
  29. package/examples/jsm/nodes/core/Node.js +11 -2
  30. package/examples/jsm/nodes/core/PropertyNode.js +4 -0
  31. package/examples/jsm/nodes/display/BumpMapNode.js +77 -0
  32. package/examples/jsm/nodes/display/NormalMapNode.js +2 -2
  33. package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +10 -2
  34. package/examples/jsm/nodes/functions/BSDF/Schlick_to_F0.js +13 -0
  35. package/examples/jsm/nodes/functions/PhongLightingModel.js +53 -14
  36. package/examples/jsm/nodes/functions/PhysicalLightingModel.js +236 -97
  37. package/examples/jsm/nodes/geometry/RangeNode.js +2 -2
  38. package/examples/jsm/nodes/gpgpu/ComputeNode.js +13 -0
  39. package/examples/jsm/nodes/lighting/AONode.js +1 -1
  40. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +58 -20
  41. package/examples/jsm/nodes/lighting/DirectionalLightNode.js +7 -10
  42. package/examples/jsm/nodes/lighting/EnvironmentNode.js +22 -12
  43. package/examples/jsm/nodes/lighting/HemisphereLightNode.js +1 -1
  44. package/examples/jsm/nodes/lighting/LightingContextNode.js +12 -9
  45. package/examples/jsm/nodes/lighting/PointLightNode.js +7 -10
  46. package/examples/jsm/nodes/lighting/SpotLightNode.js +7 -10
  47. package/examples/jsm/nodes/materials/Materials.js +1 -0
  48. package/examples/jsm/nodes/materials/MeshLambertNodeMaterial.js +34 -0
  49. package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +2 -0
  50. package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +2 -2
  51. package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +19 -2
  52. package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +2 -2
  53. package/examples/jsm/nodes/materials/NodeMaterial.js +50 -24
  54. package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +2 -2
  55. package/examples/jsm/nodes/shadernode/ShaderNode.js +2 -2
  56. package/examples/jsm/objects/Reflector.js +1 -9
  57. package/examples/jsm/objects/Refractor.js +0 -8
  58. package/examples/jsm/offscreen/scene.js +0 -1
  59. package/examples/jsm/postprocessing/MaskPass.js +4 -1
  60. package/examples/jsm/postprocessing/OutputPass.js +33 -14
  61. package/examples/jsm/postprocessing/UnrealBloomPass.js +21 -17
  62. package/examples/jsm/renderers/common/Background.js +22 -20
  63. package/examples/jsm/renderers/common/Binding.js +8 -0
  64. package/examples/jsm/renderers/common/Bindings.js +2 -6
  65. package/examples/jsm/renderers/common/Geometries.js +1 -1
  66. package/examples/jsm/renderers/common/Pipelines.js +94 -45
  67. package/examples/jsm/renderers/common/RenderContext.js +1 -0
  68. package/examples/jsm/renderers/common/RenderContexts.js +16 -5
  69. package/examples/jsm/renderers/common/RenderObject.js +20 -4
  70. package/examples/jsm/renderers/common/RenderObjects.js +10 -7
  71. package/examples/jsm/renderers/common/Renderer.js +70 -39
  72. package/examples/jsm/renderers/common/Textures.js +20 -8
  73. package/examples/jsm/renderers/common/nodes/Nodes.js +15 -4
  74. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +51 -54
  75. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +33 -9
  76. package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +55 -36
  77. package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +83 -5
  78. package/examples/jsm/renderers/webgpu/utils/WebGPUConstants.js +24 -22
  79. package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +83 -130
  80. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +35 -8
  81. package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +1 -1
  82. package/examples/jsm/shaders/OutputShader.js +19 -2
  83. package/examples/jsm/utils/BufferGeometryUtils.js +13 -4
  84. package/examples/jsm/webxr/OculusHandPointerModel.js +2 -2
  85. package/package.json +2 -2
  86. package/src/Three.js +2 -0
  87. package/src/animation/PropertyBinding.js +1 -1
  88. package/src/cameras/CubeCamera.js +1 -4
  89. package/src/constants.js +1 -1
  90. package/src/core/BufferAttribute.js +20 -0
  91. package/src/core/Object3D.js +1 -1
  92. package/src/core/RenderTarget.js +122 -0
  93. package/src/geometries/CapsuleGeometry.js +1 -1
  94. package/src/loaders/DataTextureLoader.js +21 -2
  95. package/src/renderers/WebGLMultipleRenderTargets.js +0 -2
  96. package/src/renderers/WebGLRenderTarget.js +3 -110
  97. package/src/renderers/WebGLRenderer.js +62 -8
  98. package/src/renderers/shaders/ShaderChunk/iridescence_fragment.glsl.js +1 -2
  99. package/src/renderers/webgl/WebGLGeometries.js +5 -1
  100. package/src/renderers/webgl/WebGLMaterials.js +1 -1
  101. package/src/renderers/webgl/WebGLPrograms.js +14 -2
  102. package/src/renderers/webgl/WebGLTextures.js +97 -12
  103. package/src/textures/CompressedCubeTexture.js +19 -0
  104. package/examples/jsm/nodes/functions/BSDF/BRDF_BlinnPhong.js +0 -30
  105. package/examples/jsm/renderers/common/RenderTarget.js +0 -15
  106. package/examples/jsm/renderers/common/nodes/NodeRender.js +0 -302
@@ -54,7 +54,8 @@ class WebGPUBackend extends Backend {
54
54
  this.context = null;
55
55
  this.colorBuffer = null;
56
56
 
57
- this.depthBuffers = new WeakMap();
57
+ this.defaultDepthTexture = new DepthTexture();
58
+ this.defaultDepthTexture.name = 'depthBuffer';
58
59
 
59
60
  this.utils = new WebGPUUtils( this );
60
61
  this.attributeUtils = new WebGPUAttributeUtils( this );
@@ -123,9 +124,9 @@ class WebGPUBackend extends Backend {
123
124
 
124
125
  }
125
126
 
126
- async getArrayBuffer( attribute ) {
127
+ async getArrayBufferAsync( attribute ) {
127
128
 
128
- return await this.attributeUtils.getArrayBuffer( attribute );
129
+ return await this.attributeUtils.getArrayBufferAsync( attribute );
129
130
 
130
131
  }
131
132
 
@@ -154,15 +155,25 @@ class WebGPUBackend extends Backend {
154
155
  const textureData = this.get( renderContext.texture );
155
156
  const depthTextureData = this.get( renderContext.depthTexture );
156
157
 
157
- // @TODO: Support RenderTarget with antialiasing.
158
-
159
- colorAttachment.view = textureData.texture.createView( {
158
+ const view = textureData.texture.createView( {
160
159
  baseMipLevel: 0,
161
160
  mipLevelCount: 1,
162
161
  baseArrayLayer: renderContext.activeCubeFace,
163
162
  dimension: GPUTextureViewDimension.TwoD
164
163
  } );
165
164
 
165
+ if ( textureData.msaaTexture !== undefined ) {
166
+
167
+ colorAttachment.view = textureData.msaaTexture.createView();
168
+ colorAttachment.resolveTarget = view;
169
+
170
+ } else {
171
+
172
+ colorAttachment.view = view;
173
+ colorAttachment.resolveTarget = undefined;
174
+
175
+ }
176
+
166
177
  depthStencilAttachment.view = depthTextureData.texture.createView();
167
178
 
168
179
  if ( renderContext.stencil && renderContext.depthTexture.format === DepthFormat ) {
@@ -438,18 +449,18 @@ class WebGPUBackend extends Backend {
438
449
 
439
450
  // vertex buffers
440
451
 
441
- const attributes = renderObject.getAttributes();
452
+ const vertexBuffers = renderObject.getVertexBuffers();
442
453
 
443
- for ( let i = 0, l = attributes.length; i < l; i ++ ) {
454
+ for ( let i = 0, l = vertexBuffers.length; i < l; i ++ ) {
444
455
 
445
- const attribute = attributes[ i ];
456
+ const vertexBuffer = vertexBuffers[ i ];
446
457
 
447
- if ( attributesSet[ i ] !== attribute ) {
458
+ if ( attributesSet[ i ] !== vertexBuffer ) {
448
459
 
449
- const buffer = this.get( attribute ).buffer;
460
+ const buffer = this.get( vertexBuffer ).buffer;
450
461
  passEncoderGPU.setVertexBuffer( i, buffer );
451
462
 
452
- attributesSet[ i ] = attribute;
463
+ attributesSet[ i ] = vertexBuffer;
453
464
 
454
465
  }
455
466
 
@@ -554,9 +565,9 @@ class WebGPUBackend extends Backend {
554
565
 
555
566
  }
556
567
 
557
- createTexture( texture ) {
568
+ createTexture( texture, options ) {
558
569
 
559
- this.textureUtils.createTexture( texture );
570
+ this.textureUtils.createTexture( texture, options );
560
571
 
561
572
  }
562
573
 
@@ -613,23 +624,23 @@ class WebGPUBackend extends Backend {
613
624
 
614
625
  }
615
626
 
616
- createComputePipeline( computePipeline ) {
627
+ createComputePipeline( computePipeline, bindings ) {
617
628
 
618
- this.pipelineUtils.createComputePipeline( computePipeline );
629
+ this.pipelineUtils.createComputePipeline( computePipeline, bindings );
619
630
 
620
631
  }
621
632
 
622
633
  // bindings
623
634
 
624
- createBindings( bindings, pipeline ) {
635
+ createBindings( bindings ) {
625
636
 
626
- this.bindingUtils.createBindings( bindings, pipeline );
637
+ this.bindingUtils.createBindings( bindings );
627
638
 
628
639
  }
629
640
 
630
- updateBindings( bindings, pipeline ) {
641
+ updateBindings( bindings ) {
631
642
 
632
- this.bindingUtils.createBindings( bindings, pipeline );
643
+ this.bindingUtils.createBindings( bindings );
633
644
 
634
645
  }
635
646
 
@@ -753,63 +764,49 @@ class WebGPUBackend extends Backend {
753
764
 
754
765
  _getDepthBufferGPU( renderContext ) {
755
766
 
756
- const { depthBuffers } = this;
757
767
  const { width, height } = this.getDrawingBufferSize();
758
768
 
759
- let depthTexture = depthBuffers.get( renderContext );
769
+ const depthTexture = this.defaultDepthTexture;
770
+ const depthTextureGPU = this.get( depthTexture ).texture;
771
+
772
+ let format, type;
760
773
 
761
- if ( depthTexture !== undefined && depthTexture.image.width === width && depthTexture.image.height === height ) {
774
+ if ( renderContext.stencil ) {
762
775
 
763
- return this.get( depthTexture ).texture;
776
+ format = DepthStencilFormat;
777
+ type = UnsignedInt248Type;
764
778
 
765
- }
779
+ } else if ( renderContext.depth ) {
766
780
 
767
- this._destroyDepthBufferGPU( renderContext );
781
+ format = DepthFormat;
782
+ type = UnsignedIntType;
768
783
 
769
- depthTexture = new DepthTexture();
770
- depthTexture.name = 'depthBuffer';
784
+ }
771
785
 
772
- if ( renderContext.stencil ) {
786
+ if ( depthTextureGPU !== undefined ) {
773
787
 
774
- depthTexture = new DepthTexture();
775
- depthTexture.format = DepthStencilFormat;
776
- depthTexture.type = UnsignedInt248Type;
788
+ if ( depthTexture.image.width === width && depthTexture.image.height === height && depthTexture.format === format && depthTexture.type === type ) {
777
789
 
778
- } else if ( renderContext.depth ) {
790
+ return depthTextureGPU;
779
791
 
780
- depthTexture = new DepthTexture();
781
- depthTexture.format = DepthFormat;
782
- depthTexture.type = UnsignedIntType;
792
+ }
793
+
794
+ this.textureUtils.destroyTexture( depthTexture );
783
795
 
784
796
  }
785
797
 
798
+ depthTexture.name = 'depthBuffer';
799
+ depthTexture.format = format;
800
+ depthTexture.type = type;
786
801
  depthTexture.image.width = width;
787
802
  depthTexture.image.height = height;
788
803
 
789
804
  this.textureUtils.createTexture( depthTexture, { sampleCount: this.parameters.sampleCount } );
790
805
 
791
- depthBuffers.set( renderContext, depthTexture );
792
-
793
806
  return this.get( depthTexture ).texture;
794
807
 
795
808
  }
796
809
 
797
- _destroyDepthBufferGPU( renderContext ) {
798
-
799
- const { depthBuffers } = this;
800
-
801
- const depthTexture = depthBuffers.get( renderContext );
802
-
803
- if ( depthTexture !== undefined ) {
804
-
805
- this.textureUtils.destroyTexture( depthTexture );
806
-
807
- depthBuffers.delete( renderContext );
808
-
809
- }
810
-
811
- }
812
-
813
810
  _configureContext() {
814
811
 
815
812
  this.context.configure( {
@@ -1,4 +1,4 @@
1
- import { NoColorSpace } from 'three';
1
+ import { RenderTarget, NoColorSpace } from 'three';
2
2
 
3
3
  import UniformsGroup from '../../common/UniformsGroup.js';
4
4
  import {
@@ -12,20 +12,17 @@ import UniformBuffer from '../../common/UniformBuffer.js';
12
12
  import StorageBuffer from '../../common/StorageBuffer.js';
13
13
  import { getVectorLength, getStrideLength } from '../../common/BufferUtils.js';
14
14
 
15
- import RenderTarget from '../../common/RenderTarget.js';
16
15
  import CubeRenderTarget from '../../common/CubeRenderTarget.js';
17
16
 
18
17
  import { NodeBuilder, CodeNode, NodeMaterial } from '../../../nodes/Nodes.js';
19
18
 
20
19
  import WGSLNodeParser from './WGSLNodeParser.js';
21
20
 
22
- /*
23
21
  const gpuShaderStageLib = {
24
22
  'vertex': GPUShaderStage.VERTEX,
25
23
  'fragment': GPUShaderStage.FRAGMENT,
26
24
  'compute': GPUShaderStage.COMPUTE
27
25
  };
28
- */
29
26
 
30
27
  const supports = {
31
28
  instance: true
@@ -207,6 +204,20 @@ class WGSLNodeBuilder extends NodeBuilder {
207
204
 
208
205
  }
209
206
 
207
+ getTextureCompare( texture, textureProperty, uvSnippet, compareSnippet, shaderStage = this.shaderStage ) {
208
+
209
+ if ( shaderStage === 'fragment' ) {
210
+
211
+ return `textureSampleCompare( ${textureProperty}, ${textureProperty}_sampler, ${uvSnippet}, ${compareSnippet} )`;
212
+
213
+ } else {
214
+
215
+ console.error( `WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${ shaderStage } shader.` );
216
+
217
+ }
218
+
219
+ }
220
+
210
221
  getTextureLevel( texture, textureProperty, uvSnippet, biasSnippet, shaderStage = this.shaderStage ) {
211
222
 
212
223
  let snippet = null;
@@ -273,8 +284,6 @@ class WGSLNodeBuilder extends NodeBuilder {
273
284
 
274
285
  if ( type === 'texture' || type === 'cubeTexture' ) {
275
286
 
276
- const sampler = new NodeSampler( `${uniformNode.name}_sampler`, uniformNode.node );
277
-
278
287
  let texture = null;
279
288
 
280
289
  if ( type === 'texture' ) {
@@ -287,12 +296,17 @@ class WGSLNodeBuilder extends NodeBuilder {
287
296
 
288
297
  }
289
298
 
299
+ texture.setVisibility( gpuShaderStageLib[ shaderStage ] );
300
+
290
301
  // add first textures in sequence and group for last
291
302
  const lastBinding = bindings[ bindings.length - 1 ];
292
303
  const index = lastBinding && lastBinding.isUniformsGroup ? bindings.length - 1 : bindings.length;
293
304
 
294
305
  if ( shaderStage === 'fragment' ) {
295
306
 
307
+ const sampler = new NodeSampler( `${uniformNode.name}_sampler`, uniformNode.node );
308
+ sampler.setVisibility( gpuShaderStageLib[ shaderStage ] );
309
+
296
310
  bindings.splice( index, 0, sampler, texture );
297
311
 
298
312
  uniformGPU = [ sampler, texture ];
@@ -309,7 +323,7 @@ class WGSLNodeBuilder extends NodeBuilder {
309
323
 
310
324
  const bufferClass = type === 'storageBuffer' ? StorageBuffer : UniformBuffer;
311
325
  const buffer = new bufferClass( 'NodeBuffer_' + node.id, node.value );
312
- //buffer.setVisibility( gpuShaderStageLib[ shaderStage ] );
326
+ buffer.setVisibility( gpuShaderStageLib[ shaderStage ] );
313
327
 
314
328
  // add first textures in sequence and group for last
315
329
  const lastBinding = bindings[ bindings.length - 1 ];
@@ -326,7 +340,7 @@ class WGSLNodeBuilder extends NodeBuilder {
326
340
  if ( uniformsGroup === undefined ) {
327
341
 
328
342
  uniformsGroup = new UniformsGroup( 'nodeUniforms' );
329
- //uniformsGroup.setVisibility( gpuShaderStageLib[ shaderStage ] );
343
+ uniformsGroup.setVisibility( gpuShaderStageLib[ shaderStage ] );
330
344
 
331
345
  this.uniformsGroup[ shaderStage ] = uniformsGroup;
332
346
 
@@ -568,7 +582,17 @@ class WGSLNodeBuilder extends NodeBuilder {
568
582
 
569
583
  if ( shaderStage === 'fragment' ) {
570
584
 
571
- bindingSnippets.push( `@binding( ${index ++} ) @group( 0 ) var ${uniform.name}_sampler : sampler;` );
585
+ const texture = uniform.node.value;
586
+
587
+ if ( texture.isDepthTexture === true && texture.compareFunction !== null ) {
588
+
589
+ bindingSnippets.push( `@binding( ${index ++} ) @group( 0 ) var ${uniform.name}_sampler : sampler_comparison;` );
590
+
591
+ } else {
592
+
593
+ bindingSnippets.push( `@binding( ${index ++} ) @group( 0 ) var ${uniform.name}_sampler : sampler;` );
594
+
595
+ }
572
596
 
573
597
  }
574
598
 
@@ -34,23 +34,31 @@ class WebGPUAttributeUtils {
34
34
  const bufferAttribute = this._getBufferAttribute( attribute );
35
35
 
36
36
  const backend = this.backend;
37
- const device = backend.device;
37
+ const bufferData = backend.get( bufferAttribute );
38
38
 
39
- const array = bufferAttribute.array;
40
- const size = array.byteLength + ( ( 4 - ( array.byteLength % 4 ) ) % 4 ); // ensure 4 byte alignment, see #20441
39
+ let buffer = bufferData.buffer;
40
+
41
+ if ( buffer === undefined ) {
41
42
 
42
- const buffer = device.createBuffer( {
43
- label: bufferAttribute.name,
44
- size: size,
45
- usage: usage,
46
- mappedAtCreation: true
47
- } );
43
+ const device = backend.device;
48
44
 
49
- new array.constructor( buffer.getMappedRange() ).set( array );
45
+ const array = bufferAttribute.array;
46
+ const size = array.byteLength + ( ( 4 - ( array.byteLength % 4 ) ) % 4 ); // ensure 4 byte alignment, see #20441
47
+
48
+ buffer = device.createBuffer( {
49
+ label: bufferAttribute.name,
50
+ size: size,
51
+ usage: usage,
52
+ mappedAtCreation: true
53
+ } );
50
54
 
51
- buffer.unmap();
55
+ new array.constructor( buffer.getMappedRange() ).set( array );
52
56
 
53
- backend.get( attribute ).buffer = buffer;
57
+ buffer.unmap();
58
+
59
+ bufferData.buffer = buffer;
60
+
61
+ }
54
62
 
55
63
  }
56
64
 
@@ -61,7 +69,7 @@ class WebGPUAttributeUtils {
61
69
  const backend = this.backend;
62
70
  const device = backend.device;
63
71
 
64
- const buffer = backend.get( attribute ).buffer;
72
+ const buffer = backend.get( bufferAttribute ).buffer;
65
73
 
66
74
  const array = bufferAttribute.array;
67
75
  const updateRange = bufferAttribute.updateRange;
@@ -93,51 +101,64 @@ class WebGPUAttributeUtils {
93
101
 
94
102
  }
95
103
 
96
- createShaderAttributes( renderObject ) {
104
+ createShaderVertexBuffers( renderObject ) {
97
105
 
98
106
  const attributes = renderObject.getAttributes();
99
- const shaderAttributes = [];
107
+ const vertexBuffers = new Map();
100
108
 
101
109
  for ( let slot = 0; slot < attributes.length; slot ++ ) {
102
110
 
103
111
  const geometryAttribute = attributes[ slot ];
104
112
  const bytesPerElement = geometryAttribute.array.BYTES_PER_ELEMENT;
113
+ const bufferAttribute = this._getBufferAttribute( geometryAttribute );
105
114
 
106
- const format = this._getVertexFormat( geometryAttribute );
115
+ let vertexBufferLayout = vertexBuffers.get( bufferAttribute );
107
116
 
108
- let arrayStride = geometryAttribute.itemSize * bytesPerElement;
109
- let offset = 0;
110
- let stepMode = geometryAttribute.isInstancedBufferAttribute ? GPUInputStepMode.Instance : GPUInputStepMode.Vertex;
117
+ if ( vertexBufferLayout === undefined ) {
111
118
 
112
- if ( geometryAttribute.isInterleavedBufferAttribute === true ) {
119
+ let arrayStride, stepMode;
113
120
 
114
- // @TODO: It can be optimized for "vertexBuffers" on RenderPipeline
121
+ if ( geometryAttribute.isInterleavedBufferAttribute === true ) {
115
122
 
116
- arrayStride = geometryAttribute.data.stride * bytesPerElement;
117
- offset = geometryAttribute.offset * bytesPerElement;
118
- if ( geometryAttribute.data.isInstancedInterleavedBuffer ) stepMode = GPUInputStepMode.Instance;
123
+ arrayStride = geometryAttribute.data.stride * bytesPerElement;
124
+ stepMode = geometryAttribute.data.isInstancedInterleavedBuffer ? GPUInputStepMode.Instance : GPUInputStepMode.Vertex;
125
+
126
+ } else {
127
+
128
+ arrayStride = geometryAttribute.itemSize * bytesPerElement;
129
+ stepMode = geometryAttribute.isInstancedBufferAttribute ? GPUInputStepMode.Instance : GPUInputStepMode.Vertex;
130
+
131
+ }
132
+
133
+ vertexBufferLayout = {
134
+ arrayStride,
135
+ attributes: [],
136
+ stepMode
137
+ };
138
+
139
+ vertexBuffers.set( bufferAttribute, vertexBufferLayout );
119
140
 
120
141
  }
121
142
 
122
- shaderAttributes.push( {
123
- geometryAttribute,
124
- arrayStride,
125
- stepMode,
143
+ const format = this._getVertexFormat( geometryAttribute );
144
+ const offset = ( geometryAttribute.isInterleavedBufferAttribute === true ) ? geometryAttribute.offset * bytesPerElement : 0;
145
+
146
+ vertexBufferLayout.attributes.push( {
147
+ shaderLocation: slot,
126
148
  offset,
127
- format,
128
- slot
149
+ format
129
150
  } );
130
151
 
131
152
  }
132
153
 
133
- return shaderAttributes;
154
+ return Array.from( vertexBuffers.values() );
134
155
 
135
156
  }
136
157
 
137
158
  destroyAttribute( attribute ) {
138
159
 
139
160
  const backend = this.backend;
140
- const data = backend.get( attribute );
161
+ const data = backend.get( this._getBufferAttribute( attribute ) );
141
162
 
142
163
  data.buffer.destroy();
143
164
 
@@ -145,14 +166,12 @@ class WebGPUAttributeUtils {
145
166
 
146
167
  }
147
168
 
148
- async getArrayBuffer( attribute ) {
169
+ async getArrayBufferAsync( attribute ) {
149
170
 
150
171
  const backend = this.backend;
151
172
  const device = backend.device;
152
173
 
153
- const data = backend.get( attribute );
154
-
155
- //const bufferAttribute = this._getBufferAttribute( attribute );
174
+ const data = backend.get( this._getBufferAttribute( attribute ) );
156
175
 
157
176
  const bufferGPU = data.buffer;
158
177
  const size = bufferGPU.size;
@@ -1,5 +1,5 @@
1
1
  import {
2
- GPUTextureAspect, GPUTextureViewDimension
2
+ GPUTextureAspect, GPUTextureViewDimension, GPUBufferBindingType
3
3
  } from './WebGPUConstants.js';
4
4
 
5
5
  class WebGPUBindingUtils {
@@ -10,16 +10,94 @@ class WebGPUBindingUtils {
10
10
 
11
11
  }
12
12
 
13
- createBindings( bindings, pipeline ) {
13
+ createBindingsLayout( bindings ) {
14
+
15
+ const backend = this.backend;
16
+ const device = backend.device;
17
+
18
+ const entries = [];
19
+
20
+ let index = 0;
21
+
22
+ for ( const binding of bindings ) {
23
+
24
+ const bindingGPU = {
25
+ binding: index ++,
26
+ visibility: binding.visibility
27
+ };
28
+
29
+ if ( binding.isUniformBuffer || binding.isStorageBuffer ) {
30
+
31
+ const buffer = {}; // GPUBufferBindingLayout
32
+
33
+ if ( binding.isStorageBuffer ) {
34
+
35
+ buffer.type = GPUBufferBindingType.Storage;
36
+
37
+ }
38
+
39
+ bindingGPU.buffer = buffer;
40
+
41
+ } else if ( binding.isSampler ) {
42
+
43
+ const sampler = {}; // GPUSamplerBindingLayout
44
+
45
+ if ( binding.texture.isDepthTexture ) {
46
+
47
+ if ( binding.texture.compareFunction !== null ) {
48
+
49
+ sampler.type = 'comparison';
50
+
51
+ }
52
+
53
+ }
54
+
55
+ bindingGPU.sampler = sampler;
56
+
57
+ } else if ( binding.isSampledTexture && binding.texture.isVideoTexture ) {
58
+
59
+ bindingGPU.externalTexture = {}; // GPUExternalTextureBindingLayout
60
+
61
+ } else if ( binding.isSampledTexture ) {
62
+
63
+ const texture = {}; // GPUTextureBindingLayout
64
+
65
+ if ( binding.texture.isDepthTexture ) {
66
+
67
+ texture.sampleType = 'depth';
68
+
69
+ }
70
+
71
+ if ( binding.isSampledCubeTexture ) {
72
+
73
+ texture.viewDimension = GPUTextureViewDimension.Cube;
74
+
75
+ }
76
+
77
+ bindingGPU.texture = texture;
78
+
79
+ } else {
80
+
81
+ console.error( 'WebGPUBindingUtils: Unsupported binding "${ binding }".' );
82
+
83
+ }
84
+
85
+ entries.push( bindingGPU );
86
+
87
+ }
88
+
89
+ return device.createBindGroupLayout( { entries } );
90
+
91
+ }
92
+
93
+ createBindings( bindings ) {
14
94
 
15
95
  const backend = this.backend;
16
96
  const bindingsData = backend.get( bindings );
17
97
 
18
98
  // setup (static) binding layout and (dynamic) binding group
19
99
 
20
- const pipelineGPU = backend.get( pipeline ).pipeline;
21
-
22
- const bindLayoutGPU = pipelineGPU.getBindGroupLayout( 0 );
100
+ const bindLayoutGPU = this.createBindingsLayout( bindings );
23
101
  const bindGroupGPU = this.createBindGroup( bindings, bindLayoutGPU );
24
102
 
25
103
  bindingsData.layout = bindLayoutGPU;
@@ -214,12 +214,6 @@ export const GPUAddressMode = {
214
214
  MirrorRepeat: 'mirror-repeat'
215
215
  };
216
216
 
217
- export const GPUSamplerBindingType = {
218
- Filtering: 'filtering',
219
- NonFiltering: 'non-filtering',
220
- Comparison: 'comparison'
221
- };
222
-
223
217
  export const GPUFilterMode = {
224
218
  Linear: 'linear',
225
219
  Nearest: 'nearest'
@@ -228,17 +222,17 @@ export const GPUFilterMode = {
228
222
  export const GPUBlendFactor = {
229
223
  Zero: 'zero',
230
224
  One: 'one',
231
- SrcColor: 'src-color',
232
- OneMinusSrcColor: 'one-minus-src-color',
225
+ Src: 'src',
226
+ OneMinusSrc: 'one-minus-src',
233
227
  SrcAlpha: 'src-alpha',
234
228
  OneMinusSrcAlpha: 'one-minus-src-alpha',
235
- DstColor: 'dst-color',
236
- OneMinusDstColor: 'one-minus-dst-color',
229
+ Dst: 'dst',
230
+ OneMinusDstColor: 'one-minus-dst',
237
231
  DstAlpha: 'dst-alpha',
238
232
  OneMinusDstAlpha: 'one-minus-dst-alpha',
239
233
  SrcAlphaSaturated: 'src-alpha-saturated',
240
- BlendColor: 'blend-color',
241
- OneMinusBlendColor: 'one-minus-blend-color'
234
+ Constant: 'constant',
235
+ OneMinusConstant: 'one-minus-constant'
242
236
  };
243
237
 
244
238
  export const GPUBlendOperation = {
@@ -269,16 +263,24 @@ export const GPUStencilOperation = {
269
263
  DecrementWrap: 'decrement-wrap'
270
264
  };
271
265
 
272
- export const GPUBindingType = {
273
- UniformBuffer: 'uniform-buffer',
274
- StorageBuffer: 'storage-buffer',
275
- ReadonlyStorageBuffer: 'readonly-storage-buffer',
276
- Sampler: 'sampler',
277
- ComparisonSampler: 'comparison-sampler',
278
- SampledTexture: 'sampled-texture',
279
- MultisampledTexture: 'multisampled-texture',
280
- ReadonlyStorageTexture: 'readonly-storage-texture',
281
- WriteonlyStorageTexture: 'writeonly-storage-texture'
266
+ export const GPUBufferBindingType = {
267
+ Uniform: 'uniform',
268
+ Storage: 'storage',
269
+ ReadOnlyStorage: 'read-only-storage'
270
+ };
271
+
272
+ export const GPUSamplerBindingType = {
273
+ Filtering: 'filtering',
274
+ NonFiltering: 'non-filtering',
275
+ Comparison: 'comparison'
276
+ };
277
+
278
+ export const GPUTextureSampleType = {
279
+ Float: 'float',
280
+ UnfilterableFloat: 'unfilterable-float',
281
+ Depth: 'depth',
282
+ SInt: 'sint',
283
+ UInt: 'uint'
282
284
  };
283
285
 
284
286
  export const GPUTextureDimension = {