super-three 0.167.0 → 0.168.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 (311) hide show
  1. package/build/three.cjs +165 -44
  2. package/build/three.module.js +165 -45
  3. package/build/three.module.min.js +1 -1
  4. package/build/three.webgpu.js +23600 -21931
  5. package/build/three.webgpu.min.js +1 -1
  6. package/examples/jsm/Addons.js +3 -1
  7. package/examples/jsm/animation/AnimationClipCreator.js +1 -1
  8. package/examples/jsm/capabilities/WebGL.js +27 -21
  9. package/examples/jsm/controls/ArcballControls.js +174 -158
  10. package/examples/jsm/controls/DragControls.js +260 -132
  11. package/examples/jsm/controls/FirstPersonControls.js +175 -163
  12. package/examples/jsm/controls/FlyControls.js +194 -188
  13. package/examples/jsm/controls/OrbitControls.js +777 -786
  14. package/examples/jsm/controls/PointerLockControls.js +24 -15
  15. package/examples/jsm/controls/TrackballControls.js +453 -452
  16. package/examples/jsm/effects/AnaglyphEffect.js +6 -13
  17. package/examples/jsm/effects/ParallaxBarrierEffect.js +17 -11
  18. package/examples/jsm/effects/StereoEffect.js +6 -1
  19. package/examples/jsm/environments/RoomEnvironment.js +1 -1
  20. package/examples/jsm/exporters/GLTFExporter.js +6 -1
  21. package/examples/jsm/exporters/USDZExporter.js +29 -8
  22. package/examples/jsm/helpers/LightProbeHelper.js +42 -43
  23. package/examples/jsm/loaders/KTX2Loader.js +19 -7
  24. package/examples/jsm/loaders/MaterialXLoader.js +11 -4
  25. package/examples/jsm/loaders/PCDLoader.js +9 -9
  26. package/examples/jsm/objects/SkyMesh.js +188 -0
  27. package/examples/jsm/objects/Water2Mesh.js +159 -0
  28. package/examples/jsm/objects/WaterMesh.js +102 -0
  29. package/examples/jsm/physics/RapierPhysics.js +20 -0
  30. package/examples/jsm/postprocessing/OutlinePass.js +31 -46
  31. package/examples/jsm/postprocessing/SSAARenderPass.js +3 -1
  32. package/examples/jsm/shaders/BleachBypassShader.js +1 -2
  33. package/examples/jsm/shaders/OutputShader.js +1 -1
  34. package/examples/jsm/transpiler/TSLEncoder.js +8 -8
  35. package/examples/jsm/utils/TextureUtils.js +1 -1
  36. package/package.json +2 -1
  37. package/src/Three.WebGPU.js +6 -0
  38. package/src/Three.js +1 -0
  39. package/src/constants.js +1 -1
  40. package/src/extras/Controls.js +32 -0
  41. package/src/loaders/ObjectLoader.js +3 -3
  42. package/src/{nodes/loaders → loaders/nodes}/NodeLoader.js +4 -4
  43. package/src/{nodes/loaders → loaders/nodes}/NodeMaterialLoader.js +1 -2
  44. package/src/materials/Material.js +4 -7
  45. package/src/{nodes/materials → materials/nodes}/InstancedPointsNodeMaterial.js +33 -24
  46. package/src/{nodes/materials → materials/nodes}/Line2NodeMaterial.js +34 -37
  47. package/src/{nodes/materials → materials/nodes}/LineBasicNodeMaterial.js +3 -4
  48. package/src/{nodes/materials → materials/nodes}/LineDashedNodeMaterial.js +7 -9
  49. package/src/{nodes/materials → materials/nodes}/MeshBasicNodeMaterial.js +11 -11
  50. package/src/{nodes/materials → materials/nodes}/MeshLambertNodeMaterial.js +5 -5
  51. package/src/{nodes/materials → materials/nodes}/MeshMatcapNodeMaterial.js +8 -8
  52. package/src/materials/nodes/MeshNormalNodeMaterial.js +40 -0
  53. package/src/{nodes/materials → materials/nodes}/MeshPhongNodeMaterial.js +9 -8
  54. package/src/{nodes/materials → materials/nodes}/MeshPhysicalNodeMaterial.js +18 -17
  55. package/src/{nodes/materials → materials/nodes}/MeshSSSNodeMaterial.js +6 -6
  56. package/src/{nodes/materials → materials/nodes}/MeshStandardNodeMaterial.js +17 -11
  57. package/src/{nodes/materials → materials/nodes}/MeshToonNodeMaterial.js +4 -4
  58. package/src/{nodes/materials → materials/nodes}/NodeMaterial.js +67 -86
  59. package/src/{nodes/materials/Materials.js → materials/nodes/NodeMaterials.js} +1 -1
  60. package/src/{nodes/materials → materials/nodes}/PointsNodeMaterial.js +3 -4
  61. package/src/{nodes/materials → materials/nodes}/ShadowNodeMaterial.js +4 -4
  62. package/src/{nodes/materials → materials/nodes}/SpriteNodeMaterial.js +11 -11
  63. package/src/{nodes/materials → materials/nodes}/VolumeNodeMaterial.js +14 -16
  64. package/src/nodes/Nodes.js +103 -159
  65. package/src/nodes/TSL.js +176 -0
  66. package/src/nodes/accessors/AccessorsUtils.js +8 -8
  67. package/src/nodes/accessors/BatchNode.js +48 -20
  68. package/src/nodes/accessors/{BitangentNode.js → Bitangent.js} +9 -9
  69. package/src/nodes/accessors/BufferAttributeNode.js +5 -5
  70. package/src/nodes/accessors/BufferNode.js +4 -4
  71. package/src/nodes/accessors/{CameraNode.js → Camera.js} +10 -10
  72. package/src/nodes/accessors/ClippingNode.js +16 -14
  73. package/src/nodes/accessors/CubeTextureNode.js +5 -7
  74. package/src/nodes/accessors/InstanceNode.js +17 -13
  75. package/src/nodes/accessors/InstancedPointsMaterialNode.js +4 -4
  76. package/src/nodes/accessors/MaterialNode.js +52 -55
  77. package/src/nodes/accessors/MaterialProperties.js +3 -0
  78. package/src/nodes/accessors/MaterialReferenceNode.js +6 -4
  79. package/src/nodes/accessors/ModelNode.js +11 -11
  80. package/src/nodes/accessors/ModelViewProjectionNode.js +6 -7
  81. package/src/nodes/accessors/MorphNode.js +12 -12
  82. package/src/nodes/accessors/Normal.js +62 -0
  83. package/src/nodes/accessors/Object3DNode.js +10 -10
  84. package/src/nodes/accessors/PointUVNode.js +4 -4
  85. package/src/nodes/accessors/Position.js +10 -0
  86. package/src/nodes/accessors/ReferenceBaseNode.js +143 -0
  87. package/src/nodes/accessors/ReferenceNode.js +13 -7
  88. package/src/nodes/accessors/ReflectVector.js +10 -0
  89. package/src/nodes/accessors/RendererReferenceNode.js +6 -6
  90. package/src/nodes/accessors/SceneNode.js +5 -6
  91. package/src/nodes/accessors/SkinningNode.js +84 -21
  92. package/src/nodes/accessors/StorageBufferNode.js +4 -5
  93. package/src/nodes/accessors/StorageTextureNode.js +5 -5
  94. package/src/nodes/accessors/Tangent.js +22 -0
  95. package/src/nodes/accessors/Texture3DNode.js +11 -11
  96. package/src/nodes/accessors/{TextureBicubicNode.js → TextureBicubic.js} +3 -32
  97. package/src/nodes/accessors/TextureNode.js +16 -21
  98. package/src/nodes/accessors/TextureSizeNode.js +4 -6
  99. package/src/nodes/accessors/{UniformsNode.js → UniformArrayNode.js} +17 -8
  100. package/src/nodes/accessors/UserDataNode.js +4 -4
  101. package/src/nodes/accessors/VelocityNode.js +83 -0
  102. package/src/nodes/accessors/VertexColorNode.js +4 -4
  103. package/src/nodes/code/CodeNode.js +5 -5
  104. package/src/nodes/code/ExpressionNode.js +4 -4
  105. package/src/nodes/code/FunctionCallNode.js +5 -5
  106. package/src/nodes/code/FunctionNode.js +5 -23
  107. package/src/nodes/code/ScriptableNode.js +4 -6
  108. package/src/nodes/code/ScriptableValueNode.js +4 -6
  109. package/src/nodes/core/AssignNode.js +5 -5
  110. package/src/nodes/core/AttributeNode.js +7 -20
  111. package/src/nodes/core/BypassNode.js +5 -5
  112. package/src/nodes/core/CacheNode.js +5 -5
  113. package/src/nodes/core/ConstNode.js +2 -2
  114. package/src/nodes/core/ContextNode.js +17 -11
  115. package/src/nodes/core/IndexNode.js +12 -7
  116. package/src/nodes/core/InputNode.js +2 -2
  117. package/src/nodes/core/MRTNode.js +12 -6
  118. package/src/nodes/core/Node.js +39 -19
  119. package/src/nodes/core/NodeBuilder.js +46 -33
  120. package/src/nodes/core/NodeUtils.js +1 -0
  121. package/src/nodes/core/OutputStructNode.js +4 -4
  122. package/src/nodes/core/ParameterNode.js +4 -4
  123. package/src/nodes/core/PropertyNode.js +32 -32
  124. package/src/nodes/core/StackNode.js +26 -10
  125. package/src/nodes/core/StructTypeNode.js +2 -2
  126. package/src/nodes/core/TempNode.js +2 -2
  127. package/src/nodes/core/UniformGroupNode.js +8 -9
  128. package/src/nodes/core/UniformNode.js +4 -4
  129. package/src/nodes/core/VarNode.js +6 -6
  130. package/src/nodes/core/VaryingNode.js +5 -5
  131. package/src/nodes/display/AfterImageNode.js +9 -9
  132. package/src/nodes/display/AnaglyphPassNode.js +61 -0
  133. package/src/nodes/display/AnamorphicNode.js +11 -11
  134. package/src/nodes/display/BleachBypass.js +26 -0
  135. package/src/nodes/display/BlendMode.js +54 -0
  136. package/src/nodes/display/BloomNode.js +21 -19
  137. package/src/nodes/display/BumpMapNode.js +7 -12
  138. package/src/nodes/display/ColorAdjustment.js +46 -0
  139. package/src/nodes/display/ColorSpaceFunctions.js +38 -0
  140. package/src/nodes/display/ColorSpaceNode.js +40 -63
  141. package/src/nodes/display/DenoiseNode.js +20 -17
  142. package/src/nodes/display/DepthOfFieldNode.js +8 -6
  143. package/src/nodes/display/DotScreenNode.js +10 -22
  144. package/src/nodes/display/FXAANode.js +17 -15
  145. package/src/nodes/display/FilmNode.js +7 -6
  146. package/src/nodes/display/FrontFacingNode.js +5 -5
  147. package/src/nodes/display/GTAONode.js +19 -15
  148. package/src/nodes/display/GaussianBlurNode.js +11 -8
  149. package/src/nodes/display/Lut3DNode.js +6 -5
  150. package/src/nodes/display/MotionBlur.js +25 -0
  151. package/src/nodes/display/NormalMapNode.js +8 -10
  152. package/src/nodes/display/ParallaxBarrierPassNode.js +55 -0
  153. package/src/nodes/display/PassNode.js +84 -8
  154. package/src/nodes/display/PixelationPassNode.js +12 -7
  155. package/src/nodes/display/PosterizeNode.js +4 -6
  156. package/src/nodes/display/RGBShiftNode.js +8 -7
  157. package/src/nodes/display/RenderOutputNode.js +9 -9
  158. package/src/nodes/display/SSAAPassNode.js +284 -0
  159. package/src/nodes/display/Sepia.js +17 -0
  160. package/src/nodes/display/SobelOperatorNode.js +9 -7
  161. package/src/nodes/display/StereoCompositePassNode.js +107 -0
  162. package/src/nodes/display/StereoPassNode.js +80 -0
  163. package/src/nodes/display/ToneMappingFunctions.js +190 -0
  164. package/src/nodes/display/ToneMappingNode.js +12 -173
  165. package/src/nodes/display/TransitionNode.js +9 -8
  166. package/src/nodes/display/ViewportDepthNode.js +30 -29
  167. package/src/nodes/display/ViewportDepthTextureNode.js +6 -8
  168. package/src/nodes/display/ViewportNode.js +26 -25
  169. package/src/nodes/display/ViewportSharedTextureNode.js +6 -8
  170. package/src/nodes/display/ViewportTextureNode.js +7 -10
  171. package/src/nodes/fog/FogExp2Node.js +4 -6
  172. package/src/nodes/fog/FogNode.js +5 -7
  173. package/src/nodes/fog/FogRangeNode.js +4 -6
  174. package/src/nodes/functions/BSDF/BRDF_GGX.js +4 -4
  175. package/src/nodes/functions/BSDF/BRDF_Lambert.js +2 -2
  176. package/src/nodes/functions/BSDF/BRDF_Sheen.js +6 -6
  177. package/src/nodes/functions/BSDF/DFGApprox.js +2 -2
  178. package/src/nodes/functions/BSDF/D_GGX.js +2 -2
  179. package/src/nodes/functions/BSDF/D_GGX_Anisotropic.js +3 -3
  180. package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
  181. package/src/nodes/functions/BSDF/F_Schlick.js +2 -2
  182. package/src/nodes/functions/BSDF/LTC.js +6 -6
  183. package/src/nodes/functions/BSDF/Schlick_to_F0.js +2 -2
  184. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +2 -2
  185. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +2 -2
  186. package/src/nodes/functions/BasicLightingModel.js +1 -1
  187. package/src/nodes/functions/PhongLightingModel.js +5 -5
  188. package/src/nodes/functions/PhysicalLightingModel.js +32 -31
  189. package/src/nodes/functions/ShadowMaskModel.js +1 -1
  190. package/src/nodes/functions/ToonLightingModel.js +3 -3
  191. package/src/nodes/functions/material/getGeometryRoughness.js +4 -4
  192. package/src/nodes/functions/material/getRoughness.js +2 -2
  193. package/src/nodes/geometry/RangeNode.js +4 -4
  194. package/src/nodes/gpgpu/ComputeNode.js +5 -5
  195. package/src/nodes/lighting/AONode.js +2 -2
  196. package/src/nodes/lighting/AmbientLightNode.js +2 -7
  197. package/src/nodes/lighting/AnalyticLightNode.js +34 -13
  198. package/src/nodes/lighting/BasicEnvironmentNode.js +4 -3
  199. package/src/nodes/lighting/BasicLightMapNode.js +3 -3
  200. package/src/nodes/lighting/DirectionalLightNode.js +2 -7
  201. package/src/nodes/lighting/EnvironmentNode.js +20 -19
  202. package/src/nodes/lighting/HemisphereLightNode.js +3 -7
  203. package/src/nodes/lighting/IESSpotLightNode.js +3 -8
  204. package/src/nodes/lighting/IrradianceNode.js +2 -2
  205. package/src/nodes/lighting/LightNode.js +5 -5
  206. package/src/nodes/lighting/LightProbeNode.js +76 -0
  207. package/src/nodes/lighting/LightUtils.js +3 -3
  208. package/src/nodes/lighting/LightingContextNode.js +15 -17
  209. package/src/nodes/lighting/LightingNode.js +2 -2
  210. package/src/nodes/lighting/LightsNode.js +94 -76
  211. package/src/nodes/lighting/PointLightNode.js +3 -8
  212. package/src/nodes/lighting/RectAreaLightNode.js +2 -6
  213. package/src/nodes/lighting/SpotLightNode.js +3 -8
  214. package/src/nodes/materialx/MaterialXNodes.js +2 -2
  215. package/src/nodes/materialx/lib/mx_hsv.js +36 -31
  216. package/src/nodes/materialx/lib/mx_noise.js +96 -96
  217. package/src/nodes/materialx/lib/mx_transform_color.js +2 -2
  218. package/src/nodes/math/{CondNode.js → ConditionalNode.js} +18 -7
  219. package/src/nodes/math/Hash.js +13 -0
  220. package/src/nodes/math/MathNode.js +124 -124
  221. package/src/nodes/math/MathUtils.js +0 -7
  222. package/src/nodes/math/OperatorNode.js +94 -52
  223. package/src/nodes/math/TriNoise3D.js +19 -29
  224. package/src/nodes/pmrem/PMREMNode.js +58 -15
  225. package/src/nodes/pmrem/PMREMUtils.js +46 -46
  226. package/src/nodes/procedural/Checker.js +14 -0
  227. package/src/nodes/tsl/TSLBase.js +30 -0
  228. package/src/nodes/{shadernode/ShaderNode.js → tsl/TSLCore.js} +105 -97
  229. package/src/nodes/utils/ArrayElementNode.js +2 -2
  230. package/src/nodes/utils/ConvertNode.js +2 -2
  231. package/src/nodes/utils/CubeMapNode.js +157 -0
  232. package/src/nodes/utils/Discard.js +8 -0
  233. package/src/nodes/utils/EquirectUVNode.js +5 -5
  234. package/src/nodes/utils/FlipNode.js +65 -0
  235. package/src/nodes/utils/FunctionOverloadingNode.js +5 -5
  236. package/src/nodes/utils/JoinNode.js +2 -2
  237. package/src/nodes/utils/LoopNode.js +12 -6
  238. package/src/nodes/utils/MatcapUVNode.js +6 -6
  239. package/src/nodes/utils/MaxMipLevelNode.js +4 -4
  240. package/src/nodes/utils/OscNode.js +7 -7
  241. package/src/nodes/utils/Packing.js +4 -0
  242. package/src/nodes/utils/RTTNode.js +8 -8
  243. package/src/nodes/utils/ReflectorNode.js +8 -3
  244. package/src/nodes/utils/RemapNode.js +7 -7
  245. package/src/nodes/utils/RotateNode.js +4 -12
  246. package/src/nodes/utils/SetNode.js +2 -2
  247. package/src/nodes/utils/SplitNode.js +2 -2
  248. package/src/nodes/utils/SpriteSheetUVNode.js +5 -5
  249. package/src/nodes/utils/SpriteUtils.js +47 -0
  250. package/src/nodes/utils/StorageArrayElementNode.js +4 -6
  251. package/src/nodes/utils/TimerNode.js +5 -5
  252. package/src/nodes/utils/TriplanarTexturesNode.js +7 -9
  253. package/src/nodes/utils/UVUtils.js +19 -0
  254. package/src/nodes/utils/ViewportUtils.js +14 -0
  255. package/src/objects/BatchedMesh.js +2 -3
  256. package/src/renderers/WebGLRenderer.js +24 -0
  257. package/src/renderers/common/Backend.js +2 -2
  258. package/src/renderers/common/Background.js +3 -1
  259. package/src/renderers/common/BindGroup.js +3 -1
  260. package/src/renderers/common/Bindings.js +13 -15
  261. package/src/renderers/common/ClippingContext.js +14 -5
  262. package/src/renderers/common/CubeRenderTarget.js +9 -3
  263. package/src/renderers/common/PostProcessing.js +4 -1
  264. package/src/renderers/common/QuadMesh.js +2 -0
  265. package/src/renderers/common/RenderContext.js +24 -0
  266. package/src/renderers/common/RenderList.js +1 -1
  267. package/src/renderers/common/RenderObject.js +2 -2
  268. package/src/renderers/common/Renderer.js +75 -49
  269. package/src/renderers/common/SampledTexture.js +12 -3
  270. package/src/renderers/common/StandardRenderer.js +18 -0
  271. package/src/renderers/common/Textures.js +8 -12
  272. package/src/renderers/common/extras/PMREMGenerator.js +12 -13
  273. package/src/renderers/common/nodes/NodeBuilderState.js +1 -1
  274. package/src/renderers/common/nodes/NodeLibrary.js +118 -0
  275. package/src/renderers/common/nodes/NodeSampledTexture.js +2 -2
  276. package/src/renderers/common/nodes/Nodes.js +36 -9
  277. package/src/renderers/common/nodes/StandardNodeLibrary.js +105 -0
  278. package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +2 -2
  279. package/src/renderers/webgl/WebGLProgram.js +1 -1
  280. package/src/renderers/webgl/WebGLProperties.js +7 -0
  281. package/src/renderers/webgl/WebGLTextures.js +61 -4
  282. package/src/renderers/webgl-fallback/WebGLBackend.js +88 -68
  283. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +57 -9
  284. package/src/renderers/webgl-fallback/utils/WebGLState.js +21 -0
  285. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +28 -21
  286. package/src/renderers/webgpu/WebGPUBackend.js +86 -68
  287. package/src/renderers/webgpu/WebGPURenderer.js +8 -8
  288. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +99 -63
  289. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +45 -21
  290. package/src/renderers/webgpu/utils/WebGPUConstants.js +2 -1
  291. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +6 -15
  292. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +62 -5
  293. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +36 -21
  294. package/src/renderers/webgpu/utils/WebGPUUtils.js +18 -1
  295. package/src/renderers/webxr/WebXRManager.js +32 -25
  296. package/examples/jsm/loaders/LogLuvLoader.js +0 -606
  297. package/src/nodes/accessors/NormalNode.js +0 -14
  298. package/src/nodes/accessors/PositionNode.js +0 -10
  299. package/src/nodes/accessors/ReflectVectorNode.js +0 -10
  300. package/src/nodes/accessors/TangentNode.js +0 -23
  301. package/src/nodes/core/NodeKeywords.js +0 -80
  302. package/src/nodes/display/BlendModeNode.js +0 -128
  303. package/src/nodes/display/ColorAdjustmentNode.js +0 -104
  304. package/src/nodes/materials/MeshNormalNodeMaterial.js +0 -40
  305. package/src/nodes/math/HashNode.js +0 -34
  306. package/src/nodes/procedural/CheckerNode.js +0 -42
  307. package/src/nodes/utils/DiscardNode.js +0 -28
  308. package/src/nodes/utils/PackingNode.js +0 -55
  309. package/src/nodes/utils/RotateUVNode.js +0 -35
  310. /package/src/{nodes/loaders → loaders/nodes}/NodeObjectLoader.js +0 -0
  311. /package/src/nodes/accessors/{UVNode.js → UV.js} +0 -0
