super-three 0.169.1 → 0.170.1

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 (255) hide show
  1. package/build/three.cjs +24628 -24228
  2. package/build/three.core.js +37002 -0
  3. package/build/three.core.min.js +6 -0
  4. package/build/three.module.js +10519 -47108
  5. package/build/three.module.min.js +1 -1
  6. package/build/three.tsl.js +533 -0
  7. package/build/three.tsl.min.js +6 -0
  8. package/build/three.webgpu.js +17071 -53583
  9. package/build/three.webgpu.min.js +1 -1
  10. package/build/three.webgpu.nodes.js +17134 -53623
  11. package/build/three.webgpu.nodes.min.js +1 -1
  12. package/examples/jsm/Addons.js +3 -3
  13. package/examples/jsm/animation/MMDAnimationHelper.js +2 -0
  14. package/examples/jsm/animation/MMDPhysics.js +2 -0
  15. package/examples/jsm/capabilities/WebGPU.js +1 -10
  16. package/examples/jsm/controls/ArcballControls.js +25 -21
  17. package/examples/jsm/controls/OrbitControls.js +41 -9
  18. package/examples/jsm/controls/PointerLockControls.js +2 -5
  19. package/examples/jsm/controls/TransformControls.js +22 -6
  20. package/examples/jsm/csm/CSM.js +2 -2
  21. package/examples/jsm/csm/CSMFrustum.js +7 -4
  22. package/examples/jsm/csm/CSMHelper.js +2 -0
  23. package/examples/jsm/csm/CSMShadowNode.js +437 -0
  24. package/examples/jsm/curves/NURBSCurve.js +34 -3
  25. package/examples/jsm/exporters/GLTFExporter.js +138 -71
  26. package/examples/jsm/exporters/KTX2Exporter.js +35 -12
  27. package/examples/jsm/exporters/MMDExporter.js +6 -0
  28. package/examples/jsm/exporters/USDZExporter.js +21 -3
  29. package/examples/jsm/geometries/DecalGeometry.js +70 -21
  30. package/examples/jsm/geometries/InstancedPointsGeometry.js +2 -0
  31. package/examples/jsm/helpers/TextureHelperGPU.js +175 -0
  32. package/examples/jsm/interactive/HTMLMesh.js +1 -0
  33. package/examples/jsm/lighting/TiledLighting.js +18 -0
  34. package/examples/jsm/lights/RectAreaLightTexturesLib.js +1 -1
  35. package/examples/jsm/lines/LineGeometry.js +25 -0
  36. package/examples/jsm/lines/LineMaterial.js +0 -1
  37. package/examples/jsm/lines/LineSegmentsGeometry.js +2 -0
  38. package/examples/jsm/lines/webgpu/Line2.js +2 -1
  39. package/examples/jsm/lines/webgpu/LineSegments2.js +2 -16
  40. package/examples/jsm/lines/webgpu/Wireframe.js +57 -0
  41. package/examples/jsm/loaders/3DMLoader.js +1 -0
  42. package/examples/jsm/loaders/3MFLoader.js +91 -0
  43. package/examples/jsm/loaders/FBXLoader.js +12 -2
  44. package/examples/jsm/loaders/GLTFLoader.js +2 -0
  45. package/examples/jsm/loaders/KTX2Loader.js +143 -49
  46. package/examples/jsm/loaders/LDrawLoader.js +22 -136
  47. package/examples/jsm/loaders/LottieLoader.js +1 -0
  48. package/examples/jsm/loaders/MMDLoader.js +3 -0
  49. package/examples/jsm/loaders/MaterialXLoader.js +2 -2
  50. package/examples/jsm/materials/LDrawConditionalLineMaterial.js +143 -0
  51. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +114 -0
  52. package/examples/jsm/math/ColorSpaces.js +76 -0
  53. package/examples/jsm/misc/ProgressiveLightMap.js +52 -40
  54. package/examples/jsm/misc/ProgressiveLightMapGPU.js +293 -0
  55. package/examples/jsm/misc/VolumeSlice.js +1 -0
  56. package/examples/jsm/objects/InstancedPoints.js +2 -4
  57. package/examples/jsm/objects/LensflareMesh.js +4 -2
  58. package/examples/jsm/objects/SkyMesh.js +5 -3
  59. package/examples/jsm/objects/Water2Mesh.js +7 -3
  60. package/examples/jsm/objects/WaterMesh.js +12 -10
  61. package/examples/jsm/postprocessing/AfterimagePass.js +14 -3
  62. package/examples/jsm/postprocessing/SSRPass.js +6 -0
  63. package/examples/jsm/renderers/CSS2DRenderer.js +6 -3
  64. package/examples/jsm/renderers/CSS3DRenderer.js +7 -4
  65. package/examples/jsm/shaders/FXAAShader.js +225 -224
  66. package/examples/jsm/transpiler/AST.js +2 -2
  67. package/examples/jsm/transpiler/GLSLDecoder.js +57 -25
  68. package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
  69. package/examples/jsm/transpiler/TSLEncoder.js +11 -6
  70. package/{src/nodes → examples/jsm/tsl}/display/AfterImageNode.js +18 -21
  71. package/{src/nodes → examples/jsm/tsl}/display/AnaglyphPassNode.js +2 -6
  72. package/{src/nodes → examples/jsm/tsl}/display/AnamorphicNode.js +12 -18
  73. package/{src/nodes → examples/jsm/tsl}/display/BleachBypass.js +1 -3
  74. package/{src/nodes → examples/jsm/tsl}/display/BloomNode.js +12 -41
  75. package/{src/nodes → examples/jsm/tsl}/display/DenoiseNode.js +60 -47
  76. package/{src/nodes → examples/jsm/tsl}/display/DepthOfFieldNode.js +4 -9
  77. package/{src/nodes → examples/jsm/tsl}/display/DotScreenNode.js +2 -9
  78. package/examples/jsm/tsl/display/FXAANode.js +316 -0
  79. package/{src/nodes → examples/jsm/tsl}/display/FilmNode.js +4 -7
  80. package/{src/nodes → examples/jsm/tsl}/display/GTAONode.js +73 -78
  81. package/{src/nodes → examples/jsm/tsl}/display/GaussianBlurNode.js +78 -42
  82. package/examples/jsm/tsl/display/LensflareNode.js +161 -0
  83. package/{src/nodes → examples/jsm/tsl}/display/Lut3DNode.js +3 -5
  84. package/{src/nodes → examples/jsm/tsl}/display/MotionBlur.js +2 -3
  85. package/examples/jsm/tsl/display/OutlineNode.js +434 -0
  86. package/{src/nodes → examples/jsm/tsl}/display/ParallaxBarrierPassNode.js +2 -5
  87. package/{src/nodes → examples/jsm/tsl}/display/PixelationPassNode.js +5 -17
  88. package/{src/nodes → examples/jsm/tsl}/display/RGBShiftNode.js +2 -6
  89. package/examples/jsm/tsl/display/SMAANode.js +620 -0
  90. package/{src/nodes → examples/jsm/tsl}/display/SSAAPassNode.js +10 -25
  91. package/examples/jsm/tsl/display/SSRNode.js +366 -0
  92. package/{src/nodes → examples/jsm/tsl}/display/Sepia.js +1 -2
  93. package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +4 -12
  94. package/{src/nodes → examples/jsm/tsl}/display/StereoCompositePassNode.js +9 -11
  95. package/{src/nodes → examples/jsm/tsl}/display/StereoPassNode.js +10 -11
  96. package/examples/jsm/tsl/display/TRAAPassNode.js +355 -0
  97. package/{src/nodes → examples/jsm/tsl}/display/TransitionNode.js +3 -7
  98. package/examples/jsm/tsl/display/hashBlur.js +24 -0
  99. package/examples/jsm/tsl/lighting/TiledLightsNode.js +389 -0
  100. package/examples/jsm/utils/SceneOptimizer.js +410 -0
  101. package/examples/jsm/utils/UVsDebug.js +1 -1
  102. package/examples/jsm/utils/{TextureUtilsGPU.js → WebGPUTextureUtils.js} +2 -1
  103. package/examples/jsm/webxr/OculusHandPointerModel.js +21 -21
  104. package/examples/jsm/webxr/Text2D.js +6 -6
  105. package/package.json +4 -4
  106. package/src/Three.Core.js +178 -0
  107. package/src/Three.TSL.js +526 -0
  108. package/src/Three.WebGPU.Nodes.js +9 -186
  109. package/src/Three.WebGPU.js +8 -186
  110. package/src/Three.js +1 -177
  111. package/src/animation/AnimationClip.js +2 -2
  112. package/src/animation/AnimationObjectGroup.js +2 -2
  113. package/src/audio/Audio.js +38 -0
  114. package/src/cameras/PerspectiveCamera.js +6 -6
  115. package/src/cameras/StereoCamera.js +2 -2
  116. package/src/constants.js +1 -6
  117. package/src/core/BufferGeometry.js +48 -8
  118. package/src/core/InterleavedBuffer.js +4 -4
  119. package/src/core/Object3D.js +2 -2
  120. package/src/extras/core/Curve.js +3 -3
  121. package/src/extras/core/Shape.js +2 -2
  122. package/src/geometries/CylinderGeometry.js +2 -2
  123. package/src/geometries/EdgesGeometry.js +2 -2
  124. package/src/geometries/LatheGeometry.js +2 -2
  125. package/src/lights/SpotLightShadow.js +2 -2
  126. package/src/materials/LineDashedMaterial.js +0 -1
  127. package/src/materials/Material.js +2 -2
  128. package/src/materials/MeshPhongMaterial.js +1 -1
  129. package/src/materials/MeshPhysicalMaterial.js +2 -2
  130. package/src/materials/MeshStandardMaterial.js +2 -2
  131. package/src/materials/nodes/Line2NodeMaterial.js +32 -13
  132. package/src/materials/nodes/LineDashedNodeMaterial.js +4 -2
  133. package/src/materials/nodes/NodeMaterial.js +93 -23
  134. package/src/materials/nodes/SpriteNodeMaterial.js +11 -2
  135. package/src/materials/nodes/manager/NodeMaterialObserver.js +119 -7
  136. package/src/math/ColorManagement.js +143 -102
  137. package/src/math/Line3.js +2 -2
  138. package/src/math/Quaternion.js +2 -2
  139. package/src/math/Spherical.js +3 -3
  140. package/src/math/Vector2.js +7 -7
  141. package/src/math/Vector3.js +9 -9
  142. package/src/math/Vector4.js +22 -9
  143. package/src/nodes/Nodes.js +2 -21
  144. package/src/nodes/TSL.js +9 -25
  145. package/src/nodes/accessors/Arrays.js +27 -0
  146. package/src/nodes/accessors/BuiltinNode.js +26 -0
  147. package/src/nodes/accessors/Camera.js +0 -1
  148. package/src/nodes/accessors/ClippingNode.js +76 -42
  149. package/src/nodes/accessors/InstanceNode.js +17 -20
  150. package/src/nodes/accessors/InstancedMeshNode.js +26 -0
  151. package/src/nodes/accessors/Lights.js +32 -0
  152. package/src/nodes/accessors/SceneNode.js +35 -1
  153. package/src/nodes/accessors/StorageBufferNode.js +61 -19
  154. package/src/nodes/accessors/StorageTextureNode.js +10 -4
  155. package/src/nodes/accessors/TextureNode.js +1 -1
  156. package/src/nodes/accessors/VelocityNode.js +13 -3
  157. package/src/nodes/code/FunctionCallNode.js +16 -5
  158. package/src/nodes/code/ScriptableNode.js +4 -4
  159. package/src/nodes/core/Node.js +1 -0
  160. package/src/nodes/core/NodeBuilder.js +31 -14
  161. package/src/nodes/core/NodeUtils.js +28 -0
  162. package/src/nodes/core/VarNode.js +15 -3
  163. package/src/nodes/core/constants.js +6 -0
  164. package/src/nodes/display/BlendModes.js +99 -0
  165. package/src/nodes/display/ColorAdjustment.js +53 -4
  166. package/src/nodes/display/ColorSpaceFunctions.js +5 -5
  167. package/src/nodes/display/ColorSpaceNode.js +27 -39
  168. package/src/nodes/display/PassNode.js +6 -4
  169. package/src/nodes/display/ToneMappingNode.js +1 -1
  170. package/src/nodes/display/ToonOutlinePassNode.js +3 -3
  171. package/src/nodes/display/ViewportDepthNode.js +48 -1
  172. package/src/nodes/functions/PhysicalLightingModel.js +21 -15
  173. package/src/nodes/functions/material/getAlphaHashThreshold.js +70 -0
  174. package/src/nodes/functions/material/getGeometryRoughness.js +8 -2
  175. package/src/nodes/functions/material/getParallaxCorrectNormal.js +22 -0
  176. package/src/nodes/gpgpu/ComputeNode.js +9 -1
  177. package/src/nodes/lighting/AnalyticLightNode.js +23 -419
  178. package/src/nodes/lighting/LightsNode.js +24 -12
  179. package/src/nodes/lighting/PointLightNode.js +41 -22
  180. package/src/nodes/lighting/PointShadowNode.js +254 -0
  181. package/src/nodes/lighting/RectAreaLightNode.js +3 -0
  182. package/src/nodes/lighting/ShadowNode.js +593 -0
  183. package/src/nodes/lighting/SpotLightNode.js +14 -2
  184. package/src/nodes/utils/LoopNode.js +2 -2
  185. package/src/nodes/utils/Oscillators.js +6 -0
  186. package/src/nodes/utils/PostProcessingUtils.js +89 -0
  187. package/src/nodes/utils/RTTNode.js +9 -1
  188. package/src/nodes/utils/ReflectorNode.js +101 -15
  189. package/src/nodes/utils/StorageArrayElementNode.js +2 -2
  190. package/src/nodes/utils/Timer.js +29 -0
  191. package/src/objects/BatchedMesh.js +472 -296
  192. package/src/objects/ClippingGroup.js +19 -0
  193. package/src/objects/Skeleton.js +2 -2
  194. package/src/renderers/WebGLRenderer.js +183 -109
  195. package/src/renderers/common/Animation.js +23 -11
  196. package/src/renderers/common/Attributes.js +4 -0
  197. package/src/renderers/common/Backend.js +2 -0
  198. package/src/renderers/common/Background.js +15 -5
  199. package/src/renderers/common/Bindings.js +23 -6
  200. package/src/renderers/common/ClippingContext.js +77 -85
  201. package/src/renderers/common/Constants.js +2 -1
  202. package/src/renderers/common/Geometries.js +20 -0
  203. package/src/renderers/common/IndirectStorageBufferAttribute.js +15 -0
  204. package/src/renderers/common/Lighting.js +45 -0
  205. package/src/renderers/common/PostProcessingUtils.js +86 -0
  206. package/src/renderers/common/RenderList.js +48 -17
  207. package/src/renderers/common/RenderLists.js +4 -2
  208. package/src/renderers/common/RenderObject.js +45 -28
  209. package/src/renderers/common/RenderObjects.js +12 -6
  210. package/src/renderers/common/Renderer.js +222 -77
  211. package/src/renderers/common/Textures.js +41 -17
  212. package/src/renderers/common/UniformsGroup.js +16 -4
  213. package/src/renderers/common/extras/PMREMGenerator.js +89 -13
  214. package/src/renderers/common/nodes/NodeLibrary.js +2 -15
  215. package/src/renderers/common/nodes/NodeStorageBuffer.js +2 -3
  216. package/src/renderers/common/nodes/NodeUniform.js +42 -0
  217. package/src/renderers/common/nodes/Nodes.js +2 -2
  218. package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
  219. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
  220. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
  221. package/src/renderers/webgl/WebGLBackground.js +20 -1
  222. package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
  223. package/src/renderers/webgl/WebGLCapabilities.js +0 -7
  224. package/src/renderers/webgl/WebGLGeometries.js +0 -28
  225. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
  226. package/src/renderers/webgl/WebGLProgram.js +24 -28
  227. package/src/renderers/webgl/WebGLPrograms.js +5 -2
  228. package/src/renderers/webgl/WebGLState.js +37 -1
  229. package/src/renderers/webgl/WebGLTextures.js +29 -12
  230. package/src/renderers/webgl-fallback/WebGLBackend.js +111 -37
  231. package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +2 -7
  232. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +43 -12
  233. package/src/renderers/webgl-fallback/utils/WebGLState.js +26 -1
  234. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +37 -9
  235. package/src/renderers/webgpu/WebGPUBackend.js +152 -56
  236. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +1 -1
  237. package/src/renderers/webgpu/WebGPURenderer.js +1 -1
  238. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +0 -8
  239. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +13 -34
  240. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +192 -92
  241. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +12 -4
  242. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +15 -2
  243. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +72 -7
  244. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +29 -9
  245. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +29 -7
  246. package/src/renderers/webgpu/utils/WebGPUUtils.js +0 -1
  247. package/src/renderers/webxr/WebXRManager.js +4 -4
  248. package/src/textures/Source.js +2 -2
  249. package/src/textures/Texture.js +2 -2
  250. package/examples/jsm/cameras/CinematicCamera.js +0 -208
  251. package/src/nodes/display/BlendMode.js +0 -54
  252. package/src/nodes/display/FXAANode.js +0 -332
  253. package/src/nodes/utils/OscNode.js +0 -85
  254. package/src/nodes/utils/TimerNode.js +0 -97
  255. /package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +0 -0
