super-three 0.169.0 → 0.170.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 (195) hide show
  1. package/build/three.cjs +989 -1131
  2. package/build/three.module.js +990 -1128
  3. package/build/three.module.min.js +1 -1
  4. package/build/three.webgpu.js +8398 -9842
  5. package/build/three.webgpu.min.js +1 -1
  6. package/build/three.webgpu.nodes.js +8398 -9842
  7. package/build/three.webgpu.nodes.min.js +1 -1
  8. package/examples/jsm/Addons.js +3 -3
  9. package/examples/jsm/animation/MMDAnimationHelper.js +2 -0
  10. package/examples/jsm/animation/MMDPhysics.js +2 -0
  11. package/examples/jsm/controls/TransformControls.js +22 -6
  12. package/examples/jsm/csm/CSM.js +2 -2
  13. package/examples/jsm/csm/CSMFrustum.js +7 -4
  14. package/examples/jsm/csm/CSMHelper.js +2 -0
  15. package/examples/jsm/csm/CSMShadowNode.js +435 -0
  16. package/examples/jsm/curves/NURBSCurve.js +34 -3
  17. package/examples/jsm/exporters/GLTFExporter.js +138 -71
  18. package/examples/jsm/exporters/KTX2Exporter.js +35 -12
  19. package/examples/jsm/exporters/MMDExporter.js +6 -0
  20. package/examples/jsm/exporters/USDZExporter.js +21 -3
  21. package/examples/jsm/geometries/DecalGeometry.js +65 -20
  22. package/examples/jsm/geometries/InstancedPointsGeometry.js +2 -0
  23. package/examples/jsm/helpers/TextureHelperGPU.js +175 -0
  24. package/examples/jsm/interactive/HTMLMesh.js +1 -0
  25. package/examples/jsm/lighting/TiledLighting.js +18 -0
  26. package/examples/jsm/lights/RectAreaLightTexturesLib.js +1 -1
  27. package/examples/jsm/lines/LineMaterial.js +7 -2
  28. package/examples/jsm/lines/LineSegmentsGeometry.js +2 -0
  29. package/examples/jsm/lines/webgpu/LineSegments2.js +0 -15
  30. package/examples/jsm/lines/webgpu/Wireframe.js +56 -0
  31. package/examples/jsm/loaders/3DMLoader.js +1 -0
  32. package/examples/jsm/loaders/3MFLoader.js +91 -0
  33. package/examples/jsm/loaders/FBXLoader.js +12 -2
  34. package/examples/jsm/loaders/GLTFLoader.js +2 -0
  35. package/examples/jsm/loaders/KTX2Loader.js +140 -49
  36. package/examples/jsm/loaders/LDrawLoader.js +22 -136
  37. package/examples/jsm/loaders/LottieLoader.js +1 -0
  38. package/examples/jsm/loaders/MMDLoader.js +9 -2
  39. package/examples/jsm/materials/LDrawConditionalLineMaterial.js +143 -0
  40. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +114 -0
  41. package/examples/jsm/materials/MeshGouraudMaterial.js +6 -2
  42. package/examples/jsm/math/ColorSpaces.js +76 -0
  43. package/examples/jsm/misc/ProgressiveLightMap.js +52 -40
  44. package/examples/jsm/misc/ProgressiveLightMapGPU.js +293 -0
  45. package/examples/jsm/misc/VolumeSlice.js +1 -0
  46. package/examples/jsm/objects/WaterMesh.js +8 -8
  47. package/examples/jsm/postprocessing/AfterimagePass.js +14 -3
  48. package/examples/jsm/postprocessing/SSRPass.js +6 -0
  49. package/examples/jsm/renderers/CSS2DRenderer.js +6 -3
  50. package/examples/jsm/renderers/CSS3DRenderer.js +7 -4
  51. package/examples/jsm/shaders/FXAAShader.js +225 -224
  52. package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
  53. package/{src/nodes → examples/jsm/tsl}/display/AfterImageNode.js +17 -20
  54. package/{src/nodes → examples/jsm/tsl}/display/AnaglyphPassNode.js +2 -6
  55. package/{src/nodes → examples/jsm/tsl}/display/AnamorphicNode.js +12 -18
  56. package/{src/nodes → examples/jsm/tsl}/display/BleachBypass.js +1 -3
  57. package/{src/nodes → examples/jsm/tsl}/display/BloomNode.js +11 -40
  58. package/{src/nodes → examples/jsm/tsl}/display/DenoiseNode.js +18 -41
  59. package/{src/nodes → examples/jsm/tsl}/display/DepthOfFieldNode.js +2 -8
  60. package/{src/nodes → examples/jsm/tsl}/display/DotScreenNode.js +2 -9
  61. package/examples/jsm/tsl/display/FXAANode.js +316 -0
  62. package/{src/nodes → examples/jsm/tsl}/display/FilmNode.js +2 -6
  63. package/{src/nodes → examples/jsm/tsl}/display/GTAONode.js +30 -70
  64. package/{src/nodes → examples/jsm/tsl}/display/GaussianBlurNode.js +74 -36
  65. package/examples/jsm/tsl/display/LensflareNode.js +161 -0
  66. package/{src/nodes → examples/jsm/tsl}/display/Lut3DNode.js +1 -4
  67. package/{src/nodes → examples/jsm/tsl}/display/MotionBlur.js +2 -3
  68. package/examples/jsm/tsl/display/OutlineNode.js +434 -0
  69. package/{src/nodes → examples/jsm/tsl}/display/ParallaxBarrierPassNode.js +1 -5
  70. package/{src/nodes → examples/jsm/tsl}/display/PixelationPassNode.js +3 -15
  71. package/{src/nodes → examples/jsm/tsl}/display/RGBShiftNode.js +1 -6
  72. package/examples/jsm/tsl/display/SMAANode.js +620 -0
  73. package/{src/nodes → examples/jsm/tsl}/display/SSAAPassNode.js +10 -25
  74. package/examples/jsm/tsl/display/SSRNode.js +343 -0
  75. package/{src/nodes → examples/jsm/tsl}/display/Sepia.js +1 -2
  76. package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +3 -11
  77. package/{src/nodes → examples/jsm/tsl}/display/StereoCompositePassNode.js +9 -11
  78. package/{src/nodes → examples/jsm/tsl}/display/StereoPassNode.js +10 -11
  79. package/examples/jsm/tsl/display/TRAAPassNode.js +355 -0
  80. package/{src/nodes → examples/jsm/tsl}/display/TransitionNode.js +1 -6
  81. package/examples/jsm/tsl/display/hashBlur.js +24 -0
  82. package/examples/jsm/tsl/lighting/TiledLightsNode.js +392 -0
  83. package/examples/jsm/utils/{TextureUtilsGPU.js → WebGPUTextureUtils.js} +2 -1
  84. package/examples/jsm/webxr/OculusHandPointerModel.js +21 -21
  85. package/examples/jsm/webxr/Text2D.js +6 -6
  86. package/package.json +2 -2
  87. package/src/Three.WebGPU.Nodes.js +4 -0
  88. package/src/Three.WebGPU.js +4 -0
  89. package/src/constants.js +1 -6
  90. package/src/core/BufferGeometry.js +44 -6
  91. package/src/geometries/CylinderGeometry.js +2 -2
  92. package/src/materials/LineBasicMaterial.js +6 -2
  93. package/src/materials/LineDashedMaterial.js +6 -2
  94. package/src/materials/Material.js +14 -1
  95. package/src/materials/MeshBasicMaterial.js +6 -2
  96. package/src/materials/MeshDepthMaterial.js +6 -2
  97. package/src/materials/MeshDistanceMaterial.js +6 -2
  98. package/src/materials/MeshLambertMaterial.js +6 -2
  99. package/src/materials/MeshMatcapMaterial.js +6 -2
  100. package/src/materials/MeshNormalMaterial.js +6 -2
  101. package/src/materials/MeshPhongMaterial.js +6 -2
  102. package/src/materials/MeshPhysicalMaterial.js +6 -2
  103. package/src/materials/MeshStandardMaterial.js +6 -2
  104. package/src/materials/MeshToonMaterial.js +6 -2
  105. package/src/materials/PointsMaterial.js +6 -2
  106. package/src/materials/RawShaderMaterial.js +6 -2
  107. package/src/materials/ShaderMaterial.js +6 -2
  108. package/src/materials/ShadowMaterial.js +6 -2
  109. package/src/materials/SpriteMaterial.js +6 -2
  110. package/src/materials/nodes/NodeMaterial.js +31 -9
  111. package/src/materials/nodes/SpriteNodeMaterial.js +11 -2
  112. package/src/materials/nodes/manager/NodeMaterialObserver.js +111 -2
  113. package/src/math/ColorManagement.js +118 -85
  114. package/src/math/Vector4.js +11 -0
  115. package/src/nodes/Nodes.js +1 -21
  116. package/src/nodes/TSL.js +6 -24
  117. package/src/nodes/accessors/Camera.js +0 -1
  118. package/src/nodes/accessors/SceneNode.js +35 -1
  119. package/src/nodes/accessors/StorageBufferNode.js +32 -10
  120. package/src/nodes/accessors/VelocityNode.js +13 -3
  121. package/src/nodes/code/FunctionCallNode.js +16 -5
  122. package/src/nodes/code/ScriptableNode.js +4 -4
  123. package/src/nodes/core/Node.js +1 -0
  124. package/src/nodes/core/NodeBuilder.js +29 -5
  125. package/src/nodes/core/VarNode.js +15 -3
  126. package/src/nodes/display/ColorAdjustment.js +53 -4
  127. package/src/nodes/display/ColorSpaceFunctions.js +5 -5
  128. package/src/nodes/display/ColorSpaceNode.js +27 -39
  129. package/src/nodes/display/PassNode.js +6 -4
  130. package/src/nodes/display/ToneMappingNode.js +1 -1
  131. package/src/nodes/display/ViewportDepthNode.js +33 -1
  132. package/src/nodes/functions/PhysicalLightingModel.js +21 -15
  133. package/src/nodes/functions/material/getAlphaHashThreshold.js +64 -0
  134. package/src/nodes/functions/material/getGeometryRoughness.js +8 -2
  135. package/src/nodes/functions/material/getParallaxCorrectNormal.js +22 -0
  136. package/src/nodes/gpgpu/ComputeNode.js +9 -1
  137. package/src/nodes/lighting/AnalyticLightNode.js +12 -416
  138. package/src/nodes/lighting/LightsNode.js +24 -12
  139. package/src/nodes/lighting/PointLightNode.js +36 -26
  140. package/src/nodes/lighting/RectAreaLightNode.js +3 -0
  141. package/src/nodes/lighting/ShadowNode.js +484 -0
  142. package/src/nodes/utils/LoopNode.js +2 -2
  143. package/src/nodes/utils/Oscillators.js +6 -0
  144. package/src/nodes/utils/PostProcessingUtils.js +89 -0
  145. package/src/nodes/utils/ReflectorNode.js +101 -15
  146. package/src/nodes/utils/Timer.js +29 -0
  147. package/src/objects/BatchedMesh.js +458 -241
  148. package/src/renderers/WebGLRenderer.js +121 -126
  149. package/src/renderers/common/Attributes.js +4 -0
  150. package/src/renderers/common/Backend.js +2 -0
  151. package/src/renderers/common/Background.js +14 -4
  152. package/src/renderers/common/Bindings.js +3 -2
  153. package/src/renderers/common/Constants.js +2 -1
  154. package/src/renderers/common/Geometries.js +20 -0
  155. package/src/renderers/common/IndirectStorageBufferAttribute.js +15 -0
  156. package/src/renderers/common/Lighting.js +45 -0
  157. package/src/renderers/common/PostProcessingUtils.js +86 -0
  158. package/src/renderers/common/RenderList.js +39 -11
  159. package/src/renderers/common/RenderLists.js +4 -2
  160. package/src/renderers/common/RenderObject.js +18 -1
  161. package/src/renderers/common/Renderer.js +165 -26
  162. package/src/renderers/common/Textures.js +30 -14
  163. package/src/renderers/common/nodes/NodeLibrary.js +1 -14
  164. package/src/renderers/common/nodes/Nodes.js +2 -2
  165. package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
  166. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
  167. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
  168. package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
  169. package/src/renderers/webgl/WebGLCapabilities.js +0 -7
  170. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
  171. package/src/renderers/webgl/WebGLProgram.js +24 -28
  172. package/src/renderers/webgl/WebGLPrograms.js +5 -2
  173. package/src/renderers/webgl/WebGLState.js +37 -1
  174. package/src/renderers/webgl/WebGLTextures.js +29 -12
  175. package/src/renderers/webgl-fallback/WebGLBackend.js +98 -31
  176. package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +2 -7
  177. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +33 -8
  178. package/src/renderers/webgpu/WebGPUBackend.js +105 -25
  179. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +1 -1
  180. package/src/renderers/webgpu/WebGPURenderer.js +1 -1
  181. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +0 -8
  182. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +0 -8
  183. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +10 -20
  184. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +12 -4
  185. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +29 -9
  186. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +24 -6
  187. package/src/renderers/webgpu/utils/WebGPUUtils.js +0 -1
  188. package/src/renderers/webxr/WebXRManager.js +4 -4
  189. package/examples/jsm/cameras/CinematicCamera.js +0 -208
  190. package/src/nodes/display/FXAANode.js +0 -332
  191. package/src/nodes/utils/OscNode.js +0 -85
  192. package/src/nodes/utils/TimerNode.js +0 -97
  193. package/src/renderers/webvr/WebVRManager.js +0 -495
  194. package/src/renderers/webvr/WebVRUtils.js +0 -66
  195. /package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +0 -0
