super-three 0.154.1 → 0.156.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/build/three.cjs +360 -160
- package/build/three.js +360 -160
- package/build/three.min.js +1 -1
- package/build/three.module.js +355 -161
- package/build/three.module.min.js +1 -1
- package/examples/jsm/controls/OrbitControls.js +155 -25
- package/examples/jsm/csm/CSMShader.js +35 -1
- package/examples/jsm/environments/RoomEnvironment.js +1 -1
- package/examples/jsm/exporters/USDZExporter.js +1 -0
- package/examples/jsm/interactive/SelectionHelper.js +7 -0
- package/examples/jsm/libs/tween.module.js +790 -735
- package/examples/jsm/libs/utif.module.js +1644 -1558
- package/examples/jsm/loaders/DDSLoader.js +46 -3
- package/examples/jsm/loaders/EXRLoader.js +4 -4
- package/examples/jsm/loaders/FBXLoader.js +3 -1
- package/examples/jsm/loaders/GLTFLoader.js +25 -10
- package/examples/jsm/loaders/KTX2Loader.js +128 -79
- package/examples/jsm/loaders/LDrawLoader.js +1 -1
- package/examples/jsm/loaders/LogLuvLoader.js +2 -2
- package/examples/jsm/loaders/MMDLoader.js +10 -7
- package/examples/jsm/loaders/NRRDLoader.js +3 -3
- package/examples/jsm/loaders/PLYLoader.js +1 -1
- package/examples/jsm/loaders/RGBELoader.js +48 -66
- package/examples/jsm/loaders/STLLoader.js +7 -0
- package/examples/jsm/loaders/TGALoader.js +10 -10
- package/examples/jsm/loaders/VRMLLoader.js +1 -1
- package/examples/jsm/misc/GPUComputationRenderer.js +0 -9
- package/examples/jsm/misc/Volume.js +4 -6
- package/examples/jsm/nodes/Nodes.js +8 -6
- package/examples/jsm/nodes/accessors/BufferAttributeNode.js +29 -3
- package/examples/jsm/nodes/accessors/CubeTextureNode.js +20 -3
- package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +15 -4
- package/examples/jsm/nodes/accessors/InstanceNode.js +8 -8
- package/examples/jsm/nodes/accessors/LineMaterialNode.js +31 -0
- package/examples/jsm/nodes/accessors/MaterialNode.js +73 -61
- package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +3 -0
- package/examples/jsm/nodes/accessors/Object3DNode.js +2 -2
- package/examples/jsm/nodes/accessors/SceneNode.js +6 -0
- package/examples/jsm/nodes/accessors/TextureNode.js +54 -9
- package/examples/jsm/nodes/accessors/TextureStoreNode.js +29 -0
- package/examples/jsm/nodes/core/AttributeNode.js +2 -2
- package/examples/jsm/nodes/core/LightingModel.js +7 -9
- package/examples/jsm/nodes/core/Node.js +28 -3
- package/examples/jsm/nodes/core/NodeBuilder.js +94 -12
- package/examples/jsm/nodes/core/NodeUniform.js +1 -1
- package/examples/jsm/nodes/core/OutputStructNode.js +58 -0
- package/examples/jsm/nodes/core/PropertyNode.js +6 -0
- package/examples/jsm/nodes/core/StackNode.js +4 -4
- package/examples/jsm/nodes/core/StructTypeNode.js +24 -0
- package/examples/jsm/nodes/display/BumpMapNode.js +77 -0
- package/examples/jsm/nodes/display/NormalMapNode.js +2 -2
- package/examples/jsm/nodes/display/ViewportNode.js +19 -5
- package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +10 -2
- package/examples/jsm/nodes/functions/BSDF/Schlick_to_F0.js +13 -0
- package/examples/jsm/nodes/functions/PhongLightingModel.js +53 -14
- package/examples/jsm/nodes/functions/PhysicalLightingModel.js +236 -97
- package/examples/jsm/nodes/geometry/RangeNode.js +2 -2
- package/examples/jsm/nodes/gpgpu/ComputeNode.js +13 -0
- package/examples/jsm/nodes/lighting/AONode.js +1 -1
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +58 -20
- package/examples/jsm/nodes/lighting/DirectionalLightNode.js +7 -10
- package/examples/jsm/nodes/lighting/EnvironmentNode.js +22 -12
- package/examples/jsm/nodes/lighting/HemisphereLightNode.js +1 -1
- package/examples/jsm/nodes/lighting/LightingContextNode.js +12 -9
- package/examples/jsm/nodes/lighting/PointLightNode.js +7 -10
- package/examples/jsm/nodes/lighting/SpotLightNode.js +7 -10
- package/examples/jsm/nodes/materials/LineDashedNodeMaterial.js +54 -0
- package/examples/jsm/nodes/materials/Materials.js +2 -0
- package/examples/jsm/nodes/materials/MeshLambertNodeMaterial.js +34 -0
- package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +2 -0
- package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +2 -2
- package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +19 -2
- package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +2 -2
- package/examples/jsm/nodes/materials/NodeMaterial.js +61 -26
- package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +2 -2
- package/examples/jsm/nodes/math/HashNode.js +35 -0
- package/examples/jsm/nodes/shadernode/ShaderNode.js +6 -2
- package/examples/jsm/nodes/utils/SplitNode.js +1 -1
- package/examples/jsm/objects/Reflector.js +1 -9
- package/examples/jsm/objects/Refractor.js +0 -8
- package/examples/jsm/offscreen/scene.js +0 -1
- package/examples/jsm/postprocessing/FilmPass.js +3 -5
- package/examples/jsm/postprocessing/MaskPass.js +4 -1
- package/examples/jsm/postprocessing/OutputPass.js +33 -14
- package/examples/jsm/postprocessing/RenderPass.js +30 -12
- package/examples/jsm/postprocessing/SAOPass.js +23 -98
- package/examples/jsm/postprocessing/SSAOPass.js +10 -30
- package/examples/jsm/postprocessing/UnrealBloomPass.js +21 -17
- package/examples/jsm/renderers/common/Backend.js +11 -8
- package/examples/jsm/renderers/common/Background.js +22 -20
- package/examples/jsm/renderers/common/Binding.js +14 -0
- package/examples/jsm/renderers/common/Bindings.js +7 -10
- package/examples/jsm/renderers/common/Geometries.js +1 -1
- package/examples/jsm/renderers/common/Pipelines.js +96 -47
- package/examples/jsm/renderers/common/RenderContext.js +1 -0
- package/examples/jsm/renderers/common/RenderContexts.js +41 -5
- package/examples/jsm/renderers/common/RenderList.js +12 -4
- package/examples/jsm/renderers/common/RenderObject.js +26 -6
- package/examples/jsm/renderers/common/RenderObjects.js +10 -7
- package/examples/jsm/renderers/common/Renderer.js +82 -42
- package/examples/jsm/renderers/common/SampledTexture.js +2 -1
- package/examples/jsm/renderers/common/Sampler.js +1 -1
- package/examples/jsm/renderers/common/StorageBuffer.js +1 -1
- package/examples/jsm/renderers/common/Textures.js +172 -20
- package/examples/jsm/renderers/common/nodes/NodeSampledTexture.js +2 -2
- package/examples/jsm/renderers/common/nodes/NodeSampler.js +1 -1
- package/examples/jsm/renderers/common/nodes/Nodes.js +58 -13
- package/examples/jsm/renderers/webgl/WebGLBackend.js +607 -0
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +118 -17
- package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +84 -0
- package/examples/jsm/renderers/webgl/utils/WebGLExtensions.js +26 -0
- package/examples/jsm/renderers/webgl/utils/WebGLState.js +529 -0
- package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +199 -0
- package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +242 -0
- package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +340 -0
- package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/WebGLNodeBuilder.js +1 -1
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +320 -84
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +18 -2
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +120 -66
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js +2 -2
- package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +55 -36
- package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +96 -5
- package/examples/jsm/renderers/webgpu/utils/WebGPUConstants.js +24 -22
- package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +117 -139
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +60 -142
- package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +7 -6
- package/examples/jsm/shaders/FilmShader.js +11 -54
- package/examples/jsm/shaders/OutputShader.js +19 -2
- package/examples/jsm/shaders/SAOShader.js +0 -13
- package/examples/jsm/shaders/SSAOShader.js +33 -26
- package/examples/jsm/utils/BufferGeometryUtils.js +13 -4
- package/examples/jsm/webxr/OculusHandPointerModel.js +2 -2
- package/package.json +2 -2
- package/src/Three.js +3 -0
- package/src/animation/PropertyBinding.js +1 -1
- package/src/audio/Audio.js +6 -0
- package/src/cameras/CubeCamera.js +1 -4
- package/src/constants.js +4 -1
- package/src/core/BufferAttribute.js +20 -0
- package/src/core/Object3D.js +2 -15
- package/src/core/RenderTarget.js +122 -0
- package/src/core/UniformsGroup.js +2 -2
- package/src/geometries/CapsuleGeometry.js +1 -1
- package/src/loaders/DataTextureLoader.js +19 -2
- package/src/materials/Material.js +2 -2
- package/src/math/Vector2.js +2 -2
- package/src/math/Vector3.js +3 -3
- package/src/math/Vector4.js +4 -4
- package/src/objects/Line.js +1 -1
- package/src/objects/Mesh.js +1 -1
- package/src/objects/Points.js +1 -1
- package/src/renderers/WebGLMultipleRenderTargets.js +0 -2
- package/src/renderers/WebGLRenderTarget.js +3 -110
- package/src/renderers/WebGLRenderer.js +83 -57
- package/src/renderers/shaders/ShaderChunk/iridescence_fragment.glsl.js +1 -2
- package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +11 -1
- package/src/renderers/shaders/ShaderLib/background.glsl.js +8 -0
- package/src/renderers/webgl/WebGLBackground.js +5 -14
- package/src/renderers/webgl/WebGLGeometries.js +5 -1
- package/src/renderers/webgl/WebGLMaterials.js +1 -1
- package/src/renderers/webgl/WebGLProgram.js +2 -0
- package/src/renderers/webgl/WebGLPrograms.js +19 -3
- package/src/renderers/webgl/WebGLTextures.js +101 -16
- package/src/renderers/webgl/WebGLUtils.js +27 -20
- package/src/textures/CompressedCubeTexture.js +19 -0
- package/src/textures/Texture.js +2 -2
- package/src/utils.js +9 -1
- package/examples/jsm/nodes/functions/BSDF/BRDF_BlinnPhong.js +0 -30
- package/examples/jsm/renderers/common/RenderTarget.js +0 -15
- package/examples/jsm/renderers/common/nodes/NodeRender.js +0 -302
- /package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/SlotNode.js +0 -0
- /package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/WebGLNodes.js +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EventDispatcher } from 'three';
|
|
1
2
|
import { NodeUpdateType } from './constants.js';
|
|
2
3
|
import { getNodeChildren, getCacheKey } from './NodeUtils.js';
|
|
3
4
|
import { MathUtils } from 'three';
|
|
@@ -6,11 +7,11 @@ const NodeClasses = new Map();
|
|
|
6
7
|
|
|
7
8
|
let _nodeId = 0;
|
|
8
9
|
|
|
9
|
-
class Node {
|
|
10
|
+
class Node extends EventDispatcher {
|
|
10
11
|
|
|
11
12
|
constructor( nodeType = null ) {
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
super();
|
|
14
15
|
|
|
15
16
|
this.nodeType = nodeType;
|
|
16
17
|
|
|
@@ -19,6 +20,8 @@ class Node {
|
|
|
19
20
|
|
|
20
21
|
this.uuid = MathUtils.generateUUID();
|
|
21
22
|
|
|
23
|
+
this.isNode = true;
|
|
24
|
+
|
|
22
25
|
Object.defineProperty( this, 'id', { value: _nodeId ++ } );
|
|
23
26
|
|
|
24
27
|
}
|
|
@@ -29,6 +32,14 @@ class Node {
|
|
|
29
32
|
|
|
30
33
|
}
|
|
31
34
|
|
|
35
|
+
getSelf() {
|
|
36
|
+
|
|
37
|
+
// Returns non-node object.
|
|
38
|
+
|
|
39
|
+
return this.self || this;
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
32
43
|
isGlobal( /*builder*/ ) {
|
|
33
44
|
|
|
34
45
|
return false;
|
|
@@ -52,6 +63,12 @@ class Node {
|
|
|
52
63
|
|
|
53
64
|
}
|
|
54
65
|
|
|
66
|
+
dispose() {
|
|
67
|
+
|
|
68
|
+
this.dispatchEvent( { type: 'dispose' } );
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
|
|
55
72
|
traverse( callback, replaceNode = null ) {
|
|
56
73
|
|
|
57
74
|
callback( this, replaceNode );
|
|
@@ -88,7 +105,15 @@ class Node {
|
|
|
88
105
|
|
|
89
106
|
}
|
|
90
107
|
|
|
91
|
-
getNodeType(
|
|
108
|
+
getNodeType( builder ) {
|
|
109
|
+
|
|
110
|
+
const nodeProperties = builder.getNodeProperties( this );
|
|
111
|
+
|
|
112
|
+
if ( nodeProperties.outputNode ) {
|
|
113
|
+
|
|
114
|
+
return nodeProperties.outputNode.getNodeType( builder );
|
|
115
|
+
|
|
116
|
+
}
|
|
92
117
|
|
|
93
118
|
return this.nodeType;
|
|
94
119
|
|
|
@@ -8,11 +8,18 @@ import NodeCache from './NodeCache.js';
|
|
|
8
8
|
import { createNodeMaterialFromType } from '../materials/NodeMaterial.js';
|
|
9
9
|
import { NodeUpdateType, defaultBuildStages, shaderStages } from './constants.js';
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
FloatNodeUniform, Vector2NodeUniform, Vector3NodeUniform, Vector4NodeUniform,
|
|
13
|
+
ColorNodeUniform, Matrix3NodeUniform, Matrix4NodeUniform
|
|
14
|
+
} from '../../renderers/common/nodes/NodeUniform.js';
|
|
15
|
+
|
|
16
|
+
import { REVISION, RenderTarget, NoColorSpace, LinearEncoding, sRGBEncoding, SRGBColorSpace, Color, Vector2, Vector3, Vector4, Float16BufferAttribute } from 'three';
|
|
12
17
|
|
|
13
18
|
import { stack } from './StackNode.js';
|
|
14
19
|
import { maxMipLevel } from '../utils/MaxMipLevelNode.js';
|
|
15
20
|
|
|
21
|
+
import CubeRenderTarget from '../../renderers/common/CubeRenderTarget.js';
|
|
22
|
+
|
|
16
23
|
const typeFromLength = new Map( [
|
|
17
24
|
[ 2, 'vec2' ],
|
|
18
25
|
[ 3, 'vec3' ],
|
|
@@ -69,6 +76,7 @@ class NodeBuilder {
|
|
|
69
76
|
this.flowNodes = { vertex: [], fragment: [], compute: [] };
|
|
70
77
|
this.flowCode = { vertex: '', fragment: '', compute: [] };
|
|
71
78
|
this.uniforms = { vertex: [], fragment: [], compute: [], index: 0 };
|
|
79
|
+
this.structs = { vertex: [], fragment: [], compute: [], index: 0 };
|
|
72
80
|
this.codes = { vertex: [], fragment: [], compute: [] };
|
|
73
81
|
this.bindings = { vertex: [], fragment: [], compute: [] };
|
|
74
82
|
this.bindingsOffset = { vertex: 0, fragment: 0, compute: 0 };
|
|
@@ -98,12 +106,38 @@ class NodeBuilder {
|
|
|
98
106
|
|
|
99
107
|
}
|
|
100
108
|
|
|
109
|
+
getRenderTarget( width, height, options ) {
|
|
110
|
+
|
|
111
|
+
return new RenderTarget( width, height, options );
|
|
112
|
+
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
getCubeRenderTarget( size, options ) {
|
|
116
|
+
|
|
117
|
+
return new CubeRenderTarget( size, options );
|
|
118
|
+
|
|
119
|
+
}
|
|
120
|
+
|
|
101
121
|
includes( node ) {
|
|
102
122
|
|
|
103
123
|
return this.nodes.includes( node );
|
|
104
124
|
|
|
105
125
|
}
|
|
106
126
|
|
|
127
|
+
createBindings() {
|
|
128
|
+
|
|
129
|
+
const bindingsArray = [];
|
|
130
|
+
|
|
131
|
+
for ( const binding of this.getBindings() ) {
|
|
132
|
+
|
|
133
|
+
bindingsArray.push( binding.clone() );
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return bindingsArray;
|
|
138
|
+
|
|
139
|
+
}
|
|
140
|
+
|
|
107
141
|
getBindings() {
|
|
108
142
|
|
|
109
143
|
let bindingsArray = this.bindingsArray;
|
|
@@ -128,14 +162,26 @@ class NodeBuilder {
|
|
|
128
162
|
|
|
129
163
|
addNode( node ) {
|
|
130
164
|
|
|
131
|
-
if ( this.nodes.
|
|
165
|
+
if ( this.nodes.includes( node ) === false ) {
|
|
166
|
+
|
|
167
|
+
this.nodes.push( node );
|
|
168
|
+
|
|
169
|
+
this.setHashNode( node, node.getHash( this ) );
|
|
170
|
+
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
buildUpdateNodes() {
|
|
176
|
+
|
|
177
|
+
for ( const node of this.nodes ) {
|
|
132
178
|
|
|
133
179
|
const updateType = node.getUpdateType();
|
|
134
180
|
const updateBeforeType = node.getUpdateBeforeType();
|
|
135
181
|
|
|
136
182
|
if ( updateType !== NodeUpdateType.NONE ) {
|
|
137
183
|
|
|
138
|
-
this.updateNodes.push( node );
|
|
184
|
+
this.updateNodes.push( node.getSelf() );
|
|
139
185
|
|
|
140
186
|
}
|
|
141
187
|
|
|
@@ -145,10 +191,6 @@ class NodeBuilder {
|
|
|
145
191
|
|
|
146
192
|
}
|
|
147
193
|
|
|
148
|
-
this.nodes.push( node );
|
|
149
|
-
|
|
150
|
-
this.setHashNode( node, node.getHash( this ) );
|
|
151
|
-
|
|
152
194
|
}
|
|
153
195
|
|
|
154
196
|
}
|
|
@@ -331,6 +373,8 @@ class NodeBuilder {
|
|
|
331
373
|
|
|
332
374
|
getType( type ) {
|
|
333
375
|
|
|
376
|
+
if ( type === 'color' ) return 'vec3';
|
|
377
|
+
|
|
334
378
|
return type;
|
|
335
379
|
|
|
336
380
|
}
|
|
@@ -561,17 +605,19 @@ class NodeBuilder {
|
|
|
561
605
|
|
|
562
606
|
if ( nodeData === undefined ) {
|
|
563
607
|
|
|
564
|
-
nodeData = {
|
|
608
|
+
nodeData = {};
|
|
565
609
|
|
|
566
610
|
cache.setNodeData( node, nodeData );
|
|
567
611
|
|
|
568
612
|
}
|
|
569
613
|
|
|
570
|
-
|
|
614
|
+
if ( nodeData[ shaderStage ] === undefined ) nodeData[ shaderStage ] = {};
|
|
615
|
+
|
|
616
|
+
return nodeData[ shaderStage ];
|
|
571
617
|
|
|
572
618
|
}
|
|
573
619
|
|
|
574
|
-
getNodeProperties( node, shaderStage =
|
|
620
|
+
getNodeProperties( node, shaderStage = 'any' ) {
|
|
575
621
|
|
|
576
622
|
const nodeData = this.getDataFromNode( node, shaderStage );
|
|
577
623
|
|
|
@@ -601,6 +647,27 @@ class NodeBuilder {
|
|
|
601
647
|
|
|
602
648
|
}
|
|
603
649
|
|
|
650
|
+
getStructTypeFromNode( node, shaderStage = this.shaderStage, name = null ) {
|
|
651
|
+
|
|
652
|
+
const nodeData = this.getDataFromNode( node, shaderStage );
|
|
653
|
+
|
|
654
|
+
let nodeStruct = nodeData.structType;
|
|
655
|
+
|
|
656
|
+
if ( nodeStruct === undefined ) {
|
|
657
|
+
|
|
658
|
+
const index = this.structs.index ++;
|
|
659
|
+
|
|
660
|
+
node.name = `StructType${index}`;
|
|
661
|
+
this.structs[ shaderStage ].push( node );
|
|
662
|
+
|
|
663
|
+
nodeData.structType = node;
|
|
664
|
+
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
return node;
|
|
668
|
+
|
|
669
|
+
}
|
|
670
|
+
|
|
604
671
|
getUniformFromNode( node, type, shaderStage = this.shaderStage, name = null ) {
|
|
605
672
|
|
|
606
673
|
const nodeData = this.getDataFromNode( node, shaderStage );
|
|
@@ -648,7 +715,7 @@ class NodeBuilder {
|
|
|
648
715
|
|
|
649
716
|
getVaryingFromNode( node, type ) {
|
|
650
717
|
|
|
651
|
-
const nodeData = this.getDataFromNode( node,
|
|
718
|
+
const nodeData = this.getDataFromNode( node, 'any' );
|
|
652
719
|
|
|
653
720
|
let nodeVarying = nodeData.varying;
|
|
654
721
|
|
|
@@ -812,7 +879,7 @@ class NodeBuilder {
|
|
|
812
879
|
|
|
813
880
|
getVar( type, name ) {
|
|
814
881
|
|
|
815
|
-
return `${type} ${name}`;
|
|
882
|
+
return `${ this.getType( type ) } ${ name }`;
|
|
816
883
|
|
|
817
884
|
}
|
|
818
885
|
|
|
@@ -936,11 +1003,26 @@ class NodeBuilder {
|
|
|
936
1003
|
// stage 4: build code for a specific output
|
|
937
1004
|
|
|
938
1005
|
this.buildCode();
|
|
1006
|
+
this.buildUpdateNodes();
|
|
939
1007
|
|
|
940
1008
|
return this;
|
|
941
1009
|
|
|
942
1010
|
}
|
|
943
1011
|
|
|
1012
|
+
getNodeUniform( uniformNode, type ) {
|
|
1013
|
+
|
|
1014
|
+
if ( type === 'float' ) return new FloatNodeUniform( uniformNode );
|
|
1015
|
+
if ( type === 'vec2' ) return new Vector2NodeUniform( uniformNode );
|
|
1016
|
+
if ( type === 'vec3' ) return new Vector3NodeUniform( uniformNode );
|
|
1017
|
+
if ( type === 'vec4' ) return new Vector4NodeUniform( uniformNode );
|
|
1018
|
+
if ( type === 'color' ) return new ColorNodeUniform( uniformNode );
|
|
1019
|
+
if ( type === 'mat3' ) return new Matrix3NodeUniform( uniformNode );
|
|
1020
|
+
if ( type === 'mat4' ) return new Matrix4NodeUniform( uniformNode );
|
|
1021
|
+
|
|
1022
|
+
throw new Error( `Uniform "${type}" not declared.` );
|
|
1023
|
+
|
|
1024
|
+
}
|
|
1025
|
+
|
|
944
1026
|
createNodeMaterial( type ) {
|
|
945
1027
|
|
|
946
1028
|
return createNodeMaterialFromType( type );
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import Node, { addNodeClass } from './Node.js';
|
|
2
|
+
import StructTypeNode from './StructTypeNode.js';
|
|
3
|
+
import { nodeProxy } from '../shadernode/ShaderNode.js';
|
|
4
|
+
|
|
5
|
+
class OutputStructNode extends Node {
|
|
6
|
+
|
|
7
|
+
constructor( ...members ) {
|
|
8
|
+
|
|
9
|
+
super();
|
|
10
|
+
|
|
11
|
+
this.isOutputStructNode = true;
|
|
12
|
+
this.members = members;
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
construct( builder ) {
|
|
17
|
+
|
|
18
|
+
super.construct( builder );
|
|
19
|
+
|
|
20
|
+
const members = this.members;
|
|
21
|
+
const types = [];
|
|
22
|
+
|
|
23
|
+
for ( let i = 0; i < members.length; i++ ) {
|
|
24
|
+
|
|
25
|
+
types.push( members[ i ].getNodeType( builder ) );
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
this.nodeType = builder.getStructTypeFromNode( new StructTypeNode( types ) ).name;
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
generate( builder, output ) {
|
|
34
|
+
|
|
35
|
+
const nodeVar = builder.getVarFromNode( this, this.nodeType );
|
|
36
|
+
const propertyName = builder.getPropertyName( nodeVar );
|
|
37
|
+
|
|
38
|
+
const members = this.members;
|
|
39
|
+
|
|
40
|
+
for ( let i = 0; i < members.length; i++ ) {
|
|
41
|
+
|
|
42
|
+
const snippet = members[ i ].build( builder, output );
|
|
43
|
+
|
|
44
|
+
builder.addLineFlowCode( `${propertyName}.m${i} = ${snippet}` );
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return propertyName;
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default OutputStructNode;
|
|
55
|
+
|
|
56
|
+
export const outputStruct = nodeProxy( OutputStructNode );
|
|
57
|
+
|
|
58
|
+
addNodeClass( OutputStructNode );
|
|
@@ -51,7 +51,13 @@ export const clearcoat = nodeImmutable( PropertyNode, 'float', 'Clearcoat' );
|
|
|
51
51
|
export const clearcoatRoughness = nodeImmutable( PropertyNode, 'float', 'ClearcoatRoughness' );
|
|
52
52
|
export const sheen = nodeImmutable( PropertyNode, 'vec3', 'Sheen' );
|
|
53
53
|
export const sheenRoughness = nodeImmutable( PropertyNode, 'float', 'SheenRoughness' );
|
|
54
|
+
export const iridescence = nodeImmutable( PropertyNode, 'float', 'Iridescence' );
|
|
55
|
+
export const iridescenceIOR = nodeImmutable( PropertyNode, 'float', 'IridescenceIOR' );
|
|
56
|
+
export const iridescenceThickness = nodeImmutable( PropertyNode, 'float', 'IridescenceThickness' );
|
|
54
57
|
export const specularColor = nodeImmutable( PropertyNode, 'color', 'SpecularColor' );
|
|
55
58
|
export const shininess = nodeImmutable( PropertyNode, 'float', 'Shininess' );
|
|
59
|
+
export const output = nodeImmutable( PropertyNode, 'vec4', 'Output' );
|
|
60
|
+
export const dashSize = nodeImmutable( PropertyNode, 'float', 'dashScale' );
|
|
61
|
+
export const gapSize= nodeImmutable( PropertyNode, 'float', 'gapSize' );
|
|
56
62
|
|
|
57
63
|
addNodeClass( PropertyNode );
|
|
@@ -4,7 +4,7 @@ import { bypass } from '../core/BypassNode.js';
|
|
|
4
4
|
import { expression } from '../code/ExpressionNode.js';
|
|
5
5
|
import { cond } from '../math/CondNode.js';
|
|
6
6
|
import { loop } from '../utils/LoopNode.js';
|
|
7
|
-
import {
|
|
7
|
+
import { ShaderNode, nodeProxy } from '../shadernode/ShaderNode.js';
|
|
8
8
|
|
|
9
9
|
class StackNode extends Node {
|
|
10
10
|
|
|
@@ -39,7 +39,7 @@ class StackNode extends Node {
|
|
|
39
39
|
|
|
40
40
|
if( boolNode, method ) {
|
|
41
41
|
|
|
42
|
-
const methodNode =
|
|
42
|
+
const methodNode = new ShaderNode( method );
|
|
43
43
|
this._currentCond = cond( boolNode, methodNode );
|
|
44
44
|
|
|
45
45
|
return this.add( this._currentCond );
|
|
@@ -48,7 +48,7 @@ class StackNode extends Node {
|
|
|
48
48
|
|
|
49
49
|
elseif( boolNode, method ) {
|
|
50
50
|
|
|
51
|
-
const methodNode =
|
|
51
|
+
const methodNode = new ShaderNode( method );
|
|
52
52
|
const ifNode = cond( boolNode, methodNode );
|
|
53
53
|
|
|
54
54
|
this._currentCond.elseNode = ifNode;
|
|
@@ -60,7 +60,7 @@ class StackNode extends Node {
|
|
|
60
60
|
|
|
61
61
|
else( method ) {
|
|
62
62
|
|
|
63
|
-
this._currentCond.elseNode =
|
|
63
|
+
this._currentCond.elseNode = new ShaderNode( method );
|
|
64
64
|
|
|
65
65
|
return this;
|
|
66
66
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import Node, { addNodeClass } from './Node.js';
|
|
2
|
+
|
|
3
|
+
class StructTypeNode extends Node {
|
|
4
|
+
|
|
5
|
+
constructor( types ) {
|
|
6
|
+
|
|
7
|
+
super();
|
|
8
|
+
|
|
9
|
+
this.types = types;
|
|
10
|
+
this.isStructTypeNode = true;
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getMemberTypes() {
|
|
15
|
+
|
|
16
|
+
return this.types;
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default StructTypeNode;
|
|
23
|
+
|
|
24
|
+
addNodeClass( StructTypeNode );
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import TempNode from '../core/TempNode.js';
|
|
2
|
+
import { texture } from '../accessors/TextureNode.js';
|
|
3
|
+
import { addNodeClass } from '../core/Node.js';
|
|
4
|
+
import { uv } from '../accessors/UVNode.js';
|
|
5
|
+
import { normalView } from '../accessors/NormalNode.js';
|
|
6
|
+
import { positionView } from '../accessors/PositionNode.js';
|
|
7
|
+
import { faceDirection } from './FrontFacingNode.js';
|
|
8
|
+
import { tslFn, nodeProxy, vec2 } from '../shadernode/ShaderNode.js';
|
|
9
|
+
|
|
10
|
+
// Bump Mapping Unparametrized Surfaces on the GPU by Morten S. Mikkelsen
|
|
11
|
+
// https://mmikk.github.io/papers3d/mm_sfgrad_bump.pdf
|
|
12
|
+
|
|
13
|
+
// Evaluate the derivative of the height w.r.t. screen-space using forward differencing (listing 2)
|
|
14
|
+
|
|
15
|
+
const dHdxy_fwd = tslFn( ( { bumpTexture, bumpScale } ) => {
|
|
16
|
+
|
|
17
|
+
const uvNode = uv();
|
|
18
|
+
|
|
19
|
+
const Hll = texture( bumpTexture, uvNode ).x;
|
|
20
|
+
|
|
21
|
+
return vec2(
|
|
22
|
+
texture( bumpTexture, uvNode.add( uvNode.dFdx() ) ).x.sub( Hll ),
|
|
23
|
+
texture( bumpTexture, uvNode.add( uvNode.dFdy() ) ).x.sub( Hll )
|
|
24
|
+
).mul( bumpScale );
|
|
25
|
+
|
|
26
|
+
} );
|
|
27
|
+
|
|
28
|
+
const perturbNormalArb = tslFn( ( inputs ) => {
|
|
29
|
+
|
|
30
|
+
const { surf_pos, surf_norm, dHdxy } = inputs;
|
|
31
|
+
|
|
32
|
+
const vSigmaX = surf_pos.dFdx();
|
|
33
|
+
const vSigmaY = surf_pos.dFdy();
|
|
34
|
+
const vN = surf_norm; // normalized
|
|
35
|
+
|
|
36
|
+
const R1 = vSigmaY.cross( vN );
|
|
37
|
+
const R2 = vN.cross( vSigmaX );
|
|
38
|
+
|
|
39
|
+
const fDet = vSigmaX.dot( R1 ).mul( faceDirection );
|
|
40
|
+
|
|
41
|
+
const vGrad = fDet.sign().mul( dHdxy.x.mul( R1 ).add( dHdxy.y.mul( R2 ) ) );
|
|
42
|
+
|
|
43
|
+
return fDet.abs().mul( surf_norm ).sub( vGrad ).normalize();
|
|
44
|
+
|
|
45
|
+
} );
|
|
46
|
+
|
|
47
|
+
class BumpMapNode extends TempNode {
|
|
48
|
+
|
|
49
|
+
constructor( texture, scaleNode = null ) {
|
|
50
|
+
|
|
51
|
+
super( 'vec3' );
|
|
52
|
+
|
|
53
|
+
this.texture = texture;
|
|
54
|
+
this.scaleNode = scaleNode;
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
construct() {
|
|
59
|
+
|
|
60
|
+
const bumpScale = this.scaleNode !== null ? this.scaleNode : 1;
|
|
61
|
+
const dHdxy = dHdxy_fwd( { bumpTexture: this.texture, bumpScale } );
|
|
62
|
+
|
|
63
|
+
return perturbNormalArb( {
|
|
64
|
+
surf_pos: positionView.negate(),
|
|
65
|
+
surf_norm: normalView,
|
|
66
|
+
dHdxy
|
|
67
|
+
} );
|
|
68
|
+
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export default BumpMapNode;
|
|
74
|
+
|
|
75
|
+
export const bumpMap = nodeProxy( BumpMapNode );
|
|
76
|
+
|
|
77
|
+
addNodeClass( BumpMapNode );
|
|
@@ -15,7 +15,7 @@ import { TangentSpaceNormalMap, ObjectSpaceNormalMap } from 'three';
|
|
|
15
15
|
// Normal Mapping Without Precomputed Tangents
|
|
16
16
|
// http://www.thetenthplanet.de/archives/1180
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const perturbNormal2Arb = tslFn( ( inputs ) => {
|
|
19
19
|
|
|
20
20
|
const { eye_pos, surf_norm, mapN, uv } = inputs;
|
|
21
21
|
|
|
@@ -80,7 +80,7 @@ class NormalMapNode extends TempNode {
|
|
|
80
80
|
|
|
81
81
|
} else {
|
|
82
82
|
|
|
83
|
-
outputNode =
|
|
83
|
+
outputNode = perturbNormal2Arb( {
|
|
84
84
|
eye_pos: positionView,
|
|
85
85
|
surf_norm: normalView,
|
|
86
86
|
mapN: normalMap,
|
|
@@ -3,9 +3,9 @@ import { NodeUpdateType } from '../core/constants.js';
|
|
|
3
3
|
import { uniform } from '../core/UniformNode.js';
|
|
4
4
|
import { nodeImmutable, vec2 } from '../shadernode/ShaderNode.js';
|
|
5
5
|
|
|
6
|
-
import { Vector2 } from 'three';
|
|
6
|
+
import { Vector2, Vector4 } from 'three';
|
|
7
7
|
|
|
8
|
-
let resolution;
|
|
8
|
+
let resolution, viewportResult;
|
|
9
9
|
|
|
10
10
|
class ViewportNode extends Node {
|
|
11
11
|
|
|
@@ -21,7 +21,7 @@ class ViewportNode extends Node {
|
|
|
21
21
|
|
|
22
22
|
getNodeType() {
|
|
23
23
|
|
|
24
|
-
return this.scope === ViewportNode.COORDINATE ? 'vec4' : 'vec2';
|
|
24
|
+
return this.scope === ViewportNode.COORDINATE || this.scope === ViewportNode.VIEWPORT ? 'vec4' : 'vec2';
|
|
25
25
|
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -29,7 +29,7 @@ class ViewportNode extends Node {
|
|
|
29
29
|
|
|
30
30
|
let updateType = NodeUpdateType.NONE;
|
|
31
31
|
|
|
32
|
-
if ( this.scope === ViewportNode.RESOLUTION ) {
|
|
32
|
+
if ( this.scope === ViewportNode.RESOLUTION || this.scope === ViewportNode.VIEWPORT ) {
|
|
33
33
|
|
|
34
34
|
updateType = NodeUpdateType.FRAME;
|
|
35
35
|
|
|
@@ -43,7 +43,15 @@ class ViewportNode extends Node {
|
|
|
43
43
|
|
|
44
44
|
update( { renderer } ) {
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
if ( this.scope === ViewportNode.VIEWPORT ) {
|
|
47
|
+
|
|
48
|
+
renderer.getViewport( viewportResult );
|
|
49
|
+
|
|
50
|
+
} else {
|
|
51
|
+
|
|
52
|
+
renderer.getDrawingBufferSize( resolution );
|
|
53
|
+
|
|
54
|
+
}
|
|
47
55
|
|
|
48
56
|
}
|
|
49
57
|
|
|
@@ -59,6 +67,10 @@ class ViewportNode extends Node {
|
|
|
59
67
|
|
|
60
68
|
output = uniform( resolution || ( resolution = new Vector2() ) );
|
|
61
69
|
|
|
70
|
+
} else if ( scope === ViewportNode.VIEWPORT ) {
|
|
71
|
+
|
|
72
|
+
output = uniform( viewportResult || ( viewportResult = new Vector4() ) );
|
|
73
|
+
|
|
62
74
|
} else {
|
|
63
75
|
|
|
64
76
|
const coordinateNode = vec2( new ViewportNode( ViewportNode.COORDINATE ) );
|
|
@@ -98,6 +110,7 @@ class ViewportNode extends Node {
|
|
|
98
110
|
|
|
99
111
|
ViewportNode.COORDINATE = 'coordinate';
|
|
100
112
|
ViewportNode.RESOLUTION = 'resolution';
|
|
113
|
+
ViewportNode.VIEWPORT = 'viewport';
|
|
101
114
|
ViewportNode.TOP_LEFT = 'topLeft';
|
|
102
115
|
ViewportNode.BOTTOM_LEFT = 'bottomLeft';
|
|
103
116
|
ViewportNode.TOP_RIGHT = 'topRight';
|
|
@@ -107,6 +120,7 @@ export default ViewportNode;
|
|
|
107
120
|
|
|
108
121
|
export const viewportCoordinate = nodeImmutable( ViewportNode, ViewportNode.COORDINATE );
|
|
109
122
|
export const viewportResolution = nodeImmutable( ViewportNode, ViewportNode.RESOLUTION );
|
|
123
|
+
export const viewport = nodeImmutable( ViewportNode, ViewportNode.VIEWPORT );
|
|
110
124
|
export const viewportTopLeft = nodeImmutable( ViewportNode, ViewportNode.TOP_LEFT );
|
|
111
125
|
export const viewportBottomLeft = nodeImmutable( ViewportNode, ViewportNode.BOTTOM_LEFT );
|
|
112
126
|
export const viewportTopRight = nodeImmutable( ViewportNode, ViewportNode.TOP_RIGHT );
|
|
@@ -3,12 +3,13 @@ import V_GGX_SmithCorrelated from './V_GGX_SmithCorrelated.js';
|
|
|
3
3
|
import D_GGX from './D_GGX.js';
|
|
4
4
|
import { transformedNormalView } from '../../accessors/NormalNode.js';
|
|
5
5
|
import { positionViewDirection } from '../../accessors/PositionNode.js';
|
|
6
|
+
import { iridescence } from '../../core/PropertyNode.js';
|
|
6
7
|
import { tslFn } from '../../shadernode/ShaderNode.js';
|
|
7
8
|
|
|
8
9
|
// GGX Distribution, Schlick Fresnel, GGX_SmithCorrelated Visibility
|
|
9
10
|
const BRDF_GGX = tslFn( ( inputs ) => {
|
|
10
11
|
|
|
11
|
-
const { lightDirection, f0, f90, roughness } = inputs;
|
|
12
|
+
const { lightDirection, f0, f90, roughness, iridescenceFresnel } = inputs;
|
|
12
13
|
|
|
13
14
|
const normalView = inputs.normalView || transformedNormalView;
|
|
14
15
|
|
|
@@ -21,7 +22,14 @@ const BRDF_GGX = tslFn( ( inputs ) => {
|
|
|
21
22
|
const dotNH = normalView.dot( halfDir ).clamp();
|
|
22
23
|
const dotVH = positionViewDirection.dot( halfDir ).clamp();
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
let F = F_Schlick( { f0, f90, dotVH } );
|
|
26
|
+
|
|
27
|
+
if ( iridescenceFresnel ) {
|
|
28
|
+
|
|
29
|
+
F = iridescence.mix( F, iridescenceFresnel );
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
|
|
25
33
|
const V = V_GGX_SmithCorrelated( { alpha, dotNL, dotNV } );
|
|
26
34
|
const D = D_GGX( { alpha, dotNH } );
|
|
27
35
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { tslFn, vec3 } from '../../shadernode/ShaderNode.js';
|
|
2
|
+
|
|
3
|
+
const Schlick_to_F0 = tslFn( ( { f, f90, dotVH } ) => {
|
|
4
|
+
|
|
5
|
+
const x = dotVH.oneMinus().saturate();
|
|
6
|
+
const x2 = x.mul( x );
|
|
7
|
+
const x5 = x.mul( x2, x2 ).clamp( 0, .9999 );
|
|
8
|
+
|
|
9
|
+
return f.sub( vec3( f90 ).mul( x5 ) ).div( x5.oneMinus() );
|
|
10
|
+
|
|
11
|
+
} );
|
|
12
|
+
|
|
13
|
+
export default Schlick_to_F0;
|