@plastic-software/three 0.167.1 → 0.167.3

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 (94) hide show
  1. package/build/three.cjs +17 -8
  2. package/build/three.module.js +17 -8
  3. package/build/three.module.min.js +1 -1
  4. package/build/three.webgpu.js +746 -374
  5. package/build/three.webgpu.min.js +1 -1
  6. package/examples/jsm/controls/Controls.js +32 -0
  7. package/examples/jsm/controls/DragControls.js +260 -132
  8. package/examples/jsm/transpiler/TSLEncoder.js +8 -8
  9. package/package.json +1 -1
  10. package/src/loaders/ObjectLoader.js +3 -3
  11. package/src/nodes/Nodes.js +3 -2
  12. package/src/nodes/accessors/BatchNode.js +2 -2
  13. package/src/nodes/accessors/ClippingNode.js +8 -8
  14. package/src/nodes/accessors/MorphNode.js +4 -4
  15. package/src/nodes/accessors/TangentNode.js +2 -2
  16. package/src/nodes/accessors/Texture3DNode.js +8 -8
  17. package/src/nodes/accessors/UniformArrayNode.js +5 -3
  18. package/src/nodes/core/StackNode.js +22 -6
  19. package/src/nodes/display/AfterImageNode.js +3 -3
  20. package/src/nodes/display/AnamorphicNode.js +4 -4
  21. package/src/nodes/display/BleachBypassNode.js +2 -2
  22. package/src/nodes/display/BlendModeNode.js +8 -8
  23. package/src/nodes/display/BloomNode.js +9 -9
  24. package/src/nodes/display/BumpMapNode.js +3 -3
  25. package/src/nodes/display/ColorAdjustmentNode.js +4 -4
  26. package/src/nodes/display/ColorSpaceNode.js +3 -3
  27. package/src/nodes/display/DenoiseNode.js +8 -8
  28. package/src/nodes/display/DepthOfFieldNode.js +2 -2
  29. package/src/nodes/display/DotScreenNode.js +3 -3
  30. package/src/nodes/display/FXAANode.js +11 -11
  31. package/src/nodes/display/FilmNode.js +2 -2
  32. package/src/nodes/display/GTAONode.js +9 -9
  33. package/src/nodes/display/GaussianBlurNode.js +2 -2
  34. package/src/nodes/display/Lut3DNode.js +2 -2
  35. package/src/nodes/display/NormalMapNode.js +2 -2
  36. package/src/nodes/display/PassNode.js +71 -3
  37. package/src/nodes/display/PixelationPassNode.js +3 -3
  38. package/src/nodes/display/RGBShiftNode.js +2 -2
  39. package/src/nodes/display/SepiaNode.js +2 -2
  40. package/src/nodes/display/SobelOperatorNode.js +2 -2
  41. package/src/nodes/display/ToneMappingNode.js +13 -13
  42. package/src/nodes/display/TransitionNode.js +3 -3
  43. package/src/nodes/functions/BSDF/BRDF_GGX.js +2 -2
  44. package/src/nodes/functions/BSDF/BRDF_Lambert.js +2 -2
  45. package/src/nodes/functions/BSDF/BRDF_Sheen.js +4 -4
  46. package/src/nodes/functions/BSDF/DFGApprox.js +2 -2
  47. package/src/nodes/functions/BSDF/D_GGX.js +2 -2
  48. package/src/nodes/functions/BSDF/D_GGX_Anisotropic.js +2 -2
  49. package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
  50. package/src/nodes/functions/BSDF/F_Schlick.js +2 -2
  51. package/src/nodes/functions/BSDF/LTC.js +6 -6
  52. package/src/nodes/functions/BSDF/Schlick_to_F0.js +2 -2
  53. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +2 -2
  54. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +2 -2
  55. package/src/nodes/functions/PhongLightingModel.js +3 -3
  56. package/src/nodes/functions/PhysicalLightingModel.js +18 -18
  57. package/src/nodes/functions/ToonLightingModel.js +2 -2
  58. package/src/nodes/functions/material/getGeometryRoughness.js +2 -2
  59. package/src/nodes/functions/material/getRoughness.js +2 -2
  60. package/src/nodes/lighting/AnalyticLightNode.js +5 -5
  61. package/src/nodes/lighting/BasicEnvironmentNode.js +2 -1
  62. package/src/nodes/lighting/LightProbeNode.js +80 -0
  63. package/src/nodes/lighting/LightUtils.js +3 -3
  64. package/src/nodes/materials/InstancedPointsNodeMaterial.js +3 -3
  65. package/src/nodes/materials/Line2NodeMaterial.js +17 -17
  66. package/src/nodes/materials/MeshPhysicalNodeMaterial.js +1 -1
  67. package/src/nodes/materials/VolumeNodeMaterial.js +5 -5
  68. package/src/nodes/materialx/lib/mx_hsv.js +12 -12
  69. package/src/nodes/materialx/lib/mx_noise.js +80 -80
  70. package/src/nodes/materialx/lib/mx_transform_color.js +2 -2
  71. package/src/nodes/math/CondNode.js +13 -2
  72. package/src/nodes/math/MathNode.js +2 -2
  73. package/src/nodes/math/TriNoise3D.js +6 -6
  74. package/src/nodes/pmrem/PMREMUtils.js +34 -34
  75. package/src/nodes/procedural/CheckerNode.js +2 -2
  76. package/src/nodes/shadernode/ShaderNode.js +11 -4
  77. package/src/nodes/utils/CubeMapNode.js +157 -0
  78. package/src/nodes/utils/LoopNode.js +10 -4
  79. package/src/nodes/utils/SpriteUtils.js +2 -2
  80. package/src/nodes/utils/UVUtils.js +3 -3
  81. package/src/nodes/utils/ViewportUtils.js +3 -3
  82. package/src/renderers/WebGLRenderer.js +8 -0
  83. package/src/renderers/common/RenderContext.js +24 -0
  84. package/src/renderers/common/RenderObject.js +1 -1
  85. package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +1 -1
  86. package/src/renderers/shaders/ShaderChunk/batching_vertex.glsl.js +1 -1
  87. package/src/renderers/shaders/ShaderLib/linedashed.glsl.js +0 -2
  88. package/src/renderers/shaders/ShaderLib/points.glsl.js +0 -2
  89. package/src/renderers/webgl/WebGLPrograms.js +2 -1
  90. package/src/renderers/webgl-fallback/WebGLBackend.js +31 -27
  91. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +12 -8
  92. package/src/renderers/webgpu/WebGPUBackend.js +10 -14
  93. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +30 -2
  94. package/src/renderers/webgpu/utils/WebGPUConstants.js +2 -1
