shaders 2.2.24 → 2.2.25
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.
- package/dist/core/AngularBlur-Dl2gwk68.js +64 -0
- package/dist/core/Ascii-Dha_QpT3.js +286 -0
- package/dist/core/Beam-CTN9Ni43.js +139 -0
- package/dist/core/Blob-CxFDZovO.js +218 -0
- package/dist/core/Blur-Y2FsmFk_.js +77 -0
- package/dist/core/Bulge-Cb-t0xqI.js +132 -0
- package/dist/core/CRTScreen-CtERsenz.js +112 -0
- package/dist/core/ChannelBlur-CvM6GJgZ.js +118 -0
- package/dist/core/Checkerboard-CgB-egNY.js +83 -0
- package/dist/core/ChromaFlow-vRCwhQpN.js +222 -0
- package/dist/core/ChromaticAberration-FTquTQIL.js +88 -0
- package/dist/core/Circle-Daziv5d7.js +67 -0
- package/dist/core/CursorTrail-Bsz9e6Fn.js +145 -0
- package/dist/core/DiffuseBlur-Cj2PtRNd.js +83 -0
- package/dist/core/Dither-D2Nf4p3w.js +66 -0
- package/dist/core/DotGrid-CzOwquo4.js +75 -0
- package/dist/core/Duotone-XuTN9tI7.js +65 -0
- package/dist/core/FilmGrain-D3-nbi12.js +28 -0
- package/dist/core/FloatingParticles-D9Nnu1qg.js +217 -0
- package/dist/core/GlassTiles-CnjCvajI.js +69 -0
- package/dist/core/Glow-BluFc9be.js +75 -0
- package/dist/core/Godrays-ChLh_vGl.js +144 -0
- package/dist/core/Grayscale-DRny75A9.js +20 -0
- package/dist/core/Grid-DgyDa4H1.js +58 -0
- package/dist/core/GridDistortion-BAspCYvp.js +188 -0
- package/dist/core/Group-Dul7PUBl.js +14 -0
- package/dist/core/Halftone-Ifv5F_FT.js +65 -0
- package/dist/core/HueShift-De8ukMWs.js +31 -0
- package/dist/core/ImageTexture-DvYcQgJB.js +143 -0
- package/dist/core/Invert-Fz0NtIJc.js +21 -0
- package/dist/core/LinearBlur-LmhnQoA4.js +62 -0
- package/dist/core/LinearGradient-xbloQjzt.js +133 -0
- package/dist/core/Liquify-DMe1V5-O.js +175 -0
- package/dist/core/Pixelate-Cv8537Pj.js +37 -0
- package/dist/core/PolarCoordinates-DDvDhBE-.js +112 -0
- package/dist/core/Posterize-3m3xkWOz.js +29 -0
- package/dist/core/ProgressiveBlur-EGkevObV.js +121 -0
- package/dist/core/RadialGradient-B7ZZB_VJ.js +71 -0
- package/dist/core/RectangularCoordinates-muWR8mZS.js +101 -0
- package/dist/core/Ripples-8XaZaXQF.js +117 -0
- package/dist/core/Saturation-CYFI1jzN.js +30 -0
- package/dist/core/SimplexNoise-DJUe0wz_.js +99 -0
- package/dist/core/SineWave-Dl3nFO1W.js +120 -0
- package/dist/core/SolidColor-CWGq_Bjq.js +21 -0
- package/dist/core/Spherize-C-jZEUsN.js +128 -0
- package/dist/core/Spiral-BSB_R39p.js +132 -0
- package/dist/core/Strands-0stO5BMy.js +161 -0
- package/dist/core/Stretch-B645paha.js +133 -0
- package/dist/core/Swirl-CVnbawit.js +173 -0
- package/dist/core/TiltShift-0CxNRI6L.js +134 -0
- package/dist/core/Tritone-Daa-I5UD.js +76 -0
- package/dist/core/Twirl-2CJVZEtk.js +96 -0
- package/dist/core/Vibrance-DRtecEvb.js +30 -0
- package/dist/core/WaveDistortion-BscXN2rs.js +173 -0
- package/dist/core/ZoomBlur-CAqK0Kju.js +62 -0
- package/dist/core/colorMixing-BXiTAqJU.js +69 -0
- package/dist/core/edges-Bn_OIa_h.js +26 -0
- package/dist/core/index.js +2257 -1606
- package/dist/core/shaders/AngularBlur/index.js +3 -7
- package/dist/core/shaders/Ascii/index.js +2 -6
- package/dist/core/shaders/Beam/index.js +4 -8
- package/dist/core/shaders/Blob/index.js +5 -9
- package/dist/core/shaders/Blur/index.js +2 -6
- package/dist/core/shaders/Bulge/index.js +4 -8
- package/dist/core/shaders/CRTScreen/index.js +2 -6
- package/dist/core/shaders/ChannelBlur/index.js +2 -6
- package/dist/core/shaders/Checkerboard/index.js +4 -8
- package/dist/core/shaders/ChromaFlow/index.js +3 -7
- package/dist/core/shaders/ChromaticAberration/index.js +3 -7
- package/dist/core/shaders/Circle/index.js +3 -7
- package/dist/core/shaders/CursorTrail/index.js +4 -8
- package/dist/core/shaders/DiffuseBlur/index.js +4 -8
- package/dist/core/shaders/Dither/index.js +3 -7
- package/dist/core/shaders/DotGrid/index.js +3 -7
- package/dist/core/shaders/Duotone/index.js +4 -8
- package/dist/core/shaders/FilmGrain/index.js +2 -6
- package/dist/core/shaders/FloatingParticles/index.js +3 -7
- package/dist/core/shaders/GlassTiles/index.js +2 -6
- package/dist/core/shaders/Glow/index.js +2 -6
- package/dist/core/shaders/Godrays/index.js +3 -7
- package/dist/core/shaders/Grayscale/index.js +2 -8
- package/dist/core/shaders/Grid/index.js +3 -7
- package/dist/core/shaders/GridDistortion/index.js +4 -8
- package/dist/core/shaders/Group/index.js +2 -6
- package/dist/core/shaders/Halftone/index.js +3 -7
- package/dist/core/shaders/HueShift/index.js +2 -8
- package/dist/core/shaders/ImageTexture/index.js +2 -6
- package/dist/core/shaders/Invert/index.js +2 -6
- package/dist/core/shaders/LinearBlur/index.js +3 -7
- package/dist/core/shaders/LinearGradient/index.js +4 -8
- package/dist/core/shaders/Liquify/index.js +4 -8
- package/dist/core/shaders/Pixelate/index.js +2 -6
- package/dist/core/shaders/PolarCoordinates/index.js +4 -8
- package/dist/core/shaders/Posterize/index.js +2 -7
- package/dist/core/shaders/ProgressiveBlur/index.js +3 -7
- package/dist/core/shaders/RadialGradient/index.js +4 -8
- package/dist/core/shaders/RectangularCoordinates/index.js +4 -8
- package/dist/core/shaders/Ripples/index.js +5 -9
- package/dist/core/shaders/Saturation/index.js +2 -8
- package/dist/core/shaders/SimplexNoise/index.js +5 -9
- package/dist/core/shaders/SineWave/index.js +3 -7
- package/dist/core/shaders/SolidColor/index.js +3 -7
- package/dist/core/shaders/Spherize/index.js +3 -7
- package/dist/core/shaders/Spiral/index.js +4 -8
- package/dist/core/shaders/Strands/index.js +4 -8
- package/dist/core/shaders/Stretch/index.js +4 -8
- package/dist/core/shaders/Swirl/index.js +5 -9
- package/dist/core/shaders/TiltShift/index.js +3 -7
- package/dist/core/shaders/Tritone/index.js +4 -8
- package/dist/core/shaders/Twirl/index.js +4 -8
- package/dist/core/shaders/Vibrance/index.js +2 -8
- package/dist/core/shaders/WaveDistortion/index.js +4 -8
- package/dist/core/shaders/ZoomBlur/index.js +3 -7
- package/dist/core/telemetry/index.js +189 -157
- package/dist/core/time-CTJvRUZ4.js +10 -0
- package/dist/core/transformations-DxfQXZWi.js +4715 -0
- package/dist/react/generatePresetCode-CCibXbtZ.js +645 -0
- package/dist/react/index.js +7645 -104827
- package/dist/react/utils/generatePresetCode.js +2 -5
- package/dist/solid/index.js +6670 -102727
- package/dist/solid/utils/generatePresetCode.js +583 -554
- package/dist/svelte/generatePresetCode-CymgoDq_.js +645 -0
- package/dist/svelte/index.js +6175 -102645
- package/dist/svelte/utils/generatePresetCode.js +2 -5
- package/dist/vue/generatePresetCode-CRJmU8iF.js +649 -0
- package/dist/vue/index.js +6929 -103706
- package/dist/vue/utils/generatePresetCode.js +2 -5
- package/package.json +4 -1
- package/dist/core/AngularBlur-ClvtyURQ.js +0 -56
- package/dist/core/Ascii-BT0-K_vw.js +0 -196
- package/dist/core/Beam-BAKql1AP.js +0 -116
- package/dist/core/Blob-CVSxhHJG.js +0 -169
- package/dist/core/Blur-C1TTBHCX.js +0 -64
- package/dist/core/Bulge-DV8tX-cw.js +0 -103
- package/dist/core/CRTScreen-VTJQoOeq.js +0 -91
- package/dist/core/ChannelBlur-BLZ9kBNA.js +0 -89
- package/dist/core/Checkerboard-DQ4Df3vm.js +0 -75
- package/dist/core/ChromaFlow-BggN1_Av.js +0 -134
- package/dist/core/ChromaticAberration-DlTaHNcp.js +0 -82
- package/dist/core/Circle-B9ObWlq5.js +0 -62
- package/dist/core/ColorAdjustment-FeXXpypd.js +0 -14
- package/dist/core/CursorTrail-C7QdUj8O.js +0 -105
- package/dist/core/DiffuseBlur-Mx6LBsqz.js +0 -69
- package/dist/core/Dither-CeIdV_9C.js +0 -61
- package/dist/core/DotGrid-D6xUvYrt.js +0 -61
- package/dist/core/Duotone-C2Pqt2gR.js +0 -66
- package/dist/core/FilmGrain-CJ9n_fgk.js +0 -28
- package/dist/core/FloatingParticles-iGtMs44K.js +0 -160
- package/dist/core/GlassTiles-D_lVyag2.js +0 -52
- package/dist/core/Glow-B0jj-6OC.js +0 -66
- package/dist/core/Godrays-DjLVuZa4.js +0 -105
- package/dist/core/Grayscale-BbsdDa_X.js +0 -21
- package/dist/core/Grid-ByjU-_ua.js +0 -50
- package/dist/core/GridDistortion-C_eIlhkW.js +0 -147
- package/dist/core/Group-CyaDLGpI.js +0 -17
- package/dist/core/Halftone-BvuAe_k-.js +0 -55
- package/dist/core/HueShift-B_qE9c08.js +0 -32
- package/dist/core/ImageTexture-h00TFC1l.js +0 -105
- package/dist/core/Invert-BEDDB0sm.js +0 -20
- package/dist/core/LinearBlur-CLKxuyeT.js +0 -56
- package/dist/core/LinearGradient-BPo8TX_M.js +0 -111
- package/dist/core/Liquify-DGkfeixZ.js +0 -139
- package/dist/core/Pixelate-Bzy_7LnJ.js +0 -38
- package/dist/core/PolarCoordinates-BUumPeTv.js +0 -103
- package/dist/core/Posterize-ggKIJlmm.js +0 -46
- package/dist/core/ProgressiveBlur-D6_6T7SS.js +0 -102
- package/dist/core/RadialGradient-DEY9fRqa.js +0 -71
- package/dist/core/RectangularCoordinates-CZ-cFrCh.js +0 -92
- package/dist/core/Ripples-BwNlcsnV.js +0 -106
- package/dist/core/Saturation-Dl3gCWuZ.js +0 -31
- package/dist/core/SimplexNoise-BhE_WyGt.js +0 -94
- package/dist/core/SineWave-Db_Y0Mcv.js +0 -107
- package/dist/core/SolidColor-CerOp4EQ.js +0 -22
- package/dist/core/Spherize-Dh8E5XwG.js +0 -103
- package/dist/core/Spiral-BvygQEfP.js +0 -115
- package/dist/core/Strands-maaPn4On.js +0 -125
- package/dist/core/Stretch-CnA0-nSz.js +0 -103
- package/dist/core/Swirl-CQBUahTB.js +0 -148
- package/dist/core/TSLBase-Bt7Z4hv_.js +0 -8053
- package/dist/core/TiltShift-qFj0oFzN.js +0 -114
- package/dist/core/Tritone-AiixmTg8.js +0 -75
- package/dist/core/Twirl-ooHQcV89.js +0 -82
- package/dist/core/Vibrance-C2FRlLkK.js +0 -31
- package/dist/core/WaveDistortion-CN8MjKlm.js +0 -132
- package/dist/core/ZoomBlur-CxWGx8PH.js +0 -56
- package/dist/core/colorMixing--dhzx0ch.js +0 -21
- package/dist/core/edges-CDzKsauJ.js +0 -15
- package/dist/core/three.tsl-Btj1hLsf.js +0 -43845
- package/dist/core/time-DbRMw6Jm.js +0 -10
- package/dist/core/transformations-CsrIJXh-.js +0 -3992
- package/dist/react/generatePresetCode-CVj6IV8Y.js +0 -646
- package/dist/svelte/generatePresetCode-CVj6IV8Y.js +0 -646
- package/dist/vue/generatePresetCode-DCaIsDhE.js +0 -652
package/dist/core/index.js
CHANGED
|
@@ -1,1650 +1,2301 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import "./
|
|
5
|
-
import { n as
|
|
6
|
-
import
|
|
7
|
-
import "./
|
|
8
|
-
import { n as
|
|
9
|
-
import { n as
|
|
10
|
-
import { n as
|
|
11
|
-
import { n as
|
|
12
|
-
import { n as
|
|
13
|
-
import { n as
|
|
14
|
-
import { n as
|
|
15
|
-
import { n as
|
|
16
|
-
import { n as
|
|
17
|
-
import { n as
|
|
18
|
-
import { n as
|
|
19
|
-
import { n as
|
|
20
|
-
import { n as
|
|
21
|
-
import { n as
|
|
22
|
-
import { n as
|
|
23
|
-
import { n as
|
|
24
|
-
import { n as
|
|
25
|
-
import { n as
|
|
26
|
-
import { n as
|
|
27
|
-
import { n as
|
|
28
|
-
import "./
|
|
29
|
-
import "./
|
|
30
|
-
import { n as
|
|
31
|
-
import { n as
|
|
32
|
-
import { n as
|
|
33
|
-
import { n as
|
|
34
|
-
import { n as
|
|
35
|
-
import { n as
|
|
36
|
-
import { n as
|
|
37
|
-
import { n as
|
|
38
|
-
import { n as
|
|
39
|
-
import { n as
|
|
40
|
-
import { n as
|
|
41
|
-
import { n as
|
|
42
|
-
import { n as
|
|
43
|
-
import { n as
|
|
44
|
-
import { n as $
|
|
45
|
-
import { n as
|
|
46
|
-
import { n as
|
|
47
|
-
import { n as
|
|
48
|
-
import { n as
|
|
49
|
-
import { n as
|
|
50
|
-
import { n as
|
|
51
|
-
import { n as
|
|
52
|
-
import { n as
|
|
53
|
-
import { n as
|
|
54
|
-
import { n as
|
|
55
|
-
import { n as
|
|
56
|
-
import { n as
|
|
57
|
-
import { n as
|
|
58
|
-
import { n as
|
|
59
|
-
import { n as
|
|
60
|
-
import {
|
|
61
|
-
import {
|
|
62
|
-
import
|
|
63
|
-
import {
|
|
64
|
-
function
|
|
65
|
-
|
|
66
|
-
|
|
1
|
+
import { n as applyEdgeToUV, t as applyEdgeHandling } from "./edges-Bn_OIa_h.js";
|
|
2
|
+
import { t as createAnimatedTime } from "./time-CTJvRUZ4.js";
|
|
3
|
+
import "./transformations-DxfQXZWi.js";
|
|
4
|
+
import { n as componentDefinition } from "./AngularBlur-Dl2gwk68.js";
|
|
5
|
+
import { n as componentDefinition$1 } from "./Ascii-Dha_QpT3.js";
|
|
6
|
+
import "./colorMixing-BXiTAqJU.js";
|
|
7
|
+
import { n as componentDefinition$2 } from "./Beam-CTN9Ni43.js";
|
|
8
|
+
import { n as componentDefinition$3 } from "./Blob-CxFDZovO.js";
|
|
9
|
+
import { n as componentDefinition$4 } from "./Blur-Y2FsmFk_.js";
|
|
10
|
+
import { n as componentDefinition$5 } from "./Bulge-Cb-t0xqI.js";
|
|
11
|
+
import { n as componentDefinition$6 } from "./ChannelBlur-CvM6GJgZ.js";
|
|
12
|
+
import { n as componentDefinition$7 } from "./Checkerboard-CgB-egNY.js";
|
|
13
|
+
import { n as componentDefinition$8 } from "./ChromaFlow-vRCwhQpN.js";
|
|
14
|
+
import { n as componentDefinition$9 } from "./ChromaticAberration-FTquTQIL.js";
|
|
15
|
+
import { n as componentDefinition$10 } from "./Circle-Daziv5d7.js";
|
|
16
|
+
import { n as componentDefinition$11 } from "./CRTScreen-CtERsenz.js";
|
|
17
|
+
import { n as componentDefinition$12 } from "./CursorTrail-Bsz9e6Fn.js";
|
|
18
|
+
import { n as componentDefinition$13 } from "./DiffuseBlur-Cj2PtRNd.js";
|
|
19
|
+
import { n as componentDefinition$14 } from "./Dither-D2Nf4p3w.js";
|
|
20
|
+
import { n as componentDefinition$15 } from "./DotGrid-CzOwquo4.js";
|
|
21
|
+
import { n as componentDefinition$16 } from "./Duotone-XuTN9tI7.js";
|
|
22
|
+
import { n as componentDefinition$17 } from "./FilmGrain-D3-nbi12.js";
|
|
23
|
+
import { n as componentDefinition$18 } from "./FloatingParticles-D9Nnu1qg.js";
|
|
24
|
+
import { n as componentDefinition$19 } from "./GlassTiles-CnjCvajI.js";
|
|
25
|
+
import { n as componentDefinition$20 } from "./Glow-BluFc9be.js";
|
|
26
|
+
import { n as componentDefinition$21 } from "./Godrays-ChLh_vGl.js";
|
|
27
|
+
import { n as componentDefinition$22 } from "./Grayscale-DRny75A9.js";
|
|
28
|
+
import { n as componentDefinition$23 } from "./Grid-DgyDa4H1.js";
|
|
29
|
+
import { n as componentDefinition$24 } from "./GridDistortion-BAspCYvp.js";
|
|
30
|
+
import { n as componentDefinition$25 } from "./Group-Dul7PUBl.js";
|
|
31
|
+
import { n as componentDefinition$26 } from "./Halftone-Ifv5F_FT.js";
|
|
32
|
+
import { n as componentDefinition$27 } from "./HueShift-De8ukMWs.js";
|
|
33
|
+
import { n as componentDefinition$28 } from "./ImageTexture-DvYcQgJB.js";
|
|
34
|
+
import { n as componentDefinition$29 } from "./Invert-Fz0NtIJc.js";
|
|
35
|
+
import { n as componentDefinition$30 } from "./LinearBlur-LmhnQoA4.js";
|
|
36
|
+
import { n as componentDefinition$31 } from "./LinearGradient-xbloQjzt.js";
|
|
37
|
+
import { n as componentDefinition$32 } from "./Liquify-DMe1V5-O.js";
|
|
38
|
+
import { n as componentDefinition$33 } from "./Pixelate-Cv8537Pj.js";
|
|
39
|
+
import { n as componentDefinition$34 } from "./PolarCoordinates-DDvDhBE-.js";
|
|
40
|
+
import { n as componentDefinition$35 } from "./Posterize-3m3xkWOz.js";
|
|
41
|
+
import { n as componentDefinition$36 } from "./ProgressiveBlur-EGkevObV.js";
|
|
42
|
+
import { n as componentDefinition$37 } from "./RadialGradient-B7ZZB_VJ.js";
|
|
43
|
+
import { n as componentDefinition$38 } from "./RectangularCoordinates-muWR8mZS.js";
|
|
44
|
+
import { n as componentDefinition$39 } from "./Ripples-8XaZaXQF.js";
|
|
45
|
+
import { n as componentDefinition$40 } from "./Saturation-CYFI1jzN.js";
|
|
46
|
+
import { n as componentDefinition$41 } from "./SimplexNoise-DJUe0wz_.js";
|
|
47
|
+
import { n as componentDefinition$42 } from "./SineWave-Dl3nFO1W.js";
|
|
48
|
+
import { n as componentDefinition$43 } from "./SolidColor-CWGq_Bjq.js";
|
|
49
|
+
import { n as componentDefinition$44 } from "./Spherize-C-jZEUsN.js";
|
|
50
|
+
import { n as componentDefinition$45 } from "./Spiral-BSB_R39p.js";
|
|
51
|
+
import { n as componentDefinition$46 } from "./Strands-0stO5BMy.js";
|
|
52
|
+
import { n as componentDefinition$47 } from "./Stretch-B645paha.js";
|
|
53
|
+
import { n as componentDefinition$48 } from "./Swirl-CVnbawit.js";
|
|
54
|
+
import { n as componentDefinition$49 } from "./TiltShift-0CxNRI6L.js";
|
|
55
|
+
import { n as componentDefinition$50 } from "./Tritone-Daa-I5UD.js";
|
|
56
|
+
import { n as componentDefinition$51 } from "./Twirl-2CJVZEtk.js";
|
|
57
|
+
import { n as componentDefinition$52 } from "./Vibrance-DRtecEvb.js";
|
|
58
|
+
import { n as componentDefinition$53 } from "./WaveDistortion-BscXN2rs.js";
|
|
59
|
+
import { n as componentDefinition$54 } from "./ZoomBlur-CAqK0Kju.js";
|
|
60
|
+
import { Material, Mesh, MeshBasicNodeMaterial, OrthographicCamera, PlaneGeometry, SRGBColorSpace, Scene, WebGPURenderer } from "three/webgpu";
|
|
61
|
+
import { WebGLRenderer } from "three";
|
|
62
|
+
import * as TSL from "three/tsl";
|
|
63
|
+
import { abs, add, atan, convertToTexture, cos, div, dot, float, max, min, mix, mul, pow, screenUV, sin, sqrt, step, sub, uniform, vec3, vec4, viewportSize } from "three/tsl";
|
|
64
|
+
function normal_default(base, overlay, opacity = 1) {
|
|
65
|
+
const overlayAlpha = mul(overlay.a, opacity);
|
|
66
|
+
const finalAlpha = add(overlayAlpha, mul(base.a, sub(1, overlayAlpha)));
|
|
67
|
+
return vec4(add(mul(overlay.rgb, overlayAlpha), mul(base.rgb, mul(base.a, sub(1, overlayAlpha)))), finalAlpha);
|
|
67
68
|
}
|
|
68
|
-
var
|
|
69
|
-
|
|
70
|
-
return N(d.mul(0.2104542553).add(k.mul(0.793617785)).sub(U.mul(0.0040720468)), d.mul(1.9779984951).sub(k.mul(2.428592205)).add(U.mul(0.4505937099)), d.mul(0.0259040371).add(k.mul(0.7827717662)).sub(U.mul(0.808675766)));
|
|
71
|
-
}, tr = (e) => {
|
|
72
|
-
const n = e.x, s = e.y, t = e.z, u = n.add(s.mul(0.3963377774)).add(t.mul(0.2158037573)), p = n.sub(s.mul(0.1055613458)).sub(t.mul(0.0638541728)), h = n.sub(s.mul(0.0894841775)).sub(t.mul(1.291485548)), d = W(u, j(3)), k = W(p, j(3)), U = W(h, j(3));
|
|
73
|
-
return N(d.mul(4.0767416621).sub(k.mul(3.3077115913)).add(U.mul(0.2309699292)), d.mul(-1.2684380046).add(k.mul(2.6097574011)).sub(U.mul(0.3413193965)), d.mul(-0.0041960863).sub(k.mul(0.7034186147)).add(U.mul(1.707614701)));
|
|
74
|
-
}, un = (e) => {
|
|
75
|
-
const n = e.x, s = e.y, t = e.z;
|
|
76
|
-
return N(n, vn(s.mul(s).add(t.mul(t))), Hn(t, s));
|
|
77
|
-
}, rr = (e) => {
|
|
78
|
-
const n = e.x, s = e.y, t = e.z;
|
|
79
|
-
return N(n, s.mul(jn(t)), s.mul(Vn(t)));
|
|
69
|
+
var p3ToSRGB$1 = (p3) => {
|
|
70
|
+
return vec3(p3.x.mul(1.2249401).sub(p3.y.mul(.2249404)).sub(p3.z.mul(0)), p3.x.mul(-.0420569).add(p3.y.mul(1.0420571)).add(p3.z.mul(0)), p3.x.mul(-.0196376).sub(p3.y.mul(.0786361)).add(p3.z.mul(1.0982735)));
|
|
80
71
|
};
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
72
|
+
var sRGBToP3$1 = (srgb) => {
|
|
73
|
+
return vec3(srgb.x.mul(.8224621).add(srgb.y.mul(.177538)).add(srgb.z.mul(0)), srgb.x.mul(.0331941).add(srgb.y.mul(.9668058)).add(srgb.z.mul(0)), srgb.x.mul(.0170826).add(srgb.y.mul(.0723974)).add(srgb.z.mul(.9105199)));
|
|
74
|
+
};
|
|
75
|
+
var rgbToOklab$1 = (rgb) => {
|
|
76
|
+
const r = rgb.x;
|
|
77
|
+
const g = rgb.y;
|
|
78
|
+
const b = rgb.z;
|
|
79
|
+
const l = r.mul(.4122214708).add(g.mul(.5363325363)).add(b.mul(.0514459929));
|
|
80
|
+
const m = r.mul(.2119034982).add(g.mul(.6806995451).add(b.mul(.1073969566)));
|
|
81
|
+
const s = r.mul(.0883024619).add(g.mul(.2817188376)).add(b.mul(.6299787005));
|
|
82
|
+
const l_ = pow(l, float(1 / 3));
|
|
83
|
+
const m_ = pow(m, float(1 / 3));
|
|
84
|
+
const s_ = pow(s, float(1 / 3));
|
|
85
|
+
return vec3(l_.mul(.2104542553).add(m_.mul(.793617785)).sub(s_.mul(.0040720468)), l_.mul(1.9779984951).sub(m_.mul(2.428592205)).add(s_.mul(.4505937099)), l_.mul(.0259040371).add(m_.mul(.7827717662)).sub(s_.mul(.808675766)));
|
|
86
|
+
};
|
|
87
|
+
var oklabToRgb$1 = (lab) => {
|
|
88
|
+
const L = lab.x;
|
|
89
|
+
const a = lab.y;
|
|
90
|
+
const b = lab.z;
|
|
91
|
+
const l_ = L.add(a.mul(.3963377774)).add(b.mul(.2158037573));
|
|
92
|
+
const m_ = L.sub(a.mul(.1055613458)).sub(b.mul(.0638541728));
|
|
93
|
+
const s_ = L.sub(a.mul(.0894841775)).sub(b.mul(1.291485548));
|
|
94
|
+
const l = pow(l_, float(3));
|
|
95
|
+
const m = pow(m_, float(3));
|
|
96
|
+
const s = pow(s_, float(3));
|
|
97
|
+
return vec3(l.mul(4.0767416621).sub(m.mul(3.3077115913)).add(s.mul(.2309699292)), l.mul(-1.2684380046).add(m.mul(2.6097574011)).sub(s.mul(.3413193965)), l.mul(-.0041960863).sub(m.mul(.7034186147)).add(s.mul(1.707614701)));
|
|
98
|
+
};
|
|
99
|
+
var oklabToOklch = (lab) => {
|
|
100
|
+
const L = lab.x;
|
|
101
|
+
const a = lab.y;
|
|
102
|
+
const b = lab.z;
|
|
103
|
+
return vec3(L, sqrt(a.mul(a).add(b.mul(b))), atan(b, a));
|
|
104
|
+
};
|
|
105
|
+
var oklchToOklab = (lch) => {
|
|
106
|
+
const L = lch.x;
|
|
107
|
+
const C = lch.y;
|
|
108
|
+
const h = lch.z;
|
|
109
|
+
return vec3(L, C.mul(cos(h)), C.mul(sin(h)));
|
|
110
|
+
};
|
|
111
|
+
function normal_oklch_default(base, overlay, opacity = 1) {
|
|
112
|
+
const overlayAlpha = mul(overlay.a, opacity);
|
|
113
|
+
const finalAlpha = add(overlayAlpha, mul(base.a, sub(1, overlayAlpha)));
|
|
114
|
+
const baseSRGB = p3ToSRGB$1(vec3(base.r, base.g, base.b));
|
|
115
|
+
const overlaySRGB = p3ToSRGB$1(vec3(overlay.r, overlay.g, overlay.b));
|
|
116
|
+
const baseOklab = rgbToOklab$1(baseSRGB);
|
|
117
|
+
const overlayOklab = rgbToOklab$1(overlaySRGB);
|
|
118
|
+
const baseOklch = oklabToOklch(baseOklab);
|
|
119
|
+
return vec4(sRGBToP3$1(oklabToRgb$1(oklchToOklab(add(mul(oklabToOklch(overlayOklab), overlayAlpha), mul(baseOklch, mul(base.a, sub(1, overlayAlpha))))))), finalAlpha);
|
|
84
120
|
}
|
|
85
|
-
var
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
121
|
+
var p3ToSRGB = (p3) => {
|
|
122
|
+
return vec3(p3.x.mul(1.2249401).sub(p3.y.mul(.2249404)).sub(p3.z.mul(0)), p3.x.mul(-.0420569).add(p3.y.mul(1.0420571)).add(p3.z.mul(0)), p3.x.mul(-.0196376).sub(p3.y.mul(.0786361)).add(p3.z.mul(1.0982735)));
|
|
123
|
+
};
|
|
124
|
+
var sRGBToP3 = (srgb) => {
|
|
125
|
+
return vec3(srgb.x.mul(.8224621).add(srgb.y.mul(.177538)).add(srgb.z.mul(0)), srgb.x.mul(.0331941).add(srgb.y.mul(.9668058)).add(srgb.z.mul(0)), srgb.x.mul(.0170826).add(srgb.y.mul(.0723974)).add(srgb.z.mul(.9105199)));
|
|
126
|
+
};
|
|
127
|
+
var rgbToOklab = (rgb) => {
|
|
128
|
+
const r = rgb.x;
|
|
129
|
+
const g = rgb.y;
|
|
130
|
+
const b = rgb.z;
|
|
131
|
+
const l = r.mul(.4122214708).add(g.mul(.5363325363)).add(b.mul(.0514459929));
|
|
132
|
+
const m = r.mul(.2119034982).add(g.mul(.6806995451).add(b.mul(.1073969566)));
|
|
133
|
+
const s = r.mul(.0883024619).add(g.mul(.2817188376)).add(b.mul(.6299787005));
|
|
134
|
+
const l_ = pow(l, float(1 / 3));
|
|
135
|
+
const m_ = pow(m, float(1 / 3));
|
|
136
|
+
const s_ = pow(s, float(1 / 3));
|
|
137
|
+
return vec3(l_.mul(.2104542553).add(m_.mul(.793617785)).sub(s_.mul(.0040720468)), l_.mul(1.9779984951).sub(m_.mul(2.428592205)).add(s_.mul(.4505937099)), l_.mul(.0259040371).add(m_.mul(.7827717662)).sub(s_.mul(.808675766)));
|
|
91
138
|
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
139
|
+
var oklabToRgb = (lab) => {
|
|
140
|
+
const L = lab.x;
|
|
141
|
+
const a = lab.y;
|
|
142
|
+
const b = lab.z;
|
|
143
|
+
const l_ = L.add(a.mul(.3963377774)).add(b.mul(.2158037573));
|
|
144
|
+
const m_ = L.sub(a.mul(.1055613458)).sub(b.mul(.0638541728));
|
|
145
|
+
const s_ = L.sub(a.mul(.0894841775)).sub(b.mul(1.291485548));
|
|
146
|
+
const l = pow(l_, float(3));
|
|
147
|
+
const m = pow(m_, float(3));
|
|
148
|
+
const s = pow(s_, float(3));
|
|
149
|
+
return vec3(l.mul(4.0767416621).sub(m.mul(3.3077115913)).add(s.mul(.2309699292)), l.mul(-1.2684380046).add(m.mul(2.6097574011)).sub(s.mul(.3413193965)), l.mul(-.0041960863).sub(m.mul(.7034186147)).add(s.mul(1.707614701)));
|
|
150
|
+
};
|
|
151
|
+
function normal_oklab_default(base, overlay, opacity = 1) {
|
|
152
|
+
const overlayAlpha = mul(overlay.a, opacity);
|
|
153
|
+
const finalAlpha = add(overlayAlpha, mul(base.a, sub(1, overlayAlpha)));
|
|
154
|
+
const baseSRGB = p3ToSRGB(vec3(base.r, base.g, base.b));
|
|
155
|
+
const overlaySRGB = p3ToSRGB(vec3(overlay.r, overlay.g, overlay.b));
|
|
156
|
+
const baseOklab = rgbToOklab(baseSRGB);
|
|
157
|
+
return vec4(sRGBToP3(oklabToRgb(add(mul(rgbToOklab(overlaySRGB), overlayAlpha), mul(baseOklab, mul(base.a, sub(1, overlayAlpha)))))), finalAlpha);
|
|
95
158
|
}
|
|
96
|
-
function
|
|
97
|
-
|
|
98
|
-
|
|
159
|
+
function multiply_default(base, overlay, opacity = 1) {
|
|
160
|
+
const overlayAlpha = mul(overlay.a, opacity);
|
|
161
|
+
const finalAlpha = add(overlayAlpha, mul(base.a, sub(1, overlayAlpha)));
|
|
162
|
+
return vec4(add(mul(mul(base.rgb, overlay.rgb), overlayAlpha), mul(base.rgb, mul(base.a, sub(1, overlayAlpha)))), finalAlpha);
|
|
99
163
|
}
|
|
100
|
-
function
|
|
101
|
-
|
|
102
|
-
|
|
164
|
+
function screen_default(base, overlay, opacity = 1) {
|
|
165
|
+
const overlayAlpha = mul(overlay.a, opacity);
|
|
166
|
+
const finalAlpha = add(overlayAlpha, mul(base.a, sub(1, overlayAlpha)));
|
|
167
|
+
return vec4(add(mul(sub(1, mul(sub(1, base.rgb), sub(1, overlay.rgb))), overlayAlpha), mul(base.rgb, mul(base.a, sub(1, overlayAlpha)))), finalAlpha);
|
|
103
168
|
}
|
|
104
|
-
function
|
|
105
|
-
|
|
106
|
-
|
|
169
|
+
function linearDodge_default(base, overlay, opacity = 1) {
|
|
170
|
+
const overlayAlpha = mul(overlay.a, opacity);
|
|
171
|
+
const finalAlpha = add(overlayAlpha, mul(base.a, sub(1, overlayAlpha)));
|
|
172
|
+
return vec4(add(mul(min(add(base.rgb, overlay.rgb), 1), overlayAlpha), mul(base.rgb, mul(base.a, sub(1, overlayAlpha)))), finalAlpha);
|
|
107
173
|
}
|
|
108
|
-
function
|
|
109
|
-
|
|
110
|
-
|
|
174
|
+
function overlay_default(base, overlay, opacity = 1) {
|
|
175
|
+
const overlayAlpha = mul(overlay.a, opacity);
|
|
176
|
+
const finalAlpha = add(overlayAlpha, mul(base.a, sub(1, overlayAlpha)));
|
|
177
|
+
return vec4(add(mul(mix(mul(2, mul(base.rgb, overlay.rgb)), sub(1, mul(2, mul(sub(1, base.rgb), sub(1, overlay.rgb)))), step(.5, base.rgb)), overlayAlpha), mul(base.rgb, mul(base.a, sub(1, overlayAlpha)))), finalAlpha);
|
|
111
178
|
}
|
|
112
|
-
function
|
|
113
|
-
|
|
114
|
-
|
|
179
|
+
function difference_default(base, overlay, opacity = 1) {
|
|
180
|
+
const overlayAlpha = mul(overlay.a, opacity);
|
|
181
|
+
const finalAlpha = add(overlayAlpha, mul(base.a, sub(1, overlayAlpha)));
|
|
182
|
+
return vec4(add(mul(abs(sub(base.rgb, overlay.rgb)), overlayAlpha), mul(base.rgb, mul(base.a, sub(1, overlayAlpha)))), finalAlpha);
|
|
115
183
|
}
|
|
116
|
-
function
|
|
117
|
-
|
|
118
|
-
|
|
184
|
+
function colorDodge_default(base, overlay, opacity = 1) {
|
|
185
|
+
const overlayAlpha = mul(overlay.a, opacity);
|
|
186
|
+
const finalAlpha = add(overlayAlpha, mul(base.a, sub(1, overlayAlpha)));
|
|
187
|
+
return vec4(add(mul(mix(base.rgb, min(div(base.rgb, sub(1, overlay.rgb)), 1), step(.001, sub(1, overlay.rgb))), overlayAlpha), mul(base.rgb, mul(base.a, sub(1, overlayAlpha)))), finalAlpha);
|
|
119
188
|
}
|
|
120
|
-
function
|
|
121
|
-
|
|
122
|
-
|
|
189
|
+
function exclusion_default(base, overlay, opacity = 1) {
|
|
190
|
+
const overlayAlpha = mul(overlay.a, opacity);
|
|
191
|
+
const finalAlpha = add(overlayAlpha, mul(base.a, sub(1, overlayAlpha)));
|
|
192
|
+
return vec4(add(mul(sub(add(base.rgb, overlay.rgb), mul(2, mul(base.rgb, overlay.rgb))), overlayAlpha), mul(base.rgb, mul(base.a, sub(1, overlayAlpha)))), finalAlpha);
|
|
123
193
|
}
|
|
124
|
-
function
|
|
125
|
-
|
|
194
|
+
function getLuminance(rgb) {
|
|
195
|
+
return add(add(mul(rgb.r, .2126), mul(rgb.g, .7152)), mul(rgb.b, .0722));
|
|
126
196
|
}
|
|
127
|
-
function
|
|
128
|
-
|
|
129
|
-
|
|
197
|
+
function color_default(base, overlay, opacity = 1) {
|
|
198
|
+
const overlayAlpha = mul(overlay.a, opacity);
|
|
199
|
+
const finalAlpha = add(overlayAlpha, mul(base.a, sub(1, overlayAlpha)));
|
|
200
|
+
const lumDiff = sub(getLuminance(base.rgb), getLuminance(overlay.rgb));
|
|
201
|
+
return vec4(add(mul(add(overlay.rgb, lumDiff), overlayAlpha), mul(base.rgb, mul(base.a, sub(1, overlayAlpha)))), finalAlpha);
|
|
130
202
|
}
|
|
131
|
-
function
|
|
132
|
-
|
|
133
|
-
|
|
203
|
+
function luminosity_default(base, overlay, opacity = 1) {
|
|
204
|
+
const overlayAlpha = mul(overlay.a, opacity);
|
|
205
|
+
const finalAlpha = add(overlayAlpha, mul(base.a, sub(1, overlayAlpha)));
|
|
206
|
+
const baseLum = getLuminance(base.rgb);
|
|
207
|
+
const lumRatio = getLuminance(overlay.rgb).div(add(baseLum, 1e-4));
|
|
208
|
+
return vec4(add(mul(mul(base.rgb, lumRatio), overlayAlpha), mul(base.rgb, mul(base.a, sub(1, overlayAlpha)))), finalAlpha);
|
|
134
209
|
}
|
|
135
|
-
function
|
|
136
|
-
|
|
137
|
-
|
|
210
|
+
function darken_default(base, overlay, opacity = 1) {
|
|
211
|
+
const overlayAlpha = mul(overlay.a, opacity);
|
|
212
|
+
const finalAlpha = add(overlayAlpha, mul(base.a, sub(1, overlayAlpha)));
|
|
213
|
+
return vec4(add(mul(min(base.rgb, overlay.rgb), overlayAlpha), mul(base.rgb, mul(base.a, sub(1, overlayAlpha)))), finalAlpha);
|
|
138
214
|
}
|
|
139
|
-
function
|
|
140
|
-
|
|
141
|
-
|
|
215
|
+
function lighten_default(base, overlay, opacity = 1) {
|
|
216
|
+
const overlayAlpha = mul(overlay.a, opacity);
|
|
217
|
+
const finalAlpha = add(overlayAlpha, mul(base.a, sub(1, overlayAlpha)));
|
|
218
|
+
return vec4(add(mul(max(base.rgb, overlay.rgb), overlayAlpha), mul(base.rgb, mul(base.a, sub(1, overlayAlpha)))), finalAlpha);
|
|
142
219
|
}
|
|
143
|
-
function
|
|
144
|
-
|
|
145
|
-
|
|
220
|
+
function colorBurn_default(base, overlay, opacity = 1) {
|
|
221
|
+
const overlayAlpha = mul(overlay.a, opacity);
|
|
222
|
+
const finalAlpha = add(overlayAlpha, mul(base.a, sub(1, overlayAlpha)));
|
|
223
|
+
return vec4(add(mul(mix(vec4(0, 0, 0, 1).rgb, max(sub(1, sub(1, base.rgb).div(add(overlay.rgb, 1e-4))), 0), step(1e-4, overlay.rgb)), overlayAlpha), mul(base.rgb, mul(base.a, sub(1, overlayAlpha)))), finalAlpha);
|
|
146
224
|
}
|
|
147
|
-
function
|
|
148
|
-
|
|
149
|
-
|
|
225
|
+
function linearBurn_default(base, overlay, opacity = 1) {
|
|
226
|
+
const overlayAlpha = mul(overlay.a, opacity);
|
|
227
|
+
const finalAlpha = add(overlayAlpha, mul(base.a, sub(1, overlayAlpha)));
|
|
228
|
+
return vec4(add(mul(max(add(add(base.rgb, overlay.rgb), -1), 0), overlayAlpha), mul(base.rgb, mul(base.a, sub(1, overlayAlpha)))), finalAlpha);
|
|
150
229
|
}
|
|
151
|
-
function
|
|
152
|
-
|
|
153
|
-
|
|
230
|
+
function softLight_default(base, overlay, opacity = 1) {
|
|
231
|
+
const overlayAlpha = mul(overlay.a, opacity);
|
|
232
|
+
const finalAlpha = add(overlayAlpha, mul(base.a, sub(1, overlayAlpha)));
|
|
233
|
+
const softLightDark = add(mul(2, mul(base.rgb, overlay.rgb)), mul(mul(base.rgb, base.rgb), sub(1, mul(2, overlay.rgb))));
|
|
234
|
+
const baseSqrt = sqrt(base.rgb);
|
|
235
|
+
return vec4(add(mul(mix(softLightDark, add(mul(2, mul(base.rgb, sub(1, overlay.rgb))), mul(baseSqrt, sub(mul(2, overlay.rgb), 1))), step(.5, overlay.rgb)), overlayAlpha), mul(base.rgb, mul(base.a, sub(1, overlayAlpha)))), finalAlpha);
|
|
154
236
|
}
|
|
155
|
-
function
|
|
156
|
-
|
|
157
|
-
|
|
237
|
+
function hardLight_default(base, overlay, opacity = 1) {
|
|
238
|
+
const overlayAlpha = mul(overlay.a, opacity);
|
|
239
|
+
const finalAlpha = add(overlayAlpha, mul(base.a, sub(1, overlayAlpha)));
|
|
240
|
+
return vec4(add(mul(mix(mul(2, mul(base.rgb, overlay.rgb)), sub(1, mul(2, mul(sub(1, base.rgb), sub(1, overlay.rgb)))), step(.5, overlay.rgb)), overlayAlpha), mul(base.rgb, mul(base.a, sub(1, overlayAlpha)))), finalAlpha);
|
|
158
241
|
}
|
|
159
|
-
function
|
|
160
|
-
|
|
161
|
-
|
|
242
|
+
function hue_default(base, overlay, opacity = 1) {
|
|
243
|
+
const overlayAlpha = mul(overlay.a, opacity);
|
|
244
|
+
const finalAlpha = add(overlayAlpha, mul(base.a, sub(1, overlayAlpha)));
|
|
245
|
+
const baseLum = getLuminance(base.rgb);
|
|
246
|
+
const overlayLum = getLuminance(overlay.rgb);
|
|
247
|
+
const baseChromaticity = base.rgb.sub(baseLum);
|
|
248
|
+
const overlayChromaticity = overlay.rgb.sub(overlayLum);
|
|
249
|
+
const baseChromaLength = baseChromaticity.length();
|
|
250
|
+
return vec4(add(mul(add(mul(overlayChromaticity.normalize(), baseChromaLength), baseLum), overlayAlpha), mul(base.rgb, mul(base.a, sub(1, overlayAlpha)))), finalAlpha);
|
|
162
251
|
}
|
|
163
|
-
function
|
|
164
|
-
|
|
165
|
-
|
|
252
|
+
function saturation_default(base, overlay, opacity = 1) {
|
|
253
|
+
const overlayAlpha = mul(overlay.a, opacity);
|
|
254
|
+
const finalAlpha = add(overlayAlpha, mul(base.a, sub(1, overlayAlpha)));
|
|
255
|
+
const baseLum = getLuminance(base.rgb);
|
|
256
|
+
const overlayLum = getLuminance(overlay.rgb);
|
|
257
|
+
const baseChromaticity = base.rgb.sub(baseLum);
|
|
258
|
+
const overlayChromaticity = overlay.rgb.sub(overlayLum);
|
|
259
|
+
return vec4(add(mul(add(mul(baseChromaticity.normalize(), overlayChromaticity.length()), baseLum), overlayAlpha), mul(base.rgb, mul(base.a, sub(1, overlayAlpha)))), finalAlpha);
|
|
166
260
|
}
|
|
167
|
-
var
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
261
|
+
var blendModes = {
|
|
262
|
+
normal: normal_default,
|
|
263
|
+
"normal-oklch": normal_oklch_default,
|
|
264
|
+
"normal-oklab": normal_oklab_default,
|
|
265
|
+
multiply: multiply_default,
|
|
266
|
+
screen: screen_default,
|
|
267
|
+
linearDodge: linearDodge_default,
|
|
268
|
+
overlay: overlay_default,
|
|
269
|
+
difference: difference_default,
|
|
270
|
+
colorDodge: colorDodge_default,
|
|
271
|
+
exclusion: exclusion_default,
|
|
272
|
+
color: color_default,
|
|
273
|
+
luminosity: luminosity_default,
|
|
274
|
+
darken: darken_default,
|
|
275
|
+
lighten: lighten_default,
|
|
276
|
+
colorBurn: colorBurn_default,
|
|
277
|
+
linearBurn: linearBurn_default,
|
|
278
|
+
softLight: softLight_default,
|
|
279
|
+
hardLight: hardLight_default,
|
|
280
|
+
hue: hue_default,
|
|
281
|
+
saturation: saturation_default
|
|
188
282
|
};
|
|
189
|
-
function
|
|
190
|
-
|
|
283
|
+
function applyBlendMode(baseNode, overlayNode, blendMode = "normal", opacity = 1) {
|
|
284
|
+
return (blendModes[blendMode] || blendModes.normal)(baseNode, overlayNode, opacity);
|
|
191
285
|
}
|
|
192
|
-
function
|
|
193
|
-
|
|
194
|
-
|
|
286
|
+
function alpha_default(target, mask) {
|
|
287
|
+
const maskedAlpha = mul(target.a, mask.a);
|
|
288
|
+
return vec4(target.rgb, maskedAlpha);
|
|
195
289
|
}
|
|
196
|
-
function
|
|
197
|
-
|
|
198
|
-
|
|
290
|
+
function alphaInverted_default(target, mask) {
|
|
291
|
+
const invertedMaskAlpha = sub(1, mask.a);
|
|
292
|
+
const maskedAlpha = mul(target.a, invertedMaskAlpha);
|
|
293
|
+
return vec4(target.rgb, maskedAlpha);
|
|
199
294
|
}
|
|
200
|
-
function
|
|
201
|
-
|
|
202
|
-
|
|
295
|
+
function luminance_default(target, mask) {
|
|
296
|
+
const luminanceWeights = vec3(.2126, .7152, .0722);
|
|
297
|
+
const luminance = dot(mask.rgb, luminanceWeights);
|
|
298
|
+
const maskedAlpha = mul(target.a, luminance);
|
|
299
|
+
return vec4(target.rgb, maskedAlpha);
|
|
203
300
|
}
|
|
204
|
-
function
|
|
205
|
-
|
|
206
|
-
|
|
301
|
+
function luminanceInverted_default(target, mask) {
|
|
302
|
+
const luminanceWeights = vec3(.2126, .7152, .0722);
|
|
303
|
+
const invertedLuminance = sub(1, dot(mask.rgb, luminanceWeights));
|
|
304
|
+
const maskedAlpha = mul(target.a, invertedLuminance);
|
|
305
|
+
return vec4(target.rgb, maskedAlpha);
|
|
207
306
|
}
|
|
208
|
-
var
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
307
|
+
var maskFunctions = {
|
|
308
|
+
"alpha": alpha_default,
|
|
309
|
+
"alphaInverted": alphaInverted_default,
|
|
310
|
+
"luminance": luminance_default,
|
|
311
|
+
"luminanceInverted": luminanceInverted_default
|
|
213
312
|
};
|
|
214
|
-
function
|
|
215
|
-
|
|
313
|
+
function applyMask(target, mask, maskType = "alpha") {
|
|
314
|
+
return (maskFunctions[maskType] || maskFunctions["alpha"])(target, mask);
|
|
216
315
|
}
|
|
217
|
-
var
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
|
|
316
|
+
var PerformanceTracker = class {
|
|
317
|
+
frameTimesMs = [];
|
|
318
|
+
maxSamples = 60;
|
|
319
|
+
targetFrameTime = 16.67;
|
|
320
|
+
jankFrameCount = 0;
|
|
321
|
+
totalFrameCount = 0;
|
|
322
|
+
memorySnapshots = [];
|
|
323
|
+
memoryWindowMs = 5e3;
|
|
324
|
+
nodeCount = 0;
|
|
325
|
+
rttNodeCount = 0;
|
|
326
|
+
lastCpuTime = null;
|
|
327
|
+
lastGpuTime = null;
|
|
328
|
+
isRendering = false;
|
|
329
|
+
lastFrameTimestamp = 0;
|
|
330
|
+
frameIntervals = [];
|
|
331
|
+
recordFrame(frameTimeMs) {
|
|
332
|
+
this.frameTimesMs.push(frameTimeMs);
|
|
333
|
+
if (this.frameTimesMs.length > this.maxSamples) this.frameTimesMs.shift();
|
|
334
|
+
this.totalFrameCount++;
|
|
335
|
+
if (frameTimeMs > this.targetFrameTime) this.jankFrameCount++;
|
|
336
|
+
const now = performance.now();
|
|
337
|
+
if (this.lastFrameTimestamp > 0) {
|
|
338
|
+
const interval = now - this.lastFrameTimestamp;
|
|
339
|
+
this.frameIntervals.push(interval);
|
|
340
|
+
if (this.frameIntervals.length > this.maxSamples) this.frameIntervals.shift();
|
|
341
|
+
}
|
|
342
|
+
this.lastFrameTimestamp = now;
|
|
343
|
+
this.recordMemorySnapshot();
|
|
344
|
+
}
|
|
345
|
+
recordCpuTime(timeMs) {
|
|
346
|
+
this.lastCpuTime = timeMs;
|
|
347
|
+
}
|
|
348
|
+
recordGpuTime(timeMs) {
|
|
349
|
+
this.lastGpuTime = timeMs;
|
|
350
|
+
}
|
|
351
|
+
updateNodeCounts(nodeCount, rttNodeCount) {
|
|
352
|
+
this.nodeCount = nodeCount;
|
|
353
|
+
this.rttNodeCount = rttNodeCount;
|
|
354
|
+
}
|
|
355
|
+
setRendering(rendering) {
|
|
356
|
+
this.isRendering = rendering;
|
|
357
|
+
}
|
|
358
|
+
recordMemorySnapshot() {
|
|
359
|
+
if (!performance.memory) return;
|
|
360
|
+
const now = performance.now();
|
|
361
|
+
const bytes = performance.memory.usedJSHeapSize;
|
|
362
|
+
this.memorySnapshots.push({
|
|
363
|
+
time: now,
|
|
364
|
+
bytes
|
|
365
|
+
});
|
|
366
|
+
const cutoff = now - this.memoryWindowMs;
|
|
367
|
+
this.memorySnapshots = this.memorySnapshots.filter((s) => s.time > cutoff);
|
|
368
|
+
}
|
|
369
|
+
calculateMemoryGrowthRate() {
|
|
370
|
+
if (this.memorySnapshots.length < 2) return null;
|
|
371
|
+
const oldest = this.memorySnapshots[0];
|
|
372
|
+
const newest = this.memorySnapshots[this.memorySnapshots.length - 1];
|
|
373
|
+
const timeDeltaSeconds = (newest.time - oldest.time) / 1e3;
|
|
374
|
+
return (newest.bytes - oldest.bytes) / (1024 * 1024) / timeDeltaSeconds;
|
|
375
|
+
}
|
|
376
|
+
calculateStdDev(values) {
|
|
377
|
+
if (values.length === 0) return 0;
|
|
378
|
+
const mean = values.reduce((a, b) => a + b, 0) / values.length;
|
|
379
|
+
const avgSquaredDiff = values.map((v) => Math.pow(v - mean, 2)).reduce((a, b) => a + b, 0) / values.length;
|
|
380
|
+
return Math.sqrt(avgSquaredDiff);
|
|
381
|
+
}
|
|
382
|
+
calculateP99(values) {
|
|
383
|
+
if (values.length === 0) return 0;
|
|
384
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
385
|
+
const index = Math.floor(sorted.length * .99);
|
|
386
|
+
return sorted[Math.min(index, sorted.length - 1)];
|
|
387
|
+
}
|
|
388
|
+
calculateComplexityScore() {
|
|
389
|
+
return this.nodeCount + this.rttNodeCount * 10;
|
|
390
|
+
}
|
|
391
|
+
calculateIntensityScore() {
|
|
392
|
+
const frameCount = this.frameTimesMs.length;
|
|
393
|
+
if (frameCount === 0) return {
|
|
394
|
+
score: 0,
|
|
395
|
+
label: "N/A"
|
|
396
|
+
};
|
|
397
|
+
const avgFrameTime = this.frameTimesMs.reduce((a, b) => a + b, 0) / frameCount;
|
|
398
|
+
const frameTimeScore = Math.min(avgFrameTime / 16.67 * 100, 100);
|
|
399
|
+
const complexity = this.calculateComplexityScore();
|
|
400
|
+
const complexityScore = Math.min(complexity / 100 * 100, 100);
|
|
401
|
+
let gpuTimeScore = 0;
|
|
402
|
+
if (this.lastGpuTime !== null) gpuTimeScore = Math.min(this.lastGpuTime / 16.67 * 100, 100);
|
|
403
|
+
const weights = this.lastGpuTime !== null ? {
|
|
404
|
+
frame: .4,
|
|
405
|
+
gpu: .4,
|
|
406
|
+
complexity: .2
|
|
407
|
+
} : {
|
|
408
|
+
frame: .7,
|
|
409
|
+
gpu: 0,
|
|
410
|
+
complexity: .3
|
|
411
|
+
};
|
|
412
|
+
const finalScore = Math.round(frameTimeScore * weights.frame + gpuTimeScore * weights.gpu + complexityScore * weights.complexity);
|
|
413
|
+
let label;
|
|
414
|
+
if (finalScore <= 20) label = "Very Light";
|
|
415
|
+
else if (finalScore <= 40) label = "Light";
|
|
416
|
+
else if (finalScore <= 60) label = "Medium";
|
|
417
|
+
else if (finalScore <= 80) label = "Heavy";
|
|
418
|
+
else label = "Very Heavy";
|
|
419
|
+
return {
|
|
420
|
+
score: Math.min(finalScore, 100),
|
|
421
|
+
label
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
getStats(rendererInfo) {
|
|
425
|
+
const frameCount = this.frameTimesMs.length;
|
|
426
|
+
const fps = this.frameIntervals.length > 0 ? 1e3 / (this.frameIntervals.reduce((a, b) => a + b, 0) / this.frameIntervals.length) : 0;
|
|
427
|
+
const avgFrameTime = frameCount > 0 ? this.frameTimesMs.reduce((a, b) => a + b, 0) / frameCount : 0;
|
|
428
|
+
const minFrameTime = frameCount > 0 ? Math.min(...this.frameTimesMs) : 0;
|
|
429
|
+
const maxFrameTime = frameCount > 0 ? Math.max(...this.frameTimesMs) : 0;
|
|
430
|
+
const p99FrameTime = this.calculateP99(this.frameTimesMs);
|
|
431
|
+
const stdDevFrameTime = this.calculateStdDev(this.frameTimesMs);
|
|
432
|
+
const jankPercent = this.totalFrameCount > 0 ? this.jankFrameCount / this.totalFrameCount * 100 : 0;
|
|
433
|
+
const memory = performance.memory;
|
|
434
|
+
const memoryUsedMB = memory ? memory.usedJSHeapSize / (1024 * 1024) : null;
|
|
435
|
+
const memoryGrowthRate = this.calculateMemoryGrowthRate();
|
|
436
|
+
const budgetUsed = avgFrameTime > 0 ? avgFrameTime / this.targetFrameTime * 100 : 0;
|
|
437
|
+
const drawCalls = rendererInfo?.render?.calls ?? null;
|
|
438
|
+
const shaderPrograms = rendererInfo?.programs?.length ?? null;
|
|
439
|
+
const textureCount = rendererInfo?.memory?.textures ?? null;
|
|
440
|
+
const intensity = this.calculateIntensityScore();
|
|
441
|
+
return {
|
|
442
|
+
fps: Math.round(fps),
|
|
443
|
+
avgFrameTime: Math.round(avgFrameTime * 100) / 100,
|
|
444
|
+
minFrameTime: Math.round(minFrameTime * 100) / 100,
|
|
445
|
+
maxFrameTime: Math.round(maxFrameTime * 100) / 100,
|
|
446
|
+
p99FrameTime: Math.round(p99FrameTime * 100) / 100,
|
|
447
|
+
stdDevFrameTime: Math.round(stdDevFrameTime * 100) / 100,
|
|
448
|
+
jankCount: this.jankFrameCount,
|
|
449
|
+
jankPercent: Math.round(jankPercent * 10) / 10,
|
|
450
|
+
nodeCount: this.nodeCount,
|
|
451
|
+
rttNodeCount: this.rttNodeCount,
|
|
452
|
+
complexityScore: this.calculateComplexityScore(),
|
|
453
|
+
memoryUsedMB: memoryUsedMB !== null ? Math.round(memoryUsedMB * 100) / 100 : null,
|
|
454
|
+
memoryGrowthRate: memoryGrowthRate !== null ? Math.round(memoryGrowthRate * 1e3) / 1e3 : null,
|
|
455
|
+
cpuTime: this.lastCpuTime !== null ? Math.round(this.lastCpuTime * 100) / 100 : null,
|
|
456
|
+
gpuTime: this.lastGpuTime !== null ? Math.round(this.lastGpuTime * 100) / 100 : null,
|
|
457
|
+
budgetUsed: Math.round(budgetUsed * 10) / 10,
|
|
458
|
+
drawCalls,
|
|
459
|
+
shaderPrograms,
|
|
460
|
+
textureCount,
|
|
461
|
+
intensityScore: intensity.score,
|
|
462
|
+
intensityLabel: intensity.label,
|
|
463
|
+
isRendering: this.isRendering
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
reset() {
|
|
467
|
+
this.frameTimesMs = [];
|
|
468
|
+
this.frameIntervals = [];
|
|
469
|
+
this.lastFrameTimestamp = 0;
|
|
470
|
+
this.jankFrameCount = 0;
|
|
471
|
+
this.totalFrameCount = 0;
|
|
472
|
+
this.memorySnapshots = [];
|
|
473
|
+
this.lastCpuTime = null;
|
|
474
|
+
this.lastGpuTime = null;
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
var { vec2: vec2$3, cos: cos$1, sin: sin$2, float: float$1, PI } = TSL;
|
|
478
|
+
const needsTransformation = (transform) => {
|
|
479
|
+
if (!transform) return false;
|
|
480
|
+
return transform.offsetX !== 0 || transform.offsetY !== 0 || transform.rotation !== 0 || transform.scale !== 1 || transform.anchorX !== .5 || transform.anchorY !== .5;
|
|
481
|
+
};
|
|
482
|
+
const applyUVTransform = (uv, offsetXUniform, offsetYUniform, rotationUniform, scaleUniform, anchorXUniform, anchorYUniform, aspectRatioUniform) => {
|
|
483
|
+
const rotationRad = rotationUniform.mul(PI).div(float$1(180));
|
|
484
|
+
const cosAngle = cos$1(rotationRad);
|
|
485
|
+
const sinAngle = sin$2(rotationRad);
|
|
486
|
+
const anchor = vec2$3(anchorXUniform, anchorYUniform);
|
|
487
|
+
const scaledUV = uv.sub(anchor).div(scaleUniform);
|
|
488
|
+
const squareUV = vec2$3(scaledUV.x.mul(aspectRatioUniform), scaledUV.y);
|
|
489
|
+
const rotatedSquareUV = vec2$3(squareUV.x.mul(cosAngle).sub(squareUV.y.mul(sinAngle)), squareUV.x.mul(sinAngle).add(squareUV.y.mul(cosAngle)));
|
|
490
|
+
return vec2$3(rotatedSquareUV.x.div(aspectRatioUniform), rotatedSquareUV.y).sub(vec2$3(offsetXUniform, offsetYUniform)).add(anchor);
|
|
387
491
|
};
|
|
388
|
-
var { uniform:
|
|
389
|
-
function
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
492
|
+
var { uniform: uniform$1 } = TSL;
|
|
493
|
+
function createUniformsMap(component, reactiveProps, instanceId) {
|
|
494
|
+
const uniformsMap = {};
|
|
495
|
+
Object.entries(component.props).forEach(([propName, propConfig]) => {
|
|
496
|
+
const initialValue = reactiveProps[propName];
|
|
497
|
+
let uniformValue = initialValue;
|
|
498
|
+
if (propConfig.transform) {
|
|
499
|
+
const transformed = propConfig.transform(initialValue);
|
|
500
|
+
uniformValue = transformed?.node ?? transformed;
|
|
501
|
+
}
|
|
502
|
+
if (uniformValue === null || uniformValue === void 0) {
|
|
503
|
+
uniformValue = propConfig.default;
|
|
504
|
+
if (propConfig.transform && uniformValue !== null && uniformValue !== void 0) {
|
|
505
|
+
const transformed = propConfig.transform(uniformValue);
|
|
506
|
+
uniformValue = transformed?.node ?? transformed;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
if (uniformValue === null || uniformValue === void 0) {
|
|
510
|
+
console.error(`[Shaders] Uniform "${propName}" is null/undefined after fallback. PropConfig:`, {
|
|
511
|
+
propName,
|
|
512
|
+
initialValue,
|
|
513
|
+
default: propConfig.default,
|
|
514
|
+
hasTransform: !!propConfig.transform
|
|
515
|
+
});
|
|
516
|
+
uniformValue = 0;
|
|
517
|
+
}
|
|
518
|
+
const uniformNode = uniform$1(uniformValue).setName(`${propName}_${instanceId}`);
|
|
519
|
+
if (typeof uniformValue === "string" && uniformNode.value === null) uniformNode.value = uniformValue;
|
|
520
|
+
uniformsMap[propName] = {
|
|
521
|
+
uniform: uniformNode,
|
|
522
|
+
transform: propConfig.transform || void 0
|
|
523
|
+
};
|
|
524
|
+
});
|
|
525
|
+
return uniformsMap;
|
|
414
526
|
}
|
|
415
|
-
function
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
527
|
+
function updateUniformValue(uniform$2, newValue) {
|
|
528
|
+
if (uniform$2?.transform) {
|
|
529
|
+
const transformed = uniform$2.transform(newValue);
|
|
530
|
+
const dataValue = transformed?.data ?? transformed;
|
|
531
|
+
uniform$2.uniform.value = dataValue;
|
|
532
|
+
} else uniform$2.uniform.value = newValue;
|
|
420
533
|
}
|
|
421
|
-
var
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
534
|
+
var hasLoggedLicenseInfo = false;
|
|
535
|
+
var globalEventManager = (() => {
|
|
536
|
+
let instanceCount = 0;
|
|
537
|
+
const callbacks = /* @__PURE__ */ new Set();
|
|
538
|
+
const globalMouseMoveHandler = (e) => {
|
|
539
|
+
callbacks.forEach((cb) => {
|
|
540
|
+
try {
|
|
541
|
+
cb.onMouseMove(e);
|
|
542
|
+
} catch (error) {
|
|
543
|
+
console.error("[Shaders] Error in mouse move handler:", error);
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
};
|
|
547
|
+
const globalTouchMoveHandler = (e) => {
|
|
548
|
+
callbacks.forEach((cb) => {
|
|
549
|
+
try {
|
|
550
|
+
cb.onTouchMove(e);
|
|
551
|
+
} catch (error) {
|
|
552
|
+
console.error("[Shaders] Error in touch move handler:", error);
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
};
|
|
556
|
+
const globalMouseUpHandler = () => {
|
|
557
|
+
callbacks.forEach((cb) => {
|
|
558
|
+
try {
|
|
559
|
+
cb.onMouseUp();
|
|
560
|
+
} catch (error) {
|
|
561
|
+
console.error("[Shaders] Error in mouse up handler:", error);
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
};
|
|
565
|
+
const globalTouchEndHandler = () => {
|
|
566
|
+
callbacks.forEach((cb) => {
|
|
567
|
+
try {
|
|
568
|
+
cb.onTouchEnd();
|
|
569
|
+
} catch (error) {
|
|
570
|
+
console.error("[Shaders] Error in touch end handler:", error);
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
};
|
|
574
|
+
return { register(handlers) {
|
|
575
|
+
callbacks.add(handlers);
|
|
576
|
+
instanceCount++;
|
|
577
|
+
if (instanceCount === 1) {
|
|
578
|
+
window.addEventListener("mousemove", globalMouseMoveHandler);
|
|
579
|
+
window.addEventListener("touchmove", globalTouchMoveHandler);
|
|
580
|
+
window.addEventListener("mouseup", globalMouseUpHandler);
|
|
581
|
+
window.addEventListener("touchend", globalTouchEndHandler);
|
|
582
|
+
}
|
|
583
|
+
return () => {
|
|
584
|
+
callbacks.delete(handlers);
|
|
585
|
+
instanceCount--;
|
|
586
|
+
if (instanceCount === 0) {
|
|
587
|
+
window.removeEventListener("mousemove", globalMouseMoveHandler);
|
|
588
|
+
window.removeEventListener("touchmove", globalTouchMoveHandler);
|
|
589
|
+
window.removeEventListener("mouseup", globalMouseUpHandler);
|
|
590
|
+
window.removeEventListener("touchend", globalTouchEndHandler);
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
} };
|
|
594
|
+
})();
|
|
595
|
+
var isDevelopment = () => {
|
|
596
|
+
try {
|
|
597
|
+
{
|
|
598
|
+
const { MODE, DEV } = {
|
|
599
|
+
"DEV": false,
|
|
600
|
+
"MODE": "production"
|
|
601
|
+
};
|
|
602
|
+
return DEV || MODE === "development";
|
|
603
|
+
}
|
|
604
|
+
if (typeof window !== "undefined" && window.location) {
|
|
605
|
+
const hostname = window.location.hostname;
|
|
606
|
+
return hostname === "localhost" || hostname === "127.0.0.1" || hostname.endsWith(".local") || hostname.includes("dev.") || hostname.startsWith("dev-");
|
|
607
|
+
}
|
|
608
|
+
return false;
|
|
609
|
+
} catch (error) {
|
|
610
|
+
return false;
|
|
611
|
+
}
|
|
478
612
|
};
|
|
479
|
-
function
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
613
|
+
function shaderRenderer() {
|
|
614
|
+
let canvasElement = null;
|
|
615
|
+
let renderer;
|
|
616
|
+
let camera;
|
|
617
|
+
let scene;
|
|
618
|
+
let mesh;
|
|
619
|
+
let material;
|
|
620
|
+
const nodeRegistry = {
|
|
621
|
+
nodes: /* @__PURE__ */ new Map(),
|
|
622
|
+
rootId: null,
|
|
623
|
+
idToNodeId: /* @__PURE__ */ new Map()
|
|
624
|
+
};
|
|
625
|
+
const parentToChildren = /* @__PURE__ */ new Map();
|
|
626
|
+
let animationFrameId = null;
|
|
627
|
+
let resizeObserver = null;
|
|
628
|
+
let intersectionObserver = null;
|
|
629
|
+
let isInitialized = false;
|
|
630
|
+
let isInitializing = false;
|
|
631
|
+
let hasInitialDimensions = false;
|
|
632
|
+
let initializationAbortController = null;
|
|
633
|
+
let isVisible = false;
|
|
634
|
+
let shouldAnimate = true;
|
|
635
|
+
let currentWidth = 0;
|
|
636
|
+
let currentHeight = 0;
|
|
637
|
+
let lastRenderTime = 0;
|
|
638
|
+
let needsMaterialRefresh = false;
|
|
639
|
+
let pointerX = .5;
|
|
640
|
+
let pointerY = .5;
|
|
641
|
+
let pointerActive = false;
|
|
642
|
+
let isUpdatingMaterial = false;
|
|
643
|
+
let globalEventUnregister = null;
|
|
644
|
+
let unloadHandler = null;
|
|
645
|
+
let enablePerformanceTracking = false;
|
|
646
|
+
const performanceTracker = new PerformanceTracker();
|
|
647
|
+
let pendingRegistrationQueue = [];
|
|
648
|
+
let isRendererReady = false;
|
|
649
|
+
let registrationQueue = [];
|
|
650
|
+
let registrationBatchRAF = null;
|
|
651
|
+
let metadataUpdateQueue = [];
|
|
652
|
+
let metadataUpdateBatchRAF = null;
|
|
653
|
+
let lastComposedNodes = /* @__PURE__ */ new Set();
|
|
654
|
+
let activeRTTNodes = /* @__PURE__ */ new Set();
|
|
655
|
+
let actualRTTOperations = 0;
|
|
656
|
+
let currentTextures = /* @__PURE__ */ new Set();
|
|
657
|
+
let previousTextures = /* @__PURE__ */ new Set();
|
|
658
|
+
let pendingResize = null;
|
|
659
|
+
let isResizeScheduled = false;
|
|
660
|
+
const updateRendererDimensions = (width, height) => {
|
|
661
|
+
if (width <= 0 || height <= 0) return;
|
|
662
|
+
if (width === currentWidth && height === currentHeight) return;
|
|
663
|
+
pendingResize = {
|
|
664
|
+
width,
|
|
665
|
+
height
|
|
666
|
+
};
|
|
667
|
+
if (!isResizeScheduled) {
|
|
668
|
+
isResizeScheduled = true;
|
|
669
|
+
requestAnimationFrame(() => {
|
|
670
|
+
isResizeScheduled = false;
|
|
671
|
+
if (!pendingResize) return;
|
|
672
|
+
const { width: width$1, height: height$1 } = pendingResize;
|
|
673
|
+
pendingResize = null;
|
|
674
|
+
currentWidth = width$1;
|
|
675
|
+
currentHeight = height$1;
|
|
676
|
+
if (!hasInitialDimensions) hasInitialDimensions = true;
|
|
677
|
+
renderer.setSize(width$1, height$1, false);
|
|
678
|
+
const aspectRatio = width$1 / height$1;
|
|
679
|
+
const frustumHeight = 2;
|
|
680
|
+
const frustumWidth = frustumHeight * aspectRatio;
|
|
681
|
+
camera.left = -frustumWidth / 2;
|
|
682
|
+
camera.right = frustumWidth / 2;
|
|
683
|
+
camera.top = frustumHeight / 2;
|
|
684
|
+
camera.bottom = -frustumHeight / 2;
|
|
685
|
+
camera.updateProjectionMatrix();
|
|
686
|
+
mesh.scale.set(frustumWidth, frustumHeight, 1);
|
|
687
|
+
nodeRegistry.nodes.forEach((nodeInfo) => {
|
|
688
|
+
if (nodeInfo.transformUniforms?.aspectRatio) nodeInfo.transformUniforms.aspectRatio.value = aspectRatio;
|
|
689
|
+
nodeInfo.resizeCallbacks.forEach((callback) => {
|
|
690
|
+
try {
|
|
691
|
+
callback({
|
|
692
|
+
width: width$1,
|
|
693
|
+
height: height$1
|
|
694
|
+
});
|
|
695
|
+
} catch (error) {
|
|
696
|
+
console.error("Error in resize callback:", error);
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
});
|
|
700
|
+
renderFrame().catch(console.warn);
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
const canRender = () => {
|
|
705
|
+
return isInitialized && !!renderer && !!scene && !!camera && !!material && currentWidth > 0 && currentHeight > 0;
|
|
706
|
+
};
|
|
707
|
+
const handleResize = (entries) => {
|
|
708
|
+
if (!renderer || !camera || !mesh) return;
|
|
709
|
+
const entry = entries[0];
|
|
710
|
+
if (!entry) return;
|
|
711
|
+
let width, height;
|
|
712
|
+
if (entry.contentBoxSize) {
|
|
713
|
+
const boxSize = Array.isArray(entry.contentBoxSize) ? entry.contentBoxSize[0] : entry.contentBoxSize;
|
|
714
|
+
if (boxSize) {
|
|
715
|
+
width = Math.round(boxSize.inlineSize);
|
|
716
|
+
height = Math.round(boxSize.blockSize);
|
|
717
|
+
} else {
|
|
718
|
+
width = Math.round(entry.contentRect.width);
|
|
719
|
+
height = Math.round(entry.contentRect.height);
|
|
720
|
+
}
|
|
721
|
+
} else {
|
|
722
|
+
width = Math.round(entry.contentRect.width);
|
|
723
|
+
height = Math.round(entry.contentRect.height);
|
|
724
|
+
}
|
|
725
|
+
if (width === 0 || height === 0) return;
|
|
726
|
+
updateRendererDimensions(width, height);
|
|
727
|
+
};
|
|
728
|
+
const handleVisibilityChange = (entries) => {
|
|
729
|
+
const entry = entries[0];
|
|
730
|
+
if (!entry) return;
|
|
731
|
+
isVisible = entry.isIntersecting;
|
|
732
|
+
};
|
|
733
|
+
const setsAreEqual = (set1, set2) => {
|
|
734
|
+
if (set1.size !== set2.size) return false;
|
|
735
|
+
for (const item of set1) if (!set2.has(item)) return false;
|
|
736
|
+
return true;
|
|
737
|
+
};
|
|
738
|
+
const trackConvertToTexture = (node) => {
|
|
739
|
+
actualRTTOperations++;
|
|
740
|
+
const texture = convertToTexture(node);
|
|
741
|
+
currentTextures.add(texture);
|
|
742
|
+
return texture;
|
|
743
|
+
};
|
|
744
|
+
const disposePreviousTextures = () => {
|
|
745
|
+
previousTextures.forEach((texture) => {
|
|
746
|
+
try {
|
|
747
|
+
if (texture?.renderTarget?.dispose) texture.renderTarget.dispose();
|
|
748
|
+
} catch (e) {}
|
|
749
|
+
});
|
|
750
|
+
previousTextures.clear();
|
|
751
|
+
};
|
|
752
|
+
let materialUpdatePending = false;
|
|
753
|
+
const updateMaterial = () => {
|
|
754
|
+
if (!nodeRegistry.rootId || !material || isUpdatingMaterial) return;
|
|
755
|
+
if (!nodeRegistry.nodes.get(nodeRegistry.rootId)) return;
|
|
756
|
+
if (currentWidth === 0 || currentHeight === 0) {
|
|
757
|
+
if (!materialUpdatePending) {
|
|
758
|
+
materialUpdatePending = true;
|
|
759
|
+
requestAnimationFrame(() => {
|
|
760
|
+
materialUpdatePending = false;
|
|
761
|
+
if (currentWidth > 0 && currentHeight > 0) updateMaterial();
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
isUpdatingMaterial = true;
|
|
767
|
+
try {
|
|
768
|
+
previousTextures = new Set(currentTextures);
|
|
769
|
+
currentTextures.clear();
|
|
770
|
+
const currentComposedNodes = /* @__PURE__ */ new Set();
|
|
771
|
+
activeRTTNodes.clear();
|
|
772
|
+
nodeRegistry.nodes.forEach((nodeInfo, nodeId) => {
|
|
773
|
+
if (nodeInfo.requiresRTT || nodeInfo.transformRTTActive) activeRTTNodes.add(nodeId);
|
|
774
|
+
});
|
|
775
|
+
actualRTTOperations = 0;
|
|
776
|
+
const composedNode = composeNodeTree(nodeRegistry.rootId, /* @__PURE__ */ new Set(), currentComposedNodes);
|
|
777
|
+
if (composedNode && material) {
|
|
778
|
+
const compositionChanged = !setsAreEqual(lastComposedNodes, currentComposedNodes);
|
|
779
|
+
const nodeChanged = material.fragmentNode !== composedNode;
|
|
780
|
+
if (compositionChanged || needsMaterialRefresh || nodeChanged) {
|
|
781
|
+
disposePreviousTextures();
|
|
782
|
+
try {
|
|
783
|
+
material.dispose();
|
|
784
|
+
if (renderer.renderTarget) renderer.renderTarget.dispose();
|
|
785
|
+
} catch (e) {}
|
|
786
|
+
const newMaterial = new MeshBasicNodeMaterial({ transparent: true });
|
|
787
|
+
newMaterial.fragmentNode = composedNode;
|
|
788
|
+
newMaterial.needsUpdate = true;
|
|
789
|
+
mesh.material = newMaterial;
|
|
790
|
+
material = newMaterial;
|
|
791
|
+
needsMaterialRefresh = false;
|
|
792
|
+
lastComposedNodes = currentComposedNodes;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
} catch (error) {
|
|
796
|
+
console.error("Error composing shader tree:", error);
|
|
797
|
+
} finally {
|
|
798
|
+
isUpdatingMaterial = false;
|
|
799
|
+
}
|
|
800
|
+
renderFrame().catch(console.warn);
|
|
801
|
+
};
|
|
802
|
+
const findChildNodes = (parentId) => {
|
|
803
|
+
const childIds = parentToChildren.get(parentId);
|
|
804
|
+
if (!childIds) return [];
|
|
805
|
+
const children = [];
|
|
806
|
+
for (const childId of childIds) {
|
|
807
|
+
const nodeInfo = nodeRegistry.nodes.get(childId);
|
|
808
|
+
if (nodeInfo) children.push(nodeInfo);
|
|
809
|
+
}
|
|
810
|
+
return children;
|
|
811
|
+
};
|
|
812
|
+
const findNodeByCustomId = (customId) => {
|
|
813
|
+
for (const [nodeId, info] of nodeRegistry.nodes.entries()) if (info.metadata.id === customId) return nodeId;
|
|
814
|
+
return null;
|
|
815
|
+
};
|
|
816
|
+
const applyMaskIfNeeded = (result, nodeInfo, nodeId, processedMasks, distortedUV) => {
|
|
817
|
+
if (!nodeInfo.metadata.mask?.source) return result;
|
|
818
|
+
const maskSourceId = nodeInfo.metadata.mask.source;
|
|
819
|
+
const maskNodeId = findNodeByCustomId(maskSourceId);
|
|
820
|
+
if (!maskNodeId) return result;
|
|
821
|
+
if (processedMasks.has(maskNodeId)) {
|
|
822
|
+
console.error(`Uh oh, looks like you've got a circular dependency in your shader masks.`);
|
|
823
|
+
return result;
|
|
824
|
+
}
|
|
825
|
+
const newProcessedMasks = new Set(processedMasks);
|
|
826
|
+
newProcessedMasks.add(nodeId);
|
|
827
|
+
const maskNode = composeNodeTree(maskNodeId, newProcessedMasks);
|
|
828
|
+
let finalMaskNode = maskNode;
|
|
829
|
+
if (distortedUV) finalMaskNode = trackConvertToTexture(maskNode).sample(distortedUV);
|
|
830
|
+
const maskType = nodeInfo.metadata.mask.type || "alpha";
|
|
831
|
+
return applyMask(result, finalMaskNode, maskType);
|
|
832
|
+
};
|
|
833
|
+
const applyNodeTransformation = (result, nodeInfo) => {
|
|
834
|
+
if (!nodeInfo.metadata.transform || !nodeInfo.transformUniforms || !needsTransformation(nodeInfo.metadata.transform) && !nodeInfo.transformRTTActive) return result;
|
|
835
|
+
const texture = trackConvertToTexture(result);
|
|
836
|
+
const transformedUV = applyUVTransform(screenUV, nodeInfo.transformUniforms.offsetX, nodeInfo.transformUniforms.offsetY, nodeInfo.transformUniforms.rotation, nodeInfo.transformUniforms.scale, nodeInfo.transformUniforms.anchorX, nodeInfo.transformUniforms.anchorY, nodeInfo.transformUniforms.aspectRatio);
|
|
837
|
+
return applyEdgeHandling(transformedUV, texture.sample(transformedUV), texture, nodeInfo.transformUniforms.edges);
|
|
838
|
+
};
|
|
839
|
+
const isUVComposable = (nodeInfo) => {
|
|
840
|
+
return !!nodeInfo.uvTransformFunc && nodeInfo.requiresChild && nodeInfo.metadata.blendMode === "normal" && (nodeInfo.metadata.opacity === void 0 || nodeInfo.metadata.opacity === 1) && nodeInfo.metadata.visible !== false && !nodeInfo.metadata.mask?.source && !(nodeInfo.transformUniforms && nodeInfo.metadata.transform && needsTransformation(nodeInfo.metadata.transform));
|
|
841
|
+
};
|
|
842
|
+
const findUVChain = (startNodeId) => {
|
|
843
|
+
const chain = [];
|
|
844
|
+
let currentId = startNodeId;
|
|
845
|
+
while (currentId) {
|
|
846
|
+
const nodeInfo = nodeRegistry.nodes.get(currentId);
|
|
847
|
+
if (!nodeInfo) break;
|
|
848
|
+
if (!isUVComposable(nodeInfo)) break;
|
|
849
|
+
chain.push(nodeInfo);
|
|
850
|
+
const children = findChildNodes(nodeInfo.id);
|
|
851
|
+
if (children.length !== 1) break;
|
|
852
|
+
const child = children[0];
|
|
853
|
+
if (isUVComposable(child)) currentId = child.id;
|
|
854
|
+
else break;
|
|
855
|
+
}
|
|
856
|
+
return chain;
|
|
857
|
+
};
|
|
858
|
+
const findUVChainTerminus = (chain) => {
|
|
859
|
+
if (chain.length === 0) return null;
|
|
860
|
+
const innermostNode = chain[chain.length - 1];
|
|
861
|
+
const children = findChildNodes(innermostNode.id);
|
|
862
|
+
if (children.length === 0) return null;
|
|
863
|
+
if (children.length === 1) return children[0];
|
|
864
|
+
return null;
|
|
865
|
+
};
|
|
866
|
+
const canSkipRTT = (distortionInfo) => {
|
|
867
|
+
if (!distortionInfo.uvTransformFunc) return false;
|
|
868
|
+
if (!isUVComposable(distortionInfo)) return false;
|
|
869
|
+
const children = findChildNodes(distortionInfo.id);
|
|
870
|
+
if (children.length !== 1) return false;
|
|
871
|
+
const child = children[0];
|
|
872
|
+
if (child.acceptsUVContext && !child.requiresChild) return true;
|
|
873
|
+
if (child.uvTransformFunc && isUVComposable(child)) return canSkipRTT(child);
|
|
874
|
+
return false;
|
|
875
|
+
};
|
|
876
|
+
const composeUVContextChain = (startNodeId, _processedMasks, currentlyComposedNodes) => {
|
|
877
|
+
const chain = [];
|
|
878
|
+
let currentId = startNodeId;
|
|
879
|
+
while (currentId) {
|
|
880
|
+
const nodeInfo = nodeRegistry.nodes.get(currentId);
|
|
881
|
+
if (!nodeInfo) break;
|
|
882
|
+
if (chain.length >= 2) return composeNodeTree(startNodeId, _processedMasks, currentlyComposedNodes, true);
|
|
883
|
+
chain.push(nodeInfo);
|
|
884
|
+
if (currentlyComposedNodes) currentlyComposedNodes.add(nodeInfo.id);
|
|
885
|
+
if (nodeInfo.acceptsUVContext && !nodeInfo.requiresChild) break;
|
|
886
|
+
const children = findChildNodes(currentId);
|
|
887
|
+
if (children.length !== 1) break;
|
|
888
|
+
currentId = children[0].id;
|
|
889
|
+
}
|
|
890
|
+
if (chain.length === 0) return vec4(0, 0, 0, 0);
|
|
891
|
+
const terminus = chain[chain.length - 1];
|
|
892
|
+
let composedUV = screenUV;
|
|
893
|
+
for (let i = 0; i < chain.length; i++) {
|
|
894
|
+
const nodeInfo = chain[i];
|
|
895
|
+
if (nodeInfo.uvTransformFunc) composedUV = nodeInfo.uvTransformFunc({
|
|
896
|
+
uv: composedUV,
|
|
897
|
+
uniforms: nodeInfo.uniforms,
|
|
898
|
+
viewportSize
|
|
899
|
+
});
|
|
900
|
+
if (nodeInfo.transformUniforms && nodeInfo.metadata.transform && needsTransformation(nodeInfo.metadata.transform)) {
|
|
901
|
+
composedUV = applyUVTransform(composedUV, nodeInfo.transformUniforms.offsetX, nodeInfo.transformUniforms.offsetY, nodeInfo.transformUniforms.rotation, nodeInfo.transformUniforms.scale, nodeInfo.transformUniforms.anchorX, nodeInfo.transformUniforms.anchorY, nodeInfo.transformUniforms.aspectRatio);
|
|
902
|
+
if (nodeInfo.transformUniforms.edges) composedUV = applyEdgeToUV(composedUV, nodeInfo.transformUniforms.edges);
|
|
903
|
+
nodeInfo.transformRTTActive = true;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
for (let i = 0; i < chain.length - 1; i++) {
|
|
907
|
+
const distortion = chain[i];
|
|
908
|
+
if (!distortion.requiresChild) continue;
|
|
909
|
+
const distortionOnCleanup = (callback) => {
|
|
910
|
+
distortion.cleanupCallbacks.push(callback);
|
|
911
|
+
};
|
|
912
|
+
const distortionOnBeforeRender = (callback) => {
|
|
913
|
+
distortion.beforeRenderCallbacks.push(callback);
|
|
914
|
+
};
|
|
915
|
+
const distortionOnAfterRender = (callback) => {
|
|
916
|
+
distortion.afterRenderCallbacks.push(callback);
|
|
917
|
+
};
|
|
918
|
+
const distortionOnResize = (callback) => {
|
|
919
|
+
distortion.resizeCallbacks.push(callback);
|
|
920
|
+
};
|
|
921
|
+
distortion.cleanupCallbacks.forEach((callback) => {
|
|
922
|
+
try {
|
|
923
|
+
callback();
|
|
924
|
+
} catch (e) {
|
|
925
|
+
console.error("Error in cleanup callback:", e);
|
|
926
|
+
}
|
|
927
|
+
});
|
|
928
|
+
distortion.cleanupCallbacks = [];
|
|
929
|
+
distortion.beforeRenderCallbacks = [];
|
|
930
|
+
distortion.afterRenderCallbacks = [];
|
|
931
|
+
distortion.resizeCallbacks = [];
|
|
932
|
+
distortion.fragmentNodeFunc({
|
|
933
|
+
uniforms: distortion.uniforms ?? {},
|
|
934
|
+
childNode: void 0,
|
|
935
|
+
uvContext: void 0,
|
|
936
|
+
onCleanup: distortionOnCleanup,
|
|
937
|
+
onBeforeRender: distortionOnBeforeRender,
|
|
938
|
+
onAfterRender: distortionOnAfterRender,
|
|
939
|
+
onResize: distortionOnResize,
|
|
940
|
+
canvas: canvasElement,
|
|
941
|
+
dimensions: {
|
|
942
|
+
width: currentWidth,
|
|
943
|
+
height: currentHeight
|
|
944
|
+
},
|
|
945
|
+
renderer
|
|
946
|
+
});
|
|
947
|
+
}
|
|
948
|
+
const terminusOnCleanup = (callback) => {
|
|
949
|
+
terminus.cleanupCallbacks.push(callback);
|
|
950
|
+
};
|
|
951
|
+
const terminusOnBeforeRender = (callback) => {
|
|
952
|
+
terminus.beforeRenderCallbacks.push(callback);
|
|
953
|
+
};
|
|
954
|
+
const terminusOnAfterRender = (callback) => {
|
|
955
|
+
terminus.afterRenderCallbacks.push(callback);
|
|
956
|
+
};
|
|
957
|
+
const terminusOnResize = (callback) => {
|
|
958
|
+
terminus.resizeCallbacks.push(callback);
|
|
959
|
+
};
|
|
960
|
+
terminus.cleanupCallbacks.forEach((callback) => {
|
|
961
|
+
try {
|
|
962
|
+
callback();
|
|
963
|
+
} catch (e) {
|
|
964
|
+
console.error("Error in cleanup callback:", e);
|
|
965
|
+
}
|
|
966
|
+
});
|
|
967
|
+
terminus.cleanupCallbacks = [];
|
|
968
|
+
terminus.beforeRenderCallbacks = [];
|
|
969
|
+
terminus.afterRenderCallbacks = [];
|
|
970
|
+
terminus.resizeCallbacks = [];
|
|
971
|
+
const result = terminus.fragmentNodeFunc({
|
|
972
|
+
uniforms: terminus.uniforms ?? {},
|
|
973
|
+
childNode: void 0,
|
|
974
|
+
uvContext: composedUV,
|
|
975
|
+
onCleanup: terminusOnCleanup,
|
|
976
|
+
onBeforeRender: terminusOnBeforeRender,
|
|
977
|
+
onAfterRender: terminusOnAfterRender,
|
|
978
|
+
onResize: terminusOnResize,
|
|
979
|
+
canvas: canvasElement,
|
|
980
|
+
dimensions: {
|
|
981
|
+
width: currentWidth,
|
|
982
|
+
height: currentHeight
|
|
983
|
+
},
|
|
984
|
+
renderer
|
|
985
|
+
});
|
|
986
|
+
for (const nodeInfo of chain) if (nodeInfo.uniforms.edges?.uniform) return applyEdgeHandling(composedUV, result, null, nodeInfo.uniforms.edges.uniform);
|
|
987
|
+
return result;
|
|
988
|
+
};
|
|
989
|
+
const composeUVChain = (chain, processedMasks, currentlyComposedNodes) => {
|
|
990
|
+
if (chain.length === 0) return vec4(0, 0, 0, 0);
|
|
991
|
+
const terminus = findUVChainTerminus(chain);
|
|
992
|
+
let terminusNode;
|
|
993
|
+
if (terminus) terminusNode = composeNodeTree(terminus.id, processedMasks, currentlyComposedNodes);
|
|
994
|
+
else {
|
|
995
|
+
const innermostNode = chain[chain.length - 1];
|
|
996
|
+
if (findChildNodes(innermostNode.id).length === 0) return vec4(0, 0, 0, 0);
|
|
997
|
+
terminusNode = composeNodeTree(innermostNode.id, processedMasks, currentlyComposedNodes);
|
|
998
|
+
}
|
|
999
|
+
const texture = trackConvertToTexture(terminusNode);
|
|
1000
|
+
let composedUV = screenUV;
|
|
1001
|
+
for (let i = chain.length - 1; i >= 0; i--) {
|
|
1002
|
+
const nodeInfo = chain[i];
|
|
1003
|
+
if (nodeInfo.uvTransformFunc) {
|
|
1004
|
+
composedUV = nodeInfo.uvTransformFunc({
|
|
1005
|
+
uv: composedUV,
|
|
1006
|
+
uniforms: nodeInfo.uniforms,
|
|
1007
|
+
viewportSize
|
|
1008
|
+
});
|
|
1009
|
+
if (nodeInfo.uniforms.edges?.uniform) composedUV = applyEdgeToUV(composedUV, nodeInfo.uniforms.edges.uniform);
|
|
1010
|
+
}
|
|
1011
|
+
if (currentlyComposedNodes) currentlyComposedNodes.add(nodeInfo.id);
|
|
1012
|
+
}
|
|
1013
|
+
const sampledColor = texture.sample(composedUV);
|
|
1014
|
+
const outermostNode = chain[0];
|
|
1015
|
+
if (outermostNode.uniforms.edges?.uniform) return applyEdgeHandling(composedUV, sampledColor, texture, outermostNode.uniforms.edges.uniform);
|
|
1016
|
+
return sampledColor;
|
|
1017
|
+
};
|
|
1018
|
+
const findSiblingUVChain = (sortedChildren, startIndex) => {
|
|
1019
|
+
const chain = [];
|
|
1020
|
+
for (let i = startIndex; i < sortedChildren.length; i++) {
|
|
1021
|
+
const sibling = sortedChildren[i];
|
|
1022
|
+
if (!isUVComposable(sibling)) break;
|
|
1023
|
+
if (findChildNodes(sibling.id).length > 0) break;
|
|
1024
|
+
chain.push(sibling);
|
|
1025
|
+
}
|
|
1026
|
+
return chain;
|
|
1027
|
+
};
|
|
1028
|
+
const composeSiblingUVChain = (chain, inputContent, currentlyComposedNodes) => {
|
|
1029
|
+
if (chain.length === 0) return inputContent;
|
|
1030
|
+
const texture = trackConvertToTexture(inputContent);
|
|
1031
|
+
let composedUV = screenUV;
|
|
1032
|
+
for (let i = chain.length - 1; i >= 0; i--) {
|
|
1033
|
+
const nodeInfo = chain[i];
|
|
1034
|
+
if (nodeInfo.uvTransformFunc) {
|
|
1035
|
+
composedUV = nodeInfo.uvTransformFunc({
|
|
1036
|
+
uv: composedUV,
|
|
1037
|
+
uniforms: nodeInfo.uniforms,
|
|
1038
|
+
viewportSize
|
|
1039
|
+
});
|
|
1040
|
+
if (nodeInfo.uniforms.edges?.uniform) composedUV = applyEdgeToUV(composedUV, nodeInfo.uniforms.edges.uniform);
|
|
1041
|
+
}
|
|
1042
|
+
if (currentlyComposedNodes) currentlyComposedNodes.add(nodeInfo.id);
|
|
1043
|
+
}
|
|
1044
|
+
const sampledColor = texture.sample(composedUV);
|
|
1045
|
+
const lastNode = chain[chain.length - 1];
|
|
1046
|
+
if (lastNode.uniforms.edges?.uniform) return applyEdgeHandling(composedUV, sampledColor, texture, lastNode.uniforms.edges.uniform);
|
|
1047
|
+
return sampledColor;
|
|
1048
|
+
};
|
|
1049
|
+
const hasUVPropagationOpportunity = (sortedChildren) => {
|
|
1050
|
+
const generators = [];
|
|
1051
|
+
const distortions = [];
|
|
1052
|
+
let hasGeneratorBeforeDistortion = false;
|
|
1053
|
+
for (let i = 0; i < sortedChildren.length; i++) {
|
|
1054
|
+
const child = sortedChildren[i];
|
|
1055
|
+
const childHasChildren = findChildNodes(child.id).length > 0;
|
|
1056
|
+
if (child.acceptsUVContext && !child.requiresChild) generators.push(i);
|
|
1057
|
+
if (isUVComposable(child) && !childHasChildren) {
|
|
1058
|
+
distortions.push(i);
|
|
1059
|
+
if (generators.length > 0) hasGeneratorBeforeDistortion = true;
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
if (generators.length === 0 || distortions.length === 0 || !hasGeneratorBeforeDistortion) return false;
|
|
1063
|
+
const minGen = Math.min(...generators);
|
|
1064
|
+
const maxDist = Math.max(...distortions);
|
|
1065
|
+
for (let i = minGen + 1; i < maxDist; i++) {
|
|
1066
|
+
const node = sortedChildren[i];
|
|
1067
|
+
if (node.requiresRTT && !isUVComposable(node) && !(node.acceptsUVContext && !node.requiresChild)) return false;
|
|
1068
|
+
}
|
|
1069
|
+
if (distortions.length > 2) return false;
|
|
1070
|
+
return true;
|
|
1071
|
+
};
|
|
1072
|
+
const composeSiblingsWithUVContext = (sortedChildren, processedMasks, currentlyComposedNodes) => {
|
|
1073
|
+
const generators = [];
|
|
1074
|
+
const distortions = [];
|
|
1075
|
+
sortedChildren.forEach((child, index) => {
|
|
1076
|
+
const hasChildren = findChildNodes(child.id).length > 0;
|
|
1077
|
+
if (isUVComposable(child) && !hasChildren) distortions.push({
|
|
1078
|
+
node: child,
|
|
1079
|
+
index
|
|
1080
|
+
});
|
|
1081
|
+
else if (child.acceptsUVContext && !child.requiresChild && !hasChildren) generators.push({
|
|
1082
|
+
node: child,
|
|
1083
|
+
index
|
|
1084
|
+
});
|
|
1085
|
+
});
|
|
1086
|
+
for (const d of distortions) {
|
|
1087
|
+
const distortion = d.node;
|
|
1088
|
+
distortion.cleanupCallbacks.forEach((cb) => {
|
|
1089
|
+
try {
|
|
1090
|
+
cb();
|
|
1091
|
+
} catch (e) {
|
|
1092
|
+
console.error("Cleanup error:", e);
|
|
1093
|
+
}
|
|
1094
|
+
});
|
|
1095
|
+
distortion.cleanupCallbacks = [];
|
|
1096
|
+
distortion.beforeRenderCallbacks = [];
|
|
1097
|
+
distortion.afterRenderCallbacks = [];
|
|
1098
|
+
distortion.resizeCallbacks = [];
|
|
1099
|
+
const onCleanup = (cb) => distortion.cleanupCallbacks.push(cb);
|
|
1100
|
+
const onBeforeRender = (cb) => distortion.beforeRenderCallbacks.push(cb);
|
|
1101
|
+
const onAfterRender = (cb) => distortion.afterRenderCallbacks.push(cb);
|
|
1102
|
+
const onResize = (cb) => distortion.resizeCallbacks.push(cb);
|
|
1103
|
+
distortion.fragmentNodeFunc({
|
|
1104
|
+
uniforms: distortion.uniforms ?? {},
|
|
1105
|
+
childNode: void 0,
|
|
1106
|
+
uvContext: void 0,
|
|
1107
|
+
onCleanup,
|
|
1108
|
+
onBeforeRender,
|
|
1109
|
+
onAfterRender,
|
|
1110
|
+
onResize,
|
|
1111
|
+
canvas: canvasElement,
|
|
1112
|
+
dimensions: {
|
|
1113
|
+
width: currentWidth,
|
|
1114
|
+
height: currentHeight
|
|
1115
|
+
},
|
|
1116
|
+
renderer
|
|
1117
|
+
});
|
|
1118
|
+
if (currentlyComposedNodes) currentlyComposedNodes.add(distortion.id);
|
|
1119
|
+
}
|
|
1120
|
+
let composedResult = void 0;
|
|
1121
|
+
for (let i = 0; i < sortedChildren.length; i++) {
|
|
1122
|
+
const childInfo = sortedChildren[i];
|
|
1123
|
+
if (childInfo.metadata.visible === false) continue;
|
|
1124
|
+
const effectiveOpacity = childInfo.metadata.opacity ?? 1;
|
|
1125
|
+
childInfo.opacityUniform.value = effectiveOpacity;
|
|
1126
|
+
if (currentlyComposedNodes) currentlyComposedNodes.add(childInfo.id);
|
|
1127
|
+
const hasChildren = findChildNodes(childInfo.id).length > 0;
|
|
1128
|
+
let childResult;
|
|
1129
|
+
const genEntry = generators.find((g) => g.index === i);
|
|
1130
|
+
if (genEntry) {
|
|
1131
|
+
const applicableDistortions = distortions.filter((d) => d.index > genEntry.index).sort((a, b) => a.index - b.index).map((d) => d.node);
|
|
1132
|
+
let composedUV = screenUV;
|
|
1133
|
+
for (let j = applicableDistortions.length - 1; j >= 0; j--) {
|
|
1134
|
+
const distortion = applicableDistortions[j];
|
|
1135
|
+
if (distortion.uvTransformFunc) composedUV = distortion.uvTransformFunc({
|
|
1136
|
+
uv: composedUV,
|
|
1137
|
+
uniforms: distortion.uniforms,
|
|
1138
|
+
viewportSize
|
|
1139
|
+
});
|
|
1140
|
+
if (distortion.transformUniforms && distortion.metadata.transform && needsTransformation(distortion.metadata.transform)) {
|
|
1141
|
+
composedUV = applyUVTransform(composedUV, distortion.transformUniforms.offsetX, distortion.transformUniforms.offsetY, distortion.transformUniforms.rotation, distortion.transformUniforms.scale, distortion.transformUniforms.anchorX, distortion.transformUniforms.anchorY, distortion.transformUniforms.aspectRatio);
|
|
1142
|
+
if (distortion.transformUniforms.edges) composedUV = applyEdgeToUV(composedUV, distortion.transformUniforms.edges);
|
|
1143
|
+
distortion.transformRTTActive = true;
|
|
1144
|
+
}
|
|
1145
|
+
if (distortion.uniforms.edges?.uniform) composedUV = applyEdgeToUV(composedUV, distortion.uniforms.edges.uniform);
|
|
1146
|
+
}
|
|
1147
|
+
if (genEntry.node.transformUniforms && genEntry.node.metadata.transform && needsTransformation(genEntry.node.metadata.transform)) {
|
|
1148
|
+
composedUV = applyUVTransform(composedUV, genEntry.node.transformUniforms.offsetX, genEntry.node.transformUniforms.offsetY, genEntry.node.transformUniforms.rotation, genEntry.node.transformUniforms.scale, genEntry.node.transformUniforms.anchorX, genEntry.node.transformUniforms.anchorY, genEntry.node.transformUniforms.aspectRatio);
|
|
1149
|
+
if (genEntry.node.transformUniforms.edges) composedUV = applyEdgeToUV(composedUV, genEntry.node.transformUniforms.edges);
|
|
1150
|
+
genEntry.node.transformRTTActive = true;
|
|
1151
|
+
}
|
|
1152
|
+
childInfo.cleanupCallbacks.forEach((cb) => {
|
|
1153
|
+
try {
|
|
1154
|
+
cb();
|
|
1155
|
+
} catch (e) {
|
|
1156
|
+
console.error("Cleanup error:", e);
|
|
1157
|
+
}
|
|
1158
|
+
});
|
|
1159
|
+
childInfo.cleanupCallbacks = [];
|
|
1160
|
+
childInfo.beforeRenderCallbacks = [];
|
|
1161
|
+
childInfo.afterRenderCallbacks = [];
|
|
1162
|
+
childInfo.resizeCallbacks = [];
|
|
1163
|
+
const onCleanup = (cb) => childInfo.cleanupCallbacks.push(cb);
|
|
1164
|
+
const onBeforeRender = (cb) => childInfo.beforeRenderCallbacks.push(cb);
|
|
1165
|
+
const onAfterRender = (cb) => childInfo.afterRenderCallbacks.push(cb);
|
|
1166
|
+
const onResize = (cb) => childInfo.resizeCallbacks.push(cb);
|
|
1167
|
+
let fragmentResult = childInfo.fragmentNodeFunc({
|
|
1168
|
+
uniforms: childInfo.uniforms ?? {},
|
|
1169
|
+
childNode: void 0,
|
|
1170
|
+
uvContext: composedUV,
|
|
1171
|
+
onCleanup,
|
|
1172
|
+
onBeforeRender,
|
|
1173
|
+
onAfterRender,
|
|
1174
|
+
onResize,
|
|
1175
|
+
canvas: canvasElement,
|
|
1176
|
+
dimensions: {
|
|
1177
|
+
width: currentWidth,
|
|
1178
|
+
height: currentHeight
|
|
1179
|
+
},
|
|
1180
|
+
renderer
|
|
1181
|
+
});
|
|
1182
|
+
if (applicableDistortions.length > 0) {
|
|
1183
|
+
const outermostDistortion = applicableDistortions[0];
|
|
1184
|
+
if (outermostDistortion.uniforms.edges?.uniform) fragmentResult = applyEdgeHandling(composedUV, fragmentResult, null, outermostDistortion.uniforms.edges.uniform);
|
|
1185
|
+
}
|
|
1186
|
+
childResult = applyMaskIfNeeded(fragmentResult, childInfo, childInfo.id, processedMasks, composedUV);
|
|
1187
|
+
} else if (distortions.find((d) => d.index === i)) continue;
|
|
1188
|
+
else if (hasChildren) {
|
|
1189
|
+
if (canSkipRTT(childInfo)) childResult = composeUVContextChain(childInfo.id, processedMasks, currentlyComposedNodes);
|
|
1190
|
+
else if (isUVComposable(childInfo)) {
|
|
1191
|
+
const uvChain = findUVChain(childInfo.id);
|
|
1192
|
+
if (uvChain.length > 1) childResult = composeUVChain(uvChain, processedMasks, currentlyComposedNodes);
|
|
1193
|
+
else childResult = composeNodeTree(childInfo.id, processedMasks, currentlyComposedNodes);
|
|
1194
|
+
} else childResult = composeNodeTree(childInfo.id, processedMasks, currentlyComposedNodes);
|
|
1195
|
+
const applicableDistortions = distortions.filter((d) => d.index > i).sort((a, b) => a.index - b.index).map((d) => d.node);
|
|
1196
|
+
if (applicableDistortions.length > 0) {
|
|
1197
|
+
const childTexture = trackConvertToTexture(childResult);
|
|
1198
|
+
let composedUV = screenUV;
|
|
1199
|
+
for (let j = applicableDistortions.length - 1; j >= 0; j--) {
|
|
1200
|
+
const distortion = applicableDistortions[j];
|
|
1201
|
+
if (distortion.uvTransformFunc) composedUV = distortion.uvTransformFunc({
|
|
1202
|
+
uv: composedUV,
|
|
1203
|
+
uniforms: distortion.uniforms,
|
|
1204
|
+
viewportSize
|
|
1205
|
+
});
|
|
1206
|
+
if (distortion.transformUniforms && distortion.metadata.transform && needsTransformation(distortion.metadata.transform)) {
|
|
1207
|
+
composedUV = applyUVTransform(composedUV, distortion.transformUniforms.offsetX, distortion.transformUniforms.offsetY, distortion.transformUniforms.rotation, distortion.transformUniforms.scale, distortion.transformUniforms.anchorX, distortion.transformUniforms.anchorY, distortion.transformUniforms.aspectRatio);
|
|
1208
|
+
if (distortion.transformUniforms.edges) composedUV = applyEdgeToUV(composedUV, distortion.transformUniforms.edges);
|
|
1209
|
+
distortion.transformRTTActive = true;
|
|
1210
|
+
}
|
|
1211
|
+
if (distortion.uniforms.edges?.uniform) composedUV = applyEdgeToUV(composedUV, distortion.uniforms.edges.uniform);
|
|
1212
|
+
}
|
|
1213
|
+
childResult = childTexture.sample(composedUV);
|
|
1214
|
+
const outermostDistortion = applicableDistortions[applicableDistortions.length - 1];
|
|
1215
|
+
if (outermostDistortion.transformUniforms?.edges) childResult = applyEdgeHandling(composedUV, childResult, childTexture, outermostDistortion.transformUniforms.edges);
|
|
1216
|
+
}
|
|
1217
|
+
} else {
|
|
1218
|
+
childInfo.cleanupCallbacks.forEach((cb) => {
|
|
1219
|
+
try {
|
|
1220
|
+
cb();
|
|
1221
|
+
} catch (e) {
|
|
1222
|
+
console.error("Cleanup error:", e);
|
|
1223
|
+
}
|
|
1224
|
+
});
|
|
1225
|
+
childInfo.cleanupCallbacks = [];
|
|
1226
|
+
childInfo.beforeRenderCallbacks = [];
|
|
1227
|
+
childInfo.afterRenderCallbacks = [];
|
|
1228
|
+
childInfo.resizeCallbacks = [];
|
|
1229
|
+
const onCleanup = (cb) => childInfo.cleanupCallbacks.push(cb);
|
|
1230
|
+
const onBeforeRender = (cb) => childInfo.beforeRenderCallbacks.push(cb);
|
|
1231
|
+
const onAfterRender = (cb) => childInfo.afterRenderCallbacks.push(cb);
|
|
1232
|
+
const onResize = (cb) => childInfo.resizeCallbacks.push(cb);
|
|
1233
|
+
let effectiveChildNode = composedResult;
|
|
1234
|
+
if (childInfo.requiresRTT && composedResult !== void 0) effectiveChildNode = applyBlendMode(vec4(0, 0, 0, 0), composedResult, "normal", 1);
|
|
1235
|
+
childResult = applyMaskIfNeeded(applyNodeTransformation(childInfo.fragmentNodeFunc({
|
|
1236
|
+
uniforms: childInfo.uniforms ?? {},
|
|
1237
|
+
childNode: effectiveChildNode,
|
|
1238
|
+
onCleanup,
|
|
1239
|
+
onBeforeRender,
|
|
1240
|
+
onAfterRender,
|
|
1241
|
+
onResize,
|
|
1242
|
+
canvas: canvasElement,
|
|
1243
|
+
dimensions: {
|
|
1244
|
+
width: currentWidth,
|
|
1245
|
+
height: currentHeight
|
|
1246
|
+
},
|
|
1247
|
+
renderer
|
|
1248
|
+
}), childInfo), childInfo, childInfo.id, processedMasks);
|
|
1249
|
+
}
|
|
1250
|
+
if (childInfo.requiresChild && childInfo.metadata.blendMode === "normal" && !hasChildren) composedResult = applyBlendMode(vec4(0, 0, 0, 0), childResult, "normal", childInfo.opacityUniform);
|
|
1251
|
+
else if (composedResult === void 0) composedResult = applyBlendMode(vec4(1, 1, 1, 0), childResult, childInfo.metadata.blendMode, childInfo.opacityUniform);
|
|
1252
|
+
else composedResult = applyBlendMode(composedResult, childResult, childInfo.metadata.blendMode, childInfo.opacityUniform);
|
|
1253
|
+
}
|
|
1254
|
+
return composedResult ?? vec4(0, 0, 0, 0);
|
|
1255
|
+
};
|
|
1256
|
+
const composeNodeTree = (nodeId, processedMasks = /* @__PURE__ */ new Set(), currentlyComposedNodes, forceRTT = false) => {
|
|
1257
|
+
if (currentWidth === 0 || currentHeight === 0) return vec4(0, 0, 0, 0);
|
|
1258
|
+
const nodeInfo = nodeRegistry.nodes.get(nodeId);
|
|
1259
|
+
if (!nodeInfo) return vec4(0, 0, 0, 0);
|
|
1260
|
+
const nodeSpecificOnCleanup = (callback) => {
|
|
1261
|
+
nodeInfo.cleanupCallbacks.push(callback);
|
|
1262
|
+
};
|
|
1263
|
+
const nodeSpecificOnBeforeRender = (callback) => {
|
|
1264
|
+
nodeInfo.beforeRenderCallbacks.push(callback);
|
|
1265
|
+
};
|
|
1266
|
+
const nodeSpecificOnAfterRender = (callback) => {
|
|
1267
|
+
nodeInfo.afterRenderCallbacks.push(callback);
|
|
1268
|
+
};
|
|
1269
|
+
const nodeSpecificOnResize = (callback) => {
|
|
1270
|
+
nodeInfo.resizeCallbacks.push(callback);
|
|
1271
|
+
};
|
|
1272
|
+
const childNodes = findChildNodes(nodeId);
|
|
1273
|
+
if (childNodes.length === 0) {
|
|
1274
|
+
nodeInfo.cleanupCallbacks.forEach((callback) => {
|
|
1275
|
+
try {
|
|
1276
|
+
callback();
|
|
1277
|
+
} catch (e) {
|
|
1278
|
+
console.error("Error in cleanup callback:", e);
|
|
1279
|
+
}
|
|
1280
|
+
});
|
|
1281
|
+
nodeInfo.cleanupCallbacks = [];
|
|
1282
|
+
nodeInfo.beforeRenderCallbacks = [];
|
|
1283
|
+
nodeInfo.afterRenderCallbacks = [];
|
|
1284
|
+
nodeInfo.resizeCallbacks = [];
|
|
1285
|
+
return applyMaskIfNeeded(applyNodeTransformation(nodeInfo.fragmentNodeFunc({
|
|
1286
|
+
uniforms: nodeInfo.uniforms ?? {},
|
|
1287
|
+
childNode: void 0,
|
|
1288
|
+
onCleanup: nodeSpecificOnCleanup,
|
|
1289
|
+
onBeforeRender: nodeSpecificOnBeforeRender,
|
|
1290
|
+
onAfterRender: nodeSpecificOnAfterRender,
|
|
1291
|
+
onResize: nodeSpecificOnResize,
|
|
1292
|
+
canvas: canvasElement,
|
|
1293
|
+
dimensions: {
|
|
1294
|
+
width: currentWidth,
|
|
1295
|
+
height: currentHeight
|
|
1296
|
+
},
|
|
1297
|
+
renderer
|
|
1298
|
+
}), nodeInfo), nodeInfo, nodeId, processedMasks);
|
|
1299
|
+
} else {
|
|
1300
|
+
const sortedChildren = [...childNodes].sort((a, b) => a.metadata.renderOrder - b.metadata.renderOrder);
|
|
1301
|
+
if (nodeInfo.parentId === null) {
|
|
1302
|
+
if (!forceRTT && hasUVPropagationOpportunity(sortedChildren)) return applyMaskIfNeeded(applyNodeTransformation(composeSiblingsWithUVContext(sortedChildren, processedMasks, currentlyComposedNodes), nodeInfo), nodeInfo, nodeId, processedMasks);
|
|
1303
|
+
let composedChildren = void 0;
|
|
1304
|
+
for (let i = 0; i < sortedChildren.length; i++) {
|
|
1305
|
+
const childInfo = sortedChildren[i];
|
|
1306
|
+
let effectiveOpacity;
|
|
1307
|
+
if (childInfo.metadata.opacity === void 0) {
|
|
1308
|
+
effectiveOpacity = 1;
|
|
1309
|
+
childInfo.opacityUniform.value = effectiveOpacity;
|
|
1310
|
+
} else {
|
|
1311
|
+
effectiveOpacity = childInfo.metadata.opacity;
|
|
1312
|
+
childInfo.opacityUniform.value = effectiveOpacity;
|
|
1313
|
+
}
|
|
1314
|
+
if (childInfo.metadata.visible === false) continue;
|
|
1315
|
+
if (currentlyComposedNodes) currentlyComposedNodes.add(childInfo.id);
|
|
1316
|
+
const childHasChildren = findChildNodes(childInfo.id).length > 0;
|
|
1317
|
+
let childResult;
|
|
1318
|
+
if (childHasChildren) if (forceRTT) childResult = composeNodeTree(childInfo.id, processedMasks, currentlyComposedNodes, true);
|
|
1319
|
+
else if (canSkipRTT(childInfo)) childResult = composeUVContextChain(childInfo.id, processedMasks, currentlyComposedNodes);
|
|
1320
|
+
else if (isUVComposable(childInfo)) {
|
|
1321
|
+
const uvChain = findUVChain(childInfo.id);
|
|
1322
|
+
if (uvChain.length > 1) childResult = composeUVChain(uvChain, processedMasks, currentlyComposedNodes);
|
|
1323
|
+
else childResult = composeNodeTree(childInfo.id, processedMasks, currentlyComposedNodes);
|
|
1324
|
+
} else childResult = composeNodeTree(childInfo.id, processedMasks, currentlyComposedNodes);
|
|
1325
|
+
else {
|
|
1326
|
+
if (isUVComposable(childInfo) && childInfo.requiresChild && composedChildren !== void 0) {
|
|
1327
|
+
const siblingChain = findSiblingUVChain(sortedChildren, i);
|
|
1328
|
+
if (siblingChain.length > 1) {
|
|
1329
|
+
childResult = composeSiblingUVChain(siblingChain, composedChildren, currentlyComposedNodes);
|
|
1330
|
+
i += siblingChain.length - 1;
|
|
1331
|
+
composedChildren = childResult;
|
|
1332
|
+
continue;
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
{
|
|
1336
|
+
const childSpecificOnCleanup = (callback) => {
|
|
1337
|
+
childInfo.cleanupCallbacks.push(callback);
|
|
1338
|
+
};
|
|
1339
|
+
const childSpecificOnBeforeRender = (callback) => {
|
|
1340
|
+
childInfo.beforeRenderCallbacks.push(callback);
|
|
1341
|
+
};
|
|
1342
|
+
const childSpecificOnAfterRender = (callback) => {
|
|
1343
|
+
childInfo.afterRenderCallbacks.push(callback);
|
|
1344
|
+
};
|
|
1345
|
+
const childSpecificOnResize = (callback) => {
|
|
1346
|
+
childInfo.resizeCallbacks.push(callback);
|
|
1347
|
+
};
|
|
1348
|
+
let effectiveChildNode = composedChildren;
|
|
1349
|
+
if (childInfo.requiresRTT && composedChildren !== void 0) effectiveChildNode = applyBlendMode(vec4(0, 0, 0, 0), composedChildren, "normal", 1);
|
|
1350
|
+
childInfo.cleanupCallbacks.forEach((callback) => {
|
|
1351
|
+
try {
|
|
1352
|
+
callback();
|
|
1353
|
+
} catch (e) {
|
|
1354
|
+
console.error("Error in cleanup callback:", e);
|
|
1355
|
+
}
|
|
1356
|
+
});
|
|
1357
|
+
childInfo.cleanupCallbacks = [];
|
|
1358
|
+
childInfo.beforeRenderCallbacks = [];
|
|
1359
|
+
childInfo.afterRenderCallbacks = [];
|
|
1360
|
+
childInfo.resizeCallbacks = [];
|
|
1361
|
+
childResult = applyMaskIfNeeded(applyNodeTransformation(childInfo.fragmentNodeFunc({
|
|
1362
|
+
uniforms: childInfo.uniforms ?? {},
|
|
1363
|
+
childNode: effectiveChildNode,
|
|
1364
|
+
onCleanup: childSpecificOnCleanup,
|
|
1365
|
+
onBeforeRender: childSpecificOnBeforeRender,
|
|
1366
|
+
onAfterRender: childSpecificOnAfterRender,
|
|
1367
|
+
onResize: childSpecificOnResize,
|
|
1368
|
+
canvas: canvasElement,
|
|
1369
|
+
dimensions: {
|
|
1370
|
+
width: currentWidth,
|
|
1371
|
+
height: currentHeight
|
|
1372
|
+
},
|
|
1373
|
+
renderer
|
|
1374
|
+
}), childInfo), childInfo, childInfo.id, processedMasks);
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
if (childInfo.requiresChild && childInfo.metadata.blendMode === "normal" && !childHasChildren) composedChildren = applyBlendMode(vec4(0, 0, 0, 0), childResult, "normal", childInfo.opacityUniform);
|
|
1378
|
+
else if (composedChildren === void 0) if (nodeInfo.requiresRTT || effectiveOpacity !== 1) composedChildren = applyBlendMode(vec4(1, 1, 1, 0), childResult, childInfo.metadata.blendMode, childInfo.opacityUniform);
|
|
1379
|
+
else composedChildren = childResult;
|
|
1380
|
+
else composedChildren = applyBlendMode(composedChildren, childResult, childInfo.metadata.blendMode, childInfo.opacityUniform);
|
|
1381
|
+
}
|
|
1382
|
+
nodeInfo.cleanupCallbacks.forEach((callback) => {
|
|
1383
|
+
try {
|
|
1384
|
+
callback();
|
|
1385
|
+
} catch (e) {
|
|
1386
|
+
console.error("Error in cleanup callback:", e);
|
|
1387
|
+
}
|
|
1388
|
+
});
|
|
1389
|
+
nodeInfo.cleanupCallbacks = [];
|
|
1390
|
+
nodeInfo.beforeRenderCallbacks = [];
|
|
1391
|
+
nodeInfo.afterRenderCallbacks = [];
|
|
1392
|
+
nodeInfo.resizeCallbacks = [];
|
|
1393
|
+
return applyMaskIfNeeded(applyNodeTransformation(nodeInfo.fragmentNodeFunc({
|
|
1394
|
+
uniforms: nodeInfo.uniforms ?? {},
|
|
1395
|
+
childNode: composedChildren,
|
|
1396
|
+
onCleanup: nodeSpecificOnCleanup,
|
|
1397
|
+
onBeforeRender: nodeSpecificOnBeforeRender,
|
|
1398
|
+
onAfterRender: nodeSpecificOnAfterRender,
|
|
1399
|
+
onResize: nodeSpecificOnResize,
|
|
1400
|
+
canvas: canvasElement,
|
|
1401
|
+
dimensions: {
|
|
1402
|
+
width: currentWidth,
|
|
1403
|
+
height: currentHeight
|
|
1404
|
+
},
|
|
1405
|
+
renderer
|
|
1406
|
+
}), nodeInfo), nodeInfo, nodeId, processedMasks);
|
|
1407
|
+
} else {
|
|
1408
|
+
if (!forceRTT && hasUVPropagationOpportunity(sortedChildren)) {
|
|
1409
|
+
const composedChildrenResult$1 = composeSiblingsWithUVContext(sortedChildren, processedMasks, currentlyComposedNodes);
|
|
1410
|
+
return applyMaskIfNeeded(applyNodeTransformation(nodeInfo.fragmentNodeFunc({
|
|
1411
|
+
uniforms: nodeInfo.uniforms ?? {},
|
|
1412
|
+
childNode: composedChildrenResult$1,
|
|
1413
|
+
onCleanup: nodeSpecificOnCleanup,
|
|
1414
|
+
onBeforeRender: nodeSpecificOnBeforeRender,
|
|
1415
|
+
onAfterRender: nodeSpecificOnAfterRender,
|
|
1416
|
+
onResize: nodeSpecificOnResize,
|
|
1417
|
+
canvas: canvasElement,
|
|
1418
|
+
dimensions: {
|
|
1419
|
+
width: currentWidth,
|
|
1420
|
+
height: currentHeight
|
|
1421
|
+
},
|
|
1422
|
+
renderer
|
|
1423
|
+
}), nodeInfo), nodeInfo, nodeId, processedMasks);
|
|
1424
|
+
}
|
|
1425
|
+
let composedChildrenResult = void 0;
|
|
1426
|
+
for (let i = 0; i < sortedChildren.length; i++) {
|
|
1427
|
+
const childInfo = sortedChildren[i];
|
|
1428
|
+
let effectiveOpacity;
|
|
1429
|
+
if (childInfo.metadata.opacity === void 0) {
|
|
1430
|
+
effectiveOpacity = 1;
|
|
1431
|
+
childInfo.opacityUniform.value = effectiveOpacity;
|
|
1432
|
+
} else {
|
|
1433
|
+
effectiveOpacity = childInfo.metadata.opacity;
|
|
1434
|
+
childInfo.opacityUniform.value = effectiveOpacity;
|
|
1435
|
+
}
|
|
1436
|
+
if (childInfo.metadata.visible === false) continue;
|
|
1437
|
+
if (currentlyComposedNodes) currentlyComposedNodes.add(childInfo.id);
|
|
1438
|
+
const childHasChildren = findChildNodes(childInfo.id).length > 0;
|
|
1439
|
+
let childResult;
|
|
1440
|
+
if (childHasChildren) if (forceRTT) childResult = composeNodeTree(childInfo.id, processedMasks, currentlyComposedNodes, true);
|
|
1441
|
+
else if (canSkipRTT(childInfo)) childResult = composeUVContextChain(childInfo.id, processedMasks, currentlyComposedNodes);
|
|
1442
|
+
else if (isUVComposable(childInfo)) {
|
|
1443
|
+
const uvChain = findUVChain(childInfo.id);
|
|
1444
|
+
if (uvChain.length > 1) childResult = composeUVChain(uvChain, processedMasks, currentlyComposedNodes);
|
|
1445
|
+
else childResult = composeNodeTree(childInfo.id, processedMasks, currentlyComposedNodes);
|
|
1446
|
+
} else childResult = composeNodeTree(childInfo.id, processedMasks, currentlyComposedNodes);
|
|
1447
|
+
else {
|
|
1448
|
+
if (isUVComposable(childInfo) && childInfo.requiresChild && composedChildrenResult !== void 0) {
|
|
1449
|
+
const siblingChain = findSiblingUVChain(sortedChildren, i);
|
|
1450
|
+
if (siblingChain.length > 1) {
|
|
1451
|
+
childResult = composeSiblingUVChain(siblingChain, composedChildrenResult, currentlyComposedNodes);
|
|
1452
|
+
i += siblingChain.length - 1;
|
|
1453
|
+
composedChildrenResult = childResult;
|
|
1454
|
+
continue;
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
{
|
|
1458
|
+
const childSpecificOnCleanup = (callback) => {
|
|
1459
|
+
childInfo.cleanupCallbacks.push(callback);
|
|
1460
|
+
};
|
|
1461
|
+
const childSpecificOnBeforeRender = (callback) => {
|
|
1462
|
+
childInfo.beforeRenderCallbacks.push(callback);
|
|
1463
|
+
};
|
|
1464
|
+
const childSpecificOnAfterRender = (callback) => {
|
|
1465
|
+
childInfo.afterRenderCallbacks.push(callback);
|
|
1466
|
+
};
|
|
1467
|
+
const childSpecificOnResize = (callback) => {
|
|
1468
|
+
childInfo.resizeCallbacks.push(callback);
|
|
1469
|
+
};
|
|
1470
|
+
let effectiveChildNode = composedChildrenResult;
|
|
1471
|
+
if (childInfo.requiresRTT && composedChildrenResult !== void 0) effectiveChildNode = applyBlendMode(vec4(0, 0, 0, 0), composedChildrenResult, "normal", 1);
|
|
1472
|
+
childInfo.cleanupCallbacks = [];
|
|
1473
|
+
childInfo.beforeRenderCallbacks = [];
|
|
1474
|
+
childInfo.afterRenderCallbacks = [];
|
|
1475
|
+
childInfo.resizeCallbacks = [];
|
|
1476
|
+
childResult = applyMaskIfNeeded(applyNodeTransformation(childInfo.fragmentNodeFunc({
|
|
1477
|
+
uniforms: childInfo.uniforms ?? {},
|
|
1478
|
+
childNode: effectiveChildNode,
|
|
1479
|
+
onCleanup: childSpecificOnCleanup,
|
|
1480
|
+
onBeforeRender: childSpecificOnBeforeRender,
|
|
1481
|
+
onAfterRender: childSpecificOnAfterRender,
|
|
1482
|
+
onResize: childSpecificOnResize,
|
|
1483
|
+
canvas: canvasElement,
|
|
1484
|
+
dimensions: {
|
|
1485
|
+
width: currentWidth,
|
|
1486
|
+
height: currentHeight
|
|
1487
|
+
},
|
|
1488
|
+
renderer
|
|
1489
|
+
}), childInfo), childInfo, childInfo.id, processedMasks);
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
if (childInfo.requiresChild && childInfo.metadata.blendMode === "normal" && !childHasChildren) composedChildrenResult = applyBlendMode(vec4(0, 0, 0, 0), childResult, "normal", childInfo.opacityUniform);
|
|
1493
|
+
else if (composedChildrenResult === void 0) if (nodeInfo.requiresRTT || effectiveOpacity !== 1) composedChildrenResult = applyBlendMode(vec4(1, 1, 1, 0), childResult, childInfo.metadata.blendMode, childInfo.opacityUniform);
|
|
1494
|
+
else composedChildrenResult = childResult;
|
|
1495
|
+
else composedChildrenResult = applyBlendMode(composedChildrenResult, childResult, childInfo.metadata.blendMode, childInfo.opacityUniform);
|
|
1496
|
+
}
|
|
1497
|
+
nodeInfo.cleanupCallbacks.forEach((callback) => {
|
|
1498
|
+
try {
|
|
1499
|
+
callback();
|
|
1500
|
+
} catch (e) {
|
|
1501
|
+
console.error("Error in cleanup callback:", e);
|
|
1502
|
+
}
|
|
1503
|
+
});
|
|
1504
|
+
nodeInfo.cleanupCallbacks = [];
|
|
1505
|
+
nodeInfo.beforeRenderCallbacks = [];
|
|
1506
|
+
nodeInfo.afterRenderCallbacks = [];
|
|
1507
|
+
nodeInfo.resizeCallbacks = [];
|
|
1508
|
+
return applyMaskIfNeeded(applyNodeTransformation(nodeInfo.fragmentNodeFunc({
|
|
1509
|
+
uniforms: nodeInfo.uniforms ?? {},
|
|
1510
|
+
childNode: composedChildrenResult,
|
|
1511
|
+
onCleanup: nodeSpecificOnCleanup,
|
|
1512
|
+
onBeforeRender: nodeSpecificOnBeforeRender,
|
|
1513
|
+
onAfterRender: nodeSpecificOnAfterRender,
|
|
1514
|
+
onResize: nodeSpecificOnResize,
|
|
1515
|
+
canvas: canvasElement,
|
|
1516
|
+
dimensions: {
|
|
1517
|
+
width: currentWidth,
|
|
1518
|
+
height: currentHeight
|
|
1519
|
+
},
|
|
1520
|
+
renderer
|
|
1521
|
+
}), nodeInfo), nodeInfo, nodeId, processedMasks);
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
};
|
|
1525
|
+
const registerNode = (id, fragmentNodeFunc, parentId, metadata, uniforms = {}, componentDefinition$55) => {
|
|
1526
|
+
if (fragmentNodeFunc === null) {
|
|
1527
|
+
const queueIndex = pendingRegistrationQueue.findIndex((item) => item.id === id);
|
|
1528
|
+
if (queueIndex !== -1) {
|
|
1529
|
+
pendingRegistrationQueue.splice(queueIndex, 1);
|
|
1530
|
+
return;
|
|
1531
|
+
}
|
|
1532
|
+
removeNode(id);
|
|
1533
|
+
return;
|
|
1534
|
+
}
|
|
1535
|
+
if (!isRendererReady) {
|
|
1536
|
+
const existing = pendingRegistrationQueue.findIndex((item) => item.id === id);
|
|
1537
|
+
if (existing !== -1) pendingRegistrationQueue[existing] = {
|
|
1538
|
+
id,
|
|
1539
|
+
fragmentNodeFunc,
|
|
1540
|
+
parentId,
|
|
1541
|
+
metadata,
|
|
1542
|
+
uniforms,
|
|
1543
|
+
componentDefinition: componentDefinition$55
|
|
1544
|
+
};
|
|
1545
|
+
else pendingRegistrationQueue.push({
|
|
1546
|
+
id,
|
|
1547
|
+
fragmentNodeFunc,
|
|
1548
|
+
parentId,
|
|
1549
|
+
metadata,
|
|
1550
|
+
uniforms,
|
|
1551
|
+
componentDefinition: componentDefinition$55
|
|
1552
|
+
});
|
|
1553
|
+
return;
|
|
1554
|
+
}
|
|
1555
|
+
let defaultRenderOrder = 0;
|
|
1556
|
+
if (parentId !== null) {
|
|
1557
|
+
const siblings = parentToChildren.get(parentId);
|
|
1558
|
+
if (siblings && siblings.size > 0) {
|
|
1559
|
+
let maxOrder = 0;
|
|
1560
|
+
for (const siblingId of siblings) {
|
|
1561
|
+
const sibling = nodeRegistry.nodes.get(siblingId);
|
|
1562
|
+
if (sibling && sibling.metadata.renderOrder > maxOrder) maxOrder = sibling.metadata.renderOrder;
|
|
1563
|
+
}
|
|
1564
|
+
defaultRenderOrder = maxOrder + 1;
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
const opacityUniform = uniform(metadata?.opacity !== void 0 ? metadata.opacity : 1);
|
|
1568
|
+
let transformUniforms = void 0;
|
|
1569
|
+
if (metadata?.transform) {
|
|
1570
|
+
const aspectRatio = currentWidth / Math.max(1, currentHeight);
|
|
1571
|
+
transformUniforms = {
|
|
1572
|
+
offsetX: uniform(metadata.transform.offsetX),
|
|
1573
|
+
offsetY: uniform(metadata.transform.offsetY),
|
|
1574
|
+
rotation: uniform(metadata.transform.rotation),
|
|
1575
|
+
scale: uniform(metadata.transform.scale),
|
|
1576
|
+
anchorX: uniform(metadata.transform.anchorX),
|
|
1577
|
+
anchorY: uniform(metadata.transform.anchorY),
|
|
1578
|
+
edges: uniform(metadata.transform.edges === "stretch" ? 0 : metadata.transform.edges === "transparent" ? 1 : metadata.transform.edges === "mirror" ? 2 : 3),
|
|
1579
|
+
aspectRatio: uniform(aspectRatio)
|
|
1580
|
+
};
|
|
1581
|
+
}
|
|
1582
|
+
const nodeInfo = {
|
|
1583
|
+
id,
|
|
1584
|
+
componentName: componentDefinition$55?.name || "Unknown",
|
|
1585
|
+
fragmentNodeFunc,
|
|
1586
|
+
parentId,
|
|
1587
|
+
requiresRTT: componentDefinition$55?.requiresRTT || false,
|
|
1588
|
+
requiresChild: componentDefinition$55?.requiresChild || false,
|
|
1589
|
+
opacityUniform,
|
|
1590
|
+
metadata: {
|
|
1591
|
+
blendMode: metadata?.blendMode || "normal",
|
|
1592
|
+
opacity: metadata?.opacity,
|
|
1593
|
+
visible: metadata?.visible === false ? false : true,
|
|
1594
|
+
id: metadata?.id,
|
|
1595
|
+
mask: metadata?.mask,
|
|
1596
|
+
renderOrder: metadata?.renderOrder !== void 0 ? metadata?.renderOrder : defaultRenderOrder,
|
|
1597
|
+
transform: metadata?.transform
|
|
1598
|
+
},
|
|
1599
|
+
uniforms,
|
|
1600
|
+
cleanupCallbacks: [],
|
|
1601
|
+
beforeRenderCallbacks: [],
|
|
1602
|
+
afterRenderCallbacks: [],
|
|
1603
|
+
resizeCallbacks: [],
|
|
1604
|
+
transformUniforms,
|
|
1605
|
+
transformRTTActive: false,
|
|
1606
|
+
uvTransformFunc: componentDefinition$55?.uvTransformNode,
|
|
1607
|
+
acceptsUVContext: componentDefinition$55?.acceptsUVContext || false
|
|
1608
|
+
};
|
|
1609
|
+
nodeRegistry.nodes.set(id, nodeInfo);
|
|
1610
|
+
if (parentId === null) nodeRegistry.rootId = id;
|
|
1611
|
+
const childrenSet = parentToChildren.get(parentId) || /* @__PURE__ */ new Set();
|
|
1612
|
+
childrenSet.add(id);
|
|
1613
|
+
parentToChildren.set(parentId, childrenSet);
|
|
1614
|
+
if (material && isInitialized && currentWidth > 0 && currentHeight > 0) {
|
|
1615
|
+
if (!registrationQueue.includes(id)) registrationQueue.push(id);
|
|
1616
|
+
if (registrationBatchRAF === null) registrationBatchRAF = requestAnimationFrame(() => {
|
|
1617
|
+
registrationBatchRAF = null;
|
|
1618
|
+
registrationQueue = [];
|
|
1619
|
+
updateMaterial();
|
|
1620
|
+
});
|
|
1621
|
+
} else if (material && isInitialized) {
|
|
1622
|
+
if (!materialUpdatePending) {
|
|
1623
|
+
materialUpdatePending = true;
|
|
1624
|
+
requestAnimationFrame(() => {
|
|
1625
|
+
materialUpdatePending = false;
|
|
1626
|
+
if (currentWidth > 0 && currentHeight > 0) updateMaterial();
|
|
1627
|
+
});
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
};
|
|
1631
|
+
const updateUniformValue$1 = (nodeId, uniformName, value) => {
|
|
1632
|
+
const nodeInfo = nodeRegistry.nodes.get(nodeId);
|
|
1633
|
+
if (!nodeInfo || !nodeInfo.uniforms) return;
|
|
1634
|
+
const uniformDefinition = nodeInfo.uniforms[uniformName];
|
|
1635
|
+
if (!uniformDefinition || !uniformDefinition.uniform) return;
|
|
1636
|
+
if (uniformDefinition.transform) updateUniformValue(uniformDefinition, value);
|
|
1637
|
+
else uniformDefinition.uniform.value = value;
|
|
1638
|
+
renderFrame();
|
|
1639
|
+
};
|
|
1640
|
+
const updateNodeMetadata = (nodeId, metadata) => {
|
|
1641
|
+
const existingNode = nodeRegistry.nodes.get(nodeId);
|
|
1642
|
+
if (!existingNode) return;
|
|
1643
|
+
let needsRecompose = false;
|
|
1644
|
+
if (metadata.blendMode !== void 0 && existingNode.metadata.blendMode !== metadata.blendMode) {
|
|
1645
|
+
existingNode.metadata.blendMode = metadata.blendMode;
|
|
1646
|
+
needsRecompose = true;
|
|
1647
|
+
}
|
|
1648
|
+
if (metadata.opacity !== void 0 && existingNode.metadata.opacity !== metadata.opacity) {
|
|
1649
|
+
existingNode.metadata.opacity = metadata.opacity;
|
|
1650
|
+
existingNode.opacityUniform.value = metadata.opacity;
|
|
1651
|
+
}
|
|
1652
|
+
if (metadata.renderOrder !== void 0 && existingNode.metadata.renderOrder !== metadata.renderOrder) {
|
|
1653
|
+
existingNode.metadata.renderOrder = metadata.renderOrder;
|
|
1654
|
+
needsRecompose = true;
|
|
1655
|
+
}
|
|
1656
|
+
const newVisible = metadata.visible === false ? false : true;
|
|
1657
|
+
if (existingNode.metadata.visible !== newVisible) {
|
|
1658
|
+
existingNode.metadata.visible = newVisible;
|
|
1659
|
+
needsRecompose = true;
|
|
1660
|
+
}
|
|
1661
|
+
if (metadata.id !== void 0 && existingNode.metadata.id !== metadata.id) {
|
|
1662
|
+
existingNode.metadata.id = metadata.id;
|
|
1663
|
+
needsRecompose = true;
|
|
1664
|
+
}
|
|
1665
|
+
if (metadata.mask !== void 0 && (existingNode.metadata.mask?.source !== metadata.mask?.source || existingNode.metadata.mask?.type !== metadata.mask?.type)) {
|
|
1666
|
+
existingNode.metadata.mask = metadata.mask;
|
|
1667
|
+
needsRecompose = true;
|
|
1668
|
+
}
|
|
1669
|
+
if (metadata.transform !== void 0) {
|
|
1670
|
+
const oldTransformState = existingNode.metadata.transform ? needsTransformation(existingNode.metadata.transform) : false;
|
|
1671
|
+
const newTransformState = needsTransformation(metadata.transform);
|
|
1672
|
+
existingNode.metadata.transform = metadata.transform;
|
|
1673
|
+
if (!existingNode.transformUniforms && metadata.transform) {
|
|
1674
|
+
const aspectRatio = currentWidth / Math.max(1, currentHeight);
|
|
1675
|
+
existingNode.transformUniforms = {
|
|
1676
|
+
offsetX: uniform(metadata.transform.offsetX),
|
|
1677
|
+
offsetY: uniform(metadata.transform.offsetY),
|
|
1678
|
+
rotation: uniform(metadata.transform.rotation),
|
|
1679
|
+
scale: uniform(metadata.transform.scale),
|
|
1680
|
+
anchorX: uniform(metadata.transform.anchorX),
|
|
1681
|
+
anchorY: uniform(metadata.transform.anchorY),
|
|
1682
|
+
edges: uniform(metadata.transform.edges === "stretch" ? 0 : metadata.transform.edges === "transparent" ? 1 : metadata.transform.edges === "mirror" ? 2 : 3),
|
|
1683
|
+
aspectRatio: uniform(aspectRatio)
|
|
1684
|
+
};
|
|
1685
|
+
} else if (existingNode.transformUniforms) {
|
|
1686
|
+
existingNode.transformUniforms.offsetX.value = metadata.transform.offsetX;
|
|
1687
|
+
existingNode.transformUniforms.offsetY.value = metadata.transform.offsetY;
|
|
1688
|
+
existingNode.transformUniforms.rotation.value = metadata.transform.rotation;
|
|
1689
|
+
existingNode.transformUniforms.scale.value = metadata.transform.scale;
|
|
1690
|
+
existingNode.transformUniforms.anchorX.value = metadata.transform.anchorX;
|
|
1691
|
+
existingNode.transformUniforms.anchorY.value = metadata.transform.anchorY;
|
|
1692
|
+
existingNode.transformUniforms.edges.value = metadata.transform.edges === "stretch" ? 0 : metadata.transform.edges === "transparent" ? 1 : metadata.transform.edges === "mirror" ? 2 : 3;
|
|
1693
|
+
}
|
|
1694
|
+
if (newTransformState && !existingNode.transformRTTActive) {
|
|
1695
|
+
existingNode.transformRTTActive = true;
|
|
1696
|
+
needsRecompose = true;
|
|
1697
|
+
}
|
|
1698
|
+
if (!oldTransformState && newTransformState && !existingNode.transformRTTActive) needsRecompose = true;
|
|
1699
|
+
}
|
|
1700
|
+
if (needsRecompose && material && isInitialized) {
|
|
1701
|
+
if (!metadataUpdateQueue.includes(nodeId)) metadataUpdateQueue.push(nodeId);
|
|
1702
|
+
if (metadataUpdateBatchRAF === null) metadataUpdateBatchRAF = requestAnimationFrame(() => {
|
|
1703
|
+
metadataUpdateBatchRAF = null;
|
|
1704
|
+
metadataUpdateQueue = [];
|
|
1705
|
+
updateMaterial();
|
|
1706
|
+
});
|
|
1707
|
+
} else renderFrame();
|
|
1708
|
+
};
|
|
1709
|
+
const removeNode = (id) => {
|
|
1710
|
+
if (!nodeRegistry.nodes.has(id)) return;
|
|
1711
|
+
const nodeInfo = nodeRegistry.nodes.get(id);
|
|
1712
|
+
if (nodeInfo && nodeInfo.cleanupCallbacks.length > 0) for (const callback of nodeInfo.cleanupCallbacks) try {
|
|
1713
|
+
callback();
|
|
1714
|
+
} catch (e) {
|
|
1715
|
+
console.error(`Error executing cleanup callback for node ${id}:`, e);
|
|
1716
|
+
}
|
|
1717
|
+
const childNodes = findChildNodes(id);
|
|
1718
|
+
for (const child of childNodes) removeNode(child.id);
|
|
1719
|
+
if (nodeRegistry.rootId === id) nodeRegistry.rootId = null;
|
|
1720
|
+
if (nodeInfo) {
|
|
1721
|
+
const childrenSet = parentToChildren.get(nodeInfo.parentId);
|
|
1722
|
+
if (childrenSet) {
|
|
1723
|
+
childrenSet.delete(id);
|
|
1724
|
+
if (childrenSet.size === 0) parentToChildren.delete(nodeInfo.parentId);
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
nodeRegistry.nodes.delete(id);
|
|
1728
|
+
if (material && isInitialized) updateMaterial();
|
|
1729
|
+
};
|
|
1730
|
+
const executeBeforeRenderCallbacks = (deltaTime) => {
|
|
1731
|
+
const params = {
|
|
1732
|
+
deltaTime,
|
|
1733
|
+
pointer: {
|
|
1734
|
+
x: pointerX,
|
|
1735
|
+
y: pointerY
|
|
1736
|
+
},
|
|
1737
|
+
pointerActive,
|
|
1738
|
+
dimensions: {
|
|
1739
|
+
width: currentWidth,
|
|
1740
|
+
height: currentHeight
|
|
1741
|
+
}
|
|
1742
|
+
};
|
|
1743
|
+
for (const nodeInfo of nodeRegistry.nodes.values()) if (nodeInfo.beforeRenderCallbacks.length > 0) for (const callback of nodeInfo.beforeRenderCallbacks) try {
|
|
1744
|
+
callback(params);
|
|
1745
|
+
} catch (e) {
|
|
1746
|
+
console.error(`Error executing before render callback for node ${nodeInfo.id}:`, e);
|
|
1747
|
+
}
|
|
1748
|
+
};
|
|
1749
|
+
const executeAfterRenderCallbacks = (deltaTime) => {
|
|
1750
|
+
const params = {
|
|
1751
|
+
deltaTime,
|
|
1752
|
+
pointer: {
|
|
1753
|
+
x: pointerX,
|
|
1754
|
+
y: pointerY
|
|
1755
|
+
},
|
|
1756
|
+
pointerActive,
|
|
1757
|
+
dimensions: {
|
|
1758
|
+
width: currentWidth,
|
|
1759
|
+
height: currentHeight
|
|
1760
|
+
}
|
|
1761
|
+
};
|
|
1762
|
+
for (const nodeInfo of nodeRegistry.nodes.values()) if (nodeInfo.afterRenderCallbacks.length > 0) for (const callback of nodeInfo.afterRenderCallbacks) try {
|
|
1763
|
+
callback(params);
|
|
1764
|
+
} catch (e) {
|
|
1765
|
+
console.error(`Error executing after render callback for node ${nodeInfo.id}:`, e);
|
|
1766
|
+
}
|
|
1767
|
+
};
|
|
1768
|
+
const renderFrame = async () => {
|
|
1769
|
+
if (!canRender()) return;
|
|
1770
|
+
const frameStartTime = enablePerformanceTracking ? performance.now() : 0;
|
|
1771
|
+
const currentTime = frameStartTime || performance.now();
|
|
1772
|
+
const deltaTime = lastRenderTime > 0 ? (currentTime - lastRenderTime) / 1e3 : .016;
|
|
1773
|
+
const OFF_SCREEN_FPS_INTERVAL = 1e3;
|
|
1774
|
+
if (!isVisible && lastRenderTime > 0) {
|
|
1775
|
+
if (currentTime - lastRenderTime < OFF_SCREEN_FPS_INTERVAL) return;
|
|
1776
|
+
}
|
|
1777
|
+
const cappedDeltaTime = Math.min(deltaTime, .1);
|
|
1778
|
+
lastRenderTime = currentTime;
|
|
1779
|
+
if (enablePerformanceTracking) performance.mark("shader-cpu-start");
|
|
1780
|
+
executeBeforeRenderCallbacks(cappedDeltaTime);
|
|
1781
|
+
try {
|
|
1782
|
+
if (isUpdatingMaterial) return;
|
|
1783
|
+
if (enablePerformanceTracking) performance.mark("shader-gpu-start");
|
|
1784
|
+
renderer.render(scene, camera);
|
|
1785
|
+
executeAfterRenderCallbacks(cappedDeltaTime);
|
|
1786
|
+
if (enablePerformanceTracking) {
|
|
1787
|
+
performance.mark("shader-gpu-end");
|
|
1788
|
+
if (renderer instanceof WebGPURenderer) try {
|
|
1789
|
+
const backend = renderer.backend;
|
|
1790
|
+
if (backend && backend.get && backend.get(renderer)) {
|
|
1791
|
+
const renderContext = backend.get(renderer);
|
|
1792
|
+
if (renderContext?.timestampQuery) {
|
|
1793
|
+
const gpuTime = renderContext.timestampQuery.getResult();
|
|
1794
|
+
if (gpuTime !== null && gpuTime !== void 0) performanceTracker.recordGpuTime(gpuTime / 1e6);
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
} catch (e) {}
|
|
1798
|
+
try {
|
|
1799
|
+
performance.measure("shader-gpu-time", "shader-gpu-start", "shader-gpu-end");
|
|
1800
|
+
const gpuMeasure = performance.getEntriesByName("shader-gpu-time")[0];
|
|
1801
|
+
if (gpuMeasure) performanceTracker.recordGpuTime(gpuMeasure.duration);
|
|
1802
|
+
performance.clearMarks("shader-gpu-start");
|
|
1803
|
+
performance.clearMarks("shader-gpu-end");
|
|
1804
|
+
performance.clearMeasures("shader-gpu-time");
|
|
1805
|
+
} catch (e) {}
|
|
1806
|
+
}
|
|
1807
|
+
if (enablePerformanceTracking) {
|
|
1808
|
+
performance.mark("shader-cpu-end");
|
|
1809
|
+
try {
|
|
1810
|
+
performance.measure("shader-cpu-time", "shader-cpu-start", "shader-cpu-end");
|
|
1811
|
+
const cpuMeasure = performance.getEntriesByName("shader-cpu-time")[0];
|
|
1812
|
+
if (cpuMeasure) performanceTracker.recordCpuTime(cpuMeasure.duration);
|
|
1813
|
+
performance.clearMarks("shader-cpu-start");
|
|
1814
|
+
performance.clearMarks("shader-cpu-end");
|
|
1815
|
+
performance.clearMeasures("shader-cpu-time");
|
|
1816
|
+
} catch (e) {}
|
|
1817
|
+
const frameTime = performance.now() - frameStartTime;
|
|
1818
|
+
performanceTracker.recordFrame(frameTime);
|
|
1819
|
+
}
|
|
1820
|
+
} catch (error) {
|
|
1821
|
+
console.error("Render frame error:", error);
|
|
1822
|
+
}
|
|
1823
|
+
};
|
|
1824
|
+
const updatePerformanceNodeCounts = () => {
|
|
1825
|
+
const nodeCount = Math.max(0, nodeRegistry.nodes.size - 1);
|
|
1826
|
+
const rttNodeCount = actualRTTOperations;
|
|
1827
|
+
performanceTracker.updateNodeCounts(nodeCount, rttNodeCount);
|
|
1828
|
+
};
|
|
1829
|
+
const getPerformanceStats = () => {
|
|
1830
|
+
updatePerformanceNodeCounts();
|
|
1831
|
+
const rendererInfo = renderer?.info;
|
|
1832
|
+
return performanceTracker.getStats(rendererInfo);
|
|
1833
|
+
};
|
|
1834
|
+
const startAnimation = () => {
|
|
1835
|
+
if (animationFrameId || !shouldAnimate) return;
|
|
1836
|
+
performanceTracker.setRendering(true);
|
|
1837
|
+
const animate = () => {
|
|
1838
|
+
animationFrameId = requestAnimationFrame(animate);
|
|
1839
|
+
renderFrame().catch(console.warn);
|
|
1840
|
+
};
|
|
1841
|
+
animate();
|
|
1842
|
+
};
|
|
1843
|
+
const stopAnimation = () => {
|
|
1844
|
+
if (animationFrameId) {
|
|
1845
|
+
cancelAnimationFrame(animationFrameId);
|
|
1846
|
+
animationFrameId = null;
|
|
1847
|
+
}
|
|
1848
|
+
performanceTracker.setRendering(false);
|
|
1849
|
+
};
|
|
1850
|
+
const updatePointerCoords = (event) => {
|
|
1851
|
+
if (!canvasElement) return;
|
|
1852
|
+
let clientX;
|
|
1853
|
+
let clientY;
|
|
1854
|
+
if ("touches" in event) {
|
|
1855
|
+
if (event.touches.length === 0) return;
|
|
1856
|
+
clientX = event.touches[0].clientX;
|
|
1857
|
+
clientY = event.touches[0].clientY;
|
|
1858
|
+
} else {
|
|
1859
|
+
clientX = event.clientX;
|
|
1860
|
+
clientY = event.clientY;
|
|
1861
|
+
}
|
|
1862
|
+
const rect = canvasElement.getBoundingClientRect();
|
|
1863
|
+
const x = (clientX - rect.left) / rect.width;
|
|
1864
|
+
const y = (clientY - rect.top) / rect.height;
|
|
1865
|
+
pointerX = x;
|
|
1866
|
+
pointerY = y;
|
|
1867
|
+
};
|
|
1868
|
+
const globalMouseMoveHandler = (event) => {
|
|
1869
|
+
if (!isInitialized || !canvasElement) return;
|
|
1870
|
+
updatePointerCoords(event);
|
|
1871
|
+
};
|
|
1872
|
+
const globalTouchMoveHandler = (event) => {
|
|
1873
|
+
if (!isInitialized || !canvasElement) return;
|
|
1874
|
+
updatePointerCoords(event);
|
|
1875
|
+
};
|
|
1876
|
+
const globalMouseUpHandler = () => {
|
|
1877
|
+
if (!isInitialized) return;
|
|
1878
|
+
pointerActive = false;
|
|
1879
|
+
renderFrame().catch(console.warn);
|
|
1880
|
+
};
|
|
1881
|
+
const globalTouchEndHandler = () => {
|
|
1882
|
+
if (!isInitialized) return;
|
|
1883
|
+
pointerActive = false;
|
|
1884
|
+
renderFrame().catch(console.warn);
|
|
1885
|
+
};
|
|
1886
|
+
const canvasMouseDownHandler = () => {
|
|
1887
|
+
pointerActive = true;
|
|
1888
|
+
renderFrame().catch(console.warn);
|
|
1889
|
+
};
|
|
1890
|
+
const canvasTouchStartHandler = () => {
|
|
1891
|
+
pointerActive = true;
|
|
1892
|
+
renderFrame().catch(console.warn);
|
|
1893
|
+
};
|
|
1894
|
+
const processQueuedRegistrations = () => {
|
|
1895
|
+
if (pendingRegistrationQueue.length === 0) return;
|
|
1896
|
+
const queue = [...pendingRegistrationQueue];
|
|
1897
|
+
pendingRegistrationQueue = [];
|
|
1898
|
+
for (const { id, fragmentNodeFunc, parentId, metadata, uniforms, componentDefinition: componentDefinition$55 } of queue) if (fragmentNodeFunc) registerNode(id, fragmentNodeFunc, parentId, metadata, uniforms, componentDefinition$55);
|
|
1899
|
+
};
|
|
1900
|
+
const initialize = async ({ canvas, enablePerformanceTracking: enableTracking = false }) => {
|
|
1901
|
+
if (isInitialized || isInitializing) return;
|
|
1902
|
+
enablePerformanceTracking = enableTracking;
|
|
1903
|
+
isInitializing = true;
|
|
1904
|
+
initializationAbortController = new AbortController();
|
|
1905
|
+
const localAbortController = initializationAbortController;
|
|
1906
|
+
try {
|
|
1907
|
+
canvasElement = canvas;
|
|
1908
|
+
scene = new Scene();
|
|
1909
|
+
scene.background = null;
|
|
1910
|
+
camera = new OrthographicCamera(-1, 1, 1, -1, .1, 10);
|
|
1911
|
+
camera.position.z = 1;
|
|
1912
|
+
camera.lookAt(0, 0, 0);
|
|
1913
|
+
globalEventUnregister = globalEventManager.register({
|
|
1914
|
+
onMouseMove: globalMouseMoveHandler,
|
|
1915
|
+
onTouchMove: globalTouchMoveHandler,
|
|
1916
|
+
onMouseUp: globalMouseUpHandler,
|
|
1917
|
+
onTouchEnd: globalTouchEndHandler
|
|
1918
|
+
});
|
|
1919
|
+
canvas.addEventListener("mousedown", canvasMouseDownHandler);
|
|
1920
|
+
canvas.addEventListener("touchstart", canvasTouchStartHandler);
|
|
1921
|
+
unloadHandler = () => {
|
|
1922
|
+
cleanup();
|
|
1923
|
+
};
|
|
1924
|
+
window.addEventListener("beforeunload", unloadHandler);
|
|
1925
|
+
if (localAbortController.signal.aborted) return;
|
|
1926
|
+
try {
|
|
1927
|
+
const rendererOptions = {
|
|
1928
|
+
canvas,
|
|
1929
|
+
antialias: true,
|
|
1930
|
+
alpha: true,
|
|
1931
|
+
depth: false,
|
|
1932
|
+
powerPreference: "high-performance"
|
|
1933
|
+
};
|
|
1934
|
+
if (enablePerformanceTracking) {
|
|
1935
|
+
rendererOptions.forceWebGL = false;
|
|
1936
|
+
rendererOptions.requiredFeatures = ["timestamp-query"];
|
|
1937
|
+
}
|
|
1938
|
+
renderer = new WebGPURenderer(rendererOptions);
|
|
1939
|
+
await renderer.init();
|
|
1940
|
+
if (localAbortController.signal.aborted) return;
|
|
1941
|
+
} catch (e) {
|
|
1942
|
+
if (localAbortController.signal.aborted) return;
|
|
1943
|
+
console.warn("[Shaders] WebGPU initialization failed, falling back to WebGL:", e);
|
|
1944
|
+
try {
|
|
1945
|
+
renderer = new WebGLRenderer({
|
|
1946
|
+
canvas,
|
|
1947
|
+
antialias: true,
|
|
1948
|
+
alpha: true,
|
|
1949
|
+
depth: false,
|
|
1950
|
+
powerPreference: "high-performance"
|
|
1951
|
+
});
|
|
1952
|
+
if (localAbortController.signal.aborted) return;
|
|
1953
|
+
} catch (webglError) {
|
|
1954
|
+
if (localAbortController.signal.aborted) return;
|
|
1955
|
+
console.error("[Shaders] Both WebGPU and WebGL initialization failed:", webglError);
|
|
1956
|
+
return;
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
if (localAbortController.signal.aborted) return;
|
|
1960
|
+
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
|
|
1961
|
+
renderer.outputColorSpace = SRGBColorSpace;
|
|
1962
|
+
material = new MeshBasicNodeMaterial({ transparent: true });
|
|
1963
|
+
material.fragmentNode = vec4(0, 0, 0, 0);
|
|
1964
|
+
mesh = new Mesh(new PlaneGeometry(2, 2), material);
|
|
1965
|
+
scene.add(mesh);
|
|
1966
|
+
const parentElement = canvas.parentElement;
|
|
1967
|
+
if (!parentElement) {
|
|
1968
|
+
console.warn("[Shaders] Canvas has no parent element for resize observation");
|
|
1969
|
+
return;
|
|
1970
|
+
}
|
|
1971
|
+
resizeObserver = new ResizeObserver(handleResize);
|
|
1972
|
+
resizeObserver.observe(parentElement);
|
|
1973
|
+
intersectionObserver = new IntersectionObserver(handleVisibilityChange, { threshold: 0 });
|
|
1974
|
+
intersectionObserver.observe(canvas);
|
|
1975
|
+
const rect = canvas.getBoundingClientRect();
|
|
1976
|
+
isVisible = rect.width > 0 && rect.height > 0 && rect.top < window.innerHeight && rect.bottom > 0 && rect.left < window.innerWidth && rect.right > 0;
|
|
1977
|
+
shouldAnimate = true;
|
|
1978
|
+
const { width, height } = canvas.getBoundingClientRect();
|
|
1979
|
+
const roundedWidth = Math.round(width);
|
|
1980
|
+
const roundedHeight = Math.round(height);
|
|
1981
|
+
if (roundedWidth > 0 && roundedHeight > 0) {
|
|
1982
|
+
currentWidth = roundedWidth;
|
|
1983
|
+
currentHeight = roundedHeight;
|
|
1984
|
+
hasInitialDimensions = true;
|
|
1985
|
+
renderer.setSize(roundedWidth, roundedHeight, false);
|
|
1986
|
+
const aspectRatio = roundedWidth / roundedHeight;
|
|
1987
|
+
const frustumHeight = 2;
|
|
1988
|
+
const frustumWidth = frustumHeight * aspectRatio;
|
|
1989
|
+
camera.left = -frustumWidth / 2;
|
|
1990
|
+
camera.right = frustumWidth / 2;
|
|
1991
|
+
camera.top = frustumHeight / 2;
|
|
1992
|
+
camera.bottom = -frustumHeight / 2;
|
|
1993
|
+
camera.updateProjectionMatrix();
|
|
1994
|
+
mesh.scale.set(frustumWidth, frustumHeight, 1);
|
|
1995
|
+
await renderFrame();
|
|
1996
|
+
} else hasInitialDimensions = false;
|
|
1997
|
+
if (shouldAnimate) startAnimation();
|
|
1998
|
+
if (!localAbortController.signal.aborted) {
|
|
1999
|
+
isInitialized = true;
|
|
2000
|
+
isRendererReady = true;
|
|
2001
|
+
processQueuedRegistrations();
|
|
2002
|
+
}
|
|
2003
|
+
} catch (error) {
|
|
2004
|
+
console.error("[Shaders] Initialization error:", error);
|
|
2005
|
+
} finally {
|
|
2006
|
+
isInitializing = false;
|
|
2007
|
+
if (initializationAbortController === localAbortController) initializationAbortController = null;
|
|
2008
|
+
}
|
|
2009
|
+
};
|
|
2010
|
+
const showLicenseWarning = () => {
|
|
2011
|
+
if (!isDevelopment() || hasLoggedLicenseInfo) return;
|
|
2012
|
+
console.warn("Shaders is running in development mode. Please purchase a license at https://shaders.com to use it in production.");
|
|
2013
|
+
hasLoggedLicenseInfo = true;
|
|
2014
|
+
};
|
|
2015
|
+
const cleanup = () => {
|
|
2016
|
+
if (initializationAbortController) initializationAbortController.abort();
|
|
2017
|
+
if (resizeObserver) {
|
|
2018
|
+
resizeObserver.disconnect();
|
|
2019
|
+
resizeObserver = null;
|
|
2020
|
+
}
|
|
2021
|
+
if (intersectionObserver) {
|
|
2022
|
+
intersectionObserver.disconnect();
|
|
2023
|
+
intersectionObserver = null;
|
|
2024
|
+
}
|
|
2025
|
+
if (globalEventUnregister) {
|
|
2026
|
+
globalEventUnregister();
|
|
2027
|
+
globalEventUnregister = null;
|
|
2028
|
+
}
|
|
2029
|
+
if (canvasElement) {
|
|
2030
|
+
canvasElement.removeEventListener("mousedown", canvasMouseDownHandler);
|
|
2031
|
+
canvasElement.removeEventListener("touchstart", canvasTouchStartHandler);
|
|
2032
|
+
}
|
|
2033
|
+
if (unloadHandler) {
|
|
2034
|
+
window.removeEventListener("beforeunload", unloadHandler);
|
|
2035
|
+
unloadHandler = null;
|
|
2036
|
+
}
|
|
2037
|
+
stopAnimation();
|
|
2038
|
+
disposePreviousTextures();
|
|
2039
|
+
currentTextures.forEach((texture) => {
|
|
2040
|
+
try {
|
|
2041
|
+
if (texture?.renderTarget?.dispose) texture.renderTarget.dispose();
|
|
2042
|
+
} catch (e) {}
|
|
2043
|
+
});
|
|
2044
|
+
currentTextures.clear();
|
|
2045
|
+
nodeRegistry.nodes.clear();
|
|
2046
|
+
nodeRegistry.rootId = null;
|
|
2047
|
+
nodeRegistry.idToNodeId.clear();
|
|
2048
|
+
parentToChildren.clear();
|
|
2049
|
+
pendingRegistrationQueue = [];
|
|
2050
|
+
isRendererReady = false;
|
|
2051
|
+
registrationQueue = [];
|
|
2052
|
+
if (registrationBatchRAF !== null) {
|
|
2053
|
+
cancelAnimationFrame(registrationBatchRAF);
|
|
2054
|
+
registrationBatchRAF = null;
|
|
2055
|
+
}
|
|
2056
|
+
metadataUpdateQueue = [];
|
|
2057
|
+
if (metadataUpdateBatchRAF !== null) {
|
|
2058
|
+
cancelAnimationFrame(metadataUpdateBatchRAF);
|
|
2059
|
+
metadataUpdateBatchRAF = null;
|
|
2060
|
+
}
|
|
2061
|
+
pendingResize = null;
|
|
2062
|
+
isResizeScheduled = false;
|
|
2063
|
+
if (mesh) {
|
|
2064
|
+
if (scene) scene.remove(mesh);
|
|
2065
|
+
try {
|
|
2066
|
+
if (mesh.geometry && typeof mesh.geometry.dispose === "function") mesh.geometry.dispose();
|
|
2067
|
+
} catch (e) {}
|
|
2068
|
+
try {
|
|
2069
|
+
if (mesh.material instanceof Material && typeof mesh.material.dispose === "function") mesh.material.dispose();
|
|
2070
|
+
} catch (e) {}
|
|
2071
|
+
}
|
|
2072
|
+
if (renderer && typeof renderer.dispose === "function") try {
|
|
2073
|
+
renderer.dispose();
|
|
2074
|
+
} catch (e) {}
|
|
2075
|
+
canvasElement = null;
|
|
2076
|
+
renderer = null;
|
|
2077
|
+
camera = null;
|
|
2078
|
+
scene = null;
|
|
2079
|
+
mesh = null;
|
|
2080
|
+
material = null;
|
|
2081
|
+
isInitialized = false;
|
|
2082
|
+
isInitializing = false;
|
|
2083
|
+
hasInitialDimensions = false;
|
|
2084
|
+
initializationAbortController = null;
|
|
2085
|
+
currentWidth = 0;
|
|
2086
|
+
currentHeight = 0;
|
|
2087
|
+
isVisible = false;
|
|
2088
|
+
shouldAnimate = true;
|
|
2089
|
+
pointerX = .5;
|
|
2090
|
+
pointerY = .5;
|
|
2091
|
+
pointerActive = false;
|
|
2092
|
+
};
|
|
2093
|
+
const getRendererType = () => {
|
|
2094
|
+
if (!renderer) return null;
|
|
2095
|
+
return renderer instanceof WebGPURenderer ? "webgpu" : "webgl";
|
|
2096
|
+
};
|
|
2097
|
+
return {
|
|
2098
|
+
initialize,
|
|
2099
|
+
cleanup,
|
|
2100
|
+
registerNode,
|
|
2101
|
+
removeNode,
|
|
2102
|
+
updateUniformValue: updateUniformValue$1,
|
|
2103
|
+
updateNodeMetadata,
|
|
2104
|
+
showLicenseWarning,
|
|
2105
|
+
isInitialized: () => isInitialized,
|
|
2106
|
+
startAnimation,
|
|
2107
|
+
stopAnimation,
|
|
2108
|
+
getPerformanceStats,
|
|
2109
|
+
getNodeRegistry: () => ({ nodes: new Map(nodeRegistry.nodes) }),
|
|
2110
|
+
getRendererType,
|
|
2111
|
+
__testing: {
|
|
2112
|
+
isUVComposable,
|
|
2113
|
+
canSkipRTT,
|
|
2114
|
+
hasUVPropagationOpportunity,
|
|
2115
|
+
needsTransformation,
|
|
2116
|
+
findUVChain,
|
|
2117
|
+
findSiblingUVChain,
|
|
2118
|
+
findChildNodes,
|
|
2119
|
+
composeUVContextChain,
|
|
2120
|
+
composeUVChain,
|
|
2121
|
+
composeSiblingUVChain,
|
|
2122
|
+
composeSiblingsWithUVContext,
|
|
2123
|
+
applyMaskIfNeeded,
|
|
2124
|
+
applyNodeTransformation,
|
|
2125
|
+
getNodeRegistry: () => nodeRegistry,
|
|
2126
|
+
getParentToChildren: () => parentToChildren
|
|
2127
|
+
}
|
|
2128
|
+
};
|
|
1498
2129
|
}
|
|
1499
|
-
function
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
2130
|
+
function resolveMaskDependencies(nodes) {
|
|
2131
|
+
const elementIdToNodeId = /* @__PURE__ */ new Map();
|
|
2132
|
+
const maskDependencies = /* @__PURE__ */ new Map();
|
|
2133
|
+
const result = {
|
|
2134
|
+
processingOrder: [],
|
|
2135
|
+
maskSources: /* @__PURE__ */ new Map(),
|
|
2136
|
+
circularDependencies: []
|
|
2137
|
+
};
|
|
2138
|
+
nodes.forEach((node) => {
|
|
2139
|
+
if (node.elementId) elementIdToNodeId.set(node.elementId, node.id);
|
|
2140
|
+
});
|
|
2141
|
+
nodes.forEach((node) => {
|
|
2142
|
+
if (node.mask?.source) {
|
|
2143
|
+
const sourceElementId = node.mask.source.startsWith("#") ? node.mask.source.substring(1) : node.mask.source;
|
|
2144
|
+
const sourceNodeId = elementIdToNodeId.get(sourceElementId);
|
|
2145
|
+
if (sourceNodeId) {
|
|
2146
|
+
if (!maskDependencies.has(node.id)) maskDependencies.set(node.id, []);
|
|
2147
|
+
maskDependencies.get(node.id)?.push(sourceNodeId);
|
|
2148
|
+
result.maskSources.set(node.id, sourceNodeId);
|
|
2149
|
+
} else console.warn(`Mask source "${sourceElementId}" not found for node "${node.id}"`);
|
|
2150
|
+
}
|
|
2151
|
+
});
|
|
2152
|
+
result.processingOrder = topologicalSort(maskDependencies, result.circularDependencies);
|
|
2153
|
+
return result;
|
|
1513
2154
|
}
|
|
1514
|
-
function
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
2155
|
+
function topologicalSort(dependencies, circularDependencies) {
|
|
2156
|
+
const result = [];
|
|
2157
|
+
const visited = /* @__PURE__ */ new Set();
|
|
2158
|
+
const tempVisited = /* @__PURE__ */ new Set();
|
|
2159
|
+
function visit(nodeId, path = []) {
|
|
2160
|
+
if (visited.has(nodeId)) return;
|
|
2161
|
+
if (tempVisited.has(nodeId)) {
|
|
2162
|
+
const cycle = [...path.slice(path.indexOf(nodeId)), nodeId];
|
|
2163
|
+
circularDependencies.push(cycle);
|
|
2164
|
+
return;
|
|
2165
|
+
}
|
|
2166
|
+
tempVisited.add(nodeId);
|
|
2167
|
+
path.push(nodeId);
|
|
2168
|
+
const deps = dependencies.get(nodeId) || [];
|
|
2169
|
+
for (const depId of deps) visit(depId, [...path]);
|
|
2170
|
+
tempVisited.delete(nodeId);
|
|
2171
|
+
visited.add(nodeId);
|
|
2172
|
+
result.push(nodeId);
|
|
2173
|
+
}
|
|
2174
|
+
for (const nodeId of dependencies.keys()) if (!visited.has(nodeId)) visit(nodeId);
|
|
2175
|
+
const allSourceNodeIds = new Set([...dependencies.values()].flat());
|
|
2176
|
+
for (const sourceId of allSourceNodeIds) if (!visited.has(sourceId) && !dependencies.has(sourceId)) result.push(sourceId);
|
|
2177
|
+
return result.reverse();
|
|
1532
2178
|
}
|
|
1533
|
-
var { vec2:
|
|
1534
|
-
const
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
2179
|
+
var { vec2: vec2$2, fract, sin: sin$1, dot: dot$1 } = TSL;
|
|
2180
|
+
const noise = (st) => fract(sin$1(dot$1(st, vec2$2(12.12345, 78.12345))).mul(40000.12345));
|
|
2181
|
+
const grain = (intensity = .03) => (st) => noise(st).mul(intensity).mul(.10012345);
|
|
2182
|
+
var { vec2: vec2$1 } = TSL;
|
|
2183
|
+
const distort = (uv = vec2$1(0), intensity = .02, frequency = 1, seed = 1) => {
|
|
2184
|
+
const { vec2: vec2$4, sin: sin$3, cos: cos$2, time } = TSL;
|
|
2185
|
+
const phaseX = seed * 1.618033988749895;
|
|
2186
|
+
const phaseY = seed * 2.718281828459045;
|
|
2187
|
+
const freqMod1 = (Math.sin(seed) + 2) * 5;
|
|
2188
|
+
const freqMod2 = (Math.cos(seed) + 2) * 5;
|
|
2189
|
+
const flow1 = vec2$4(sin$3(uv.x.mul(frequency).mul(freqMod1).add(time.mul(.1)).add(phaseX)), cos$2(uv.y.mul(frequency).mul(freqMod1).add(time.mul(.1)).add(phaseY)));
|
|
2190
|
+
const flow2 = vec2$4(sin$3(uv.y.mul(frequency).mul(freqMod2).add(time.mul(.05)).add(phaseY)), cos$2(uv.x.mul(frequency).mul(freqMod2).add(time.mul(.05)).add(phaseX)));
|
|
2191
|
+
const offset = flow1.add(flow2).mul(intensity);
|
|
2192
|
+
return uv.add(offset);
|
|
1545
2193
|
};
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
Beam: et,
|
|
1552
|
-
Blob: nt,
|
|
1553
|
-
Blur: tt,
|
|
1554
|
-
Bulge: rt,
|
|
1555
|
-
ChannelBlur: ot,
|
|
1556
|
-
Checkerboard: it,
|
|
1557
|
-
ChromaFlow: at,
|
|
1558
|
-
ChromaticAberration: st,
|
|
1559
|
-
Circle: lt,
|
|
1560
|
-
CRTScreen: ct,
|
|
1561
|
-
CursorTrail: ft,
|
|
1562
|
-
DiffuseBlur: ut,
|
|
1563
|
-
Dither: mt,
|
|
1564
|
-
DotGrid: dt,
|
|
1565
|
-
Duotone: ht,
|
|
1566
|
-
FilmGrain: pt,
|
|
1567
|
-
FloatingParticles: gt,
|
|
1568
|
-
GlassTiles: bt,
|
|
1569
|
-
Glow: vt,
|
|
1570
|
-
Godrays: Ct,
|
|
1571
|
-
Grayscale: Rt,
|
|
1572
|
-
Grid: kt,
|
|
1573
|
-
GridDistortion: Tt,
|
|
1574
|
-
Group: yt,
|
|
1575
|
-
Halftone: wt,
|
|
1576
|
-
HueShift: Ut,
|
|
1577
|
-
ImageTexture: St,
|
|
1578
|
-
Invert: Mt,
|
|
1579
|
-
LinearBlur: xt,
|
|
1580
|
-
LinearGradient: At,
|
|
1581
|
-
Liquify: Dt,
|
|
1582
|
-
Pixelate: zt,
|
|
1583
|
-
PolarCoordinates: Et,
|
|
1584
|
-
Posterize: Ft,
|
|
1585
|
-
ProgressiveBlur: $t,
|
|
1586
|
-
RadialGradient: Ot,
|
|
1587
|
-
RectangularCoordinates: Bt,
|
|
1588
|
-
Ripples: _t,
|
|
1589
|
-
Saturation: Lt,
|
|
1590
|
-
SimplexNoise: Gt,
|
|
1591
|
-
SineWave: Nt,
|
|
1592
|
-
SolidColor: Vt,
|
|
1593
|
-
Spherize: qt,
|
|
1594
|
-
Spiral: Pt,
|
|
1595
|
-
Strands: Xt,
|
|
1596
|
-
Stretch: Yt,
|
|
1597
|
-
Swirl: It,
|
|
1598
|
-
TiltShift: Ht,
|
|
1599
|
-
Tritone: Wt,
|
|
1600
|
-
Twirl: jt,
|
|
1601
|
-
Vibrance: Qt,
|
|
1602
|
-
WaveDistortion: Jt,
|
|
1603
|
-
ZoomBlur: Zt
|
|
1604
|
-
}).forEach(([s, t]) => {
|
|
1605
|
-
const u = {};
|
|
1606
|
-
t.props && Object.entries(t.props).forEach(([p, h]) => {
|
|
1607
|
-
h.ui && (u[p] = {
|
|
1608
|
-
ui: h.ui,
|
|
1609
|
-
default: h.default,
|
|
1610
|
-
description: h.description
|
|
1611
|
-
});
|
|
1612
|
-
}), e[t.name] = {
|
|
1613
|
-
name: t.name,
|
|
1614
|
-
fileName: s,
|
|
1615
|
-
category: t.category || "Uncategorized",
|
|
1616
|
-
definition: t,
|
|
1617
|
-
propsMetadata: u
|
|
1618
|
-
};
|
|
1619
|
-
}), e;
|
|
2194
|
+
const glow = (color, glowColor, threshold = .6, softness = .3, intensity = 1) => {
|
|
2195
|
+
const { max: max$1, smoothstep, vec4: vec4$1 } = TSL;
|
|
2196
|
+
const brightness = max$1(max$1(color.r, color.g), color.b);
|
|
2197
|
+
const glowAmount = smoothstep(threshold, threshold + softness, brightness).mul(intensity).mul(1);
|
|
2198
|
+
return vec4$1(color.rgb.add(glowColor.rgb.mul(glowAmount)), color.a);
|
|
1620
2199
|
};
|
|
1621
|
-
const
|
|
1622
|
-
|
|
1623
|
-
|
|
2200
|
+
const edgeMask = (options = {}) => {
|
|
2201
|
+
const { inset = .4, softness = .5, offsetX = 0, offsetY = 0 } = options;
|
|
2202
|
+
const { float: float$2, smoothstep, uv } = TSL;
|
|
2203
|
+
const rawUV = uv();
|
|
2204
|
+
const ovalX = rawUV.x.sub(.5).sub(float$2(offsetX)).mul(2);
|
|
2205
|
+
const ovalY = rawUV.y.sub(.5).add(float$2(offsetY)).mul(2);
|
|
2206
|
+
const ovalDistance = ovalX.mul(ovalX).add(ovalY.mul(ovalY)).sqrt();
|
|
2207
|
+
return float$2(1).sub(smoothstep(float$2(1).sub(float$2(inset)), float$2(1).sub(float$2(inset)).add(float$2(softness)), ovalDistance.mul(float$2(1).add(float$2(softness)))));
|
|
2208
|
+
};
|
|
2209
|
+
var createShaderRegistry = () => {
|
|
2210
|
+
const registry = {};
|
|
2211
|
+
const shaderDefinitions = {
|
|
2212
|
+
AngularBlur: componentDefinition,
|
|
2213
|
+
Ascii: componentDefinition$1,
|
|
2214
|
+
Beam: componentDefinition$2,
|
|
2215
|
+
Blob: componentDefinition$3,
|
|
2216
|
+
Blur: componentDefinition$4,
|
|
2217
|
+
Bulge: componentDefinition$5,
|
|
2218
|
+
ChannelBlur: componentDefinition$6,
|
|
2219
|
+
Checkerboard: componentDefinition$7,
|
|
2220
|
+
ChromaFlow: componentDefinition$8,
|
|
2221
|
+
ChromaticAberration: componentDefinition$9,
|
|
2222
|
+
Circle: componentDefinition$10,
|
|
2223
|
+
CRTScreen: componentDefinition$11,
|
|
2224
|
+
CursorTrail: componentDefinition$12,
|
|
2225
|
+
DiffuseBlur: componentDefinition$13,
|
|
2226
|
+
Dither: componentDefinition$14,
|
|
2227
|
+
DotGrid: componentDefinition$15,
|
|
2228
|
+
Duotone: componentDefinition$16,
|
|
2229
|
+
FilmGrain: componentDefinition$17,
|
|
2230
|
+
FloatingParticles: componentDefinition$18,
|
|
2231
|
+
GlassTiles: componentDefinition$19,
|
|
2232
|
+
Glow: componentDefinition$20,
|
|
2233
|
+
Godrays: componentDefinition$21,
|
|
2234
|
+
Grayscale: componentDefinition$22,
|
|
2235
|
+
Grid: componentDefinition$23,
|
|
2236
|
+
GridDistortion: componentDefinition$24,
|
|
2237
|
+
Group: componentDefinition$25,
|
|
2238
|
+
Halftone: componentDefinition$26,
|
|
2239
|
+
HueShift: componentDefinition$27,
|
|
2240
|
+
ImageTexture: componentDefinition$28,
|
|
2241
|
+
Invert: componentDefinition$29,
|
|
2242
|
+
LinearBlur: componentDefinition$30,
|
|
2243
|
+
LinearGradient: componentDefinition$31,
|
|
2244
|
+
Liquify: componentDefinition$32,
|
|
2245
|
+
Pixelate: componentDefinition$33,
|
|
2246
|
+
PolarCoordinates: componentDefinition$34,
|
|
2247
|
+
Posterize: componentDefinition$35,
|
|
2248
|
+
ProgressiveBlur: componentDefinition$36,
|
|
2249
|
+
RadialGradient: componentDefinition$37,
|
|
2250
|
+
RectangularCoordinates: componentDefinition$38,
|
|
2251
|
+
Ripples: componentDefinition$39,
|
|
2252
|
+
Saturation: componentDefinition$40,
|
|
2253
|
+
SimplexNoise: componentDefinition$41,
|
|
2254
|
+
SineWave: componentDefinition$42,
|
|
2255
|
+
SolidColor: componentDefinition$43,
|
|
2256
|
+
Spherize: componentDefinition$44,
|
|
2257
|
+
Spiral: componentDefinition$45,
|
|
2258
|
+
Strands: componentDefinition$46,
|
|
2259
|
+
Stretch: componentDefinition$47,
|
|
2260
|
+
Swirl: componentDefinition$48,
|
|
2261
|
+
TiltShift: componentDefinition$49,
|
|
2262
|
+
Tritone: componentDefinition$50,
|
|
2263
|
+
Twirl: componentDefinition$51,
|
|
2264
|
+
Vibrance: componentDefinition$52,
|
|
2265
|
+
WaveDistortion: componentDefinition$53,
|
|
2266
|
+
ZoomBlur: componentDefinition$54
|
|
2267
|
+
};
|
|
2268
|
+
Object.entries(shaderDefinitions).forEach(([fileName, def]) => {
|
|
2269
|
+
const propsMetadata = {};
|
|
2270
|
+
if (def.props) Object.entries(def.props).forEach(([propName, propConfig]) => {
|
|
2271
|
+
if (propConfig.ui) propsMetadata[propName] = {
|
|
2272
|
+
ui: propConfig.ui,
|
|
2273
|
+
default: propConfig.default,
|
|
2274
|
+
description: propConfig.description
|
|
2275
|
+
};
|
|
2276
|
+
});
|
|
2277
|
+
registry[def.name] = {
|
|
2278
|
+
name: def.name,
|
|
2279
|
+
fileName,
|
|
2280
|
+
category: def.category || "Uncategorized",
|
|
2281
|
+
definition: def,
|
|
2282
|
+
propsMetadata
|
|
2283
|
+
};
|
|
2284
|
+
});
|
|
2285
|
+
return registry;
|
|
2286
|
+
};
|
|
2287
|
+
const shaderRegistry = createShaderRegistry();
|
|
2288
|
+
function getAllShaders() {
|
|
2289
|
+
return Object.values(shaderRegistry);
|
|
1624
2290
|
}
|
|
1625
|
-
function
|
|
1626
|
-
|
|
2291
|
+
function getShaderByName(name) {
|
|
2292
|
+
return shaderRegistry[name];
|
|
1627
2293
|
}
|
|
1628
|
-
function
|
|
1629
|
-
|
|
2294
|
+
function getShadersByCategory(category) {
|
|
2295
|
+
return Object.values(shaderRegistry).filter((shader) => shader.category === category);
|
|
1630
2296
|
}
|
|
1631
|
-
function
|
|
1632
|
-
|
|
1633
|
-
|
|
2297
|
+
function getShaderCategories() {
|
|
2298
|
+
const categories = new Set(Object.values(shaderRegistry).map((shader) => shader.category));
|
|
2299
|
+
return Array.from(categories).sort();
|
|
1634
2300
|
}
|
|
1635
|
-
export {
|
|
1636
|
-
Jr as createAnimatedTime,
|
|
1637
|
-
ii as createUniformsMap,
|
|
1638
|
-
ci as distort,
|
|
1639
|
-
ui as edgeMask,
|
|
1640
|
-
mi as getAllShaders,
|
|
1641
|
-
di as getShaderByName,
|
|
1642
|
-
pi as getShaderCategories,
|
|
1643
|
-
hi as getShadersByCategory,
|
|
1644
|
-
fi as glow,
|
|
1645
|
-
li as grain,
|
|
1646
|
-
si as resolveMaskDependencies,
|
|
1647
|
-
Le as shaderRegistry,
|
|
1648
|
-
ai as shaderRenderer,
|
|
1649
|
-
Br as updateUniformValue
|
|
1650
|
-
};
|
|
2301
|
+
export { createAnimatedTime, createUniformsMap, distort, edgeMask, getAllShaders, getShaderByName, getShaderCategories, getShadersByCategory, glow, grain, resolveMaskDependencies, shaderRegistry, shaderRenderer, updateUniformValue };
|