@@ -0,0 +1,190 @@
1
+ import { Fn, float, mat3, vec3, If } from '../tsl/TSLBase.js';
2
+ import { select } from '../math/ConditionalNode.js';
3
+ import { clamp, log2, max, min, pow, mix } from '../math/MathNode.js';
4
+ import { mul, sub, div } from '../math/OperatorNode.js';
5
+
6
+ // exposure only
7
+
8
+ export const LinearToneMapping = /*@__PURE__*/ Fn( ( [ color, exposure ] ) => {
9
+
10
+ return color.mul( exposure ).clamp();
11
+
12
+ } ).setLayout( {
13
+ name: 'LinearToneMapping',
14
+ type: 'vec3',
15
+ inputs: [
16
+ { name: 'color', type: 'vec3' },
17
+ { name: 'exposure', type: 'float' }
18
+ ]
19
+ } );
20
+
21
+ // source: https://www.cs.utah.edu/docs/techreports/2002/pdf/UUCS-02-001.pdf
22
+
23
+ export const ReinhardToneMapping = /*@__PURE__*/ Fn( ( [ color, exposure ] ) => {
24
+
25
+ color = color.mul( exposure );
26
+
27
+ return color.div( color.add( 1.0 ) ).clamp();
28
+
29
+ } ).setLayout( {
30
+ name: 'ReinhardToneMapping',
31
+ type: 'vec3',
32
+ inputs: [
33
+ { name: 'color', type: 'vec3' },
34
+ { name: 'exposure', type: 'float' }
35
+ ]
36
+ } );
37
+
38
+ // source: http://filmicworlds.com/blog/filmic-tonemapping-operators/
39
+
40
+ export const CineonToneMapping = /*@__PURE__*/ Fn( ( [ color, exposure ] ) => {
41
+
42
+ // filmic operator by Jim Hejl and Richard Burgess-Dawson
43
+ color = color.mul( exposure );
44
+ color = color.sub( 0.004 ).max( 0.0 );
45
+
46
+ const a = color.mul( color.mul( 6.2 ).add( 0.5 ) );
47
+ const b = color.mul( color.mul( 6.2 ).add( 1.7 ) ).add( 0.06 );
48
+
49
+ return a.div( b ).pow( 2.2 );
50
+
51
+ } ).setLayout( {
52
+ name: 'CineonToneMapping',
53
+ type: 'vec3',
54
+ inputs: [
55
+ { name: 'color', type: 'vec3' },
56
+ { name: 'exposure', type: 'float' }
57
+ ]
58
+ } );
59
+
60
+ // source: https://github.com/selfshadow/ltc_code/blob/master/webgl/shaders/ltc/ltc_blit.fs
61
+
62
+ const RRTAndODTFit = /*@__PURE__*/ Fn( ( [ color ] ) => {
63
+
64
+ const a = color.mul( color.add( 0.0245786 ) ).sub( 0.000090537 );
65
+ const b = color.mul( color.add( 0.4329510 ).mul( 0.983729 ) ).add( 0.238081 );
66
+
67
+ return a.div( b );
68
+
69
+ } );
70
+
71
+ // source: https://github.com/selfshadow/ltc_code/blob/master/webgl/shaders/ltc/ltc_blit.fs
72
+
73
+ export const ACESFilmicToneMapping = /*@__PURE__*/ Fn( ( [ color, exposure ] ) => {
74
+
75
+ // sRGB => XYZ => D65_2_D60 => AP1 => RRT_SAT
76
+ const ACESInputMat = mat3(
77
+ 0.59719, 0.35458, 0.04823,
78
+ 0.07600, 0.90834, 0.01566,
79
+ 0.02840, 0.13383, 0.83777
80
+ );
81
+
82
+ // ODT_SAT => XYZ => D60_2_D65 => sRGB
83
+ const ACESOutputMat = mat3(
84
+ 1.60475, - 0.53108, - 0.07367,
85
+ - 0.10208, 1.10813, - 0.00605,
86
+ - 0.00327, - 0.07276, 1.07602
87
+ );
88
+
89
+ color = color.mul( exposure ).div( 0.6 );
90
+
91
+ color = ACESInputMat.mul( color );
92
+
93
+ // Apply RRT and ODT
94
+ color = RRTAndODTFit( color );
95
+
96
+ color = ACESOutputMat.mul( color );
97
+
98
+ // Clamp to [0, 1]
99
+ return color.clamp();
100
+
101
+ } ).setLayout( {
102
+ name: 'ACESFilmicToneMapping',
103
+ type: 'vec3',
104
+ inputs: [
105
+ { name: 'color', type: 'vec3' },
106
+ { name: 'exposure', type: 'float' }
107
+ ]
108
+ } );
109
+
110
+ const LINEAR_REC2020_TO_LINEAR_SRGB = /*@__PURE__*/ mat3( vec3( 1.6605, - 0.1246, - 0.0182 ), vec3( - 0.5876, 1.1329, - 0.1006 ), vec3( - 0.0728, - 0.0083, 1.1187 ) );
111
+ const LINEAR_SRGB_TO_LINEAR_REC2020 = /*@__PURE__*/ mat3( vec3( 0.6274, 0.0691, 0.0164 ), vec3( 0.3293, 0.9195, 0.0880 ), vec3( 0.0433, 0.0113, 0.8956 ) );
112
+
113
+ const agxDefaultContrastApprox = /*@__PURE__*/ Fn( ( [ x_immutable ] ) => {
114
+
115
+ const x = vec3( x_immutable ).toVar();
116
+ const x2 = vec3( x.mul( x ) ).toVar();
117
+ const x4 = vec3( x2.mul( x2 ) ).toVar();
118
+
119
+ return float( 15.5 ).mul( x4.mul( x2 ) ).sub( mul( 40.14, x4.mul( x ) ) ).add( mul( 31.96, x4 ).sub( mul( 6.868, x2.mul( x ) ) ).add( mul( 0.4298, x2 ).add( mul( 0.1191, x ).sub( 0.00232 ) ) ) );
120
+
121
+ } );
122
+
123
+ export const AgXToneMapping = /*@__PURE__*/ Fn( ( [ color, exposure ] ) => {
124
+
125
+ const colortone = vec3( color ).toVar();
126
+ const AgXInsetMatrix = mat3( vec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ), vec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ), vec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 ) );
127
+ const AgXOutsetMatrix = mat3( vec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ), vec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ), vec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 ) );
128
+ const AgxMinEv = float( - 12.47393 );
129
+ const AgxMaxEv = float( 4.026069 );
130
+ colortone.mulAssign( exposure );
131
+ colortone.assign( LINEAR_SRGB_TO_LINEAR_REC2020.mul( colortone ) );
132
+ colortone.assign( AgXInsetMatrix.mul( colortone ) );
133
+ colortone.assign( max( colortone, 1e-10 ) );
134
+ colortone.assign( log2( colortone ) );
135
+ colortone.assign( colortone.sub( AgxMinEv ).div( AgxMaxEv.sub( AgxMinEv ) ) );
136
+ colortone.assign( clamp( colortone, 0.0, 1.0 ) );
137
+ colortone.assign( agxDefaultContrastApprox( colortone ) );
138
+ colortone.assign( AgXOutsetMatrix.mul( colortone ) );
139
+ colortone.assign( pow( max( vec3( 0.0 ), colortone ), vec3( 2.2 ) ) );
140
+ colortone.assign( LINEAR_REC2020_TO_LINEAR_SRGB.mul( colortone ) );
141
+ colortone.assign( clamp( colortone, 0.0, 1.0 ) );
142
+
143
+ return colortone;
144
+
145
+ } ).setLayout( {
146
+ name: 'AgXToneMapping',
147
+ type: 'vec3',
148
+ inputs: [
149
+ { name: 'color', type: 'vec3' },
150
+ { name: 'exposure', type: 'float' }
151
+ ]
152
+ } );
153
+
154
+ // https://modelviewer.dev/examples/tone-mapping
155
+
156
+ export const NeutralToneMapping = /*@__PURE__*/ Fn( ( [ color, exposure ] ) => {
157
+
158
+ const StartCompression = float( 0.8 - 0.04 );
159
+ const Desaturation = float( 0.15 );
160
+
161
+ color = color.mul( exposure );
162
+
163
+ const x = min( color.r, min( color.g, color.b ) );
164
+ const offset = select( x.lessThan( 0.08 ), x.sub( mul( 6.25, x.mul( x ) ) ), 0.04 );
165
+
166
+ color.subAssign( offset );
167
+
168
+ const peak = max( color.r, max( color.g, color.b ) );
169
+
170
+ If( peak.lessThan( StartCompression ), () => {
171
+
172
+ return color;
173
+
174
+ } );
175
+
176
+ const d = sub( 1, StartCompression );
177
+ const newPeak = sub( 1, d.mul( d ).div( peak.add( d.sub( StartCompression ) ) ) );
178
+ color.mulAssign( newPeak.div( peak ) );
179
+ const g = sub( 1, div( 1, Desaturation.mul( peak.sub( newPeak ) ).add( 1 ) ) );
180
+
181
+ return mix( color, vec3( newPeak ), g );
182
+
183
+ } ).setLayout( {
184
+ name: 'NeutralToneMapping',
185
+ type: 'vec3',
186
+ inputs: [
187
+ { name: 'color', type: 'vec3' },
188
+ { name: 'exposure', type: 'float' }
189
+ ]
190
+ } );
@@ -1,173 +1,13 @@
1
+ import { registerNode } from '../core/Node.js';
1
2
  import TempNode from '../core/TempNode.js';
