@plastic-software/three 0.178.0 → 0.180.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 (245) hide show
  1. package/README.md +1 -1
  2. package/build/three.cjs +950 -230
  3. package/build/three.core.js +754 -138
  4. package/build/three.core.min.js +1 -1
  5. package/build/three.module.js +197 -96
  6. package/build/three.module.min.js +1 -1
  7. package/build/three.tsl.js +99 -25
  8. package/build/three.tsl.min.js +1 -1
  9. package/build/three.webgpu.js +4586 -1499
  10. package/build/three.webgpu.min.js +1 -1
  11. package/build/three.webgpu.nodes.js +4544 -1499
  12. package/build/three.webgpu.nodes.min.js +1 -1
  13. package/examples/jsm/Addons.js +2 -3
  14. package/examples/jsm/capabilities/WebGPU.js +1 -1
  15. package/examples/jsm/controls/ArcballControls.js +7 -7
  16. package/examples/jsm/controls/DragControls.js +6 -56
  17. package/examples/jsm/controls/FirstPersonControls.js +2 -2
  18. package/examples/jsm/controls/PointerLockControls.js +0 -8
  19. package/examples/jsm/csm/CSMShadowNode.js +4 -4
  20. package/examples/jsm/environments/RoomEnvironment.js +8 -3
  21. package/examples/jsm/exporters/GLTFExporter.js +30 -22
  22. package/examples/jsm/exporters/KTX2Exporter.js +4 -2
  23. package/examples/jsm/exporters/PLYExporter.js +1 -1
  24. package/examples/jsm/exporters/USDZExporter.js +676 -299
  25. package/examples/jsm/geometries/RoundedBoxGeometry.js +47 -8
  26. package/examples/jsm/interactive/HTMLMesh.js +5 -3
  27. package/examples/jsm/libs/ktx-parse.module.js +1 -1
  28. package/examples/jsm/libs/meshopt_decoder.module.js +75 -58
  29. package/examples/jsm/lights/LightProbeGenerator.js +14 -3
  30. package/examples/jsm/lines/Line2.js +3 -3
  31. package/examples/jsm/lines/LineGeometry.js +1 -1
  32. package/examples/jsm/lines/LineSegments2.js +2 -2
  33. package/examples/jsm/lines/Wireframe.js +2 -2
  34. package/examples/jsm/lines/WireframeGeometry2.js +1 -1
  35. package/examples/jsm/lines/webgpu/LineSegments2.js +1 -1
  36. package/examples/jsm/lines/webgpu/Wireframe.js +1 -1
  37. package/examples/jsm/loaders/ColladaLoader.js +1 -1
  38. package/examples/jsm/loaders/EXRLoader.js +210 -22
  39. package/examples/jsm/loaders/FBXLoader.js +1 -1
  40. package/examples/jsm/loaders/GLTFLoader.js +9 -5
  41. package/examples/jsm/loaders/HDRCubeTextureLoader.js +5 -5
  42. package/examples/jsm/loaders/HDRLoader.js +486 -0
  43. package/examples/jsm/loaders/KTX2Loader.js +112 -32
  44. package/examples/jsm/loaders/MaterialXLoader.js +212 -30
  45. package/examples/jsm/loaders/RGBELoader.js +7 -473
  46. package/examples/jsm/loaders/TTFLoader.js +13 -1
  47. package/examples/jsm/loaders/USDLoader.js +219 -0
  48. package/examples/jsm/loaders/USDZLoader.js +4 -892
  49. package/examples/jsm/loaders/UltraHDRLoader.js +1 -1
  50. package/examples/jsm/loaders/lwo/IFFParser.js +1 -1
  51. package/examples/jsm/loaders/usd/USDAParser.js +741 -0
  52. package/examples/jsm/loaders/usd/USDCParser.js +17 -0
  53. package/examples/jsm/materials/WoodNodeMaterial.js +533 -0
  54. package/examples/jsm/math/ColorSpaces.js +19 -1
  55. package/examples/jsm/math/ConvexHull.js +2 -2
  56. package/examples/jsm/math/Lut.js +2 -2
  57. package/examples/jsm/misc/MD2CharacterComplex.js +1 -1
  58. package/examples/jsm/misc/ProgressiveLightMap.js +1 -1
  59. package/examples/jsm/misc/Volume.js +1 -1
  60. package/examples/jsm/objects/LensflareMesh.js +3 -3
  61. package/examples/jsm/objects/SkyMesh.js +2 -2
  62. package/examples/jsm/physics/RapierPhysics.js +14 -5
  63. package/examples/jsm/postprocessing/GTAOPass.js +10 -9
  64. package/examples/jsm/postprocessing/OutlinePass.js +17 -17
  65. package/examples/jsm/postprocessing/SSAOPass.js +10 -9
  66. package/examples/jsm/postprocessing/SSRPass.js +37 -8
  67. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +11 -2
  68. package/examples/jsm/transpiler/GLSLDecoder.js +23 -20
  69. package/examples/jsm/transpiler/TSLEncoder.js +2 -10
  70. package/examples/jsm/transpiler/WGSLEncoder.js +24 -0
  71. package/examples/jsm/tsl/display/AnamorphicNode.js +27 -4
  72. package/examples/jsm/tsl/display/BloomNode.js +7 -6
  73. package/examples/jsm/tsl/display/ChromaticAberrationNode.js +2 -1
  74. package/examples/jsm/tsl/display/DepthOfFieldNode.js +439 -90
  75. package/examples/jsm/tsl/display/GTAONode.js +8 -0
  76. package/examples/jsm/tsl/display/GaussianBlurNode.js +51 -41
  77. package/examples/jsm/tsl/display/OutlineNode.js +2 -2
  78. package/examples/jsm/tsl/display/SSRNode.js +180 -65
  79. package/examples/jsm/tsl/display/{TRAAPassNode.js → TRAANode.js} +181 -172
  80. package/examples/jsm/tsl/display/boxBlur.js +64 -0
  81. package/examples/jsm/tsl/display/hashBlur.js +15 -18
  82. package/examples/jsm/tsl/lighting/TiledLightsNode.js +1 -1
  83. package/examples/jsm/utils/BufferGeometryUtils.js +1 -1
  84. package/examples/jsm/utils/ShadowMapViewerGPU.js +12 -5
  85. package/examples/jsm/webxr/OculusHandModel.js +1 -1
  86. package/package.json +1 -1
  87. package/src/Three.Core.js +2 -0
  88. package/src/Three.TSL.js +98 -24
  89. package/src/animation/AnimationClip.js +17 -2
  90. package/src/animation/KeyframeTrack.js +1 -1
  91. package/src/animation/tracks/BooleanKeyframeTrack.js +1 -1
  92. package/src/animation/tracks/StringKeyframeTrack.js +1 -1
  93. package/src/cameras/Camera.js +14 -0
  94. package/src/cameras/OrthographicCamera.js +1 -1
  95. package/src/cameras/PerspectiveCamera.js +1 -1
  96. package/src/constants.js +11 -3
  97. package/src/core/BufferGeometry.js +2 -2
  98. package/{examples/jsm/misc → src/core}/Timer.js +4 -42
  99. package/src/extras/PMREMGenerator.js +11 -0
  100. package/src/extras/TextureUtils.js +2 -1
  101. package/src/extras/lib/earcut.js +1 -1
  102. package/src/helpers/CameraHelper.js +41 -11
  103. package/src/helpers/SkeletonHelper.js +35 -6
  104. package/src/lights/LightShadow.js +21 -8
  105. package/src/lights/PointLightShadow.js +1 -1
  106. package/src/lights/webgpu/ProjectorLight.js +1 -1
  107. package/src/loaders/FileLoader.js +25 -2
  108. package/src/loaders/ImageBitmapLoader.js +23 -0
  109. package/src/loaders/Loader.js +14 -0
  110. package/src/loaders/LoadingManager.js +23 -0
  111. package/src/materials/Material.js +12 -0
  112. package/src/materials/MeshBasicMaterial.js +1 -1
  113. package/src/materials/MeshDistanceMaterial.js +1 -1
  114. package/src/materials/nodes/Line2NodeMaterial.js +0 -8
  115. package/src/materials/nodes/NodeMaterial.js +1 -1
  116. package/src/materials/nodes/PointsNodeMaterial.js +86 -28
  117. package/src/materials/nodes/SpriteNodeMaterial.js +3 -15
  118. package/src/materials/nodes/manager/NodeMaterialObserver.js +87 -2
  119. package/src/math/ColorManagement.js +7 -1
  120. package/src/math/Frustum.js +19 -8
  121. package/src/math/FrustumArray.js +10 -5
  122. package/src/math/Line3.js +129 -2
  123. package/src/math/Matrix4.js +48 -27
  124. package/src/math/Spherical.js +2 -2
  125. package/src/nodes/Nodes.js +4 -0
  126. package/src/nodes/TSL.js +4 -0
  127. package/src/nodes/accessors/BufferNode.js +1 -1
  128. package/src/nodes/accessors/Camera.js +142 -16
  129. package/src/nodes/accessors/ClippingNode.js +6 -5
  130. package/src/nodes/accessors/CubeTextureNode.js +2 -2
  131. package/src/nodes/accessors/InstanceNode.js +3 -1
  132. package/src/nodes/accessors/Normal.js +11 -11
  133. package/src/nodes/accessors/Object3DNode.js +1 -1
  134. package/src/nodes/accessors/ReferenceBaseNode.js +1 -1
  135. package/src/nodes/accessors/ReferenceNode.js +19 -4
  136. package/src/nodes/accessors/SceneNode.js +1 -1
  137. package/src/nodes/accessors/StorageTextureNode.js +1 -1
  138. package/src/nodes/accessors/Texture3DNode.js +13 -0
  139. package/src/nodes/accessors/TextureNode.js +83 -19
  140. package/src/nodes/code/FunctionCallNode.js +19 -0
  141. package/src/nodes/code/FunctionNode.js +23 -0
  142. package/src/nodes/core/ArrayNode.js +12 -0
  143. package/src/nodes/core/AssignNode.js +6 -2
  144. package/src/nodes/core/ContextNode.js +44 -1
  145. package/src/nodes/core/Node.js +30 -22
  146. package/src/nodes/core/NodeBuilder.js +71 -32
  147. package/src/nodes/core/NodeFrame.js +1 -1
  148. package/src/nodes/core/NodeUniform.js +1 -1
  149. package/src/nodes/core/NodeUtils.js +5 -3
  150. package/src/nodes/core/StackNode.js +71 -4
  151. package/src/nodes/core/StructNode.js +5 -5
  152. package/src/nodes/core/StructTypeNode.js +1 -0
  153. package/src/nodes/core/SubBuildNode.js +2 -2
  154. package/src/nodes/core/UniformNode.js +79 -14
  155. package/src/nodes/core/VarNode.js +83 -15
  156. package/src/nodes/display/FrontFacingNode.js +4 -8
  157. package/src/nodes/display/PassNode.js +148 -2
  158. package/src/nodes/display/ScreenNode.js +42 -13
  159. package/src/nodes/display/ViewportDepthTextureNode.js +16 -4
  160. package/src/nodes/display/ViewportSharedTextureNode.js +12 -0
  161. package/src/nodes/display/ViewportTextureNode.js +94 -4
  162. package/src/nodes/functions/PhysicalLightingModel.js +2 -2
  163. package/src/nodes/gpgpu/AtomicFunctionNode.js +1 -1
  164. package/src/nodes/gpgpu/ComputeNode.js +67 -23
  165. package/src/nodes/gpgpu/SubgroupFunctionNode.js +430 -0
  166. package/src/nodes/gpgpu/WorkgroupInfoNode.js +28 -3
  167. package/src/nodes/lighting/LightsNode.js +1 -1
  168. package/src/nodes/lighting/ProjectorLightNode.js +19 -6
  169. package/src/nodes/lighting/ShadowFilterNode.js +1 -1
  170. package/src/nodes/materialx/MaterialXNodes.js +131 -2
  171. package/src/nodes/materialx/lib/mx_noise.js +165 -1
  172. package/src/nodes/math/BitcastNode.js +156 -0
  173. package/src/nodes/math/ConditionalNode.js +19 -3
  174. package/src/nodes/math/MathNode.js +72 -60
  175. package/src/nodes/math/OperatorNode.js +26 -25
  176. package/src/nodes/tsl/TSLCore.js +477 -142
  177. package/src/nodes/utils/DebugNode.js +1 -1
  178. package/src/nodes/utils/EventNode.js +83 -0
  179. package/src/nodes/utils/JoinNode.js +3 -1
  180. package/src/nodes/utils/MemberNode.js +58 -7
  181. package/src/nodes/utils/RTTNode.js +10 -1
  182. package/src/nodes/utils/ReflectorNode.js +51 -7
  183. package/src/nodes/utils/SampleNode.js +12 -2
  184. package/src/nodes/utils/SplitNode.js +11 -0
  185. package/src/nodes/utils/Timer.js +0 -47
  186. package/src/objects/BatchedMesh.js +6 -4
  187. package/src/objects/LOD.js +1 -1
  188. package/src/objects/Sprite.js +2 -2
  189. package/src/renderers/WebGLRenderer.js +21 -31
  190. package/src/renderers/common/Attributes.js +1 -1
  191. package/src/renderers/common/Backend.js +19 -1
  192. package/src/renderers/common/Bindings.js +21 -18
  193. package/src/renderers/common/ChainMap.js +1 -1
  194. package/src/renderers/common/Color4.js +2 -2
  195. package/src/renderers/common/DataMap.js +1 -1
  196. package/src/renderers/common/Pipelines.js +1 -1
  197. package/src/renderers/common/PostProcessing.js +60 -5
  198. package/src/renderers/common/RenderContext.js +2 -2
  199. package/src/renderers/common/RenderObject.js +14 -2
  200. package/src/renderers/common/Renderer.js +55 -32
  201. package/src/renderers/common/SampledTexture.js +4 -72
  202. package/src/renderers/common/Sampler.js +91 -0
  203. package/src/renderers/common/Storage3DTexture.js +21 -0
  204. package/src/renderers/common/StorageArrayTexture.js +21 -0
  205. package/src/renderers/common/StorageTexture.js +19 -0
  206. package/src/renderers/common/Textures.js +52 -14
  207. package/src/renderers/common/TimestampQueryPool.js +3 -3
  208. package/src/renderers/common/XRManager.js +51 -17
  209. package/src/renderers/common/nodes/NodeBuilderState.js +1 -1
  210. package/src/renderers/common/nodes/NodeLibrary.js +5 -5
  211. package/src/renderers/common/nodes/NodeSampledTexture.js +0 -12
  212. package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +1 -1
  213. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +1 -1
  214. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +1 -1
  215. package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +1 -1
  216. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +21 -11
  217. package/src/renderers/shaders/ShaderLib/depth.glsl.js +11 -2
  218. package/src/renderers/webgl/WebGLCapabilities.js +2 -2
  219. package/src/renderers/webgl/WebGLMaterials.js +6 -6
  220. package/src/renderers/webgl/WebGLProgram.js +24 -18
  221. package/src/renderers/webgl/WebGLPrograms.js +4 -4
  222. package/src/renderers/webgl/WebGLShadowMap.js +11 -1
  223. package/src/renderers/webgl/WebGLTextures.js +20 -7
  224. package/src/renderers/webgl/WebGLUtils.js +3 -2
  225. package/src/renderers/webgl-fallback/WebGLBackend.js +207 -146
  226. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +112 -19
  227. package/src/renderers/webgl-fallback/utils/WebGLState.js +1 -1
  228. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +52 -3
  229. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +9 -10
  230. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +3 -2
  231. package/src/renderers/webgpu/WebGPUBackend.js +87 -44
  232. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +169 -99
  233. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +35 -31
  234. package/src/renderers/webgpu/utils/WebGPUConstants.js +2 -2
  235. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +10 -19
  236. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +120 -84
  237. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +3 -3
  238. package/src/renderers/webgpu/utils/WebGPUUtils.js +2 -17
  239. package/src/renderers/webxr/WebXRDepthSensing.js +6 -10
  240. package/src/renderers/webxr/WebXRManager.js +86 -11
  241. package/src/textures/ExternalTexture.js +56 -0
  242. package/src/textures/FramebufferTexture.js +2 -2
  243. package/src/textures/Source.js +12 -2
  244. package/src/textures/VideoTexture.js +27 -2
  245. package/examples/jsm/loaders/RGBMLoader.js +0 -1148
