@needle-tools/three 0.153.1 → 0.154.1

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 (180) hide show
  1. package/build/three.cjs +1260 -1517
  2. package/build/three.js +1267 -1524
  3. package/build/three.min.js +7 -8
  4. package/build/three.module.js +859 -1097
  5. package/build/three.module.min.js +6 -7
  6. package/examples/jsm/controls/ArcballControls.js +2 -1
  7. package/examples/jsm/controls/FlyControls.js +25 -9
  8. package/examples/jsm/controls/OrbitControls.js +7 -1
  9. package/examples/jsm/csm/CSM.js +1 -1
  10. package/examples/jsm/effects/AnaglyphEffect.js +1 -1
  11. package/examples/jsm/effects/OutlineEffect.js +1 -1
  12. package/examples/jsm/effects/ParallaxBarrierEffect.js +1 -1
  13. package/examples/jsm/environments/RoomEnvironment.js +6 -2
  14. package/examples/jsm/lines/LineMaterial.js +1 -1
  15. package/examples/jsm/loaders/3DMLoader.js +1 -1
  16. package/examples/jsm/loaders/3MFLoader.js +5 -1
  17. package/examples/jsm/loaders/AMFLoader.js +5 -1
  18. package/examples/jsm/loaders/ColladaLoader.js +4 -1
  19. package/examples/jsm/loaders/FBXLoader.js +9 -2
  20. package/examples/jsm/loaders/LDrawLoader.js +4 -7
  21. package/examples/jsm/loaders/PLYLoader.js +16 -6
  22. package/examples/jsm/loaders/VRMLLoader.js +16 -4
  23. package/examples/jsm/materials/MeshGouraudMaterial.js +2 -2
  24. package/examples/jsm/math/MeshSurfaceSampler.js +76 -35
  25. package/examples/jsm/nodes/Nodes.js +20 -15
  26. package/examples/jsm/nodes/accessors/BufferAttributeNode.js +21 -8
  27. package/examples/jsm/nodes/accessors/CameraNode.js +25 -4
  28. package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +7 -1
  29. package/examples/jsm/nodes/accessors/InstanceNode.js +2 -4
  30. package/examples/jsm/nodes/accessors/MaterialNode.js +55 -47
  31. package/examples/jsm/nodes/accessors/ModelNode.js +3 -1
  32. package/examples/jsm/nodes/accessors/MorphNode.js +70 -0
  33. package/examples/jsm/nodes/accessors/NormalNode.js +3 -2
  34. package/examples/jsm/nodes/accessors/Object3DNode.js +10 -2
  35. package/examples/jsm/nodes/accessors/SceneNode.js +46 -0
  36. package/examples/jsm/nodes/accessors/SkinningNode.js +43 -62
  37. package/examples/jsm/nodes/accessors/TangentNode.js +2 -2
  38. package/examples/jsm/nodes/accessors/TextureBicubicNode.js +94 -0
  39. package/examples/jsm/nodes/accessors/TextureNode.js +68 -6
  40. package/examples/jsm/nodes/accessors/TextureSizeNode.js +35 -0
  41. package/examples/jsm/nodes/accessors/UVNode.js +1 -1
  42. package/examples/jsm/nodes/code/CodeNode.js +3 -0
  43. package/examples/jsm/nodes/code/FunctionNode.js +25 -4
  44. package/examples/jsm/nodes/core/BypassNode.js +2 -2
  45. package/examples/jsm/nodes/core/ContextNode.js +2 -0
  46. package/examples/jsm/nodes/core/IndexNode.js +66 -0
  47. package/examples/jsm/nodes/core/LightingModel.js +2 -1
  48. package/examples/jsm/nodes/core/Node.js +12 -15
  49. package/examples/jsm/nodes/core/NodeBuilder.js +24 -5
  50. package/examples/jsm/nodes/core/PropertyNode.js +4 -0
  51. package/examples/jsm/nodes/core/StackNode.js +1 -1
  52. package/examples/jsm/nodes/core/UniformNode.js +1 -1
  53. package/examples/jsm/nodes/core/VarNode.js +1 -3
  54. package/examples/jsm/nodes/display/BlendModeNode.js +9 -9
  55. package/examples/jsm/nodes/display/ColorAdjustmentNode.js +7 -7
  56. package/examples/jsm/nodes/display/ColorSpaceNode.js +50 -49
  57. package/examples/jsm/nodes/display/NormalMapNode.js +3 -3
  58. package/examples/jsm/nodes/display/ToneMappingNode.js +8 -8
  59. package/examples/jsm/nodes/display/ViewportDepthNode.js +69 -0
  60. package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +34 -0
  61. package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +6 -5
  62. package/examples/jsm/nodes/display/ViewportTextureNode.js +23 -15
  63. package/examples/jsm/nodes/functions/BSDF/BRDF_BlinnPhong.js +5 -5
  64. package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +10 -8
  65. package/examples/jsm/nodes/functions/BSDF/BRDF_Lambert.js +2 -2
  66. package/examples/jsm/nodes/functions/BSDF/BRDF_Sheen.js +43 -0
  67. package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +4 -4
  68. package/examples/jsm/nodes/functions/BSDF/D_GGX.js +2 -2
  69. package/examples/jsm/nodes/functions/BSDF/EnvironmentBRDF.js +13 -0
  70. package/examples/jsm/nodes/functions/BSDF/F_Schlick.js +2 -4
  71. package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +2 -2
  72. package/examples/jsm/nodes/functions/PhongLightingModel.js +7 -7
  73. package/examples/jsm/nodes/functions/PhysicalLightingModel.js +129 -18
  74. package/examples/jsm/nodes/functions/material/getGeometryRoughness.js +2 -2
  75. package/examples/jsm/nodes/functions/material/getRoughness.js +3 -3
  76. package/examples/jsm/nodes/geometry/RangeNode.js +1 -1
  77. package/examples/jsm/nodes/lighting/DirectionalLightNode.js +2 -2
  78. package/examples/jsm/nodes/lighting/EnvironmentNode.js +91 -62
  79. package/examples/jsm/nodes/lighting/LightUtils.js +2 -2
  80. package/examples/jsm/nodes/lighting/LightingContextNode.js +17 -15
  81. package/examples/jsm/nodes/lighting/PointLightNode.js +3 -3
  82. package/examples/jsm/nodes/lighting/SpotLightNode.js +3 -3
  83. package/examples/jsm/nodes/materials/LineBasicNodeMaterial.js +0 -15
  84. package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +0 -15
  85. package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +0 -10
  86. package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +0 -9
  87. package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +41 -0
  88. package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +1 -14
  89. package/examples/jsm/nodes/materials/NodeMaterial.js +79 -28
  90. package/examples/jsm/nodes/materials/PointsNodeMaterial.js +0 -9
  91. package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +0 -7
  92. package/examples/jsm/nodes/materialx/lib/mx_hsv.js +3 -3
  93. package/examples/jsm/nodes/materialx/lib/mx_noise.js +14 -14
  94. package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +4 -4
  95. package/examples/jsm/nodes/math/MathNode.js +6 -0
  96. package/examples/jsm/nodes/math/OperatorNode.js +1 -1
  97. package/examples/jsm/nodes/procedural/CheckerNode.js +3 -3
  98. package/examples/jsm/nodes/shadernode/ShaderNode.js +24 -4
  99. package/examples/jsm/nodes/utils/LoopNode.js +1 -1
  100. package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +1 -1
  101. package/examples/jsm/objects/GroundProjectedSkybox.js +1 -1
  102. package/examples/jsm/objects/Reflector.js +1 -1
  103. package/examples/jsm/objects/Refractor.js +1 -1
  104. package/examples/jsm/objects/Sky.js +1 -1
  105. package/examples/jsm/objects/Water.js +1 -1
  106. package/examples/jsm/objects/Water2.js +1 -1
  107. package/examples/jsm/offscreen/scene.js +1 -0
  108. package/examples/jsm/postprocessing/EffectComposer.js +2 -0
  109. package/examples/jsm/postprocessing/OutlinePass.js +1 -3
  110. package/examples/jsm/postprocessing/SSAARenderPass.js +3 -12
  111. package/examples/jsm/postprocessing/SavePass.js +3 -1
  112. package/examples/jsm/postprocessing/TAARenderPass.js +14 -2
  113. package/examples/jsm/postprocessing/TexturePass.js +2 -1
  114. package/examples/jsm/postprocessing/UnrealBloomPass.js +9 -10
  115. package/examples/jsm/renderers/common/Backend.js +2 -0
  116. package/examples/jsm/renderers/common/Background.js +7 -6
  117. package/examples/jsm/renderers/common/Pipelines.js +26 -14
  118. package/examples/jsm/renderers/common/RenderObject.js +18 -0
  119. package/examples/jsm/renderers/common/RenderObjects.js +29 -29
  120. package/examples/jsm/renderers/common/Renderer.js +48 -6
  121. package/examples/jsm/renderers/common/nodes/Nodes.js +1 -1
  122. package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +340 -0
  123. package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +23 -19
  124. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +123 -41
  125. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +29 -9
  126. package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +4 -0
  127. package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +8 -13
  128. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +85 -3
  129. package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +5 -1
  130. package/examples/jsm/shaders/BlendShader.js +1 -2
  131. package/examples/jsm/shaders/BokehShader2.js +1 -1
  132. package/examples/jsm/shaders/CopyShader.js +2 -2
  133. package/examples/jsm/shaders/ToonShader.js +4 -4
  134. package/examples/jsm/shaders/WaterRefractionShader.js +1 -1
  135. package/examples/jsm/webxr/OculusHandPointerModel.js +34 -13
  136. package/package.json +2 -1
  137. package/src/Three.Legacy.js +0 -228
  138. package/src/animation/PropertyBinding.js +1 -1
  139. package/src/constants.js +1 -1
  140. package/src/core/BufferAttribute.js +0 -24
  141. package/src/core/BufferGeometry.js +0 -7
  142. package/src/loaders/Loader.js +2 -0
  143. package/src/loaders/MaterialLoader.js +1 -0
  144. package/src/materials/Material.js +3 -0
  145. package/src/objects/Skeleton.js +0 -2
  146. package/src/renderers/WebGLRenderer.js +9 -21
  147. package/src/renderers/shaders/ShaderChunk/alphahash_fragment.glsl.js +7 -0
  148. package/src/renderers/shaders/ShaderChunk/alphahash_pars_fragment.glsl.js +68 -0
  149. package/src/renderers/shaders/ShaderChunk/begin_vertex.glsl.js +6 -0
  150. package/src/renderers/shaders/ShaderChunk/common.glsl.js +6 -0
  151. package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +9 -1
  152. package/src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl.js +1 -1
  153. package/src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl.js +1 -1
  154. package/src/renderers/shaders/ShaderChunk/uv_vertex.glsl.js +1 -1
  155. package/src/renderers/shaders/ShaderChunk.js +10 -6
  156. package/src/renderers/shaders/ShaderLib/background.glsl.js +1 -1
  157. package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +1 -1
  158. package/src/renderers/shaders/ShaderLib/cube.glsl.js +1 -1
  159. package/src/renderers/shaders/ShaderLib/depth.glsl.js +2 -0
  160. package/src/renderers/shaders/ShaderLib/distanceRGBA.glsl.js +2 -0
  161. package/src/renderers/shaders/ShaderLib/equirect.glsl.js +1 -1
  162. package/src/renderers/shaders/ShaderLib/linedashed.glsl.js +2 -2
  163. package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +4 -2
  164. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +4 -2
  165. package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +4 -2
  166. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +4 -2
  167. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -2
  168. package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +4 -2
  169. package/src/renderers/shaders/ShaderLib/points.glsl.js +4 -2
  170. package/src/renderers/shaders/ShaderLib/shadow.glsl.js +1 -1
  171. package/src/renderers/shaders/ShaderLib/sprite.glsl.js +4 -2
  172. package/src/renderers/webgl/WebGLObjects.js +23 -3
  173. package/src/renderers/webgl/WebGLProgram.js +24 -5
  174. package/src/renderers/webgl/WebGLPrograms.js +3 -0
  175. package/src/renderers/webxr/WebXRManager.js +11 -33
  176. package/src/scenes/Scene.js +0 -14
  177. package/examples/jsm/nodes/core/InstanceIndexNode.js +0 -45
  178. /package/src/renderers/shaders/ShaderChunk/{encodings_fragment.glsl.js → colorspace_fragment.glsl.js} +0 -0
  179. /package/src/renderers/shaders/ShaderChunk/{encodings_pars_fragment.glsl.js → colorspace_pars_fragment.glsl.js} +0 -0
  180. /package/src/renderers/shaders/ShaderChunk/{output_fragment.glsl.js → opaque_fragment.glsl.js} +0 -0
