super-three 0.184.0 → 0.185.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 +1260 -927
- package/build/three.core.js +1104 -829
- package/build/three.core.min.js +1 -1
- package/build/three.module.js +156 -98
- package/build/three.module.min.js +1 -1
- package/build/three.tsl.js +11 -4
- package/build/three.tsl.min.js +1 -1
- package/build/three.webgpu.js +7538 -3367
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +7538 -3366
- package/build/three.webgpu.nodes.min.js +1 -1
- package/examples/jsm/Addons.js +3 -0
- package/examples/jsm/controls/ArcballControls.js +6 -2
- package/examples/jsm/controls/FirstPersonControls.js +79 -42
- package/examples/jsm/controls/TransformControls.js +68 -15
- package/examples/jsm/csm/CSMFrustum.js +31 -6
- package/examples/jsm/csm/CSMShadowNode.js +4 -1
- package/examples/jsm/effects/AsciiEffect.js +14 -1
- package/examples/jsm/exporters/DRACOExporter.js +27 -6
- package/examples/jsm/exporters/GLTFExporter.js +114 -12
- package/examples/jsm/exporters/PLYExporter.js +286 -73
- package/examples/jsm/exporters/USDZExporter.js +347 -112
- package/examples/jsm/generators/CityGenerator.js +346 -0
- package/examples/jsm/generators/ForestGenerator.js +347 -0
- package/examples/jsm/generators/TerrainGenerator.js +504 -0
- package/examples/jsm/generators/TreeGenerator.js +377 -0
- package/examples/jsm/generators/city/SidewalkGenerator.js +253 -0
- package/examples/jsm/generators/city/SkyscraperGenerator.js +1357 -0
- package/examples/jsm/geometries/LoftGeometry.js +355 -0
- package/examples/jsm/helpers/LightProbeGridHelper.js +1 -1
- package/examples/jsm/helpers/LightProbeHelper.js +5 -4
- package/examples/jsm/helpers/ViewHelper.js +16 -6
- package/examples/jsm/inspector/Inspector.js +53 -15
- package/examples/jsm/inspector/RendererInspector.js +152 -36
- package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphEditor.js +1 -1
- package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphLoader.js +1 -1
- package/examples/jsm/inspector/tabs/Console.js +200 -18
- package/examples/jsm/inspector/tabs/Memory.js +8 -0
- package/examples/jsm/inspector/tabs/Parameters.js +64 -4
- package/examples/jsm/inspector/tabs/Performance.js +21 -6
- package/examples/jsm/inspector/tabs/Settings.js +51 -9
- package/examples/jsm/inspector/tabs/Timeline.js +178 -93
- package/examples/jsm/inspector/tabs/Viewer.js +628 -16
- package/examples/jsm/inspector/ui/Graph.js +162 -25
- package/examples/jsm/inspector/ui/Item.js +92 -13
- package/examples/jsm/inspector/ui/List.js +1 -1
- package/examples/jsm/inspector/ui/Profiler.js +90 -45
- package/examples/jsm/inspector/ui/Style.js +1788 -1401
- package/examples/jsm/inspector/ui/Tab.js +5 -3
- package/examples/jsm/inspector/ui/Values.js +71 -6
- package/examples/jsm/inspector/ui/utils.js +130 -10
- package/examples/jsm/libs/basis/README.md +0 -1
- package/examples/jsm/libs/demuxer_mp4.js +3 -3
- package/examples/jsm/libs/draco/README.md +0 -1
- package/examples/jsm/libs/meshopt_clusterizer.module.js +421 -0
- package/examples/jsm/libs/meshopt_simplifier.module.js +627 -0
- package/examples/jsm/libs/mikktspace.module.js +34 -9
- package/examples/jsm/lighting/ClusteredLighting.js +55 -0
- package/examples/jsm/lighting/LightProbeGrid.js +106 -76
- package/examples/jsm/lines/LineMaterial.js +38 -15
- package/examples/jsm/lines/LineSegments2.js +8 -0
- package/examples/jsm/lines/webgpu/LineSegments2.js +8 -0
- package/examples/jsm/loaders/3DMLoader.js +1 -1
- package/examples/jsm/loaders/DRACOLoader.js +46 -13
- package/examples/jsm/loaders/EXRLoader.js +27 -55
- package/examples/jsm/loaders/HDRLoader.js +6 -28
- package/examples/jsm/loaders/KTX2Loader.js +31 -12
- package/examples/jsm/loaders/LDrawLoader.js +8 -8
- package/examples/jsm/loaders/LUT3dlLoader.js +2 -2
- package/examples/jsm/loaders/LUTCubeLoader.js +2 -2
- package/examples/jsm/loaders/LWOLoader.js +4 -0
- package/examples/jsm/loaders/LottieLoader.js +1 -1
- package/examples/jsm/loaders/MaterialXLoader.js +31 -9
- package/examples/jsm/loaders/NRRDLoader.js +3 -3
- package/examples/jsm/loaders/PCDLoader.js +7 -7
- package/examples/jsm/loaders/PLYLoader.js +218 -55
- package/examples/jsm/loaders/SVGLoader.js +547 -495
- package/examples/jsm/loaders/TTFLoader.js +1 -1
- package/examples/jsm/loaders/USDLoader.js +33 -9
- package/examples/jsm/loaders/VRMLLoader.js +1 -1
- package/examples/jsm/loaders/usd/USDAParser.js +93 -20
- package/examples/jsm/loaders/usd/USDCParser.js +1 -1
- package/examples/jsm/loaders/usd/USDComposer.js +52 -19
- package/examples/jsm/misc/TileCreasedNormalsPlugin.js +270 -0
- package/examples/jsm/misc/Volume.js +2 -2
- package/examples/jsm/objects/GroundedSkybox.js +1 -1
- package/examples/jsm/objects/Reflector.js +2 -3
- package/examples/jsm/objects/Water2Mesh.js +1 -1
- package/examples/jsm/physics/AmmoPhysics.js +15 -8
- package/examples/jsm/physics/RapierPhysics.js +27 -2
- package/examples/jsm/shaders/VolumeShader.js +31 -44
- package/examples/jsm/transpiler/GLSLDecoder.js +6 -6
- package/examples/jsm/transpiler/Linker.js +1 -1
- package/examples/jsm/tsl/display/BloomNode.js +59 -19
- package/examples/jsm/tsl/display/DepthOfFieldNode.js +2 -2
- package/examples/jsm/tsl/display/FXAANode.js +11 -12
- package/examples/jsm/tsl/display/GTAONode.js +34 -13
- package/examples/jsm/tsl/display/GodraysNode.js +1 -1
- package/examples/jsm/tsl/display/ImportanceSampledEnvironment.js +560 -0
- package/examples/jsm/tsl/display/PixelationPassNode.js +2 -2
- package/examples/jsm/tsl/display/RecurrentDenoiseNode.js +912 -0
- package/examples/jsm/tsl/display/SSAAPassNode.js +13 -25
- package/examples/jsm/tsl/display/SSGINode.js +89 -39
- package/examples/jsm/tsl/display/SSRNode.js +829 -132
- package/examples/jsm/tsl/display/SSSNode.js +2 -2
- package/examples/jsm/tsl/display/TemporalReprojectNode.js +1023 -0
- package/examples/jsm/tsl/lighting/ClusteredLightsNode.js +622 -0
- package/examples/jsm/tsl/lighting/DynamicLightsNode.js +1 -1
- package/examples/jsm/tsl/math/curlNoise.js +107 -0
- package/examples/jsm/tsl/shadows/TileShadowNode.js +1 -1
- package/examples/jsm/tsl/shadows/TileShadowNodeHelper.js +3 -3
- package/examples/jsm/tsl/utils/GroundedSkybox.js +62 -0
- package/examples/jsm/tsl/utils/RNoise.js +51 -0
- package/examples/jsm/tsl/utils/SpecularHelpers.js +325 -0
- package/examples/jsm/utils/BufferGeometryUtils.js +126 -59
- package/examples/jsm/utils/GeometryCompressionUtils.js +1 -1
- package/examples/jsm/utils/SceneOptimizer.js +1 -1
- package/examples/jsm/webxr/ARButton.js +1 -1
- package/examples/jsm/webxr/WebGLXRFallback.js +89 -0
- package/examples/jsm/webxr/XRControllerModelFactory.js +2 -2
- package/package.json +7 -7
- package/src/Three.TSL.js +10 -3
- package/src/Three.WebGPU.js +4 -0
- package/src/animation/AnimationAction.js +15 -11
- package/src/animation/AnimationClip.js +0 -139
- package/src/animation/KeyframeTrack.js +2 -2
- package/src/animation/PropertyBinding.js +2 -2
- package/src/cameras/Camera.js +2 -2
- package/src/cameras/StereoCamera.js +5 -2
- package/src/constants.js +1 -1
- package/src/core/BufferGeometry.js +29 -7
- package/src/core/Object3D.js +17 -7
- package/src/core/Raycaster.js +1 -1
- package/src/core/RenderTarget.js +15 -2
- package/src/extras/PMREMGenerator.js +6 -4
- package/src/extras/TextureUtils.js +1 -1
- package/src/extras/core/ShapePath.js +149 -160
- package/src/geometries/SphereGeometry.js +8 -3
- package/src/helpers/DirectionalLightHelper.js +2 -0
- package/src/helpers/HemisphereLightHelper.js +2 -0
- package/src/helpers/PointLightHelper.js +2 -0
- package/src/helpers/SpotLightHelper.js +1 -1
- package/src/loaders/DataTextureLoader.js +69 -38
- package/src/loaders/LoadingManager.js +5 -0
- package/src/loaders/MaterialLoader.js +36 -266
- package/src/loaders/ObjectLoader.js +3 -1
- package/src/materials/LineBasicMaterial.js +4 -0
- package/src/materials/Material.js +196 -1
- package/src/materials/MeshBasicMaterial.js +24 -0
- package/src/materials/MeshDepthMaterial.js +10 -0
- package/src/materials/MeshDistanceMaterial.js +10 -0
- package/src/materials/MeshLambertMaterial.js +40 -1
- package/src/materials/MeshMatcapMaterial.js +25 -1
- package/src/materials/MeshNormalMaterial.js +9 -1
- package/src/materials/MeshPhongMaterial.js +40 -1
- package/src/materials/MeshPhysicalMaterial.js +38 -0
- package/src/materials/MeshStandardMaterial.js +42 -1
- package/src/materials/MeshToonMaterial.js +34 -1
- package/src/materials/PointsMaterial.js +7 -0
- package/src/materials/ShaderMaterial.js +86 -0
- package/src/materials/SpriteMaterial.js +7 -0
- package/src/materials/nodes/Line2NodeMaterial.js +378 -322
- package/src/materials/nodes/MeshBasicNodeMaterial.js +2 -2
- package/src/materials/nodes/MeshNormalNodeMaterial.js +2 -2
- package/src/materials/nodes/MeshPhongNodeMaterial.js +0 -9
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +0 -30
- package/src/materials/nodes/MeshSSSNodeMaterial.js +0 -13
- package/src/materials/nodes/MeshStandardNodeMaterial.js +0 -11
- package/src/materials/nodes/NodeMaterial.js +115 -71
- package/src/materials/nodes/SpriteNodeMaterial.js +0 -10
- package/src/materials/nodes/manager/NodeMaterialObserver.js +49 -20
- package/src/math/Box3.js +5 -0
- package/src/math/FrustumArray.js +103 -133
- package/src/math/Interpolant.js +1 -1
- package/src/math/MathUtils.js +2 -2
- package/src/math/Matrix3.js +11 -0
- package/src/math/Matrix4.js +28 -3
- package/src/math/Vector2.js +2 -2
- package/src/math/Vector3.js +2 -2
- package/src/math/Vector4.js +2 -2
- package/src/math/interpolants/BezierInterpolant.js +4 -6
- package/src/nodes/Nodes.js +2 -5
- package/src/nodes/TSL.js +8 -6
- package/src/nodes/accessors/Arrays.js +4 -4
- package/src/nodes/accessors/Batch.js +108 -0
- package/src/nodes/accessors/Bitangent.js +2 -2
- package/src/nodes/accessors/BufferAttributeNode.js +13 -2
- package/src/nodes/accessors/Camera.js +7 -7
- package/src/nodes/accessors/ClippingNode.js +1 -1
- package/src/nodes/accessors/Instance.js +264 -0
- package/src/nodes/accessors/MaterialNode.js +18 -2
- package/src/nodes/accessors/MaterialProperties.js +4 -3
- package/src/nodes/accessors/{MorphNode.js → Morph.js} +99 -112
- package/src/nodes/accessors/Normal.js +13 -13
- package/src/nodes/accessors/Position.js +5 -1
- package/src/nodes/accessors/ReferenceNode.js +1 -0
- package/src/nodes/accessors/ReflectVector.js +3 -3
- package/src/nodes/accessors/SceneProperties.js +1 -1
- package/src/nodes/accessors/Skinning.js +263 -0
- package/src/nodes/accessors/StorageBufferNode.js +2 -2
- package/src/nodes/accessors/StorageTexture3DNode.js +100 -0
- package/src/nodes/accessors/StorageTextureNode.js +39 -7
- package/src/nodes/accessors/Tangent.js +4 -4
- package/src/nodes/accessors/TextureNode.js +60 -5
- package/src/nodes/code/FunctionNode.js +2 -16
- package/src/nodes/core/MRTNode.js +7 -2
- package/src/nodes/core/Node.js +39 -2
- package/src/nodes/core/NodeBuilder.js +201 -41
- package/src/nodes/core/NodeUtils.js +13 -13
- package/src/nodes/core/OutputStructNode.js +1 -1
- package/src/nodes/core/OverrideContextNode.js +153 -0
- package/src/nodes/core/PropertyNode.js +51 -5
- package/src/nodes/core/StackNode.js +56 -34
- package/src/nodes/core/StructNode.js +4 -6
- package/src/nodes/core/StructTypeNode.js +6 -6
- package/src/nodes/core/VarNode.js +8 -0
- package/src/nodes/core/VaryingNode.js +12 -2
- package/src/nodes/display/BlendModes.js +1 -41
- package/src/nodes/display/BumpMapNode.js +6 -1
- package/src/nodes/display/ColorAdjustment.js +10 -9
- package/src/nodes/display/FrontFacingNode.js +38 -9
- package/src/nodes/display/NormalMapNode.js +2 -2
- package/src/nodes/display/PassNode.js +35 -43
- package/src/nodes/display/PremultiplyAlphaFunctions.js +39 -0
- package/src/nodes/display/RenderOutputNode.js +12 -3
- package/src/nodes/functions/VolumetricLightingModel.js +40 -7
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +1 -1
- package/src/nodes/lighting/EnvironmentNode.js +2 -2
- package/src/nodes/lighting/IESSpotLightNode.js +40 -2
- package/src/nodes/lighting/LightingContextNode.js +10 -2
- package/src/nodes/lighting/LightsNode.js +90 -37
- package/src/nodes/lighting/PointShadowNode.js +6 -1
- package/src/nodes/lighting/ShadowFilterNode.js +21 -52
- package/src/nodes/lighting/ShadowNode.js +34 -14
- package/src/nodes/materialx/lib/mx_noise.js +2 -2
- package/src/nodes/math/ConditionalNode.js +3 -3
- package/src/nodes/math/MathNode.js +39 -11
- package/src/nodes/math/OperatorNode.js +23 -23
- package/src/nodes/parsers/GLSLNodeFunction.js +1 -1
- package/src/nodes/pmrem/PMREMNode.js +33 -2
- package/src/nodes/tsl/TSLCore.js +63 -18
- package/src/nodes/utils/EquirectUV.js +30 -5
- package/src/nodes/utils/FunctionOverloadingNode.js +1 -1
- package/src/nodes/utils/Packing.js +35 -4
- package/src/nodes/utils/RTTNode.js +40 -24
- package/src/nodes/utils/ReflectorNode.js +1 -0
- package/src/nodes/utils/StorageArrayElementNode.js +1 -1
- package/src/objects/BatchedMesh.js +22 -14
- package/src/objects/InstancedMesh.js +0 -11
- package/src/objects/Skeleton.js +0 -9
- package/src/renderers/WebGLRenderer.js +19 -15
- package/src/renderers/common/Backend.js +49 -5
- package/src/renderers/common/Bindings.js +114 -45
- package/src/renderers/common/Buffer.js +9 -0
- package/src/renderers/common/ClippingContext.js +10 -2
- package/src/renderers/common/Info.js +63 -22
- package/src/renderers/common/Lighting.js +53 -5
- package/src/renderers/common/RenderList.js +41 -4
- package/src/renderers/common/RenderObject.js +73 -13
- package/src/renderers/common/Renderer.js +281 -108
- package/src/renderers/common/Sampler.js +16 -48
- package/src/renderers/common/Textures.js +32 -5
- package/src/renderers/common/TimestampQueryPool.js +1 -1
- package/src/renderers/common/UniformsGroup.js +31 -9
- package/src/renderers/common/XRManager.js +340 -22
- package/src/renderers/common/extras/PMREMGenerator.js +15 -38
- package/src/renderers/common/nodes/NodeBuilderState.js +9 -1
- package/src/renderers/common/nodes/NodeLibrary.js +4 -4
- package/src/renderers/common/nodes/NodeManager.js +63 -14
- package/src/renderers/common/nodes/NodeUniformBuffer.js +13 -0
- package/src/renderers/shaders/ShaderChunk/common.glsl.js +13 -4
- package/src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl.js +0 -6
- package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/envmap_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/normal_vertex.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/distance.glsl.js +1 -1
- package/src/renderers/webgl/WebGLOutput.js +2 -1
- package/src/renderers/webgl/WebGLProgram.js +5 -4
- package/src/renderers/webgl/WebGLPrograms.js +12 -5
- package/src/renderers/webgl/WebGLRenderLists.js +9 -1
- package/src/renderers/webgl/WebGLShaderCache.js +5 -11
- package/src/renderers/webgl/WebGLTextures.js +20 -7
- package/src/renderers/webgl/WebGLUniformsGroups.js +66 -38
- package/src/renderers/webgl-fallback/WebGLBackend.js +84 -25
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +138 -8
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +1 -1
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +52 -22
- package/src/renderers/webgl-fallback/utils/WebGLUtils.js +4 -2
- package/src/renderers/webgpu/WebGPUBackend.js +480 -169
- package/src/renderers/webgpu/descriptors/GPUBindGroupDescriptor.js +48 -0
- package/src/renderers/webgpu/descriptors/GPUBufferDescriptor.js +57 -0
- package/src/renderers/webgpu/descriptors/GPUCommandEncoderDescriptor.js +30 -0
- package/src/renderers/webgpu/descriptors/GPUComputePassDescriptor.js +38 -0
- package/src/renderers/webgpu/descriptors/GPUComputePipelineDescriptor.js +48 -0
- package/src/renderers/webgpu/descriptors/GPUCopyExternalImageDestInfo.js +47 -0
- package/src/renderers/webgpu/descriptors/GPUCopyExternalImageSourceInfo.js +50 -0
- package/src/renderers/webgpu/descriptors/GPUExtent3D.js +51 -0
- package/src/renderers/webgpu/descriptors/GPUPipelineLayoutDescriptor.js +39 -0
- package/src/renderers/webgpu/descriptors/GPUQuerySetDescriptor.js +47 -0
- package/src/renderers/webgpu/descriptors/GPURenderBundleEncoderDescriptor.js +74 -0
- package/src/renderers/webgpu/descriptors/GPURenderPassColorAttachment.js +72 -0
- package/src/renderers/webgpu/descriptors/GPURenderPassDepthStencilAttachment.js +99 -0
- package/src/renderers/webgpu/descriptors/GPURenderPassDescriptor.js +72 -0
- package/src/renderers/webgpu/descriptors/GPURenderPassTimestampWrites.js +49 -0
- package/src/renderers/webgpu/descriptors/GPURenderPipelineDescriptor.js +130 -0
- package/src/renderers/webgpu/descriptors/GPUSamplerDescriptor.js +119 -0
- package/src/renderers/webgpu/descriptors/GPUShaderModuleDescriptor.js +46 -0
- package/src/renderers/webgpu/descriptors/GPUTexelCopyBufferInfo.js +57 -0
- package/src/renderers/webgpu/descriptors/GPUTexelCopyBufferLayout.js +48 -0
- package/src/renderers/webgpu/descriptors/GPUTexelCopyTextureInfo.js +61 -0
- package/src/renderers/webgpu/descriptors/GPUTextureDescriptor.js +99 -0
- package/src/renderers/webgpu/descriptors/GPUTextureViewDescriptor.js +108 -0
- package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +0 -1
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +164 -7
- package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +1 -1
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +98 -38
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +72 -68
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +164 -69
- package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +158 -95
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +297 -141
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +33 -18
- package/src/renderers/webgpu/utils/WebGPUUtils.js +38 -3
- package/src/textures/DepthTexture.js +1 -1
- package/src/textures/ExternalTexture.js +0 -3
- package/examples/fonts/LICENSE +0 -13
- package/examples/fonts/MPLUSRounded1c/MPLUSRounded1c-Regular.typeface.json.zip +0 -0
- package/examples/fonts/MPLUSRounded1c/OFL.txt +0 -91
- package/examples/fonts/README.md +0 -11
- package/examples/fonts/droid/NOTICE +0 -190
- package/examples/fonts/droid/README.txt +0 -18
- package/examples/fonts/droid/droid_sans_bold.typeface.json +0 -1
- package/examples/fonts/droid/droid_sans_mono_regular.typeface.json +0 -1
- package/examples/fonts/droid/droid_sans_regular.typeface.json +0 -1
- package/examples/fonts/droid/droid_serif_bold.typeface.json +0 -1
- package/examples/fonts/droid/droid_serif_regular.typeface.json +0 -1
- package/examples/fonts/gentilis_bold.typeface.json +0 -1
- package/examples/fonts/gentilis_regular.typeface.json +0 -1
- package/examples/fonts/helvetiker_bold.typeface.json +0 -1
- package/examples/fonts/helvetiker_regular.typeface.json +0 -1
- package/examples/fonts/optimer_bold.typeface.json +0 -1
- package/examples/fonts/optimer_regular.typeface.json +0 -1
- package/examples/fonts/ttf/README.md +0 -9
- package/examples/fonts/ttf/kenpixel.ttf +0 -0
- package/examples/jsm/inspector/extensions/extensions.json +0 -6
- package/examples/jsm/libs/ammo.wasm.js +0 -822
- package/examples/jsm/libs/ammo.wasm.wasm +0 -0
- package/examples/jsm/libs/draco/draco_encoder.js +0 -33
- package/examples/jsm/libs/draco/gltf/draco_encoder.js +0 -33
- package/examples/jsm/libs/lottie_canvas.module.js +0 -14849
- package/examples/jsm/libs/opentype.module.js +0 -14506
- package/examples/jsm/libs/rhino3dm/rhino3dm.js +0 -21
- package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +0 -16
- package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
- package/examples/jsm/lighting/TiledLighting.js +0 -42
- package/examples/jsm/tsl/display/AnamorphicNode.js +0 -293
- package/examples/jsm/tsl/lighting/TiledLightsNode.js +0 -442
- package/src/nodes/accessors/BatchNode.js +0 -163
- package/src/nodes/accessors/InstanceNode.js +0 -349
- package/src/nodes/accessors/InstancedMeshNode.js +0 -50
- package/src/nodes/accessors/SkinningNode.js +0 -328
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HDR environment importance sampling (CDF tables + MIS) for screen-space effects.
|
|
3
|
+
*
|
|
4
|
+
* CDF precomputation and the MIS env-miss estimator are adapted from
|
|
5
|
+
* [three-gpu-pathtracer](https://github.com/gkjohnson/three-gpu-pathtracer).
|
|
6
|
+
*
|
|
7
|
+
* @see {@link https://github.com/gkjohnson/three-gpu-pathtracer}
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { If, dot, equirectUV, float, luminance, max, normalize, texture, uniform, vec2, vec4 } from 'three/tsl';
|
|
11
|
+
import { ClampToEdgeWrapping, DataTexture, DataUtils, FloatType, HalfFloatType, LinearFilter, RedFormat, RepeatWrapping, Source, Vector2 } from 'three/webgpu';
|
|
12
|
+
import { D_GTR, F_Schlick, GeometryTerm, SmithG, equirectDirPdf, misPowerHeuristic } from '../utils/SpecularHelpers.js';
|
|
13
|
+
|
|
14
|
+
function colorToLuminance( r, g, b ) {
|
|
15
|
+
|
|
16
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function binarySearchFindClosestIndexOf( array, targetValue, offset = 0, count = array.length ) {
|
|
21
|
+
|
|
22
|
+
let lower = offset;
|
|
23
|
+
let upper = offset + count - 1;
|
|
24
|
+
|
|
25
|
+
while ( lower < upper ) {
|
|
26
|
+
|
|
27
|
+
const mid = ( lower + upper ) >> 1;
|
|
28
|
+
|
|
29
|
+
if ( array[ mid ] < targetValue ) {
|
|
30
|
+
|
|
31
|
+
lower = mid + 1;
|
|
32
|
+
|
|
33
|
+
} else {
|
|
34
|
+
|
|
35
|
+
upper = mid;
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return lower - offset;
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function preprocessEnvMap( envMap ) {
|
|
46
|
+
|
|
47
|
+
const map = envMap.clone();
|
|
48
|
+
map.source = new Source( { ...map.image } );
|
|
49
|
+
const { width, height, data } = map.image;
|
|
50
|
+
|
|
51
|
+
let newData = data;
|
|
52
|
+
|
|
53
|
+
if ( map.type !== HalfFloatType ) {
|
|
54
|
+
|
|
55
|
+
newData = new Uint16Array( data.length );
|
|
56
|
+
|
|
57
|
+
let maxIntValue;
|
|
58
|
+
if ( data instanceof Int8Array || data instanceof Int16Array || data instanceof Int32Array ) {
|
|
59
|
+
|
|
60
|
+
maxIntValue = 2 ** ( 8 * data.BYTES_PER_ELEMENT - 1 ) - 1;
|
|
61
|
+
|
|
62
|
+
} else {
|
|
63
|
+
|
|
64
|
+
maxIntValue = 2 ** ( 8 * data.BYTES_PER_ELEMENT ) - 1;
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
for ( let i = 0, l = data.length; i < l; i ++ ) {
|
|
69
|
+
|
|
70
|
+
let v = data[ i ];
|
|
71
|
+
|
|
72
|
+
if ( map.type === HalfFloatType ) {
|
|
73
|
+
|
|
74
|
+
v = DataUtils.fromHalfFloat( data[ i ] );
|
|
75
|
+
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if ( map.type !== FloatType && map.type !== HalfFloatType ) {
|
|
79
|
+
|
|
80
|
+
v /= maxIntValue;
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
newData[ i ] = DataUtils.toHalfFloat( v );
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
map.image.data = newData;
|
|
89
|
+
map.type = HalfFloatType;
|
|
90
|
+
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if ( map.flipY ) {
|
|
94
|
+
|
|
95
|
+
const ogData = newData;
|
|
96
|
+
newData = newData.slice();
|
|
97
|
+
|
|
98
|
+
for ( let y = 0; y < height; y ++ ) {
|
|
99
|
+
|
|
100
|
+
for ( let x = 0; x < width; x ++ ) {
|
|
101
|
+
|
|
102
|
+
const newY = height - y - 1;
|
|
103
|
+
const ogIndex = 4 * ( y * width + x );
|
|
104
|
+
const newIndex = 4 * ( newY * width + x );
|
|
105
|
+
|
|
106
|
+
newData[ newIndex + 0 ] = ogData[ ogIndex + 0 ];
|
|
107
|
+
newData[ newIndex + 1 ] = ogData[ ogIndex + 1 ];
|
|
108
|
+
newData[ newIndex + 2 ] = ogData[ ogIndex + 2 ];
|
|
109
|
+
newData[ newIndex + 3 ] = ogData[ ogIndex + 3 ];
|
|
110
|
+
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
map.flipY = false;
|
|
116
|
+
map.image.data = newData;
|
|
117
|
+
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return map;
|
|
121
|
+
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Precomputes marginal and conditional CDF textures from an equirectangular HDR environment map
|
|
126
|
+
* for luminance importance sampling.
|
|
127
|
+
*/
|
|
128
|
+
class EnvMapCDFGenerator {
|
|
129
|
+
|
|
130
|
+
constructor() {
|
|
131
|
+
|
|
132
|
+
this.map = null;
|
|
133
|
+
this.marginalWeights = null;
|
|
134
|
+
this.conditionalWeights = null;
|
|
135
|
+
this.totalSum = 0;
|
|
136
|
+
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
updateFrom( hdr ) {
|
|
140
|
+
|
|
141
|
+
this.updateMapOnly( hdr );
|
|
142
|
+
|
|
143
|
+
const { width, height, data } = this.map.image;
|
|
144
|
+
|
|
145
|
+
const pdfConditional = new Float32Array( width * height );
|
|
146
|
+
const cdfConditional = new Float32Array( width * height );
|
|
147
|
+
const pdfMarginal = new Float32Array( height );
|
|
148
|
+
const cdfMarginal = new Float32Array( height );
|
|
149
|
+
|
|
150
|
+
let totalSumValue = 0.0;
|
|
151
|
+
let cumulativeWeightMarginal = 0.0;
|
|
152
|
+
|
|
153
|
+
for ( let y = 0; y < height; y ++ ) {
|
|
154
|
+
|
|
155
|
+
let cumulativeRowWeight = 0.0;
|
|
156
|
+
|
|
157
|
+
for ( let x = 0; x < width; x ++ ) {
|
|
158
|
+
|
|
159
|
+
const i = y * width + x;
|
|
160
|
+
const r = DataUtils.fromHalfFloat( data[ 4 * i + 0 ] );
|
|
161
|
+
const g = DataUtils.fromHalfFloat( data[ 4 * i + 1 ] );
|
|
162
|
+
const b = DataUtils.fromHalfFloat( data[ 4 * i + 2 ] );
|
|
163
|
+
|
|
164
|
+
const weight = colorToLuminance( r, g, b );
|
|
165
|
+
cumulativeRowWeight += weight;
|
|
166
|
+
totalSumValue += weight;
|
|
167
|
+
|
|
168
|
+
pdfConditional[ i ] = weight;
|
|
169
|
+
cdfConditional[ i ] = cumulativeRowWeight;
|
|
170
|
+
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if ( cumulativeRowWeight !== 0 ) {
|
|
174
|
+
|
|
175
|
+
for ( let i = y * width, l = y * width + width; i < l; i ++ ) {
|
|
176
|
+
|
|
177
|
+
pdfConditional[ i ] /= cumulativeRowWeight;
|
|
178
|
+
cdfConditional[ i ] /= cumulativeRowWeight;
|
|
179
|
+
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
cumulativeWeightMarginal += cumulativeRowWeight;
|
|
185
|
+
pdfMarginal[ y ] = cumulativeRowWeight;
|
|
186
|
+
cdfMarginal[ y ] = cumulativeWeightMarginal;
|
|
187
|
+
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if ( cumulativeWeightMarginal !== 0 ) {
|
|
191
|
+
|
|
192
|
+
for ( let i = 0, l = pdfMarginal.length; i < l; i ++ ) {
|
|
193
|
+
|
|
194
|
+
pdfMarginal[ i ] /= cumulativeWeightMarginal;
|
|
195
|
+
cdfMarginal[ i ] /= cumulativeWeightMarginal;
|
|
196
|
+
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const marginalDataArray = new Uint16Array( height );
|
|
202
|
+
const conditionalDataArray = new Uint16Array( width * height );
|
|
203
|
+
|
|
204
|
+
for ( let i = 0; i < height; i ++ ) {
|
|
205
|
+
|
|
206
|
+
const dist = ( i + 1 ) / height;
|
|
207
|
+
const row = binarySearchFindClosestIndexOf( cdfMarginal, dist );
|
|
208
|
+
marginalDataArray[ i ] = DataUtils.toHalfFloat( ( row + 0.5 ) / height );
|
|
209
|
+
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
for ( let y = 0; y < height; y ++ ) {
|
|
213
|
+
|
|
214
|
+
for ( let x = 0; x < width; x ++ ) {
|
|
215
|
+
|
|
216
|
+
const i = y * width + x;
|
|
217
|
+
const dist = ( x + 1 ) / width;
|
|
218
|
+
const col = binarySearchFindClosestIndexOf( cdfConditional, dist, y * width, width );
|
|
219
|
+
conditionalDataArray[ i ] = DataUtils.toHalfFloat( ( col + 0.5 ) / width );
|
|
220
|
+
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if ( this.marginalWeights ) {
|
|
226
|
+
|
|
227
|
+
this.marginalWeights.dispose();
|
|
228
|
+
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if ( this.conditionalWeights ) {
|
|
232
|
+
|
|
233
|
+
this.conditionalWeights.dispose();
|
|
234
|
+
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
this.marginalWeights = new DataTexture( marginalDataArray, height, 1 );
|
|
238
|
+
this.marginalWeights.type = HalfFloatType;
|
|
239
|
+
this.marginalWeights.format = RedFormat;
|
|
240
|
+
this.marginalWeights.minFilter = LinearFilter;
|
|
241
|
+
this.marginalWeights.magFilter = LinearFilter;
|
|
242
|
+
this.marginalWeights.wrapS = ClampToEdgeWrapping;
|
|
243
|
+
this.marginalWeights.wrapT = ClampToEdgeWrapping;
|
|
244
|
+
this.marginalWeights.generateMipmaps = false;
|
|
245
|
+
this.marginalWeights.needsUpdate = true;
|
|
246
|
+
|
|
247
|
+
this.conditionalWeights = new DataTexture( conditionalDataArray, width, height );
|
|
248
|
+
this.conditionalWeights.type = HalfFloatType;
|
|
249
|
+
this.conditionalWeights.format = RedFormat;
|
|
250
|
+
this.conditionalWeights.minFilter = LinearFilter;
|
|
251
|
+
this.conditionalWeights.magFilter = LinearFilter;
|
|
252
|
+
this.conditionalWeights.wrapS = ClampToEdgeWrapping;
|
|
253
|
+
this.conditionalWeights.wrapT = ClampToEdgeWrapping;
|
|
254
|
+
this.conditionalWeights.generateMipmaps = false;
|
|
255
|
+
this.conditionalWeights.needsUpdate = true;
|
|
256
|
+
|
|
257
|
+
this.totalSum = totalSumValue;
|
|
258
|
+
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
updateMapOnly( hdr ) {
|
|
262
|
+
|
|
263
|
+
if ( this.map ) {
|
|
264
|
+
|
|
265
|
+
this.map.dispose();
|
|
266
|
+
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const map = preprocessEnvMap( hdr );
|
|
270
|
+
map.wrapS = RepeatWrapping;
|
|
271
|
+
map.wrapT = ClampToEdgeWrapping;
|
|
272
|
+
|
|
273
|
+
this.map = map;
|
|
274
|
+
this.totalSum = 0;
|
|
275
|
+
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
dispose() {
|
|
279
|
+
|
|
280
|
+
if ( this.marginalWeights ) {
|
|
281
|
+
|
|
282
|
+
this.marginalWeights.dispose();
|
|
283
|
+
this.marginalWeights = null;
|
|
284
|
+
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if ( this.conditionalWeights ) {
|
|
288
|
+
|
|
289
|
+
this.conditionalWeights.dispose();
|
|
290
|
+
this.conditionalWeights = null;
|
|
291
|
+
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if ( this.map ) {
|
|
295
|
+
|
|
296
|
+
this.map.dispose();
|
|
297
|
+
this.map = null;
|
|
298
|
+
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Manages a preprocessed HDR environment map (CDF textures, uniforms) and exposes
|
|
307
|
+
* TSL helpers for BRDF-direction lookups and MIS importance sampling.
|
|
308
|
+
*
|
|
309
|
+
* @see {@link https://github.com/gkjohnson/three-gpu-pathtracer}
|
|
310
|
+
*/
|
|
311
|
+
class ImportanceSampledEnvironment {
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* @param {boolean} [importanceSampling=false] - When `true`, builds luminance CDF tables and enables MIS env sampling.
|
|
315
|
+
*/
|
|
316
|
+
constructor( importanceSampling = false ) {
|
|
317
|
+
|
|
318
|
+
this._importanceSampling = importanceSampling;
|
|
319
|
+
this._cdf = new EnvMapCDFGenerator();
|
|
320
|
+
|
|
321
|
+
this._totalSum = uniform( 0.0, 'float' );
|
|
322
|
+
this._size = uniform( new Vector2( 1, 1 ) );
|
|
323
|
+
this.intensity = uniform( 1.0, 'float' );
|
|
324
|
+
|
|
325
|
+
this._mapNode = null;
|
|
326
|
+
this._marginalNode = null;
|
|
327
|
+
this._conditionalNode = null;
|
|
328
|
+
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* @param {Texture} hdr - Equirectangular HDR environment map.
|
|
333
|
+
*/
|
|
334
|
+
updateFrom( hdr ) {
|
|
335
|
+
|
|
336
|
+
if ( this._importanceSampling ) {
|
|
337
|
+
|
|
338
|
+
this._cdf.updateFrom( hdr );
|
|
339
|
+
this._totalSum.value = this._cdf.totalSum;
|
|
340
|
+
|
|
341
|
+
} else {
|
|
342
|
+
|
|
343
|
+
this._cdf.updateMapOnly( hdr );
|
|
344
|
+
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
this._size.value.set( this._cdf.map.image.width, this._cdf.map.image.height );
|
|
348
|
+
|
|
349
|
+
if ( this._mapNode === null ) {
|
|
350
|
+
|
|
351
|
+
this._mapNode = texture( this._cdf.map );
|
|
352
|
+
|
|
353
|
+
if ( this._importanceSampling ) {
|
|
354
|
+
|
|
355
|
+
this._marginalNode = texture( this._cdf.marginalWeights );
|
|
356
|
+
this._conditionalNode = texture( this._cdf.conditionalWeights );
|
|
357
|
+
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
} else {
|
|
361
|
+
|
|
362
|
+
this._mapNode.value = this._cdf.map;
|
|
363
|
+
|
|
364
|
+
if ( this._importanceSampling ) {
|
|
365
|
+
|
|
366
|
+
this._marginalNode.value = this._cdf.marginalWeights;
|
|
367
|
+
this._conditionalNode.value = this._cdf.conditionalWeights;
|
|
368
|
+
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
clear() {
|
|
376
|
+
|
|
377
|
+
this.dispose();
|
|
378
|
+
this._cdf = new EnvMapCDFGenerator();
|
|
379
|
+
this._mapNode = null;
|
|
380
|
+
this._marginalNode = null;
|
|
381
|
+
this._conditionalNode = null;
|
|
382
|
+
this._totalSum.value = 0;
|
|
383
|
+
this._size.value.set( 1, 1 );
|
|
384
|
+
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Simple environment lookup along the reflected direction (no MIS).
|
|
389
|
+
*
|
|
390
|
+
* @param {Object} params
|
|
391
|
+
* @param {UniformNode<Matrix4>} params.cameraWorldMatrix
|
|
392
|
+
* @param {Node<vec3>} params.viewReflectDir
|
|
393
|
+
* @param {Node<float>} [params.sampleWeight] - Optional radiance scale (defaults to 1).
|
|
394
|
+
* @return {Node<vec3>}
|
|
395
|
+
*/
|
|
396
|
+
sampleReflect( { cameraWorldMatrix, viewReflectDir, sampleWeight = float( 1 ) } ) {
|
|
397
|
+
|
|
398
|
+
const worldReflectDir = cameraWorldMatrix.mul( vec4( viewReflectDir, float( 0 ) ) ).xyz.normalize();
|
|
399
|
+
const envUV = equirectUV( worldReflectDir );
|
|
400
|
+
|
|
401
|
+
// Explicit LOD 0: the per-pixel reflected direction is discontinuous at the equirect pole/seam
|
|
402
|
+
// (atan is undefined at the poles), so derivative-driven mip selection collapses to the coarsest
|
|
403
|
+
// (near-average) mip there and produces a bright streak. Roughness is handled via direction sampling.
|
|
404
|
+
return texture( this._mapNode, envUV ).level( 0 ).rgb.mul( this.intensity ).mul( sampleWeight );
|
|
405
|
+
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Environment reflection for a screen-space miss using only the BRDF / reflected-ray direction.
|
|
410
|
+
*
|
|
411
|
+
* @param {Object} params
|
|
412
|
+
* @param {UniformNode<Matrix4>} params.cameraWorldMatrix
|
|
413
|
+
* @param {Node<vec3>} params.viewReflectDir - View-space GGX-sampled reflected ray.
|
|
414
|
+
* @param {Node<vec3>} params.N - View-space shading normal.
|
|
415
|
+
* @param {Node<vec3>} params.V - View-space direction to camera.
|
|
416
|
+
* @param {Node<float>} params.alpha - GGX roughness (alpha).
|
|
417
|
+
* @param {Node<vec3>} params.f0
|
|
418
|
+
* @return {Node<vec3>}
|
|
419
|
+
*/
|
|
420
|
+
sampleEnvironmentBRDF( {
|
|
421
|
+
cameraWorldMatrix,
|
|
422
|
+
viewReflectDir,
|
|
423
|
+
N,
|
|
424
|
+
V,
|
|
425
|
+
alpha,
|
|
426
|
+
f0
|
|
427
|
+
} ) {
|
|
428
|
+
|
|
429
|
+
const worldNormal = cameraWorldMatrix.mul( vec4( N, 0 ) ).xyz.normalize().toVar();
|
|
430
|
+
const worldV = cameraWorldMatrix.mul( vec4( V, 0 ) ).xyz.normalize().toVar();
|
|
431
|
+
const NdotV = max( float( 0 ), dot( worldNormal, worldV ) ).toVar();
|
|
432
|
+
|
|
433
|
+
const L1 = cameraWorldMatrix.mul( vec4( viewReflectDir, float( 0 ) ) ).xyz.normalize().toVar();
|
|
434
|
+
// Explicit LOD 0: the equirect mapping is singular at the poles (atan undefined when the reflected
|
|
435
|
+
// ray points straight up/down, e.g. a flat floor under a top-down camera), so derivative-driven mip
|
|
436
|
+
// selection picks the coarsest, near-average mip and yields a bright streak. Sample full-res instead.
|
|
437
|
+
const brdfEnvColor = texture( this._mapNode, equirectUV( L1 ) ).level( 0 ).rgb;
|
|
438
|
+
|
|
439
|
+
const H1 = normalize( worldV.add( L1 ) ).toVar();
|
|
440
|
+
const NdotL1 = max( float( 0 ), dot( worldNormal, L1 ) ).toVar();
|
|
441
|
+
const VdotH1 = max( float( 0 ), dot( worldV, H1 ) ).toVar();
|
|
442
|
+
|
|
443
|
+
const W1 = F_Schlick( f0, VdotH1 ).mul( GeometryTerm( NdotL1, NdotV, alpha ) ).div( SmithG( NdotV, alpha ).max( float( 1e-4 ) ) );
|
|
444
|
+
|
|
445
|
+
return brdfEnvColor.mul( W1 ).mul( this.intensity );
|
|
446
|
+
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Environment reflection for a screen-space miss, estimated with multiple importance
|
|
451
|
+
* sampling (MIS) between the BRDF / reflected-ray direction and the env-luminance CDF
|
|
452
|
+
* direction. Both techniques use consistent solid-angle PDFs (`D·G1(N·V)/(4·N·V)`), so
|
|
453
|
+
* the power heuristic is unbiased. Adapted from three-gpu-pathtracer.
|
|
454
|
+
*
|
|
455
|
+
* @see {@link https://github.com/gkjohnson/three-gpu-pathtracer}
|
|
456
|
+
*
|
|
457
|
+
* @param {Object} params
|
|
458
|
+
* @param {UniformNode<Matrix4>} params.cameraWorldMatrix
|
|
459
|
+
* @param {Node<vec3>} params.viewReflectDir - View-space GGX-sampled reflected ray.
|
|
460
|
+
* @param {Node<vec3>} params.N - View-space shading normal.
|
|
461
|
+
* @param {Node<vec3>} params.V - View-space direction to camera.
|
|
462
|
+
* @param {Node<float>} params.alpha - GGX roughness (alpha).
|
|
463
|
+
* @param {Node<vec3>} params.f0
|
|
464
|
+
* @param {Node<vec4>} params.Xi2 - Second blue-noise sample (zw used for the CDF).
|
|
465
|
+
* @return {Node<vec3>}
|
|
466
|
+
*/
|
|
467
|
+
sampleEnvironmentMIS( {
|
|
468
|
+
cameraWorldMatrix,
|
|
469
|
+
viewReflectDir,
|
|
470
|
+
N,
|
|
471
|
+
V,
|
|
472
|
+
alpha,
|
|
473
|
+
f0,
|
|
474
|
+
Xi2
|
|
475
|
+
} ) {
|
|
476
|
+
|
|
477
|
+
const mapNode = this._mapNode;
|
|
478
|
+
const marginalNode = this._marginalNode;
|
|
479
|
+
const conditionalNode = this._conditionalNode;
|
|
480
|
+
const totalSum = this._totalSum;
|
|
481
|
+
const envW = this._size.x;
|
|
482
|
+
const envH = this._size.y;
|
|
483
|
+
const envMapIntensity = this.intensity;
|
|
484
|
+
|
|
485
|
+
const worldNormal = cameraWorldMatrix.mul( vec4( N, 0 ) ).xyz.normalize().toVar();
|
|
486
|
+
const worldV = cameraWorldMatrix.mul( vec4( V, 0 ) ).xyz.normalize().toVar();
|
|
487
|
+
const NdotV = max( float( 0 ), dot( worldNormal, worldV ) ).toVar();
|
|
488
|
+
|
|
489
|
+
// MIS sample 1: the BRDF / reflected-ray direction
|
|
490
|
+
const L1 = cameraWorldMatrix.mul( vec4( viewReflectDir, float( 0 ) ) ).xyz.normalize().toVar();
|
|
491
|
+
const brdfEnvColor = texture( mapNode, equirectUV( L1 ) ).level( 0 ).rgb;
|
|
492
|
+
|
|
493
|
+
const H1 = normalize( worldV.add( L1 ) ).toVar();
|
|
494
|
+
const NdotL1 = max( float( 0 ), dot( worldNormal, L1 ) ).toVar();
|
|
495
|
+
const NdotH1 = max( float( 0 ), dot( worldNormal, H1 ) ).toVar();
|
|
496
|
+
const VdotH1 = max( float( 0 ), dot( worldV, H1 ) ).toVar();
|
|
497
|
+
|
|
498
|
+
// Solid-angle PDF of the reflected ray for the BRDF technique: D(H)·G1(N·V)/(4·N·V).
|
|
499
|
+
const pdfBrdf1 = D_GTR( alpha, NdotH1, float( 2 ) ).mul( SmithG( NdotV, alpha ) ).div( max( float( 1e-6 ), float( 4 ).mul( NdotV ) ) ).max( float( 1e-8 ) );
|
|
500
|
+
// Env-luminance CDF PDF evaluated at the same direction.
|
|
501
|
+
const pdfEnv1 = envW.mul( envH ).mul( luminance( brdfEnvColor ).div( totalSum ) ).mul( equirectDirPdf( L1 ) ).max( float( 1e-8 ) );
|
|
502
|
+
const w1 = misPowerHeuristic( pdfBrdf1, pdfEnv1 );
|
|
503
|
+
|
|
504
|
+
// Monte-Carlo weight f·cosθ/pdfBrdf1 = F·G1(N·L) (GGX D cancels analytically — stable at low
|
|
505
|
+
// roughness). G2 and the pdf's G1 must use the same alpha for the cancellation to hold.
|
|
506
|
+
const W1 = F_Schlick( f0, VdotH1 ).mul( GeometryTerm( NdotL1, NdotV, alpha ) ).div( SmithG( NdotV, alpha ).max( float( 1e-4 ) ) );
|
|
507
|
+
const result = brdfEnvColor.mul( W1 ).mul( w1 ).toVar();
|
|
508
|
+
|
|
509
|
+
// MIS sample 2: the env-luminance CDF direction
|
|
510
|
+
// Mitigates noise on high-dynamic-range environments (the CDF lands samples on bright regions
|
|
511
|
+
// the BRDF lobe rarely hits). Skipped for near-mirror lobes (alpha ≲ 0.01, i.e. roughness ≲ 0.1):
|
|
512
|
+
// a global CDF direction almost never lands inside such a tight specular lobe.
|
|
513
|
+
If( alpha.greaterThan( 0.01 ), () => {
|
|
514
|
+
|
|
515
|
+
const r_env = vec2( Xi2.z, Xi2.w );
|
|
516
|
+
const v_cdf = texture( marginalNode, vec2( r_env.x, float( 0 ) ) ).r;
|
|
517
|
+
const u_cdf = texture( conditionalNode, vec2( r_env.y, v_cdf ) ).r;
|
|
518
|
+
const isEnvUV = vec2( u_cdf, v_cdf );
|
|
519
|
+
const envDirWS = equirectUV( isEnvUV );
|
|
520
|
+
|
|
521
|
+
const envHalf = normalize( worldV.add( envDirWS ) );
|
|
522
|
+
const envNdotL = max( float( 0 ), dot( worldNormal, envDirWS ) );
|
|
523
|
+
const envNdotH = max( float( 0 ), dot( worldNormal, envHalf ) );
|
|
524
|
+
const envVdotH = max( float( 0 ), dot( worldV, envHalf ) );
|
|
525
|
+
|
|
526
|
+
If( envNdotL.greaterThan( 0.001 ), () => {
|
|
527
|
+
|
|
528
|
+
// GGX normal-distribution term, shared by the BRDF pdf and the specular BRDF
|
|
529
|
+
// (both evaluate D(envNdotH)) so the pow is computed once.
|
|
530
|
+
const D = D_GTR( alpha, envNdotH, float( 2 ) ).toVar();
|
|
531
|
+
|
|
532
|
+
const sampledColor = texture( mapNode, isEnvUV ).level( 0 ).rgb;
|
|
533
|
+
const pdfEnv2 = envW.mul( envH ).mul( luminance( sampledColor ).div( totalSum ) ).mul( equirectDirPdf( envDirWS ) ).max( float( 1e-8 ) );
|
|
534
|
+
// BRDF technique pdf at the env direction — same solid-angle form as pdfBrdf1 (no V·H).
|
|
535
|
+
const pdfBrdf2 = D.mul( SmithG( NdotV, alpha ) ).div( max( float( 1e-6 ), float( 4 ).mul( NdotV ) ) ).max( float( 1e-8 ) );
|
|
536
|
+
const w2 = misPowerHeuristic( pdfEnv2, pdfBrdf2 );
|
|
537
|
+
|
|
538
|
+
// Specular BRDF (without Fresnel): D·G2 / (4·N·L·N·V), reusing D. Same GGX alpha as the pdf.
|
|
539
|
+
const envBrdfSpec = D.mul( GeometryTerm( envNdotL, NdotV, alpha ) ).div( max( float( 1e-6 ), float( 4 ).mul( envNdotL ).mul( NdotV ) ) );
|
|
540
|
+
const envFresnelWeight = F_Schlick( f0, envVdotH ); // vec3 — chromatic metal tint
|
|
541
|
+
|
|
542
|
+
result.addAssign( sampledColor.mul( envBrdfSpec ).mul( envFresnelWeight ).mul( envNdotL ).div( pdfEnv2 ).mul( w2 ) );
|
|
543
|
+
|
|
544
|
+
} );
|
|
545
|
+
|
|
546
|
+
} );
|
|
547
|
+
|
|
548
|
+
return result.mul( envMapIntensity );
|
|
549
|
+
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
dispose() {
|
|
553
|
+
|
|
554
|
+
this._cdf.dispose();
|
|
555
|
+
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
export default ImportanceSampledEnvironment;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NearestFilter, Vector4, TempNode, NodeUpdateType, PassNode } from 'three/webgpu';
|
|
2
|
-
import { nodeObject, Fn, float, uv, uniform, convertToTexture, vec2, vec3, clamp, floor, dot, smoothstep, If, sign, step, mrt, output, normalView, property } from 'three/tsl';
|
|
2
|
+
import { nodeObject, Fn, float, uv, uniform, convertToTexture, vec2, vec3, clamp, floor, dot, smoothstep, If, sign, step, mrt, output, normalView, property, vec4 } from 'three/tsl';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* A inner node definition that implements the actual pixelation TSL code.
|
|
@@ -202,7 +202,7 @@ class PixelationNode extends TempNode {
|
|
|
202
202
|
|
|
203
203
|
const strength = dei.greaterThan( 0 ).select( float( 1.0 ).sub( dei.mul( this.depthEdgeStrength ) ), nei.mul( this.normalEdgeStrength ).add( 1 ) );
|
|
204
204
|
|
|
205
|
-
return texel.mul( strength );
|
|
205
|
+
return vec4( texel.mul( strength ).rgb, texel.a );
|
|
206
206
|
|
|
207
207
|
} );
|
|
208
208
|
|