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.
Files changed (183) hide show
  1. package/README.md +6 -4
  2. package/build/three.cjs +1486 -842
  3. package/build/three.js +1486 -842
  4. package/build/three.min.js +1 -1
  5. package/build/three.module.js +1481 -843
  6. package/build/three.module.min.js +1 -1
  7. package/examples/jsm/Addons.js +290 -0
  8. package/examples/jsm/controls/FlyControls.js +26 -0
  9. package/examples/jsm/controls/OrbitControls.js +12 -1
  10. package/examples/jsm/controls/TransformControls.js +27 -11
  11. package/examples/jsm/csm/CSMShader.js +1 -1
  12. package/examples/jsm/exporters/GLTFExporter.js +72 -2
  13. package/examples/jsm/geometries/InstancedPointsGeometry.js +174 -0
  14. package/examples/jsm/geometries/SDFGeometryGenerator.js +144 -0
  15. package/examples/jsm/libs/lottie_canvas.module.js +6 -1
  16. package/examples/jsm/libs/opentype.module.js +13 -75
  17. package/examples/jsm/libs/surfaceNet.js +201 -0
  18. package/examples/jsm/loaders/GLTFLoader.js +12 -3
  19. package/examples/jsm/loaders/LUTImageLoader.js +162 -0
  20. package/examples/jsm/loaders/lwo/IFFParser.js +89 -93
  21. package/examples/jsm/materials/MeshGouraudMaterial.js +2 -0
  22. package/examples/jsm/math/Capsule.js +0 -55
  23. package/examples/jsm/math/Octree.js +70 -3
  24. package/examples/jsm/modifiers/SimplifyModifier.js +103 -11
  25. package/examples/jsm/modifiers/TessellateModifier.js +3 -3
  26. package/examples/jsm/nodes/Nodes.js +6 -6
  27. package/examples/jsm/nodes/accessors/CubeTextureNode.js +3 -3
  28. package/examples/jsm/nodes/accessors/InstanceNode.js +3 -3
  29. package/examples/jsm/nodes/accessors/InstancedPointsMaterialNode.js +21 -0
  30. package/examples/jsm/nodes/accessors/MaterialNode.js +68 -31
  31. package/examples/jsm/nodes/accessors/ModelNode.js +1 -2
  32. package/examples/jsm/nodes/accessors/MorphNode.js +5 -5
  33. package/examples/jsm/nodes/accessors/NormalNode.js +1 -1
  34. package/examples/jsm/nodes/accessors/PositionNode.js +1 -1
  35. package/examples/jsm/nodes/accessors/SkinningNode.js +13 -3
  36. package/examples/jsm/nodes/accessors/TextureNode.js +3 -3
  37. package/examples/jsm/nodes/code/FunctionNode.js +1 -1
  38. package/examples/jsm/nodes/core/AssignNode.js +72 -0
  39. package/examples/jsm/nodes/core/LightingModel.js +3 -1
  40. package/examples/jsm/nodes/core/Node.js +7 -12
  41. package/examples/jsm/nodes/core/NodeBuilder.js +126 -16
  42. package/examples/jsm/nodes/core/NodeUtils.js +4 -2
  43. package/examples/jsm/nodes/core/OutputStructNode.js +1 -1
  44. package/examples/jsm/nodes/core/ParameterNode.js +33 -0
  45. package/examples/jsm/nodes/core/PropertyNode.js +4 -10
  46. package/examples/jsm/nodes/core/StackNode.js +7 -17
  47. package/examples/jsm/nodes/core/TempNode.js +1 -1
  48. package/examples/jsm/nodes/core/VarNode.js +6 -35
  49. package/examples/jsm/nodes/core/VaryingNode.js +2 -0
  50. package/examples/jsm/nodes/display/BumpMapNode.js +35 -13
  51. package/examples/jsm/nodes/display/NormalMapNode.js +3 -1
  52. package/examples/jsm/nodes/display/ViewportNode.js +14 -4
  53. package/examples/jsm/nodes/functions/BSDF/BRDF_Sheen.js +20 -6
  54. package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +8 -7
  55. package/examples/jsm/nodes/functions/BSDF/D_GGX.js +8 -3
  56. package/examples/jsm/nodes/functions/BSDF/Schlick_to_F0.js +8 -0
  57. package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +8 -0
  58. package/examples/jsm/nodes/functions/PhysicalLightingModel.js +93 -43
  59. package/examples/jsm/nodes/gpgpu/ComputeNode.js +2 -2
  60. package/examples/jsm/nodes/lighting/AmbientLightNode.js +1 -1
  61. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +19 -5
  62. package/examples/jsm/nodes/lighting/DirectionalLightNode.js +1 -1
  63. package/examples/jsm/nodes/lighting/EnvironmentNode.js +0 -6
  64. package/examples/jsm/nodes/lighting/LightingContextNode.js +21 -57
  65. package/examples/jsm/nodes/lighting/LightsNode.js +62 -4
  66. package/examples/jsm/nodes/lighting/PointLightNode.js +1 -1
  67. package/examples/jsm/nodes/lighting/SpotLightNode.js +1 -1
  68. package/examples/jsm/nodes/materials/InstancedPointsNodeMaterial.js +162 -0
  69. package/examples/jsm/nodes/materials/Line2NodeMaterial.js +70 -71
  70. package/examples/jsm/nodes/materials/LineDashedNodeMaterial.js +5 -5
  71. package/examples/jsm/nodes/materials/Materials.js +1 -0
  72. package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +2 -2
  73. package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +3 -3
  74. package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +47 -20
  75. package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +6 -6
  76. package/examples/jsm/nodes/materials/NodeMaterial.js +17 -20
  77. package/examples/jsm/nodes/materialx/lib/mx_noise.js +5 -5
  78. package/examples/jsm/nodes/math/OperatorNode.js +5 -21
  79. package/examples/jsm/nodes/shadernode/ShaderNode.js +128 -9
  80. package/examples/jsm/nodes/utils/ArrayElementNode.js +2 -0
  81. package/examples/jsm/nodes/utils/DiscardNode.js +3 -2
  82. package/examples/jsm/nodes/utils/JoinNode.js +11 -1
  83. package/examples/jsm/nodes/utils/LoopNode.js +36 -24
  84. package/examples/jsm/nodes/utils/SplitNode.js +2 -0
  85. package/examples/jsm/objects/BatchedMesh.js +586 -0
  86. package/examples/jsm/objects/InstancedPoints.js +21 -0
  87. package/examples/jsm/objects/Lensflare.js +20 -0
  88. package/examples/jsm/objects/ReflectorForSSRPass.js +3 -0
  89. package/examples/jsm/objects/Refractor.js +3 -0
  90. package/examples/jsm/objects/Sky.js +5 -3
  91. package/examples/jsm/objects/Water.js +5 -2
  92. package/examples/jsm/objects/Water2.js +3 -0
  93. package/examples/jsm/physics/AmmoPhysics.js +21 -0
  94. package/examples/jsm/physics/RapierPhysics.js +21 -0
  95. package/examples/jsm/postprocessing/BokehPass.js +3 -2
  96. package/examples/jsm/postprocessing/LUTPass.js +2 -1
  97. package/examples/jsm/postprocessing/OutputPass.js +1 -0
  98. package/examples/jsm/postprocessing/Pass.js +14 -3
  99. package/examples/jsm/postprocessing/SAOPass.js +0 -1
  100. package/examples/jsm/postprocessing/SMAAPass.js +0 -2
  101. package/examples/jsm/postprocessing/TAARenderPass.js +1 -2
  102. package/examples/jsm/renderers/CSS3DRenderer.js +3 -9
  103. package/examples/jsm/renderers/SVGRenderer.js +9 -6
  104. package/examples/jsm/renderers/common/Bindings.js +1 -1
  105. package/examples/jsm/renderers/common/RenderObject.js +8 -1
  106. package/examples/jsm/renderers/common/RenderObjects.js +1 -1
  107. package/examples/jsm/renderers/common/Textures.js +4 -36
  108. package/examples/jsm/renderers/common/nodes/Nodes.js +53 -18
  109. package/examples/jsm/renderers/webgl/WebGLBackend.js +291 -50
  110. package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +88 -12
  111. package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +40 -5
  112. package/examples/jsm/renderers/webgl/utils/WebGLState.js +14 -2
  113. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +2 -0
  114. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +36 -4
  115. package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +2 -0
  116. package/examples/jsm/shaders/AfterimageShader.js +2 -0
  117. package/examples/jsm/shaders/BasicShader.js +2 -0
  118. package/examples/jsm/shaders/BlendShader.js +2 -0
  119. package/examples/jsm/shaders/BokehShader.js +2 -0
  120. package/examples/jsm/shaders/BokehShader2.js +4 -0
  121. package/examples/jsm/shaders/BrightnessContrastShader.js +2 -0
  122. package/examples/jsm/shaders/ColorCorrectionShader.js +2 -0
  123. package/examples/jsm/shaders/DOFMipMapShader.js +2 -0
  124. package/examples/jsm/shaders/DepthLimitedBlurShader.js +5 -0
  125. package/examples/jsm/shaders/FXAAShader.js +2 -0
  126. package/examples/jsm/shaders/FilmShader.js +1 -1
  127. package/examples/jsm/shaders/FocusShader.js +2 -0
  128. package/examples/jsm/shaders/FreiChenShader.js +2 -0
  129. package/examples/jsm/shaders/GodRaysShader.js +8 -0
  130. package/examples/jsm/shaders/HalftoneShader.js +2 -0
  131. package/examples/jsm/shaders/HorizontalTiltShiftShader.js +2 -0
  132. package/examples/jsm/shaders/HueSaturationShader.js +2 -0
  133. package/examples/jsm/shaders/KaleidoShader.js +2 -0
  134. package/examples/jsm/shaders/LuminosityHighPassShader.js +2 -0
  135. package/examples/jsm/shaders/LuminosityShader.js +2 -0
  136. package/examples/jsm/shaders/MMDToonShader.js +2 -0
  137. package/examples/jsm/shaders/MirrorShader.js +2 -0
  138. package/examples/jsm/shaders/NormalMapShader.js +2 -0
  139. package/examples/jsm/shaders/OutputShader.js +4 -5
  140. package/examples/jsm/shaders/SAOShader.js +5 -0
  141. package/examples/jsm/shaders/SMAAShader.js +6 -0
  142. package/examples/jsm/shaders/SSAOShader.js +6 -0
  143. package/examples/jsm/shaders/SSRShader.js +6 -0
  144. package/examples/jsm/shaders/SobelOperatorShader.js +2 -0
  145. package/examples/jsm/shaders/SubsurfaceScatteringShader.js +2 -0
  146. package/examples/jsm/shaders/TechnicolorShader.js +2 -0
  147. package/examples/jsm/shaders/TriangleBlurShader.js +2 -0
  148. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +2 -0
  149. package/examples/jsm/shaders/VelocityShader.js +2 -0
  150. package/examples/jsm/shaders/VerticalTiltShiftShader.js +2 -0
  151. package/examples/jsm/shaders/WaterRefractionShader.js +2 -0
  152. package/examples/jsm/transpiler/AST.js +231 -0
  153. package/examples/jsm/transpiler/GLSLDecoder.js +899 -0
  154. package/examples/jsm/transpiler/ShaderToyDecoder.js +49 -0
  155. package/examples/jsm/transpiler/TSLEncoder.js +611 -0
  156. package/examples/jsm/transpiler/Transpiler.js +18 -0
  157. package/examples/jsm/webxr/VRButton.js +1 -1
  158. package/examples/jsm/webxr/XRButton.js +7 -5
  159. package/examples/jsm/webxr/XREstimatedLight.js +1 -1
  160. package/package.json +4 -1
  161. package/src/constants.js +7 -1
  162. package/src/extras/PMREMGenerator.js +7 -1
  163. package/src/loaders/MaterialLoader.js +10 -2
  164. package/src/materials/Material.js +27 -13
  165. package/src/math/Box3.js +35 -18
  166. package/src/math/Vector3.js +11 -12
  167. package/src/objects/SkinnedMesh.js +6 -7
  168. package/src/renderers/WebGLMultiviewRenderTarget.js +35 -0
  169. package/src/renderers/WebGLRenderer.js +199 -45
  170. package/src/renderers/shaders/ShaderChunk/aomap_fragment.glsl.js +8 -0
  171. package/src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js +3 -2
  172. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +1 -1
  173. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +8 -6
  174. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +2 -2
  175. package/src/renderers/webgl/WebGLBackground.js +1 -1
  176. package/src/renderers/webgl/WebGLMultiview.js +100 -0
  177. package/src/renderers/webgl/WebGLProgram.js +130 -50
  178. package/src/renderers/webgl/WebGLPrograms.js +8 -0
  179. package/src/renderers/webgl/WebGLState.js +25 -4
  180. package/src/renderers/webgl/WebGLTextures.js +197 -20
  181. package/src/renderers/webxr/WebXRManager.js +36 -12
  182. package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +0 -76
  183. 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/ExtendedMaterialNode.js';
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, dFdx, dFdy } from '../math/MathNode.js';
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
- builder.stack.assign( output, outputNode );
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
- builder.stack.add( morph( object ) );
127
+ morph( object ).append();
129
128
 
