super-three 0.177.0 → 0.179.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/README.md +1 -1
- package/build/three.cjs +959 -231
- package/build/three.core.js +751 -170
- package/build/three.core.min.js +1 -1
- package/build/three.module.js +210 -64
- package/build/three.module.min.js +1 -1
- package/build/three.tsl.js +78 -29
- package/build/three.tsl.min.js +1 -1
- package/build/three.webgpu.js +3269 -1545
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +3093 -1545
- package/build/three.webgpu.nodes.min.js +1 -1
- package/examples/jsm/Addons.js +1 -2
- package/examples/jsm/capabilities/WebGL.js +0 -27
- package/examples/jsm/capabilities/WebGPU.js +1 -1
- package/examples/jsm/controls/ArcballControls.js +1 -1
- package/examples/jsm/controls/TransformControls.js +61 -14
- package/examples/jsm/csm/CSMShadowNode.js +4 -4
- package/examples/jsm/environments/RoomEnvironment.js +8 -3
- package/examples/jsm/exporters/USDZExporter.js +676 -299
- package/examples/jsm/geometries/RoundedBoxGeometry.js +47 -8
- package/examples/jsm/interactive/HTMLMesh.js +5 -3
- package/examples/jsm/libs/meshopt_decoder.module.js +75 -58
- package/examples/jsm/lights/LightProbeGenerator.js +14 -3
- package/examples/jsm/loaders/ColladaLoader.js +1 -1
- package/examples/jsm/loaders/EXRLoader.js +210 -22
- package/examples/jsm/loaders/FBXLoader.js +2 -2
- package/examples/jsm/loaders/MaterialXLoader.js +212 -30
- package/examples/jsm/loaders/TTFLoader.js +13 -1
- package/examples/jsm/loaders/USDLoader.js +219 -0
- package/examples/jsm/loaders/USDZLoader.js +4 -892
- package/examples/jsm/loaders/usd/USDAParser.js +741 -0
- package/examples/jsm/loaders/usd/USDCParser.js +17 -0
- package/examples/jsm/objects/LensflareMesh.js +3 -3
- package/examples/jsm/objects/SkyMesh.js +2 -2
- package/examples/jsm/physics/RapierPhysics.js +95 -16
- package/examples/jsm/postprocessing/GTAOPass.js +10 -9
- package/examples/jsm/postprocessing/OutlinePass.js +17 -17
- package/examples/jsm/postprocessing/SSAOPass.js +10 -9
- package/examples/jsm/shaders/UnpackDepthRGBAShader.js +11 -2
- package/examples/jsm/transpiler/AST.js +381 -30
- package/examples/jsm/transpiler/GLSLDecoder.js +226 -86
- package/examples/jsm/transpiler/Linker.js +327 -0
- package/examples/jsm/transpiler/TSLEncoder.js +197 -92
- package/examples/jsm/transpiler/Transpiler.js +17 -1
- package/examples/jsm/transpiler/TranspilerUtils.js +29 -0
- package/examples/jsm/transpiler/WGSLEncoder.js +788 -0
- package/examples/jsm/tsl/display/BloomNode.js +8 -7
- package/examples/jsm/tsl/display/ChromaticAberrationNode.js +206 -0
- package/examples/jsm/tsl/display/GaussianBlurNode.js +8 -10
- package/examples/jsm/tsl/display/SSAAPassNode.js +2 -2
- package/examples/jsm/tsl/display/{TRAAPassNode.js → TRAANode.js} +181 -172
- package/examples/jsm/tsl/display/hashBlur.js +3 -3
- package/examples/jsm/tsl/lighting/TiledLightsNode.js +1 -1
- package/package.json +1 -1
- package/src/Three.Core.js +1 -0
- package/src/Three.TSL.js +77 -28
- package/src/Three.WebGPU.js +2 -0
- package/src/animation/KeyframeTrack.js +1 -1
- package/src/animation/tracks/BooleanKeyframeTrack.js +1 -1
- package/src/animation/tracks/StringKeyframeTrack.js +1 -1
- package/src/cameras/Camera.js +14 -0
- package/src/cameras/OrthographicCamera.js +1 -1
- package/src/cameras/PerspectiveCamera.js +1 -1
- package/src/constants.js +3 -3
- package/src/core/BufferAttribute.js +3 -3
- package/src/core/Clock.js +2 -8
- package/src/core/GLBufferAttribute.js +13 -1
- package/src/core/Object3D.js +1 -1
- package/{examples/jsm/misc → src/core}/Timer.js +4 -42
- package/src/extras/PMREMGenerator.js +11 -0
- package/src/extras/core/Path.js +22 -22
- package/src/helpers/CameraHelper.js +41 -11
- package/src/helpers/SkeletonHelper.js +35 -6
- package/src/lights/LightShadow.js +21 -8
- package/src/lights/PointLightShadow.js +1 -1
- package/src/loaders/FileLoader.js +27 -4
- package/src/loaders/ImageBitmapLoader.js +27 -4
- package/src/loaders/ImageLoader.js +55 -8
- package/src/loaders/Loader.js +14 -0
- package/src/loaders/LoadingManager.js +23 -0
- package/src/materials/MeshBasicMaterial.js +1 -1
- package/src/materials/nodes/Line2NodeMaterial.js +0 -8
- package/src/materials/nodes/MeshBasicNodeMaterial.js +4 -3
- package/src/materials/nodes/MeshMatcapNodeMaterial.js +1 -1
- package/src/materials/nodes/MeshNormalNodeMaterial.js +2 -2
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +2 -1
- package/src/materials/nodes/MeshSSSNodeMaterial.js +2 -2
- package/src/materials/nodes/NodeMaterial.js +28 -5
- package/src/materials/nodes/PointsNodeMaterial.js +5 -0
- package/src/materials/nodes/manager/NodeMaterialObserver.js +87 -2
- package/src/math/Frustum.js +25 -9
- package/src/math/FrustumArray.js +10 -5
- package/src/math/Line3.js +129 -2
- package/src/math/Matrix4.js +48 -27
- package/src/math/Quaternion.js +1 -1
- package/src/math/Spherical.js +2 -2
- package/src/nodes/Nodes.js +2 -3
- package/src/nodes/TSL.js +5 -3
- package/src/nodes/accessors/AccessorsUtils.js +7 -8
- package/src/nodes/accessors/Bitangent.js +31 -25
- package/src/nodes/accessors/Camera.js +12 -12
- package/src/nodes/accessors/Normal.js +95 -29
- package/src/nodes/accessors/Object3DNode.js +1 -1
- package/src/nodes/accessors/Position.js +7 -7
- package/src/nodes/accessors/ReferenceNode.js +18 -3
- package/src/nodes/accessors/ReflectVector.js +3 -3
- package/src/nodes/accessors/SceneNode.js +1 -1
- package/src/nodes/accessors/StorageTextureNode.js +1 -1
- package/src/nodes/accessors/Tangent.js +25 -17
- package/src/nodes/accessors/TangentUtils.js +46 -0
- package/src/nodes/accessors/TextureBicubic.js +21 -3
- package/src/nodes/accessors/TextureNode.js +12 -0
- package/src/nodes/accessors/UniformArrayNode.js +0 -16
- package/src/nodes/core/ArrayNode.js +12 -0
- package/src/nodes/core/AssignNode.js +3 -0
- package/src/nodes/core/CacheNode.js +0 -14
- package/src/nodes/core/ContextNode.js +20 -1
- package/src/nodes/core/Node.js +15 -3
- package/src/nodes/core/NodeBuilder.js +228 -92
- package/src/nodes/core/NodeUtils.js +4 -1
- package/src/nodes/core/StackNode.js +49 -29
- package/src/nodes/core/SubBuildNode.js +89 -0
- package/src/nodes/core/UniformNode.js +63 -5
- package/src/nodes/core/VarNode.js +91 -2
- package/src/nodes/core/VaryingNode.js +6 -4
- package/src/nodes/display/BlendModes.js +2 -2
- package/src/nodes/display/FrontFacingNode.js +34 -2
- package/src/nodes/display/NormalMapNode.js +19 -50
- package/src/nodes/display/PassNode.js +157 -9
- package/src/nodes/display/ScreenNode.js +0 -26
- package/src/nodes/display/ViewportTextureNode.js +67 -7
- package/src/nodes/functions/BSDF/BRDF_GGX.js +2 -6
- package/src/nodes/functions/BSDF/BRDF_Sheen.js +4 -4
- package/src/nodes/functions/PhongLightingModel.js +3 -3
- package/src/nodes/functions/PhysicalLightingModel.js +16 -16
- package/src/nodes/functions/material/getGeometryRoughness.js +2 -2
- package/src/nodes/gpgpu/AtomicFunctionNode.js +1 -1
- package/src/nodes/gpgpu/ComputeNode.js +67 -23
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +28 -3
- package/src/nodes/lighting/EnvironmentNode.js +5 -5
- package/src/nodes/lighting/LightsNode.js +4 -4
- package/src/nodes/lighting/ProjectorLightNode.js +19 -6
- package/src/nodes/lighting/ShadowFilterNode.js +1 -1
- package/src/nodes/lighting/ShadowNode.js +2 -2
- package/src/nodes/materialx/MaterialXNodes.js +131 -2
- package/src/nodes/materialx/lib/mx_noise.js +165 -1
- package/src/nodes/math/ConditionalNode.js +1 -20
- package/src/nodes/math/MathNode.js +90 -55
- package/src/nodes/math/OperatorNode.js +22 -39
- package/src/nodes/tsl/TSLBase.js +1 -0
- package/src/nodes/tsl/TSLCore.js +114 -55
- package/src/nodes/utils/DebugNode.js +1 -1
- package/src/nodes/utils/EquirectUV.js +27 -0
- package/src/nodes/utils/EventNode.js +83 -0
- package/src/nodes/utils/LoopNode.js +0 -17
- package/src/nodes/utils/MatcapUV.js +22 -0
- package/src/nodes/utils/RTTNode.js +22 -5
- package/src/nodes/utils/ReflectorNode.js +11 -4
- package/src/nodes/utils/SampleNode.js +81 -0
- package/src/nodes/utils/TriplanarTextures.js +65 -0
- package/src/objects/BatchedMesh.js +4 -2
- package/src/renderers/WebGLRenderer.js +26 -24
- package/src/renderers/common/Background.js +2 -2
- package/src/renderers/common/Bindings.js +19 -18
- package/src/renderers/common/Color4.js +2 -2
- package/src/renderers/common/CubeRenderTarget.js +1 -1
- package/src/renderers/common/PostProcessing.js +60 -5
- package/src/renderers/common/RenderObject.js +68 -3
- package/src/renderers/common/Renderer.js +19 -16
- package/src/renderers/common/SampledTexture.js +3 -71
- package/src/renderers/common/Sampler.js +79 -0
- package/src/renderers/common/Storage3DTexture.js +100 -0
- package/src/renderers/common/StorageArrayTexture.js +84 -0
- package/src/renderers/common/StorageTexture.js +19 -0
- package/src/renderers/common/Textures.js +19 -3
- package/src/renderers/common/XRManager.js +31 -12
- package/src/renderers/common/XRRenderTarget.js +21 -4
- package/src/renderers/common/extras/PMREMGenerator.js +1 -1
- package/src/renderers/common/nodes/NodeSampledTexture.js +0 -12
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +20 -2
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +11 -2
- package/src/renderers/webgl/WebGLAttributes.js +4 -0
- package/src/renderers/webgl/WebGLCapabilities.js +2 -2
- package/src/renderers/webgl/WebGLProgram.js +12 -6
- package/src/renderers/webgl/WebGLPrograms.js +6 -4
- package/src/renderers/webgl/WebGLShadowMap.js +11 -1
- package/src/renderers/webgl/WebGLState.js +4 -4
- package/src/renderers/webgl/WebGLTextures.js +19 -7
- package/src/renderers/webgl-fallback/WebGLBackend.js +103 -72
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +3 -5
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +4 -0
- package/src/renderers/webgl-fallback/utils/WebGLState.js +4 -4
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +2 -0
- package/src/renderers/webgpu/WebGPUBackend.js +63 -16
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +64 -79
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +6 -0
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +45 -31
- package/src/renderers/webgpu/utils/WebGPUConstants.js +7 -1
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +5 -5
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +12 -65
- package/src/renderers/webgpu/utils/WebGPUUtils.js +2 -17
- package/src/renderers/webxr/WebXRDepthSensing.js +6 -10
- package/src/renderers/webxr/WebXRManager.js +68 -6
- package/src/textures/ExternalTexture.js +45 -0
- package/src/textures/FramebufferTexture.js +2 -2
- package/src/textures/Source.js +11 -1
- package/src/textures/VideoTexture.js +30 -2
- package/src/nodes/utils/EquirectUVNode.js +0 -65
- package/src/nodes/utils/MatcapUVNode.js +0 -49
- package/src/nodes/utils/TriplanarTexturesNode.js +0 -148
|
@@ -35,10 +35,18 @@ class ViewportTextureNode extends TextureNode {
|
|
|
35
35
|
*/
|
|
36
36
|
constructor( uvNode = screenUV, levelNode = null, framebufferTexture = null ) {
|
|
37
37
|
|
|
38
|
+
let defaultFramebuffer = null;
|
|
39
|
+
|
|
38
40
|
if ( framebufferTexture === null ) {
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
defaultFramebuffer = new FramebufferTexture();
|
|
43
|
+
defaultFramebuffer.minFilter = LinearMipmapLinearFilter;
|
|
44
|
+
|
|
45
|
+
framebufferTexture = defaultFramebuffer;
|
|
46
|
+
|
|
47
|
+
} else {
|
|
48
|
+
|
|
49
|
+
defaultFramebuffer = framebufferTexture;
|
|
42
50
|
|
|
43
51
|
}
|
|
44
52
|
|
|
@@ -52,6 +60,16 @@ class ViewportTextureNode extends TextureNode {
|
|
|
52
60
|
*/
|
|
53
61
|
this.generateMipmaps = false;
|
|
54
62
|
|
|
63
|
+
/**
|
|
64
|
+
* The reference framebuffer texture. This is used to store the framebuffer texture
|
|
65
|
+
* for the current render target. If the render target changes, a new framebuffer texture
|
|
66
|
+
* is created automatically.
|
|
67
|
+
*
|
|
68
|
+
* @type {FramebufferTexture}
|
|
69
|
+
* @default null
|
|
70
|
+
*/
|
|
71
|
+
this.defaultFramebuffer = defaultFramebuffer;
|
|
72
|
+
|
|
55
73
|
/**
|
|
56
74
|
* This flag can be used for type testing.
|
|
57
75
|
*
|
|
@@ -62,24 +80,64 @@ class ViewportTextureNode extends TextureNode {
|
|
|
62
80
|
this.isOutputTextureNode = true;
|
|
63
81
|
|
|
64
82
|
/**
|
|
65
|
-
* The `updateBeforeType` is set to `NodeUpdateType.
|
|
66
|
-
* scene once per
|
|
83
|
+
* The `updateBeforeType` is set to `NodeUpdateType.RENDER` since the node renders the
|
|
84
|
+
* scene once per render in its {@link ViewportTextureNode#updateBefore} method.
|
|
67
85
|
*
|
|
68
86
|
* @type {string}
|
|
69
87
|
* @default 'frame'
|
|
70
88
|
*/
|
|
71
|
-
this.updateBeforeType = NodeUpdateType.
|
|
89
|
+
this.updateBeforeType = NodeUpdateType.RENDER;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The framebuffer texture for the current renderer context.
|
|
93
|
+
*
|
|
94
|
+
* @type {WeakMap<RenderTarget, FramebufferTexture>}
|
|
95
|
+
* @private
|
|
96
|
+
*/
|
|
97
|
+
this._textures = new WeakMap();
|
|
98
|
+
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
getFrameBufferTexture( reference = null ) {
|
|
102
|
+
|
|
103
|
+
const defaultFramebuffer = this.referenceNode ? this.referenceNode.defaultFramebuffer : this.defaultFramebuffer;
|
|
104
|
+
|
|
105
|
+
if ( reference === null ) {
|
|
106
|
+
|
|
107
|
+
return defaultFramebuffer;
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if ( this._textures.has( reference ) === false ) {
|
|
112
|
+
|
|
113
|
+
const framebufferTexture = defaultFramebuffer.clone();
|
|
114
|
+
|
|
115
|
+
this._textures.set( reference, framebufferTexture );
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return this._textures.get( reference );
|
|
72
120
|
|
|
73
121
|
}
|
|
74
122
|
|
|
75
123
|
updateBefore( frame ) {
|
|
76
124
|
|
|
77
125
|
const renderer = frame.renderer;
|
|
78
|
-
renderer.
|
|
126
|
+
const renderTarget = renderer.getRenderTarget();
|
|
127
|
+
|
|
128
|
+
if ( renderTarget === null ) {
|
|
129
|
+
|
|
130
|
+
renderer.getDrawingBufferSize( _size );
|
|
131
|
+
|
|
132
|
+
} else {
|
|
133
|
+
|
|
134
|
+
_size.set( renderTarget.width, renderTarget.height );
|
|
135
|
+
|
|
136
|
+
}
|
|
79
137
|
|
|
80
138
|
//
|
|
81
139
|
|
|
82
|
-
const framebufferTexture = this.
|
|
140
|
+
const framebufferTexture = this.getFrameBufferTexture( renderTarget );
|
|
83
141
|
|
|
84
142
|
if ( framebufferTexture.image.width !== _size.width || framebufferTexture.image.height !== _size.height ) {
|
|
85
143
|
|
|
@@ -98,6 +156,8 @@ class ViewportTextureNode extends TextureNode {
|
|
|
98
156
|
|
|
99
157
|
framebufferTexture.generateMipmaps = currentGenerateMipmaps;
|
|
100
158
|
|
|
159
|
+
this.value = framebufferTexture;
|
|
160
|
+
|
|
101
161
|
}
|
|
102
162
|
|
|
103
163
|
clone() {
|
|
@@ -3,17 +3,13 @@ import V_GGX_SmithCorrelated from './V_GGX_SmithCorrelated.js';
|
|
|
3
3
|
import V_GGX_SmithCorrelated_Anisotropic from './V_GGX_SmithCorrelated_Anisotropic.js';
|
|
4
4
|
import D_GGX from './D_GGX.js';
|
|
5
5
|
import D_GGX_Anisotropic from './D_GGX_Anisotropic.js';
|
|
6
|
-
import {
|
|
6
|
+
import { normalView as NormalView } from '../../accessors/Normal.js';
|
|
7
7
|
import { positionViewDirection } from '../../accessors/Position.js';
|
|
8
8
|
import { iridescence, alphaT, anisotropyT, anisotropyB } from '../../core/PropertyNode.js';
|
|
9
9
|
import { Fn, defined } from '../../tsl/TSLBase.js';
|
|
10
10
|
|
|
11
11
|
// GGX Distribution, Schlick Fresnel, GGX_SmithCorrelated Visibility
|
|
12
|
-
const BRDF_GGX = /*@__PURE__*/ Fn( (
|
|
13
|
-
|
|
14
|
-
const { lightDirection, f0, f90, roughness, f, USE_IRIDESCENCE, USE_ANISOTROPY } = inputs;
|
|
15
|
-
|
|
16
|
-
const normalView = inputs.normalView || transformedNormalView;
|
|
12
|
+
const BRDF_GGX = /*@__PURE__*/ Fn( ( { lightDirection, f0, f90, roughness, f, normalView = NormalView, USE_IRIDESCENCE, USE_ANISOTROPY } ) => {
|
|
17
13
|
|
|
18
14
|
const alpha = roughness.pow2(); // UE4's roughness
|
|
19
15
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { normalView } from '../../accessors/Normal.js';
|
|
2
2
|
import { positionViewDirection } from '../../accessors/Position.js';
|
|
3
3
|
import { sheen, sheenRoughness } from '../../core/PropertyNode.js';
|
|
4
4
|
import { Fn, float } from '../../tsl/TSLBase.js';
|
|
@@ -43,9 +43,9 @@ const BRDF_Sheen = /*@__PURE__*/ Fn( ( { lightDirection } ) => {
|
|
|
43
43
|
|
|
44
44
|
const halfDir = lightDirection.add( positionViewDirection ).normalize();
|
|
45
45
|
|
|
46
|
-
const dotNL =
|
|
47
|
-
const dotNV =
|
|
48
|
-
const dotNH =
|
|
46
|
+
const dotNL = normalView.dot( lightDirection ).clamp();
|
|
47
|
+
const dotNV = normalView.dot( positionViewDirection ).clamp();
|
|
48
|
+
const dotNH = normalView.dot( halfDir ).clamp();
|
|
49
49
|
|
|
50
50
|
const D = D_Charlie( { roughness: sheenRoughness, dotNH } );
|
|
51
51
|
const V = V_Neubelt( { dotNV, dotNL } );
|
|
@@ -2,7 +2,7 @@ import BasicLightingModel from './BasicLightingModel.js';
|
|
|
2
2
|
import F_Schlick from './BSDF/F_Schlick.js';
|
|
3
3
|
import BRDF_Lambert from './BSDF/BRDF_Lambert.js';
|
|
4
4
|
import { diffuseColor, shininess, specularColor } from '../core/PropertyNode.js';
|
|
5
|
-
import {
|
|
5
|
+
import { normalView } from '../accessors/Normal.js';
|
|
6
6
|
import { materialSpecularStrength } from '../accessors/MaterialNode.js';
|
|
7
7
|
import { positionViewDirection } from '../accessors/Position.js';
|
|
8
8
|
import { Fn, float } from '../tsl/TSLBase.js';
|
|
@@ -19,7 +19,7 @@ const BRDF_BlinnPhong = /*@__PURE__*/ Fn( ( { lightDirection } ) => {
|
|
|
19
19
|
|
|
20
20
|
const halfDir = lightDirection.add( positionViewDirection ).normalize();
|
|
21
21
|
|
|
22
|
-
const dotNH =
|
|
22
|
+
const dotNH = normalView.dot( halfDir ).clamp();
|
|
23
23
|
const dotVH = positionViewDirection.dot( halfDir ).clamp();
|
|
24
24
|
|
|
25
25
|
const F = F_Schlick( { f0: specularColor, f90: 1.0, dotVH } );
|
|
@@ -66,7 +66,7 @@ class PhongLightingModel extends BasicLightingModel {
|
|
|
66
66
|
*/
|
|
67
67
|
direct( { lightDirection, lightColor, reflectedLight } ) {
|
|
68
68
|
|
|
69
|
-
const dotNL =
|
|
69
|
+
const dotNL = normalView.dot( lightDirection ).clamp();
|
|
70
70
|
const irradiance = dotNL.mul( lightColor );
|
|
71
71
|
|
|
72
72
|
reflectedLight.directDiffuse.addAssign( irradiance.mul( BRDF_Lambert( { diffuseColor: diffuseColor.rgb } ) ) );
|
|
@@ -8,7 +8,7 @@ import BRDF_Sheen from './BSDF/BRDF_Sheen.js';
|
|
|
8
8
|
import { LTC_Evaluate, LTC_Uv } from './BSDF/LTC.js';
|
|
9
9
|
import LightingModel from '../core/LightingModel.js';
|
|
10
10
|
import { diffuseColor, specularColor, specularF90, roughness, clearcoat, clearcoatRoughness, sheen, sheenRoughness, iridescence, iridescenceIOR, iridescenceThickness, ior, thickness, transmission, attenuationDistance, attenuationColor, dispersion } from '../core/PropertyNode.js';
|
|
11
|
-
import {
|
|
11
|
+
import { normalView, clearcoatNormalView, normalWorld } from '../accessors/Normal.js';
|
|
12
12
|
import { positionViewDirection, positionView, positionWorld } from '../accessors/Position.js';
|
|
13
13
|
import { Fn, float, vec2, vec3, vec4, mat3, If } from '../tsl/TSLBase.js';
|
|
14
14
|
import { select } from '../math/ConditionalNode.js';
|
|
@@ -18,7 +18,7 @@ import { cameraPosition, cameraProjectionMatrix, cameraViewMatrix } from '../acc
|
|
|
18
18
|
import { modelWorldMatrix } from '../accessors/ModelNode.js';
|
|
19
19
|
import { screenSize } from '../display/ScreenNode.js';
|
|
20
20
|
import { viewportMipTexture } from '../display/ViewportTextureNode.js';
|
|
21
|
-
import {
|
|
21
|
+
import { textureBicubicLevel } from '../accessors/TextureBicubic.js';
|
|
22
22
|
import { Loop } from '../utils/LoopNode.js';
|
|
23
23
|
import { BackSide } from '../../constants.js';
|
|
24
24
|
|
|
@@ -80,7 +80,7 @@ const getTransmissionSample = /*@__PURE__*/ Fn( ( [ fragCoord, roughness, ior ],
|
|
|
80
80
|
|
|
81
81
|
const lod = log2( screenSize.x ).mul( applyIorToRoughness( roughness, ior ) );
|
|
82
82
|
|
|
83
|
-
return
|
|
83
|
+
return textureBicubicLevel( transmissionSample, lod );
|
|
84
84
|
|
|
85
85
|
} );
|
|
86
86
|
|
|
@@ -494,7 +494,7 @@ class PhysicalLightingModel extends LightingModel {
|
|
|
494
494
|
|
|
495
495
|
if ( this.iridescence === true ) {
|
|
496
496
|
|
|
497
|
-
const dotNVi =
|
|
497
|
+
const dotNVi = normalView.dot( positionViewDirection ).clamp();
|
|
498
498
|
|
|
499
499
|
this.iridescenceFresnel = evalIridescence( {
|
|
500
500
|
outsideIOR: float( 1.0 ),
|
|
@@ -512,7 +512,7 @@ class PhysicalLightingModel extends LightingModel {
|
|
|
512
512
|
|
|
513
513
|
const position = positionWorld;
|
|
514
514
|
const v = cameraPosition.sub( positionWorld ).normalize(); // TODO: Create Node for this, same issue in MaterialX
|
|
515
|
-
const n =
|
|
515
|
+
const n = normalWorld;
|
|
516
516
|
|
|
517
517
|
const context = builder.context;
|
|
518
518
|
|
|
@@ -550,7 +550,7 @@ class PhysicalLightingModel extends LightingModel {
|
|
|
550
550
|
|
|
551
551
|
computeMultiscattering( singleScatter, multiScatter, specularF90 ) {
|
|
552
552
|
|
|
553
|
-
const dotNV =
|
|
553
|
+
const dotNV = normalView.dot( positionViewDirection ).clamp(); // @ TODO: Move to core dotNV
|
|
554
554
|
|
|
555
555
|
const fab = DFGApprox( { roughness, dotNV } );
|
|
556
556
|
|
|
@@ -575,9 +575,9 @@ class PhysicalLightingModel extends LightingModel {
|
|
|
575
575
|
* @param {Object} lightData - The light data.
|
|
576
576
|
* @param {NodeBuilder} builder - The current node builder.
|
|
577
577
|
*/
|
|
578
|
-
direct( { lightDirection, lightColor, reflectedLight } ) {
|
|
578
|
+
direct( { lightDirection, lightColor, reflectedLight }, /* builder */ ) {
|
|
579
579
|
|
|
580
|
-
const dotNL =
|
|
580
|
+
const dotNL = normalView.dot( lightDirection ).clamp();
|
|
581
581
|
const irradiance = dotNL.mul( lightColor );
|
|
582
582
|
|
|
583
583
|
if ( this.sheen === true ) {
|
|
@@ -588,10 +588,10 @@ class PhysicalLightingModel extends LightingModel {
|
|
|
588
588
|
|
|
589
589
|
if ( this.clearcoat === true ) {
|
|
590
590
|
|
|
591
|
-
const dotNLcc =
|
|
591
|
+
const dotNLcc = clearcoatNormalView.dot( lightDirection ).clamp();
|
|
592
592
|
const ccIrradiance = dotNLcc.mul( lightColor );
|
|
593
593
|
|
|
594
|
-
this.clearcoatSpecularDirect.addAssign( ccIrradiance.mul( BRDF_GGX( { lightDirection, f0: clearcoatF0, f90: clearcoatF90, roughness: clearcoatRoughness, normalView:
|
|
594
|
+
this.clearcoatSpecularDirect.addAssign( ccIrradiance.mul( BRDF_GGX( { lightDirection, f0: clearcoatF0, f90: clearcoatF90, roughness: clearcoatRoughness, normalView: clearcoatNormalView } ) ) );
|
|
595
595
|
|
|
596
596
|
}
|
|
597
597
|
|
|
@@ -608,14 +608,14 @@ class PhysicalLightingModel extends LightingModel {
|
|
|
608
608
|
* @param {Object} input - The input data.
|
|
609
609
|
* @param {NodeBuilder} builder - The current node builder.
|
|
610
610
|
*/
|
|
611
|
-
directRectArea( { lightColor, lightPosition, halfWidth, halfHeight, reflectedLight, ltc_1, ltc_2 } ) {
|
|
611
|
+
directRectArea( { lightColor, lightPosition, halfWidth, halfHeight, reflectedLight, ltc_1, ltc_2 }, /* builder */ ) {
|
|
612
612
|
|
|
613
613
|
const p0 = lightPosition.add( halfWidth ).sub( halfHeight ); // counterclockwise; light shines in local neg z direction
|
|
614
614
|
const p1 = lightPosition.sub( halfWidth ).sub( halfHeight );
|
|
615
615
|
const p2 = lightPosition.sub( halfWidth ).add( halfHeight );
|
|
616
616
|
const p3 = lightPosition.add( halfWidth ).add( halfHeight );
|
|
617
617
|
|
|
618
|
-
const N =
|
|
618
|
+
const N = normalView;
|
|
619
619
|
const V = positionViewDirection;
|
|
620
620
|
const P = positionView.toVar();
|
|
621
621
|
|
|
@@ -680,7 +680,7 @@ class PhysicalLightingModel extends LightingModel {
|
|
|
680
680
|
this.sheenSpecularIndirect.addAssign( iblIrradiance.mul(
|
|
681
681
|
sheen,
|
|
682
682
|
IBLSheenBRDF( {
|
|
683
|
-
normal:
|
|
683
|
+
normal: normalView,
|
|
684
684
|
viewDir: positionViewDirection,
|
|
685
685
|
roughness: sheenRoughness
|
|
686
686
|
} )
|
|
@@ -690,7 +690,7 @@ class PhysicalLightingModel extends LightingModel {
|
|
|
690
690
|
|
|
691
691
|
if ( this.clearcoat === true ) {
|
|
692
692
|
|
|
693
|
-
const dotNVcc =
|
|
693
|
+
const dotNVcc = clearcoatNormalView.dot( positionViewDirection ).clamp();
|
|
694
694
|
|
|
695
695
|
const clearcoatEnv = EnvironmentBRDF( {
|
|
696
696
|
dotNV: dotNVcc,
|
|
@@ -731,7 +731,7 @@ class PhysicalLightingModel extends LightingModel {
|
|
|
731
731
|
|
|
732
732
|
const { ambientOcclusion, reflectedLight } = builder.context;
|
|
733
733
|
|
|
734
|
-
const dotNV =
|
|
734
|
+
const dotNV = normalView.dot( positionViewDirection ).clamp(); // @ TODO: Move to core dotNV
|
|
735
735
|
|
|
736
736
|
const aoNV = dotNV.add( ambientOcclusion );
|
|
737
737
|
const aoExp = roughness.mul( - 16.0 ).oneMinus().negate().exp2();
|
|
@@ -766,7 +766,7 @@ class PhysicalLightingModel extends LightingModel {
|
|
|
766
766
|
|
|
767
767
|
if ( this.clearcoat === true ) {
|
|
768
768
|
|
|
769
|
-
const dotNVcc =
|
|
769
|
+
const dotNVcc = clearcoatNormalView.dot( positionViewDirection ).clamp();
|
|
770
770
|
|
|
771
771
|
const Fcc = F_Schlick( {
|
|
772
772
|
dotVH: dotNVcc,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { normalViewGeometry } from '../../accessors/Normal.js';
|
|
2
2
|
import { float, Fn } from '../../tsl/TSLBase.js';
|
|
3
3
|
|
|
4
4
|
const getGeometryRoughness = /*@__PURE__*/ Fn( ( builder ) => {
|
|
@@ -9,7 +9,7 @@ const getGeometryRoughness = /*@__PURE__*/ Fn( ( builder ) => {
|
|
|
9
9
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
const dxy =
|
|
12
|
+
const dxy = normalViewGeometry.dFdx().abs().max( normalViewGeometry.dFdy().abs() );
|
|
13
13
|
const geometryRoughness = dxy.x.max( dxy.y ).max( dxy.z );
|
|
14
14
|
|
|
15
15
|
return geometryRoughness;
|
|
@@ -113,7 +113,7 @@ class AtomicFunctionNode extends Node {
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
const methodSnippet = `${ builder.getMethod( method, type ) }( ${ params.join( ', ' ) } )`;
|
|
116
|
-
const isVoid = parents.length === 1 && parents[ 0 ].isStackNode === true;
|
|
116
|
+
const isVoid = parents ? ( parents.length === 1 && parents[ 0 ].isStackNode === true ) : false;
|
|
117
117
|
|
|
118
118
|
if ( isVoid ) {
|
|
119
119
|
|
|
@@ -19,10 +19,9 @@ class ComputeNode extends Node {
|
|
|
19
19
|
* Constructs a new compute node.
|
|
20
20
|
*
|
|
21
21
|
* @param {Node} computeNode - TODO
|
|
22
|
-
* @param {number}
|
|
23
|
-
* @param {Array<number>} [workgroupSize=[64]] - TODO.
|
|
22
|
+
* @param {Array<number>} workgroupSize - TODO.
|
|
24
23
|
*/
|
|
25
|
-
constructor( computeNode,
|
|
24
|
+
constructor( computeNode, workgroupSize ) {
|
|
26
25
|
|
|
27
26
|
super( 'void' );
|
|
28
27
|
|
|
@@ -42,18 +41,12 @@ class ComputeNode extends Node {
|
|
|
42
41
|
*/
|
|
43
42
|
this.computeNode = computeNode;
|
|
44
43
|
|
|
45
|
-
/**
|
|
46
|
-
* TODO
|
|
47
|
-
*
|
|
48
|
-
* @type {number}
|
|
49
|
-
*/
|
|
50
|
-
this.count = count;
|
|
51
44
|
|
|
52
45
|
/**
|
|
53
46
|
* TODO
|
|
54
47
|
*
|
|
55
48
|
* @type {Array<number>}
|
|
56
|
-
* @default [64]
|
|
49
|
+
* @default [ 64 ]
|
|
57
50
|
*/
|
|
58
51
|
this.workgroupSize = workgroupSize;
|
|
59
52
|
|
|
@@ -62,7 +55,7 @@ class ComputeNode extends Node {
|
|
|
62
55
|
*
|
|
63
56
|
* @type {number}
|
|
64
57
|
*/
|
|
65
|
-
this.
|
|
58
|
+
this.count = null;
|
|
66
59
|
|
|
67
60
|
/**
|
|
68
61
|
* TODO
|
|
@@ -95,7 +88,19 @@ class ComputeNode extends Node {
|
|
|
95
88
|
*/
|
|
96
89
|
this.onInitFunction = null;
|
|
97
90
|
|
|
98
|
-
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
setCount( count ) {
|
|
94
|
+
|
|
95
|
+
this.count = count;
|
|
96
|
+
|
|
97
|
+
return this;
|
|
98
|
+
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
getCount() {
|
|
102
|
+
|
|
103
|
+
return this.count;
|
|
99
104
|
|
|
100
105
|
}
|
|
101
106
|
|
|
@@ -114,7 +119,7 @@ class ComputeNode extends Node {
|
|
|
114
119
|
* @param {string} name - The name of the uniform.
|
|
115
120
|
* @return {ComputeNode} A reference to this node.
|
|
116
121
|
*/
|
|
117
|
-
|
|
122
|
+
setName( name ) {
|
|
118
123
|
|
|
119
124
|
this.name = name;
|
|
120
125
|
|
|
@@ -123,18 +128,17 @@ class ComputeNode extends Node {
|
|
|
123
128
|
}
|
|
124
129
|
|
|
125
130
|
/**
|
|
126
|
-
*
|
|
131
|
+
* Sets the {@link ComputeNode#name} property.
|
|
132
|
+
*
|
|
133
|
+
* @deprecated
|
|
134
|
+
* @param {string} name - The name of the uniform.
|
|
135
|
+
* @return {ComputeNode} A reference to this node.
|
|
127
136
|
*/
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const { count, workgroupSize } = this;
|
|
131
|
-
|
|
132
|
-
let size = workgroupSize[ 0 ];
|
|
137
|
+
label( name ) {
|
|
133
138
|
|
|
134
|
-
|
|
135
|
-
size *= workgroupSize[ i ];
|
|
139
|
+
console.warn( 'THREE.TSL: "label()" has been deprecated. Use "setName()" instead.' ); // @deprecated r179
|
|
136
140
|
|
|
137
|
-
this.
|
|
141
|
+
return this.setName( name );
|
|
138
142
|
|
|
139
143
|
}
|
|
140
144
|
|
|
@@ -213,6 +217,45 @@ class ComputeNode extends Node {
|
|
|
213
217
|
|
|
214
218
|
export default ComputeNode;
|
|
215
219
|
|
|
220
|
+
/**
|
|
221
|
+
* TSL function for creating a compute kernel node.
|
|
222
|
+
*
|
|
223
|
+
* @tsl
|
|
224
|
+
* @function
|
|
225
|
+
* @param {Node} node - TODO
|
|
226
|
+
* @param {Array<number>} [workgroupSize=[64]] - TODO.
|
|
227
|
+
* @returns {AtomicFunctionNode}
|
|
228
|
+
*/
|
|
229
|
+
export const computeKernel = ( node, workgroupSize = [ 64 ] ) => {
|
|
230
|
+
|
|
231
|
+
if ( workgroupSize.length === 0 || workgroupSize.length > 3 ) {
|
|
232
|
+
|
|
233
|
+
console.error( 'THREE.TSL: compute() workgroupSize must have 1, 2, or 3 elements' );
|
|
234
|
+
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
for ( let i = 0; i < workgroupSize.length; i ++ ) {
|
|
238
|
+
|
|
239
|
+
const val = workgroupSize[ i ];
|
|
240
|
+
|
|
241
|
+
if ( typeof val !== 'number' || val <= 0 || ! Number.isInteger( val ) ) {
|
|
242
|
+
|
|
243
|
+
console.error( `THREE.TSL: compute() workgroupSize element at index [ ${ i } ] must be a positive integer` );
|
|
244
|
+
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Implicit fill-up to [ x, y, z ] with 1s, just like WGSL treats @workgroup_size when fewer dimensions are specified
|
|
250
|
+
|
|
251
|
+
while ( workgroupSize.length < 3 ) workgroupSize.push( 1 );
|
|
252
|
+
|
|
253
|
+
//
|
|
254
|
+
|
|
255
|
+
return nodeObject( new ComputeNode( nodeObject( node ), workgroupSize ) );
|
|
256
|
+
|
|
257
|
+
};
|
|
258
|
+
|
|
216
259
|
/**
|
|
217
260
|
* TSL function for creating a compute node.
|
|
218
261
|
*
|
|
@@ -223,6 +266,7 @@ export default ComputeNode;
|
|
|
223
266
|
* @param {Array<number>} [workgroupSize=[64]] - TODO.
|
|
224
267
|
* @returns {AtomicFunctionNode}
|
|
225
268
|
*/
|
|
226
|
-
export const compute = ( node, count, workgroupSize ) =>
|
|
269
|
+
export const compute = ( node, count, workgroupSize ) => computeKernel( node, workgroupSize ).setCount( count );
|
|
227
270
|
|
|
228
271
|
addMethodChaining( 'compute', compute );
|
|
272
|
+
addMethodChaining( 'computeKernel', computeKernel );
|
|
@@ -116,15 +116,23 @@ class WorkgroupInfoNode extends Node {
|
|
|
116
116
|
*/
|
|
117
117
|
this.scope = scope;
|
|
118
118
|
|
|
119
|
+
/**
|
|
120
|
+
* The name of the workgroup scoped buffer.
|
|
121
|
+
*
|
|
122
|
+
* @type {string}
|
|
123
|
+
* @default ''
|
|
124
|
+
*/
|
|
125
|
+
this.name = '';
|
|
126
|
+
|
|
119
127
|
}
|
|
120
128
|
|
|
121
129
|
/**
|
|
122
|
-
* Sets the name
|
|
130
|
+
* Sets the name of this node.
|
|
123
131
|
*
|
|
124
132
|
* @param {string} name - The name to set.
|
|
125
133
|
* @return {WorkgroupInfoNode} A reference to this node.
|
|
126
134
|
*/
|
|
127
|
-
|
|
135
|
+
setName( name ) {
|
|
128
136
|
|
|
129
137
|
this.name = name;
|
|
130
138
|
|
|
@@ -132,6 +140,21 @@ class WorkgroupInfoNode extends Node {
|
|
|
132
140
|
|
|
133
141
|
}
|
|
134
142
|
|
|
143
|
+
/**
|
|
144
|
+
* Sets the name/label of this node.
|
|
145
|
+
*
|
|
146
|
+
* @deprecated
|
|
147
|
+
* @param {string} name - The name to set.
|
|
148
|
+
* @return {WorkgroupInfoNode} A reference to this node.
|
|
149
|
+
*/
|
|
150
|
+
label( name ) {
|
|
151
|
+
|
|
152
|
+
console.warn( 'THREE.TSL: "label()" has been deprecated. Use "setName()" instead.' ); // @deprecated r179
|
|
153
|
+
|
|
154
|
+
return this.setName( name );
|
|
155
|
+
|
|
156
|
+
}
|
|
157
|
+
|
|
135
158
|
/**
|
|
136
159
|
* Sets the scope of this node.
|
|
137
160
|
*
|
|
@@ -185,7 +208,9 @@ class WorkgroupInfoNode extends Node {
|
|
|
185
208
|
|
|
186
209
|
generate( builder ) {
|
|
187
210
|
|
|
188
|
-
|
|
211
|
+
const name = ( this.name !== '' ) ? this.name : `${this.scope}Array_${this.id}`;
|
|
212
|
+
|
|
213
|
+
return builder.getScopedArray( name, this.scope.toLowerCase(), this.bufferType, this.bufferCount );
|
|
189
214
|
|
|
190
215
|
}
|
|
191
216
|
|
|
@@ -2,10 +2,10 @@ import LightingNode from './LightingNode.js';
|
|
|
2
2
|
import { cache } from '../core/CacheNode.js';
|
|
3
3
|
import { roughness, clearcoatRoughness } from '../core/PropertyNode.js';
|
|
4
4
|
import { cameraViewMatrix } from '../accessors/Camera.js';
|
|
5
|
-
import {
|
|
5
|
+
import { normalView, clearcoatNormalView, normalWorld } from '../accessors/Normal.js';
|
|
6
6
|
import { positionViewDirection } from '../accessors/Position.js';
|
|
7
7
|
import { float } from '../tsl/TSLBase.js';
|
|
8
|
-
import {
|
|
8
|
+
import { bentNormalView } from '../accessors/AccessorsUtils.js';
|
|
9
9
|
import { pmremTexture } from '../pmrem/PMREMNode.js';
|
|
10
10
|
import { materialEnvIntensity } from '../accessors/MaterialProperties.js';
|
|
11
11
|
|
|
@@ -72,10 +72,10 @@ class EnvironmentNode extends LightingNode {
|
|
|
72
72
|
//
|
|
73
73
|
|
|
74
74
|
const useAnisotropy = material.useAnisotropy === true || material.anisotropy > 0;
|
|
75
|
-
const radianceNormalView = useAnisotropy ?
|
|
75
|
+
const radianceNormalView = useAnisotropy ? bentNormalView : normalView;
|
|
76
76
|
|
|
77
77
|
const radiance = envNode.context( createRadianceContext( roughness, radianceNormalView ) ).mul( materialEnvIntensity );
|
|
78
|
-
const irradiance = envNode.context( createIrradianceContext(
|
|
78
|
+
const irradiance = envNode.context( createIrradianceContext( normalWorld ) ).mul( Math.PI ).mul( materialEnvIntensity );
|
|
79
79
|
|
|
80
80
|
const isolateRadiance = cache( radiance );
|
|
81
81
|
const isolateIrradiance = cache( irradiance );
|
|
@@ -92,7 +92,7 @@ class EnvironmentNode extends LightingNode {
|
|
|
92
92
|
|
|
93
93
|
if ( clearcoatRadiance ) {
|
|
94
94
|
|
|
95
|
-
const clearcoatRadianceContext = envNode.context( createRadianceContext( clearcoatRoughness,
|
|
95
|
+
const clearcoatRadianceContext = envNode.context( createRadianceContext( clearcoatRoughness, clearcoatNormalView ) ).mul( materialEnvIntensity );
|
|
96
96
|
const isolateClearcoatRadiance = cache( clearcoatRadianceContext );
|
|
97
97
|
|
|
98
98
|
clearcoatRadiance.addAssign( isolateClearcoatRadiance );
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Node from '../core/Node.js';
|
|
2
|
-
import { nodeObject, vec3 } from '../tsl/TSLBase.js';
|
|
2
|
+
import { nodeObject, property, vec3 } from '../tsl/TSLBase.js';
|
|
3
3
|
import { hashArray } from '../core/NodeUtils.js';
|
|
4
4
|
|
|
5
5
|
const sortLights = ( lights ) => {
|
|
@@ -54,21 +54,21 @@ class LightsNode extends Node {
|
|
|
54
54
|
*
|
|
55
55
|
* @type {Node<vec3>}
|
|
56
56
|
*/
|
|
57
|
-
this.totalDiffuseNode = vec3
|
|
57
|
+
this.totalDiffuseNode = property( 'vec3', 'totalDiffuse' );
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* A node representing the total specular light.
|
|
61
61
|
*
|
|
62
62
|
* @type {Node<vec3>}
|
|
63
63
|
*/
|
|
64
|
-
this.totalSpecularNode = vec3
|
|
64
|
+
this.totalSpecularNode = property( 'vec3', 'totalSpecular' );
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* A node representing the outgoing light.
|
|
68
68
|
*
|
|
69
69
|
* @type {Node<vec3>}
|
|
70
70
|
*/
|
|
71
|
-
this.outgoingLightNode = vec3
|
|
71
|
+
this.outgoingLightNode = property( 'vec3', 'outgoingLight' );
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
74
|
* An array representing the lights in the scene.
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import SpotLightNode from './SpotLightNode.js';
|
|
2
2
|
|
|
3
|
-
import { Fn, vec2 } from '../tsl/TSLCore.js';
|
|
3
|
+
import { float, Fn, If, vec2 } from '../tsl/TSLCore.js';
|
|
4
4
|
import { length, min, max, saturate, acos } from '../math/MathNode.js';
|
|
5
5
|
import { div, sub } from '../math/OperatorNode.js';
|
|
6
|
+
import { lightShadowMatrix } from '../accessors/Lights.js';
|
|
7
|
+
import { positionWorld } from '../accessors/Position.js';
|
|
6
8
|
|
|
7
9
|
const sdBox = /*@__PURE__*/ Fn( ( [ p, b ] ) => {
|
|
8
10
|
|
|
@@ -61,13 +63,24 @@ class ProjectorLightNode extends SpotLightNode {
|
|
|
61
63
|
*/
|
|
62
64
|
getSpotAttenuation( builder ) {
|
|
63
65
|
|
|
66
|
+
const attenuation = float( 0 );
|
|
64
67
|
const penumbraCos = this.penumbraCosNode;
|
|
65
|
-
const spotLightCoord = this.getLightCoord( builder );
|
|
66
|
-
const coord = spotLightCoord.xyz.div( spotLightCoord.w );
|
|
67
68
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
69
|
+
// compute the fragment's position in the light's clip space
|
|
70
|
+
|
|
71
|
+
const spotLightCoord = lightShadowMatrix( this.light ).mul( builder.context.positionWorld || positionWorld );
|
|
72
|
+
|
|
73
|
+
// the sign of w determines whether the current fragment is in front or behind the light.
|
|
74
|
+
// to avoid a back-projection, it's important to only compute an attenuation if w is positive
|
|
75
|
+
|
|
76
|
+
If( spotLightCoord.w.greaterThan( 0 ), () => {
|
|
77
|
+
|
|
78
|
+
const projectionUV = spotLightCoord.xyz.div( spotLightCoord.w );
|
|
79
|
+
const boxDist = sdBox( projectionUV.xy.sub( vec2( 0.5 ) ), vec2( 0.5 ) );
|
|
80
|
+
const angleFactor = div( - 1.0, sub( 1.0, acos( penumbraCos ) ).sub( 1.0 ) );
|
|
81
|
+
attenuation.assign( saturate( boxDist.mul( - 2.0 ).mul( angleFactor ) ) );
|
|
82
|
+
|
|
83
|
+
} );
|
|
71
84
|
|
|
72
85
|
return attenuation;
|
|
73
86
|
|
|
@@ -22,7 +22,7 @@ const shadowMaterialLib = /*@__PURE__*/ new WeakMap();
|
|
|
22
22
|
*/
|
|
23
23
|
export const BasicShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, shadowCoord, depthLayer } ) => {
|
|
24
24
|
|
|
25
|
-
let basic = texture( depthTexture, shadowCoord.xy ).
|
|
25
|
+
let basic = texture( depthTexture, shadowCoord.xy ).setName( 't_basic' );
|
|
26
26
|
|
|
27
27
|
if ( depthTexture.isArrayTexture ) {
|
|
28
28
|
|