@@ -1,11 +1,11 @@
1
1
  import TempNode from '../core/TempNode.js';
2
2
  import { uv } from '../accessors/UVNode.js';
3
- import { addNodeElement, tslFn, nodeObject, float, vec2, vec4, int, If } from '../shadernode/ShaderNode.js';
3
+ import { addNodeElement, Fn, nodeObject, float, vec2, vec4, int, If } from '../shadernode/ShaderNode.js';
4
4
  import { NodeUpdateType } from '../core/constants.js';
5
5
  import { uniform } from '../core/UniformNode.js';
6
6
  import { abs, max, min, mix, pow } from '../math/MathNode.js';
7
7
  import { sub } from '../math/OperatorNode.js';
8
- import { loop, Break } from '../utils/LoopNode.js';
8
+ import { Loop, Break } from '../utils/LoopNode.js';
9
9
 
10
10
  import { Vector2 } from '../../math/Vector2.js';
11
11
 
@@ -77,7 +77,7 @@ class FXAANode extends TempNode {
77
77
 
78
78
  const NUM_SAMPLES = int( 5 );
79
79
 
80
- const contrast = tslFn( ( [ a_immutable, b_immutable ] ) => {
80
+ const contrast = Fn( ( [ a_immutable, b_immutable ] ) => {
81
81
 
82
82
  // assumes colors have premultipliedAlpha, so that the calculated color contrast is scaled by alpha
83
83
 
@@ -91,7 +91,7 @@ class FXAANode extends TempNode {
91
91
 
92
92
  // FXAA3 QUALITY - PC
93
93
 
94
- const FxaaPixelShader = tslFn( ( [ uv, fxaaQualityRcpFrame, fxaaQualityEdgeThreshold, fxaaQualityinvEdgeThreshold ] ) => {
94
+ const FxaaPixelShader = Fn( ( [ uv, fxaaQualityRcpFrame, fxaaQualityEdgeThreshold, fxaaQualityinvEdgeThreshold ] ) => {
95
95
 
96
96
  const rgbaM = FxaaTexTop( uv ).toVar();
97
97
  const rgbaS = FxaaTexOff( uv, vec2( 0.0, - 1.0 ), fxaaQualityRcpFrame.xy ).toVar();
@@ -130,8 +130,8 @@ class FXAANode extends TempNode {
130
130
 
131
131
  // locate the edge
132
132
 
133
- const x = contrastE.greaterThan( contrastW ).cond( 1, - 1 ).toVar();
134
- const y = contrastS.greaterThan( contrastN ).cond( 1, - 1 ).toVar();
133
+ const x = contrastE.greaterThan( contrastW ).select( 1, - 1 ).toVar();
134
+ const y = contrastS.greaterThan( contrastN ).select( 1, - 1 ).toVar();
135
135
 
136
136
  const dirToEdge = vec2( x, y ).toVar();
137
137
  // . 2 . . 1 .
@@ -184,7 +184,7 @@ class FXAANode extends TempNode {
184
184
  offNP.x.assign( 0 );
185
185
  offNP.y.assign( fxaaQualityRcpFrame.y );
186
186
 
187
- } ).else( () => {
187
+ } ).Else( () => {
188
188
 
189
189
  offNP.x.assign( fxaaQualityRcpFrame.x );
190
190
  offNP.y.assign( 0 );
@@ -212,7 +212,7 @@ class FXAANode extends TempNode {
212
212
  const iterationsUsedN = int( 0 ).toVar();
213
213
  const iterationsUsedP = int( 0 ).toVar();
214
214
 
215
- loop( NUM_SAMPLES, ( { i } ) => {
215
+ Loop( NUM_SAMPLES, ( { i } ) => {
216
216
 
217
217
  const increment = i.add( 1 ).toVar();
218
218
 
@@ -233,7 +233,7 @@ class FXAANode extends TempNode {
233
233
 
234
234
  iterationsUsedN.assign( i );
235
235
 
236
- } );
236
+ } );
237
237
 
238
238
  If( doneP.equal( 0 ), () => {
239
239
 
@@ -252,7 +252,7 @@ class FXAANode extends TempNode {
252
252
 
253
253
  iterationsUsedP.assign( i );
254
254
 
255
- } );
255
+ } );
256
256
 
257
257
  If( doneN.equal( 1 ).or( doneP.equal( 1 ) ), () => {
258
258
 
@@ -303,7 +303,7 @@ class FXAANode extends TempNode {
303
303
  ]
304
304
  } );
305
305
 
306
- const fxaa = tslFn( () => {
306
+ const fxaa = Fn( () => {
307
307
 
308
308
  const edgeDetectionQuality = float( 0.2 );
309
309
  const invEdgeDetectionQuality = float( 1 ).div( edgeDetectionQuality );
@@ -1,6 +1,6 @@
1
1
  import TempNode from '../core/TempNode.js';
2
2
  import { uv } from '../accessors/UVNode.js';
3
- import { addNodeElement, tslFn, nodeProxy, vec4 } from '../shadernode/ShaderNode.js';
3
+ import { addNodeElement, Fn, nodeProxy, vec4 } from '../shadernode/ShaderNode.js';
4
4
  import { mix, fract, clamp, rand } from '../math/MathNode.js';
5
5
  import { timerLocal } from '../utils/TimerNode.js';
6
6
 
@@ -20,7 +20,7 @@ class FilmNode extends TempNode {
20
20
 
21
21
  const uvNode = this.uvNode || uv();
22
22
 
23
- const film = tslFn( () => {
23
+ const film = Fn( () => {
24
24
 
25
25
  const base = this.inputNode.rgb;
26
26
  const noise = rand( fract( uvNode.add( timerLocal() ) ) );
@@ -2,7 +2,7 @@ import TempNode from '../core/TempNode.js';
2
2
  import { texture } from '../accessors/TextureNode.js';
3
3
  import { textureSize } from '../accessors/TextureSizeNode.js';
4
4
  import { uv } from '../accessors/UVNode.js';
5
- import { addNodeElement, nodeObject, tslFn, mat3, vec2, vec3, vec4, float, int, If } from '../shadernode/ShaderNode.js';
5
+ import { addNodeElement, nodeObject, Fn, mat3, vec2, vec3, vec4, float, int, If } from '../shadernode/ShaderNode.js';
6
6
  import { NodeUpdateType } from '../core/constants.js';
7
7
  import { uniform } from '../core/UniformNode.js';
8
8
  import { DataTexture } from '../../textures/DataTexture.js';
@@ -10,7 +10,7 @@ import { Vector2 } from '../../math/Vector2.js';
10
10
  import { Vector3 } from '../../math/Vector3.js';
11
11
  import { PI, cos, sin, pow, clamp, abs, max, mix, sqrt, acos, dot, normalize, cross } from '../math/MathNode.js';
12
12
  import { div, mul, add, sub } from '../math/OperatorNode.js';
13
- import { loop } from '../utils/LoopNode.js';
13
+ import { Loop } from '../utils/LoopNode.js';
14
14
  import { passTexture } from './PassNode.js';
15
15
  import { RepeatWrapping } from '../../constants.js';
16
16
  import QuadMesh from '../../renderers/common/QuadMesh.js';
@@ -106,7 +106,7 @@ class GTAONode extends TempNode {
106
106
  const sampleDepth = ( uv ) => this.depthNode.uv( uv ).x;
107
107
  const sampleNoise = ( uv ) => this.noiseNode.uv( uv );
108
108
 
109
- const getSceneUvAndDepth = tslFn( ( [ sampleViewPos ] )=> {
109
+ const getSceneUvAndDepth = Fn( ( [ sampleViewPos ] )=> {
110
110
 
111
111
  const sampleClipPos = this.cameraProjectionMatrix.mul( vec4( sampleViewPos, 1.0 ) );
112
112
  let sampleUv = sampleClipPos.xy.div( sampleClipPos.w ).mul( 0.5 ).add( 0.5 ).toVar();
@@ -116,7 +116,7 @@ class GTAONode extends TempNode {
116
116
 
117
117
  } );
118
118
 
119
- const getViewPosition = tslFn( ( [ screenPosition, depth ] ) => {
119
+ const getViewPosition = Fn( ( [ screenPosition, depth ] ) => {
120
120
 
121
121
  screenPosition = vec2( screenPosition.x, screenPosition.y.oneMinus() ).mul( 2.0 ).sub( 1.0 );
122
122
 
@@ -127,7 +127,7 @@ class GTAONode extends TempNode {
127
127
 
128
128
  } );
129
129
 
130
- const ao = tslFn( () => {
130
+ const ao = Fn( () => {
131
131
 
132
132
  const depth = sampleDepth( uvNode );
133
133
 
@@ -147,12 +147,12 @@ class GTAONode extends TempNode {
147
147
  const bitangent = vec3( tangent.y.mul( - 1.0 ), tangent.x, 0.0 );
148
148
  const kernelMatrix = mat3( tangent, bitangent, vec3( 0.0, 0.0, 1.0 ) );
149
149
 
150
- const DIRECTIONS = this.SAMPLES.lessThan( 30 ).cond( 3, 5 );
150
+ const DIRECTIONS = this.SAMPLES.lessThan( 30 ).select( 3, 5 );
151
151
  const STEPS = add( this.SAMPLES, DIRECTIONS.sub( 1 ) ).div( DIRECTIONS );
152
152
 
153
153
  const ao = float( 0 ).toVar();
154
154
 
155
- loop( { start: int( 0 ), end: DIRECTIONS, type: 'int', condition: '<' }, ( { i } ) => {
155
+ Loop( { start: int( 0 ), end: DIRECTIONS, type: 'int', condition: '<' }, ( { i } ) => {
156
156
 
157
157
  const angle = float( i ).div( float( DIRECTIONS ) ).mul( PI );
158
158
  const sampleDir = vec4( cos( angle ), sin( angle ), 0., add( 0.5, mul( 0.5, noiseTexel.w ) ) );
@@ -166,7 +166,7 @@ class GTAONode extends TempNode {
166
166
  const tangentToNormalInSlice = cross( normalInSlice, sliceBitangent );
167
167
  const cosHorizons = vec2( dot( viewDir, tangentToNormalInSlice ), dot( viewDir, tangentToNormalInSlice.negate() ) ).toVar();
168
168
 
169
- loop( { end: STEPS, type: 'int', name: 'j', condition: '<' }, ( { j } ) => {
169
+ Loop( { end: STEPS, type: 'int', name: 'j', condition: '<' }, ( { j } ) => {
170
170
 
171
171
  const sampleViewOffset = sampleDir.xyz.mul( radiusToUse ).mul( sampleDir.w ).mul( pow( div( float( j ).add( 1.0 ), float( STEPS ) ), this.distanceExponent ) );
172
172
 
@@ -206,7 +206,7 @@ class GTAONode extends TempNode {
206
206
  const occlusion = nx.mul( nxb ).add( ny.mul( nyb ) );
207
207
  ao.addAssign( occlusion );
208
208
 
209
- } );
209
+ } );
210
210
 
211
211
  ao.assign( clamp( ao.div( DIRECTIONS ), 0, 1 ) );
212
212
  ao.assign( pow( ao, this.scale ) );
@@ -1,5 +1,5 @@
1
1
  import TempNode from '../core/TempNode.js';
2
- import { nodeObject, addNodeElement, tslFn, float, vec2, vec4 } from '../shadernode/ShaderNode.js';
2
+ import { nodeObject, addNodeElement, Fn, float, vec2, vec4 } from '../shadernode/ShaderNode.js';
3
3
  import { NodeUpdateType } from '../core/constants.js';
4
4
  import { mul } from '../math/OperatorNode.js';
5
5
  import { uv } from '../accessors/UVNode.js';
@@ -129,7 +129,7 @@ class GaussianBlurNode extends TempNode {
129
129
 
130
130
  const sampleTexture = ( uv ) => textureNode.uv( uv );
131
131
 
132
- const blur = tslFn( () => {
132
+ const blur = Fn( () => {
133
133
 
134
134
  const kernelSize = 3 + ( 2 * this.sigma );
135
135
  const gaussianCoefficients = this._getCoefficients( kernelSize );
@@ -1,5 +1,5 @@
1
1
  import TempNode from '../core/TempNode.js';
2
- import { addNodeElement, tslFn, nodeObject, vec3, vec4, float } from '../shadernode/ShaderNode.js';
2
+ import { addNodeElement, Fn, nodeObject, vec3, vec4, float } from '../shadernode/ShaderNode.js';
3
3
  import { uniform } from '../core/UniformNode.js';
4
4
  import { mix } from '../math/MathNode.js';
5
5
 
@@ -22,7 +22,7 @@ class Lut3DNode extends TempNode {
22
22
 
23
23
  const sampleLut = ( uv ) => lutNode.uv( uv );
24
24
 
25
- const lut3D = tslFn( () => {
25
+ const lut3D = Fn( () => {
26
26
 
27
27
  const base = inputNode;
28
28
 
@@ -8,14 +8,14 @@ import { TBNViewMatrix } from '../accessors/AccessorsUtils.js';
8
8
  import { uv } from '../accessors/UVNode.js';
9
9
  import { faceDirection } from './FrontFacingNode.js';
10
10
  import { addNodeClass } from '../core/Node.js';
11
- import { addNodeElement, tslFn, nodeProxy, vec3 } from '../shadernode/ShaderNode.js';
11
+ import { addNodeElement, Fn, nodeProxy, vec3 } from '../shadernode/ShaderNode.js';
12
12
 
13
13
  import { TangentSpaceNormalMap, ObjectSpaceNormalMap } from '../../constants.js';
14
14
 
15
15
  // Normal Mapping Without Precomputed Tangents
16
16
  // http://www.thetenthplanet.de/archives/1180
17
17
 
18
- const perturbNormal2Arb = tslFn( ( inputs ) => {
18
+ const perturbNormal2Arb = Fn( ( inputs ) => {
19
19
 
20
20
  const { eye_pos, surf_norm, mapN, uv } = inputs;
21
21
 
@@ -43,17 +43,24 @@ class PassTextureNode extends TextureNode {
43
43
 
44
44
  class PassMultipleTextureNode extends PassTextureNode {
45
45
 
46
- constructor( passNode, textureName ) {
46
+ constructor( passNode, textureName, previousTexture = false ) {
47
47
 
48
48
  super( passNode, null );
49
49
 
50
50
  this.textureName = textureName;
51
+ this.previousTexture = previousTexture;
52
+
53
+ }
54
+
55
+ updateTexture() {
56
+
57
+ this.value = this.previousTexture ? this.passNode.getPreviousTexture( this.textureName ) : this.passNode.getTexture( this.textureName );
51
58
 
52
59
  }
53
60
 
54
61
  setup( builder ) {
55
62
 
56
- this.value = this.passNode.getTexture( this.textureName );
63
+ this.updateTexture();
57
64
 
58
65
  return super.setup( builder );
59
66
 
@@ -61,7 +68,7 @@ class PassMultipleTextureNode extends PassTextureNode {
61
68
 
62
69
  clone() {
63
70
 
64
- return new this.constructor( this.passNode, this.textureName );
71
+ return new this.constructor( this.passNode, this.textureName, this.previousTexture );
65
72
 
66
73
  }
67
74
 
@@ -104,6 +111,9 @@ class PassNode extends TempNode {
104
111
  this._linearDepthNodes = {};
105
112
  this._viewZNodes = {};
106
113
 
114
+ this._previousTextures = {};
115
+ this._previousTextureNodes = {};
116
+
107
117
  this._cameraNear = uniform( 0 );
108
118
  this._cameraFar = uniform( 0 );
109
119
 
@@ -155,6 +165,44 @@ class PassNode extends TempNode {
155
165
 
156
166
  }
157
167
 
168
+ getPreviousTexture( name ) {
169
+
170
+ let texture = this._previousTextures[ name ];
171
+
172
+ if ( texture === undefined ) {
173
+
174
+ texture = this.getTexture( name ).clone();
175
+ texture.isRenderTargetTexture = true;
176
+
177
+ this._previousTextures[ name ] = texture;
178
+
179
+ }
180
+
181
+ return texture;
182
+
183
+ }
184
+
185
+ toggleTexture( name ) {
186
+
187
+ const prevTexture = this._previousTextures[ name ];
188
+
189
+ if ( prevTexture !== undefined ) {
190
+
191
+ const texture = this._textures[ name ];
192
+
193
+ const index = this.renderTarget.textures.indexOf( texture );
194
+ this.renderTarget.textures[ index ] = prevTexture;
195
+
196
+ this._textures[ name ] = prevTexture;
197
+ this._previousTextures[ name ] = texture;
198
+
199
+ this._textureNodes[ name ].updateTexture();
200
+ this._previousTextureNodes[ name ].updateTexture();
201
+
202
+ }
203
+
204
+ }
205
+
158
206
  getTextureNode( name = 'output' ) {
159
207
 
160
208
  let textureNode = this._textureNodes[ name ];
@@ -169,6 +217,20 @@ class PassNode extends TempNode {
169
217
 
170
218
  }
171
219
 
220
+ getPreviousTextureNode( name = 'output' ) {
221
+
222
+ let textureNode = this._previousTextureNodes[ name ];
223
+
224
+ if ( textureNode === undefined ) {
225
+
226
+ this._previousTextureNodes[ name ] = textureNode = nodeObject( new PassMultipleTextureNode( this, name, true ) );
227
+
228
+ }
229
+
230
+ return textureNode;
231
+
232
+ }
233
+
172
234
  getViewZNode( name = 'depth' ) {
173
235
 
174
236
  let viewZNode = this._viewZNodes[ name ];
@@ -240,6 +302,12 @@ class PassNode extends TempNode {
240
302
  this._cameraNear.value = camera.near;
241
303
  this._cameraFar.value = camera.far;
242
304
 
305
+ for ( const name in this._previousTextures ) {
306
+
307
+ this.toggleTexture( name );
308
+
309
+ }
310
+
243
311
  renderer.setRenderTarget( this.renderTarget );
244
312
  renderer.setMRT( this._mrt );
245
313
 
@@ -1,6 +1,6 @@
1
1
  import TempNode from '../core/TempNode.js';
2
2
  import { uv } from '../accessors/UVNode.js';
3
- import { addNodeElement, tslFn, nodeObject, vec2, vec3, float, If } from '../shadernode/ShaderNode.js';
3
+ import { addNodeElement, Fn, nodeObject, vec2, vec3, float, If } from '../shadernode/ShaderNode.js';
4
4
  import { NodeUpdateType } from '../core/constants.js';
5
5
  import { uniform } from '../core/UniformNode.js';
6
6
  import { dot, clamp, smoothstep, sign, step, floor } from '../math/MathNode.js';
@@ -106,7 +106,7 @@ class PixelationNode extends TempNode {
106
106
 
107
107
  };
108
108
 
109
- const pixelation = tslFn( () => {
109
+ const pixelation = Fn( () => {
110
110
 
111
111
  const texel = sampleTexture();
112
112
 
@@ -136,7 +136,7 @@ class PixelationNode extends TempNode {
136
136
 
137
137
  } );
138
138
 
139
- const strength = dei.greaterThan( 0 ).cond( float( 1.0 ).sub( dei.mul( this.depthEdgeStrength ) ), nei.mul( this.normalEdgeStrength ).add( 1 ) );
139
+ const strength = dei.greaterThan( 0 ).select( float( 1.0 ).sub( dei.mul( this.depthEdgeStrength ) ), nei.mul( this.normalEdgeStrength ).add( 1 ) );
140
140
 
141
141
  return texel.mul( strength );
142
142
 
@@ -1,5 +1,5 @@
1
1
  import TempNode from '../core/TempNode.js';
2
- import { nodeObject, addNodeElement, tslFn, vec2, vec4 } from '../shadernode/ShaderNode.js';
2
+ import { nodeObject, addNodeElement, Fn, vec2, vec4 } from '../shadernode/ShaderNode.js';
3
3
  import { uniform } from '../core/UniformNode.js';
4
4
  import { uv } from '../accessors/UVNode.js';
5
5
  import { sin, cos } from '../math/MathNode.js';
@@ -24,7 +24,7 @@ class RGBShiftNode extends TempNode {
24
24
 
25
25
  const sampleTexture = ( uv ) => textureNode.uv( uv );
26
26
 
27
- const rgbShift = tslFn( () => {
27
+ const rgbShift = Fn( () => {
28
28
 
29
29
  const offset = vec2( cos( this.angle ), sin( this.angle ) ).mul( this.amount );
30
30
  const cr = sampleTexture( uvNode.add( offset ) );
@@ -1,7 +1,7 @@
1
- import { addNodeElement, tslFn, vec3 } from '../shadernode/ShaderNode.js';
1
+ import { addNodeElement, Fn, vec3 } from '../shadernode/ShaderNode.js';
2
2
  import { dot } from '../math/MathNode.js';
3
3
 
4
- export const sepia = /*@__PURE__*/ tslFn( ( [ color ] ) => {
4
+ export const sepia = /*@__PURE__*/ Fn( ( [ color ] ) => {
5
5
 
6
6
  const c = vec3( color );
7
7
 
@@ -1,7 +1,7 @@
1
1
  import TempNode from '../core/TempNode.js';
2
2
  import { uv } from '../accessors/UVNode.js';
3
3
  import { luminance } from './ColorAdjustmentNode.js';
4
- import { addNodeElement, tslFn, nodeObject, vec2, vec3, vec4, mat3 } from '../shadernode/ShaderNode.js';
4
+ import { addNodeElement, Fn, nodeObject, vec2, vec3, vec4, mat3 } from '../shadernode/ShaderNode.js';
5
5
  import { NodeUpdateType } from '../core/constants.js';
6
6
  import { uniform } from '../core/UniformNode.js';
7
7
  import { add } from '../math/OperatorNode.js';
@@ -38,7 +38,7 @@ class SobelOperatorNode extends TempNode {
38
38
 
39
39
  const sampleTexture = ( uv ) => textureNode.uv( uv );
40
40
 
41
- const sobel = tslFn( () => {
41
+ const sobel = Fn( () => {
42
42
 
43
43
  // Sobel Edge Detection (see https://youtu.be/uihBwtPIBxM)
44
44
 
@@ -1,22 +1,22 @@
1
1
  import TempNode from '../core/TempNode.js';
2
2
  import { addNodeClass } from '../core/Node.js';
3
- import { addNodeElement, tslFn, nodeObject, float, mat3, vec3, If } from '../shadernode/ShaderNode.js';
3
+ import { addNodeElement, Fn, nodeObject, float, mat3, vec3, vec4, If } from '../shadernode/ShaderNode.js';
4
4
  import { rendererReference } from '../accessors/RendererReferenceNode.js';
5
- import { cond } from '../math/CondNode.js';
5
+ import { select } from '../math/CondNode.js';
6
6
  import { clamp, log2, max, min, pow, mix } from '../math/MathNode.js';
7
7
  import { mul, sub, div } from '../math/OperatorNode.js';
8
8
 
9
9
  import { NoToneMapping, LinearToneMapping, ReinhardToneMapping, CineonToneMapping, ACESFilmicToneMapping, AgXToneMapping, NeutralToneMapping } from '../../constants.js';
10
10
 
11
11
  // exposure only
12
- const LinearToneMappingNode = tslFn( ( { color, exposure } ) => {
12
+ const LinearToneMappingNode = Fn( ( { color, exposure } ) => {
13
13
 
14
14
  return color.mul( exposure ).clamp();
15
15
 
16
16
  } );
17
17
 
18
18
  // source: https://www.cs.utah.edu/docs/techreports/2002/pdf/UUCS-02-001.pdf
19
- const ReinhardToneMappingNode = tslFn( ( { color, exposure } ) => {
19
+ const ReinhardToneMappingNode = Fn( ( { color, exposure } ) => {
20
20
 
21
21
  color = color.mul( exposure );
22
22
 
@@ -25,7 +25,7 @@ const ReinhardToneMappingNode = tslFn( ( { color, exposure } ) => {
25
25
  } );
26
26
 
27
27
  // source: http://filmicworlds.com/blog/filmic-tonemapping-operators/
28
- const OptimizedCineonToneMappingNode = tslFn( ( { color, exposure } ) => {
28
+ const OptimizedCineonToneMappingNode = Fn( ( { color, exposure } ) => {
29
29
 
30
30
  // optimized filmic operator by Jim Hejl and Richard Burgess-Dawson
31
31
  color = color.mul( exposure );
@@ -39,7 +39,7 @@ const OptimizedCineonToneMappingNode = tslFn( ( { color, exposure } ) => {
39
39
  } );
40
40
 
41
41
  // source: https://github.com/selfshadow/ltc_code/blob/master/webgl/shaders/ltc/ltc_blit.fs
42
- const RRTAndODTFit = tslFn( ( { color } ) => {
42
+ const RRTAndODTFit = Fn( ( { color } ) => {
43
43
 
44
44
  const a = color.mul( color.add( 0.0245786 ) ).sub( 0.000090537 );
45
45
  const b = color.mul( color.add( 0.4329510 ).mul( 0.983729 ) ).add( 0.238081 );
@@ -49,7 +49,7 @@ const RRTAndODTFit = tslFn( ( { color } ) => {
49
49
  } );
50
50
 
51
51
  // source: https://github.com/selfshadow/ltc_code/blob/master/webgl/shaders/ltc/ltc_blit.fs
52
- const ACESFilmicToneMappingNode = tslFn( ( { color, exposure } ) => {
52
+ const ACESFilmicToneMappingNode = Fn( ( { color, exposure } ) => {
53
53
 
54
54
  // sRGB => XYZ => D65_2_D60 => AP1 => RRT_SAT
55
55
  const ACESInputMat = mat3(
@@ -84,7 +84,7 @@ const ACESFilmicToneMappingNode = tslFn( ( { color, exposure } ) => {
84
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
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
86
 
87
- const agxDefaultContrastApprox = tslFn( ( [ x_immutable ] ) => {
87
+ const agxDefaultContrastApprox = Fn( ( [ x_immutable ] ) => {
88
88
 
89
89
  const x = vec3( x_immutable ).toVar();
90
90
  const x2 = vec3( x.mul( x ) ).toVar();
@@ -94,7 +94,7 @@ const agxDefaultContrastApprox = tslFn( ( [ x_immutable ] ) => {
94
94
 
95
95
  } );
96
96
 
97
- const AGXToneMappingNode = tslFn( ( { color, exposure } ) => {
97
+ const AGXToneMappingNode = Fn( ( { color, exposure } ) => {
98
98
 
99
99
  const colortone = vec3( color ).toVar();
100
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 ) );
@@ -120,7 +120,7 @@ const AGXToneMappingNode = tslFn( ( { color, exposure } ) => {
120
120
 
121
121
  // https://modelviewer.dev/examples/tone-mapping
122
122
 
123
- const NeutralToneMappingNode = tslFn( ( { color, exposure } ) => {
123
+ const NeutralToneMappingNode = Fn( ( { color, exposure } ) => {
124
124
 
125
125
  const StartCompression = float( 0.8 - 0.04 );
126
126
  const Desaturation = float( 0.15 );
@@ -128,7 +128,7 @@ const NeutralToneMappingNode = tslFn( ( { color, exposure } ) => {
128
128
  color = color.mul( exposure );
129
129
 
130
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 );
131
+ const offset = select( x.lessThan( 0.08 ), x.sub( mul( 6.25, x.mul( x ) ) ), 0.04 );
132
132
 
133
133
  color.subAssign( offset );
134
134
 
@@ -194,14 +194,14 @@ class ToneMappingNode extends TempNode {
194
194
 
195
195
  if ( toneMapping === NoToneMapping ) return colorNode;
196
196
 
197
- const toneMappingParams = { exposure: this.exposureNode, color: colorNode };
197
+ const toneMappingParams = { exposure: this.exposureNode, color: colorNode.rgb };
198
198
  const toneMappingNode = toneMappingLib[ toneMapping ];
199
199
 
200
200
  let outputNode = null;
201
201
 
202
202
  if ( toneMappingNode ) {
203
203
 
204
- outputNode = toneMappingNode( toneMappingParams );
204
+ outputNode = vec4( toneMappingNode( toneMappingParams ), colorNode.a );
205
205
 
206
206
  } else {
207
207
 
@@ -1,6 +1,6 @@
1
1
  import TempNode from '../core/TempNode.js';
2
2
  import { uv } from '../accessors/UVNode.js';
3
- import { addNodeElement, tslFn, nodeObject, float, int, vec4, If } from '../shadernode/ShaderNode.js';
3
+ import { addNodeElement, Fn, nodeObject, float, int, vec4, If } from '../shadernode/ShaderNode.js';
4
4
  import { clamp, mix } from '../math/MathNode.js';
5
5
  import { sub } from '../math/OperatorNode.js';
6
6
 
@@ -35,7 +35,7 @@ class TransitionNode extends TempNode {
35
35
 
36
36
  };
37
37
 
38
- const transition = tslFn( () => {
38
+ const transition = Fn( () => {
39
39
 
40
40
  const texelOne = sampleTexture( textureNodeA );
41
41
  const texelTwo = sampleTexture( textureNodeB );
@@ -50,7 +50,7 @@ class TransitionNode extends TempNode {
50
50
 
51
51
  color.assign( mix( texelOne, texelTwo, mixf ) );
52
52
 
53
- } ).else( () => {
53
+ } ).Else( () => {
54
54
 
55
55
  color.assign( mix( texelTwo, texelOne, mixRatioNode ) );
56
56
 
@@ -6,10 +6,10 @@ import D_GGX_Anisotropic from './D_GGX_Anisotropic.js';
6
6
  import { transformedNormalView } from '../../accessors/NormalNode.js';
7
7
  import { positionViewDirection } from '../../accessors/PositionNode.js';
8
8
  import { iridescence, alphaT, anisotropyT, anisotropyB } from '../../core/PropertyNode.js';
9
- import { tslFn, defined } from '../../shadernode/ShaderNode.js';
9
+ import { Fn, defined } from '../../shadernode/ShaderNode.js';
10
10
 
11
11
  // GGX Distribution, Schlick Fresnel, GGX_SmithCorrelated Visibility
12
- const BRDF_GGX = tslFn( ( inputs ) => {
12
+ const BRDF_GGX = Fn( ( inputs ) => {
13
13
 
14
14
  const { lightDirection, f0, f90, roughness, f, USE_IRIDESCENCE, USE_ANISOTROPY } = inputs;
15
15
 
@@ -1,6 +1,6 @@
1
- import { tslFn } from '../../shadernode/ShaderNode.js';
1
+ import { Fn } from '../../shadernode/ShaderNode.js';
2
2
 
3
- const BRDF_Lambert = tslFn( ( inputs ) => {
3
+ const BRDF_Lambert = Fn( ( inputs ) => {
4
4
 
5
5
  return inputs.diffuseColor.mul( 1 / Math.PI ); // punctual light
6
6
 
@@ -1,10 +1,10 @@
1
1
  import { transformedNormalView } from '../../accessors/NormalNode.js';
2
2
  import { positionViewDirection } from '../../accessors/PositionNode.js';
3
3
  import { sheen, sheenRoughness } from '../../core/PropertyNode.js';
4
- import { tslFn, float } from '../../shadernode/ShaderNode.js';
4
+ import { Fn, float } from '../../shadernode/ShaderNode.js';
5
5
 
6
6
  // https://github.com/google/filament/blob/master/shaders/src/brdf.fs
7
- const D_Charlie = tslFn( ( { roughness, dotNH } ) => {
7
+ const D_Charlie = Fn( ( { roughness, dotNH } ) => {
8
8
 
9
9
  const alpha = roughness.pow2();
10
10
 
@@ -25,7 +25,7 @@ const D_Charlie = tslFn( ( { roughness, dotNH } ) => {
25
25
  } );
26
26
 
27
27
  // https://github.com/google/filament/blob/master/shaders/src/brdf.fs
28
- const V_Neubelt = tslFn( ( { dotNV, dotNL } ) => {
28
+ const V_Neubelt = Fn( ( { dotNV, dotNL } ) => {
29
29
 
30
30
  // Neubelt and Pettineo 2013, "Crafting a Next-gen Material Pipeline for The Order: 1886"
31
31
  return float( 1.0 ).div( float( 4.0 ).mul( dotNL.add( dotNV ).sub( dotNL.mul( dotNV ) ) ) );
@@ -39,7 +39,7 @@ const V_Neubelt = tslFn( ( { dotNV, dotNL } ) => {
39
39
  ]
40
40
  } );
41
41
 
42
- const BRDF_Sheen = tslFn( ( { lightDirection } ) => {
42
+ const BRDF_Sheen = Fn( ( { lightDirection } ) => {
43
43
 
44
44
  const halfDir = lightDirection.add( positionViewDirection ).normalize();
45
45
 
@@ -1,10 +1,10 @@
1
- import { tslFn, vec2, vec4 } from '../../shadernode/ShaderNode.js';
1
+ import { Fn, vec2, vec4 } from '../../shadernode/ShaderNode.js';
2
2
 
3
3
  // Analytical approximation of the DFG LUT, one half of the
4
4
  // split-sum approximation used in indirect specular lighting.
5
5
  // via 'environmentBRDF' from "Physically Based Shading on Mobile"
6
6
  // https://www.unrealengine.com/blog/physically-based-shading-on-mobile
7
- const DFGApprox = tslFn( ( { roughness, dotNV } ) => {
7
+ const DFGApprox = Fn( ( { roughness, dotNV } ) => {
8
8
 
9
9
  const c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );
10
10
 
@@ -1,9 +1,9 @@
1
- import { tslFn } from '../../shadernode/ShaderNode.js';
1
+ import { Fn } from '../../shadernode/ShaderNode.js';
2
2
 
3
3
  // Microfacet Models for Refraction through Rough Surfaces - equation (33)
4
4
  // http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html
5
5
  // alpha is "roughness squared" in Disney’s reparameterization
6
- const D_GGX = tslFn( ( { alpha, dotNH } ) => {
6
+ const D_GGX = Fn( ( { alpha, dotNH } ) => {
7
7
 
8
8
  const a2 = alpha.pow2();
9
9
 
@@ -1,10 +1,10 @@
1
- import { tslFn, float, vec3 } from '../../shadernode/ShaderNode.js';
1
+ import { Fn, float, vec3 } from '../../shadernode/ShaderNode.js';
2
2
 
3
3
  const RECIPROCAL_PI = float( 1 / Math.PI );
4
4
 
5
5
  // https://google.github.io/filament/Filament.md.html#materialsystem/anisotropicmodel/anisotropicspecularbrdf
6
6
 
7
- const D_GGX_Anisotropic = tslFn( ( { alphaT, alphaB, dotNH, dotTH, dotBH } ) => {
7
+ const D_GGX_Anisotropic = Fn( ( { alphaT, alphaB, dotNH, dotTH, dotBH } ) => {
8
8
 
9
9
  const a2 = alphaT.mul( alphaB );
10
10
  const v = vec3( alphaB.mul( dotTH ), alphaT.mul( dotBH ), a2.mul( dotNH ) );