super-three 0.157.1 → 0.160.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/build/three.cjs +3100 -1537
- package/build/three.js +3100 -1537
- package/build/three.min.js +1 -1
- package/build/three.module.js +3093 -1538
- package/build/three.module.min.js +1 -1
- package/examples/jsm/Addons.js +291 -0
- package/examples/jsm/controls/FlyControls.js +26 -0
- package/examples/jsm/controls/OrbitControls.js +62 -41
- package/examples/jsm/controls/TransformControls.js +27 -11
- package/examples/jsm/csm/CSMShader.js +53 -48
- package/examples/jsm/exporters/GLTFExporter.js +151 -3
- package/examples/jsm/exporters/USDZExporter.js +27 -19
- package/examples/jsm/geometries/InstancedPointsGeometry.js +174 -0
- package/examples/jsm/geometries/SDFGeometryGenerator.js +144 -0
- package/examples/jsm/helpers/TextureHelper.js +237 -0
- package/examples/jsm/interactive/HTMLMesh.js +9 -2
- package/examples/jsm/libs/lottie_canvas.module.js +6 -1
- package/examples/jsm/libs/opentype.module.js +13 -75
- package/examples/jsm/libs/surfaceNet.js +201 -0
- package/examples/jsm/lines/LineMaterial.js +16 -33
- package/examples/jsm/loaders/ColladaLoader.js +0 -6
- package/examples/jsm/loaders/DRACOLoader.js +4 -3
- package/examples/jsm/loaders/FBXLoader.js +294 -124
- package/examples/jsm/loaders/GLTFLoader.js +83 -6
- package/examples/jsm/loaders/LUTImageLoader.js +162 -0
- package/examples/jsm/loaders/MaterialXLoader.js +73 -54
- package/examples/jsm/loaders/NRRDLoader.js +0 -13
- package/examples/jsm/loaders/SVGLoader.js +4 -4
- package/examples/jsm/loaders/USDZLoader.js +3 -17
- package/examples/jsm/loaders/lwo/IFFParser.js +89 -93
- package/examples/jsm/materials/MeshGouraudMaterial.js +2 -0
- package/examples/jsm/math/Capsule.js +0 -55
- package/examples/jsm/math/Octree.js +85 -7
- package/examples/jsm/misc/Timer.js +119 -0
- package/examples/jsm/misc/TubePainter.js +3 -6
- package/examples/jsm/modifiers/CurveModifier.js +20 -2
- package/examples/jsm/modifiers/SimplifyModifier.js +103 -11
- package/examples/jsm/modifiers/TessellateModifier.js +3 -3
- package/examples/jsm/nodes/Nodes.js +16 -12
- package/examples/jsm/nodes/accessors/CameraNode.js +18 -2
- package/examples/jsm/nodes/accessors/CubeTextureNode.js +5 -73
- package/examples/jsm/nodes/accessors/InstanceNode.js +3 -3
- package/examples/jsm/nodes/accessors/InstancedPointsMaterialNode.js +21 -0
- package/examples/jsm/nodes/accessors/MaterialNode.js +68 -31
- package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +11 -2
- package/examples/jsm/nodes/accessors/ModelNode.js +1 -2
- package/examples/jsm/nodes/accessors/ModelViewProjectionNode.js +12 -3
- package/examples/jsm/nodes/accessors/MorphNode.js +191 -16
- package/examples/jsm/nodes/accessors/NormalNode.js +1 -1
- package/examples/jsm/nodes/accessors/PositionNode.js +1 -1
- package/examples/jsm/nodes/accessors/ReferenceNode.js +25 -1
- package/examples/jsm/nodes/accessors/SkinningNode.js +13 -3
- package/examples/jsm/nodes/accessors/TextureNode.js +123 -37
- package/examples/jsm/nodes/code/CodeNode.js +3 -3
- package/examples/jsm/nodes/code/FunctionNode.js +1 -1
- package/examples/jsm/nodes/core/AssignNode.js +72 -0
- package/examples/jsm/nodes/core/AttributeNode.js +7 -1
- package/examples/jsm/nodes/core/CacheNode.js +4 -1
- package/examples/jsm/nodes/core/ConstNode.js +1 -1
- package/examples/jsm/nodes/core/LightingModel.js +3 -1
- package/examples/jsm/nodes/core/Node.js +13 -15
- package/examples/jsm/nodes/core/NodeBuilder.js +209 -42
- package/examples/jsm/nodes/core/NodeFrame.js +10 -8
- package/examples/jsm/nodes/core/NodeUniform.js +12 -0
- package/examples/jsm/nodes/core/NodeUtils.js +7 -9
- package/examples/jsm/nodes/core/OutputStructNode.js +4 -4
- package/examples/jsm/nodes/core/ParameterNode.js +33 -0
- package/examples/jsm/nodes/core/PropertyNode.js +15 -6
- package/examples/jsm/nodes/core/StackNode.js +7 -17
- package/examples/jsm/nodes/core/StructTypeNode.js +4 -4
- package/examples/jsm/nodes/core/TempNode.js +1 -1
- package/examples/jsm/nodes/core/UniformGroup.js +13 -0
- package/examples/jsm/nodes/core/UniformGroupNode.js +36 -0
- package/examples/jsm/nodes/core/UniformNode.js +17 -0
- package/examples/jsm/nodes/core/VarNode.js +7 -34
- package/examples/jsm/nodes/core/VaryingNode.js +3 -7
- package/examples/jsm/nodes/display/BumpMapNode.js +35 -13
- package/examples/jsm/nodes/display/ColorAdjustmentNode.js +6 -10
- package/examples/jsm/nodes/display/GaussianBlurNode.js +170 -0
- package/examples/jsm/nodes/display/NormalMapNode.js +3 -1
- package/examples/jsm/nodes/display/PassNode.js +182 -0
- package/examples/jsm/nodes/display/ViewportDepthNode.js +31 -3
- package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +2 -2
- package/examples/jsm/nodes/display/ViewportNode.js +17 -10
- package/examples/jsm/nodes/functions/BSDF/BRDF_Sheen.js +20 -6
- package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +8 -7
- package/examples/jsm/nodes/functions/BSDF/D_GGX.js +8 -3
- package/examples/jsm/nodes/functions/BSDF/Schlick_to_F0.js +8 -0
- package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +8 -0
- package/examples/jsm/nodes/functions/PhysicalLightingModel.js +93 -43
- package/examples/jsm/nodes/gpgpu/ComputeNode.js +2 -2
- package/examples/jsm/nodes/lighting/AmbientLightNode.js +1 -1
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +55 -6
- package/examples/jsm/nodes/lighting/DirectionalLightNode.js +1 -1
- package/examples/jsm/nodes/lighting/EnvironmentNode.js +8 -18
- package/examples/jsm/nodes/lighting/LightingContextNode.js +21 -57
- package/examples/jsm/nodes/lighting/LightsNode.js +80 -20
- package/examples/jsm/nodes/lighting/PointLightNode.js +1 -1
- package/examples/jsm/nodes/lighting/SpotLightNode.js +1 -1
- package/examples/jsm/nodes/materials/InstancedPointsNodeMaterial.js +162 -0
- package/examples/jsm/nodes/materials/Line2NodeMaterial.js +76 -77
- package/examples/jsm/nodes/materials/LineDashedNodeMaterial.js +5 -5
- package/examples/jsm/nodes/materials/Materials.js +1 -0
- package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +1 -0
- package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +3 -3
- package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +3 -3
- package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +47 -20
- package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +6 -6
- package/examples/jsm/nodes/materials/NodeMaterial.js +82 -60
- package/examples/jsm/nodes/materials/PointsNodeMaterial.js +0 -10
- package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +0 -7
- package/examples/jsm/nodes/materialx/MaterialXNodes.js +10 -10
- package/examples/jsm/nodes/materialx/lib/mx_hsv.js +128 -54
- package/examples/jsm/nodes/materialx/lib/mx_noise.js +1430 -618
- package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +24 -14
- package/examples/jsm/nodes/math/MathNode.js +2 -0
- package/examples/jsm/nodes/math/OperatorNode.js +24 -27
- package/examples/jsm/nodes/shadernode/ShaderNode.js +158 -10
- package/examples/jsm/nodes/utils/ArrayElementNode.js +2 -0
- package/examples/jsm/nodes/utils/DiscardNode.js +3 -2
- package/examples/jsm/nodes/utils/FunctionOverloadingNode.js +95 -0
- package/examples/jsm/nodes/utils/JoinNode.js +11 -1
- package/examples/jsm/nodes/utils/LoopNode.js +36 -24
- package/examples/jsm/nodes/utils/RemapNode.js +2 -2
- package/examples/jsm/nodes/utils/SplitNode.js +10 -2
- package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +3 -3
- package/examples/jsm/objects/InstancedPoints.js +21 -0
- package/examples/jsm/objects/Lensflare.js +20 -0
- package/examples/jsm/objects/QuadMesh.js +60 -0
- package/examples/jsm/objects/ReflectorForSSRPass.js +3 -0
- package/examples/jsm/objects/Refractor.js +3 -0
- package/examples/jsm/objects/Sky.js +5 -3
- package/examples/jsm/objects/Water.js +5 -2
- package/examples/jsm/objects/Water2.js +3 -0
- package/examples/jsm/physics/AmmoPhysics.js +21 -0
- package/examples/jsm/physics/RapierPhysics.js +21 -0
- package/examples/jsm/postprocessing/BokehPass.js +3 -2
- package/examples/jsm/postprocessing/GTAOPass.js +572 -0
- package/examples/jsm/postprocessing/LUTPass.js +2 -1
- package/examples/jsm/postprocessing/OutputPass.js +3 -0
- package/examples/jsm/postprocessing/Pass.js +14 -3
- package/examples/jsm/postprocessing/SAOPass.js +0 -1
- package/examples/jsm/postprocessing/SMAAPass.js +0 -2
- package/examples/jsm/postprocessing/TAARenderPass.js +1 -2
- package/examples/jsm/renderers/CSS3DRenderer.js +3 -9
- package/examples/jsm/renderers/SVGRenderer.js +9 -6
- package/examples/jsm/renderers/common/Animation.js +10 -21
- package/examples/jsm/renderers/common/Backend.js +19 -3
- package/examples/jsm/renderers/common/Background.js +20 -22
- package/examples/jsm/renderers/common/Bindings.js +31 -22
- package/examples/jsm/renderers/common/ChainMap.js +3 -3
- package/examples/jsm/renderers/common/Color4.js +37 -0
- package/examples/jsm/renderers/common/Geometries.js +4 -4
- package/examples/jsm/renderers/common/Info.js +12 -2
- package/examples/jsm/renderers/common/Pipelines.js +3 -51
- package/examples/jsm/renderers/common/PostProcessing.js +25 -0
- package/examples/jsm/renderers/common/RenderContext.js +1 -1
- package/examples/jsm/renderers/common/RenderContexts.js +1 -1
- package/examples/jsm/renderers/common/RenderObject.js +21 -2
- package/examples/jsm/renderers/common/RenderObjects.js +5 -3
- package/examples/jsm/renderers/common/Renderer.js +137 -37
- package/examples/jsm/renderers/common/StorageTexture.js +1 -0
- package/examples/jsm/renderers/common/Textures.js +8 -37
- package/examples/jsm/renderers/common/nodes/NodeBuilderState.js +10 -2
- package/examples/jsm/renderers/common/nodes/NodeUniformsGroup.js +44 -0
- package/examples/jsm/renderers/common/nodes/Nodes.js +121 -19
- package/examples/jsm/renderers/webgl/WebGLBackend.js +366 -67
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +183 -38
- package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +92 -5
- package/examples/jsm/renderers/webgl/utils/WebGLCapabilities.js +36 -0
- package/examples/jsm/renderers/webgl/utils/WebGLExtensions.js +11 -1
- package/examples/jsm/renderers/webgl/utils/WebGLState.js +14 -2
- package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +71 -2
- package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +42 -0
- package/examples/jsm/renderers/webgl-legacy/nodes/SlotNode.js +1 -1
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +33 -3
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js +4 -14
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +188 -137
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +1 -1
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +241 -90
- package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +15 -10
- package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +11 -3
- package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +2 -3
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +88 -6
- package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +2 -0
- package/examples/jsm/shaders/AfterimageShader.js +2 -0
- package/examples/jsm/shaders/BasicShader.js +2 -0
- package/examples/jsm/shaders/BlendShader.js +2 -0
- package/examples/jsm/shaders/BokehShader.js +2 -0
- package/examples/jsm/shaders/BokehShader2.js +4 -0
- package/examples/jsm/shaders/BrightnessContrastShader.js +2 -0
- package/examples/jsm/shaders/ColorCorrectionShader.js +2 -0
- package/examples/jsm/shaders/DOFMipMapShader.js +2 -0
- package/examples/jsm/shaders/DepthLimitedBlurShader.js +5 -0
- package/examples/jsm/shaders/FXAAShader.js +135 -133
- package/examples/jsm/shaders/FilmShader.js +1 -1
- package/examples/jsm/shaders/FocusShader.js +2 -0
- package/examples/jsm/shaders/FreiChenShader.js +2 -0
- package/examples/jsm/shaders/GTAOShader.js +424 -0
- package/examples/jsm/shaders/GodRaysShader.js +8 -0
- package/examples/jsm/shaders/HalftoneShader.js +2 -0
- package/examples/jsm/shaders/HorizontalTiltShiftShader.js +2 -0
- package/examples/jsm/shaders/HueSaturationShader.js +2 -0
- package/examples/jsm/shaders/KaleidoShader.js +2 -0
- package/examples/jsm/shaders/LuminosityHighPassShader.js +2 -0
- package/examples/jsm/shaders/LuminosityShader.js +2 -0
- package/examples/jsm/shaders/MMDToonShader.js +2 -0
- package/examples/jsm/shaders/MirrorShader.js +2 -0
- package/examples/jsm/shaders/NormalMapShader.js +2 -0
- package/examples/jsm/shaders/OutputShader.js +8 -5
- package/examples/jsm/shaders/PoissonDenoiseShader.js +226 -0
- package/examples/jsm/shaders/SAOShader.js +7 -3
- package/examples/jsm/shaders/SMAAShader.js +6 -0
- package/examples/jsm/shaders/SSAOShader.js +8 -3
- package/examples/jsm/shaders/SSRShader.js +6 -0
- package/examples/jsm/shaders/SobelOperatorShader.js +2 -0
- package/examples/jsm/shaders/SubsurfaceScatteringShader.js +2 -0
- package/examples/jsm/shaders/TechnicolorShader.js +2 -0
- package/examples/jsm/shaders/TriangleBlurShader.js +2 -0
- package/examples/jsm/shaders/UnpackDepthRGBAShader.js +2 -0
- package/examples/jsm/shaders/VelocityShader.js +2 -0
- package/examples/jsm/shaders/VerticalTiltShiftShader.js +2 -0
- package/examples/jsm/shaders/WaterRefractionShader.js +2 -0
- package/examples/jsm/transpiler/AST.js +270 -0
- package/examples/jsm/transpiler/GLSLDecoder.js +941 -0
- package/examples/jsm/transpiler/ShaderToyDecoder.js +49 -0
- package/examples/jsm/transpiler/TSLEncoder.js +715 -0
- package/examples/jsm/transpiler/Transpiler.js +18 -0
- package/examples/jsm/utils/SortUtils.js +158 -0
- package/examples/jsm/utils/TextureUtils.js +33 -21
- package/examples/jsm/webxr/ARButton.js +14 -0
- package/examples/jsm/webxr/VRButton.js +24 -9
- package/examples/jsm/webxr/XRButton.js +27 -11
- package/examples/jsm/webxr/XREstimatedLight.js +1 -1
- package/package.json +8 -6
- package/src/Three.js +1 -0
- package/src/constants.js +8 -1
- package/src/core/BufferAttribute.js +21 -2
- package/src/core/InterleavedBuffer.js +21 -1
- package/src/core/Object3D.js +60 -12
- package/src/core/UniformsGroup.js +7 -1
- package/src/extras/PMREMGenerator.js +7 -1
- package/src/extras/curves/LineCurve3.js +4 -0
- package/src/loaders/AudioLoader.js +1 -1
- package/src/loaders/BufferGeometryLoader.js +0 -7
- package/src/loaders/ImageBitmapLoader.js +25 -1
- package/src/loaders/MaterialLoader.js +10 -2
- package/src/loaders/ObjectLoader.js +49 -0
- package/src/materials/Material.js +27 -13
- package/src/materials/ShaderMaterial.js +2 -1
- package/src/math/Box3.js +35 -18
- package/src/math/ColorManagement.js +0 -16
- package/src/math/Quaternion.js +5 -4
- package/src/math/Sphere.js +2 -0
- package/src/math/Triangle.js +17 -5
- package/src/math/Vector3.js +11 -12
- package/src/objects/BatchedMesh.js +1020 -0
- package/src/objects/Skeleton.js +1 -3
- package/src/objects/SkinnedMesh.js +6 -7
- package/src/renderers/WebGL3DRenderTarget.js +2 -2
- package/src/renderers/WebGLArrayRenderTarget.js +2 -2
- package/src/renderers/WebGLRenderer.js +165 -43
- package/src/renderers/shaders/ShaderChunk/aomap_fragment.glsl.js +8 -0
- package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +19 -0
- package/src/renderers/shaders/ShaderChunk/batching_vertex.glsl.js +5 -0
- package/src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js +3 -2
- package/src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl.js +0 -5
- package/src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl.js +31 -4
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +9 -4
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +8 -6
- package/src/renderers/shaders/ShaderChunk/project_vertex.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl.js +9 -17
- package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +84 -0
- package/src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk.js +4 -0
- 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/meshbasic.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +3 -0
- package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -2
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +3 -0
- package/src/renderers/webgl/WebGLAttributes.js +39 -5
- package/src/renderers/webgl/WebGLBufferRenderer.js +31 -0
- package/src/renderers/webgl/WebGLCubeMaps.js +1 -1
- package/src/renderers/webgl/WebGLExtensions.js +1 -0
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +31 -0
- package/src/renderers/webgl/WebGLLights.js +11 -2
- package/src/renderers/webgl/WebGLProgram.js +100 -51
- package/src/renderers/webgl/WebGLPrograms.js +8 -0
- package/src/renderers/webgl/WebGLShadowMap.js +35 -0
- package/src/renderers/webgl/WebGLState.js +25 -4
- package/src/renderers/webgl/WebGLTextures.js +7 -11
- package/src/renderers/webgl/WebGLUniforms.js +11 -1
- package/src/renderers/webgl/WebGLUniformsGroups.js +72 -93
- package/src/renderers/webxr/WebXRManager.js +16 -0
- package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +0 -76
- package/examples/jsm/nodes/accessors/LineMaterialNode.js +0 -29
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { addNodeClass } from '../core/Node.js';
|
|
2
|
+
import TempNode from '../core/TempNode.js';
|
|
3
|
+
import { addNodeElement, nodeProxy } from '../shadernode/ShaderNode.js';
|
|
4
|
+
|
|
5
|
+
class AssignNode extends TempNode {
|
|
6
|
+
|
|
7
|
+
constructor( targetNode, sourceNode ) {
|
|
8
|
+
|
|
9
|
+
super();
|
|
10
|
+
|
|
11
|
+
this.targetNode = targetNode;
|
|
12
|
+
this.sourceNode = sourceNode;
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
hasDependencies() {
|
|
17
|
+
|
|
18
|
+
return false;
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getNodeType( builder, output ) {
|
|
23
|
+
|
|
24
|
+
return output !== 'void' ? this.targetNode.getNodeType( builder ) : 'void';
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
generate( builder, output ) {
|
|
29
|
+
|
|
30
|
+
const targetNode = this.targetNode;
|
|
31
|
+
const sourceNode = this.sourceNode;
|
|
32
|
+
|
|
33
|
+
const targetType = targetNode.getNodeType( builder );
|
|
34
|
+
|
|
35
|
+
const target = targetNode.build( builder );
|
|
36
|
+
const source = sourceNode.build( builder, targetType );
|
|
37
|
+
|
|
38
|
+
const snippet = `${ target } = ${ source }`;
|
|
39
|
+
|
|
40
|
+
if ( output === 'void' ) {
|
|
41
|
+
|
|
42
|
+
builder.addLineFlowCode( snippet );
|
|
43
|
+
|
|
44
|
+
return;
|
|
45
|
+
|
|
46
|
+
} else {
|
|
47
|
+
|
|
48
|
+
const sourceType = sourceNode.getNodeType( builder );
|
|
49
|
+
|
|
50
|
+
if ( sourceType === 'void' ) {
|
|
51
|
+
|
|
52
|
+
builder.addLineFlowCode( snippet );
|
|
53
|
+
|
|
54
|
+
return target;
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return builder.format( snippet, targetType, output );
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export default AssignNode;
|
|
67
|
+
|
|
68
|
+
export const assign = nodeProxy( AssignNode );
|
|
69
|
+
|
|
70
|
+
addNodeClass( 'AssignNode', AssignNode );
|
|
71
|
+
|
|
72
|
+
addNodeElement( 'assign', assign );
|
|
@@ -12,6 +12,12 @@ class AttributeNode extends Node {
|
|
|
12
12
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
isGlobal() {
|
|
16
|
+
|
|
17
|
+
return true;
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
|
|
15
21
|
getHash( builder ) {
|
|
16
22
|
|
|
17
23
|
return this.getAttributeName( builder );
|
|
@@ -87,7 +93,7 @@ class AttributeNode extends Node {
|
|
|
87
93
|
|
|
88
94
|
console.warn( `AttributeNode: Attribute "${ attributeName }" not found.` );
|
|
89
95
|
|
|
90
|
-
return builder.
|
|
96
|
+
return builder.generateConst( nodeType );
|
|
91
97
|
|
|
92
98
|
}
|
|
93
99
|
|
|
@@ -24,8 +24,9 @@ class CacheNode extends Node {
|
|
|
24
24
|
build( builder, ...params ) {
|
|
25
25
|
|
|
26
26
|
const previousCache = builder.getCache();
|
|
27
|
+
const cache = this.cache || builder.globalCache;
|
|
27
28
|
|
|
28
|
-
builder.setCache(
|
|
29
|
+
builder.setCache( cache );
|
|
29
30
|
|
|
30
31
|
const data = this.node.build( builder, ...params );
|
|
31
32
|
|
|
@@ -40,7 +41,9 @@ class CacheNode extends Node {
|
|
|
40
41
|
export default CacheNode;
|
|
41
42
|
|
|
42
43
|
export const cache = nodeProxy( CacheNode );
|
|
44
|
+
export const globalCache = ( node ) => cache( node, null );
|
|
43
45
|
|
|
44
46
|
addNodeElement( 'cache', cache );
|
|
47
|
+
addNodeElement( 'globalCache', globalCache );
|
|
45
48
|
|
|
46
49
|
addNodeClass( 'CacheNode', CacheNode );
|
|
@@ -54,16 +54,9 @@ class Node extends EventDispatcher {
|
|
|
54
54
|
|
|
55
55
|
* getChildren() {
|
|
56
56
|
|
|
57
|
-
const
|
|
57
|
+
for ( const { childNode } of getNodeChildren( this ) ) {
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
yield { childNode, replaceNode( node ) {
|
|
62
|
-
|
|
63
|
-
if ( index === undefined ) self[ property ] = node;
|
|
64
|
-
else self[ property ][ index ] = node;
|
|
65
|
-
|
|
66
|
-
} };
|
|
59
|
+
yield childNode;
|
|
67
60
|
|
|
68
61
|
}
|
|
69
62
|
|
|
@@ -75,13 +68,13 @@ class Node extends EventDispatcher {
|
|
|
75
68
|
|
|
76
69
|
}
|
|
77
70
|
|
|
78
|
-
traverse( callback
|
|
71
|
+
traverse( callback ) {
|
|
79
72
|
|
|
80
|
-
callback( this
|
|
73
|
+
callback( this );
|
|
81
74
|
|
|
82
|
-
for ( const
|
|
75
|
+
for ( const childNode of this.getChildren() ) {
|
|
83
76
|
|
|
84
|
-
childNode.traverse( callback
|
|
77
|
+
childNode.traverse( callback );
|
|
85
78
|
|
|
86
79
|
}
|
|
87
80
|
|
|
@@ -138,7 +131,7 @@ class Node extends EventDispatcher {
|
|
|
138
131
|
|
|
139
132
|
const nodeProperties = builder.getNodeProperties( this );
|
|
140
133
|
|
|
141
|
-
for ( const
|
|
134
|
+
for ( const childNode of this.getChildren() ) {
|
|
142
135
|
|
|
143
136
|
nodeProperties[ '_node' + childNode.id ] = childNode;
|
|
144
137
|
|
|
@@ -465,7 +458,12 @@ export default Node;
|
|
|
465
458
|
export function addNodeClass( type, nodeClass ) {
|
|
466
459
|
|
|
467
460
|
if ( typeof nodeClass !== 'function' || ! type ) throw new Error( `Node class ${ type } is not a class` );
|
|
468
|
-
if ( NodeClasses.has( type ) )
|
|
461
|
+
if ( NodeClasses.has( type ) ) {
|
|
462
|
+
|
|
463
|
+
console.warn( `Redefinition of node class ${ type }` );
|
|
464
|
+
return;
|
|
465
|
+
|
|
466
|
+
}
|
|
469
467
|
|
|
470
468
|
NodeClasses.set( type, nodeClass );
|
|
471
469
|
nodeClass.type = type;
|
|
@@ -5,6 +5,8 @@ import NodeVar from './NodeVar.js';
|
|
|
5
5
|
import NodeCode from './NodeCode.js';
|
|
6
6
|
import NodeKeywords from './NodeKeywords.js';
|
|
7
7
|
import NodeCache from './NodeCache.js';
|
|
8
|
+
import ParameterNode from './ParameterNode.js';
|
|
9
|
+
import FunctionNode from '../code/FunctionNode.js';
|
|
8
10
|
import { createNodeMaterialFromType } from '../materials/NodeMaterial.js';
|
|
9
11
|
import { NodeUpdateType, defaultBuildStages, shaderStages } from './constants.js';
|
|
10
12
|
|
|
@@ -16,9 +18,12 @@ import {
|
|
|
16
18
|
import { REVISION, RenderTarget, NoColorSpace, LinearEncoding, sRGBEncoding, SRGBColorSpace, Color, Vector2, Vector3, Vector4, Float16BufferAttribute } from 'three';
|
|
17
19
|
|
|
18
20
|
import { stack } from './StackNode.js';
|
|
19
|
-
import {
|
|
21
|
+
import { getCurrentStack, setCurrentStack } from '../shadernode/ShaderNode.js';
|
|
20
22
|
|
|
21
23
|
import CubeRenderTarget from '../../renderers/common/CubeRenderTarget.js';
|
|
24
|
+
import ChainMap from '../../renderers/common/ChainMap.js';
|
|
25
|
+
|
|
26
|
+
const uniformsGroupCache = new ChainMap();
|
|
22
27
|
|
|
23
28
|
const typeFromLength = new Map( [
|
|
24
29
|
[ 2, 'vec2' ],
|
|
@@ -38,8 +43,6 @@ const typeFromArray = new Map( [
|
|
|
38
43
|
[ Float32Array, 'float' ]
|
|
39
44
|
] );
|
|
40
45
|
|
|
41
|
-
const isNonPaddingElementArray = new Set( [ Int32Array, Uint32Array, Float32Array ] );
|
|
42
|
-
|
|
43
46
|
const toFloat = ( value ) => {
|
|
44
47
|
|
|
45
48
|
value = Number( value );
|
|
@@ -77,23 +80,25 @@ class NodeBuilder {
|
|
|
77
80
|
this.flowCode = { vertex: '', fragment: '', compute: [] };
|
|
78
81
|
this.uniforms = { vertex: [], fragment: [], compute: [], index: 0 };
|
|
79
82
|
this.structs = { vertex: [], fragment: [], compute: [], index: 0 };
|
|
80
|
-
this.codes = { vertex: [], fragment: [], compute: [] };
|
|
81
83
|
this.bindings = { vertex: [], fragment: [], compute: [] };
|
|
82
84
|
this.bindingsOffset = { vertex: 0, fragment: 0, compute: 0 };
|
|
83
85
|
this.bindingsArray = null;
|
|
84
86
|
this.attributes = [];
|
|
85
87
|
this.bufferAttributes = [];
|
|
86
88
|
this.varyings = [];
|
|
87
|
-
this.
|
|
89
|
+
this.codes = {};
|
|
90
|
+
this.vars = {};
|
|
88
91
|
this.flow = { code: '' };
|
|
89
92
|
this.chaining = [];
|
|
90
93
|
this.stack = stack();
|
|
94
|
+
this.stacks = [];
|
|
91
95
|
this.tab = '\t';
|
|
92
96
|
|
|
97
|
+
this.currentFunctionNode = null;
|
|
98
|
+
|
|
93
99
|
this.context = {
|
|
94
100
|
keywords: new NodeKeywords(),
|
|
95
|
-
material: this.material
|
|
96
|
-
getMIPLevelAlgorithmNode: ( textureNode, levelNode ) => levelNode.mul( maxMipLevel( textureNode ) )
|
|
101
|
+
material: this.material
|
|
97
102
|
};
|
|
98
103
|
|
|
99
104
|
this.cache = new NodeCache();
|
|
@@ -124,6 +129,41 @@ class NodeBuilder {
|
|
|
124
129
|
|
|
125
130
|
}
|
|
126
131
|
|
|
132
|
+
_getSharedBindings( bindings ) {
|
|
133
|
+
|
|
134
|
+
const shared = [];
|
|
135
|
+
|
|
136
|
+
for ( const binding of bindings ) {
|
|
137
|
+
|
|
138
|
+
if ( binding.shared === true ) {
|
|
139
|
+
|
|
140
|
+
// nodes is the chainmap key
|
|
141
|
+
const nodes = binding.getNodes();
|
|
142
|
+
|
|
143
|
+
let sharedBinding = uniformsGroupCache.get( nodes );
|
|
144
|
+
|
|
145
|
+
if ( sharedBinding === undefined ) {
|
|
146
|
+
|
|
147
|
+
uniformsGroupCache.set( nodes, binding );
|
|
148
|
+
|
|
149
|
+
sharedBinding = binding;
|
|
150
|
+
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
shared.push( sharedBinding );
|
|
154
|
+
|
|
155
|
+
} else {
|
|
156
|
+
|
|
157
|
+
shared.push( binding );
|
|
158
|
+
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return shared;
|
|
164
|
+
|
|
165
|
+
}
|
|
166
|
+
|
|
127
167
|
getBindings() {
|
|
128
168
|
|
|
129
169
|
let bindingsArray = this.bindingsArray;
|
|
@@ -132,7 +172,7 @@ class NodeBuilder {
|
|
|
132
172
|
|
|
133
173
|
const bindings = this.bindings;
|
|
134
174
|
|
|
135
|
-
this.bindingsArray = bindingsArray = ( this.material !== null ) ? [ ...bindings.vertex, ...bindings.fragment ] : bindings.compute;
|
|
175
|
+
this.bindingsArray = bindingsArray = this._getSharedBindings( ( this.material !== null ) ? [ ...bindings.vertex, ...bindings.fragment ] : bindings.compute );
|
|
136
176
|
|
|
137
177
|
}
|
|
138
178
|
|
|
@@ -293,20 +333,19 @@ class NodeBuilder {
|
|
|
293
333
|
|
|
294
334
|
}
|
|
295
335
|
|
|
296
|
-
|
|
336
|
+
generateTexture( /* texture, textureProperty, uvSnippet */ ) {
|
|
297
337
|
|
|
298
338
|
console.warn( 'Abstract function.' );
|
|
299
339
|
|
|
300
340
|
}
|
|
301
341
|
|
|
302
|
-
|
|
342
|
+
generateTextureLod( /* texture, textureProperty, uvSnippet, levelSnippet */ ) {
|
|
303
343
|
|
|
304
344
|
console.warn( 'Abstract function.' );
|
|
305
345
|
|
|
306
346
|
}
|
|
307
347
|
|
|
308
|
-
|
|
309
|
-
getConst( type, value = null ) {
|
|
348
|
+
generateConst( type, value = null ) {
|
|
310
349
|
|
|
311
350
|
if ( value === null ) {
|
|
312
351
|
|
|
@@ -329,23 +368,23 @@ class NodeBuilder {
|
|
|
329
368
|
|
|
330
369
|
const componentType = this.getComponentType( type );
|
|
331
370
|
|
|
332
|
-
const
|
|
371
|
+
const generateConst = value => this.generateConst( componentType, value );
|
|
333
372
|
|
|
334
373
|
if ( typeLength === 2 ) {
|
|
335
374
|
|
|
336
|
-
return `${ this.getType( type ) }( ${
|
|
375
|
+
return `${ this.getType( type ) }( ${ generateConst( value.x ) }, ${ generateConst( value.y ) } )`;
|
|
337
376
|
|
|
338
377
|
} else if ( typeLength === 3 ) {
|
|
339
378
|
|
|
340
|
-
return `${ this.getType( type ) }( ${
|
|
379
|
+
return `${ this.getType( type ) }( ${ generateConst( value.x ) }, ${ generateConst( value.y ) }, ${ generateConst( value.z ) } )`;
|
|
341
380
|
|
|
342
381
|
} else if ( typeLength === 4 ) {
|
|
343
382
|
|
|
344
|
-
return `${ this.getType( type ) }( ${
|
|
383
|
+
return `${ this.getType( type ) }( ${ generateConst( value.x ) }, ${ generateConst( value.y ) }, ${ generateConst( value.z ) }, ${ generateConst( value.w ) } )`;
|
|
345
384
|
|
|
346
385
|
} else if ( typeLength > 4 && value && ( value.isMatrix3 || value.isMatrix4 ) ) {
|
|
347
386
|
|
|
348
|
-
return `${ this.getType( type ) }( ${ value.elements.map(
|
|
387
|
+
return `${ this.getType( type ) }( ${ value.elements.map( generateConst ).join( ', ' ) } )`;
|
|
349
388
|
|
|
350
389
|
} else if ( typeLength > 4 ) {
|
|
351
390
|
|
|
@@ -514,7 +553,7 @@ class NodeBuilder {
|
|
|
514
553
|
if ( attribute.isInterleavedBufferAttribute ) dataAttribute = attribute.data;
|
|
515
554
|
|
|
516
555
|
const array = dataAttribute.array;
|
|
517
|
-
const itemSize =
|
|
556
|
+
const itemSize = attribute.itemSize;
|
|
518
557
|
const normalized = attribute.normalized;
|
|
519
558
|
|
|
520
559
|
let arrayType;
|
|
@@ -569,23 +608,27 @@ class NodeBuilder {
|
|
|
569
608
|
|
|
570
609
|
this.stack = stack( this.stack );
|
|
571
610
|
|
|
611
|
+
this.stacks.push( getCurrentStack() || this.stack );
|
|
612
|
+
setCurrentStack( this.stack );
|
|
613
|
+
|
|
572
614
|
return this.stack;
|
|
573
615
|
|
|
574
616
|
}
|
|
575
617
|
|
|
576
618
|
removeStack() {
|
|
577
619
|
|
|
578
|
-
const
|
|
620
|
+
const lastStack = this.stack;
|
|
621
|
+
this.stack = lastStack.parent;
|
|
579
622
|
|
|
580
|
-
this.
|
|
623
|
+
setCurrentStack( this.stacks.pop() );
|
|
581
624
|
|
|
582
|
-
return
|
|
625
|
+
return lastStack;
|
|
583
626
|
|
|
584
627
|
}
|
|
585
628
|
|
|
586
|
-
getDataFromNode( node, shaderStage = this.shaderStage ) {
|
|
629
|
+
getDataFromNode( node, shaderStage = this.shaderStage, cache = null ) {
|
|
587
630
|
|
|
588
|
-
|
|
631
|
+
cache = cache === null ? ( node.isGlobal( this ) ? this.globalCache : this.cache ) : cache;
|
|
589
632
|
|
|
590
633
|
let nodeData = cache.getNodeData( node );
|
|
591
634
|
|
|
@@ -633,17 +676,15 @@ class NodeBuilder {
|
|
|
633
676
|
|
|
634
677
|
}
|
|
635
678
|
|
|
636
|
-
getStructTypeFromNode( node, shaderStage = this.shaderStage
|
|
679
|
+
getStructTypeFromNode( node, shaderStage = this.shaderStage ) {
|
|
637
680
|
|
|
638
681
|
const nodeData = this.getDataFromNode( node, shaderStage );
|
|
639
682
|
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
if ( nodeStruct === undefined ) {
|
|
683
|
+
if ( nodeData.structType === undefined ) {
|
|
643
684
|
|
|
644
685
|
const index = this.structs.index ++;
|
|
645
686
|
|
|
646
|
-
node.name = `StructType${index}`;
|
|
687
|
+
node.name = `StructType${ index }`;
|
|
647
688
|
this.structs[ shaderStage ].push( node );
|
|
648
689
|
|
|
649
690
|
nodeData.structType = node;
|
|
@@ -656,7 +697,7 @@ class NodeBuilder {
|
|
|
656
697
|
|
|
657
698
|
getUniformFromNode( node, type, shaderStage = this.shaderStage, name = null ) {
|
|
658
699
|
|
|
659
|
-
const nodeData = this.getDataFromNode( node, shaderStage );
|
|
700
|
+
const nodeData = this.getDataFromNode( node, shaderStage, this.globalCache );
|
|
660
701
|
|
|
661
702
|
let nodeUniform = nodeData.uniform;
|
|
662
703
|
|
|
@@ -676,7 +717,7 @@ class NodeBuilder {
|
|
|
676
717
|
|
|
677
718
|
}
|
|
678
719
|
|
|
679
|
-
getVarFromNode( node, type, shaderStage = this.shaderStage ) {
|
|
720
|
+
getVarFromNode( node, name = null, type = node.getNodeType( this ), shaderStage = this.shaderStage ) {
|
|
680
721
|
|
|
681
722
|
const nodeData = this.getDataFromNode( node, shaderStage );
|
|
682
723
|
|
|
@@ -684,10 +725,11 @@ class NodeBuilder {
|
|
|
684
725
|
|
|
685
726
|
if ( nodeVar === undefined ) {
|
|
686
727
|
|
|
687
|
-
const vars = this.vars[ shaderStage ];
|
|
688
|
-
const index = vars.length;
|
|
728
|
+
const vars = this.vars[ shaderStage ] || ( this.vars[ shaderStage ] = [] );
|
|
689
729
|
|
|
690
|
-
|
|
730
|
+
if ( name === null ) name = 'nodeVar' + vars.length;
|
|
731
|
+
|
|
732
|
+
nodeVar = new NodeVar( name, type );
|
|
691
733
|
|
|
692
734
|
vars.push( nodeVar );
|
|
693
735
|
|
|
@@ -699,7 +741,7 @@ class NodeBuilder {
|
|
|
699
741
|
|
|
700
742
|
}
|
|
701
743
|
|
|
702
|
-
getVaryingFromNode( node, type ) {
|
|
744
|
+
getVaryingFromNode( node, name = null, type = node.getNodeType( this ) ) {
|
|
703
745
|
|
|
704
746
|
const nodeData = this.getDataFromNode( node, 'any' );
|
|
705
747
|
|
|
@@ -710,7 +752,9 @@ class NodeBuilder {
|
|
|
710
752
|
const varyings = this.varyings;
|
|
711
753
|
const index = varyings.length;
|
|
712
754
|
|
|
713
|
-
|
|
755
|
+
if ( name === null ) name = 'nodeVarying' + index;
|
|
756
|
+
|
|
757
|
+
nodeVarying = new NodeVarying( name, type );
|
|
714
758
|
|
|
715
759
|
varyings.push( nodeVarying );
|
|
716
760
|
|
|
@@ -730,7 +774,7 @@ class NodeBuilder {
|
|
|
730
774
|
|
|
731
775
|
if ( nodeCode === undefined ) {
|
|
732
776
|
|
|
733
|
-
const codes = this.codes[ shaderStage ];
|
|
777
|
+
const codes = this.codes[ shaderStage ] || ( this.codes[ shaderStage ] = [] );
|
|
734
778
|
const index = codes.length;
|
|
735
779
|
|
|
736
780
|
nodeCode = new NodeCode( 'nodeCode' + index, type );
|
|
@@ -805,12 +849,106 @@ class NodeBuilder {
|
|
|
805
849
|
|
|
806
850
|
}
|
|
807
851
|
|
|
852
|
+
buildFunctionNode( shaderNode ) {
|
|
853
|
+
|
|
854
|
+
const fn = new FunctionNode();
|
|
855
|
+
|
|
856
|
+
const previous = this.currentFunctionNode;
|
|
857
|
+
|
|
858
|
+
this.currentFunctionNode = fn;
|
|
859
|
+
|
|
860
|
+
fn.code = this.buildFunctionCode( shaderNode );
|
|
861
|
+
|
|
862
|
+
this.currentFunctionNode = previous;
|
|
863
|
+
|
|
864
|
+
return fn;
|
|
865
|
+
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
flowShaderNode( shaderNode ) {
|
|
869
|
+
|
|
870
|
+
const layout = shaderNode.layout;
|
|
871
|
+
|
|
872
|
+
let inputs;
|
|
873
|
+
|
|
874
|
+
if ( shaderNode.isArrayInput ) {
|
|
875
|
+
|
|
876
|
+
inputs = [];
|
|
877
|
+
|
|
878
|
+
for ( const input of layout.inputs ) {
|
|
879
|
+
|
|
880
|
+
inputs.push( new ParameterNode( input.type, input.name ) );
|
|
881
|
+
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
} else {
|
|
885
|
+
|
|
886
|
+
inputs = {};
|
|
887
|
+
|
|
888
|
+
for ( const input of layout.inputs ) {
|
|
889
|
+
|
|
890
|
+
inputs[ input.name ] = new ParameterNode( input.type, input.name );
|
|
891
|
+
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
//
|
|
897
|
+
|
|
898
|
+
shaderNode.layout = null;
|
|
899
|
+
|
|
900
|
+
const callNode = shaderNode.call( inputs );
|
|
901
|
+
const flowData = this.flowStagesNode( callNode, layout.type );
|
|
902
|
+
|
|
903
|
+
shaderNode.layout = layout;
|
|
904
|
+
|
|
905
|
+
return flowData;
|
|
906
|
+
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
flowStagesNode( node, output = null ) {
|
|
910
|
+
|
|
911
|
+
const previousFlow = this.flow;
|
|
912
|
+
const previousVars = this.vars;
|
|
913
|
+
const previousBuildStage = this.buildStage;
|
|
914
|
+
|
|
915
|
+
const flow = {
|
|
916
|
+
code: ''
|
|
917
|
+
};
|
|
918
|
+
|
|
919
|
+
this.flow = flow;
|
|
920
|
+
this.vars = {};
|
|
921
|
+
|
|
922
|
+
for ( const buildStage of defaultBuildStages ) {
|
|
923
|
+
|
|
924
|
+
this.setBuildStage( buildStage );
|
|
925
|
+
|
|
926
|
+
flow.result = node.build( this, output );
|
|
927
|
+
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
flow.vars = this.getVars( this.shaderStage );
|
|
931
|
+
|
|
932
|
+
this.flow = previousFlow;
|
|
933
|
+
this.vars = previousVars;
|
|
934
|
+
this.setBuildStage( previousBuildStage );
|
|
935
|
+
|
|
936
|
+
return flow;
|
|
937
|
+
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
getFunctionOperator() {
|
|
941
|
+
|
|
942
|
+
return null;
|
|
943
|
+
|
|
944
|
+
}
|
|
945
|
+
|
|
808
946
|
flowChildNode( node, output = null ) {
|
|
809
947
|
|
|
810
948
|
const previousFlow = this.flow;
|
|
811
949
|
|
|
812
950
|
const flow = {
|
|
813
|
-
code: ''
|
|
951
|
+
code: ''
|
|
814
952
|
};
|
|
815
953
|
|
|
816
954
|
this.flow = flow;
|
|
@@ -875,9 +1013,13 @@ class NodeBuilder {
|
|
|
875
1013
|
|
|
876
1014
|
const vars = this.vars[ shaderStage ];
|
|
877
1015
|
|
|
878
|
-
|
|
1016
|
+
if ( vars !== undefined ) {
|
|
1017
|
+
|
|
1018
|
+
for ( const variable of vars ) {
|
|
879
1019
|
|
|
880
|
-
|
|
1020
|
+
snippet += `${ this.getVar( variable.type, variable.name ) }; `;
|
|
1021
|
+
|
|
1022
|
+
}
|
|
881
1023
|
|
|
882
1024
|
}
|
|
883
1025
|
|
|
@@ -897,9 +1039,13 @@ class NodeBuilder {
|
|
|
897
1039
|
|
|
898
1040
|
let code = '';
|
|
899
1041
|
|
|
900
|
-
|
|
1042
|
+
if ( codes !== undefined ) {
|
|
1043
|
+
|
|
1044
|
+
for ( const nodeCode of codes ) {
|
|
901
1045
|
|
|
902
|
-
|
|
1046
|
+
code += nodeCode.code + '\n';
|
|
1047
|
+
|
|
1048
|
+
}
|
|
903
1049
|
|
|
904
1050
|
}
|
|
905
1051
|
|
|
@@ -1015,6 +1161,18 @@ class NodeBuilder {
|
|
|
1015
1161
|
|
|
1016
1162
|
}
|
|
1017
1163
|
|
|
1164
|
+
getPrimitiveType( type ) {
|
|
1165
|
+
|
|
1166
|
+
let primitiveType;
|
|
1167
|
+
|
|
1168
|
+
if ( type[ 0 ] === 'i' ) primitiveType = 'int';
|
|
1169
|
+
else if ( type[ 0 ] === 'u' ) primitiveType = 'uint';
|
|
1170
|
+
else primitiveType = 'float';
|
|
1171
|
+
|
|
1172
|
+
return primitiveType;
|
|
1173
|
+
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1018
1176
|
format( snippet, fromType, toType ) {
|
|
1019
1177
|
|
|
1020
1178
|
fromType = this.getVectorType( fromType );
|
|
@@ -1057,7 +1215,7 @@ class NodeBuilder {
|
|
|
1057
1215
|
|
|
1058
1216
|
}
|
|
1059
1217
|
|
|
1060
|
-
if ( toTypeLength === 4 ) { // toType is vec4-like
|
|
1218
|
+
if ( toTypeLength === 4 && fromTypeLength > 1 ) { // toType is vec4-like
|
|
1061
1219
|
|
|
1062
1220
|
return `${ this.getType( toType ) }( ${ this.format( snippet, fromType, 'vec3' ) }, 1.0 )`;
|
|
1063
1221
|
|
|
@@ -1069,6 +1227,15 @@ class NodeBuilder {
|
|
|
1069
1227
|
|
|
1070
1228
|
}
|
|
1071
1229
|
|
|
1230
|
+
if ( fromTypeLength === 1 && toTypeLength > 1 && fromType[ 0 ] !== toType[ 0 ] ) { // fromType is float-like
|
|
1231
|
+
|
|
1232
|
+
// convert a number value to vector type, e.g:
|
|
1233
|
+
// vec3( 1u ) -> vec3( float( 1u ) )
|
|
1234
|
+
|
|
1235
|
+
snippet = `${ this.getType( this.getPrimitiveType( toType ) ) }( ${ snippet } )`;
|
|
1236
|
+
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1072
1239
|
return `${ this.getType( toType ) }( ${ snippet } )`; // fromType is float-like
|
|
1073
1240
|
|
|
1074
1241
|
}
|