@@ -1,8 +1,10 @@
1
1
  import SpotLightNode from './SpotLightNode.js';
2
2
 
3
- import { Fn, vec2 } from '../tsl/TSLCore.js';
3
+ import { float, Fn, If, vec2 } from '../tsl/TSLCore.js';
4
4
  import { length, min, max, saturate, acos } from '../math/MathNode.js';
5
5
  import { div, sub } from '../math/OperatorNode.js';
6
+ import { lightShadowMatrix } from '../accessors/Lights.js';
7
+ import { positionWorld } from '../accessors/Position.js';
6
8
 
7
9
  const sdBox = /*@__PURE__*/ Fn( ( [ p, b ] ) => {
8
10
 
@@ -61,13 +63,24 @@ class ProjectorLightNode extends SpotLightNode {
61
63
  */
62
64
  getSpotAttenuation( builder ) {
63
65
 
66
+ const attenuation = float( 0 );
64
67
  const penumbraCos = this.penumbraCosNode;
65
- const spotLightCoord = this.getLightCoord( builder );
66
- const coord = spotLightCoord.xyz.div( spotLightCoord.w );
67
68
 
68
- const boxDist = sdBox( coord.xy.sub( vec2( 0.5 ) ), vec2( 0.5 ) );
69
- const angleFactor = div( - 1.0, sub( 1.0, acos( penumbraCos ) ).sub( 1.0 ) );
70
- const attenuation = saturate( boxDist.mul( - 2.0 ).mul( angleFactor ) );
69
+ // compute the fragment's position in the light's clip space
70
+
71
+ const spotLightCoord = lightShadowMatrix( this.light ).mul( builder.context.positionWorld || positionWorld );
72
+
73
+ // the sign of w determines whether the current fragment is in front or behind the light.
74
+ // to avoid a back-projection, it's important to only compute an attenuation if w is positive
75
+
76
+ If( spotLightCoord.w.greaterThan( 0 ), () => {
77
+
78
+ const projectionUV = spotLightCoord.xyz.div( spotLightCoord.w );
79
+ const boxDist = sdBox( projectionUV.xy.sub( vec2( 0.5 ) ), vec2( 0.5 ) );
80
+ const angleFactor = div( - 1.0, sub( 1.0, acos( penumbraCos ) ).sub( 1.0 ) );
81
+ attenuation.assign( saturate( boxDist.mul( - 2.0 ).mul( angleFactor ) ) );
82
+
83
+ } );
71
84
 
72
85
  return attenuation;
73
86
 
@@ -22,7 +22,7 @@ const shadowMaterialLib = /*@__PURE__*/ new WeakMap();
22
22
  */
23
23
  export const BasicShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, shadowCoord, depthLayer } ) => {
24
24
 
25
- let basic = texture( depthTexture, shadowCoord.xy ).label( 't_basic' );
25
+ let basic = texture( depthTexture, shadowCoord.xy ).setName( 't_basic' );
26
26
 
27
27
  if ( depthTexture.isArrayTexture ) {
28
28
 
@@ -2,13 +2,17 @@ import {
2
2
  mx_perlin_noise_float, mx_perlin_noise_vec3,
3
3
  mx_worley_noise_float as worley_noise_float, mx_worley_noise_vec2 as worley_noise_vec2, mx_worley_noise_vec3 as worley_noise_vec3,
4
4
  mx_cell_noise_float as cell_noise_float,
5
+ mx_unifiednoise2d as unifiednoise2d, mx_unifiednoise3d as unifiednoise3d,
5
6
  mx_fractal_noise_float as fractal_noise_float, mx_fractal_noise_vec2 as fractal_noise_vec2, mx_fractal_noise_vec3 as fractal_noise_vec3, mx_fractal_noise_vec4 as fractal_noise_vec4
6
7
  } from './lib/mx_noise.js';
7
8
  import { mx_hsvtorgb, mx_rgbtohsv } from './lib/mx_hsv.js';
8
9
  import { mx_srgb_texture_to_lin_rec709 } from './lib/mx_transform_color.js';
9
- import { mix, smoothstep } from '../math/MathNode.js';
10
+
11
+ import { float, vec2, vec3, vec4, int, add, sub, mul, div, mod, atan, mix, pow, smoothstep } from '../tsl/TSLBase.js';
10
12
  import { uv } from '../accessors/UV.js';
11
- import { float, vec2, vec4, int } from '../tsl/TSLBase.js';
13
+ import { bumpMap } from '../display/BumpMapNode.js';
14
+ import { rotate } from '../utils/RotateNode.js';
15
+ import { frameId, time } from '../utils/Timer.js';
12
16
 
13
17
  export const mx_aastep = ( threshold, value ) => {
14
18
 
@@ -25,6 +29,19 @@ const _ramp = ( a, b, uv, p ) => mix( a, b, uv[ p ].clamp() );
25
29
  export const mx_ramplr = ( valuel, valuer, texcoord = uv() ) => _ramp( valuel, valuer, texcoord, 'x' );
26
30
  export const mx_ramptb = ( valuet, valueb, texcoord = uv() ) => _ramp( valuet, valueb, texcoord, 'y' );
27
31
 
32
+ // Bilinear ramp: interpolate between four corners (tl, tr, bl, br) using texcoord.x and texcoord.y
33
+ export const mx_ramp4 = (
34
+ valuetl, valuetr, valuebl, valuebr, texcoord = uv()
35
+ ) => {
36
+
37
+ const u = texcoord.x.clamp();
38
+ const v = texcoord.y.clamp();
39
+ const top = mix( valuetl, valuetr, u );
40
+ const bottom = mix( valuebl, valuebr, u );
41
+ return mix( top, bottom, v );
42
+
43
+ };
44
+
28
45
  const _split = ( a, b, center, uv, p ) => mix( a, b, mx_aastep( center, uv[ p ] ) );
29
46
  export const mx_splitlr = ( valuel, valuer, center, texcoord = uv() ) => _split( valuel, valuer, center, texcoord, 'x' );
30
47
  export const mx_splittb = ( valuet, valueb, center, texcoord = uv() ) => _split( valuet, valueb, center, texcoord, 'y' );
@@ -54,6 +71,9 @@ export const mx_noise_vec4 = ( texcoord = uv(), amplitude = 1, pivot = 0 ) => {
54
71
 
55
72
  };
56
73
 
74
+ export const mx_unifiednoise2d = ( noiseType, texcoord = uv(), freq = vec2( 1, 1 ), offset = vec2( 0, 0 ), jitter = 1, outmin = 0, outmax = 1, clampoutput = false, octaves = 1, lacunarity = 2, diminish = .5 ) => unifiednoise2d( noiseType, texcoord.convert( 'vec2|vec3' ), freq, offset, jitter, outmin, outmax, clampoutput, octaves, lacunarity, diminish );
75
+ export const mx_unifiednoise3d = ( noiseType, texcoord = uv(), freq = vec2( 1, 1 ), offset = vec2( 0, 0 ), jitter = 1, outmin = 0, outmax = 1, clampoutput = false, octaves = 1, lacunarity = 2, diminish = .5 ) => unifiednoise3d( noiseType, texcoord.convert( 'vec2|vec3' ), freq, offset, jitter, outmin, outmax, clampoutput, octaves, lacunarity, diminish );
76
+
57
77
  export const mx_worley_noise_float = ( texcoord = uv(), jitter = 1 ) => worley_noise_float( texcoord.convert( 'vec2|vec3' ), jitter, int( 1 ) );
58
78
  export const mx_worley_noise_vec2 = ( texcoord = uv(), jitter = 1 ) => worley_noise_vec2( texcoord.convert( 'vec2|vec3' ), jitter, int( 1 ) );
59
79
  export const mx_worley_noise_vec3 = ( texcoord = uv(), jitter = 1 ) => worley_noise_vec3( texcoord.convert( 'vec2|vec3' ), jitter, int( 1 ) );
@@ -66,3 +86,112 @@ export const mx_fractal_noise_vec3 = ( position = uv(), octaves = 3, lacunarity
66
86
  export const mx_fractal_noise_vec4 = ( position = uv(), octaves = 3, lacunarity = 2, diminish = .5, amplitude = 1 ) => fractal_noise_vec4( position, int( octaves ), lacunarity, diminish ).mul( amplitude );
67
87
 
68
88
  export { mx_hsvtorgb, mx_rgbtohsv, mx_srgb_texture_to_lin_rec709 };
89
+
90
+ // === Moved from MaterialXLoader.js ===
91
+
92
+ // Math ops
93
+ export const mx_add = ( in1, in2 = float( 0 ) ) => add( in1, in2 );
94
+ export const mx_subtract = ( in1, in2 = float( 0 ) ) => sub( in1, in2 );
95
+ export const mx_multiply = ( in1, in2 = float( 1 ) ) => mul( in1, in2 );
96
+ export const mx_divide = ( in1, in2 = float( 1 ) ) => div( in1, in2 );
97
+ export const mx_modulo = ( in1, in2 = float( 1 ) ) => mod( in1, in2 );
98
+ export const mx_power = ( in1, in2 = float( 1 ) ) => pow( in1, in2 );
99
+ export const mx_atan2 = ( in1 = float( 0 ), in2 = float( 1 ) ) => atan( in1, in2 );
100
+ export const mx_timer = () => time;
101
+ export const mx_frame = () => frameId;
102
+ export const mx_invert = ( in1, amount = float( 1 ) ) => sub( amount, in1 );
103
+ export const mx_ifgreater = ( value1, value2, in1, in2 ) => value1.greaterThan( value2 ).mix( in1, in2 );
104
+ export const mx_ifgreatereq = ( value1, value2, in1, in2 ) => value1.greaterThanEqual( value2 ).mix( in1, in2 );
105
+ export const mx_ifequal = ( value1, value2, in1, in2 ) => value1.equal( value2 ).mix( in1, in2 );
106
+
107
+ // Enhanced separate node to support multi-output referencing (outx, outy, outz, outw)
108
+ export const mx_separate = ( in1, channelOrOut = null ) => {
109
+
110
+ if ( typeof channelOrOut === 'string' ) {
111
+
112
+ const map = { x: 0, r: 0, y: 1, g: 1, z: 2, b: 2, w: 3, a: 3 };
113
+ const c = channelOrOut.replace( /^out/, '' ).toLowerCase();
114
+ if ( map[ c ] !== undefined ) return in1.element( map[ c ] );
115
+
116
+ }
117
+
118
+ if ( typeof channelOrOut === 'number' ) {
119
+
120
+ return in1.element( channelOrOut );
121
+
122
+ }
123
+
124
+ if ( typeof channelOrOut === 'string' && channelOrOut.length === 1 ) {
125
+
126
+ const map = { x: 0, r: 0, y: 1, g: 1, z: 2, b: 2, w: 3, a: 3 };
127
+ if ( map[ channelOrOut ] !== undefined ) return in1.element( map[ channelOrOut ] );
128
+
129
+ }
130
+
131
+ return in1;
132
+
133
+ };
134
+
135
+ export const mx_place2d = (
136
+ texcoord, pivot = vec2( 0.5, 0.5 ), scale = vec2( 1, 1 ), rotate = float( 0 ), offset = vec2( 0, 0 )/*, operationorder = int( 0 )*/
137
+ ) => {
138
+
139
+ let uv = texcoord;
140
+ if ( pivot ) uv = uv.sub( pivot );
141
+ if ( scale ) uv = uv.mul( scale );
142
+ if ( rotate ) {
143
+
144
+ const rad = rotate.mul( Math.PI / 180.0 );
145
+ const cosR = rad.cos();
146
+ const sinR = rad.sin();
147
+ uv = vec2(
148
+ uv.x.mul( cosR ).sub( uv.y.mul( sinR ) ),
149
+ uv.x.mul( sinR ).add( uv.y.mul( cosR ) )
150
+ );
151
+
152
+ }
153
+
154
+ if ( pivot ) uv = uv.add( pivot );
155
+ if ( offset ) uv = uv.add( offset );
156
+ return uv;
157
+
158
+ };
159
+
160
+ export const mx_rotate2d = ( input, amount ) => {
161
+
162
+ input = vec2( input );
163
+ amount = float( amount );
164
+
165
+ const radians = amount.mul( Math.PI / 180.0 );
166
+ return rotate( input, radians );
167
+
168
+ };
169
+
170
+ export const mx_rotate3d = ( input, amount, axis ) => {
171
+
172
+ input = vec3( input );
173
+ amount = float( amount );
174
+ axis = vec3( axis );
175
+
176
+
177
+ const radians = amount.mul( Math.PI / 180.0 );
178
+ const nAxis = axis.normalize();
179
+ const cosA = radians.cos();
180
+ const sinA = radians.sin();
181
+ const oneMinusCosA = float( 1 ).sub( cosA );
182
+ const rot =
183
+ input.mul( cosA )
184
+ .add( nAxis.cross( input ).mul( sinA ) )
185
+ .add( nAxis.mul( nAxis.dot( input ) ).mul( oneMinusCosA ) );
186
+ return rot;
187
+
188
+ };
189
+
190
+ export const mx_heighttonormal = ( input, scale/*, texcoord*/ ) => {
191
+
192
+ input = vec3( input );
193
+ scale = float( scale );
194
+
195
+ return bumpMap( input, scale );
196
+
197
+ };
@@ -4,7 +4,7 @@
4
4
  import { int, uint, float, vec3, bool, uvec3, vec2, vec4, If, Fn } from '../../tsl/TSLBase.js';
5
5
  import { select } from '../../math/ConditionalNode.js';
6
6
  import { sub, mul } from '../../math/OperatorNode.js';
7
- import { floor, abs, max, dot, min, sqrt } from '../../math/MathNode.js';
7
+ import { floor, abs, max, dot, min, sqrt, clamp } from '../../math/MathNode.js';
8
8
  import { overloadingFn } from '../../utils/FunctionOverloadingNode.js';
9
9
  import { Loop } from '../../utils/LoopNode.js';
10
10
 
@@ -1325,3 +1325,167 @@ export const mx_worley_noise_vec3_1 = /*@__PURE__*/ Fn( ( [ p_immutable, jitter_
1325
1325
  } );
1326
1326
 
1327
1327
  export const mx_worley_noise_vec3 = /*@__PURE__*/ overloadingFn( [ mx_worley_noise_vec3_0, mx_worley_noise_vec3_1 ] );
1328
+
1329
+ // Unified Noise 2D
1330
+ export const mx_unifiednoise2d = /*@__PURE__*/ Fn( ( [
1331
+ noiseType_immutable, texcoord_immutable, freq_immutable, offset_immutable,
1332
+ jitter_immutable, outmin_immutable, outmax_immutable, clampoutput_immutable,
1333
+ octaves_immutable, lacunarity_immutable, diminish_immutable
1334
+ ] ) => {
1335
+
1336
+ const noiseType = int( noiseType_immutable ).toVar();
1337
+ const texcoord = vec2( texcoord_immutable ).toVar();
1338
+ const freq = vec2( freq_immutable ).toVar();
1339
+ const offset = vec2( offset_immutable ).toVar();
1340
+ const jitter = float( jitter_immutable ).toVar();
1341
+ const outmin = float( outmin_immutable ).toVar();
1342
+ const outmax = float( outmax_immutable ).toVar();
1343
+ const clampoutput = bool( clampoutput_immutable ).toVar();
1344
+ const octaves = int( octaves_immutable ).toVar();
1345
+ const lacunarity = float( lacunarity_immutable ).toVar();
1346
+ const diminish = float( diminish_immutable ).toVar();
1347
+
1348
+ // Compute input position
1349
+ const p = texcoord.mul( freq ).add( offset );
1350
+
1351
+ const result = float( 0.0 ).toVar();
1352
+
1353
+ // Perlin
1354
+ If( noiseType.equal( int( 0 ) ), () => {
1355
+
1356
+ result.assign( mx_perlin_noise_vec3( p ) );
1357
+
1358
+ } );
1359
+
1360
+ // Cell
1361
+ If( noiseType.equal( int( 1 ) ), () => {
1362
+
1363
+ result.assign( mx_cell_noise_vec3( p ) );
1364
+
1365
+ } );
1366
+
1367
+ // Worley (metric=0 = euclidean)
1368
+ If( noiseType.equal( int( 2 ) ), () => {
1369
+
1370
+ result.assign( mx_worley_noise_vec3( p, jitter, int( 0 ) ) );
1371
+
1372
+ } );
1373
+
1374
+ // Fractal (use vec3(p, 0.0) for 2D input)
1375
+ If( noiseType.equal( int( 3 ) ), () => {
1376
+
1377
+ result.assign( mx_fractal_noise_vec3( vec3( p, 0.0 ), octaves, lacunarity, diminish ) );
1378
+
1379
+ } );
1380
+
1381
+ // Remap output to [outmin, outmax]
1382
+ result.assign( result.mul( outmax.sub( outmin ) ).add( outmin ) );
1383
+
1384
+ // Clamp if requested
1385
+ If( clampoutput, () => {
1386
+
1387
+ result.assign( clamp( result, outmin, outmax ) );
1388
+
1389
+ } );
1390
+
1391
+ return result;
1392
+
1393
+ } ).setLayout( {
1394
+ name: 'mx_unifiednoise2d',
1395
+ type: 'float',
1396
+ inputs: [
1397
+ { name: 'noiseType', type: 'int' },
1398
+ { name: 'texcoord', type: 'vec2' },
1399
+ { name: 'freq', type: 'vec2' },
1400
+ { name: 'offset', type: 'vec2' },
1401
+ { name: 'jitter', type: 'float' },
1402
+ { name: 'outmin', type: 'float' },
1403
+ { name: 'outmax', type: 'float' },
1404
+ { name: 'clampoutput', type: 'bool' },
1405
+ { name: 'octaves', type: 'int' },
1406
+ { name: 'lacunarity', type: 'float' },
1407
+ { name: 'diminish', type: 'float' }
1408
+ ]
1409
+ } );
1410
+
1411
+ // Unified Noise 3D
1412
+ export const mx_unifiednoise3d = /*@__PURE__*/ Fn( ( [
1413
+ noiseType_immutable, position_immutable, freq_immutable, offset_immutable,
1414
+ jitter_immutable, outmin_immutable, outmax_immutable, clampoutput_immutable,
1415
+ octaves_immutable, lacunarity_immutable, diminish_immutable
1416
+ ] ) => {
1417
+
1418
+ const noiseType = int( noiseType_immutable ).toVar();
1419
+ const position = vec3( position_immutable ).toVar();
1420
+ const freq = vec3( freq_immutable ).toVar();
1421
+ const offset = vec3( offset_immutable ).toVar();
1422
+ const jitter = float( jitter_immutable ).toVar();
1423
+ const outmin = float( outmin_immutable ).toVar();
1424
+ const outmax = float( outmax_immutable ).toVar();
1425
+ const clampoutput = bool( clampoutput_immutable ).toVar();
1426
+ const octaves = int( octaves_immutable ).toVar();
1427
+ const lacunarity = float( lacunarity_immutable ).toVar();
1428
+ const diminish = float( diminish_immutable ).toVar();
1429
+
1430
+ // Compute input position
1431
+ const p = position.mul( freq ).add( offset );
1432
+
1433
+ const result = float( 0.0 ).toVar();
1434
+
1435
+ // Perlin
1436
+ If( noiseType.equal( int( 0 ) ), () => {
1437
+
1438
+ result.assign( mx_perlin_noise_vec3( p ) );
1439
+
1440
+ } );
1441
+
1442
+ // Cell
1443
+ If( noiseType.equal( int( 1 ) ), () => {
1444
+
1445
+ result.assign( mx_cell_noise_vec3( p ) );
1446
+
1447
+ } );
1448
+
1449
+ // Worley (metric=0 = euclidean)
1450
+ If( noiseType.equal( int( 2 ) ), () => {
1451
+
1452
+ result.assign( mx_worley_noise_vec3( p, jitter, int( 0 ) ) );
1453
+
1454
+ } );
1455
+
1456
+ // Fractal
1457
+ If( noiseType.equal( int( 3 ) ), () => {
1458
+
1459
+ result.assign( mx_fractal_noise_vec3( p, octaves, lacunarity, diminish ) );
1460
+
1461
+ } );
1462
+
1463
+ // Remap output to [outmin, outmax]
1464
+ result.assign( result.mul( outmax.sub( outmin ) ).add( outmin ) );
1465
+
1466
+ // Clamp if requested
1467
+ If( clampoutput, () => {
1468
+
1469
+ result.assign( clamp( result, outmin, outmax ) );
1470
+
1471
+ } );
1472
+
1473
+ return result;
1474
+
1475
+ } ).setLayout( {
1476
+ name: 'mx_unifiednoise3d',
1477
+ type: 'float',
1478
+ inputs: [
1479
+ { name: 'noiseType', type: 'int' },
1480
+ { name: 'position', type: 'vec3' },
1481
+ { name: 'freq', type: 'vec3' },
1482
+ { name: 'offset', type: 'vec3' },
1483
+ { name: 'jitter', type: 'float' },
1484
+ { name: 'outmin', type: 'float' },
1485
+ { name: 'outmax', type: 'float' },
1486
+ { name: 'clampoutput', type: 'bool' },
1487
+ { name: 'octaves', type: 'int' },
1488
+ { name: 'lacunarity', type: 'float' },
1489
+ { name: 'diminish', type: 'float' }
1490
+ ]
1491
+ } );
@@ -0,0 +1,156 @@
1
+ import TempNode from '../core/TempNode.js';
2
+ import { nodeProxyIntent } from '../tsl/TSLCore.js';
3
+ /**
4
+ * This node represents an operation that reinterprets the bit representation of a value
5
+ * in one type as a value in another type.
6
+ *
7
+ * @augments TempNode
8
+ */
9
+ class BitcastNode extends TempNode {
10
+
11
+ static get type() {
12
+
13
+ return 'BitcastNode';
14
+
15
+ }
16
+
17
+ /**
18
+ * Constructs a new bitcast node.
19
+ *
20
+ * @param {Node} valueNode - The value to convert.
21
+ * @param {string} conversionType - The type to convert to.
22
+ * @param {?string} [inputType = null] - The expected input data type of the bitcast operation.
23
+ */
24
+ constructor( valueNode, conversionType, inputType = null ) {
25
+
26
+ super();
27
+
28
+ /**
29
+ * The data to bitcast to a new type.
30
+ *
31
+ * @type {Node}
32
+ */
33
+ this.valueNode = valueNode;
34
+
35
+ /**
36
+ * The type the value will be converted to.
37
+ *
38
+ * @type {string}
39
+ */
40
+ this.conversionType = conversionType;
41
+
42
+
43
+ /**
44
+ * The expected input data type of the bitcast operation.
45
+ *
46
+ *
47
+ * @type {string}
48
+ * @default null
49
+ */
50
+ this.inputType = inputType;
51
+
52
+ /**
53
+ * This flag can be used for type testing.
54
+ *
55
+ * @type {boolean}
56
+ * @readonly
57
+ * @default true
58
+ */
59
+ this.isBitcastNode = true;
60
+
61
+ }
62
+
63
+ getNodeType( builder ) {
64
+
65
+ // GLSL aliasing
66
+ if ( this.inputType !== null ) {
67
+
68
+ const valueType = this.valueNode.getNodeType( builder );
69
+ const valueLength = builder.getTypeLength( valueType );
70
+
71
+ return builder.getTypeFromLength( valueLength, this.conversionType );
72
+
73
+ }
74
+
75
+ return this.conversionType;
76
+
77
+ }
78
+
79
+
80
+ generate( builder ) {
81
+
82
+ const type = this.getNodeType( builder );
83
+ let inputType = '';
84
+
85
+ if ( this.inputType !== null ) {
86
+
87
+ const valueType = this.valueNode.getNodeType( builder );
88
+ const valueTypeLength = builder.getTypeLength( valueType );
89
+
90
+ inputType = valueTypeLength === 1 ? this.inputType : builder.changeComponentType( valueType, this.inputType );
91
+
92
+ } else {
93
+
94
+ inputType = this.valueNode.getNodeType( builder );
95
+
96
+ }
97
+
98
+ return `${ builder.getBitcastMethod( type, inputType ) }( ${ this.valueNode.build( builder, inputType ) } )`;
99
+
100
+
101
+ }
102
+
103
+ }
104
+
105
+ export default BitcastNode;
106
+
107
+ /**
108
+ * Reinterpret the bit representation of a value in one type as a value in another type.
109
+ *
110
+ * @tsl
111
+ * @function
112
+ * @param {Node | number} x - The parameter.
113
+ * @param {string} y - The new type.
114
+ * @returns {Node}
115
+ */
116
+ export const bitcast = /*@__PURE__*/ nodeProxyIntent( BitcastNode ).setParameterLength( 2 );
117
+
118
+ /**
119
+ * Bitcasts a float or a vector of floats to a corresponding integer type with the same element size.
120
+ *
121
+ * @tsl
122
+ * @function
123
+ * @param {Node<float>} value - The float or vector of floats to bitcast.
124
+ * @returns {BitcastNode}
125
+ */
126
+ export const floatBitsToInt = ( value ) => new BitcastNode( value, 'int', 'float' );
127
+
128
+ /**
129
+ * Bitcasts a float or a vector of floats to a corresponding unsigned integer type with the same element size.
130
+ *
131
+ * @tsl
132
+ * @function
133
+ * @param {Node<float>} value - The float or vector of floats to bitcast.
134
+ * @returns {BitcastNode}
135
+ */
136
+ export const floatBitsToUint = ( value ) => new BitcastNode( value, 'uint', 'float' );
137
+
138
+ /**
139
+ * Bitcasts an integer or a vector of integers to a corresponding float type with the same element size.
140
+ *
141
+ * @tsl
142
+ * @function
143
+ * @param {Node<int>} value - The integer or vector of integers to bitcast.
144
+ * @returns {BitcastNode}
145
+ */
146
+ export const intBitsToFloat = ( value ) => new BitcastNode( value, 'float', 'int' );
147
+
148
+ /**
149
+ * Bitcast an unsigned integer or a vector of unsigned integers to a corresponding float type with the same element size.
150
+ *
151
+ * @tsl
152
+ * @function
153
+ * @param {Node<uint>} value - The unsigned integer or vector of unsigned integers to bitcast.
154
+ * @returns {BitcastNode}
155
+ */
156
+ export const uintBitsToFloat = ( value ) => new BitcastNode( value, 'float', 'uint' );
@@ -73,7 +73,7 @@ class ConditionalNode extends Node {
73
73
 
74
74
  // fallback setup
75
75
 
76
- this.setup( builder );
76
+ builder.flowBuildStage( this, 'setup' );
77
77
 
78
78
  return this.getNodeType( builder );
79
79
 
@@ -112,10 +112,12 @@ class ConditionalNode extends Node {
112
112
 
113
113
  //
114
114
 
115
+ const isUniformFlow = builder.context.uniformFlow;
116
+
115
117
  const properties = builder.getNodeProperties( this );
116
118
  properties.condNode = condNode;
117
- properties.ifNode = ifNode.context( { nodeBlock: ifNode } );
118
- properties.elseNode = elseNode ? elseNode.context( { nodeBlock: elseNode } ) : null;
119
+ properties.ifNode = isUniformFlow ? ifNode : ifNode.context( { nodeBlock: ifNode } );
120
+ properties.elseNode = elseNode ? ( isUniformFlow ? elseNode : elseNode.context( { nodeBlock: elseNode } ) ) : null;
119
121
 
120
122
  }
121
123
 
@@ -140,6 +142,20 @@ class ConditionalNode extends Node {
140
142
  nodeData.nodeProperty = nodeProperty;
141
143
 
142
144
  const nodeSnippet = condNode.build( builder, 'bool' );
145
+ const isUniformFlow = builder.context.uniformFlow;
146
+
147
+ if ( isUniformFlow && elseNode !== null ) {
148
+
149
+ const ifSnippet = ifNode.build( builder, type );
150
+ const elseSnippet = elseNode.build( builder, type );
151
+
152
+ const mathSnippet = builder.getTernary( nodeSnippet, ifSnippet, elseSnippet );
153
+
154
+ // TODO: If node property already exists return something else
155
+
156
+ return builder.format( mathSnippet, type, output );
157
+
158
+ }
143
159
 
144
160
  builder.addFlowCode( `\n${ builder.tab }if ( ${ nodeSnippet } ) {\n\n` ).addFlowTab();
145
161