2
- import { addNodeClass } from '../core/Node.js';
3
- import { addNodeElement, tslFn, nodeObject, float, mat3, vec3, If } from '../shadernode/ShaderNode.js';
3
+ import { addMethodChaining, nodeObject, vec4 } from '../tsl/TSLCore.js';
4
4
  import { rendererReference } from '../accessors/RendererReferenceNode.js';
5
- import { cond } from '../math/CondNode.js';
6
- import { clamp, log2, max, min, pow, mix } from '../math/MathNode.js';
7
- import { mul, sub, div } from '../math/OperatorNode.js';
8
5
 
9
- import { NoToneMapping, LinearToneMapping, ReinhardToneMapping, CineonToneMapping, ACESFilmicToneMapping, AgXToneMapping, NeutralToneMapping } from '../../constants.js';
10
-
11
- // exposure only
12
- const LinearToneMappingNode = tslFn( ( { color, exposure } ) => {
13
-
14
- return color.mul( exposure ).clamp();
15
-
16
- } );
17
-
18
- // source: https://www.cs.utah.edu/docs/techreports/2002/pdf/UUCS-02-001.pdf
19
- const ReinhardToneMappingNode = tslFn( ( { color, exposure } ) => {
20
-
21
- color = color.mul( exposure );
22
-
23
- return color.div( color.add( 1.0 ) ).clamp();
24
-
25
- } );
26
-
27
- // source: http://filmicworlds.com/blog/filmic-tonemapping-operators/
28
- const OptimizedCineonToneMappingNode = tslFn( ( { color, exposure } ) => {
29
-
30
- // optimized filmic operator by Jim Hejl and Richard Burgess-Dawson
31
- color = color.mul( exposure );
32
- color = color.sub( 0.004 ).max( 0.0 );
33
-
34
- const a = color.mul( color.mul( 6.2 ).add( 0.5 ) );
35
- const b = color.mul( color.mul( 6.2 ).add( 1.7 ) ).add( 0.06 );
36
-
37
- return a.div( b ).pow( 2.2 );
38
-
39
- } );
40
-
41
- // source: https://github.com/selfshadow/ltc_code/blob/master/webgl/shaders/ltc/ltc_blit.fs
42
- const RRTAndODTFit = tslFn( ( { color } ) => {
43
-
44
- const a = color.mul( color.add( 0.0245786 ) ).sub( 0.000090537 );
45
- const b = color.mul( color.add( 0.4329510 ).mul( 0.983729 ) ).add( 0.238081 );
46
-
47
- return a.div( b );
48
-
49
- } );
50
-
51
- // source: https://github.com/selfshadow/ltc_code/blob/master/webgl/shaders/ltc/ltc_blit.fs
52
- const ACESFilmicToneMappingNode = tslFn( ( { color, exposure } ) => {
53
-
54
- // sRGB => XYZ => D65_2_D60 => AP1 => RRT_SAT
55
- const ACESInputMat = mat3(
56
- 0.59719, 0.35458, 0.04823,
57
- 0.07600, 0.90834, 0.01566,
58
- 0.02840, 0.13383, 0.83777
59
- );
60
-
61
- // ODT_SAT => XYZ => D60_2_D65 => sRGB
62
- const ACESOutputMat = mat3(
63
- 1.60475, - 0.53108, - 0.07367,
64
- - 0.10208, 1.10813, - 0.00605,
65
- - 0.00327, - 0.07276, 1.07602
66
- );
67
-
68
- color = color.mul( exposure ).div( 0.6 );
69
-
70
- color = ACESInputMat.mul( color );
71
-
72
- // Apply RRT and ODT
73
- color = RRTAndODTFit( { color } );
74
-
75
- color = ACESOutputMat.mul( color );
76
-
77
- // Clamp to [0, 1]
78
- return color.clamp();
79
-
80
- } );
81
-
82
-
83
-
84
- const LINEAR_REC2020_TO_LINEAR_SRGB = mat3( vec3( 1.6605, - 0.1246, - 0.0182 ), vec3( - 0.5876, 1.1329, - 0.1006 ), vec3( - 0.0728, - 0.0083, 1.1187 ) );
85
- const LINEAR_SRGB_TO_LINEAR_REC2020 = mat3( vec3( 0.6274, 0.0691, 0.0164 ), vec3( 0.3293, 0.9195, 0.0880 ), vec3( 0.0433, 0.0113, 0.8956 ) );
86
-
87
- const agxDefaultContrastApprox = tslFn( ( [ x_immutable ] ) => {
88
-
89
- const x = vec3( x_immutable ).toVar();
90
- const x2 = vec3( x.mul( x ) ).toVar();
91
- const x4 = vec3( x2.mul( x2 ) ).toVar();
92
-
93
- return float( 15.5 ).mul( x4.mul( x2 ) ).sub( mul( 40.14, x4.mul( x ) ) ).add( mul( 31.96, x4 ).sub( mul( 6.868, x2.mul( x ) ) ).add( mul( 0.4298, x2 ).add( mul( 0.1191, x ).sub( 0.00232 ) ) ) );
94
-
95
- } );
96
-
97
- const AGXToneMappingNode = tslFn( ( { color, exposure } ) => {
98
-
99
- const colortone = vec3( color ).toVar();
100
- const AgXInsetMatrix = mat3( vec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ), vec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ), vec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 ) );
101
- const AgXOutsetMatrix = mat3( vec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ), vec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ), vec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 ) );
102
- const AgxMinEv = float( - 12.47393 );
103
- const AgxMaxEv = float( 4.026069 );
104
- colortone.mulAssign( exposure );
105
- colortone.assign( LINEAR_SRGB_TO_LINEAR_REC2020.mul( colortone ) );
106
- colortone.assign( AgXInsetMatrix.mul( colortone ) );
107
- colortone.assign( max( colortone, 1e-10 ) );
108
- colortone.assign( log2( colortone ) );
109
- colortone.assign( colortone.sub( AgxMinEv ).div( AgxMaxEv.sub( AgxMinEv ) ) );
110
- colortone.assign( clamp( colortone, 0.0, 1.0 ) );
111
- colortone.assign( agxDefaultContrastApprox( colortone ) );
112
- colortone.assign( AgXOutsetMatrix.mul( colortone ) );
113
- colortone.assign( pow( max( vec3( 0.0 ), colortone ), vec3( 2.2 ) ) );
114
- colortone.assign( LINEAR_REC2020_TO_LINEAR_SRGB.mul( colortone ) );
115
- colortone.assign( clamp( colortone, 0.0, 1.0 ) );
116
-
117
- return colortone;
118
-
119
- } );
120
-
121
- // https://modelviewer.dev/examples/tone-mapping
122
-
123
- const NeutralToneMappingNode = tslFn( ( { color, exposure } ) => {
124
-
125
- const StartCompression = float( 0.8 - 0.04 );
126
- const Desaturation = float( 0.15 );
127
-
128
- color = color.mul( exposure );
129
-
130
- const x = min( color.r, min( color.g, color.b ) );
131
- const offset = cond( x.lessThan( 0.08 ), x.sub( mul( 6.25, x.mul( x ) ) ), 0.04 );
132
-
133
- color.subAssign( offset );
134
-
135
- const peak = max( color.r, max( color.g, color.b ) );
136
-
137
- If( peak.lessThan( StartCompression ), () => {
138
-
139
- return color;
140
-
141
- } );
142
-
143
- const d = sub( 1, StartCompression );
144
- const newPeak = sub( 1, d.mul( d ).div( peak.add( d.sub( StartCompression ) ) ) );
145
- color.mulAssign( newPeak.div( peak ) );
146
- const g = sub( 1, div( 1, Desaturation.mul( peak.sub( newPeak ) ).add( 1 ) ) );
147
-
148
- return mix( color, vec3( newPeak ), g );
149
-
150
- } ).setLayout( {
151
- name: 'NeutralToneMapping',
152
- type: 'vec3',
153
- inputs: [
154
- { name: 'color', type: 'vec3' },
155
- { name: 'exposure', type: 'float' }
156
- ]
157
- } );
158
-
159
- const toneMappingLib = {
160
- [ LinearToneMapping ]: LinearToneMappingNode,
161
- [ ReinhardToneMapping ]: ReinhardToneMappingNode,
162
- [ CineonToneMapping ]: OptimizedCineonToneMappingNode,
163
- [ ACESFilmicToneMapping ]: ACESFilmicToneMappingNode,
164
- [ AgXToneMapping ]: AGXToneMappingNode,
165
- [ NeutralToneMapping ]: NeutralToneMappingNode
166
- };
6
+ import { NoToneMapping } from '../../constants.js';
167
7
 
