@tableslayer/ui 0.1.3 → 0.1.4

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 (205) hide show
  1. package/package.json +2 -13
  2. package/src/lib/components/Avatar/Avatar.svelte +82 -0
  3. package/src/lib/components/Avatar/AvatarFileInput.svelte +85 -0
  4. package/src/lib/components/Avatar/AvatarPopover.svelte +34 -0
  5. package/src/lib/components/Avatar/index.ts +4 -0
  6. package/src/lib/components/Avatar/types.ts +24 -0
  7. package/src/lib/components/BrushSizeSlider/BrushSizeSlider.svelte +174 -0
  8. package/src/lib/components/BrushSizeSlider/index.ts +1 -0
  9. package/src/lib/components/Button/Button.svelte +182 -0
  10. package/src/lib/components/Button/ConfirmActionButton.svelte +98 -0
  11. package/src/lib/components/Button/IconButton.svelte +121 -0
  12. package/src/lib/components/Button/RadioButton.svelte +93 -0
  13. package/src/lib/components/Button/index.ts +5 -0
  14. package/src/lib/components/Button/types.ts +54 -0
  15. package/src/lib/components/CardFan/CardFan.svelte +165 -0
  16. package/src/lib/components/CardFan/index.ts +2 -0
  17. package/src/lib/components/CardFan/types.ts +6 -0
  18. package/src/lib/components/CodeBlock/Code.svelte +7 -0
  19. package/src/lib/components/CodeBlock/CodeBlock.svelte +102 -0
  20. package/src/lib/components/CodeBlock/index.ts +3 -0
  21. package/src/lib/components/CodeBlock/types.ts +10 -0
  22. package/src/lib/components/ColorMode/ColorMode.svelte +8 -0
  23. package/src/lib/components/ColorMode/index.ts +2 -0
  24. package/src/lib/components/ColorMode/types.ts +12 -0
  25. package/src/lib/components/ColorPicker/ColorPicker.svelte +838 -0
  26. package/src/lib/components/ColorPicker/ColorPickerSwatch.svelte +32 -0
  27. package/src/lib/components/ColorPicker/index.ts +3 -0
  28. package/src/lib/components/ColorPicker/types.ts +51 -0
  29. package/src/lib/components/ContextMenu/ContextMenu.svelte +86 -0
  30. package/src/lib/components/ContextMenu/index.ts +2 -0
  31. package/src/lib/components/ContextMenu/types.ts +15 -0
  32. package/src/lib/components/DrawingSliders/DrawingSliders.svelte +379 -0
  33. package/src/lib/components/DrawingSliders/index.ts +1 -0
  34. package/src/lib/components/Editor/Editor.svelte +825 -0
  35. package/src/lib/components/Editor/index.ts +1 -0
  36. package/src/lib/components/FogSliders/FogSliders.svelte +33 -0
  37. package/src/lib/components/FogSliders/index.ts +1 -0
  38. package/src/lib/components/Hr/Hr.svelte +15 -0
  39. package/src/lib/components/Hr/index.ts +1 -0
  40. package/src/lib/components/Icon/Icon.svelte +6 -0
  41. package/src/lib/components/Icon/index.ts +2 -0
  42. package/src/lib/components/Icon/types.ts +20 -0
  43. package/src/lib/components/Input/DualInputSlider.svelte +126 -0
  44. package/src/lib/components/Input/FileInput.svelte +176 -0
  45. package/src/lib/components/Input/FormControl.svelte +150 -0
  46. package/src/lib/components/Input/FormError.svelte +37 -0
  47. package/src/lib/components/Input/Input.svelte +56 -0
  48. package/src/lib/components/Input/InputCheckbox.svelte +99 -0
  49. package/src/lib/components/Input/InputSlider.svelte +86 -0
  50. package/src/lib/components/Input/Label.svelte +19 -0
  51. package/src/lib/components/Input/index.ts +9 -0
  52. package/src/lib/components/Input/types.ts +39 -0
  53. package/src/lib/components/Link/Link.svelte +41 -0
  54. package/src/lib/components/Link/LinkBox.svelte +20 -0
  55. package/src/lib/components/Link/LinkOverlay.svelte +23 -0
  56. package/src/lib/components/Link/index.ts +4 -0
  57. package/src/lib/components/Link/types.ts +17 -0
  58. package/src/lib/components/Loading/Loader.svelte +60 -0
  59. package/src/lib/components/Loading/Skeleton.svelte +9 -0
  60. package/src/lib/components/Loading/index.ts +2 -0
  61. package/src/lib/components/Logo/Logo.svelte +16 -0
  62. package/src/lib/components/Logo/index.ts +1 -0
  63. package/src/lib/components/MarkerTooltip/MarkerTooltip.svelte +435 -0
  64. package/src/lib/components/MarkerTooltip/index.ts +1 -0
  65. package/src/lib/components/Menu/SelectorMenu.svelte +280 -0
  66. package/src/lib/components/Menu/index.ts +2 -0
  67. package/src/lib/components/Menu/types.ts +17 -0
  68. package/src/lib/components/MyCounterButton.svelte +11 -0
  69. package/src/lib/components/Panel/index.ts +2 -0
  70. package/src/lib/components/Panel/panel.svelte +18 -0
  71. package/src/lib/components/Panel/types.ts +8 -0
  72. package/src/lib/components/PersistButton/PersistButton.svelte +100 -0
  73. package/src/lib/components/PersistButton/index.ts +1 -0
  74. package/src/lib/components/Popover/Popover.svelte +81 -0
  75. package/src/lib/components/Popover/index.ts +2 -0
  76. package/src/lib/components/Popover/types.ts +19 -0
  77. package/src/lib/components/PropsTable/PropsTable.svelte +107 -0
  78. package/src/lib/components/RadialMenu/EffectPreview.svelte +36 -0
  79. package/src/lib/components/RadialMenu/EffectPreviewScene.svelte +194 -0
  80. package/src/lib/components/RadialMenu/RadialMenu.svelte +503 -0
  81. package/src/lib/components/RadialMenu/RadialMenuItem.svelte +176 -0
  82. package/src/lib/components/RadialMenu/index.ts +2 -0
  83. package/src/lib/components/RadialMenu/types.ts +35 -0
  84. package/src/lib/components/Select/Select.svelte +342 -0
  85. package/src/lib/components/Select/index.ts +2 -0
  86. package/src/lib/components/Select/types.ts +22 -0
  87. package/src/lib/components/Spacer/Spacer.svelte +14 -0
  88. package/src/lib/components/Spacer/index.ts +2 -0
  89. package/src/lib/components/Spacer/types.ts +5 -0
  90. package/src/lib/components/Stage/components/AnnotationLayer/AnnotationLayer.svelte +445 -0
  91. package/src/lib/components/Stage/components/AnnotationLayer/AnnotationMaterial.svelte +167 -0
  92. package/src/lib/components/Stage/components/AnnotationLayer/types.ts +196 -0
  93. package/src/lib/components/Stage/components/CursorLayer/CursorLayer.svelte +148 -0
  94. package/src/lib/components/Stage/components/CursorLayer/cursor.svg +26 -0
  95. package/src/lib/components/Stage/components/CursorLayer/index.ts +2 -0
  96. package/src/lib/components/Stage/components/CursorLayer/types.ts +23 -0
  97. package/src/lib/components/Stage/components/DrawingLayer/DrawingMaterial.svelte +364 -0
  98. package/src/lib/components/Stage/components/DrawingLayer/types.ts +65 -0
  99. package/src/lib/components/Stage/components/EdgeOverlayLayer/EdgeOverlayLayer.svelte +72 -0
  100. package/src/lib/components/Stage/components/EdgeOverlayLayer/types.ts +34 -0
  101. package/src/lib/components/Stage/components/FogLayer/FogLayer.svelte +75 -0
  102. package/src/lib/components/Stage/components/FogLayer/types.ts +51 -0
  103. package/src/lib/components/Stage/components/FogOfWarLayer/FogOfWarLayer.svelte +249 -0
  104. package/src/lib/components/Stage/components/FogOfWarLayer/FogOfWarMaterial.svelte +200 -0
  105. package/src/lib/components/Stage/components/FogOfWarLayer/types.ts +116 -0
  106. package/src/lib/components/Stage/components/GridLayer/GridLayer.svelte +20 -0
  107. package/src/lib/components/Stage/components/GridLayer/GridMaterial.svelte +69 -0
  108. package/src/lib/components/Stage/components/GridLayer/types.ts +79 -0
  109. package/src/lib/components/Stage/components/LayerInput/LayerInput.svelte +300 -0
  110. package/src/lib/components/Stage/components/MapLayer/MapLayer.svelte +196 -0
  111. package/src/lib/components/Stage/components/MapLayer/dataSources/GifDataSource.ts +265 -0
  112. package/src/lib/components/Stage/components/MapLayer/dataSources/IMapDataSource.ts +55 -0
  113. package/src/lib/components/Stage/components/MapLayer/dataSources/ImageDataSource.ts +87 -0
  114. package/src/lib/components/Stage/components/MapLayer/dataSources/VideoDataSource.ts +150 -0
  115. package/src/lib/components/Stage/components/MapLayer/dataSources/dataSourceFactory.ts +48 -0
  116. package/src/lib/components/Stage/components/MapLayer/dataSources/index.ts +16 -0
  117. package/src/lib/components/Stage/components/MapLayer/types.ts +58 -0
  118. package/src/lib/components/Stage/components/MarkerLayer/MarkerLayer.svelte +398 -0
  119. package/src/lib/components/Stage/components/MarkerLayer/MarkerToken.svelte +262 -0
  120. package/src/lib/components/Stage/components/MarkerLayer/types.ts +126 -0
  121. package/src/lib/components/Stage/components/MeasurementLayer/MeasurementLayer.svelte +364 -0
  122. package/src/lib/components/Stage/components/MeasurementLayer/MeasurementManager.svelte +473 -0
  123. package/src/lib/components/Stage/components/MeasurementLayer/measurements/BaseMeasurement.ts +427 -0
  124. package/src/lib/components/Stage/components/MeasurementLayer/measurements/BeamMeasurement.ts +105 -0
  125. package/src/lib/components/Stage/components/MeasurementLayer/measurements/CircleMeasurement.ts +98 -0
  126. package/src/lib/components/Stage/components/MeasurementLayer/measurements/ConeMeasurement.ts +163 -0
  127. package/src/lib/components/Stage/components/MeasurementLayer/measurements/LineMeasurement.ts +102 -0
  128. package/src/lib/components/Stage/components/MeasurementLayer/measurements/RectangleMeasurement.ts +120 -0
  129. package/src/lib/components/Stage/components/MeasurementLayer/measurements/index.ts +7 -0
  130. package/src/lib/components/Stage/components/MeasurementLayer/types.ts +94 -0
  131. package/src/lib/components/Stage/components/MeasurementLayer/utils/canvasDrawing.ts +357 -0
  132. package/src/lib/components/Stage/components/MeasurementLayer/utils/distanceCalculations.ts +170 -0
  133. package/src/lib/components/Stage/components/ParticleSystem/ParticleSystem.svelte +220 -0
  134. package/src/lib/components/Stage/components/ParticleSystem/particles/atlases/ash.png +0 -0
  135. package/src/lib/components/Stage/components/ParticleSystem/particles/atlases/leaves.png +0 -0
  136. package/src/lib/components/Stage/components/ParticleSystem/particles/atlases/rain.png +0 -0
  137. package/src/lib/components/Stage/components/ParticleSystem/particles/atlases/snow.png +0 -0
  138. package/src/lib/components/Stage/components/ParticleSystem/rng.js +20 -0
  139. package/src/lib/components/Stage/components/ParticleSystem/types.ts +95 -0
  140. package/src/lib/components/Stage/components/PerformanceDebugger/PerformanceDebugger.svelte +144 -0
  141. package/src/lib/components/Stage/components/PerformanceDebugger/index.ts +1 -0
  142. package/src/lib/components/Stage/components/PerformanceOverlay/PerformanceOverlay.svelte +208 -0
  143. package/src/lib/components/Stage/components/PerformanceOverlay/index.ts +1 -0
  144. package/src/lib/components/Stage/components/PointerInputManager/PointerInputManager.svelte +201 -0
  145. package/src/lib/components/Stage/components/Scene/Scene.svelte +651 -0
  146. package/src/lib/components/Stage/components/Scene/luts.ts +24 -0
  147. package/src/lib/components/Stage/components/Scene/types.ts +225 -0
  148. package/src/lib/components/Stage/components/Stage/Stage.svelte +332 -0
  149. package/src/lib/components/Stage/components/Stage/types.ts +136 -0
  150. package/src/lib/components/Stage/components/WeatherLayer/WeatherLayer.svelte +135 -0
  151. package/src/lib/components/Stage/components/WeatherLayer/presets/AshPreset.ts +71 -0
  152. package/src/lib/components/Stage/components/WeatherLayer/presets/LeavesPreset.ts +70 -0
  153. package/src/lib/components/Stage/components/WeatherLayer/presets/RainPreset.ts +68 -0
  154. package/src/lib/components/Stage/components/WeatherLayer/presets/SnowPreset.ts +70 -0
  155. package/src/lib/components/Stage/components/WeatherLayer/presets/index.ts +6 -0
  156. package/src/lib/components/Stage/components/WeatherLayer/types.ts +35 -0
  157. package/src/lib/components/Stage/helpers/clippingPlaneStore.svelte.ts +28 -0
  158. package/src/lib/components/Stage/helpers/debugState.svelte.ts +18 -0
  159. package/src/lib/components/Stage/helpers/grid.ts +548 -0
  160. package/src/lib/components/Stage/helpers/lazyBrush.ts +171 -0
  161. package/src/lib/components/Stage/helpers/performanceMetrics.svelte.ts +220 -0
  162. package/src/lib/components/Stage/helpers/utils.ts +21 -0
  163. package/src/lib/components/Stage/index.ts +49 -0
  164. package/src/lib/components/Stage/shaders/AnnotationEffects.frag +1070 -0
  165. package/src/lib/components/Stage/shaders/Annotations.frag +29 -0
  166. package/src/lib/components/Stage/shaders/Drawing.frag +83 -0
  167. package/src/lib/components/Stage/shaders/Drawing.vert +5 -0
  168. package/src/lib/components/Stage/shaders/Fog.frag +147 -0
  169. package/src/lib/components/Stage/shaders/FractalNoise.frag +96 -0
  170. package/src/lib/components/Stage/shaders/GridShader.frag +174 -0
  171. package/src/lib/components/Stage/shaders/Overlay.frag +23 -0
  172. package/src/lib/components/Stage/shaders/Overlay.vert +0 -0
  173. package/src/lib/components/Stage/shaders/Particles.frag +27 -0
  174. package/src/lib/components/Stage/shaders/Particles.vert +51 -0
  175. package/src/lib/components/Stage/shaders/ToolOutline.frag +59 -0
  176. package/src/lib/components/Stage/shaders/default.vert +8 -0
  177. package/src/lib/components/Stage/types.ts +4 -0
  178. package/src/lib/components/Table/Table.svelte +16 -0
  179. package/src/lib/components/Table/Td.svelte +17 -0
  180. package/src/lib/components/Table/Th.svelte +18 -0
  181. package/src/lib/components/Table/index.ts +4 -0
  182. package/src/lib/components/Table/types.ts +14 -0
  183. package/src/lib/components/Text/Text.svelte +23 -0
  184. package/src/lib/components/Text/index.ts +2 -0
  185. package/src/lib/components/Text/types.ts +12 -0
  186. package/src/lib/components/Title/Title.svelte +54 -0
  187. package/src/lib/components/Title/index.ts +2 -0
  188. package/src/lib/components/Title/types.ts +9 -0
  189. package/src/lib/components/Toast/Toast.svelte +155 -0
  190. package/src/lib/components/Toast/index.ts +5 -0
  191. package/src/lib/components/Toast/toastCookie.ts +24 -0
  192. package/src/lib/components/Toast/types.ts +6 -0
  193. package/src/lib/components/ToolTip/ToolTip.svelte +70 -0
  194. package/src/lib/components/ToolTip/index.ts +2 -0
  195. package/src/lib/components/ToolTip/types.ts +14 -0
  196. package/src/lib/components/index.ts +32 -0
  197. package/src/lib/components/types.ts +0 -0
  198. package/src/lib/index.ts +2 -0
  199. package/src/lib/styles/globals.css +108 -0
  200. package/src/lib/styles/normalize.css +9 -0
  201. package/src/lib/styles/reset.css +133 -0
  202. package/src/lib/styles/utilities.css +179 -0
  203. package/src/lib/styles/vars.css +1103 -0
  204. package/src/lib/types/awareness.ts +17 -0
  205. package/src/lib/utils/rle.ts +217 -0
