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
@@ -2,14 +2,6 @@ import {
2
2
  Vector2
3
3
  } from 'three';
4
4
 
5
- /**
6
- * NVIDIA FXAA by Timothy Lottes
7
- * https://developer.download.nvidia.com/assets/gamedev/files/sdk/11/FXAA_WhitePaper.pdf
8
- * - WebGL port by @supereggbert
9
- * http://www.glge.org/demos/fxaa/
10
- * Further improved by Daniel Sturk
11
- */
12
-
13
5
  const FXAAShader = {
14
6
 
15
7
  name: 'FXAAShader',
@@ -33,253 +25,262 @@ const FXAAShader = {
33
25
  }`,
34
26
 
35
27
  fragmentShader: /* glsl */`
36
- precision highp float;
37
28
 
38
- uniform sampler2D tDiffuse;
29
+ // FXAA algorithm from NVIDIA, C# implementation by Jasper Flick, GLSL port by Dave Hoskins
30
+ // http://developer.download.nvidia.com/assets/gamedev/files/sdk/11/FXAA_WhitePaper.pdf
31
+ // https://catlikecoding.com/unity/tutorials/advanced-rendering/fxaa/
39
32
 
33
+ uniform sampler2D tDiffuse;
40
34
  uniform vec2 resolution;
41
-
42
35
  varying vec2 vUv;
43
36
 
44
- // FXAA 3.11 implementation by NVIDIA, ported to WebGL by Agost Biro (biro@archilogic.com)
45
-
46
- //----------------------------------------------------------------------------------
47
- // File: es3-kepler\FXAA\assets\shaders/FXAA_DefaultES.frag
48
- // SDK Version: v3.00
49
- // Email: gameworks@nvidia.com
50
- // Site: http://developer.nvidia.com/
51
- //
52
- // Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved.
53
- //
54
- // Redistribution and use in source and binary forms, with or without
55
- // modification, are permitted provided that the following conditions
56
- // are met:
57
- // * Redistributions of source code must retain the above copyright
58
- // notice, this list of conditions and the following disclaimer.
59
- // * Redistributions in binary form must reproduce the above copyright
60
- // notice, this list of conditions and the following disclaimer in the
61
- // documentation and/or other materials provided with the distribution.
62
- // * Neither the name of NVIDIA CORPORATION nor the names of its
63
- // contributors may be used to endorse or promote products derived
64
- // from this software without specific prior written permission.
65
- //
66
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
67
- // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
68
- // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
69
- // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
70
- // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
71
- // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
72
- // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
73
- // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
74
- // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
75
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
76
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
77
- //
78
- //----------------------------------------------------------------------------------
79
-
80
- #ifndef FXAA_DISCARD
81
- //
82
- // Only valid for PC OpenGL currently.
83
- // Probably will not work when FXAA_GREEN_AS_LUMA = 1.
84
- //
85
- // 1 = Use discard on pixels which don't need AA.
86
- // For APIs which enable concurrent TEX+ROP from same surface.
87
- // 0 = Return unchanged color on pixels which don't need AA.
88
- //
89
- #define FXAA_DISCARD 0
90
- #endif
91
-
92
- /*--------------------------------------------------------------------------*/
93
- #define FxaaTexTop(t, p) texture2D(t, p, -100.0)
94
- #define FxaaTexOff(t, p, o, r) texture2D(t, p + (o * r), -100.0)
95
- /*--------------------------------------------------------------------------*/
96
-
97
- #define NUM_SAMPLES 5
98
-
99
- // assumes colors have premultipliedAlpha, so that the calculated color contrast is scaled by alpha
100
- float contrast( vec4 a, vec4 b ) {
101
- vec4 diff = abs( a - b );
102
- return max( max( max( diff.r, diff.g ), diff.b ), diff.a );
37
+ #define EDGE_STEP_COUNT 6
38
+ #define EDGE_GUESS 8.0
39
+ #define EDGE_STEPS 1.0, 1.5, 2.0, 2.0, 2.0, 4.0
40
+ const float edgeSteps[EDGE_STEP_COUNT] = float[EDGE_STEP_COUNT]( EDGE_STEPS );
41
+
42
+ float _ContrastThreshold = 0.0312;
43
+ float _RelativeThreshold = 0.063;
44
+ float _SubpixelBlending = 1.0;
45
+
46
+ vec4 Sample( sampler2D tex2D, vec2 uv ) {
47
+
48
+ return texture( tex2D, uv );
49
+
50
+ }
51
+
52
+ float SampleLuminance( sampler2D tex2D, vec2 uv ) {
53
+
54
+ return dot( Sample( tex2D, uv ).rgb, vec3( 0.3, 0.59, 0.11 ) );
55
+
56
+ }
57
+
58
+ float SampleLuminance( sampler2D tex2D, vec2 texSize, vec2 uv, float uOffset, float vOffset ) {
59
+
60
+ uv += texSize * vec2(uOffset, vOffset);
61
+ return SampleLuminance(tex2D, uv);
62
+
63
+ }
64
+
65
+ struct LuminanceData {
66
+
67
+ float m, n, e, s, w;
68
+ float ne, nw, se, sw;
69
+ float highest, lowest, contrast;
70
+
71
+ };
72
+
73
+ LuminanceData SampleLuminanceNeighborhood( sampler2D tex2D, vec2 texSize, vec2 uv ) {
74
+
75
+ LuminanceData l;
76
+ l.m = SampleLuminance( tex2D, uv );
77
+ l.n = SampleLuminance( tex2D, texSize, uv, 0.0, 1.0 );
78
+ l.e = SampleLuminance( tex2D, texSize, uv, 1.0, 0.0 );
79
+ l.s = SampleLuminance( tex2D, texSize, uv, 0.0, -1.0 );
80
+ l.w = SampleLuminance( tex2D, texSize, uv, -1.0, 0.0 );
81
+
82
+ l.ne = SampleLuminance( tex2D, texSize, uv, 1.0, 1.0 );
83
+ l.nw = SampleLuminance( tex2D, texSize, uv, -1.0, 1.0 );
84
+ l.se = SampleLuminance( tex2D, texSize, uv, 1.0, -1.0 );
85
+ l.sw = SampleLuminance( tex2D, texSize, uv, -1.0, -1.0 );
86
+
87
+ l.highest = max( max( max( max( l.n, l.e ), l.s ), l.w ), l.m );
88
+ l.lowest = min( min( min( min( l.n, l.e ), l.s ), l.w ), l.m );
89
+ l.contrast = l.highest - l.lowest;
90
+ return l;
91
+
92
+ }
93
+
94
+ bool ShouldSkipPixel( LuminanceData l ) {
95
+
96
+ float threshold = max( _ContrastThreshold, _RelativeThreshold * l.highest );
97
+ return l.contrast < threshold;
98
+
99
+ }
100
+
101
+ float DeterminePixelBlendFactor( LuminanceData l ) {
102
+
103
+ float f = 2.0 * ( l.n + l.e + l.s + l.w );
104
+ f += l.ne + l.nw + l.se + l.sw;
105
+ f *= 1.0 / 12.0;
106
+ f = abs( f - l.m );
107
+ f = clamp( f / l.contrast, 0.0, 1.0 );
108
+
109
+ float blendFactor = smoothstep( 0.0, 1.0, f );
110
+ return blendFactor * blendFactor * _SubpixelBlending;
111
+
103
112
  }
104
113
 
105
- /*============================================================================
106
-
107
- FXAA3 QUALITY - PC
108
-
109
- ============================================================================*/
110
-
111
- /*--------------------------------------------------------------------------*/
112
- vec4 FxaaPixelShader(
113
- vec2 posM,
114
- sampler2D tex,
115
- vec2 fxaaQualityRcpFrame,
116
- float fxaaQualityEdgeThreshold,
117
- float fxaaQualityinvEdgeThreshold
118
- ) {
119
- vec4 rgbaM = FxaaTexTop(tex, posM);
120
- vec4 rgbaS = FxaaTexOff(tex, posM, vec2( 0.0, 1.0), fxaaQualityRcpFrame.xy);
121
- vec4 rgbaE = FxaaTexOff(tex, posM, vec2( 1.0, 0.0), fxaaQualityRcpFrame.xy);
122
- vec4 rgbaN = FxaaTexOff(tex, posM, vec2( 0.0,-1.0), fxaaQualityRcpFrame.xy);
123
- vec4 rgbaW = FxaaTexOff(tex, posM, vec2(-1.0, 0.0), fxaaQualityRcpFrame.xy);
124
- // . S .
125
- // W M E
126
- // . N .
127
-
128
- bool earlyExit = max( max( max(
129
- contrast( rgbaM, rgbaN ),
130
- contrast( rgbaM, rgbaS ) ),
131
- contrast( rgbaM, rgbaE ) ),
132
- contrast( rgbaM, rgbaW ) )
133
- < fxaaQualityEdgeThreshold;
134
- // . 0 .
135
- // 0 0 0
136
- // . 0 .
137
-
138
- #if (FXAA_DISCARD == 1)
139
- if(earlyExit) FxaaDiscard;
140
- #else
141
- if(earlyExit) return rgbaM;
142
- #endif
143
-
144
- float contrastN = contrast( rgbaM, rgbaN );
145
- float contrastS = contrast( rgbaM, rgbaS );
146
- float contrastE = contrast( rgbaM, rgbaE );
147
- float contrastW = contrast( rgbaM, rgbaW );
148
-
149
- float relativeVContrast = ( contrastN + contrastS ) - ( contrastE + contrastW );
150
- relativeVContrast *= fxaaQualityinvEdgeThreshold;
151
-
152
- bool horzSpan = relativeVContrast > 0.;
153
- // . 1 .
154
- // 0 0 0
155
- // . 1 .
156
-
157
- // 45 deg edge detection and corners of objects, aka V/H contrast is too similar
158
- if( abs( relativeVContrast ) < .3 ) {
159
- // locate the edge
160
- vec2 dirToEdge;
161
- dirToEdge.x = contrastE > contrastW ? 1. : -1.;
162
- dirToEdge.y = contrastS > contrastN ? 1. : -1.;
163
- // . 2 . . 1 .
164
- // 1 0 2 ~= 0 0 1
165
- // . 1 . . 0 .
166
-
167
- // tap 2 pixels and see which ones are "outside" the edge, to
168
- // determine if the edge is vertical or horizontal
169
-
170
- vec4 rgbaAlongH = FxaaTexOff(tex, posM, vec2( dirToEdge.x, -dirToEdge.y ), fxaaQualityRcpFrame.xy);
171
- float matchAlongH = contrast( rgbaM, rgbaAlongH );
172
- // . 1 .
173
- // 0 0 1
174
- // . 0 H
175
-
176
- vec4 rgbaAlongV = FxaaTexOff(tex, posM, vec2( -dirToEdge.x, dirToEdge.y ), fxaaQualityRcpFrame.xy);
177
- float matchAlongV = contrast( rgbaM, rgbaAlongV );
178
- // V 1 .
179
- // 0 0 1
180
- // . 0 .
181
-
182
- relativeVContrast = matchAlongV - matchAlongH;
183
- relativeVContrast *= fxaaQualityinvEdgeThreshold;
184
-
185
- if( abs( relativeVContrast ) < .3 ) { // 45 deg edge
186
- // 1 1 .
187
- // 0 0 1
188
- // . 0 1
189
-
190
- // do a simple blur
191
- return mix(
192
- rgbaM,
193
- (rgbaN + rgbaS + rgbaE + rgbaW) * .25,
194
- .4
195
- );
196
- }
197
-
198
- horzSpan = relativeVContrast > 0.;
114
+ struct EdgeData {
115
+
116
+ bool isHorizontal;
117
+ float pixelStep;
118
+ float oppositeLuminance, gradient;
119
+
120
+ };
121
+
122
+ EdgeData DetermineEdge( vec2 texSize, LuminanceData l ) {
123
+
124
+ EdgeData e;
125
+ float horizontal =
126
+ abs( l.n + l.s - 2.0 * l.m ) * 2.0 +
127
+ abs( l.ne + l.se - 2.0 * l.e ) +
128
+ abs( l.nw + l.sw - 2.0 * l.w );
129
+ float vertical =
130
+ abs( l.e + l.w - 2.0 * l.m ) * 2.0 +
131
+ abs( l.ne + l.nw - 2.0 * l.n ) +
132
+ abs( l.se + l.sw - 2.0 * l.s );
133
+ e.isHorizontal = horizontal >= vertical;
134
+
135
+ float pLuminance = e.isHorizontal ? l.n : l.e;
136
+ float nLuminance = e.isHorizontal ? l.s : l.w;
137
+ float pGradient = abs( pLuminance - l.m );
138
+ float nGradient = abs( nLuminance - l.m );
139
+
140
+ e.pixelStep = e.isHorizontal ? texSize.y : texSize.x;
141
+
142
+ if (pGradient < nGradient) {
143
+
144
+ e.pixelStep = -e.pixelStep;
145
+ e.oppositeLuminance = nLuminance;
146
+ e.gradient = nGradient;
147
+
148
+ } else {
149
+
150
+ e.oppositeLuminance = pLuminance;
151
+ e.gradient = pGradient;
152
+
199
153
  }
200
154
 
201
- if(!horzSpan) rgbaN = rgbaW;
202
- if(!horzSpan) rgbaS = rgbaE;
203
- // . 0 . 1
204
- // 1 0 1 -> 0
205
- // . 0 . 1
155
+ return e;
206
156
 
207
- bool pairN = contrast( rgbaM, rgbaN ) > contrast( rgbaM, rgbaS );
208
- if(!pairN) rgbaN = rgbaS;
157
+ }
158
+
159
+ float DetermineEdgeBlendFactor( sampler2D tex2D, vec2 texSize, LuminanceData l, EdgeData e, vec2 uv ) {
160
+
161
+ vec2 uvEdge = uv;
162
+ vec2 edgeStep;
163
+ if (e.isHorizontal) {
164
+
165
+ uvEdge.y += e.pixelStep * 0.5;
166
+ edgeStep = vec2( texSize.x, 0.0 );
167
+
168
+ } else {
169
+
170
+ uvEdge.x += e.pixelStep * 0.5;
171
+ edgeStep = vec2( 0.0, texSize.y );
172
+
173
+ }
174
+
175
+ float edgeLuminance = ( l.m + e.oppositeLuminance ) * 0.5;
176
+ float gradientThreshold = e.gradient * 0.25;
177
+
178
+ vec2 puv = uvEdge + edgeStep * edgeSteps[0];
179
+ float pLuminanceDelta = SampleLuminance( tex2D, puv ) - edgeLuminance;
180
+ bool pAtEnd = abs( pLuminanceDelta ) >= gradientThreshold;
181
+
182
+ for ( int i = 1; i < EDGE_STEP_COUNT && !pAtEnd; i++ ) {
209
183
 
210
- vec2 offNP;
211
- offNP.x = (!horzSpan) ? 0.0 : fxaaQualityRcpFrame.x;
212
- offNP.y = ( horzSpan) ? 0.0 : fxaaQualityRcpFrame.y;
184
+ puv += edgeStep * edgeSteps[i];
185
+ pLuminanceDelta = SampleLuminance( tex2D, puv ) - edgeLuminance;
186
+ pAtEnd = abs( pLuminanceDelta ) >= gradientThreshold;
213
187
 
214
- bool doneN = false;
215
- bool doneP = false;
188
+ }
216
189
 
217
- float nDist = 0.;
218
- float pDist = 0.;
190
+ if ( !pAtEnd ) {
219
191
 
220
- vec2 posN = posM;
221
- vec2 posP = posM;
192
+ puv += edgeStep * EDGE_GUESS;
222
193
 
223
- int iterationsUsedN = 0;
224
- int iterationsUsedP = 0;
225
- for( int i = 0; i < NUM_SAMPLES; i++ ) {
194
+ }
226
195
 
227
- float increment = float(i + 1);
196
+ vec2 nuv = uvEdge - edgeStep * edgeSteps[0];
197
+ float nLuminanceDelta = SampleLuminance( tex2D, nuv ) - edgeLuminance;
198
+ bool nAtEnd = abs( nLuminanceDelta ) >= gradientThreshold;
228
199
 
229
- if(!doneN) {
230
- nDist += increment;
231
- posN = posM + offNP * nDist;
232
- vec4 rgbaEndN = FxaaTexTop(tex, posN.xy);
233
- doneN = contrast( rgbaEndN, rgbaM ) > contrast( rgbaEndN, rgbaN );
234
- iterationsUsedN = i;
235
- }
200
+ for ( int i = 1; i < EDGE_STEP_COUNT && !nAtEnd; i++ ) {
236
201
 
237
- if(!doneP) {
238
- pDist += increment;
239
- posP = posM - offNP * pDist;
240
- vec4 rgbaEndP = FxaaTexTop(tex, posP.xy);
241
- doneP = contrast( rgbaEndP, rgbaM ) > contrast( rgbaEndP, rgbaN );
242
- iterationsUsedP = i;
243
- }
202
+ nuv -= edgeStep * edgeSteps[i];
203
+ nLuminanceDelta = SampleLuminance( tex2D, nuv ) - edgeLuminance;
204
+ nAtEnd = abs( nLuminanceDelta ) >= gradientThreshold;
244
205
 
245
- if(doneN || doneP) break;
246
206
  }
247
207
 
208
+ if ( !nAtEnd ) {
209
+
210
+ nuv -= edgeStep * EDGE_GUESS;
248
211
 
249
- if ( !doneP && !doneN ) return rgbaM; // failed to find end of edge
212
+ }
213
+
214
+ float pDistance, nDistance;
215
+ if ( e.isHorizontal ) {
250
216
 
251
- float dist = min(
252
- doneN ? float( iterationsUsedN ) / float( NUM_SAMPLES - 1 ) : 1.,
253
- doneP ? float( iterationsUsedP ) / float( NUM_SAMPLES - 1 ) : 1.
254
- );
217
+ pDistance = puv.x - uv.x;
218
+ nDistance = uv.x - nuv.x;
255
219
 
256
- // hacky way of reduces blurriness of mostly diagonal edges
257
- // but reduces AA quality
258
- dist = pow(dist, .5);
220
+ } else {
221
+
222
+ pDistance = puv.y - uv.y;
223
+ nDistance = uv.y - nuv.y;
259
224
 
260
- dist = 1. - dist;
225
+ }
226
+
227
+ float shortestDistance;
228
+ bool deltaSign;
229
+ if ( pDistance <= nDistance ) {
230
+
231
+ shortestDistance = pDistance;
232
+ deltaSign = pLuminanceDelta >= 0.0;
233
+
234
+ } else {
235
+
236
+ shortestDistance = nDistance;
237
+ deltaSign = nLuminanceDelta >= 0.0;
238
+
239
+ }
240
+
241
+ if ( deltaSign == ( l.m - edgeLuminance >= 0.0 ) ) {
242
+
243
+ return 0.0;
244
+
245
+ }
246
+
247
+ return 0.5 - shortestDistance / ( pDistance + nDistance );
261
248
 
262
- return mix(
263
- rgbaM,
264
- rgbaN,
265
- dist * .5
266
- );
267
249
  }
268
250
 
269
- void main() {
270
- const float edgeDetectionQuality = .2;
271
- const float invEdgeDetectionQuality = 1. / edgeDetectionQuality;
251
+ vec4 ApplyFXAA( sampler2D tex2D, vec2 texSize, vec2 uv ) {
252
+
253
+ LuminanceData luminance = SampleLuminanceNeighborhood( tex2D, texSize, uv );
254
+ if ( ShouldSkipPixel( luminance ) ) {
255
+
256
+ return Sample( tex2D, uv );
257
+
258
+ }
272
259
 
273
- gl_FragColor = FxaaPixelShader(
274
- vUv,
275
- tDiffuse,
276
- resolution,
277
- edgeDetectionQuality, // [0,1] contrast needed, otherwise early discard
278
- invEdgeDetectionQuality
279
- );
260
+ float pixelBlend = DeterminePixelBlendFactor( luminance );
261
+ EdgeData edge = DetermineEdge( texSize, luminance );
262
+ float edgeBlend = DetermineEdgeBlendFactor( tex2D, texSize, luminance, edge, uv );
263
+ float finalBlend = max( pixelBlend, edgeBlend );
264
+
265
+ if (edge.isHorizontal) {
266
+
267
+ uv.y += edge.pixelStep * finalBlend;
268
+
269
+ } else {
270
+
271
+ uv.x += edge.pixelStep * finalBlend;
272
+
273
+ }
274
+
275
+ return Sample( tex2D, uv );
280
276
 
281
277
  }
282
- `
278
+
279
+ void main() {
280
+
281
+ gl_FragColor = ApplyFXAA( tDiffuse, resolution.xy, vUv );
282
+
283
+ }`
283
284
 
284
285
  };
285
286
 
@@ -7,7 +7,7 @@ class ShaderToyDecoder extends GLSLDecoder {
7
7
 
8
8
  super();
9
9
 
10
- this.addPolyfill( 'iTime', 'float iTime = timerGlobal();' );
10
+ this.addPolyfill( 'iTime', 'float iTime = time;' );
11
11
  this.addPolyfill( 'iResolution', 'vec2 iResolution = screenSize;' );
12
12
  this.addPolyfill( 'fragCoord', 'vec3 fragCoord = vec3( screenCoordinate.x, screenSize.y - screenCoordinate.y, screenCoordinate.z );' );
13
13
 
@@ -1,22 +1,11 @@
1
- import TempNode from '../core/TempNode.js';
2
- import { nodeObject, Fn, float, vec4 } from '../tsl/TSLBase.js';
3
- import { NodeUpdateType } from '../core/constants.js';
4
- import { uv } from '../accessors/UV.js';
5
- import { texture } from '../accessors/TextureNode.js';
6
- import { passTexture } from './PassNode.js';
7
- import { uniform } from '../core/UniformNode.js';
8
- import { sign, max } from '../math/MathNode.js';
9
- import { convertToTexture } from '../utils/RTTNode.js';
10
- import QuadMesh from '../../renderers/common/QuadMesh.js';
11
- import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
12
-
13
- import { Vector2 } from '../../math/Vector2.js';
14
- import { RenderTarget } from '../../core/RenderTarget.js';
1
+ import { RenderTarget, Vector2, PostProcessingUtils } from 'three';
2
+ import { TempNode, nodeObject, Fn, float, vec4, NodeUpdateType, uv, texture, passTexture, uniform, sign, max, convertToTexture, QuadMesh, NodeMaterial } from 'three/tsl';
15
3
 
16
4
  const _size = /*@__PURE__*/ new Vector2();
17
-
18
5
  const _quadMeshComp = /*@__PURE__*/ new QuadMesh();
19
6
 
7
+ let _rendererState;
8
+
20
9
  class AfterImageNode extends TempNode {
21
10
 
22
11
  static get type() {
@@ -33,15 +22,15 @@ class AfterImageNode extends TempNode {
33
22
  this.textureNodeOld = texture();
34
23
  this.damp = uniform( damp );
35
24
 
36
- this._compRT = new RenderTarget();
25
+ this._compRT = new RenderTarget( 1, 1, { depthBuffer: false } );
37
26
  this._compRT.texture.name = 'AfterImageNode.comp';
38
27
 
39
- this._oldRT = new RenderTarget();
28
+ this._oldRT = new RenderTarget( 1, 1, { depthBuffer: false } );
40
29
  this._oldRT.texture.name = 'AfterImageNode.old';
41
30
 
42
31
  this._textureNode = passTexture( this, this._compRT.texture );
43
32
 
44
- this.updateBeforeType = NodeUpdateType.RENDER;
33
+ this.updateBeforeType = NodeUpdateType.FRAME;
45
34
 
46
35
  }
47
36
 
@@ -62,6 +51,10 @@ class AfterImageNode extends TempNode {
62
51
 
63
52
  const { renderer } = frame;
64
53
 
54
+ _rendererState = PostProcessingUtils.resetRendererState( renderer, _rendererState );
55
+
56
+ //
57
+
65
58
  const textureNode = this.textureNode;
66
59
  const map = textureNode.value;
67
60
 
@@ -74,23 +67,27 @@ class AfterImageNode extends TempNode {
74
67
 
75
68
  this.setSize( _size.x, _size.y );
76
69
 
77
- const currentRenderTarget = renderer.getRenderTarget();
78
70
  const currentTexture = textureNode.value;
79
71
 
80
72
  this.textureNodeOld.value = this._oldRT.texture;
81
73
 
82
74
  // comp
75
+
83
76
  renderer.setRenderTarget( this._compRT );
84
77
  _quadMeshComp.render( renderer );
85
78
 
86
79
  // Swap the textures
80
+
87
81
  const temp = this._oldRT;
88
82
  this._oldRT = this._compRT;
89
83
  this._compRT = temp;
90
84
 
91
- renderer.setRenderTarget( currentRenderTarget );
85
+ //
86
+
92
87
  textureNode.value = currentTexture;
93
88
 
89
+ PostProcessingUtils.restoreRendererState( renderer, _rendererState );
90
+
94
91
  }
95
92
 
96
93
  setup( builder ) {
@@ -1,10 +1,6 @@
1
- import { Fn, nodeObject, vec4 } from '../tsl/TSLBase.js';
2
- import { Matrix3 } from '../../math/Matrix3.js';
3
- import { uniform } from '../core/UniformNode.js';
4
- import { uv } from '../accessors/UV.js';
5
- import { clamp, max } from '../math/MathNode.js';
1
+ import { Matrix3 } from 'three';
2
+ import { clamp, nodeObject, Fn, vec4, uv, uniform, max, NodeMaterial } from 'three/tsl';
6
3
  import StereoCompositePassNode from './StereoCompositePassNode.js';
7
- import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
8
4
 
9
5
  class AnaglyphPassNode extends StereoCompositePassNode {
10
6
 
@@ -1,20 +1,10 @@
1
- import TempNode from '../core/TempNode.js';
2
- import { nodeObject, Fn, float, vec2, vec3 } from '../tsl/TSLBase.js';
3
- import { Loop } from '../utils/LoopNode.js';
4
- import { uniform } from '../core/UniformNode.js';
5
- import { NodeUpdateType } from '../core/constants.js';
6
- import { threshold } from './ColorAdjustment.js';
7
- import { uv } from '../accessors/UV.js';
8
- import { passTexture } from './PassNode.js';
9
- import { convertToTexture } from '../utils/RTTNode.js';
10
- import QuadMesh from '../../renderers/common/QuadMesh.js';
11
- import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
12
-
13
- import { Vector2 } from '../../math/Vector2.js';
14
- import { RenderTarget } from '../../core/RenderTarget.js';
1
+ import { RenderTarget, Vector2, PostProcessingUtils } from 'three';
2
+ import { TempNode, nodeObject, Fn, float, NodeUpdateType, uv, passTexture, uniform, convertToTexture, QuadMesh, NodeMaterial, vec2, vec3, Loop, threshold } from 'three/tsl';
15
3
 
16
4
  const _quadMesh = /*@__PURE__*/ new QuadMesh();
17
5
 
6
+ let _rendererState;
7
+
18
8
  class AnamorphicNode extends TempNode {
19
9
 
20
10
  static get type() {
@@ -34,14 +24,14 @@ class AnamorphicNode extends TempNode {
34
24
  this.samples = samples;
35
25
  this.resolution = new Vector2( 1, 1 );
36
26
 
37
- this._renderTarget = new RenderTarget();
27
+ this._renderTarget = new RenderTarget( 1, 1, { depthBuffer: false } );
38
28
  this._renderTarget.texture.name = 'anamorphic';
39
29
 
40
30
  this._invSize = uniform( new Vector2() );
41
31
 
42
32
  this._textureNode = passTexture( this, this._renderTarget.texture );
43
33
 
44
- this.updateBeforeType = NodeUpdateType.RENDER;
34
+ this.updateBeforeType = NodeUpdateType.FRAME;
45
35
 
46
36
  }
47
37
 
@@ -66,12 +56,15 @@ class AnamorphicNode extends TempNode {
66
56
 
67
57
  const { renderer } = frame;
68
58
 
59
+ _rendererState = PostProcessingUtils.resetRendererState( renderer, _rendererState );
60
+
61
+ //
62
+
69
63
  const textureNode = this.textureNode;
70
64
  const map = textureNode.value;
71
65
 
72
66
  this._renderTarget.texture.type = map.type;
73
67
 
74
- const currentRenderTarget = renderer.getRenderTarget();
75
68
  const currentTexture = textureNode.value;
76
69
 
77
70
  _quadMesh.material = this._material;
@@ -86,9 +79,10 @@ class AnamorphicNode extends TempNode {
86
79
 
87
80
  // restore
88
81
 
89
- renderer.setRenderTarget( currentRenderTarget );
90
82
  textureNode.value = currentTexture;
91
83
 
84
+ PostProcessingUtils.restoreRendererState( renderer, _rendererState );
85
+
92
86
  }
93
87
 
94
88
  setup( builder ) {