@plastic-software/three 0.182.0 → 0.183.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/build/three.cjs +11520 -10877
- package/build/three.core.js +11732 -11340
- package/build/three.core.min.js +2 -2
- package/build/three.module.js +509 -262
- package/build/three.module.min.js +2 -2
- package/build/three.tsl.js +7 -11
- package/build/three.tsl.min.js +2 -2
- package/build/three.webgpu.js +3072 -2607
- package/build/three.webgpu.min.js +2 -2
- package/build/three.webgpu.nodes.js +3071 -2607
- package/build/three.webgpu.nodes.min.js +2 -2
- package/examples/jsm/Addons.js +0 -3
- package/examples/jsm/animation/CCDIKSolver.js +2 -2
- package/examples/jsm/controls/ArcballControls.js +3 -3
- package/examples/jsm/controls/OrbitControls.js +103 -0
- package/examples/jsm/effects/AnaglyphEffect.js +102 -7
- package/examples/jsm/environments/ColorEnvironment.js +59 -0
- package/examples/jsm/environments/RoomEnvironment.js +1 -0
- package/examples/jsm/exporters/EXRExporter.js +1 -1
- package/examples/jsm/exporters/GLTFExporter.js +131 -4
- package/examples/jsm/exporters/USDZExporter.js +22 -3
- package/examples/jsm/helpers/AnimationPathHelper.js +302 -0
- package/examples/jsm/helpers/ViewHelper.js +67 -8
- package/examples/jsm/inspector/Inspector.js +21 -5
- package/examples/jsm/inspector/tabs/Console.js +39 -5
- package/examples/jsm/inspector/tabs/Parameters.js +16 -0
- package/examples/jsm/inspector/ui/Style.js +25 -1
- package/examples/jsm/libs/meshopt_decoder.module.js +6 -5
- package/examples/jsm/lines/LineMaterial.js +6 -0
- 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/EXRLoader.js +5 -5
- package/examples/jsm/loaders/FBXLoader.js +2 -2
- package/examples/jsm/loaders/GCodeLoader.js +34 -8
- package/examples/jsm/loaders/GLTFLoader.js +122 -171
- package/examples/jsm/loaders/KMZLoader.js +5 -5
- package/examples/jsm/loaders/KTX2Loader.js +5 -5
- package/examples/jsm/loaders/LWOLoader.js +7 -39
- package/examples/jsm/loaders/NRRDLoader.js +2 -2
- package/examples/jsm/loaders/PCDLoader.js +3 -2
- package/examples/jsm/loaders/USDLoader.js +100 -40
- package/examples/jsm/loaders/UltraHDRLoader.js +182 -30
- package/examples/jsm/loaders/VRMLLoader.js +77 -0
- package/examples/jsm/loaders/VTKLoader.js +37 -24
- package/examples/jsm/loaders/collada/ColladaComposer.js +2950 -0
- package/examples/jsm/loaders/collada/ColladaParser.js +1962 -0
- package/examples/jsm/loaders/usd/USDAParser.js +447 -366
- package/examples/jsm/loaders/usd/USDCParser.js +1841 -6
- package/examples/jsm/loaders/usd/USDComposer.js +4041 -0
- package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +2 -2
- package/examples/jsm/objects/LensflareMesh.js +1 -1
- package/examples/jsm/objects/Sky.js +76 -4
- package/examples/jsm/objects/SkyMesh.js +114 -7
- package/examples/jsm/objects/Water.js +4 -3
- package/examples/jsm/objects/Water2.js +5 -3
- package/examples/jsm/objects/WaterMesh.js +5 -7
- package/examples/jsm/physics/JoltPhysics.js +7 -5
- package/examples/jsm/physics/RapierPhysics.js +6 -4
- package/examples/jsm/postprocessing/EffectComposer.js +7 -5
- package/examples/jsm/postprocessing/RenderTransitionPass.js +1 -1
- package/examples/jsm/renderers/CSS3DRenderer.js +1 -1
- package/examples/jsm/renderers/SVGRenderer.js +2 -2
- 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/VignetteShader.js +1 -1
- package/examples/jsm/tsl/display/AfterImageNode.js +1 -1
- package/examples/jsm/tsl/display/AnaglyphPassNode.js +456 -16
- package/examples/jsm/tsl/display/AnamorphicNode.js +1 -1
- package/examples/jsm/tsl/display/BilateralBlurNode.js +364 -0
- package/examples/jsm/tsl/display/BloomNode.js +5 -5
- package/examples/jsm/tsl/display/CRT.js +150 -0
- package/examples/jsm/tsl/display/DenoiseNode.js +1 -1
- package/examples/jsm/tsl/display/DepthOfFieldNode.js +1 -1
- package/examples/jsm/tsl/display/DotScreenNode.js +1 -1
- package/examples/jsm/tsl/display/FXAANode.js +2 -2
- package/examples/jsm/tsl/display/GTAONode.js +2 -2
- package/examples/jsm/tsl/display/GaussianBlurNode.js +11 -2
- package/examples/jsm/tsl/display/GodraysNode.js +624 -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 +3 -3
- package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +2 -2
- package/examples/jsm/tsl/display/PixelationPassNode.js +5 -5
- package/examples/jsm/tsl/display/RGBShiftNode.js +2 -2
- 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 +2 -2
- package/examples/jsm/tsl/display/SSGINode.js +2 -2
- package/examples/jsm/tsl/display/SSRNode.js +7 -7
- package/examples/jsm/tsl/display/SSSNode.js +2 -2
- package/examples/jsm/tsl/display/Shape.js +29 -0
- package/examples/jsm/tsl/display/SobelOperatorNode.js +2 -2
- package/examples/jsm/tsl/display/StereoPassNode.js +1 -2
- package/examples/jsm/tsl/display/TRAANode.js +9 -12
- package/examples/jsm/tsl/display/TransitionNode.js +1 -1
- package/examples/jsm/tsl/display/depthAwareBlend.js +80 -0
- package/examples/jsm/tsl/math/Bayer.js +40 -1
- package/examples/jsm/utils/LDrawUtils.js +1 -1
- package/package.json +11 -19
- package/src/Three.Core.js +1 -1
- package/src/Three.TSL.js +5 -9
- package/src/Three.WebGPU.Nodes.js +2 -0
- package/src/Three.WebGPU.js +3 -0
- package/src/Three.js +1 -0
- package/src/animation/AnimationAction.js +1 -1
- package/src/animation/AnimationClip.js +1 -1
- package/src/animation/AnimationMixer.js +6 -0
- package/src/animation/KeyframeTrack.js +46 -7
- package/src/animation/PropertyMixer.js +4 -4
- package/src/audio/Audio.js +1 -1
- package/src/audio/AudioListener.js +5 -3
- package/src/cameras/Camera.js +32 -2
- package/src/cameras/CubeCamera.js +20 -0
- package/src/constants.js +30 -1
- package/src/core/Clock.js +7 -0
- package/src/core/Object3D.js +56 -4
- package/src/core/RenderTarget.js +3 -4
- package/src/extras/PMREMGenerator.js +4 -8
- package/src/geometries/TorusGeometry.js +8 -3
- package/src/helpers/CameraHelper.js +3 -0
- package/src/helpers/DirectionalLightHelper.js +4 -1
- package/src/helpers/HemisphereLightHelper.js +3 -0
- package/src/helpers/PointLightHelper.js +0 -24
- package/src/helpers/SpotLightHelper.js +3 -0
- package/src/lights/LightShadow.js +15 -3
- package/src/lights/webgpu/IESSpotLight.js +2 -1
- package/src/loaders/Cache.js +28 -0
- package/src/loaders/FileLoader.js +1 -1
- package/src/loaders/ImageBitmapLoader.js +8 -3
- package/src/loaders/Loader.js +6 -0
- package/src/loaders/ObjectLoader.js +18 -1
- package/src/materials/MeshLambertMaterial.js +9 -0
- package/src/materials/MeshPhongMaterial.js +9 -0
- package/src/materials/nodes/Line2NodeMaterial.js +5 -5
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +2 -0
- package/src/materials/nodes/NodeMaterial.js +15 -24
- package/src/materials/nodes/manager/NodeMaterialObserver.js +9 -3
- package/src/math/Line3.js +3 -5
- package/src/math/MathUtils.js +10 -10
- package/src/math/Matrix4.js +35 -26
- package/src/math/Quaternion.js +3 -29
- package/src/math/Vector3.js +3 -3
- package/src/math/interpolants/BezierInterpolant.js +108 -0
- package/src/nodes/Nodes.js +87 -68
- package/src/nodes/TSL.js +2 -5
- package/src/nodes/accessors/Arrays.js +1 -1
- package/src/nodes/accessors/Bitangent.js +5 -5
- package/src/nodes/accessors/BufferAttributeNode.js +1 -1
- package/src/nodes/accessors/Camera.js +149 -28
- package/src/nodes/accessors/InstanceNode.js +105 -40
- package/src/nodes/accessors/Normal.js +9 -9
- package/src/nodes/accessors/Position.js +34 -2
- package/src/nodes/accessors/SceneProperties.js +53 -0
- package/src/nodes/accessors/SkinningNode.js +12 -24
- package/src/nodes/accessors/StorageBufferNode.js +0 -19
- package/src/nodes/accessors/StorageTextureNode.js +37 -1
- package/src/nodes/accessors/Tangent.js +3 -3
- package/src/nodes/accessors/Texture3DNode.js +6 -34
- package/src/nodes/accessors/TextureNode.js +58 -22
- package/src/nodes/accessors/UniformArrayNode.js +2 -0
- package/src/nodes/core/MRTNode.js +48 -2
- package/src/nodes/core/Node.js +29 -3
- package/src/nodes/core/NodeBuilder.js +115 -40
- package/src/nodes/core/NodeError.js +28 -0
- package/src/nodes/core/NodeUtils.js +5 -3
- package/src/nodes/core/OutputStructNode.js +12 -10
- package/src/nodes/core/ParameterNode.js +2 -1
- package/src/nodes/core/StackNode.js +9 -8
- package/src/nodes/core/StackTrace.js +139 -0
- package/src/nodes/core/StructNode.js +15 -0
- package/src/nodes/core/SubBuildNode.js +1 -1
- package/src/nodes/core/UniformNode.js +2 -1
- package/src/nodes/core/VarNode.js +1 -1
- package/src/nodes/core/VaryingNode.js +1 -18
- package/src/nodes/display/BlendModes.js +0 -64
- package/src/nodes/display/ColorAdjustment.js +17 -0
- package/src/nodes/display/ColorSpaceNode.js +3 -3
- package/src/nodes/display/NormalMapNode.js +2 -2
- package/src/nodes/display/PassNode.js +21 -2
- package/src/nodes/display/RenderOutputNode.js +3 -3
- package/src/nodes/display/ScreenNode.js +2 -1
- 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/ViewportTextureNode.js +21 -4
- package/src/nodes/fog/Fog.js +18 -35
- package/src/nodes/functions/PhysicalLightingModel.js +25 -3
- package/src/nodes/geometry/RangeNode.js +4 -2
- package/src/nodes/gpgpu/ComputeNode.js +5 -4
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +2 -1
- package/src/nodes/lighting/EnvironmentNode.js +28 -3
- package/src/nodes/lighting/PointShadowNode.js +24 -12
- package/src/nodes/lighting/ShadowFilterNode.js +15 -43
- package/src/nodes/lighting/ShadowNode.js +54 -32
- package/src/nodes/math/ConditionalNode.js +2 -2
- package/src/nodes/math/MathNode.js +3 -40
- package/src/nodes/math/OperatorNode.js +2 -1
- package/src/nodes/pmrem/PMREMUtils.js +9 -15
- package/src/nodes/tsl/TSLCore.js +13 -10
- package/src/nodes/utils/DebugNode.js +11 -11
- package/src/nodes/utils/JoinNode.js +2 -2
- package/src/nodes/utils/LoopNode.js +1 -1
- package/src/nodes/utils/MemberNode.js +1 -1
- package/src/nodes/utils/RTTNode.js +1 -1
- package/src/nodes/utils/ReflectorNode.js +2 -3
- package/src/nodes/utils/SpriteSheetUV.js +35 -0
- package/src/nodes/utils/UVUtils.js +4 -2
- package/src/objects/BatchedMesh.js +22 -12
- package/src/objects/InstancedMesh.js +11 -0
- package/src/renderers/WebGLRenderer.js +34 -60
- package/src/renderers/common/Backend.js +21 -0
- package/src/renderers/common/Background.js +7 -4
- package/src/renderers/common/BindGroup.js +1 -9
- package/src/renderers/common/Bindings.js +20 -5
- package/src/renderers/common/BlendMode.js +143 -0
- package/src/renderers/common/BundleGroup.js +1 -1
- package/src/renderers/common/CubeRenderTarget.js +50 -6
- package/src/renderers/common/Geometries.js +17 -3
- package/src/renderers/common/Lighting.js +5 -21
- package/src/renderers/common/Pipelines.js +4 -4
- package/src/renderers/common/PostProcessing.js +8 -206
- package/src/renderers/common/RenderBundles.js +2 -1
- package/src/renderers/common/RenderContext.js +16 -0
- package/src/renderers/common/RenderContexts.js +33 -56
- package/src/renderers/common/RenderLists.js +2 -1
- package/src/renderers/common/RenderObject.js +2 -3
- package/src/renderers/common/RenderObjectPipeline.js +40 -0
- package/src/renderers/common/RenderObjects.js +18 -2
- package/src/renderers/common/RenderPipeline.js +203 -17
- package/src/renderers/common/Renderer.js +207 -40
- package/src/renderers/common/Sampler.js +4 -4
- package/src/renderers/common/StorageBuffer.js +13 -1
- package/src/renderers/common/Textures.js +16 -0
- package/src/renderers/common/TimestampQueryPool.js +5 -3
- package/src/renderers/common/Uniform.js +8 -0
- package/src/renderers/common/UniformsGroup.js +60 -0
- package/src/renderers/common/XRManager.js +2 -2
- package/src/renderers/common/nodes/NodeBuilderState.js +1 -1
- package/src/renderers/common/nodes/{Nodes.js → NodeManager.js} +18 -6
- package/src/renderers/common/nodes/NodeStorageBuffer.js +13 -2
- 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/envmap_fragment.glsl.js +7 -11
- 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_physical_pars_fragment.glsl.js +23 -1
- package/src/renderers/shaders/ShaderChunk/packing.glsl.js +20 -4
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +55 -24
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +1 -0
- package/src/renderers/shaders/ShaderLib.js +4 -2
- package/src/renderers/shaders/UniformsLib.js +0 -3
- package/src/renderers/webgl/WebGLBackground.js +2 -2
- package/src/renderers/webgl/WebGLBindingStates.js +99 -27
- package/src/renderers/webgl/WebGLEnvironments.js +228 -0
- package/src/renderers/webgl/WebGLGeometries.js +10 -7
- package/src/renderers/webgl/WebGLMaterials.js +12 -0
- package/src/renderers/webgl/WebGLObjects.js +3 -1
- package/src/renderers/webgl/WebGLProgram.js +2 -2
- package/src/renderers/webgl/WebGLPrograms.js +10 -4
- package/src/renderers/webgl/WebGLRenderLists.js +15 -0
- package/src/renderers/webgl/WebGLShadowMap.js +5 -4
- package/src/renderers/webgl/WebGLState.js +12 -17
- package/src/renderers/webgl-fallback/WebGLBackend.js +71 -7
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +98 -29
- package/src/renderers/webgl-fallback/utils/WebGLState.js +168 -7
- package/src/renderers/webgpu/WebGPUBackend.js +58 -9
- package/src/renderers/webgpu/WebGPURenderer.js +1 -0
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +257 -45
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +8 -19
- package/src/renderers/webgpu/utils/WebGPUConstants.js +1 -1
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +56 -31
- package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +152 -200
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +25 -25
- package/src/renderers/webgpu/utils/WebGPUUtils.js +10 -6
- package/src/renderers/webxr/WebXRManager.js +2 -2
- package/src/textures/Texture.js +2 -2
- package/src/utils.js +246 -3
- package/examples/jsm/materials/MeshGouraudMaterial.js +0 -433
- package/examples/jsm/materials/MeshPostProcessingMaterial.js +0 -167
- package/examples/jsm/shaders/GodRaysShader.js +0 -333
- package/src/nodes/accessors/SceneNode.js +0 -145
- 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/utils/SpriteSheetUVNode.js +0 -90
- package/src/renderers/webgl/WebGLCubeMaps.js +0 -99
- package/src/renderers/webgl/WebGLCubeUVMaps.js +0 -134
|
@@ -80,13 +80,13 @@ class ViewportTextureNode extends TextureNode {
|
|
|
80
80
|
this.isOutputTextureNode = true;
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
|
-
* The `updateBeforeType` is set to `NodeUpdateType.
|
|
84
|
-
*
|
|
83
|
+
* The `updateBeforeType` is set to `NodeUpdateType.RENDER` since the node should extract
|
|
84
|
+
* the current contents of the bound framebuffer for each render call.
|
|
85
85
|
*
|
|
86
86
|
* @type {string}
|
|
87
|
-
* @default '
|
|
87
|
+
* @default 'render'
|
|
88
88
|
*/
|
|
89
|
-
this.updateBeforeType = NodeUpdateType.
|
|
89
|
+
this.updateBeforeType = NodeUpdateType.RENDER;
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
92
|
* The framebuffer texture for the current renderer context.
|
|
@@ -226,3 +226,20 @@ export const viewportTexture = /*@__PURE__*/ nodeProxy( ViewportTextureNode ).se
|
|
|
226
226
|
* @returns {ViewportTextureNode}
|
|
227
227
|
*/
|
|
228
228
|
export const viewportMipTexture = /*@__PURE__*/ nodeProxy( ViewportTextureNode, null, null, { generateMipmaps: true } ).setParameterLength( 0, 3 );
|
|
229
|
+
|
|
230
|
+
// Singleton instances for common usage
|
|
231
|
+
const _singletonOpaqueViewportTextureNode = /*@__PURE__*/ viewportMipTexture();
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* TSL function for creating a viewport texture node with enabled mipmap generation.
|
|
235
|
+
* The texture should only contain the opaque rendering objects.
|
|
236
|
+
*
|
|
237
|
+
* This should be used just in transparent or transmissive materials.
|
|
238
|
+
*
|
|
239
|
+
* @tsl
|
|
240
|
+
* @function
|
|
241
|
+
* @param {?Node} [uv=screenUV] - The uv node.
|
|
242
|
+
* @param {?Node} [level=null] - The level node.
|
|
243
|
+
* @returns {ViewportTextureNode}
|
|
244
|
+
*/
|
|
245
|
+
export const viewportOpaqueMipTexture = ( uv = screenUV, level = null ) => _singletonOpaqueViewportTextureNode.sample( uv, level ); // TODO: Use once() when sample() supports it
|
package/src/nodes/fog/Fog.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { positionView } from '../accessors/Position.js';
|
|
1
|
+
import { positionView, positionWorld } from '../accessors/Position.js';
|
|
2
2
|
import { smoothstep } from '../math/MathNode.js';
|
|
3
3
|
import { Fn, output, vec4 } from '../tsl/TSLBase.js';
|
|
4
|
-
import { warn } from '../../utils.js';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Returns a node that represents the `z` coordinate in view space
|
|
@@ -64,51 +63,35 @@ export const densityFogFactor = Fn( ( [ density ], builder ) => {
|
|
|
64
63
|
} );
|
|
65
64
|
|
|
66
65
|
/**
|
|
67
|
-
*
|
|
68
|
-
* Nodes of this type are assigned to `Scene.fogNode`.
|
|
66
|
+
* Constructs a new height fog factor node. This fog factor requires a Y-up coordinate system.
|
|
69
67
|
*
|
|
70
68
|
* @tsl
|
|
71
69
|
* @function
|
|
72
|
-
* @param {Node}
|
|
73
|
-
* @param {Node}
|
|
70
|
+
* @param {Node} density - Defines the fog density.
|
|
71
|
+
* @param {Node} height - The height threshold in world space. Everything below this y-coordinate is affected by fog.
|
|
74
72
|
*/
|
|
75
|
-
export const
|
|
76
|
-
|
|
77
|
-
return vec4( factor.toFloat().mix( output.rgb, color.toVec3() ), output.a );
|
|
78
|
-
|
|
79
|
-
} );
|
|
73
|
+
export const exponentialHeightFogFactor = Fn( ( [ density, height ], builder ) => {
|
|
80
74
|
|
|
81
|
-
|
|
75
|
+
const viewZ = getViewZNode( builder );
|
|
82
76
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
* @function
|
|
86
|
-
* @deprecated since r171. Use `fog( color, rangeFogFactor( near, far ) )` instead.
|
|
87
|
-
*
|
|
88
|
-
* @param {Node} color
|
|
89
|
-
* @param {Node} near
|
|
90
|
-
* @param {Node} far
|
|
91
|
-
* @returns {Function}
|
|
92
|
-
*/
|
|
93
|
-
export function rangeFog( color, near, far ) { // @deprecated, r171
|
|
77
|
+
const distance = height.sub( positionWorld.y ).max( 0 ).toConst();
|
|
78
|
+
const m = distance.mul( viewZ ).toConst();
|
|
94
79
|
|
|
95
|
-
|
|
96
|
-
return fog( color, rangeFogFactor( near, far ) );
|
|
80
|
+
return density.mul( density, m, m ).negate().exp().oneMinus();
|
|
97
81
|
|
|
98
|
-
}
|
|
82
|
+
} );
|
|
99
83
|
|
|
100
84
|
/**
|
|
85
|
+
* This class can be used to configure a fog for the scene.
|
|
86
|
+
* Nodes of this type are assigned to `Scene.fogNode`.
|
|
87
|
+
*
|
|
101
88
|
* @tsl
|
|
102
89
|
* @function
|
|
103
|
-
* @
|
|
104
|
-
*
|
|
105
|
-
* @param {Node} color
|
|
106
|
-
* @param {Node} density
|
|
107
|
-
* @returns {Function}
|
|
90
|
+
* @param {Node} color - Defines the color of the fog.
|
|
91
|
+
* @param {Node} factor - Defines how the fog is factored in the scene.
|
|
108
92
|
*/
|
|
109
|
-
export
|
|
93
|
+
export const fog = Fn( ( [ color, factor ] ) => {
|
|
110
94
|
|
|
111
|
-
|
|
112
|
-
return fog( color, densityFogFactor( density ) );
|
|
95
|
+
return vec4( factor.toFloat().mix( output.rgb, color.toVec3() ), output.a );
|
|
113
96
|
|
|
114
|
-
}
|
|
97
|
+
} );
|
|
@@ -17,7 +17,7 @@ import { div } from '../math/OperatorNode.js';
|
|
|
17
17
|
import { cameraPosition, cameraProjectionMatrix, cameraViewMatrix } from '../accessors/Camera.js';
|
|
18
18
|
import { modelWorldMatrix } from '../accessors/ModelNode.js';
|
|
19
19
|
import { screenSize } from '../display/ScreenNode.js';
|
|
20
|
-
import { viewportMipTexture } from '../display/ViewportTextureNode.js';
|
|
20
|
+
import { viewportMipTexture, viewportOpaqueMipTexture } from '../display/ViewportTextureNode.js';
|
|
21
21
|
import { textureBicubicLevel } from '../accessors/TextureBicubic.js';
|
|
22
22
|
import { Loop } from '../utils/LoopNode.js';
|
|
23
23
|
import { BackSide } from '../../constants.js';
|
|
@@ -69,7 +69,7 @@ const applyIorToRoughness = /*@__PURE__*/ Fn( ( [ roughness, ior ] ) => {
|
|
|
69
69
|
} );
|
|
70
70
|
|
|
71
71
|
const viewportBackSideTexture = /*@__PURE__*/ viewportMipTexture();
|
|
72
|
-
const viewportFrontSideTexture = /*@__PURE__*/
|
|
72
|
+
const viewportFrontSideTexture = /*@__PURE__*/ viewportOpaqueMipTexture();
|
|
73
73
|
|
|
74
74
|
const getTransmissionSample = /*@__PURE__*/ Fn( ( [ fragCoord, roughness, ior ], { material } ) => {
|
|
75
75
|
|
|
@@ -658,12 +658,34 @@ class PhysicalLightingModel extends LightingModel {
|
|
|
658
658
|
|
|
659
659
|
// LTC Fresnel Approximation by Stephen Hill
|
|
660
660
|
// http://blog.selfshadow.com/publications/s2016-advances/s2016_ltc_fresnel.pdf
|
|
661
|
-
const fresnel = specularColorBlended.mul( t2.x ).add(
|
|
661
|
+
const fresnel = specularColorBlended.mul( t2.x ).add( specularF90.sub( specularColorBlended ).mul( t2.y ) ).toVar();
|
|
662
662
|
|
|
663
663
|
reflectedLight.directSpecular.addAssign( lightColor.mul( fresnel ).mul( LTC_Evaluate( { N, V, P, mInv, p0, p1, p2, p3 } ) ) );
|
|
664
664
|
|
|
665
665
|
reflectedLight.directDiffuse.addAssign( lightColor.mul( diffuseContribution ).mul( LTC_Evaluate( { N, V, P, mInv: mat3( 1, 0, 0, 0, 1, 0, 0, 0, 1 ), p0, p1, p2, p3 } ) ) );
|
|
666
666
|
|
|
667
|
+
if ( this.clearcoat === true ) {
|
|
668
|
+
|
|
669
|
+
const Ncc = clearcoatNormalView;
|
|
670
|
+
|
|
671
|
+
const uvClearcoat = LTC_Uv( { N: Ncc, V, roughness: clearcoatRoughness } );
|
|
672
|
+
|
|
673
|
+
const t1Clearcoat = ltc_1.sample( uvClearcoat );
|
|
674
|
+
const t2Clearcoat = ltc_2.sample( uvClearcoat );
|
|
675
|
+
|
|
676
|
+
const mInvClearcoat = mat3(
|
|
677
|
+
vec3( t1Clearcoat.x, 0, t1Clearcoat.y ),
|
|
678
|
+
vec3( 0, 1, 0 ),
|
|
679
|
+
vec3( t1Clearcoat.z, 0, t1Clearcoat.w )
|
|
680
|
+
);
|
|
681
|
+
|
|
682
|
+
// LTC Fresnel Approximation for clearcoat
|
|
683
|
+
const fresnelClearcoat = clearcoatF0.mul( t2Clearcoat.x ).add( clearcoatF90.sub( clearcoatF0 ).mul( t2Clearcoat.y ) );
|
|
684
|
+
|
|
685
|
+
this.clearcoatSpecularDirect.addAssign( lightColor.mul( fresnelClearcoat ).mul( LTC_Evaluate( { N: Ncc, V, P, mInv: mInvClearcoat, p0, p1, p2, p3 } ) ) );
|
|
686
|
+
|
|
687
|
+
}
|
|
688
|
+
|
|
667
689
|
}
|
|
668
690
|
|
|
669
691
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Node from '../core/Node.js';
|
|
2
|
+
import NodeError from '../core/NodeError.js';
|
|
2
3
|
import { getValueType } from '../core/NodeUtils.js';
|
|
3
4
|
import { buffer } from '../accessors/BufferNode.js';
|
|
4
5
|
import { instancedBufferAttribute } from '../accessors/BufferAttributeNode.js';
|
|
@@ -111,7 +112,7 @@ class RangeNode extends Node {
|
|
|
111
112
|
|
|
112
113
|
if ( output === null ) {
|
|
113
114
|
|
|
114
|
-
throw new
|
|
115
|
+
throw new NodeError( 'THREE.TSL: No "ConstNode" found in node graph.', this.stackTrace );
|
|
115
116
|
|
|
116
117
|
}
|
|
117
118
|
|
|
@@ -167,8 +168,9 @@ class RangeNode extends Node {
|
|
|
167
168
|
}
|
|
168
169
|
|
|
169
170
|
const nodeType = this.getNodeType( builder );
|
|
171
|
+
const uniformBufferSize = object.count * 4 * 4; // count * 4 components * 4 bytes (float)
|
|
170
172
|
|
|
171
|
-
if (
|
|
173
|
+
if ( uniformBufferSize <= builder.getUniformBufferLimit() ) {
|
|
172
174
|
|
|
173
175
|
output = buffer( array, 'vec4', object.count ).element( instanceIndex ).convert( nodeType );
|
|
174
176
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Node from '../core/Node.js';
|
|
2
|
+
import StackTrace from '../core/StackTrace.js';
|
|
2
3
|
import { NodeUpdateType } from '../core/constants.js';
|
|
3
4
|
import { addMethodChaining, nodeObject } from '../tsl/TSLCore.js';
|
|
4
5
|
import { warn, error } from '../../utils.js';
|
|
@@ -148,7 +149,7 @@ class ComputeNode extends Node {
|
|
|
148
149
|
*/
|
|
149
150
|
label( name ) {
|
|
150
151
|
|
|
151
|
-
warn( 'TSL: "label()" has been deprecated. Use "setName()" instead.' ); // @deprecated r179
|
|
152
|
+
warn( 'TSL: "label()" has been deprecated. Use "setName()" instead.', new StackTrace() ); // @deprecated r179
|
|
152
153
|
|
|
153
154
|
return this.setName( name );
|
|
154
155
|
|
|
@@ -242,7 +243,7 @@ export const computeKernel = ( node, workgroupSize = [ 64 ] ) => {
|
|
|
242
243
|
|
|
243
244
|
if ( workgroupSize.length === 0 || workgroupSize.length > 3 ) {
|
|
244
245
|
|
|
245
|
-
error( 'TSL: compute() workgroupSize must have 1, 2, or 3 elements' );
|
|
246
|
+
error( 'TSL: compute() workgroupSize must have 1, 2, or 3 elements', new StackTrace() );
|
|
246
247
|
|
|
247
248
|
}
|
|
248
249
|
|
|
@@ -252,7 +253,7 @@ export const computeKernel = ( node, workgroupSize = [ 64 ] ) => {
|
|
|
252
253
|
|
|
253
254
|
if ( typeof val !== 'number' || val <= 0 || ! Number.isInteger( val ) ) {
|
|
254
255
|
|
|
255
|
-
error( `TSL: compute() workgroupSize element at index [ ${ i } ] must be a positive integer
|
|
256
|
+
error( `TSL: compute() workgroupSize element at index [ ${ i } ] must be a positive integer`, new StackTrace() );
|
|
256
257
|
|
|
257
258
|
}
|
|
258
259
|
|
|
@@ -264,7 +265,7 @@ export const computeKernel = ( node, workgroupSize = [ 64 ] ) => {
|
|
|
264
265
|
|
|
265
266
|
//
|
|
266
267
|
|
|
267
|
-
return
|
|
268
|
+
return new ComputeNode( nodeObject( node ), workgroupSize );
|
|
268
269
|
|
|
269
270
|
};
|
|
270
271
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import ArrayElementNode from '../utils/ArrayElementNode.js';
|
|
2
2
|
import Node from '../core/Node.js';
|
|
3
3
|
import { warn } from '../../utils.js';
|
|
4
|
+
import StackTrace from '../core/StackTrace.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Represents an element of a 'workgroup' scoped buffer.
|
|
@@ -149,7 +150,7 @@ class WorkgroupInfoNode extends Node {
|
|
|
149
150
|
*/
|
|
150
151
|
label( name ) {
|
|
151
152
|
|
|
152
|
-
warn( 'TSL: "label()" has been deprecated. Use "setName()" instead.' ); // @deprecated r179
|
|
153
|
+
warn( 'TSL: "label()" has been deprecated. Use "setName()" instead.', new StackTrace() ); // @deprecated r179
|
|
153
154
|
|
|
154
155
|
return this.setName( name );
|
|
155
156
|
|
|
@@ -9,7 +9,7 @@ import { bentNormalView } from '../accessors/AccessorsUtils.js';
|
|
|
9
9
|
import { pmremTexture } from '../pmrem/PMREMNode.js';
|
|
10
10
|
import { materialEnvIntensity } from '../accessors/MaterialProperties.js';
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const _rendererCache = new WeakMap();
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Represents a physical model for Image-based lighting (IBL). The environment
|
|
@@ -55,13 +55,15 @@ class EnvironmentNode extends LightingNode {
|
|
|
55
55
|
|
|
56
56
|
const value = ( envNode.isTextureNode ) ? envNode.value : material[ envNode.property ];
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
const cache = this._getPMREMNodeCache( builder.renderer );
|
|
59
|
+
|
|
60
|
+
let cacheEnvNode = cache.get( value );
|
|
59
61
|
|
|
60
62
|
if ( cacheEnvNode === undefined ) {
|
|
61
63
|
|
|
62
64
|
cacheEnvNode = pmremTexture( value );
|
|
63
65
|
|
|
64
|
-
|
|
66
|
+
cache.set( value, cacheEnvNode );
|
|
65
67
|
|
|
66
68
|
}
|
|
67
69
|
|
|
@@ -101,6 +103,29 @@ class EnvironmentNode extends LightingNode {
|
|
|
101
103
|
|
|
102
104
|
}
|
|
103
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Returns the PMREM node cache of the current renderer.
|
|
108
|
+
*
|
|
109
|
+
* @private
|
|
110
|
+
* @param {Renderer} renderer - The current renderer.
|
|
111
|
+
* @return {WeakMap} The node cache.
|
|
112
|
+
*/
|
|
113
|
+
_getPMREMNodeCache( renderer ) {
|
|
114
|
+
|
|
115
|
+
let pmremCache = _rendererCache.get( renderer );
|
|
116
|
+
|
|
117
|
+
if ( pmremCache === undefined ) {
|
|
118
|
+
|
|
119
|
+
pmremCache = new WeakMap();
|
|
120
|
+
|
|
121
|
+
_rendererCache.set( renderer, pmremCache );
|
|
122
|
+
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return pmremCache;
|
|
126
|
+
|
|
127
|
+
}
|
|
128
|
+
|
|
104
129
|
}
|
|
105
130
|
|
|
106
131
|
export default EnvironmentNode;
|
|
@@ -7,11 +7,12 @@ import { renderGroup } from '../core/UniformGroupNode.js';
|
|
|
7
7
|
import { Matrix4 } from '../../math/Matrix4.js';
|
|
8
8
|
import { Vector3 } from '../../math/Vector3.js';
|
|
9
9
|
import { Color } from '../../math/Color.js';
|
|
10
|
-
import { BasicShadowMap,
|
|
10
|
+
import { BasicShadowMap, GreaterEqualCompare, LessEqualCompare, WebGPUCoordinateSystem } from '../../constants.js';
|
|
11
11
|
import { CubeDepthTexture } from '../../textures/CubeDepthTexture.js';
|
|
12
12
|
import { screenCoordinate } from '../display/ScreenNode.js';
|
|
13
13
|
import { interleavedGradientNoise, vogelDiskSample } from '../utils/PostProcessingUtils.js';
|
|
14
14
|
import { abs, normalize, cross } from '../math/MathNode.js';
|
|
15
|
+
import { viewZToPerspectiveDepth, viewZToReversedPerspectiveDepth } from '../display/ViewportDepthNode.js';
|
|
15
16
|
|
|
16
17
|
const _clearColor = /*@__PURE__*/ new Color();
|
|
17
18
|
const _projScreenMatrix = /*@__PURE__*/ new Matrix4();
|
|
@@ -93,27 +94,38 @@ export const PointShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, bd3D, dp, s
|
|
|
93
94
|
|
|
94
95
|
} );
|
|
95
96
|
|
|
96
|
-
const pointShadowFilter = /*@__PURE__*/ Fn( ( { filterFn, depthTexture, shadowCoord, shadow } ) => {
|
|
97
|
+
const pointShadowFilter = /*@__PURE__*/ Fn( ( { filterFn, depthTexture, shadowCoord, shadow }, builder ) => {
|
|
97
98
|
|
|
98
99
|
// for point lights, the uniform @vShadowCoord is re-purposed to hold
|
|
99
100
|
// the vector from the light to the world-space position of the fragment.
|
|
100
|
-
const
|
|
101
|
-
const
|
|
101
|
+
const shadowPosition = shadowCoord.xyz.toConst();
|
|
102
|
+
const shadowPositionAbs = shadowPosition.abs().toConst();
|
|
103
|
+
const viewZ = shadowPositionAbs.x.max( shadowPositionAbs.y ).max( shadowPositionAbs.z );
|
|
102
104
|
|
|
103
|
-
const
|
|
104
|
-
const
|
|
105
|
+
const shadowCameraNear = uniform( 'float' ).setGroup( renderGroup ).onRenderUpdate( () => shadow.camera.near );
|
|
106
|
+
const shadowCameraFar = uniform( 'float' ).setGroup( renderGroup ).onRenderUpdate( () => shadow.camera.far );
|
|
105
107
|
const bias = reference( 'bias', 'float', shadow ).setGroup( renderGroup );
|
|
106
108
|
|
|
107
109
|
const result = float( 1.0 ).toVar();
|
|
108
110
|
|
|
109
|
-
If(
|
|
111
|
+
If( viewZ.sub( shadowCameraFar ).lessThanEqual( 0.0 ).and( viewZ.sub( shadowCameraNear ).greaterThanEqual( 0.0 ) ), () => {
|
|
110
112
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
113
|
+
let dp;
|
|
114
|
+
|
|
115
|
+
if ( builder.renderer.reversedDepthBuffer ) {
|
|
116
|
+
|
|
117
|
+
dp = viewZToReversedPerspectiveDepth( viewZ.negate(), shadowCameraNear, shadowCameraFar );
|
|
118
|
+
dp.subAssign( bias );
|
|
119
|
+
|
|
120
|
+
} else {
|
|
121
|
+
|
|
122
|
+
dp = viewZToPerspectiveDepth( viewZ.negate(), shadowCameraNear, shadowCameraFar );
|
|
123
|
+
dp.addAssign( bias );
|
|
124
|
+
|
|
125
|
+
}
|
|
114
126
|
|
|
115
127
|
// bd3D = base direction 3D (direction from light to fragment)
|
|
116
|
-
const bd3D =
|
|
128
|
+
const bd3D = shadowPosition.normalize();
|
|
117
129
|
|
|
118
130
|
// percentage-closer filtering using cube texture sampling
|
|
119
131
|
result.assign( filterFn( { depthTexture, bd3D, dp, shadow } ) );
|
|
@@ -205,7 +217,7 @@ class PointShadowNode extends ShadowNode {
|
|
|
205
217
|
|
|
206
218
|
const depthTexture = new CubeDepthTexture( shadow.mapSize.width );
|
|
207
219
|
depthTexture.name = 'PointShadowDepthTexture';
|
|
208
|
-
depthTexture.compareFunction =
|
|
220
|
+
depthTexture.compareFunction = builder.renderer.reversedDepthBuffer ? GreaterEqualCompare : LessEqualCompare;
|
|
209
221
|
|
|
210
222
|
const shadowMap = builder.createCubeRenderTarget( shadow.mapSize.width );
|
|
211
223
|
shadowMap.texture.name = 'PointShadowMap';
|
|
@@ -5,10 +5,9 @@ import { mix, fract, step, max, clamp } from '../math/MathNode.js';
|
|
|
5
5
|
import { add, sub } from '../math/OperatorNode.js';
|
|
6
6
|
import { renderGroup } from '../core/UniformGroupNode.js';
|
|
7
7
|
import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
|
|
8
|
-
import { objectPosition } from '../accessors/Object3DNode.js';
|
|
9
|
-
import { positionWorld } from '../accessors/Position.js';
|
|
10
8
|
import { screenCoordinate } from '../display/ScreenNode.js';
|
|
11
9
|
import { interleavedGradientNoise, vogelDiskSample } from '../utils/PostProcessingUtils.js';
|
|
10
|
+
import { NoBlending } from '../../constants.js';
|
|
12
11
|
|
|
13
12
|
const shadowMaterialLib = /*@__PURE__*/ new WeakMap();
|
|
14
13
|
|
|
@@ -174,7 +173,7 @@ export const PCFSoftShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, shadowCoo
|
|
|
174
173
|
* @param {Node<vec3>} inputs.shadowCoord - The shadow coordinates.
|
|
175
174
|
* @return {Node<float>} The filtering result.
|
|
176
175
|
*/
|
|
177
|
-
export const VSMShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, shadowCoord, depthLayer } ) => {
|
|
176
|
+
export const VSMShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, shadowCoord, depthLayer }, builder ) => {
|
|
178
177
|
|
|
179
178
|
let distribution = texture( depthTexture ).sample( shadowCoord.xy );
|
|
180
179
|
|
|
@@ -189,53 +188,28 @@ export const VSMShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, shadowCoord,
|
|
|
189
188
|
const mean = distribution.x;
|
|
190
189
|
const variance = max( 0.0000001, distribution.y.mul( distribution.y ) );
|
|
191
190
|
|
|
192
|
-
const hardShadow = step( shadowCoord.z, mean );
|
|
191
|
+
const hardShadow = ( builder.renderer.reversedDepthBuffer ) ? step( mean, shadowCoord.z ) : step( shadowCoord.z, mean );
|
|
193
192
|
|
|
194
|
-
|
|
195
|
-
If( hardShadow.equal( 1.0 ), () => {
|
|
193
|
+
const output = float( 1 ).toVar(); // default, fully lit
|
|
196
194
|
|
|
197
|
-
|
|
195
|
+
If( hardShadow.notEqual( 1.0 ), () => {
|
|
198
196
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
// Distance from mean
|
|
202
|
-
const d = shadowCoord.z.sub( mean );
|
|
203
|
-
|
|
204
|
-
// Chebyshev's inequality for upper bound on probability
|
|
205
|
-
let p_max = variance.div( variance.add( d.mul( d ) ) );
|
|
206
|
-
|
|
207
|
-
// Reduce light bleeding by remapping [amount, 1] to [0, 1]
|
|
208
|
-
p_max = clamp( sub( p_max, 0.3 ).div( 0.65 ) );
|
|
197
|
+
// Distance from mean
|
|
198
|
+
const d = shadowCoord.z.sub( mean );
|
|
209
199
|
|
|
210
|
-
|
|
200
|
+
// Chebyshev's inequality for upper bound on probability
|
|
201
|
+
let p_max = variance.div( variance.add( d.mul( d ) ) );
|
|
211
202
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
//
|
|
203
|
+
// Reduce light bleeding by remapping [amount, 1] to [0, 1]
|
|
204
|
+
p_max = clamp( sub( p_max, 0.3 ).div( 0.65 ) );
|
|
215
205
|
|
|
216
|
-
|
|
206
|
+
output.assign( max( hardShadow, p_max ) );
|
|
217
207
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
dist = dist.saturate(); // clamp to [ 0, 1 ]
|
|
221
|
-
|
|
222
|
-
return dist;
|
|
208
|
+
} );
|
|
209
|
+
return output;
|
|
223
210
|
|
|
224
211
|
} );
|
|
225
212
|
|
|
226
|
-
const linearShadowDistance = ( light ) => {
|
|
227
|
-
|
|
228
|
-
const camera = light.shadow.camera;
|
|
229
|
-
|
|
230
|
-
const nearDistance = reference( 'near', 'float', camera ).setGroup( renderGroup );
|
|
231
|
-
const farDistance = reference( 'far', 'float', camera ).setGroup( renderGroup );
|
|
232
|
-
|
|
233
|
-
const referencePosition = objectPosition( light );
|
|
234
|
-
|
|
235
|
-
return linearDistance( referencePosition, nearDistance, farDistance );
|
|
236
|
-
|
|
237
|
-
};
|
|
238
|
-
|
|
239
213
|
/**
|
|
240
214
|
* Retrieves or creates a shadow material for the given light source.
|
|
241
215
|
*
|
|
@@ -256,13 +230,11 @@ export const getShadowMaterial = ( light ) => {
|
|
|
256
230
|
|
|
257
231
|
if ( material === undefined ) {
|
|
258
232
|
|
|
259
|
-
const depthNode = light.isPointLight ? linearShadowDistance( light ) : null;
|
|
260
|
-
|
|
261
233
|
material = new NodeMaterial();
|
|
262
234
|
material.colorNode = vec4( 0, 0, 0, 1 );
|
|
263
|
-
material.depthNode = depthNode;
|
|
264
235
|
material.isShadowPassMaterial = true; // Use to avoid other overrideMaterial override material.colorNode unintentionally when using material.shadowNode
|
|
265
236
|
material.name = 'ShadowMaterial';
|
|
237
|
+
material.blending = NoBlending;
|
|
266
238
|
material.fog = false;
|
|
267
239
|
|
|
268
240
|
shadowMaterialLib.set( light, material );
|
|
@@ -11,7 +11,7 @@ import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
|
|
|
11
11
|
import QuadMesh from '../../renderers/common/QuadMesh.js';
|
|
12
12
|
import { Loop } from '../utils/LoopNode.js';
|
|
13
13
|
import { screenCoordinate } from '../display/ScreenNode.js';
|
|
14
|
-
import { HalfFloatType,
|
|
14
|
+
import { Compatibility, GreaterEqualCompare, HalfFloatType, LessEqualCompare, LinearFilter, NearestFilter, PCFShadowMap, PCFSoftShadowMap, RGFormat, VSMShadowMap } from '../../constants.js';
|
|
15
15
|
import { renderGroup } from '../core/UniformGroupNode.js';
|
|
16
16
|
import { viewZToLogarithmicDepth } from '../display/ViewportDepthNode.js';
|
|
17
17
|
import { lightShadowMatrix } from '../accessors/Lights.js';
|
|
@@ -19,7 +19,6 @@ import { resetRendererAndSceneState, restoreRendererAndSceneState } from '../../
|
|
|
19
19
|
import { getDataFromObject } from '../core/NodeUtils.js';
|
|
20
20
|
import { getShadowMaterial, disposeShadowMaterial, BasicShadowFilter, PCFShadowFilter, PCFSoftShadowFilter, VSMShadowFilter } from './ShadowFilterNode.js';
|
|
21
21
|
import ChainMap from '../../renderers/common/ChainMap.js';
|
|
22
|
-
import { warn } from '../../utils.js';
|
|
23
22
|
import { textureSize } from '../accessors/TextureSizeNode.js';
|
|
24
23
|
import { uv } from '../accessors/UV.js';
|
|
25
24
|
|
|
@@ -342,7 +341,7 @@ class ShadowNode extends ShadowBaseNode {
|
|
|
342
341
|
const { shadow } = this;
|
|
343
342
|
const { renderer } = builder;
|
|
344
343
|
|
|
345
|
-
const bias = reference( 'bias', 'float', shadow ).setGroup( renderGroup );
|
|
344
|
+
const bias = shadow.biasNode || reference( 'bias', 'float', shadow ).setGroup( renderGroup );
|
|
346
345
|
|
|
347
346
|
let shadowCoord = shadowPosition;
|
|
348
347
|
let coordZ;
|
|
@@ -353,12 +352,6 @@ class ShadowNode extends ShadowBaseNode {
|
|
|
353
352
|
|
|
354
353
|
coordZ = shadowCoord.z;
|
|
355
354
|
|
|
356
|
-
if ( renderer.coordinateSystem === WebGPUCoordinateSystem ) {
|
|
357
|
-
|
|
358
|
-
coordZ = coordZ.mul( 2 ).sub( 1 ); // WebGPU: Conversion [ 0, 1 ] to [ - 1, 1 ]
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
|
|
362
355
|
} else {
|
|
363
356
|
|
|
364
357
|
const w = shadowCoord.w;
|
|
@@ -377,7 +370,7 @@ class ShadowNode extends ShadowBaseNode {
|
|
|
377
370
|
shadowCoord = vec3(
|
|
378
371
|
shadowCoord.x,
|
|
379
372
|
shadowCoord.y.oneMinus(), // follow webgpu standards
|
|
380
|
-
coordZ.add( bias )
|
|
373
|
+
renderer.reversedDepthBuffer ? coordZ.sub( bias ) : coordZ.add( bias )
|
|
381
374
|
);
|
|
382
375
|
|
|
383
376
|
return shadowCoord;
|
|
@@ -401,7 +394,7 @@ class ShadowNode extends ShadowBaseNode {
|
|
|
401
394
|
|
|
402
395
|
const depthTexture = new DepthTexture( shadow.mapSize.width, shadow.mapSize.height );
|
|
403
396
|
depthTexture.name = 'ShadowDepthTexture';
|
|
404
|
-
depthTexture.compareFunction =
|
|
397
|
+
depthTexture.compareFunction = builder.renderer.reversedDepthBuffer ? GreaterEqualCompare : LessEqualCompare;
|
|
405
398
|
|
|
406
399
|
const shadowMap = builder.createRenderTarget( shadow.mapSize.width, shadow.mapSize.height );
|
|
407
400
|
shadowMap.texture.name = 'ShadowMap';
|
|
@@ -424,9 +417,22 @@ class ShadowNode extends ShadowBaseNode {
|
|
|
424
417
|
|
|
425
418
|
const { light, shadow } = this;
|
|
426
419
|
|
|
420
|
+
const { depthTexture, shadowMap } = this.setupRenderTarget( shadow, builder );
|
|
421
|
+
|
|
427
422
|
const shadowMapType = renderer.shadowMap.type;
|
|
423
|
+
const hasTextureCompare = renderer.hasCompatibility( Compatibility.TEXTURE_COMPARE );
|
|
428
424
|
|
|
429
|
-
|
|
425
|
+
if ( ( shadowMapType === PCFShadowMap || shadowMapType === PCFSoftShadowMap ) && hasTextureCompare ) {
|
|
426
|
+
|
|
427
|
+
depthTexture.minFilter = LinearFilter;
|
|
428
|
+
depthTexture.magFilter = LinearFilter;
|
|
429
|
+
|
|
430
|
+
} else {
|
|
431
|
+
|
|
432
|
+
depthTexture.minFilter = NearestFilter;
|
|
433
|
+
depthTexture.magFilter = NearestFilter;
|
|
434
|
+
|
|
435
|
+
}
|
|
430
436
|
|
|
431
437
|
shadow.camera.coordinateSystem = camera.coordinateSystem;
|
|
432
438
|
shadow.camera.updateProjectionMatrix();
|
|
@@ -519,24 +525,40 @@ class ShadowNode extends ShadowBaseNode {
|
|
|
519
525
|
|
|
520
526
|
let shadowColor;
|
|
521
527
|
|
|
522
|
-
if ( shadowMap.
|
|
528
|
+
if ( renderer.shadowMap.transmitted === true ) {
|
|
523
529
|
|
|
524
|
-
|
|
525
|
-
shadowColor = cubeTexture( shadowMap.texture, shadowCoord.xyz );
|
|
530
|
+
if ( shadowMap.texture.isCubeTexture ) {
|
|
526
531
|
|
|
527
|
-
|
|
532
|
+
// For cube shadow maps (point lights), use cubeTexture with vec3 coordinates
|
|
533
|
+
shadowColor = cubeTexture( shadowMap.texture, shadowCoord.xyz );
|
|
534
|
+
|
|
535
|
+
} else {
|
|
528
536
|
|
|
529
|
-
|
|
537
|
+
shadowColor = texture( shadowMap.texture, shadowCoord );
|
|
530
538
|
|
|
531
|
-
|
|
539
|
+
if ( depthTexture.isArrayTexture ) {
|
|
532
540
|
|
|
533
|
-
|
|
541
|
+
shadowColor = shadowColor.depth( this.depthLayer );
|
|
542
|
+
|
|
543
|
+
}
|
|
534
544
|
|
|
535
545
|
}
|
|
536
546
|
|
|
537
547
|
}
|
|
538
548
|
|
|
539
|
-
|
|
549
|
+
//
|
|
550
|
+
|
|
551
|
+
let shadowOutput;
|
|
552
|
+
|
|
553
|
+
if ( shadowColor ) {
|
|
554
|
+
|
|
555
|
+
shadowOutput = mix( 1, shadowNode.rgb.mix( shadowColor, 1 ), shadowIntensity.mul( shadowColor.a ) ).toVar();
|
|
556
|
+
|
|
557
|
+
} else {
|
|
558
|
+
|
|
559
|
+
shadowOutput = mix( 1, shadowNode, shadowIntensity ).toVar();
|
|
560
|
+
|
|
561
|
+
}
|
|
540
562
|
|
|
541
563
|
this.shadowMap = shadowMap;
|
|
542
564
|
this.shadow.map = shadowMap;
|
|
@@ -545,17 +567,23 @@ class ShadowNode extends ShadowBaseNode {
|
|
|
545
567
|
|
|
546
568
|
const inspectName = `${ this.light.type } Shadow [ ${ this.light.name || 'ID: ' + this.light.id } ]`;
|
|
547
569
|
|
|
548
|
-
|
|
570
|
+
if ( shadowColor ) {
|
|
549
571
|
|
|
550
|
-
|
|
572
|
+
shadowOutput.toInspector( `${ inspectName } / Color`, () => {
|
|
551
573
|
|
|
552
|
-
|
|
574
|
+
if ( this.shadowMap.texture.isCubeTexture ) {
|
|
553
575
|
|
|
554
|
-
|
|
576
|
+
return cubeTexture( this.shadowMap.texture );
|
|
555
577
|
|
|
556
|
-
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
return texture( this.shadowMap.texture );
|
|
581
|
+
|
|
582
|
+
} );
|
|
583
|
+
|
|
584
|
+
}
|
|
557
585
|
|
|
558
|
-
|
|
586
|
+
return shadowOutput.toInspector( `${ inspectName } / Depth`, () => {
|
|
559
587
|
|
|
560
588
|
// TODO: Use linear depth
|
|
561
589
|
|
|
@@ -604,12 +632,6 @@ class ShadowNode extends ShadowBaseNode {
|
|
|
604
632
|
|
|
605
633
|
}
|
|
606
634
|
|
|
607
|
-
if ( builder.material.shadowNode ) { // @deprecated, r171
|
|
608
|
-
|
|
609
|
-
warn( 'NodeMaterial: ".shadowNode" is deprecated. Use ".castShadowNode" instead.' );
|
|
610
|
-
|
|
611
|
-
}
|
|
612
|
-
|
|
613
635
|
if ( builder.material.receivedShadowNode ) {
|
|
614
636
|
|
|
615
637
|
node = builder.material.receivedShadowNode( node );
|