130
129
  }
131
130
 
132
131
  if ( object.isSkinnedMesh === true ) {
133
132
 
134
- builder.stack.add( skinning( object ) );
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
- builder.stack.add( instance( object ) );
139
+ instance( object ).append();
141
140
 
142
141
  }
143
142
 
144
143
  if ( this.positionNode !== null ) {
145
144
 
146
- builder.stack.assign( positionLocal, this.positionNode );
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( { stack, geometry } ) {
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
- stack.assign( diffuseColor, colorNode );
169
+ diffuseColor.assign( colorNode );
171
170
 
172
171
  // OPACITY
173
172
 
174
173
  const opacityNode = this.opacityNode ? float( this.opacityNode ) : materialOpacity;
175
- stack.assign( diffuseColor.a, diffuseColor.a.mul( opacityNode ) );
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
- stack.add( diffuseColor.a.lessThanEqual( alphaTestNode ).discard() );
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( { stack } ) {
194
+ setupNormal() {
196
195
 
197
196
  // NORMAL VIEW
198
197
 
199
198
  if ( this.flatShading === true ) {
200
199
 
201
- const fdx = dFdx( positionView );
202
- const fdy = dFdy( positionView );
203
- const normalNode = fdx.cross( fdy ).normalize();
200
+ const normalNode = positionView.dFdx().cross( positionView.dFdy() ).normalize();
204
201
 
205
- stack.assign( transformedNormalView, normalNode );
202
+ transformedNormalView.assign( normalNode );
206
203
 
207
204
  } else {
208
205
 
209
206
  const normalNode = this.normalNode ? vec3( this.normalNode ) : materialNormal;
210
207
 
211
- stack.assign( transformedNormalView, normalNode );
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 lightingModelNode = this.setupLightingModel( builder );
289
+ const lightingModel = this.setupLightingModel( builder );
293
290
 
294
- outgoingLightNode = lightingContext( lightsNode, lightingModelNode, backdropNode, backdropAlphaNode );
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( 'float mx_worley_noise_vec2( any p, float jitter, int metric )', includes );
613
- export const mx_worley_noise_vec3 = glslFn( 'float mx_worley_noise_vec3( any p, float jitter, int metric )', includes );
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( 'float mx_fractal_noise_vec2( vec3 p, int octaves, float lacunarity, float diminish )', includes );
617
- export const mx_fractal_noise_vec3 = glslFn( 'float mx_fractal_noise_vec3( vec3 p, int octaves, float lacunarity, float diminish )', includes );
618
- export const mx_fractal_noise_vec4 = glslFn( 'float mx_fractal_noise_vec4( vec3 p, int octaves, float lacunarity, float diminish )', includes );
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 === '=' || 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 assign = nodeProxy( OperatorNode, '=' );
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( 'assign', assign );
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: function ( node, prop, nodeObj ) {
37
+ get( node, prop, nodeObj ) {
34
38
 
35
39
  if ( typeof prop === 'string' && node[ prop ] === undefined ) {
36
40
 
37
- if ( NodeElements.has( prop ) ) {
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( node, prop ) );
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( node, new ConstNode( Number( prop ), 'uint' ) ) );
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[ prop ];
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( nodeObjects( inputNodes ), builder.stack, builder ) : jsFunc( builder.stack, builder );
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
- return ( inputs ) => shaderNode.call( inputs );
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
 
@@ -9,6 +9,8 @@ class ArrayElementNode extends Node { // @TODO: If extending from TempNode it br
9
9
  this.node = node;
10
10
  this.indexNode = indexNode;
11
11
 
12
+ this.isArrayElementNode = true;
13
+
12
14
  }
13
15
 
14
16
  getNodeType( builder ) {
@@ -19,8 +19,9 @@ class DiscardNode extends CondNode {
19
19
 
20
20
  export default DiscardNode;
21
21
 
22
- export const discard = nodeProxy( DiscardNode );
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
- const inputSnippet = input.build( builder );
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 prop = this.getVarName( i );
35
+ const param = this.params[ i ];
36
36
 
37
- inputs[ prop ] = expression( prop, 'int' );
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, direction = 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, 'int' );
84
- direction = 'forward';
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
- direction = param.direction;
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, 'int' );
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, 'int' );
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
- direction = 'backwards';
109
+ condition = '>=';
103
110
 
104
111
  } else if ( end !== undefined && start === undefined ) {
105
112
 
106
113
  start = '0';
107
- direction = 'forward';
114
+ condition = '<';
108
115
 
109
116
  }
110
117
 
111
- if ( direction === undefined ) {
118
+ if ( condition === undefined ) {
112
119
 
113
120
  if ( Number( start ) > Number( end ) ) {
114
121
 
115
- direction = 'backwards';
122
+ condition = '>=';
116
123
 
117
124
  } else {
118
125
 
119
- direction = 'forward';
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, direction };
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
- declarationSnippet += builder.getVar( 'int', property ) + ' = ' + startSnippet;
145
+ if ( ! update ) {
139
146
 
140
- if ( internalParam.direction === 'backwards' ) {
147
+ if ( type === 'int' ) {
141
148
 
142
- conditionalSnippet += property + ' >= ' + endSnippet;
143
- updateSnippet += property + ' --';
149
+ if ( condition.includes( '<' ) ) update = '++';
150
+ else update = '--';
144
151
 
145
- } else {
152
+ } else {
146
153
 
147
- // forward
154
+ if ( condition.includes( '<' ) ) update = '+= 1';
155
+ else update = '-= 1';
148
156
 
149
- conditionalSnippet += property + ' < ' + endSnippet;
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
 
@@ -12,6 +12,8 @@ class SplitNode extends Node {
12
12
  this.node = node;
13
13
  this.components = components;
14
14
 
15
+ this.isSplitNode = true;
16
+
15
17
  }
16
18
 
17
19
  getVectorLength() {