@plastic-software/three 0.181.3 → 0.182.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 (253) hide show
  1. package/README.md +3 -4
  2. package/build/three.cjs +1192 -522
  3. package/build/three.core.js +345 -219
  4. package/build/three.core.min.js +1 -1
  5. package/build/three.module.js +864 -328
  6. package/build/three.module.min.js +1 -1
  7. package/build/three.tsl.js +15 -3
  8. package/build/three.tsl.min.js +1 -1
  9. package/build/three.webgpu.js +3660 -1545
  10. package/build/three.webgpu.min.js +1 -1
  11. package/build/three.webgpu.nodes.js +3659 -1544
  12. package/build/three.webgpu.nodes.min.js +1 -1
  13. package/examples/jsm/controls/MapControls.js +55 -1
  14. package/examples/jsm/controls/OrbitControls.js +6 -6
  15. package/examples/jsm/controls/TrackballControls.js +6 -6
  16. package/examples/jsm/csm/CSM.js +2 -1
  17. package/examples/jsm/environments/RoomEnvironment.js +2 -0
  18. package/examples/jsm/geometries/DecalGeometry.js +1 -1
  19. package/examples/jsm/helpers/LightProbeHelperGPU.js +1 -1
  20. package/examples/jsm/helpers/TextureHelperGPU.js +1 -1
  21. package/examples/jsm/inspector/Inspector.js +53 -9
  22. package/examples/jsm/inspector/RendererInspector.js +12 -2
  23. package/examples/jsm/inspector/tabs/Console.js +2 -2
  24. package/examples/jsm/inspector/tabs/Parameters.js +2 -2
  25. package/examples/jsm/inspector/tabs/Performance.js +2 -2
  26. package/examples/jsm/inspector/tabs/Viewer.js +4 -4
  27. package/examples/jsm/inspector/ui/Profiler.js +1836 -31
  28. package/examples/jsm/inspector/ui/Style.js +948 -13
  29. package/examples/jsm/inspector/ui/Tab.js +188 -1
  30. package/examples/jsm/inspector/ui/Values.js +17 -1
  31. package/examples/jsm/loaders/3DMLoader.js +5 -4
  32. package/examples/jsm/loaders/DRACOLoader.js +5 -5
  33. package/examples/jsm/loaders/FBXLoader.js +0 -2
  34. package/examples/jsm/loaders/HDRLoader.js +0 -1
  35. package/examples/jsm/loaders/KTX2Loader.js +16 -0
  36. package/examples/jsm/loaders/LDrawLoader.js +2 -3
  37. package/examples/jsm/loaders/PCDLoader.js +1 -0
  38. package/examples/jsm/loaders/SVGLoader.js +1 -1
  39. package/examples/jsm/loaders/TDSLoader.js +0 -2
  40. package/examples/jsm/loaders/TGALoader.js +0 -2
  41. package/examples/jsm/loaders/UltraHDRLoader.js +110 -137
  42. package/examples/jsm/loaders/VOXLoader.js +660 -117
  43. package/examples/jsm/loaders/VRMLLoader.js +2 -2
  44. package/examples/jsm/loaders/usd/USDCParser.js +1 -1
  45. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +1 -1
  46. package/examples/jsm/materials/MeshGouraudMaterial.js +0 -1
  47. package/examples/jsm/materials/WoodNodeMaterial.js +11 -11
  48. package/examples/jsm/math/Octree.js +131 -1
  49. package/examples/jsm/misc/Volume.js +0 -1
  50. package/examples/jsm/misc/VolumeSlice.js +0 -1
  51. package/examples/jsm/objects/SkyMesh.js +13 -3
  52. package/examples/jsm/physics/AmmoPhysics.js +12 -7
  53. package/examples/jsm/physics/JoltPhysics.js +3 -1
  54. package/examples/jsm/physics/RapierPhysics.js +3 -1
  55. package/examples/jsm/postprocessing/OutputPass.js +9 -0
  56. package/examples/jsm/postprocessing/RenderPass.js +10 -0
  57. package/examples/jsm/postprocessing/UnrealBloomPass.js +48 -18
  58. package/examples/jsm/renderers/Projector.js +268 -30
  59. package/examples/jsm/renderers/SVGRenderer.js +191 -58
  60. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +2 -4
  61. package/examples/jsm/transpiler/AST.js +44 -0
  62. package/examples/jsm/transpiler/GLSLDecoder.js +61 -4
  63. package/examples/jsm/transpiler/ShaderToyDecoder.js +2 -0
  64. package/examples/jsm/transpiler/TSLEncoder.js +46 -3
  65. package/examples/jsm/transpiler/TranspilerUtils.js +3 -3
  66. package/examples/jsm/transpiler/WGSLEncoder.js +27 -0
  67. package/examples/jsm/tsl/display/AnaglyphPassNode.js +2 -0
  68. package/examples/jsm/tsl/display/BloomNode.js +11 -1
  69. package/examples/jsm/tsl/display/GTAONode.js +3 -2
  70. package/examples/jsm/tsl/display/PixelationPassNode.js +2 -1
  71. package/examples/jsm/tsl/display/SSGINode.js +7 -19
  72. package/examples/jsm/tsl/display/SSRNode.js +1 -1
  73. package/examples/jsm/tsl/display/SSSNode.js +4 -2
  74. package/examples/jsm/tsl/display/StereoCompositePassNode.js +8 -1
  75. package/examples/jsm/tsl/display/TRAANode.js +265 -114
  76. package/examples/jsm/tsl/display/radialBlur.js +68 -0
  77. package/examples/jsm/utils/ShadowMapViewer.js +24 -10
  78. package/examples/jsm/utils/ShadowMapViewerGPU.js +1 -1
  79. package/examples/jsm/utils/WebGPUTextureUtils.js +1 -1
  80. package/package.json +14 -12
  81. package/src/Three.Core.js +1 -0
  82. package/src/Three.TSL.js +14 -2
  83. package/src/animation/AnimationUtils.js +1 -12
  84. package/src/animation/KeyframeTrack.js +1 -1
  85. package/src/animation/tracks/BooleanKeyframeTrack.js +1 -1
  86. package/src/animation/tracks/ColorKeyframeTrack.js +1 -1
  87. package/src/animation/tracks/NumberKeyframeTrack.js +1 -1
  88. package/src/animation/tracks/QuaternionKeyframeTrack.js +1 -1
  89. package/src/animation/tracks/StringKeyframeTrack.js +1 -1
  90. package/src/animation/tracks/VectorKeyframeTrack.js +1 -1
  91. package/src/constants.js +61 -5
  92. package/src/core/BufferGeometry.js +14 -2
  93. package/src/core/Raycaster.js +2 -2
  94. package/src/extras/PMREMGenerator.js +3 -10
  95. package/src/extras/TextureUtils.js +5 -1
  96. package/src/geometries/ExtrudeGeometry.js +2 -2
  97. package/src/geometries/PolyhedronGeometry.js +1 -1
  98. package/src/helpers/PointLightHelper.js +1 -1
  99. package/src/lights/DirectionalLight.js +13 -0
  100. package/src/lights/HemisphereLight.js +10 -0
  101. package/src/lights/Light.js +1 -11
  102. package/src/lights/LightProbe.js +0 -15
  103. package/src/lights/LightShadow.js +0 -3
  104. package/src/lights/PointLight.js +15 -0
  105. package/src/lights/PointLightShadow.js +0 -86
  106. package/src/lights/SpotLight.js +22 -1
  107. package/src/loaders/MaterialLoader.js +2 -1
  108. package/src/loaders/ObjectLoader.js +3 -1
  109. package/src/loaders/nodes/NodeLoader.js +2 -2
  110. package/src/materials/Material.js +2 -0
  111. package/src/materials/ShaderMaterial.js +20 -1
  112. package/src/materials/nodes/Line2NodeMaterial.js +2 -2
  113. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +3 -2
  114. package/src/materials/nodes/MeshStandardNodeMaterial.js +5 -4
  115. package/src/materials/nodes/NodeMaterial.js +59 -3
  116. package/src/materials/nodes/manager/NodeMaterialObserver.js +1 -1
  117. package/src/math/Matrix4.js +40 -40
  118. package/src/math/Sphere.js +1 -1
  119. package/src/math/Vector3.js +0 -2
  120. package/src/nodes/TSL.js +4 -1
  121. package/src/nodes/accessors/BatchNode.js +10 -10
  122. package/src/nodes/accessors/BufferAttributeNode.js +98 -12
  123. package/src/nodes/accessors/BufferNode.js +29 -2
  124. package/src/nodes/accessors/ClippingNode.js +4 -4
  125. package/src/nodes/accessors/CubeTextureNode.js +20 -1
  126. package/src/nodes/accessors/InstanceNode.js +69 -29
  127. package/src/nodes/accessors/MaterialNode.js +9 -1
  128. package/src/nodes/accessors/MaterialReferenceNode.js +1 -2
  129. package/src/nodes/accessors/ModelNode.js +1 -1
  130. package/src/nodes/accessors/Normal.js +2 -2
  131. package/src/nodes/accessors/ReferenceBaseNode.js +4 -4
  132. package/src/nodes/accessors/ReferenceNode.js +4 -4
  133. package/src/nodes/accessors/RendererReferenceNode.js +1 -2
  134. package/src/nodes/accessors/SkinningNode.js +15 -2
  135. package/src/nodes/accessors/StorageBufferNode.js +4 -2
  136. package/src/nodes/accessors/Tangent.js +1 -11
  137. package/src/nodes/accessors/Texture3DNode.js +26 -1
  138. package/src/nodes/accessors/UniformArrayNode.js +2 -2
  139. package/src/nodes/accessors/UserDataNode.js +1 -2
  140. package/src/nodes/accessors/VertexColorNode.js +1 -2
  141. package/src/nodes/code/FunctionNode.js +1 -2
  142. package/src/nodes/core/ArrayNode.js +20 -1
  143. package/src/nodes/core/AssignNode.js +2 -2
  144. package/src/nodes/core/AttributeNode.js +2 -2
  145. package/src/nodes/core/ContextNode.js +103 -4
  146. package/src/nodes/core/NodeBuilder.js +56 -14
  147. package/src/nodes/core/NodeFrame.js +12 -4
  148. package/src/nodes/core/NodeUtils.js +5 -5
  149. package/src/nodes/core/ParameterNode.js +1 -2
  150. package/src/nodes/core/PropertyNode.js +19 -3
  151. package/src/nodes/core/StackNode.js +56 -8
  152. package/src/nodes/core/StructNode.js +1 -2
  153. package/src/nodes/core/StructTypeNode.js +11 -17
  154. package/src/nodes/core/UniformNode.js +19 -4
  155. package/src/nodes/core/VarNode.js +46 -21
  156. package/src/nodes/display/NormalMapNode.js +37 -2
  157. package/src/nodes/display/PassNode.js +77 -7
  158. package/src/nodes/display/ScreenNode.js +1 -0
  159. package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +3 -3
  160. package/src/nodes/functions/BSDF/DFGLUT.js +56 -0
  161. package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
  162. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +1 -1
  163. package/src/nodes/functions/PhysicalLightingModel.js +102 -43
  164. package/src/nodes/gpgpu/ComputeBuiltinNode.js +1 -2
  165. package/src/nodes/gpgpu/SubgroupFunctionNode.js +1 -1
  166. package/src/nodes/gpgpu/WorkgroupInfoNode.js +2 -3
  167. package/src/nodes/lighting/AnalyticLightNode.js +53 -0
  168. package/src/nodes/lighting/LightsNode.js +2 -2
  169. package/src/nodes/lighting/PointShadowNode.js +141 -140
  170. package/src/nodes/lighting/ShadowFilterNode.js +53 -37
  171. package/src/nodes/lighting/ShadowNode.js +53 -19
  172. package/src/nodes/math/BitcountNode.js +433 -0
  173. package/src/nodes/math/PackFloatNode.js +98 -0
  174. package/src/nodes/math/UnpackFloatNode.js +96 -0
  175. package/src/nodes/pmrem/PMREMNode.js +1 -1
  176. package/src/nodes/tsl/TSLCore.js +4 -4
  177. package/src/nodes/utils/ArrayElementNode.js +13 -0
  178. package/src/nodes/utils/EventNode.js +1 -2
  179. package/src/nodes/utils/Packing.js +13 -1
  180. package/src/nodes/utils/PostProcessingUtils.js +33 -1
  181. package/src/nodes/utils/ReflectorNode.js +1 -1
  182. package/src/nodes/utils/SampleNode.js +1 -1
  183. package/src/nodes/utils/UVUtils.js +26 -0
  184. package/src/objects/BatchedMesh.js +5 -2
  185. package/src/objects/Line.js +1 -1
  186. package/src/objects/Mesh.js +1 -1
  187. package/src/objects/Points.js +1 -1
  188. package/src/objects/Skeleton.js +9 -0
  189. package/src/renderers/WebGLRenderer.js +145 -33
  190. package/src/renderers/common/Backend.js +8 -0
  191. package/src/renderers/common/Background.js +19 -9
  192. package/src/renderers/common/Binding.js +11 -0
  193. package/src/renderers/common/Bindings.js +7 -7
  194. package/src/renderers/common/Buffer.js +40 -0
  195. package/src/renderers/common/ChainMap.js +30 -6
  196. package/src/renderers/common/Geometries.js +12 -0
  197. package/src/renderers/common/RenderContexts.js +8 -1
  198. package/src/renderers/common/RenderObject.js +14 -1
  199. package/src/renderers/common/Renderer.js +53 -35
  200. package/src/renderers/common/Textures.js +1 -1
  201. package/src/renderers/common/UniformsGroup.js +1 -0
  202. package/src/renderers/common/XRManager.js +1 -0
  203. package/src/renderers/common/extras/PMREMGenerator.js +2 -8
  204. package/src/renderers/common/nodes/NodeUniformBuffer.js +52 -0
  205. package/src/renderers/shaders/DFGLUTData.js +19 -34
  206. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +5 -2
  207. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +8 -4
  208. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +90 -51
  209. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +194 -186
  210. package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +1 -1
  211. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
  212. package/src/renderers/shaders/ShaderChunk.js +3 -3
  213. package/src/renderers/shaders/ShaderLib/depth.glsl.js +3 -0
  214. package/src/renderers/shaders/ShaderLib/{distanceRGBA.glsl.js → distance.glsl.js} +1 -2
  215. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +0 -1
  216. package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +1 -2
  217. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +0 -1
  218. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -9
  219. package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +0 -1
  220. package/src/renderers/shaders/ShaderLib/shadow.glsl.js +0 -1
  221. package/src/renderers/shaders/ShaderLib/vsm.glsl.js +4 -6
  222. package/src/renderers/shaders/ShaderLib.js +3 -3
  223. package/src/renderers/webgl/WebGLCapabilities.js +3 -4
  224. package/src/renderers/webgl/WebGLLights.js +18 -1
  225. package/src/renderers/webgl/WebGLOutput.js +267 -0
  226. package/src/renderers/webgl/WebGLProgram.js +43 -107
  227. package/src/renderers/webgl/WebGLPrograms.js +35 -45
  228. package/src/renderers/webgl/WebGLShadowMap.js +188 -25
  229. package/src/renderers/webgl/WebGLState.js +20 -20
  230. package/src/renderers/webgl/WebGLTextures.js +89 -28
  231. package/src/renderers/webgl/WebGLUniforms.js +40 -3
  232. package/src/renderers/webgl/WebGLUtils.js +6 -2
  233. package/src/renderers/webgl-fallback/WebGLBackend.js +79 -13
  234. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +59 -7
  235. package/src/renderers/webgl-fallback/utils/WebGLState.js +18 -3
  236. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +5 -3
  237. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +9 -9
  238. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +6 -2
  239. package/src/renderers/webgpu/WebGPUBackend.js +61 -4
  240. package/src/renderers/webgpu/WebGPURenderer.js +1 -1
  241. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +65 -23
  242. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +4 -17
  243. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +354 -186
  244. package/src/renderers/webgpu/utils/WebGPUConstants.js +2 -0
  245. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +20 -7
  246. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +40 -17
  247. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +7 -7
  248. package/src/renderers/webgpu/utils/WebGPUUtils.js +7 -5
  249. package/src/textures/CubeDepthTexture.js +76 -0
  250. package/src/textures/Source.js +1 -1
  251. package/src/textures/Texture.js +1 -1
  252. package/src/utils.js +13 -1
  253. package/src/nodes/functions/BSDF/DFGApprox.js +0 -71
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  /**
7
- * Unpack RGBA depth shader that shows RGBA encoded depth as monochrome color.
7
+ * Depth visualization shader that shows depth values as monochrome color.
8
8
  *
9
9
  * @constant
10
10
  * @type {ShaderMaterial~Shader}
@@ -39,11 +39,9 @@ const UnpackDepthRGBAShader = {
39
39
 
40
40
  varying vec2 vUv;
41
41
 
42
- #include <packing>
43
-
44
42
  void main() {
45
43
 
46
- float depth = unpackRGBAToDepth( texture2D( tDiffuse, vUv ) );
44
+ float depth = texture2D( tDiffuse, vUv ).r;
47
45
 
48
46
  #ifdef USE_REVERSED_DEPTH_BUFFER
49
47
 
@@ -46,6 +46,20 @@ export class ASTNode {
46
46
 
47
47
  }
48
48
 
49
+ getProgram() {
50
+
51
+ let current = this;
52
+
53
+ while ( current.parent !== null ) {
54
+
55
+ current = current.parent;
56
+
57
+ }
58
+
59
+ return current.isProgram === true ? current : null;
60
+
61
+ }
62
+
49
63
  getParent( parents = [] ) {
50
64
 
51
65
  if ( this.parent === null ) {
@@ -114,6 +128,7 @@ export class Program extends ASTNode {
114
128
  super();
115
129
 
116
130
  this.body = body;
131
+ this.structTypes = new Map();
117
132
 
118
133
  this.isProgram = true;
119
134
 
@@ -629,3 +644,32 @@ export class SwitchCase extends ASTNode {
629
644
  }
630
645
 
631
646
  }
647
+
648
+ // helper class for StructDefinition
649
+ export class StructMember {
650
+
651
+ constructor( type, name ) {
652
+
653
+ this.type = type;
654
+ this.name = name;
655
+ this.isStructMember = true;
656
+
657
+ }
658
+
659
+ }
660
+
661
+ export class StructDefinition extends ASTNode {
662
+
663
+ constructor( name, members = [] ) {
664
+
665
+ super();
666
+
667
+ this.name = name;
668
+ this.members = members;
669
+ this.isStructDefinition = true;
670
+
671
+ this.initialize();
672
+
673
+ }
674
+
675
+ }
@@ -1,6 +1,6 @@
1
- import { Program, FunctionDeclaration, Switch, For, AccessorElements, Ternary, Varying, DynamicElement, StaticElement, FunctionParameter, Unary, Conditional, VariableDeclaration, Operator, Number, String, FunctionCall, Return, Accessor, Uniform, Discard, SwitchCase, Continue, Break, While, Comment } from './AST.js';
1
+ import { Program, FunctionDeclaration, Switch, For, AccessorElements, Ternary, Varying, DynamicElement, StaticElement, FunctionParameter, Unary, Conditional, VariableDeclaration, Operator, Number, String, FunctionCall, Return, Accessor, Uniform, Discard, SwitchCase, Continue, Break, While, Comment, StructMember, StructDefinition } from './AST.js';
2
2
 
3
- import { isType } from './TranspilerUtils.js';
3
+ import { isBuiltinType } from './TranspilerUtils.js';
4
4
 
5
5
  const unaryOperators = [
6
6
  '+', '-', '~', '!', '++', '--'
@@ -255,6 +255,7 @@ class GLSLDecoder {
255
255
  this.index = 0;
256
256
  this.tokenizer = null;
257
257
  this.keywords = [];
258
+ this.structTypes = new Map();
258
259
 
259
260
  this.addPolyfill( 'gl_FragCoord', 'vec3 gl_FragCoord = vec3( screenCoordinate.x, screenCoordinate.y.oneMinus(), screenCoordinate.z );' );
260
261
 
@@ -780,6 +781,54 @@ class GLSLDecoder {
780
781
 
781
782
  }
782
783
 
784
+ parseStructDefinition() {
785
+
786
+ const tokens = this.readTokensUntil( ';' );
787
+
788
+ const structName = tokens[ 1 ].str;
789
+
790
+ if ( tokens[ 2 ].str !== '{' ) {
791
+
792
+ throw new Error( 'Expected \'{\' after struct name ' );
793
+
794
+ }
795
+
796
+ const structMembers = [];
797
+ for ( let i = 3; i < tokens.length - 2; i += 3 ) {
798
+
799
+ const typeToken = tokens[ i ];
800
+ const nameToken = tokens[ i + 1 ];
801
+
802
+ if ( typeToken.type != 'literal' || nameToken.type != 'literal' ) {
803
+
804
+ throw new Error( 'Invalid struct declaration' );
805
+
806
+ }
807
+
808
+ if ( tokens[ i + 2 ].str !== ';' ) {
809
+
810
+ throw new Error( 'Missing \';\' after struct member name' );
811
+
812
+ }
813
+
814
+ const member = new StructMember( typeToken.str, nameToken.str );
815
+ structMembers.push( member );
816
+
817
+ }
818
+
819
+ if ( tokens[ tokens.length - 2 ].str !== '}' ) {
820
+
821
+ throw new Error( 'Missing closing \'}\' for struct ' + structName );
822
+
823
+ }
824
+
825
+ const definition = new StructDefinition( structName, structMembers );
826
+ this.structTypes.set( structName, definition );
827
+
828
+ return definition;
829
+
830
+ }
831
+
783
832
  parseReturn() {
784
833
 
785
834
  this.readToken(); // skip 'return'
@@ -827,7 +876,9 @@ class GLSLDecoder {
827
876
 
828
877
  let initialization;
829
878
 
830
- if ( initializationTokens[ 0 ] && isType( initializationTokens[ 0 ].str ) ) {
879
+ const firstToken = initializationTokens[ 0 ];
880
+
881
+ if ( firstToken && ( isBuiltinType( firstToken.str ) || this.structTypes.has( firstToken.str ) ) ) {
831
882
 
832
883
  initialization = this.parseVariablesFromToken( initializationTokens );
833
884
 
@@ -1079,7 +1130,11 @@ class GLSLDecoder {
1079
1130
 
1080
1131
  statement = this.parseVarying();
1081
1132
 
1082
- } else if ( isType( token.str ) ) {
1133
+ } else if ( token.str === 'struct' ) {
1134
+
1135
+ statement = this.parseStructDefinition();
1136
+
1137
+ } else if ( isBuiltinType( token.str ) || this.structTypes.has( token.str ) ) {
1083
1138
 
1084
1139
  if ( this.getToken( 2 ).str === '(' ) {
1085
1140
 
@@ -1159,7 +1214,9 @@ class GLSLDecoder {
1159
1214
  this.tokenizer = new Tokenizer( polyfill + source ).tokenize();
1160
1215
 
1161
1216
  const body = this.parseBlock();
1217
+
1162
1218
  const program = new Program( body );
1219
+ program.structTypes = this.structTypes;
1163
1220
 
1164
1221
  return program;
1165
1222
 
@@ -38,6 +38,8 @@ class ShaderToyDecoder extends GLSLDecoder {
38
38
  node.body.unshift( new VariableDeclaration( 'vec4', 'fragColor' ) );
39
39
  node.body.push( new Return( fragColor ) );
40
40
 
41
+ node.initialize();
42
+
41
43
  }
42
44
 
43
45
  return node;
@@ -314,6 +314,10 @@ class TSLEncoder {
314
314
 
315
315
  code = this.emitVarying( node );
316
316
 
317
+ } else if ( node.isStructDefinition ) {
318
+
319
+ code = this.emitStructDefinition( node );
320
+
317
321
  } else if ( node.isTernary ) {
318
322
 
319
323
  code = this.emitTernary( node );
@@ -669,9 +673,19 @@ ${ this.tab }} )`;
669
673
 
670
674
  } else {
671
675
 
672
- varStr += ` = property( '${ type }' )`;
676
+ const program = node.getProgram();
677
+
678
+ if ( program.structTypes.has( type ) ) {
679
+
680
+ varStr += ` = ${ type }()`;
681
+
682
+ } else {
683
+
684
+ varStr += ` = property( '${ type }' )`;
673
685
 
674
- this.addImport( 'property' );
686
+ this.addImport( 'property' );
687
+
688
+ }
675
689
 
676
690
  }
677
691
 
@@ -702,6 +716,34 @@ ${ this.tab }} )`;
702
716
 
703
717
  }
704
718
 
719
+ emitStructDefinition( node ) {
720
+
721
+ const { name, members } = node;
722
+
723
+ this.addImport( 'struct' );
724
+
725
+ let structString = `const ${ name } = struct( {\n`;
726
+
727
+ for ( let i = 0; i < members.length; i += 1 ) {
728
+
729
+ const member = members[ i ];
730
+
731
+ structString += `${this.tab}\t${member.name}: '${member.type}'`;
732
+
733
+ if ( i != members.length - 1 ) {
734
+
735
+ structString += ',\n';
736
+
737
+ }
738
+
739
+ }
740
+
741
+ structString += `\n${this.tab}}, \'${name}\' )`;
742
+
743
+ return structString;
744
+
745
+ }
746
+
705
747
  emitOverloadingFunction( nodes ) {
706
748
 
707
749
  const { name } = nodes[ 0 ];
@@ -798,7 +840,8 @@ ${ this.tab }}`;
798
840
 
799
841
  if ( node.layout !== false && hasPointer === false ) {
800
842
 
801
- funcStr += ', { ' + inputs.join( ', ' ) + ', return: \'' + type + '\' }';
843
+ const inputsStr = inputs.length > 0 ? inputs.join( ', ' ) + ', ' : '';
844
+ funcStr += ', { ' + inputsStr + 'return: \'' + type + '\' }';
802
845
 
803
846
  }
804
847
 
@@ -1,6 +1,6 @@
1
1
  export function isExpression( st ) {
2
2
 
3
- return st.isFunctionDeclaration !== true && st.isFor !== true && st.isWhile !== true && st.isConditional !== true && st.isSwitch !== true;
3
+ return st.isFunctionDeclaration !== true && st.isFor !== true && st.isWhile !== true && st.isConditional !== true && st.isSwitch !== true && st.isStructDefinition !== true;
4
4
 
5
5
  }
6
6
 
@@ -10,9 +10,9 @@ export function isPrimitive( value ) {
10
10
 
11
11
  }
12
12
 
13
- export function isType( str ) {
13
+ export function isBuiltinType( str ) {
14
14
 
15
- return /void|bool|float|u?int|mat[234]|mat[234]x[234]|(u|i|b)?vec[234]/.test( str );
15
+ return /^(void|bool|float|u?int|mat[234]|mat[234]x[234]|(u|i|b)?vec[234])$/.test( str );
16
16
 
17
17
  }
18
18
 
@@ -300,6 +300,10 @@ class WGSLEncoder {
300
300
  this.varyings.push( node );
301
301
  return ''; // Defer emission to the header
302
302
 
303
+ } else if ( node.isStructDefinition ) {
304
+
305
+ code = this.emitStructDefinition( node );
306
+
303
307
  } else if ( node.isTernary ) {
304
308
 
305
309
  const cond = this.emitExpression( node.cond );
@@ -584,6 +588,29 @@ class WGSLEncoder {
584
588
 
585
589
  }
586
590
 
591
+ emitStructDefinition( node ) {
592
+
593
+ const { name, members } = node;
594
+
595
+ let structString = `struct ${ name } {\n`;
596
+
597
+ for ( let i = 0; i < members.length; i += 1 ) {
598
+
599
+ const member = members[ i ];
600
+
601
+ structString += `${ this.tab }\t${ member.name }: ${ this.getWgslType( member.type ) }`;
602
+
603
+ const delimiter = ( i != members.length - 1 ) ? ',\n' : '\n';
604
+ structString += delimiter;
605
+
606
+ }
607
+
608
+ structString += this.tab + '}';
609
+
610
+ return structString;
611
+
612
+ }
613
+
587
614
  emitFunction( node ) {
588
615
 
589
616
  const name = node.name;
@@ -40,6 +40,7 @@ class AnaglyphPassNode extends StereoCompositePassNode {
40
40
  /**
41
41
  * Color matrix node for the left eye.
42
42
  *
43
+ * @private
43
44
  * @type {UniformNode<mat3>}
44
45
  */
