super-three 0.168.0 → 0.169.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 +369 -131
- package/build/three.module.js +369 -131
- package/build/three.module.min.js +1 -1
- package/build/three.webgpu.js +24644 -22406
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +79941 -0
- package/build/three.webgpu.nodes.min.js +6 -0
- package/examples/jsm/Addons.js +0 -6
- package/examples/jsm/controls/TrackballControls.js +32 -12
- package/examples/jsm/controls/TransformControls.js +97 -62
- package/examples/jsm/exporters/DRACOExporter.js +4 -2
- package/examples/jsm/exporters/EXRExporter.js +19 -11
- package/examples/jsm/exporters/KTX2Exporter.js +21 -13
- package/examples/jsm/exporters/OBJExporter.js +5 -1
- package/examples/jsm/exporters/PLYExporter.js +9 -7
- package/examples/jsm/geometries/DecalGeometry.js +4 -1
- package/examples/jsm/geometries/InstancedPointsGeometry.js +1 -1
- package/examples/jsm/helpers/LightProbeHelper.js +1 -1
- package/examples/jsm/helpers/LightProbeHelperGPU.js +65 -0
- package/examples/jsm/libs/basis/basis_transcoder.js +8 -10
- package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
- package/examples/jsm/libs/ktx-parse.module.js +1 -1
- package/examples/jsm/lights/LightProbeGenerator.js +24 -10
- package/examples/jsm/loaders/ColladaLoader.js +9 -6
- package/examples/jsm/loaders/DRACOLoader.js +3 -1
- package/examples/jsm/loaders/FBXLoader.js +30 -20
- package/examples/jsm/loaders/GLTFLoader.js +5 -10
- package/examples/jsm/loaders/KTX2Loader.js +10 -7
- package/examples/jsm/loaders/MTLLoader.js +4 -3
- package/examples/jsm/loaders/MaterialXLoader.js +29 -10
- package/examples/jsm/loaders/OBJLoader.js +5 -3
- package/examples/jsm/loaders/PCDLoader.js +5 -4
- package/examples/jsm/loaders/PDBLoader.js +3 -2
- package/examples/jsm/loaders/PLYLoader.js +8 -5
- package/examples/jsm/loaders/STLLoader.js +3 -2
- package/examples/jsm/loaders/VRMLLoader.js +10 -10
- package/examples/jsm/loaders/VTKLoader.js +4 -3
- package/examples/jsm/loaders/XYZLoader.js +3 -2
- package/examples/jsm/misc/Timer.js +1 -1
- package/examples/jsm/modifiers/CurveModifierGPU.js +233 -0
- package/examples/jsm/objects/LensflareMesh.js +322 -0
- package/examples/jsm/objects/SkyMesh.js +1 -2
- package/examples/jsm/objects/Water2Mesh.js +2 -3
- package/examples/jsm/objects/WaterMesh.js +1 -2
- package/examples/jsm/physics/JoltPhysics.js +1 -1
- package/examples/jsm/physics/RapierPhysics.js +1 -1
- package/examples/jsm/transpiler/GLSLDecoder.js +1 -1
- package/examples/jsm/transpiler/ShaderToyDecoder.js +2 -2
- package/examples/jsm/utils/GeometryCompressionUtils.js +37 -122
- package/examples/jsm/utils/ShadowMapViewer.js +3 -8
- package/examples/jsm/utils/ShadowMapViewerGPU.js +201 -0
- package/examples/jsm/utils/SkeletonUtils.js +84 -66
- package/examples/jsm/utils/TextureUtils.js +1 -0
- package/examples/jsm/utils/TextureUtilsGPU.js +63 -0
- package/examples/jsm/webxr/XRControllerModelFactory.js +1 -1
- package/package.json +2 -2
- package/src/Three.WebGPU.Nodes.js +200 -0
- package/src/Three.WebGPU.js +2 -1
- package/src/audio/Audio.js +2 -2
- package/src/constants.js +1 -1
- package/src/core/BufferAttribute.js +0 -9
- package/src/core/Clock.js +1 -1
- package/src/core/InterleavedBuffer.js +0 -9
- package/src/extras/Controls.js +1 -1
- package/src/geometries/CylinderGeometry.js +11 -4
- package/src/loaders/MaterialLoader.js +7 -1
- package/src/loaders/nodes/NodeLoader.js +24 -4
- package/src/loaders/nodes/NodeMaterialLoader.js +21 -17
- package/src/loaders/nodes/NodeObjectLoader.js +19 -0
- package/src/materials/nodes/InstancedPointsNodeMaterial.js +19 -34
- package/src/materials/nodes/Line2NodeMaterial.js +26 -26
- package/src/materials/nodes/LineBasicNodeMaterial.js +7 -3
- package/src/materials/nodes/LineDashedNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshBasicNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshLambertNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshMatcapNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshNormalNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshPhongNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +6 -3
- package/src/materials/nodes/MeshSSSNodeMaterial.js +6 -3
- package/src/materials/nodes/MeshStandardNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshToonNodeMaterial.js +7 -3
- package/src/materials/nodes/NodeMaterial.js +20 -45
- package/src/materials/nodes/NodeMaterials.js +2 -0
- package/src/materials/nodes/PointsNodeMaterial.js +7 -3
- package/src/materials/nodes/ShadowNodeMaterial.js +7 -3
- package/src/materials/nodes/SpriteNodeMaterial.js +39 -6
- package/src/materials/nodes/VolumeNodeMaterial.js +13 -9
- package/src/materials/nodes/manager/NodeMaterialObserver.js +302 -0
- package/src/math/Triangle.js +24 -0
- package/src/nodes/Nodes.js +3 -3
- package/src/nodes/TSL.js +96 -93
- package/src/nodes/accessors/BatchNode.js +7 -3
- package/src/nodes/accessors/BufferAttributeNode.js +6 -3
- package/src/nodes/accessors/BufferNode.js +6 -3
- package/src/nodes/accessors/Camera.js +10 -16
- package/src/nodes/accessors/ClippingNode.js +7 -3
- package/src/nodes/accessors/CubeTextureNode.js +6 -3
- package/src/nodes/accessors/InstanceNode.js +11 -11
- package/src/nodes/accessors/InstancedPointsMaterialNode.js +6 -3
- package/src/nodes/accessors/Lights.js +51 -0
- package/src/nodes/accessors/MaterialNode.js +8 -4
- package/src/nodes/accessors/MaterialReferenceNode.js +6 -3
- package/src/nodes/accessors/ModelNode.js +42 -7
- package/src/nodes/accessors/ModelViewProjectionNode.js +9 -5
- package/src/nodes/accessors/MorphNode.js +7 -3
- package/src/nodes/accessors/Normal.js +32 -6
- package/src/nodes/accessors/Object3DNode.js +11 -27
- package/src/nodes/accessors/PointUVNode.js +7 -3
- package/src/nodes/accessors/ReferenceBaseNode.js +32 -4
- package/src/nodes/accessors/ReferenceNode.js +40 -3
- package/src/nodes/accessors/RendererReferenceNode.js +9 -3
- package/src/nodes/accessors/SceneNode.js +7 -3
- package/src/nodes/accessors/SkinningNode.js +7 -3
- package/src/nodes/accessors/StorageBufferNode.js +21 -3
- package/src/nodes/accessors/StorageTextureNode.js +7 -4
- package/src/nodes/accessors/Texture3DNode.js +7 -4
- package/src/nodes/accessors/TextureNode.js +19 -8
- package/src/nodes/accessors/TextureSizeNode.js +8 -5
- package/src/nodes/accessors/UniformArrayNode.js +12 -9
- package/src/nodes/accessors/UserDataNode.js +9 -6
- package/src/nodes/accessors/VelocityNode.js +74 -23
- package/src/nodes/accessors/VertexColorNode.js +6 -3
- package/src/nodes/code/CodeNode.js +7 -3
- package/src/nodes/code/ExpressionNode.js +8 -4
- package/src/nodes/code/FunctionCallNode.js +6 -3
- package/src/nodes/code/FunctionNode.js +6 -3
- package/src/nodes/code/ScriptableNode.js +11 -6
- package/src/nodes/code/ScriptableValueNode.js +7 -3
- package/src/nodes/core/AssignNode.js +9 -6
- package/src/nodes/core/AttributeNode.js +7 -3
- package/src/nodes/core/BypassNode.js +8 -4
- package/src/nodes/core/CacheNode.js +8 -4
- package/src/nodes/core/ConstNode.js +6 -3
- package/src/nodes/core/ContextNode.js +7 -3
- package/src/nodes/core/IndexNode.js +25 -3
- package/src/nodes/core/InputNode.js +7 -3
- package/src/nodes/core/MRTNode.js +6 -3
- package/src/nodes/core/Node.js +10 -51
- package/src/nodes/core/NodeBuilder.js +71 -5
- package/src/nodes/core/NodeUtils.js +48 -6
- package/src/nodes/core/OutputStructNode.js +8 -4
- package/src/nodes/core/ParameterNode.js +6 -3
- package/src/nodes/core/PropertyNode.js +7 -3
- package/src/nodes/core/StackNode.js +7 -3
- package/src/nodes/core/StructTypeNode.js +7 -3
- package/src/nodes/core/TempNode.js +8 -4
- package/src/nodes/core/UniformGroupNode.js +10 -6
- package/src/nodes/core/UniformNode.js +6 -3
- package/src/nodes/core/VarNode.js +8 -4
- package/src/nodes/core/VaryingNode.js +7 -3
- package/src/nodes/display/AfterImageNode.js +6 -0
- package/src/nodes/display/AnaglyphPassNode.js +6 -0
- package/src/nodes/display/AnamorphicNode.js +6 -0
- package/src/nodes/display/BloomNode.js +6 -0
- package/src/nodes/display/BumpMapNode.js +6 -0
- package/src/nodes/display/ColorSpaceFunctions.js +4 -4
- package/src/nodes/display/ColorSpaceNode.js +43 -14
- package/src/nodes/display/DenoiseNode.js +6 -3
- package/src/nodes/display/DepthOfFieldNode.js +6 -3
- package/src/nodes/display/DotScreenNode.js +8 -5
- package/src/nodes/display/FXAANode.js +6 -3
- package/src/nodes/display/FilmNode.js +6 -3
- package/src/nodes/display/FrontFacingNode.js +7 -3
- package/src/nodes/display/GTAONode.js +6 -3
- package/src/nodes/display/GaussianBlurNode.js +6 -3
- package/src/nodes/display/Lut3DNode.js +6 -3
- package/src/nodes/display/NormalMapNode.js +8 -6
- package/src/nodes/display/ParallaxBarrierPassNode.js +8 -5
- package/src/nodes/display/PassNode.js +18 -7
- package/src/nodes/display/PixelationPassNode.js +12 -5
- package/src/nodes/display/PosterizeNode.js +6 -3
- package/src/nodes/display/RGBShiftNode.js +6 -3
- package/src/nodes/display/RenderOutputNode.js +12 -8
- package/src/nodes/display/SSAAPassNode.js +6 -3
- package/src/nodes/display/ScreenNode.js +181 -0
- package/src/nodes/display/SobelOperatorNode.js +6 -3
- package/src/nodes/display/StereoCompositePassNode.js +6 -3
- package/src/nodes/display/StereoPassNode.js +6 -3
- package/src/nodes/display/ToneMappingFunctions.js +12 -12
- package/src/nodes/display/ToneMappingNode.js +8 -7
- package/src/nodes/display/ToonOutlinePassNode.js +111 -0
- package/src/nodes/display/TransitionNode.js +6 -3
- package/src/nodes/display/ViewportDepthNode.js +7 -3
- package/src/nodes/display/ViewportDepthTextureNode.js +8 -5
- package/src/nodes/display/ViewportSharedTextureNode.js +8 -5
- package/src/nodes/display/ViewportTextureNode.js +8 -5
- package/src/nodes/fog/FogExp2Node.js +6 -3
- package/src/nodes/fog/FogNode.js +7 -3
- package/src/nodes/fog/FogRangeNode.js +6 -3
- package/src/nodes/functions/PhysicalLightingModel.js +2 -2
- package/src/nodes/functions/material/getShIrradianceAt.js +28 -0
- package/src/nodes/geometry/RangeNode.js +7 -3
- package/src/nodes/gpgpu/AtomicFunctionNode.js +99 -0
- package/src/nodes/gpgpu/BarrierNode.js +40 -0
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +98 -0
- package/src/nodes/gpgpu/ComputeNode.js +8 -4
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +100 -0
- package/src/nodes/lighting/AONode.js +6 -3
- package/src/nodes/lighting/AmbientLightNode.js +6 -3
- package/src/nodes/lighting/AnalyticLightNode.js +198 -30
- package/src/nodes/lighting/BasicEnvironmentNode.js +6 -3
- package/src/nodes/lighting/BasicLightMapNode.js +6 -3
- package/src/nodes/lighting/DirectionalLightNode.js +7 -4
- package/src/nodes/lighting/EnvironmentNode.js +6 -3
- package/src/nodes/lighting/HemisphereLightNode.js +10 -6
- package/src/nodes/lighting/IESSpotLightNode.js +6 -3
- package/src/nodes/lighting/IrradianceNode.js +6 -3
- package/src/nodes/lighting/LightProbeNode.js +8 -31
- package/src/nodes/lighting/LightingContextNode.js +6 -3
- package/src/nodes/lighting/LightingNode.js +7 -3
- package/src/nodes/lighting/LightsNode.js +24 -5
- package/src/nodes/lighting/PointLightNode.js +11 -7
- package/src/nodes/lighting/RectAreaLightNode.js +11 -7
- package/src/nodes/lighting/SpotLightNode.js +13 -10
- package/src/nodes/math/ConditionalNode.js +23 -6
- package/src/nodes/math/MathNode.js +6 -3
- package/src/nodes/math/OperatorNode.js +6 -3
- package/src/nodes/pmrem/PMREMNode.js +6 -3
- package/src/nodes/utils/ArrayElementNode.js +8 -4
- package/src/nodes/utils/ConvertNode.js +7 -3
- package/src/nodes/utils/CubeMapNode.js +6 -3
- package/src/nodes/utils/EquirectUVNode.js +6 -3
- package/src/nodes/utils/FlipNode.js +7 -4
- package/src/nodes/utils/FunctionOverloadingNode.js +7 -3
- package/src/nodes/utils/JoinNode.js +6 -3
- package/src/nodes/utils/LoopNode.js +7 -3
- package/src/nodes/utils/MatcapUVNode.js +6 -3
- package/src/nodes/utils/MaxMipLevelNode.js +6 -3
- package/src/nodes/utils/OscNode.js +7 -3
- package/src/nodes/utils/RTTNode.js +6 -3
- package/src/nodes/utils/ReflectorNode.js +8 -5
- package/src/nodes/utils/RemapNode.js +7 -3
- package/src/nodes/utils/RotateNode.js +6 -3
- package/src/nodes/utils/SetNode.js +7 -4
- package/src/nodes/utils/SplitNode.js +7 -3
- package/src/nodes/utils/SpriteSheetUVNode.js +7 -3
- package/src/nodes/utils/StorageArrayElementNode.js +9 -8
- package/src/nodes/utils/TimerNode.js +6 -3
- package/src/nodes/utils/TriplanarTexturesNode.js +7 -3
- package/src/nodes/utils/ViewportUtils.js +2 -2
- package/src/objects/BatchedMesh.js +76 -10
- package/src/objects/LOD.js +21 -0
- package/src/objects/Line.js +1 -0
- package/src/objects/Mesh.js +7 -23
- package/src/objects/Points.js +2 -0
- package/src/renderers/WebGLRenderer.js +64 -41
- package/src/renderers/common/BundleGroup.js +26 -0
- package/src/renderers/common/ClippingContext.js +4 -3
- package/src/renderers/common/RenderContext.js +4 -5
- package/src/renderers/common/RenderObject.js +116 -5
- package/src/renderers/common/RenderObjects.js +8 -1
- package/src/renderers/common/Renderer.js +57 -49
- package/src/renderers/common/extras/PMREMGenerator.js +7 -9
- package/src/renderers/common/nodes/NodeBuilderState.js +3 -3
- package/src/renderers/common/nodes/Nodes.js +33 -14
- package/src/renderers/shaders/ShaderLib/sprite.glsl.js +2 -4
- package/src/renderers/webgl/WebGLAttributes.js +45 -14
- package/src/renderers/webgl/WebGLCapabilities.js +9 -0
- package/src/renderers/webgl/WebGLProgram.js +2 -0
- package/src/renderers/webgl/WebGLPrograms.js +21 -17
- package/src/renderers/webgl/WebGLState.js +21 -0
- package/src/renderers/webgl/WebGLTextures.js +22 -0
- package/src/renderers/webgl-fallback/WebGLBackend.js +50 -45
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +4 -4
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +6 -0
- package/src/renderers/webgl-fallback/utils/WebGLState.js +1 -4
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +61 -16
- package/src/renderers/webgpu/WebGPUBackend.js +33 -25
- package/src/renderers/webgpu/WebGPURenderer.Nodes.js +42 -0
- package/src/renderers/webgpu/WebGPURenderer.js +5 -2
- package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +59 -0
- package/src/renderers/{common → webgpu}/nodes/StandardNodeLibrary.js +11 -11
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +91 -11
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +6 -16
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +1 -1
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +7 -5
- package/src/renderers/webgpu/utils/WebGPUUtils.js +1 -1
- package/src/utils.js +33 -1
- package/examples/jsm/geometries/SDFGeometryGenerator.js +0 -144
- package/examples/jsm/loaders/TiltLoader.js +0 -520
- package/examples/jsm/utils/GPUStatsPanel.js +0 -95
- package/examples/jsm/utils/PackedPhongMaterial.js +0 -178
- package/src/nodes/display/ViewportNode.js +0 -138
- package/src/nodes/lighting/LightNode.js +0 -57
- package/src/renderers/common/StandardRenderer.js +0 -18
|
@@ -94,7 +94,8 @@ fn tsl_repeatWrapping( uv : vec2<f32>, dimension : vec2<u32> ) -> vec2<u32> {
|
|
|
94
94
|
biquadraticTexture: new CodeNode( `
|
|
95
95
|
fn tsl_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, level : i32 ) -> vec4f {
|
|
96
96
|
|
|
97
|
-
let
|
|
97
|
+
let iRes = vec2i( textureDimensions( map, level ) );
|
|
98
|
+
let res = vec2f( iRes );
|
|
98
99
|
|
|
99
100
|
let uvScaled = coord * res;
|
|
100
101
|
let uvWrapping = ( ( uvScaled % res ) + res ) % res;
|
|
@@ -105,10 +106,10 @@ fn tsl_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, level : i32 ) -
|
|
|
105
106
|
let iuv = floor( uv );
|
|
106
107
|
let f = fract( uv );
|
|
107
108
|
|
|
108
|
-
let rg1 = textureLoad( map, vec2i( iuv + vec2( 0.5, 0.5 ) ), level );
|
|
109
|
-
let rg2 = textureLoad( map, vec2i( iuv + vec2( 1.5, 0.5 ) ), level );
|
|
110
|
-
let rg3 = textureLoad( map, vec2i( iuv + vec2( 0.5, 1.5 ) ), level );
|
|
111
|
-
let rg4 = textureLoad( map, vec2i( iuv + vec2( 1.5, 1.5 ) ), level );
|
|
109
|
+
let rg1 = textureLoad( map, vec2i( iuv + vec2( 0.5, 0.5 ) ) % iRes, level );
|
|
110
|
+
let rg2 = textureLoad( map, vec2i( iuv + vec2( 1.5, 0.5 ) ) % iRes, level );
|
|
111
|
+
let rg3 = textureLoad( map, vec2i( iuv + vec2( 0.5, 1.5 ) ) % iRes, level );
|
|
112
|
+
let rg4 = textureLoad( map, vec2i( iuv + vec2( 1.5, 1.5 ) ) % iRes, level );
|
|
112
113
|
|
|
113
114
|
return mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );
|
|
114
115
|
|
|
@@ -149,6 +150,16 @@ if ( /Windows/g.test( navigator.userAgent ) ) {
|
|
|
149
150
|
|
|
150
151
|
//
|
|
151
152
|
|
|
153
|
+
let diagnostics = '';
|
|
154
|
+
|
|
155
|
+
if ( /Firefox/g.test( navigator.userAgent ) !== true ) {
|
|
156
|
+
|
|
157
|
+
diagnostics += 'diagnostic( off, derivative_uniformity );\n';
|
|
158
|
+
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
//
|
|
162
|
+
|
|
152
163
|
class WGSLNodeBuilder extends NodeBuilder {
|
|
153
164
|
|
|
154
165
|
constructor( object, renderer ) {
|
|
@@ -161,6 +172,8 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
161
172
|
|
|
162
173
|
this.directives = {};
|
|
163
174
|
|
|
175
|
+
this.scopedArrays = new Map();
|
|
176
|
+
|
|
164
177
|
}
|
|
165
178
|
|
|
166
179
|
needsToWorkingColorSpace( texture ) {
|
|
@@ -571,6 +584,12 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
571
584
|
|
|
572
585
|
}
|
|
573
586
|
|
|
587
|
+
hasBuiltin( name, shaderStage = this.shaderStage ) {
|
|
588
|
+
|
|
589
|
+
return ( this.builtins[ shaderStage ] !== undefined && this.builtins[ shaderStage ].has( name ) );
|
|
590
|
+
|
|
591
|
+
}
|
|
592
|
+
|
|
574
593
|
getVertexIndex() {
|
|
575
594
|
|
|
576
595
|
if ( this.shaderStage === 'vertex' ) {
|
|
@@ -643,11 +662,19 @@ ${ flowData.code }
|
|
|
643
662
|
|
|
644
663
|
}
|
|
645
664
|
|
|
665
|
+
getInvocationSubgroupIndex() {
|
|
666
|
+
|
|
667
|
+
this.enableSubGroups();
|
|
668
|
+
|
|
669
|
+
return this.getBuiltin( 'subgroup_invocation_id', 'invocationSubgroupIndex', 'u32', 'attribute' );
|
|
670
|
+
|
|
671
|
+
}
|
|
672
|
+
|
|
646
673
|
getSubgroupIndex() {
|
|
647
674
|
|
|
648
675
|
this.enableSubGroups();
|
|
649
676
|
|
|
650
|
-
return this.getBuiltin( '
|
|
677
|
+
return this.getBuiltin( 'subgroup_id', 'subgroupIndex', 'u32', 'attribute' );
|
|
651
678
|
|
|
652
679
|
}
|
|
653
680
|
|
|
@@ -756,6 +783,45 @@ ${ flowData.code }
|
|
|
756
783
|
|
|
757
784
|
}
|
|
758
785
|
|
|
786
|
+
getScopedArray( name, scope, bufferType, bufferCount ) {
|
|
787
|
+
|
|
788
|
+
if ( this.scopedArrays.has( name ) === false ) {
|
|
789
|
+
|
|
790
|
+
this.scopedArrays.set( name, {
|
|
791
|
+
name,
|
|
792
|
+
scope,
|
|
793
|
+
bufferType,
|
|
794
|
+
bufferCount
|
|
795
|
+
} );
|
|
796
|
+
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
return name;
|
|
800
|
+
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
getScopedArrays( shaderStage ) {
|
|
804
|
+
|
|
805
|
+
if ( shaderStage !== 'compute' ) {
|
|
806
|
+
|
|
807
|
+
return;
|
|
808
|
+
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
const snippets = [];
|
|
812
|
+
|
|
813
|
+
for ( const { name, scope, bufferType, bufferCount } of this.scopedArrays.values() ) {
|
|
814
|
+
|
|
815
|
+
const type = this.getType( bufferType );
|
|
816
|
+
|
|
817
|
+
snippets.push( `var<${scope}> ${name}: array< ${type}, ${bufferCount} >;` );
|
|
818
|
+
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
return snippets.join( '\n' );
|
|
822
|
+
|
|
823
|
+
}
|
|
824
|
+
|
|
759
825
|
getAttributes( shaderStage ) {
|
|
760
826
|
|
|
761
827
|
const snippets = [];
|
|
@@ -767,6 +833,13 @@ ${ flowData.code }
|
|
|
767
833
|
this.getBuiltin( 'local_invocation_id', 'localId', 'vec3<u32>', 'attribute' );
|
|
768
834
|
this.getBuiltin( 'num_workgroups', 'numWorkgroups', 'vec3<u32>', 'attribute' );
|
|
769
835
|
|
|
836
|
+
if ( this.renderer.hasFeature( 'subgroups' ) ) {
|
|
837
|
+
|
|
838
|
+
this.enableDirective( 'subgroups', shaderStage );
|
|
839
|
+
this.getBuiltin( 'subgroup_size', 'subgroupSize', 'u32', 'attribute' );
|
|
840
|
+
|
|
841
|
+
}
|
|
842
|
+
|
|
770
843
|
}
|
|
771
844
|
|
|
772
845
|
if ( shaderStage === 'vertex' || shaderStage === 'compute' ) {
|
|
@@ -926,8 +999,8 @@ ${ flowData.code }
|
|
|
926
999
|
|
|
927
1000
|
for ( const uniform of uniforms ) {
|
|
928
1001
|
|
|
929
|
-
const
|
|
930
|
-
const uniformIndexes = this.bindingsIndexes[
|
|
1002
|
+
const groupName = uniform.groupNode.name;
|
|
1003
|
+
const uniformIndexes = this.bindingsIndexes[ groupName ];
|
|
931
1004
|
|
|
932
1005
|
if ( uniform.type === 'texture' || uniform.type === 'cubeTexture' || uniform.type === 'storageTexture' || uniform.type === 'texture3D' ) {
|
|
933
1006
|
|
|
@@ -1001,7 +1074,8 @@ ${ flowData.code }
|
|
|
1001
1074
|
const bufferCount = bufferNode.bufferCount;
|
|
1002
1075
|
|
|
1003
1076
|
const bufferCountSnippet = bufferCount > 0 ? ', ' + bufferCount : '';
|
|
1004
|
-
const
|
|
1077
|
+
const bufferTypeSnippet = bufferNode.isAtomic ? `atomic<${bufferType}>` : `${bufferType}`;
|
|
1078
|
+
const bufferSnippet = `\t${ uniform.name } : array< ${ bufferTypeSnippet }${ bufferCountSnippet } >\n`;
|
|
1005
1079
|
const bufferAccessMode = bufferNode.isStorageBufferNode ? `storage, ${ this.getStorageAccess( bufferNode ) }` : 'uniform';
|
|
1006
1080
|
|
|
1007
1081
|
bufferSnippets.push( this._getWGSLStructBinding( 'NodeBuffer_' + bufferNode.id, bufferSnippet, bufferAccessMode, uniformIndexes.binding ++, uniformIndexes.group ) );
|
|
@@ -1043,6 +1117,8 @@ ${ flowData.code }
|
|
|
1043
1117
|
|
|
1044
1118
|
const shadersData = this.material !== null ? { fragment: {}, vertex: {} } : { compute: {} };
|
|
1045
1119
|
|
|
1120
|
+
this.sortBindingGroups();
|
|
1121
|
+
|
|
1046
1122
|
for ( const shaderStage in shadersData ) {
|
|
1047
1123
|
|
|
1048
1124
|
const stageData = shadersData[ shaderStage ];
|
|
@@ -1053,6 +1129,7 @@ ${ flowData.code }
|
|
|
1053
1129
|
stageData.vars = this.getVars( shaderStage );
|
|
1054
1130
|
stageData.codes = this.getCodes( shaderStage );
|
|
1055
1131
|
stageData.directives = this.getDirectives( shaderStage );
|
|
1132
|
+
stageData.scopedArrays = this.getScopedArrays( shaderStage );
|
|
1056
1133
|
|
|
1057
1134
|
//
|
|
1058
1135
|
|
|
@@ -1244,8 +1321,8 @@ fn main( ${shaderData.attributes} ) -> VaryingsStruct {
|
|
|
1244
1321
|
_getWGSLFragmentCode( shaderData ) {
|
|
1245
1322
|
|
|
1246
1323
|
return `${ this.getSignature() }
|
|
1247
|
-
|
|
1248
|
-
|
|
1324
|
+
// global
|
|
1325
|
+
${ diagnostics }
|
|
1249
1326
|
|
|
1250
1327
|
// uniforms
|
|
1251
1328
|
${shaderData.uniforms}
|
|
@@ -1279,6 +1356,9 @@ ${shaderData.directives}
|
|
|
1279
1356
|
// system
|
|
1280
1357
|
var<private> instanceIndex : u32;
|
|
1281
1358
|
|
|
1359
|
+
// locals
|
|
1360
|
+
${shaderData.scopedArrays}
|
|
1361
|
+
|
|
1282
1362
|
// uniforms
|
|
1283
1363
|
${shaderData.uniforms}
|
|
1284
1364
|
|
|
@@ -224,22 +224,12 @@ class WebGPUAttributeUtils {
|
|
|
224
224
|
const bufferGPU = data.buffer;
|
|
225
225
|
const size = bufferGPU.size;
|
|
226
226
|
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
const readBufferGPU = device.createBuffer( {
|
|
228
|
+
label: attribute.name,
|
|
229
|
+
size,
|
|
230
|
+
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ
|
|
231
|
+
} );
|
|
229
232
|
|
|
230
|
-
if ( readBufferGPU === undefined ) {
|
|
231
|
-
|
|
232
|
-
readBufferGPU = device.createBuffer( {
|
|
233
|
-
label: attribute.name,
|
|
234
|
-
size,
|
|
235
|
-
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ
|
|
236
|
-
} );
|
|
237
|
-
|
|
238
|
-
needsUnmap = false;
|
|
239
|
-
|
|
240
|
-
data.readBuffer = readBufferGPU;
|
|
241
|
-
|
|
242
|
-
}
|
|
243
233
|
|
|
244
234
|
const cmdEncoder = device.createCommandEncoder( {} );
|
|
245
235
|
|
|
@@ -251,7 +241,7 @@ class WebGPUAttributeUtils {
|
|
|
251
241
|
size
|
|
252
242
|
);
|
|
253
243
|
|
|
254
|
-
|
|
244
|
+
readBufferGPU.unmap();
|
|
255
245
|
|
|
256
246
|
const gpuCommands = cmdEncoder.finish();
|
|
257
247
|
device.queue.submit( [ gpuCommands ] );
|
|
@@ -138,7 +138,7 @@ class WebGPUPipelineUtils {
|
|
|
138
138
|
},
|
|
139
139
|
multisample: {
|
|
140
140
|
count: sampleCount,
|
|
141
|
-
alphaToCoverageEnabled: material.alphaToCoverage
|
|
141
|
+
alphaToCoverageEnabled: material.alphaToCoverage && sampleCount > 1
|
|
142
142
|
},
|
|
143
143
|
layout: device.createPipelineLayout( {
|
|
144
144
|
bindGroupLayouts
|
|
@@ -122,6 +122,8 @@ class WebGPUTextureUtils {
|
|
|
122
122
|
const dimension = this._getDimension( texture );
|
|
123
123
|
const format = texture.internalFormat || options.format || getFormat( texture, backend.device );
|
|
124
124
|
|
|
125
|
+
textureData.format = format;
|
|
126
|
+
|
|
125
127
|
let sampleCount = options.sampleCount !== undefined ? options.sampleCount : 1;
|
|
126
128
|
|
|
127
129
|
sampleCount = backend.utils.getSampleCount( sampleCount );
|
|
@@ -369,7 +371,7 @@ class WebGPUTextureUtils {
|
|
|
369
371
|
|
|
370
372
|
}
|
|
371
373
|
|
|
372
|
-
async copyTextureToBuffer( texture, x, y, width, height ) {
|
|
374
|
+
async copyTextureToBuffer( texture, x, y, width, height, faceIndex ) {
|
|
373
375
|
|
|
374
376
|
const device = this.backend.device;
|
|
375
377
|
|
|
@@ -393,7 +395,7 @@ class WebGPUTextureUtils {
|
|
|
393
395
|
encoder.copyTextureToBuffer(
|
|
394
396
|
{
|
|
395
397
|
texture: textureGPU,
|
|
396
|
-
origin: { x, y },
|
|
398
|
+
origin: { x, y, z: faceIndex },
|
|
397
399
|
},
|
|
398
400
|
{
|
|
399
401
|
buffer: readBuffer,
|
|
@@ -792,9 +794,9 @@ class WebGPUTextureUtils {
|
|
|
792
794
|
if ( format === GPUTextureFormat.RG16Sint ) return Int16Array;
|
|
793
795
|
if ( format === GPUTextureFormat.RGBA16Uint ) return Uint16Array;
|
|
794
796
|
if ( format === GPUTextureFormat.RGBA16Sint ) return Int16Array;
|
|
795
|
-
if ( format === GPUTextureFormat.R16Float ) return
|
|
796
|
-
if ( format === GPUTextureFormat.RG16Float ) return
|
|
797
|
-
if ( format === GPUTextureFormat.RGBA16Float ) return
|
|
797
|
+
if ( format === GPUTextureFormat.R16Float ) return Uint16Array;
|
|
798
|
+
if ( format === GPUTextureFormat.RG16Float ) return Uint16Array;
|
|
799
|
+
if ( format === GPUTextureFormat.RGBA16Float ) return Uint16Array;
|
|
798
800
|
|
|
799
801
|
|
|
800
802
|
if ( format === GPUTextureFormat.R32Uint ) return Uint32Array;
|
package/src/utils.js
CHANGED
|
@@ -117,4 +117,36 @@ function probeAsync( gl, sync, interval ) {
|
|
|
117
117
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
function toNormalizedProjectionMatrix( projectionMatrix ) {
|
|
121
|
+
|
|
122
|
+
const m = projectionMatrix.elements;
|
|
123
|
+
|
|
124
|
+
// Convert [-1, 1] to [0, 1] projection matrix
|
|
125
|
+
m[ 2 ] = 0.5 * m[ 2 ] + 0.5 * m[ 3 ];
|
|
126
|
+
m[ 6 ] = 0.5 * m[ 6 ] + 0.5 * m[ 7 ];
|
|
127
|
+
m[ 10 ] = 0.5 * m[ 10 ] + 0.5 * m[ 11 ];
|
|
128
|
+
m[ 14 ] = 0.5 * m[ 14 ] + 0.5 * m[ 15 ];
|
|
129
|
+
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function toReversedProjectionMatrix( projectionMatrix ) {
|
|
133
|
+
|
|
134
|
+
const m = projectionMatrix.elements;
|
|
135
|
+
const isPerspectiveMatrix = m[ 11 ] === - 1;
|
|
136
|
+
|
|
137
|
+
// Reverse [0, 1] projection matrix
|
|
138
|
+
if ( isPerspectiveMatrix ) {
|
|
139
|
+
|
|
140
|
+
m[ 10 ] = - m[ 10 ] - 1;
|
|
141
|
+
m[ 14 ] = - m[ 14 ];
|
|
142
|
+
|
|
143
|
+
} else {
|
|
144
|
+
|
|
145
|
+
m[ 10 ] = - m[ 10 ];
|
|
146
|
+
m[ 14 ] = - m[ 14 ] + 1;
|
|
147
|
+
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export { arrayMin, arrayMax, arrayNeedsUint32, getTypedArray, createElementNS, createCanvasElement, warnOnce, probeAsync, toNormalizedProjectionMatrix, toReversedProjectionMatrix };
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author santiago / @glitch_life
|
|
3
|
-
* wrapper of https://www.npmjs.com/package/isosurface by https://github.com/mikolalysenko
|
|
4
|
-
*
|
|
5
|
-
* Returns BufferGeometry from SDF
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
BufferAttribute,
|
|
10
|
-
BufferGeometry,
|
|
11
|
-
FloatType,
|
|
12
|
-
Mesh,
|
|
13
|
-
OrthographicCamera,
|
|
14
|
-
PlaneGeometry,
|
|
15
|
-
Scene,
|
|
16
|
-
ShaderMaterial,
|
|
17
|
-
Vector2,
|
|
18
|
-
WebGLRenderTarget
|
|
19
|
-
} from 'three';
|
|
20
|
-
|
|
21
|
-
import { surfaceNet } from './../libs/surfaceNet.js';
|
|
22
|
-
|
|
23
|
-
class SDFGeometryGenerator {
|
|
24
|
-
|
|
25
|
-
constructor( renderer ) {
|
|
26
|
-
|
|
27
|
-
this.renderer = renderer;
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
generate( res = 64, distFunc = 'float dist( vec3 p ){ return length(p) - 0.5; }', bounds = 1 ) {
|
|
32
|
-
|
|
33
|
-
let w, h;
|
|
34
|
-
if ( res == 8 ) [ w, h ] = [ 32, 16 ];
|
|
35
|
-
else if ( res == 16 ) [ w, h ] = [ 64, 64 ];
|
|
36
|
-
else if ( res == 32 ) [ w, h ] = [ 256, 128 ];
|
|
37
|
-
else if ( res == 64 ) [ w, h ] = [ 512, 512 ];
|
|
38
|
-
else if ( res == 128 ) [ w, h ] = [ 2048, 1024 ];
|
|
39
|
-
else if ( res == 256 ) [ w, h ] = [ 4096, 4096 ];
|
|
40
|
-
else if ( res == 512 ) [ w, h ] = [ 16384, 8096 ];
|
|
41
|
-
else if ( res == 1024 ) [ w, h ] = [ 32768, 32768 ];
|
|
42
|
-
else throw new Error( 'THREE.SDFGeometryGenerator: Resolution must be in range 8 < res < 1024 and must be ^2' );
|
|
43
|
-
|
|
44
|
-
const maxTexSize = this.renderer.capabilities.maxTextureSize;
|
|
45
|
-
|
|
46
|
-
if ( w > maxTexSize || h > maxTexSize ) throw new Error( 'THREE.SDFGeometryGenerator: Your device does not support this resolution ( ' + res + ' ), decrease [res] param.' );
|
|
47
|
-
|
|
48
|
-
const [ tilesX, tilesY ] = [ ( w / res ), ( h / res ) ];
|
|
49
|
-
|
|
50
|
-
const sdfCompute = `
|
|
51
|
-
varying vec2 vUv;
|
|
52
|
-
uniform float tileNum;
|
|
53
|
-
uniform float bounds;
|
|
54
|
-
[#dist#]
|
|
55
|
-
void main() { gl_FragColor=vec4( ( dist( vec3( vUv, tileNum ) * 2.0 * bounds - vec3( bounds ) ) < 0.00001 ) ? 1.0 : 0.0 ); }
|
|
56
|
-
`;
|
|
57
|
-
|
|
58
|
-
const sdfRT = this.computeSDF( w, h, tilesX, tilesY, bounds, sdfCompute.replace( '[#dist#]', distFunc ) );
|
|
59
|
-
|
|
60
|
-
const read = new Float32Array( w * h * 4 );
|
|
61
|
-
this.renderer.readRenderTargetPixels( sdfRT, 0, 0, w, h, read );
|
|
62
|
-
sdfRT.dispose();
|
|
63
|
-
|
|
64
|
-
//
|
|
65
|
-
|
|
66
|
-
const mesh = surfaceNet( [ res, res, res ], ( x, y, z ) => {
|
|
67
|
-
|
|
68
|
-
x = ( x + bounds ) * ( res / ( bounds * 2 ) );
|
|
69
|
-
y = ( y + bounds ) * ( res / ( bounds * 2 ) );
|
|
70
|
-
z = ( z + bounds ) * ( res / ( bounds * 2 ) );
|
|
71
|
-
let p = ( x + ( z % tilesX ) * res ) + y * w + ( Math.floor( z / tilesX ) * res * w );
|
|
72
|
-
p *= 4;
|
|
73
|
-
return ( read[ p + 3 ] > 0 ) ? - 0.000000001 : 1;
|
|
74
|
-
|
|
75
|
-
}, [[ - bounds, - bounds, - bounds ], [ bounds, bounds, bounds ]] );
|
|
76
|
-
|
|
77
|
-
const ps = [], ids = [];
|
|
78
|
-
const geometry = new BufferGeometry();
|
|
79
|
-
mesh.positions.forEach( p => {
|
|
80
|
-
|
|
81
|
-
ps.push( p[ 0 ], p[ 1 ], p[ 2 ] );
|
|
82
|
-
|
|
83
|
-
} );
|
|
84
|
-
mesh.cells.forEach( p => ids.push( p[ 0 ], p[ 1 ], p[ 2 ] ) );
|
|
85
|
-
geometry.setAttribute( 'position', new BufferAttribute( new Float32Array( ps ), 3 ) );
|
|
86
|
-
geometry.setIndex( ids );
|
|
87
|
-
|
|
88
|
-
return geometry;
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
computeSDF( width, height, tilesX, tilesY, bounds, shader ) {
|
|
93
|
-
|
|
94
|
-
const rt = new WebGLRenderTarget( width, height, { type: FloatType } );
|
|
95
|
-
const scn = new Scene();
|
|
96
|
-
const cam = new OrthographicCamera();
|
|
97
|
-
const tiles = tilesX * tilesY;
|
|
98
|
-
let currentTile = 0;
|
|
99
|
-
|
|
100
|
-
Object.assign( cam, { left: width / - 2, right: width / 2, top: height / 2, bottom: height / - 2 } ).updateProjectionMatrix();
|
|
101
|
-
cam.position.z = 2;
|
|
102
|
-
|
|
103
|
-
const tileSize = width / tilesX;
|
|
104
|
-
const geometry = new PlaneGeometry( tileSize, tileSize );
|
|
105
|
-
|
|
106
|
-
while ( currentTile ++ < tiles ) {
|
|
107
|
-
|
|
108
|
-
const c = currentTile - 1;
|
|
109
|
-
const [ px, py ] = [ ( tileSize ) / 2 + ( c % tilesX ) * ( tileSize ) - width / 2, ( tileSize ) / 2 + Math.floor( c / tilesX ) * ( tileSize ) - height / 2 ];
|
|
110
|
-
const compPlane = new Mesh( geometry, new ShaderMaterial( {
|
|
111
|
-
uniforms: {
|
|
112
|
-
res: { value: new Vector2( width, height ) },
|
|
113
|
-
tileNum: { value: c / ( tilesX * tilesY - 1 ) },
|
|
114
|
-
bounds: { value: bounds }
|
|
115
|
-
},
|
|
116
|
-
vertexShader: 'varying vec2 vUv;void main(){vUv=uv;gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.0);}',
|
|
117
|
-
fragmentShader: shader
|
|
118
|
-
} ) );
|
|
119
|
-
compPlane.position.set( px, py, 0 );
|
|
120
|
-
scn.add( compPlane );
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
this.renderer.setRenderTarget( rt );
|
|
125
|
-
this.renderer.render( scn, cam );
|
|
126
|
-
this.renderer.setRenderTarget( null );
|
|
127
|
-
|
|
128
|
-
//
|
|
129
|
-
|
|
130
|
-
geometry.dispose();
|
|
131
|
-
|
|
132
|
-
scn.traverse( function ( object ) {
|
|
133
|
-
|
|
134
|
-
if ( object.material !== undefined ) object.material.dispose();
|
|
135
|
-
|
|
136
|
-
} );
|
|
137
|
-
|
|
138
|
-
return rt;
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export { SDFGeometryGenerator };
|