super-three 0.157.0 → 0.158.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 +1486 -842
- package/build/three.js +1486 -842
- package/build/three.min.js +1 -1
- package/build/three.module.js +1481 -843
- package/build/three.module.min.js +1 -1
- package/examples/jsm/Addons.js +290 -0
- package/examples/jsm/controls/FlyControls.js +26 -0
- package/examples/jsm/controls/OrbitControls.js +12 -1
- package/examples/jsm/controls/TransformControls.js +27 -11
- package/examples/jsm/csm/CSMShader.js +1 -1
- package/examples/jsm/exporters/GLTFExporter.js +72 -2
- package/examples/jsm/geometries/InstancedPointsGeometry.js +174 -0
- package/examples/jsm/geometries/SDFGeometryGenerator.js +144 -0
- 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/loaders/GLTFLoader.js +12 -3
- package/examples/jsm/loaders/LUTImageLoader.js +162 -0
- 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 +70 -3
- package/examples/jsm/modifiers/SimplifyModifier.js +103 -11
- package/examples/jsm/modifiers/TessellateModifier.js +3 -3
- package/examples/jsm/nodes/Nodes.js +6 -6
- package/examples/jsm/nodes/accessors/CubeTextureNode.js +3 -3
- 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/ModelNode.js +1 -2
- package/examples/jsm/nodes/accessors/MorphNode.js +5 -5
- package/examples/jsm/nodes/accessors/NormalNode.js +1 -1
- package/examples/jsm/nodes/accessors/PositionNode.js +1 -1
- package/examples/jsm/nodes/accessors/SkinningNode.js +13 -3
- package/examples/jsm/nodes/accessors/TextureNode.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/LightingModel.js +3 -1
- package/examples/jsm/nodes/core/Node.js +7 -12
- package/examples/jsm/nodes/core/NodeBuilder.js +126 -16
- package/examples/jsm/nodes/core/NodeUtils.js +4 -2
- package/examples/jsm/nodes/core/OutputStructNode.js +1 -1
- package/examples/jsm/nodes/core/ParameterNode.js +33 -0
- package/examples/jsm/nodes/core/PropertyNode.js +4 -10
- package/examples/jsm/nodes/core/StackNode.js +7 -17
- package/examples/jsm/nodes/core/TempNode.js +1 -1
- package/examples/jsm/nodes/core/VarNode.js +6 -35
- package/examples/jsm/nodes/core/VaryingNode.js +2 -0
- package/examples/jsm/nodes/display/BumpMapNode.js +35 -13
- package/examples/jsm/nodes/display/NormalMapNode.js +3 -1
- package/examples/jsm/nodes/display/ViewportNode.js +14 -4
- 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 +19 -5
- package/examples/jsm/nodes/lighting/DirectionalLightNode.js +1 -1
- package/examples/jsm/nodes/lighting/EnvironmentNode.js +0 -6
- package/examples/jsm/nodes/lighting/LightingContextNode.js +21 -57
- package/examples/jsm/nodes/lighting/LightsNode.js +62 -4
- 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 +70 -71
- package/examples/jsm/nodes/materials/LineDashedNodeMaterial.js +5 -5
- package/examples/jsm/nodes/materials/Materials.js +1 -0
- package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +2 -2
- 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 +17 -20
- package/examples/jsm/nodes/materialx/lib/mx_noise.js +5 -5
- package/examples/jsm/nodes/math/OperatorNode.js +5 -21
- package/examples/jsm/nodes/shadernode/ShaderNode.js +128 -9
- package/examples/jsm/nodes/utils/ArrayElementNode.js +2 -0
- package/examples/jsm/nodes/utils/DiscardNode.js +3 -2
- package/examples/jsm/nodes/utils/JoinNode.js +11 -1
- package/examples/jsm/nodes/utils/LoopNode.js +36 -24
- package/examples/jsm/nodes/utils/SplitNode.js +2 -0
- package/examples/jsm/objects/BatchedMesh.js +586 -0
- package/examples/jsm/objects/InstancedPoints.js +21 -0
- package/examples/jsm/objects/Lensflare.js +20 -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/LUTPass.js +2 -1
- package/examples/jsm/postprocessing/OutputPass.js +1 -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/Bindings.js +1 -1
- package/examples/jsm/renderers/common/RenderObject.js +8 -1
- package/examples/jsm/renderers/common/RenderObjects.js +1 -1
- package/examples/jsm/renderers/common/Textures.js +4 -36
- package/examples/jsm/renderers/common/nodes/Nodes.js +53 -18
- package/examples/jsm/renderers/webgl/WebGLBackend.js +291 -50
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +88 -12
- package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +40 -5
- package/examples/jsm/renderers/webgl/utils/WebGLState.js +14 -2
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +2 -0
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +36 -4
- 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 +2 -0
- 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/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 +4 -5
- package/examples/jsm/shaders/SAOShader.js +5 -0
- package/examples/jsm/shaders/SMAAShader.js +6 -0
- package/examples/jsm/shaders/SSAOShader.js +6 -0
- 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 +231 -0
- package/examples/jsm/transpiler/GLSLDecoder.js +899 -0
- package/examples/jsm/transpiler/ShaderToyDecoder.js +49 -0
- package/examples/jsm/transpiler/TSLEncoder.js +611 -0
- package/examples/jsm/transpiler/Transpiler.js +18 -0
- package/examples/jsm/webxr/VRButton.js +1 -1
- package/examples/jsm/webxr/XRButton.js +7 -5
- package/examples/jsm/webxr/XREstimatedLight.js +1 -1
- package/package.json +4 -1
- package/src/constants.js +7 -1
- package/src/extras/PMREMGenerator.js +7 -1
- package/src/loaders/MaterialLoader.js +10 -2
- package/src/materials/Material.js +27 -13
- package/src/math/Box3.js +35 -18
- package/src/math/Vector3.js +11 -12
- package/src/objects/SkinnedMesh.js +6 -7
- package/src/renderers/WebGLMultiviewRenderTarget.js +35 -0
- package/src/renderers/WebGLRenderer.js +199 -45
- package/src/renderers/shaders/ShaderChunk/aomap_fragment.glsl.js +8 -0
- package/src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js +3 -2
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +8 -6
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +2 -2
- package/src/renderers/webgl/WebGLBackground.js +1 -1
- package/src/renderers/webgl/WebGLMultiview.js +100 -0
- package/src/renderers/webgl/WebGLProgram.js +130 -50
- package/src/renderers/webgl/WebGLPrograms.js +8 -0
- package/src/renderers/webgl/WebGLState.js +25 -4
- package/src/renderers/webgl/WebGLTextures.js +197 -20
- package/src/renderers/webxr/WebXRManager.js +36 -12
- package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +0 -76
- package/examples/jsm/nodes/accessors/LineMaterialNode.js +0 -29
|
@@ -2,8 +2,7 @@ import { Material, ShaderMaterial, NoColorSpace, LinearSRGBColorSpace } from 'th
|
|
|
2
2
|
import { getNodeChildren, getCacheKey } from '../core/NodeUtils.js';
|
|
3
3
|
import { attribute } from '../core/AttributeNode.js';
|
|
4
4
|
import { output, diffuseColor } from '../core/PropertyNode.js';
|
|
5
|
-
import { materialNormal } from '../accessors/
|
|
6
|
-
import { materialAlphaTest, materialColor, materialOpacity, materialEmissive } from '../accessors/MaterialNode.js';
|
|
5
|
+
import { materialAlphaTest, materialColor, materialOpacity, materialEmissive, materialNormal } from '../accessors/MaterialNode.js';
|
|
7
6
|
import { modelViewProjection } from '../accessors/ModelViewProjectionNode.js';
|
|
8
7
|
import { transformedNormalView } from '../accessors/NormalNode.js';
|
|
9
8
|
import { instance } from '../accessors/InstanceNode.js';
|
|
@@ -13,7 +12,7 @@ import { morph } from '../accessors/MorphNode.js';
|
|
|
13
12
|
import { texture } from '../accessors/TextureNode.js';
|
|
14
13
|
import { cubeTexture } from '../accessors/CubeTextureNode.js';
|
|
15
14
|
import { lightsWithoutWrap } from '../lighting/LightsNode.js';
|
|
16
|
-
import { mix
|
|
15
|
+
import { mix } from '../math/MathNode.js';
|
|
17
16
|
import { float, vec3, vec4 } from '../shadernode/ShaderNode.js';
|
|
18
17
|
import AONode from '../lighting/AONode.js';
|
|
19
18
|
import { lightingContext } from '../lighting/LightingContextNode.js';
|
|
@@ -98,7 +97,7 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
98
97
|
|
|
99
98
|
// OUTPUT NODE
|
|
100
99
|
|
|
101
|
-
|
|
100
|
+
output.assign( outputNode );
|
|
102
101
|
|
|
103
102
|
//
|
|
104
103
|
|
|
@@ -125,25 +124,25 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
125
124
|
|
|
126
125
|
if ( geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color ) {
|
|
127
126
|
|
|
128
|
-
|
|
127
|
+
morph( object ).append();
|
|
129
128
|
|
|
130
129
|
}
|
|
131
130
|
|
|
132
131
|
if ( object.isSkinnedMesh === true ) {
|
|
133
132
|
|
|
134
|
-
|
|
133
|
+
skinning( object ).append();
|
|
135
134
|
|
|
136
135
|
}
|
|
137
136
|
|
|
138
137
|
if ( ( object.instanceMatrix && object.instanceMatrix.isInstancedBufferAttribute === true ) && builder.isAvailable( 'instance' ) === true ) {
|
|
139
138
|
|
|
140
|
-
|
|
139
|
+
instance( object ).append();
|
|
141
140
|
|
|
142
141
|
}
|
|
143
142
|
|
|
144
143
|
if ( this.positionNode !== null ) {
|
|
145
144
|
|
|
146
|
-
|
|
145
|
+
positionLocal.assign( this.positionNode );
|
|
147
146
|
|
|
148
147
|
}
|
|
149
148
|
|
|
@@ -153,7 +152,7 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
153
152
|
|
|
154
153
|
}
|
|
155
154
|
|
|
156
|
-
setupDiffuseColor( {
|
|
155
|
+
setupDiffuseColor( { geometry } ) {
|
|
157
156
|
|
|
158
157
|
let colorNode = this.colorNode ? vec4( this.colorNode ) : materialColor;
|
|
159
158
|
|
|
@@ -167,12 +166,12 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
167
166
|
|
|
168
167
|
// COLOR
|
|
169
168
|
|
|
170
|
-
|
|
169
|
+
diffuseColor.assign( colorNode );
|
|
171
170
|
|
|
172
171
|
// OPACITY
|
|
173
172
|
|
|
174
173
|
const opacityNode = this.opacityNode ? float( this.opacityNode ) : materialOpacity;
|
|
175
|
-
|
|
174
|
+
diffuseColor.a.assign( diffuseColor.a.mul( opacityNode ) );
|
|
176
175
|
|
|
177
176
|
// ALPHA TEST
|
|
178
177
|
|
|
@@ -180,7 +179,7 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
180
179
|
|
|
181
180
|
const alphaTestNode = this.alphaTestNode !== null ? float( this.alphaTestNode ) : materialAlphaTest;
|
|
182
181
|
|
|
183
|
-
|
|
182
|
+
diffuseColor.a.lessThanEqual( alphaTestNode ).discard();
|
|
184
183
|
|
|
185
184
|
}
|
|
186
185
|
|
|
@@ -192,23 +191,21 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
192
191
|
|
|
193
192
|
}
|
|
194
193
|
|
|
195
|
-
setupNormal(
|
|
194
|
+
setupNormal() {
|
|
196
195
|
|
|
197
196
|
// NORMAL VIEW
|
|
198
197
|
|
|
199
198
|
if ( this.flatShading === true ) {
|
|
200
199
|
|
|
201
|
-
const
|
|
202
|
-
const fdy = dFdy( positionView );
|
|
203
|
-
const normalNode = fdx.cross( fdy ).normalize();
|
|
200
|
+
const normalNode = positionView.dFdx().cross( positionView.dFdy() ).normalize();
|
|
204
201
|
|
|
205
|
-
|
|
202
|
+
transformedNormalView.assign( normalNode );
|
|
206
203
|
|
|
207
204
|
} else {
|
|
208
205
|
|
|
209
206
|
const normalNode = this.normalNode ? vec3( this.normalNode ) : materialNormal;
|
|
210
207
|
|
|
211
|
-
|
|
208
|
+
transformedNormalView.assign( normalNode );
|
|
212
209
|
|
|
213
210
|
}
|
|
214
211
|
|
|
@@ -289,9 +286,9 @@ class NodeMaterial extends ShaderMaterial {
|
|
|
289
286
|
|
|
290
287
|
if ( lightsNode && lightsNode.hasLight !== false ) {
|
|
291
288
|
|
|
292
|
-
const
|
|
289
|
+
const lightingModel = this.setupLightingModel( builder );
|
|
293
290
|
|
|
294
|
-
outgoingLightNode = lightingContext( lightsNode,
|
|
291
|
+
outgoingLightNode = lightingContext( lightsNode, lightingModel, backdropNode, backdropAlphaNode );
|
|
295
292
|
|
|
296
293
|
} else if ( backdropNode !== null ) {
|
|
297
294
|
|
|
@@ -609,10 +609,10 @@ export const mx_perlin_noise_vec3 = glslFn( 'vec3 mx_perlin_noise_vec3( any p )'
|
|
|
609
609
|
export const mx_cell_noise_float = glslFn( 'float mx_cell_noise_float( vec3 p )', includes );
|
|
610
610
|
|
|
611
611
|
export const mx_worley_noise_float = glslFn( 'float mx_worley_noise_float( any p, float jitter, int metric )', includes );
|
|
612
|
-
export const mx_worley_noise_vec2 = glslFn( '
|
|
613
|
-
export const mx_worley_noise_vec3 = glslFn( '
|
|
612
|
+
export const mx_worley_noise_vec2 = glslFn( 'vec2 mx_worley_noise_vec2( any p, float jitter, int metric )', includes );
|
|
613
|
+
export const mx_worley_noise_vec3 = glslFn( 'vec3 mx_worley_noise_vec3( any p, float jitter, int metric )', includes );
|
|
614
614
|
|
|
615
615
|
export const mx_fractal_noise_float = glslFn( 'float mx_fractal_noise_float( vec3 p, int octaves, float lacunarity, float diminish )', includes );
|
|
616
|
-
export const mx_fractal_noise_vec2 = glslFn( '
|
|
617
|
-
export const mx_fractal_noise_vec3 = glslFn( '
|
|
618
|
-
export const mx_fractal_noise_vec4 = glslFn( '
|
|
616
|
+
export const mx_fractal_noise_vec2 = glslFn( 'vec2 mx_fractal_noise_vec2( vec3 p, int octaves, float lacunarity, float diminish )', includes );
|
|
617
|
+
export const mx_fractal_noise_vec3 = glslFn( 'vec3 mx_fractal_noise_vec3( vec3 p, int octaves, float lacunarity, float diminish )', includes );
|
|
618
|
+
export const mx_fractal_noise_vec4 = glslFn( 'vec4 mx_fractal_noise_vec4( vec3 p, int octaves, float lacunarity, float diminish )', includes );
|
|
@@ -29,12 +29,6 @@ class OperatorNode extends TempNode {
|
|
|
29
29
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
hasDependencies( builder ) {
|
|
33
|
-
|
|
34
|
-
return this.op !== '=' ? super.hasDependencies( builder ) : false;
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
32
|
getNodeType( builder, output ) {
|
|
39
33
|
|
|
40
34
|
const op = this.op;
|
|
@@ -49,7 +43,7 @@ class OperatorNode extends TempNode {
|
|
|
49
43
|
|
|
50
44
|
return 'void';
|
|
51
45
|
|
|
52
|
-
} else if ( op === '
|
|
46
|
+
} else if ( op === '%' ) {
|
|
53
47
|
|
|
54
48
|
return typeA;
|
|
55
49
|
|
|
@@ -116,11 +110,7 @@ class OperatorNode extends TempNode {
|
|
|
116
110
|
typeA = aNode.getNodeType( builder );
|
|
117
111
|
typeB = bNode.getNodeType( builder );
|
|
118
112
|
|
|
119
|
-
if ( op === '
|
|
120
|
-
|
|
121
|
-
typeB = typeA;
|
|
122
|
-
|
|
123
|
-
} else if ( op === '<' || op === '>' || op === '<=' || op === '>=' || op === '==' ) {
|
|
113
|
+
if ( op === '<' || op === '>' || op === '<=' || op === '>=' || op === '==' ) {
|
|
124
114
|
|
|
125
115
|
if ( builder.isVector( typeA ) ) {
|
|
126
116
|
|
|
@@ -170,13 +160,7 @@ class OperatorNode extends TempNode {
|
|
|
170
160
|
|
|
171
161
|
if ( output !== 'void' ) {
|
|
172
162
|
|
|
173
|
-
if ( op === '
|
|
174
|
-
|
|
175
|
-
builder.addLineFlowCode( `${a} ${this.op} ${b}` );
|
|
176
|
-
|
|
177
|
-
return a;
|
|
178
|
-
|
|
179
|
-
} else if ( op === '<' && outputLength > 1 ) {
|
|
163
|
+
if ( op === '<' && outputLength > 1 ) {
|
|
180
164
|
|
|
181
165
|
return builder.format( `${ builder.getMethod( 'lessThan' ) }( ${a}, ${b} )`, type, output );
|
|
182
166
|
|
|
@@ -232,7 +216,7 @@ export const mul = nodeProxy( OperatorNode, '*' );
|
|
|
232
216
|
export const div = nodeProxy( OperatorNode, '/' );
|
|
233
217
|
export const remainder = nodeProxy( OperatorNode, '%' );
|
|
234
218
|
export const equal = nodeProxy( OperatorNode, '==' );
|
|
235
|
-
export const
|
|
219
|
+
export const notEqual = nodeProxy( OperatorNode, '!=' );
|
|
236
220
|
export const lessThan = nodeProxy( OperatorNode, '<' );
|
|
237
221
|
export const greaterThan = nodeProxy( OperatorNode, '>' );
|
|
238
222
|
export const lessThanEqual = nodeProxy( OperatorNode, '<=' );
|
|
@@ -252,7 +236,7 @@ addNodeElement( 'mul', mul );
|
|
|
252
236
|
addNodeElement( 'div', div );
|
|
253
237
|
addNodeElement( 'remainder', remainder );
|
|
254
238
|
addNodeElement( 'equal', equal );
|
|
255
|
-
addNodeElement( '
|
|
239
|
+
addNodeElement( 'notEqual', notEqual );
|
|
256
240
|
addNodeElement( 'lessThan', lessThan );
|
|
257
241
|
addNodeElement( 'greaterThan', greaterThan );
|
|
258
242
|
addNodeElement( 'lessThanEqual', lessThanEqual );
|
|
@@ -7,6 +7,10 @@ import SetNode from '../utils/SetNode.js';
|
|
|
7
7
|
import ConstNode from '../core/ConstNode.js';
|
|
8
8
|
import { getValueFromType, getValueType } from '../core/NodeUtils.js';
|
|
9
9
|
|
|
10
|
+
//
|
|
11
|
+
|
|
12
|
+
let currentStack = null;
|
|
13
|
+
|
|
10
14
|
const NodeElements = new Map(); // @TODO: Currently only a few nodes are added, probably also add others
|
|
11
15
|
|
|
12
16
|
export function addNodeElement( name, nodeElement ) {
|
|
@@ -30,15 +34,19 @@ const shaderNodeHandler = {
|
|
|
30
34
|
|
|
31
35
|
},
|
|
32
36
|
|
|
33
|
-
get
|
|
37
|
+
get( node, prop, nodeObj ) {
|
|
34
38
|
|
|
35
39
|
if ( typeof prop === 'string' && node[ prop ] === undefined ) {
|
|
36
40
|
|
|
37
|
-
if (
|
|
41
|
+
if ( node.isStackNode !== true && prop === 'assign' ) {
|
|
42
|
+
|
|
43
|
+
return ( ...params ) => currentStack.assign( nodeObj, ...params );
|
|
44
|
+
|
|
45
|
+
} else if ( NodeElements.has( prop ) ) {
|
|
38
46
|
|
|
39
47
|
const nodeElement = NodeElements.get( prop );
|
|
40
48
|
|
|
41
|
-
return ( ...params ) => nodeElement( nodeObj, ...params );
|
|
49
|
+
return node.isStackNode ? ( ...params ) => nodeObj.add( nodeElement( ...params ) ) : ( ...params ) => nodeElement( nodeObj, ...params );
|
|
42
50
|
|
|
43
51
|
} else if ( prop === 'self' ) {
|
|
44
52
|
|
|
@@ -48,7 +56,7 @@ const shaderNodeHandler = {
|
|
|
48
56
|
|
|
49
57
|
const nodeElement = NodeElements.get( prop.slice( 0, prop.length - 'Assign'.length ) );
|
|
50
58
|
|
|
51
|
-
return ( ...params ) => nodeObj.assign( nodeElement( nodeObj, ...params ) );
|
|
59
|
+
return node.isStackNode ? ( ...params ) => nodeObj.assign( params[ 0 ], nodeElement( ...params ) ) : ( ...params ) => nodeObj.assign( nodeElement( nodeObj, ...params ) );
|
|
52
60
|
|
|
53
61
|
} else if ( /^[xyzwrgbastpq]{1,4}$/.test( prop ) === true ) {
|
|
54
62
|
|
|
@@ -56,7 +64,7 @@ const shaderNodeHandler = {
|
|
|
56
64
|
|
|
57
65
|
prop = parseSwizzle( prop );
|
|
58
66
|
|
|
59
|
-
return nodeObject( new SplitNode(
|
|
67
|
+
return nodeObject( new SplitNode( nodeObj, prop ) );
|
|
60
68
|
|
|
61
69
|
} else if ( /^set[XYZWRGBASTPQ]{1,4}$/.test( prop ) === true ) {
|
|
62
70
|
|
|
@@ -84,19 +92,40 @@ const shaderNodeHandler = {
|
|
|
84
92
|
|
|
85
93
|
// accessing array
|
|
86
94
|
|
|
87
|
-
return nodeObject( new ArrayElementNode(
|
|
95
|
+
return nodeObject( new ArrayElementNode( nodeObj, new ConstNode( Number( prop ), 'uint' ) ) );
|
|
96
|
+
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return Reflect.get( node, prop, nodeObj );
|
|
102
|
+
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
set( node, prop, value, nodeObj ) {
|
|
106
|
+
|
|
107
|
+
if ( typeof prop === 'string' && node[ prop ] === undefined ) {
|
|
108
|
+
|
|
109
|
+
// setting properties
|
|
110
|
+
|
|
111
|
+
if ( /^[xyzwrgbastpq]{1,4}$/.test( prop ) === true || prop === 'width' || prop === 'height' || prop === 'depth' || /^\d+$/.test( prop ) === true ) {
|
|
112
|
+
|
|
113
|
+
nodeObj[ prop ].assign( value );
|
|
114
|
+
|
|
115
|
+
return true;
|
|
88
116
|
|
|
89
117
|
}
|
|
90
118
|
|
|
91
119
|
}
|
|
92
120
|
|
|
93
|
-
return node
|
|
121
|
+
return Reflect.set( node, prop, value, nodeObj );
|
|
94
122
|
|
|
95
123
|
}
|
|
96
124
|
|
|
97
125
|
};
|
|
98
126
|
|
|
99
127
|
const nodeObjectsCacheMap = new WeakMap();
|
|
128
|
+
const nodeBuilderFunctionsCacheMap = new WeakMap();
|
|
100
129
|
|
|
101
130
|
const ShaderNodeObject = function ( obj, altType = null ) {
|
|
102
131
|
|
|
@@ -109,6 +138,7 @@ const ShaderNodeObject = function ( obj, altType = null ) {
|
|
|
109
138
|
if ( nodeObject === undefined ) {
|
|
110
139
|
|
|
111
140
|
nodeObject = new Proxy( obj, shaderNodeHandler );
|
|
141
|
+
|
|
112
142
|
nodeObjectsCacheMap.set( obj, nodeObject );
|
|
113
143
|
nodeObjectsCacheMap.set( nodeObject, nodeObject );
|
|
114
144
|
|
|
@@ -219,8 +249,34 @@ class ShaderCallNodeInternal extends Node {
|
|
|
219
249
|
|
|
220
250
|
const { shaderNode, inputNodes } = this;
|
|
221
251
|
|
|
252
|
+
if ( shaderNode.layout ) {
|
|
253
|
+
|
|
254
|
+
let functionNodesCacheMap = nodeBuilderFunctionsCacheMap.get( builder.constructor );
|
|
255
|
+
|
|
256
|
+
if ( functionNodesCacheMap === undefined ) {
|
|
257
|
+
|
|
258
|
+
functionNodesCacheMap = new WeakMap();
|
|
259
|
+
|
|
260
|
+
nodeBuilderFunctionsCacheMap.set( builder.constructor, functionNodesCacheMap );
|
|
261
|
+
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
let functionNode = functionNodesCacheMap.get( shaderNode );
|
|
265
|
+
|
|
266
|
+
if ( functionNode === undefined ) {
|
|
267
|
+
|
|
268
|
+
functionNode = nodeObject( builder.buildFunctionNode( shaderNode ) );
|
|
269
|
+
|
|
270
|
+
functionNodesCacheMap.set( shaderNode, functionNode );
|
|
271
|
+
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return nodeObject( functionNode.call( inputNodes ) );
|
|
275
|
+
|
|
276
|
+
}
|
|
277
|
+
|
|
222
278
|
const jsFunc = shaderNode.jsFunc;
|
|
223
|
-
const outputNode = inputNodes !== null ? jsFunc(
|
|
279
|
+
const outputNode = inputNodes !== null ? jsFunc( inputNodes, builder.stack, builder ) : jsFunc( builder.stack, builder );
|
|
224
280
|
|
|
225
281
|
return nodeObject( outputNode );
|
|
226
282
|
|
|
@@ -261,11 +317,28 @@ class ShaderNodeInternal extends Node {
|
|
|
261
317
|
super();
|
|
262
318
|
|
|
263
319
|
this.jsFunc = jsFunc;
|
|
320
|
+
this.layout = null;
|
|
321
|
+
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
get isArrayInput() {
|
|
325
|
+
|
|
326
|
+
return /^\(\s+?\[/.test( this.jsFunc.toString() );
|
|
327
|
+
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
setLayout( layout ) {
|
|
331
|
+
|
|
332
|
+
this.layout = layout;
|
|
333
|
+
|
|
334
|
+
return this;
|
|
264
335
|
|
|
265
336
|
}
|
|
266
337
|
|
|
267
338
|
call( inputs = null ) {
|
|
268
339
|
|
|
340
|
+
nodeObjects( inputs );
|
|
341
|
+
|
|
269
342
|
return nodeObject( new ShaderCallNodeInternal( this, inputs ) );
|
|
270
343
|
|
|
271
344
|
}
|
|
@@ -395,12 +468,58 @@ export const tslFn = ( jsFunc ) => {
|
|
|
395
468
|
|
|
396
469
|
const shaderNode = new ShaderNode( jsFunc );
|
|
397
470
|
|
|
398
|
-
|
|
471
|
+
const fn = ( ...params ) => {
|
|
472
|
+
|
|
473
|
+
let inputs;
|
|
474
|
+
|
|
475
|
+
nodeObjects( params );
|
|
476
|
+
|
|
477
|
+
if ( params[ 0 ] && params[ 0 ].isNode ) {
|
|
478
|
+
|
|
479
|
+
inputs = [ ...params ];
|
|
480
|
+
|
|
481
|
+
} else {
|
|
482
|
+
|
|
483
|
+
inputs = params[ 0 ];
|
|
484
|
+
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
return shaderNode.call( inputs );
|
|
488
|
+
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
fn.shaderNode = shaderNode;
|
|
492
|
+
fn.setLayout = ( layout ) => {
|
|
493
|
+
|
|
494
|
+
shaderNode.setLayout( layout );
|
|
495
|
+
|
|
496
|
+
return fn;
|
|
497
|
+
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
return fn;
|
|
399
501
|
|
|
400
502
|
};
|
|
401
503
|
|
|
402
504
|
addNodeClass( 'ShaderNode', ShaderNode );
|
|
403
505
|
|
|
506
|
+
//
|
|
507
|
+
|
|
508
|
+
export const setCurrentStack = stack => currentStack = stack;
|
|
509
|
+
export const getCurrentStack = () => currentStack;
|
|
510
|
+
|
|
511
|
+
export const If = ( ...params ) => currentStack.if( ...params );
|
|
512
|
+
|
|
513
|
+
export function append( node ) {
|
|
514
|
+
|
|
515
|
+
if ( currentStack ) currentStack.add( node );
|
|
516
|
+
|
|
517
|
+
return node;
|
|
518
|
+
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
addNodeElement( 'append', append );
|
|
522
|
+
|
|
404
523
|
// types
|
|
405
524
|
// @TODO: Maybe export from ConstNode.js?
|
|
406
525
|
|
|
@@ -19,8 +19,9 @@ class DiscardNode extends CondNode {
|
|
|
19
19
|
|
|
20
20
|
export default DiscardNode;
|
|
21
21
|
|
|
22
|
-
export const
|
|
22
|
+
export const inlineDiscard = nodeProxy( DiscardNode );
|
|
23
|
+
export const discard = ( condNode ) => inlineDiscard( condNode ).append();
|
|
23
24
|
|
|
24
|
-
addNodeElement( 'discard', discard );
|
|
25
|
+
addNodeElement( 'discard', discard ); // @TODO: Check... this cause a little confusing using in chaining
|
|
25
26
|
|
|
26
27
|
addNodeClass( 'DiscardNode', DiscardNode );
|
|
@@ -28,11 +28,21 @@ class JoinNode extends TempNode {
|
|
|
28
28
|
const type = this.getNodeType( builder );
|
|
29
29
|
const nodes = this.nodes;
|
|
30
30
|
|
|
31
|
+
const primitiveType = builder.getPrimitiveType( type );
|
|
32
|
+
|
|
31
33
|
const snippetValues = [];
|
|
32
34
|
|
|
33
35
|
for ( const input of nodes ) {
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
let inputSnippet = input.build( builder );
|
|
38
|
+
|
|
39
|
+
const inputPrimitiveType = builder.getPrimitiveType( input.getNodeType( builder ) );
|
|
40
|
+
|
|
41
|
+
if ( inputPrimitiveType !== primitiveType ) {
|
|
42
|
+
|
|
43
|
+
inputSnippet = builder.format( inputSnippet, inputPrimitiveType, primitiveType );
|
|
44
|
+
|
|
45
|
+
}
|
|
36
46
|
|
|
37
47
|
snippetValues.push( inputSnippet );
|
|
38
48
|
|
|
@@ -32,9 +32,12 @@ class LoopNode extends Node {
|
|
|
32
32
|
|
|
33
33
|
for ( let i = 0, l = this.params.length - 1; i < l; i ++ ) {
|
|
34
34
|
|
|
35
|
-
const
|
|
35
|
+
const param = this.params[ i ];
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
const name = ( param.isNode !== true && param.name ) || this.getVarName( i );
|
|
38
|
+
const type = ( param.isNode !== true && param.type ) || 'int';
|
|
39
|
+
|
|
40
|
+
inputs[ name ] = expression( name, type );
|
|
38
41
|
|
|
39
42
|
}
|
|
40
43
|
|
|
@@ -73,50 +76,54 @@ class LoopNode extends Node {
|
|
|
73
76
|
for ( let i = 0, l = params.length - 1; i < l; i ++ ) {
|
|
74
77
|
|
|
75
78
|
const param = params[ i ];
|
|
76
|
-
const property = this.getVarName( i );
|
|
77
79
|
|
|
78
|
-
let start = null, end = null,
|
|
80
|
+
let start = null, end = null, name = null, type = null, condition = null, update = null;
|
|
79
81
|
|
|
80
82
|
if ( param.isNode ) {
|
|
81
83
|
|
|
84
|
+
type = 'int';
|
|
85
|
+
name = this.getVarName( i );
|
|
82
86
|
start = '0';
|
|
83
|
-
end = param.build( builder,
|
|
84
|
-
|
|
87
|
+
end = param.build( builder, type );
|
|
88
|
+
condition = '<';
|
|
85
89
|
|
|
86
90
|
} else {
|
|
87
91
|
|
|
92
|
+
type = param.type || 'int';
|
|
93
|
+
name = param.name || this.getVarName( i );
|
|
88
94
|
start = param.start;
|
|
89
95
|
end = param.end;
|
|
90
|
-
|
|
96
|
+
condition = param.condition;
|
|
97
|
+
update = param.update;
|
|
91
98
|
|
|
92
99
|
if ( typeof start === 'number' ) start = start.toString();
|
|
93
|
-
else if ( start && start.isNode ) start = start.build( builder,
|
|
100
|
+
else if ( start && start.isNode ) start = start.build( builder, type );
|
|
94
101
|
|
|
95
102
|
if ( typeof end === 'number' ) end = end.toString();
|
|
96
|
-
else if ( end && end.isNode ) end = end.build( builder,
|
|
103
|
+
else if ( end && end.isNode ) end = end.build( builder, type );
|
|
97
104
|
|
|
98
105
|
if ( start !== undefined && end === undefined ) {
|
|
99
106
|
|
|
100
107
|
start = start + ' - 1';
|
|
101
108
|
end = '0';
|
|
102
|
-
|
|
109
|
+
condition = '>=';
|
|
103
110
|
|
|
104
111
|
} else if ( end !== undefined && start === undefined ) {
|
|
105
112
|
|
|
106
113
|
start = '0';
|
|
107
|
-
|
|
114
|
+
condition = '<';
|
|
108
115
|
|
|
109
116
|
}
|
|
110
117
|
|
|
111
|
-
if (
|
|
118
|
+
if ( condition === undefined ) {
|
|
112
119
|
|
|
113
120
|
if ( Number( start ) > Number( end ) ) {
|
|
114
121
|
|
|
115
|
-
|
|
122
|
+
condition = '>=';
|
|
116
123
|
|
|
117
124
|
} else {
|
|
118
125
|
|
|
119
|
-
|
|
126
|
+
condition = '<';
|
|
120
127
|
|
|
121
128
|
}
|
|
122
129
|
|
|
@@ -124,7 +131,7 @@ class LoopNode extends Node {
|
|
|
124
131
|
|
|
125
132
|
}
|
|
126
133
|
|
|
127
|
-
const internalParam = { start, end,
|
|
134
|
+
const internalParam = { start, end, condition };
|
|
128
135
|
|
|
129
136
|
//
|
|
130
137
|
|
|
@@ -135,22 +142,27 @@ class LoopNode extends Node {
|
|
|
135
142
|
let conditionalSnippet = '';
|
|
136
143
|
let updateSnippet = '';
|
|
137
144
|
|
|
138
|
-
|
|
145
|
+
if ( ! update ) {
|
|
139
146
|
|
|
140
|
-
|
|
147
|
+
if ( type === 'int' ) {
|
|
141
148
|
|
|
142
|
-
|
|
143
|
-
|
|
149
|
+
if ( condition.includes( '<' ) ) update = '++';
|
|
150
|
+
else update = '--';
|
|
144
151
|
|
|
145
|
-
|
|
152
|
+
} else {
|
|
146
153
|
|
|
147
|
-
|
|
154
|
+
if ( condition.includes( '<' ) ) update = '+= 1';
|
|
155
|
+
else update = '-= 1';
|
|
148
156
|
|
|
149
|
-
|
|
150
|
-
updateSnippet += property + ' ++';
|
|
157
|
+
}
|
|
151
158
|
|
|
152
159
|
}
|
|
153
160
|
|
|
161
|
+
declarationSnippet += builder.getVar( type, name ) + ' = ' + startSnippet;
|
|
162
|
+
|
|
163
|
+
conditionalSnippet += name + ' ' + condition + ' ' + endSnippet;
|
|
164
|
+
updateSnippet += name + ' ' + update;
|
|
165
|
+
|
|
154
166
|
const forSnippet = `for ( ${ declarationSnippet }; ${ conditionalSnippet }; ${ updateSnippet } )`;
|
|
155
167
|
|
|
156
168
|
builder.addFlowCode( ( i === 0 ? '\n' : '' ) + builder.tab + forSnippet + ' {\n\n' ).addFlowTab();
|
|
@@ -179,7 +191,7 @@ class LoopNode extends Node {
|
|
|
179
191
|
|
|
180
192
|
export default LoopNode;
|
|
181
193
|
|
|
182
|
-
export const loop = ( ...params ) => nodeObject( new LoopNode( nodeArray( params, 'int' ) ) );
|
|
194
|
+
export const loop = ( ...params ) => nodeObject( new LoopNode( nodeArray( params, 'int' ) ) ).append();
|
|
183
195
|
|
|
184
196
|
addNodeElement( 'loop', ( returns, ...params ) => bypass( returns, loop( ...params ) ) );
|
|
185
197
|
|