super-three 0.169.1 → 0.170.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/three.cjs +24628 -24228
- package/build/three.core.js +37002 -0
- package/build/three.core.min.js +6 -0
- package/build/three.module.js +10519 -47108
- package/build/three.module.min.js +1 -1
- package/build/three.tsl.js +533 -0
- package/build/three.tsl.min.js +6 -0
- package/build/three.webgpu.js +17071 -53583
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +17134 -53623
- package/build/three.webgpu.nodes.min.js +1 -1
- package/examples/jsm/Addons.js +3 -3
- package/examples/jsm/animation/MMDAnimationHelper.js +2 -0
- package/examples/jsm/animation/MMDPhysics.js +2 -0
- package/examples/jsm/capabilities/WebGPU.js +1 -10
- package/examples/jsm/controls/ArcballControls.js +25 -21
- package/examples/jsm/controls/OrbitControls.js +41 -9
- package/examples/jsm/controls/PointerLockControls.js +2 -5
- package/examples/jsm/controls/TransformControls.js +22 -6
- package/examples/jsm/csm/CSM.js +2 -2
- package/examples/jsm/csm/CSMFrustum.js +7 -4
- package/examples/jsm/csm/CSMHelper.js +2 -0
- package/examples/jsm/csm/CSMShadowNode.js +437 -0
- package/examples/jsm/curves/NURBSCurve.js +34 -3
- package/examples/jsm/exporters/GLTFExporter.js +138 -71
- package/examples/jsm/exporters/KTX2Exporter.js +35 -12
- package/examples/jsm/exporters/MMDExporter.js +6 -0
- package/examples/jsm/exporters/USDZExporter.js +21 -3
- package/examples/jsm/geometries/DecalGeometry.js +70 -21
- package/examples/jsm/geometries/InstancedPointsGeometry.js +2 -0
- package/examples/jsm/helpers/TextureHelperGPU.js +175 -0
- package/examples/jsm/interactive/HTMLMesh.js +1 -0
- package/examples/jsm/lighting/TiledLighting.js +18 -0
- package/examples/jsm/lights/RectAreaLightTexturesLib.js +1 -1
- package/examples/jsm/lines/LineGeometry.js +25 -0
- package/examples/jsm/lines/LineMaterial.js +0 -1
- package/examples/jsm/lines/LineSegmentsGeometry.js +2 -0
- package/examples/jsm/lines/webgpu/Line2.js +2 -1
- package/examples/jsm/lines/webgpu/LineSegments2.js +2 -16
- package/examples/jsm/lines/webgpu/Wireframe.js +57 -0
- package/examples/jsm/loaders/3DMLoader.js +1 -0
- package/examples/jsm/loaders/3MFLoader.js +91 -0
- package/examples/jsm/loaders/FBXLoader.js +12 -2
- package/examples/jsm/loaders/GLTFLoader.js +2 -0
- package/examples/jsm/loaders/KTX2Loader.js +143 -49
- package/examples/jsm/loaders/LDrawLoader.js +22 -136
- package/examples/jsm/loaders/LottieLoader.js +1 -0
- package/examples/jsm/loaders/MMDLoader.js +3 -0
- package/examples/jsm/loaders/MaterialXLoader.js +2 -2
- package/examples/jsm/materials/LDrawConditionalLineMaterial.js +143 -0
- package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +114 -0
- package/examples/jsm/math/ColorSpaces.js +76 -0
- package/examples/jsm/misc/ProgressiveLightMap.js +52 -40
- package/examples/jsm/misc/ProgressiveLightMapGPU.js +293 -0
- package/examples/jsm/misc/VolumeSlice.js +1 -0
- package/examples/jsm/objects/InstancedPoints.js +2 -4
- package/examples/jsm/objects/LensflareMesh.js +4 -2
- package/examples/jsm/objects/SkyMesh.js +5 -3
- package/examples/jsm/objects/Water2Mesh.js +7 -3
- package/examples/jsm/objects/WaterMesh.js +12 -10
- package/examples/jsm/postprocessing/AfterimagePass.js +14 -3
- package/examples/jsm/postprocessing/SSRPass.js +6 -0
- package/examples/jsm/renderers/CSS2DRenderer.js +6 -3
- package/examples/jsm/renderers/CSS3DRenderer.js +7 -4
- package/examples/jsm/shaders/FXAAShader.js +225 -224
- package/examples/jsm/transpiler/AST.js +2 -2
- package/examples/jsm/transpiler/GLSLDecoder.js +57 -25
- package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
- package/examples/jsm/transpiler/TSLEncoder.js +11 -6
- package/{src/nodes → examples/jsm/tsl}/display/AfterImageNode.js +18 -21
- package/{src/nodes → examples/jsm/tsl}/display/AnaglyphPassNode.js +2 -6
- package/{src/nodes → examples/jsm/tsl}/display/AnamorphicNode.js +12 -18
- package/{src/nodes → examples/jsm/tsl}/display/BleachBypass.js +1 -3
- package/{src/nodes → examples/jsm/tsl}/display/BloomNode.js +12 -41
- package/{src/nodes → examples/jsm/tsl}/display/DenoiseNode.js +60 -47
- package/{src/nodes → examples/jsm/tsl}/display/DepthOfFieldNode.js +4 -9
- package/{src/nodes → examples/jsm/tsl}/display/DotScreenNode.js +2 -9
- package/examples/jsm/tsl/display/FXAANode.js +316 -0
- package/{src/nodes → examples/jsm/tsl}/display/FilmNode.js +4 -7
- package/{src/nodes → examples/jsm/tsl}/display/GTAONode.js +73 -78
- package/{src/nodes → examples/jsm/tsl}/display/GaussianBlurNode.js +78 -42
- package/examples/jsm/tsl/display/LensflareNode.js +161 -0
- package/{src/nodes → examples/jsm/tsl}/display/Lut3DNode.js +3 -5
- package/{src/nodes → examples/jsm/tsl}/display/MotionBlur.js +2 -3
- package/examples/jsm/tsl/display/OutlineNode.js +434 -0
- package/{src/nodes → examples/jsm/tsl}/display/ParallaxBarrierPassNode.js +2 -5
- package/{src/nodes → examples/jsm/tsl}/display/PixelationPassNode.js +5 -17
- package/{src/nodes → examples/jsm/tsl}/display/RGBShiftNode.js +2 -6
- package/examples/jsm/tsl/display/SMAANode.js +620 -0
- package/{src/nodes → examples/jsm/tsl}/display/SSAAPassNode.js +10 -25
- package/examples/jsm/tsl/display/SSRNode.js +366 -0
- package/{src/nodes → examples/jsm/tsl}/display/Sepia.js +1 -2
- package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +4 -12
- package/{src/nodes → examples/jsm/tsl}/display/StereoCompositePassNode.js +9 -11
- package/{src/nodes → examples/jsm/tsl}/display/StereoPassNode.js +10 -11
- package/examples/jsm/tsl/display/TRAAPassNode.js +355 -0
- package/{src/nodes → examples/jsm/tsl}/display/TransitionNode.js +3 -7
- package/examples/jsm/tsl/display/hashBlur.js +24 -0
- package/examples/jsm/tsl/lighting/TiledLightsNode.js +389 -0
- package/examples/jsm/utils/SceneOptimizer.js +410 -0
- package/examples/jsm/utils/UVsDebug.js +1 -1
- package/examples/jsm/utils/{TextureUtilsGPU.js → WebGPUTextureUtils.js} +2 -1
- package/examples/jsm/webxr/OculusHandPointerModel.js +21 -21
- package/examples/jsm/webxr/Text2D.js +6 -6
- package/package.json +4 -4
- package/src/Three.Core.js +178 -0
- package/src/Three.TSL.js +526 -0
- package/src/Three.WebGPU.Nodes.js +9 -186
- package/src/Three.WebGPU.js +8 -186
- package/src/Three.js +1 -177
- package/src/animation/AnimationClip.js +2 -2
- package/src/animation/AnimationObjectGroup.js +2 -2
- package/src/audio/Audio.js +38 -0
- package/src/cameras/PerspectiveCamera.js +6 -6
- package/src/cameras/StereoCamera.js +2 -2
- package/src/constants.js +1 -6
- package/src/core/BufferGeometry.js +48 -8
- package/src/core/InterleavedBuffer.js +4 -4
- package/src/core/Object3D.js +2 -2
- package/src/extras/core/Curve.js +3 -3
- package/src/extras/core/Shape.js +2 -2
- package/src/geometries/CylinderGeometry.js +2 -2
- package/src/geometries/EdgesGeometry.js +2 -2
- package/src/geometries/LatheGeometry.js +2 -2
- package/src/lights/SpotLightShadow.js +2 -2
- package/src/materials/LineDashedMaterial.js +0 -1
- package/src/materials/Material.js +2 -2
- package/src/materials/MeshPhongMaterial.js +1 -1
- package/src/materials/MeshPhysicalMaterial.js +2 -2
- package/src/materials/MeshStandardMaterial.js +2 -2
- package/src/materials/nodes/Line2NodeMaterial.js +32 -13
- package/src/materials/nodes/LineDashedNodeMaterial.js +4 -2
- package/src/materials/nodes/NodeMaterial.js +93 -23
- package/src/materials/nodes/SpriteNodeMaterial.js +11 -2
- package/src/materials/nodes/manager/NodeMaterialObserver.js +119 -7
- package/src/math/ColorManagement.js +143 -102
- package/src/math/Line3.js +2 -2
- package/src/math/Quaternion.js +2 -2
- package/src/math/Spherical.js +3 -3
- package/src/math/Vector2.js +7 -7
- package/src/math/Vector3.js +9 -9
- package/src/math/Vector4.js +22 -9
- package/src/nodes/Nodes.js +2 -21
- package/src/nodes/TSL.js +9 -25
- package/src/nodes/accessors/Arrays.js +27 -0
- package/src/nodes/accessors/BuiltinNode.js +26 -0
- package/src/nodes/accessors/Camera.js +0 -1
- package/src/nodes/accessors/ClippingNode.js +76 -42
- package/src/nodes/accessors/InstanceNode.js +17 -20
- package/src/nodes/accessors/InstancedMeshNode.js +26 -0
- package/src/nodes/accessors/Lights.js +32 -0
- package/src/nodes/accessors/SceneNode.js +35 -1
- package/src/nodes/accessors/StorageBufferNode.js +61 -19
- package/src/nodes/accessors/StorageTextureNode.js +10 -4
- package/src/nodes/accessors/TextureNode.js +1 -1
- package/src/nodes/accessors/VelocityNode.js +13 -3
- package/src/nodes/code/FunctionCallNode.js +16 -5
- package/src/nodes/code/ScriptableNode.js +4 -4
- package/src/nodes/core/Node.js +1 -0
- package/src/nodes/core/NodeBuilder.js +31 -14
- package/src/nodes/core/NodeUtils.js +28 -0
- package/src/nodes/core/VarNode.js +15 -3
- package/src/nodes/core/constants.js +6 -0
- package/src/nodes/display/BlendModes.js +99 -0
- package/src/nodes/display/ColorAdjustment.js +53 -4
- package/src/nodes/display/ColorSpaceFunctions.js +5 -5
- package/src/nodes/display/ColorSpaceNode.js +27 -39
- package/src/nodes/display/PassNode.js +6 -4
- package/src/nodes/display/ToneMappingNode.js +1 -1
- package/src/nodes/display/ToonOutlinePassNode.js +3 -3
- package/src/nodes/display/ViewportDepthNode.js +48 -1
- package/src/nodes/functions/PhysicalLightingModel.js +21 -15
- package/src/nodes/functions/material/getAlphaHashThreshold.js +70 -0
- package/src/nodes/functions/material/getGeometryRoughness.js +8 -2
- package/src/nodes/functions/material/getParallaxCorrectNormal.js +22 -0
- package/src/nodes/gpgpu/ComputeNode.js +9 -1
- package/src/nodes/lighting/AnalyticLightNode.js +23 -419
- package/src/nodes/lighting/LightsNode.js +24 -12
- package/src/nodes/lighting/PointLightNode.js +41 -22
- package/src/nodes/lighting/PointShadowNode.js +254 -0
- package/src/nodes/lighting/RectAreaLightNode.js +3 -0
- package/src/nodes/lighting/ShadowNode.js +593 -0
- package/src/nodes/lighting/SpotLightNode.js +14 -2
- package/src/nodes/utils/LoopNode.js +2 -2
- package/src/nodes/utils/Oscillators.js +6 -0
- package/src/nodes/utils/PostProcessingUtils.js +89 -0
- package/src/nodes/utils/RTTNode.js +9 -1
- package/src/nodes/utils/ReflectorNode.js +101 -15
- package/src/nodes/utils/StorageArrayElementNode.js +2 -2
- package/src/nodes/utils/Timer.js +29 -0
- package/src/objects/BatchedMesh.js +472 -296
- package/src/objects/ClippingGroup.js +19 -0
- package/src/objects/Skeleton.js +2 -2
- package/src/renderers/WebGLRenderer.js +183 -109
- package/src/renderers/common/Animation.js +23 -11
- package/src/renderers/common/Attributes.js +4 -0
- package/src/renderers/common/Backend.js +2 -0
- package/src/renderers/common/Background.js +15 -5
- package/src/renderers/common/Bindings.js +23 -6
- package/src/renderers/common/ClippingContext.js +77 -85
- package/src/renderers/common/Constants.js +2 -1
- package/src/renderers/common/Geometries.js +20 -0
- package/src/renderers/common/IndirectStorageBufferAttribute.js +15 -0
- package/src/renderers/common/Lighting.js +45 -0
- package/src/renderers/common/PostProcessingUtils.js +86 -0
- package/src/renderers/common/RenderList.js +48 -17
- package/src/renderers/common/RenderLists.js +4 -2
- package/src/renderers/common/RenderObject.js +45 -28
- package/src/renderers/common/RenderObjects.js +12 -6
- package/src/renderers/common/Renderer.js +222 -77
- package/src/renderers/common/Textures.js +41 -17
- package/src/renderers/common/UniformsGroup.js +16 -4
- package/src/renderers/common/extras/PMREMGenerator.js +89 -13
- package/src/renderers/common/nodes/NodeLibrary.js +2 -15
- package/src/renderers/common/nodes/NodeStorageBuffer.js +2 -3
- package/src/renderers/common/nodes/NodeUniform.js +42 -0
- package/src/renderers/common/nodes/Nodes.js +2 -2
- package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
- package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
- package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
- package/src/renderers/webgl/WebGLBackground.js +20 -1
- package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
- package/src/renderers/webgl/WebGLCapabilities.js +0 -7
- package/src/renderers/webgl/WebGLGeometries.js +0 -28
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
- package/src/renderers/webgl/WebGLProgram.js +24 -28
- package/src/renderers/webgl/WebGLPrograms.js +5 -2
- package/src/renderers/webgl/WebGLState.js +37 -1
- package/src/renderers/webgl/WebGLTextures.js +29 -12
- package/src/renderers/webgl-fallback/WebGLBackend.js +111 -37
- package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +2 -7
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +43 -12
- package/src/renderers/webgl-fallback/utils/WebGLState.js +26 -1
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +37 -9
- package/src/renderers/webgpu/WebGPUBackend.js +152 -56
- package/src/renderers/webgpu/WebGPURenderer.Nodes.js +1 -1
- package/src/renderers/webgpu/WebGPURenderer.js +1 -1
- package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +0 -8
- package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +13 -34
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +192 -92
- package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +12 -4
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +15 -2
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +72 -7
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +29 -9
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +29 -7
- package/src/renderers/webgpu/utils/WebGPUUtils.js +0 -1
- package/src/renderers/webxr/WebXRManager.js +4 -4
- package/src/textures/Source.js +2 -2
- package/src/textures/Texture.js +2 -2
- package/examples/jsm/cameras/CinematicCamera.js +0 -208
- package/src/nodes/display/BlendMode.js +0 -54
- package/src/nodes/display/FXAANode.js +0 -332
- package/src/nodes/utils/OscNode.js +0 -85
- package/src/nodes/utils/TimerNode.js +0 -97
- /package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +0 -0
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Vector2,
|
|
3
|
+
Vector3,
|
|
4
|
+
MathUtils,
|
|
5
|
+
Matrix4,
|
|
6
|
+
Box3,
|
|
7
|
+
Object3D,
|
|
8
|
+
WebGLCoordinateSystem,
|
|
9
|
+
NodeUpdateType,
|
|
10
|
+
Node
|
|
11
|
+
} from 'three/webgpu';
|
|
12
|
+
|
|
13
|
+
import { CSMFrustum } from './CSMFrustum.js';
|
|
14
|
+
import { viewZToOrthographicDepth, reference, uniform, float, vec4, vec2, If, Fn, min, renderGroup, positionView, shadow } from 'three/tsl';
|
|
15
|
+
|
|
16
|
+
const _cameraToLightMatrix = new Matrix4();
|
|
17
|
+
const _lightSpaceFrustum = new CSMFrustum();
|
|
18
|
+
const _center = new Vector3();
|
|
19
|
+
const _bbox = new Box3();
|
|
20
|
+
const _uniformArray = [];
|
|
21
|
+
const _logArray = [];
|
|
22
|
+
const _lightDirection = new Vector3();
|
|
23
|
+
const _lightOrientationMatrix = new Matrix4();
|
|
24
|
+
const _lightOrientationMatrixInverse = new Matrix4();
|
|
25
|
+
const _up = new Vector3( 0, 1, 0 );
|
|
26
|
+
|
|
27
|
+
class LwLight extends Object3D {
|
|
28
|
+
|
|
29
|
+
constructor() {
|
|
30
|
+
|
|
31
|
+
super();
|
|
32
|
+
|
|
33
|
+
this.target = new Object3D();
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
class CSMShadowNode extends Node {
|
|
40
|
+
|
|
41
|
+
constructor( light, data = {} ) {
|
|
42
|
+
|
|
43
|
+
super();
|
|
44
|
+
|
|
45
|
+
this.light = light;
|
|
46
|
+
this.camera = null;
|
|
47
|
+
this.cascades = data.cascades || 3;
|
|
48
|
+
this.maxFar = data.maxFar || 100000;
|
|
49
|
+
this.mode = data.mode || 'practical';
|
|
50
|
+
this.lightMargin = data.lightMargin || 200;
|
|
51
|
+
this.customSplitsCallback = data.customSplitsCallback;
|
|
52
|
+
|
|
53
|
+
this.fade = false;
|
|
54
|
+
|
|
55
|
+
this.breaks = [];
|
|
56
|
+
|
|
57
|
+
this._cascades = [];
|
|
58
|
+
this.mainFrustum = null;
|
|
59
|
+
this.frustums = [];
|
|
60
|
+
this.updateBeforeType = NodeUpdateType.FRAME;
|
|
61
|
+
|
|
62
|
+
this.lights = [];
|
|
63
|
+
|
|
64
|
+
this._shadowNodes = [];
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
init( { camera, renderer } ) {
|
|
69
|
+
|
|
70
|
+
this.camera = camera;
|
|
71
|
+
|
|
72
|
+
const data = { webGL: renderer.coordinateSystem === WebGLCoordinateSystem };
|
|
73
|
+
this.mainFrustum = new CSMFrustum( data );
|
|
74
|
+
|
|
75
|
+
const light = this.light;
|
|
76
|
+
const parent = light.parent;
|
|
77
|
+
|
|
78
|
+
for ( let i = 0; i < this.cascades; i ++ ) {
|
|
79
|
+
|
|
80
|
+
const lwLight = new LwLight();
|
|
81
|
+
const lShadow = light.shadow.clone();
|
|
82
|
+
lShadow.bias = lShadow.bias * ( i + 1 );
|
|
83
|
+
|
|
84
|
+
this.lights.push( lwLight );
|
|
85
|
+
|
|
86
|
+
parent.add( lwLight );
|
|
87
|
+
parent.add( lwLight.target );
|
|
88
|
+
|
|
89
|
+
lwLight.shadow = lShadow;
|
|
90
|
+
|
|
91
|
+
this._shadowNodes.push( shadow( lwLight, lShadow ) );
|
|
92
|
+
|
|
93
|
+
this._cascades.push( new Vector2() );
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
this.updateFrustums();
|
|
98
|
+
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
initCascades() {
|
|
102
|
+
|
|
103
|
+
const camera = this.camera;
|
|
104
|
+
camera.updateProjectionMatrix();
|
|
105
|
+
|
|
106
|
+
this.mainFrustum.setFromProjectionMatrix( camera.projectionMatrix, this.maxFar );
|
|
107
|
+
this.mainFrustum.split( this.breaks, this.frustums );
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
getBreaks() {
|
|
112
|
+
|
|
113
|
+
const camera = this.camera;
|
|
114
|
+
const far = Math.min( camera.far, this.maxFar );
|
|
115
|
+
|
|
116
|
+
this.breaks.length = 0;
|
|
117
|
+
|
|
118
|
+
switch ( this.mode ) {
|
|
119
|
+
|
|
120
|
+
case 'uniform':
|
|
121
|
+
uniformSplit( this.cascades, camera.near, far, this.breaks );
|
|
122
|
+
break;
|
|
123
|
+
|
|
124
|
+
case 'logarithmic':
|
|
125
|
+
logarithmicSplit( this.cascades, camera.near, far, this.breaks );
|
|
126
|
+
break;
|
|
127
|
+
|
|
128
|
+
case 'practical':
|
|
129
|
+
practicalSplit( this.cascades, camera.near, far, 0.5, this.breaks );
|
|
130
|
+
break;
|
|
131
|
+
|
|
132
|
+
case 'custom':
|
|
133
|
+
if ( this.customSplitsCallback === undefined ) console.error( 'CSM: Custom split scheme callback not defined.' );
|
|
134
|
+
this.customSplitsCallback( this.cascades, camera.near, far, this.breaks );
|
|
135
|
+
break;
|
|
136
|
+
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function uniformSplit( amount, near, far, target ) {
|
|
140
|
+
|
|
141
|
+
for ( let i = 1; i < amount; i ++ ) {
|
|
142
|
+
|
|
143
|
+
target.push( ( near + ( far - near ) * i / amount ) / far );
|
|
144
|
+
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
target.push( 1 );
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function logarithmicSplit( amount, near, far, target ) {
|
|
152
|
+
|
|
153
|
+
for ( let i = 1; i < amount; i ++ ) {
|
|
154
|
+
|
|
155
|
+
target.push( ( near * ( far / near ) ** ( i / amount ) ) / far );
|
|
156
|
+
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
target.push( 1 );
|
|
160
|
+
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function practicalSplit( amount, near, far, lambda, target ) {
|
|
164
|
+
|
|
165
|
+
_uniformArray.length = 0;
|
|
166
|
+
_logArray.length = 0;
|
|
167
|
+
logarithmicSplit( amount, near, far, _logArray );
|
|
168
|
+
uniformSplit( amount, near, far, _uniformArray );
|
|
169
|
+
|
|
170
|
+
for ( let i = 1; i < amount; i ++ ) {
|
|
171
|
+
|
|
172
|
+
target.push( MathUtils.lerp( _uniformArray[ i - 1 ], _logArray[ i - 1 ], lambda ) );
|
|
173
|
+
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
target.push( 1 );
|
|
177
|
+
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
setLightBreaks() {
|
|
183
|
+
|
|
184
|
+
for ( let i = 0, l = this.cascades; i < l; i ++ ) {
|
|
185
|
+
|
|
186
|
+
const amount = this.breaks[ i ];
|
|
187
|
+
const prev = this.breaks[ i - 1 ] || 0;
|
|
188
|
+
|
|
189
|
+
this._cascades[ i ].set( prev, amount );
|
|
190
|
+
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
updateShadowBounds() {
|
|
196
|
+
|
|
197
|
+
const frustums = this.frustums;
|
|
198
|
+
|
|
199
|
+
for ( let i = 0; i < frustums.length; i ++ ) {
|
|
200
|
+
|
|
201
|
+
const shadowCam = this.lights[ i ].shadow.camera;
|
|
202
|
+
const frustum = this.frustums[ i ];
|
|
203
|
+
|
|
204
|
+
// Get the two points that represent that furthest points on the frustum assuming
|
|
205
|
+
// that's either the diagonal across the far plane or the diagonal across the whole
|
|
206
|
+
// frustum itself.
|
|
207
|
+
const nearVerts = frustum.vertices.near;
|
|
208
|
+
const farVerts = frustum.vertices.far;
|
|
209
|
+
const point1 = farVerts[ 0 ];
|
|
210
|
+
|
|
211
|
+
let point2;
|
|
212
|
+
|
|
213
|
+
if ( point1.distanceTo( farVerts[ 2 ] ) > point1.distanceTo( nearVerts[ 2 ] ) ) {
|
|
214
|
+
|
|
215
|
+
point2 = farVerts[ 2 ];
|
|
216
|
+
|
|
217
|
+
} else {
|
|
218
|
+
|
|
219
|
+
point2 = nearVerts[ 2 ];
|
|
220
|
+
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
let squaredBBWidth = point1.distanceTo( point2 );
|
|
224
|
+
|
|
225
|
+
if ( this.fade ) {
|
|
226
|
+
|
|
227
|
+
// expand the shadow extents by the fade margin if fade is enabled.
|
|
228
|
+
const camera = this.camera;
|
|
229
|
+
const far = Math.max( camera.far, this.maxFar );
|
|
230
|
+
const linearDepth = frustum.vertices.far[ 0 ].z / ( far - camera.near );
|
|
231
|
+
const margin = 0.25 * Math.pow( linearDepth, 2.0 ) * ( far - camera.near );
|
|
232
|
+
|
|
233
|
+
squaredBBWidth += margin;
|
|
234
|
+
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
shadowCam.left = - squaredBBWidth / 2;
|
|
238
|
+
shadowCam.right = squaredBBWidth / 2;
|
|
239
|
+
shadowCam.top = squaredBBWidth / 2;
|
|
240
|
+
shadowCam.bottom = - squaredBBWidth / 2;
|
|
241
|
+
shadowCam.updateProjectionMatrix();
|
|
242
|
+
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
updateFrustums() {
|
|
248
|
+
|
|
249
|
+
this.getBreaks();
|
|
250
|
+
this.initCascades();
|
|
251
|
+
this.updateShadowBounds();
|
|
252
|
+
this.setLightBreaks();
|
|
253
|
+
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
setupFade() {
|
|
257
|
+
|
|
258
|
+
const cameraNear = reference( 'camera.near', 'float', this ).setGroup( renderGroup );
|
|
259
|
+
const cascades = reference( '_cascades', 'vec2', this ).setGroup( renderGroup ).label( 'cacades' );
|
|
260
|
+
|
|
261
|
+
const shadowFar = uniform( 'float' ).setGroup( renderGroup ).label( 'shadowFar' )
|
|
262
|
+
.onRenderUpdate( () => Math.min( this.maxFar, this.camera.far ) );
|
|
263
|
+
|
|
264
|
+
const linearDepth = viewZToOrthographicDepth( positionView.z, cameraNear, shadowFar ).toVar( 'linearDepth' );
|
|
265
|
+
const lastCascade = this.cascades - 1;
|
|
266
|
+
|
|
267
|
+
return Fn( () => {
|
|
268
|
+
|
|
269
|
+
const ret = vec4( 1, 1, 1, 1 ).toVar( 'shadowValue' );
|
|
270
|
+
|
|
271
|
+
const cascade = vec2().toVar( 'cascade' );
|
|
272
|
+
const cascadeCenter = float().toVar( 'cascadeCenter' );
|
|
273
|
+
|
|
274
|
+
const margin = float().toVar( 'margin' );
|
|
275
|
+
|
|
276
|
+
const csmX = float().toVar( 'csmX' );
|
|
277
|
+
const csmY = float().toVar( 'csmY' );
|
|
278
|
+
|
|
279
|
+
for ( let i = 0; i < this.cascades; i ++ ) {
|
|
280
|
+
|
|
281
|
+
const isLastCascade = i === lastCascade;
|
|
282
|
+
|
|
283
|
+
cascade.assign( cascades.element( i ) );
|
|
284
|
+
|
|
285
|
+
cascadeCenter.assign( cascade.x.add( cascade.y ).div( 2.0 ) );
|
|
286
|
+
|
|
287
|
+
const closestEdge = linearDepth.lessThan( cascadeCenter ).select( cascade.x, cascade.y );
|
|
288
|
+
|
|
289
|
+
margin.assign( float( 0.25 ).mul( closestEdge.pow( 2.0 ) ) );
|
|
290
|
+
|
|
291
|
+
csmX.assign( cascade.x.sub( margin.div( 2.0 ) ) );
|
|
292
|
+
|
|
293
|
+
if ( isLastCascade ) {
|
|
294
|
+
|
|
295
|
+
csmY.assign( cascade.y );
|
|
296
|
+
|
|
297
|
+
} else {
|
|
298
|
+
|
|
299
|
+
csmY.assign( cascade.y.add( margin.div( 2.0 ) ) );
|
|
300
|
+
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const inRange = linearDepth.greaterThanEqual( csmX ).and( linearDepth.lessThanEqual( csmY ) );
|
|
304
|
+
|
|
305
|
+
If( inRange, () => {
|
|
306
|
+
|
|
307
|
+
const dist = min( linearDepth.sub( csmX ), csmY.sub( linearDepth ) ).toVar();
|
|
308
|
+
|
|
309
|
+
let ratio = dist.div( margin ).clamp( 0.0, 1.0 );
|
|
310
|
+
|
|
311
|
+
if ( i === 0 ) {
|
|
312
|
+
|
|
313
|
+
// dont fade at nearest edge
|
|
314
|
+
ratio = linearDepth.greaterThan( cascadeCenter ).select( ratio, 1 );
|
|
315
|
+
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
ret.subAssign( this._shadowNodes[ i ].oneMinus().mul( ratio ) );
|
|
319
|
+
|
|
320
|
+
} );
|
|
321
|
+
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return ret;
|
|
325
|
+
|
|
326
|
+
} )();
|
|
327
|
+
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
setupStandard() {
|
|
331
|
+
|
|
332
|
+
const cameraNear = reference( 'camera.near', 'float', this ).setGroup( renderGroup );
|
|
333
|
+
const cascades = reference( '_cascades', 'vec2', this ).setGroup( renderGroup ).label( 'cacades' );
|
|
334
|
+
|
|
335
|
+
const shadowFar = uniform( 'float' ).setGroup( renderGroup ).label( 'shadowFar' )
|
|
336
|
+
.onRenderUpdate( () => Math.min( this.maxFar, this.camera.far ) );
|
|
337
|
+
|
|
338
|
+
const linearDepth = viewZToOrthographicDepth( positionView.z, cameraNear, shadowFar ).toVar( 'linearDepth' );
|
|
339
|
+
|
|
340
|
+
return Fn( () => {
|
|
341
|
+
|
|
342
|
+
const ret = vec4( 1, 1, 1, 1 ).toVar( 'shadowValue' );
|
|
343
|
+
const cascade = vec2().toVar( 'cascade' );
|
|
344
|
+
|
|
345
|
+
for ( let i = 0; i < this.cascades; i ++ ) {
|
|
346
|
+
|
|
347
|
+
cascade.assign( cascades.element( i ) );
|
|
348
|
+
|
|
349
|
+
If( linearDepth.greaterThanEqual( cascade.x ).and( linearDepth.lessThanEqual( cascade.y ) ), () => {
|
|
350
|
+
|
|
351
|
+
ret.assign( this._shadowNodes[ i ] );
|
|
352
|
+
|
|
353
|
+
} );
|
|
354
|
+
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
return ret;
|
|
358
|
+
|
|
359
|
+
} )();
|
|
360
|
+
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
setup( builder ) {
|
|
364
|
+
|
|
365
|
+
if ( this.camera === null ) this.init( builder );
|
|
366
|
+
|
|
367
|
+
return this.fade === true ? this.setupFade() : this.setupStandard();
|
|
368
|
+
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
updateBefore( /*builder*/ ) {
|
|
372
|
+
|
|
373
|
+
const light = this.light;
|
|
374
|
+
const camera = this.camera;
|
|
375
|
+
const frustums = this.frustums;
|
|
376
|
+
|
|
377
|
+
_lightDirection.subVectors( light.target.position, light.position ).normalize();
|
|
378
|
+
|
|
379
|
+
// for each frustum we need to find its min-max box aligned with the light orientation
|
|
380
|
+
// the position in _lightOrientationMatrix does not matter, as we transform there and back
|
|
381
|
+
_lightOrientationMatrix.lookAt( light.position, light.target.position, _up );
|
|
382
|
+
_lightOrientationMatrixInverse.copy( _lightOrientationMatrix ).invert();
|
|
383
|
+
|
|
384
|
+
for ( let i = 0; i < frustums.length; i ++ ) {
|
|
385
|
+
|
|
386
|
+
const lwLight = this.lights[ i ];
|
|
387
|
+
const shadow = lwLight.shadow;
|
|
388
|
+
const shadowCam = shadow.camera;
|
|
389
|
+
const texelWidth = ( shadowCam.right - shadowCam.left ) / shadow.mapSize.width;
|
|
390
|
+
const texelHeight = ( shadowCam.top - shadowCam.bottom ) / shadow.mapSize.height;
|
|
391
|
+
|
|
392
|
+
_cameraToLightMatrix.multiplyMatrices( _lightOrientationMatrixInverse, camera.matrixWorld );
|
|
393
|
+
frustums[ i ].toSpace( _cameraToLightMatrix, _lightSpaceFrustum );
|
|
394
|
+
|
|
395
|
+
const nearVerts = _lightSpaceFrustum.vertices.near;
|
|
396
|
+
const farVerts = _lightSpaceFrustum.vertices.far;
|
|
397
|
+
|
|
398
|
+
_bbox.makeEmpty();
|
|
399
|
+
|
|
400
|
+
for ( let j = 0; j < 4; j ++ ) {
|
|
401
|
+
|
|
402
|
+
_bbox.expandByPoint( nearVerts[ j ] );
|
|
403
|
+
_bbox.expandByPoint( farVerts[ j ] );
|
|
404
|
+
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
_bbox.getCenter( _center );
|
|
408
|
+
_center.z = _bbox.max.z + this.lightMargin;
|
|
409
|
+
_center.x = Math.floor( _center.x / texelWidth ) * texelWidth;
|
|
410
|
+
_center.y = Math.floor( _center.y / texelHeight ) * texelHeight;
|
|
411
|
+
_center.applyMatrix4( _lightOrientationMatrix );
|
|
412
|
+
|
|
413
|
+
lwLight.position.copy( _center );
|
|
414
|
+
lwLight.target.position.copy( _center );
|
|
415
|
+
lwLight.target.position.add( _lightDirection );
|
|
416
|
+
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
dispose() {
|
|
422
|
+
|
|
423
|
+
for ( let i = 0; i < this.lights.length; i ++ ) {
|
|
424
|
+
|
|
425
|
+
const light = this.lights[ i ];
|
|
426
|
+
const parent = light.parent;
|
|
427
|
+
|
|
428
|
+
parent.remove( light.target );
|
|
429
|
+
parent.remove( light );
|
|
430
|
+
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
export { CSMShadowNode };
|
|
@@ -26,14 +26,17 @@ class NURBSCurve extends Curve {
|
|
|
26
26
|
|
|
27
27
|
super();
|
|
28
28
|
|
|
29
|
+
const knotsLength = knots ? knots.length - 1 : 0;
|
|
30
|
+
const pointsLength = controlPoints ? controlPoints.length : 0;
|
|
31
|
+
|
|
29
32
|
this.degree = degree;
|
|
30
33
|
this.knots = knots;
|
|
31
34
|
this.controlPoints = [];
|
|
32
35
|
// Used by periodic NURBS to remove hidden spans
|
|
33
36
|
this.startKnot = startKnot || 0;
|
|
34
|
-
this.endKnot = endKnot ||
|
|
37
|
+
this.endKnot = endKnot || knotsLength;
|
|
35
38
|
|
|
36
|
-
for ( let i = 0; i <
|
|
39
|
+
for ( let i = 0; i < pointsLength; ++ i ) {
|
|
37
40
|
|
|
38
41
|
// ensure Vector4 for control points
|
|
39
42
|
const point = controlPoints[ i ];
|
|
@@ -75,6 +78,34 @@ class NURBSCurve extends Curve {
|
|
|
75
78
|
|
|
76
79
|
}
|
|
77
80
|
|
|
81
|
+
toJSON() {
|
|
82
|
+
|
|
83
|
+
const data = super.toJSON();
|
|
84
|
+
|
|
85
|
+
data.degree = this.degree;
|
|
86
|
+
data.knots = [ ...this.knots ];
|
|
87
|
+
data.controlPoints = this.controlPoints.map( p => p.toArray() );
|
|
88
|
+
data.startKnot = this.startKnot;
|
|
89
|
+
data.endKnot = this.endKnot;
|
|
90
|
+
|
|
91
|
+
return data;
|
|
92
|
+
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
fromJSON( json ) {
|
|
96
|
+
|
|
97
|
+
super.fromJSON( json );
|
|
98
|
+
|
|
99
|
+
this.degree = json.degree;
|
|
100
|
+
this.knots = [ ...json.knots ];
|
|
101
|
+
this.controlPoints = json.controlPoints.map( p => new Vector4( p[ 0 ], p[ 1 ], p[ 2 ], p[ 3 ] ) );
|
|
102
|
+
this.startKnot = json.startKnot;
|
|
103
|
+
this.endKnot = json.endKnot;
|
|
104
|
+
|
|
105
|
+
return this;
|
|
106
|
+
|
|
107
|
+
}
|
|
108
|
+
|
|
78
109
|
}
|
|
79
110
|
|
|
80
|
-
export { NURBSCurve };
|
|
111
|
+
export { NURBSCurve };
|