@@ -7,12 +7,13 @@ import { materialAlphaTest, materialColor, materialOpacity, materialEmissive } f
7
7
  import { modelViewProjection } from '../accessors/ModelViewProjectionNode.js';
8
8
  import { transformedNormalView } from '../accessors/NormalNode.js';
9
9
  import { instance } from '../accessors/InstanceNode.js';
10
- import { positionLocal } from '../accessors/PositionNode.js';
10
+ import { positionLocal, positionView } from '../accessors/PositionNode.js';
11
11
  import { skinning } from '../accessors/SkinningNode.js';
12
+ import { morph } from '../accessors/MorphNode.js';
12
13
  import { texture } from '../accessors/TextureNode.js';
13
14
  import { cubeTexture } from '../accessors/CubeTextureNode.js';
14
15
  import { lightsWithoutWrap } from '../lighting/LightsNode.js';
15
- import { mix } from '../math/MathNode.js';
16
+ import { mix, dFdx, dFdy } from '../math/MathNode.js';
16
17
  import { float, vec3, vec4 } from '../shadernode/ShaderNode.js';
17
18
  import AONode from '../lighting/AONode.js';
18
19
  import EnvironmentNode from '../lighting/EnvironmentNode.js';
@@ -29,6 +30,8 @@ class NodeMaterial extends ShaderMaterial {
29
30
 
30
31
  this.type = this.constructor.name;
31
32
 
33
+ this.forceSinglePass = false;
34
+
32
35
  this.lights = true;
33
36
  this.normals = true;
34
37
 
@@ -43,12 +46,13 @@ class NodeMaterial extends ShaderMaterial {
43
46
  this.alphaTestNode = null;
44
47
 
45
48
  this.positionNode = null;
49
+ this.outputNode = null;
46
50
 
47
51
  }
48
52
 
49
53
  customProgramCacheKey() {
50
54
 
51
- return getCacheKey( this );
55
+ return this.type + getCacheKey( this );
52
56
 
53
57
  }
54
58
 
@@ -72,14 +76,22 @@ class NodeMaterial extends ShaderMaterial {
72
76
 
73
77
  builder.addStack();
74
78
 
75
- if ( this.normals === true ) this.constructNormal( builder );
79
+ if ( this.isUnlit === false ) {
80
+
81
+ if ( this.normals === true ) this.constructNormal( builder );
82
+
83
+ this.constructDiffuseColor( builder );
84
+ this.constructVariants( builder );
76
85
 
77
- this.constructDiffuseColor( builder );
78
- this.constructVariants( builder );
86
+ const outgoingLightNode = this.constructLighting( builder );
79
87
 
80
- const outgoingLightNode = this.constructLighting( builder );
88
+ builder.stack.outputNode = this.constructOutput( builder, vec4( outgoingLightNode, diffuseColor.a ) );
89
+
90
+ } else {
81
91
 
82
- builder.stack.outputNode = this.constructOutput( builder, outgoingLightNode, diffuseColor.a );
92
+ builder.stack.outputNode = this.constructOutput( builder, this.outputNode || vec4( 0, 0, 0, 1 ) );
93
+
94
+ }
83
95
 
84
96
  builder.addFlow( 'fragment', builder.removeStack() );
85
97
 
@@ -88,28 +100,35 @@ class NodeMaterial extends ShaderMaterial {
88
100
  constructPosition( builder ) {
89
101
 
90
102
  const object = builder.object;
103
+ const geometry = object.geometry;
91
104
 
92
- let vertex = positionLocal;
105
+ builder.addStack();
93
106
 
94
- if ( this.positionNode !== null ) {
107
+ if ( geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color ) {
95
108
 
96
- vertex = vertex.bypass( positionLocal.assign( this.positionNode ) );
109
+ builder.stack.add( morph( object ) );
110
+
111
+ }
112
+
113
+ if ( object.isSkinnedMesh === true ) {
114
+
115
+ builder.stack.add( skinning( object ) );
97
116
 
98
117
  }
99
118
 
100
119
  if ( ( object.instanceMatrix && object.instanceMatrix.isInstancedBufferAttribute === true ) && builder.isAvailable( 'instance' ) === true ) {
101
120
 
102
- vertex = vertex.bypass( instance( object ) );
121
+ builder.stack.add( instance( object ) );
103
122
 
104
123
  }
105
124
 
106
- if ( object.isSkinnedMesh === true ) {
125
+ if ( this.positionNode !== null ) {
107
126
 
108
- vertex = vertex.bypass( skinning( object ) );
127
+ builder.stack.assign( positionLocal, this.positionNode );
109
128
 
110
129
  }
111
130
 
112
- builder.context.vertex = vertex;
131
+ builder.context.vertex = builder.removeStack();
113
132
 
114
133
  return modelViewProjection();
115
134
 
@@ -138,9 +157,9 @@ class NodeMaterial extends ShaderMaterial {
138
157
 
139
158
  // ALPHA TEST
140
159
 
141
- if ( this.alphaTestNode || this.alphaTest > 0 ) {
160
+ if ( this.alphaTestNode !== null || this.alphaTest > 0 ) {
142
161
 
143
- const alphaTestNode = this.alphaTestNode ? float( this.alphaTestNode ) : materialAlphaTest;
162
+ const alphaTestNode = this.alphaTestNode !== null ? float( this.alphaTestNode ) : materialAlphaTest;
144
163
 
145
164
  stack.add( diffuseColor.a.lessThanEqual( alphaTestNode ).discard() );
146
165
 
@@ -158,11 +177,21 @@ class NodeMaterial extends ShaderMaterial {
158
177
 
159
178
  // NORMAL VIEW
160
179
 
161
- const normalNode = this.normalNode ? vec3( this.normalNode ) : materialNormal;
180
+ if ( this.flatShading === true ) {
181
+
182
+ const fdx = dFdx( positionView );
183
+ const fdy = dFdy( positionView.negate() ); // use -positionView ?
184
+ const normalNode = fdx.cross( fdy ).normalize();
185
+
186
+ stack.assign( transformedNormalView, normalNode );
162
187
 
163
- stack.assign( transformedNormalView, normalNode );
188
+ } else {
189
+
190
+ const normalNode = this.normalNode ? vec3( this.normalNode ) : materialNormal;
164
191
 
165
- return normalNode;
192
+ stack.assign( transformedNormalView, normalNode );
193
+
194
+ }
166
195
 
167
196
  }
168
197
 
@@ -236,12 +265,13 @@ class NodeMaterial extends ShaderMaterial {
236
265
  const lights = this.lights === true || this.lightsNode !== null;
237
266
 
238
267
  const lightsNode = lights ? this.constructLights( builder ) : null;
239
- const lightingModelNode = lightsNode ? this.constructLightingModel( builder ) : null;
240
268
 
241
269
  let outgoingLightNode = diffuseColor.rgb;
242
270
 
243
271
  if ( lightsNode && lightsNode.hasLight !== false ) {
244
272
 
273
+ const lightingModelNode = this.constructLightingModel( builder );
274
+
245
275
  outgoingLightNode = lightsNode.lightingContext( lightingModelNode, backdropNode, backdropAlphaNode );
246
276
 
247
277
  } else if ( backdropNode !== null ) {
@@ -262,7 +292,7 @@ class NodeMaterial extends ShaderMaterial {
262
292
 
263
293
  }
264
294
 
265
- constructOutput( builder, outgoingLight, opacity ) {
295
+ constructOutput( builder, outputNode ) {
266
296
 
267
297
  const renderer = builder.renderer;
268
298
 
@@ -272,14 +302,10 @@ class NodeMaterial extends ShaderMaterial {
272
302
 
273
303
  if ( toneMappingNode ) {
274
304
 
275
- outgoingLight = toneMappingNode.context( { color: outgoingLight } );
305
+ outputNode = vec4( toneMappingNode.context( { color: outputNode.rgb } ), outputNode.a );
276
306
 
277
307
  }
278
308
 
279
- // @TODO: Optimize outputNode to vec3.
280
-
281
- let outputNode = vec4( outgoingLight, opacity );
282
-
283
309
  // ENCODING
284
310
 
285
311
  const renderTarget = renderer.getRenderTarget();
@@ -296,7 +322,7 @@ class NodeMaterial extends ShaderMaterial {
296
322
 
297
323
  }
298
324
 
299
- if ( outputColorSpace !== NoColorSpace ) outputNode = outputNode.colorSpace( outputColorSpace );
325
+ if ( outputColorSpace !== NoColorSpace ) outputNode = outputNode.linearToColorSpace( outputColorSpace );
300
326
 
301
327
  // FOG
302
328
 
@@ -403,6 +429,31 @@ class NodeMaterial extends ShaderMaterial {
403
429
 
404
430
  }
405
431
 
432
+ get isUnlit() {
433
+
434
+ return this.constructor === NodeMaterial.prototype.constructor;
435
+
436
+ }
437
+
438
+ copy( source ) {
439
+
440
+ this.lightsNode = source.lightsNode;
441
+ this.envNode = source.envNode;
442
+
443
+ this.colorNode = source.colorNode;
444
+ this.normalNode = source.normalNode;
445
+ this.opacityNode = source.opacityNode;
446
+ this.backdropNode = source.backdropNode;
447
+ this.backdropAlphaNode = source.backdropAlphaNode;
448
+ this.alphaTestNode = source.alphaTestNode;
449
+
450
+ this.positionNode = source.positionNode;
451
+ this.outputNode = source.outputNode;
452
+
453
+ return super.copy( source );
454
+
455
+ }
456
+
406
457
  static fromMaterial( material ) {
407
458
 
408
459
  if ( material.isNodeMaterial === true ) { // is already a node material
@@ -36,17 +36,8 @@ class PointsNodeMaterial extends NodeMaterial {
36
36
 
37
37
  copy( source ) {
38
38
 
39
- this.colorNode = source.colorNode;
40
- this.opacityNode = source.opacityNode;
41
-
42
- this.alphaTestNode = source.alphaTestNode;
43
-
44
- this.lightNode = source.lightNode;
45
-
46
39
  this.sizeNode = source.sizeNode;
47
40
 
48
- this.positionNode = source.positionNode;
49
-
50
41
  return super.copy( source );
51
42
 
52
43
  }
@@ -88,13 +88,6 @@ class SpriteNodeMaterial extends NodeMaterial {
88
88
 
89
89
  copy( source ) {
90
90
 
91
- this.colorNode = source.colorNode;
92
- this.opacityNode = source.opacityNode;
93
-
94
- this.alphaTestNode = source.alphaTestNode;
95
-
96
- this.lightNode = source.lightNode;
97
-
98
91
  this.positionNode = source.positionNode;
99
92
  this.rotationNode = source.rotationNode;
100
93
  this.scaleNode = source.scaleNode;
@@ -1,9 +1,9 @@
1
- import { fn } from '../../code/FunctionNode.js';
1
+ import { glslFn } from '../../code/FunctionNode.js';
2
2
 
3
3
  // Original shader code from:
4
4
  // https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/libraries/stdlib/genglsl/lib/mx_hsv.glsl
5
5
 
6
- export const mx_hsvtorgb = fn( `vec3 mx_hsvtorgb(vec3 hsv)
6
+ export const mx_hsvtorgb = glslFn( `vec3 mx_hsvtorgb(vec3 hsv)
7
7
  {
8
8
  // Reference for this technique: Foley & van Dam
9
9
  float h = hsv.x; float s = hsv.y; float v = hsv.z;
@@ -30,7 +30,7 @@ export const mx_hsvtorgb = fn( `vec3 mx_hsvtorgb(vec3 hsv)
30
30
  }
31
31
  }` );
32
32
 
33
- export const mx_rgbtohsv = fn( `vec3 mx_rgbtohsv(vec3 c)
33
+ export const mx_rgbtohsv = glslFn( `vec3 mx_rgbtohsv(vec3 c)
34
34
  {
35
35
  // See Foley & van Dam
36
36
  float r = c.x; float g = c.y; float b = c.z;
@@ -1,10 +1,10 @@
1
- import { code } from '../../code/CodeNode.js';
2
- import { fn } from '../../code/FunctionNode.js';
1
+ import { glsl } from '../../code/CodeNode.js';
2
+ import { glslFn } from '../../code/FunctionNode.js';
3
3
 
4
4
  // Original shader code from:
5
5
  // https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/libraries/stdlib/genglsl/lib/mx_noise.glsl
6
6
 
7
- export const mx_noise = code( `float mx_select(bool b, float t, float f)
7
+ export const mx_noise = glsl( `float mx_select(bool b, float t, float f)
8
8
  {
9
9
  return b ? t : f;
10
10
  }
@@ -602,17 +602,17 @@ vec3 mx_worley_noise_vec3(vec3 p, float jitter, int metric)
602
602
 
603
603
  const includes = [ mx_noise ];
604
604
 
605
- export const mx_perlin_noise_float = fn( 'float mx_perlin_noise_float( any p )', includes );
606
- export const mx_perlin_noise_vec2 = fn( 'vec2 mx_perlin_noise_vec2( any p )', includes );
607
- export const mx_perlin_noise_vec3 = fn( 'vec3 mx_perlin_noise_vec3( any p )', includes );
605
+ export const mx_perlin_noise_float = glslFn( 'float mx_perlin_noise_float( any p )', includes );
606
+ export const mx_perlin_noise_vec2 = glslFn( 'vec2 mx_perlin_noise_vec2( any p )', includes );
607
+ export const mx_perlin_noise_vec3 = glslFn( 'vec3 mx_perlin_noise_vec3( any p )', includes );
608
608
 
609
- export const mx_cell_noise_float = fn( 'float mx_cell_noise_float( vec3 p )', includes );
609
+ export const mx_cell_noise_float = glslFn( 'float mx_cell_noise_float( vec3 p )', includes );
610
610
 
611
- export const mx_worley_noise_float = fn( 'float mx_worley_noise_float( any p, float jitter, int metric )', includes );
612
- export const mx_worley_noise_vec2 = fn( 'float mx_worley_noise_vec2( any p, float jitter, int metric )', includes );
613
- export const mx_worley_noise_vec3 = fn( 'float mx_worley_noise_vec3( any p, float jitter, int metric )', includes );
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 );
614
614
 
615
- export const mx_fractal_noise_float = fn( 'float mx_fractal_noise_float( vec3 p, int octaves, float lacunarity, float diminish )', includes );
616
- export const mx_fractal_noise_vec2 = fn( 'float mx_fractal_noise_vec2( vec3 p, int octaves, float lacunarity, float diminish )', includes );
617
- export const mx_fractal_noise_vec3 = fn( 'float mx_fractal_noise_vec3( vec3 p, int octaves, float lacunarity, float diminish )', includes );
618
- export const mx_fractal_noise_vec4 = fn( 'float mx_fractal_noise_vec4( vec3 p, int octaves, float lacunarity, float diminish )', includes );
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 );
@@ -1,10 +1,10 @@
1
- import { code } from '../../code/CodeNode.js';
2
- import { fn } from '../../code/FunctionNode.js';
1
+ import { glsl } from '../../code/CodeNode.js';
2
+ import { glslFn } from '../../code/FunctionNode.js';
3
3
 
4
4
  // Original shader code from:
5
5
  // https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/libraries/stdlib/genglsl/lib/mx_transform_color.glsl
6
6
 
7
- export const mx_transform_color = code( `#define M_AP1_TO_REC709 mat3(1.705079555511475, -0.1297005265951157, -0.02416634373366833, -0.6242334842681885, 1.138468623161316, -0.1246141716837883, -0.0808461606502533, -0.008768022060394287, 1.148780584335327)
7
+ export const mx_transform_color = glsl( `#define M_AP1_TO_REC709 mat3(1.705079555511475, -0.1297005265951157, -0.02416634373366833, -0.6242334842681885, 1.138468623161316, -0.1246141716837883, -0.0808461606502533, -0.008768022060394287, 1.148780584335327)
8
8
 
9
9
  vec3 mx_srgb_texture_to_lin_rec709(vec3 color)
10
10
  {
@@ -16,4 +16,4 @@ vec3 mx_srgb_texture_to_lin_rec709(vec3 color)
16
16
 
17
17
  const includes = [ mx_transform_color ];
18
18
 
19
- export const mx_srgb_texture_to_lin_rec709 = fn( 'vec3 mx_srgb_texture_to_lin_rec709( vec3 color )', includes );
19
+ export const mx_srgb_texture_to_lin_rec709 = glslFn( 'vec3 mx_srgb_texture_to_lin_rec709( vec3 color )', includes );
@@ -218,6 +218,8 @@ MathNode.DFDX = 'dFdx';
218
218
  MathNode.DFDY = 'dFdy';
219
219
  MathNode.ROUND = 'round';
220
220
  MathNode.RECIPROCAL = 'reciprocal';
221
+ MathNode.TRUNC = 'trunc';
222
+ MathNode.FWIDTH = 'fwidth';
221
223
 
222
224
  // 2 inputs
223
225
 
@@ -274,6 +276,8 @@ export const dFdx = nodeProxy( MathNode, MathNode.DFDX );
274
276
  export const dFdy = nodeProxy( MathNode, MathNode.DFDY );
275
277
  export const round = nodeProxy( MathNode, MathNode.ROUND );
276
278
  export const reciprocal = nodeProxy( MathNode, MathNode.RECIPROCAL );
279
+ export const trunc = nodeProxy( MathNode, MathNode.TRUNC );
280
+ export const fwidth = nodeProxy( MathNode, MathNode.FWIDTH );
277
281
 
278
282
  export const atan2 = nodeProxy( MathNode, MathNode.ATAN2 );
279
283
  export const min = nodeProxy( MathNode, MathNode.MIN );
@@ -328,6 +332,8 @@ addNodeElement( 'dFdx', dFdx );
328
332
  addNodeElement( 'dFdy', dFdy );
329
333
  addNodeElement( 'round', round );
330
334
  addNodeElement( 'reciprocal', reciprocal );
335
+ addNodeElement( 'trunc', trunc );
336
+ addNodeElement( 'fwidth', fwidth );
331
337
  addNodeElement( 'atan2', atan2 );
332
338
  addNodeElement( 'min', min );
333
339
  addNodeElement( 'max', max );
@@ -120,7 +120,7 @@ class OperatorNode extends TempNode {
120
120
 
121
121
  typeB = typeA;
122
122
 
123
- } else if ( op === '<' || op === '>' || op === '<=' || op === '>=' ) {
123
+ } else if ( op === '<' || op === '>' || op === '<=' || op === '>=' || op === '==' ) {
124
124
 
125
125
  if ( builder.isVector( typeA ) ) {
126
126
 
@@ -1,9 +1,9 @@
1
1
  import TempNode from '../core/TempNode.js';
2
2
  import { uv } from '../accessors/UVNode.js';
3
3
  import { addNodeClass } from '../core/Node.js';
4
- import { addNodeElement, ShaderNode, nodeProxy } from '../shadernode/ShaderNode.js';
4
+ import { addNodeElement, tslFn, nodeProxy } from '../shadernode/ShaderNode.js';
5
5
 
6
- const checkerShaderNode = new ShaderNode( ( inputs ) => {
6
+ const checkerShaderNode = tslFn( ( inputs ) => {
7
7
 
8
8
  const uv = inputs.uv.mul( 2.0 );
9
9
 
@@ -27,7 +27,7 @@ class CheckerNode extends TempNode {
27
27
 
28
28
  generate( builder ) {
29
29
 
30
- return checkerShaderNode.call( { uv: this.uvNode } ).build( builder );
30
+ return checkerShaderNode( { uv: this.uvNode } ).build( builder );
31
31
 
32
32
  }
33
33
 
@@ -103,7 +103,7 @@ const ShaderNodeObject = function ( obj, altType = null ) {
103
103
 
104
104
  } else if ( type === 'shader' ) {
105
105
 
106
- return shader( obj );
106
+ return tslFn( obj );
107
107
 
108
108
  }
109
109
 
@@ -317,10 +317,30 @@ export function ShaderNode( jsFunc ) {
317
317
  export const nodeObject = ( val, altType = null ) => /* new */ ShaderNodeObject( val, altType );
318
318
  export const nodeObjects = ( val, altType = null ) => new ShaderNodeObjects( val, altType );
319
319
  export const nodeArray = ( val, altType = null ) => new ShaderNodeArray( val, altType );
320
- export const nodeProxy = ( ...val ) => new ShaderNodeProxy( ...val );
321
- export const nodeImmutable = ( ...val ) => new ShaderNodeImmutable( ...val );
320
+ export const nodeProxy = ( ...params ) => new ShaderNodeProxy( ...params );
321
+ export const nodeImmutable = ( ...params ) => new ShaderNodeImmutable( ...params );
322
322
 
323
- export const shader = ( ...val ) => new ShaderNode( ...val );
323
+ export const shader = ( jsFunc ) => { // @deprecated, r154
324
+
325
+ console.warn( 'TSL: shader() is deprecated. Use fn() instead.' );
326
+
327
+ return new ShaderNode( jsFunc );
328
+
329
+ };
330
+
331
+ export const tslFn = ( jsFunc ) => {
332
+
333
+ let shaderNode = null;
334
+
335
+ return ( ...params ) => {
336
+
337
+ if ( shaderNode === null ) shaderNode = new ShaderNode( jsFunc );
338
+
339
+ return shaderNode.call( ...params );
340
+
341
+ };
342
+
343
+ };
324
344
 
325
345
  addNodeClass( ShaderNode );
326
346
 
@@ -38,7 +38,7 @@ class LoopNode extends Node {
38
38
 
39
39
  }
40
40
 
41
- properties.returnsNode = this.params[ this.params.length - 1 ].call( inputs, builder.addStack(), builder );
41
+ properties.returnsNode = this.params[ this.params.length - 1 ]( inputs, builder.addStack(), builder );
42
42
  properties.stackNode = builder.removeStack();
43
43
 
44
44
  return properties;
@@ -55,7 +55,7 @@ class TriplanarTexturesNode extends Node {
55
55
  export default TriplanarTexturesNode;
56
56
 
57
57
  export const triplanarTextures = nodeProxy( TriplanarTexturesNode );
58
- export const triplanarTexture = ( texture, ...params ) => triplanarTextures( texture, texture, texture, ...params );
58
+ export const triplanarTexture = ( ...params ) => triplanarTextures( ...params );
59
59
 
60
60
  addNodeElement( 'triplanarTexture', triplanarTexture );
61
61
 
@@ -120,7 +120,7 @@ class GroundProjectedSkybox extends Mesh {
120
120
  gl_FragColor = vec4( outcolor, 1.0 );
121
121
 
122
122
  #include <tonemapping_fragment>
123
- #include <encodings_fragment>
123
+ #include <colorspace_fragment>
124
124
 
125
125
  }
126
126
  `;
@@ -264,7 +264,7 @@ Reflector.ReflectorShader = {
264
264
  gl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );
265
265
 
266
266
  #include <tonemapping_fragment>
267
- #include <encodings_fragment>
267
+ #include <colorspace_fragment>
268
268
 
269
269
  }`
270
270
  };
@@ -323,7 +323,7 @@ Refractor.RefractorShader = {
323
323
  gl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );
324
324
 
325
325
  #include <tonemapping_fragment>
326
- #include <encodings_fragment>
326
+ #include <colorspace_fragment>
327
327
 
328
328
  }`
329
329
 
@@ -210,7 +210,7 @@ Sky.SkyShader = {
210
210
  gl_FragColor = vec4( retColor, 1.0 );
211
211
 
212
212
  #include <tonemapping_fragment>
213
- #include <encodings_fragment>
213
+ #include <colorspace_fragment>
214
214
 
215
215
  }`
216
216
 
@@ -181,7 +181,7 @@ class Water extends Mesh {
181
181
  gl_FragColor = vec4( outgoingLight, alpha );
182
182
 
183
183
  #include <tonemapping_fragment>
184
- #include <encodings_fragment>
184
+ #include <colorspace_fragment>
185
185
  #include <fog_fragment>
186
186
  }`
187
187
 
@@ -348,7 +348,7 @@ Water.WaterShader = {
348
348
  gl_FragColor = vec4( color, 1.0 ) * mix( refractColor, reflectColor, reflectance );
349
349
 
350
350
  #include <tonemapping_fragment>
351
- #include <encodings_fragment>
351
+ #include <colorspace_fragment>
352
352
  #include <fog_fragment>
353
353
 
354
354
  }`
@@ -45,6 +45,7 @@ function init( canvas, width, height, pixelRatio, path ) {
45
45
  renderer = new THREE.WebGLRenderer( { antialias: true, canvas: canvas } );
46
46
  renderer.setPixelRatio( pixelRatio );
47
47
  renderer.setSize( width, height, false );
48
+ renderer.useLegacyLights = false;
48
49
 
49
50
  animate();
50
51
 
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  Clock,
3
3
  HalfFloatType,
4
+ NoBlending,
4
5
  Vector2,
5
6
  WebGLRenderTarget
6
7
  } from 'three';
@@ -45,6 +46,7 @@ class EffectComposer {
45
46
  this.passes = [];
46
47
 
47
48
  this.copyPass = new ShaderPass( CopyShader );
49
+ this.copyPass.material.blending = NoBlending;
48
50
 
49
51
  this.clock = new Clock();
50
52
 
@@ -96,7 +96,6 @@ class OutlinePass extends Pass {
96
96
  const copyShader = CopyShader;
97
97
 
98
98
  this.copyUniforms = UniformsUtils.clone( copyShader.uniforms );
99
- this.copyUniforms[ 'opacity' ].value = 1.0;
100
99
 
101
100
  this.materialCopy = new ShaderMaterial( {
102
101
  uniforms: this.copyUniforms,
@@ -104,8 +103,7 @@ class OutlinePass extends Pass {
104
103
  fragmentShader: copyShader.fragmentShader,
105
104
  blending: NoBlending,
106
105
  depthTest: false,
107
- depthWrite: false,
108
- transparent: true
106
+ depthWrite: false
109
107
  } );
110
108
 
111
109
  this.enabled = true;
@@ -1,8 +1,5 @@
1
1
  import {
2
- CustomBlending,
3
- OneFactor,
4
- AddEquation,
5
- SrcAlphaFactor,
2
+ AdditiveBlending,
6
3
  Color,
7
4
  HalfFloatType,
8
5
  ShaderMaterial,
@@ -49,14 +46,8 @@ class SSAARenderPass extends Pass {
49
46
  transparent: true,
50
47
  depthTest: false,
51
48
  depthWrite: false,
52
-
53
- // do not use AdditiveBlending because it mixes the alpha channel instead of adding
54
- blending: CustomBlending,
55
- blendEquation: AddEquation,
56
- blendDst: OneFactor,
57
- blendDstAlpha: OneFactor,
58
- blendSrc: SrcAlphaFactor,
59
- blendSrcAlpha: OneFactor
49
+ premultipliedAlpha: true,
50
+ blending: AdditiveBlending
60
51
  } );
61
52
 
62
53
  this.fsQuad = new FullScreenQuad( this.copyMaterial );
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  HalfFloatType,
3
+ NoBlending,
3
4
  ShaderMaterial,
4
5
  UniformsUtils,
5
6
  WebGLRenderTarget
@@ -23,7 +24,8 @@ class SavePass extends Pass {
23
24
 
24
25
  uniforms: this.uniforms,
25
26
  vertexShader: shader.vertexShader,
26
- fragmentShader: shader.fragmentShader
27
+ fragmentShader: shader.fragmentShader,
28
+ blending: NoBlending
27
29
 
28
30
  } );
29
31