super-three 0.162.0 → 0.164.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 (187) hide show
  1. package/build/three.cjs +847 -1226
  2. package/build/three.module.js +846 -1225
  3. package/build/three.module.min.js +2 -2
  4. package/examples/jsm/animation/CCDIKSolver.js +4 -2
  5. package/examples/jsm/controls/TransformControls.js +3 -3
  6. package/examples/jsm/exporters/GLTFExporter.js +66 -5
  7. package/examples/jsm/exporters/USDZExporter.js +22 -1
  8. package/examples/jsm/geometries/TextGeometry.js +10 -2
  9. package/examples/jsm/interactive/HTMLMesh.js +7 -9
  10. package/examples/jsm/libs/draco/README.md +2 -2
  11. package/examples/jsm/libs/fflate.module.js +694 -496
  12. package/examples/jsm/lines/LineMaterial.js +0 -2
  13. package/examples/jsm/loaders/3MFLoader.js +2 -0
  14. package/examples/jsm/loaders/EXRLoader.js +351 -97
  15. package/examples/jsm/loaders/FBXLoader.js +1 -1
  16. package/examples/jsm/loaders/GLTFLoader.js +59 -0
  17. package/examples/jsm/loaders/KTX2Loader.js +3 -10
  18. package/examples/jsm/loaders/LUT3dlLoader.js +0 -15
  19. package/examples/jsm/loaders/LUTCubeLoader.js +0 -14
  20. package/examples/jsm/loaders/LUTImageLoader.js +0 -14
  21. package/examples/jsm/loaders/RGBMLoader.js +16 -0
  22. package/examples/jsm/loaders/VRMLLoader.js +1 -1
  23. package/examples/jsm/loaders/lwo/IFFParser.js +8 -5
  24. package/examples/jsm/materials/MeshGouraudMaterial.js +7 -1
  25. package/examples/jsm/math/Octree.js +26 -20
  26. package/examples/jsm/misc/GPUComputationRenderer.js +0 -6
  27. package/examples/jsm/nodes/Nodes.js +10 -4
  28. package/examples/jsm/nodes/accessors/AccessorsUtils.js +16 -1
  29. package/examples/jsm/nodes/accessors/BatchNode.js +78 -0
  30. package/examples/jsm/nodes/accessors/ClippingNode.js +3 -2
  31. package/examples/jsm/nodes/accessors/InstanceNode.js +25 -2
  32. package/examples/jsm/nodes/accessors/MaterialNode.js +107 -3
  33. package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +1 -1
  34. package/examples/jsm/nodes/accessors/MorphNode.js +13 -3
  35. package/examples/jsm/nodes/accessors/NormalNode.js +12 -2
  36. package/examples/jsm/nodes/accessors/ReferenceNode.js +1 -1
  37. package/examples/jsm/nodes/accessors/RendererReferenceNode.js +29 -0
  38. package/examples/jsm/nodes/accessors/StorageBufferNode.js +9 -0
  39. package/examples/jsm/nodes/accessors/TextureNode.js +51 -10
  40. package/examples/jsm/nodes/accessors/TextureSizeNode.js +1 -1
  41. package/examples/jsm/nodes/code/FunctionNode.js +0 -8
  42. package/examples/jsm/nodes/core/Node.js +63 -4
  43. package/examples/jsm/nodes/core/NodeBuilder.js +26 -25
  44. package/examples/jsm/nodes/core/NodeFrame.js +10 -10
  45. package/examples/jsm/nodes/core/NodeUtils.js +2 -2
  46. package/examples/jsm/nodes/core/OutputStructNode.js +2 -1
  47. package/examples/jsm/nodes/core/PropertyNode.js +10 -0
  48. package/examples/jsm/nodes/core/UniformNode.js +20 -0
  49. package/examples/jsm/nodes/display/BumpMapNode.js +7 -26
  50. package/examples/jsm/nodes/display/FrontFacingNode.js +13 -0
  51. package/examples/jsm/nodes/display/PassNode.js +17 -1
  52. package/examples/jsm/nodes/display/ToneMappingNode.js +8 -4
  53. package/examples/jsm/nodes/display/ViewportDepthNode.js +1 -1
  54. package/examples/jsm/nodes/display/ViewportNode.js +4 -2
  55. package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +6 -0
  56. package/examples/jsm/nodes/display/ViewportTextureNode.js +4 -1
  57. package/examples/jsm/nodes/fog/FogExp2Node.js +4 -5
  58. package/examples/jsm/nodes/fog/FogNode.js +13 -3
  59. package/examples/jsm/nodes/fog/FogRangeNode.js +4 -3
  60. package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +26 -7
  61. package/examples/jsm/nodes/functions/BSDF/D_GGX_Anisotropic.js +28 -0
  62. package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +1 -3
  63. package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +29 -0
  64. package/examples/jsm/nodes/functions/PhongLightingModel.js +1 -1
  65. package/examples/jsm/nodes/functions/PhysicalLightingModel.js +164 -10
  66. package/examples/jsm/nodes/functions/ShadowMaskModel.js +31 -0
  67. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +19 -5
  68. package/examples/jsm/nodes/lighting/DirectionalLightNode.js +2 -1
  69. package/examples/jsm/nodes/lighting/EnvironmentNode.js +22 -70
  70. package/examples/jsm/nodes/lighting/IrradianceNode.js +24 -0
  71. package/examples/jsm/nodes/lighting/LightsNode.js +11 -1
  72. package/examples/jsm/nodes/lighting/PointLightNode.js +2 -1
  73. package/examples/jsm/nodes/lighting/SpotLightNode.js +2 -1
  74. package/examples/jsm/nodes/materials/Line2NodeMaterial.js +10 -6
  75. package/examples/jsm/nodes/materials/Materials.js +1 -0
  76. package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +0 -2
  77. package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +2 -2
  78. package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +76 -5
  79. package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +11 -4
  80. package/examples/jsm/nodes/materials/NodeMaterial.js +55 -43
  81. package/examples/jsm/nodes/materials/ShadowNodeMaterial.js +34 -0
  82. package/examples/jsm/nodes/pmrem/PMREMNode.js +193 -0
  83. package/examples/jsm/nodes/pmrem/PMREMUtils.js +288 -0
  84. package/examples/jsm/nodes/shadernode/ShaderNode.js +3 -9
  85. package/examples/jsm/nodes/utils/EquirectUVNode.js +1 -1
  86. package/examples/jsm/objects/QuadMesh.js +7 -23
  87. package/examples/jsm/physics/JoltPhysics.js +281 -0
  88. package/examples/jsm/physics/RapierPhysics.js +4 -4
  89. package/examples/jsm/postprocessing/GlitchPass.js +0 -3
  90. package/examples/jsm/postprocessing/LUTPass.js +5 -71
  91. package/examples/jsm/postprocessing/RenderTransitionPass.js +193 -0
  92. package/examples/jsm/postprocessing/SAOPass.js +0 -1
  93. package/examples/jsm/postprocessing/SSAOPass.js +0 -3
  94. package/examples/jsm/renderers/common/Animation.js +3 -0
  95. package/examples/jsm/renderers/common/Background.js +8 -8
  96. package/examples/jsm/renderers/common/ClippingContext.js +1 -1
  97. package/examples/jsm/renderers/common/Info.js +11 -19
  98. package/examples/jsm/renderers/common/PostProcessing.js +12 -4
  99. package/examples/jsm/renderers/common/RenderContext.js +1 -1
  100. package/examples/jsm/renderers/common/RenderList.js +1 -1
  101. package/examples/jsm/renderers/common/RenderObject.js +47 -5
  102. package/examples/jsm/renderers/common/RenderObjects.js +1 -1
  103. package/examples/jsm/renderers/common/Renderer.js +153 -21
  104. package/examples/jsm/renderers/common/Textures.js +1 -1
  105. package/examples/jsm/renderers/common/extras/PMREMGenerator.js +773 -0
  106. package/examples/jsm/renderers/common/nodes/Nodes.js +34 -63
  107. package/examples/jsm/renderers/webgl/WebGLBackend.js +146 -36
  108. package/examples/jsm/renderers/webgl/WebGLBufferRenderer.js +145 -0
  109. package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +9 -3
  110. package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +1 -1
  111. package/examples/jsm/renderers/webgl/utils/WebGLConstants.js +1 -0
  112. package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +64 -7
  113. package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +6 -23
  114. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +77 -60
  115. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +21 -4
  116. package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +29 -1
  117. package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +18 -4
  118. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +92 -18
  119. package/examples/jsm/transpiler/GLSLDecoder.js +1 -1
  120. package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
  121. package/examples/jsm/utils/GPUStatsPanel.js +10 -45
  122. package/examples/jsm/utils/SceneUtils.js +60 -1
  123. package/examples/jsm/utils/TextureUtils.js +1 -1
  124. package/examples/jsm/webxr/OculusHandModel.js +3 -2
  125. package/examples/jsm/webxr/XRHandModelFactory.js +4 -2
  126. package/package.json +1 -1
  127. package/src/Three.js +0 -1
  128. package/src/animation/AnimationClip.js +1 -1
  129. package/src/constants.js +3 -3
  130. package/src/core/Object3D.js +10 -7
  131. package/src/core/RenderTarget.js +8 -0
  132. package/src/extras/PMREMGenerator.js +21 -11
  133. package/src/loaders/FileLoader.js +1 -1
  134. package/src/loaders/MaterialLoader.js +1 -0
  135. package/src/loaders/ObjectLoader.js +2 -0
  136. package/src/materials/Material.js +2 -0
  137. package/src/materials/MeshPhysicalMaterial.js +20 -0
  138. package/src/materials/ShaderMaterial.js +0 -4
  139. package/src/math/Spherical.js +4 -5
  140. package/src/objects/BatchedMesh.js +27 -3
  141. package/src/objects/InstancedMesh.js +10 -0
  142. package/src/objects/Line.js +66 -43
  143. package/src/renderers/WebGLRenderer.js +130 -158
  144. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +6 -0
  145. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +1 -0
  146. package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +2 -2
  147. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +1 -1
  148. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +2 -10
  149. package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +2 -16
  150. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +32 -22
  151. package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +17 -9
  152. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
  153. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +47 -13
  154. package/src/renderers/shaders/ShaderChunk.js +0 -2
  155. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -0
  156. package/src/renderers/shaders/ShaderLib.js +2 -1
  157. package/src/renderers/shaders/UniformsUtils.js +10 -1
  158. package/src/renderers/webgl/WebGLAttributes.js +6 -33
  159. package/src/renderers/webgl/WebGLBackground.js +18 -3
  160. package/src/renderers/webgl/WebGLBindingStates.js +14 -51
  161. package/src/renderers/webgl/WebGLBufferRenderer.js +35 -21
  162. package/src/renderers/webgl/WebGLCapabilities.js +35 -13
  163. package/src/renderers/webgl/WebGLCubeUVMaps.js +10 -6
  164. package/src/renderers/webgl/WebGLExtensions.js +4 -19
  165. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +35 -21
  166. package/src/renderers/webgl/WebGLLights.js +6 -32
  167. package/src/renderers/webgl/WebGLMaterials.js +8 -3
  168. package/src/renderers/webgl/WebGLMorphtargets.js +79 -217
  169. package/src/renderers/webgl/WebGLProgram.js +21 -52
  170. package/src/renderers/webgl/WebGLPrograms.js +24 -31
  171. package/src/renderers/webgl/WebGLRenderStates.js +13 -7
  172. package/src/renderers/webgl/WebGLShadowMap.js +25 -25
  173. package/src/renderers/webgl/WebGLState.js +15 -59
  174. package/src/renderers/webgl/WebGLTextures.js +138 -292
  175. package/src/renderers/webgl/WebGLUniformsGroups.js +1 -1
  176. package/src/renderers/webgl/WebGLUtils.js +9 -78
  177. package/src/renderers/webxr/WebXRDepthSensing.js +2 -3
  178. package/src/renderers/webxr/WebXRManager.js +4 -6
  179. package/src/scenes/Scene.js +7 -1
  180. package/src/textures/Texture.js +11 -1
  181. package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +0 -37
  182. package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +0 -320
  183. package/examples/jsm/renderers/webgl-legacy/nodes/SlotNode.js +0 -26
  184. package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +0 -794
  185. package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js +0 -51
  186. package/src/renderers/WebGL1Renderer.js +0 -7
  187. package/src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl.js +0 -10
