super-three 0.160.1 → 0.162.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/LICENSE +1 -1
- package/build/three.cjs +867 -499
- package/build/three.module.js +867 -496
- package/build/three.module.min.js +1 -1
- package/examples/jsm/Addons.js +5 -1
- package/examples/jsm/capabilities/WebGPU.js +13 -9
- package/examples/jsm/controls/DragControls.js +91 -30
- package/examples/jsm/controls/OrbitControls.js +130 -15
- package/examples/jsm/controls/TransformControls.js +6 -6
- package/examples/jsm/curves/NURBSUtils.js +59 -4
- package/examples/jsm/curves/NURBSVolume.js +62 -0
- package/examples/jsm/exporters/GLTFExporter.js +11 -1
- package/examples/jsm/exporters/USDZExporter.js +8 -7
- package/examples/jsm/helpers/TextureHelper.js +3 -3
- package/examples/jsm/interactive/InteractiveGroup.js +15 -25
- 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/loaders/3DMLoader.js +57 -64
- package/examples/jsm/loaders/DDSLoader.js +1 -0
- package/examples/jsm/loaders/KTX2Loader.js +20 -5
- package/examples/jsm/loaders/LUT3dlLoader.js +78 -46
- package/examples/jsm/loaders/LUTCubeLoader.js +81 -67
- package/examples/jsm/loaders/LUTImageLoader.js +3 -2
- package/examples/jsm/loaders/MaterialXLoader.js +115 -16
- package/examples/jsm/loaders/SVGLoader.js +4 -3
- package/examples/jsm/loaders/VOXLoader.js +9 -2
- package/examples/jsm/loaders/VRMLLoader.js +7 -3
- package/examples/jsm/materials/MeshPostProcessingMaterial.js +144 -0
- package/examples/jsm/misc/ProgressiveLightMap.js +1 -0
- package/examples/jsm/misc/Timer.js +13 -4
- package/examples/jsm/nodes/Nodes.js +24 -11
- package/examples/jsm/nodes/accessors/AccessorsUtils.js +10 -0
- package/examples/jsm/nodes/accessors/BufferAttributeNode.js +5 -3
- package/examples/jsm/nodes/accessors/CameraNode.js +9 -4
- package/examples/jsm/nodes/accessors/ClippingNode.js +144 -0
- package/examples/jsm/nodes/accessors/CubeTextureNode.js +12 -1
- 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 +8 -8
- package/examples/jsm/nodes/accessors/ReferenceNode.js +87 -29
- package/examples/jsm/nodes/accessors/SkinningNode.js +31 -10
- package/examples/jsm/nodes/accessors/StorageBufferNode.js +45 -0
- package/examples/jsm/nodes/accessors/TangentNode.js +8 -2
- package/examples/jsm/nodes/accessors/TextureNode.js +1 -1
- package/examples/jsm/nodes/accessors/TextureStoreNode.js +56 -3
- package/examples/jsm/nodes/accessors/UniformsNode.js +140 -0
- package/examples/jsm/nodes/accessors/VertexColorNode.js +70 -0
- package/examples/jsm/nodes/code/CodeNode.js +6 -0
- package/examples/jsm/nodes/core/AssignNode.js +68 -12
- package/examples/jsm/nodes/core/AttributeNode.js +1 -1
- package/examples/jsm/nodes/core/Node.js +14 -4
- package/examples/jsm/nodes/core/NodeBuilder.js +26 -27
- package/examples/jsm/nodes/core/NodeFrame.js +18 -10
- package/examples/jsm/nodes/core/TempNode.js +1 -1
- package/examples/jsm/nodes/core/constants.js +1 -0
- package/examples/jsm/nodes/display/AfterImageNode.js +148 -0
- package/examples/jsm/nodes/display/AnamorphicNode.js +148 -0
- package/examples/jsm/nodes/display/BlendModeNode.js +30 -1
- package/examples/jsm/nodes/display/ColorAdjustmentNode.js +3 -0
- package/examples/jsm/nodes/display/GaussianBlurNode.js +33 -13
- package/examples/jsm/nodes/display/NormalMapNode.js +3 -5
- package/examples/jsm/nodes/display/PassNode.js +3 -2
- package/examples/jsm/nodes/display/ToneMappingNode.js +46 -3
- package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +1 -4
- package/examples/jsm/nodes/display/ViewportNode.js +0 -2
- package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +4 -4
- package/examples/jsm/nodes/fog/FogNode.js +2 -1
- package/examples/jsm/nodes/lighting/AmbientLightNode.js +1 -1
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +13 -5
- package/examples/jsm/nodes/lighting/LightingContextNode.js +1 -1
- package/examples/jsm/nodes/lighting/LightsNode.js +1 -1
- package/examples/jsm/nodes/materials/Line2NodeMaterial.js +18 -30
- package/examples/jsm/nodes/materials/Materials.js +1 -0
- package/examples/jsm/nodes/materials/MeshSSSNodeMaterial.js +84 -0
- package/examples/jsm/nodes/materials/NodeMaterial.js +43 -10
- package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +1 -7
- package/examples/jsm/nodes/math/CondNode.js +42 -7
- package/examples/jsm/nodes/math/MathNode.js +32 -2
- package/examples/jsm/nodes/math/MathUtils.js +15 -0
- package/examples/jsm/nodes/math/OperatorNode.js +13 -5
- package/examples/jsm/nodes/math/TriNoise3D.js +71 -0
- package/examples/jsm/nodes/shadernode/ShaderNode.js +10 -1
- package/examples/jsm/nodes/utils/JoinNode.js +2 -2
- package/examples/jsm/nodes/utils/LoopNode.js +5 -3
- package/examples/jsm/nodes/utils/ReflectorNode.js +227 -0
- package/examples/jsm/nodes/utils/RotateNode.js +68 -0
- package/examples/jsm/nodes/utils/RotateUVNode.js +1 -9
- package/examples/jsm/nodes/utils/SplitNode.js +4 -4
- package/examples/jsm/nodes/utils/StorageArrayElementNode.js +91 -0
- package/examples/jsm/objects/GroundedSkybox.js +50 -0
- package/examples/jsm/objects/QuadMesh.js +8 -2
- package/examples/jsm/objects/Water2.js +8 -8
- package/examples/jsm/postprocessing/GTAOPass.js +11 -1
- package/examples/jsm/postprocessing/OutputPass.js +2 -0
- package/examples/jsm/renderers/common/Backend.js +14 -0
- package/examples/jsm/renderers/common/Background.js +2 -2
- package/examples/jsm/renderers/common/Bindings.js +1 -1
- package/examples/jsm/renderers/common/ClippingContext.js +165 -0
- package/examples/jsm/renderers/common/DataMap.js +1 -1
- package/examples/jsm/renderers/common/Info.js +25 -1
- package/examples/jsm/renderers/common/Pipelines.js +8 -8
- package/examples/jsm/renderers/common/PostProcessing.js +2 -2
- package/examples/jsm/renderers/common/ProgrammableStage.js +3 -1
- package/examples/jsm/renderers/common/RenderContext.js +2 -0
- package/examples/jsm/renderers/common/RenderContexts.js +2 -13
- package/examples/jsm/renderers/common/RenderObject.js +46 -1
- package/examples/jsm/renderers/common/RenderObjects.js +3 -1
- package/examples/jsm/renderers/common/Renderer.js +290 -17
- package/examples/jsm/renderers/common/StorageBufferAttribute.js +17 -0
- package/examples/jsm/renderers/common/StorageInstancedBufferAttribute.js +17 -0
- package/examples/jsm/renderers/common/Textures.js +28 -18
- package/examples/jsm/renderers/common/UniformsGroup.js +6 -4
- package/examples/jsm/renderers/common/nodes/NodeBuilderState.js +2 -1
- 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 +5 -2
- package/examples/jsm/renderers/webgl/WebGLBackend.js +653 -272
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +171 -39
- package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +95 -8
- package/examples/jsm/renderers/webgl/utils/WebGLConstants.js +11 -0
- package/examples/jsm/renderers/webgl/utils/WebGLState.js +197 -0
- package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +424 -11
- package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +3 -2
- package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +1 -21
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +2 -2
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +300 -112
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +7 -2
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +71 -79
- package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +15 -1
- package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +38 -4
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +87 -14
- package/examples/jsm/shaders/OutputShader.js +4 -0
- package/examples/jsm/transpiler/AST.js +1 -1
- package/examples/jsm/transpiler/GLSLDecoder.js +1 -1
- package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
- package/examples/jsm/transpiler/TSLEncoder.js +1 -1
- package/examples/jsm/utils/BufferGeometryUtils.js +23 -27
- package/examples/jsm/utils/SkeletonUtils.js +14 -3
- package/examples/jsm/utils/SortUtils.js +2 -0
- package/examples/jsm/webxr/ARButton.js +12 -2
- package/examples/jsm/webxr/VRButton.js +25 -7
- package/examples/jsm/webxr/XRButton.js +12 -3
- package/examples/jsm/webxr/XRControllerModelFactory.js +14 -1
- package/examples/jsm/webxr/XRHandMeshModel.js +3 -1
- package/package.json +5 -4
- package/src/Three.Legacy.js +20 -0
- package/src/Three.js +0 -1
- package/src/audio/Audio.js +1 -3
- package/src/cameras/PerspectiveCamera.js +35 -0
- package/src/constants.js +2 -6
- package/src/core/BufferAttribute.js +2 -12
- package/src/core/BufferGeometry.js +23 -29
- package/src/core/InterleavedBuffer.js +2 -1
- package/src/core/InterleavedBufferAttribute.js +20 -0
- package/src/core/Object3D.js +11 -0
- package/src/core/Raycaster.js +18 -4
- package/src/core/RenderTarget.js +44 -21
- package/src/extras/PMREMGenerator.js +2 -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 +2 -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 +2 -1
- package/src/math/Quaternion.js +13 -12
- package/src/math/Triangle.js +0 -30
- package/src/math/Vector3.js +7 -7
- package/src/objects/BatchedMesh.js +6 -7
- package/src/objects/InstancedMesh.js +53 -0
- package/src/objects/Mesh.js +0 -1
- package/src/objects/SkinnedMesh.js +0 -8
- package/src/renderers/WebGLCubeRenderTarget.js +1 -10
- package/src/renderers/WebGLRenderer.js +20 -23
- package/src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl.js +9 -0
- package/src/renderers/shaders/ShaderChunk/clipping_planes_fragment.glsl.js +56 -11
- 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/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/tonemapping_pars_fragment.glsl.js +38 -7
- 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 +3 -2
- package/src/renderers/shaders/ShaderLib/distanceRGBA.glsl.js +3 -2
- package/src/renderers/shaders/ShaderLib/linedashed.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +2 -2
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +2 -2
- package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +4 -1
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/points.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +1 -0
- package/src/renderers/shaders/ShaderLib/sprite.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib.js +2 -1
- package/src/renderers/shaders/UniformsLib.js +1 -0
- package/src/renderers/webgl/WebGLAttributes.js +2 -2
- package/src/renderers/webgl/WebGLBackground.js +18 -0
- package/src/renderers/webgl/WebGLCubeMaps.js +1 -1
- package/src/renderers/webgl/WebGLMaterials.js +24 -1
- package/src/renderers/webgl/WebGLMorphtargets.js +15 -8
- package/src/renderers/webgl/WebGLProgram.js +42 -4
- package/src/renderers/webgl/WebGLPrograms.js +38 -27
- package/src/renderers/webgl/WebGLState.js +11 -21
- package/src/renderers/webgl/WebGLTextures.js +170 -66
- package/src/renderers/webxr/WebXRDepthSensing.js +105 -0
- package/src/renderers/webxr/WebXRManager.js +46 -0
- package/src/scenes/Scene.js +8 -0
- package/src/textures/Source.js +1 -0
- package/src/textures/Texture.js +1 -29
- package/build/three.js +0 -54519
- package/build/three.min.js +0 -7
- package/examples/jsm/nodes/core/ArrayUniformNode.js +0 -26
- package/examples/jsm/objects/GroundProjectedSkybox.js +0 -172
- package/src/renderers/WebGLMultipleRenderTargets.js +0 -82
|
@@ -7,11 +7,11 @@ import { modelViewProjection } from '../accessors/ModelViewProjectionNode.js';
|
|
|
7
7
|
import { transformedNormalView } from '../accessors/NormalNode.js';
|
|
8
8
|
import { instance } from '../accessors/InstanceNode.js';
|
|
9
9
|
import { positionLocal, positionView } from '../accessors/PositionNode.js';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { skinningReference } from '../accessors/SkinningNode.js';
|
|
11
|
+
import { morphReference } from '../accessors/MorphNode.js';
|
|
12
12
|
import { texture } from '../accessors/TextureNode.js';
|
|
13
13
|
import { cubeTexture } from '../accessors/CubeTextureNode.js';
|
|
14
|
-
import {
|
|
14
|
+
import { lightsNode } from '../lighting/LightsNode.js';
|
|
15
15
|
import { mix } from '../math/MathNode.js';
|
|
16
16
|
import { float, vec3, vec4 } from '../shadernode/ShaderNode.js';
|
|
17
17
|
import AONode from '../lighting/AONode.js';
|
|
@@ -19,6 +19,8 @@ import { lightingContext } from '../lighting/LightingContextNode.js';
|
|
|
19
19
|
import EnvironmentNode from '../lighting/EnvironmentNode.js';
|
|
20
20
|
import { depthPixel } from '../display/ViewportDepthNode.js';
|
|
21
21
|
import { cameraLogDepth } from '../accessors/CameraNode.js';
|
|
22
|
+
import { clipping, clippingAlpha } from '../accessors/ClippingNode.js';
|
|
23
|
+
import { faceDirection } from '../display/FrontFacingNode.js';
|
|
22
24
|
|
|
23
25
|
const NodeMaterials = new Map();
|
|
24
26
|
|
|
@@ -53,6 +55,7 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
53
55
|
this.positionNode = null;
|
|
54
56
|
|
|
55
57
|
this.depthNode = null;
|
|
58
|
+
this.shadowNode = null;
|
|
56
59
|
|
|
57
60
|
this.outputNode = null;
|
|
58
61
|
|
|
@@ -89,6 +92,8 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
89
92
|
|
|
90
93
|
let resultNode;
|
|
91
94
|
|
|
95
|
+
const clippingNode = this.setupClipping( builder );
|
|
96
|
+
|
|
92
97
|
if ( this.fragmentNode === null ) {
|
|
93
98
|
|
|
94
99
|
if ( this.depthWrite === true ) this.setupDepth( builder );
|
|
@@ -100,6 +105,8 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
100
105
|
|
|
101
106
|
const outgoingLightNode = this.setupLighting( builder );
|
|
102
107
|
|
|
108
|
+
if ( clippingNode !== null ) builder.stack.add( clippingNode );
|
|
109
|
+
|
|
103
110
|
resultNode = this.setupOutput( builder, vec4( outgoingLightNode, diffuseColor.a ) );
|
|
104
111
|
|
|
105
112
|
// OUTPUT NODE
|
|
@@ -122,6 +129,31 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
122
129
|
|
|
123
130
|
}
|
|
124
131
|
|
|
132
|
+
setupClipping( builder ) {
|
|
133
|
+
|
|
134
|
+
const { globalClippingCount, localClippingCount } = builder.clippingContext;
|
|
135
|
+
|
|
136
|
+
let result = null;
|
|
137
|
+
|
|
138
|
+
if ( globalClippingCount || localClippingCount ) {
|
|
139
|
+
|
|
140
|
+
if ( this.alphaToCoverage ) {
|
|
141
|
+
|
|
142
|
+
// to be added to flow when the color/alpha value has been determined
|
|
143
|
+
result = clippingAlpha();
|
|
144
|
+
|
|
145
|
+
} else {
|
|
146
|
+
|
|
147
|
+
builder.stack.add( clipping() );
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return result;
|
|
154
|
+
|
|
155
|
+
}
|
|
156
|
+
|
|
125
157
|
setupDepth( builder ) {
|
|
126
158
|
|
|
127
159
|
const { renderer } = builder;
|
|
@@ -157,13 +189,13 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
157
189
|
|
|
158
190
|
if ( geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color ) {
|
|
159
191
|
|
|
160
|
-
|
|
192
|
+
morphReference( object ).append();
|
|
161
193
|
|
|
162
194
|
}
|
|
163
195
|
|
|
164
196
|
if ( object.isSkinnedMesh === true ) {
|
|
165
197
|
|
|
166
|
-
|
|
198
|
+
skinningReference( object ).append();
|
|
167
199
|
|
|
168
200
|
}
|
|
169
201
|
|
|
@@ -235,13 +267,13 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
235
267
|
|
|
236
268
|
const normalNode = positionView.dFdx().cross( positionView.dFdy() ).normalize();
|
|
237
269
|
|
|
238
|
-
transformedNormalView.assign( normalNode );
|
|
270
|
+
transformedNormalView.assign( normalNode.mul( faceDirection ) );
|
|
239
271
|
|
|
240
272
|
} else {
|
|
241
273
|
|
|
242
274
|
const normalNode = this.normalNode ? vec3( this.normalNode ) : materialNormal;
|
|
243
275
|
|
|
244
|
-
transformedNormalView.assign( normalNode );
|
|
276
|
+
transformedNormalView.assign( normalNode.mul( faceDirection ) );
|
|
245
277
|
|
|
246
278
|
}
|
|
247
279
|
|
|
@@ -289,15 +321,15 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
289
321
|
|
|
290
322
|
}
|
|
291
323
|
|
|
292
|
-
let
|
|
324
|
+
let lightsN = this.lightsNode || builder.lightsNode;
|
|
293
325
|
|
|
294
326
|
if ( materialLightsNode.length > 0 ) {
|
|
295
327
|
|
|
296
|
-
|
|
328
|
+
lightsN = lightsNode( [ ...lightsN.lightNodes, ...materialLightsNode ] );
|
|
297
329
|
|
|
298
330
|
}
|
|
299
331
|
|
|
300
|
-
return
|
|
332
|
+
return lightsN;
|
|
301
333
|
|
|
302
334
|
}
|
|
303
335
|
|
|
@@ -496,6 +528,7 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
496
528
|
this.positionNode = source.positionNode;
|
|
497
529
|
|
|
498
530
|
this.depthNode = source.depthNode;
|
|
531
|
+
this.shadowNode = source.shadowNode;
|
|
499
532
|
|
|
500
533
|
this.outputNode = source.outputNode;
|
|
501
534
|
|
|
@@ -61,13 +61,7 @@ class SpriteNodeMaterial extends NodeMaterial {
|
|
|
61
61
|
|
|
62
62
|
const rotation = float( rotationNode || materialRotation );
|
|
63
63
|
|
|
64
|
-
const
|
|
65
|
-
const sinAngle = rotation.sin();
|
|
66
|
-
|
|
67
|
-
const rotatedPosition = vec2( // @TODO: Maybe we can create mat2 and write something like rotationMatrix.mul( alignedPosition )?
|
|
68
|
-
vec2( cosAngle, sinAngle.negate() ).dot( alignedPosition ),
|
|
69
|
-
vec2( sinAngle, cosAngle ).dot( alignedPosition )
|
|
70
|
-
);
|
|
64
|
+
const rotatedPosition = alignedPosition.rotate( rotation );
|
|
71
65
|
|
|
72
66
|
mvPosition = vec4( mvPosition.xy.add( rotatedPosition ), mvPosition.zw );
|
|
73
67
|
|
|
@@ -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,18 @@ 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
|
+
|
|
68
|
+
} else if ( method === MathNode.MOD ) {
|
|
69
|
+
|
|
70
|
+
return this.aNode.getNodeType( builder );
|
|
71
|
+
|
|
60
72
|
} else {
|
|
61
73
|
|
|
62
74
|
return this.getInputType( builder );
|
|
@@ -120,7 +132,7 @@ class MathNode extends TempNode {
|
|
|
120
132
|
|
|
121
133
|
const params = [];
|
|
122
134
|
|
|
123
|
-
if ( method === MathNode.CROSS ) {
|
|
135
|
+
if ( method === MathNode.CROSS || method === MathNode.MOD ) {
|
|
124
136
|
|
|
125
137
|
params.push(
|
|
126
138
|
a.build( builder, type ),
|
|
@@ -165,7 +177,7 @@ class MathNode extends TempNode {
|
|
|
165
177
|
|
|
166
178
|
}
|
|
167
179
|
|
|
168
|
-
return builder.format( `${ builder.getMethod( method ) }( ${params.join( ', ' )} )`, type, output );
|
|
180
|
+
return builder.format( `${ builder.getMethod( method, type ) }( ${params.join( ', ' )} )`, type, output );
|
|
169
181
|
|
|
170
182
|
}
|
|
171
183
|
|
|
@@ -191,6 +203,10 @@ class MathNode extends TempNode {
|
|
|
191
203
|
|
|
192
204
|
// 1 input
|
|
193
205
|
|
|
206
|
+
MathNode.ALL = 'all';
|
|
207
|
+
MathNode.ANY = 'any';
|
|
208
|
+
MathNode.EQUALS = 'equals';
|
|
209
|
+
|
|
194
210
|
MathNode.RADIANS = 'radians';
|
|
195
211
|
MathNode.DEGREES = 'degrees';
|
|
196
212
|
MathNode.EXP = 'exp';
|
|
@@ -249,6 +265,12 @@ export default MathNode;
|
|
|
249
265
|
|
|
250
266
|
export const EPSILON = float( 1e-6 );
|
|
251
267
|
export const INFINITY = float( 1e6 );
|
|
268
|
+
export const PI = float( Math.PI );
|
|
269
|
+
export const PI2 = float( Math.PI * 2 );
|
|
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 );
|
|
252
274
|
|
|
253
275
|
export const radians = nodeProxy( MathNode, MathNode.RADIANS );
|
|
254
276
|
export const degrees = nodeProxy( MathNode, MathNode.DEGREES );
|
|
@@ -297,6 +319,8 @@ export const pow3 = nodeProxy( MathNode, MathNode.POW, 3 );
|
|
|
297
319
|
export const pow4 = nodeProxy( MathNode, MathNode.POW, 4 );
|
|
298
320
|
export const transformDirection = nodeProxy( MathNode, MathNode.TRANSFORM_DIRECTION );
|
|
299
321
|
|
|
322
|
+
export const cbrt = ( a ) => mul( sign( a ), pow( abs( a ), 1.0 / 3.0 ) );
|
|
323
|
+
export const lengthSq = ( a ) => dot( a, a );
|
|
300
324
|
export const mix = nodeProxy( MathNode, MathNode.MIX );
|
|
301
325
|
export const clamp = ( value, low = 0, high = 1 ) => nodeObject( new MathNode( MathNode.CLAMP, nodeObject( value ), nodeObject( low ), nodeObject( high ) ) );
|
|
302
326
|
export const saturate = ( value ) => clamp( value );
|
|
@@ -307,6 +331,10 @@ export const faceForward = nodeProxy( MathNode, MathNode.FACEFORWARD );
|
|
|
307
331
|
export const mixElement = ( t, e1, e2 ) => mix( e1, e2, t );
|
|
308
332
|
export const smoothstepElement = ( x, low, high ) => smoothstep( low, high, x );
|
|
309
333
|
|
|
334
|
+
addNodeElement( 'all', all );
|
|
335
|
+
addNodeElement( 'any', any );
|
|
336
|
+
addNodeElement( 'equals', equals );
|
|
337
|
+
|
|
310
338
|
addNodeElement( 'radians', radians );
|
|
311
339
|
addNodeElement( 'degrees', degrees );
|
|
312
340
|
addNodeElement( 'exp', exp );
|
|
@@ -328,6 +356,7 @@ addNodeElement( 'atan', atan );
|
|
|
328
356
|
addNodeElement( 'abs', abs );
|
|
329
357
|
addNodeElement( 'sign', sign );
|
|
330
358
|
addNodeElement( 'length', length );
|
|
359
|
+
addNodeElement( 'lengthSq', lengthSq );
|
|
331
360
|
addNodeElement( 'negate', negate );
|
|
332
361
|
addNodeElement( 'oneMinus', oneMinus );
|
|
333
362
|
addNodeElement( 'dFdx', dFdx );
|
|
@@ -357,5 +386,6 @@ addNodeElement( 'smoothstep', smoothstepElement );
|
|
|
357
386
|
addNodeElement( 'faceForward', faceForward );
|
|
358
387
|
addNodeElement( 'difference', difference );
|
|
359
388
|
addNodeElement( 'saturate', saturate );
|
|
389
|
+
addNodeElement( 'cbrt', cbrt );
|
|
360
390
|
|
|
361
391
|
addNodeClass( 'MathNode', MathNode );
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { sub, mul, div, add } from './OperatorNode.js';
|
|
2
|
+
import { addNodeElement } from '../shadernode/ShaderNode.js';
|
|
3
|
+
import { PI, pow, sin } from './MathNode.js';
|
|
4
|
+
|
|
5
|
+
// remapping functions https://iquilezles.org/articles/functions/
|
|
6
|
+
export const parabola = ( x, k ) => pow( mul( 4.0, x.mul( sub( 1.0, x ) ) ), k );
|
|
7
|
+
export const gain = ( x, k ) => x.lessThan( 0.5 ) ? parabola( x.mul( 2.0 ), k ).div( 2.0 ) : sub( 1.0, parabola( mul( sub( 1.0, x ), 2.0 ), k ).div( 2.0 ) );
|
|
8
|
+
export const pcurve = ( x, a, b ) => pow( div( pow( x, a ), add( pow( x, a ), pow( sub( 1.0, x ), b ) ) ), 1.0 / a );
|
|
9
|
+
export const sinc = ( x, k ) => sin( PI.mul( k.mul( x ).sub( 1.0 ) ) ).div( PI.mul( k.mul( x ).sub( 1.0 ) ) );
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
addNodeElement( 'parabola', parabola );
|
|
13
|
+
addNodeElement( 'gain', gain );
|
|
14
|
+
addNodeElement( 'pcurve', pcurve );
|
|
15
|
+
addNodeElement( 'sinc', sinc );
|
|
@@ -37,7 +37,7 @@ class OperatorNode extends TempNode {
|
|
|
37
37
|
const bNode = this.bNode;
|
|
38
38
|
|
|
39
39
|
const typeA = aNode.getNodeType( builder );
|
|
40
|
-
const typeB = bNode.getNodeType( builder );
|
|
40
|
+
const typeB = typeof bNode !== 'undefined' ? bNode.getNodeType( builder ) : null;
|
|
41
41
|
|
|
42
42
|
if ( typeA === 'void' || typeB === 'void' ) {
|
|
43
43
|
|
|
@@ -47,11 +47,11 @@ class OperatorNode extends TempNode {
|
|
|
47
47
|
|
|
48
48
|
return typeA;
|
|
49
49
|
|
|
50
|
-
} else if ( op === '&' || op === '|' || op === '^' || op === '>>' || op === '<<' ) {
|
|
50
|
+
} else if ( op === '~' || op === '&' || op === '|' || op === '^' || op === '>>' || op === '<<' ) {
|
|
51
51
|
|
|
52
52
|
return builder.getIntegerType( typeA );
|
|
53
53
|
|
|
54
|
-
} else if ( op === '==' || op === '&&' || op === '||' || op === '^^' ) {
|
|
54
|
+
} else if ( op === '!' || op === '==' || op === '&&' || op === '||' || op === '^^' ) {
|
|
55
55
|
|
|
56
56
|
return 'bool';
|
|
57
57
|
|
|
@@ -108,7 +108,7 @@ class OperatorNode extends TempNode {
|
|
|
108
108
|
if ( type !== 'void' ) {
|
|
109
109
|
|
|
110
110
|
typeA = aNode.getNodeType( builder );
|
|
111
|
-
typeB = bNode.getNodeType( builder );
|
|
111
|
+
typeB = typeof bNode !== 'undefined' ? bNode.getNodeType( builder ) : null;
|
|
112
112
|
|
|
113
113
|
if ( op === '<' || op === '>' || op === '<=' || op === '>=' || op === '==' ) {
|
|
114
114
|
|
|
@@ -154,7 +154,7 @@ class OperatorNode extends TempNode {
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
const a = aNode.build( builder, typeA );
|
|
157
|
-
const b = bNode.build( builder, typeB );
|
|
157
|
+
const b = typeof bNode !== 'undefined' ? bNode.build( builder, typeB ) : null;
|
|
158
158
|
|
|
159
159
|
const outputLength = builder.getTypeLength( output );
|
|
160
160
|
const fnOpSnippet = builder.getFunctionOperator( op );
|
|
@@ -177,6 +177,10 @@ class OperatorNode extends TempNode {
|
|
|
177
177
|
|
|
178
178
|
return builder.format( `${ builder.getMethod( 'greaterThanEqual' ) }( ${ a }, ${ b } )`, type, output );
|
|
179
179
|
|
|
180
|
+
} else if ( op === '!' || op === '~' ) {
|
|
181
|
+
|
|
182
|
+
return builder.format( `(${op}${a})`, typeA, output );
|
|
183
|
+
|
|
180
184
|
} else if ( fnOpSnippet ) {
|
|
181
185
|
|
|
182
186
|
return builder.format( `${ fnOpSnippet }( ${ a }, ${ b } )`, type, output );
|
|
@@ -236,8 +240,10 @@ export const lessThanEqual = nodeProxy( OperatorNode, '<=' );
|
|
|
236
240
|
export const greaterThanEqual = nodeProxy( OperatorNode, '>=' );
|
|
237
241
|
export const and = nodeProxy( OperatorNode, '&&' );
|
|
238
242
|
export const or = nodeProxy( OperatorNode, '||' );
|
|
243
|
+
export const not = nodeProxy( OperatorNode, '!' );
|
|
239
244
|
export const xor = nodeProxy( OperatorNode, '^^' );
|
|
240
245
|
export const bitAnd = nodeProxy( OperatorNode, '&' );
|
|
246
|
+
export const bitNot = nodeProxy( OperatorNode, '~' );
|
|
241
247
|
export const bitOr = nodeProxy( OperatorNode, '|' );
|
|
242
248
|
export const bitXor = nodeProxy( OperatorNode, '^' );
|
|
243
249
|
export const shiftLeft = nodeProxy( OperatorNode, '<<' );
|
|
@@ -256,8 +262,10 @@ addNodeElement( 'lessThanEqual', lessThanEqual );
|
|
|
256
262
|
addNodeElement( 'greaterThanEqual', greaterThanEqual );
|
|
257
263
|
addNodeElement( 'and', and );
|
|
258
264
|
addNodeElement( 'or', or );
|
|
265
|
+
addNodeElement( 'not', not );
|
|
259
266
|
addNodeElement( 'xor', xor );
|
|
260
267
|
addNodeElement( 'bitAnd', bitAnd );
|
|
268
|
+
addNodeElement( 'bitNot', bitNot );
|
|
261
269
|
addNodeElement( 'bitOr', bitOr );
|
|
262
270
|
addNodeElement( 'bitXor', bitXor );
|
|
263
271
|
addNodeElement( 'shiftLeft', shiftLeft );
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// https://github.com/cabbibo/glsl-tri-noise-3d
|
|
2
|
+
|
|
3
|
+
import { loop } from '../utils/LoopNode.js';
|
|
4
|
+
import { float, vec3, tslFn } from '../shadernode/ShaderNode.js';
|
|
5
|
+
|
|
6
|
+
const tri = tslFn( ( [ x ] ) => {
|
|
7
|
+
|
|
8
|
+
return x.fract().sub( .5 ).abs();
|
|
9
|
+
|
|
10
|
+
} );
|
|
11
|
+
|
|
12
|
+
const tri3 = tslFn( ( [ p ] ) => {
|
|
13
|
+
|
|
14
|
+
return vec3( tri( p.z.add( tri( p.y.mul( 1. ) ) ) ), tri( p.z.add( tri( p.x.mul( 1. ) ) ) ), tri( p.y.add( tri( p.x.mul( 1. ) ) ) ) );
|
|
15
|
+
|
|
16
|
+
} );
|
|
17
|
+
|
|
18
|
+
const triNoise3D = tslFn( ( [ p_immutable, spd, time ] ) => {
|
|
19
|
+
|
|
20
|
+
const p = vec3( p_immutable ).toVar();
|
|
21
|
+
const z = float( 1.4 ).toVar();
|
|
22
|
+
const rz = float( 0.0 ).toVar();
|
|
23
|
+
const bp = vec3( p ).toVar();
|
|
24
|
+
|
|
25
|
+
loop( { start: float( 0.0 ), end: float( 3.0 ), type: 'float', condition: '<=' }, () => {
|
|
26
|
+
|
|
27
|
+
const dg = vec3( tri3( bp.mul( 2.0 ) ) ).toVar();
|
|
28
|
+
p.addAssign( dg.add( time.mul( float( 0.1 ).mul( spd ) ) ) );
|
|
29
|
+
bp.mulAssign( 1.8 );
|
|
30
|
+
z.mulAssign( 1.5 );
|
|
31
|
+
p.mulAssign( 1.2 );
|
|
32
|
+
|
|
33
|
+
const t = float( tri( p.z.add( tri( p.x.add( tri( p.y ) ) ) ) ) ).toVar();
|
|
34
|
+
rz.addAssign( t.div( z ) );
|
|
35
|
+
bp.addAssign( 0.14 );
|
|
36
|
+
|
|
37
|
+
} );
|
|
38
|
+
|
|
39
|
+
return rz;
|
|
40
|
+
|
|
41
|
+
} );
|
|
42
|
+
|
|
43
|
+
// layouts
|
|
44
|
+
|
|
45
|
+
tri.setLayout( {
|
|
46
|
+
name: 'tri',
|
|
47
|
+
type: 'float',
|
|
48
|
+
inputs: [
|
|
49
|
+
{ name: 'x', type: 'float' }
|
|
50
|
+
]
|
|
51
|
+
} );
|
|
52
|
+
|
|
53
|
+
tri3.setLayout( {
|
|
54
|
+
name: 'tri3',
|
|
55
|
+
type: 'vec3',
|
|
56
|
+
inputs: [
|
|
57
|
+
{ name: 'p', type: 'vec3' }
|
|
58
|
+
]
|
|
59
|
+
} );
|
|
60
|
+
|
|
61
|
+
triNoise3D.setLayout( {
|
|
62
|
+
name: 'triNoise3D',
|
|
63
|
+
type: 'float',
|
|
64
|
+
inputs: [
|
|
65
|
+
{ name: 'p', type: 'vec3' },
|
|
66
|
+
{ name: 'spd', type: 'float' },
|
|
67
|
+
{ name: 'time', type: 'float' }
|
|
68
|
+
]
|
|
69
|
+
} );
|
|
70
|
+
|
|
71
|
+
export { tri, tri3, triNoise3D };
|
|
@@ -341,7 +341,7 @@ class ShaderNodeInternal extends Node {
|
|
|
341
341
|
|
|
342
342
|
get isArrayInput() {
|
|
343
343
|
|
|
344
|
-
return /^\(\s
|
|
344
|
+
return /^\((\s+)?\[/.test( this.jsFunc.toString() );
|
|
345
345
|
|
|
346
346
|
}
|
|
347
347
|
|
|
@@ -574,6 +574,11 @@ export const ivec4 = new ConvertType( 'ivec4' );
|
|
|
574
574
|
export const uvec4 = new ConvertType( 'uvec4' );
|
|
575
575
|
export const bvec4 = new ConvertType( 'bvec4' );
|
|
576
576
|
|
|
577
|
+
export const mat2 = new ConvertType( 'mat2' );
|
|
578
|
+
export const imat2 = new ConvertType( 'imat2' );
|
|
579
|
+
export const umat2 = new ConvertType( 'umat2' );
|
|
580
|
+
export const bmat2 = new ConvertType( 'bmat2' );
|
|
581
|
+
|
|
577
582
|
export const mat3 = new ConvertType( 'mat3' );
|
|
578
583
|
export const imat3 = new ConvertType( 'imat3' );
|
|
579
584
|
export const umat3 = new ConvertType( 'umat3' );
|
|
@@ -604,6 +609,10 @@ addNodeElement( 'vec4', vec4 );
|
|
|
604
609
|
addNodeElement( 'ivec4', ivec4 );
|
|
605
610
|
addNodeElement( 'uvec4', uvec4 );
|
|
606
611
|
addNodeElement( 'bvec4', bvec4 );
|
|
612
|
+
addNodeElement( 'mat2', mat2 );
|
|
613
|
+
addNodeElement( 'imat2', imat2 );
|
|
614
|
+
addNodeElement( 'umat2', umat2 );
|
|
615
|
+
addNodeElement( 'bmat2', bmat2 );
|
|
607
616
|
addNodeElement( 'mat3', mat3 );
|
|
608
617
|
addNodeElement( 'imat3', imat3 );
|
|
609
618
|
addNodeElement( 'umat3', umat3 );
|
|
@@ -28,7 +28,7 @@ class JoinNode extends TempNode {
|
|
|
28
28
|
const type = this.getNodeType( builder );
|
|
29
29
|
const nodes = this.nodes;
|
|
30
30
|
|
|
31
|
-
const primitiveType = builder.
|
|
31
|
+
const primitiveType = builder.getComponentType( type );
|
|
32
32
|
|
|
33
33
|
const snippetValues = [];
|
|
34
34
|
|
|
@@ -36,7 +36,7 @@ class JoinNode extends TempNode {
|
|
|
36
36
|
|
|
37
37
|
let inputSnippet = input.build( builder );
|
|
38
38
|
|
|
39
|
-
const inputPrimitiveType = builder.
|
|
39
|
+
const inputPrimitiveType = builder.getComponentType( input.getNodeType( builder ) );
|
|
40
40
|
|
|
41
41
|
if ( inputPrimitiveType !== primitiveType ) {
|
|
42
42
|
|
|
@@ -144,15 +144,15 @@ class LoopNode extends Node {
|
|
|
144
144
|
|
|
145
145
|
if ( ! update ) {
|
|
146
146
|
|
|
147
|
-
if ( type === 'int' ) {
|
|
147
|
+
if ( type === 'int' || type === 'uint' ) {
|
|
148
148
|
|
|
149
149
|
if ( condition.includes( '<' ) ) update = '++';
|
|
150
150
|
else update = '--';
|
|
151
151
|
|
|
152
152
|
} else {
|
|
153
153
|
|
|
154
|
-
if ( condition.includes( '<' ) ) update = '+= 1';
|
|
155
|
-
else update = '-= 1';
|
|
154
|
+
if ( condition.includes( '<' ) ) update = '+= 1.';
|
|
155
|
+
else update = '-= 1.';
|
|
156
156
|
|
|
157
157
|
}
|
|
158
158
|
|
|
@@ -192,6 +192,8 @@ class LoopNode extends Node {
|
|
|
192
192
|
export default LoopNode;
|
|
193
193
|
|
|
194
194
|
export const loop = ( ...params ) => nodeObject( new LoopNode( nodeArray( params, 'int' ) ) ).append();
|
|
195
|
+
export const Continue = () => expression( 'continue' ).append();
|
|
196
|
+
export const Break = () => expression( 'break' ).append();
|
|
195
197
|
|
|
196
198
|
addNodeElement( 'loop', ( returns, ...params ) => bypass( returns, loop( ...params ) ) );
|
|
197
199
|
|