@@ -1,332 +0,0 @@
1
- import TempNode from '../core/TempNode.js';
2
- import { uv } from '../accessors/UV.js';
3
- import { Fn, nodeObject, float, vec2, vec4, int, If } from '../tsl/TSLBase.js';
4
- import { NodeUpdateType } from '../core/constants.js';
5
- import { uniform } from '../core/UniformNode.js';
6
- import { abs, max, min, mix, pow } from '../math/MathNode.js';
7
- import { sub } from '../math/OperatorNode.js';
8
- import { Loop, Break } from '../utils/LoopNode.js';
9
- import { convertToTexture } from '../utils/RTTNode.js';
10
-
11
- import { Vector2 } from '../../math/Vector2.js';
12
-
13
- class FXAANode extends TempNode {
14
-
15
- static get type() {
16
-
17
- return 'FXAANode';
18
-
19
- }
20
-
21
- constructor( textureNode ) {
22
-
23
- super();
24
-
25
- this.textureNode = textureNode;
26
-
27
- this.updateBeforeType = NodeUpdateType.RENDER;
28
-
29
- this._invSize = uniform( new Vector2() );
30
-
31
- }
32
-
33
- updateBefore() {
34
-
35
- const map = this.textureNode.value;
36
-
37
- this._invSize.value.set( 1 / map.image.width, 1 / map.image.height );
38
-
39
- }
40
-
41
- setup() {
42
-
43
- const textureNode = this.textureNode.bias( - 100 );
44
- const uvNode = textureNode.uvNode || uv();
45
-
46
- // FXAA 3.11 implementation by NVIDIA, ported to WebGL by Agost Biro (biro@archilogic.com)
47
-
48
- //----------------------------------------------------------------------------------
49
- // File: es3-kepler\FXAA\assets\shaders/FXAA_DefaultES.frag
50
- // SDK Version: v3.00
51
- // Email: gameworks@nvidia.com
52
- // Site: http://developer.nvidia.com/
53
- //
54
- // Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved.
55
- //
56
- // Redistribution and use in source and binary forms, with or without
57
- // modification, are permitted provided that the following conditions
58
- // are met:
59
- // * Redistributions of source code must retain the above copyright
60
- // notice, this list of conditions and the following disclaimer.
61
- // * Redistributions in binary form must reproduce the above copyright
62
- // notice, this list of conditions and the following disclaimer in the
63
- // documentation and/or other materials provided with the distribution.
64
- // * Neither the name of NVIDIA CORPORATION nor the names of its
65
- // contributors may be used to endorse or promote products derived
66
- // from this software without specific prior written permission.
67
- //
68
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
69
- // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
70
- // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
71
- // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
72
- // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
73
- // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
74
- // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
75
- // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
76
- // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
77
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
78
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
79
- //
80
- //----------------------------------------------------------------------------------
81
-
82
- const FxaaTexTop = ( p ) => textureNode.uv( p );
83
- const FxaaTexOff = ( p, o, r ) => textureNode.uv( p.add( o.mul( r ) ) );
84
-
85
- const NUM_SAMPLES = int( 5 );
86
-
87
- const contrast = Fn( ( [ a_immutable, b_immutable ] ) => {
88
-
89
- // assumes colors have premultipliedAlpha, so that the calculated color contrast is scaled by alpha
90
-
91
- const b = vec4( b_immutable ).toVar();
92
- const a = vec4( a_immutable ).toVar();
93
- const diff = vec4( abs( a.sub( b ) ) ).toVar();
94
-
95
- return max( max( max( diff.r, diff.g ), diff.b ), diff.a );
96
-
97
- } );
98
-
99
- // FXAA3 QUALITY - PC
100
-
101
- const FxaaPixelShader = Fn( ( [ uv, fxaaQualityRcpFrame, fxaaQualityEdgeThreshold, fxaaQualityinvEdgeThreshold ] ) => {
102
-
103
- const rgbaM = FxaaTexTop( uv ).toVar();
104
- const rgbaS = FxaaTexOff( uv, vec2( 0.0, - 1.0 ), fxaaQualityRcpFrame.xy ).toVar();
105
- const rgbaE = FxaaTexOff( uv, vec2( 1.0, 0.0 ), fxaaQualityRcpFrame.xy ).toVar();
106
- const rgbaN = FxaaTexOff( uv, vec2( 0.0, 1.0 ), fxaaQualityRcpFrame.xy ).toVar();
107
- const rgbaW = FxaaTexOff( uv, vec2( - 1.0, 0.0 ), fxaaQualityRcpFrame.xy ).toVar();
108
- // . S .
109
- // W M E
110
- // . N .
111
-
112
- const contrastN = contrast( rgbaM, rgbaN ).toVar();
113
- const contrastS = contrast( rgbaM, rgbaS ).toVar();
114
- const contrastE = contrast( rgbaM, rgbaE ).toVar();
115
- const contrastW = contrast( rgbaM, rgbaW ).toVar();
116
-
117
- const maxValue = max( contrastN, max( contrastS, max( contrastE, contrastW ) ) ).toVar();
118
-
119
- // . 0 .
120
- // 0 0 0
121
- // . 0 .
122
-
123
- If( maxValue.lessThan( fxaaQualityEdgeThreshold ), () => {
124
-
125
- return rgbaM; // assuming define FXAA_DISCARD is always 0
126
-
127
- } );
128
-
129
- //
130
-
131
- const relativeVContrast = sub( contrastN.add( contrastS ), ( contrastE.add( contrastW ) ) ).toVar();
132
- relativeVContrast.mulAssign( fxaaQualityinvEdgeThreshold );
133
-
134
- // 45 deg edge detection and corners of objects, aka V/H contrast is too similar
135
-
136
- If( abs( relativeVContrast ).lessThan( 0.3 ), () => {
137
-
138
- // locate the edge
139
-
140
- const x = contrastE.greaterThan( contrastW ).select( 1, - 1 ).toVar();
141
- const y = contrastS.greaterThan( contrastN ).select( 1, - 1 ).toVar();
142
-
143
- const dirToEdge = vec2( x, y ).toVar();
144
- // . 2 . . 1 .
145
- // 1 0 2 ~= 0 0 1
146
- // . 1 . . 0 .
147
-
148
- // tap 2 pixels and see which ones are "outside" the edge, to
149
- // determine if the edge is vertical or horizontal
150
-
151
- const rgbaAlongH = FxaaTexOff( uv, vec2( dirToEdge.x, dirToEdge.y ), fxaaQualityRcpFrame.xy );
152
- const matchAlongH = contrast( rgbaM, rgbaAlongH ).toVar();
153
- // . 1 .
154
- // 0 0 1
155
- // . 0 H
156
-
157
- const rgbaAlongV = FxaaTexOff( uv, vec2( dirToEdge.x.negate(), dirToEdge.y.negate() ), fxaaQualityRcpFrame.xy );
158
- const matchAlongV = contrast( rgbaM, rgbaAlongV ).toVar();
159
- // V 1 .
160
- // 0 0 1
161
- // . 0 .
162
-
163
- relativeVContrast.assign( matchAlongV.sub( matchAlongH ) );
164
- relativeVContrast.mulAssign( fxaaQualityinvEdgeThreshold );
165
-
166
- If( abs( relativeVContrast ).lessThan( 0.3 ), () => { // 45 deg edge
167
-
168
- // 1 1 .
169
- // 0 0 1
170
- // . 0 1
171
-
172
- // do a simple blur
173
- const sum = rgbaN.add( rgbaS ).add( rgbaE ).add( rgbaW );
174
- return mix( rgbaM, sum.mul( 0.25 ), 0.4 );
175
-
176
- } );
177
-
178
- } );
179
-
180
- const offNP = vec2().toVar();
181
-
182
- If( relativeVContrast.lessThanEqual( 0 ), () => {
183
-
184
- rgbaN.assign( rgbaW );
185
- rgbaS.assign( rgbaE );
186
-
187
- // . 0 . 1
188
- // 1 0 1 -> 0
189
- // . 0 . 1
190
-
191
- offNP.x.assign( 0 );
192
- offNP.y.assign( fxaaQualityRcpFrame.y );
193
-
194
- } ).Else( () => {
195
-
196
- offNP.x.assign( fxaaQualityRcpFrame.x );
197
- offNP.y.assign( 0 );
198
-
199
- } );
200
-
201
- const mn = contrast( rgbaM, rgbaN ).toVar();
202
- const ms = contrast( rgbaM, rgbaS ).toVar();
203
-
204
- If( mn.lessThanEqual( ms ), () => {
205
-
206
- rgbaN.assign( rgbaS );
207
-
208
- } );
209
-
210
- const doneN = int( 0 ).toVar();
211
- const doneP = int( 0 ).toVar();
212
-
213
- const nDist = float( 0 ).toVar();
214
- const pDist = float( 0 ).toVar();
215
-
216
- const posN = vec2( uv ).toVar();
217
- const posP = vec2( uv ).toVar();
218
-
219
- const iterationsUsedN = int( 0 ).toVar();
220
- const iterationsUsedP = int( 0 ).toVar();
221
-
222
- Loop( NUM_SAMPLES, ( { i } ) => {
223
-
224
- const increment = i.add( 1 ).toVar();
225
-
226
- If( doneN.equal( 0 ), () => {
227
-
228
- nDist.addAssign( increment );
229
- posN.assign( uv.add( offNP.mul( nDist ) ) );
230
- const rgbaEndN = FxaaTexTop( posN.xy );
231
-
232
- const nm = contrast( rgbaEndN, rgbaM ).toVar();
233
- const nn = contrast( rgbaEndN, rgbaN ).toVar();
234
-
235
- If( nm.greaterThan( nn ), () => {
236
-
237
- doneN.assign( 1 );
238
-
239
- } );
240
-
241
- iterationsUsedN.assign( i );
242
-
243
- } );
244
-
245
- If( doneP.equal( 0 ), () => {
246
-
247
- pDist.addAssign( increment );
248
- posP.assign( uv.sub( offNP.mul( pDist ) ) );
249
- const rgbaEndP = FxaaTexTop( posP.xy );
250
-
251
- const pm = contrast( rgbaEndP, rgbaM ).toVar();
252
- const pn = contrast( rgbaEndP, rgbaN ).toVar();
253
-
254
- If( pm.greaterThan( pn ), () => {
255
-
256
- doneP.assign( 1 );
257
-
258
- } );
259
-
260
- iterationsUsedP.assign( i );
261
-
262
- } );
263
-
264
- If( doneN.equal( 1 ).or( doneP.equal( 1 ) ), () => {
265
-
266
- Break();
267
-
268
- } );
269
-
270
- } );
271
-
272
- If( doneN.equal( 0 ).and( doneP.equal( 0 ) ), () => {
273
-
274
- return rgbaM; // failed to find end of edge
275
-
276
- } );
277
-
278
- const distN = float( 1 ).toVar();
279
- const distP = float( 1 ).toVar();
280
-
281
- If( doneN.equal( 1 ), () => {
282
-
283
- distN.assign( float( iterationsUsedN ).div( float( NUM_SAMPLES.sub( 1 ) ) ) );
284
-
285
- } );
286
-
287
- If( doneP.equal( 1 ), () => {
288
-
289
- distP.assign( float( iterationsUsedP ).div( float( NUM_SAMPLES.sub( 1 ) ) ) );
290
-
291
- } );
292
-
293
- const dist = min( distN, distP );
294
-
295
- // hacky way of reduces blurriness of mostly diagonal edges
296
- // but reduces AA quality
297
- dist.assign( pow( dist, 0.5 ) );
298
- dist.assign( float( 1 ).sub( dist ) );
299
-
300
- return mix( rgbaM, rgbaN, dist.mul( 0.5 ) );
301
-
302
- } ).setLayout( {
303
- name: 'FxaaPixelShader',
304
- type: 'vec4',
305
- inputs: [
306
- { name: 'uv', type: 'vec2' },
307
- { name: 'fxaaQualityRcpFrame', type: 'vec2' },
308
- { name: 'fxaaQualityEdgeThreshold', type: 'float' },
309
- { name: 'fxaaQualityinvEdgeThreshold', type: 'float' },
310
- ]
311
- } );
312
-
313
- const fxaa = Fn( () => {
314
-
315
- const edgeDetectionQuality = float( 0.2 );
316
- const invEdgeDetectionQuality = float( 1 ).div( edgeDetectionQuality );
317
-
318
- return FxaaPixelShader( uvNode, this._invSize, edgeDetectionQuality, invEdgeDetectionQuality );
319
-
320
- } );
321
-
322
- const outputNode = fxaa();
323
-
324
- return outputNode;
325
-
326
- }
327
-
328
- }
329
-
330
- export default FXAANode;
331
-
332
- export const fxaa = ( node ) => nodeObject( new FXAANode( convertToTexture( node ) ) );
@@ -1,85 +0,0 @@
1
- import Node from '../core/Node.js';
2
- import { timerLocal } from './TimerNode.js';
3
- import { nodeObject, nodeProxy } from '../tsl/TSLBase.js';
4
-
5
- class OscNode extends Node {
6
-
7
- static get type() {
8
-
9
- return 'OscNode';
10
-
11
- }
12
-
13
- constructor( method = OscNode.SINE, timeNode = timerLocal() ) {
14
-
15
- super();
16
-
17
- this.method = method;
18
- this.timeNode = timeNode;
19
-
20
- }
21
-
22
- getNodeType( builder ) {
23
-
24
- return this.timeNode.getNodeType( builder );
25
-
26
- }
27
-
28
- setup() {
29
-
30
- const method = this.method;
31
- const timeNode = nodeObject( this.timeNode );
32
-
33
- let outputNode = null;
34
-
35
- if ( method === OscNode.SINE ) {
36
-
37
- outputNode = timeNode.add( 0.75 ).mul( Math.PI * 2 ).sin().mul( 0.5 ).add( 0.5 );
38
-
39
- } else if ( method === OscNode.SQUARE ) {
40
-
41
- outputNode = timeNode.fract().round();
42
-
43
- } else if ( method === OscNode.TRIANGLE ) {
44
-
45
- outputNode = timeNode.add( 0.5 ).fract().mul( 2 ).sub( 1 ).abs();
46
-
47
- } else if ( method === OscNode.SAWTOOTH ) {
48
-
49
- outputNode = timeNode.fract();
50
-
51
- }
52
-
53
- return outputNode;
54
-
55
- }
56
-
57
- serialize( data ) {
58
-
59
- super.serialize( data );
60
-
61
- data.method = this.method;
62
-
63
- }
64
-
65
- deserialize( data ) {
66
-
67
- super.deserialize( data );
68
-
69
- this.method = data.method;
70
-
71
- }
72
-
73
- }
74
-
75
- OscNode.SINE = 'sine';
76
- OscNode.SQUARE = 'square';
77
- OscNode.TRIANGLE = 'triangle';
78
- OscNode.SAWTOOTH = 'sawtooth';
79
-
80
- export default OscNode;
81
-
82
- export const oscSine = /*@__PURE__*/ nodeProxy( OscNode, OscNode.SINE );
83
- export const oscSquare = /*@__PURE__*/ nodeProxy( OscNode, OscNode.SQUARE );
84
- export const oscTriangle = /*@__PURE__*/ nodeProxy( OscNode, OscNode.TRIANGLE );
85
- export const oscSawtooth = /*@__PURE__*/ nodeProxy( OscNode, OscNode.SAWTOOTH );
@@ -1,97 +0,0 @@
1
- import UniformNode from '../core/UniformNode.js';
2
- import { NodeUpdateType } from '../core/constants.js';
3
- import { nodeObject, nodeImmutable } from '../tsl/TSLBase.js';
4
-
5
- class TimerNode extends UniformNode {
6
-
7
- static get type() {
8
-
9
- return 'TimerNode';
10
-
11
- }
12
-
13
- constructor( scope = TimerNode.LOCAL, scale = 1, value = 0 ) {
14
-
15
- super( value );
16
-
17
- this.scope = scope;
18
- this.scale = scale;
19
-
20
- this.updateType = NodeUpdateType.FRAME;
21
-
22
- }
23
- /*
24
- @TODO:
25
- getNodeType( builder ) {
26
-
27
- const scope = this.scope;
28
-
29
- if ( scope === TimerNode.FRAME ) {
30
-
31
- return 'uint';
32
-
33
- }
34
-
35
- return 'float';
36
-
37
- }
38
- */
39
- update( frame ) {
40
-
41
- const scope = this.scope;
42
- const scale = this.scale;
43
-
44
- if ( scope === TimerNode.LOCAL ) {
45
-
46
- this.value += frame.deltaTime * scale;
47
-
48
- } else if ( scope === TimerNode.DELTA ) {
49
-
50
- this.value = frame.deltaTime * scale;
51
-
52
- } else if ( scope === TimerNode.FRAME ) {
53
-
54
- this.value = frame.frameId;
55
-
56
- } else {
57
-
58
- // global
59
-
60
- this.value = frame.time * scale;
61
-
62
- }
63
-
64
- }
65
-
66
- serialize( data ) {
67
-
68
- super.serialize( data );
69
-
70
- data.scope = this.scope;
71
- data.scale = this.scale;
72
-
73
- }
74
-
75
- deserialize( data ) {
76
-
77
- super.deserialize( data );
78
-
79
- this.scope = data.scope;
80
- this.scale = data.scale;
81
-
82
- }
83
-
84
- }
85
-
86
- TimerNode.LOCAL = 'local';
87
- TimerNode.GLOBAL = 'global';
88
- TimerNode.DELTA = 'delta';
89
- TimerNode.FRAME = 'frame';
90
-
91
- export default TimerNode;
92
-
93
- // @TODO: add support to use node in timeScale
94
- export const timerLocal = ( timeScale, value = 0 ) => nodeObject( new TimerNode( TimerNode.LOCAL, timeScale, value ) );
95
- export const timerGlobal = ( timeScale, value = 0 ) => nodeObject( new TimerNode( TimerNode.GLOBAL, timeScale, value ) );
96
- export const timerDelta = ( timeScale, value = 0 ) => nodeObject( new TimerNode( TimerNode.DELTA, timeScale, value ) );
97
- export const frameId = /*@__PURE__*/ nodeImmutable( TimerNode, TimerNode.FRAME ).toUint();