@needle-tools/three 0.162.12 → 0.169.2
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/README.md +3 -3
- package/build/three.cjs +29789 -1941
- package/build/three.module.js +29095 -1933
- package/build/three.module.min.js +2 -2
- package/build/three.webgpu.js +80003 -0
- package/build/three.webgpu.min.js +6 -0
- package/build/three.webgpu.nodes.js +79951 -0
- package/build/three.webgpu.nodes.min.js +6 -0
- package/examples/jsm/Addons.js +2 -5
- package/examples/jsm/animation/AnimationClipCreator.js +1 -1
- package/examples/jsm/animation/CCDIKSolver.js +4 -2
- 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 +790 -797
- package/examples/jsm/controls/PointerLockControls.js +24 -15
- package/examples/jsm/controls/TrackballControls.js +469 -448
- package/examples/jsm/controls/TransformControls.js +98 -63
- package/examples/jsm/csm/CSMShader.js +4 -4
- 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 +2 -6
- package/examples/jsm/exporters/DRACOExporter.js +4 -2
- package/examples/jsm/exporters/EXRExporter.js +19 -11
- package/examples/jsm/exporters/GLTFExporter.js +77 -8
- 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 +55 -11
- package/examples/jsm/geometries/DecalGeometry.js +4 -1
- package/examples/jsm/geometries/InstancedPointsGeometry.js +1 -1
- package/examples/jsm/geometries/TeapotGeometry.js +1 -1
- package/examples/jsm/geometries/TextGeometry.js +10 -2
- package/examples/jsm/helpers/LightProbeHelper.js +43 -44
- package/examples/jsm/helpers/LightProbeHelperGPU.js +65 -0
- package/examples/jsm/helpers/ViewHelper.js +75 -61
- package/examples/jsm/interactive/HTMLMesh.js +7 -9
- package/examples/jsm/libs/basis/basis_transcoder.js +8 -10
- package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
- package/examples/jsm/libs/draco/README.md +2 -2
- package/examples/jsm/libs/fflate.module.js +694 -496
- package/examples/jsm/libs/ktx-parse.module.js +1 -1
- package/examples/jsm/lights/LightProbeGenerator.js +24 -10
- package/examples/jsm/lights/RectAreaLightTexturesLib.js +91 -0
- package/examples/jsm/lights/RectAreaLightUniformsLib.js +8 -63
- package/examples/jsm/lines/LineMaterial.js +1 -17
- package/examples/jsm/lines/LineSegments2.js +15 -0
- package/examples/jsm/lines/Wireframe.js +16 -1
- package/examples/jsm/lines/webgpu/Line2.js +20 -0
- package/examples/jsm/lines/webgpu/LineSegments2.js +376 -0
- package/examples/jsm/loaders/3MFLoader.js +2 -0
- package/examples/jsm/loaders/ColladaLoader.js +9 -6
- package/examples/jsm/loaders/DRACOLoader.js +4 -2
- package/examples/jsm/loaders/EXRLoader.js +351 -97
- package/examples/jsm/loaders/FBXLoader.js +77 -78
- package/examples/jsm/loaders/GLTFLoader.js +76 -14
- package/examples/jsm/loaders/KTX2Loader.js +30 -22
- package/examples/jsm/loaders/LDrawLoader.js +3 -2
- package/examples/jsm/loaders/LUT3dlLoader.js +0 -15
- package/examples/jsm/loaders/LUTCubeLoader.js +0 -14
- package/examples/jsm/loaders/LUTImageLoader.js +0 -14
- package/examples/jsm/loaders/MMDLoader.js +31 -12
- package/examples/jsm/loaders/MTLLoader.js +4 -3
- package/examples/jsm/loaders/MaterialXLoader.js +45 -21
- 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/RGBMLoader.js +16 -0
- package/examples/jsm/loaders/STLLoader.js +3 -2
- package/examples/jsm/loaders/USDZLoader.js +124 -76
- package/examples/jsm/loaders/UltraHDRLoader.js +583 -0
- package/examples/jsm/loaders/VRMLLoader.js +11 -11
- package/examples/jsm/loaders/VTKLoader.js +80 -6
- package/examples/jsm/loaders/XYZLoader.js +3 -2
- package/examples/jsm/loaders/lwo/IFFParser.js +8 -5
- package/examples/jsm/materials/MeshGouraudMaterial.js +7 -1
- package/examples/jsm/math/Octree.js +26 -20
- package/examples/jsm/misc/GPUComputationRenderer.js +9 -25
- package/examples/jsm/misc/Timer.js +1 -1
- package/examples/jsm/modifiers/CurveModifier.js +11 -9
- package/examples/jsm/modifiers/CurveModifierGPU.js +233 -0
- package/examples/jsm/modifiers/SimplifyModifier.js +2 -1
- package/examples/jsm/objects/InstancedPoints.js +2 -2
- package/examples/jsm/objects/Lensflare.js +2 -2
- 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 +281 -0
- package/examples/jsm/physics/RapierPhysics.js +25 -5
- package/examples/jsm/postprocessing/GlitchPass.js +0 -3
- package/examples/jsm/postprocessing/LUTPass.js +5 -71
- package/examples/jsm/postprocessing/OutlinePass.js +31 -46
- package/examples/jsm/postprocessing/RenderPass.js +1 -1
- package/examples/jsm/postprocessing/RenderTransitionPass.js +168 -0
- package/examples/jsm/postprocessing/SAOPass.js +0 -1
- package/examples/jsm/postprocessing/SSAARenderPass.js +3 -1
- package/examples/jsm/postprocessing/SSAOPass.js +6 -12
- package/examples/jsm/postprocessing/UnrealBloomPass.js +4 -4
- package/examples/jsm/renderers/CSS2DRenderer.js +25 -5
- package/examples/jsm/renderers/CSS3DRenderer.js +24 -3
- package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +1 -3
- package/examples/jsm/renderers/webgl-legacy/nodes/SlotNode.js +1 -1
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +7 -4
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js +19 -5
- package/examples/jsm/shaders/BleachBypassShader.js +1 -2
- package/examples/jsm/shaders/ColorifyShader.js +1 -2
- package/examples/jsm/shaders/FXAAShader.js +0 -2
- package/examples/jsm/shaders/GTAOShader.js +1 -1
- package/examples/jsm/shaders/LuminosityHighPassShader.js +1 -3
- package/examples/jsm/shaders/OutputShader.js +1 -1
- package/examples/jsm/transpiler/GLSLDecoder.js +47 -5
- package/examples/jsm/transpiler/ShaderToyDecoder.js +2 -2
- package/examples/jsm/transpiler/TSLEncoder.js +24 -22
- package/examples/jsm/utils/BufferGeometryUtils.js +18 -16
- package/examples/jsm/utils/GeometryCompressionUtils.js +37 -122
- package/examples/jsm/utils/SceneUtils.js +60 -1
- 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/SortUtils.js +8 -5
- package/examples/jsm/utils/TextureUtils.js +3 -2
- package/examples/jsm/utils/TextureUtilsGPU.js +63 -0
- package/examples/jsm/webxr/OculusHandModel.js +3 -2
- package/examples/jsm/webxr/XRControllerModelFactory.js +1 -1
- package/examples/jsm/webxr/XRHandModelFactory.js +4 -2
- package/package.json +11 -8
- package/src/Three.WebGPU.Nodes.js +200 -0
- package/src/Three.WebGPU.js +201 -0
- package/src/Three.js +23 -1
- package/src/animation/AnimationClip.js +1 -1
- package/src/animation/tracks/BooleanKeyframeTrack.js +10 -1
- package/src/animation/tracks/QuaternionKeyframeTrack.js +1 -2
- package/src/animation/tracks/StringKeyframeTrack.js +10 -1
- package/src/audio/Audio.js +2 -2
- package/src/constants.js +6 -7
- package/src/core/BufferAttribute.js +0 -9
- package/src/core/Clock.js +1 -1
- package/src/core/InterleavedBuffer.js +0 -9
- package/src/core/Object3D.js +34 -29
- package/src/core/Raycaster.js +6 -2
- package/src/core/RenderTarget.js +8 -0
- package/src/extras/Controls.js +32 -0
- package/src/extras/PMREMGenerator.js +12 -11
- package/src/extras/TextureUtils.js +210 -0
- package/src/geometries/CylinderGeometry.js +11 -4
- package/src/lights/Light.js +1 -0
- package/src/lights/LightShadow.js +5 -0
- package/{examples/jsm/lights → src/lights/webgpu}/IESSpotLight.js +1 -1
- package/src/loaders/FileLoader.js +5 -1
- package/src/loaders/LoaderUtils.js +3 -1
- package/src/loaders/MaterialLoader.js +8 -1
- package/src/loaders/ObjectLoader.js +36 -2
- package/{examples/jsm/nodes/loaders → src/loaders/nodes}/NodeLoader.js +27 -5
- package/{examples/jsm/nodes/loaders → src/loaders/nodes}/NodeMaterialLoader.js +22 -18
- package/{examples/jsm/nodes/loaders → src/loaders/nodes}/NodeObjectLoader.js +21 -1
- package/src/materials/Material.js +4 -0
- package/src/materials/MeshPhysicalMaterial.js +20 -0
- package/src/materials/ShaderMaterial.js +0 -4
- package/src/materials/nodes/InstancedPointsNodeMaterial.js +156 -0
- package/{examples/jsm/nodes/materials → src/materials/nodes}/Line2NodeMaterial.js +69 -68
- package/src/materials/nodes/LineBasicNodeMaterial.js +31 -0
- package/{examples/jsm/nodes/materials → src/materials/nodes}/LineDashedNodeMaterial.js +15 -12
- package/src/materials/nodes/MeshBasicNodeMaterial.js +77 -0
- package/src/materials/nodes/MeshLambertNodeMaterial.js +47 -0
- package/src/materials/nodes/MeshMatcapNodeMaterial.js +57 -0
- package/src/materials/nodes/MeshNormalNodeMaterial.js +44 -0
- package/src/materials/nodes/MeshPhongNodeMaterial.js +78 -0
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +248 -0
- package/{examples/jsm/nodes/materials → src/materials/nodes}/MeshSSSNodeMaterial.js +10 -7
- package/src/materials/nodes/MeshStandardNodeMaterial.js +108 -0
- package/src/materials/nodes/MeshToonNodeMaterial.js +38 -0
- package/{examples/jsm/nodes/materials → src/materials/nodes}/NodeMaterial.js +198 -157
- package/{examples/jsm/nodes/materials/Materials.js → src/materials/nodes/NodeMaterials.js} +7 -1
- package/{examples/jsm/nodes/materials → src/materials/nodes}/PointsNodeMaterial.js +10 -7
- package/src/materials/nodes/ShadowNodeMaterial.js +38 -0
- package/src/materials/nodes/SpriteNodeMaterial.js +123 -0
- package/src/materials/nodes/VolumeNodeMaterial.js +108 -0
- package/src/materials/nodes/manager/NodeMaterialObserver.js +302 -0
- package/src/math/Box2.js +4 -4
- package/src/math/Box3.js +6 -6
- package/src/math/ColorManagement.js +10 -0
- package/src/math/Matrix2.js +54 -0
- package/src/math/Spherical.js +4 -5
- package/src/math/Triangle.js +24 -0
- package/src/math/Vector4.js +13 -0
- package/src/nodes/Nodes.js +164 -0
- package/src/nodes/TSL.js +179 -0
- package/src/nodes/accessors/AccessorsUtils.js +25 -0
- package/src/nodes/accessors/BatchNode.js +128 -0
- package/src/nodes/accessors/Bitangent.js +13 -0
- package/{examples/jsm → src}/nodes/accessors/BufferAttributeNode.js +44 -6
- package/{examples/jsm → src}/nodes/accessors/BufferNode.js +13 -4
- package/src/nodes/accessors/Camera.js +13 -0
- package/{examples/jsm → src}/nodes/accessors/ClippingNode.js +22 -15
- package/src/nodes/accessors/CubeTextureNode.js +79 -0
- package/src/nodes/accessors/InstanceNode.js +144 -0
- package/src/nodes/accessors/InstancedPointsMaterialNode.js +24 -0
- package/src/nodes/accessors/Lights.js +51 -0
- package/src/nodes/accessors/MaterialNode.js +441 -0
- package/src/nodes/accessors/MaterialProperties.js +3 -0
- package/{examples/jsm → src}/nodes/accessors/MaterialReferenceNode.js +10 -5
- package/src/nodes/accessors/ModelNode.js +72 -0
- package/src/nodes/accessors/ModelViewProjectionNode.js +42 -0
- package/{examples/jsm → src}/nodes/accessors/MorphNode.js +51 -33
- package/src/nodes/accessors/Normal.js +88 -0
- package/{examples/jsm → src}/nodes/accessors/Object3DNode.js +18 -34
- package/src/nodes/accessors/PointUVNode.js +30 -0
- package/src/nodes/accessors/Position.js +10 -0
- package/src/nodes/accessors/ReferenceBaseNode.js +171 -0
- package/{examples/jsm → src}/nodes/accessors/ReferenceNode.js +58 -9
- package/src/nodes/accessors/ReflectVector.js +10 -0
- package/src/nodes/accessors/RendererReferenceNode.js +35 -0
- package/{examples/jsm → src}/nodes/accessors/SceneNode.js +9 -6
- package/src/nodes/accessors/SkinningNode.js +191 -0
- package/src/nodes/accessors/StorageBufferNode.js +147 -0
- package/{examples/jsm/nodes/accessors/TextureStoreNode.js → src/nodes/accessors/StorageTextureNode.js} +35 -10
- package/src/nodes/accessors/Tangent.js +22 -0
- package/src/nodes/accessors/Texture3DNode.js +103 -0
- package/{examples/jsm/nodes/accessors/TextureBicubicNode.js → src/nodes/accessors/TextureBicubic.js} +3 -32
- package/{examples/jsm → src}/nodes/accessors/TextureNode.js +123 -39
- package/src/nodes/accessors/TextureSizeNode.js +36 -0
- package/src/nodes/accessors/UV.js +3 -0
- package/{examples/jsm/nodes/accessors/UniformsNode.js → src/nodes/accessors/UniformArrayNode.js} +33 -15
- package/{examples/jsm → src}/nodes/accessors/UserDataNode.js +10 -7
- package/src/nodes/accessors/VelocityNode.js +134 -0
- package/{examples/jsm → src}/nodes/accessors/VertexColorNode.js +9 -5
- package/{examples/jsm → src}/nodes/code/CodeNode.js +9 -5
- package/{examples/jsm → src}/nodes/code/ExpressionNode.js +10 -6
- package/{examples/jsm → src}/nodes/code/FunctionCallNode.js +8 -5
- package/{examples/jsm → src}/nodes/code/FunctionNode.js +8 -31
- package/{examples/jsm → src}/nodes/code/ScriptableNode.js +24 -7
- package/{examples/jsm → src}/nodes/code/ScriptableValueNode.js +11 -8
- package/{examples/jsm → src}/nodes/core/AssignNode.js +12 -9
- package/{examples/jsm → src}/nodes/core/AttributeNode.js +29 -12
- package/{examples/jsm → src}/nodes/core/BypassNode.js +11 -7
- package/src/nodes/core/CacheNode.js +50 -0
- package/{examples/jsm → src}/nodes/core/ConstNode.js +6 -3
- package/{examples/jsm → src}/nodes/core/ContextNode.js +27 -11
- package/src/nodes/core/IndexNode.js +99 -0
- package/{examples/jsm → src}/nodes/core/InputNode.js +7 -3
- package/{examples/jsm → src}/nodes/core/LightingModel.js +2 -2
- package/src/nodes/core/MRTNode.js +85 -0
- package/{examples/jsm → src}/nodes/core/Node.js +114 -57
- package/{examples/jsm → src}/nodes/core/NodeBuilder.js +327 -90
- package/src/nodes/core/NodeCache.js +36 -0
- package/{examples/jsm → src}/nodes/core/NodeFrame.js +52 -10
- package/{examples/jsm → src}/nodes/core/NodeFunction.js +2 -2
- package/{examples/jsm → src}/nodes/core/NodeUniform.js +1 -2
- package/{examples/jsm → src}/nodes/core/NodeUtils.js +56 -8
- package/{examples/jsm → src}/nodes/core/OutputStructNode.js +13 -12
- package/{examples/jsm → src}/nodes/core/ParameterNode.js +7 -4
- package/src/nodes/core/PropertyNode.js +88 -0
- package/{examples/jsm → src}/nodes/core/StackNode.js +31 -11
- package/{examples/jsm → src}/nodes/core/StructTypeNode.js +7 -3
- package/{examples/jsm → src}/nodes/core/TempNode.js +10 -6
- package/src/nodes/core/UniformGroupNode.js +59 -0
- package/{examples/jsm → src}/nodes/core/UniformNode.js +37 -5
- package/{examples/jsm → src}/nodes/core/VarNode.js +14 -14
- package/src/nodes/core/VaryingNode.js +108 -0
- package/{examples/jsm → src}/nodes/display/AfterImageNode.js +38 -28
- package/src/nodes/display/AnaglyphPassNode.js +67 -0
- package/{examples/jsm → src}/nodes/display/AnamorphicNode.js +33 -30
- package/src/nodes/display/BleachBypass.js +26 -0
- package/src/nodes/display/BlendMode.js +54 -0
- package/src/nodes/display/BloomNode.js +341 -0
- package/{examples/jsm → src}/nodes/display/BumpMapNode.js +20 -38
- package/src/nodes/display/ColorAdjustment.js +46 -0
- package/src/nodes/display/ColorSpaceFunctions.js +38 -0
- package/src/nodes/display/ColorSpaceNode.js +114 -0
- package/src/nodes/display/DenoiseNode.js +204 -0
- package/src/nodes/display/DepthOfFieldNode.js +124 -0
- package/src/nodes/display/DotScreenNode.js +66 -0
- package/src/nodes/display/FXAANode.js +332 -0
- package/src/nodes/display/FilmNode.js +56 -0
- package/src/nodes/display/FrontFacingNode.js +45 -0
- package/src/nodes/display/GTAONode.js +331 -0
- package/{examples/jsm → src}/nodes/display/GaussianBlurNode.js +47 -24
- package/src/nodes/display/Lut3DNode.js +57 -0
- package/src/nodes/display/MotionBlur.js +25 -0
- package/{examples/jsm → src}/nodes/display/NormalMapNode.js +14 -14
- package/src/nodes/display/ParallaxBarrierPassNode.js +58 -0
- package/src/nodes/display/PassNode.js +378 -0
- package/src/nodes/display/PixelationPassNode.js +213 -0
- package/{examples/jsm → src}/nodes/display/PosterizeNode.js +8 -7
- package/src/nodes/display/RGBShiftNode.js +53 -0
- package/src/nodes/display/RenderOutputNode.js +60 -0
- 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 +126 -0
- 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 +67 -0
- package/src/nodes/display/ToonOutlinePassNode.js +111 -0
- package/src/nodes/display/TransitionNode.js +80 -0
- package/src/nodes/display/ViewportDepthNode.js +125 -0
- package/src/nodes/display/ViewportDepthTextureNode.js +33 -0
- package/src/nodes/display/ViewportSharedTextureNode.js +39 -0
- package/{examples/jsm → src}/nodes/display/ViewportTextureNode.js +20 -14
- package/src/nodes/fog/FogExp2Node.js +35 -0
- package/src/nodes/fog/FogNode.js +50 -0
- package/src/nodes/fog/FogRangeNode.js +36 -0
- package/src/nodes/functions/BSDF/BRDF_GGX.js +59 -0
- package/{examples/jsm → src}/nodes/functions/BSDF/BRDF_Lambert.js +2 -2
- package/{examples/jsm → src}/nodes/functions/BSDF/BRDF_Sheen.js +6 -6
- package/{examples/jsm → src}/nodes/functions/BSDF/DFGApprox.js +2 -2
- package/{examples/jsm → src}/nodes/functions/BSDF/D_GGX.js +2 -2
- package/src/nodes/functions/BSDF/D_GGX_Anisotropic.js +28 -0
- package/{examples/jsm → src}/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
- package/{examples/jsm → src}/nodes/functions/BSDF/F_Schlick.js +2 -2
- package/src/nodes/functions/BSDF/LTC.js +131 -0
- package/{examples/jsm → src}/nodes/functions/BSDF/Schlick_to_F0.js +2 -2
- package/{examples/jsm → src}/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +2 -4
- package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +29 -0
- package/src/nodes/functions/BasicLightingModel.js +78 -0
- package/{examples/jsm → src}/nodes/functions/PhongLightingModel.js +11 -9
- package/src/nodes/functions/PhysicalLightingModel.js +633 -0
- package/src/nodes/functions/ShadowMaskModel.js +31 -0
- package/src/nodes/functions/ToonLightingModel.js +51 -0
- package/src/nodes/functions/material/getGeometryRoughness.js +13 -0
- package/{examples/jsm → src}/nodes/functions/material/getRoughness.js +2 -2
- package/src/nodes/functions/material/getShIrradianceAt.js +28 -0
- package/{examples/jsm → src}/nodes/geometry/RangeNode.js +28 -11
- 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/{examples/jsm → src}/nodes/gpgpu/ComputeNode.js +10 -6
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +100 -0
- package/src/nodes/lighting/AONode.js +27 -0
- package/{examples/jsm → src}/nodes/lighting/AmbientLightNode.js +6 -8
- package/src/nodes/lighting/AnalyticLightNode.js +522 -0
- package/src/nodes/lighting/BasicEnvironmentNode.js +30 -0
- package/src/nodes/lighting/BasicLightMapNode.js +32 -0
- package/{examples/jsm → src}/nodes/lighting/DirectionalLightNode.js +7 -9
- package/src/nodes/lighting/EnvironmentNode.js +138 -0
- package/{examples/jsm → src}/nodes/lighting/HemisphereLightNode.js +12 -11
- package/{examples/jsm → src}/nodes/lighting/IESSpotLightNode.js +7 -9
- package/src/nodes/lighting/IrradianceNode.js +27 -0
- package/src/nodes/lighting/LightProbeNode.js +53 -0
- package/{examples/jsm → src}/nodes/lighting/LightUtils.js +3 -3
- package/src/nodes/lighting/LightingContextNode.js +67 -0
- package/{examples/jsm → src}/nodes/lighting/LightingNode.js +9 -3
- package/src/nodes/lighting/LightsNode.js +250 -0
- package/{examples/jsm → src}/nodes/lighting/PointLightNode.js +12 -13
- package/src/nodes/lighting/RectAreaLightNode.js +97 -0
- package/{examples/jsm → src}/nodes/lighting/SpotLightNode.js +14 -16
- package/{examples/jsm → src}/nodes/materialx/MaterialXNodes.js +2 -2
- package/src/nodes/materialx/lib/mx_hsv.js +127 -0
- package/{examples/jsm → src}/nodes/materialx/lib/mx_noise.js +500 -603
- package/{examples/jsm → src}/nodes/materialx/lib/mx_transform_color.js +3 -9
- package/{examples/jsm/nodes/math/CondNode.js → src/nodes/math/ConditionalNode.js} +48 -13
- package/src/nodes/math/Hash.js +13 -0
- package/src/nodes/math/MathNode.js +407 -0
- package/{examples/jsm → src}/nodes/math/MathUtils.js +0 -7
- package/src/nodes/math/OperatorNode.js +319 -0
- package/{examples/jsm → src}/nodes/math/TriNoise3D.js +19 -29
- package/{examples/jsm → src}/nodes/parsers/GLSLNodeFunction.js +7 -7
- package/src/nodes/pmrem/PMREMNode.js +240 -0
- package/src/nodes/pmrem/PMREMUtils.js +288 -0
- package/src/nodes/procedural/Checker.js +14 -0
- package/src/nodes/tsl/TSLBase.js +30 -0
- package/{examples/jsm/nodes/shadernode/ShaderNode.js → src/nodes/tsl/TSLCore.js} +122 -96
- package/{examples/jsm → src}/nodes/utils/ArrayElementNode.js +9 -5
- package/{examples/jsm → 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 +36 -0
- package/src/nodes/utils/FlipNode.js +68 -0
- package/{examples/jsm → src}/nodes/utils/FunctionOverloadingNode.js +11 -5
- package/{examples/jsm → src}/nodes/utils/JoinNode.js +6 -3
- package/{examples/jsm → src}/nodes/utils/LoopNode.js +23 -12
- package/src/nodes/utils/MatcapUVNode.js +33 -0
- package/{examples/jsm → src}/nodes/utils/MaxMipLevelNode.js +16 -7
- package/{examples/jsm → src}/nodes/utils/OscNode.js +12 -8
- package/src/nodes/utils/Packing.js +4 -0
- package/src/nodes/utils/RTTNode.js +133 -0
- package/{examples/jsm → src}/nodes/utils/ReflectorNode.js +21 -5
- package/{examples/jsm → src}/nodes/utils/RemapNode.js +12 -8
- package/{examples/jsm → src}/nodes/utils/RotateNode.js +8 -13
- package/{examples/jsm → src}/nodes/utils/SetNode.js +7 -4
- package/{examples/jsm → src}/nodes/utils/SplitNode.js +7 -3
- package/{examples/jsm → src}/nodes/utils/SpriteSheetUVNode.js +10 -6
- package/src/nodes/utils/SpriteUtils.js +47 -0
- package/{examples/jsm → src}/nodes/utils/StorageArrayElementNode.js +11 -12
- package/{examples/jsm → src}/nodes/utils/TimerNode.js +8 -5
- package/{examples/jsm → 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 +302 -144
- package/src/objects/InstancedMesh.js +11 -1
- package/src/objects/LOD.js +21 -0
- package/src/objects/Line.js +67 -43
- package/src/objects/Mesh.js +7 -23
- package/src/objects/Points.js +2 -0
- package/src/renderers/WebGLRenderer.js +473 -224
- package/{examples/jsm → src}/renderers/common/Animation.js +3 -0
- package/{examples/jsm → src}/renderers/common/Attributes.js +4 -1
- package/{examples/jsm → src}/renderers/common/Backend.js +30 -27
- package/{examples/jsm → src}/renderers/common/Background.js +18 -10
- package/src/renderers/common/BindGroup.js +18 -0
- package/src/renderers/common/Bindings.js +203 -0
- package/src/renderers/common/BundleGroup.js +26 -0
- package/src/renderers/common/ChainMap.js +59 -0
- package/{examples/jsm → src}/renderers/common/ClippingContext.js +24 -12
- package/{examples/jsm → src}/renderers/common/Color4.js +1 -1
- package/{examples/jsm → src}/renderers/common/CubeRenderTarget.js +16 -4
- package/{examples/jsm → src}/renderers/common/Geometries.js +37 -5
- package/{examples/jsm → src}/renderers/common/Info.js +35 -15
- package/{examples/jsm → src}/renderers/common/Pipelines.js +2 -2
- package/src/renderers/common/PostProcessing.js +90 -0
- package/src/renderers/common/QuadMesh.js +55 -0
- package/src/renderers/common/RenderBundle.js +18 -0
- package/src/renderers/common/RenderBundles.js +38 -0
- package/{examples/jsm → src}/renderers/common/RenderContext.js +25 -2
- package/{examples/jsm → src}/renderers/common/RenderContexts.js +1 -1
- package/{examples/jsm → src}/renderers/common/RenderList.js +11 -2
- package/src/renderers/common/RenderObject.js +413 -0
- package/{examples/jsm → src}/renderers/common/RenderObjects.js +9 -2
- package/{examples/jsm → src}/renderers/common/Renderer.js +431 -83
- package/{examples/jsm → src}/renderers/common/SampledTexture.js +14 -5
- package/{examples/jsm → src}/renderers/common/StorageBufferAttribute.js +1 -1
- package/{examples/jsm → src}/renderers/common/StorageInstancedBufferAttribute.js +1 -1
- package/{examples/jsm → src}/renderers/common/StorageTexture.js +2 -1
- package/{examples/jsm → src}/renderers/common/Textures.js +15 -15
- package/{examples/jsm → src}/renderers/common/Uniform.js +10 -5
- package/{examples/jsm → src}/renderers/common/UniformsGroup.js +69 -31
- package/src/renderers/common/extras/PMREMGenerator.js +771 -0
- package/src/renderers/common/nodes/NodeBuilderState.js +58 -0
- package/src/renderers/common/nodes/NodeLibrary.js +118 -0
- package/src/renderers/common/nodes/NodeSampledTexture.js +64 -0
- package/{examples/jsm → src}/renderers/common/nodes/NodeSampler.js +8 -1
- package/{examples/jsm → src}/renderers/common/nodes/NodeStorageBuffer.js +5 -1
- package/{examples/jsm → src}/renderers/common/nodes/NodeUniform.js +3 -3
- package/{examples/jsm → src}/renderers/common/nodes/NodeUniformBuffer.js +2 -1
- package/{examples/jsm → src}/renderers/common/nodes/NodeUniformsGroup.js +2 -8
- package/{examples/jsm → src}/renderers/common/nodes/Nodes.js +106 -68
- package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +31 -1
- package/src/renderers/shaders/ShaderChunk/batching_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +9 -1
- package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +0 -9
- package/src/renderers/shaders/ShaderChunk/common.glsl.js +0 -10
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +3 -3
- package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +8 -22
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +1 -0
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +2 -10
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +2 -16
- package/src/renderers/shaders/ShaderChunk/morphcolor_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/morphinstance_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl.js +3 -14
- package/src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl.js +10 -31
- package/src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl.js +3 -23
- package/src/renderers/shaders/ShaderChunk/packing.glsl.js +45 -13
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +38 -25
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl.js +3 -0
- package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +3 -3
- package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +19 -11
- package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +47 -13
- package/src/renderers/shaders/ShaderChunk.js +0 -2
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +8 -0
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -0
- package/src/renderers/shaders/ShaderLib/sprite.glsl.js +2 -4
- package/src/renderers/shaders/ShaderLib.js +2 -1
- package/src/renderers/shaders/UniformsLib.js +3 -0
- package/src/renderers/shaders/UniformsUtils.js +10 -1
- package/src/renderers/webgl/WebGLAttributes.js +42 -38
- package/src/renderers/webgl/WebGLBackground.js +24 -3
- package/src/renderers/webgl/WebGLBindingStates.js +14 -51
- package/src/renderers/webgl/WebGLBufferRenderer.js +23 -22
- package/src/renderers/webgl/WebGLCapabilities.js +44 -13
- package/src/renderers/webgl/WebGLCubeUVMaps.js +10 -6
- package/src/renderers/webgl/WebGLExtensions.js +7 -20
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +23 -21
- package/src/renderers/webgl/WebGLLights.js +21 -44
- package/src/renderers/webgl/WebGLMaterials.js +9 -8
- package/src/renderers/webgl/WebGLMorphtargets.js +78 -217
- package/src/renderers/webgl/WebGLProgram.js +46 -78
- package/src/renderers/webgl/WebGLPrograms.js +37 -40
- package/src/renderers/webgl/WebGLProperties.js +7 -0
- package/src/renderers/webgl/WebGLRenderStates.js +15 -9
- package/src/renderers/webgl/WebGLShadowMap.js +25 -25
- package/src/renderers/webgl/WebGLState.js +35 -58
- package/src/renderers/webgl/WebGLTextures.js +313 -358
- package/src/renderers/webgl/WebGLUniforms.js +12 -2
- package/src/renderers/webgl/WebGLUniformsGroups.js +8 -8
- package/src/renderers/webgl/WebGLUtils.js +9 -78
- package/{examples/jsm/renderers/webgl → src/renderers/webgl-fallback}/WebGLBackend.js +389 -152
- package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +145 -0
- package/{examples/jsm/renderers/webgl → src/renderers/webgl-fallback}/nodes/GLSLNodeBuilder.js +245 -44
- package/{examples/jsm/renderers/webgl → src/renderers/webgl-fallback}/utils/WebGLAttributeUtils.js +7 -1
- package/{examples/jsm/renderers/webgl → src/renderers/webgl-fallback}/utils/WebGLConstants.js +2 -0
- package/{examples/jsm/renderers/webgl → src/renderers/webgl-fallback}/utils/WebGLExtensions.js +2 -0
- package/{examples/jsm/renderers/webgl → src/renderers/webgl-fallback}/utils/WebGLState.js +21 -3
- package/{examples/jsm/renderers/webgl → src/renderers/webgl-fallback}/utils/WebGLTextureUtils.js +271 -43
- package/{examples/jsm/renderers/webgl → src/renderers/webgl-fallback}/utils/WebGLUtils.js +6 -23
- package/{examples/jsm → src}/renderers/webgpu/WebGPUBackend.js +318 -141
- package/src/renderers/webgpu/WebGPURenderer.Nodes.js +42 -0
- package/{examples/jsm → src}/renderers/webgpu/WebGPURenderer.js +10 -7
- package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +59 -0
- package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +105 -0
- package/{examples/jsm → src}/renderers/webgpu/nodes/WGSLNodeBuilder.js +424 -95
- package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +159 -0
- package/{examples/jsm → src}/renderers/webgpu/utils/WebGPUAttributeUtils.js +37 -18
- package/{examples/jsm → src}/renderers/webgpu/utils/WebGPUBindingUtils.js +86 -32
- package/{examples/jsm → src}/renderers/webgpu/utils/WebGPUConstants.js +10 -1
- package/{examples/jsm → src}/renderers/webgpu/utils/WebGPUPipelineUtils.js +68 -27
- package/{examples/jsm → src}/renderers/webgpu/utils/WebGPUTexturePassUtils.js +62 -5
- package/{examples/jsm → src}/renderers/webgpu/utils/WebGPUTextureUtils.js +235 -68
- package/{examples/jsm → src}/renderers/webgpu/utils/WebGPUUtils.js +43 -5
- package/src/renderers/webxr/WebXRDepthSensing.js +11 -6
- package/src/renderers/webxr/WebXRManager.js +53 -38
- package/src/scenes/Scene.js +7 -1
- package/src/textures/CompressedArrayTexture.js +14 -0
- package/src/textures/DataArrayTexture.js +14 -0
- package/src/textures/DepthTexture.js +1 -3
- package/src/textures/Texture.js +12 -2
- package/src/utils.js +62 -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/nodes/Nodes.js +0 -195
- package/examples/jsm/nodes/accessors/AccessorsUtils.js +0 -10
- package/examples/jsm/nodes/accessors/BitangentNode.js +0 -89
- package/examples/jsm/nodes/accessors/CameraNode.js +0 -119
- package/examples/jsm/nodes/accessors/CubeTextureNode.js +0 -61
- package/examples/jsm/nodes/accessors/InstanceNode.js +0 -71
- package/examples/jsm/nodes/accessors/InstancedPointsMaterialNode.js +0 -21
- package/examples/jsm/nodes/accessors/MaterialNode.js +0 -314
- package/examples/jsm/nodes/accessors/ModelNode.js +0 -33
- package/examples/jsm/nodes/accessors/ModelViewProjectionNode.js +0 -39
- package/examples/jsm/nodes/accessors/NormalNode.js +0 -96
- package/examples/jsm/nodes/accessors/PointUVNode.js +0 -26
- package/examples/jsm/nodes/accessors/PositionNode.js +0 -104
- package/examples/jsm/nodes/accessors/ReflectVectorNode.js +0 -35
- package/examples/jsm/nodes/accessors/SkinningNode.js +0 -124
- package/examples/jsm/nodes/accessors/StorageBufferNode.js +0 -72
- package/examples/jsm/nodes/accessors/TangentNode.js +0 -109
- package/examples/jsm/nodes/accessors/TextureSizeNode.js +0 -35
- package/examples/jsm/nodes/accessors/UVNode.js +0 -47
- package/examples/jsm/nodes/core/CacheNode.js +0 -49
- package/examples/jsm/nodes/core/IndexNode.js +0 -66
- package/examples/jsm/nodes/core/NodeCache.js +0 -26
- package/examples/jsm/nodes/core/NodeKeywords.js +0 -80
- package/examples/jsm/nodes/core/PropertyNode.js +0 -72
- package/examples/jsm/nodes/core/UniformGroupNode.js +0 -36
- package/examples/jsm/nodes/core/VaryingNode.js +0 -65
- package/examples/jsm/nodes/display/BlendModeNode.js +0 -128
- package/examples/jsm/nodes/display/ColorAdjustmentNode.js +0 -99
- package/examples/jsm/nodes/display/ColorSpaceNode.js +0 -108
- package/examples/jsm/nodes/display/FrontFacingNode.js +0 -27
- package/examples/jsm/nodes/display/PassNode.js +0 -183
- package/examples/jsm/nodes/display/ToneMappingNode.js +0 -184
- package/examples/jsm/nodes/display/ViewportDepthNode.js +0 -97
- package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +0 -31
- package/examples/jsm/nodes/display/ViewportNode.js +0 -134
- package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +0 -31
- package/examples/jsm/nodes/fog/FogExp2Node.js +0 -35
- package/examples/jsm/nodes/fog/FogNode.js +0 -38
- package/examples/jsm/nodes/fog/FogRangeNode.js +0 -34
- package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +0 -40
- package/examples/jsm/nodes/functions/PhysicalLightingModel.js +0 -393
- package/examples/jsm/nodes/functions/material/getGeometryRoughness.js +0 -13
- package/examples/jsm/nodes/lighting/AONode.js +0 -27
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +0 -241
- package/examples/jsm/nodes/lighting/EnvironmentNode.js +0 -181
- package/examples/jsm/nodes/lighting/LightNode.js +0 -57
- package/examples/jsm/nodes/lighting/LightingContextNode.js +0 -66
- package/examples/jsm/nodes/lighting/LightsNode.js +0 -188
- package/examples/jsm/nodes/materials/InstancedPointsNodeMaterial.js +0 -162
- package/examples/jsm/nodes/materials/LineBasicNodeMaterial.js +0 -28
- package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +0 -28
- package/examples/jsm/nodes/materials/MeshLambertNodeMaterial.js +0 -34
- package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +0 -40
- package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +0 -65
- package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +0 -155
- package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +0 -80
- package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +0 -90
- package/examples/jsm/nodes/materialx/lib/mx_hsv.js +0 -130
- package/examples/jsm/nodes/math/HashNode.js +0 -34
- package/examples/jsm/nodes/math/MathNode.js +0 -391
- package/examples/jsm/nodes/math/OperatorNode.js +0 -274
- package/examples/jsm/nodes/procedural/CheckerNode.js +0 -42
- package/examples/jsm/nodes/utils/DiscardNode.js +0 -27
- package/examples/jsm/nodes/utils/EquirectUVNode.js +0 -33
- package/examples/jsm/nodes/utils/MatcapUVNode.js +0 -30
- package/examples/jsm/nodes/utils/PackingNode.js +0 -55
- package/examples/jsm/nodes/utils/RotateUVNode.js +0 -35
- package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +0 -37
- package/examples/jsm/objects/QuadMesh.js +0 -66
- package/examples/jsm/renderers/common/Bindings.js +0 -173
- package/examples/jsm/renderers/common/ChainMap.js +0 -89
- package/examples/jsm/renderers/common/PostProcessing.js +0 -25
- package/examples/jsm/renderers/common/RenderObject.js +0 -221
- package/examples/jsm/renderers/common/nodes/NodeBuilderState.js +0 -44
- package/examples/jsm/renderers/common/nodes/NodeSampledTexture.js +0 -49
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js +0 -104
- package/examples/jsm/utils/GPUStatsPanel.js +0 -128
- package/examples/jsm/utils/PackedPhongMaterial.js +0 -178
- package/src/renderers/WebGL1Renderer.js +0 -7
- package/src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl.js +0 -10
- /package/{examples/jsm → src}/nodes/core/NodeAttribute.js +0 -0
- /package/{examples/jsm → src}/nodes/core/NodeCode.js +0 -0
- /package/{examples/jsm → src}/nodes/core/NodeFunctionInput.js +0 -0
- /package/{examples/jsm → src}/nodes/core/NodeParser.js +0 -0
- /package/{examples/jsm → src}/nodes/core/NodeVar.js +0 -0
- /package/{examples/jsm → src}/nodes/core/NodeVarying.js +0 -0
- /package/{examples/jsm → src}/nodes/core/UniformGroup.js +0 -0
- /package/{examples/jsm → src}/nodes/core/constants.js +0 -0
- /package/{examples/jsm → src}/nodes/materialx/DISCLAIMER.md +0 -0
- /package/{examples/jsm → src}/nodes/parsers/GLSLNodeParser.js +0 -0
- /package/{examples/jsm → src}/renderers/common/Binding.js +0 -0
- /package/{examples/jsm → src}/renderers/common/Buffer.js +0 -0
- /package/{examples/jsm → src}/renderers/common/BufferUtils.js +0 -0
- /package/{examples/jsm → src}/renderers/common/ComputePipeline.js +0 -0
- /package/{examples/jsm → src}/renderers/common/Constants.js +0 -0
- /package/{examples/jsm → src}/renderers/common/DataMap.js +0 -0
- /package/{examples/jsm → src}/renderers/common/Pipeline.js +0 -0
- /package/{examples/jsm → src}/renderers/common/ProgrammableStage.js +0 -0
- /package/{examples/jsm → src}/renderers/common/RenderLists.js +0 -0
- /package/{examples/jsm → src}/renderers/common/RenderPipeline.js +0 -0
- /package/{examples/jsm → src}/renderers/common/Sampler.js +0 -0
- /package/{examples/jsm → src}/renderers/common/StorageBuffer.js +0 -0
- /package/{examples/jsm → src}/renderers/common/UniformBuffer.js +0 -0
- /package/{examples/jsm/renderers/webgl → src/renderers/webgl-fallback}/utils/WebGLCapabilities.js +0 -0
- /package/{examples/jsm → src}/renderers/webgpu/nodes/WGSLNodeParser.js +0 -0
|
@@ -0,0 +1,771 @@
|
|
|
1
|
+
import NodeMaterial from '../../../materials/nodes/NodeMaterial.js';
|
|
2
|
+
import { getDirection, blur } from '../../../nodes/pmrem/PMREMUtils.js';
|
|
3
|
+
import { equirectUV } from '../../../nodes/utils/EquirectUVNode.js';
|
|
4
|
+
import { uniform } from '../../../nodes/core/UniformNode.js';
|
|
5
|
+
import { uniformArray } from '../../../nodes/accessors/UniformArrayNode.js';
|
|
6
|
+
import { texture } from '../../../nodes/accessors/TextureNode.js';
|
|
7
|
+
import { cubeTexture } from '../../../nodes/accessors/CubeTextureNode.js';
|
|
8
|
+
import { float, vec3 } from '../../../nodes/tsl/TSLBase.js';
|
|
9
|
+
import { uv } from '../../../nodes/accessors/UV.js';
|
|
10
|
+
import { attribute } from '../../../nodes/core/AttributeNode.js';
|
|
11
|
+
|
|
12
|
+
import { OrthographicCamera } from '../../../cameras/OrthographicCamera.js';
|
|
13
|
+
import { Color } from '../../../math/Color.js';
|
|
14
|
+
import { Vector3 } from '../../../math/Vector3.js';
|
|
15
|
+
import { BufferGeometry } from '../../../core/BufferGeometry.js';
|
|
16
|
+
import { BufferAttribute } from '../../../core/BufferAttribute.js';
|
|
17
|
+
import { RenderTarget } from '../../../core/RenderTarget.js';
|
|
18
|
+
import { Mesh } from '../../../objects/Mesh.js';
|
|
19
|
+
import { PerspectiveCamera } from '../../../cameras/PerspectiveCamera.js';
|
|
20
|
+
import { MeshBasicMaterial } from '../../../materials/MeshBasicMaterial.js';
|
|
21
|
+
import { BoxGeometry } from '../../../geometries/BoxGeometry.js';
|
|
22
|
+
import {
|
|
23
|
+
CubeReflectionMapping,
|
|
24
|
+
CubeRefractionMapping,
|
|
25
|
+
CubeUVReflectionMapping,
|
|
26
|
+
LinearFilter,
|
|
27
|
+
NoBlending,
|
|
28
|
+
RGBAFormat,
|
|
29
|
+
HalfFloatType,
|
|
30
|
+
BackSide,
|
|
31
|
+
LinearSRGBColorSpace
|
|
32
|
+
} from '../../../constants.js';
|
|
33
|
+
|
|
34
|
+
const LOD_MIN = 4;
|
|
35
|
+
|
|
36
|
+
// The standard deviations (radians) associated with the extra mips. These are
|
|
37
|
+
// chosen to approximate a Trowbridge-Reitz distribution function times the
|
|
38
|
+
// geometric shadowing function. These sigma values squared must match the
|
|
39
|
+
// variance #defines in cube_uv_reflection_fragment.glsl.js.
|
|
40
|
+
const EXTRA_LOD_SIGMA = [ 0.125, 0.215, 0.35, 0.446, 0.526, 0.582 ];
|
|
41
|
+
|
|
42
|
+
// The maximum length of the blur for loop. Smaller sigmas will use fewer
|
|
43
|
+
// samples and exit early, but not recompile the shader.
|
|
44
|
+
const MAX_SAMPLES = 20;
|
|
45
|
+
|
|
46
|
+
const _flatCamera = /*@__PURE__*/ new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
|
|
47
|
+
const _cubeCamera = /*@__PURE__*/ new PerspectiveCamera( 90, 1 );
|
|
48
|
+
const _clearColor = /*@__PURE__*/ new Color();
|
|
49
|
+
let _oldTarget = null;
|
|
50
|
+
let _oldActiveCubeFace = 0;
|
|
51
|
+
let _oldActiveMipmapLevel = 0;
|
|
52
|
+
|
|
53
|
+
// Golden Ratio
|
|
54
|
+
const PHI = ( 1 + Math.sqrt( 5 ) ) / 2;
|
|
55
|
+
const INV_PHI = 1 / PHI;
|
|
56
|
+
|
|
57
|
+
// Vertices of a dodecahedron (except the opposites, which represent the
|
|
58
|
+
// same axis), used as axis directions evenly spread on a sphere.
|
|
59
|
+
const _axisDirections = [
|
|
60
|
+
/*@__PURE__*/ new Vector3( - PHI, INV_PHI, 0 ),
|
|
61
|
+
/*@__PURE__*/ new Vector3( PHI, INV_PHI, 0 ),
|
|
62
|
+
/*@__PURE__*/ new Vector3( - INV_PHI, 0, PHI ),
|
|
63
|
+
/*@__PURE__*/ new Vector3( INV_PHI, 0, PHI ),
|
|
64
|
+
/*@__PURE__*/ new Vector3( 0, PHI, - INV_PHI ),
|
|
65
|
+
/*@__PURE__*/ new Vector3( 0, PHI, INV_PHI ),
|
|
66
|
+
/*@__PURE__*/ new Vector3( - 1, 1, - 1 ),
|
|
67
|
+
/*@__PURE__*/ new Vector3( 1, 1, - 1 ),
|
|
68
|
+
/*@__PURE__*/ new Vector3( - 1, 1, 1 ),
|
|
69
|
+
/*@__PURE__*/ new Vector3( 1, 1, 1 )
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
//
|
|
73
|
+
|
|
74
|
+
// WebGPU Face indices
|
|
75
|
+
const _faceLib = [
|
|
76
|
+
3, 1, 5,
|
|
77
|
+
0, 4, 2
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
const direction = getDirection( uv(), attribute( 'faceIndex' ) ).normalize();
|
|
81
|
+
const outputDirection = vec3( direction.x, direction.y.negate(), direction.z );
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* This class generates a Prefiltered, Mipmapped Radiance Environment Map
|
|
85
|
+
* (PMREM) from a cubeMap environment texture. This allows different levels of
|
|
86
|
+
* blur to be quickly accessed based on material roughness. It is packed into a
|
|
87
|
+
* special CubeUV format that allows us to perform custom interpolation so that
|
|
88
|
+
* we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
|
|
89
|
+
* chain, it only goes down to the LOD_MIN level (above), and then creates extra
|
|
90
|
+
* even more filtered 'mips' at the same LOD_MIN resolution, associated with
|
|
91
|
+
* higher roughness levels. In this way we maintain resolution to smoothly
|
|
92
|
+
* interpolate diffuse lighting while limiting sampling computation.
|
|
93
|
+
*
|
|
94
|
+
* Paper: Fast, Accurate Image-Based Lighting
|
|
95
|
+
* https://drive.google.com/file/d/15y8r_UpKlU9SvV4ILb0C3qCPecS8pvLz/view
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
class PMREMGenerator {
|
|
99
|
+
|
|
100
|
+
constructor( renderer ) {
|
|
101
|
+
|
|
102
|
+
this._renderer = renderer;
|
|
103
|
+
this._pingPongRenderTarget = null;
|
|
104
|
+
|
|
105
|
+
this._lodMax = 0;
|
|
106
|
+
this._cubeSize = 0;
|
|
107
|
+
this._lodPlanes = [];
|
|
108
|
+
this._sizeLods = [];
|
|
109
|
+
this._sigmas = [];
|
|
110
|
+
this._lodMeshes = [];
|
|
111
|
+
|
|
112
|
+
this._blurMaterial = null;
|
|
113
|
+
this._cubemapMaterial = null;
|
|
114
|
+
this._equirectMaterial = null;
|
|
115
|
+
this._backgroundBox = null;
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Generates a PMREM from a supplied Scene, which can be faster than using an
|
|
121
|
+
* image if networking bandwidth is low. Optional sigma specifies a blur radius
|
|
122
|
+
* in radians to be applied to the scene before PMREM generation. Optional near
|
|
123
|
+
* and far planes ensure the scene is rendered in its entirety (the cubeCamera
|
|
124
|
+
* is placed at the origin).
|
|
125
|
+
*/
|
|
126
|
+
fromScene( scene, sigma = 0, near = 0.1, far = 100 ) {
|
|
127
|
+
|
|
128
|
+
_oldTarget = this._renderer.getRenderTarget();
|
|
129
|
+
_oldActiveCubeFace = this._renderer.getActiveCubeFace();
|
|
130
|
+
_oldActiveMipmapLevel = this._renderer.getActiveMipmapLevel();
|
|
131
|
+
|
|
132
|
+
this._setSize( 256 );
|
|
133
|
+
|
|
134
|
+
const cubeUVRenderTarget = this._allocateTargets();
|
|
135
|
+
cubeUVRenderTarget.depthBuffer = true;
|
|
136
|
+
|
|
137
|
+
this._sceneToCubeUV( scene, near, far, cubeUVRenderTarget );
|
|
138
|
+
|
|
139
|
+
if ( sigma > 0 ) {
|
|
140
|
+
|
|
141
|
+
this._blur( cubeUVRenderTarget, 0, 0, sigma );
|
|
142
|
+
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
this._applyPMREM( cubeUVRenderTarget );
|
|
146
|
+
|
|
147
|
+
this._cleanup( cubeUVRenderTarget );
|
|
148
|
+
|
|
149
|
+
return cubeUVRenderTarget;
|
|
150
|
+
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Generates a PMREM from an equirectangular texture, which can be either LDR
|
|
155
|
+
* or HDR. The ideal input image size is 1k (1024 x 512),
|
|
156
|
+
* as this matches best with the 256 x 256 cubemap output.
|
|
157
|
+
*/
|
|
158
|
+
fromEquirectangular( equirectangular, renderTarget = null ) {
|
|
159
|
+
|
|
160
|
+
return this._fromTexture( equirectangular, renderTarget );
|
|
161
|
+
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Generates a PMREM from an cubemap texture, which can be either LDR
|
|
166
|
+
* or HDR. The ideal input cube size is 256 x 256,
|
|
167
|
+
* as this matches best with the 256 x 256 cubemap output.
|
|
168
|
+
*/
|
|
169
|
+
fromCubemap( cubemap, renderTarget = null ) {
|
|
170
|
+
|
|
171
|
+
return this._fromTexture( cubemap, renderTarget );
|
|
172
|
+
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
|
|
177
|
+
* your texture's network fetch for increased concurrency.
|
|
178
|
+
*/
|
|
179
|
+
async compileCubemapShader() {
|
|
180
|
+
|
|
181
|
+
if ( this._cubemapMaterial === null ) {
|
|
182
|
+
|
|
183
|
+
this._cubemapMaterial = _getCubemapMaterial();
|
|
184
|
+
await this._compileMaterial( this._cubemapMaterial );
|
|
185
|
+
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
|
|
192
|
+
* your texture's network fetch for increased concurrency.
|
|
193
|
+
*/
|
|
194
|
+
async compileEquirectangularShader() {
|
|
195
|
+
|
|
196
|
+
if ( this._equirectMaterial === null ) {
|
|
197
|
+
|
|
198
|
+
this._equirectMaterial = _getEquirectMaterial();
|
|
199
|
+
await this._compileMaterial( this._equirectMaterial );
|
|
200
|
+
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
|
|
207
|
+
* so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
|
|
208
|
+
* one of them will cause any others to also become unusable.
|
|
209
|
+
*/
|
|
210
|
+
dispose() {
|
|
211
|
+
|
|
212
|
+
this._dispose();
|
|
213
|
+
|
|
214
|
+
if ( this._cubemapMaterial !== null ) this._cubemapMaterial.dispose();
|
|
215
|
+
if ( this._equirectMaterial !== null ) this._equirectMaterial.dispose();
|
|
216
|
+
if ( this._backgroundBox !== null ) {
|
|
217
|
+
|
|
218
|
+
this._backgroundBox.geometry.dispose();
|
|
219
|
+
this._backgroundBox.material.dispose();
|
|
220
|
+
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// private interface
|
|
226
|
+
|
|
227
|
+
_setSize( cubeSize ) {
|
|
228
|
+
|
|
229
|
+
this._lodMax = Math.floor( Math.log2( cubeSize ) );
|
|
230
|
+
this._cubeSize = Math.pow( 2, this._lodMax );
|
|
231
|
+
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
_dispose() {
|
|
235
|
+
|
|
236
|
+
if ( this._blurMaterial !== null ) this._blurMaterial.dispose();
|
|
237
|
+
|
|
238
|
+
if ( this._pingPongRenderTarget !== null ) this._pingPongRenderTarget.dispose();
|
|
239
|
+
|
|
240
|
+
for ( let i = 0; i < this._lodPlanes.length; i ++ ) {
|
|
241
|
+
|
|
242
|
+
this._lodPlanes[ i ].dispose();
|
|
243
|
+
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
_cleanup( outputTarget ) {
|
|
249
|
+
|
|
250
|
+
this._renderer.setRenderTarget( _oldTarget, _oldActiveCubeFace, _oldActiveMipmapLevel );
|
|
251
|
+
outputTarget.scissorTest = false;
|
|
252
|
+
_setViewport( outputTarget, 0, 0, outputTarget.width, outputTarget.height );
|
|
253
|
+
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
_fromTexture( texture, renderTarget ) {
|
|
257
|
+
|
|
258
|
+
if ( texture.mapping === CubeReflectionMapping || texture.mapping === CubeRefractionMapping ) {
|
|
259
|
+
|
|
260
|
+
this._setSize( texture.image.length === 0 ? 16 : ( texture.image[ 0 ].width || texture.image[ 0 ].image.width ) );
|
|
261
|
+
|
|
262
|
+
} else { // Equirectangular
|
|
263
|
+
|
|
264
|
+
this._setSize( texture.image.width / 4 );
|
|
265
|
+
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
_oldTarget = this._renderer.getRenderTarget();
|
|
269
|
+
_oldActiveCubeFace = this._renderer.getActiveCubeFace();
|
|
270
|
+
_oldActiveMipmapLevel = this._renderer.getActiveMipmapLevel();
|
|
271
|
+
|
|
272
|
+
const cubeUVRenderTarget = renderTarget || this._allocateTargets();
|
|
273
|
+
this._textureToCubeUV( texture, cubeUVRenderTarget );
|
|
274
|
+
this._applyPMREM( cubeUVRenderTarget );
|
|
275
|
+
this._cleanup( cubeUVRenderTarget );
|
|
276
|
+
|
|
277
|
+
return cubeUVRenderTarget;
|
|
278
|
+
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
_allocateTargets() {
|
|
282
|
+
|
|
283
|
+
const width = 3 * Math.max( this._cubeSize, 16 * 7 );
|
|
284
|
+
const height = 4 * this._cubeSize;
|
|
285
|
+
|
|
286
|
+
const params = {
|
|
287
|
+
magFilter: LinearFilter,
|
|
288
|
+
minFilter: LinearFilter,
|
|
289
|
+
generateMipmaps: false,
|
|
290
|
+
type: HalfFloatType,
|
|
291
|
+
format: RGBAFormat,
|
|
292
|
+
colorSpace: LinearSRGBColorSpace,
|
|
293
|
+
//depthBuffer: false
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
const cubeUVRenderTarget = _createRenderTarget( width, height, params );
|
|
297
|
+
|
|
298
|
+
if ( this._pingPongRenderTarget === null || this._pingPongRenderTarget.width !== width || this._pingPongRenderTarget.height !== height ) {
|
|
299
|
+
|
|
300
|
+
if ( this._pingPongRenderTarget !== null ) {
|
|
301
|
+
|
|
302
|
+
this._dispose();
|
|
303
|
+
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
this._pingPongRenderTarget = _createRenderTarget( width, height, params );
|
|
307
|
+
|
|
308
|
+
const { _lodMax } = this;
|
|
309
|
+
( { sizeLods: this._sizeLods, lodPlanes: this._lodPlanes, sigmas: this._sigmas, lodMeshes: this._lodMeshes } = _createPlanes( _lodMax ) );
|
|
310
|
+
|
|
311
|
+
this._blurMaterial = _getBlurShader( _lodMax, width, height );
|
|
312
|
+
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return cubeUVRenderTarget;
|
|
316
|
+
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
async _compileMaterial( material ) {
|
|
320
|
+
|
|
321
|
+
const tmpMesh = new Mesh( this._lodPlanes[ 0 ], material );
|
|
322
|
+
await this._renderer.compile( tmpMesh, _flatCamera );
|
|
323
|
+
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
_sceneToCubeUV( scene, near, far, cubeUVRenderTarget ) {
|
|
327
|
+
|
|
328
|
+
const cubeCamera = _cubeCamera;
|
|
329
|
+
cubeCamera.near = near;
|
|
330
|
+
cubeCamera.far = far;
|
|
331
|
+
|
|
332
|
+
// px, py, pz, nx, ny, nz
|
|
333
|
+
const upSign = [ - 1, 1, - 1, - 1, - 1, - 1 ];
|
|
334
|
+
const forwardSign = [ 1, 1, 1, - 1, - 1, - 1 ];
|
|
335
|
+
|
|
336
|
+
const renderer = this._renderer;
|
|
337
|
+
|
|
338
|
+
const originalAutoClear = renderer.autoClear;
|
|
339
|
+
|
|
340
|
+
renderer.getClearColor( _clearColor );
|
|
341
|
+
|
|
342
|
+
renderer.autoClear = false;
|
|
343
|
+
|
|
344
|
+
let backgroundBox = this._backgroundBox;
|
|
345
|
+
|
|
346
|
+
if ( backgroundBox === null ) {
|
|
347
|
+
|
|
348
|
+
const backgroundMaterial = new MeshBasicMaterial( {
|
|
349
|
+
name: 'PMREM.Background',
|
|
350
|
+
side: BackSide,
|
|
351
|
+
depthWrite: false,
|
|
352
|
+
depthTest: false
|
|
353
|
+
} );
|
|
354
|
+
|
|
355
|
+
backgroundBox = new Mesh( new BoxGeometry(), backgroundMaterial );
|
|
356
|
+
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
let useSolidColor = false;
|
|
360
|
+
const background = scene.background;
|
|
361
|
+
|
|
362
|
+
if ( background ) {
|
|
363
|
+
|
|
364
|
+
if ( background.isColor ) {
|
|
365
|
+
|
|
366
|
+
backgroundBox.material.color.copy( background );
|
|
367
|
+
scene.background = null;
|
|
368
|
+
useSolidColor = true;
|
|
369
|
+
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
} else {
|
|
373
|
+
|
|
374
|
+
backgroundBox.material.color.copy( _clearColor );
|
|
375
|
+
useSolidColor = true;
|
|
376
|
+
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
renderer.setRenderTarget( cubeUVRenderTarget );
|
|
380
|
+
|
|
381
|
+
renderer.clear();
|
|
382
|
+
|
|
383
|
+
if ( useSolidColor ) {
|
|
384
|
+
|
|
385
|
+
renderer.render( backgroundBox, cubeCamera );
|
|
386
|
+
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
for ( let i = 0; i < 6; i ++ ) {
|
|
390
|
+
|
|
391
|
+
const col = i % 3;
|
|
392
|
+
|
|
393
|
+
if ( col === 0 ) {
|
|
394
|
+
|
|
395
|
+
cubeCamera.up.set( 0, upSign[ i ], 0 );
|
|
396
|
+
cubeCamera.lookAt( forwardSign[ i ], 0, 0 );
|
|
397
|
+
|
|
398
|
+
} else if ( col === 1 ) {
|
|
399
|
+
|
|
400
|
+
cubeCamera.up.set( 0, 0, upSign[ i ] );
|
|
401
|
+
cubeCamera.lookAt( 0, forwardSign[ i ], 0 );
|
|
402
|
+
|
|
403
|
+
} else {
|
|
404
|
+
|
|
405
|
+
cubeCamera.up.set( 0, upSign[ i ], 0 );
|
|
406
|
+
cubeCamera.lookAt( 0, 0, forwardSign[ i ] );
|
|
407
|
+
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
const size = this._cubeSize;
|
|
411
|
+
|
|
412
|
+
_setViewport( cubeUVRenderTarget, col * size, i > 2 ? size : 0, size, size );
|
|
413
|
+
|
|
414
|
+
renderer.render( scene, cubeCamera );
|
|
415
|
+
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
renderer.autoClear = originalAutoClear;
|
|
419
|
+
scene.background = background;
|
|
420
|
+
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
_textureToCubeUV( texture, cubeUVRenderTarget ) {
|
|
424
|
+
|
|
425
|
+
const renderer = this._renderer;
|
|
426
|
+
|
|
427
|
+
const isCubeTexture = ( texture.mapping === CubeReflectionMapping || texture.mapping === CubeRefractionMapping );
|
|
428
|
+
|
|
429
|
+
if ( isCubeTexture ) {
|
|
430
|
+
|
|
431
|
+
if ( this._cubemapMaterial === null ) {
|
|
432
|
+
|
|
433
|
+
this._cubemapMaterial = _getCubemapMaterial( texture );
|
|
434
|
+
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
} else {
|
|
438
|
+
|
|
439
|
+
if ( this._equirectMaterial === null ) {
|
|
440
|
+
|
|
441
|
+
this._equirectMaterial = _getEquirectMaterial( texture );
|
|
442
|
+
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
const material = isCubeTexture ? this._cubemapMaterial : this._equirectMaterial;
|
|
448
|
+
material.fragmentNode.value = texture;
|
|
449
|
+
|
|
450
|
+
const mesh = this._lodMeshes[ 0 ];
|
|
451
|
+
mesh.material = material;
|
|
452
|
+
|
|
453
|
+
const size = this._cubeSize;
|
|
454
|
+
|
|
455
|
+
_setViewport( cubeUVRenderTarget, 0, 0, 3 * size, 2 * size );
|
|
456
|
+
|
|
457
|
+
renderer.setRenderTarget( cubeUVRenderTarget );
|
|
458
|
+
renderer.render( mesh, _flatCamera );
|
|
459
|
+
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
_applyPMREM( cubeUVRenderTarget ) {
|
|
463
|
+
|
|
464
|
+
const renderer = this._renderer;
|
|
465
|
+
const autoClear = renderer.autoClear;
|
|
466
|
+
renderer.autoClear = false;
|
|
467
|
+
const n = this._lodPlanes.length;
|
|
468
|
+
|
|
469
|
+
for ( let i = 1; i < n; i ++ ) {
|
|
470
|
+
|
|
471
|
+
const sigma = Math.sqrt( this._sigmas[ i ] * this._sigmas[ i ] - this._sigmas[ i - 1 ] * this._sigmas[ i - 1 ] );
|
|
472
|
+
|
|
473
|
+
const poleAxis = _axisDirections[ ( n - i - 1 ) % _axisDirections.length ];
|
|
474
|
+
|
|
475
|
+
this._blur( cubeUVRenderTarget, i - 1, i, sigma, poleAxis );
|
|
476
|
+
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
renderer.autoClear = autoClear;
|
|
480
|
+
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* This is a two-pass Gaussian blur for a cubemap. Normally this is done
|
|
485
|
+
* vertically and horizontally, but this breaks down on a cube. Here we apply
|
|
486
|
+
* the blur latitudinally (around the poles), and then longitudinally (towards
|
|
487
|
+
* the poles) to approximate the orthogonally-separable blur. It is least
|
|
488
|
+
* accurate at the poles, but still does a decent job.
|
|
489
|
+
*/
|
|
490
|
+
_blur( cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis ) {
|
|
491
|
+
|
|
492
|
+
const pingPongRenderTarget = this._pingPongRenderTarget;
|
|
493
|
+
|
|
494
|
+
this._halfBlur(
|
|
495
|
+
cubeUVRenderTarget,
|
|
496
|
+
pingPongRenderTarget,
|
|
497
|
+
lodIn,
|
|
498
|
+
lodOut,
|
|
499
|
+
sigma,
|
|
500
|
+
'latitudinal',
|
|
501
|
+
poleAxis );
|
|
502
|
+
|
|
503
|
+
this._halfBlur(
|
|
504
|
+
pingPongRenderTarget,
|
|
505
|
+
cubeUVRenderTarget,
|
|
506
|
+
lodOut,
|
|
507
|
+
lodOut,
|
|
508
|
+
sigma,
|
|
509
|
+
'longitudinal',
|
|
510
|
+
poleAxis );
|
|
511
|
+
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
_halfBlur( targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis ) {
|
|
515
|
+
|
|
516
|
+
const renderer = this._renderer;
|
|
517
|
+
const blurMaterial = this._blurMaterial;
|
|
518
|
+
|
|
519
|
+
if ( direction !== 'latitudinal' && direction !== 'longitudinal' ) {
|
|
520
|
+
|
|
521
|
+
console.error( 'blur direction must be either latitudinal or longitudinal!' );
|
|
522
|
+
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
// Number of standard deviations at which to cut off the discrete approximation.
|
|
526
|
+
const STANDARD_DEVIATIONS = 3;
|
|
527
|
+
|
|
528
|
+
const blurMesh = this._lodMeshes[ lodOut ];
|
|
529
|
+
blurMesh.material = blurMaterial;
|
|
530
|
+
|
|
531
|
+
const blurUniforms = blurMaterial.uniforms;
|
|
532
|
+
|
|
533
|
+
const pixels = this._sizeLods[ lodIn ] - 1;
|
|
534
|
+
const radiansPerPixel = isFinite( sigmaRadians ) ? Math.PI / ( 2 * pixels ) : 2 * Math.PI / ( 2 * MAX_SAMPLES - 1 );
|
|
535
|
+
const sigmaPixels = sigmaRadians / radiansPerPixel;
|
|
536
|
+
const samples = isFinite( sigmaRadians ) ? 1 + Math.floor( STANDARD_DEVIATIONS * sigmaPixels ) : MAX_SAMPLES;
|
|
537
|
+
|
|
538
|
+
if ( samples > MAX_SAMPLES ) {
|
|
539
|
+
|
|
540
|
+
console.warn( `sigmaRadians, ${
|
|
541
|
+
sigmaRadians}, is too large and will clip, as it requested ${
|
|
542
|
+
samples} samples when the maximum is set to ${MAX_SAMPLES}` );
|
|
543
|
+
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
const weights = [];
|
|
547
|
+
let sum = 0;
|
|
548
|
+
|
|
549
|
+
for ( let i = 0; i < MAX_SAMPLES; ++ i ) {
|
|
550
|
+
|
|
551
|
+
const x = i / sigmaPixels;
|
|
552
|
+
const weight = Math.exp( - x * x / 2 );
|
|
553
|
+
weights.push( weight );
|
|
554
|
+
|
|
555
|
+
if ( i === 0 ) {
|
|
556
|
+
|
|
557
|
+
sum += weight;
|
|
558
|
+
|
|
559
|
+
} else if ( i < samples ) {
|
|
560
|
+
|
|
561
|
+
sum += 2 * weight;
|
|
562
|
+
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
for ( let i = 0; i < weights.length; i ++ ) {
|
|
568
|
+
|
|
569
|
+
weights[ i ] = weights[ i ] / sum;
|
|
570
|
+
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
targetIn.texture.frame = ( targetIn.texture.frame || 0 ) + 1;
|
|
574
|
+
|
|
575
|
+
blurUniforms.envMap.value = targetIn.texture;
|
|
576
|
+
blurUniforms.samples.value = samples;
|
|
577
|
+
blurUniforms.weights.array = weights;
|
|
578
|
+
blurUniforms.latitudinal.value = direction === 'latitudinal' ? 1 : 0;
|
|
579
|
+
|
|
580
|
+
if ( poleAxis ) {
|
|
581
|
+
|
|
582
|
+
blurUniforms.poleAxis.value = poleAxis;
|
|
583
|
+
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
const { _lodMax } = this;
|
|
587
|
+
blurUniforms.dTheta.value = radiansPerPixel;
|
|
588
|
+
blurUniforms.mipInt.value = _lodMax - lodIn;
|
|
589
|
+
|
|
590
|
+
const outputSize = this._sizeLods[ lodOut ];
|
|
591
|
+
const x = 3 * outputSize * ( lodOut > _lodMax - LOD_MIN ? lodOut - _lodMax + LOD_MIN : 0 );
|
|
592
|
+
const y = 4 * ( this._cubeSize - outputSize );
|
|
593
|
+
|
|
594
|
+
_setViewport( targetOut, x, y, 3 * outputSize, 2 * outputSize );
|
|
595
|
+
renderer.setRenderTarget( targetOut );
|
|
596
|
+
renderer.render( blurMesh, _flatCamera );
|
|
597
|
+
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
function _createPlanes( lodMax ) {
|
|
603
|
+
|
|
604
|
+
const lodPlanes = [];
|
|
605
|
+
const sizeLods = [];
|
|
606
|
+
const sigmas = [];
|
|
607
|
+
const lodMeshes = [];
|
|
608
|
+
|
|
609
|
+
let lod = lodMax;
|
|
610
|
+
|
|
611
|
+
const totalLods = lodMax - LOD_MIN + 1 + EXTRA_LOD_SIGMA.length;
|
|
612
|
+
|
|
613
|
+
for ( let i = 0; i < totalLods; i ++ ) {
|
|
614
|
+
|
|
615
|
+
const sizeLod = Math.pow( 2, lod );
|
|
616
|
+
sizeLods.push( sizeLod );
|
|
617
|
+
let sigma = 1.0 / sizeLod;
|
|
618
|
+
|
|
619
|
+
if ( i > lodMax - LOD_MIN ) {
|
|
620
|
+
|
|
621
|
+
sigma = EXTRA_LOD_SIGMA[ i - lodMax + LOD_MIN - 1 ];
|
|
622
|
+
|
|
623
|
+
} else if ( i === 0 ) {
|
|
624
|
+
|
|
625
|
+
sigma = 0;
|
|
626
|
+
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
sigmas.push( sigma );
|
|
630
|
+
|
|
631
|
+
const texelSize = 1.0 / ( sizeLod - 2 );
|
|
632
|
+
const min = - texelSize;
|
|
633
|
+
const max = 1 + texelSize;
|
|
634
|
+
const uv1 = [ min, min, max, min, max, max, min, min, max, max, min, max ];
|
|
635
|
+
|
|
636
|
+
const cubeFaces = 6;
|
|
637
|
+
const vertices = 6;
|
|
638
|
+
const positionSize = 3;
|
|
639
|
+
const uvSize = 2;
|
|
640
|
+
const faceIndexSize = 1;
|
|
641
|
+
|
|
642
|
+
const position = new Float32Array( positionSize * vertices * cubeFaces );
|
|
643
|
+
const uv = new Float32Array( uvSize * vertices * cubeFaces );
|
|
644
|
+
const faceIndex = new Float32Array( faceIndexSize * vertices * cubeFaces );
|
|
645
|
+
|
|
646
|
+
for ( let face = 0; face < cubeFaces; face ++ ) {
|
|
647
|
+
|
|
648
|
+
const x = ( face % 3 ) * 2 / 3 - 1;
|
|
649
|
+
const y = face > 2 ? 0 : - 1;
|
|
650
|
+
const coordinates = [
|
|
651
|
+
x, y, 0,
|
|
652
|
+
x + 2 / 3, y, 0,
|
|
653
|
+
x + 2 / 3, y + 1, 0,
|
|
654
|
+
x, y, 0,
|
|
655
|
+
x + 2 / 3, y + 1, 0,
|
|
656
|
+
x, y + 1, 0
|
|
657
|
+
];
|
|
658
|
+
|
|
659
|
+
const faceIdx = _faceLib[ face ];
|
|
660
|
+
position.set( coordinates, positionSize * vertices * faceIdx );
|
|
661
|
+
uv.set( uv1, uvSize * vertices * faceIdx );
|
|
662
|
+
const fill = [ faceIdx, faceIdx, faceIdx, faceIdx, faceIdx, faceIdx ];
|
|
663
|
+
faceIndex.set( fill, faceIndexSize * vertices * faceIdx );
|
|
664
|
+
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
const planes = new BufferGeometry();
|
|
668
|
+
planes.setAttribute( 'position', new BufferAttribute( position, positionSize ) );
|
|
669
|
+
planes.setAttribute( 'uv', new BufferAttribute( uv, uvSize ) );
|
|
670
|
+
planes.setAttribute( 'faceIndex', new BufferAttribute( faceIndex, faceIndexSize ) );
|
|
671
|
+
lodPlanes.push( planes );
|
|
672
|
+
lodMeshes.push( new Mesh( planes, null ) );
|
|
673
|
+
|
|
674
|
+
if ( lod > LOD_MIN ) {
|
|
675
|
+
|
|
676
|
+
lod --;
|
|
677
|
+
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
return { lodPlanes, sizeLods, sigmas, lodMeshes };
|
|
683
|
+
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
function _createRenderTarget( width, height, params ) {
|
|
687
|
+
|
|
688
|
+
const cubeUVRenderTarget = new RenderTarget( width, height, params );
|
|
689
|
+
cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
|
|
690
|
+
cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
|
|
691
|
+
cubeUVRenderTarget.texture.isPMREMTexture = true;
|
|
692
|
+
cubeUVRenderTarget.scissorTest = true;
|
|
693
|
+
return cubeUVRenderTarget;
|
|
694
|
+
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
function _setViewport( target, x, y, width, height ) {
|
|
698
|
+
|
|
699
|
+
target.viewport.set( x, y, width, height );
|
|
700
|
+
target.scissor.set( x, y, width, height );
|
|
701
|
+
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
function _getMaterial( type ) {
|
|
705
|
+
|
|
706
|
+
const material = new NodeMaterial();
|
|
707
|
+
material.depthTest = false;
|
|
708
|
+
material.depthWrite = false;
|
|
709
|
+
material.blending = NoBlending;
|
|
710
|
+
material.name = `PMREM_${ type }`;
|
|
711
|
+
|
|
712
|
+
return material;
|
|
713
|
+
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
function _getBlurShader( lodMax, width, height ) {
|
|
717
|
+
|
|
718
|
+
const weights = uniformArray( new Array( MAX_SAMPLES ).fill( 0 ) );
|
|
719
|
+
const poleAxis = uniform( new Vector3( 0, 1, 0 ) );
|
|
720
|
+
const dTheta = uniform( 0 );
|
|
721
|
+
const n = float( MAX_SAMPLES );
|
|
722
|
+
const latitudinal = uniform( 0 ); // false, bool
|
|
723
|
+
const samples = uniform( 1 ); // int
|
|
724
|
+
const envMap = texture( null );
|
|
725
|
+
const mipInt = uniform( 0 ); // int
|
|
726
|
+
const CUBEUV_TEXEL_WIDTH = float( 1 / width );
|
|
727
|
+
const CUBEUV_TEXEL_HEIGHT = float( 1 / height );
|
|
728
|
+
const CUBEUV_MAX_MIP = float( lodMax );
|
|
729
|
+
|
|
730
|
+
const materialUniforms = {
|
|
731
|
+
n,
|
|
732
|
+
latitudinal,
|
|
733
|
+
weights,
|
|
734
|
+
poleAxis,
|
|
735
|
+
outputDirection,
|
|
736
|
+
dTheta,
|
|
737
|
+
samples,
|
|
738
|
+
envMap,
|
|
739
|
+
mipInt,
|
|
740
|
+
CUBEUV_TEXEL_WIDTH,
|
|
741
|
+
CUBEUV_TEXEL_HEIGHT,
|
|
742
|
+
CUBEUV_MAX_MIP
|
|
743
|
+
};
|
|
744
|
+
|
|
745
|
+
const material = _getMaterial( 'blur' );
|
|
746
|
+
material.uniforms = materialUniforms; // TODO: Move to outside of the material
|
|
747
|
+
material.fragmentNode = blur( { ...materialUniforms, latitudinal: latitudinal.equal( 1 ) } );
|
|
748
|
+
|
|
749
|
+
return material;
|
|
750
|
+
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
function _getCubemapMaterial( envTexture ) {
|
|
754
|
+
|
|
755
|
+
const material = _getMaterial( 'cubemap' );
|
|
756
|
+
material.fragmentNode = cubeTexture( envTexture, outputDirection );
|
|
757
|
+
|
|
758
|
+
return material;
|
|
759
|
+
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
function _getEquirectMaterial( envTexture ) {
|
|
763
|
+
|
|
764
|
+
const material = _getMaterial( 'equirect' );
|
|
765
|
+
material.fragmentNode = texture( envTexture, equirectUV( outputDirection ), 0 );
|
|
766
|
+
|
|
767
|
+
return material;
|
|
768
|
+
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
export default PMREMGenerator;
|