super-three 0.181.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/LICENSE +1 -1
- package/README.md +3 -4
- package/build/three.cjs +21332 -19201
- package/build/three.core.js +20908 -19853
- package/build/three.core.min.js +2 -2
- package/build/three.module.js +1947 -862
- package/build/three.module.min.js +2 -2
- package/build/three.tsl.js +37 -16
- package/build/three.tsl.min.js +2 -2
- package/build/three.webgpu.js +33628 -25197
- package/build/three.webgpu.min.js +2 -2
- package/build/three.webgpu.nodes.js +33394 -25000
- package/build/three.webgpu.nodes.min.js +2 -2
- package/examples/jsm/Addons.js +14 -3
- package/examples/jsm/animation/CCDIKSolver.js +7 -3
- package/examples/jsm/controls/ArcballControls.js +13 -6
- package/examples/jsm/controls/DragControls.js +2 -2
- package/examples/jsm/controls/FirstPersonControls.js +127 -86
- package/examples/jsm/controls/FlyControls.js +4 -0
- package/examples/jsm/controls/MapControls.js +55 -1
- package/examples/jsm/controls/OrbitControls.js +111 -8
- package/examples/jsm/controls/TrackballControls.js +8 -8
- package/examples/jsm/controls/TransformControls.js +102 -17
- package/examples/jsm/csm/CSM.js +2 -1
- package/examples/jsm/csm/CSMFrustum.js +31 -6
- package/examples/jsm/csm/CSMShadowNode.js +10 -3
- package/examples/jsm/effects/AnaglyphEffect.js +102 -7
- package/examples/jsm/effects/AsciiEffect.js +14 -1
- package/examples/jsm/environments/ColorEnvironment.js +59 -0
- package/examples/jsm/environments/RoomEnvironment.js +3 -0
- package/examples/jsm/exporters/DRACOExporter.js +27 -6
- package/examples/jsm/exporters/EXRExporter.js +1 -1
- package/examples/jsm/exporters/GLTFExporter.js +266 -21
- package/examples/jsm/exporters/PLYExporter.js +286 -73
- package/examples/jsm/exporters/USDZExporter.js +353 -99
- 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/DecalGeometry.js +1 -1
- package/examples/jsm/geometries/LoftGeometry.js +355 -0
- package/examples/jsm/geometries/TextGeometry.js +18 -0
- package/examples/jsm/helpers/AnimationPathHelper.js +302 -0
- package/examples/jsm/helpers/LightProbeGridHelper.js +221 -0
- package/examples/jsm/helpers/LightProbeHelper.js +5 -4
- package/examples/jsm/helpers/LightProbeHelperGPU.js +1 -1
- package/examples/jsm/helpers/TextureHelperGPU.js +1 -1
- package/examples/jsm/helpers/ViewHelper.js +83 -14
- package/examples/jsm/inspector/Extension.js +13 -0
- package/examples/jsm/inspector/Inspector.js +244 -91
- package/examples/jsm/inspector/RendererInspector.js +165 -39
- package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphEditor.js +916 -0
- package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphLoader.js +281 -0
- package/examples/jsm/inspector/tabs/Console.js +241 -25
- package/examples/jsm/inspector/tabs/Memory.js +136 -0
- package/examples/jsm/inspector/tabs/Parameters.js +115 -7
- package/examples/jsm/inspector/tabs/Performance.js +24 -9
- package/examples/jsm/inspector/tabs/Settings.js +306 -0
- package/examples/jsm/inspector/tabs/Timeline.js +1696 -0
- package/examples/jsm/inspector/tabs/Viewer.js +723 -9
- 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 +2 -2
- package/examples/jsm/inspector/ui/Profiler.js +1991 -44
- package/examples/jsm/inspector/ui/Style.js +1943 -543
- package/examples/jsm/inspector/ui/Tab.js +226 -5
- package/examples/jsm/inspector/ui/Values.js +126 -8
- package/examples/jsm/inspector/ui/utils.js +143 -10
- package/examples/jsm/interaction/InteractionManager.js +226 -0
- 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_decoder.module.js +9 -8
- 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/DynamicLighting.js +82 -0
- package/examples/jsm/lighting/LightProbeGrid.js +681 -0
- package/examples/jsm/lines/LineMaterial.js +45 -16
- package/examples/jsm/lines/LineSegments2.js +8 -0
- package/examples/jsm/lines/webgpu/LineSegments2.js +8 -0
- package/examples/jsm/loaders/3DMLoader.js +6 -5
- package/examples/jsm/loaders/3MFLoader.js +2 -2
- package/examples/jsm/loaders/AMFLoader.js +2 -2
- package/examples/jsm/loaders/ColladaLoader.js +24 -4026
- package/examples/jsm/loaders/DRACOLoader.js +51 -18
- package/examples/jsm/loaders/EXRLoader.js +701 -90
- package/examples/jsm/loaders/FBXLoader.js +235 -37
- package/examples/jsm/loaders/GCodeLoader.js +34 -8
- package/examples/jsm/loaders/GLTFLoader.js +146 -178
- package/examples/jsm/loaders/HDRLoader.js +7 -30
- package/examples/jsm/loaders/KMZLoader.js +5 -5
- package/examples/jsm/loaders/KTX2Loader.js +58 -17
- package/examples/jsm/loaders/LDrawLoader.js +49 -58
- package/examples/jsm/loaders/LUT3dlLoader.js +2 -2
- package/examples/jsm/loaders/LUTCubeLoader.js +2 -2
- package/examples/jsm/loaders/LWOLoader.js +11 -39
- package/examples/jsm/loaders/LottieLoader.js +1 -1
- package/examples/jsm/loaders/MaterialXLoader.js +31 -9
- package/examples/jsm/loaders/NRRDLoader.js +5 -5
- package/examples/jsm/loaders/PCDLoader.js +11 -9
- package/examples/jsm/loaders/PLYLoader.js +218 -55
- package/examples/jsm/loaders/SVGLoader.js +549 -497
- package/examples/jsm/loaders/TDSLoader.js +0 -2
- package/examples/jsm/loaders/TGALoader.js +0 -2
- package/examples/jsm/loaders/TTFLoader.js +1 -1
- package/examples/jsm/loaders/USDLoader.js +127 -43
- package/examples/jsm/loaders/UltraHDRLoader.js +285 -160
- package/examples/jsm/loaders/VOXLoader.js +660 -117
- package/examples/jsm/loaders/VRMLLoader.js +80 -3
- package/examples/jsm/loaders/VTKLoader.js +42 -25
- package/examples/jsm/loaders/collada/ColladaComposer.js +3044 -0
- package/examples/jsm/loaders/collada/ColladaParser.js +1977 -0
- package/examples/jsm/loaders/usd/USDAParser.js +504 -344
- package/examples/jsm/loaders/usd/USDCParser.js +1867 -6
- package/examples/jsm/loaders/usd/USDComposer.js +4627 -0
- package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +2 -2
- package/examples/jsm/materials/WoodNodeMaterial.js +11 -11
- package/examples/jsm/math/Octree.js +131 -1
- package/examples/jsm/misc/GPUComputationRenderer.js +2 -0
- package/examples/jsm/misc/RollerCoaster.js +42 -4
- package/examples/jsm/misc/TileCreasedNormalsPlugin.js +270 -0
- package/examples/jsm/misc/Volume.js +2 -3
- package/examples/jsm/misc/VolumeSlice.js +0 -1
- package/examples/jsm/modifiers/TessellateModifier.js +1 -1
- package/examples/jsm/objects/GroundedSkybox.js +1 -1
- package/examples/jsm/objects/LensflareMesh.js +1 -1
- package/examples/jsm/objects/Reflector.js +72 -25
- package/examples/jsm/objects/Sky.js +90 -6
- package/examples/jsm/objects/SkyMesh.js +150 -16
- package/examples/jsm/objects/Water.js +4 -3
- package/examples/jsm/objects/Water2.js +5 -3
- package/examples/jsm/objects/Water2Mesh.js +1 -1
- package/examples/jsm/objects/WaterMesh.js +5 -7
- package/examples/jsm/physics/AmmoPhysics.js +27 -15
- package/examples/jsm/physics/JoltPhysics.js +10 -6
- package/examples/jsm/physics/RapierPhysics.js +36 -7
- package/examples/jsm/postprocessing/EffectComposer.js +7 -5
- package/examples/jsm/postprocessing/OutputPass.js +9 -0
- package/examples/jsm/postprocessing/RenderPass.js +10 -0
- package/examples/jsm/postprocessing/RenderTransitionPass.js +1 -1
- package/examples/jsm/postprocessing/UnrealBloomPass.js +48 -18
- package/examples/jsm/renderers/CSS3DRenderer.js +1 -1
- package/examples/jsm/renderers/Projector.js +246 -28
- package/examples/jsm/renderers/SVGRenderer.js +174 -60
- package/examples/jsm/shaders/GTAOShader.js +19 -6
- package/examples/jsm/shaders/HalftoneShader.js +12 -1
- package/examples/jsm/shaders/PoissonDenoiseShader.js +6 -2
- package/examples/jsm/shaders/SAOShader.js +17 -4
- package/examples/jsm/shaders/SSAOShader.js +11 -1
- package/examples/jsm/shaders/SSRShader.js +6 -5
- package/examples/jsm/shaders/UnpackDepthRGBAShader.js +2 -4
- package/examples/jsm/shaders/VignetteShader.js +1 -1
- package/examples/jsm/shaders/VolumeShader.js +31 -44
- package/examples/jsm/transpiler/AST.js +44 -0
- package/examples/jsm/transpiler/GLSLDecoder.js +65 -8
- package/examples/jsm/transpiler/Linker.js +1 -1
- package/examples/jsm/transpiler/ShaderToyDecoder.js +2 -0
- package/examples/jsm/transpiler/TSLEncoder.js +46 -3
- package/examples/jsm/transpiler/TranspilerUtils.js +3 -3
- package/examples/jsm/transpiler/WGSLEncoder.js +27 -0
- package/examples/jsm/tsl/WebGLNodesHandler.js +605 -0
- package/examples/jsm/tsl/display/AfterImageNode.js +11 -1
- package/examples/jsm/tsl/display/AnaglyphPassNode.js +458 -16
- package/examples/jsm/tsl/display/BilateralBlurNode.js +374 -0
- package/examples/jsm/tsl/display/BloomNode.js +75 -25
- package/examples/jsm/tsl/display/CRT.js +150 -0
- package/examples/jsm/tsl/display/ChromaticAberrationNode.js +3 -36
- package/examples/jsm/tsl/display/DenoiseNode.js +1 -1
- package/examples/jsm/tsl/display/DepthOfFieldNode.js +3 -3
- package/examples/jsm/tsl/display/DotScreenNode.js +1 -1
- package/examples/jsm/tsl/display/FSR1Node.js +477 -0
- package/examples/jsm/tsl/display/FXAANode.js +13 -14
- package/examples/jsm/tsl/display/GTAONode.js +40 -17
- package/examples/jsm/tsl/display/GaussianBlurNode.js +21 -2
- package/examples/jsm/tsl/display/GodraysNode.js +615 -0
- package/examples/jsm/tsl/display/ImportanceSampledEnvironment.js +560 -0
- package/examples/jsm/tsl/display/LensflareNode.js +1 -1
- package/examples/jsm/tsl/display/Lut3DNode.js +1 -1
- package/examples/jsm/tsl/display/OutlineNode.js +69 -19
- package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +2 -2
- package/examples/jsm/tsl/display/PixelationPassNode.js +9 -8
- package/examples/jsm/tsl/display/RGBShiftNode.js +2 -2
- package/examples/jsm/tsl/display/RecurrentDenoiseNode.js +912 -0
- package/examples/jsm/tsl/display/RetroPassNode.js +263 -0
- package/examples/jsm/tsl/display/SMAANode.js +2 -2
- package/examples/jsm/tsl/display/SSAAPassNode.js +15 -27
- package/examples/jsm/tsl/display/SSGINode.js +96 -62
- package/examples/jsm/tsl/display/SSRNode.js +831 -134
- package/examples/jsm/tsl/display/SSSNode.js +8 -6
- package/examples/jsm/tsl/display/Shape.js +29 -0
- package/examples/jsm/tsl/display/SharpenNode.js +283 -0
- package/examples/jsm/tsl/display/SobelOperatorNode.js +2 -2
- package/examples/jsm/tsl/display/StereoCompositePassNode.js +8 -1
- package/examples/jsm/tsl/display/StereoPassNode.js +1 -2
- package/examples/jsm/tsl/display/TAAUNode.js +835 -0
- package/examples/jsm/tsl/display/TRAANode.js +315 -126
- package/examples/jsm/tsl/display/TemporalReprojectNode.js +1023 -0
- package/examples/jsm/tsl/display/TransitionNode.js +1 -1
- package/examples/jsm/tsl/display/depthAwareBlend.js +80 -0
- package/examples/jsm/tsl/display/radialBlur.js +68 -0
- package/examples/jsm/tsl/lighting/ClusteredLightsNode.js +622 -0
- package/examples/jsm/tsl/lighting/DynamicLightsNode.js +300 -0
- package/examples/jsm/tsl/lighting/data/AmbientLightDataNode.js +61 -0
- package/examples/jsm/tsl/lighting/data/DirectionalLightDataNode.js +111 -0
- package/examples/jsm/tsl/lighting/data/HemisphereLightDataNode.js +99 -0
- package/examples/jsm/tsl/lighting/data/PointLightDataNode.js +134 -0
- package/examples/jsm/tsl/lighting/data/SpotLightDataNode.js +161 -0
- package/examples/jsm/tsl/math/Bayer.js +53 -3
- 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 +128 -62
- package/examples/jsm/utils/ColorUtils.js +76 -0
- package/examples/jsm/utils/GeometryCompressionUtils.js +1 -1
- package/examples/jsm/utils/LDrawUtils.js +1 -1
- package/examples/jsm/utils/SceneOptimizer.js +1 -1
- package/examples/jsm/utils/ShadowMapViewer.js +24 -10
- package/examples/jsm/utils/ShadowMapViewerGPU.js +1 -1
- package/examples/jsm/utils/SkeletonUtils.js +14 -8
- package/examples/jsm/utils/WebGPUTextureUtils.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/examples/jsm/webxr/XRHandMeshModel.js +36 -10
- package/examples/jsm/webxr/XRHandModelFactory.js +2 -1
- package/package.json +28 -34
- package/src/Three.Core.js +3 -1
- package/src/Three.TSL.js +35 -14
- package/src/Three.WebGPU.Nodes.js +5 -0
- package/src/Three.WebGPU.js +13 -0
- package/src/Three.js +1 -0
- package/src/animation/AnimationAction.js +18 -4
- package/src/animation/AnimationClip.js +0 -139
- package/src/animation/AnimationMixer.js +6 -0
- package/src/animation/AnimationUtils.js +1 -12
- package/src/animation/KeyframeTrack.js +47 -8
- package/src/animation/PropertyBinding.js +2 -2
- package/src/animation/PropertyMixer.js +4 -4
- package/src/animation/tracks/BooleanKeyframeTrack.js +1 -1
- package/src/animation/tracks/ColorKeyframeTrack.js +1 -1
- package/src/animation/tracks/NumberKeyframeTrack.js +1 -1
- package/src/animation/tracks/QuaternionKeyframeTrack.js +1 -1
- package/src/animation/tracks/StringKeyframeTrack.js +1 -1
- package/src/animation/tracks/VectorKeyframeTrack.js +1 -1
- package/src/audio/Audio.js +1 -1
- package/src/audio/AudioContext.js +2 -2
- package/src/audio/AudioListener.js +5 -3
- package/src/cameras/Camera.js +34 -4
- package/src/cameras/CubeCamera.js +20 -0
- package/src/cameras/StereoCamera.js +5 -2
- package/src/constants.js +90 -5
- package/src/core/BufferAttribute.js +13 -1
- package/src/core/BufferGeometry.js +43 -9
- package/src/core/Clock.js +7 -0
- package/src/core/Object3D.js +69 -11
- package/src/core/Raycaster.js +3 -3
- package/src/core/RenderTarget.js +19 -6
- package/src/extras/PMREMGenerator.js +13 -22
- package/src/extras/TextureUtils.js +6 -2
- package/src/extras/core/ShapePath.js +149 -160
- package/src/extras/curves/CatmullRomCurve3.js +3 -2
- package/src/geometries/ExtrudeGeometry.js +2 -2
- package/src/geometries/PolyhedronGeometry.js +1 -1
- package/src/geometries/SphereGeometry.js +8 -3
- package/src/geometries/TorusGeometry.js +8 -3
- package/src/helpers/CameraHelper.js +3 -0
- package/src/helpers/DirectionalLightHelper.js +6 -1
- package/src/helpers/HemisphereLightHelper.js +5 -0
- package/src/helpers/PointLightHelper.js +3 -25
- package/src/helpers/SpotLightHelper.js +4 -1
- package/src/lights/DirectionalLight.js +13 -0
- package/src/lights/HemisphereLight.js +10 -0
- package/src/lights/Light.js +1 -11
- package/src/lights/LightProbe.js +0 -15
- package/src/lights/LightShadow.js +15 -6
- package/src/lights/PointLight.js +15 -0
- package/src/lights/PointLightShadow.js +0 -86
- package/src/lights/SpotLight.js +22 -1
- package/src/lights/webgpu/IESSpotLight.js +2 -1
- package/src/loaders/AudioLoader.js +11 -1
- package/src/loaders/Cache.js +28 -0
- package/src/loaders/DataTextureLoader.js +75 -42
- package/src/loaders/FileLoader.js +2 -3
- package/src/loaders/ImageBitmapLoader.js +12 -9
- package/src/loaders/Loader.js +6 -0
- package/src/loaders/LoadingManager.js +5 -0
- package/src/loaders/MaterialLoader.js +37 -266
- package/src/loaders/ObjectLoader.js +48 -6
- package/src/loaders/nodes/NodeLoader.js +2 -2
- package/src/loaders/nodes/NodeObjectLoader.js +18 -0
- package/src/materials/LineBasicMaterial.js +4 -0
- package/src/materials/Material.js +198 -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 +49 -1
- package/src/materials/MeshMatcapMaterial.js +25 -1
- package/src/materials/MeshNormalMaterial.js +9 -1
- package/src/materials/MeshPhongMaterial.js +49 -1
- package/src/materials/MeshPhysicalMaterial.js +38 -0
- package/src/materials/MeshStandardMaterial.js +42 -1
- package/src/materials/MeshToonMaterial.js +35 -2
- package/src/materials/PointsMaterial.js +7 -0
- package/src/materials/ShaderMaterial.js +106 -1
- package/src/materials/SpriteMaterial.js +7 -0
- package/src/materials/nodes/Line2NodeMaterial.js +380 -297
- 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 +3 -30
- package/src/materials/nodes/MeshSSSNodeMaterial.js +0 -13
- package/src/materials/nodes/MeshStandardNodeMaterial.js +5 -15
- package/src/materials/nodes/NodeMaterial.js +153 -89
- package/src/materials/nodes/SpriteNodeMaterial.js +0 -10
- package/src/materials/nodes/manager/NodeMaterialObserver.js +234 -100
- package/src/math/Box3.js +5 -0
- package/src/math/FrustumArray.js +103 -133
- package/src/math/Interpolant.js +1 -1
- package/src/math/Line3.js +6 -5
- package/src/math/MathUtils.js +12 -12
- package/src/math/Matrix2.js +13 -9
- package/src/math/Matrix3.js +24 -9
- package/src/math/Matrix4.js +112 -74
- package/src/math/Plane.js +4 -3
- package/src/math/Quaternion.js +3 -29
- package/src/math/Sphere.js +1 -1
- package/src/math/Triangle.js +1 -1
- package/src/math/Vector2.js +13 -9
- package/src/math/Vector3.js +17 -15
- package/src/math/Vector4.js +15 -11
- package/src/math/interpolants/BezierInterpolant.js +106 -0
- package/src/nodes/Nodes.js +86 -71
- package/src/nodes/TSL.js +15 -13
- package/src/nodes/accessors/Arrays.js +5 -5
- package/src/nodes/accessors/Batch.js +108 -0
- package/src/nodes/accessors/Bitangent.js +7 -7
- package/src/nodes/accessors/BufferAttributeNode.js +120 -17
- package/src/nodes/accessors/BufferNode.js +29 -2
- package/src/nodes/accessors/Camera.js +149 -28
- package/src/nodes/accessors/ClippingNode.js +5 -5
- package/src/nodes/accessors/CubeTextureNode.js +27 -2
- package/src/nodes/accessors/Instance.js +264 -0
- package/src/nodes/accessors/MaterialNode.js +27 -3
- package/src/nodes/accessors/MaterialProperties.js +6 -8
- package/src/nodes/accessors/MaterialReferenceNode.js +1 -2
- package/src/nodes/accessors/ModelNode.js +1 -1
- package/src/nodes/accessors/{MorphNode.js → Morph.js} +99 -112
- package/src/nodes/accessors/Normal.js +24 -24
- package/src/nodes/accessors/Object3DNode.js +1 -1
- package/src/nodes/accessors/Position.js +39 -3
- package/src/nodes/accessors/ReferenceBaseNode.js +6 -6
- package/src/nodes/accessors/ReferenceNode.js +9 -8
- package/src/nodes/accessors/ReflectVector.js +3 -3
- package/src/nodes/accessors/RendererReferenceNode.js +1 -2
- package/src/nodes/accessors/SceneProperties.js +47 -0
- package/src/nodes/accessors/Skinning.js +263 -0
- package/src/nodes/accessors/StorageBufferNode.js +16 -27
- package/src/nodes/accessors/StorageTexture3DNode.js +100 -0
- package/src/nodes/accessors/StorageTextureNode.js +74 -11
- package/src/nodes/accessors/Tangent.js +8 -18
- package/src/nodes/accessors/Texture3DNode.js +32 -35
- package/src/nodes/accessors/TextureNode.js +124 -25
- package/src/nodes/accessors/UniformArrayNode.js +6 -4
- package/src/nodes/accessors/UserDataNode.js +1 -2
- package/src/nodes/accessors/VertexColorNode.js +1 -2
- package/src/nodes/code/FunctionCallNode.js +1 -1
- package/src/nodes/code/FunctionNode.js +4 -19
- package/src/nodes/core/ArrayNode.js +21 -2
- package/src/nodes/core/AssignNode.js +3 -3
- package/src/nodes/core/AttributeNode.js +3 -3
- package/src/nodes/core/BypassNode.js +1 -1
- package/src/nodes/core/ContextNode.js +104 -5
- package/src/nodes/core/IndexNode.js +2 -1
- package/src/nodes/core/InputNode.js +1 -1
- package/src/nodes/core/InspectorNode.js +1 -1
- package/src/nodes/core/IsolateNode.js +1 -1
- package/src/nodes/core/MRTNode.js +55 -4
- package/src/nodes/core/Node.js +151 -17
- package/src/nodes/core/NodeBuilder.js +479 -101
- package/src/nodes/core/NodeError.js +28 -0
- package/src/nodes/core/NodeFrame.js +12 -4
- package/src/nodes/core/NodeUtils.js +20 -18
- package/src/nodes/core/OutputStructNode.js +13 -11
- package/src/nodes/core/OverrideContextNode.js +153 -0
- package/src/nodes/core/ParameterNode.js +4 -4
- package/src/nodes/core/PropertyNode.js +66 -4
- package/src/nodes/core/StackNode.js +91 -20
- package/src/nodes/core/StackTrace.js +139 -0
- package/src/nodes/core/StructNode.js +20 -8
- package/src/nodes/core/StructTypeNode.js +17 -23
- package/src/nodes/core/SubBuildNode.js +2 -2
- package/src/nodes/core/UniformGroupNode.js +36 -6
- package/src/nodes/core/UniformNode.js +21 -5
- package/src/nodes/core/VarNode.js +56 -23
- package/src/nodes/core/VaryingNode.js +14 -21
- package/src/nodes/display/BlendModes.js +1 -105
- package/src/nodes/display/BumpMapNode.js +6 -1
- package/src/nodes/display/ColorAdjustment.js +27 -9
- package/src/nodes/display/ColorSpaceNode.js +3 -3
- package/src/nodes/display/FrontFacingNode.js +38 -9
- package/src/nodes/display/NormalMapNode.js +41 -6
- package/src/nodes/display/PassNode.js +157 -56
- package/src/nodes/display/PremultiplyAlphaFunctions.js +39 -0
- package/src/nodes/display/RenderOutputNode.js +19 -10
- package/src/nodes/display/ScreenNode.js +4 -2
- package/src/nodes/display/ToneMappingNode.js +1 -1
- package/src/nodes/display/ToonOutlinePassNode.js +2 -2
- package/src/nodes/display/ViewportDepthNode.js +52 -4
- package/src/nodes/display/ViewportDepthTextureNode.js +11 -15
- package/src/nodes/display/ViewportTextureNode.js +39 -11
- package/src/nodes/fog/Fog.js +18 -35
- package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +3 -3
- package/src/nodes/functions/BSDF/DFGLUT.js +56 -0
- package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
- package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +2 -2
- package/src/nodes/functions/PhysicalLightingModel.js +126 -45
- package/src/nodes/functions/VolumetricLightingModel.js +40 -7
- package/src/nodes/geometry/RangeNode.js +5 -3
- package/src/nodes/gpgpu/AtomicFunctionNode.js +1 -1
- package/src/nodes/gpgpu/BarrierNode.js +9 -0
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +2 -3
- package/src/nodes/gpgpu/ComputeNode.js +74 -48
- package/src/nodes/gpgpu/SubgroupFunctionNode.js +2 -2
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +5 -5
- package/src/nodes/lighting/AnalyticLightNode.js +53 -0
- package/src/nodes/lighting/EnvironmentNode.js +30 -5
- package/src/nodes/lighting/IESSpotLightNode.js +40 -2
- package/src/nodes/lighting/LightingContextNode.js +10 -2
- package/src/nodes/lighting/LightsNode.js +97 -65
- package/src/nodes/lighting/PointShadowNode.js +166 -148
- package/src/nodes/lighting/ShadowFilterNode.js +74 -117
- package/src/nodes/lighting/ShadowNode.js +149 -51
- package/src/nodes/materialx/lib/mx_noise.js +2 -2
- package/src/nodes/math/BitcastNode.js +1 -1
- package/src/nodes/math/BitcountNode.js +433 -0
- package/src/nodes/math/ConditionalNode.js +6 -6
- package/src/nodes/math/MathNode.js +115 -52
- package/src/nodes/math/OperatorNode.js +24 -23
- package/src/nodes/math/PackFloatNode.js +98 -0
- package/src/nodes/math/UnpackFloatNode.js +96 -0
- package/src/nodes/parsers/GLSLNodeFunction.js +1 -1
- package/src/nodes/pmrem/PMREMNode.js +34 -3
- package/src/nodes/pmrem/PMREMUtils.js +9 -15
- package/src/nodes/tsl/TSLBase.js +1 -1
- package/src/nodes/tsl/TSLCore.js +99 -33
- package/src/nodes/utils/ArrayElementNode.js +14 -1
- package/src/nodes/utils/ConvertNode.js +1 -1
- package/src/nodes/utils/DebugNode.js +12 -12
- package/src/nodes/utils/EquirectUV.js +30 -5
- package/src/nodes/utils/EventNode.js +31 -2
- package/src/nodes/utils/FlipNode.js +1 -1
- package/src/nodes/utils/FunctionOverloadingNode.js +2 -2
- package/src/nodes/utils/JoinNode.js +3 -3
- package/src/nodes/utils/LoopNode.js +1 -1
- package/src/nodes/utils/MemberNode.js +2 -2
- package/src/nodes/utils/Packing.js +48 -5
- package/src/nodes/utils/PostProcessingUtils.js +33 -1
- package/src/nodes/utils/RTTNode.js +41 -25
- package/src/nodes/utils/ReflectorNode.js +4 -4
- package/src/nodes/utils/Remap.js +48 -0
- package/src/nodes/utils/RotateNode.js +1 -1
- package/src/nodes/utils/SampleNode.js +1 -1
- package/src/nodes/utils/SetNode.js +1 -1
- package/src/nodes/utils/SplitNode.js +1 -1
- package/src/nodes/utils/SpriteSheetUV.js +35 -0
- package/src/nodes/utils/StorageArrayElementNode.js +1 -1
- package/src/nodes/utils/UVUtils.js +28 -0
- package/src/objects/BatchedMesh.js +66 -30
- package/src/objects/InstancedMesh.js +19 -3
- package/src/objects/Line.js +1 -1
- package/src/objects/Mesh.js +1 -1
- package/src/objects/Points.js +1 -1
- package/src/objects/SkinnedMesh.js +26 -9
- package/src/renderers/WebGLRenderer.js +344 -156
- package/src/renderers/common/Animation.js +3 -3
- package/src/renderers/common/Attributes.js +15 -1
- package/src/renderers/common/Backend.js +78 -13
- package/src/renderers/common/Background.js +26 -13
- package/src/renderers/common/BindGroup.js +1 -16
- package/src/renderers/common/Binding.js +11 -0
- package/src/renderers/common/Bindings.js +141 -57
- package/src/renderers/common/BlendMode.js +143 -0
- package/src/renderers/common/Buffer.js +49 -0
- package/src/renderers/common/BundleGroup.js +1 -1
- package/src/renderers/common/ChainMap.js +30 -6
- package/src/renderers/common/ClippingContext.js +10 -2
- package/src/renderers/common/ComputePipeline.js +1 -1
- package/src/renderers/common/CubeRenderTarget.js +51 -7
- package/src/renderers/common/Geometries.js +29 -3
- package/src/renderers/common/Info.js +374 -4
- package/src/renderers/common/InspectorBase.js +6 -1
- package/src/renderers/common/Lighting.js +51 -19
- package/src/renderers/common/Pipelines.js +40 -7
- package/src/renderers/common/PostProcessing.js +8 -206
- package/src/renderers/common/ReadbackBuffer.js +78 -0
- package/src/renderers/common/RenderBundle.js +3 -1
- package/src/renderers/common/RenderBundles.js +7 -3
- package/src/renderers/common/RenderContext.js +16 -0
- package/src/renderers/common/RenderContexts.js +33 -49
- package/src/renderers/common/RenderList.js +41 -4
- package/src/renderers/common/RenderLists.js +2 -1
- package/src/renderers/common/RenderObject.js +88 -16
- package/src/renderers/common/RenderObjectPipeline.js +40 -0
- package/src/renderers/common/RenderObjects.js +21 -5
- package/src/renderers/common/RenderPipeline.js +232 -17
- package/src/renderers/common/Renderer.js +700 -163
- package/src/renderers/common/Sampler.js +16 -48
- package/src/renderers/common/StorageBuffer.js +13 -1
- package/src/renderers/common/Textures.js +121 -9
- package/src/renderers/common/TimestampQueryPool.js +6 -4
- package/src/renderers/common/Uniform.js +8 -0
- package/src/renderers/common/UniformsGroup.js +84 -1
- package/src/renderers/common/XRManager.js +377 -51
- package/src/renderers/common/extras/PMREMGenerator.js +40 -61
- package/src/renderers/common/nodes/NodeBuilderState.js +10 -2
- package/src/renderers/common/nodes/NodeLibrary.js +4 -4
- package/src/renderers/common/nodes/{Nodes.js → NodeManager.js} +298 -106
- package/src/renderers/common/nodes/NodeStorageBuffer.js +13 -2
- package/src/renderers/common/nodes/NodeUniformBuffer.js +65 -0
- package/src/renderers/shaders/DFGLUTData.js +19 -34
- package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/color_fragment.glsl.js +1 -5
- package/src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl.js +1 -5
- package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +1 -5
- package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +8 -10
- 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_common_pars_fragment.glsl.js +0 -1
- package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +9 -13
- 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/lightprobes_pars_fragment.glsl.js +80 -0
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +13 -2
- package/src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +6 -2
- package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +3 -1
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +8 -4
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +112 -53
- package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js +7 -0
- package/src/renderers/shaders/ShaderChunk/normal_vertex.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/packing.glsl.js +20 -4
- package/src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl.js +0 -1
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +225 -186
- package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +12 -2
- package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk.js +5 -3
- package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +1 -2
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +3 -0
- package/src/renderers/shaders/ShaderLib/{distanceRGBA.glsl.js → distance.glsl.js} +2 -3
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +1 -2
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -9
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +0 -1
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/vsm.glsl.js +4 -6
- package/src/renderers/shaders/ShaderLib.js +7 -6
- package/src/renderers/shaders/UniformsLib.js +7 -5
- package/src/renderers/shaders/UniformsUtils.js +27 -5
- package/src/renderers/webgl/WebGLAnimation.js +2 -1
- package/src/renderers/webgl/WebGLBackground.js +15 -15
- package/src/renderers/webgl/WebGLBindingStates.js +99 -27
- package/src/renderers/webgl/WebGLBufferRenderer.js +0 -32
- package/src/renderers/webgl/WebGLCapabilities.js +9 -4
- package/src/renderers/webgl/WebGLEnvironments.js +228 -0
- package/src/renderers/webgl/WebGLGeometries.js +10 -7
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +0 -32
- package/src/renderers/webgl/WebGLLights.js +18 -1
- package/src/renderers/webgl/WebGLMaterials.js +24 -13
- package/src/renderers/webgl/WebGLObjects.js +3 -1
- package/src/renderers/webgl/WebGLOutput.js +271 -0
- package/src/renderers/webgl/WebGLProgram.js +54 -113
- package/src/renderers/webgl/WebGLPrograms.js +74 -55
- package/src/renderers/webgl/WebGLRenderLists.js +24 -1
- package/src/renderers/webgl/WebGLRenderStates.js +13 -2
- package/src/renderers/webgl/WebGLShaderCache.js +5 -11
- package/src/renderers/webgl/WebGLShadowMap.js +188 -24
- package/src/renderers/webgl/WebGLState.js +75 -37
- package/src/renderers/webgl/WebGLTextures.js +230 -56
- package/src/renderers/webgl/WebGLUniforms.js +40 -3
- package/src/renderers/webgl/WebGLUniformsGroups.js +82 -35
- package/src/renderers/webgl/WebGLUtils.js +6 -2
- package/src/renderers/webgl-fallback/WebGLBackend.js +322 -92
- package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +0 -41
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +295 -66
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +53 -19
- package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +25 -0
- package/src/renderers/webgl-fallback/utils/WebGLState.js +223 -6
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +118 -73
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +10 -10
- package/src/renderers/webgl-fallback/utils/WebGLUtils.js +9 -3
- package/src/renderers/webgpu/WebGPUBackend.js +733 -302
- package/src/renderers/webgpu/WebGPURenderer.js +2 -1
- 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 +526 -93
- package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +1 -1
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +194 -61
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +395 -234
- package/src/renderers/webgpu/utils/WebGPUCapabilities.js +48 -0
- package/src/renderers/webgpu/utils/WebGPUConstants.js +10 -0
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +224 -91
- package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +228 -213
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +428 -175
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +40 -25
- package/src/renderers/webgpu/utils/WebGPUUtils.js +70 -13
- package/src/renderers/webxr/WebXRController.js +12 -0
- package/src/renderers/webxr/WebXRManager.js +4 -2
- package/src/textures/CubeDepthTexture.js +76 -0
- package/src/textures/DepthTexture.js +1 -1
- package/src/textures/ExternalTexture.js +0 -3
- package/src/textures/HTMLTexture.js +74 -0
- package/src/textures/Source.js +2 -2
- package/src/textures/Texture.js +16 -5
- package/src/utils.js +280 -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/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/materials/MeshGouraudMaterial.js +0 -434
- package/examples/jsm/materials/MeshPostProcessingMaterial.js +0 -167
- package/examples/jsm/shaders/GodRaysShader.js +0 -333
- package/examples/jsm/tsl/display/AnamorphicNode.js +0 -282
- package/examples/jsm/tsl/lighting/TiledLightsNode.js +0 -442
- package/src/nodes/accessors/BatchNode.js +0 -163
- package/src/nodes/accessors/InstanceNode.js +0 -244
- package/src/nodes/accessors/InstancedMeshNode.js +0 -50
- package/src/nodes/accessors/SceneNode.js +0 -145
- package/src/nodes/accessors/SkinningNode.js +0 -327
- package/src/nodes/code/ScriptableNode.js +0 -726
- package/src/nodes/code/ScriptableValueNode.js +0 -253
- package/src/nodes/display/PosterizeNode.js +0 -65
- package/src/nodes/functions/BSDF/DFGApprox.js +0 -71
- package/src/nodes/utils/RemapNode.js +0 -125
- package/src/nodes/utils/SpriteSheetUVNode.js +0 -90
- package/src/renderers/webgl/WebGLCubeMaps.js +0 -99
- package/src/renderers/webgl/WebGLCubeUVMaps.js +0 -134
|
@@ -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;
|
|
@@ -276,4 +276,4 @@ export default LensflareNode;
|
|
|
276
276
|
* @param {number} [params.downSampleRatio=4] - Defines how downsampling since the effect is usually not rendered at full resolution.
|
|
277
277
|
* @returns {LensflareNode}
|
|
278
278
|
*/
|
|
279
|
-
export const lensflare = ( node, params ) =>
|
|
279
|
+
export const lensflare = ( node, params ) => new LensflareNode( convertToTexture( node ), params );
|
|
@@ -106,4 +106,4 @@ export default Lut3DNode;
|
|
|
106
106
|
* @param {Node<float> | number} intensity - Controls the intensity of the effect.
|
|
107
107
|
* @returns {Lut3DNode}
|
|
108
108
|
*/
|
|
109
|
-
export const lut3D = ( node, lut, size, intensity ) =>
|
|
109
|
+
export const lut3D = ( node, lut, size, intensity ) => new Lut3DNode( nodeObject( node ), nodeObject( lut ), size, nodeObject( intensity ) );
|