@@ -0,0 +1,316 @@
1
+ import { Vector2, TempNode } from 'three/webgpu';
2
+ import { nodeObject, Fn, uniformArray, select, float, NodeUpdateType, uv, dot, clamp, uniform, convertToTexture, smoothstep, bool, vec2, vec3, If, Loop, max, min, Break, abs } from 'three/tsl';
3
+
4
+ class FXAANode extends TempNode {
5
+
6
+ static get type() {
7
+
8
+ return 'FXAANode';
9
+
10
+ }
11
+
12
+ constructor( textureNode ) {
13
+
14
+ super( 'vec4' );
15
+
16
+ this.textureNode = textureNode;
17
+
18
+ this.updateBeforeType = NodeUpdateType.FRAME;
19
+
20
+ this._invSize = uniform( new Vector2() );
21
+
22
+ }
23
+
24
+ updateBefore() {
25
+
26
+ const map = this.textureNode.value;
27
+
28
+ this._invSize.value.set( 1 / map.image.width, 1 / map.image.height );
29
+
30
+ }
31
+
32
+ setup() {
33
+
34
+ const textureNode = this.textureNode.bias( - 100 );
35
+ const uvNode = textureNode.uvNode || uv();
36
+
37
+ const EDGE_STEP_COUNT = float( 6 );
38
+ const EDGE_GUESS = float( 8.0 );
39
+ const EDGE_STEPS = uniformArray( [ 1.0, 1.5, 2.0, 2.0, 2.0, 4.0 ] );
40
+
41
+ const _ContrastThreshold = float( 0.0312 );
42
+ const _RelativeThreshold = float( 0.063 );
43
+ const _SubpixelBlending = float( 1.0 );
44
+
45
+ const Sample = Fn( ( [ uv ] ) => {
46
+
47
+ return textureNode.uv( uv );
48
+
49
+ } );
50
+
51
+ const SampleLuminance = Fn( ( [ uv ] ) => {
52
+
53
+ return dot( Sample( uv ).rgb, vec3( 0.3, 0.59, 0.11 ) );
54
+
55
+ } );
56
+
57
+ const SampleLuminanceOffset = Fn( ( [ texSize, uv, uOffset, vOffset ] ) => {
58
+
59
+ const shiftedUv = uv.add( texSize.mul( vec2( uOffset, vOffset ) ) );
60
+ return SampleLuminance( shiftedUv );
61
+
62
+ } );
63
+
64
+ const ShouldSkipPixel = ( l ) => {
65
+
66
+ const threshold = max( _ContrastThreshold, _RelativeThreshold.mul( l.highest ) );
67
+ return l.contrast.lessThan( threshold );
68
+
69
+ };
70
+
71
+ const SampleLuminanceNeighborhood = ( texSize, uv ) => {
72
+
73
+ const m = SampleLuminance( uv );
74
+
75
+ const n = SampleLuminanceOffset( texSize, uv, 0.0, - 1.0 );
76
+ const e = SampleLuminanceOffset( texSize, uv, 1.0, 0.0 );
77
+ const s = SampleLuminanceOffset( texSize, uv, 0.0, 1.0 );
78
+ const w = SampleLuminanceOffset( texSize, uv, - 1.0, 0.0 );
79
+
80
+ const ne = SampleLuminanceOffset( texSize, uv, 1.0, - 1.0 );
81
+ const nw = SampleLuminanceOffset( texSize, uv, - 1.0, - 1.0 );
82
+ const se = SampleLuminanceOffset( texSize, uv, 1.0, 1.0 );
83
+ const sw = SampleLuminanceOffset( texSize, uv, - 1.0, 1.0 );
84
+
85
+ const highest = max( max( max( max( s, e ), n ), w ), m );
86
+ const lowest = min( min( min( min( s, e ), n ), w ), m );
87
+ const contrast = highest.sub( lowest );
88
+
89
+ return { m, n, e, s, w, ne, nw, se, sw, highest, lowest, contrast };
90
+
91
+ };
92
+
93
+ const DeterminePixelBlendFactor = ( l ) => {
94
+
95
+ let f = float( 2.0 ).mul( l.s.add( l.e ).add( l.n ).add( l.w ) );
96
+ f = f.add( l.se.add( l.sw ).add( l.ne ).add( l.nw ) );
97
+ f = f.mul( 1.0 / 12.0 );
98
+ f = abs( f.sub( l.m ) );
99
+ f = clamp( f.div( max( l.contrast, 0 ) ), 0.0, 1.0 );
100
+
101
+ const blendFactor = smoothstep( 0.0, 1.0, f );
102
+ return blendFactor.mul( blendFactor ).mul( _SubpixelBlending );
103
+
104
+ };
105
+
106
+ const DetermineEdge = ( texSize, l ) => {
107
+
108
+ const horizontal =
109
+ abs( l.s.add( l.n ).sub( l.m.mul( 2.0 ) ) ).mul( 2.0 ).add(
110
+ abs( l.se.add( l.ne ).sub( l.e.mul( 2.0 ) ) ).add(
111
+ abs( l.sw.add( l.nw ).sub( l.w.mul( 2.0 ) ) )
112
+ )
113
+ );
114
+
115
+ const vertical =
116
+ abs( l.e.add( l.w ).sub( l.m.mul( 2.0 ) ) ).mul( 2.0 ).add(
117
+ abs( l.se.add( l.sw ).sub( l.s.mul( 2.0 ) ) ).add(
118
+ abs( l.ne.add( l.nw ).sub( l.n.mul( 2.0 ) ) )
119
+ )
120
+ );
121
+
122
+ const isHorizontal = horizontal.greaterThanEqual( vertical );
123
+
124
+ const pLuminance = select( isHorizontal, l.s, l.e );
125
+ const nLuminance = select( isHorizontal, l.n, l.w );
126
+ const pGradient = abs( pLuminance.sub( l.m ) );
127
+ const nGradient = abs( nLuminance.sub( l.m ) );
128
+
129
+ const pixelStep = select( isHorizontal, texSize.y, texSize.x ).toVar();
130
+ const oppositeLuminance = float().toVar();
131
+ const gradient = float().toVar();
132
+
133
+ If( pGradient.lessThan( nGradient ), () => {
134
+
135
+ pixelStep.assign( pixelStep.negate() );
136
+ oppositeLuminance.assign( nLuminance );
137
+ gradient.assign( nGradient );
138
+
139
+ } ).Else( () => {
140
+
141
+ oppositeLuminance.assign( pLuminance );
142
+ gradient.assign( pGradient );
143
+
144
+ } );
145
+
146
+ return { isHorizontal, pixelStep, oppositeLuminance, gradient };
147
+
148
+ };
149
+
150
+ const DetermineEdgeBlendFactor = ( texSize, l, e, uv ) => {
151
+
152
+ const uvEdge = uv.toVar();
153
+ const edgeStep = vec2().toVar();
154
+ If( e.isHorizontal, () => {
155
+
156
+ uvEdge.y.addAssign( e.pixelStep.mul( 0.5 ) );
157
+ edgeStep.assign( vec2( texSize.x, 0.0 ) );
158
+
159
+ } ).Else( () => {
160
+
161
+ uvEdge.x.addAssign( e.pixelStep.mul( 0.5 ) );
162
+ edgeStep.assign( vec2( 0.0, texSize.y ) );
163
+
164
+ } );
165
+
166
+ const edgeLuminance = l.m.add( e.oppositeLuminance ).mul( 0.5 );
167
+ const gradientThreshold = e.gradient.mul( 0.25 );
168
+
169
+ const puv = uvEdge.add( edgeStep.mul( EDGE_STEPS.element( 0 ) ) ).toVar();
170
+ const pLuminanceDelta = SampleLuminance( puv ).sub( edgeLuminance ).toVar();
171
+ const pAtEnd = abs( pLuminanceDelta ).greaterThanEqual( gradientThreshold ).toVar();
172
+
173
+ Loop( { start: 1, end: EDGE_STEP_COUNT }, ( { i } ) => {
174
+
175
+ If( pAtEnd, () => {
176
+
177
+ Break();
178
+
179
+ } );
180
+
181
+ puv.addAssign( edgeStep.mul( EDGE_STEPS.element( i ) ) );
182
+ pLuminanceDelta.assign( SampleLuminance( puv ).sub( edgeLuminance ) );
183
+ pAtEnd.assign( abs( pLuminanceDelta ).greaterThanEqual( gradientThreshold ) );
184
+
185
+ } );
186
+
187
+ If( pAtEnd.not(), () => {
188
+
189
+ puv.addAssign( edgeStep.mul( EDGE_GUESS ) );
190
+
191
+ } );
192
+
193
+ const nuv = uvEdge.sub( edgeStep.mul( EDGE_STEPS.element( 0 ) ) ).toVar();
194
+ const nLuminanceDelta = SampleLuminance( nuv ).sub( edgeLuminance ).toVar();
195
+ const nAtEnd = abs( nLuminanceDelta ).greaterThanEqual( gradientThreshold ).toVar();
196
+
197
+ Loop( { start: 1, end: EDGE_STEP_COUNT }, ( { i } ) => {
198
+
199
+ If( nAtEnd, () => {
200
+
201
+ Break();
202
+
203
+ } );
204
+
205
+ nuv.subAssign( edgeStep.mul( EDGE_STEPS.element( i ) ) );
206
+ nLuminanceDelta.assign( SampleLuminance( nuv ).sub( edgeLuminance ) );
207
+ nAtEnd.assign( abs( nLuminanceDelta ).greaterThanEqual( gradientThreshold ) );
208
+
209
+ } );
210
+
211
+ If( nAtEnd.not(), () => {
212
+
213
+ nuv.subAssign( edgeStep.mul( EDGE_GUESS ) );
214
+
215
+ } );
216
+
217
+ const pDistance = float().toVar();
218
+ const nDistance = float().toVar();
219
+
220
+ If( e.isHorizontal, () => {
221
+
222
+ pDistance.assign( puv.x.sub( uv.x ) );
223
+ nDistance.assign( uv.x.sub( nuv.x ) );
224
+
225
+ } ).Else( () => {
226
+
227
+ pDistance.assign( puv.y.sub( uv.y ) );
228
+ nDistance.assign( uv.y.sub( nuv.y ) );
229
+
230
+ } );
231
+
232
+ const shortestDistance = float().toVar();
233
+ const deltaSign = bool().toVar();
234
+
235
+ If( pDistance.lessThanEqual( nDistance ), () => {
236
+
237
+ shortestDistance.assign( pDistance );
238
+ deltaSign.assign( pLuminanceDelta.greaterThanEqual( 0.0 ) );
239
+
240
+ } ).Else( () => {
241
+
242
+ shortestDistance.assign( nDistance );
243
+ deltaSign.assign( nLuminanceDelta.greaterThanEqual( 0.0 ) );
244
+
245
+ } );
246
+
247
+ const blendFactor = float().toVar();
248
+
249
+ If( deltaSign.equal( l.m.sub( edgeLuminance ).greaterThanEqual( 0.0 ) ), () => {
250
+
251
+ blendFactor.assign( 0.0 );
252
+
253
+ } ).Else( () => {
254
+
255
+ blendFactor.assign( float( 0.5 ).sub( shortestDistance.div( pDistance.add( nDistance ) ) ) );
256
+
257
+ } );
258
+
259
+ return blendFactor;
260
+
261
+ };
262
+
263
+ const ApplyFXAA = Fn( ( [ uv, texSize ] ) => {
264
+
265
+ const luminance = SampleLuminanceNeighborhood( texSize, uv );
266
+ If( ShouldSkipPixel( luminance ), () => {
267
+
268
+ return Sample( uv );
269
+
270
+ } );
271
+
272
+ const pixelBlend = DeterminePixelBlendFactor( luminance );
273
+ const edge = DetermineEdge( texSize, luminance );
274
+ const edgeBlend = DetermineEdgeBlendFactor( texSize, luminance, edge, uv );
275
+
276
+ const finalBlend = max( pixelBlend, edgeBlend );
277
+ const finalUv = uv.toVar();
278
+
279
+ If( edge.isHorizontal, () => {
280
+
281
+ finalUv.y.addAssign( edge.pixelStep.mul( finalBlend ) );
282
+
283
+ } ).Else( () => {
284
+
285
+ finalUv.x.addAssign( edge.pixelStep.mul( finalBlend ) );
286
+
287
+ } );
288
+
289
+ return Sample( finalUv );
290
+
291
+ } ).setLayout( {
292
+ name: 'FxaaPixelShader',
293
+ type: 'vec4',
294
+ inputs: [
295
+ { name: 'uv', type: 'vec2' },
296
+ { name: 'texSize', type: 'vec2' },
297
+ ]
298
+ } );
299
+
300
+ const fxaa = Fn( () => {
301
+
302
+ return ApplyFXAA( uvNode, this._invSize );
303
+
304
+ } );
305
+
306
+ const outputNode = fxaa();
307
+
308
+ return outputNode;
309
+
310
+ }
311
+
312
+ }
313
+
314
+ export default FXAANode;
315
+
316
+ export const fxaa = ( node ) => nodeObject( new FXAANode( convertToTexture( node ) ) );
@@ -1,8 +1,5 @@
1
- import TempNode from '../core/TempNode.js';
2
- import { uv } from '../accessors/UV.js';
3
- import { Fn, nodeProxy, vec4 } from '../tsl/TSLBase.js';
4
- import { mix, fract, clamp, rand } from '../math/MathNode.js';
5
- import { timerLocal } from '../utils/TimerNode.js';
1
+ import { TempNode } from 'three/webgpu';
2
+ import { rand, Fn, fract, time, uv, clamp, mix, vec4, nodeProxy } from 'three/tsl';
6
3
 
