super-three 0.169.0 → 0.170.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/three.cjs +989 -1131
- package/build/three.module.js +990 -1128
- package/build/three.module.min.js +1 -1
- package/build/three.webgpu.js +8398 -9842
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +8398 -9842
- package/build/three.webgpu.nodes.min.js +1 -1
- package/examples/jsm/Addons.js +3 -3
- package/examples/jsm/animation/MMDAnimationHelper.js +2 -0
- package/examples/jsm/animation/MMDPhysics.js +2 -0
- package/examples/jsm/controls/TransformControls.js +22 -6
- package/examples/jsm/csm/CSM.js +2 -2
- package/examples/jsm/csm/CSMFrustum.js +7 -4
- package/examples/jsm/csm/CSMHelper.js +2 -0
- package/examples/jsm/csm/CSMShadowNode.js +435 -0
- package/examples/jsm/curves/NURBSCurve.js +34 -3
- package/examples/jsm/exporters/GLTFExporter.js +138 -71
- package/examples/jsm/exporters/KTX2Exporter.js +35 -12
- package/examples/jsm/exporters/MMDExporter.js +6 -0
- package/examples/jsm/exporters/USDZExporter.js +21 -3
- package/examples/jsm/geometries/DecalGeometry.js +65 -20
- package/examples/jsm/geometries/InstancedPointsGeometry.js +2 -0
- package/examples/jsm/helpers/TextureHelperGPU.js +175 -0
- package/examples/jsm/interactive/HTMLMesh.js +1 -0
- package/examples/jsm/lighting/TiledLighting.js +18 -0
- package/examples/jsm/lights/RectAreaLightTexturesLib.js +1 -1
- package/examples/jsm/lines/LineMaterial.js +7 -2
- package/examples/jsm/lines/LineSegmentsGeometry.js +2 -0
- package/examples/jsm/lines/webgpu/LineSegments2.js +0 -15
- package/examples/jsm/lines/webgpu/Wireframe.js +56 -0
- package/examples/jsm/loaders/3DMLoader.js +1 -0
- package/examples/jsm/loaders/3MFLoader.js +91 -0
- package/examples/jsm/loaders/FBXLoader.js +12 -2
- package/examples/jsm/loaders/GLTFLoader.js +2 -0
- package/examples/jsm/loaders/KTX2Loader.js +140 -49
- package/examples/jsm/loaders/LDrawLoader.js +22 -136
- package/examples/jsm/loaders/LottieLoader.js +1 -0
- package/examples/jsm/loaders/MMDLoader.js +9 -2
- package/examples/jsm/materials/LDrawConditionalLineMaterial.js +143 -0
- package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +114 -0
- package/examples/jsm/materials/MeshGouraudMaterial.js +6 -2
- package/examples/jsm/math/ColorSpaces.js +76 -0
- package/examples/jsm/misc/ProgressiveLightMap.js +52 -40
- package/examples/jsm/misc/ProgressiveLightMapGPU.js +293 -0
- package/examples/jsm/misc/VolumeSlice.js +1 -0
- package/examples/jsm/objects/WaterMesh.js +8 -8
- package/examples/jsm/postprocessing/AfterimagePass.js +14 -3
- package/examples/jsm/postprocessing/SSRPass.js +6 -0
- package/examples/jsm/renderers/CSS2DRenderer.js +6 -3
- package/examples/jsm/renderers/CSS3DRenderer.js +7 -4
- package/examples/jsm/shaders/FXAAShader.js +225 -224
- package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
- package/{src/nodes → examples/jsm/tsl}/display/AfterImageNode.js +17 -20
- package/{src/nodes → examples/jsm/tsl}/display/AnaglyphPassNode.js +2 -6
- package/{src/nodes → examples/jsm/tsl}/display/AnamorphicNode.js +12 -18
- package/{src/nodes → examples/jsm/tsl}/display/BleachBypass.js +1 -3
- package/{src/nodes → examples/jsm/tsl}/display/BloomNode.js +11 -40
- package/{src/nodes → examples/jsm/tsl}/display/DenoiseNode.js +18 -41
- package/{src/nodes → examples/jsm/tsl}/display/DepthOfFieldNode.js +2 -8
- package/{src/nodes → examples/jsm/tsl}/display/DotScreenNode.js +2 -9
- package/examples/jsm/tsl/display/FXAANode.js +316 -0
- package/{src/nodes → examples/jsm/tsl}/display/FilmNode.js +2 -6
- package/{src/nodes → examples/jsm/tsl}/display/GTAONode.js +30 -70
- package/{src/nodes → examples/jsm/tsl}/display/GaussianBlurNode.js +74 -36
- package/examples/jsm/tsl/display/LensflareNode.js +161 -0
- package/{src/nodes → examples/jsm/tsl}/display/Lut3DNode.js +1 -4
- package/{src/nodes → examples/jsm/tsl}/display/MotionBlur.js +2 -3
- package/examples/jsm/tsl/display/OutlineNode.js +434 -0
- package/{src/nodes → examples/jsm/tsl}/display/ParallaxBarrierPassNode.js +1 -5
- package/{src/nodes → examples/jsm/tsl}/display/PixelationPassNode.js +3 -15
- package/{src/nodes → examples/jsm/tsl}/display/RGBShiftNode.js +1 -6
- package/examples/jsm/tsl/display/SMAANode.js +620 -0
- package/{src/nodes → examples/jsm/tsl}/display/SSAAPassNode.js +10 -25
- package/examples/jsm/tsl/display/SSRNode.js +343 -0
- package/{src/nodes → examples/jsm/tsl}/display/Sepia.js +1 -2
- package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +3 -11
- package/{src/nodes → examples/jsm/tsl}/display/StereoCompositePassNode.js +9 -11
- package/{src/nodes → examples/jsm/tsl}/display/StereoPassNode.js +10 -11
- package/examples/jsm/tsl/display/TRAAPassNode.js +355 -0
- package/{src/nodes → examples/jsm/tsl}/display/TransitionNode.js +1 -6
- package/examples/jsm/tsl/display/hashBlur.js +24 -0
- package/examples/jsm/tsl/lighting/TiledLightsNode.js +392 -0
- package/examples/jsm/utils/{TextureUtilsGPU.js → WebGPUTextureUtils.js} +2 -1
- package/examples/jsm/webxr/OculusHandPointerModel.js +21 -21
- package/examples/jsm/webxr/Text2D.js +6 -6
- package/package.json +2 -2
- package/src/Three.WebGPU.Nodes.js +4 -0
- package/src/Three.WebGPU.js +4 -0
- package/src/constants.js +1 -6
- package/src/core/BufferGeometry.js +44 -6
- package/src/geometries/CylinderGeometry.js +2 -2
- package/src/materials/LineBasicMaterial.js +6 -2
- package/src/materials/LineDashedMaterial.js +6 -2
- package/src/materials/Material.js +14 -1
- package/src/materials/MeshBasicMaterial.js +6 -2
- package/src/materials/MeshDepthMaterial.js +6 -2
- package/src/materials/MeshDistanceMaterial.js +6 -2
- package/src/materials/MeshLambertMaterial.js +6 -2
- package/src/materials/MeshMatcapMaterial.js +6 -2
- package/src/materials/MeshNormalMaterial.js +6 -2
- package/src/materials/MeshPhongMaterial.js +6 -2
- package/src/materials/MeshPhysicalMaterial.js +6 -2
- package/src/materials/MeshStandardMaterial.js +6 -2
- package/src/materials/MeshToonMaterial.js +6 -2
- package/src/materials/PointsMaterial.js +6 -2
- package/src/materials/RawShaderMaterial.js +6 -2
- package/src/materials/ShaderMaterial.js +6 -2
- package/src/materials/ShadowMaterial.js +6 -2
- package/src/materials/SpriteMaterial.js +6 -2
- package/src/materials/nodes/NodeMaterial.js +31 -9
- package/src/materials/nodes/SpriteNodeMaterial.js +11 -2
- package/src/materials/nodes/manager/NodeMaterialObserver.js +111 -2
- package/src/math/ColorManagement.js +118 -85
- package/src/math/Vector4.js +11 -0
- package/src/nodes/Nodes.js +1 -21
- package/src/nodes/TSL.js +6 -24
- package/src/nodes/accessors/Camera.js +0 -1
- package/src/nodes/accessors/SceneNode.js +35 -1
- package/src/nodes/accessors/StorageBufferNode.js +32 -10
- package/src/nodes/accessors/VelocityNode.js +13 -3
- package/src/nodes/code/FunctionCallNode.js +16 -5
- package/src/nodes/code/ScriptableNode.js +4 -4
- package/src/nodes/core/Node.js +1 -0
- package/src/nodes/core/NodeBuilder.js +29 -5
- package/src/nodes/core/VarNode.js +15 -3
- package/src/nodes/display/ColorAdjustment.js +53 -4
- package/src/nodes/display/ColorSpaceFunctions.js +5 -5
- package/src/nodes/display/ColorSpaceNode.js +27 -39
- package/src/nodes/display/PassNode.js +6 -4
- package/src/nodes/display/ToneMappingNode.js +1 -1
- package/src/nodes/display/ViewportDepthNode.js +33 -1
- package/src/nodes/functions/PhysicalLightingModel.js +21 -15
- package/src/nodes/functions/material/getAlphaHashThreshold.js +64 -0
- package/src/nodes/functions/material/getGeometryRoughness.js +8 -2
- package/src/nodes/functions/material/getParallaxCorrectNormal.js +22 -0
- package/src/nodes/gpgpu/ComputeNode.js +9 -1
- package/src/nodes/lighting/AnalyticLightNode.js +12 -416
- package/src/nodes/lighting/LightsNode.js +24 -12
- package/src/nodes/lighting/PointLightNode.js +36 -26
- package/src/nodes/lighting/RectAreaLightNode.js +3 -0
- package/src/nodes/lighting/ShadowNode.js +484 -0
- package/src/nodes/utils/LoopNode.js +2 -2
- package/src/nodes/utils/Oscillators.js +6 -0
- package/src/nodes/utils/PostProcessingUtils.js +89 -0
- package/src/nodes/utils/ReflectorNode.js +101 -15
- package/src/nodes/utils/Timer.js +29 -0
- package/src/objects/BatchedMesh.js +458 -241
- package/src/renderers/WebGLRenderer.js +121 -126
- package/src/renderers/common/Attributes.js +4 -0
- package/src/renderers/common/Backend.js +2 -0
- package/src/renderers/common/Background.js +14 -4
- package/src/renderers/common/Bindings.js +3 -2
- package/src/renderers/common/Constants.js +2 -1
- package/src/renderers/common/Geometries.js +20 -0
- package/src/renderers/common/IndirectStorageBufferAttribute.js +15 -0
- package/src/renderers/common/Lighting.js +45 -0
- package/src/renderers/common/PostProcessingUtils.js +86 -0
- package/src/renderers/common/RenderList.js +39 -11
- package/src/renderers/common/RenderLists.js +4 -2
- package/src/renderers/common/RenderObject.js +18 -1
- package/src/renderers/common/Renderer.js +165 -26
- package/src/renderers/common/Textures.js +30 -14
- package/src/renderers/common/nodes/NodeLibrary.js +1 -14
- package/src/renderers/common/nodes/Nodes.js +2 -2
- package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
- package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
- package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
- package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
- package/src/renderers/webgl/WebGLCapabilities.js +0 -7
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
- package/src/renderers/webgl/WebGLProgram.js +24 -28
- package/src/renderers/webgl/WebGLPrograms.js +5 -2
- package/src/renderers/webgl/WebGLState.js +37 -1
- package/src/renderers/webgl/WebGLTextures.js +29 -12
- package/src/renderers/webgl-fallback/WebGLBackend.js +98 -31
- package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +2 -7
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +33 -8
- package/src/renderers/webgpu/WebGPUBackend.js +105 -25
- package/src/renderers/webgpu/WebGPURenderer.Nodes.js +1 -1
- package/src/renderers/webgpu/WebGPURenderer.js +1 -1
- package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +0 -8
- package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +0 -8
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +10 -20
- package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +12 -4
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +29 -9
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +24 -6
- package/src/renderers/webgpu/utils/WebGPUUtils.js +0 -1
- package/src/renderers/webxr/WebXRManager.js +4 -4
- package/examples/jsm/cameras/CinematicCamera.js +0 -208
- package/src/nodes/display/FXAANode.js +0 -332
- package/src/nodes/utils/OscNode.js +0 -85
- package/src/nodes/utils/TimerNode.js +0 -97
- package/src/renderers/webvr/WebVRManager.js +0 -495
- package/src/renderers/webvr/WebVRUtils.js +0 -66
- /package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +0 -0
|
@@ -36,6 +36,25 @@ class WebGLBackend extends Backend {
|
|
|
36
36
|
|
|
37
37
|
const glContext = ( parameters.context !== undefined ) ? parameters.context : renderer.domElement.getContext( 'webgl2' );
|
|
38
38
|
|
|
39
|
+
function onContextLost( event ) {
|
|
40
|
+
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
|
|
43
|
+
const contextLossInfo = {
|
|
44
|
+
api: 'WebGL',
|
|
45
|
+
message: event.statusMessage || 'Unknown reason',
|
|
46
|
+
reason: null,
|
|
47
|
+
originalEvent: event
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
renderer.onDeviceLost( contextLossInfo );
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
this._onContextLost = onContextLost;
|
|
55
|
+
|
|
56
|
+
renderer.domElement.addEventListener( 'webglcontextlost', onContextLost, false );
|
|
57
|
+
|
|
39
58
|
this.gl = glContext;
|
|
40
59
|
|
|
41
60
|
this.extensions = new WebGLExtensions( this );
|
|
@@ -63,6 +82,8 @@ class WebGLBackend extends Backend {
|
|
|
63
82
|
this.disjoint = this.extensions.get( 'EXT_disjoint_timer_query_webgl2' );
|
|
64
83
|
this.parallel = this.extensions.get( 'KHR_parallel_shader_compile' );
|
|
65
84
|
|
|
85
|
+
this._knownBindings = new WeakSet();
|
|
86
|
+
|
|
66
87
|
this._currentContext = null;
|
|
67
88
|
|
|
68
89
|
}
|
|
@@ -79,6 +100,11 @@ class WebGLBackend extends Backend {
|
|
|
79
100
|
|
|
80
101
|
}
|
|
81
102
|
|
|
103
|
+
async waitForGPU() {
|
|
104
|
+
|
|
105
|
+
await this.utils._clientWaitAsync();
|
|
106
|
+
|
|
107
|
+
}
|
|
82
108
|
|
|
83
109
|
initTimestampQuery( renderContext ) {
|
|
84
110
|
|
|
@@ -433,9 +459,17 @@ class WebGLBackend extends Backend {
|
|
|
433
459
|
|
|
434
460
|
if ( descriptor === null ) {
|
|
435
461
|
|
|
462
|
+
const clearColor = this.getClearColor();
|
|
463
|
+
|
|
464
|
+
// premultiply alpha
|
|
465
|
+
|
|
466
|
+
clearColor.r *= clearColor.a;
|
|
467
|
+
clearColor.g *= clearColor.a;
|
|
468
|
+
clearColor.b *= clearColor.a;
|
|
469
|
+
|
|
436
470
|
descriptor = {
|
|
437
471
|
textures: null,
|
|
438
|
-
clearColorValue:
|
|
472
|
+
clearColorValue: clearColor
|
|
439
473
|
};
|
|
440
474
|
|
|
441
475
|
}
|
|
@@ -450,13 +484,23 @@ class WebGLBackend extends Backend {
|
|
|
450
484
|
|
|
451
485
|
if ( clear !== 0 ) {
|
|
452
486
|
|
|
453
|
-
|
|
487
|
+
let clearColor;
|
|
454
488
|
|
|
455
|
-
|
|
489
|
+
if ( descriptor.clearColorValue ) {
|
|
456
490
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
491
|
+
clearColor = descriptor.clearColorValue;
|
|
492
|
+
|
|
493
|
+
} else {
|
|
494
|
+
|
|
495
|
+
clearColor = this.getClearColor();
|
|
496
|
+
|
|
497
|
+
// premultiply alpha
|
|
498
|
+
|
|
499
|
+
clearColor.r *= clearColor.a;
|
|
500
|
+
clearColor.g *= clearColor.a;
|
|
501
|
+
clearColor.b *= clearColor.a;
|
|
502
|
+
|
|
503
|
+
}
|
|
460
504
|
|
|
461
505
|
if ( depth ) this.state.setDepthMask( true );
|
|
462
506
|
|
|
@@ -587,6 +631,12 @@ class WebGLBackend extends Backend {
|
|
|
587
631
|
|
|
588
632
|
this.prepareTimestampBuffer( computeGroup );
|
|
589
633
|
|
|
634
|
+
if ( this._currentContext ) {
|
|
635
|
+
|
|
636
|
+
this._setFramebuffer( this._currentContext );
|
|
637
|
+
|
|
638
|
+
}
|
|
639
|
+
|
|
590
640
|
}
|
|
591
641
|
|
|
592
642
|
draw( renderObject/*, info*/ ) {
|
|
@@ -598,9 +648,9 @@ class WebGLBackend extends Backend {
|
|
|
598
648
|
|
|
599
649
|
const contextData = this.get( context );
|
|
600
650
|
|
|
601
|
-
const
|
|
651
|
+
const drawParams = renderObject.getDrawParameters();
|
|
602
652
|
|
|
603
|
-
if (
|
|
653
|
+
if ( drawParams === null ) return;
|
|
604
654
|
|
|
605
655
|
//
|
|
606
656
|
|
|
@@ -693,8 +743,8 @@ class WebGLBackend extends Backend {
|
|
|
693
743
|
|
|
694
744
|
//
|
|
695
745
|
|
|
696
|
-
const { vertexCount, instanceCount } =
|
|
697
|
-
let { firstVertex } =
|
|
746
|
+
const { vertexCount, instanceCount } = drawParams;
|
|
747
|
+
let { firstVertex } = drawParams;
|
|
698
748
|
|
|
699
749
|
renderer.object = object;
|
|
700
750
|
|
|
@@ -1059,8 +1109,6 @@ class WebGLBackend extends Backend {
|
|
|
1059
1109
|
|
|
1060
1110
|
// Bindings
|
|
1061
1111
|
|
|
1062
|
-
this.createBindings( null, bindings );
|
|
1063
|
-
|
|
1064
1112
|
this._setupBindings( bindings, programGPU );
|
|
1065
1113
|
|
|
1066
1114
|
const attributeNodes = computeProgram.attributes;
|
|
@@ -1101,33 +1149,43 @@ class WebGLBackend extends Backend {
|
|
|
1101
1149
|
|
|
1102
1150
|
createBindings( bindGroup, bindings ) {
|
|
1103
1151
|
|
|
1104
|
-
this.
|
|
1152
|
+
if ( this._knownBindings.has( bindings ) === false ) {
|
|
1105
1153
|
|
|
1106
|
-
|
|
1154
|
+
this._knownBindings.add( bindings );
|
|
1107
1155
|
|
|
1108
|
-
|
|
1156
|
+
let uniformBuffers = 0;
|
|
1157
|
+
let textures = 0;
|
|
1109
1158
|
|
|
1110
|
-
|
|
1159
|
+
for ( const bindGroup of bindings ) {
|
|
1111
1160
|
|
|
1112
|
-
|
|
1161
|
+
this.set( bindGroup, {
|
|
1162
|
+
textures: textures,
|
|
1163
|
+
uniformBuffers: uniformBuffers
|
|
1164
|
+
} );
|
|
1113
1165
|
|
|
1114
|
-
|
|
1115
|
-
|
|
1166
|
+
for ( const binding of bindGroup.bindings ) {
|
|
1167
|
+
|
|
1168
|
+
if ( binding.isUniformBuffer ) uniformBuffers ++;
|
|
1169
|
+
if ( binding.isSampledTexture ) textures ++;
|
|
1170
|
+
|
|
1171
|
+
}
|
|
1116
1172
|
|
|
1117
|
-
|
|
1173
|
+
}
|
|
1118
1174
|
|
|
1119
|
-
|
|
1175
|
+
}
|
|
1120
1176
|
|
|
1121
|
-
|
|
1177
|
+
this.updateBindings( bindGroup, bindings );
|
|
1122
1178
|
|
|
1123
|
-
|
|
1179
|
+
}
|
|
1124
1180
|
|
|
1125
|
-
|
|
1126
|
-
bindingsData.textureIndex = bindGroupData.textureIndex;
|
|
1181
|
+
updateBindings( bindGroup /*, bindings*/ ) {
|
|
1127
1182
|
|
|
1128
|
-
}
|
|
1183
|
+
const { gl } = this;
|
|
1184
|
+
|
|
1185
|
+
const bindGroupData = this.get( bindGroup );
|
|
1129
1186
|
|
|
1130
|
-
let i =
|
|
1187
|
+
let i = bindGroupData.uniformBuffers;
|
|
1188
|
+
let t = bindGroupData.textures;
|
|
1131
1189
|
|
|
1132
1190
|
for ( const binding of bindGroup.bindings ) {
|
|
1133
1191
|
|
|
@@ -1140,7 +1198,7 @@ class WebGLBackend extends Backend {
|
|
|
1140
1198
|
gl.bufferData( gl.UNIFORM_BUFFER, data, gl.DYNAMIC_DRAW );
|
|
1141
1199
|
|
|
1142
1200
|
this.set( binding, {
|
|
1143
|
-
index:
|
|
1201
|
+
index: i ++,
|
|
1144
1202
|
bufferGPU
|
|
1145
1203
|
} );
|
|
1146
1204
|
|
|
@@ -1149,7 +1207,7 @@ class WebGLBackend extends Backend {
|
|
|
1149
1207
|
const { textureGPU, glTextureType } = this.get( binding.texture );
|
|
1150
1208
|
|
|
1151
1209
|
this.set( binding, {
|
|
1152
|
-
index:
|
|
1210
|
+
index: t ++,
|
|
1153
1211
|
textureGPU,
|
|
1154
1212
|
glTextureType
|
|
1155
1213
|
} );
|
|
@@ -1247,9 +1305,9 @@ class WebGLBackend extends Backend {
|
|
|
1247
1305
|
|
|
1248
1306
|
}
|
|
1249
1307
|
|
|
1250
|
-
copyTextureToTexture(
|
|
1308
|
+
copyTextureToTexture( srcTexture, dstTexture, srcRegion, dstPosition, level ) {
|
|
1251
1309
|
|
|
1252
|
-
this.textureUtils.copyTextureToTexture(
|
|
1310
|
+
this.textureUtils.copyTextureToTexture( srcTexture, dstTexture, srcRegion, dstPosition, level );
|
|
1253
1311
|
|
|
1254
1312
|
}
|
|
1255
1313
|
|
|
@@ -1321,6 +1379,7 @@ class WebGLBackend extends Backend {
|
|
|
1321
1379
|
const texture = textures[ i ];
|
|
1322
1380
|
const textureData = this.get( texture );
|
|
1323
1381
|
textureData.renderTarget = descriptor.renderTarget;
|
|
1382
|
+
textureData.cacheKey = cacheKey; // required for copyTextureToTexture()
|
|
1324
1383
|
|
|
1325
1384
|
const attachment = gl.COLOR_ATTACHMENT0 + i;
|
|
1326
1385
|
|
|
@@ -1336,6 +1395,8 @@ class WebGLBackend extends Backend {
|
|
|
1336
1395
|
|
|
1337
1396
|
const textureData = this.get( descriptor.depthTexture );
|
|
1338
1397
|
const depthStyle = stencilBuffer ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;
|
|
1398
|
+
textureData.renderTarget = descriptor.renderTarget;
|
|
1399
|
+
textureData.cacheKey = cacheKey; // required for copyTextureToTexture()
|
|
1339
1400
|
|
|
1340
1401
|
gl.framebufferTexture2D( gl.FRAMEBUFFER, depthStyle, gl.TEXTURE_2D, textureData.textureGPU, 0 );
|
|
1341
1402
|
|
|
@@ -1614,6 +1675,12 @@ class WebGLBackend extends Backend {
|
|
|
1614
1675
|
|
|
1615
1676
|
}
|
|
1616
1677
|
|
|
1678
|
+
dispose() {
|
|
1679
|
+
|
|
1680
|
+
this.renderer.domElement.removeEventListener( 'webglcontextlost', this._onContextLost );
|
|
1681
|
+
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1617
1684
|
}
|
|
1618
1685
|
|
|
1619
1686
|
export default WebGLBackend;
|
|
@@ -120,18 +120,13 @@ class WebGLBufferRenderer {
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
let elementCount = 0;
|
|
123
|
-
|
|
124
123
|
for ( let i = 0; i < drawCount; i ++ ) {
|
|
125
124
|
|
|
126
|
-
elementCount += counts[ i ];
|
|
125
|
+
elementCount += counts[ i ] * primcount[ i ];
|
|
127
126
|
|
|
128
127
|
}
|
|
129
128
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
info.update( object, elementCount, mode, primcount[ i ] );
|
|
133
|
-
|
|
134
|
-
}
|
|
129
|
+
info.update( object, elementCount, mode, 1 );
|
|
135
130
|
|
|
136
131
|
}
|
|
137
132
|
|
|
@@ -445,8 +445,7 @@ class WebGLTextureUtils {
|
|
|
445
445
|
|
|
446
446
|
if ( glFormat !== null ) {
|
|
447
447
|
|
|
448
|
-
gl.compressedTexSubImage3D( gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, mipmap.data
|
|
449
|
-
|
|
448
|
+
gl.compressedTexSubImage3D( gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, mipmap.data );
|
|
450
449
|
|
|
451
450
|
} else {
|
|
452
451
|
|
|
@@ -607,9 +606,9 @@ class WebGLTextureUtils {
|
|
|
607
606
|
|
|
608
607
|
const { textureGPU: dstTextureGPU, glTextureType, glType, glFormat } = backend.get( dstTexture );
|
|
609
608
|
|
|
610
|
-
|
|
611
609
|
let width, height, minX, minY;
|
|
612
610
|
let dstX, dstY;
|
|
611
|
+
|
|
613
612
|
if ( srcRegion !== null ) {
|
|
614
613
|
|
|
615
614
|
width = srcRegion.max.x - srcRegion.min.x;
|
|
@@ -660,20 +659,46 @@ class WebGLTextureUtils {
|
|
|
660
659
|
gl.pixelStorei( gl.UNPACK_SKIP_PIXELS, minX );
|
|
661
660
|
gl.pixelStorei( gl.UNPACK_SKIP_ROWS, minY );
|
|
662
661
|
|
|
662
|
+
if ( srcTexture.isRenderTargetTexture || srcTexture.isDepthTexture ) {
|
|
663
|
+
|
|
664
|
+
const srcTextureData = backend.get( srcTexture );
|
|
665
|
+
const dstTextureData = backend.get( dstTexture );
|
|
666
|
+
|
|
667
|
+
const srcRenderContextData = backend.get( srcTextureData.renderTarget );
|
|
668
|
+
const dstRenderContextData = backend.get( dstTextureData.renderTarget );
|
|
669
|
+
|
|
670
|
+
const srcFramebuffer = srcRenderContextData.framebuffers[ srcTextureData.cacheKey ];
|
|
671
|
+
const dstFramebuffer = dstRenderContextData.framebuffers[ dstTextureData.cacheKey ];
|
|
672
|
+
|
|
673
|
+
state.bindFramebuffer( gl.READ_FRAMEBUFFER, srcFramebuffer );
|
|
674
|
+
state.bindFramebuffer( gl.DRAW_FRAMEBUFFER, dstFramebuffer );
|
|
675
|
+
|
|
676
|
+
let mask = gl.COLOR_BUFFER_BIT;
|
|
663
677
|
|
|
664
|
-
|
|
678
|
+
if ( srcTexture.isDepthTexture ) mask = gl.DEPTH_BUFFER_BIT;
|
|
665
679
|
|
|
666
|
-
gl.
|
|
680
|
+
gl.blitFramebuffer( minX, minY, width, height, dstX, dstY, width, height, mask, gl.NEAREST );
|
|
681
|
+
|
|
682
|
+
state.bindFramebuffer( gl.READ_FRAMEBUFFER, null );
|
|
683
|
+
state.bindFramebuffer( gl.DRAW_FRAMEBUFFER, null );
|
|
667
684
|
|
|
668
685
|
} else {
|
|
669
686
|
|
|
670
|
-
if ( srcTexture.
|
|
687
|
+
if ( srcTexture.isDataTexture ) {
|
|
671
688
|
|
|
672
|
-
gl.
|
|
689
|
+
gl.texSubImage2D( gl.TEXTURE_2D, level, dstX, dstY, width, height, glFormat, glType, image.data );
|
|
673
690
|
|
|
674
691
|
} else {
|
|
675
692
|
|
|
676
|
-
|
|
693
|
+
if ( srcTexture.isCompressedTexture ) {
|
|
694
|
+
|
|
695
|
+
gl.compressedTexSubImage2D( gl.TEXTURE_2D, level, dstX, dstY, image.width, image.height, glFormat, image.data );
|
|
696
|
+
|
|
697
|
+
} else {
|
|
698
|
+
|
|
699
|
+
gl.texSubImage2D( gl.TEXTURE_2D, level, dstX, dstY, width, height, glFormat, glType, image );
|
|
700
|
+
|
|
701
|
+
}
|
|
677
702
|
|
|
678
703
|
}
|
|
679
704
|
|
|
@@ -101,6 +101,19 @@ class WebGPUBackend extends Backend {
|
|
|
101
101
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
device.lost.then( ( info ) => {
|
|
105
|
+
|
|
106
|
+
const deviceLossInfo = {
|
|
107
|
+
api: 'WebGPU',
|
|
108
|
+
message: info.message || 'Unknown reason',
|
|
109
|
+
reason: info.reason || null,
|
|
110
|
+
originalEvent: info
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
renderer.onDeviceLost( deviceLossInfo );
|
|
114
|
+
|
|
115
|
+
} );
|
|
116
|
+
|
|
104
117
|
const context = ( parameters.context !== undefined ) ? parameters.context : renderer.domElement.getContext( 'webgpu' );
|
|
105
118
|
|
|
106
119
|
this.device = device;
|
|
@@ -151,11 +164,16 @@ class WebGPUBackend extends Backend {
|
|
|
151
164
|
colorAttachments: [ {
|
|
152
165
|
view: null
|
|
153
166
|
} ],
|
|
154
|
-
depthStencilAttachment: {
|
|
155
|
-
view: this.textureUtils.getDepthBuffer( renderer.depth, renderer.stencil ).createView()
|
|
156
|
-
}
|
|
157
167
|
};
|
|
158
168
|
|
|
169
|
+
if ( this.renderer.depth === true || this.renderer.stencil === true ) {
|
|
170
|
+
|
|
171
|
+
descriptor.depthStencilAttachment = {
|
|
172
|
+
view: this.textureUtils.getDepthBuffer( renderer.depth, renderer.stencil ).createView()
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
}
|
|
176
|
+
|
|
159
177
|
const colorAttachment = descriptor.colorAttachments[ 0 ];
|
|
160
178
|
|
|
161
179
|
if ( this.renderer.samples > 0 ) {
|
|
@@ -263,17 +281,22 @@ class WebGPUBackend extends Backend {
|
|
|
263
281
|
|
|
264
282
|
}
|
|
265
283
|
|
|
266
|
-
const depthTextureData = this.get( renderContext.depthTexture );
|
|
267
|
-
|
|
268
|
-
const depthStencilAttachment = {
|
|
269
|
-
view: depthTextureData.texture.createView()
|
|
270
|
-
};
|
|
271
284
|
|
|
272
285
|
descriptor = {
|
|
273
286
|
colorAttachments,
|
|
274
|
-
depthStencilAttachment
|
|
275
287
|
};
|
|
276
288
|
|
|
289
|
+
if ( renderContext.depth ) {
|
|
290
|
+
|
|
291
|
+
const depthTextureData = this.get( renderContext.depthTexture );
|
|
292
|
+
|
|
293
|
+
const depthStencilAttachment = {
|
|
294
|
+
view: depthTextureData.texture.createView()
|
|
295
|
+
};
|
|
296
|
+
descriptor.depthStencilAttachment = depthStencilAttachment;
|
|
297
|
+
|
|
298
|
+
}
|
|
299
|
+
|
|
277
300
|
descriptors[ cacheKey ] = descriptor;
|
|
278
301
|
|
|
279
302
|
renderTargetData.width = renderTarget.width;
|
|
@@ -825,6 +848,12 @@ class WebGPUBackend extends Backend {
|
|
|
825
848
|
|
|
826
849
|
}
|
|
827
850
|
|
|
851
|
+
async waitForGPU() {
|
|
852
|
+
|
|
853
|
+
await this.device.queue.onSubmittedWorkDone();
|
|
854
|
+
|
|
855
|
+
}
|
|
856
|
+
|
|
828
857
|
// render object
|
|
829
858
|
|
|
830
859
|
draw( renderObject, info ) {
|
|
@@ -836,9 +865,9 @@ class WebGPUBackend extends Backend {
|
|
|
836
865
|
const currentSets = renderContextData.currentSets;
|
|
837
866
|
const passEncoderGPU = renderContextData.currentPass;
|
|
838
867
|
|
|
839
|
-
const
|
|
868
|
+
const drawParams = renderObject.getDrawParameters();
|
|
840
869
|
|
|
841
|
-
if (
|
|
870
|
+
if ( drawParams === null ) return;
|
|
842
871
|
|
|
843
872
|
// pipeline
|
|
844
873
|
|
|
@@ -960,17 +989,41 @@ class WebGPUBackend extends Backend {
|
|
|
960
989
|
|
|
961
990
|
} else if ( hasIndex === true ) {
|
|
962
991
|
|
|
963
|
-
const { vertexCount: indexCount, instanceCount, firstVertex: firstIndex } =
|
|
992
|
+
const { vertexCount: indexCount, instanceCount, firstVertex: firstIndex } = drawParams;
|
|
993
|
+
|
|
994
|
+
const indirect = renderObject.getIndirect();
|
|
995
|
+
|
|
996
|
+
if ( indirect !== null ) {
|
|
997
|
+
|
|
998
|
+
const buffer = this.get( indirect ).buffer;
|
|
964
999
|
|
|
965
|
-
|
|
1000
|
+
passEncoderGPU.drawIndexedIndirect( buffer, 0 );
|
|
1001
|
+
|
|
1002
|
+
} else {
|
|
1003
|
+
|
|
1004
|
+
passEncoderGPU.drawIndexed( indexCount, instanceCount, firstIndex, 0, 0 );
|
|
1005
|
+
|
|
1006
|
+
}
|
|
966
1007
|
|
|
967
1008
|
info.update( object, indexCount, instanceCount );
|
|
968
1009
|
|
|
969
1010
|
} else {
|
|
970
1011
|
|
|
971
|
-
const { vertexCount, instanceCount, firstVertex } =
|
|
1012
|
+
const { vertexCount, instanceCount, firstVertex } = drawParams;
|
|
1013
|
+
|
|
1014
|
+
const indirect = renderObject.getIndirect();
|
|
1015
|
+
|
|
1016
|
+
if ( indirect !== null ) {
|
|
1017
|
+
|
|
1018
|
+
const buffer = this.get( indirect ).buffer;
|
|
1019
|
+
|
|
1020
|
+
passEncoderGPU.drawIndirect( buffer, 0 );
|
|
972
1021
|
|
|
973
|
-
|
|
1022
|
+
} else {
|
|
1023
|
+
|
|
1024
|
+
passEncoderGPU.draw( vertexCount, instanceCount, firstVertex, 0 );
|
|
1025
|
+
|
|
1026
|
+
}
|
|
974
1027
|
|
|
975
1028
|
info.update( object, vertexCount, instanceCount );
|
|
976
1029
|
|
|
@@ -1056,6 +1109,7 @@ class WebGPUBackend extends Backend {
|
|
|
1056
1109
|
utils.getSampleCountRenderContext( renderContext ),
|
|
1057
1110
|
utils.getCurrentColorSpace( renderContext ), utils.getCurrentColorFormat( renderContext ), utils.getCurrentDepthStencilFormat( renderContext ),
|
|
1058
1111
|
utils.getPrimitiveTopology( object, material ),
|
|
1112
|
+
renderObject.getGeometryCacheKey(),
|
|
1059
1113
|
renderObject.clippingContext.cacheKey
|
|
1060
1114
|
].join();
|
|
1061
1115
|
|
|
@@ -1325,6 +1379,12 @@ class WebGPUBackend extends Backend {
|
|
|
1325
1379
|
|
|
1326
1380
|
}
|
|
1327
1381
|
|
|
1382
|
+
createIndirectStorageAttribute( attribute ) {
|
|
1383
|
+
|
|
1384
|
+
this.attributeUtils.createAttribute( attribute, GPUBufferUsage.STORAGE | GPUBufferUsage.INDIRECT | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST );
|
|
1385
|
+
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1328
1388
|
updateAttribute( attribute ) {
|
|
1329
1389
|
|
|
1330
1390
|
this.attributeUtils.updateAttribute( attribute );
|
|
@@ -1422,8 +1482,6 @@ class WebGPUBackend extends Backend {
|
|
|
1422
1482
|
|
|
1423
1483
|
const renderContextData = this.get( renderContext );
|
|
1424
1484
|
|
|
1425
|
-
const { encoder, descriptor } = renderContextData;
|
|
1426
|
-
|
|
1427
1485
|
let sourceGPU = null;
|
|
1428
1486
|
|
|
1429
1487
|
if ( renderContext.renderTarget ) {
|
|
@@ -1462,7 +1520,19 @@ class WebGPUBackend extends Backend {
|
|
|
1462
1520
|
|
|
1463
1521
|
}
|
|
1464
1522
|
|
|
1465
|
-
|
|
1523
|
+
let encoder;
|
|
1524
|
+
|
|
1525
|
+
if ( renderContextData.currentPass ) {
|
|
1526
|
+
|
|
1527
|
+
renderContextData.currentPass.end();
|
|
1528
|
+
|
|
1529
|
+
encoder = renderContextData.encoder;
|
|
1530
|
+
|
|
1531
|
+
} else {
|
|
1532
|
+
|
|
1533
|
+
encoder = this.device.createCommandEncoder( { label: 'copyFramebufferToTexture_' + texture.id } );
|
|
1534
|
+
|
|
1535
|
+
}
|
|
1466
1536
|
|
|
1467
1537
|
encoder.copyTextureToTexture(
|
|
1468
1538
|
{
|
|
@@ -1480,17 +1550,27 @@ class WebGPUBackend extends Backend {
|
|
|
1480
1550
|
|
|
1481
1551
|
if ( texture.generateMipmaps ) this.textureUtils.generateMipmaps( texture );
|
|
1482
1552
|
|
|
1483
|
-
|
|
1553
|
+
if ( renderContextData.currentPass ) {
|
|
1484
1554
|
|
|
1485
|
-
descriptor
|
|
1555
|
+
const { descriptor } = renderContextData;
|
|
1486
1556
|
|
|
1487
|
-
|
|
1557
|
+
for ( let i = 0; i < descriptor.colorAttachments.length; i ++ ) {
|
|
1488
1558
|
|
|
1489
|
-
|
|
1490
|
-
if ( renderContext.stencil ) descriptor.depthStencilAttachment.stencilLoadOp = GPULoadOp.Load;
|
|
1559
|
+
descriptor.colorAttachments[ i ].loadOp = GPULoadOp.Load;
|
|
1491
1560
|
|
|
1492
|
-
|
|
1493
|
-
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
if ( renderContext.depth ) descriptor.depthStencilAttachment.depthLoadOp = GPULoadOp.Load;
|
|
1564
|
+
if ( renderContext.stencil ) descriptor.depthStencilAttachment.stencilLoadOp = GPULoadOp.Load;
|
|
1565
|
+
|
|
1566
|
+
renderContextData.currentPass = encoder.beginRenderPass( descriptor );
|
|
1567
|
+
renderContextData.currentSets = { attributes: {}, bindingGroups: [], pipeline: null, index: null };
|
|
1568
|
+
|
|
1569
|
+
} else {
|
|
1570
|
+
|
|
1571
|
+
this.device.queue.submit( [ encoder.finish() ] );
|
|
1572
|
+
|
|
1573
|
+
}
|
|
1494
1574
|
|
|
1495
1575
|
}
|
|
1496
1576
|
|
|
@@ -45,7 +45,7 @@ class WebGPURenderer extends Renderer {
|
|
|
45
45
|
//super( new Proxy( backend, debugHandler ) );
|
|
46
46
|
super( backend, parameters );
|
|
47
47
|
|
|
48
|
-
this.
|
|
48
|
+
this.library = new StandardNodeLibrary();
|
|
49
49
|
|
|
50
50
|
this.isWebGPURenderer = true;
|
|
51
51
|
|
|
@@ -22,11 +22,6 @@ import { IESSpotLightNode } from '../../../nodes/Nodes.js';
|
|
|
22
22
|
import { LinearToneMapping, ReinhardToneMapping, CineonToneMapping, ACESFilmicToneMapping, AgXToneMapping, NeutralToneMapping } from '../../../constants.js';
|
|
23
23
|
import { linearToneMapping, reinhardToneMapping, cineonToneMapping, acesFilmicToneMapping, agxToneMapping, neutralToneMapping } from '../../../nodes/display/ToneMappingFunctions.js';
|
|
24
24
|
|
|
25
|
-
// Color Space
|
|
26
|
-
import { LinearSRGBColorSpace, SRGBColorSpace } from '../../../constants.js';
|
|
27
|
-
import { linearSRGBTosRGB, sRGBToLinearSRGB } from '../../../nodes/display/ColorSpaceFunctions.js';
|
|
28
|
-
import { getColorSpaceMethod } from '../../../nodes/display/ColorSpaceNode.js';
|
|
29
|
-
|
|
30
25
|
class BasicNodeLibrary extends NodeLibrary {
|
|
31
26
|
|
|
32
27
|
constructor() {
|
|
@@ -49,9 +44,6 @@ class BasicNodeLibrary extends NodeLibrary {
|
|
|
49
44
|
this.addToneMapping( agxToneMapping, AgXToneMapping );
|
|
50
45
|
this.addToneMapping( neutralToneMapping, NeutralToneMapping );
|
|
51
46
|
|
|
52
|
-
this.addColorSpace( linearSRGBTosRGB, getColorSpaceMethod( LinearSRGBColorSpace, SRGBColorSpace ) );
|
|
53
|
-
this.addColorSpace( sRGBToLinearSRGB, getColorSpaceMethod( SRGBColorSpace, LinearSRGBColorSpace ) );
|
|
54
|
-
|
|
55
47
|
}
|
|
56
48
|
|
|
57
49
|
}
|
|
@@ -54,11 +54,6 @@ import { IESSpotLightNode } from '../../../nodes/Nodes.js';
|
|
|
54
54
|
import { LinearToneMapping, ReinhardToneMapping, CineonToneMapping, ACESFilmicToneMapping, AgXToneMapping, NeutralToneMapping } from '../../../constants.js';
|
|
55
55
|
import { linearToneMapping, reinhardToneMapping, cineonToneMapping, acesFilmicToneMapping, agxToneMapping, neutralToneMapping } from '../../../nodes/display/ToneMappingFunctions.js';
|
|
56
56
|
|
|
57
|
-
// Color Space
|
|
58
|
-
import { LinearSRGBColorSpace, SRGBColorSpace } from '../../../constants.js';
|
|
59
|
-
import { linearSRGBTosRGB, sRGBToLinearSRGB } from '../../../nodes/display/ColorSpaceFunctions.js';
|
|
60
|
-
import { getColorSpaceMethod } from '../../../nodes/display/ColorSpaceNode.js';
|
|
61
|
-
|
|
62
57
|
class StandardNodeLibrary extends NodeLibrary {
|
|
63
58
|
|
|
64
59
|
constructor() {
|
|
@@ -95,9 +90,6 @@ class StandardNodeLibrary extends NodeLibrary {
|
|
|
95
90
|
this.addToneMapping( agxToneMapping, AgXToneMapping );
|
|
96
91
|
this.addToneMapping( neutralToneMapping, NeutralToneMapping );
|
|
97
92
|
|
|
98
|
-
this.addColorSpace( linearSRGBTosRGB, getColorSpaceMethod( LinearSRGBColorSpace, SRGBColorSpace ) );
|
|
99
|
-
this.addColorSpace( sRGBToLinearSRGB, getColorSpaceMethod( SRGBColorSpace, LinearSRGBColorSpace ) );
|
|
100
|
-
|
|
101
93
|
}
|
|
102
94
|
|
|
103
95
|
}
|