@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,7 +1,7 @@
1
1
  import TempNode from '../core/TempNode.js';
2
2
  import { sub, mul, div } from './OperatorNode.js';
3
3
  import { addNodeClass } from '../core/Node.js';
4
- import { addNodeElement, nodeObject, nodeProxy, float, vec2, vec3, vec4, tslFn } from '../shadernode/ShaderNode.js';
4
+ import { addNodeElement, nodeObject, nodeProxy, float, vec2, vec3, vec4, Fn } from '../shadernode/ShaderNode.js';
5
5
 
6
6
  class MathNode extends TempNode {
7
7
 
@@ -330,7 +330,7 @@ export const refract = nodeProxy( MathNode, MathNode.REFRACT );
330
330
  export const smoothstep = nodeProxy( MathNode, MathNode.SMOOTHSTEP );
331
331
  export const faceForward = nodeProxy( MathNode, MathNode.FACEFORWARD );
332
332
 
333
- export const rand = tslFn( ( [ uv ] ) => {
333
+ export const rand = Fn( ( [ uv ] ) => {
334
334
 
335
335
  const a = 12.9898, b = 78.233, c = 43758.5453;
336
336
  const dt = dot( uv.xy, vec2( a, b ) ), sn = mod( dt, PI );
@@ -1,28 +1,28 @@
1
1
  // https://github.com/cabbibo/glsl-tri-noise-3d
2
2
 
3
- import { loop } from '../utils/LoopNode.js';
4
- import { float, vec3, tslFn } from '../shadernode/ShaderNode.js';
3
+ import { Loop } from '../utils/LoopNode.js';
4
+ import { float, vec3, Fn } from '../shadernode/ShaderNode.js';
5
5
 
6
- const tri = tslFn( ( [ x ] ) => {
6
+ const tri = Fn( ( [ x ] ) => {
7
7
 
8
8
  return x.fract().sub( .5 ).abs();
9
9
 
10
10
  } );
11
11
 
12
- const tri3 = tslFn( ( [ p ] ) => {
12
+ const tri3 = Fn( ( [ p ] ) => {
13
13
 
14
14
  return vec3( tri( p.z.add( tri( p.y.mul( 1. ) ) ) ), tri( p.z.add( tri( p.x.mul( 1. ) ) ) ), tri( p.y.add( tri( p.x.mul( 1. ) ) ) ) );
15
15
 
16
16
  } );
17
17
 
18
- const triNoise3D = tslFn( ( [ p_immutable, spd, time ] ) => {
18
+ const triNoise3D = Fn( ( [ p_immutable, spd, time ] ) => {
19
19
 
20
20
  const p = vec3( p_immutable ).toVar();
21
21
  const z = float( 1.4 ).toVar();
22
22
  const rz = float( 0.0 ).toVar();
23
23
  const bp = vec3( p ).toVar();
24
24
 
25
- loop( { start: float( 0.0 ), end: float( 3.0 ), type: 'float', condition: '<=' }, () => {
25
+ Loop( { start: float( 0.0 ), end: float( 3.0 ), type: 'float', condition: '<=' }, () => {
26
26
 
27
27
  const dg = vec3( tri3( bp.mul( 2.0 ) ) ).toVar();
28
28
  p.addAssign( dg.add( time.mul( float( 0.1 ).mul( spd ) ) ) );
@@ -1,8 +1,8 @@
1
- import { tslFn, int, float, vec2, vec3, vec4, If } from '../shadernode/ShaderNode.js';
1
+ import { Fn, int, float, vec2, vec3, vec4, If } from '../shadernode/ShaderNode.js';
2
2
  import { cos, sin, abs, max, exp2, log2, clamp, fract, mix, floor, normalize, cross, all } from '../math/MathNode.js';
3
3
  import { mul } from '../math/OperatorNode.js';
4
- import { cond } from '../math/CondNode.js';
5
- import { loop, Break } from '../utils/LoopNode.js';
4
+ import { select } from '../math/CondNode.js';
5
+ import { Loop, Break } from '../utils/LoopNode.js';
6
6
 
7
7
  // These defines must match with PMREMGenerator
8
8
 
@@ -24,7 +24,7 @@ const cubeUV_minTileSize = float( 16.0 );
24
24
  // a cubemap, the 0-5 integer index of a cube face, and the direction vector for
25
25
  // sampling a textureCube (not generally normalized ).
26
26
 
27
- const getFace = tslFn( ( [ direction ] ) => {
27
+ const getFace = Fn( ( [ direction ] ) => {
28
28
 
29
29
  const absDirection = vec3( abs( direction ) ).toVar();
30
30
  const face = float( - 1.0 ).toVar();
@@ -33,23 +33,23 @@ const getFace = tslFn( ( [ direction ] ) => {
33
33
 
34
34
  If( absDirection.x.greaterThan( absDirection.y ), () => {
35
35
 
36
- face.assign( cond( direction.x.greaterThan( 0.0 ), 0.0, 3.0 ) );
36
+ face.assign( select( direction.x.greaterThan( 0.0 ), 0.0, 3.0 ) );
37
37
 
38
- } ).else( () => {
38
+ } ).Else( () => {
39
39
 
40
- face.assign( cond( direction.y.greaterThan( 0.0 ), 1.0, 4.0 ) );
40
+ face.assign( select( direction.y.greaterThan( 0.0 ), 1.0, 4.0 ) );
41
41
 
42
42
  } );
43
43
 
44
- } ).else( () => {
44
+ } ).Else( () => {
45
45
 
46
46
  If( absDirection.z.greaterThan( absDirection.y ), () => {
47
47
 
48
- face.assign( cond( direction.z.greaterThan( 0.0 ), 2.0, 5.0 ) );
48
+ face.assign( select( direction.z.greaterThan( 0.0 ), 2.0, 5.0 ) );
49
49
 
50
- } ).else( () => {
50
+ } ).Else( () => {
51
51
 
52
- face.assign( cond( direction.y.greaterThan( 0.0 ), 1.0, 4.0 ) );
52
+ face.assign( select( direction.y.greaterThan( 0.0 ), 1.0, 4.0 ) );
53
53
 
54
54
  } );
55
55
 
@@ -66,7 +66,7 @@ const getFace = tslFn( ( [ direction ] ) => {
66
66
  } );
67
67
 
68
68
  // RH coordinate system; PMREM face-indexing convention
69
- const getUV = tslFn( ( [ direction, face ] ) => {
69
+ const getUV = Fn( ( [ direction, face ] ) => {
70
70
 
71
71
  const uv = vec2().toVar();
72
72
 
@@ -74,23 +74,23 @@ const getUV = tslFn( ( [ direction, face ] ) => {
74
74
 
75
75
  uv.assign( vec2( direction.z, direction.y ).div( abs( direction.x ) ) ); // pos x
76
76
 
77
- } ).elseif( face.equal( 1.0 ), () => {
77
+ } ).ElseIf( face.equal( 1.0 ), () => {
78
78
 
79
79
  uv.assign( vec2( direction.x.negate(), direction.z.negate() ).div( abs( direction.y ) ) ); // pos y
80
80
 
81
- } ).elseif( face.equal( 2.0 ), () => {
81
+ } ).ElseIf( face.equal( 2.0 ), () => {
82
82
 
83
83
  uv.assign( vec2( direction.x.negate(), direction.y ).div( abs( direction.z ) ) ); // pos z
84
84
 
85
- } ).elseif( face.equal( 3.0 ), () => {
85
+ } ).ElseIf( face.equal( 3.0 ), () => {
86
86
 
87
87
  uv.assign( vec2( direction.z.negate(), direction.y ).div( abs( direction.x ) ) ); // neg x
88
88
 
89
- } ).elseif( face.equal( 4.0 ), () => {
89
+ } ).ElseIf( face.equal( 4.0 ), () => {
90
90
 
91
91
  uv.assign( vec2( direction.x.negate(), direction.z ).div( abs( direction.y ) ) ); // neg y
92
92
 
93
- } ).else( () => {
93
+ } ).Else( () => {
94
94
 
95
95
  uv.assign( vec2( direction.x, direction.y ).div( abs( direction.z ) ) ); // neg z
96
96
 
@@ -107,7 +107,7 @@ const getUV = tslFn( ( [ direction, face ] ) => {
107
107
  ]
108
108
  } );
109
109
 
110
- const roughnessToMip = tslFn( ( [ roughness ] ) => {
110
+ const roughnessToMip = Fn( ( [ roughness ] ) => {
111
111
 
112
112
  const mip = float( 0.0 ).toVar();
113
113
 
@@ -115,19 +115,19 @@ const roughnessToMip = tslFn( ( [ roughness ] ) => {
115
115
 
116
116
  mip.assign( cubeUV_r0.sub( roughness ).mul( cubeUV_m1.sub( cubeUV_m0 ) ).div( cubeUV_r0.sub( cubeUV_r1 ) ).add( cubeUV_m0 ) );
117
117
 
118
- } ).elseif( roughness.greaterThanEqual( cubeUV_r4 ), () => {
118
+ } ).ElseIf( roughness.greaterThanEqual( cubeUV_r4 ), () => {
119
119
 
120
120
  mip.assign( cubeUV_r1.sub( roughness ).mul( cubeUV_m4.sub( cubeUV_m1 ) ).div( cubeUV_r1.sub( cubeUV_r4 ) ).add( cubeUV_m1 ) );
121
121
 
122
- } ).elseif( roughness.greaterThanEqual( cubeUV_r5 ), () => {
122
+ } ).ElseIf( roughness.greaterThanEqual( cubeUV_r5 ), () => {
123
123
 
124
124
  mip.assign( cubeUV_r4.sub( roughness ).mul( cubeUV_m5.sub( cubeUV_m4 ) ).div( cubeUV_r4.sub( cubeUV_r5 ) ).add( cubeUV_m4 ) );
125
125
 
126
- } ).elseif( roughness.greaterThanEqual( cubeUV_r6 ), () => {
126
+ } ).ElseIf( roughness.greaterThanEqual( cubeUV_r6 ), () => {
127
127
 
128
128
  mip.assign( cubeUV_r5.sub( roughness ).mul( cubeUV_m6.sub( cubeUV_m5 ) ).div( cubeUV_r5.sub( cubeUV_r6 ) ).add( cubeUV_m5 ) );
129
129
 
130
- } ).else( () => {
130
+ } ).Else( () => {
131
131
 
132
132
  mip.assign( float( - 2.0 ).mul( log2( mul( 1.16, roughness ) ) ) ); // 1.16 = 1.79^0.25
133
133
 
@@ -144,7 +144,7 @@ const roughnessToMip = tslFn( ( [ roughness ] ) => {
144
144
  } );
145
145
 
146
146
  // RH coordinate system; PMREM face-indexing convention
147
- export const getDirection = tslFn( ( [ uv_immutable, face ] ) => {
147
+ export const getDirection = Fn( ( [ uv_immutable, face ] ) => {
148
148
 
149
149
  const uv = uv_immutable.toVar();
150
150
  uv.assign( mul( 2.0, uv ).sub( 1.0 ) );
@@ -154,26 +154,26 @@ export const getDirection = tslFn( ( [ uv_immutable, face ] ) => {
154
154
 
155
155
  direction.assign( direction.zyx ); // ( 1, v, u ) pos x
156
156
 
157
- } ).elseif( face.equal( 1.0 ), () => {
157
+ } ).ElseIf( face.equal( 1.0 ), () => {
158
158
 
159
159
  direction.assign( direction.xzy );
160
160
  direction.xz.mulAssign( - 1.0 ); // ( -u, 1, -v ) pos y
161
161
 
162
- } ).elseif( face.equal( 2.0 ), () => {
162
+ } ).ElseIf( face.equal( 2.0 ), () => {
163
163
 
164
164
  direction.x.mulAssign( - 1.0 ); // ( -u, v, 1 ) pos z
165
165
 
166
- } ).elseif( face.equal( 3.0 ), () => {
166
+ } ).ElseIf( face.equal( 3.0 ), () => {
167
167
 
168
168
  direction.assign( direction.zyx );
169
169
  direction.xz.mulAssign( - 1.0 ); // ( -1, v, -u ) neg x
170
170
 
171
- } ).elseif( face.equal( 4.0 ), () => {
171
+ } ).ElseIf( face.equal( 4.0 ), () => {
172
172
 
173
173
  direction.assign( direction.xzy );
174
174
  direction.xy.mulAssign( - 1.0 ); // ( -u, -1, v ) neg y
175
175
 
176
- } ).elseif( face.equal( 5.0 ), () => {
176
+ } ).ElseIf( face.equal( 5.0 ), () => {
177
177
 
178
178
  direction.z.mulAssign( - 1.0 ); // ( u, v, -1 ) neg zS
179
179
 
@@ -192,7 +192,7 @@ export const getDirection = tslFn( ( [ uv_immutable, face ] ) => {
192
192
 
193
193
  //
194
194
 
195
- export const textureCubeUV = tslFn( ( [ envMap, sampleDir_immutable, roughness_immutable, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP ] ) => {
195
+ export const textureCubeUV = Fn( ( [ envMap, sampleDir_immutable, roughness_immutable, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP ] ) => {
196
196
 
197
197
  const roughness = float( roughness_immutable );
198
198
  const sampleDir = vec3( sampleDir_immutable );
@@ -214,7 +214,7 @@ export const textureCubeUV = tslFn( ( [ envMap, sampleDir_immutable, roughness_i
214
214
 
215
215
  } );
216
216
 
217
- const bilinearCubeUV = tslFn( ( [ envMap, direction_immutable, mipInt_immutable, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP ] ) => {
217
+ const bilinearCubeUV = Fn( ( [ envMap, direction_immutable, mipInt_immutable, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP ] ) => {
218
218
 
219
219
  const mipInt = float( mipInt_immutable ).toVar();
220
220
  const direction = vec3( direction_immutable );
@@ -241,7 +241,7 @@ const bilinearCubeUV = tslFn( ( [ envMap, direction_immutable, mipInt_immutable,
241
241
 
242
242
  } );
243
243
 
244
- const getSample = tslFn( ( { envMap, mipInt, outputDirection, theta, axis, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP } ) => {
244
+ const getSample = Fn( ( { envMap, mipInt, outputDirection, theta, axis, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP } ) => {
245
245
 
246
246
  const cosTheta = cos( theta );
247
247
 
@@ -254,9 +254,9 @@ const getSample = tslFn( ( { envMap, mipInt, outputDirection, theta, axis, CUBEU
254
254
 
255
255
  } );
256
256
 
257
- export const blur = tslFn( ( { n, latitudinal, poleAxis, outputDirection, weights, samples, dTheta, mipInt, envMap, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP } ) => {
257
+ export const blur = Fn( ( { n, latitudinal, poleAxis, outputDirection, weights, samples, dTheta, mipInt, envMap, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP } ) => {
258
258
 
259
- const axis = vec3( cond( latitudinal, poleAxis, cross( poleAxis, outputDirection ) ) ).toVar();
259
+ const axis = vec3( select( latitudinal, poleAxis, cross( poleAxis, outputDirection ) ) ).toVar();
260
260
 
261
261
  If( all( axis.equals( vec3( 0.0 ) ) ), () => {
262
262
 
@@ -269,7 +269,7 @@ export const blur = tslFn( ( { n, latitudinal, poleAxis, outputDirection, weight
269
269
  const gl_FragColor = vec3().toVar();
270
270
  gl_FragColor.addAssign( weights.element( int( 0 ) ).mul( getSample( { theta: 0.0, axis, outputDirection, mipInt, envMap, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP } ) ) );
271
271
 
272
- loop( { start: int( 1 ), end: n }, ( { i } ) => {
272
+ Loop( { start: int( 1 ), end: n }, ( { i } ) => {
273
273
 
274
274
  If( i.greaterThanEqual( samples ), () => {
275
275
 
@@ -1,9 +1,9 @@
1
1
  import TempNode from '../core/TempNode.js';
2
2
  import { uv } from '../accessors/UVNode.js';
3
3
  import { addNodeClass } from '../core/Node.js';
4
- import { addNodeElement, tslFn, nodeProxy } from '../shadernode/ShaderNode.js';
4
+ import { addNodeElement, Fn, nodeProxy } from '../shadernode/ShaderNode.js';
5
5
 
6
- const checkerShaderNode = tslFn( ( inputs ) => {
6
+ const checkerShaderNode = Fn( ( inputs ) => {
7
7
 
8
8
  const uv = inputs.uv.mul( 2.0 );
9
9
 
@@ -164,7 +164,7 @@ const ShaderNodeObject = function ( obj, altType = null ) {
164
164
 
165
165
  } else if ( type === 'shader' ) {
166
166
 
167
- return tslFn( obj );
167
+ return Fn( obj );
168
168
 
169
169
  }
170
170
 
@@ -300,7 +300,7 @@ class ShaderCallNodeInternal extends Node {
300
300
  }
301
301
 
302
302
  const jsFunc = shaderNode.jsFunc;
303
- const outputNode = inputNodes !== null ? jsFunc( inputNodes, builder.stack, builder ) : jsFunc( builder.stack, builder );
303
+ const outputNode = inputNodes !== null ? jsFunc( inputNodes, builder ) : jsFunc( builder );
304
304
 
305
305
  return nodeObject( outputNode );
306
306
 
@@ -492,7 +492,7 @@ export const nodeArray = ( val, altType = null ) => new ShaderNodeArray( val, al
492
492
  export const nodeProxy = ( ...params ) => new ShaderNodeProxy( ...params );
493
493
  export const nodeImmutable = ( ...params ) => new ShaderNodeImmutable( ...params );
494
494
 
495
- export const tslFn = ( jsFunc ) => {
495
+ export const Fn = ( jsFunc ) => {
496
496
 
497
497
  const shaderNode = new ShaderNode( jsFunc );
498
498
 
@@ -529,6 +529,13 @@ export const tslFn = ( jsFunc ) => {
529
529
 
530
530
  };
531
531
 
532
+ export const tslFn = ( ...params ) => { // @deprecated, r168
533
+
534
+ console.warn( 'TSL.tslFn: tslFn() has been renamed to Fn().' );
535
+ return Fn( ...params );
536
+
537
+ };
538
+
532
539
  addNodeClass( 'ShaderNode', ShaderNode );
533
540
 
534
541
  //
@@ -557,7 +564,7 @@ export const setCurrentStack = ( stack ) => {
557
564
 
558
565
  export const getCurrentStack = () => currentStack;
559
566
 
560
- export const If = ( ...params ) => currentStack.if( ...params );
567
+ export const If = ( ...params ) => currentStack.If( ...params );
561
568
 
562
569
  export function append( node ) {
563
570
 
@@ -0,0 +1,157 @@
1
+ import TempNode from '../core/TempNode.js';
2
+ import { addNodeClass } from '../core/Node.js';
3
+ import { NodeUpdateType } from '../core/constants.js';
4
+ import { nodeProxy } from '../shadernode/ShaderNode.js';
5
+ import { CubeTexture } from '../../textures/CubeTexture.js';
6
+ import { cubeTexture } from '../accessors/CubeTextureNode.js';
7
+ import CubeRenderTarget from '../../renderers/common/CubeRenderTarget.js';
8
+ import { CubeReflectionMapping, CubeRefractionMapping, EquirectangularReflectionMapping, EquirectangularRefractionMapping } from '../../constants';
9
+
10
+ const _cache = new WeakMap();
11
+
12
+ class CubeMapNode extends TempNode {
13
+
14
+ constructor( envNode ) {
15
+
16
+ super( 'vec3' );
17
+
18
+ this.envNode = envNode;
19
+
20
+ this._cubeTexture = null;
21
+ this._cubeTextureNode = cubeTexture();
22
+
23
+ const defaultTexture = new CubeTexture();
24
+ defaultTexture.isRenderTargetTexture = true;
25
+
26
+ this._defaultTexture = defaultTexture;
27
+
28
+ this.updateBeforeType = NodeUpdateType.RENDER;
29
+
30
+ }
31
+
32
+ updateBefore( frame ) {
33
+
34
+ const { renderer, material } = frame;
35
+
36
+ const envNode = this.envNode;
37
+
38
+ if ( envNode.isTextureNode || envNode.isMaterialReferenceNode ) {
39
+
40
+ const texture = ( envNode.isTextureNode ) ? envNode.value : material[ envNode.property ];
41
+
42
+ if ( texture && texture.isTexture ) {
43
+
44
+ const mapping = texture.mapping;
45
+
46
+ if ( mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping ) {
47
+
48
+ // check for converted cubemap map
49
+
50
+ if ( _cache.has( texture ) ) {
51
+
52
+ const cubeMap = _cache.get( texture );
53
+
54
+ mapTextureMapping( cubeMap, texture.mapping );
55
+ this._cubeTexture = cubeMap;
56
+
57
+ } else {
58
+
59
+ // create cube map from equirectangular map
60
+
61
+ const image = texture.image;
62
+
63
+ if ( isEquirectangularMapReady( image ) ) {
64
+
65
+ const renderTarget = new CubeRenderTarget( image.height );
66
+ renderTarget.fromEquirectangularTexture( renderer, texture );
67
+
68
+ mapTextureMapping( renderTarget.texture, texture.mapping );
69
+ this._cubeTexture = renderTarget.texture;
70
+
71
+ _cache.set( texture, renderTarget.texture );
72
+
73
+ texture.addEventListener( 'dispose', onTextureDispose );
74
+
75
+ } else {
76
+
77
+ // default cube texture as fallback when equirectangular texture is not yet loaded
78
+
79
+ this._cubeTexture = this._defaultTexture;
80
+
81
+ }
82
+
83
+ }
84
+
85
+ //
86
+
87
+ this._cubeTextureNode.value = this._cubeTexture;
88
+
89
+ } else {
90
+
91
+ // envNode already refers to a cube map
92
+
93
+ this._cubeTextureNode = this.envNode;
94
+
95
+ }
96
+
97
+ }
98
+
99
+ }
100
+
101
+ }
102
+
103
+ setup( builder ) {
104
+
105
+ this.updateBefore( builder );
106
+
107
+ return this._cubeTextureNode;
108
+
109
+ }
110
+
111
+ }
112
+
113
+ function isEquirectangularMapReady( image ) {
114
+
115
+ if ( image === null || image === undefined ) return false;
116
+
117
+ return image.height > 0;
118
+
119
+ }
120
+
121
+ function onTextureDispose( event ) {
122
+
123
+ const texture = event.target;
124
+
125
+ texture.removeEventListener( 'dispose', onTextureDispose );
126
+
127
+ const renderTarget = _cache.get( texture );
128
+
129
+ if ( renderTarget !== undefined ) {
130
+
131
+ _cache.delete( texture );
132
+
133
+ renderTarget.dispose();
134
+
135
+ }
136
+
137
+ }
138
+
139
+ function mapTextureMapping( texture, mapping ) {
140
+
141
+ if ( mapping === EquirectangularReflectionMapping ) {
142
+
143
+ texture.mapping = CubeReflectionMapping;
144
+
145
+ } else if ( mapping === EquirectangularRefractionMapping ) {
146
+
147
+ texture.mapping = CubeRefractionMapping;
148
+
149
+ }
150
+
151
+ }
152
+
153
+ export const cubeMapNode = nodeProxy( CubeMapNode );
154
+
155
+ addNodeClass( 'CubeMapNode', CubeMapNode );
156
+
157
+ export default CubeMapNode;
@@ -1,7 +1,6 @@
1
1
  import Node, { addNodeClass } from '../core/Node.js';
2
2
  import { expression } from '../code/ExpressionNode.js';
3
- import { bypass } from '../core/BypassNode.js';
4
- import { addNodeElement, nodeObject, nodeArray } from '../shadernode/ShaderNode.js';
3
+ import { nodeObject, nodeArray } from '../shadernode/ShaderNode.js';
5
4
 
6
5
  class LoopNode extends Node {
7
6
 
@@ -192,10 +191,17 @@ class LoopNode extends Node {
192
191
 
193
192
  export default LoopNode;
194
193
 
195
- export const loop = ( ...params ) => nodeObject( new LoopNode( nodeArray( params, 'int' ) ) ).append();
194
+ export const Loop = ( ...params ) => nodeObject( new LoopNode( nodeArray( params, 'int' ) ) ).append();
196
195
  export const Continue = () => expression( 'continue' ).append();
197
196
  export const Break = () => expression( 'break' ).append();
198
197
 
199
- addNodeElement( 'loop', ( returns, ...params ) => bypass( returns, loop( ...params ) ) );
198
+ //
199
+
200
+ export const loop = ( ...params ) => { // @deprecated, r168
201
+
202
+ console.warn( 'TSL.LoopNode: loop() has been renamed to Loop().' );
203
+ return Loop( ...params );
204
+
205
+ };
200
206
 
201
207
  addNodeClass( 'LoopNode', LoopNode );
@@ -1,9 +1,9 @@
1
1
  import { modelWorldMatrix } from '../accessors/ModelNode.js';
2
2
  import { cameraViewMatrix, cameraProjectionMatrix } from '../accessors/CameraNode.js';
3
3
  import { positionLocal } from '../accessors/PositionNode.js';
4
- import { tslFn, defined } from '../shadernode/ShaderNode.js';
4
+ import { Fn, defined } from '../shadernode/ShaderNode.js';
5
5
 
6
- export const billboarding = tslFn( ( { position = null, horizontal = true, vertical = false } ) => {
6
+ export const billboarding = Fn( ( { position = null, horizontal = true, vertical = false } ) => {
7
7
 
8
8
  let worldMatrix;
9
9
 
@@ -1,12 +1,12 @@
1
- import { addNodeElement, tslFn, vec2 } from '../shadernode/ShaderNode.js';
1
+ import { addNodeElement, Fn, vec2 } from '../shadernode/ShaderNode.js';
2
2
 
3
- export const rotateUV = tslFn( ( [ uv, rotation, center = vec2( 0.5 ) ] ) => {
3
+ export const rotateUV = Fn( ( [ uv, rotation, center = vec2( 0.5 ) ] ) => {
4
4
 
5
5
  return uv.sub( center ).rotate( rotation ).add( center );
6
6
 
7
7
  } );
8
8
 
9
- export const spherizeUV = tslFn( ( [ uv, strength, center = vec2( 0.5 ) ] ) => {
9
+ export const spherizeUV = Fn( ( [ uv, strength, center = vec2( 0.5 ) ] ) => {
10
10
 
11
11
  const delta = uv.sub( center );
12
12
  const delta2 = delta.dot( delta );
@@ -1,13 +1,13 @@
1
- import { tslFn } from '../shadernode/ShaderNode.js';
1
+ import { Fn } from '../shadernode/ShaderNode.js';
2
2
  import { viewportTopLeft } from '../display/ViewportNode.js';
3
3
  import { viewportDepthTexture } from '../display/ViewportDepthTextureNode.js';
4
4
  import { linearDepth } from '../display/ViewportDepthNode.js';
5
5
 
6
- export const viewportSafeUV = tslFn( ( [ uv = null ] ) => {
6
+ export const viewportSafeUV = Fn( ( [ uv = null ] ) => {
7
7
 
8
8
  const depth = linearDepth();
9
9
  const depthDiff = linearDepth( viewportDepthTexture( uv ) ).sub( depth );
10
- const finalUV = depthDiff.lessThan( 0 ).cond( viewportTopLeft, uv );
10
+ const finalUV = depthDiff.lessThan( 0 ).select( viewportTopLeft, uv );
11
11
 
12
12
  return finalUV;
13
13
 
@@ -1845,6 +1845,14 @@ class WebGLRenderer {
1845
1845
 
1846
1846
  needsProgramChange = true;
1847
1847
 
1848
+ } else if (object.isBatchedMesh && materialProperties.batchingMatrix === false && object._matricesTexture !== null) {
1849
+
1850
+ needsProgramChange = true;
1851
+
1852
+ } else if (object.isBatchedMesh && materialProperties.batchingMatrix === true && object._matricesTexture === null) {
1853
+
1854
+ needsProgramChange = true;
1855
+
1848
1856
  } else if ( object.isInstancedMesh && materialProperties.instancing === false ) {
1849
1857
 
1850
1858
  needsProgramChange = true;
@@ -38,6 +38,30 @@ class RenderContext {
38
38
 
39
39
  }
40
40
 
41
+ getCacheKey() {
42
+
43
+ return getCacheKey( this );
44
+
45
+ }
46
+
47
+ }
48
+
49
+ export function getCacheKey( renderContext ) {
50
+
51
+ const { textures, activeCubeFace } = renderContext;
52
+
53
+ let key = '';
54
+
55
+ for ( const texture of textures ) {
56
+
57
+ key += texture.id + ',';
58
+
59
+ }
60
+
61
+ key += activeCubeFace;
62
+
63
+ return key;
64
+
41
65
  }
42
66
 
43
67
  export default RenderContext;
@@ -263,7 +263,7 @@ export default class RenderObject {
263
263
 
264
264
  if ( object.count > 1 ) {
265
265
 
266
- cacheKey += object.count + ',';
266
+ cacheKey += object.count + ',' + object.uuid + ',';
267
267
 
268
268
  }
269
269
 
@@ -7,7 +7,7 @@ export default /* glsl */`
7
7
 
8
8
  uniform highp sampler2D batchingTexture;
9
9
  uniform highp usampler2D batchingIdTexture;
10
- mat4 getBatchingMatrix( const in float i ) {
10
+ mat4 getBatchingMatrix( const in int i ) {
11
11
 
12
12
  int size = textureSize( batchingTexture, 0 ).x;
13
13
  int j = int( i ) * 4;
@@ -1,6 +1,6 @@
1
1
  export default /* glsl */`
2
2
  #ifdef USE_BATCHING_MATRIX
3
- mat4 batchingMatrix = getBatchingMatrix( getIndirectIndex( gl_DrawID ) );
3
+ mat4 batchingMatrix = getBatchingMatrix( gl_DrawID );
4
4
  #elif defined ( USE_BATCHING )
5
5
  mat4 batchingMatrix = mat4( 1.0 );
6
6
  #endif
@@ -5,7 +5,6 @@ attribute float lineDistance;
5
5
  varying float vLineDistance;
6
6
 
7
7
  #include <common>
8
- #include <batching_pars_vertex>
9
8
  #include <uv_pars_vertex>
10
9
  #include <color_pars_vertex>
11
10
  #include <fog_pars_vertex>
@@ -21,7 +20,6 @@ void main() {
21
20
  #include <color_vertex>
22
21
  #include <morphinstance_vertex>
23
22
  #include <morphcolor_vertex>
24
- #include <batching_vertex>
25
23
  #include <begin_vertex>
26
24
  #include <morphtarget_vertex>
27
25
  #include <project_vertex>
@@ -3,7 +3,6 @@ uniform float size;
3
3
  uniform float scale;
4
4
 
5
5
  #include <common>
6
- #include <batching_pars_vertex>
7
6
  #include <color_pars_vertex>
8
7
  #include <fog_pars_vertex>
9
8
  #include <morphtarget_pars_vertex>
@@ -28,7 +27,6 @@ void main() {
28
27
  #include <color_vertex>
29
28
  #include <morphinstance_vertex>
30
29
  #include <morphcolor_vertex>
31
- #include <batching_vertex>
32
30
  #include <begin_vertex>
33
31
  #include <morphtarget_vertex>
34
32
  #include <project_vertex>