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
@@ -32,9 +32,12 @@ class CSS3DObject extends Object3D {
32
32
 
33
33
  this.traverse( function ( object ) {
34
34
 
35
- if ( object.element instanceof Element && object.element.parentNode !== null ) {
35
+ if (
36
+ object.element instanceof object.element.ownerDocument.defaultView.Element &&
37
+ object.element.parentNode !== null
38
+ ) {
36
39
 
37
- object.element.parentNode.removeChild( object.element );
40
+ object.element.remove();
38
41
 
39
42
  }
40
43
 
@@ -254,10 +257,10 @@ class CSS3DRenderer {
254
257
  function hideObject( object ) {
255
258
 
256
259
  if ( object.isCSS3DObject ) object.element.style.display = 'none';
257
-
260
+
258
261
  for ( let i = 0, l = object.children.length; i < l; i ++ ) {
259
262
 
260
- hideObject( object.children[ i ] );
263
+ hideObject( object.children[ i ] );
261
264
 
262
265
  }
263
266
 
@@ -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
 
@@ -242,9 +242,9 @@ export class DynamicElement {
242
242
 
243
243
  export class AccessorElements {
244
244
 
245
- constructor( property, elements = [] ) {
245
+ constructor( object, elements = [] ) {
246
246
 
247
- this.property = property;
247
+ this.object = object;
248
248
  this.elements = elements;
249
249
 
250
250
  this.isAccessorElements = true;
@@ -30,6 +30,10 @@ const associativityRightToLeft = [
30
30
  ':'
31
31
  ];
32
32
 
33
+ const glslToTSL = {
34
+ inversesqrt: 'inverseSqrt'
35
+ };
36
+
33
37
  const spaceRegExp = /^((\t| )\n*)+/;
34
38
  const lineRegExp = /^\n+/;
35
39
  const commentRegExp = /^\/\*[\s\S]*?\*\//;
@@ -46,6 +50,12 @@ const operatorsRegExp = new RegExp( '^(\\' + [
46
50
  '.', ',', ';', '!', '=', '~', '*', '/', '%', '+', '-', '<', '>', '&', '^', '|', '?', ':', '#'
47
51
  ].join( '$' ).split( '' ).join( '\\' ).replace( /\\\$/g, '|' ) + ')' );
48
52
 
53
+ function getFunctionName( str ) {
54
+
55
+ return glslToTSL[ str ] || str;
56
+
57
+ }
58
+
49
59
  function getGroupDelta( str ) {
50
60
 
51
61
  if ( str === '(' || str === '[' || str === '{' ) return 1;
@@ -485,62 +495,84 @@ class GLSLDecoder {
485
495
 
486
496
  // function call
487
497
 
488
- const paramsTokens = this.parseFunctionParametersFromTokens( tokens.slice( 2, tokens.length - 1 ) );
498
+ const internalTokens = this.getTokensUntil( ')', tokens, 1 ).slice( 1, - 1 );
499
+
500
+ const paramsTokens = this.parseFunctionParametersFromTokens( internalTokens );
501
+
502
+ const functionCall = new FunctionCall( getFunctionName( firstToken.str ), paramsTokens );
503
+
504
+ const accessTokens = tokens.slice( 3 + internalTokens.length );
489
505
 
490
- return new FunctionCall( firstToken.str, paramsTokens );
506
+ if ( accessTokens.length > 0 ) {
507
+
508
+ const elements = this.parseAccessorElementsFromTokens( accessTokens );
509
+
510
+ return new AccessorElements( functionCall, elements );
511
+
512
+ }
513
+
514
+ return functionCall;
491
515
 
492
516
  } else if ( secondToken.str === '[' ) {
493
517
 
494
518
  // array accessor
495
519
 
496
- const elements = [];
520
+ const elements = this.parseAccessorElementsFromTokens( tokens.slice( 1 ) );
497
521
 
498
- let currentTokens = tokens.slice( 1 );
522
+ return new AccessorElements( new Accessor( firstToken.str ), elements );
499
523
 
500
- while ( currentTokens.length > 0 ) {
524
+ }
501
525
 
502
- const token = currentTokens[ 0 ];
526
+ }
503
527
 
504
- if ( token.str === '[' ) {
528
+ return new Accessor( firstToken.str );
505
529
 
506
- const accessorTokens = this.getTokensUntil( ']', currentTokens );
530
+ }
507
531
 
508
- const element = this.parseExpressionFromTokens( accessorTokens.slice( 1, accessorTokens.length - 1 ) );
532
+ }
509
533
 
510
- currentTokens = currentTokens.slice( accessorTokens.length );
534
+ parseAccessorElementsFromTokens( tokens ) {
511
535
 
512
- elements.push( new DynamicElement( element ) );
536
+ const elements = [];
513
537
 
514
- } else if ( token.str === '.' ) {
538
+ let currentTokens = tokens;
515
539
 
516
- const accessorTokens = currentTokens.slice( 1, 2 );
540
+ while ( currentTokens.length > 0 ) {
517
541
 
518
- const element = this.parseExpressionFromTokens( accessorTokens );
542
+ const token = currentTokens[ 0 ];
519
543
 
520
- currentTokens = currentTokens.slice( 2 );
544
+ if ( token.str === '[' ) {
521
545
 
522
- elements.push( new StaticElement( element ) );
546
+ const accessorTokens = this.getTokensUntil( ']', currentTokens );
523
547
 
524
- } else {
548
+ const element = this.parseExpressionFromTokens( accessorTokens.slice( 1, accessorTokens.length - 1 ) );
525
549
 
526
- console.error( 'Unknown accessor expression', token );
550
+ currentTokens = currentTokens.slice( accessorTokens.length );
527
551
 
528
- break;
552
+ elements.push( new DynamicElement( element ) );
529
553
 
530
- }
554
+ } else if ( token.str === '.' ) {
531
555
 
532
- }
556
+ const accessorTokens = currentTokens.slice( 1, 2 );
533
557
 
534
- return new AccessorElements( firstToken.str, elements );
558
+ const element = this.parseExpressionFromTokens( accessorTokens );
535
559
 
536
- }
560
+ currentTokens = currentTokens.slice( 2 );
537
561
 
538
- }
562
+ elements.push( new StaticElement( element ) );
539
563
 
540
- return new Accessor( firstToken.str );
564
+ } else {
565
+
566
+ console.error( 'Unknown accessor expression', token );
567
+
568
+ break;
569
+
570
+ }
541
571
 
542
572
  }
543
573
 
574
+ return elements;
575
+
544
576
  }
545
577
 
546
578
  parseFunctionParametersFromTokens( tokens ) {