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
|
@@ -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,10 +253,35 @@ 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
|
|
|
256
|
+
//
|
|
257
|
+
//
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* TSL function for creating a var intent node.
|
|
261
|
+
*
|
|
262
|
+
* @tsl
|
|
263
|
+
* @function
|
|
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.
|
|
266
|
+
* @returns {VarNode}
|
|
267
|
+
*/
|
|
268
|
+
export const VarIntent = ( node ) => {
|
|
269
|
+
|
|
270
|
+
if ( getCurrentStack() === null ) {
|
|
271
|
+
|
|
272
|
+
return node;
|
|
273
|
+
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return createVar( node ).setIntent( true ).toStack();
|
|
277
|
+
|
|
278
|
+
};
|
|
279
|
+
|
|
192
280
|
// Method chaining
|
|
193
281
|
|
|
194
282
|
addMethodChaining( 'toVar', Var );
|
|
195
283
|
addMethodChaining( 'toConst', Const );
|
|
284
|
+
addMethodChaining( 'toVarIntent', VarIntent );
|
|
196
285
|
|
|
197
286
|
// Deprecated
|
|
198
287
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Node from './Node.js';
|
|
2
2
|
import { NodeShaderStage } from './constants.js';
|
|
3
3
|
import { addMethodChaining, nodeProxy } from '../tsl/TSLCore.js';
|
|
4
|
+
import { subBuild } from './SubBuildNode.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Class for representing shader varyings as nodes. Varyings are create from
|
|
@@ -131,7 +132,7 @@ class VaryingNode extends Node {
|
|
|
131
132
|
const interpolationSampling = this.interpolationSampling;
|
|
132
133
|
|
|
133
134
|
properties.varying = varying = builder.getVaryingFromNode( this, name, type, interpolationType, interpolationSampling );
|
|
134
|
-
properties.node = this.node;
|
|
135
|
+
properties.node = subBuild( this.node, 'VERTEX' );
|
|
135
136
|
|
|
136
137
|
}
|
|
137
138
|
|
|
@@ -160,18 +161,19 @@ class VaryingNode extends Node {
|
|
|
160
161
|
|
|
161
162
|
generate( builder ) {
|
|
162
163
|
|
|
164
|
+
const propertyKey = builder.getSubBuildProperty( 'property', builder.currentStack );
|
|
163
165
|
const properties = builder.getNodeProperties( this );
|
|
164
166
|
const varying = this.setupVarying( builder );
|
|
165
167
|
|
|
166
|
-
if ( properties
|
|
168
|
+
if ( properties[ propertyKey ] === undefined ) {
|
|
167
169
|
|
|
168
170
|
const type = this.getNodeType( builder );
|
|
169
171
|
const propertyName = builder.getPropertyName( varying, NodeShaderStage.VERTEX );
|
|
170
172
|
|
|
171
173
|
// force node run in vertex stage
|
|
172
|
-
builder.flowNodeFromShaderStage( NodeShaderStage.VERTEX,
|
|
174
|
+
builder.flowNodeFromShaderStage( NodeShaderStage.VERTEX, properties.node, type, propertyName );
|
|
173
175
|
|
|
174
|
-
properties
|
|
176
|
+
properties[ propertyKey ] = propertyName;
|
|
175
177
|
|
|
176
178
|
}
|
|
177
179
|
|
|
@@ -143,7 +143,7 @@ export const blendColor = /*@__PURE__*/ Fn( ( [ base, blend ] ) => {
|
|
|
143
143
|
* @param {Node<vec4>} color - The input color with non-premultiplied alpha.
|
|
144
144
|
* @return {Node<vec4>} The color with premultiplied alpha.
|
|
145
145
|
*/
|
|
146
|
-
export const
|
|
146
|
+
export const premultiplyAlpha = /*@__PURE__*/ Fn( ( [ color ] ) => {
|
|
147
147
|
|
|
148
148
|
return vec4( color.rgb.mul( color.a ), color.a );
|
|
149
149
|
|
|
@@ -162,7 +162,7 @@ export const premult = /*@__PURE__*/ Fn( ( [ color ] ) => {
|
|
|
162
162
|
* @param {Node<vec4>} color - The input color with premultiplied alpha.
|
|
163
163
|
* @return {Node<vec4>} The color with non-premultiplied alpha.
|
|
164
164
|
*/
|
|
165
|
-
export const
|
|
165
|
+
export const unpremultiplyAlpha = /*@__PURE__*/ Fn( ( [ color ] ) => {
|
|
166
166
|
|
|
167
167
|
If( color.a.equal( 0.0 ), () => vec4( 0.0 ) );
|
|
168
168
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Node from '../core/Node.js';
|
|
2
|
-
import { nodeImmutable, float } from '../tsl/TSLBase.js';
|
|
2
|
+
import { nodeImmutable, float, Fn } from '../tsl/TSLBase.js';
|
|
3
3
|
|
|
4
|
-
import { BackSide, WebGLCoordinateSystem } from '../../constants.js';
|
|
4
|
+
import { BackSide, DoubleSide, WebGLCoordinateSystem } from '../../constants.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* This node can be used to evaluate whether a primitive is front or back facing.
|
|
@@ -36,6 +36,10 @@ class FrontFacingNode extends Node {
|
|
|
36
36
|
|
|
37
37
|
generate( builder ) {
|
|
38
38
|
|
|
39
|
+
if ( builder.shaderStage !== 'fragment' ) return 'true';
|
|
40
|
+
|
|
41
|
+
//
|
|
42
|
+
|
|
39
43
|
const { renderer, material } = builder;
|
|
40
44
|
|
|
41
45
|
if ( renderer.coordinateSystem === WebGLCoordinateSystem ) {
|
|
@@ -72,3 +76,31 @@ export const frontFacing = /*@__PURE__*/ nodeImmutable( FrontFacingNode );
|
|
|
72
76
|
* @type {Node<float>}
|
|
73
77
|
*/
|
|
74
78
|
export const faceDirection = /*@__PURE__*/ float( frontFacing ).mul( 2.0 ).sub( 1.0 );
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Converts a direction vector to a face direction vector based on the material's side.
|
|
82
|
+
*
|
|
83
|
+
* If the material is set to `BackSide`, the direction is inverted.
|
|
84
|
+
* If the material is set to `DoubleSide`, the direction is multiplied by `faceDirection`.
|
|
85
|
+
*
|
|
86
|
+
* @tsl
|
|
87
|
+
* @param {Node<vec3>} direction - The direction vector to convert.
|
|
88
|
+
* @returns {Node<vec3>} The converted direction vector.
|
|
89
|
+
*/
|
|
90
|
+
export const directionToFaceDirection = /*@__PURE__*/ Fn( ( [ direction ], { material } ) => {
|
|
91
|
+
|
|
92
|
+
const side = material.side;
|
|
93
|
+
|
|
94
|
+
if ( side === BackSide ) {
|
|
95
|
+
|
|
96
|
+
direction = direction.mul( - 1.0 );
|
|
97
|
+
|
|
98
|
+
} else if ( side === DoubleSide ) {
|
|
99
|
+
|
|
100
|
+
direction = direction.mul( faceDirection );
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return direction;
|
|
105
|
+
|
|
106
|
+
} );
|
|
@@ -1,41 +1,11 @@
|
|
|
1
1
|
import TempNode from '../core/TempNode.js';
|
|
2
|
-
import { add } from '../math/OperatorNode.js';
|
|
3
2
|
|
|
4
3
|
import { normalView, transformNormalToView } from '../accessors/Normal.js';
|
|
5
|
-
import { positionView } from '../accessors/Position.js';
|
|
6
4
|
import { TBNViewMatrix } from '../accessors/AccessorsUtils.js';
|
|
7
|
-
import {
|
|
8
|
-
import { faceDirection } from './FrontFacingNode.js';
|
|
9
|
-
import { Fn, nodeProxy, vec3 } from '../tsl/TSLBase.js';
|
|
5
|
+
import { nodeProxy, vec3 } from '../tsl/TSLBase.js';
|
|
10
6
|
|
|
11
7
|
import { TangentSpaceNormalMap, ObjectSpaceNormalMap } from '../../constants.js';
|
|
12
|
-
|
|
13
|
-
// Normal Mapping Without Precomputed Tangents
|
|
14
|
-
// http://www.thetenthplanet.de/archives/1180
|
|
15
|
-
|
|
16
|
-
const perturbNormal2Arb = /*@__PURE__*/ Fn( ( inputs ) => {
|
|
17
|
-
|
|
18
|
-
const { eye_pos, surf_norm, mapN, uv } = inputs;
|
|
19
|
-
|
|
20
|
-
const q0 = eye_pos.dFdx();
|
|
21
|
-
const q1 = eye_pos.dFdy();
|
|
22
|
-
const st0 = uv.dFdx();
|
|
23
|
-
const st1 = uv.dFdy();
|
|
24
|
-
|
|
25
|
-
const N = surf_norm; // normalized
|
|
26
|
-
|
|
27
|
-
const q1perp = q1.cross( N );
|
|
28
|
-
const q0perp = N.cross( q0 );
|
|
29
|
-
|
|
30
|
-
const T = q1perp.mul( st0.x ).add( q0perp.mul( st1.x ) );
|
|
31
|
-
const B = q1perp.mul( st0.y ).add( q0perp.mul( st1.y ) );
|
|
32
|
-
|
|
33
|
-
const det = T.dot( T ).max( B.dot( B ) );
|
|
34
|
-
const scale = faceDirection.mul( det.inverseSqrt() );
|
|
35
|
-
|
|
36
|
-
return add( T.mul( mapN.x, scale ), B.mul( mapN.y, scale ), N.mul( mapN.z ) ).normalize();
|
|
37
|
-
|
|
38
|
-
} );
|
|
8
|
+
import { directionToFaceDirection } from './FrontFacingNode.js';
|
|
39
9
|
|
|
40
10
|
/**
|
|
41
11
|
* This class can be used for applying normals maps to materials.
|
|
@@ -89,7 +59,7 @@ class NormalMapNode extends TempNode {
|
|
|
89
59
|
|
|
90
60
|
}
|
|
91
61
|
|
|
92
|
-
setup(
|
|
62
|
+
setup( { material } ) {
|
|
93
63
|
|
|
94
64
|
const { normalMapType, scaleNode } = this;
|
|
95
65
|
|
|
@@ -97,38 +67,37 @@ class NormalMapNode extends TempNode {
|
|
|
97
67
|
|
|
98
68
|
if ( scaleNode !== null ) {
|
|
99
69
|
|
|
100
|
-
|
|
70
|
+
let scale = scaleNode;
|
|
71
|
+
|
|
72
|
+
if ( material.flatShading === true ) {
|
|
73
|
+
|
|
74
|
+
scale = directionToFaceDirection( scale );
|
|
75
|
+
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
normalMap = vec3( normalMap.xy.mul( scale ), normalMap.z );
|
|
101
79
|
|
|
102
80
|
}
|
|
103
81
|
|
|
104
|
-
let
|
|
82
|
+
let output = null;
|
|
105
83
|
|
|
106
84
|
if ( normalMapType === ObjectSpaceNormalMap ) {
|
|
107
85
|
|
|
108
|
-
|
|
86
|
+
output = transformNormalToView( normalMap );
|
|
109
87
|
|
|
110
88
|
} else if ( normalMapType === TangentSpaceNormalMap ) {
|
|
111
89
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if ( tangent === true ) {
|
|
90
|
+
output = TBNViewMatrix.mul( normalMap ).normalize();
|
|
115
91
|
|
|
116
|
-
|
|
92
|
+
} else {
|
|
117
93
|
|
|
118
|
-
|
|
94
|
+
console.error( `THREE.NodeMaterial: Unsupported normal map type: ${ normalMapType }` );
|
|
119
95
|
|
|
120
|
-
|
|
121
|
-
eye_pos: positionView,
|
|
122
|
-
surf_norm: normalView,
|
|
123
|
-
mapN: normalMap,
|
|
124
|
-
uv: uv()
|
|
125
|
-
} );
|
|
126
|
-
|
|
127
|
-
}
|
|
96
|
+
output = normalView; // Fallback to default normal view
|
|
128
97
|
|
|
129
98
|
}
|
|
130
99
|
|
|
131
|
-
return
|
|
100
|
+
return output;
|
|
132
101
|
|
|
133
102
|
}
|
|
134
103
|
|
|
@@ -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
|
|
|
@@ -126,7 +127,16 @@ class PassMultipleTextureNode extends PassTextureNode {
|
|
|
126
127
|
|
|
127
128
|
clone() {
|
|
128
129
|
|
|
129
|
-
|
|
130
|
+
const newNode = new this.constructor( this.passNode, this.textureName, this.previousTexture );
|
|
131
|
+
newNode.uvNode = this.uvNode;
|
|
132
|
+
newNode.levelNode = this.levelNode;
|
|
133
|
+
newNode.biasNode = this.biasNode;
|
|
134
|
+
newNode.sampler = this.sampler;
|
|
135
|
+
newNode.depthNode = this.depthNode;
|
|
136
|
+
newNode.compareNode = this.compareNode;
|
|
137
|
+
newNode.gradNode = this.gradNode;
|
|
138
|
+
|
|
139
|
+
return newNode;
|
|
130
140
|
|
|
131
141
|
}
|
|
132
142
|
|
|
@@ -314,10 +324,43 @@ class PassNode extends TempNode {
|
|
|
314
324
|
*/
|
|
315
325
|
this._mrt = null;
|
|
316
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
|
+
*/
|
|
317
335
|
this._layers = null;
|
|
318
336
|
|
|
337
|
+
/**
|
|
338
|
+
* Scales the resolution of the internal render target.
|
|
339
|
+
*
|
|
340
|
+
* @private
|
|
341
|
+
* @type {number}
|
|
342
|
+
* @default 1
|
|
343
|
+
*/
|
|
319
344
|
this._resolution = 1;
|
|
320
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
|
+
|
|
321
364
|
/**
|
|
322
365
|
* This flag can be used for type testing.
|
|
323
366
|
*
|
|
@@ -365,7 +408,6 @@ class PassNode extends TempNode {
|
|
|
365
408
|
* Gets the current resolution of the pass.
|
|
366
409
|
*
|
|
367
410
|
* @return {number} The current resolution. A value of `1` means full resolution.
|
|
368
|
-
* @default 1
|
|
369
411
|
*/
|
|
370
412
|
getResolution() {
|
|
371
413
|
|
|
@@ -373,6 +415,12 @@ class PassNode extends TempNode {
|
|
|
373
415
|
|
|
374
416
|
}
|
|
375
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
|
+
*/
|
|
376
424
|
setLayers( layers ) {
|
|
377
425
|
|
|
378
426
|
this._layers = layers;
|
|
@@ -381,6 +429,11 @@ class PassNode extends TempNode {
|
|
|
381
429
|
|
|
382
430
|
}
|
|
383
431
|
|
|
432
|
+
/**
|
|
433
|
+
* Gets the current layer configuration of the pass.
|
|
434
|
+
*
|
|
435
|
+
* @return {?Layers} .
|
|
436
|
+
*/
|
|
384
437
|
getLayers() {
|
|
385
438
|
|
|
386
439
|
return this._layers;
|
|
@@ -582,16 +635,35 @@ class PassNode extends TempNode {
|
|
|
582
635
|
|
|
583
636
|
}
|
|
584
637
|
|
|
585
|
-
|
|
638
|
+
/**
|
|
639
|
+
* Precompiles the pass.
|
|
640
|
+
*
|
|
641
|
+
* Note that this method must be called after the pass configuartion 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 ) {
|
|
586
650
|
|
|
587
|
-
|
|
651
|
+
const currentRenderTarget = renderer.getRenderTarget();
|
|
652
|
+
const currentMRT = renderer.getMRT();
|
|
588
653
|
|
|
589
|
-
|
|
590
|
-
|
|
654
|
+
renderer.setRenderTarget( this.renderTarget );
|
|
655
|
+
renderer.setMRT( this._mrt );
|
|
591
656
|
|
|
592
|
-
|
|
657
|
+
await renderer.compileAsync( this.scene, this.camera );
|
|
593
658
|
|
|
594
|
-
|
|
659
|
+
renderer.setRenderTarget( currentRenderTarget );
|
|
660
|
+
renderer.setMRT( currentMRT );
|
|
661
|
+
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
setup( { renderer } ) {
|
|
665
|
+
|
|
666
|
+
this.renderTarget.samples = this.options.samples === undefined ? renderer.samples : this.options.samples;
|
|
595
667
|
|
|
596
668
|
this.renderTarget.texture.type = renderer.getColorBufferType();
|
|
597
669
|
|
|
@@ -678,6 +750,82 @@ class PassNode extends TempNode {
|
|
|
678
750
|
|
|
679
751
|
this.renderTarget.setSize( effectiveWidth, effectiveHeight );
|
|
680
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
|
+
|
|
681
829
|
}
|
|
682
830
|
|
|
683
831
|
/**
|
|
@@ -258,29 +258,3 @@ export const viewportResolution = /*@__PURE__*/ ( Fn( () => { // @deprecated, r1
|
|
|
258
258
|
return screenSize;
|
|
259
259
|
|
|
260
260
|
}, 'vec2' ).once() )();
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* @tsl
|
|
264
|
-
* @deprecated since r168. Use {@link screenUV} instead.
|
|
265
|
-
* @type {Node<vec2>}
|
|
266
|
-
*/
|
|
267
|
-
export const viewportTopLeft = /*@__PURE__*/ ( Fn( () => { // @deprecated, r168
|
|
268
|
-
|
|
269
|
-
console.warn( 'THREE.TSL: "viewportTopLeft" is deprecated. Use "screenUV" instead.' );
|
|
270
|
-
|
|
271
|
-
return screenUV;
|
|
272
|
-
|
|
273
|
-
}, 'vec2' ).once() )();
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* @tsl
|
|
277
|
-
* @deprecated since r168. Use `screenUV.flipY()` instead.
|
|
278
|
-
* @type {Node<vec2>}
|
|
279
|
-
*/
|
|
280
|
-
export const viewportBottomLeft = /*@__PURE__*/ ( Fn( () => { // @deprecated, r168
|
|
281
|
-
|
|
282
|
-
console.warn( 'THREE.TSL: "viewportBottomLeft" is deprecated. Use "screenUV.flipY()" instead.' );
|
|
283
|
-
|
|
284
|
-
return screenUV.flipY();
|
|
285
|
-
|
|
286
|
-
}, 'vec2' ).once() )();
|