@plastic-software/three 0.178.0 → 0.180.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 +950 -230
- package/build/three.core.js +754 -138
- package/build/three.core.min.js +1 -1
- package/build/three.module.js +197 -96
- package/build/three.module.min.js +1 -1
- package/build/three.tsl.js +99 -25
- package/build/three.tsl.min.js +1 -1
- package/build/three.webgpu.js +4586 -1499
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +4544 -1499
- package/build/three.webgpu.nodes.min.js +1 -1
- package/examples/jsm/Addons.js +2 -3
- package/examples/jsm/capabilities/WebGPU.js +1 -1
- package/examples/jsm/controls/ArcballControls.js +7 -7
- package/examples/jsm/controls/DragControls.js +6 -56
- package/examples/jsm/controls/FirstPersonControls.js +2 -2
- package/examples/jsm/controls/PointerLockControls.js +0 -8
- package/examples/jsm/csm/CSMShadowNode.js +4 -4
- package/examples/jsm/environments/RoomEnvironment.js +8 -3
- package/examples/jsm/exporters/GLTFExporter.js +30 -22
- package/examples/jsm/exporters/KTX2Exporter.js +4 -2
- package/examples/jsm/exporters/PLYExporter.js +1 -1
- 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/ktx-parse.module.js +1 -1
- package/examples/jsm/libs/meshopt_decoder.module.js +75 -58
- package/examples/jsm/lights/LightProbeGenerator.js +14 -3
- package/examples/jsm/lines/Line2.js +3 -3
- package/examples/jsm/lines/LineGeometry.js +1 -1
- package/examples/jsm/lines/LineSegments2.js +2 -2
- package/examples/jsm/lines/Wireframe.js +2 -2
- package/examples/jsm/lines/WireframeGeometry2.js +1 -1
- package/examples/jsm/lines/webgpu/LineSegments2.js +1 -1
- package/examples/jsm/lines/webgpu/Wireframe.js +1 -1
- package/examples/jsm/loaders/ColladaLoader.js +1 -1
- package/examples/jsm/loaders/EXRLoader.js +210 -22
- package/examples/jsm/loaders/FBXLoader.js +1 -1
- package/examples/jsm/loaders/GLTFLoader.js +9 -5
- package/examples/jsm/loaders/HDRCubeTextureLoader.js +5 -5
- package/examples/jsm/loaders/HDRLoader.js +486 -0
- package/examples/jsm/loaders/KTX2Loader.js +112 -32
- package/examples/jsm/loaders/MaterialXLoader.js +212 -30
- package/examples/jsm/loaders/RGBELoader.js +7 -473
- 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/UltraHDRLoader.js +1 -1
- package/examples/jsm/loaders/lwo/IFFParser.js +1 -1
- package/examples/jsm/loaders/usd/USDAParser.js +741 -0
- package/examples/jsm/loaders/usd/USDCParser.js +17 -0
- package/examples/jsm/materials/WoodNodeMaterial.js +533 -0
- package/examples/jsm/math/ColorSpaces.js +19 -1
- package/examples/jsm/math/ConvexHull.js +2 -2
- package/examples/jsm/math/Lut.js +2 -2
- package/examples/jsm/misc/MD2CharacterComplex.js +1 -1
- package/examples/jsm/misc/ProgressiveLightMap.js +1 -1
- package/examples/jsm/misc/Volume.js +1 -1
- package/examples/jsm/objects/LensflareMesh.js +3 -3
- package/examples/jsm/objects/SkyMesh.js +2 -2
- package/examples/jsm/physics/RapierPhysics.js +14 -5
- 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/postprocessing/SSRPass.js +37 -8
- package/examples/jsm/shaders/UnpackDepthRGBAShader.js +11 -2
- package/examples/jsm/transpiler/GLSLDecoder.js +23 -20
- package/examples/jsm/transpiler/TSLEncoder.js +2 -10
- package/examples/jsm/transpiler/WGSLEncoder.js +24 -0
- package/examples/jsm/tsl/display/AnamorphicNode.js +27 -4
- package/examples/jsm/tsl/display/BloomNode.js +7 -6
- package/examples/jsm/tsl/display/ChromaticAberrationNode.js +2 -1
- package/examples/jsm/tsl/display/DepthOfFieldNode.js +439 -90
- package/examples/jsm/tsl/display/GTAONode.js +8 -0
- package/examples/jsm/tsl/display/GaussianBlurNode.js +51 -41
- package/examples/jsm/tsl/display/OutlineNode.js +2 -2
- package/examples/jsm/tsl/display/SSRNode.js +180 -65
- package/examples/jsm/tsl/display/{TRAAPassNode.js → TRAANode.js} +181 -172
- package/examples/jsm/tsl/display/boxBlur.js +64 -0
- package/examples/jsm/tsl/display/hashBlur.js +15 -18
- package/examples/jsm/tsl/lighting/TiledLightsNode.js +1 -1
- package/examples/jsm/utils/BufferGeometryUtils.js +1 -1
- package/examples/jsm/utils/ShadowMapViewerGPU.js +12 -5
- package/examples/jsm/webxr/OculusHandModel.js +1 -1
- package/package.json +1 -1
- package/src/Three.Core.js +2 -0
- package/src/Three.TSL.js +98 -24
- package/src/animation/AnimationClip.js +17 -2
- 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 +11 -3
- package/src/core/BufferGeometry.js +2 -2
- package/{examples/jsm/misc → src/core}/Timer.js +4 -42
- package/src/extras/PMREMGenerator.js +11 -0
- package/src/extras/TextureUtils.js +2 -1
- package/src/extras/lib/earcut.js +1 -1
- 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/lights/webgpu/ProjectorLight.js +1 -1
- package/src/loaders/FileLoader.js +25 -2
- package/src/loaders/ImageBitmapLoader.js +23 -0
- package/src/loaders/Loader.js +14 -0
- package/src/loaders/LoadingManager.js +23 -0
- package/src/materials/Material.js +12 -0
- package/src/materials/MeshBasicMaterial.js +1 -1
- package/src/materials/MeshDistanceMaterial.js +1 -1
- package/src/materials/nodes/Line2NodeMaterial.js +0 -8
- package/src/materials/nodes/NodeMaterial.js +1 -1
- package/src/materials/nodes/PointsNodeMaterial.js +86 -28
- package/src/materials/nodes/SpriteNodeMaterial.js +3 -15
- package/src/materials/nodes/manager/NodeMaterialObserver.js +87 -2
- package/src/math/ColorManagement.js +7 -1
- package/src/math/Frustum.js +19 -8
- package/src/math/FrustumArray.js +10 -5
- package/src/math/Line3.js +129 -2
- package/src/math/Matrix4.js +48 -27
- package/src/math/Spherical.js +2 -2
- package/src/nodes/Nodes.js +4 -0
- package/src/nodes/TSL.js +4 -0
- package/src/nodes/accessors/BufferNode.js +1 -1
- package/src/nodes/accessors/Camera.js +142 -16
- package/src/nodes/accessors/ClippingNode.js +6 -5
- package/src/nodes/accessors/CubeTextureNode.js +2 -2
- package/src/nodes/accessors/InstanceNode.js +3 -1
- package/src/nodes/accessors/Normal.js +11 -11
- package/src/nodes/accessors/Object3DNode.js +1 -1
- package/src/nodes/accessors/ReferenceBaseNode.js +1 -1
- package/src/nodes/accessors/ReferenceNode.js +19 -4
- package/src/nodes/accessors/SceneNode.js +1 -1
- package/src/nodes/accessors/StorageTextureNode.js +1 -1
- package/src/nodes/accessors/Texture3DNode.js +13 -0
- package/src/nodes/accessors/TextureNode.js +83 -19
- package/src/nodes/code/FunctionCallNode.js +19 -0
- package/src/nodes/code/FunctionNode.js +23 -0
- package/src/nodes/core/ArrayNode.js +12 -0
- package/src/nodes/core/AssignNode.js +6 -2
- package/src/nodes/core/ContextNode.js +44 -1
- package/src/nodes/core/Node.js +30 -22
- package/src/nodes/core/NodeBuilder.js +71 -32
- package/src/nodes/core/NodeFrame.js +1 -1
- package/src/nodes/core/NodeUniform.js +1 -1
- package/src/nodes/core/NodeUtils.js +5 -3
- package/src/nodes/core/StackNode.js +71 -4
- package/src/nodes/core/StructNode.js +5 -5
- package/src/nodes/core/StructTypeNode.js +1 -0
- package/src/nodes/core/SubBuildNode.js +2 -2
- package/src/nodes/core/UniformNode.js +79 -14
- package/src/nodes/core/VarNode.js +83 -15
- package/src/nodes/display/FrontFacingNode.js +4 -8
- package/src/nodes/display/PassNode.js +148 -2
- package/src/nodes/display/ScreenNode.js +42 -13
- package/src/nodes/display/ViewportDepthTextureNode.js +16 -4
- package/src/nodes/display/ViewportSharedTextureNode.js +12 -0
- package/src/nodes/display/ViewportTextureNode.js +94 -4
- package/src/nodes/functions/PhysicalLightingModel.js +2 -2
- package/src/nodes/gpgpu/AtomicFunctionNode.js +1 -1
- package/src/nodes/gpgpu/ComputeNode.js +67 -23
- package/src/nodes/gpgpu/SubgroupFunctionNode.js +430 -0
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +28 -3
- package/src/nodes/lighting/LightsNode.js +1 -1
- package/src/nodes/lighting/ProjectorLightNode.js +19 -6
- package/src/nodes/lighting/ShadowFilterNode.js +1 -1
- package/src/nodes/materialx/MaterialXNodes.js +131 -2
- package/src/nodes/materialx/lib/mx_noise.js +165 -1
- package/src/nodes/math/BitcastNode.js +156 -0
- package/src/nodes/math/ConditionalNode.js +19 -3
- package/src/nodes/math/MathNode.js +72 -60
- package/src/nodes/math/OperatorNode.js +26 -25
- package/src/nodes/tsl/TSLCore.js +477 -142
- package/src/nodes/utils/DebugNode.js +1 -1
- package/src/nodes/utils/EventNode.js +83 -0
- package/src/nodes/utils/JoinNode.js +3 -1
- package/src/nodes/utils/MemberNode.js +58 -7
- package/src/nodes/utils/RTTNode.js +10 -1
- package/src/nodes/utils/ReflectorNode.js +51 -7
- package/src/nodes/utils/SampleNode.js +12 -2
- package/src/nodes/utils/SplitNode.js +11 -0
- package/src/nodes/utils/Timer.js +0 -47
- package/src/objects/BatchedMesh.js +6 -4
- package/src/objects/LOD.js +1 -1
- package/src/objects/Sprite.js +2 -2
- package/src/renderers/WebGLRenderer.js +21 -31
- package/src/renderers/common/Attributes.js +1 -1
- package/src/renderers/common/Backend.js +19 -1
- package/src/renderers/common/Bindings.js +21 -18
- package/src/renderers/common/ChainMap.js +1 -1
- package/src/renderers/common/Color4.js +2 -2
- package/src/renderers/common/DataMap.js +1 -1
- package/src/renderers/common/Pipelines.js +1 -1
- package/src/renderers/common/PostProcessing.js +60 -5
- package/src/renderers/common/RenderContext.js +2 -2
- package/src/renderers/common/RenderObject.js +14 -2
- package/src/renderers/common/Renderer.js +55 -32
- package/src/renderers/common/SampledTexture.js +4 -72
- package/src/renderers/common/Sampler.js +91 -0
- package/src/renderers/common/Storage3DTexture.js +21 -0
- package/src/renderers/common/StorageArrayTexture.js +21 -0
- package/src/renderers/common/StorageTexture.js +19 -0
- package/src/renderers/common/Textures.js +52 -14
- package/src/renderers/common/TimestampQueryPool.js +3 -3
- package/src/renderers/common/XRManager.js +51 -17
- package/src/renderers/common/nodes/NodeBuilderState.js +1 -1
- package/src/renderers/common/nodes/NodeLibrary.js +5 -5
- package/src/renderers/common/nodes/NodeSampledTexture.js +0 -12
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +21 -11
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +11 -2
- package/src/renderers/webgl/WebGLCapabilities.js +2 -2
- package/src/renderers/webgl/WebGLMaterials.js +6 -6
- package/src/renderers/webgl/WebGLProgram.js +24 -18
- package/src/renderers/webgl/WebGLPrograms.js +4 -4
- package/src/renderers/webgl/WebGLShadowMap.js +11 -1
- package/src/renderers/webgl/WebGLTextures.js +20 -7
- package/src/renderers/webgl/WebGLUtils.js +3 -2
- package/src/renderers/webgl-fallback/WebGLBackend.js +207 -146
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +112 -19
- package/src/renderers/webgl-fallback/utils/WebGLState.js +1 -1
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +52 -3
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +9 -10
- package/src/renderers/webgl-fallback/utils/WebGLUtils.js +3 -2
- package/src/renderers/webgpu/WebGPUBackend.js +87 -44
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +169 -99
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +35 -31
- package/src/renderers/webgpu/utils/WebGPUConstants.js +2 -2
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +10 -19
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +120 -84
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +3 -3
- package/src/renderers/webgpu/utils/WebGPUUtils.js +2 -17
- package/src/renderers/webxr/WebXRDepthSensing.js +6 -10
- package/src/renderers/webxr/WebXRManager.js +86 -11
- package/src/textures/ExternalTexture.js +56 -0
- package/src/textures/FramebufferTexture.js +2 -2
- package/src/textures/Source.js +12 -2
- package/src/textures/VideoTexture.js +27 -2
- package/examples/jsm/loaders/RGBMLoader.js +0 -1148
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Node from './Node.js';
|
|
2
|
-
import { addMethodChaining, nodeProxy } from '../tsl/TSLCore.js';
|
|
2
|
+
import { addMethodChaining, getCurrentStack, nodeProxy } from '../tsl/TSLCore.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Class for representing shader variables as nodes. Variables are created from
|
|
@@ -81,6 +81,45 @@ class VarNode extends Node {
|
|
|
81
81
|
*/
|
|
82
82
|
this.parents = true;
|
|
83
83
|
|
|
84
|
+
/**
|
|
85
|
+
* This flag is used to indicate that this node is used for intent.
|
|
86
|
+
*
|
|
87
|
+
* @type {boolean}
|
|
88
|
+
* @default false
|
|
89
|
+
*/
|
|
90
|
+
this.intent = false;
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Sets the intent flag for this node.
|
|
96
|
+
*
|
|
97
|
+
* This flag is used to indicate that this node is used for intent
|
|
98
|
+
* and should not be built directly. Instead, it is used to indicate that
|
|
99
|
+
* the node should be treated as a variable intent.
|
|
100
|
+
*
|
|
101
|
+
* It's useful for assigning variables without needing creating a new variable node.
|
|
102
|
+
*
|
|
103
|
+
* @param {boolean} value - The value to set for the intent flag.
|
|
104
|
+
* @returns {VarNode} This node.
|
|
105
|
+
*/
|
|
106
|
+
setIntent( value ) {
|
|
107
|
+
|
|
108
|
+
this.intent = value;
|
|
109
|
+
|
|
110
|
+
return this;
|
|
111
|
+
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Returns the intent flag of this node.
|
|
116
|
+
*
|
|
117
|
+
* @return {boolean} The intent flag.
|
|
118
|
+
*/
|
|
119
|
+
getIntent() {
|
|
120
|
+
|
|
121
|
+
return this.intent;
|
|
122
|
+
|
|
84
123
|
}
|
|
85
124
|
|
|
86
125
|
getMemberType( builder, name ) {
|
|
@@ -101,6 +140,31 @@ class VarNode extends Node {
|
|
|
101
140
|
|
|
102
141
|
}
|
|
103
142
|
|
|
143
|
+
getArrayCount( builder ) {
|
|
144
|
+
|
|
145
|
+
return this.node.getArrayCount( builder );
|
|
146
|
+
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
build( ...params ) {
|
|
150
|
+
|
|
151
|
+
if ( this.intent === true ) {
|
|
152
|
+
|
|
153
|
+
const builder = params[ 0 ];
|
|
154
|
+
const properties = builder.getNodeProperties( this );
|
|
155
|
+
|
|
156
|
+
if ( properties.assign !== true ) {
|
|
157
|
+
|
|
158
|
+
return this.node.build( ...params );
|
|
159
|
+
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return super.build( ...params );
|
|
165
|
+
|
|
166
|
+
}
|
|
167
|
+
|
|
104
168
|
generate( builder ) {
|
|
105
169
|
|
|
106
170
|
const { node, name, readOnly } = this;
|
|
@@ -138,7 +202,7 @@ class VarNode extends Node {
|
|
|
138
202
|
|
|
139
203
|
} else {
|
|
140
204
|
|
|
141
|
-
const count =
|
|
205
|
+
const count = node.getArrayCount( builder );
|
|
142
206
|
|
|
143
207
|
declarationPrefix = `const ${ builder.getVar( nodeVar.type, propertyName, count ) }`;
|
|
144
208
|
|
|
@@ -189,28 +253,32 @@ export const Var = ( node, name = null ) => createVar( node, name ).toStack();
|
|
|
189
253
|
*/
|
|
190
254
|
export const Const = ( node, name = null ) => createVar( node, name, true ).toStack();
|
|
191
255
|
|
|
192
|
-
//
|
|
193
|
-
|
|
194
|
-
addMethodChaining( 'toVar', Var );
|
|
195
|
-
addMethodChaining( 'toConst', Const );
|
|
196
|
-
|
|
197
|
-
// Deprecated
|
|
256
|
+
//
|
|
257
|
+
//
|
|
198
258
|
|
|
199
259
|
/**
|
|
260
|
+
* TSL function for creating a var intent node.
|
|
261
|
+
*
|
|
200
262
|
* @tsl
|
|
201
263
|
* @function
|
|
202
|
-
* @
|
|
203
|
-
*
|
|
204
|
-
* @param {any} node
|
|
264
|
+
* @param {Node} node - The node for which a variable should be created.
|
|
265
|
+
* @param {?string} name - The name of the variable in the shader.
|
|
205
266
|
* @returns {VarNode}
|
|
206
267
|
*/
|
|
207
|
-
export const
|
|
268
|
+
export const VarIntent = ( node ) => {
|
|
208
269
|
|
|
209
|
-
|
|
270
|
+
if ( getCurrentStack() === null ) {
|
|
210
271
|
|
|
211
|
-
|
|
272
|
+
return node;
|
|
273
|
+
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return createVar( node ).setIntent( true ).toStack();
|
|
212
277
|
|
|
213
278
|
};
|
|
214
279
|
|
|
215
|
-
|
|
280
|
+
// Method chaining
|
|
216
281
|
|
|
282
|
+
addMethodChaining( 'toVar', Var );
|
|
283
|
+
addMethodChaining( 'toConst', Const );
|
|
284
|
+
addMethodChaining( 'toVarIntent', VarIntent );
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Node from '../core/Node.js';
|
|
2
2
|
import { nodeImmutable, float, Fn } from '../tsl/TSLBase.js';
|
|
3
3
|
|
|
4
|
-
import { BackSide, DoubleSide
|
|
4
|
+
import { BackSide, DoubleSide } from '../../constants.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* This node can be used to evaluate whether a primitive is front or back facing.
|
|
@@ -40,15 +40,11 @@ class FrontFacingNode extends Node {
|
|
|
40
40
|
|
|
41
41
|
//
|
|
42
42
|
|
|
43
|
-
const {
|
|
43
|
+
const { material } = builder;
|
|
44
44
|
|
|
45
|
-
if (
|
|
45
|
+
if ( material.side === BackSide ) {
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return 'false';
|
|
50
|
-
|
|
51
|
-
}
|
|
47
|
+
return 'false';
|
|
52
48
|
|
|
53
49
|
}
|
|
54
50
|
|
|
@@ -7,6 +7,7 @@ import { viewZToOrthographicDepth, perspectiveDepthToViewZ } from './ViewportDep
|
|
|
7
7
|
|
|
8
8
|
import { HalfFloatType/*, FloatType*/ } from '../../constants.js';
|
|
9
9
|
import { Vector2 } from '../../math/Vector2.js';
|
|
10
|
+
import { Vector4 } from '../../math/Vector4.js';
|
|
10
11
|
import { DepthTexture } from '../../textures/DepthTexture.js';
|
|
11
12
|
import { RenderTarget } from '../../core/RenderTarget.js';
|
|
12
13
|
|
|
@@ -48,7 +49,7 @@ class PassTextureNode extends TextureNode {
|
|
|
48
49
|
|
|
49
50
|
setup( builder ) {
|
|
50
51
|
|
|
51
|
-
|
|
52
|
+
this.passNode.build( builder );
|
|
52
53
|
|
|
53
54
|
return super.setup( builder );
|
|
54
55
|
|
|
@@ -323,10 +324,43 @@ class PassNode extends TempNode {
|
|
|
323
324
|
*/
|
|
324
325
|
this._mrt = null;
|
|
325
326
|
|
|
327
|
+
/**
|
|
328
|
+
* Layer object for configuring the camera that is used
|
|
329
|
+
* to produce the pass.
|
|
330
|
+
*
|
|
331
|
+
* @private
|
|
332
|
+
* @type {?Layers}
|
|
333
|
+
* @default null
|
|
334
|
+
*/
|
|
326
335
|
this._layers = null;
|
|
327
336
|
|
|
337
|
+
/**
|
|
338
|
+
* Scales the resolution of the internal render target.
|
|
339
|
+
*
|
|
340
|
+
* @private
|
|
341
|
+
* @type {number}
|
|
342
|
+
* @default 1
|
|
343
|
+
*/
|
|
328
344
|
this._resolution = 1;
|
|
329
345
|
|
|
346
|
+
/**
|
|
347
|
+
* Custom viewport definition.
|
|
348
|
+
*
|
|
349
|
+
* @private
|
|
350
|
+
* @type {?Vector4}
|
|
351
|
+
* @default null
|
|
352
|
+
*/
|
|
353
|
+
this._viewport = null;
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Custom scissor definition.
|
|
357
|
+
*
|
|
358
|
+
* @private
|
|
359
|
+
* @type {?Vector4}
|
|
360
|
+
* @default null
|
|
361
|
+
*/
|
|
362
|
+
this._scissor = null;
|
|
363
|
+
|
|
330
364
|
/**
|
|
331
365
|
* This flag can be used for type testing.
|
|
332
366
|
*
|
|
@@ -374,7 +408,6 @@ class PassNode extends TempNode {
|
|
|
374
408
|
* Gets the current resolution of the pass.
|
|
375
409
|
*
|
|
376
410
|
* @return {number} The current resolution. A value of `1` means full resolution.
|
|
377
|
-
* @default 1
|
|
378
411
|
*/
|
|
379
412
|
getResolution() {
|
|
380
413
|
|
|
@@ -382,6 +415,12 @@ class PassNode extends TempNode {
|
|
|
382
415
|
|
|
383
416
|
}
|
|
384
417
|
|
|
418
|
+
/**
|
|
419
|
+
* Sets the layer configuration that should be used when rendering the pass.
|
|
420
|
+
*
|
|
421
|
+
* @param {Layers} layers - The layers object to set.
|
|
422
|
+
* @return {PassNode} A reference to this pass.
|
|
423
|
+
*/
|
|
385
424
|
setLayers( layers ) {
|
|
386
425
|
|
|
387
426
|
this._layers = layers;
|
|
@@ -390,6 +429,11 @@ class PassNode extends TempNode {
|
|
|
390
429
|
|
|
391
430
|
}
|
|
392
431
|
|
|
432
|
+
/**
|
|
433
|
+
* Gets the current layer configuration of the pass.
|
|
434
|
+
*
|
|
435
|
+
* @return {?Layers} .
|
|
436
|
+
*/
|
|
393
437
|
getLayers() {
|
|
394
438
|
|
|
395
439
|
return this._layers;
|
|
@@ -591,6 +635,32 @@ class PassNode extends TempNode {
|
|
|
591
635
|
|
|
592
636
|
}
|
|
593
637
|
|
|
638
|
+
/**
|
|
639
|
+
* Precompiles the pass.
|
|
640
|
+
*
|
|
641
|
+
* Note that this method must be called after the pass configuration is complete.
|
|
642
|
+
* So calls like `setMRT()` and `getTextureNode()` must proceed the precompilation.
|
|
643
|
+
*
|
|
644
|
+
* @async
|
|
645
|
+
* @param {Renderer} renderer - The renderer.
|
|
646
|
+
* @return {Promise} A Promise that resolves when the compile has been finished.
|
|
647
|
+
* @see {@link Renderer#compileAsync}
|
|
648
|
+
*/
|
|
649
|
+
async compileAsync( renderer ) {
|
|
650
|
+
|
|
651
|
+
const currentRenderTarget = renderer.getRenderTarget();
|
|
652
|
+
const currentMRT = renderer.getMRT();
|
|
653
|
+
|
|
654
|
+
renderer.setRenderTarget( this.renderTarget );
|
|
655
|
+
renderer.setMRT( this._mrt );
|
|
656
|
+
|
|
657
|
+
await renderer.compileAsync( this.scene, this.camera );
|
|
658
|
+
|
|
659
|
+
renderer.setRenderTarget( currentRenderTarget );
|
|
660
|
+
renderer.setMRT( currentMRT );
|
|
661
|
+
|
|
662
|
+
}
|
|
663
|
+
|
|
594
664
|
setup( { renderer } ) {
|
|
595
665
|
|
|
596
666
|
this.renderTarget.samples = this.options.samples === undefined ? renderer.samples : this.options.samples;
|
|
@@ -680,6 +750,82 @@ class PassNode extends TempNode {
|
|
|
680
750
|
|
|
681
751
|
this.renderTarget.setSize( effectiveWidth, effectiveHeight );
|
|
682
752
|
|
|
753
|
+
if ( this._scissor !== null ) this.renderTarget.scissor.copy( this._scissor );
|
|
754
|
+
if ( this._viewport !== null ) this.renderTarget.viewport.copy( this._viewport );
|
|
755
|
+
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* This method allows to define the pass's scissor rectangle. By default, the scissor rectangle is kept
|
|
760
|
+
* in sync with the pass's dimensions. To reverse the process and use auto-sizing again, call the method
|
|
761
|
+
* with `null` as the single argument.
|
|
762
|
+
*
|
|
763
|
+
* @param {?(number | Vector4)} x - The horizontal coordinate for the lower left corner of the box in logical pixel unit.
|
|
764
|
+
* Instead of passing four arguments, the method also works with a single four-dimensional vector.
|
|
765
|
+
* @param {number} y - The vertical coordinate for the lower left corner of the box in logical pixel unit.
|
|
766
|
+
* @param {number} width - The width of the scissor box in logical pixel unit.
|
|
767
|
+
* @param {number} height - The height of the scissor box in logical pixel unit.
|
|
768
|
+
*/
|
|
769
|
+
setScissor( x, y, width, height ) {
|
|
770
|
+
|
|
771
|
+
if ( x === null ) {
|
|
772
|
+
|
|
773
|
+
this._scissor = null;
|
|
774
|
+
|
|
775
|
+
} else {
|
|
776
|
+
|
|
777
|
+
if ( this._scissor === null ) this._scissor = new Vector4();
|
|
778
|
+
|
|
779
|
+
if ( x.isVector4 ) {
|
|
780
|
+
|
|
781
|
+
this._scissor.copy( x );
|
|
782
|
+
|
|
783
|
+
} else {
|
|
784
|
+
|
|
785
|
+
this._scissor.set( x, y, width, height );
|
|
786
|
+
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
this._scissor.multiplyScalar( this._pixelRatio * this._resolution ).floor();
|
|
790
|
+
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
/**
|
|
796
|
+
* This method allows to define the pass's viewport. By default, the viewport is kept in sync
|
|
797
|
+
* with the pass's dimensions. To reverse the process and use auto-sizing again, call the method
|
|
798
|
+
* with `null` as the single argument.
|
|
799
|
+
*
|
|
800
|
+
* @param {number | Vector4} x - The horizontal coordinate for the lower left corner of the viewport origin in logical pixel unit.
|
|
801
|
+
* @param {number} y - The vertical coordinate for the lower left corner of the viewport origin in logical pixel unit.
|
|
802
|
+
* @param {number} width - The width of the viewport in logical pixel unit.
|
|
803
|
+
* @param {number} height - The height of the viewport in logical pixel unit.
|
|
804
|
+
*/
|
|
805
|
+
setViewport( x, y, width, height ) {
|
|
806
|
+
|
|
807
|
+
if ( x === null ) {
|
|
808
|
+
|
|
809
|
+
this._viewport = null;
|
|
810
|
+
|
|
811
|
+
} else {
|
|
812
|
+
|
|
813
|
+
if ( this._viewport === null ) this._viewport = new Vector4();
|
|
814
|
+
|
|
815
|
+
if ( x.isVector4 ) {
|
|
816
|
+
|
|
817
|
+
this._viewport.copy( x );
|
|
818
|
+
|
|
819
|
+
} else {
|
|
820
|
+
|
|
821
|
+
this._viewport.set( x, y, width, height );
|
|
822
|
+
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
this._viewport.multiplyScalar( this._pixelRatio * this._resolution ).floor();
|
|
826
|
+
|
|
827
|
+
}
|
|
828
|
+
|
|
683
829
|
}
|
|
684
830
|
|
|
685
831
|
/**
|
|
@@ -6,7 +6,7 @@ import { Fn, nodeImmutable, vec2 } from '../tsl/TSLBase.js';
|
|
|
6
6
|
import { Vector2 } from '../../math/Vector2.js';
|
|
7
7
|
import { Vector4 } from '../../math/Vector4.js';
|
|
8
8
|
|
|
9
|
-
let
|
|
9
|
+
let _screenSizeVec, _viewportVec;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* This node provides a collection of screen related metrics.
|
|
@@ -26,7 +26,7 @@ class ScreenNode extends Node {
|
|
|
26
26
|
/**
|
|
27
27
|
* Constructs a new screen node.
|
|
28
28
|
*
|
|
29
|
-
* @param {('coordinate'|'viewport'|'size'|'uv')} scope - The node's scope.
|
|
29
|
+
* @param {('coordinate'|'viewport'|'size'|'uv'|'dpr')} scope - The node's scope.
|
|
30
30
|
*/
|
|
31
31
|
constructor( scope ) {
|
|
32
32
|
|
|
@@ -39,11 +39,20 @@ class ScreenNode extends Node {
|
|
|
39
39
|
* - `ScreenNode.VIEWPORT`: The current viewport defined as a four-dimensional vector.
|
|
40
40
|
* - `ScreenNode.SIZE`: The dimensions of the current bound framebuffer.
|
|
41
41
|
* - `ScreenNode.UV`: Normalized coordinates.
|
|
42
|
+
* - `ScreenNode.DPR`: Device pixel ratio.
|
|
42
43
|
*
|
|
43
|
-
* @type {('coordinate'|'viewport'|'size'|'uv')}
|
|
44
|
+
* @type {('coordinate'|'viewport'|'size'|'uv'|'dpr')}
|
|
44
45
|
*/
|
|
45
46
|
this.scope = scope;
|
|
46
47
|
|
|
48
|
+
/**
|
|
49
|
+
* This output node.
|
|
50
|
+
*
|
|
51
|
+
* @type {?Node}
|
|
52
|
+
* @default null
|
|
53
|
+
*/
|
|
54
|
+
this._output = null;
|
|
55
|
+
|
|
47
56
|
/**
|
|
48
57
|
* This flag can be used for type testing.
|
|
49
58
|
*
|
|
@@ -58,10 +67,11 @@ class ScreenNode extends Node {
|
|
|
58
67
|
/**
|
|
59
68
|
* This method is overwritten since the node type depends on the selected scope.
|
|
60
69
|
*
|
|
61
|
-
* @return {('vec2'|'vec4')} The node type.
|
|
70
|
+
* @return {('float'|'vec2'|'vec4')} The node type.
|
|
62
71
|
*/
|
|
63
72
|
getNodeType() {
|
|
64
73
|
|
|
74
|
+
if ( this.scope === ScreenNode.DPR ) return 'float';
|
|
65
75
|
if ( this.scope === ScreenNode.VIEWPORT ) return 'vec4';
|
|
66
76
|
else return 'vec2';
|
|
67
77
|
|
|
@@ -76,7 +86,7 @@ class ScreenNode extends Node {
|
|
|
76
86
|
|
|
77
87
|
let updateType = NodeUpdateType.NONE;
|
|
78
88
|
|
|
79
|
-
if ( this.scope === ScreenNode.SIZE || this.scope === ScreenNode.VIEWPORT ) {
|
|
89
|
+
if ( this.scope === ScreenNode.SIZE || this.scope === ScreenNode.VIEWPORT || this.scope === ScreenNode.DPR ) {
|
|
80
90
|
|
|
81
91
|
updateType = NodeUpdateType.RENDER;
|
|
82
92
|
|
|
@@ -102,26 +112,30 @@ class ScreenNode extends Node {
|
|
|
102
112
|
|
|
103
113
|
if ( renderTarget !== null ) {
|
|
104
114
|
|
|
105
|
-
|
|
115
|
+
_viewportVec.copy( renderTarget.viewport );
|
|
106
116
|
|
|
107
117
|
} else {
|
|
108
118
|
|
|
109
|
-
renderer.getViewport(
|
|
119
|
+
renderer.getViewport( _viewportVec );
|
|
110
120
|
|
|
111
|
-
|
|
121
|
+
_viewportVec.multiplyScalar( renderer.getPixelRatio() );
|
|
112
122
|
|
|
113
123
|
}
|
|
114
124
|
|
|
125
|
+
} else if ( this.scope === ScreenNode.DPR ) {
|
|
126
|
+
|
|
127
|
+
this._output.value = renderer.getPixelRatio();
|
|
128
|
+
|
|
115
129
|
} else {
|
|
116
130
|
|
|
117
131
|
if ( renderTarget !== null ) {
|
|
118
132
|
|
|
119
|
-
|
|
120
|
-
|
|
133
|
+
_screenSizeVec.width = renderTarget.width;
|
|
134
|
+
_screenSizeVec.height = renderTarget.height;
|
|
121
135
|
|
|
122
136
|
} else {
|
|
123
137
|
|
|
124
|
-
renderer.getDrawingBufferSize(
|
|
138
|
+
renderer.getDrawingBufferSize( _screenSizeVec );
|
|
125
139
|
|
|
126
140
|
}
|
|
127
141
|
|
|
@@ -137,11 +151,15 @@ class ScreenNode extends Node {
|
|
|
137
151
|
|
|
138
152
|
if ( scope === ScreenNode.SIZE ) {
|
|
139
153
|
|
|
140
|
-
output = uniform(
|
|
154
|
+
output = uniform( _screenSizeVec || ( _screenSizeVec = new Vector2() ) );
|
|
141
155
|
|
|
142
156
|
} else if ( scope === ScreenNode.VIEWPORT ) {
|
|
143
157
|
|
|
144
|
-
output = uniform(
|
|
158
|
+
output = uniform( _viewportVec || ( _viewportVec = new Vector4() ) );
|
|
159
|
+
|
|
160
|
+
} else if ( scope === ScreenNode.DPR ) {
|
|
161
|
+
|
|
162
|
+
output = uniform( 1 );
|
|
145
163
|
|
|
146
164
|
} else {
|
|
147
165
|
|
|
@@ -149,6 +167,8 @@ class ScreenNode extends Node {
|
|
|
149
167
|
|
|
150
168
|
}
|
|
151
169
|
|
|
170
|
+
this._output = output;
|
|
171
|
+
|
|
152
172
|
return output;
|
|
153
173
|
|
|
154
174
|
}
|
|
@@ -183,11 +203,20 @@ ScreenNode.COORDINATE = 'coordinate';
|
|
|
183
203
|
ScreenNode.VIEWPORT = 'viewport';
|
|
184
204
|
ScreenNode.SIZE = 'size';
|
|
185
205
|
ScreenNode.UV = 'uv';
|
|
206
|
+
ScreenNode.DPR = 'dpr';
|
|
186
207
|
|
|
187
208
|
export default ScreenNode;
|
|
188
209
|
|
|
189
210
|
// Screen
|
|
190
211
|
|
|
212
|
+
/**
|
|
213
|
+
* TSL object that represents the current DPR.
|
|
214
|
+
*
|
|
215
|
+
* @tsl
|
|
216
|
+
* @type {ScreenNode<float>}
|
|
217
|
+
*/
|
|
218
|
+
export const screenDPR = /*@__PURE__*/ nodeImmutable( ScreenNode, ScreenNode.DPR );
|
|
219
|
+
|
|
191
220
|
/**
|
|
192
221
|
* TSL object that represents normalized screen coordinates, unitless in `[0, 1]`.
|
|
193
222
|
*
|
|
@@ -4,7 +4,7 @@ import { screenUV } from './ScreenNode.js';
|
|
|
4
4
|
|
|
5
5
|
import { DepthTexture } from '../../textures/DepthTexture.js';
|
|
6
6
|
|
|
7
|
-
let
|
|
7
|
+
let _sharedDepthbuffer = null;
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Represents the depth of the current viewport as a texture. This module
|
|
@@ -29,13 +29,25 @@ class ViewportDepthTextureNode extends ViewportTextureNode {
|
|
|
29
29
|
*/
|
|
30
30
|
constructor( uvNode = screenUV, levelNode = null ) {
|
|
31
31
|
|
|
32
|
-
if (
|
|
32
|
+
if ( _sharedDepthbuffer === null ) {
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
_sharedDepthbuffer = new DepthTexture();
|
|
35
35
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
super( uvNode, levelNode,
|
|
38
|
+
super( uvNode, levelNode, _sharedDepthbuffer );
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Overwritten so the method always returns the unique shared
|
|
44
|
+
* depth texture.
|
|
45
|
+
*
|
|
46
|
+
* @return {DepthTexture} The shared depth texture.
|
|
47
|
+
*/
|
|
48
|
+
getTextureForReference() {
|
|
49
|
+
|
|
50
|
+
return _sharedDepthbuffer;
|
|
39
51
|
|
|
40
52
|
}
|
|
41
53
|
|
|
@@ -39,6 +39,18 @@ class ViewportSharedTextureNode extends ViewportTextureNode {
|
|
|
39
39
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Overwritten so the method always returns the unique shared
|
|
44
|
+
* framebuffer texture.
|
|
45
|
+
*
|
|
46
|
+
* @return {FramebufferTexture} The shared framebuffer texture.
|
|
47
|
+
*/
|
|
48
|
+
getTextureForReference() {
|
|
49
|
+
|
|
50
|
+
return _sharedFramebuffer;
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
42
54
|
updateReference() {
|
|
43
55
|
|
|
44
56
|
return this;
|
|
@@ -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
|
*
|
|
@@ -70,16 +88,88 @@ class ViewportTextureNode extends TextureNode {
|
|
|
70
88
|
*/
|
|
71
89
|
this.updateBeforeType = NodeUpdateType.FRAME;
|
|
72
90
|
|
|
91
|
+
/**
|
|
92
|
+
* The framebuffer texture for the current renderer context.
|
|
93
|
+
*
|
|
94
|
+
* @type {WeakMap<RenderTarget, FramebufferTexture>}
|
|
95
|
+
* @private
|
|
96
|
+
*/
|
|
97
|
+
this._cacheTextures = new WeakMap();
|
|
98
|
+
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* This methods returns a texture for the given render target reference.
|
|
103
|
+
*
|
|
104
|
+
* To avoid rendering errors, `ViewportTextureNode` must use unique framebuffer textures
|
|
105
|
+
* for different render contexts.
|
|
106
|
+
*
|
|
107
|
+
* @param {?RenderTarget} [reference=null] - The render target reference.
|
|
108
|
+
* @return {Texture} The framebuffer texture.
|
|
109
|
+
*/
|
|
110
|
+
getTextureForReference( reference = null ) {
|
|
111
|
+
|
|
112
|
+
let defaultFramebuffer;
|
|
113
|
+
let cacheTextures;
|
|
114
|
+
|
|
115
|
+
if ( this.referenceNode ) {
|
|
116
|
+
|
|
117
|
+
defaultFramebuffer = this.referenceNode.defaultFramebuffer;
|
|
118
|
+
cacheTextures = this.referenceNode._cacheTextures;
|
|
119
|
+
|
|
120
|
+
} else {
|
|
121
|
+
|
|
122
|
+
defaultFramebuffer = this.defaultFramebuffer;
|
|
123
|
+
cacheTextures = this._cacheTextures;
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if ( reference === null ) {
|
|
128
|
+
|
|
129
|
+
return defaultFramebuffer;
|
|
130
|
+
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if ( cacheTextures.has( reference ) === false ) {
|
|
134
|
+
|
|
135
|
+
const framebufferTexture = defaultFramebuffer.clone();
|
|
136
|
+
|
|
137
|
+
cacheTextures.set( reference, framebufferTexture );
|
|
138
|
+
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return cacheTextures.get( reference );
|
|
142
|
+
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
updateReference( frame ) {
|
|
146
|
+
|
|
147
|
+
const renderTarget = frame.renderer.getRenderTarget();
|
|
148
|
+
|
|
149
|
+
this.value = this.getTextureForReference( renderTarget );
|
|
150
|
+
|
|
151
|
+
return this.value;
|
|
152
|
+
|
|
73
153
|
}
|
|
74
154
|
|
|
75
155
|
updateBefore( frame ) {
|
|
76
156
|
|
|
77
157
|
const renderer = frame.renderer;
|
|
78
|
-
renderer.
|
|
158
|
+
const renderTarget = renderer.getRenderTarget();
|
|
159
|
+
|
|
160
|
+
if ( renderTarget === null ) {
|
|
161
|
+
|
|
162
|
+
renderer.getDrawingBufferSize( _size );
|
|
163
|
+
|
|
164
|
+
} else {
|
|
165
|
+
|
|
166
|
+
_size.set( renderTarget.width, renderTarget.height );
|
|
167
|
+
|
|
168
|
+
}
|
|
79
169
|
|
|
80
170
|
//
|
|
81
171
|
|
|
82
|
-
const framebufferTexture = this.
|
|
172
|
+
const framebufferTexture = this.getTextureForReference( renderTarget );
|
|
83
173
|
|
|
84
174
|
if ( framebufferTexture.image.width !== _size.width || framebufferTexture.image.height !== _size.height ) {
|
|
85
175
|
|