@@ -0,0 +1,29 @@
1
+ precision highp float;
2
+
3
+ uniform sampler2D uMaskTexture;
4
+ uniform vec3 uColor;
5
+ uniform float uOpacity;
6
+ uniform vec4 uClippingPlanes[NUM_CLIPPING_PLANES];
7
+
8
+ varying vec2 vUv;
9
+ varying vec3 vWorldPosition;
10
+
11
+ void main() {
12
+
13
+ vec4 plane;
14
+
15
+ #pragma unroll_loop
16
+ for(int i = 0; i < NUM_CLIPPING_PLANES; i++) {
17
+ plane = uClippingPlanes[i];
18
+ if(dot(-vWorldPosition, plane.xyz) > plane.w) {
19
+ discard;
20
+ }
21
+ }
22
+
23
+ // Sample at multiple levels of detail to get a nice feathered edge
24
+ vec2 texSize = vec2(textureSize(uMaskTexture, 0));
25
+
26
+ float mask = texture2D(uMaskTexture, vUv).a;
27
+
28
+ gl_FragColor = vec4(uColor, mask * uOpacity);
29
+ }
@@ -0,0 +1,83 @@
1
+ uniform sampler2D uPreviousState;
2
+ uniform vec2 uStart;
3
+ uniform vec2 uEnd;
4
+ uniform float uBrushSize;
5
+ uniform vec2 uTextureSize;
6
+ uniform vec4 uBrushColor;
7
+ uniform bool uIsRevertOperation;
8
+ uniform bool uIsClearOperation;
9
+ uniform bool uIsFillOperation;
10
+ uniform int uShapeType;
11
+
12
+ varying vec2 vUv;
13
+
14
+ float isInsideEllipse(vec2 p, vec2 a, vec2 b) {
15
+ // Find center of ellipse
16
+ vec2 center = (a + b) / 2.0;
17
+
18
+ // Find semi-major and semi-minor axes
19
+ vec2 radii = abs(b - a) / 2.0;
20
+
21
+ // Translate point to origin
22
+ vec2 p0 = p - center;
23
+
24
+ // Calculate normalized distance from point to ellipse
25
+ float value = (p0.x * p0.x) / (radii.x * radii.x) + (p0.y * p0.y) / (radii.y * radii.y);
26
+
27
+ // If inside ellipse, return 0
28
+ if(value <= 1.0) {
29
+ return 0.0;
30
+ }
31
+
32
+ // Otherwise return approximate distance to ellipse edge
33
+ // Scale p0 to make the ellipse a circle, find distance to unit circle, then scale back
34
+ vec2 scaledP = vec2(p0.x / radii.x, p0.y / radii.y);
35
+ float dist = (length(scaledP) - 1.0) * min(radii.x, radii.y);
36
+ return dist;
37
+ }
38
+
39
+ float distanceToRectangle(vec2 p, vec2 a, vec2 b) {
40
+ vec2 rectMin = vec2(min(a.x, b.x), min(a.y, b.y));
41
+ vec2 rectMax = vec2(max(a.x, b.x), max(a.y, b.y));
42
+
43
+ // Find closest point on rectangle to p
44
+ vec2 closest = vec2(clamp(p.x, rectMin.x, rectMax.x), clamp(p.y, rectMin.y, rectMax.y));
45
+
46
+ // Return distance to closest point
47
+ return length(p - closest);
48
+ }
49
+
50
+ float distanceToLine(vec2 p, vec2 a, vec2 b) {
51
+ vec2 pa = p - a;
52
+ vec2 ba = b - a;
53
+ float t = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);
54
+ return length(pa - ba * t);
55
+ }
56
+
57
+ void main() {
58
+ if(uIsRevertOperation) {
59
+ gl_FragColor = texture2D(uPreviousState, vUv);
60
+ } else if(uIsClearOperation) {
61
+ gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
62
+ } else if(uIsFillOperation) {
63
+ gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
64
+ } else {
65
+ vec2 pixelPos = vUv * uTextureSize;
66
+ vec4 prevColor = texture2D(uPreviousState, vUv);
67
+
68
+ float brushMask = 0.0;
69
+
70
+ if(uShapeType == 1) {
71
+ float dist = distanceToLine(pixelPos, uStart, uEnd);
72
+ brushMask = step(dist, uBrushSize);
73
+ } else if(uShapeType == 2) {
74
+ float dist = distanceToRectangle(pixelPos, uStart, uEnd);
75
+ brushMask = dist < 1.0 ? 1.0 : 0.0;
76
+ } else if(uShapeType == 3) {
77
+ float dist = isInsideEllipse(pixelPos, uStart, uEnd);
78
+ brushMask = dist < 1.0 ? 1.0 : 0.0;
79
+ }
80
+
81
+ gl_FragColor = mix(prevColor, uBrushColor, brushMask);
82
+ }
83
+ }
@@ -0,0 +1,5 @@
1
+ varying vec2 vUv;
2
+ void main() {
3
+ vUv = uv;
4
+ gl_Position = vec4(position, 1.0);
5
+ }
@@ -0,0 +1,147 @@
1
+ precision highp float;
2
+
3
+ uniform float uTime;
4
+ uniform vec3 uBaseColor;
5
+ uniform vec3 uFogColor1;
6
+ uniform vec3 uFogColor2;
7
+ uniform vec3 uFogColor3;
8
+ uniform vec3 uFogColor4;
9
+ uniform float uOpacity;
10
+
11
+ uniform vec4 uFogSpeed;
12
+ uniform vec4 uPersistence;
13
+ uniform vec4 uLacunarity;
14
+ uniform vec4 uFrequency;
15
+ uniform vec4 uAmplitude;
16
+ uniform vec4 uOffset;
17
+ uniform ivec4 uLevels;
18
+
19
+ uniform int uEdgeMinMipMapLevel;
20
+ uniform int uEdgeMaxMipMapLevel;
21
+ uniform vec4 uEdgeFrequency;
22
+ uniform vec4 uEdgeAmplitude;
23
+ uniform float uEdgeOffset;
24
+ uniform float uEdgeSpeed;
25
+
26
+ uniform sampler2D uMaskTexture;
27
+ uniform vec4 uClippingPlanes[NUM_CLIPPING_PLANES];
28
+
29
+ varying vec2 vUv;
30
+ varying vec3 vWorldPosition;
31
+
32
+ // Simplex noise functions from https://github.com/ashima/webgl-noise
33
+ vec3 mod289(vec3 x) {
34
+ return x - floor(x * (1.0 / 289.0)) * 289.0;
35
+ }
36
+
37
+ vec2 mod289(vec2 x) {
38
+ return x - floor(x * (1.0 / 289.0)) * 289.0;
39
+ }
40
+
41
+ vec3 permute(vec3 x) {
42
+ return mod289(((x * 34.0) + 1.0) * x);
43
+ }
44
+
45
+ float snoise(vec2 v) {
46
+ const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0
47
+ 0.366025403784439, // 0.5*(sqrt(3.0)-1.0)
48
+ -0.577350269189626, // -1.0 + 2.0 * C.x
49
+ 0.024390243902439); // 1.0 / 41.0
50
+ vec2 i = floor(v + dot(v, C.yy));
51
+ vec2 x0 = v - i + dot(i, C.xx);
52
+ vec2 i1;
53
+ i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
54
+ vec4 x12 = x0.xyxy + C.xxzz;
55
+ x12.xy -= i1;
56
+ i = mod289(i);
57
+ vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0)) + i.x + vec3(0.0, i1.x, 1.0));
58
+ vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy), dot(x12.zw, x12.zw)), 0.0);
59
+ m = m * m;
60
+ m = m * m;
61
+ vec3 x = 2.0 * fract(p * C.www) - 1.0;
62
+ vec3 h = abs(x) - 0.5;
63
+ vec3 ox = floor(x + 0.5);
64
+ vec3 a0 = x - ox;
65
+ m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h);
66
+ vec3 g;
67
+ g.x = a0.x * x0.x + h.x * x0.y;
68
+ g.yz = a0.yz * x12.xz + h.yz * x12.yw;
69
+
70
+ float n = 130.0 * dot(m, g);
71
+ return n;
72
+ }
73
+
74
+ float fog(vec2 uv, vec2 size, float amplitude, float frequency, float persistence, float lacunarity, float offset, int levels, float speed) {
75
+ float sum = 0.0;
76
+
77
+ // Layer multiple octaves of noise with varying brightness
78
+ float a = 1.0;
79
+ for(int i = 0; i < levels; i++) {
80
+ sum += a * snoise(uv * size * frequency + uTime * speed);
81
+ a *= persistence;
82
+ frequency *= lacunarity;
83
+ }
84
+
85
+ sum /= float(levels);
86
+ sum = sum + 0.5 + offset;
87
+
88
+ return amplitude * clamp(sum, 0.0, 1.0);
89
+ }
90
+
91
+ float mask(vec2 uv, vec2 size, float amplitude, float frequency) {
92
+ // Sample the mask at multiple mipmap levels to get a feathered edge
93
+ float featheredMask = 0.0;
94
+ float totalWeight = 0.0;
95
+ for(int i = uEdgeMinMipMapLevel; i <= uEdgeMaxMipMapLevel; i++) {
96
+ featheredMask += textureLod(uMaskTexture, uv, float(i)).a;
97
+ }
98
+ featheredMask /= float(uEdgeMaxMipMapLevel - uEdgeMinMipMapLevel + 1);
99
+ featheredMask = clamp(featheredMask, 0.0, 1.0);
100
+
101
+ // Add noise to the edge of the mask
102
+ vec2 noiseUV = uv * size;
103
+ float edgeNoise = snoise(frequency * noiseUV + uTime * uEdgeSpeed) + uEdgeOffset;
104
+
105
+ // Create an edge mask that's only non-zero near the transition
106
+ float edgeWidth = 0.2;
107
+ float edgeMask = smoothstep(0.0, edgeWidth, featheredMask) * (1.0 - smoothstep(1.0 - edgeWidth, 1.0, featheredMask));
108
+
109
+ // Blend the noise only at the edges
110
+ float finalMask = featheredMask + edgeNoise * amplitude * edgeMask;
111
+
112
+ float baseMask = texture2D(uMaskTexture, vUv).a;
113
+ return amplitude * finalMask + (1.0 - amplitude) * baseMask;
114
+ }
115
+
116
+ void main() {
117
+
118
+ vec4 plane;
119
+
120
+ #pragma unroll_loop
121
+ for(int i = 0; i < NUM_CLIPPING_PLANES; i++) {
122
+ plane = uClippingPlanes[i];
123
+ if(dot(-vWorldPosition, plane.xyz) > plane.w) {
124
+ discard;
125
+ }
126
+ }
127
+
128
+ // Sample at multiple levels of detail to get a nice feathered edge
129
+ vec2 texSize = vec2(textureSize(uMaskTexture, 0));
130
+
131
+ float mask1 = mask(vUv, texSize, uEdgeAmplitude.x, uEdgeFrequency.x);
132
+ float mask2 = mask(vUv, texSize, uEdgeAmplitude.y, uEdgeFrequency.y);
133
+ float mask3 = mask(vUv, texSize, uEdgeAmplitude.z, uEdgeFrequency.z);
134
+ float mask4 = mask(vUv, texSize, uEdgeAmplitude.w, uEdgeFrequency.w);
135
+
136
+ vec3 fog1 = uFogColor1 * fog(vUv, texSize, uAmplitude.x, uFrequency.x, uPersistence.x, uLacunarity.x, uOffset.x, uLevels.x, uFogSpeed.x);
137
+ vec3 fog2 = uFogColor2 * fog(vUv, texSize, uAmplitude.y, uFrequency.y, uPersistence.y, uLacunarity.y, uOffset.y, uLevels.y, uFogSpeed.y);
138
+ vec3 fog3 = uFogColor3 * fog(vUv, texSize, uAmplitude.z, uFrequency.z, uPersistence.z, uLacunarity.z, uOffset.z, uLevels.z, uFogSpeed.z);
139
+ vec3 fog4 = uFogColor4 * fog(vUv, texSize, uAmplitude.w, uFrequency.w, uPersistence.w, uLacunarity.w, uOffset.w, uLevels.w, uFogSpeed.w);
140
+
141
+ vec4 finalFog = clamp(vec4(fog1, mask1) +
142
+ vec4(fog2, mask2) +
143
+ vec4(fog3, mask3) +
144
+ vec4(fog4, mask4), 0.0, 1.0);
145
+
146
+ gl_FragColor = vec4(uBaseColor + finalFog.rgb, finalFog.a * uOpacity);
147
+ }
@@ -0,0 +1,96 @@
1
+ precision highp float;
2
+
3
+ uniform float uTime;
4
+ uniform float uAspectRatio;
5
+ uniform vec3 uFogColor;
6
+ uniform float uOpacity;
7
+
8
+ uniform float uFogSpeed;
9
+ uniform float uPersistence;
10
+ uniform float uLacunarity;
11
+ uniform float uFrequency;
12
+ uniform float uAmplitude;
13
+ uniform float uOffset;
14
+ uniform int uLevels;
15
+
16
+ uniform vec4 uClippingPlanes[NUM_CLIPPING_PLANES];
17
+
18
+ varying vec2 vUv;
19
+ varying vec3 vWorldPosition;
20
+
21
+ // Simplex noise functions from https://github.com/ashima/webgl-noise
22
+ vec3 mod289(vec3 x) {
23
+ return x - floor(x * (1.0 / 289.0)) * 289.0;
24
+ }
25
+
26
+ vec2 mod289(vec2 x) {
27
+ return x - floor(x * (1.0 / 289.0)) * 289.0;
28
+ }
29
+
30
+ vec3 permute(vec3 x) {
31
+ return mod289(((x * 34.0) + 1.0) * x);
32
+ }
33
+
34
+ float snoise(vec2 v) {
35
+ const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0
36
+ 0.366025403784439, // 0.5*(sqrt(3.0)-1.0)
37
+ -0.577350269189626, // -1.0 + 2.0 * C.x
38
+ 0.024390243902439); // 1.0 / 41.0
39
+ vec2 i = floor(v + dot(v, C.yy));
40
+ vec2 x0 = v - i + dot(i, C.xx);
41
+ vec2 i1;
42
+ i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
43
+ vec4 x12 = x0.xyxy + C.xxzz;
44
+ x12.xy -= i1;
45
+ i = mod289(i);
46
+ vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0)) + i.x + vec3(0.0, i1.x, 1.0));
47
+ vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy), dot(x12.zw, x12.zw)), 0.0);
48
+ m = m * m;
49
+ m = m * m;
50
+ vec3 x = 2.0 * fract(p * C.www) - 1.0;
51
+ vec3 h = abs(x) - 0.5;
52
+ vec3 ox = floor(x + 0.5);
53
+ vec3 a0 = x - ox;
54
+ m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h);
55
+ vec3 g;
56
+ g.x = a0.x * x0.x + h.x * x0.y;
57
+ g.yz = a0.yz * x12.xz + h.yz * x12.yw;
58
+
59
+ float n = 130.0 * dot(m, g);
60
+ return n;
61
+ }
62
+
63
+ float fog(vec2 uv, float amplitude, float frequency, float persistence, float lacunarity, float offset, int levels, float speed) {
64
+ float sum = 0.0;
65
+
66
+ // Layer multiple octaves of noise with varying brightness
67
+ float a = 1.0;
68
+ for(int i = 0; i < levels; i++) {
69
+ sum += a * snoise(uv * frequency + uTime * speed);
70
+ a *= persistence;
71
+ frequency *= lacunarity;
72
+ }
73
+
74
+ sum /= float(levels);
75
+ sum = sum + 0.5 + offset;
76
+
77
+ return amplitude * clamp(sum, 0.0, 1.0);
78
+ }
79
+
80
+ void main() {
81
+
82
+ vec4 plane;
83
+
84
+ #pragma unroll_loop
85
+ for(int i = 0; i < NUM_CLIPPING_PLANES; i++) {
86
+ plane = uClippingPlanes[i];
87
+ if(dot(-vWorldPosition, plane.xyz) > plane.w) {
88
+ discard;
89
+ }
90
+ }
91
+
92
+ vec2 uv = vec2(vUv.x * uAspectRatio, vUv.y);
93
+ float alpha = fog(uv, uAmplitude, uFrequency, uPersistence, uLacunarity, uOffset, uLevels, uFogSpeed);
94
+
95
+ gl_FragColor = vec4(uFogColor, alpha * uOpacity);
96
+ }
@@ -0,0 +1,174 @@
1
+ uniform int uGridType;
2
+ uniform int uGridMode;
3
+ uniform float uSpacing_in;
4
+ uniform float uOpacity;
5
+ uniform vec2 uPadding_px;
6
+ uniform float uLineThickness;
7
+ uniform vec3 uLineColor;
8
+ uniform float uShadowOpacity;
9
+ uniform float uShadowBlur;
10
+ uniform float uShadowSpread;
11
+ uniform vec3 uShadowColor;
12
+ uniform float uSceneScale;
13
+ uniform vec2 uResolution_px;
14
+ uniform vec2 uDisplaySize_in;
15
+ uniform float uFixedGridCountX;
16
+ uniform float uFixedGridCountY;
17
+
18
+ varying vec2 vUv;
19
+
20
+ #define PI 3.141592653589793
21
+
22
+ const vec2 s = vec2(1.0, 1.7320508); // For hexagonal grid calculations
23
+
24
+ /**
25
+ Returns 0 or 1 to indicate if this fragment is a grid line
26
+
27
+ Params
28
+ - coords: The coordinates of the fragment relative to the grid origin
29
+ - spacing: The grid spacing in pixels
30
+ */
31
+ float squareGrid(vec2 coords, vec2 spacing, float thickness, float sharpness) {
32
+ // Use modulus to compute the locations of the nearest grid lines
33
+ vec2 gridLine_px = vec2(round(coords.x / spacing.x) * spacing.x, round(coords.y / spacing.y) * spacing.y);
34
+
35
+ // Compute distance to the grid line and modulate opacity based on line thickness
36
+ vec2 distanceToLine_px = abs(coords - gridLine_px);
37
+
38
+ vec2 grid = 1.0 - smoothstep(vec2(thickness / 4.0) - 50.0 * sharpness, vec2(thickness / 4.0) + 50.0 * sharpness, distanceToLine_px);
39
+
40
+ return max(grid.x, grid.y);
41
+ }
42
+
43
+ // This function maps a 2D point p to its corresponding hexagonal grid
44
+ // coordinates and returns information about the hexagonal cell it's in.
45
+ // NOTE: Function and comments are AI generated using ChatGPT 4o
46
+ vec2 getHex(vec2 p) {
47
+ // Step 1: Compute the approximate centers of candidate hexagons.
48
+ // - `vec4(p, p - vec2(0.5, 1.0))` creates two shifted versions of the input `p`.
49
+ // - The first two components are `p` for direct scaling.
50
+ // - The last two components are `p - vec2(0.5, 1.0)` to account for hexagonal offsets.
51
+ // - Divide by `s.xyxy` (grid scaling factors) to map the coordinates into a normalized hexagonal grid.
52
+ // - `floor(...) + 0.5` maps the point to the center of the grid cell it lies in.
53
+ vec4 hC = floor(vec4(p, p - vec2(0.5, 1.0)) / s.xyxy) + 0.5;
54
+
55
+ // Step 2: Calculate the two potential hexagon centers in the original space.
56
+ // - `hC.xy * s`: Maps the first candidate center back to the original space.
57
+ // - `(hC.zw + 0.5) * s`: Maps the second candidate center back, accounting for offsets.
58
+ // - Subtract these centers from `p` to calculate relative positions (distance vectors) to `p`.
59
+ vec4 h = vec4(p - hC.xy * s, p - (hC.zw + 0.5) * s);
60
+
61
+ // Step 3: Compare distances to the two candidate centers.
62
+ // - Use `dot(h.xy, h.xy)` and `dot(h.zw, h.zw)` to compute the squared distances (avoids expensive sqrt).
63
+ // - Return the center (either `h.xy` or `h.zw`) that is closer to `p`.
64
+ return dot(h.xy, h.xy) < dot(h.zw, h.zw) ? h.xy : h.zw;
65
+ }
66
+
67
+ // This function helps define the shape of a hexagon by transforming a
68
+ // 2D coordinate and determining whether the point falls inside the
69
+ // boundaries of a hexagonal cell.
70
+ float hexGrid(vec2 coords, vec2 spacing, float thickness, float sharpness) {
71
+ vec2 hexUv = getHex(coords / spacing);
72
+ hexUv = abs(hexUv);
73
+ float hexValue = max(dot(hexUv, s * 0.5), hexUv.x);
74
+
75
+ // 0 is max thickness, 0.5 is zero thickness
76
+ // 0 maps to spacing * 0.5 pixels
77
+ vec2 maxThickness = spacing * 0.5;
78
+
79
+ // When the thickness is equal to spacing * 0.5, it must be zero
80
+ return smoothstep(0.5 * (1.0 - thickness / spacing.x / 2.0) - sharpness, 0.5 * (1.0 - thickness / spacing.x / 2.0) + sharpness, hexValue);
81
+ }
82
+
83
+ void main() {
84
+ // NOTE: To make it easier to determine what units a variable is, the _px suffix is used
85
+ // for values measured in pixels and the _in suffix is for inches.
86
+
87
+ // Convert UV coordinates to pixels and get the coordinates of this fragment in pixels
88
+ vec2 displayCoord_px = vUv * uResolution_px;
89
+
90
+ // Compute the pixel pitch
91
+ vec2 pixelPitch_in = uDisplaySize_in / uResolution_px;
92
+
93
+ vec2 gridSpacing_px;
94
+ vec2 gridCount;
95
+ vec2 gridSize_px;
96
+ vec2 gridOrigin_px;
97
+
98
+ if (uGridMode == 0) {
99
+ // FillSpace mode - use padding-based calculation
100
+ vec2 safeZoneSize_px = uResolution_px - uPadding_px * 2.0 - uLineThickness;
101
+ gridSpacing_px = vec2(uSpacing_in) / pixelPitch_in;
102
+ gridCount = floor(safeZoneSize_px / gridSpacing_px);
103
+ gridSize_px = gridSpacing_px * gridCount + uLineThickness / 2.0;
104
+ gridOrigin_px = (uResolution_px - gridSize_px) / 2.0;
105
+ } else {
106
+ // MapDefined mode - use exact grid dimensions
107
+ gridCount = vec2(uFixedGridCountX, uFixedGridCountY);
108
+
109
+ // Calculate grid spacing to maintain 1:1 inch squares
110
+ gridSpacing_px = vec2(uSpacing_in) / pixelPitch_in;
111
+
112
+ // Calculate total grid size
113
+ gridSize_px = gridSpacing_px * gridCount + uLineThickness / 2.0;
114
+
115
+ // Position grid based on overflow:
116
+ // - If grid fits horizontally, center it
117
+ // - If grid overflows horizontally, align left
118
+ float originX = gridSize_px.x <= uResolution_px.x ?
119
+ (uResolution_px.x - gridSize_px.x) / 2.0 : 0.0;
120
+
121
+ // - If grid fits vertically, center it
122
+ // - If grid overflows vertically, align to top of screen (bleed goes down)
123
+ // In UV space: Y=0 is bottom, Y=uResolution_px.y is top
124
+ // To start at top when overflowing: originY = uResolution_px.y - gridSize_px.y
125
+ float originY = gridSize_px.y <= uResolution_px.y ?
126
+ (uResolution_px.y - gridSize_px.y) / 2.0 :
127
+ uResolution_px.y - gridSize_px.y;
128
+
129
+ gridOrigin_px = vec2(originX, originY);
130
+ }
131
+
132
+ vec2 gridCoords_px = displayCoord_px - gridOrigin_px;
133
+
134
+ float grid = 0.0;
135
+ float shadow = 0.0;
136
+ float t = uLineThickness * uSceneScale < 2.0 ? 2.0 / uSceneScale : uLineThickness;
137
+
138
+ if(uGridType == 0) {
139
+ grid = squareGrid(gridCoords_px - t / 4.0, gridSpacing_px, t, 0.0);
140
+ shadow = squareGrid(gridCoords_px - t / 4.0, gridSpacing_px, t * uShadowSpread, uShadowBlur);
141
+ } else {
142
+ // Subtract half the grid size so the hex grid is symmetrical on the edges
143
+ grid = hexGrid((gridCoords_px - (gridSize_px / 2.0)), gridSpacing_px, t, 0.0);
144
+ shadow = hexGrid((gridCoords_px - (gridSize_px / 2.0)), gridSpacing_px, t * uShadowSpread, uShadowBlur);
145
+ }
146
+
147
+ // Add border
148
+ vec2 topRight = gridOrigin_px + gridSize_px - displayCoord_px;
149
+ vec2 bottomLeft = displayCoord_px - gridOrigin_px;
150
+
151
+ // If any coordinates are inside the border zone, set isBorder to true
152
+ bool isBorder = (topRight.x < t / 2.0) ||
153
+ (topRight.y < t / 2.0) ||
154
+ (bottomLeft.x < t / 2.0) ||
155
+ (bottomLeft.y < t / 2.0);
156
+
157
+ grid = max(grid, float(isBorder));
158
+ shadow = max(shadow, float(isBorder));
159
+
160
+ /* Uncomment these lines to visualize the area outside the safe zone
161
+ float outsideSafeZone = step(uPadding_px.x, p.x) - step((uResolution_px.x - uPadding_px.x), p.x);
162
+ outsideSafeZone *= step(uPadding_px.y, p.y) - step((uResolution_px.y - uPadding_px.y), p.y);
163
+ vec4 exclusionZoneColor = vec4(1.0, 0, 0, 1.0 - outsideSafeZone);
164
+ */
165
+
166
+ float insideGrid = step(gridOrigin_px.x, displayCoord_px.x) - step((gridOrigin_px.x + gridSize_px.x), displayCoord_px.x);
167
+ insideGrid *= step(gridOrigin_px.y, displayCoord_px.y) - step((gridOrigin_px.y + gridSize_px.y), displayCoord_px.y);
168
+
169
+ vec4 lineColor = vec4(uLineColor, grid * insideGrid * uOpacity);
170
+ vec4 shadedScene = vec4(uShadowColor.rgb, shadow * uShadowOpacity * uOpacity);
171
+ vec4 finalColor = mix(shadedScene, lineColor, grid);
172
+
173
+ gl_FragColor = finalColor;
174
+ }
@@ -0,0 +1,23 @@
1
+ uniform sampler2D uTexture;
2
+ uniform float uOpacity;
3
+ uniform float uFadeStart;
4
+ uniform float uFadeEnd;
5
+ uniform vec2 uResolution;
6
+ uniform float uScale;
7
+
8
+ varying vec2 vUv;
9
+
10
+ void main() {
11
+ vec2 uv = fract(vUv * uResolution / max(uResolution.x, uResolution.y) * uScale);
12
+ vec4 texColor = texture2D(uTexture, uv);
13
+
14
+ // Calculate distance from center (0.5, 0.5)
15
+ vec2 center = vec2(0.5, 0.5);
16
+ float dist = length(vUv - center);
17
+
18
+ // Fade based on distance
19
+ float fade = 1.0 - smoothstep(uFadeStart, uFadeEnd, dist);
20
+
21
+ gl_FragColor = texColor;
22
+ gl_FragColor.a *= (1.0 - fade) * uOpacity;
23
+ }
File without changes
@@ -0,0 +1,27 @@
1
+ precision highp float;
2
+
3
+ uniform sampler2D uTexture;
4
+
5
+ uniform float uTime;
6
+
7
+ uniform float uOpacity;
8
+ uniform vec3 uColor;
9
+
10
+ uniform float uLifetime;
11
+ uniform float uFadeInTime;
12
+ uniform float uFadeOutTime;
13
+
14
+ varying vec2 vUv;
15
+ varying vec3 vPos;
16
+ varying float vAge;
17
+
18
+ void main() {
19
+ vec4 textureColor = texture2D(uTexture, vUv);
20
+
21
+ float opacity = uOpacity * textureColor.a;
22
+
23
+ // Fade particles in and out at beginning and end of their lifetime
24
+ float fade = smoothstep(0.0, uFadeInTime, vAge) - (1.0 - smoothstep(uLifetime, uLifetime - uFadeOutTime, vAge));
25
+
26
+ gl_FragColor = vec4(textureColor.rgb * uColor, clamp(opacity * fade, 0.0, 1.0));
27
+ }
@@ -0,0 +1,51 @@
1
+ precision highp float;
2
+
3
+ attribute vec2 center;
4
+ attribute float ageOffset;
5
+
6
+ uniform sampler2D uTexture;
7
+
8
+ uniform float uOpacity;
9
+ uniform float uTime;
10
+ uniform float uLifetime;
11
+
12
+ uniform vec3 uColor;
13
+
14
+ uniform float uAngularVelocity;
15
+ uniform vec3 uInitialVelocity;
16
+ uniform vec3 uLinearForceAmplitude;
17
+ uniform vec3 uExponentialForceAmplitude;
18
+ uniform vec3 uSinusoidalForceAmplitude;
19
+ uniform vec3 uSinusoidalForceFrequency;
20
+
21
+ varying vec2 vUv;
22
+ varying vec3 vPos;
23
+ varying float vAge;
24
+
25
+ void main() {
26
+ vAge = mod(ageOffset + uTime, uLifetime);
27
+
28
+ vec3 velocity = uInitialVelocity + vAge * uLinearForceAmplitude;
29
+ velocity += uExponentialForceAmplitude * exp(vAge);
30
+ velocity += uSinusoidalForceAmplitude * sin(vAge * uSinusoidalForceFrequency + ageOffset);
31
+
32
+ vec3 pos = position;
33
+
34
+ // Apply rotation around center point
35
+ vec2 toCenter = pos.xy - center;
36
+ float angle = uAngularVelocity * vAge;
37
+ float cosA = cos(angle);
38
+ float sinA = sin(angle);
39
+ mat2 rotation = mat2(cosA, -sinA, sinA, cosA);
40
+ vec2 rotated = rotation * toCenter;
41
+ pos.xy = rotated + center;
42
+
43
+ pos += vAge * velocity;
44
+
45
+ vUv = uv;
46
+
47
+ vec4 transformedPosition = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);
48
+ vPos = transformedPosition.xyz;
49
+
50
+ gl_Position = transformedPosition;
51
+ }