super-three 0.167.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 +532 -173
- package/build/three.module.js +532 -174
- package/build/three.module.min.js +1 -1
- package/build/three.webgpu.js +18173 -14266
- 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 -4
- package/examples/jsm/animation/AnimationClipCreator.js +1 -1
- package/examples/jsm/capabilities/WebGL.js +27 -21
- package/examples/jsm/controls/ArcballControls.js +174 -158
- package/examples/jsm/controls/DragControls.js +260 -132
- package/examples/jsm/controls/FirstPersonControls.js +175 -163
- package/examples/jsm/controls/FlyControls.js +194 -188
- package/examples/jsm/controls/OrbitControls.js +777 -786
- package/examples/jsm/controls/PointerLockControls.js +24 -15
- package/examples/jsm/controls/TrackballControls.js +469 -448
- package/examples/jsm/controls/TransformControls.js +97 -62
- package/examples/jsm/effects/AnaglyphEffect.js +6 -13
- package/examples/jsm/effects/ParallaxBarrierEffect.js +17 -11
- package/examples/jsm/effects/StereoEffect.js +6 -1
- package/examples/jsm/environments/RoomEnvironment.js +1 -1
- package/examples/jsm/exporters/DRACOExporter.js +4 -2
- package/examples/jsm/exporters/EXRExporter.js +19 -11
- package/examples/jsm/exporters/GLTFExporter.js +6 -1
- 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/exporters/USDZExporter.js +29 -8
- package/examples/jsm/geometries/DecalGeometry.js +4 -1
- package/examples/jsm/geometries/InstancedPointsGeometry.js +1 -1
- package/examples/jsm/helpers/LightProbeHelper.js +43 -44
- 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 +27 -12
- package/examples/jsm/loaders/MTLLoader.js +4 -3
- package/examples/jsm/loaders/MaterialXLoader.js +40 -14
- package/examples/jsm/loaders/OBJLoader.js +5 -3
- package/examples/jsm/loaders/PCDLoader.js +14 -13
- 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 +187 -0
- package/examples/jsm/objects/Water2Mesh.js +158 -0
- package/examples/jsm/objects/WaterMesh.js +101 -0
- package/examples/jsm/physics/JoltPhysics.js +1 -1
- package/examples/jsm/physics/RapierPhysics.js +21 -1
- package/examples/jsm/postprocessing/OutlinePass.js +31 -46
- package/examples/jsm/postprocessing/SSAARenderPass.js +3 -1
- package/examples/jsm/shaders/BleachBypassShader.js +1 -2
- package/examples/jsm/shaders/OutputShader.js +1 -1
- package/examples/jsm/transpiler/GLSLDecoder.js +1 -1
- package/examples/jsm/transpiler/ShaderToyDecoder.js +2 -2
- package/examples/jsm/transpiler/TSLEncoder.js +8 -8
- 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 +2 -1
- package/examples/jsm/utils/TextureUtilsGPU.js +63 -0
- package/examples/jsm/webxr/XRControllerModelFactory.js +1 -1
- package/package.json +3 -2
- package/src/Three.WebGPU.Nodes.js +200 -0
- package/src/Three.WebGPU.js +7 -0
- package/src/Three.js +1 -0
- 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 +32 -0
- package/src/geometries/CylinderGeometry.js +11 -4
- package/src/loaders/MaterialLoader.js +7 -1
- package/src/loaders/ObjectLoader.js +3 -3
- package/src/{nodes/loaders → loaders/nodes}/NodeLoader.js +25 -5
- package/src/{nodes/loaders → loaders/nodes}/NodeMaterialLoader.js +21 -18
- package/src/{nodes/loaders → loaders/nodes}/NodeObjectLoader.js +19 -0
- package/src/materials/Material.js +4 -7
- package/src/materials/nodes/InstancedPointsNodeMaterial.js +156 -0
- package/src/{nodes/materials → materials/nodes}/Line2NodeMaterial.js +56 -59
- package/src/{nodes/materials → materials/nodes}/LineBasicNodeMaterial.js +8 -5
- package/src/{nodes/materials → materials/nodes}/LineDashedNodeMaterial.js +12 -10
- package/src/{nodes/materials → materials/nodes}/MeshBasicNodeMaterial.js +16 -12
- package/src/{nodes/materials → materials/nodes}/MeshLambertNodeMaterial.js +10 -6
- package/src/{nodes/materials → materials/nodes}/MeshMatcapNodeMaterial.js +13 -9
- package/src/{nodes/materials → materials/nodes}/MeshNormalNodeMaterial.js +13 -9
- package/src/{nodes/materials → materials/nodes}/MeshPhongNodeMaterial.js +14 -9
- package/src/{nodes/materials → materials/nodes}/MeshPhysicalNodeMaterial.js +22 -18
- package/src/{nodes/materials → materials/nodes}/MeshSSSNodeMaterial.js +10 -7
- package/src/{nodes/materials → materials/nodes}/MeshStandardNodeMaterial.js +22 -12
- package/src/{nodes/materials → materials/nodes}/MeshToonNodeMaterial.js +9 -5
- package/src/{nodes/materials → materials/nodes}/NodeMaterial.js +71 -115
- package/src/{nodes/materials/Materials.js → materials/nodes/NodeMaterials.js} +3 -1
- package/src/{nodes/materials → materials/nodes}/PointsNodeMaterial.js +8 -5
- package/src/{nodes/materials → materials/nodes}/ShadowNodeMaterial.js +9 -5
- package/src/{nodes/materials → materials/nodes}/SpriteNodeMaterial.js +47 -14
- package/src/{nodes/materials → materials/nodes}/VolumeNodeMaterial.js +24 -22
- package/src/materials/nodes/manager/NodeMaterialObserver.js +302 -0
- package/src/math/Triangle.js +24 -0
- package/src/nodes/Nodes.js +103 -159
- package/src/nodes/TSL.js +179 -0
- package/src/nodes/accessors/AccessorsUtils.js +8 -8
- package/src/nodes/accessors/BatchNode.js +53 -21
- package/src/nodes/accessors/{BitangentNode.js → Bitangent.js} +9 -9
- package/src/nodes/accessors/BufferAttributeNode.js +8 -5
- package/src/nodes/accessors/BufferNode.js +7 -4
- package/src/nodes/accessors/Camera.js +13 -0
- package/src/nodes/accessors/ClippingNode.js +19 -13
- package/src/nodes/accessors/CubeTextureNode.js +9 -8
- package/src/nodes/accessors/InstanceNode.js +19 -15
- package/src/nodes/accessors/InstancedPointsMaterialNode.js +8 -5
- package/src/nodes/accessors/Lights.js +51 -0
- package/src/nodes/accessors/MaterialNode.js +56 -55
- package/src/nodes/accessors/MaterialProperties.js +3 -0
- package/src/nodes/accessors/MaterialReferenceNode.js +9 -4
- package/src/nodes/accessors/ModelNode.js +47 -12
- package/src/nodes/accessors/ModelViewProjectionNode.js +12 -9
- package/src/nodes/accessors/MorphNode.js +17 -13
- package/src/nodes/accessors/Normal.js +88 -0
- package/src/nodes/accessors/Object3DNode.js +17 -33
- package/src/nodes/accessors/PointUVNode.js +9 -5
- package/src/nodes/accessors/Position.js +10 -0
- package/src/nodes/accessors/ReferenceBaseNode.js +171 -0
- package/src/nodes/accessors/ReferenceNode.js +50 -7
- package/src/nodes/accessors/ReflectVector.js +10 -0
- package/src/nodes/accessors/RendererReferenceNode.js +12 -6
- package/src/nodes/accessors/SceneNode.js +9 -6
- package/src/nodes/accessors/SkinningNode.js +88 -21
- package/src/nodes/accessors/StorageBufferNode.js +22 -5
- package/src/nodes/accessors/StorageTextureNode.js +9 -6
- package/src/nodes/accessors/Tangent.js +22 -0
- package/src/nodes/accessors/Texture3DNode.js +16 -13
- package/src/nodes/accessors/{TextureBicubicNode.js → TextureBicubic.js} +3 -32
- package/src/nodes/accessors/TextureNode.js +29 -23
- package/src/nodes/accessors/TextureSizeNode.js +10 -9
- package/src/nodes/accessors/{UniformsNode.js → UniformArrayNode.js} +26 -14
- package/src/nodes/accessors/UserDataNode.js +10 -7
- package/src/nodes/accessors/VelocityNode.js +134 -0
- package/src/nodes/accessors/VertexColorNode.js +7 -4
- package/src/nodes/code/CodeNode.js +9 -5
- package/src/nodes/code/ExpressionNode.js +10 -6
- package/src/nodes/code/FunctionCallNode.js +8 -5
- package/src/nodes/code/FunctionNode.js +8 -23
- package/src/nodes/code/ScriptableNode.js +13 -10
- package/src/nodes/code/ScriptableValueNode.js +9 -7
- package/src/nodes/core/AssignNode.js +12 -9
- package/src/nodes/core/AttributeNode.js +12 -21
- package/src/nodes/core/BypassNode.js +11 -7
- package/src/nodes/core/CacheNode.js +10 -6
- package/src/nodes/core/ConstNode.js +6 -3
- package/src/nodes/core/ContextNode.js +21 -11
- package/src/nodes/core/IndexNode.js +35 -8
- package/src/nodes/core/InputNode.js +7 -3
- package/src/nodes/core/MRTNode.js +16 -7
- package/src/nodes/core/Node.js +19 -40
- package/src/nodes/core/NodeBuilder.js +117 -38
- package/src/nodes/core/NodeUtils.js +49 -6
- package/src/nodes/core/OutputStructNode.js +10 -6
- package/src/nodes/core/ParameterNode.js +7 -4
- package/src/nodes/core/PropertyNode.js +36 -32
- package/src/nodes/core/StackNode.js +31 -11
- package/src/nodes/core/StructTypeNode.js +7 -3
- package/src/nodes/core/TempNode.js +8 -4
- package/src/nodes/core/UniformGroupNode.js +14 -11
- package/src/nodes/core/UniformNode.js +7 -4
- package/src/nodes/core/VarNode.js +12 -8
- package/src/nodes/core/VaryingNode.js +10 -6
- package/src/nodes/display/AfterImageNode.js +15 -9
- package/src/nodes/display/AnaglyphPassNode.js +67 -0
- package/src/nodes/display/AnamorphicNode.js +17 -11
- package/src/nodes/display/BleachBypass.js +26 -0
- package/src/nodes/display/BlendMode.js +54 -0
- package/src/nodes/display/BloomNode.js +27 -19
- package/src/nodes/display/BumpMapNode.js +13 -12
- package/src/nodes/display/ColorAdjustment.js +46 -0
- package/src/nodes/display/ColorSpaceFunctions.js +38 -0
- package/src/nodes/display/ColorSpaceNode.js +67 -61
- package/src/nodes/display/DenoiseNode.js +23 -17
- package/src/nodes/display/DepthOfFieldNode.js +12 -7
- package/src/nodes/display/DotScreenNode.js +13 -22
- package/src/nodes/display/FXAANode.js +21 -16
- package/src/nodes/display/FilmNode.js +11 -7
- package/src/nodes/display/FrontFacingNode.js +10 -6
- package/src/nodes/display/GTAONode.js +22 -15
- package/src/nodes/display/GaussianBlurNode.js +14 -8
- package/src/nodes/display/Lut3DNode.js +10 -6
- package/src/nodes/display/MotionBlur.js +25 -0
- package/src/nodes/display/NormalMapNode.js +13 -13
- package/src/nodes/display/ParallaxBarrierPassNode.js +58 -0
- package/src/nodes/display/PassNode.js +95 -8
- package/src/nodes/display/PixelationPassNode.js +20 -8
- package/src/nodes/display/PosterizeNode.js +8 -7
- package/src/nodes/display/RGBShiftNode.js +11 -7
- package/src/nodes/display/RenderOutputNode.js +15 -11
- package/src/nodes/display/SSAAPassNode.js +287 -0
- package/src/nodes/display/ScreenNode.js +181 -0
- package/src/nodes/display/Sepia.js +17 -0
- package/src/nodes/display/SobelOperatorNode.js +13 -8
- package/src/nodes/display/StereoCompositePassNode.js +110 -0
- package/src/nodes/display/StereoPassNode.js +83 -0
- package/src/nodes/display/ToneMappingFunctions.js +190 -0
- package/src/nodes/display/ToneMappingNode.js +15 -175
- package/src/nodes/display/ToonOutlinePassNode.js +111 -0
- package/src/nodes/display/TransitionNode.js +12 -8
- package/src/nodes/display/ViewportDepthNode.js +34 -29
- package/src/nodes/display/ViewportDepthTextureNode.js +10 -9
- package/src/nodes/display/ViewportSharedTextureNode.js +10 -9
- package/src/nodes/display/ViewportTextureNode.js +11 -11
- package/src/nodes/fog/FogExp2Node.js +8 -7
- package/src/nodes/fog/FogNode.js +10 -8
- package/src/nodes/fog/FogRangeNode.js +8 -7
- package/src/nodes/functions/BSDF/BRDF_GGX.js +4 -4
- package/src/nodes/functions/BSDF/BRDF_Lambert.js +2 -2
- package/src/nodes/functions/BSDF/BRDF_Sheen.js +6 -6
- package/src/nodes/functions/BSDF/DFGApprox.js +2 -2
- package/src/nodes/functions/BSDF/D_GGX.js +2 -2
- package/src/nodes/functions/BSDF/D_GGX_Anisotropic.js +3 -3
- package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
- package/src/nodes/functions/BSDF/F_Schlick.js +2 -2
- package/src/nodes/functions/BSDF/LTC.js +6 -6
- package/src/nodes/functions/BSDF/Schlick_to_F0.js +2 -2
- package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +2 -2
- package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +2 -2
- package/src/nodes/functions/BasicLightingModel.js +1 -1
- package/src/nodes/functions/PhongLightingModel.js +5 -5
- package/src/nodes/functions/PhysicalLightingModel.js +34 -33
- package/src/nodes/functions/ShadowMaskModel.js +1 -1
- package/src/nodes/functions/ToonLightingModel.js +3 -3
- package/src/nodes/functions/material/getGeometryRoughness.js +4 -4
- package/src/nodes/functions/material/getRoughness.js +2 -2
- package/src/nodes/functions/material/getShIrradianceAt.js +28 -0
- package/src/nodes/geometry/RangeNode.js +9 -5
- 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 +10 -6
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +100 -0
- package/src/nodes/lighting/AONode.js +6 -3
- package/src/nodes/lighting/AmbientLightNode.js +6 -8
- package/src/nodes/lighting/AnalyticLightNode.js +225 -36
- package/src/nodes/lighting/BasicEnvironmentNode.js +8 -4
- package/src/nodes/lighting/BasicLightMapNode.js +7 -4
- package/src/nodes/lighting/DirectionalLightNode.js +7 -9
- package/src/nodes/lighting/EnvironmentNode.js +23 -19
- package/src/nodes/lighting/HemisphereLightNode.js +11 -11
- package/src/nodes/lighting/IESSpotLightNode.js +7 -9
- package/src/nodes/lighting/IrradianceNode.js +6 -3
- package/src/nodes/lighting/LightProbeNode.js +53 -0
- package/src/nodes/lighting/LightUtils.js +3 -3
- package/src/nodes/lighting/LightingContextNode.js +19 -18
- package/src/nodes/lighting/LightingNode.js +7 -3
- package/src/nodes/lighting/LightsNode.js +112 -75
- package/src/nodes/lighting/PointLightNode.js +12 -13
- package/src/nodes/lighting/RectAreaLightNode.js +11 -11
- package/src/nodes/lighting/SpotLightNode.js +14 -16
- package/src/nodes/materialx/MaterialXNodes.js +2 -2
- package/src/nodes/materialx/lib/mx_hsv.js +36 -31
- package/src/nodes/materialx/lib/mx_noise.js +96 -96
- package/src/nodes/materialx/lib/mx_transform_color.js +2 -2
- package/src/nodes/math/{CondNode.js → ConditionalNode.js} +38 -10
- package/src/nodes/math/Hash.js +13 -0
- package/src/nodes/math/MathNode.js +127 -124
- package/src/nodes/math/MathUtils.js +0 -7
- package/src/nodes/math/OperatorNode.js +97 -52
- package/src/nodes/math/TriNoise3D.js +19 -29
- package/src/nodes/pmrem/PMREMNode.js +61 -15
- package/src/nodes/pmrem/PMREMUtils.js +46 -46
- package/src/nodes/procedural/Checker.js +14 -0
- package/src/nodes/tsl/TSLBase.js +30 -0
- package/src/nodes/{shadernode/ShaderNode.js → tsl/TSLCore.js} +105 -97
- package/src/nodes/utils/ArrayElementNode.js +8 -4
- package/src/nodes/utils/ConvertNode.js +7 -3
- package/src/nodes/utils/CubeMapNode.js +160 -0
- package/src/nodes/utils/Discard.js +8 -0
- package/src/nodes/utils/EquirectUVNode.js +9 -6
- package/src/nodes/utils/FlipNode.js +68 -0
- package/src/nodes/utils/FunctionOverloadingNode.js +9 -5
- package/src/nodes/utils/JoinNode.js +6 -3
- package/src/nodes/utils/LoopNode.js +16 -6
- package/src/nodes/utils/MatcapUVNode.js +10 -7
- package/src/nodes/utils/MaxMipLevelNode.js +8 -5
- package/src/nodes/utils/OscNode.js +12 -8
- package/src/nodes/utils/Packing.js +4 -0
- package/src/nodes/utils/RTTNode.js +11 -8
- package/src/nodes/utils/ReflectorNode.js +12 -4
- package/src/nodes/utils/RemapNode.js +12 -8
- package/src/nodes/utils/RotateNode.js +8 -13
- package/src/nodes/utils/SetNode.js +7 -4
- package/src/nodes/utils/SplitNode.js +7 -3
- package/src/nodes/utils/SpriteSheetUVNode.js +10 -6
- package/src/nodes/utils/SpriteUtils.js +47 -0
- package/src/nodes/utils/StorageArrayElementNode.js +11 -12
- package/src/nodes/utils/TimerNode.js +8 -5
- package/src/nodes/utils/TriplanarTexturesNode.js +11 -9
- package/src/nodes/utils/UVUtils.js +19 -0
- package/src/nodes/utils/ViewportUtils.js +14 -0
- package/src/objects/BatchedMesh.js +78 -13
- 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 +88 -41
- package/src/renderers/common/Backend.js +2 -2
- package/src/renderers/common/Background.js +3 -1
- package/src/renderers/common/BindGroup.js +3 -1
- package/src/renderers/common/Bindings.js +13 -15
- package/src/renderers/common/BundleGroup.js +26 -0
- package/src/renderers/common/ClippingContext.js +15 -5
- package/src/renderers/common/CubeRenderTarget.js +9 -3
- package/src/renderers/common/PostProcessing.js +4 -1
- package/src/renderers/common/QuadMesh.js +2 -0
- package/src/renderers/common/RenderContext.js +23 -0
- package/src/renderers/common/RenderList.js +1 -1
- package/src/renderers/common/RenderObject.js +117 -6
- package/src/renderers/common/RenderObjects.js +8 -1
- package/src/renderers/common/Renderer.js +128 -94
- package/src/renderers/common/SampledTexture.js +12 -3
- package/src/renderers/common/Textures.js +8 -12
- package/src/renderers/common/extras/PMREMGenerator.js +19 -22
- package/src/renderers/common/nodes/NodeBuilderState.js +4 -4
- package/src/renderers/common/nodes/NodeLibrary.js +118 -0
- package/src/renderers/common/nodes/NodeSampledTexture.js +2 -2
- package/src/renderers/common/nodes/Nodes.js +65 -19
- package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +2 -2
- 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 +3 -1
- package/src/renderers/webgl/WebGLPrograms.js +21 -17
- package/src/renderers/webgl/WebGLProperties.js +7 -0
- package/src/renderers/webgl/WebGLState.js +21 -0
- package/src/renderers/webgl/WebGLTextures.js +83 -4
- package/src/renderers/webgl-fallback/WebGLBackend.js +135 -110
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +60 -12
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +6 -0
- package/src/renderers/webgl-fallback/utils/WebGLState.js +20 -2
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +89 -37
- package/src/renderers/webgpu/WebGPUBackend.js +112 -86
- package/src/renderers/webgpu/WebGPURenderer.Nodes.js +42 -0
- package/src/renderers/webgpu/WebGPURenderer.js +9 -6
- package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +59 -0
- package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +105 -0
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +189 -73
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +6 -16
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +45 -21
- package/src/renderers/webgpu/utils/WebGPUConstants.js +2 -1
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +7 -16
- package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +62 -5
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +43 -26
- package/src/renderers/webgpu/utils/WebGPUUtils.js +19 -2
- package/src/renderers/webxr/WebXRManager.js +32 -25
- package/src/utils.js +33 -1
- package/examples/jsm/geometries/SDFGeometryGenerator.js +0 -144
- package/examples/jsm/loaders/LogLuvLoader.js +0 -606
- 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/accessors/CameraNode.js +0 -19
- package/src/nodes/accessors/NormalNode.js +0 -14
- package/src/nodes/accessors/PositionNode.js +0 -10
- package/src/nodes/accessors/ReflectVectorNode.js +0 -10
- package/src/nodes/accessors/TangentNode.js +0 -23
- package/src/nodes/core/NodeKeywords.js +0 -80
- package/src/nodes/display/BlendModeNode.js +0 -128
- package/src/nodes/display/ColorAdjustmentNode.js +0 -104
- package/src/nodes/display/ViewportNode.js +0 -137
- package/src/nodes/lighting/LightNode.js +0 -57
- package/src/nodes/materials/InstancedPointsNodeMaterial.js +0 -162
- package/src/nodes/math/HashNode.js +0 -34
- package/src/nodes/procedural/CheckerNode.js +0 -42
- package/src/nodes/utils/DiscardNode.js +0 -28
- package/src/nodes/utils/PackingNode.js +0 -55
- package/src/nodes/utils/RotateUVNode.js +0 -35
- /package/src/nodes/accessors/{UVNode.js → UV.js} +0 -0
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GLSLNodeParser, NodeBuilder, TextureNode, vectorComponents } from '../../../nodes/Nodes.js';
|
|
2
2
|
|
|
3
3
|
import NodeUniformBuffer from '../../common/nodes/NodeUniformBuffer.js';
|
|
4
4
|
import NodeUniformsGroup from '../../common/nodes/NodeUniformsGroup.js';
|
|
5
5
|
|
|
6
6
|
import { NodeSampledTexture, NodeSampledCubeTexture, NodeSampledTexture3D } from '../../common/nodes/NodeSampledTexture.js';
|
|
7
7
|
|
|
8
|
-
import { ByteType, ShortType, RGBAIntegerFormat, RGBIntegerFormat, RedIntegerFormat, RGIntegerFormat, UnsignedByteType, UnsignedIntType, UnsignedShortType, RedFormat, RGFormat, IntType, RGBFormat, RGBAFormat, FloatType } from '../../../constants.js';
|
|
8
|
+
import { NoColorSpace, ByteType, ShortType, RGBAIntegerFormat, RGBIntegerFormat, RedIntegerFormat, RGIntegerFormat, UnsignedByteType, UnsignedIntType, UnsignedShortType, RedFormat, RGFormat, IntType, RGBFormat, RGBAFormat, FloatType } from '../../../constants.js';
|
|
9
9
|
import { DataTexture } from '../../../textures/DataTexture.js';
|
|
10
10
|
|
|
11
11
|
const glslMethods = {
|
|
12
|
-
|
|
12
|
+
atan2: 'atan',
|
|
13
13
|
textureDimensions: 'textureSize',
|
|
14
14
|
equals: 'equal'
|
|
15
15
|
};
|
|
@@ -54,8 +54,15 @@ class GLSLNodeBuilder extends NodeBuilder {
|
|
|
54
54
|
|
|
55
55
|
this.uniformGroups = {};
|
|
56
56
|
this.transforms = [];
|
|
57
|
+
this.extensions = {};
|
|
57
58
|
|
|
58
|
-
this.
|
|
59
|
+
this.useComparisonMethod = true;
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
needsColorSpaceToLinearSRGB( texture ) {
|
|
64
|
+
|
|
65
|
+
return texture.isVideoTexture === true && texture.colorSpace !== NoColorSpace;
|
|
59
66
|
|
|
60
67
|
}
|
|
61
68
|
|
|
@@ -198,7 +205,7 @@ ${ flowData.code }
|
|
|
198
205
|
const nodeUniform = this.getUniformFromNode( attribute.pboNode, 'texture', this.shaderStage, this.context.label );
|
|
199
206
|
const textureName = this.getPropertyName( nodeUniform );
|
|
200
207
|
|
|
201
|
-
|
|
208
|
+
this.increaseUsage( indexNode ); // force cache generate to be used as index in x,y
|
|
202
209
|
const indexSnippet = indexNode.build( this, 'uint' );
|
|
203
210
|
|
|
204
211
|
const elementNodeData = this.getDataFromNode( storageArrayElementNode );
|
|
@@ -225,7 +232,7 @@ ${ flowData.code }
|
|
|
225
232
|
|
|
226
233
|
this.getVarFromNode( node, propertySizeName, 'uint' );
|
|
227
234
|
|
|
228
|
-
this.addLineFlowCode( `${ propertySizeName } = uint( textureSize( ${ textureName }, 0 ).x )
|
|
235
|
+
this.addLineFlowCode( `${ propertySizeName } = uint( textureSize( ${ textureName }, 0 ).x )`, storageArrayElementNode );
|
|
229
236
|
|
|
230
237
|
bufferNodeData.propertySizeName = propertySizeName;
|
|
231
238
|
|
|
@@ -255,7 +262,7 @@ ${ flowData.code }
|
|
|
255
262
|
|
|
256
263
|
}
|
|
257
264
|
|
|
258
|
-
this.addLineFlowCode( `${ propertyName } = ${prefix}(${ snippet })${channel}
|
|
265
|
+
this.addLineFlowCode( `${ propertyName } = ${prefix}(${ snippet })${channel}`, storageArrayElementNode );
|
|
259
266
|
|
|
260
267
|
elementNodeData.propertyName = propertyName;
|
|
261
268
|
|
|
@@ -384,7 +391,7 @@ ${ flowData.code }
|
|
|
384
391
|
|
|
385
392
|
snippet = `sampler2DShadow ${ uniform.name };`;
|
|
386
393
|
|
|
387
|
-
} else if ( texture.isDataArrayTexture === true ) {
|
|
394
|
+
} else if ( texture.isDataArrayTexture === true || texture.isCompressedArrayTexture === true ) {
|
|
388
395
|
|
|
389
396
|
snippet = `${typePrefix}sampler2DArray ${ uniform.name };`;
|
|
390
397
|
|
|
@@ -604,6 +611,16 @@ ${ flowData.code }
|
|
|
604
611
|
|
|
605
612
|
}
|
|
606
613
|
|
|
614
|
+
getInvocationLocalIndex() {
|
|
615
|
+
|
|
616
|
+
const workgroupSize = this.object.workgroupSize;
|
|
617
|
+
|
|
618
|
+
const size = workgroupSize.reduce( ( acc, curr ) => acc * curr, 1 );
|
|
619
|
+
|
|
620
|
+
return `uint( gl_InstanceID ) % ${size}u`;
|
|
621
|
+
|
|
622
|
+
}
|
|
623
|
+
|
|
607
624
|
getDrawIndex() {
|
|
608
625
|
|
|
609
626
|
const extensions = this.renderer.backend.extensions;
|
|
@@ -626,7 +643,7 @@ ${ flowData.code }
|
|
|
626
643
|
|
|
627
644
|
getFragCoord() {
|
|
628
645
|
|
|
629
|
-
return 'gl_FragCoord';
|
|
646
|
+
return 'gl_FragCoord.xy';
|
|
630
647
|
|
|
631
648
|
}
|
|
632
649
|
|
|
@@ -636,9 +653,24 @@ ${ flowData.code }
|
|
|
636
653
|
|
|
637
654
|
}
|
|
638
655
|
|
|
656
|
+
enableExtension( name, behavior, shaderStage = this.shaderStage ) {
|
|
657
|
+
|
|
658
|
+
const map = this.extensions[ shaderStage ] || ( this.extensions[ shaderStage ] = new Map() );
|
|
659
|
+
|
|
660
|
+
if ( map.has( name ) === false ) {
|
|
661
|
+
|
|
662
|
+
map.set( name, {
|
|
663
|
+
name,
|
|
664
|
+
behavior
|
|
665
|
+
} );
|
|
666
|
+
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
}
|
|
670
|
+
|
|
639
671
|
getExtensions( shaderStage ) {
|
|
640
672
|
|
|
641
|
-
|
|
673
|
+
const snippets = [];
|
|
642
674
|
|
|
643
675
|
if ( shaderStage === 'vertex' ) {
|
|
644
676
|
|
|
@@ -647,13 +679,25 @@ ${ flowData.code }
|
|
|
647
679
|
|
|
648
680
|
if ( isBatchedMesh && ext.has( 'WEBGL_multi_draw' ) ) {
|
|
649
681
|
|
|
650
|
-
|
|
682
|
+
this.enableExtension( 'GL_ANGLE_multi_draw', 'require', shaderStage );
|
|
651
683
|
|
|
652
684
|
}
|
|
653
685
|
|
|
654
686
|
}
|
|
655
687
|
|
|
656
|
-
|
|
688
|
+
const extensions = this.extensions[ shaderStage ];
|
|
689
|
+
|
|
690
|
+
if ( extensions !== undefined ) {
|
|
691
|
+
|
|
692
|
+
for ( const { name, behavior } of extensions.values() ) {
|
|
693
|
+
|
|
694
|
+
snippets.push( `#extension ${name} : ${behavior}` );
|
|
695
|
+
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
return snippets.join( '\n' );
|
|
657
701
|
|
|
658
702
|
}
|
|
659
703
|
|
|
@@ -733,6 +777,8 @@ ${vars}
|
|
|
733
777
|
|
|
734
778
|
return `#version 300 es
|
|
735
779
|
|
|
780
|
+
${ this.getSignature() }
|
|
781
|
+
|
|
736
782
|
// extensions
|
|
737
783
|
${shaderData.extensions}
|
|
738
784
|
|
|
@@ -806,6 +852,8 @@ void main() {
|
|
|
806
852
|
|
|
807
853
|
const shadersData = this.material !== null ? { fragment: {}, vertex: {} } : { compute: {} };
|
|
808
854
|
|
|
855
|
+
this.sortBindingGroups();
|
|
856
|
+
|
|
809
857
|
for ( const shaderStage in shadersData ) {
|
|
810
858
|
|
|
811
859
|
let flow = '// code\n\n';
|
|
@@ -233,10 +233,16 @@ class WebGLAttributeUtils {
|
|
|
233
233
|
|
|
234
234
|
const dstBuffer = new attribute.array.constructor( array.length );
|
|
235
235
|
|
|
236
|
+
// Ensure the buffer is bound before reading
|
|
237
|
+
gl.bindBuffer( gl.COPY_WRITE_BUFFER, writeBuffer );
|
|
238
|
+
|
|
236
239
|
gl.getBufferSubData( gl.COPY_WRITE_BUFFER, 0, dstBuffer );
|
|
237
240
|
|
|
238
241
|
gl.deleteBuffer( writeBuffer );
|
|
239
242
|
|
|
243
|
+
gl.bindBuffer( gl.COPY_READ_BUFFER, null );
|
|
244
|
+
gl.bindBuffer( gl.COPY_WRITE_BUFFER, null );
|
|
245
|
+
|
|
240
246
|
return dstBuffer.buffer;
|
|
241
247
|
|
|
242
248
|
}
|
|
@@ -48,6 +48,7 @@ class WebGLState {
|
|
|
48
48
|
this.maxTextures = this.gl.getParameter( this.gl.MAX_TEXTURE_IMAGE_UNITS );
|
|
49
49
|
this.currentTextureSlot = null;
|
|
50
50
|
this.currentBoundTextures = {};
|
|
51
|
+
this.currentBoundBufferBases = {};
|
|
51
52
|
|
|
52
53
|
if ( initialized === false ) {
|
|
53
54
|
|
|
@@ -511,7 +512,7 @@ class WebGLState {
|
|
|
511
512
|
|
|
512
513
|
this.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
|
|
513
514
|
|
|
514
|
-
material.alphaToCoverage === true
|
|
515
|
+
material.alphaToCoverage === true && this.backend.renderer.samples > 1
|
|
515
516
|
? this.enable( gl.SAMPLE_ALPHA_TO_COVERAGE )
|
|
516
517
|
: this.disable( gl.SAMPLE_ALPHA_TO_COVERAGE );
|
|
517
518
|
|
|
@@ -648,7 +649,6 @@ class WebGLState {
|
|
|
648
649
|
|
|
649
650
|
}
|
|
650
651
|
|
|
651
|
-
|
|
652
652
|
}
|
|
653
653
|
|
|
654
654
|
|
|
@@ -710,12 +710,30 @@ class WebGLState {
|
|
|
710
710
|
boundTexture.type = webglType;
|
|
711
711
|
boundTexture.texture = webglTexture;
|
|
712
712
|
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
bindBufferBase( target, index, buffer ) {
|
|
718
|
+
|
|
719
|
+
const { gl } = this;
|
|
720
|
+
|
|
721
|
+
const key = `${target}-${index}`;
|
|
722
|
+
|
|
723
|
+
if ( this.currentBoundBufferBases[ key ] !== buffer ) {
|
|
724
|
+
|
|
725
|
+
gl.bindBufferBase( target, index, buffer );
|
|
726
|
+
this.currentBoundBufferBases[ key ] = buffer;
|
|
727
|
+
|
|
728
|
+
return true;
|
|
713
729
|
|
|
714
730
|
}
|
|
715
731
|
|
|
732
|
+
return false;
|
|
716
733
|
|
|
717
734
|
}
|
|
718
735
|
|
|
736
|
+
|
|
719
737
|
unbindTexture() {
|
|
720
738
|
|
|
721
739
|
const { gl, currentTextureSlot, currentBoundTextures } = this;
|
|
@@ -79,11 +79,11 @@ class WebGLTextureUtils {
|
|
|
79
79
|
|
|
80
80
|
glTextureType = gl.TEXTURE_CUBE_MAP;
|
|
81
81
|
|
|
82
|
-
} else if ( texture.isDataArrayTexture === true ) {
|
|
82
|
+
} else if ( texture.isDataArrayTexture === true || texture.isCompressedArrayTexture === true ) {
|
|
83
83
|
|
|
84
84
|
glTextureType = gl.TEXTURE_2D_ARRAY;
|
|
85
85
|
|
|
86
|
-
} else if ( texture.isData3DTexture === true ) {
|
|
86
|
+
} else if ( texture.isData3DTexture === true ) { // TODO: isCompressed3DTexture, wait for #26642
|
|
87
87
|
|
|
88
88
|
glTextureType = gl.TEXTURE_3D;
|
|
89
89
|
|
|
@@ -245,7 +245,11 @@ class WebGLTextureUtils {
|
|
|
245
245
|
|
|
246
246
|
const { gl, extensions, backend } = this;
|
|
247
247
|
|
|
248
|
-
|
|
248
|
+
|
|
249
|
+
gl.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
|
|
250
|
+
gl.pixelStorei( gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
|
|
251
|
+
gl.pixelStorei( gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
|
|
252
|
+
gl.pixelStorei( gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE );
|
|
249
253
|
|
|
250
254
|
gl.texParameteri( textureType, gl.TEXTURE_WRAP_S, wrappingToGL[ texture.wrapS ] );
|
|
251
255
|
gl.texParameteri( textureType, gl.TEXTURE_WRAP_T, wrappingToGL[ texture.wrapT ] );
|
|
@@ -259,8 +263,10 @@ class WebGLTextureUtils {
|
|
|
259
263
|
gl.texParameteri( textureType, gl.TEXTURE_MAG_FILTER, filterToGL[ texture.magFilter ] );
|
|
260
264
|
|
|
261
265
|
|
|
266
|
+
const hasMipmaps = texture.mipmaps !== undefined && texture.mipmaps.length > 0;
|
|
267
|
+
|
|
262
268
|
// follow WebGPU backend mapping for texture filtering
|
|
263
|
-
const minFilter =
|
|
269
|
+
const minFilter = texture.minFilter === LinearFilter && hasMipmaps ? LinearMipmapLinearFilter : texture.minFilter;
|
|
264
270
|
|
|
265
271
|
gl.texParameteri( textureType, gl.TEXTURE_MIN_FILTER, filterToGL[ minFilter ] );
|
|
266
272
|
|
|
@@ -277,11 +283,10 @@ class WebGLTextureUtils {
|
|
|
277
283
|
if ( texture.minFilter !== NearestMipmapLinearFilter && texture.minFilter !== LinearMipmapLinearFilter ) return;
|
|
278
284
|
if ( texture.type === FloatType && extensions.has( 'OES_texture_float_linear' ) === false ) return; // verify extension for WebGL 1 and WebGL 2
|
|
279
285
|
|
|
280
|
-
if ( texture.anisotropy > 1
|
|
286
|
+
if ( texture.anisotropy > 1 ) {
|
|
281
287
|
|
|
282
288
|
const extension = extensions.get( 'EXT_texture_filter_anisotropic' );
|
|
283
289
|
gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, backend.getMaxAnisotropy() ) );
|
|
284
|
-
backend.get( texture ).currentAnisotropy = texture.anisotropy;
|
|
285
290
|
|
|
286
291
|
}
|
|
287
292
|
|
|
@@ -334,14 +339,9 @@ class WebGLTextureUtils {
|
|
|
334
339
|
|
|
335
340
|
backend.state.bindTexture( glTextureType, textureGPU );
|
|
336
341
|
|
|
337
|
-
gl.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
|
|
338
|
-
gl.pixelStorei( gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
|
|
339
|
-
gl.pixelStorei( gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
|
|
340
|
-
gl.pixelStorei( gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE );
|
|
341
|
-
|
|
342
342
|
this.setTextureParameters( glTextureType, texture );
|
|
343
343
|
|
|
344
|
-
if ( texture.isDataArrayTexture ) {
|
|
344
|
+
if ( texture.isDataArrayTexture || texture.isCompressedArrayTexture ) {
|
|
345
345
|
|
|
346
346
|
gl.texStorage3D( gl.TEXTURE_2D_ARRAY, levels, glInternalFormat, width, height, depth );
|
|
347
347
|
|
|
@@ -427,9 +427,12 @@ class WebGLTextureUtils {
|
|
|
427
427
|
|
|
428
428
|
this.backend.state.bindTexture( glTextureType, textureGPU );
|
|
429
429
|
|
|
430
|
+
this.setTextureParameters( glTextureType, texture );
|
|
431
|
+
|
|
430
432
|
if ( texture.isCompressedTexture ) {
|
|
431
433
|
|
|
432
434
|
const mipmaps = texture.mipmaps;
|
|
435
|
+
const image = options.image;
|
|
433
436
|
|
|
434
437
|
for ( let i = 0; i < mipmaps.length; i ++ ) {
|
|
435
438
|
|
|
@@ -437,7 +440,6 @@ class WebGLTextureUtils {
|
|
|
437
440
|
|
|
438
441
|
if ( texture.isCompressedArrayTexture ) {
|
|
439
442
|
|
|
440
|
-
const image = options.image;
|
|
441
443
|
|
|
442
444
|
if ( texture.format !== gl.RGBA ) {
|
|
443
445
|
|
|
@@ -474,6 +476,7 @@ class WebGLTextureUtils {
|
|
|
474
476
|
|
|
475
477
|
}
|
|
476
478
|
|
|
479
|
+
|
|
477
480
|
} else if ( texture.isCubeTexture ) {
|
|
478
481
|
|
|
479
482
|
const images = options.images;
|
|
@@ -527,7 +530,6 @@ class WebGLTextureUtils {
|
|
|
527
530
|
|
|
528
531
|
deallocateRenderBuffers( renderTarget ) {
|
|
529
532
|
|
|
530
|
-
|
|
531
533
|
const { gl, backend } = this;
|
|
532
534
|
|
|
533
535
|
// remove framebuffer reference
|
|
@@ -537,31 +539,36 @@ class WebGLTextureUtils {
|
|
|
537
539
|
|
|
538
540
|
renderContextData.renderBufferStorageSetup = undefined;
|
|
539
541
|
|
|
540
|
-
if ( renderContextData.
|
|
542
|
+
if ( renderContextData.framebuffers ) {
|
|
541
543
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
+
for ( const cacheKey in renderContextData.framebuffers ) {
|
|
545
|
+
|
|
546
|
+
gl.deleteFramebuffer( renderContextData.framebuffers[ cacheKey ] );
|
|
547
|
+
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
delete renderContextData.framebuffers;
|
|
544
551
|
|
|
545
552
|
}
|
|
546
553
|
|
|
547
554
|
if ( renderContextData.depthRenderbuffer ) {
|
|
548
555
|
|
|
549
556
|
gl.deleteRenderbuffer( renderContextData.depthRenderbuffer );
|
|
550
|
-
renderContextData.depthRenderbuffer
|
|
557
|
+
delete renderContextData.depthRenderbuffer;
|
|
551
558
|
|
|
552
559
|
}
|
|
553
560
|
|
|
554
561
|
if ( renderContextData.stencilRenderbuffer ) {
|
|
555
562
|
|
|
556
563
|
gl.deleteRenderbuffer( renderContextData.stencilRenderbuffer );
|
|
557
|
-
renderContextData.stencilRenderbuffer
|
|
564
|
+
delete renderContextData.stencilRenderbuffer;
|
|
558
565
|
|
|
559
566
|
}
|
|
560
567
|
|
|
561
568
|
if ( renderContextData.msaaFrameBuffer ) {
|
|
562
569
|
|
|
563
570
|
gl.deleteFramebuffer( renderContextData.msaaFrameBuffer );
|
|
564
|
-
renderContextData.msaaFrameBuffer
|
|
571
|
+
delete renderContextData.msaaFrameBuffer;
|
|
565
572
|
|
|
566
573
|
}
|
|
567
574
|
|
|
@@ -573,7 +580,7 @@ class WebGLTextureUtils {
|
|
|
573
580
|
|
|
574
581
|
}
|
|
575
582
|
|
|
576
|
-
renderContextData.msaaRenderbuffers
|
|
583
|
+
delete renderContextData.msaaRenderbuffers;
|
|
577
584
|
|
|
578
585
|
}
|
|
579
586
|
|
|
@@ -685,20 +692,22 @@ class WebGLTextureUtils {
|
|
|
685
692
|
|
|
686
693
|
}
|
|
687
694
|
|
|
688
|
-
copyFramebufferToTexture( texture, renderContext ) {
|
|
695
|
+
copyFramebufferToTexture( texture, renderContext, rectangle ) {
|
|
689
696
|
|
|
690
697
|
const { gl } = this;
|
|
691
698
|
const { state } = this.backend;
|
|
692
699
|
|
|
693
700
|
const { textureGPU } = this.backend.get( texture );
|
|
694
701
|
|
|
695
|
-
const width =
|
|
696
|
-
const height = texture.image.height;
|
|
702
|
+
const { x, y, z: width, w: height } = rectangle;
|
|
697
703
|
|
|
698
704
|
const requireDrawFrameBuffer = texture.isDepthTexture === true || ( renderContext.renderTarget && renderContext.renderTarget.samples > 0 );
|
|
699
705
|
|
|
706
|
+
const srcHeight = renderContext.renderTarget ? renderContext.renderTarget.height : this.backend.gerDrawingBufferSize().y;
|
|
707
|
+
|
|
700
708
|
if ( requireDrawFrameBuffer ) {
|
|
701
709
|
|
|
710
|
+
const partial = ( x !== 0 || y !== 0 );
|
|
702
711
|
let mask;
|
|
703
712
|
let attachment;
|
|
704
713
|
|
|
@@ -720,19 +729,45 @@ class WebGLTextureUtils {
|
|
|
720
729
|
|
|
721
730
|
}
|
|
722
731
|
|
|
723
|
-
|
|
724
|
-
state.bindFramebuffer( gl.DRAW_FRAMEBUFFER, fb );
|
|
732
|
+
if ( partial ) {
|
|
725
733
|
|
|
726
|
-
|
|
734
|
+
const renderTargetContextData = this.backend.get( renderContext.renderTarget );
|
|
727
735
|
|
|
728
|
-
|
|
736
|
+
const fb = renderTargetContextData.framebuffers[ renderContext.getCacheKey() ];
|
|
737
|
+
const msaaFrameBuffer = renderTargetContextData.msaaFrameBuffer;
|
|
729
738
|
|
|
730
|
-
|
|
739
|
+
state.bindFramebuffer( gl.DRAW_FRAMEBUFFER, fb );
|
|
740
|
+
state.bindFramebuffer( gl.READ_FRAMEBUFFER, msaaFrameBuffer );
|
|
741
|
+
|
|
742
|
+
const flippedY = srcHeight - y - height;
|
|
743
|
+
|
|
744
|
+
gl.blitFramebuffer( x, flippedY, x + width, flippedY + height, x, flippedY, x + width, flippedY + height, mask, gl.NEAREST );
|
|
745
|
+
|
|
746
|
+
state.bindFramebuffer( gl.READ_FRAMEBUFFER, fb );
|
|
747
|
+
|
|
748
|
+
state.bindTexture( gl.TEXTURE_2D, textureGPU );
|
|
749
|
+
|
|
750
|
+
gl.copyTexSubImage2D( gl.TEXTURE_2D, 0, 0, 0, x, flippedY, width, height );
|
|
751
|
+
|
|
752
|
+
state.unbindTexture();
|
|
753
|
+
|
|
754
|
+
} else {
|
|
755
|
+
|
|
756
|
+
const fb = gl.createFramebuffer();
|
|
757
|
+
|
|
758
|
+
state.bindFramebuffer( gl.DRAW_FRAMEBUFFER, fb );
|
|
759
|
+
|
|
760
|
+
gl.framebufferTexture2D( gl.DRAW_FRAMEBUFFER, attachment, gl.TEXTURE_2D, textureGPU, 0 );
|
|
761
|
+
gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, gl.NEAREST );
|
|
762
|
+
|
|
763
|
+
gl.deleteFramebuffer( fb );
|
|
764
|
+
|
|
765
|
+
}
|
|
731
766
|
|
|
732
767
|
} else {
|
|
733
768
|
|
|
734
769
|
state.bindTexture( gl.TEXTURE_2D, textureGPU );
|
|
735
|
-
gl.copyTexSubImage2D( gl.TEXTURE_2D, 0, 0, 0,
|
|
770
|
+
gl.copyTexSubImage2D( gl.TEXTURE_2D, 0, 0, 0, x, srcHeight - height - y, width, height );
|
|
736
771
|
|
|
737
772
|
state.unbindTexture();
|
|
738
773
|
|
|
@@ -799,7 +834,7 @@ class WebGLTextureUtils {
|
|
|
799
834
|
|
|
800
835
|
}
|
|
801
836
|
|
|
802
|
-
async copyTextureToBuffer( texture, x, y, width, height ) {
|
|
837
|
+
async copyTextureToBuffer( texture, x, y, width, height, faceIndex ) {
|
|
803
838
|
|
|
804
839
|
const { backend, gl } = this;
|
|
805
840
|
|
|
@@ -808,10 +843,13 @@ class WebGLTextureUtils {
|
|
|
808
843
|
const fb = gl.createFramebuffer();
|
|
809
844
|
|
|
810
845
|
gl.bindFramebuffer( gl.READ_FRAMEBUFFER, fb );
|
|
811
|
-
|
|
846
|
+
|
|
847
|
+
const target = texture.isCubeTexture ? gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex : gl.TEXTURE_2D;
|
|
848
|
+
|
|
849
|
+
gl.framebufferTexture2D( gl.READ_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, target, textureGPU, 0 );
|
|
812
850
|
|
|
813
851
|
const typedArrayType = this._getTypedArrayType( glType );
|
|
814
|
-
const bytesPerTexel = this._getBytesPerTexel( glFormat );
|
|
852
|
+
const bytesPerTexel = this._getBytesPerTexel( glType, glFormat );
|
|
815
853
|
|
|
816
854
|
const elementCount = width * height;
|
|
817
855
|
const byteLength = elementCount * bytesPerTexel;
|
|
@@ -849,19 +887,33 @@ class WebGLTextureUtils {
|
|
|
849
887
|
if ( glType === gl.UNSIGNED_SHORT ) return Uint16Array;
|
|
850
888
|
if ( glType === gl.UNSIGNED_INT ) return Uint32Array;
|
|
851
889
|
|
|
890
|
+
if ( glType === gl.HALF_FLOAT ) return Uint16Array;
|
|
852
891
|
if ( glType === gl.FLOAT ) return Float32Array;
|
|
853
892
|
|
|
854
893
|
throw new Error( `Unsupported WebGL type: ${glType}` );
|
|
855
894
|
|
|
856
895
|
}
|
|
857
896
|
|
|
858
|
-
_getBytesPerTexel( glFormat ) {
|
|
897
|
+
_getBytesPerTexel( glType, glFormat ) {
|
|
859
898
|
|
|
860
899
|
const { gl } = this;
|
|
861
900
|
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
if (
|
|
901
|
+
let bytesPerComponent = 0;
|
|
902
|
+
|
|
903
|
+
if ( glType === gl.UNSIGNED_BYTE ) bytesPerComponent = 1;
|
|
904
|
+
|
|
905
|
+
if ( glType === gl.UNSIGNED_SHORT_4_4_4_4 ||
|
|
906
|
+
glType === gl.UNSIGNED_SHORT_5_5_5_1 ||
|
|
907
|
+
glType === gl.UNSIGNED_SHORT_5_6_5 ||
|
|
908
|
+
glType === gl.UNSIGNED_SHORT ||
|
|
909
|
+
glType === gl.HALF_FLOAT ) bytesPerComponent = 2;
|
|
910
|
+
|
|
911
|
+
if ( glType === gl.UNSIGNED_INT ||
|
|
912
|
+
glType === gl.FLOAT ) bytesPerComponent = 4;
|
|
913
|
+
|
|
914
|
+
if ( glFormat === gl.RGBA ) return bytesPerComponent * 4;
|
|
915
|
+
if ( glFormat === gl.RGB ) return bytesPerComponent * 3;
|
|
916
|
+
if ( glFormat === gl.ALPHA ) return bytesPerComponent;
|
|
865
917
|
|
|
866
918
|
}
|
|
867
919
|
|