super-three 0.154.1 → 0.156.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.
- package/build/three.cjs +360 -160
- package/build/three.js +360 -160
- package/build/three.min.js +1 -1
- package/build/three.module.js +355 -161
- package/build/three.module.min.js +1 -1
- package/examples/jsm/controls/OrbitControls.js +155 -25
- package/examples/jsm/csm/CSMShader.js +35 -1
- package/examples/jsm/environments/RoomEnvironment.js +1 -1
- package/examples/jsm/exporters/USDZExporter.js +1 -0
- package/examples/jsm/interactive/SelectionHelper.js +7 -0
- package/examples/jsm/libs/tween.module.js +790 -735
- package/examples/jsm/libs/utif.module.js +1644 -1558
- package/examples/jsm/loaders/DDSLoader.js +46 -3
- package/examples/jsm/loaders/EXRLoader.js +4 -4
- package/examples/jsm/loaders/FBXLoader.js +3 -1
- package/examples/jsm/loaders/GLTFLoader.js +25 -10
- package/examples/jsm/loaders/KTX2Loader.js +128 -79
- package/examples/jsm/loaders/LDrawLoader.js +1 -1
- package/examples/jsm/loaders/LogLuvLoader.js +2 -2
- package/examples/jsm/loaders/MMDLoader.js +10 -7
- package/examples/jsm/loaders/NRRDLoader.js +3 -3
- package/examples/jsm/loaders/PLYLoader.js +1 -1
- package/examples/jsm/loaders/RGBELoader.js +48 -66
- package/examples/jsm/loaders/STLLoader.js +7 -0
- package/examples/jsm/loaders/TGALoader.js +10 -10
- package/examples/jsm/loaders/VRMLLoader.js +1 -1
- package/examples/jsm/misc/GPUComputationRenderer.js +0 -9
- package/examples/jsm/misc/Volume.js +4 -6
- package/examples/jsm/nodes/Nodes.js +8 -6
- package/examples/jsm/nodes/accessors/BufferAttributeNode.js +29 -3
- package/examples/jsm/nodes/accessors/CubeTextureNode.js +20 -3
- package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +15 -4
- package/examples/jsm/nodes/accessors/InstanceNode.js +8 -8
- package/examples/jsm/nodes/accessors/LineMaterialNode.js +31 -0
- package/examples/jsm/nodes/accessors/MaterialNode.js +73 -61
- package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +3 -0
- package/examples/jsm/nodes/accessors/Object3DNode.js +2 -2
- package/examples/jsm/nodes/accessors/SceneNode.js +6 -0
- package/examples/jsm/nodes/accessors/TextureNode.js +54 -9
- package/examples/jsm/nodes/accessors/TextureStoreNode.js +29 -0
- package/examples/jsm/nodes/core/AttributeNode.js +2 -2
- package/examples/jsm/nodes/core/LightingModel.js +7 -9
- package/examples/jsm/nodes/core/Node.js +28 -3
- package/examples/jsm/nodes/core/NodeBuilder.js +94 -12
- package/examples/jsm/nodes/core/NodeUniform.js +1 -1
- package/examples/jsm/nodes/core/OutputStructNode.js +58 -0
- package/examples/jsm/nodes/core/PropertyNode.js +6 -0
- package/examples/jsm/nodes/core/StackNode.js +4 -4
- package/examples/jsm/nodes/core/StructTypeNode.js +24 -0
- package/examples/jsm/nodes/display/BumpMapNode.js +77 -0
- package/examples/jsm/nodes/display/NormalMapNode.js +2 -2
- package/examples/jsm/nodes/display/ViewportNode.js +19 -5
- package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +10 -2
- package/examples/jsm/nodes/functions/BSDF/Schlick_to_F0.js +13 -0
- package/examples/jsm/nodes/functions/PhongLightingModel.js +53 -14
- package/examples/jsm/nodes/functions/PhysicalLightingModel.js +236 -97
- package/examples/jsm/nodes/geometry/RangeNode.js +2 -2
- package/examples/jsm/nodes/gpgpu/ComputeNode.js +13 -0
- package/examples/jsm/nodes/lighting/AONode.js +1 -1
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +58 -20
- package/examples/jsm/nodes/lighting/DirectionalLightNode.js +7 -10
- package/examples/jsm/nodes/lighting/EnvironmentNode.js +22 -12
- package/examples/jsm/nodes/lighting/HemisphereLightNode.js +1 -1
- package/examples/jsm/nodes/lighting/LightingContextNode.js +12 -9
- package/examples/jsm/nodes/lighting/PointLightNode.js +7 -10
- package/examples/jsm/nodes/lighting/SpotLightNode.js +7 -10
- package/examples/jsm/nodes/materials/LineDashedNodeMaterial.js +54 -0
- package/examples/jsm/nodes/materials/Materials.js +2 -0
- package/examples/jsm/nodes/materials/MeshLambertNodeMaterial.js +34 -0
- package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +2 -0
- package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +2 -2
- package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +19 -2
- package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +2 -2
- package/examples/jsm/nodes/materials/NodeMaterial.js +61 -26
- package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +2 -2
- package/examples/jsm/nodes/math/HashNode.js +35 -0
- package/examples/jsm/nodes/shadernode/ShaderNode.js +6 -2
- package/examples/jsm/nodes/utils/SplitNode.js +1 -1
- package/examples/jsm/objects/Reflector.js +1 -9
- package/examples/jsm/objects/Refractor.js +0 -8
- package/examples/jsm/offscreen/scene.js +0 -1
- package/examples/jsm/postprocessing/FilmPass.js +3 -5
- package/examples/jsm/postprocessing/MaskPass.js +4 -1
- package/examples/jsm/postprocessing/OutputPass.js +33 -14
- package/examples/jsm/postprocessing/RenderPass.js +30 -12
- package/examples/jsm/postprocessing/SAOPass.js +23 -98
- package/examples/jsm/postprocessing/SSAOPass.js +10 -30
- package/examples/jsm/postprocessing/UnrealBloomPass.js +21 -17
- package/examples/jsm/renderers/common/Backend.js +11 -8
- package/examples/jsm/renderers/common/Background.js +22 -20
- package/examples/jsm/renderers/common/Binding.js +14 -0
- package/examples/jsm/renderers/common/Bindings.js +7 -10
- package/examples/jsm/renderers/common/Geometries.js +1 -1
- package/examples/jsm/renderers/common/Pipelines.js +96 -47
- package/examples/jsm/renderers/common/RenderContext.js +1 -0
- package/examples/jsm/renderers/common/RenderContexts.js +41 -5
- package/examples/jsm/renderers/common/RenderList.js +12 -4
- package/examples/jsm/renderers/common/RenderObject.js +26 -6
- package/examples/jsm/renderers/common/RenderObjects.js +10 -7
- package/examples/jsm/renderers/common/Renderer.js +82 -42
- package/examples/jsm/renderers/common/SampledTexture.js +2 -1
- package/examples/jsm/renderers/common/Sampler.js +1 -1
- package/examples/jsm/renderers/common/StorageBuffer.js +1 -1
- package/examples/jsm/renderers/common/Textures.js +172 -20
- package/examples/jsm/renderers/common/nodes/NodeSampledTexture.js +2 -2
- package/examples/jsm/renderers/common/nodes/NodeSampler.js +1 -1
- package/examples/jsm/renderers/common/nodes/Nodes.js +58 -13
- package/examples/jsm/renderers/webgl/WebGLBackend.js +607 -0
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +118 -17
- package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +84 -0
- package/examples/jsm/renderers/webgl/utils/WebGLExtensions.js +26 -0
- package/examples/jsm/renderers/webgl/utils/WebGLState.js +529 -0
- package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +199 -0
- package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +242 -0
- package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +340 -0
- package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/WebGLNodeBuilder.js +1 -1
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +320 -84
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +18 -2
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +120 -66
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js +2 -2
- package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +55 -36
- package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +96 -5
- package/examples/jsm/renderers/webgpu/utils/WebGPUConstants.js +24 -22
- package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +117 -139
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +60 -142
- package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +7 -6
- package/examples/jsm/shaders/FilmShader.js +11 -54
- package/examples/jsm/shaders/OutputShader.js +19 -2
- package/examples/jsm/shaders/SAOShader.js +0 -13
- package/examples/jsm/shaders/SSAOShader.js +33 -26
- package/examples/jsm/utils/BufferGeometryUtils.js +13 -4
- package/examples/jsm/webxr/OculusHandPointerModel.js +2 -2
- package/package.json +2 -2
- package/src/Three.js +3 -0
- package/src/animation/PropertyBinding.js +1 -1
- package/src/audio/Audio.js +6 -0
- package/src/cameras/CubeCamera.js +1 -4
- package/src/constants.js +4 -1
- package/src/core/BufferAttribute.js +20 -0
- package/src/core/Object3D.js +2 -15
- package/src/core/RenderTarget.js +122 -0
- package/src/core/UniformsGroup.js +2 -2
- package/src/geometries/CapsuleGeometry.js +1 -1
- package/src/loaders/DataTextureLoader.js +19 -2
- package/src/materials/Material.js +2 -2
- package/src/math/Vector2.js +2 -2
- package/src/math/Vector3.js +3 -3
- package/src/math/Vector4.js +4 -4
- package/src/objects/Line.js +1 -1
- package/src/objects/Mesh.js +1 -1
- package/src/objects/Points.js +1 -1
- package/src/renderers/WebGLMultipleRenderTargets.js +0 -2
- package/src/renderers/WebGLRenderTarget.js +3 -110
- package/src/renderers/WebGLRenderer.js +83 -57
- package/src/renderers/shaders/ShaderChunk/iridescence_fragment.glsl.js +1 -2
- package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +11 -1
- package/src/renderers/shaders/ShaderLib/background.glsl.js +8 -0
- package/src/renderers/webgl/WebGLBackground.js +5 -14
- package/src/renderers/webgl/WebGLGeometries.js +5 -1
- package/src/renderers/webgl/WebGLMaterials.js +1 -1
- package/src/renderers/webgl/WebGLProgram.js +2 -0
- package/src/renderers/webgl/WebGLPrograms.js +19 -3
- package/src/renderers/webgl/WebGLTextures.js +101 -16
- package/src/renderers/webgl/WebGLUtils.js +27 -20
- package/src/textures/CompressedCubeTexture.js +19 -0
- package/src/textures/Texture.js +2 -2
- package/src/utils.js +9 -1
- package/examples/jsm/nodes/functions/BSDF/BRDF_BlinnPhong.js +0 -30
- package/examples/jsm/renderers/common/RenderTarget.js +0 -15
- package/examples/jsm/renderers/common/nodes/NodeRender.js +0 -302
- /package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/SlotNode.js +0 -0
- /package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/WebGLNodes.js +0 -0
|
@@ -54,13 +54,15 @@ class WebGPUBackend extends Backend {
|
|
|
54
54
|
this.context = null;
|
|
55
55
|
this.colorBuffer = null;
|
|
56
56
|
|
|
57
|
-
this.
|
|
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 );
|
|
61
62
|
this.bindingUtils = new WebGPUBindingUtils( this );
|
|
62
63
|
this.pipelineUtils = new WebGPUPipelineUtils( this );
|
|
63
64
|
this.textureUtils = new WebGPUTextureUtils( this );
|
|
65
|
+
this.occludedResolveCache = new Map();
|
|
64
66
|
|
|
65
67
|
}
|
|
66
68
|
|
|
@@ -123,9 +125,9 @@ class WebGPUBackend extends Backend {
|
|
|
123
125
|
|
|
124
126
|
}
|
|
125
127
|
|
|
126
|
-
async
|
|
128
|
+
async getArrayBufferAsync( attribute ) {
|
|
127
129
|
|
|
128
|
-
return await this.attributeUtils.
|
|
130
|
+
return await this.attributeUtils.getArrayBufferAsync( attribute );
|
|
129
131
|
|
|
130
132
|
}
|
|
131
133
|
|
|
@@ -134,6 +136,32 @@ class WebGPUBackend extends Backend {
|
|
|
134
136
|
const renderContextData = this.get( renderContext );
|
|
135
137
|
|
|
136
138
|
const device = this.device;
|
|
139
|
+
const occlusionQueryCount = renderContext.occlusionQueryCount;
|
|
140
|
+
|
|
141
|
+
let occlusionQuerySet;
|
|
142
|
+
|
|
143
|
+
if ( occlusionQueryCount > 0 ) {
|
|
144
|
+
|
|
145
|
+
if ( renderContextData.currentOcclusionQuerySet ) renderContextData.currentOcclusionQuerySet.destroy();
|
|
146
|
+
if ( renderContextData.currentOcclusionQueryBuffer ) renderContextData.currentOcclusionQueryBuffer.destroy();
|
|
147
|
+
|
|
148
|
+
// Get a reference to the array of objects with queries. The renderContextData property
|
|
149
|
+
// can be changed by another render pass before the buffer.mapAsyc() completes.
|
|
150
|
+
renderContextData.currentOcclusionQuerySet = renderContextData.occlusionQuerySet;
|
|
151
|
+
renderContextData.currentOcclusionQueryBuffer = renderContextData.occlusionQueryBuffer;
|
|
152
|
+
renderContextData.currentOcclusionQueryObjects = renderContextData.occlusionQueryObjects;
|
|
153
|
+
|
|
154
|
+
//
|
|
155
|
+
|
|
156
|
+
occlusionQuerySet = device.createQuerySet( { type: 'occlusion', count: occlusionQueryCount } );
|
|
157
|
+
|
|
158
|
+
renderContextData.occlusionQuerySet = occlusionQuerySet;
|
|
159
|
+
renderContextData.occlusionQueryIndex = 0;
|
|
160
|
+
renderContextData.occlusionQueryObjects = new Array( occlusionQueryCount );
|
|
161
|
+
|
|
162
|
+
renderContextData.lastOcclusionObject = null;
|
|
163
|
+
|
|
164
|
+
}
|
|
137
165
|
|
|
138
166
|
const descriptor = {
|
|
139
167
|
colorAttachments: [ {
|
|
@@ -141,7 +169,8 @@ class WebGPUBackend extends Backend {
|
|
|
141
169
|
} ],
|
|
142
170
|
depthStencilAttachment: {
|
|
143
171
|
view: null
|
|
144
|
-
}
|
|
172
|
+
},
|
|
173
|
+
occlusionQuerySet
|
|
145
174
|
};
|
|
146
175
|
|
|
147
176
|
const colorAttachment = descriptor.colorAttachments[ 0 ];
|
|
@@ -149,19 +178,50 @@ class WebGPUBackend extends Backend {
|
|
|
149
178
|
|
|
150
179
|
const antialias = this.parameters.antialias;
|
|
151
180
|
|
|
152
|
-
if ( renderContext.
|
|
181
|
+
if ( renderContext.textures !== null ) {
|
|
153
182
|
|
|
154
|
-
const
|
|
155
|
-
|
|
183
|
+
const textures = renderContext.textures;
|
|
184
|
+
|
|
185
|
+
descriptor.colorAttachments = [];
|
|
186
|
+
|
|
187
|
+
const colorAttachments = descriptor.colorAttachments;
|
|
188
|
+
|
|
189
|
+
for ( let i = 0; i < textures.length; i ++ ) {
|
|
190
|
+
|
|
191
|
+
const textureData = this.get( textures[ i ] );
|
|
192
|
+
|
|
193
|
+
const textureView = textureData.texture.createView( {
|
|
194
|
+
baseMipLevel: 0,
|
|
195
|
+
mipLevelCount: 1,
|
|
196
|
+
baseArrayLayer: renderContext.activeCubeFace,
|
|
197
|
+
dimension: GPUTextureViewDimension.TwoD
|
|
198
|
+
} );
|
|
199
|
+
|
|
200
|
+
let view, resolveTarget;
|
|
201
|
+
|
|
202
|
+
if ( textureData.msaaTexture !== undefined ) {
|
|
203
|
+
|
|
204
|
+
view = textureData.msaaTexture.createView();
|
|
205
|
+
resolveTarget = textureView;
|
|
156
206
|
|
|
157
|
-
|
|
207
|
+
} else {
|
|
158
208
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
209
|
+
view = textureView;
|
|
210
|
+
resolveTarget = undefined;
|
|
211
|
+
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
colorAttachments.push( {
|
|
215
|
+
view,
|
|
216
|
+
resolveTarget,
|
|
217
|
+
loadOp: GPULoadOp.Load,
|
|
218
|
+
storeOp: GPUStoreOp.Store
|
|
219
|
+
|
|
220
|
+
} );
|
|
221
|
+
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const depthTextureData = this.get( renderContext.depthTexture );
|
|
165
225
|
|
|
166
226
|
depthStencilAttachment.view = depthTextureData.texture.createView();
|
|
167
227
|
|
|
@@ -189,16 +249,44 @@ class WebGPUBackend extends Backend {
|
|
|
189
249
|
|
|
190
250
|
}
|
|
191
251
|
|
|
192
|
-
if ( renderContext.
|
|
252
|
+
if ( renderContext.textures !== null ) {
|
|
253
|
+
|
|
254
|
+
const colorAttachments = descriptor.colorAttachments;
|
|
255
|
+
|
|
256
|
+
for ( let i = 0; i < colorAttachments.length; i ++ ) {
|
|
257
|
+
|
|
258
|
+
const colorAttachment = colorAttachments[ i ];
|
|
259
|
+
|
|
260
|
+
if ( renderContext.clearColor ) {
|
|
261
|
+
|
|
262
|
+
colorAttachment.clearValue = renderContext.clearColorValue;
|
|
263
|
+
colorAttachment.loadOp = GPULoadOp.Clear;
|
|
264
|
+
colorAttachment.storeOp = GPUStoreOp.Store;
|
|
265
|
+
|
|
266
|
+
} else {
|
|
267
|
+
|
|
268
|
+
colorAttachment.loadOp = GPULoadOp.Load;
|
|
269
|
+
colorAttachment.storeOp = GPUStoreOp.Store;
|
|
270
|
+
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
}
|
|
193
274
|
|
|
194
|
-
colorAttachment.clearValue = renderContext.clearColorValue;
|
|
195
|
-
colorAttachment.loadOp = GPULoadOp.Clear;
|
|
196
|
-
colorAttachment.storeOp = GPUStoreOp.Store;
|
|
197
275
|
|
|
198
276
|
} else {
|
|
199
277
|
|
|
200
|
-
|
|
201
|
-
|
|
278
|
+
if ( renderContext.clearColor ) {
|
|
279
|
+
|
|
280
|
+
colorAttachment.clearValue = renderContext.clearColorValue;
|
|
281
|
+
colorAttachment.loadOp = GPULoadOp.Clear;
|
|
282
|
+
colorAttachment.storeOp = GPUStoreOp.Store;
|
|
283
|
+
|
|
284
|
+
} else {
|
|
285
|
+
|
|
286
|
+
colorAttachment.loadOp = GPULoadOp.Load;
|
|
287
|
+
colorAttachment.storeOp = GPUStoreOp.Store;
|
|
288
|
+
|
|
289
|
+
}
|
|
202
290
|
|
|
203
291
|
}
|
|
204
292
|
|
|
@@ -248,7 +336,7 @@ class WebGPUBackend extends Backend {
|
|
|
248
336
|
renderContextData.descriptor = descriptor;
|
|
249
337
|
renderContextData.encoder = encoder;
|
|
250
338
|
renderContextData.currentPass = currentPass;
|
|
251
|
-
renderContextData.
|
|
339
|
+
renderContextData.currentSets = { attributes: {} };
|
|
252
340
|
|
|
253
341
|
//
|
|
254
342
|
|
|
@@ -271,16 +359,123 @@ class WebGPUBackend extends Backend {
|
|
|
271
359
|
finishRender( renderContext ) {
|
|
272
360
|
|
|
273
361
|
const renderContextData = this.get( renderContext );
|
|
362
|
+
const occlusionQueryCount = renderContext.occlusionQueryCount;
|
|
363
|
+
|
|
364
|
+
if ( occlusionQueryCount > renderContextData.occlusionQueryIndex ) {
|
|
365
|
+
|
|
366
|
+
renderContextData.currentPass.endOcclusionQuery();
|
|
367
|
+
|
|
368
|
+
}
|
|
274
369
|
|
|
275
370
|
renderContextData.currentPass.end();
|
|
276
371
|
|
|
372
|
+
if ( occlusionQueryCount > 0 ) {
|
|
373
|
+
|
|
374
|
+
const bufferSize = occlusionQueryCount * 8; // 8 byte entries for query results
|
|
375
|
+
|
|
376
|
+
//
|
|
377
|
+
|
|
378
|
+
let queryResolveBuffer = this.occludedResolveCache.get( bufferSize );
|
|
379
|
+
|
|
380
|
+
if ( queryResolveBuffer === undefined ) {
|
|
381
|
+
|
|
382
|
+
queryResolveBuffer = this.device.createBuffer(
|
|
383
|
+
{
|
|
384
|
+
size: bufferSize,
|
|
385
|
+
usage: GPUBufferUsage.QUERY_RESOLVE | GPUBufferUsage.COPY_SRC
|
|
386
|
+
}
|
|
387
|
+
);
|
|
388
|
+
|
|
389
|
+
this.occludedResolveCache.set( bufferSize, queryResolveBuffer );
|
|
390
|
+
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
//
|
|
394
|
+
|
|
395
|
+
const readBuffer = this.device.createBuffer(
|
|
396
|
+
{
|
|
397
|
+
size: bufferSize,
|
|
398
|
+
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ
|
|
399
|
+
}
|
|
400
|
+
);
|
|
401
|
+
|
|
402
|
+
// two buffers required here - WebGPU doesn't allow usage of QUERY_RESOLVE & MAP_READ to be combined
|
|
403
|
+
renderContextData.encoder.resolveQuerySet( renderContextData.occlusionQuerySet, 0, occlusionQueryCount, queryResolveBuffer, 0 );
|
|
404
|
+
renderContextData.encoder.copyBufferToBuffer( queryResolveBuffer, 0, readBuffer, 0, bufferSize );
|
|
405
|
+
|
|
406
|
+
renderContextData.occlusionQueryBuffer = readBuffer;
|
|
407
|
+
|
|
408
|
+
//
|
|
409
|
+
|
|
410
|
+
this.resolveOccludedAsync( renderContext );
|
|
411
|
+
|
|
412
|
+
}
|
|
413
|
+
|
|
277
414
|
this.device.queue.submit( [ renderContextData.encoder.finish() ] );
|
|
278
415
|
|
|
279
416
|
//
|
|
280
417
|
|
|
281
|
-
if ( renderContext.
|
|
418
|
+
if ( renderContext.textures !== null ) {
|
|
419
|
+
|
|
420
|
+
const textures = renderContext.textures;
|
|
421
|
+
|
|
422
|
+
for ( let i = 0; i < textures.length; i ++ ) {
|
|
423
|
+
|
|
424
|
+
const texture = textures[ i ];
|
|
425
|
+
|
|
426
|
+
if ( texture.generateMipmaps === true ) {
|
|
282
427
|
|
|
283
|
-
|
|
428
|
+
this.textureUtils.generateMipmaps( texture );
|
|
429
|
+
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
isOccluded( renderContext, object ) {
|
|
439
|
+
|
|
440
|
+
const renderContextData = this.get( renderContext );
|
|
441
|
+
|
|
442
|
+
return renderContextData.occluded && renderContextData.occluded.has( object );
|
|
443
|
+
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
async resolveOccludedAsync( renderContext ) {
|
|
447
|
+
|
|
448
|
+
const renderContextData = this.get( renderContext );
|
|
449
|
+
|
|
450
|
+
// handle occlusion query results
|
|
451
|
+
|
|
452
|
+
const { currentOcclusionQueryBuffer, currentOcclusionQueryObjects } = renderContextData;
|
|
453
|
+
|
|
454
|
+
if ( currentOcclusionQueryBuffer && currentOcclusionQueryObjects ) {
|
|
455
|
+
|
|
456
|
+
const occluded = new WeakSet();
|
|
457
|
+
|
|
458
|
+
renderContextData.currentOcclusionQueryObjects = null;
|
|
459
|
+
renderContextData.currentOcclusionQueryBuffer = null;
|
|
460
|
+
|
|
461
|
+
await currentOcclusionQueryBuffer.mapAsync( GPUMapMode.READ );
|
|
462
|
+
|
|
463
|
+
const buffer = currentOcclusionQueryBuffer.getMappedRange();
|
|
464
|
+
const results = new BigUint64Array( buffer );
|
|
465
|
+
|
|
466
|
+
for ( let i = 0; i < currentOcclusionQueryObjects.length; i++ ) {
|
|
467
|
+
|
|
468
|
+
if ( results[ i ] !== 0n ) {
|
|
469
|
+
|
|
470
|
+
occluded.add( currentOcclusionQueryObjects[ i ], true );
|
|
471
|
+
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
currentOcclusionQueryBuffer.destroy();
|
|
477
|
+
|
|
478
|
+
renderContextData.occluded = occluded;
|
|
284
479
|
|
|
285
480
|
}
|
|
286
481
|
|
|
@@ -306,6 +501,7 @@ class WebGPUBackend extends Backend {
|
|
|
306
501
|
stencil = stencil && renderContext.stencil;
|
|
307
502
|
|
|
308
503
|
const colorAttachment = descriptor.colorAttachments[ 0 ];
|
|
504
|
+
const depthStencilAttachment = descriptor.depthStencilAttachment;
|
|
309
505
|
|
|
310
506
|
const antialias = this.parameters.antialias;
|
|
311
507
|
|
|
@@ -329,19 +525,31 @@ class WebGPUBackend extends Backend {
|
|
|
329
525
|
colorAttachment.loadOp = GPULoadOp.Clear;
|
|
330
526
|
colorAttachment.clearValue = renderContext.clearColorValue;
|
|
331
527
|
|
|
528
|
+
} else {
|
|
529
|
+
|
|
530
|
+
colorAttachment.loadOp = GPULoadOp.Load;
|
|
531
|
+
|
|
332
532
|
}
|
|
333
533
|
|
|
334
534
|
if ( depth ) {
|
|
335
535
|
|
|
336
|
-
|
|
337
|
-
|
|
536
|
+
depthStencilAttachment.depthLoadOp = GPULoadOp.Clear;
|
|
537
|
+
depthStencilAttachment.depthClearValue = renderContext.clearDepthValue;
|
|
538
|
+
|
|
539
|
+
} else {
|
|
540
|
+
|
|
541
|
+
depthStencilAttachment.depthLoadOp = GPULoadOp.Load;
|
|
338
542
|
|
|
339
543
|
}
|
|
340
544
|
|
|
341
545
|
if ( stencil ) {
|
|
342
546
|
|
|
343
|
-
|
|
344
|
-
|
|
547
|
+
depthStencilAttachment.stencilLoadOp = GPULoadOp.Clear;
|
|
548
|
+
depthStencilAttachment.stencilClearValue = renderContext.clearStencilValue;
|
|
549
|
+
|
|
550
|
+
} else {
|
|
551
|
+
|
|
552
|
+
depthStencilAttachment.stencilLoadOp = GPULoadOp.Load;
|
|
345
553
|
|
|
346
554
|
}
|
|
347
555
|
|
|
@@ -401,12 +609,19 @@ class WebGPUBackend extends Backend {
|
|
|
401
609
|
const bindingsData = this.get( renderObject.getBindings() );
|
|
402
610
|
const contextData = this.get( context );
|
|
403
611
|
const pipelineGPU = this.get( pipeline ).pipeline;
|
|
404
|
-
const
|
|
612
|
+
const currentSets = contextData.currentSets;
|
|
405
613
|
|
|
406
614
|
// pipeline
|
|
407
615
|
|
|
408
616
|
const passEncoderGPU = contextData.currentPass;
|
|
409
|
-
|
|
617
|
+
|
|
618
|
+
if ( currentSets.pipeline !== pipelineGPU ) {
|
|
619
|
+
|
|
620
|
+
passEncoderGPU.setPipeline( pipelineGPU );
|
|
621
|
+
|
|
622
|
+
currentSets.pipeline = pipelineGPU;
|
|
623
|
+
|
|
624
|
+
}
|
|
410
625
|
|
|
411
626
|
// bind group
|
|
412
627
|
|
|
@@ -423,14 +638,14 @@ class WebGPUBackend extends Backend {
|
|
|
423
638
|
|
|
424
639
|
if ( hasIndex === true ) {
|
|
425
640
|
|
|
426
|
-
if (
|
|
427
|
-
|
|
641
|
+
if ( currentSets.index !== index ) {
|
|
642
|
+
|
|
428
643
|
const buffer = this.get( index ).buffer;
|
|
429
644
|
const indexFormat = ( index.array instanceof Uint16Array ) ? GPUIndexFormat.Uint16 : GPUIndexFormat.Uint32;
|
|
430
645
|
|
|
431
646
|
passEncoderGPU.setIndexBuffer( buffer, indexFormat );
|
|
432
647
|
|
|
433
|
-
|
|
648
|
+
currentSets.index = index;
|
|
434
649
|
|
|
435
650
|
}
|
|
436
651
|
|
|
@@ -438,18 +653,46 @@ class WebGPUBackend extends Backend {
|
|
|
438
653
|
|
|
439
654
|
// vertex buffers
|
|
440
655
|
|
|
441
|
-
const
|
|
656
|
+
const vertexBuffers = renderObject.getVertexBuffers();
|
|
442
657
|
|
|
443
|
-
for ( let i = 0, l =
|
|
658
|
+
for ( let i = 0, l = vertexBuffers.length; i < l; i ++ ) {
|
|
444
659
|
|
|
445
|
-
const
|
|
660
|
+
const vertexBuffer = vertexBuffers[ i ];
|
|
446
661
|
|
|
447
|
-
if (
|
|
662
|
+
if ( currentSets.attributes[ i ] !== vertexBuffer ) {
|
|
448
663
|
|
|
449
|
-
const buffer = this.get(
|
|
664
|
+
const buffer = this.get( vertexBuffer ).buffer;
|
|
450
665
|
passEncoderGPU.setVertexBuffer( i, buffer );
|
|
451
666
|
|
|
452
|
-
|
|
667
|
+
currentSets.attributes[ i ] = vertexBuffer;
|
|
668
|
+
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
// occlusion queries - handle multiple consecutive draw calls for an object
|
|
674
|
+
|
|
675
|
+
if ( contextData.occlusionQuerySet !== undefined ) {
|
|
676
|
+
|
|
677
|
+
const lastObject = contextData.lastOcclusionObject;
|
|
678
|
+
|
|
679
|
+
if ( lastObject !== object ) {
|
|
680
|
+
|
|
681
|
+
if ( lastObject !== null && lastObject.occlusionTest === true ) {
|
|
682
|
+
|
|
683
|
+
passEncoderGPU.endOcclusionQuery();
|
|
684
|
+
contextData.occlusionQueryIndex ++;
|
|
685
|
+
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
if ( object.occlusionTest === true ) {
|
|
689
|
+
|
|
690
|
+
passEncoderGPU.beginOcclusionQuery( contextData.occlusionQueryIndex );
|
|
691
|
+
contextData.occlusionQueryObjects[ contextData.occlusionQueryIndex ] = object;
|
|
692
|
+
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
contextData.lastOcclusionObject = object;
|
|
453
696
|
|
|
454
697
|
}
|
|
455
698
|
|
|
@@ -461,6 +704,7 @@ class WebGPUBackend extends Backend {
|
|
|
461
704
|
const firstVertex = drawRange.start;
|
|
462
705
|
|
|
463
706
|
const instanceCount = this.getInstanceCount( renderObject );
|
|
707
|
+
if ( instanceCount === 0 ) return;
|
|
464
708
|
|
|
465
709
|
if ( hasIndex === true ) {
|
|
466
710
|
|
|
@@ -554,15 +798,21 @@ class WebGPUBackend extends Backend {
|
|
|
554
798
|
|
|
555
799
|
}
|
|
556
800
|
|
|
557
|
-
createTexture( texture ) {
|
|
801
|
+
createTexture( texture, options ) {
|
|
802
|
+
|
|
803
|
+
this.textureUtils.createTexture( texture, options );
|
|
804
|
+
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
updateTexture( texture, options ) {
|
|
558
808
|
|
|
559
|
-
this.textureUtils.
|
|
809
|
+
this.textureUtils.updateTexture( texture, options );
|
|
560
810
|
|
|
561
811
|
}
|
|
562
812
|
|
|
563
|
-
|
|
813
|
+
generateMipmaps( texture ) {
|
|
564
814
|
|
|
565
|
-
this.textureUtils.
|
|
815
|
+
this.textureUtils.generateMipmaps( texture );
|
|
566
816
|
|
|
567
817
|
}
|
|
568
818
|
|
|
@@ -613,23 +863,23 @@ class WebGPUBackend extends Backend {
|
|
|
613
863
|
|
|
614
864
|
}
|
|
615
865
|
|
|
616
|
-
createComputePipeline( computePipeline ) {
|
|
866
|
+
createComputePipeline( computePipeline, bindings ) {
|
|
617
867
|
|
|
618
|
-
this.pipelineUtils.createComputePipeline( computePipeline );
|
|
868
|
+
this.pipelineUtils.createComputePipeline( computePipeline, bindings );
|
|
619
869
|
|
|
620
870
|
}
|
|
621
871
|
|
|
622
872
|
// bindings
|
|
623
873
|
|
|
624
|
-
createBindings( bindings
|
|
874
|
+
createBindings( bindings ) {
|
|
625
875
|
|
|
626
|
-
this.bindingUtils.createBindings( bindings
|
|
876
|
+
this.bindingUtils.createBindings( bindings );
|
|
627
877
|
|
|
628
878
|
}
|
|
629
879
|
|
|
630
|
-
updateBindings( bindings
|
|
880
|
+
updateBindings( bindings ) {
|
|
631
881
|
|
|
632
|
-
this.bindingUtils.createBindings( bindings
|
|
882
|
+
this.bindingUtils.createBindings( bindings );
|
|
633
883
|
|
|
634
884
|
}
|
|
635
885
|
|
|
@@ -745,7 +995,7 @@ class WebGPUBackend extends Backend {
|
|
|
745
995
|
if ( renderContext.stencil ) descriptor.depthStencilAttachment.stencilLoadOp = GPULoadOp.Load;
|
|
746
996
|
|
|
747
997
|
renderContextData.currentPass = encoder.beginRenderPass( descriptor );
|
|
748
|
-
renderContextData.
|
|
998
|
+
renderContextData.currentSets = { attributes: {} };
|
|
749
999
|
|
|
750
1000
|
}
|
|
751
1001
|
|
|
@@ -753,60 +1003,46 @@ class WebGPUBackend extends Backend {
|
|
|
753
1003
|
|
|
754
1004
|
_getDepthBufferGPU( renderContext ) {
|
|
755
1005
|
|
|
756
|
-
const { depthBuffers } = this;
|
|
757
1006
|
const { width, height } = this.getDrawingBufferSize();
|
|
758
1007
|
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
if ( depthTexture !== undefined && depthTexture.image.width === width && depthTexture.image.height === height ) {
|
|
762
|
-
|
|
763
|
-
return this.get( depthTexture ).texture;
|
|
764
|
-
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
this._destroyDepthBufferGPU( renderContext );
|
|
1008
|
+
const depthTexture = this.defaultDepthTexture;
|
|
1009
|
+
const depthTextureGPU = this.get( depthTexture ).texture;
|
|
768
1010
|
|
|
769
|
-
|
|
770
|
-
depthTexture.name = 'depthBuffer';
|
|
1011
|
+
let format, type;
|
|
771
1012
|
|
|
772
|
-
if ( renderContext.stencil
|
|
1013
|
+
if ( renderContext.stencil ) {
|
|
773
1014
|
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
depthTexture.type = UnsignedInt248Type;
|
|
1015
|
+
format = DepthStencilFormat;
|
|
1016
|
+
type = UnsignedInt248Type;
|
|
777
1017
|
|
|
778
1018
|
} else if ( renderContext.depth ) {
|
|
779
1019
|
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
depthTexture.type = UnsignedIntType;
|
|
1020
|
+
format = DepthFormat;
|
|
1021
|
+
type = UnsignedIntType;
|
|
783
1022
|
|
|
784
1023
|
}
|
|
785
1024
|
|
|
786
|
-
|
|
787
|
-
depthTexture.image.height = height;
|
|
788
|
-
|
|
789
|
-
this.textureUtils.createTexture( depthTexture, { sampleCount: this.parameters.sampleCount } );
|
|
790
|
-
|
|
791
|
-
depthBuffers.set( renderContext, depthTexture );
|
|
792
|
-
|
|
793
|
-
return this.get( depthTexture ).texture;
|
|
1025
|
+
if ( depthTextureGPU !== undefined ) {
|
|
794
1026
|
|
|
795
|
-
|
|
1027
|
+
if ( depthTexture.image.width === width && depthTexture.image.height === height && depthTexture.format === format && depthTexture.type === type ) {
|
|
796
1028
|
|
|
797
|
-
|
|
1029
|
+
return depthTextureGPU;
|
|
798
1030
|
|
|
799
|
-
|
|
1031
|
+
}
|
|
800
1032
|
|
|
801
|
-
|
|
1033
|
+
this.textureUtils.destroyTexture( depthTexture );
|
|
802
1034
|
|
|
803
|
-
|
|
1035
|
+
}
|
|
804
1036
|
|
|
805
|
-
|
|
1037
|
+
depthTexture.name = 'depthBuffer';
|
|
1038
|
+
depthTexture.format = format;
|
|
1039
|
+
depthTexture.type = type;
|
|
1040
|
+
depthTexture.image.width = width;
|
|
1041
|
+
depthTexture.image.height = height;
|
|
806
1042
|
|
|
807
|
-
|
|
1043
|
+
this.textureUtils.createTexture( depthTexture, { sampleCount: this.parameters.sampleCount, width, height } );
|
|
808
1044
|
|
|
809
|
-
|
|
1045
|
+
return this.get( depthTexture ).texture;
|
|
810
1046
|
|
|
811
1047
|
}
|
|
812
1048
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import Renderer from '../common/Renderer.js';
|
|
2
|
+
import WebGLBackend from '../webgl/WebGLBackend.js';
|
|
2
3
|
import WebGPUBackend from './WebGPUBackend.js';
|
|
4
|
+
import WebGPU from '../../capabilities/WebGPU.js';
|
|
3
5
|
/*
|
|
4
6
|
const debugHandler = {
|
|
5
7
|
|
|
@@ -18,9 +20,23 @@ class WebGPURenderer extends Renderer {
|
|
|
18
20
|
|
|
19
21
|
constructor( parameters = {} ) {
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
//const backend = new Proxy( new WebGPUBackend( parameters ), debugHandler );
|
|
23
|
+
let BackendClass;
|
|
23
24
|
|
|
25
|
+
if ( WebGPU.isAvailable() ) {
|
|
26
|
+
|
|
27
|
+
BackendClass = WebGPUBackend;
|
|
28
|
+
|
|
29
|
+
} else {
|
|
30
|
+
|
|
31
|
+
BackendClass = WebGLBackend;
|
|
32
|
+
|
|
33
|
+
console.warn( 'THREE.WebGPURenderer: WebGPU is not available, running under WebGL2 backend.' );
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const backend = new BackendClass( parameters );
|
|
38
|
+
|
|
39
|
+
//super( new Proxy( backend, debugHandler ) );
|
|
24
40
|
super( backend );
|
|
25
41
|
|
|
26
42
|
this.isWebGPURenderer = true;
|