super-three 0.161.0 → 0.163.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 +822 -1332
- package/build/three.module.js +820 -1328
- package/build/three.module.min.js +1 -1
- package/examples/jsm/controls/DragControls.js +91 -30
- package/examples/jsm/controls/OrbitControls.js +32 -6
- package/examples/jsm/controls/TransformControls.js +9 -9
- package/examples/jsm/exporters/GLTFExporter.js +30 -3
- package/examples/jsm/exporters/USDZExporter.js +15 -0
- package/examples/jsm/geometries/TextGeometry.js +10 -2
- package/examples/jsm/interactive/HTMLMesh.js +7 -9
- package/examples/jsm/interactive/InteractiveGroup.js +15 -25
- package/examples/jsm/libs/fflate.module.js +694 -496
- package/examples/jsm/libs/rhino3dm/rhino3dm.js +1 -8723
- package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +1 -8734
- package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
- package/examples/jsm/libs/tween.module.js +32 -14
- package/examples/jsm/lines/LineMaterial.js +0 -2
- package/examples/jsm/loaders/3DMLoader.js +13 -21
- package/examples/jsm/loaders/3MFLoader.js +2 -0
- package/examples/jsm/loaders/EXRLoader.js +89 -19
- package/examples/jsm/loaders/FBXLoader.js +1 -1
- package/examples/jsm/loaders/GLTFLoader.js +6 -0
- package/examples/jsm/loaders/KTX2Loader.js +2 -6
- package/examples/jsm/loaders/LUT3dlLoader.js +0 -15
- package/examples/jsm/loaders/LUTCubeLoader.js +0 -14
- package/examples/jsm/loaders/LUTImageLoader.js +0 -14
- package/examples/jsm/loaders/RGBMLoader.js +16 -0
- package/examples/jsm/loaders/VOXLoader.js +9 -2
- package/examples/jsm/loaders/VRMLLoader.js +6 -2
- package/examples/jsm/misc/GPUComputationRenderer.js +0 -6
- package/examples/jsm/misc/ProgressiveLightMap.js +1 -0
- package/examples/jsm/nodes/Nodes.js +15 -8
- package/examples/jsm/nodes/accessors/AccessorsUtils.js +10 -0
- package/examples/jsm/nodes/accessors/BatchNode.js +78 -0
- package/examples/jsm/nodes/accessors/ClippingNode.js +144 -0
- package/examples/jsm/nodes/accessors/InstanceNode.js +25 -2
- package/examples/jsm/nodes/accessors/MaterialNode.js +2 -2
- package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +2 -12
- package/examples/jsm/nodes/accessors/MorphNode.js +20 -10
- package/examples/jsm/nodes/accessors/NormalNode.js +12 -2
- package/examples/jsm/nodes/accessors/ReferenceNode.js +87 -29
- package/examples/jsm/nodes/accessors/RendererReferenceNode.js +29 -0
- package/examples/jsm/nodes/accessors/SkinningNode.js +31 -10
- package/examples/jsm/nodes/accessors/StorageBufferNode.js +18 -0
- package/examples/jsm/nodes/accessors/TangentNode.js +8 -2
- package/examples/jsm/nodes/accessors/TextureNode.js +30 -7
- package/examples/jsm/nodes/accessors/UniformsNode.js +140 -0
- package/examples/jsm/nodes/code/CodeNode.js +6 -0
- package/examples/jsm/nodes/core/AssignNode.js +68 -12
- package/examples/jsm/nodes/core/Node.js +67 -6
- package/examples/jsm/nodes/core/NodeBuilder.js +23 -24
- package/examples/jsm/nodes/core/NodeFrame.js +8 -8
- package/examples/jsm/nodes/core/NodeUtils.js +2 -2
- package/examples/jsm/nodes/core/TempNode.js +1 -1
- package/examples/jsm/nodes/core/UniformNode.js +20 -0
- package/examples/jsm/nodes/display/BlendModeNode.js +30 -1
- package/examples/jsm/nodes/display/NormalMapNode.js +3 -5
- package/examples/jsm/nodes/display/PassNode.js +17 -1
- package/examples/jsm/nodes/display/ToneMappingNode.js +8 -4
- package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +6 -0
- package/examples/jsm/nodes/fog/FogExp2Node.js +4 -5
- package/examples/jsm/nodes/fog/FogNode.js +13 -3
- package/examples/jsm/nodes/fog/FogRangeNode.js +4 -3
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +1 -1
- package/examples/jsm/nodes/lighting/EnvironmentNode.js +12 -69
- package/examples/jsm/nodes/materials/NodeMaterial.js +70 -17
- package/examples/jsm/nodes/math/CondNode.js +42 -7
- package/examples/jsm/nodes/math/MathNode.js +20 -0
- package/examples/jsm/nodes/pmrem/PMREMNode.js +193 -0
- package/examples/jsm/nodes/pmrem/PMREMUtils.js +288 -0
- package/examples/jsm/nodes/shadernode/ShaderNode.js +1 -1
- package/examples/jsm/nodes/utils/ArrayElementNode.js +0 -6
- package/examples/jsm/nodes/utils/EquirectUVNode.js +1 -1
- package/examples/jsm/nodes/utils/LoopNode.js +2 -0
- package/examples/jsm/nodes/utils/StorageArrayElementNode.js +91 -0
- package/examples/jsm/objects/QuadMesh.js +7 -23
- package/examples/jsm/physics/RapierPhysics.js +4 -4
- package/examples/jsm/postprocessing/GlitchPass.js +0 -3
- package/examples/jsm/postprocessing/LUTPass.js +5 -71
- package/examples/jsm/postprocessing/OutputPass.js +2 -0
- package/examples/jsm/postprocessing/SAOPass.js +0 -1
- package/examples/jsm/postprocessing/SSAOPass.js +0 -3
- package/examples/jsm/renderers/common/Animation.js +3 -0
- package/examples/jsm/renderers/common/Background.js +3 -3
- package/examples/jsm/renderers/common/ClippingContext.js +165 -0
- package/examples/jsm/renderers/common/Info.js +11 -19
- package/examples/jsm/renderers/common/PostProcessing.js +12 -4
- package/examples/jsm/renderers/common/RenderContext.js +3 -1
- package/examples/jsm/renderers/common/RenderContexts.js +2 -13
- package/examples/jsm/renderers/common/RenderObject.js +46 -3
- package/examples/jsm/renderers/common/RenderObjects.js +2 -0
- package/examples/jsm/renderers/common/Renderer.js +113 -39
- package/examples/jsm/renderers/common/StorageBufferAttribute.js +2 -2
- package/examples/jsm/renderers/common/StorageInstancedBufferAttribute.js +17 -0
- package/examples/jsm/renderers/common/Textures.js +3 -13
- package/examples/jsm/renderers/common/UniformsGroup.js +6 -4
- package/examples/jsm/renderers/common/extras/PMREMGenerator.js +777 -0
- package/examples/jsm/renderers/common/nodes/NodeStorageBuffer.js +23 -0
- package/examples/jsm/renderers/common/nodes/NodeUniformBuffer.js +23 -0
- package/examples/jsm/renderers/common/nodes/Nodes.js +6 -18
- package/examples/jsm/renderers/webgl/WebGLBackend.js +174 -30
- package/examples/jsm/renderers/webgl/WebGLBufferRenderer.js +141 -0
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +136 -11
- package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +8 -2
- package/examples/jsm/renderers/webgl/utils/WebGLConstants.js +1 -0
- package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +90 -0
- package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +3 -1
- package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +0 -2
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +0 -2
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +67 -37
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +20 -43
- package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +32 -1
- package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +18 -4
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +94 -20
- package/examples/jsm/shaders/OutputShader.js +4 -0
- package/examples/jsm/utils/GPUStatsPanel.js +10 -45
- package/examples/jsm/utils/SkeletonUtils.js +14 -3
- package/examples/jsm/utils/TextureUtils.js +1 -1
- package/examples/jsm/webxr/VRButton.js +13 -5
- package/examples/jsm/webxr/XRButton.js +0 -1
- package/examples/jsm/webxr/XRControllerModelFactory.js +8 -0
- package/package.json +4 -3
- package/src/Three.Legacy.js +20 -0
- package/src/Three.js +0 -2
- package/src/animation/AnimationClip.js +1 -1
- package/src/constants.js +4 -7
- package/src/core/BufferAttribute.js +0 -11
- package/src/core/BufferGeometry.js +23 -29
- package/src/core/Object3D.js +21 -7
- package/src/core/Raycaster.js +18 -4
- package/src/core/RenderTarget.js +44 -21
- package/src/extras/PMREMGenerator.js +11 -0
- package/src/extras/curves/EllipseCurve.js +2 -2
- package/src/helpers/SpotLightHelper.js +18 -1
- package/src/loaders/DataTextureLoader.js +0 -4
- package/src/loaders/MaterialLoader.js +1 -0
- package/src/loaders/ObjectLoader.js +4 -1
- package/src/materials/Material.js +2 -1
- package/src/materials/MeshBasicMaterial.js +3 -0
- package/src/materials/MeshLambertMaterial.js +3 -0
- package/src/materials/MeshPhongMaterial.js +3 -0
- package/src/materials/MeshStandardMaterial.js +3 -0
- package/src/materials/ShaderMaterial.js +0 -4
- package/src/math/Quaternion.js +13 -12
- package/src/math/Spherical.js +4 -5
- package/src/math/Vector3.js +7 -7
- package/src/objects/BatchedMesh.js +4 -3
- package/src/objects/InstancedMesh.js +63 -0
- package/src/objects/Mesh.js +0 -1
- package/src/renderers/WebGLCubeRenderTarget.js +1 -10
- package/src/renderers/WebGLRenderer.js +70 -136
- package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +1 -0
- package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +2 -10
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +2 -16
- package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/morphinstance_vertex.glsl.js +14 -0
- package/src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl.js +11 -2
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +32 -22
- package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +23 -0
- package/src/renderers/shaders/ShaderChunk.js +2 -0
- package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +3 -2
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/distanceRGBA.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/linedashed.glsl.js +1 -0
- package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +1 -0
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +1 -0
- package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +1 -0
- package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +1 -0
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +1 -0
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +1 -0
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +1 -0
- package/src/renderers/shaders/ShaderLib/points.glsl.js +1 -0
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +1 -0
- package/src/renderers/shaders/ShaderLib.js +3 -2
- package/src/renderers/shaders/UniformsLib.js +1 -0
- package/src/renderers/shaders/UniformsUtils.js +10 -1
- package/src/renderers/webgl/WebGLAttributes.js +6 -33
- package/src/renderers/webgl/WebGLBackground.js +18 -0
- package/src/renderers/webgl/WebGLBindingStates.js +14 -51
- package/src/renderers/webgl/WebGLBufferRenderer.js +3 -25
- package/src/renderers/webgl/WebGLCapabilities.js +2 -12
- package/src/renderers/webgl/WebGLCubeUVMaps.js +10 -6
- package/src/renderers/webgl/WebGLExtensions.js +4 -19
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +3 -25
- package/src/renderers/webgl/WebGLLights.js +6 -32
- package/src/renderers/webgl/WebGLMaterials.js +26 -4
- package/src/renderers/webgl/WebGLMorphtargets.js +79 -210
- package/src/renderers/webgl/WebGLProgram.js +30 -48
- package/src/renderers/webgl/WebGLPrograms.js +5 -14
- package/src/renderers/webgl/WebGLRenderStates.js +8 -6
- package/src/renderers/webgl/WebGLState.js +21 -75
- package/src/renderers/webgl/WebGLTextures.js +143 -275
- package/src/renderers/webgl/WebGLUniformsGroups.js +1 -1
- package/src/renderers/webgl/WebGLUtils.js +6 -57
- package/src/renderers/webxr/WebXRDepthSensing.js +2 -3
- package/src/renderers/webxr/WebXRManager.js +2 -2
- package/src/scenes/Scene.js +14 -0
- package/src/textures/Texture.js +6 -24
- package/examples/jsm/nodes/core/ArrayUniformNode.js +0 -26
- package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +0 -37
- package/src/renderers/WebGL1Renderer.js +0 -7
- package/src/renderers/WebGLMultipleRenderTargets.js +0 -82
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import FogNode from './FogNode.js';
|
|
2
2
|
import { smoothstep } from '../math/MathNode.js';
|
|
3
|
-
import { positionView } from '../accessors/PositionNode.js';
|
|
4
3
|
import { addNodeClass } from '../core/Node.js';
|
|
5
4
|
import { addNodeElement, nodeProxy } from '../shadernode/ShaderNode.js';
|
|
6
5
|
|
|
@@ -17,9 +16,11 @@ class FogRangeNode extends FogNode {
|
|
|
17
16
|
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
setup() {
|
|
19
|
+
setup( builder ) {
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
const viewZ = this.getViewZNode( builder );
|
|
22
|
+
|
|
23
|
+
return smoothstep( this.nearNode, this.farNode, viewZ );
|
|
23
24
|
|
|
24
25
|
}
|
|
25
26
|
|
|
@@ -63,7 +63,7 @@ class AnalyticLightNode extends LightingNode {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
const shadow = this.light.shadow;
|
|
66
|
-
const rtt = builder.
|
|
66
|
+
const rtt = builder.createRenderTarget( shadow.mapSize.width, shadow.mapSize.height );
|
|
67
67
|
|
|
68
68
|
const depthTexture = new DepthTexture();
|
|
69
69
|
depthTexture.minFilter = NearestFilter;
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import LightingNode from './LightingNode.js';
|
|
2
2
|
import { cache } from '../core/CacheNode.js';
|
|
3
3
|
import { context } from '../core/ContextNode.js';
|
|
4
|
-
import { maxMipLevel } from '../utils/MaxMipLevelNode.js';
|
|
5
4
|
import { roughness, clearcoatRoughness } from '../core/PropertyNode.js';
|
|
6
|
-
import { equirectUV } from '../utils/EquirectUVNode.js';
|
|
7
|
-
import { specularMIPLevel } from '../utils/SpecularMIPLevelNode.js';
|
|
8
5
|
import { cameraViewMatrix } from '../accessors/CameraNode.js';
|
|
9
6
|
import { transformedClearcoatNormalView, transformedNormalView, transformedNormalWorld } from '../accessors/NormalNode.js';
|
|
10
7
|
import { positionViewDirection } from '../accessors/PositionNode.js';
|
|
11
8
|
import { addNodeClass } from '../core/Node.js';
|
|
12
|
-
import {
|
|
13
|
-
import { cubeTexture } from '../accessors/CubeTextureNode.js';
|
|
9
|
+
import { float } from '../shadernode/ShaderNode.js';
|
|
14
10
|
import { reference } from '../accessors/ReferenceNode.js';
|
|
11
|
+
import { pmremTexture } from '../pmrem/PMREMNode.js';
|
|
15
12
|
|
|
16
13
|
const envNodeCache = new WeakMap();
|
|
17
14
|
|
|
@@ -29,19 +26,13 @@ class EnvironmentNode extends LightingNode {
|
|
|
29
26
|
|
|
30
27
|
let envNode = this.envNode;
|
|
31
28
|
|
|
32
|
-
if ( envNode.isTextureNode
|
|
29
|
+
if ( envNode.isTextureNode ) {
|
|
33
30
|
|
|
34
31
|
let cacheEnvNode = envNodeCache.get( envNode.value );
|
|
35
32
|
|
|
36
33
|
if ( cacheEnvNode === undefined ) {
|
|
37
34
|
|
|
38
|
-
|
|
39
|
-
const renderer = builder.renderer;
|
|
40
|
-
|
|
41
|
-
// @TODO: Add dispose logic here
|
|
42
|
-
const cubeRTT = builder.getCubeRenderTarget( 512 ).fromEquirectangularTexture( renderer, texture );
|
|
43
|
-
|
|
44
|
-
cacheEnvNode = cubeTexture( cubeRTT.texture );
|
|
35
|
+
cacheEnvNode = pmremTexture( envNode.value );
|
|
45
36
|
|
|
46
37
|
envNodeCache.set( envNode.value, cacheEnvNode );
|
|
47
38
|
|
|
@@ -53,7 +44,8 @@ class EnvironmentNode extends LightingNode {
|
|
|
53
44
|
|
|
54
45
|
//
|
|
55
46
|
|
|
56
|
-
const
|
|
47
|
+
const envMap = builder.material.envMap;
|
|
48
|
+
const intensity = envMap ? reference( 'envMapIntensity', 'float', builder.material ) : reference( 'environmentIntensity', 'float', builder.scene ); // @TODO: Add materialEnvIntensity in MaterialNode
|
|
57
49
|
|
|
58
50
|
const radiance = context( envNode, createRadianceContext( roughness, transformedNormalView ) ).mul( intensity );
|
|
59
51
|
const irradiance = context( envNode, createIrradianceContext( transformedNormalWorld ) ).mul( Math.PI ).mul( intensity );
|
|
@@ -86,12 +78,9 @@ class EnvironmentNode extends LightingNode {
|
|
|
86
78
|
const createRadianceContext = ( roughnessNode, normalViewNode ) => {
|
|
87
79
|
|
|
88
80
|
let reflectVec = null;
|
|
89
|
-
let textureUVNode = null;
|
|
90
81
|
|
|
91
82
|
return {
|
|
92
|
-
getUV: (
|
|
93
|
-
|
|
94
|
-
let node = null;
|
|
83
|
+
getUV: () => {
|
|
95
84
|
|
|
96
85
|
if ( reflectVec === null ) {
|
|
97
86
|
|
|
@@ -101,36 +90,13 @@ const createRadianceContext = ( roughnessNode, normalViewNode ) => {
|
|
|
101
90
|
|
|
102
91
|
}
|
|
103
92
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
node = reflectVec;
|
|
107
|
-
|
|
108
|
-
} else if ( textureNode.isTextureNode ) {
|
|
109
|
-
|
|
110
|
-
if ( textureUVNode === null ) {
|
|
111
|
-
|
|
112
|
-
// @TODO: Needed PMREM
|
|
113
|
-
|
|
114
|
-
textureUVNode = equirectUV( reflectVec );
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
node = textureUVNode;
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return node;
|
|
93
|
+
return reflectVec;
|
|
123
94
|
|
|
124
95
|
},
|
|
125
96
|
getTextureLevel: () => {
|
|
126
97
|
|
|
127
98
|
return roughnessNode;
|
|
128
99
|
|
|
129
|
-
},
|
|
130
|
-
getTextureLevelAlgorithm: ( textureNode, levelNode ) => {
|
|
131
|
-
|
|
132
|
-
return specularMIPLevel( textureNode, levelNode );
|
|
133
|
-
|
|
134
100
|
}
|
|
135
101
|
};
|
|
136
102
|
|
|
@@ -138,38 +104,15 @@ const createRadianceContext = ( roughnessNode, normalViewNode ) => {
|
|
|
138
104
|
|
|
139
105
|
const createIrradianceContext = ( normalWorldNode ) => {
|
|
140
106
|
|
|
141
|
-
let textureUVNode = null;
|
|
142
|
-
|
|
143
107
|
return {
|
|
144
|
-
getUV: (
|
|
145
|
-
|
|
146
|
-
let node = null;
|
|
147
|
-
|
|
148
|
-
if ( textureNode.isCubeTextureNode ) {
|
|
149
|
-
|
|
150
|
-
node = normalWorldNode;
|
|
151
|
-
|
|
152
|
-
} else if ( textureNode.isTextureNode ) {
|
|
153
|
-
|
|
154
|
-
if ( textureUVNode === null ) {
|
|
108
|
+
getUV: () => {
|
|
155
109
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
textureUVNode = equirectUV( normalWorldNode );
|
|
159
|
-
textureUVNode = vec2( textureUVNode.x, textureUVNode.y.oneMinus() );
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
node = textureUVNode;
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return node;
|
|
110
|
+
return normalWorldNode;
|
|
168
111
|
|
|
169
112
|
},
|
|
170
|
-
getTextureLevel: (
|
|
113
|
+
getTextureLevel: () => {
|
|
171
114
|
|
|
172
|
-
return
|
|
115
|
+
return float( 1.0 );
|
|
173
116
|
|
|
174
117
|
}
|
|
175
118
|
};
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { Material, ShaderMaterial, NoColorSpace, LinearSRGBColorSpace } from 'three';
|
|
2
2
|
import { getNodeChildren, getCacheKey } from '../core/NodeUtils.js';
|
|
3
3
|
import { attribute } from '../core/AttributeNode.js';
|
|
4
|
-
import { output, diffuseColor } from '../core/PropertyNode.js';
|
|
4
|
+
import { output, diffuseColor, varyingProperty } from '../core/PropertyNode.js';
|
|
5
5
|
import { materialAlphaTest, materialColor, materialOpacity, materialEmissive, materialNormal } from '../accessors/MaterialNode.js';
|
|
6
6
|
import { modelViewProjection } from '../accessors/ModelViewProjectionNode.js';
|
|
7
7
|
import { transformedNormalView } from '../accessors/NormalNode.js';
|
|
8
8
|
import { instance } from '../accessors/InstanceNode.js';
|
|
9
|
+
import { batch } from '../accessors/BatchNode.js';
|
|
10
|
+
|
|
9
11
|
import { positionLocal, positionView } from '../accessors/PositionNode.js';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
+
import { skinningReference } from '../accessors/SkinningNode.js';
|
|
13
|
+
import { morphReference } from '../accessors/MorphNode.js';
|
|
12
14
|
import { texture } from '../accessors/TextureNode.js';
|
|
13
15
|
import { cubeTexture } from '../accessors/CubeTextureNode.js';
|
|
14
16
|
import { lightsNode } from '../lighting/LightsNode.js';
|
|
@@ -19,6 +21,8 @@ import { lightingContext } from '../lighting/LightingContextNode.js';
|
|
|
19
21
|
import EnvironmentNode from '../lighting/EnvironmentNode.js';
|
|
20
22
|
import { depthPixel } from '../display/ViewportDepthNode.js';
|
|
21
23
|
import { cameraLogDepth } from '../accessors/CameraNode.js';
|
|
24
|
+
import { clipping, clippingAlpha } from '../accessors/ClippingNode.js';
|
|
25
|
+
import { faceDirection } from '../display/FrontFacingNode.js';
|
|
22
26
|
|
|
23
27
|
const NodeMaterials = new Map();
|
|
24
28
|
|
|
@@ -90,6 +94,8 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
90
94
|
|
|
91
95
|
let resultNode;
|
|
92
96
|
|
|
97
|
+
const clippingNode = this.setupClipping( builder );
|
|
98
|
+
|
|
93
99
|
if ( this.fragmentNode === null ) {
|
|
94
100
|
|
|
95
101
|
if ( this.depthWrite === true ) this.setupDepth( builder );
|
|
@@ -101,7 +107,13 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
101
107
|
|
|
102
108
|
const outgoingLightNode = this.setupLighting( builder );
|
|
103
109
|
|
|
104
|
-
|
|
110
|
+
if ( clippingNode !== null ) builder.stack.add( clippingNode );
|
|
111
|
+
|
|
112
|
+
// force unsigned floats - useful for RenderTargets
|
|
113
|
+
|
|
114
|
+
const basicOutput = vec4( outgoingLightNode, diffuseColor.a ).max( 0 );
|
|
115
|
+
|
|
116
|
+
resultNode = this.setupOutput( builder, basicOutput );
|
|
105
117
|
|
|
106
118
|
// OUTPUT NODE
|
|
107
119
|
|
|
@@ -123,6 +135,31 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
123
135
|
|
|
124
136
|
}
|
|
125
137
|
|
|
138
|
+
setupClipping( builder ) {
|
|
139
|
+
|
|
140
|
+
const { globalClippingCount, localClippingCount } = builder.clippingContext;
|
|
141
|
+
|
|
142
|
+
let result = null;
|
|
143
|
+
|
|
144
|
+
if ( globalClippingCount || localClippingCount ) {
|
|
145
|
+
|
|
146
|
+
if ( this.alphaToCoverage ) {
|
|
147
|
+
|
|
148
|
+
// to be added to flow when the color/alpha value has been determined
|
|
149
|
+
result = clippingAlpha();
|
|
150
|
+
|
|
151
|
+
} else {
|
|
152
|
+
|
|
153
|
+
builder.stack.add( clipping() );
|
|
154
|
+
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return result;
|
|
160
|
+
|
|
161
|
+
}
|
|
162
|
+
|
|
126
163
|
setupDepth( builder ) {
|
|
127
164
|
|
|
128
165
|
const { renderer } = builder;
|
|
@@ -158,13 +195,19 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
158
195
|
|
|
159
196
|
if ( geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color ) {
|
|
160
197
|
|
|
161
|
-
|
|
198
|
+
morphReference( object ).append();
|
|
162
199
|
|
|
163
200
|
}
|
|
164
201
|
|
|
165
202
|
if ( object.isSkinnedMesh === true ) {
|
|
166
203
|
|
|
167
|
-
|
|
204
|
+
skinningReference( object ).append();
|
|
205
|
+
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if ( object.isBatchedMesh ) {
|
|
209
|
+
|
|
210
|
+
batch( object ).append();
|
|
168
211
|
|
|
169
212
|
}
|
|
170
213
|
|
|
@@ -189,7 +232,7 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
189
232
|
|
|
190
233
|
}
|
|
191
234
|
|
|
192
|
-
setupDiffuseColor( { geometry } ) {
|
|
235
|
+
setupDiffuseColor( { object, geometry } ) {
|
|
193
236
|
|
|
194
237
|
let colorNode = this.colorNode ? vec4( this.colorNode ) : materialColor;
|
|
195
238
|
|
|
@@ -201,6 +244,16 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
201
244
|
|
|
202
245
|
}
|
|
203
246
|
|
|
247
|
+
// Instanced colors
|
|
248
|
+
|
|
249
|
+
if ( object.instanceColor ) {
|
|
250
|
+
|
|
251
|
+
const instanceColor = varyingProperty( 'vec3', 'vInstanceColor' );
|
|
252
|
+
|
|
253
|
+
colorNode = instanceColor.mul( colorNode );
|
|
254
|
+
|
|
255
|
+
}
|
|
256
|
+
|
|
204
257
|
// COLOR
|
|
205
258
|
|
|
206
259
|
diffuseColor.assign( colorNode );
|
|
@@ -236,13 +289,13 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
236
289
|
|
|
237
290
|
const normalNode = positionView.dFdx().cross( positionView.dFdy() ).normalize();
|
|
238
291
|
|
|
239
|
-
transformedNormalView.assign( normalNode );
|
|
292
|
+
transformedNormalView.assign( normalNode.mul( faceDirection ) );
|
|
240
293
|
|
|
241
294
|
} else {
|
|
242
295
|
|
|
243
296
|
const normalNode = this.normalNode ? vec3( this.normalNode ) : materialNormal;
|
|
244
297
|
|
|
245
|
-
transformedNormalView.assign( normalNode );
|
|
298
|
+
transformedNormalView.assign( normalNode.mul( faceDirection ) );
|
|
246
299
|
|
|
247
300
|
}
|
|
248
301
|
|
|
@@ -349,23 +402,23 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
349
402
|
|
|
350
403
|
const renderer = builder.renderer;
|
|
351
404
|
|
|
352
|
-
//
|
|
405
|
+
// FOG
|
|
353
406
|
|
|
354
|
-
|
|
407
|
+
if ( this.fog === true ) {
|
|
355
408
|
|
|
356
|
-
|
|
409
|
+
const fogNode = builder.fogNode;
|
|
357
410
|
|
|
358
|
-
outputNode = vec4(
|
|
411
|
+
if ( fogNode ) outputNode = vec4( fogNode.mix( outputNode.rgb, fogNode.colorNode ), outputNode.a );
|
|
359
412
|
|
|
360
413
|
}
|
|
361
414
|
|
|
362
|
-
//
|
|
415
|
+
// TONE MAPPING
|
|
363
416
|
|
|
364
|
-
|
|
417
|
+
const toneMappingNode = builder.toneMappingNode;
|
|
365
418
|
|
|
366
|
-
|
|
419
|
+
if ( this.toneMapped === true && toneMappingNode ) {
|
|
367
420
|
|
|
368
|
-
|
|
421
|
+
outputNode = vec4( toneMappingNode.context( { color: outputNode.rgb } ), outputNode.a );
|
|
369
422
|
|
|
370
423
|
}
|
|
371
424
|
|
|
@@ -36,23 +36,45 @@ class CondNode extends Node {
|
|
|
36
36
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
generate( builder ) {
|
|
39
|
+
generate( builder, output ) {
|
|
40
40
|
|
|
41
41
|
const type = this.getNodeType( builder );
|
|
42
42
|
const context = { tempWrite: false };
|
|
43
43
|
|
|
44
|
+
const nodeData = builder.getDataFromNode( this );
|
|
45
|
+
|
|
46
|
+
if ( nodeData.nodeProperty !== undefined ) {
|
|
47
|
+
|
|
48
|
+
return nodeData.nodeProperty;
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
44
52
|
const { ifNode, elseNode } = this;
|
|
45
53
|
|
|
46
|
-
const
|
|
47
|
-
const nodeProperty =
|
|
54
|
+
const needsOutput = output !== 'void';
|
|
55
|
+
const nodeProperty = needsOutput ? property( type ).build( builder ) : '';
|
|
56
|
+
|
|
57
|
+
nodeData.nodeProperty = nodeProperty;
|
|
48
58
|
|
|
49
59
|
const nodeSnippet = contextNode( this.condNode/*, context*/ ).build( builder, 'bool' );
|
|
50
60
|
|
|
51
61
|
builder.addFlowCode( `\n${ builder.tab }if ( ${ nodeSnippet } ) {\n\n` ).addFlowTab();
|
|
52
62
|
|
|
53
|
-
let ifSnippet = contextNode(
|
|
63
|
+
let ifSnippet = contextNode( ifNode, context ).build( builder, type );
|
|
64
|
+
|
|
65
|
+
if ( ifSnippet ) {
|
|
66
|
+
|
|
67
|
+
if ( needsOutput ) {
|
|
68
|
+
|
|
69
|
+
ifSnippet = nodeProperty + ' = ' + ifSnippet + ';';
|
|
70
|
+
|
|
71
|
+
} else {
|
|
72
|
+
|
|
73
|
+
ifSnippet = 'return ' + ifSnippet + ';';
|
|
54
74
|
|
|
55
|
-
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
}
|
|
56
78
|
|
|
57
79
|
builder.removeFlowTab().addFlowCode( builder.tab + '\t' + ifSnippet + '\n\n' + builder.tab + '}' );
|
|
58
80
|
|
|
@@ -61,7 +83,20 @@ class CondNode extends Node {
|
|
|
61
83
|
builder.addFlowCode( ' else {\n\n' ).addFlowTab();
|
|
62
84
|
|
|
63
85
|
let elseSnippet = contextNode( elseNode, context ).build( builder, type );
|
|
64
|
-
|
|
86
|
+
|
|
87
|
+
if ( elseSnippet ) {
|
|
88
|
+
|
|
89
|
+
if ( needsOutput ) {
|
|
90
|
+
|
|
91
|
+
elseSnippet = nodeProperty + ' = ' + elseSnippet + ';';
|
|
92
|
+
|
|
93
|
+
} else {
|
|
94
|
+
|
|
95
|
+
elseSnippet = 'return ' + elseSnippet + ';';
|
|
96
|
+
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
}
|
|
65
100
|
|
|
66
101
|
builder.removeFlowTab().addFlowCode( builder.tab + '\t' + elseSnippet + '\n\n' + builder.tab + '}\n\n' );
|
|
67
102
|
|
|
@@ -71,7 +106,7 @@ class CondNode extends Node {
|
|
|
71
106
|
|
|
72
107
|
}
|
|
73
108
|
|
|
74
|
-
return nodeProperty;
|
|
109
|
+
return builder.format( nodeProperty, type, output );
|
|
75
110
|
|
|
76
111
|
}
|
|
77
112
|
|
|
@@ -57,6 +57,14 @@ class MathNode extends TempNode {
|
|
|
57
57
|
|
|
58
58
|
return 'vec3';
|
|
59
59
|
|
|
60
|
+
} else if ( method === MathNode.ALL ) {
|
|
61
|
+
|
|
62
|
+
return 'bool';
|
|
63
|
+
|
|
64
|
+
} else if ( method === MathNode.EQUALS ) {
|
|
65
|
+
|
|
66
|
+
return builder.changeComponentType( this.aNode.getNodeType( builder ), 'bool' );
|
|
67
|
+
|
|
60
68
|
} else if ( method === MathNode.MOD ) {
|
|
61
69
|
|
|
62
70
|
return this.aNode.getNodeType( builder );
|
|
@@ -195,6 +203,10 @@ class MathNode extends TempNode {
|
|
|
195
203
|
|
|
196
204
|
// 1 input
|
|
197
205
|
|
|
206
|
+
MathNode.ALL = 'all';
|
|
207
|
+
MathNode.ANY = 'any';
|
|
208
|
+
MathNode.EQUALS = 'equals';
|
|
209
|
+
|
|
198
210
|
MathNode.RADIANS = 'radians';
|
|
199
211
|
MathNode.DEGREES = 'degrees';
|
|
200
212
|
MathNode.EXP = 'exp';
|
|
@@ -256,6 +268,10 @@ export const INFINITY = float( 1e6 );
|
|
|
256
268
|
export const PI = float( Math.PI );
|
|
257
269
|
export const PI2 = float( Math.PI * 2 );
|
|
258
270
|
|
|
271
|
+
export const all = nodeProxy( MathNode, MathNode.ALL );
|
|
272
|
+
export const any = nodeProxy( MathNode, MathNode.ANY );
|
|
273
|
+
export const equals = nodeProxy( MathNode, MathNode.EQUALS );
|
|
274
|
+
|
|
259
275
|
export const radians = nodeProxy( MathNode, MathNode.RADIANS );
|
|
260
276
|
export const degrees = nodeProxy( MathNode, MathNode.DEGREES );
|
|
261
277
|
export const exp = nodeProxy( MathNode, MathNode.EXP );
|
|
@@ -315,6 +331,10 @@ export const faceForward = nodeProxy( MathNode, MathNode.FACEFORWARD );
|
|
|
315
331
|
export const mixElement = ( t, e1, e2 ) => mix( e1, e2, t );
|
|
316
332
|
export const smoothstepElement = ( x, low, high ) => smoothstep( low, high, x );
|
|
317
333
|
|
|
334
|
+
addNodeElement( 'all', all );
|
|
335
|
+
addNodeElement( 'any', any );
|
|
336
|
+
addNodeElement( 'equals', equals );
|
|
337
|
+
|
|
318
338
|
addNodeElement( 'radians', radians );
|
|
319
339
|
addNodeElement( 'degrees', degrees );
|
|
320
340
|
addNodeElement( 'exp', exp );
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import TempNode from '../core/TempNode.js';
|
|
2
|
+
import { addNodeClass } from '../core/Node.js';
|
|
3
|
+
import { texture } from '../accessors/TextureNode.js';
|
|
4
|
+
import { textureCubeUV } from './PMREMUtils.js';
|
|
5
|
+
import { uniform } from '../core/UniformNode.js';
|
|
6
|
+
import { NodeUpdateType } from '../core/constants.js';
|
|
7
|
+
import { nodeProxy, vec3 } from '../shadernode/ShaderNode.js';
|
|
8
|
+
import { WebGLCoordinateSystem } from 'three';
|
|
9
|
+
|
|
10
|
+
let _generator = null;
|
|
11
|
+
|
|
12
|
+
const _cache = new WeakMap();
|
|
13
|
+
|
|
14
|
+
function _generateCubeUVSize( imageHeight ) {
|
|
15
|
+
|
|
16
|
+
const maxMip = Math.log2( imageHeight ) - 2;
|
|
17
|
+
|
|
18
|
+
const texelHeight = 1.0 / imageHeight;
|
|
19
|
+
|
|
20
|
+
const texelWidth = 1.0 / ( 3 * Math.max( Math.pow( 2, maxMip ), 7 * 16 ) );
|
|
21
|
+
|
|
22
|
+
return { texelWidth, texelHeight, maxMip };
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function _getPMREMFromTexture( texture ) {
|
|
27
|
+
|
|
28
|
+
let cacheTexture = _cache.get( texture );
|
|
29
|
+
|
|
30
|
+
const pmremVersion = cacheTexture !== undefined ? cacheTexture.pmremVersion : - 1;
|
|
31
|
+
|
|
32
|
+
if ( pmremVersion !== texture.pmremVersion ) {
|
|
33
|
+
|
|
34
|
+
if ( texture.isCubeTexture ) {
|
|
35
|
+
|
|
36
|
+
if ( texture.source.data.some( ( texture ) => texture === undefined ) ) {
|
|
37
|
+
|
|
38
|
+
throw new Error( 'PMREMNode: Undefined texture in CubeTexture. Use onLoad callback or async loader' );
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
cacheTexture = _generator.fromCubemap( texture, cacheTexture );
|
|
43
|
+
|
|
44
|
+
} else {
|
|
45
|
+
|
|
46
|
+
if ( texture.image === undefined ) {
|
|
47
|
+
|
|
48
|
+
throw new Error( 'PMREMNode: Undefined image in Texture. Use onLoad callback or async loader' );
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
cacheTexture = _generator.fromEquirectangular( texture, cacheTexture );
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
cacheTexture.pmremVersion = texture.pmremVersion;
|
|
57
|
+
|
|
58
|
+
_cache.set( texture, cacheTexture );
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return cacheTexture.texture;
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
class PMREMNode extends TempNode {
|
|
67
|
+
|
|
68
|
+
constructor( value, uvNode = null, levelNode = null ) {
|
|
69
|
+
|
|
70
|
+
super( 'vec3' );
|
|
71
|
+
|
|
72
|
+
this._value = value;
|
|
73
|
+
this._pmrem = null;
|
|
74
|
+
|
|
75
|
+
this.uvNode = uvNode;
|
|
76
|
+
this.levelNode = levelNode;
|
|
77
|
+
|
|
78
|
+
this._generator = null;
|
|
79
|
+
this._texture = texture( null );
|
|
80
|
+
this._width = uniform( 0 );
|
|
81
|
+
this._height = uniform( 0 );
|
|
82
|
+
this._maxMip = uniform( 0 );
|
|
83
|
+
|
|
84
|
+
this.updateBeforeType = NodeUpdateType.RENDER;
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
set value( value ) {
|
|
89
|
+
|
|
90
|
+
this._value = value;
|
|
91
|
+
this._pmrem = null;
|
|
92
|
+
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
get value() {
|
|
96
|
+
|
|
97
|
+
return this._value;
|
|
98
|
+
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
updateFromTexture( texture ) {
|
|
102
|
+
|
|
103
|
+
const cubeUVSize = _generateCubeUVSize( texture.image.height );
|
|
104
|
+
|
|
105
|
+
this._texture.value = texture;
|
|
106
|
+
this._width.value = cubeUVSize.texelWidth;
|
|
107
|
+
this._height.value = cubeUVSize.texelHeight;
|
|
108
|
+
this._maxMip.value = cubeUVSize.maxMip;
|
|
109
|
+
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
updateBefore() {
|
|
113
|
+
|
|
114
|
+
let pmrem = this._pmrem;
|
|
115
|
+
|
|
116
|
+
const pmremVersion = pmrem ? pmrem.pmremVersion : - 1;
|
|
117
|
+
const texture = this._value;
|
|
118
|
+
|
|
119
|
+
if ( pmremVersion !== texture.pmremVersion ) {
|
|
120
|
+
|
|
121
|
+
if ( texture.isPMREMTexture === true ) {
|
|
122
|
+
|
|
123
|
+
pmrem = texture;
|
|
124
|
+
|
|
125
|
+
} else {
|
|
126
|
+
|
|
127
|
+
pmrem = _getPMREMFromTexture( texture );
|
|
128
|
+
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
this._pmrem = pmrem;
|
|
132
|
+
|
|
133
|
+
this.updateFromTexture( pmrem );
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
setup( builder ) {
|
|
140
|
+
|
|
141
|
+
if ( _generator === null ) {
|
|
142
|
+
|
|
143
|
+
_generator = builder.createPMREMGenerator();
|
|
144
|
+
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
//
|
|
148
|
+
|
|
149
|
+
this.updateBefore( builder );
|
|
150
|
+
|
|
151
|
+
//
|
|
152
|
+
|
|
153
|
+
let uvNode = this.uvNode;
|
|
154
|
+
|
|
155
|
+
if ( uvNode === null && builder.context.getUV ) {
|
|
156
|
+
|
|
157
|
+
uvNode = builder.context.getUV( this );
|
|
158
|
+
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
//
|
|
162
|
+
|
|
163
|
+
const texture = this.value;
|
|
164
|
+
|
|
165
|
+
if ( builder.renderer.coordinateSystem === WebGLCoordinateSystem && texture.isPMREMTexture !== true && texture.isRenderTargetTexture === true ) {
|
|
166
|
+
|
|
167
|
+
uvNode = vec3( uvNode.x.negate(), uvNode.yz );
|
|
168
|
+
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
//
|
|
172
|
+
|
|
173
|
+
let levelNode = this.levelNode;
|
|
174
|
+
|
|
175
|
+
if ( levelNode === null && builder.context.getTextureLevel ) {
|
|
176
|
+
|
|
177
|
+
levelNode = builder.context.getTextureLevel( this );
|
|
178
|
+
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
//
|
|
182
|
+
|
|
183
|
+
return textureCubeUV( this._texture, uvNode, levelNode, this._width, this._height, this._maxMip );
|
|
184
|
+
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export const pmremTexture = nodeProxy( PMREMNode );
|
|
190
|
+
|
|
191
|
+
addNodeClass( 'PMREMNode', PMREMNode );
|
|
192
|
+
|
|
193
|
+
export default PMREMNode;
|