@@ -0,0 +1,288 @@
1
+ import { tslFn, int, float, vec2, vec3, vec4, If } from '../shadernode/ShaderNode.js';
2
+ import { cos, sin, abs, max, exp2, log2, clamp, fract, mix, floor, normalize, cross, all } from '../math/MathNode.js';
3
+ import { mul } from '../math/OperatorNode.js';
4
+ import { cond } from '../math/CondNode.js';
5
+ import { loop, Break } from '../utils/LoopNode.js';
6
+
7
+ // These defines must match with PMREMGenerator
8
+
9
+ const cubeUV_r0 = float( 1.0 );
10
+ const cubeUV_m0 = float( - 2.0 );
11
+ const cubeUV_r1 = float( 0.8 );
12
+ const cubeUV_m1 = float( - 1.0 );
13
+ const cubeUV_r4 = float( 0.4 );
14
+ const cubeUV_m4 = float( 2.0 );
15
+ const cubeUV_r5 = float( 0.305 );
16
+ const cubeUV_m5 = float( 3.0 );
17
+ const cubeUV_r6 = float( 0.21 );
18
+ const cubeUV_m6 = float( 4.0 );
19
+
20
+ const cubeUV_minMipLevel = float( 4.0 );
21
+ const cubeUV_minTileSize = float( 16.0 );
22
+
23
+ // These shader functions convert between the UV coordinates of a single face of
24
+ // a cubemap, the 0-5 integer index of a cube face, and the direction vector for
25
+ // sampling a textureCube (not generally normalized ).
26
+
27
+ const getFace = tslFn( ( [ direction ] ) => {
28
+
29
+ const absDirection = vec3( abs( direction ) ).toVar();
30
+ const face = float( - 1.0 ).toVar();
31
+
32
+ If( absDirection.x.greaterThan( absDirection.z ), () => {
33
+
34
+ If( absDirection.x.greaterThan( absDirection.y ), () => {
35
+
36
+ face.assign( cond( direction.x.greaterThan( 0.0 ), 0.0, 3.0 ) );
37
+
38
+ } ).else( () => {
39
+
40
+ face.assign( cond( direction.y.greaterThan( 0.0 ), 1.0, 4.0 ) );
41
+
42
+ } );
43
+
44
+ } ).else( () => {
45
+
46
+ If( absDirection.z.greaterThan( absDirection.y ), () => {
47
+
48
+ face.assign( cond( direction.z.greaterThan( 0.0 ), 2.0, 5.0 ) );
49
+
50
+ } ).else( () => {
51
+
52
+ face.assign( cond( direction.y.greaterThan( 0.0 ), 1.0, 4.0 ) );
53
+
54
+ } );
55
+
56
+ } );
57
+
58
+ return face;
59
+
60
+ } ).setLayout( {
61
+ name: 'getFace',
62
+ type: 'float',
63
+ inputs: [
64
+ { name: 'direction', type: 'vec3' }
65
+ ]
66
+ } );
67
+
68
+ // RH coordinate system; PMREM face-indexing convention
69
+ const getUV = tslFn( ( [ direction, face ] ) => {
70
+
71
+ const uv = vec2().toVar();
72
+
73
+ If( face.equal( 0.0 ), () => {
74
+
75
+ uv.assign( vec2( direction.z, direction.y ).div( abs( direction.x ) ) ); // pos x
76
+
77
+ } ).elseif( face.equal( 1.0 ), () => {
78
+
79
+ uv.assign( vec2( direction.x.negate(), direction.z.negate() ).div( abs( direction.y ) ) ); // pos y
80
+
81
+ } ).elseif( face.equal( 2.0 ), () => {
82
+
83
+ uv.assign( vec2( direction.x.negate(), direction.y ).div( abs( direction.z ) ) ); // pos z
84
+
85
+ } ).elseif( face.equal( 3.0 ), () => {
86
+
87
+ uv.assign( vec2( direction.z.negate(), direction.y ).div( abs( direction.x ) ) ); // neg x
88
+
89
+ } ).elseif( face.equal( 4.0 ), () => {
90
+
91
+ uv.assign( vec2( direction.x.negate(), direction.z ).div( abs( direction.y ) ) ); // neg y
92
+
93
+ } ).else( () => {
94
+
95
+ uv.assign( vec2( direction.x, direction.y ).div( abs( direction.z ) ) ); // neg z
96
+
97
+ } );
98
+
99
+ return mul( 0.5, uv.add( 1.0 ) );
100
+
101
+ } ).setLayout( {
102
+ name: 'getUV',
103
+ type: 'vec2',
104
+ inputs: [
105
+ { name: 'direction', type: 'vec3' },
106
+ { name: 'face', type: 'float' }
107
+ ]
108
+ } );
109
+
110
+ const roughnessToMip = tslFn( ( [ roughness ] ) => {
111
+
112
+ const mip = float( 0.0 ).toVar();
113
+
114
+ If( roughness.greaterThanEqual( cubeUV_r1 ), () => {
115
+
116
+ mip.assign( cubeUV_r0.sub( roughness ).mul( cubeUV_m1.sub( cubeUV_m0 ) ).div( cubeUV_r0.sub( cubeUV_r1 ) ).add( cubeUV_m0 ) );
117
+
118
+ } ).elseif( roughness.greaterThanEqual( cubeUV_r4 ), () => {
119
+
120
+ mip.assign( cubeUV_r1.sub( roughness ).mul( cubeUV_m4.sub( cubeUV_m1 ) ).div( cubeUV_r1.sub( cubeUV_r4 ) ).add( cubeUV_m1 ) );
121
+
122
+ } ).elseif( roughness.greaterThanEqual( cubeUV_r5 ), () => {
123
+
124
+ mip.assign( cubeUV_r4.sub( roughness ).mul( cubeUV_m5.sub( cubeUV_m4 ) ).div( cubeUV_r4.sub( cubeUV_r5 ) ).add( cubeUV_m4 ) );
125
+
126
+ } ).elseif( roughness.greaterThanEqual( cubeUV_r6 ), () => {
127
+
128
+ mip.assign( cubeUV_r5.sub( roughness ).mul( cubeUV_m6.sub( cubeUV_m5 ) ).div( cubeUV_r5.sub( cubeUV_r6 ) ).add( cubeUV_m5 ) );
129
+
130
+ } ).else( () => {
131
+
132
+ mip.assign( float( - 2.0 ).mul( log2( mul( 1.16, roughness ) ) ) ); // 1.16 = 1.79^0.25
133
+
134
+ } );
135
+
136
+ return mip;
137
+
138
+ } ).setLayout( {
139
+ name: 'roughnessToMip',
140
+ type: 'float',
141
+ inputs: [
142
+ { name: 'roughness', type: 'float' }
143
+ ]
144
+ } );
145
+
146
+ // RH coordinate system; PMREM face-indexing convention
147
+ export const getDirection = tslFn( ( [ uv_immutable, face ] ) => {
148
+
149
+ const uv = uv_immutable.toVar();
150
+ uv.assign( mul( 2.0, uv ).sub( 1.0 ) );
151
+ const direction = vec3( uv, 1.0 ).toVar();
152
+
153
+ If( face.equal( 0.0 ), () => {
154
+
155
+ direction.assign( direction.zyx ); // ( 1, v, u ) pos x
156
+
157
+ } ).elseif( face.equal( 1.0 ), () => {
158
+
159
+ direction.assign( direction.xzy );
160
+ direction.xz.mulAssign( - 1.0 ); // ( -u, 1, -v ) pos y
161
+
162
+ } ).elseif( face.equal( 2.0 ), () => {
163
+
164
+ direction.x.mulAssign( - 1.0 ); // ( -u, v, 1 ) pos z
165
+
166
+ } ).elseif( face.equal( 3.0 ), () => {
167
+
168
+ direction.assign( direction.zyx );
169
+ direction.xz.mulAssign( - 1.0 ); // ( -1, v, -u ) neg x
170
+
171
+ } ).elseif( face.equal( 4.0 ), () => {
172
+
173
+ direction.assign( direction.xzy );
174
+ direction.xy.mulAssign( - 1.0 ); // ( -u, -1, v ) neg y
175
+
176
+ } ).elseif( face.equal( 5.0 ), () => {
177
+
178
+ direction.z.mulAssign( - 1.0 ); // ( u, v, -1 ) neg zS
179
+
180
+ } );
181
+
182
+ return direction;
183
+
184
+ } ).setLayout( {
185
+ name: 'getDirection',
186
+ type: 'vec3',
187
+ inputs: [
188
+ { name: 'uv', type: 'vec2' },
189
+ { name: 'face', type: 'float' }
190
+ ]
191
+ } );
192
+
193
+ //
194
+
195
+ export const textureCubeUV = tslFn( ( [ envMap, sampleDir_immutable, roughness_immutable, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP ] ) => {
196
+
197
+ const roughness = float( roughness_immutable );
198
+ const sampleDir = vec3( sampleDir_immutable );
199
+
200
+ const mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP );
201
+ const mipF = fract( mip );
202
+ const mipInt = floor( mip );
203
+ const color0 = vec3( bilinearCubeUV( envMap, sampleDir, mipInt, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP ) ).toVar();
204
+
205
+ If( mipF.notEqual( 0.0 ), () => {
206
+
207
+ const color1 = vec3( bilinearCubeUV( envMap, sampleDir, mipInt.add( 1.0 ), CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP ) ).toVar();
208
+
209
+ color0.assign( mix( color0, color1, mipF ) );
210
+
211
+ } );
212
+
213
+ return color0;
214
+
215
+ } );
216
+
217
+ const bilinearCubeUV = tslFn( ( [ envMap, direction_immutable, mipInt_immutable, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP ] ) => {
218
+
219
+ const mipInt = float( mipInt_immutable ).toVar();
220
+ const direction = vec3( direction_immutable );
221
+ const face = float( getFace( direction ) ).toVar();
222
+ const filterInt = float( max( cubeUV_minMipLevel.sub( mipInt ), 0.0 ) ).toVar();
223
+ mipInt.assign( max( mipInt, cubeUV_minMipLevel ) );
224
+ const faceSize = float( exp2( mipInt ) ).toVar();
225
+ const uv = vec2( getUV( direction, face ).mul( faceSize.sub( 2.0 ) ).add( 1.0 ) ).toVar();
226
+
227
+ If( face.greaterThan( 2.0 ), () => {
228
+
229
+ uv.y.addAssign( faceSize );
230
+ face.subAssign( 3.0 );
231
+
232
+ } );
233
+
234
+ uv.x.addAssign( face.mul( faceSize ) );
235
+ uv.x.addAssign( filterInt.mul( mul( 3.0, cubeUV_minTileSize ) ) );
236
+ uv.y.addAssign( mul( 4.0, exp2( CUBEUV_MAX_MIP ).sub( faceSize ) ) );
237
+ uv.x.mulAssign( CUBEUV_TEXEL_WIDTH );
238
+ uv.y.mulAssign( CUBEUV_TEXEL_HEIGHT );
239
+
240
+ return envMap.uv( uv ).grad( vec2(), vec2() ); // disable anisotropic filtering
241
+
242
+ } );
243
+
244
+ const getSample = tslFn( ( { envMap, mipInt, outputDirection, theta, axis, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP } ) => {
245
+
246
+ const cosTheta = cos( theta );
247
+
248
+ // Rodrigues' axis-angle rotation
249
+ const sampleDirection = outputDirection.mul( cosTheta )
250
+ .add( axis.cross( outputDirection ).mul( sin( theta ) ) )
251
+ .add( axis.mul( axis.dot( outputDirection ).mul( cosTheta.oneMinus() ) ) );
252
+
253
+ return bilinearCubeUV( envMap, sampleDirection, mipInt, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP );
254
+
255
+ } );
256
+
257
+ export const blur = tslFn( ( { n, latitudinal, poleAxis, outputDirection, weights, samples, dTheta, mipInt, envMap, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP } ) => {
258
+
259
+ const axis = vec3( cond( latitudinal, poleAxis, cross( poleAxis, outputDirection ) ) ).toVar();
260
+
261
+ If( all( axis.equals( vec3( 0.0 ) ) ), () => {
262
+
263
+ axis.assign( vec3( outputDirection.z, 0.0, outputDirection.x.negate() ) );
264
+
265
+ } );
266
+
267
+ axis.assign( normalize( axis ) );
268
+
269
+ const gl_FragColor = vec3().toVar();
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
+
272
+ loop( { start: int( 1 ), end: n }, ( { i } ) => {
273
+
274
+ If( i.greaterThanEqual( samples ), () => {
275
+
276
+ Break();
277
+
278
+ } );
279
+
280
+ const theta = float( dTheta.mul( float( i ) ) ).toVar();
281
+ gl_FragColor.addAssign( weights.element( i ).mul( getSample( { theta: theta.mul( - 1.0 ), axis, outputDirection, mipInt, envMap, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP } ) ) );
282
+ gl_FragColor.addAssign( weights.element( i ).mul( getSample( { theta, axis, outputDirection, mipInt, envMap, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP } ) ) );
283
+
284
+ } );
285
+
286
+ return vec4( gl_FragColor, 1 );
287
+
288
+ } );
@@ -456,6 +456,8 @@ const ConvertType = function ( type, cacheMap = null ) {
456
456
 
457
457
  // exports
458
458
 
459
+ export const defined = ( value ) => value && value.value;
460
+
459
461
  // utils
460
462
 
461
463
  export const getConstNodeType = ( value ) => ( value !== undefined && value !== null ) ? ( value.nodeType || value.convertTo || ( typeof value === 'string' ? value : null ) ) : null;
@@ -474,14 +476,6 @@ export const nodeArray = ( val, altType = null ) => new ShaderNodeArray( val, al
474
476
  export const nodeProxy = ( ...params ) => new ShaderNodeProxy( ...params );
475
477
  export const nodeImmutable = ( ...params ) => new ShaderNodeImmutable( ...params );
476
478
 
477
- export const shader = ( jsFunc ) => { // @deprecated, r154
478
-
479
- console.warn( 'TSL: shader() is deprecated. Use tslFn() instead.' );
480
-
481
- return new ShaderNode( jsFunc );
482
-
483
- };
484
-
485
479
  export const tslFn = ( jsFunc ) => {
486
480
 
487
481
  const shaderNode = new ShaderNode( jsFunc );
@@ -555,7 +549,7 @@ addNodeElement( 'append', append );
555
549
  export const color = new ConvertType( 'color' );
556
550
 
557
551
  export const float = new ConvertType( 'float', cacheMaps.float );
558
- export const int = new ConvertType( 'int', cacheMaps.int );
552
+ export const int = new ConvertType( 'int', cacheMaps.ints );
559
553
  export const uint = new ConvertType( 'uint', cacheMaps.uint );
560
554
  export const bool = new ConvertType( 'bool', cacheMaps.bool );
561
555
 
@@ -18,7 +18,7 @@ class EquirectUVNode extends TempNode {
18
18
  const dir = this.dirNode;
19
19
 
20
20
  const u = dir.z.atan2( dir.x ).mul( 1 / ( Math.PI * 2 ) ).add( 0.5 );
21
- const v = dir.y.negate().clamp( - 1.0, 1.0 ).asin().mul( 1 / Math.PI ).add( 0.5 ); // @TODO: The use of negate() here could be an NDC issue.
21
+ const v = dir.y.clamp( - 1.0, 1.0 ).asin().mul( 1 / Math.PI ).add( 0.5 );
22
22
 
23
23
  return vec2( u, v );
24
24
 
@@ -23,41 +23,25 @@ class QuadGeometry extends BufferGeometry {
23
23
 
24
24
  const _geometry = new QuadGeometry();
25
25
 
26
- class QuadMesh {
26
+ class QuadMesh extends Mesh {
27
27
 
28
28
  constructor( material = null ) {
29
29
 
30
- this._mesh = new Mesh( _geometry, material );
30
+ super( _geometry, material );
31
31
 
32
- }
33
-
34
- dispose() {
35
-
36
- this._mesh.geometry.dispose();
37
-
38
- }
39
-
40
- async renderAsync( renderer ) {
41
-
42
- await renderer.renderAsync( this._mesh, _camera );
43
-
44
- }
45
-
46
- get material() {
47
-
48
- return this._mesh.material;
32
+ this.camera = _camera;
49
33
 
50
34
  }
51
35
 
52
- set material( value ) {
36
+ renderAsync( renderer ) {
53
37
 
54
- this._mesh.material = value;
38
+ return renderer.renderAsync( this, _camera );
55
39
 
56
40
  }
57
41
 
58
- get render() {
42
+ render( renderer ) {
59
43
 
60
- return this.renderAsync;
44
+ renderer.render( this, _camera );
61
45
 
62
46
  }
63
47
 
@@ -0,0 +1,281 @@
1
+ import { Clock, Vector3, Quaternion, Matrix4 } from 'three';
2
+
3
+ const JOLT_PATH = 'https://cdn.jsdelivr.net/npm/jolt-physics@0.23.0/dist/jolt-physics.wasm-compat.js';
4
+
5
+ const frameRate = 60;
6
+
7
+ let Jolt = null;
8
+
9
+ function getShape( geometry ) {
10
+
11
+ const parameters = geometry.parameters;
12
+
13
+ // TODO change type to is*
14
+
15
+ if ( geometry.type === 'BoxGeometry' ) {
16
+
17
+ const sx = parameters.width !== undefined ? parameters.width / 2 : 0.5;
18
+ const sy = parameters.height !== undefined ? parameters.height / 2 : 0.5;
19
+ const sz = parameters.depth !== undefined ? parameters.depth / 2 : 0.5;
20
+
21
+ return new Jolt.BoxShape( new Jolt.Vec3( sx, sy, sz ), 0.05 * Math.min( sx, sy, sz ), null );
22
+
23
+ } else if ( geometry.type === 'SphereGeometry' || geometry.type === 'IcosahedronGeometry' ) {
24
+
25
+ const radius = parameters.radius !== undefined ? parameters.radius : 1;
26
+
27
+ return new Jolt.SphereShape( radius, null );
28
+
29
+ }
30
+
31
+ return null;
32
+
33
+ }
34
+
35
+ // Object layers
36
+ const LAYER_NON_MOVING = 0;
37
+ const LAYER_MOVING = 1;
38
+ const NUM_OBJECT_LAYERS = 2;
39
+
40
+ function setupCollisionFiltering( settings ) {
41
+
42
+ let objectFilter = new Jolt.ObjectLayerPairFilterTable( NUM_OBJECT_LAYERS );
43
+ objectFilter.EnableCollision( LAYER_NON_MOVING, LAYER_MOVING );
44
+ objectFilter.EnableCollision( LAYER_MOVING, LAYER_MOVING );
45
+
46
+ const BP_LAYER_NON_MOVING = new Jolt.BroadPhaseLayer( 0 );
47
+ const BP_LAYER_MOVING = new Jolt.BroadPhaseLayer( 1 );
48
+ const NUM_BROAD_PHASE_LAYERS = 2;
49
+
50
+ let bpInterface = new Jolt.BroadPhaseLayerInterfaceTable( NUM_OBJECT_LAYERS, NUM_BROAD_PHASE_LAYERS );
51
+ bpInterface.MapObjectToBroadPhaseLayer( LAYER_NON_MOVING, BP_LAYER_NON_MOVING );
52
+ bpInterface.MapObjectToBroadPhaseLayer( LAYER_MOVING, BP_LAYER_MOVING );
53
+
54
+ settings.mObjectLayerPairFilter = objectFilter;
55
+ settings.mBroadPhaseLayerInterface = bpInterface;
56
+ settings.mObjectVsBroadPhaseLayerFilter = new Jolt.ObjectVsBroadPhaseLayerFilterTable( settings.mBroadPhaseLayerInterface, NUM_BROAD_PHASE_LAYERS, settings.mObjectLayerPairFilter, NUM_OBJECT_LAYERS );
57
+
58
+ };
59
+
60
+ async function JoltPhysics() {
61
+
62
+ if ( Jolt === null ) {
63
+
64
+ const { default: initJolt } = await import( JOLT_PATH );
65
+ Jolt = await initJolt();
66
+
67
+ }
68
+
69
+ const settings = new Jolt.JoltSettings();
70
+ setupCollisionFiltering( settings );
71
+
72
+ const jolt = new Jolt.JoltInterface( settings );
73
+ Jolt.destroy( settings );
74
+
75
+ const physicsSystem = jolt.GetPhysicsSystem();
76
+ const bodyInterface = physicsSystem.GetBodyInterface();
77
+
78
+ const meshes = [];
79
+ const meshMap = new WeakMap();
80
+
81
+ const _position = new Vector3();
82
+ const _quaternion = new Quaternion();
83
+ const _scale = new Vector3( 1, 1, 1 );
84
+
85
+ const _matrix = new Matrix4();
86
+
87
+ function addScene( scene ) {
88
+
89
+ scene.traverse( function ( child ) {
90
+
91
+ if ( child.isMesh ) {
92
+
93
+ const physics = child.userData.physics;
94
+
95
+ if ( physics ) {
96
+
97
+ addMesh( child, physics.mass, physics.restitution );
98
+
99
+ }
100
+
101
+ }
102
+
103
+ } );
104
+
105
+ }
106
+
107
+ function addMesh( mesh, mass = 0, restitution = 0 ) {
108
+
109
+ const shape = getShape( mesh.geometry );
110
+
111
+ if ( shape === null ) return;
112
+
113
+ const body = mesh.isInstancedMesh
114
+ ? createInstancedBody( mesh, mass, restitution, shape )
115
+ : createBody( mesh.position, mesh.quaternion, mass, restitution, shape );
116
+
117
+ if ( mass > 0 ) {
118
+
119
+ meshes.push( mesh );
120
+ meshMap.set( mesh, body );
121
+
122
+ }
123
+
124
+ }
125
+
126
+ function createInstancedBody( mesh, mass, restitution, shape ) {
127
+
128
+ const array = mesh.instanceMatrix.array;
129
+
130
+ const bodies = [];
131
+
132
+ for ( let i = 0; i < mesh.count; i ++ ) {
133
+
134
+ const position = _position.fromArray( array, i * 16 + 12 );
135
+ const quaternion = _quaternion.setFromRotationMatrix( _matrix.fromArray( array, i * 16 ) ); // TODO Copilot did this
136
+ bodies.push( createBody( position, quaternion, mass, restitution, shape ) );
137
+
138
+ }
139
+
140
+ return bodies;
141
+
142
+ }
143
+
144
+ function createBody( position, rotation, mass, restitution, shape ) {
145
+
146
+ const pos = new Jolt.Vec3( position.x, position.y, position.z );
147
+ const rot = new Jolt.Quat( rotation.x, rotation.y, rotation.z, rotation.w );
148
+
149
+ const motion = mass > 0 ? Jolt.EMotionType_Dynamic : Jolt.EMotionType_Static;
150
+ const layer = mass > 0 ? LAYER_MOVING : LAYER_NON_MOVING;
151
+
152
+ const creationSettings = new Jolt.BodyCreationSettings( shape, pos, rot, motion, layer );
153
+ creationSettings.mRestitution = restitution;
154
+
155
+ const body = bodyInterface.CreateBody( creationSettings );
156
+
157
+ bodyInterface.AddBody( body.GetID(), Jolt.EActivation_Activate );
158
+
159
+ Jolt.destroy( creationSettings );
160
+
161
+ return body;
162
+
163
+ }
164
+
165
+ function setMeshPosition( mesh, position, index = 0 ) {
166
+
167
+ if ( mesh.isInstancedMesh ) {
168
+
169
+ const bodies = meshMap.get( mesh );
170
+
171
+ const body = bodies[ index ];
172
+
173
+ bodyInterface.RemoveBody( body.GetID() );
174
+ bodyInterface.DestroyBody( body.GetID() );
175
+
176
+ const physics = mesh.userData.physics;
177
+
178
+ let shape = body.GetShape();
179
+ let body2 = createBody( position, { x: 0, y: 0, z: 0, w: 1 }, physics.mass, physics.restitution, shape );
180
+
181
+ bodies[ index ] = body2;
182
+
183
+ } else {
184
+
185
+ // TODO: Implement this
186
+
187
+ }
188
+
189
+ }
190
+
191
+ function setMeshVelocity( mesh, velocity, index = 0 ) {
192
+
193
+ /*
194
+ let body = meshMap.get( mesh );
195
+
196
+ if ( mesh.isInstancedMesh ) {
197
+
198
+ body = body[ index ];
199
+
200
+ }
201
+
202
+ body.setLinvel( velocity );
203
+ */
204
+
205
+ }
206
+
207
+ //
208
+
209
+ const clock = new Clock();
210
+
211
+ function step() {
212
+
213
+ let deltaTime = clock.getDelta();
214
+
215
+ // Don't go below 30 Hz to prevent spiral of death
216
+ deltaTime = Math.min( deltaTime, 1.0 / 30.0 );
217
+
218
+ // When running below 55 Hz, do 2 steps instead of 1
219
+ const numSteps = deltaTime > 1.0 / 55.0 ? 2 : 1;
220
+
221
+ // Step the physics world
222
+ jolt.Step( deltaTime, numSteps );
223
+
224
+ //
225
+
226
+ for ( let i = 0, l = meshes.length; i < l; i ++ ) {
227
+
228
+ const mesh = meshes[ i ];
229
+
230
+ if ( mesh.isInstancedMesh ) {
231
+
232
+ const array = mesh.instanceMatrix.array;
233
+ const bodies = meshMap.get( mesh );
234
+
235
+ for ( let j = 0; j < bodies.length; j ++ ) {
236
+
237
+ const body = bodies[ j ];
238
+
239
+ const position = body.GetPosition();
240
+ const quaternion = body.GetRotation();
241
+
242
+ _position.set( position.GetX(), position.GetY(), position.GetZ() );
243
+ _quaternion.set( quaternion.GetX(), quaternion.GetY(), quaternion.GetZ(), quaternion.GetW() );
244
+
245
+ _matrix.compose( _position, _quaternion, _scale ).toArray( array, j * 16 );
246
+
247
+ }
248
+
249
+ mesh.instanceMatrix.needsUpdate = true;
250
+ mesh.computeBoundingSphere();
251
+
252
+ } else {
253
+
254
+ const body = meshMap.get( mesh );
255
+
256
+ const position = body.GetPosition();
257
+ const rotation = body.GetRotation();
258
+
259
+ mesh.position.set( position.GetX(), position.GetY(), position.GetZ() );
260
+ mesh.quaternion.set( rotation.GetX(), rotation.GetY(), rotation.GetZ(), rotation.GetW() );
261
+
262
+ }
263
+
264
+ }
265
+
266
+ }
267
+
268
+ // animate
269
+
270
+ setInterval( step, 1000 / frameRate );
271
+
272
+ return {
273
+ addScene: addScene,
274
+ addMesh: addMesh,
275
+ setMeshPosition: setMeshPosition,
276
+ setMeshVelocity: setMeshVelocity
277
+ };
278
+
279
+ }
280
+
281
+ export { JoltPhysics };
@@ -1,6 +1,6 @@
1
1
  import { Clock, Vector3, Quaternion, Matrix4 } from 'three';
2
2
 
3
- const RAPIER_PATH = 'https://cdn.skypack.dev/@dimforge/rapier3d-compat@0.11.2';
3
+ const RAPIER_PATH = 'https://cdn.skypack.dev/@dimforge/rapier3d-compat@0.12.0';
4
4
 
5
5
  const frameRate = 60;
6
6
 
@@ -9,7 +9,7 @@ const ZERO = new Vector3();
9
9
 
10
10
  let RAPIER = null;
11
11
 
12
- function getCollider( geometry ) {
12
+ function getShape( geometry ) {
13
13
 
14
14
  const parameters = geometry.parameters;
15
15
 
@@ -43,7 +43,7 @@ async function RapierPhysics() {
43
43
 
44
44
  }
45
45
 
46
- // Docs: https://rapier.rs/docs/api/javascript/JavaScript3D/
46
+ // Docs: https://rapier.rs/docs/api/javascript/JavaScript3D/
47
47
 
48
48
  const gravity = new Vector3( 0.0, - 9.81, 0.0 );
49
49
  const world = new RAPIER.World( gravity );
@@ -77,7 +77,7 @@ async function RapierPhysics() {
77
77
 
78
78
  function addMesh( mesh, mass = 0, restitution = 0 ) {
79
79
 
80
- const shape = getCollider( mesh.geometry );
80
+ const shape = getShape( mesh.geometry );
81
81
 
82
82
  if ( shape === null ) return;
83
83
 
@@ -3,7 +3,6 @@ import {
3
3
  FloatType,
4
4
  MathUtils,
5
5
  RedFormat,
6
- LuminanceFormat,
7
6
  ShaderMaterial,
8
7
  UniformsUtils
9
8
  } from 'three';
@@ -40,8 +39,6 @@ class GlitchPass extends Pass {
40
39
 
41
40
  render( renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */ ) {
42
41
 
43
- if ( renderer.capabilities.isWebGL2 === false ) this.uniforms[ 'tDisp' ].value.format = LuminanceFormat;
44
-
45
42
  this.uniforms[ 'tDiffuse' ].value = readBuffer.texture;
46
43
  this.uniforms[ 'seed' ].value = Math.random();//default seeding
47
44
  this.uniforms[ 'byp' ].value = 0;