@plastic-software/three 0.183.3 → 0.184.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 +783 -290
- package/build/three.core.js +372 -110
- package/build/three.core.min.js +1 -1
- package/build/three.module.js +436 -184
- package/build/three.module.min.js +1 -1
- package/build/three.tsl.js +7 -1
- package/build/three.tsl.min.js +1 -1
- package/build/three.webgpu.js +2979 -1281
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +2942 -1281
- package/build/three.webgpu.nodes.min.js +1 -1
- package/examples/jsm/Addons.js +11 -0
- package/examples/jsm/animation/CCDIKSolver.js +5 -1
- package/examples/jsm/controls/ArcballControls.js +4 -1
- package/examples/jsm/controls/DragControls.js +2 -2
- package/examples/jsm/controls/FirstPersonControls.js +58 -54
- package/examples/jsm/controls/FlyControls.js +4 -0
- package/examples/jsm/controls/OrbitControls.js +2 -2
- package/examples/jsm/controls/TrackballControls.js +2 -2
- package/examples/jsm/controls/TransformControls.js +34 -2
- package/examples/jsm/csm/CSMShadowNode.js +6 -2
- package/examples/jsm/exporters/GLTFExporter.js +21 -5
- package/examples/jsm/geometries/TextGeometry.js +18 -0
- package/examples/jsm/helpers/LightProbeGridHelper.js +221 -0
- package/examples/jsm/inspector/Extension.js +13 -0
- package/examples/jsm/inspector/Inspector.js +169 -114
- package/examples/jsm/inspector/RendererInspector.js +2 -2
- package/examples/jsm/inspector/extensions/extensions.json +6 -0
- package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphEditor.js +916 -0
- package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphLoader.js +281 -0
- package/examples/jsm/inspector/tabs/Memory.js +128 -0
- package/examples/jsm/inspector/tabs/Parameters.js +34 -2
- package/examples/jsm/inspector/tabs/Performance.js +2 -2
- package/examples/jsm/inspector/tabs/Settings.js +264 -0
- package/examples/jsm/inspector/tabs/Timeline.js +1611 -0
- package/examples/jsm/inspector/tabs/Viewer.js +105 -3
- package/examples/jsm/inspector/ui/Graph.js +2 -2
- package/examples/jsm/inspector/ui/List.js +1 -1
- package/examples/jsm/inspector/ui/Profiler.js +273 -176
- package/examples/jsm/inspector/ui/Style.js +64 -10
- package/examples/jsm/inspector/ui/Tab.js +39 -7
- package/examples/jsm/inspector/ui/Values.js +39 -2
- package/examples/jsm/inspector/ui/utils.js +13 -0
- package/examples/jsm/interaction/InteractionManager.js +226 -0
- package/examples/jsm/libs/meshopt_decoder.module.js +8 -8
- package/examples/jsm/lighting/DynamicLighting.js +82 -0
- package/examples/jsm/lighting/LightProbeGrid.js +651 -0
- package/examples/jsm/lines/LineMaterial.js +1 -1
- package/examples/jsm/loaders/EXRLoader.js +682 -43
- package/examples/jsm/loaders/FBXLoader.js +233 -33
- package/examples/jsm/loaders/GLTFLoader.js +24 -7
- package/examples/jsm/loaders/HDRLoader.js +1 -1
- package/examples/jsm/loaders/KTX2Loader.js +8 -2
- package/examples/jsm/loaders/LDrawLoader.js +39 -47
- package/examples/jsm/loaders/SVGLoader.js +1 -1
- package/examples/jsm/loaders/VTKLoader.js +5 -1
- package/examples/jsm/loaders/collada/ColladaComposer.js +101 -7
- package/examples/jsm/loaders/collada/ColladaParser.js +19 -4
- package/examples/jsm/loaders/usd/USDAParser.js +6 -0
- package/examples/jsm/loaders/usd/USDCParser.js +26 -0
- package/examples/jsm/loaders/usd/USDComposer.js +656 -103
- package/examples/jsm/misc/GPUComputationRenderer.js +2 -0
- package/examples/jsm/misc/RollerCoaster.js +42 -4
- package/examples/jsm/modifiers/TessellateModifier.js +1 -1
- package/examples/jsm/objects/Reflector.js +73 -25
- package/examples/jsm/objects/Sky.js +14 -2
- package/examples/jsm/objects/SkyMesh.js +23 -6
- package/examples/jsm/renderers/Projector.js +18 -38
- package/examples/jsm/renderers/SVGRenderer.js +6 -25
- package/examples/jsm/transpiler/GLSLDecoder.js +2 -2
- package/examples/jsm/tsl/WebGLNodesHandler.js +605 -0
- package/examples/jsm/tsl/display/AfterImageNode.js +10 -0
- package/examples/jsm/tsl/display/AnamorphicNode.js +11 -0
- package/examples/jsm/tsl/display/BilateralBlurNode.js +10 -0
- package/examples/jsm/tsl/display/ChromaticAberrationNode.js +3 -36
- package/examples/jsm/tsl/display/FSR1Node.js +477 -0
- package/examples/jsm/tsl/display/GTAONode.js +2 -1
- package/examples/jsm/tsl/display/GaussianBlurNode.js +10 -0
- package/examples/jsm/tsl/display/GodraysNode.js +2 -11
- package/examples/jsm/tsl/display/OutlineNode.js +66 -16
- package/examples/jsm/tsl/display/SSGINode.js +0 -4
- package/examples/jsm/tsl/display/SharpenNode.js +283 -0
- package/examples/jsm/tsl/display/TAAUNode.js +835 -0
- package/examples/jsm/tsl/display/TRAANode.js +48 -7
- package/examples/jsm/tsl/lighting/DynamicLightsNode.js +300 -0
- package/examples/jsm/tsl/lighting/data/AmbientLightDataNode.js +61 -0
- package/examples/jsm/tsl/lighting/data/DirectionalLightDataNode.js +111 -0
- package/examples/jsm/tsl/lighting/data/HemisphereLightDataNode.js +99 -0
- package/examples/jsm/tsl/lighting/data/PointLightDataNode.js +134 -0
- package/examples/jsm/tsl/lighting/data/SpotLightDataNode.js +161 -0
- package/examples/jsm/tsl/math/Bayer.js +13 -2
- package/examples/jsm/utils/BufferGeometryUtils.js +2 -3
- package/examples/jsm/utils/ColorUtils.js +76 -0
- package/examples/jsm/utils/SkeletonUtils.js +14 -8
- package/examples/jsm/webxr/XRHandMeshModel.js +36 -10
- package/examples/jsm/webxr/XRHandModelFactory.js +2 -1
- package/package.json +4 -4
- package/src/Three.Core.js +1 -0
- package/src/Three.TSL.js +6 -0
- package/src/Three.WebGPU.Nodes.js +3 -0
- package/src/Three.WebGPU.js +6 -0
- package/src/animation/AnimationAction.js +11 -1
- package/src/audio/AudioContext.js +2 -2
- package/src/constants.js +1 -1
- package/src/core/BufferAttribute.js +13 -1
- package/src/core/Clock.js +1 -1
- package/src/core/Object3D.js +1 -5
- package/src/core/RenderTarget.js +1 -0
- package/src/extras/PMREMGenerator.js +1 -1
- package/src/extras/curves/CatmullRomCurve3.js +3 -2
- package/src/loaders/AudioLoader.js +11 -1
- package/src/loaders/DataTextureLoader.js +6 -4
- package/src/loaders/FileLoader.js +1 -2
- package/src/loaders/ImageBitmapLoader.js +4 -6
- package/src/loaders/MaterialLoader.js +1 -1
- package/src/loaders/ObjectLoader.js +25 -4
- package/src/loaders/nodes/NodeObjectLoader.js +18 -0
- package/src/materials/MeshToonMaterial.js +1 -1
- package/src/materials/nodes/Line2NodeMaterial.js +27 -0
- package/src/materials/nodes/NodeMaterial.js +0 -27
- package/src/materials/nodes/manager/NodeMaterialObserver.js +188 -89
- package/src/math/Line3.js +3 -0
- package/src/math/Matrix2.js +13 -9
- package/src/math/Matrix3.js +13 -9
- package/src/math/Matrix4.js +13 -9
- package/src/math/Plane.js +4 -3
- package/src/math/Triangle.js +1 -1
- package/src/math/Vector2.js +11 -7
- package/src/math/Vector3.js +12 -8
- package/src/math/Vector4.js +13 -9
- package/src/nodes/Nodes.js +0 -1
- package/src/nodes/TSL.js +1 -1
- package/src/nodes/accessors/BufferAttributeNode.js +9 -3
- package/src/nodes/accessors/CubeTextureNode.js +7 -1
- package/src/nodes/accessors/MaterialProperties.js +2 -5
- package/src/nodes/accessors/Object3DNode.js +1 -1
- package/src/nodes/accessors/ReferenceBaseNode.js +2 -2
- package/src/nodes/accessors/ReferenceNode.js +4 -4
- package/src/nodes/accessors/SceneProperties.js +2 -8
- package/src/nodes/accessors/StorageBufferNode.js +10 -4
- package/src/nodes/accessors/StorageTextureNode.js +4 -9
- package/src/nodes/accessors/TextureNode.js +10 -2
- package/src/nodes/accessors/UniformArrayNode.js +2 -2
- package/src/nodes/code/FunctionCallNode.js +1 -1
- package/src/nodes/code/FunctionNode.js +1 -1
- package/src/nodes/core/ArrayNode.js +1 -1
- package/src/nodes/core/AssignNode.js +1 -1
- package/src/nodes/core/AttributeNode.js +1 -1
- package/src/nodes/core/BypassNode.js +1 -1
- package/src/nodes/core/ContextNode.js +1 -1
- package/src/nodes/core/IndexNode.js +2 -1
- package/src/nodes/core/InputNode.js +1 -1
- package/src/nodes/core/InspectorNode.js +1 -1
- package/src/nodes/core/IsolateNode.js +1 -1
- package/src/nodes/core/Node.js +83 -12
- package/src/nodes/core/NodeBuilder.js +117 -16
- package/src/nodes/core/NodeUtils.js +1 -1
- package/src/nodes/core/OutputStructNode.js +1 -1
- package/src/nodes/core/ParameterNode.js +1 -1
- package/src/nodes/core/StackNode.js +1 -1
- package/src/nodes/core/StructNode.js +1 -1
- package/src/nodes/core/StructTypeNode.js +1 -1
- package/src/nodes/core/SubBuildNode.js +1 -1
- package/src/nodes/core/UniformGroupNode.js +36 -6
- package/src/nodes/core/VarNode.js +1 -1
- package/src/nodes/core/VaryingNode.js +1 -1
- package/src/nodes/display/NormalMapNode.js +2 -2
- package/src/nodes/display/PassNode.js +27 -7
- package/src/nodes/display/RenderOutputNode.js +4 -4
- package/src/nodes/display/ScreenNode.js +1 -1
- package/src/nodes/display/ViewportDepthTextureNode.js +11 -15
- package/src/nodes/display/ViewportTextureNode.js +18 -7
- package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +2 -2
- package/src/nodes/geometry/RangeNode.js +1 -1
- package/src/nodes/gpgpu/AtomicFunctionNode.js +1 -1
- package/src/nodes/gpgpu/BarrierNode.js +9 -0
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +1 -1
- package/src/nodes/gpgpu/ComputeNode.js +69 -44
- package/src/nodes/gpgpu/SubgroupFunctionNode.js +1 -1
- package/src/nodes/lighting/LightsNode.js +6 -27
- package/src/nodes/lighting/ShadowNode.js +24 -2
- package/src/nodes/math/BitcastNode.js +1 -1
- package/src/nodes/math/ConditionalNode.js +1 -1
- package/src/nodes/math/MathNode.js +73 -1
- package/src/nodes/math/OperatorNode.js +1 -1
- package/src/nodes/math/PackFloatNode.js +1 -1
- package/src/nodes/math/UnpackFloatNode.js +1 -1
- package/src/nodes/tsl/TSLBase.js +1 -1
- package/src/nodes/tsl/TSLCore.js +21 -3
- package/src/nodes/utils/ArrayElementNode.js +1 -1
- package/src/nodes/utils/ConvertNode.js +1 -1
- package/src/nodes/utils/DebugNode.js +1 -1
- package/src/nodes/utils/EventNode.js +30 -0
- package/src/nodes/utils/FlipNode.js +1 -1
- package/src/nodes/utils/FunctionOverloadingNode.js +1 -1
- package/src/nodes/utils/JoinNode.js +1 -1
- package/src/nodes/utils/MemberNode.js +1 -1
- package/src/nodes/utils/Remap.js +48 -0
- package/src/nodes/utils/RotateNode.js +1 -1
- package/src/nodes/utils/SetNode.js +1 -1
- package/src/nodes/utils/SplitNode.js +1 -1
- package/src/objects/BatchedMesh.js +17 -2
- package/src/objects/InstancedMesh.js +19 -3
- package/src/objects/SkinnedMesh.js +26 -9
- package/src/renderers/WebGLRenderer.js +148 -49
- package/src/renderers/common/Animation.js +3 -3
- package/src/renderers/common/Attributes.js +15 -1
- package/src/renderers/common/Backend.js +0 -8
- package/src/renderers/common/Background.js +2 -2
- package/src/renderers/common/BindGroup.js +1 -8
- package/src/renderers/common/Bindings.js +2 -2
- package/src/renderers/common/ComputePipeline.js +1 -1
- package/src/renderers/common/CubeRenderTarget.js +1 -1
- package/src/renderers/common/Info.js +333 -4
- package/src/renderers/common/InspectorBase.js +6 -1
- package/src/renderers/common/Pipelines.js +36 -3
- package/src/renderers/common/ReadbackBuffer.js +78 -0
- package/src/renderers/common/RenderBundle.js +3 -1
- package/src/renderers/common/RenderBundles.js +5 -2
- package/src/renderers/common/RenderObject.js +2 -2
- package/src/renderers/common/RenderObjects.js +3 -3
- package/src/renderers/common/RenderPipeline.js +35 -6
- package/src/renderers/common/Renderer.js +232 -53
- package/src/renderers/common/Textures.js +72 -3
- package/src/renderers/common/UniformsGroup.js +1 -1
- package/src/renderers/common/XRManager.js +34 -27
- package/src/renderers/common/extras/PMREMGenerator.js +23 -15
- package/src/renderers/common/nodes/NodeBuilderState.js +1 -1
- package/src/renderers/common/nodes/NodeManager.js +230 -99
- package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +20 -0
- package/src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl.js +9 -1
- package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +0 -1
- package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/lightprobes_pars_fragment.glsl.js +80 -0
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +8 -0
- package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +2 -0
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +1 -3
- package/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js +7 -0
- package/src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl.js +0 -1
- package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +12 -2
- package/src/renderers/shaders/ShaderChunk.js +2 -0
- package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +1 -2
- package/src/renderers/shaders/ShaderLib.js +0 -1
- package/src/renderers/shaders/UniformsLib.js +7 -2
- package/src/renderers/shaders/UniformsUtils.js +27 -5
- package/src/renderers/webgl/WebGLAnimation.js +2 -1
- package/src/renderers/webgl/WebGLBackground.js +13 -13
- package/src/renderers/webgl/WebGLBufferRenderer.js +0 -32
- package/src/renderers/webgl/WebGLCapabilities.js +6 -0
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +0 -32
- package/src/renderers/webgl/WebGLMaterials.js +12 -13
- package/src/renderers/webgl/WebGLOutput.js +4 -1
- package/src/renderers/webgl/WebGLProgram.js +5 -0
- package/src/renderers/webgl/WebGLPrograms.js +24 -3
- package/src/renderers/webgl/WebGLRenderStates.js +13 -2
- package/src/renderers/webgl/WebGLState.js +43 -0
- package/src/renderers/webgl/WebGLTextures.js +129 -26
- package/src/renderers/webgl/WebGLUniformsGroups.js +19 -0
- package/src/renderers/webgl-fallback/WebGLBackend.js +106 -65
- package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +0 -41
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +29 -51
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +53 -19
- package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +25 -0
- package/src/renderers/webgl-fallback/utils/WebGLState.js +42 -1
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +63 -50
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +1 -1
- package/src/renderers/webgpu/WebGPUBackend.js +160 -146
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +55 -33
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +103 -17
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +1 -1
- package/src/renderers/webgpu/utils/WebGPUCapabilities.js +48 -0
- package/src/renderers/webgpu/utils/WebGPUConstants.js +8 -0
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +91 -17
- package/src/renderers/webgpu/utils/WebGPUUtils.js +18 -2
- package/src/renderers/webxr/WebXRController.js +12 -0
- package/src/textures/HTMLTexture.js +74 -0
- package/src/textures/Source.js +1 -1
- package/src/textures/Texture.js +13 -2
- package/src/utils.js +23 -1
- package/src/nodes/utils/RemapNode.js +0 -125
|
@@ -230,6 +230,22 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
230
230
|
*/
|
|
231
231
|
this.scopedArrays = new Map();
|
|
232
232
|
|
|
233
|
+
/**
|
|
234
|
+
* A flag that indicates that early returns are allowed.
|
|
235
|
+
*
|
|
236
|
+
* @type {boolean}
|
|
237
|
+
* @default true
|
|
238
|
+
*/
|
|
239
|
+
this.allowEarlyReturns = true;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* A flag that indicates that global variables are allowed.
|
|
243
|
+
*
|
|
244
|
+
* @type {boolean}
|
|
245
|
+
* @default true
|
|
246
|
+
*/
|
|
247
|
+
this.allowGlobalVariables = true;
|
|
248
|
+
|
|
233
249
|
}
|
|
234
250
|
|
|
235
251
|
/**
|
|
@@ -428,7 +444,7 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
428
444
|
*/
|
|
429
445
|
generateTextureDimension( texture, textureProperty, levelSnippet ) {
|
|
430
446
|
|
|
431
|
-
const textureData = this.getDataFromNode( texture, this.shaderStage, this.
|
|
447
|
+
const textureData = this.getDataFromNode( texture, this.shaderStage, this.cache );
|
|
432
448
|
|
|
433
449
|
if ( textureData.dimensionsSnippet === undefined ) textureData.dimensionsSnippet = {};
|
|
434
450
|
|
|
@@ -708,7 +724,7 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
708
724
|
isUnfilterable( texture ) {
|
|
709
725
|
|
|
710
726
|
return this.getComponentTypeFromTexture( texture ) !== 'float' ||
|
|
711
|
-
( ! this.isAvailable( 'float32Filterable' ) && texture.
|
|
727
|
+
( ! this.isAvailable( 'float32Filterable' ) && texture.type === FloatType ) ||
|
|
712
728
|
( this.isSampleCompare( texture ) === false && texture.minFilter === NearestFilter && texture.magFilter === NearestFilter ) ||
|
|
713
729
|
this.renderer.backend.utils.getTextureSampleData( texture ).primarySamples > 1;
|
|
714
730
|
|
|
@@ -1733,11 +1749,12 @@ ${ flowData.code }
|
|
|
1733
1749
|
* @param {string} type - The variable's type.
|
|
1734
1750
|
* @param {string} name - The variable's name.
|
|
1735
1751
|
* @param {?number} [count=null] - The array length.
|
|
1752
|
+
* @param {string} [qualifier=''] - The variable's qualifier.
|
|
1736
1753
|
* @return {string} The WGSL snippet that defines a variable.
|
|
1737
1754
|
*/
|
|
1738
|
-
getVar( type, name, count = null ) {
|
|
1755
|
+
getVar( type, name, count = null, qualifier = '' ) {
|
|
1739
1756
|
|
|
1740
|
-
let snippet = `var ${ name } : `;
|
|
1757
|
+
let snippet = `var${ qualifier } ${ name } : `;
|
|
1741
1758
|
|
|
1742
1759
|
if ( count !== null ) {
|
|
1743
1760
|
|
|
@@ -1759,7 +1776,15 @@ ${ flowData.code }
|
|
|
1759
1776
|
* @param {string} shaderStage - The shader stage.
|
|
1760
1777
|
* @return {string} The WGSL snippet that defines the variables.
|
|
1761
1778
|
*/
|
|
1762
|
-
getVars( shaderStage ) {
|
|
1779
|
+
getVars( shaderStage, global = false ) {
|
|
1780
|
+
|
|
1781
|
+
let qualifier = '';
|
|
1782
|
+
|
|
1783
|
+
if ( global ) {
|
|
1784
|
+
|
|
1785
|
+
qualifier = '<private>';
|
|
1786
|
+
|
|
1787
|
+
}
|
|
1763
1788
|
|
|
1764
1789
|
const snippets = [];
|
|
1765
1790
|
const vars = this.vars[ shaderStage ];
|
|
@@ -1768,13 +1793,13 @@ ${ flowData.code }
|
|
|
1768
1793
|
|
|
1769
1794
|
for ( const variable of vars ) {
|
|
1770
1795
|
|
|
1771
|
-
snippets.push(
|
|
1796
|
+
snippets.push( `${ this.getVar( variable.type, variable.name, variable.count, qualifier ) };` );
|
|
1772
1797
|
|
|
1773
1798
|
}
|
|
1774
1799
|
|
|
1775
1800
|
}
|
|
1776
1801
|
|
|
1777
|
-
return `\n${ snippets.join( '\n' ) }\n`;
|
|
1802
|
+
return global ? snippets.join( '\n' ) : `\n\t${ snippets.join( '\n\t' ) }\n`;
|
|
1778
1803
|
|
|
1779
1804
|
}
|
|
1780
1805
|
|
|
@@ -1799,13 +1824,15 @@ ${ flowData.code }
|
|
|
1799
1824
|
const varyings = this.varyings;
|
|
1800
1825
|
const vars = this.vars[ shaderStage ];
|
|
1801
1826
|
|
|
1827
|
+
let varyingIndex = 0;
|
|
1828
|
+
|
|
1802
1829
|
for ( let index = 0; index < varyings.length; index ++ ) {
|
|
1803
1830
|
|
|
1804
1831
|
const varying = varyings[ index ];
|
|
1805
1832
|
|
|
1806
1833
|
if ( varying.needsInterpolation ) {
|
|
1807
1834
|
|
|
1808
|
-
let attributesSnippet = `@location( ${
|
|
1835
|
+
let attributesSnippet = `@location( ${ varyingIndex ++ } )`;
|
|
1809
1836
|
|
|
1810
1837
|
if ( varying.interpolationType ) {
|
|
1811
1838
|
|
|
@@ -1866,6 +1893,7 @@ ${ flowData.code }
|
|
|
1866
1893
|
*/
|
|
1867
1894
|
getUniforms( shaderStage ) {
|
|
1868
1895
|
|
|
1896
|
+
const backend = this.renderer.backend;
|
|
1869
1897
|
const uniforms = this.uniforms[ shaderStage ];
|
|
1870
1898
|
|
|
1871
1899
|
const bindingSnippets = [];
|
|
@@ -1903,7 +1931,7 @@ ${ flowData.code }
|
|
|
1903
1931
|
|
|
1904
1932
|
let multisampled = '';
|
|
1905
1933
|
|
|
1906
|
-
const { primarySamples } =
|
|
1934
|
+
const { primarySamples } = backend.utils.getTextureSampleData( texture );
|
|
1907
1935
|
|
|
1908
1936
|
if ( primarySamples > 1 ) {
|
|
1909
1937
|
|
|
@@ -1921,7 +1949,7 @@ ${ flowData.code }
|
|
|
1921
1949
|
|
|
1922
1950
|
} else if ( texture.isDepthTexture === true ) {
|
|
1923
1951
|
|
|
1924
|
-
if (
|
|
1952
|
+
if ( backend.compatibilityMode && texture.compareFunction === null ) {
|
|
1925
1953
|
|
|
1926
1954
|
textureType = `texture${ multisampled }_2d<f32>`;
|
|
1927
1955
|
|
|
@@ -1933,7 +1961,7 @@ ${ flowData.code }
|
|
|
1933
1961
|
|
|
1934
1962
|
} else if ( uniform.node.isStorageTextureNode === true ) {
|
|
1935
1963
|
|
|
1936
|
-
const format = getFormat( texture );
|
|
1964
|
+
const format = getFormat( texture, backend.device );
|
|
1937
1965
|
const access = this.getStorageAccess( uniform.node, shaderStage );
|
|
1938
1966
|
|
|
1939
1967
|
const is3D = uniform.node.value.is3DTexture;
|
|
@@ -2061,12 +2089,14 @@ ${ flowData.code }
|
|
|
2061
2089
|
|
|
2062
2090
|
this.shaderStage = shaderStage;
|
|
2063
2091
|
|
|
2092
|
+
const allowGlobal = this.allowGlobalVariables;
|
|
2093
|
+
|
|
2064
2094
|
const stageData = shadersData[ shaderStage ];
|
|
2065
2095
|
stageData.uniforms = this.getUniforms( shaderStage );
|
|
2066
2096
|
stageData.attributes = this.getAttributes( shaderStage );
|
|
2067
2097
|
stageData.varyings = this.getVaryings( shaderStage );
|
|
2068
2098
|
stageData.structs = this.getStructs( shaderStage );
|
|
2069
|
-
stageData.vars = this.getVars( shaderStage );
|
|
2099
|
+
stageData.vars = this.getVars( shaderStage, allowGlobal );
|
|
2070
2100
|
stageData.codes = this.getCodes( shaderStage );
|
|
2071
2101
|
stageData.directives = this.getDirectives( shaderStage );
|
|
2072
2102
|
stageData.scopedArrays = this.getScopedArrays( shaderStage );
|
|
@@ -2116,7 +2146,7 @@ ${ flowData.code }
|
|
|
2116
2146
|
|
|
2117
2147
|
} else {
|
|
2118
2148
|
|
|
2119
|
-
let structSnippet = '\t@location(0) color: vec4<f32>';
|
|
2149
|
+
let structSnippet = '\t@location( 0 ) color: vec4<f32>';
|
|
2120
2150
|
|
|
2121
2151
|
const builtins = this.getBuiltins( 'output' );
|
|
2122
2152
|
|
|
@@ -2280,17 +2310,6 @@ ${ flowData.code }
|
|
|
2280
2310
|
|
|
2281
2311
|
}
|
|
2282
2312
|
|
|
2283
|
-
/**
|
|
2284
|
-
* Returns the maximum uniform buffer size limit.
|
|
2285
|
-
*
|
|
2286
|
-
* @return {number} The maximum uniform buffer size in bytes.
|
|
2287
|
-
*/
|
|
2288
|
-
getUniformBufferLimit() {
|
|
2289
|
-
|
|
2290
|
-
return this.renderer.backend.device.limits.maxUniformBufferBindingSize;
|
|
2291
|
-
|
|
2292
|
-
}
|
|
2293
|
-
|
|
2294
2313
|
/**
|
|
2295
2314
|
* Returns the native shader method name for a given generic name.
|
|
2296
2315
|
*
|
|
@@ -2352,15 +2371,15 @@ ${shaderData.uniforms}
|
|
|
2352
2371
|
${shaderData.varyings}
|
|
2353
2372
|
var<private> varyings : VaryingsStruct;
|
|
2354
2373
|
|
|
2374
|
+
// vars
|
|
2375
|
+
${shaderData.vars}
|
|
2376
|
+
|
|
2355
2377
|
// codes
|
|
2356
2378
|
${shaderData.codes}
|
|
2357
2379
|
|
|
2358
2380
|
@vertex
|
|
2359
2381
|
fn main( ${shaderData.attributes} ) -> VaryingsStruct {
|
|
2360
2382
|
|
|
2361
|
-
// vars
|
|
2362
|
-
${shaderData.vars}
|
|
2363
|
-
|
|
2364
2383
|
// flow
|
|
2365
2384
|
${shaderData.flow}
|
|
2366
2385
|
|
|
@@ -2390,15 +2409,15 @@ ${shaderData.structs}
|
|
|
2390
2409
|
// uniforms
|
|
2391
2410
|
${shaderData.uniforms}
|
|
2392
2411
|
|
|
2412
|
+
// vars
|
|
2413
|
+
${shaderData.vars}
|
|
2414
|
+
|
|
2393
2415
|
// codes
|
|
2394
2416
|
${shaderData.codes}
|
|
2395
2417
|
|
|
2396
2418
|
@fragment
|
|
2397
2419
|
fn main( ${shaderData.varyings} ) -> ${shaderData.returnType} {
|
|
2398
2420
|
|
|
2399
|
-
// vars
|
|
2400
|
-
${shaderData.vars}
|
|
2401
|
-
|
|
2402
2421
|
// flow
|
|
2403
2422
|
${shaderData.flow}
|
|
2404
2423
|
|
|
@@ -2435,20 +2454,23 @@ ${ shaderData.structs }
|
|
|
2435
2454
|
// uniforms
|
|
2436
2455
|
${ shaderData.uniforms }
|
|
2437
2456
|
|
|
2457
|
+
// vars
|
|
2458
|
+
${ this.allowGlobalVariables ? shaderData.vars : '' }
|
|
2459
|
+
|
|
2438
2460
|
// codes
|
|
2439
2461
|
${ shaderData.codes }
|
|
2440
2462
|
|
|
2441
2463
|
@compute @workgroup_size( ${ workgroupSizeX }, ${ workgroupSizeY }, ${ workgroupSizeZ } )
|
|
2442
2464
|
fn main( ${ shaderData.attributes } ) {
|
|
2443
2465
|
|
|
2466
|
+
// local vars
|
|
2467
|
+
${ this.allowGlobalVariables ? '' : shaderData.vars }
|
|
2468
|
+
|
|
2444
2469
|
// system
|
|
2445
2470
|
instanceIndex = globalId.x
|
|
2446
2471
|
+ globalId.y * ( ${ workgroupSizeX } * numWorkgroups.x )
|
|
2447
2472
|
+ globalId.z * ( ${ workgroupSizeX } * numWorkgroups.x ) * ( ${ workgroupSizeY } * numWorkgroups.y );
|
|
2448
2473
|
|
|
2449
|
-
// vars
|
|
2450
|
-
${ shaderData.vars }
|
|
2451
|
-
|
|
2452
2474
|
// flow
|
|
2453
2475
|
${ shaderData.flow }
|
|
2454
2476
|
|
|
@@ -315,51 +315,137 @@ class WebGPUAttributeUtils {
|
|
|
315
315
|
|
|
316
316
|
/**
|
|
317
317
|
* This method performs a readback operation by moving buffer data from
|
|
318
|
-
* a storage buffer attribute from the GPU to the CPU.
|
|
318
|
+
* a storage buffer attribute from the GPU to the CPU. ReadbackBuffer can
|
|
319
|
+
* be used to retain and reuse handles to the intermediate buffers and prevent
|
|
320
|
+
* new allocation.
|
|
319
321
|
*
|
|
320
322
|
* @async
|
|
321
|
-
* @param {
|
|
322
|
-
* @
|
|
323
|
+
* @param {BufferAttribute} attribute - The storage buffer attribute to read frm.
|
|
324
|
+
* @param {number} count - The offset from which to start reading the
|
|
325
|
+
* @param {number} offset - The storage buffer attribute.
|
|
326
|
+
* @param {ReadbackBuffer|ArrayBuffer} target - The storage buffer attribute.
|
|
327
|
+
* @return {Promise<ArrayBuffer|ReadbackBuffer>} A promise that resolves with the buffer data when the data are ready.
|
|
323
328
|
*/
|
|
324
|
-
async getArrayBufferAsync( attribute ) {
|
|
329
|
+
async getArrayBufferAsync( attribute, target = null, offset = 0, count = - 1 ) {
|
|
325
330
|
|
|
326
331
|
const backend = this.backend;
|
|
327
332
|
const device = backend.device;
|
|
328
333
|
|
|
329
334
|
const data = backend.get( this._getBufferAttribute( attribute ) );
|
|
330
335
|
const bufferGPU = data.buffer;
|
|
331
|
-
const
|
|
336
|
+
const byteLength = count === - 1 ? bufferGPU.size - offset : count;
|
|
332
337
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
+
let readBufferGPU;
|
|
339
|
+
if ( target !== null && target.isReadbackBuffer ) {
|
|
340
|
+
|
|
341
|
+
const readbackInfo = backend.get( target );
|
|
342
|
+
|
|
343
|
+
if ( target._mapped === true ) {
|
|
344
|
+
|
|
345
|
+
throw new Error( 'WebGPURenderer: ReadbackBuffer must be released before being used again.' );
|
|
346
|
+
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
target._mapped = true;
|
|
350
|
+
|
|
351
|
+
// initialize the GPU-side read copy buffer if it is not present
|
|
352
|
+
if ( readbackInfo.readBufferGPU === undefined ) {
|
|
353
|
+
|
|
354
|
+
readBufferGPU = device.createBuffer( {
|
|
355
|
+
label: `${ target.name }_readback`,
|
|
356
|
+
size: target.maxByteLength,
|
|
357
|
+
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ
|
|
358
|
+
} );
|
|
359
|
+
|
|
360
|
+
// release / dispose
|
|
361
|
+
const releaseCallback = () => {
|
|
338
362
|
|
|
363
|
+
target.buffer = null;
|
|
364
|
+
target._mapped = false;
|
|
365
|
+
|
|
366
|
+
readBufferGPU.unmap();
|
|
367
|
+
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
const disposeCallback = () => {
|
|
371
|
+
|
|
372
|
+
target.buffer = null;
|
|
373
|
+
target._mapped = false;
|
|
374
|
+
|
|
375
|
+
readBufferGPU.destroy();
|
|
376
|
+
|
|
377
|
+
backend.delete( target );
|
|
378
|
+
|
|
379
|
+
target.removeEventListener( 'release', releaseCallback );
|
|
380
|
+
target.removeEventListener( 'dispose', disposeCallback );
|
|
381
|
+
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
target.addEventListener( 'release', releaseCallback );
|
|
385
|
+
target.addEventListener( 'dispose', disposeCallback );
|
|
386
|
+
|
|
387
|
+
// register
|
|
388
|
+
readbackInfo.readBufferGPU = readBufferGPU;
|
|
389
|
+
|
|
390
|
+
} else {
|
|
391
|
+
|
|
392
|
+
readBufferGPU = readbackInfo.readBufferGPU;
|
|
393
|
+
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
} else {
|
|
397
|
+
|
|
398
|
+
// create a new temp buffer for array buffers otherwise
|
|
399
|
+
readBufferGPU = device.createBuffer( {
|
|
400
|
+
label: `${ attribute.name }_readback`,
|
|
401
|
+
size: byteLength,
|
|
402
|
+
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ
|
|
403
|
+
} );
|
|
404
|
+
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// copy the data
|
|
339
408
|
const cmdEncoder = device.createCommandEncoder( {
|
|
340
409
|
label: `readback_encoder_${ attribute.name }`
|
|
341
410
|
} );
|
|
342
411
|
|
|
343
412
|
cmdEncoder.copyBufferToBuffer(
|
|
344
413
|
bufferGPU,
|
|
345
|
-
|
|
414
|
+
offset,
|
|
346
415
|
readBufferGPU,
|
|
347
416
|
0,
|
|
348
|
-
|
|
417
|
+
byteLength,
|
|
349
418
|
);
|
|
350
419
|
|
|
351
420
|
const gpuCommands = cmdEncoder.finish();
|
|
352
421
|
device.queue.submit( [ gpuCommands ] );
|
|
353
422
|
|
|
354
|
-
|
|
423
|
+
// map the data to the CPU
|
|
424
|
+
await readBufferGPU.mapAsync( GPUMapMode.READ, 0, byteLength );
|
|
425
|
+
|
|
426
|
+
if ( target === null ) {
|
|
355
427
|
|
|
356
|
-
|
|
428
|
+
// return a new array buffer and clean up the gpu handles
|
|
429
|
+
const arrayBuffer = readBufferGPU.getMappedRange( 0, byteLength );
|
|
430
|
+
const result = arrayBuffer.slice();
|
|
431
|
+
readBufferGPU.destroy();
|
|
432
|
+
return result;
|
|
357
433
|
|
|
358
|
-
|
|
434
|
+
} else if ( target.isReadbackBuffer ) {
|
|
359
435
|
|
|
360
|
-
|
|
436
|
+
// assign the data to the read back handle
|
|
437
|
+
target.buffer = readBufferGPU.getMappedRange( 0, byteLength );
|
|
438
|
+
return target;
|
|
361
439
|
|
|
362
|
-
|
|
440
|
+
} else {
|
|
441
|
+
|
|
442
|
+
// copy the data into the target array buffer
|
|
443
|
+
const arrayBuffer = readBufferGPU.getMappedRange( 0, byteLength );
|
|
444
|
+
new Uint8Array( target ).set( new Uint8Array( arrayBuffer ) );
|
|
445
|
+
readBufferGPU.destroy();
|
|
446
|
+
return target;
|
|
447
|
+
|
|
448
|
+
}
|
|
363
449
|
|
|
364
450
|
}
|
|
365
451
|
|
|
@@ -520,7 +520,7 @@ class WebGPUBindingUtils {
|
|
|
520
520
|
|
|
521
521
|
}
|
|
522
522
|
|
|
523
|
-
} else if ( binding.texture.isDataTexture || binding.texture.isDataArrayTexture || binding.texture.isData3DTexture ) {
|
|
523
|
+
} else if ( binding.texture.isDataTexture || binding.texture.isDataArrayTexture || binding.texture.isData3DTexture || binding.texture.isStorageTexture ) {
|
|
524
524
|
|
|
525
525
|
const type = binding.texture.type;
|
|
526
526
|
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A WebGPU backend utility module for managing the device's capabilities.
|
|
3
|
+
*
|
|
4
|
+
* @private
|
|
5
|
+
*/
|
|
6
|
+
class WebGPUCapabilities {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Constructs a new utility object.
|
|
10
|
+
*
|
|
11
|
+
* @param {WebGPUBackend} backend - The WebGPU backend.
|
|
12
|
+
*/
|
|
13
|
+
constructor( backend ) {
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A reference to the WebGPU backend.
|
|
17
|
+
*
|
|
18
|
+
* @type {WebGPUBackend}
|
|
19
|
+
*/
|
|
20
|
+
this.backend = backend;
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Returns the maximum anisotropy texture filtering value.
|
|
26
|
+
*
|
|
27
|
+
* @return {number} The maximum anisotropy texture filtering value.
|
|
28
|
+
*/
|
|
29
|
+
getMaxAnisotropy() {
|
|
30
|
+
|
|
31
|
+
return 16;
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Returns the maximum number of bytes available for uniform buffers.
|
|
37
|
+
*
|
|
38
|
+
* @return {number} The maximum number of bytes available for uniform buffers.
|
|
39
|
+
*/
|
|
40
|
+
getUniformBufferLimit() {
|
|
41
|
+
|
|
42
|
+
return this.backend.device.limits.maxUniformBufferBindingSize;
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default WebGPUCapabilities;
|
|
@@ -96,6 +96,8 @@ export const GPUTextureFormat = {
|
|
|
96
96
|
RG8Snorm: 'rg8snorm',
|
|
97
97
|
RG8Uint: 'rg8uint',
|
|
98
98
|
RG8Sint: 'rg8sint',
|
|
99
|
+
R16Unorm: 'r16unorm',
|
|
100
|
+
R16Snorm: 'r16snorm',
|
|
99
101
|
|
|
100
102
|
// 32-bit formats
|
|
101
103
|
|
|
@@ -112,7 +114,11 @@ export const GPUTextureFormat = {
|
|
|
112
114
|
RGBA8Sint: 'rgba8sint',
|
|
113
115
|
BGRA8Unorm: 'bgra8unorm',
|
|
114
116
|
BGRA8UnormSRGB: 'bgra8unorm-srgb',
|
|
117
|
+
RG16Unorm: 'rg16unorm',
|
|
118
|
+
RG16Snorm: 'rg16snorm',
|
|
119
|
+
|
|
115
120
|
// Packed 32-bit formats
|
|
121
|
+
|
|
116
122
|
RGB9E5UFloat: 'rgb9e5ufloat',
|
|
117
123
|
RGB10A2Unorm: 'rgb10a2unorm',
|
|
118
124
|
RG11B10UFloat: 'rg11b10ufloat',
|
|
@@ -125,6 +131,8 @@ export const GPUTextureFormat = {
|
|
|
125
131
|
RGBA16Uint: 'rgba16uint',
|
|
126
132
|
RGBA16Sint: 'rgba16sint',
|
|
127
133
|
RGBA16Float: 'rgba16float',
|
|
134
|
+
RGBA16Unorm: 'rgba16unorm',
|
|
135
|
+
RGBA16Snorm: 'rgba16snorm',
|
|
128
136
|
|
|
129
137
|
// 128-bit formats
|
|
130
138
|
|