45
46
  this._colorMatrixLeft = uniform( new Matrix3().fromArray( [
@@ -51,6 +52,7 @@ class AnaglyphPassNode extends StereoCompositePassNode {
51
52
  /**
52
53
  * Color matrix node for the right eye.
53
54
  *
55
+ * @private
54
56
  * @type {UniformNode<mat3>}
55
57
  */
56
58
  this._colorMatrixRight = uniform( new Matrix3().fromArray( [
@@ -77,7 +77,7 @@ class BloomNode extends TempNode {
77
77
  this.strength = uniform( strength );
78
78
 
79
79
  /**
80
- * The radius of the bloom.
80
+ * The radius of the bloom. Must be in the range `[0,1]`.
81
81
  *
82
82
  * @type {UniformNode<float>}
83
83
  */
@@ -443,11 +443,21 @@ class BloomNode extends TempNode {
443
443
 
444
444
  this._renderTargetBright.dispose();
445
445
 
446
+ if ( this._highPassFilterMaterial !== null ) this._highPassFilterMaterial.dispose();
447
+ if ( this._compositeMaterial !== null ) this._compositeMaterial.dispose();
448
+
449
+ for ( let i = 0; i < this._separableBlurMaterials.length; i ++ ) {
450
+
451
+ this._separableBlurMaterials[ i ].dispose();
452
+
453
+ }
454
+
446
455
  }
447
456
 
448
457
  /**
449
458
  * Create a separable blur material for the given kernel radius.
450
459
  *
460
+ * @private
451
461
  * @param {NodeBuilder} builder - The current node builder.
452
462
  * @param {number} kernelRadius - The kernel radius.
453
463
  * @return {NodeMaterial}
@@ -29,7 +29,7 @@ let _rendererState;
29
29
  * postProcessing.outputNod = aoPass.getTextureNode().mul( scenePassColor );
30
30
  * ```
31
31
  *
32
- * Reference: {@link https://www.activision.com/cdn/research/Practical_Real_Time_Strategies_for_Accurate_Indirect_Occlusion_NEW%20VERSION_COLOR.pdf}.
32
+ * Reference: [Practical Real-Time Strategies for Accurate Indirect Occlusion](https://www.activision.com/cdn/research/Practical_Real_Time_Strategies_for_Accurate_Indirect_Occlusion_NEW%20VERSION_COLOR.pdf).
33
33
  *
34
34
  * @augments TempNode
35
35
  * @three_import import { ao } from 'three/addons/tsl/display/GTAONode.js';
@@ -210,6 +210,7 @@ class GTAONode extends TempNode {
210
210
  /**
211
211
  * Temporal direction that influences the rotation angle for each slice.
212
212
  *
213
+ * @private
213
214
  * @type {UniformNode<float>}
214
215
  */
215
216
  this._temporalDirection = uniform( 0 );
@@ -567,4 +568,4 @@ function generateMagicSquare( size ) {
567
568
  * @param {Camera} camera - The camera the scene is rendered with.
568
569
  * @returns {GTAONode}
569
570
  */
570
- export const ao = ( depthNode, normalNode, camera ) => nodeObject( new GTAONode( nodeObject( depthNode ), nodeObject( normalNode ), camera ) );
571
+ export const ao = ( depthNode, normalNode, camera ) => new GTAONode( nodeObject( depthNode ), nodeObject( normalNode ), camera );
@@ -74,6 +74,7 @@ class PixelationNode extends TempNode {
74
74
  /**
75
75
  * Uniform node that represents the resolution.
76
76
  *
77
+ * @private
77
78
  * @type {Node<vec4>}
78
79
  */
79
80
  this._resolution = uniform( new Vector4() );
@@ -193,7 +194,7 @@ class PixelationNode extends TempNode {
193
194
 
194
195
  const nei = property( 'float', 'nei' );
195
196
 
196
- If( this.normalEdgeStrength.greaterThan( 0.0 ), () => {
197
+ If( this.normalEdgeStrength.greaterThan( 0.0 ).and( normal.length().greaterThan( 0 ) ), () => {
197
198
 
198
199
  nei.assign( normalEdgeIndicator( depth, normal ) );
199
200
 
@@ -1,5 +1,5 @@
1
1
  import { RenderTarget, Vector2, TempNode, QuadMesh, NodeMaterial, RendererUtils, MathUtils } from 'three/webgpu';
2
- import { clamp, normalize, reference, nodeObject, Fn, NodeUpdateType, uniform, vec4, passTexture, uv, logarithmicDepthToViewZ, viewZToPerspectiveDepth, getViewPosition, screenCoordinate, float, sub, fract, dot, vec2, rand, vec3, Loop, mul, PI, cos, sin, uint, cross, acos, sign, pow, luminance, If, max, abs, Break, sqrt, HALF_PI, div, ceil, shiftRight, convertToTexture, bool, getNormalFromDepth, interleavedGradientNoise } from 'three/tsl';
2
+ import { clamp, normalize, reference, nodeObject, Fn, NodeUpdateType, uniform, vec4, passTexture, uv, logarithmicDepthToViewZ, viewZToPerspectiveDepth, getViewPosition, screenCoordinate, float, sub, fract, dot, vec2, rand, vec3, Loop, mul, PI, cos, sin, uint, cross, acos, sign, pow, luminance, If, max, abs, Break, sqrt, HALF_PI, div, ceil, shiftRight, convertToTexture, bool, getNormalFromDepth, countOneBits, interleavedGradientNoise } from 'three/tsl';
3
3
 
4
4
  const _quadMesh = /*@__PURE__*/ new QuadMesh();
5
5
  const _size = /*@__PURE__*/ new Vector2();
@@ -197,6 +197,7 @@ class SSGINode extends TempNode {
197
197
  /**
198
198
  * The resolution of the effect.
199
199
  *
200
+ * @private
200
201
  * @type {UniformNode<vec2>}
201
202
  */
202
203
  this._resolution = uniform( new Vector2() );
@@ -204,6 +205,7 @@ class SSGINode extends TempNode {
204
205
  /**
205
206
  * Used to compute the effective step radius when viewSpaceSampling is `false`.
206
207
  *
208
+ * @private
207
209
  * @type {UniformNode<vec2>}
208
210
  */
209
211
  this._halfProjScale = uniform( 1 );
@@ -211,6 +213,7 @@ class SSGINode extends TempNode {
211
213
  /**
212
214
  * Temporal direction that influences the rotation angle for each slice.
213
215
  *
216
+ * @private
214
217
  * @type {UniformNode<float>}
215
218
  */
216
219
  this._temporalDirection = uniform( 0 );
@@ -218,6 +221,7 @@ class SSGINode extends TempNode {
218
221
  /**
219
222
  * Temporal offset added to the initial ray step.
220
223
  *
224
+ * @private
221
225
  * @type {UniformNode<float>}
222
226
  */
223
227
  this._temporalOffset = uniform( 0 );
@@ -431,22 +435,6 @@ class SSGINode extends TempNode {
431
435
  ]
432
436
  } );
433
437
 
434
- const bitCount = Fn( ( [ value ] ) => {
435
-
436
- const v = uint( value );
437
- v.assign( v.sub( v.shiftRight( uint( 1 ) ).bitAnd( uint( 0x55555555 ) ) ) );
438
- v.assign( v.bitAnd( uint( 0x33333333 ) ).add( v.shiftRight( uint( 2 ) ).bitAnd( uint( 0x33333333 ) ) ) );
439
-
440
- return v.add( v.shiftRight( uint( 4 ) ) ).bitAnd( uint( 0xF0F0F0F ) ).mul( uint( 0x1010101 ) ).shiftRight( uint( 24 ) );
441
-
442
- } ).setLayout( {
443
- name: 'bitCount',
444
- type: 'uint',
445
- inputs: [
446
- { name: 'value', type: 'uint' }
447
- ]
448
- } );
449
-
450
438
  const horizonSampling = Fn( ( [ directionIsRight, RADIUS, viewPosition, slideDirTexelSize, initialRayStep, uvNode, viewDir, viewNormal, n ] ) => {
451
439
 
452
440
  const STEP_COUNT = this.stepCount.toConst();
@@ -509,7 +497,7 @@ class SSGINode extends TempNode {
509
497
  currentOccludedBitfield = currentOccludedBitfield.bitAnd( globalOccludedBitfield.bitNot() );
510
498
 
511
499
  globalOccludedBitfield.assign( globalOccludedBitfield.bitOr( currentOccludedBitfield ) );
512
- const numOccludedZones = bitCount( currentOccludedBitfield );
500
+ const numOccludedZones = countOneBits( currentOccludedBitfield );
513
501
 
514
502
  //
515
503
 
@@ -593,7 +581,7 @@ class SSGINode extends TempNode {
593
581
  color.addAssign( horizonSampling( bool( true ), RADIUS, viewPosition, slideDirTexelSize, initialRayStep, uvNode, viewDir, viewNormal, n ) );
594
582
  color.addAssign( horizonSampling( bool( false ), RADIUS, viewPosition, slideDirTexelSize, initialRayStep, uvNode, viewDir, viewNormal, n ) );
595
583
 
596
- ao.addAssign( float( bitCount( globalOccludedBitfield ) ).div( float( MAX_RAY ) ) );
584
+ ao.addAssign( float( countOneBits( globalOccludedBitfield ) ).div( float( MAX_RAY ) ) );
597
585
 
598
586
  } );
599
587
 
@@ -206,7 +206,7 @@ class SSRNode extends TempNode {
206
206
  * @private
207
207
  * @type {UniformNode<bool>}
208
208
  */
209
- this._isPerspectiveCamera = uniform( camera.isPerspectiveCamera );
209
+ this._isPerspectiveCamera = uniform( camera.isPerspectiveCamera === true );
210
210
 
211
211
  /**
212
212
  * The resolution of the pass.
@@ -90,9 +90,9 @@ class SSSNode extends TempNode {
90
90
  * Shadow intensity. Must be in the range `[0, 1]`.
91
91
  *
92
92
  * @type {UniformNode<float>}
93
- * @default 0.5
93
+ * @default 1.0
94
94
  */
95
- this.shadowIntensity = uniform( 0.5, 'float' );
95
+ this.shadowIntensity = uniform( 1.0, 'float' );
96
96
 
97
97
  /**
98
98
  * This parameter controls how detailed the raymarching process works.
@@ -192,6 +192,7 @@ class SSSNode extends TempNode {
192
192
  /**
193
193
  * Temporal offset added to the initial ray step.
194
194
  *
195
+ * @private
195
196
  * @type {UniformNode<float>}
196
197
  */
197
198
  this._temporalOffset = uniform( 0 );
@@ -199,6 +200,7 @@ class SSSNode extends TempNode {
199
200
  /**
200
201
  * The frame ID use when temporal filtering is enabled.
201
202
  *
203
+ * @private
202
204
  * @type {UniformNode<uint>}
203
205
  */
204
206
  this._frameId = uniform( 0 );
@@ -50,11 +50,13 @@ class StereoCompositePassNode extends PassNode {
50
50
  * @type {StereoCamera}
51
51
  */
52
52
  this.stereo = new StereoCamera();
53
+
53
54
  const _params = { minFilter: LinearFilter, magFilter: NearestFilter, type: HalfFloatType };
54
55
 
55
56
  /**
56
57
  * The render target for rendering the left eye's view.
57
58
  *
59
+ * @private
58
60
  * @type {RenderTarget}
59
61
  */
60
62
  this._renderTargetL = new RenderTarget( 1, 1, _params );
@@ -62,6 +64,7 @@ class StereoCompositePassNode extends PassNode {
62
64
  /**
63
65
  * The render target for rendering the right eye's view.
64
66
  *
67
+ * @private
65
68
  * @type {RenderTarget}
66
69
  */
67
70
  this._renderTargetR = new RenderTarget( 1, 1, _params );
@@ -69,6 +72,7 @@ class StereoCompositePassNode extends PassNode {
69
72
  /**
70
73
  * A texture node representing the left's eye view.
71
74
  *
75
+ * @private
72
76
  * @type {TextureNode}
73
77
  */
74
78
  this._mapLeft = texture( this._renderTargetL.texture );
@@ -76,6 +80,7 @@ class StereoCompositePassNode extends PassNode {
76
80
  /**
77
81
  * A texture node representing the right's eye view.
78
82
  *
83
+ * @private
79
84
  * @type {TextureNode}
80
85
  */
81
86
  this._mapRight = texture( this._renderTargetR.texture );
@@ -84,7 +89,9 @@ class StereoCompositePassNode extends PassNode {
84
89
  * The node material that implements the composite. All
85
90
  * derived effect passes must provide an instance for rendering.
86
91
  *
87
- * @type {NodeMaterial}
92
+ * @private
93
+ * @type {?NodeMaterial}
94
+ * @default null
88
95
  */
89
96
  this._material = null;
90
97