7
4
  class FilmNode extends TempNode {
8
5
 
@@ -14,7 +11,7 @@ class FilmNode extends TempNode {
14
11
 
15
12
  constructor( inputNode, intensityNode = null, uvNode = null ) {
16
13
 
17
- super();
14
+ super( 'vec4' );
18
15
 
19
16
  this.inputNode = inputNode;
20
17
  this.intensityNode = intensityNode;
@@ -29,7 +26,7 @@ class FilmNode extends TempNode {
29
26
  const film = Fn( () => {
30
27
 
31
28
  const base = this.inputNode.rgb;
32
- const noise = rand( fract( uvNode.add( timerLocal() ) ) );
29
+ const noise = rand( fract( uvNode.add( time ) ) );
33
30
 
34
31
  let color = base.add( base.mul( clamp( noise.add( 0.1 ), 0, 1 ) ) );
35
32
 
@@ -1,28 +1,15 @@
1
- import TempNode from '../core/TempNode.js';
2
- import { texture } from '../accessors/TextureNode.js';
3
- import { textureSize } from '../accessors/TextureSizeNode.js';
4
- import { uv } from '../accessors/UV.js';
5
- import { nodeObject, Fn, mat3, vec2, vec3, vec4, float, int, If } from '../tsl/TSLBase.js';
6
- import { NodeUpdateType } from '../core/constants.js';
7
- import { uniform } from '../core/UniformNode.js';
8
- import { DataTexture } from '../../textures/DataTexture.js';
9
- import { Vector2 } from '../../math/Vector2.js';
10
- import { Vector3 } from '../../math/Vector3.js';
11
- import { PI, cos, sin, pow, clamp, abs, max, mix, sqrt, acos, dot, normalize, cross } from '../math/MathNode.js';
12
- import { div, mul, add, sub } from '../math/OperatorNode.js';
13
- import { Loop } from '../utils/LoopNode.js';
14
- import { passTexture } from './PassNode.js';
15
- import { RepeatWrapping } from '../../constants.js';
16
- import QuadMesh from '../../renderers/common/QuadMesh.js';
17
- import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
18
-
19
- import { RenderTarget } from '../../core/RenderTarget.js';
20
- import { Color } from '../../math/Color.js';
1
+ import { DataTexture, RenderTarget, RepeatWrapping, Vector2, Vector3, TempNode, QuadMesh, NodeMaterial, PostProcessingUtils } from 'three/webgpu';
2
+ import { reference, logarithmicDepthToViewZ, viewZToPerspectiveDepth, getNormalFromDepth, getScreenPosition, getViewPosition, nodeObject, Fn, float, NodeUpdateType, uv, uniform, Loop, vec2, vec3, vec4, int, dot, max, pow, abs, If, textureSize, sin, cos, PI, texture, passTexture, mat3, add, normalize, mul, cross, div, mix, sqrt, sub, acos, clamp } from 'three/tsl';
21
3
 
22
4
  const _quadMesh = /*@__PURE__*/ new QuadMesh();
23
- const _currentClearColor = /*@__PURE__*/ new Color();
24
5
  const _size = /*@__PURE__*/ new Vector2();
25
6
 
7
+ let _rendererState;
8
+
9
+ /**
10
+ * References:
11
+ * https://www.activision.com/cdn/research/Practical_Real_Time_Strategies_for_Accurate_Indirect_Occlusion_NEW%20VERSION_COLOR.pdf
12
+ */
26
13
  class GTAONode extends TempNode {
27
14
 
28
15
  static get type() {
@@ -33,31 +20,44 @@ class GTAONode extends TempNode {
33
20
 
34
21
  constructor( depthNode, normalNode, camera ) {
35
22
 
36
- super();
23
+ super( 'vec4' );
37
24
 
38
25
  this.depthNode = depthNode;
39
26
  this.normalNode = normalNode;
40
27
 
28
+ this.resolutionScale = 1;
29
+
30
+ this.updateBeforeType = NodeUpdateType.FRAME;
31
+
32
+ // render targets
33
+
34
+ this._aoRenderTarget = new RenderTarget( 1, 1, { depthBuffer: false } );
35
+ this._aoRenderTarget.texture.name = 'GTAONode.AO';
36
+
37
+ // uniforms
38
+
41
39
  this.radius = uniform( 0.25 );
42
40
  this.resolution = uniform( new Vector2() );
43
41
  this.thickness = uniform( 1 );
44
42
  this.distanceExponent = uniform( 1 );
45
43
  this.distanceFallOff = uniform( 1 );
46
44
  this.scale = uniform( 1 );
47
- this.noiseNode = texture( generateMagicSquareNoise() );
45
+ this.samples = uniform( 16 );
48
46
 
49
- this.cameraProjectionMatrix = uniform( camera.projectionMatrix );
50
- this.cameraProjectionMatrixInverse = uniform( camera.projectionMatrixInverse );
47
+ this._noiseNode = texture( generateMagicSquareNoise() );
48
+ this._cameraProjectionMatrix = uniform( camera.projectionMatrix );
49
+ this._cameraProjectionMatrixInverse = uniform( camera.projectionMatrixInverse );
50
+ this._cameraNear = reference( 'near', 'float', camera );
51
+ this._cameraFar = reference( 'far', 'float', camera );
51
52
 
52
- this.SAMPLES = uniform( 16 );
53
+ // materials
53
54
 
54
- this._aoRenderTarget = new RenderTarget();
55
- this._aoRenderTarget.texture.name = 'GTAONode.AO';
55
+ this._material = new NodeMaterial();
56
+ this._material.name = 'GTAO';
56
57
 
57
- this._material = null;
58
- this._textureNode = passTexture( this, this._aoRenderTarget.texture );
58
+ //
59
59
 
60
- this.updateBeforeType = NodeUpdateType.FRAME;
60
+ this._textureNode = passTexture( this, this._aoRenderTarget.texture );
61
61
 
62
62
  }
63
63
 
@@ -69,6 +69,9 @@ class GTAONode extends TempNode {
69
69
 
70
70
  setSize( width, height ) {
71
71
 
72
+ width = Math.round( this.resolutionScale * width );
73
+ height = Math.round( this.resolutionScale * height );
74
+
72
75
  this.resolution.value.set( width, height );
73
76
  this._aoRenderTarget.setSize( width, height );
74
77
 
@@ -78,20 +81,17 @@ class GTAONode extends TempNode {
78
81
 
79
82
  const { renderer } = frame;
80
83
 
81
- const size = renderer.getDrawingBufferSize( _size );
82
-
83
- const currentRenderTarget = renderer.getRenderTarget();
84
- const currentMRT = renderer.getMRT();
85
- renderer.getClearColor( _currentClearColor );
86
- const currentClearAlpha = renderer.getClearAlpha();
84
+ _rendererState = PostProcessingUtils.resetRendererState( renderer, _rendererState );
87
85
 
88
- _quadMesh.material = this._material;
86
+ //
89
87
 
88
+ const size = renderer.getDrawingBufferSize( _size );
90
89
  this.setSize( size.width, size.height );
91
90
 
91
+ _quadMesh.material = this._material;
92
+
92
93
  // clear
93
94
 
94
- renderer.setMRT( null );
95
95
  renderer.setClearColor( 0xffffff, 1 );
96
96
 
97
97
  // ao
@@ -101,9 +101,7 @@ class GTAONode extends TempNode {
101
101
 
102
102
  // restore
103
103
 
104
- renderer.setRenderTarget( currentRenderTarget );
105
- renderer.setMRT( currentMRT );
106
- renderer.setClearColor( _currentClearColor, currentClearAlpha );
104
+ PostProcessingUtils.restoreRendererState( renderer, _rendererState );
107
105
 
108
106
  }
109
107
 
@@ -111,42 +109,37 @@ class GTAONode extends TempNode {
111
109
 
112
110
  const uvNode = uv();
113
111
 
114
- const sampleDepth = ( uv ) => this.depthNode.uv( uv ).x;
115
- const sampleNoise = ( uv ) => this.noiseNode.uv( uv );
112
+ const sampleDepth = ( uv ) => {
116
113
 
117
- const getSceneUvAndDepth = Fn( ( [ sampleViewPos ] )=> {
114
+ const depth = this.depthNode.uv( uv ).r;
118
115
 
119
- const sampleClipPos = this.cameraProjectionMatrix.mul( vec4( sampleViewPos, 1.0 ) );
120
- let sampleUv = sampleClipPos.xy.div( sampleClipPos.w ).mul( 0.5 ).add( 0.5 ).toVar();
121
- sampleUv = vec2( sampleUv.x, sampleUv.y.oneMinus() );
122
- const sampleSceneDepth = sampleDepth( sampleUv );
123
- return vec3( sampleUv, sampleSceneDepth );
116
+ if ( builder.renderer.logarithmicDepthBuffer === true ) {
124
117
 
125
- } );
118
+ const viewZ = logarithmicDepthToViewZ( depth, this._cameraNear, this._cameraFar );
126
119
 
127
- const getViewPosition = Fn( ( [ screenPosition, depth ] ) => {
120
+ return viewZToPerspectiveDepth( viewZ, this._cameraNear, this._cameraFar );
128
121
 
129
- screenPosition = vec2( screenPosition.x, screenPosition.y.oneMinus() ).mul( 2.0 ).sub( 1.0 );
122
+ }
130
123
 
131
- const clipSpacePosition = vec4( vec3( screenPosition, depth ), 1.0 );
132
- const viewSpacePosition = vec4( this.cameraProjectionMatrixInverse.mul( clipSpacePosition ) );
124
+ return depth;
133
125
 
134
- return viewSpacePosition.xyz.div( viewSpacePosition.w );
126
+ };
135
127
 
136
- } );
128
+ const sampleNoise = ( uv ) => this._noiseNode.uv( uv );
129
+ const sampleNormal = ( uv ) => ( this.normalNode !== null ) ? this.normalNode.uv( uv ).rgb.normalize() : getNormalFromDepth( uv, this.depthNode.value, this._cameraProjectionMatrixInverse );
137
130
 
138
131
  const ao = Fn( () => {
139
132
 
140
- const depth = sampleDepth( uvNode );
133
+ const depth = sampleDepth( uvNode ).toVar();
141
134
 
142
135
  depth.greaterThanEqual( 1.0 ).discard();
143
136
 
144
- const viewPosition = getViewPosition( uvNode, depth );
145
- const viewNormal = this.normalNode.rgb.normalize();
137
+ const viewPosition = getViewPosition( uvNode, depth, this._cameraProjectionMatrixInverse ).toVar();
138
+ const viewNormal = sampleNormal( uvNode ).toVar();
146
139
 
147
140
  const radiusToUse = this.radius;
148
141
 
149
- const noiseResolution = textureSize( this.noiseNode, 0 );
142
+ const noiseResolution = textureSize( this._noiseNode, 0 );
150
143
  let noiseUv = vec2( uvNode.x, uvNode.y.oneMinus() );
151
144
  noiseUv = noiseUv.mul( this.resolution.div( noiseResolution ) );
152
145
  const noiseTexel = sampleNoise( noiseUv );
@@ -155,23 +148,23 @@ class GTAONode extends TempNode {
155
148
  const bitangent = vec3( tangent.y.mul( - 1.0 ), tangent.x, 0.0 );
156
149
  const kernelMatrix = mat3( tangent, bitangent, vec3( 0.0, 0.0, 1.0 ) );
157
150
 
158
- const DIRECTIONS = this.SAMPLES.lessThan( 30 ).select( 3, 5 );
159
- const STEPS = add( this.SAMPLES, DIRECTIONS.sub( 1 ) ).div( DIRECTIONS );
151
+ const DIRECTIONS = this.samples.lessThan( 30 ).select( 3, 5 ).toVar();
152
+ const STEPS = add( this.samples, DIRECTIONS.sub( 1 ) ).div( DIRECTIONS ).toVar();
160
153
 
161
154
  const ao = float( 0 ).toVar();
162
155
 
163
156
  Loop( { start: int( 0 ), end: DIRECTIONS, type: 'int', condition: '<' }, ( { i } ) => {
164
157
 
165
- const angle = float( i ).div( float( DIRECTIONS ) ).mul( PI );
158
+ const angle = float( i ).div( float( DIRECTIONS ) ).mul( PI ).toVar();
166
159
  const sampleDir = vec4( cos( angle ), sin( angle ), 0., add( 0.5, mul( 0.5, noiseTexel.w ) ) );
167
160
  sampleDir.xyz = normalize( kernelMatrix.mul( sampleDir.xyz ) );
168
161
 
169
- const viewDir = normalize( viewPosition.xyz.negate() );
170
- const sliceBitangent = normalize( cross( sampleDir.xyz, viewDir ) );
162
+ const viewDir = normalize( viewPosition.xyz.negate() ).toVar();
163
+ const sliceBitangent = normalize( cross( sampleDir.xyz, viewDir ) ).toVar();
171
164
  const sliceTangent = cross( sliceBitangent, viewDir );
172
165
  const normalInSlice = normalize( viewNormal.sub( sliceBitangent.mul( dot( viewNormal, sliceBitangent ) ) ) );
173
166
 
174
- const tangentToNormalInSlice = cross( normalInSlice, sliceBitangent );
167
+ const tangentToNormalInSlice = cross( normalInSlice, sliceBitangent ).toVar();
175
168
  const cosHorizons = vec2( dot( viewDir, tangentToNormalInSlice ), dot( viewDir, tangentToNormalInSlice.negate() ) ).toVar();
176
169
 
177
170
  Loop( { end: STEPS, type: 'int', name: 'j', condition: '<' }, ( { j } ) => {
@@ -180,9 +173,10 @@ class GTAONode extends TempNode {
180
173
 
181
174
  // x
182
175
 
183
- const sampleSceneUvDepthX = getSceneUvAndDepth( viewPosition.add( sampleViewOffset ) );
184
- const sampleSceneViewPositionX = getViewPosition( sampleSceneUvDepthX.xy, sampleSceneUvDepthX.z );
185
- const viewDeltaX = sampleSceneViewPositionX.sub( viewPosition );
176
+ const sampleScreenPositionX = getScreenPosition( viewPosition.add( sampleViewOffset ), this._cameraProjectionMatrix ).toVar();
177
+ const sampleDepthX = sampleDepth( sampleScreenPositionX ).toVar();
178
+ const sampleSceneViewPositionX = getViewPosition( sampleScreenPositionX, sampleDepthX, this._cameraProjectionMatrixInverse ).toVar();
179
+ const viewDeltaX = sampleSceneViewPositionX.sub( viewPosition ).toVar();
186
180
 
187
181
  If( abs( viewDeltaX.z ).lessThan( this.thickness ), () => {
188
182
 
@@ -193,9 +187,10 @@ class GTAONode extends TempNode {
193
187
 
194
188
  // y
195
189
 
196
- const sampleSceneUvDepthY = getSceneUvAndDepth( viewPosition.sub( sampleViewOffset ) );
197
- const sampleSceneViewPositionY = getViewPosition( sampleSceneUvDepthY.xy, sampleSceneUvDepthY.z );
198
- const viewDeltaY = sampleSceneViewPositionY.sub( viewPosition );
190
+ const sampleScreenPositionY = getScreenPosition( viewPosition.sub( sampleViewOffset ), this._cameraProjectionMatrix ).toVar();
191
+ const sampleDepthY = sampleDepth( sampleScreenPositionY ).toVar();
192
+ const sampleSceneViewPositionY = getViewPosition( sampleScreenPositionY, sampleDepthY, this._cameraProjectionMatrixInverse ).toVar();
193
+ const viewDeltaY = sampleSceneViewPositionY.sub( viewPosition ).toVar();
199
194
 
200
195
  If( abs( viewDeltaY.z ).lessThan( this.thickness ), () => {
201
196
 
@@ -206,7 +201,7 @@ class GTAONode extends TempNode {
206
201
 
207
202
  } );
208
203
 
209
- const sinHorizons = sqrt( sub( 1.0, cosHorizons.mul( cosHorizons ) ) );
204
+ const sinHorizons = sqrt( sub( 1.0, cosHorizons.mul( cosHorizons ) ) ).toVar();
210
205
  const nx = dot( normalInSlice, sliceTangent );
211
206
  const ny = dot( normalInSlice, viewDir );
212
207
  const nxb = mul( 0.5, acos( cosHorizons.y ).sub( acos( cosHorizons.x ) ).add( sinHorizons.x.mul( cosHorizons.x ).sub( sinHorizons.y.mul( cosHorizons.y ) ) ) );
@@ -223,10 +218,8 @@ class GTAONode extends TempNode {
223
218
 
224
219
  } );
225
220
 
226
- const material = this._material || ( this._material = new NodeMaterial() );
227
- material.fragmentNode = ao().context( builder.getSharedContext() );
228
- material.name = 'GTAO';
229
- material.needsUpdate = true;
221
+ this._material.fragmentNode = ao().context( builder.getSharedContext() );
222
+ this._material.needsUpdate = true;
230
223
 
231
224
  //
232
225
 
@@ -238,6 +231,8 @@ class GTAONode extends TempNode {
238
231
 
239
232
  this._aoRenderTarget.dispose();
240
233
 
234
+ this._material.dispose();
235
+
241
236
  }
242
237
 
243
238
  }