168
8
  class ToneMappingNode extends TempNode {
169
9
 
170
- constructor( toneMapping = NoToneMapping, exposureNode = toneMappingExposure, colorNode = null ) {
10
+ constructor( toneMapping, exposureNode = toneMappingExposure, colorNode = null ) {
171
11
 
172
12
  super( 'vec3' );
173
13
 
@@ -194,14 +34,13 @@ class ToneMappingNode extends TempNode {
194
34
 
195
35
  if ( toneMapping === NoToneMapping ) return colorNode;
196
36
 
197
- const toneMappingParams = { exposure: this.exposureNode, color: colorNode };
198
- const toneMappingNode = toneMappingLib[ toneMapping ];
199
-
200
37
  let outputNode = null;
201
38
 
202
- if ( toneMappingNode ) {
39
+ const toneMappingFn = builder.renderer.nodes.library.getToneMappingFunction( toneMapping );
203
40
 
204
- outputNode = toneMappingNode( toneMappingParams );
41
+ if ( toneMappingFn !== null ) {
42
+
43
+ outputNode = vec4( toneMappingFn( colorNode.rgb, this.exposureNode ), colorNode.a );
205
44
 
206
45
  } else {
207
46
 
@@ -219,9 +58,9 @@ class ToneMappingNode extends TempNode {
219
58
 
220
59
  export default ToneMappingNode;
221
60
 
222
- export const toneMapping = ( mapping, exposure, color ) => nodeObject( new ToneMappingNode( mapping, nodeObject( exposure ), nodeObject( color ) ) );
223
- export const toneMappingExposure = rendererReference( 'toneMappingExposure', 'float' );
61
+ ToneMappingNode.type = /*@__PURE__*/ registerNode( 'ToneMapping', ToneMappingNode );
224
62
 
225
- addNodeElement( 'toneMapping', ( color, mapping, exposure ) => toneMapping( mapping, exposure, color ) );
63
+ export const toneMapping = ( mapping, exposure, color ) => nodeObject( new ToneMappingNode( mapping, nodeObject( exposure ), nodeObject( color ) ) );
64
+ export const toneMappingExposure = /*@__PURE__*/ rendererReference( 'toneMappingExposure', 'float' );
226
65
 
227
- addNodeClass( 'ToneMappingNode', ToneMappingNode );
66
+ addMethodChaining( 'toneMapping', ( color, mapping, exposure ) => toneMapping( mapping, exposure, color ) );
@@ -1,8 +1,10 @@
1
+ import { registerNode } from '../core/Node.js';
1
2
  import TempNode from '../core/TempNode.js';
2
- import { uv } from '../accessors/UVNode.js';
3
- import { addNodeElement, tslFn, nodeObject, float, int, vec4, If } from '../shadernode/ShaderNode.js';
3
+ import { uv } from '../accessors/UV.js';
4
+ import { Fn, nodeObject, float, int, vec4, If } from '../tsl/TSLBase.js';
4
5
  import { clamp, mix } from '../math/MathNode.js';
5
6
  import { sub } from '../math/OperatorNode.js';
7
+ import { convertToTexture } from '../utils/RTTNode.js';
6
8
 
7
9
  class TransitionNode extends TempNode {
8
10
 
@@ -35,7 +37,7 @@ class TransitionNode extends TempNode {
35
37
 
36
38
  };
37
39
 
38
- const transition = tslFn( () => {
40
+ const transition = Fn( () => {
39
41
 
40
42
  const texelOne = sampleTexture( textureNodeA );
41
43
  const texelTwo = sampleTexture( textureNodeB );
@@ -50,7 +52,7 @@ class TransitionNode extends TempNode {
50
52
 
51
53
  color.assign( mix( texelOne, texelTwo, mixf ) );
52
54
 
53
- } ).else( () => {
55
+ } ).Else( () => {
54
56
 
55
57
  color.assign( mix( texelTwo, texelOne, mixRatioNode ) );
56
58
 
@@ -68,9 +70,8 @@ class TransitionNode extends TempNode {
68
70
 
69
71
  }
70
72
 
71
- export const transition = ( nodeA, nodeB, mixTexture, mixRatio = 0.0, threshold = 0.1, useTexture = 0 ) => nodeObject( new TransitionNode( nodeObject( nodeA ).toTexture(), nodeObject( nodeB ).toTexture(), nodeObject( mixTexture ).toTexture(), nodeObject( mixRatio ), nodeObject( threshold ), nodeObject( useTexture ) ) );
72
-
73
- addNodeElement( 'transition', transition );
74
-
75
73
  export default TransitionNode;
76
74
 
75
+ TransitionNode.type = /*@__PURE__*/ registerNode( 'Transition', TransitionNode );
76
+
77
+ export const transition = ( nodeA, nodeB, mixTexture, mixRatio = 0.0, threshold = 0.1, useTexture = 0 ) => nodeObject( new TransitionNode( convertToTexture( nodeA ), convertToTexture( nodeB ), convertToTexture( mixTexture ), nodeObject( mixRatio ), nodeObject( threshold ), nodeObject( useTexture ) ) );
@@ -1,7 +1,7 @@
1
- import Node, { addNodeClass } from '../core/Node.js';
2
- import { nodeImmutable, nodeProxy } from '../shadernode/ShaderNode.js';
3
- import { cameraNear, cameraFar } from '../accessors/CameraNode.js';
4
- import { positionView } from '../accessors/PositionNode.js';
1
+ import Node, { registerNode } from '../core/Node.js';
2
+ import { nodeImmutable, nodeProxy } from '../tsl/TSLBase.js';
3
+ import { cameraNear, cameraFar } from '../accessors/Camera.js';
4
+ import { positionView } from '../accessors/Position.js';
5
5
  import { viewportDepthTexture } from './ViewportDepthTextureNode.js';
6
6
 
7
7
  class ViewportDepthNode extends Node {
@@ -21,7 +21,7 @@ class ViewportDepthNode extends Node {
21
21
 
22
22
  const { scope } = this;
23
23
 
24
- if ( scope === ViewportDepthNode.DEPTH ) {
24
+ if ( scope === ViewportDepthNode.DEPTH_BASE ) {
25
25
 
26
26
  return builder.getFragDepth();
27
27
 
@@ -34,43 +34,43 @@ class ViewportDepthNode extends Node {
34
34
  setup( { camera } ) {
35
35
 
36
36
  const { scope } = this;
37
- const texture = this.valueNode;
37
+ const value = this.valueNode;
38
38
 
39
39
  let node = null;
40
40
 
41
- if ( scope === ViewportDepthNode.DEPTH ) {
41
+ if ( scope === ViewportDepthNode.DEPTH_BASE ) {
42
42
 
43
- if ( texture !== null ) {
43
+ if ( value !== null ) {
44
44
 
45
- node = depthBase().assign( texture );
45
+ node = depthBase().assign( value );
46
46
 
47
- } else {
47
+ }
48
48
 
49
- if ( camera.isPerspectiveCamera ) {
49
+ } else if ( scope === ViewportDepthNode.DEPTH ) {
50
50
 
51
- node = viewZToPerspectiveDepth( positionView.z, cameraNear, cameraFar );
51
+ if ( camera.isPerspectiveCamera ) {
52
52
 
53
- } else {
53
+ node = viewZToPerspectiveDepth( positionView.z, cameraNear, cameraFar );
54
54
 
55
- node = viewZToOrthographicDepth( positionView.z, cameraNear, cameraFar );
55
+ } else {
56
56
 
57
- }
57
+ node = viewZToOrthographicDepth( positionView.z, cameraNear, cameraFar );
58
58
 
59
59
  }
60
60
 
61
61
  } else if ( scope === ViewportDepthNode.LINEAR_DEPTH ) {
62
62
 
63
- if ( texture !== null ) {
63
+ if ( value !== null ) {
64
64
 
65
65
  if ( camera.isPerspectiveCamera ) {
66
66
 
67
- const viewZ = perspectiveDepthToViewZ( texture, cameraNear, cameraFar );
67
+ const viewZ = perspectiveDepthToViewZ( value, cameraNear, cameraFar );
68
68
 
69
69
  node = viewZToOrthographicDepth( viewZ, cameraNear, cameraFar );
70
70
 
71
71
  } else {
72
72
 
73
- node = texture;
73
+ node = value;
74
74
 
75
75
  }
76
76
 
@@ -88,6 +88,14 @@ class ViewportDepthNode extends Node {
88
88
 
89
89
  }
90
90
 
91
+ ViewportDepthNode.DEPTH_BASE = 'depthBase';
92
+ ViewportDepthNode.DEPTH = 'depth';
93
+ ViewportDepthNode.LINEAR_DEPTH = 'linearDepth';
94
+
95
+ export default ViewportDepthNode;
96
+
97
+ ViewportDepthNode.type = /*@__PURE__*/ registerNode( 'ViewportDepth', ViewportDepthNode );
98
+
91
99
  // NOTE: viewZ, the z-coordinate in camera space, is negative for points in front of the camera
92
100
 
93
101
  // -near maps to 0; -far maps to 1
@@ -104,17 +112,10 @@ export const viewZToPerspectiveDepth = ( viewZ, near, far ) => near.add( viewZ )
104
112
  // maps perspective depth in [ 0, 1 ] to viewZ
105
113
  export const perspectiveDepthToViewZ = ( depth, near, far ) => near.mul( far ).div( far.sub( near ).mul( depth ).sub( far ) );
106
114
 
107
- ViewportDepthNode.DEPTH = 'depth';
108
- ViewportDepthNode.LINEAR_DEPTH = 'linearDepth';
115
+ const depthBase = /*@__PURE__*/ nodeProxy( ViewportDepthNode, ViewportDepthNode.DEPTH_BASE );
109
116
 
110
- export default ViewportDepthNode;
111
-
112
- const depthBase = nodeProxy( ViewportDepthNode, ViewportDepthNode.DEPTH );
113
-
114
- export const depth = nodeImmutable( ViewportDepthNode, ViewportDepthNode.DEPTH );
115
- export const linearDepth = nodeProxy( ViewportDepthNode, ViewportDepthNode.LINEAR_DEPTH );
116
- export const viewportLinearDepth = linearDepth( viewportDepthTexture() );
117
+ export const depth = /*@__PURE__*/ nodeImmutable( ViewportDepthNode, ViewportDepthNode.DEPTH );
118
+ export const linearDepth = /*@__PURE__*/ nodeProxy( ViewportDepthNode, ViewportDepthNode.LINEAR_DEPTH );
119
+ export const viewportLinearDepth = /*@__PURE__*/ linearDepth( viewportDepthTexture() );
117
120
 
118
121
  depth.assign = ( value ) => depthBase( value );
119
-
120
- addNodeClass( 'ViewportDepthNode', ViewportDepthNode );
@@ -1,7 +1,7 @@
1
+ import { registerNode } from '../core/Node.js';
1
2
  import ViewportTextureNode from './ViewportTextureNode.js';
2
- import { addNodeClass } from '../core/Node.js';
3
- import { addNodeElement, nodeProxy } from '../shadernode/ShaderNode.js';
4
- import { viewportTopLeft } from './ViewportNode.js';
3
+ import { nodeProxy } from '../tsl/TSLBase.js';
4
+ import { viewportUV } from './ViewportNode.js';
5
5
 
6
6
  import { DepthTexture } from '../../textures/DepthTexture.js';
7
7
 
@@ -9,7 +9,7 @@ let sharedDepthbuffer = null;
9
9
 
10
10
  class ViewportDepthTextureNode extends ViewportTextureNode {
11
11
 
12
- constructor( uvNode = viewportTopLeft, levelNode = null ) {
12
+ constructor( uvNode = viewportUV, levelNode = null ) {
13
13
 
14
14
  if ( sharedDepthbuffer === null ) {
15
15
 
@@ -25,8 +25,6 @@ class ViewportDepthTextureNode extends ViewportTextureNode {
25
25
 
26
26
  export default ViewportDepthTextureNode;
27
27
 
28
- export const viewportDepthTexture = nodeProxy( ViewportDepthTextureNode );
28
+ ViewportDepthTextureNode.type = /*@__PURE__*/ registerNode( 'ViewportDepthTexture', ViewportDepthTextureNode );
29
29
 
30
- addNodeElement( 'viewportDepthTexture', viewportDepthTexture );
31
-
32
- addNodeClass( 'ViewportDepthTextureNode', ViewportDepthTextureNode );
30
+ export const viewportDepthTexture = /*@__PURE__*/ nodeProxy( ViewportDepthTextureNode );
@@ -1,7 +1,7 @@
1
- import Node, { addNodeClass } from '../core/Node.js';
1
+ import Node, { registerNode } from '../core/Node.js';
2
2
  import { NodeUpdateType } from '../core/constants.js';
3
3
  import { uniform } from '../core/UniformNode.js';
4
- import { nodeImmutable, vec2 } from '../shadernode/ShaderNode.js';
4
+ import { Fn, nodeImmutable, vec2 } from '../tsl/TSLBase.js';
5
5
 
6
6
  import { Vector2 } from '../../math/Vector2.js';
7
7
  import { Vector4 } from '../../math/Vector4.js';
@@ -23,7 +23,6 @@ class ViewportNode extends Node {
23
23
  getNodeType() {
24
24
 
25
25
  if ( this.scope === ViewportNode.VIEWPORT ) return 'vec4';
26
- else if ( this.scope === ViewportNode.COORDINATE ) return 'vec3';
27
26
  else return 'vec2';
28
27
 
29
28
  }
@@ -74,15 +73,7 @@ class ViewportNode extends Node {
74
73
 
75
74
  } else {
76
75
 
77
- output = viewportCoordinate.div( viewportResolution );
78
-
79
- let outX = output.x;
80
- let outY = output.y;
81
-
82
- if ( /bottom/i.test( scope ) ) outY = outY.oneMinus();
83
- if ( /right/i.test( scope ) ) outX = outX.oneMinus();
84
-
85
- output = vec2( outX, outY );
76
+ output = vec2( viewportCoordinate.div( viewportResolution ) );
86
77
 
87
78
  }
88
79
 
@@ -102,7 +93,7 @@ class ViewportNode extends Node {
102
93
 
103
94
  const resolution = builder.getNodeProperties( viewportResolution ).outputNode.build( builder );
104
95
 
105
- coord = `${ builder.getType( 'vec3' ) }( ${ coord }.x, ${ resolution }.y - ${ coord }.y, ${ coord }.z )`;
96
+ coord = `${ builder.getType( 'vec2' ) }( ${ coord }.x, ${ resolution }.y - ${ coord }.y )`;
106
97
 
107
98
  }
108
99
 
@@ -119,19 +110,29 @@ class ViewportNode extends Node {
119
110
  ViewportNode.COORDINATE = 'coordinate';
120
111
  ViewportNode.RESOLUTION = 'resolution';
121
112
  ViewportNode.VIEWPORT = 'viewport';
122
- ViewportNode.TOP_LEFT = 'topLeft';
123
- ViewportNode.BOTTOM_LEFT = 'bottomLeft';
124
- ViewportNode.TOP_RIGHT = 'topRight';
125
- ViewportNode.BOTTOM_RIGHT = 'bottomRight';
113
+ ViewportNode.UV = 'uv';
126
114
 
127
115
  export default ViewportNode;
128
116
 
129
- export const viewportCoordinate = nodeImmutable( ViewportNode, ViewportNode.COORDINATE );
130
- export const viewportResolution = nodeImmutable( ViewportNode, ViewportNode.RESOLUTION );
131
- export const viewport = nodeImmutable( ViewportNode, ViewportNode.VIEWPORT );
132
- export const viewportTopLeft = nodeImmutable( ViewportNode, ViewportNode.TOP_LEFT );
133
- export const viewportBottomLeft = nodeImmutable( ViewportNode, ViewportNode.BOTTOM_LEFT );
134
- export const viewportTopRight = nodeImmutable( ViewportNode, ViewportNode.TOP_RIGHT );
135
- export const viewportBottomRight = nodeImmutable( ViewportNode, ViewportNode.BOTTOM_RIGHT );
117
+ ViewportNode.type = /*@__PURE__*/ registerNode( 'Viewport', ViewportNode );
118
+
119
+ export const viewportCoordinate = /*@__PURE__*/ nodeImmutable( ViewportNode, ViewportNode.COORDINATE );
120
+ export const viewportResolution = /*@__PURE__*/ nodeImmutable( ViewportNode, ViewportNode.RESOLUTION );
121
+ export const viewport = /*@__PURE__*/ nodeImmutable( ViewportNode, ViewportNode.VIEWPORT );
122
+ export const viewportUV = /*@__PURE__*/ nodeImmutable( ViewportNode, ViewportNode.UV );
123
+
124
+ export const viewportTopLeft = /*@__PURE__*/ ( Fn( () => { // @deprecated, r168
125
+
126
+ console.warn( 'TSL.ViewportNode: "viewportTopLeft" is deprecated. Use "viewportUV" instead.' );
127
+
128
+ return viewportUV;
129
+
130
+ }, 'vec2' ).once() )();
131
+
132
+ export const viewportBottomLeft = /*@__PURE__*/ ( Fn( () => { // @deprecated, r168
133
+
134
+ console.warn( 'TSL.ViewportNode: "viewportBottomLeft" is deprecated. Use "viewportUV.flipY()" instead.' );
135
+
136
+ return viewportUV.flipY();
136
137
 
137
- addNodeClass( 'ViewportNode', ViewportNode );
138
+ }, 'vec2' ).once() )();