@remotion/effects 4.0.541 → 4.0.543

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/THIRD_PARTY_LICENSES.md +10 -0
  2. package/dist/esm/lightning.mjs +603 -0
  3. package/dist/esm/magnify.mjs +403 -0
  4. package/dist/esm/preview/barrel-distortion.mjs +303 -0
  5. package/dist/esm/preview/bevel-alpha.mjs +525 -0
  6. package/dist/esm/preview/blur.mjs +435 -0
  7. package/dist/esm/preview/brightness.mjs +95 -0
  8. package/dist/esm/preview/burlap.mjs +481 -0
  9. package/dist/esm/preview/checkerboard.mjs +8 -0
  10. package/dist/esm/preview/chromatic-aberration.mjs +308 -0
  11. package/dist/esm/preview/color-correction.mjs +522 -0
  12. package/dist/esm/preview/color-key.mjs +440 -0
  13. package/dist/esm/preview/contour-lines.mjs +608 -0
  14. package/dist/esm/preview/contrast.mjs +95 -0
  15. package/dist/esm/preview/corner-pin.mjs +6 -0
  16. package/dist/esm/preview/curves.mjs +357 -0
  17. package/dist/esm/preview/cylinder.mjs +273 -0
  18. package/dist/esm/preview/dot-grid.mjs +333 -0
  19. package/dist/esm/preview/drop-shadow.mjs +607 -0
  20. package/dist/esm/preview/duotone.mjs +344 -0
  21. package/dist/esm/preview/emboss.mjs +479 -0
  22. package/dist/esm/preview/evolve.mjs +485 -0
  23. package/dist/esm/preview/exposure.mjs +264 -0
  24. package/dist/esm/preview/film-burn.mjs +298 -0
  25. package/dist/esm/preview/fisheye.mjs +422 -0
  26. package/dist/esm/preview/flannel.mjs +401 -0
  27. package/dist/esm/preview/fractal-noise.mjs +642 -0
  28. package/dist/esm/preview/glow.mjs +598 -0
  29. package/dist/esm/preview/grayscale.mjs +86 -0
  30. package/dist/esm/preview/gridlines.mjs +8 -0
  31. package/dist/esm/preview/halftone-linear-gradient.mjs +523 -0
  32. package/dist/esm/preview/halftone.mjs +552 -0
  33. package/dist/esm/preview/hue.mjs +83 -0
  34. package/dist/esm/preview/index-00v3hr66.mjs +299 -0
  35. package/dist/esm/preview/index-0w4eqht8.mjs +351 -0
  36. package/dist/esm/preview/index-18y0zcy2.mjs +440 -0
  37. package/dist/esm/preview/index-1m1b1ad7.mjs +520 -0
  38. package/dist/esm/preview/index-34fxm3ax.mjs +518 -0
  39. package/dist/esm/preview/index-4fvp93ps.mjs +32 -0
  40. package/dist/esm/preview/index-4scpn12x.mjs +224 -0
  41. package/dist/esm/preview/index-4z6pt3ka.mjs +104 -0
  42. package/dist/esm/preview/index-618ky75w.mjs +51 -0
  43. package/dist/esm/preview/index-6agxdrvr.mjs +411 -0
  44. package/dist/esm/preview/index-6jkps947.mjs +120 -0
  45. package/dist/esm/preview/index-8agtsbw4.mjs +617 -0
  46. package/dist/esm/preview/index-8jx11jyn.mjs +29 -0
  47. package/dist/esm/preview/index-8p04sssx.mjs +123 -0
  48. package/dist/esm/preview/index-afdtmrh2.mjs +596 -0
  49. package/dist/esm/preview/index-b86qstcs.mjs +18 -0
  50. package/dist/esm/preview/index-cb77qg3g.mjs +587 -0
  51. package/dist/esm/preview/index-cdp7tr8x.mjs +122 -0
  52. package/dist/esm/preview/index-evy8hyah.mjs +55 -0
  53. package/dist/esm/preview/index-gnsce796.mjs +6 -0
  54. package/dist/esm/preview/index-kkvzt8b7.mjs +199 -0
  55. package/dist/esm/preview/index-r0v18b2n.mjs +425 -0
  56. package/dist/esm/preview/index-rswpzmm5.mjs +926 -0
  57. package/dist/esm/preview/index-s9mrx750.mjs +97 -0
  58. package/dist/esm/preview/index-tvfexb7s.mjs +164 -0
  59. package/dist/esm/preview/index-vp56k1gj.mjs +215 -0
  60. package/dist/esm/preview/index-wxhvgv2s.mjs +79 -0
  61. package/dist/esm/preview/index-wy95a41r.mjs +407 -0
  62. package/dist/esm/preview/index-ysnwfc4t.mjs +306 -0
  63. package/dist/esm/preview/index.mjs +51 -0
  64. package/dist/esm/preview/invert.mjs +84 -0
  65. package/dist/esm/preview/iris-wipe.mjs +315 -0
  66. package/dist/esm/preview/lens-blur.mjs +563 -0
  67. package/dist/esm/preview/levels.mjs +400 -0
  68. package/dist/esm/preview/light-leak.mjs +8 -0
  69. package/dist/esm/preview/light-trail.mjs +516 -0
  70. package/dist/esm/preview/lightning.mjs +603 -0
  71. package/dist/esm/preview/linear-gradient-tint.mjs +6 -0
  72. package/dist/esm/preview/linear-gradient.mjs +6 -0
  73. package/dist/esm/preview/linear-progressive-blur.mjs +516 -0
  74. package/dist/esm/preview/linear-progressive-pixelate.mjs +176 -0
  75. package/dist/esm/preview/lines.mjs +536 -0
  76. package/dist/esm/preview/liquid-contours.mjs +512 -0
  77. package/dist/esm/preview/long-shadows.mjs +437 -0
  78. package/dist/esm/preview/lut.mjs +601 -0
  79. package/dist/esm/preview/magnify.mjs +403 -0
  80. package/dist/esm/preview/mirror.mjs +341 -0
  81. package/dist/esm/preview/noise-displacement.mjs +584 -0
  82. package/dist/esm/preview/noise.mjs +318 -0
  83. package/dist/esm/preview/outline.mjs +725 -0
  84. package/dist/esm/preview/page-turn.mjs +302 -0
  85. package/dist/esm/preview/paper.mjs +1249 -0
  86. package/dist/esm/preview/pattern.mjs +6 -0
  87. package/dist/esm/preview/pixel-dissolve.mjs +360 -0
  88. package/dist/esm/preview/pixelate.mjs +249 -0
  89. package/dist/esm/preview/radial-progressive-blur.mjs +582 -0
  90. package/dist/esm/preview/radial-progressive-pixelate.mjs +220 -0
  91. package/dist/esm/preview/radial-wipe.mjs +224 -0
  92. package/dist/esm/preview/rain-fall.mjs +114 -0
  93. package/dist/esm/preview/region-blur.mjs +500 -0
  94. package/dist/esm/preview/rings.mjs +8 -0
  95. package/dist/esm/preview/roughen-edges.mjs +590 -0
  96. package/dist/esm/preview/saturation.mjs +86 -0
  97. package/dist/esm/preview/scale.mjs +109 -0
  98. package/dist/esm/preview/scanlines.mjs +362 -0
  99. package/dist/esm/preview/shadows-highlights.mjs +284 -0
  100. package/dist/esm/preview/shatter.mjs +868 -0
  101. package/dist/esm/preview/shine.mjs +368 -0
  102. package/dist/esm/preview/shrinkwrap.mjs +769 -0
  103. package/dist/esm/preview/skew.mjs +300 -0
  104. package/dist/esm/preview/snow-fall.mjs +170 -0
  105. package/dist/esm/preview/speckle.mjs +356 -0
  106. package/dist/esm/preview/sphere.mjs +252 -0
  107. package/dist/esm/preview/starburst.mjs +8 -0
  108. package/dist/esm/preview/tear.mjs +375 -0
  109. package/dist/esm/preview/thermal-vision.mjs +387 -0
  110. package/dist/esm/preview/tile.mjs +7 -0
  111. package/dist/esm/preview/tint.mjs +125 -0
  112. package/dist/esm/preview/translate.mjs +151 -0
  113. package/dist/esm/preview/turbulent-displace.mjs +613 -0
  114. package/dist/esm/preview/tv-signal-off.mjs +308 -0
  115. package/dist/esm/preview/venetian-blinds.mjs +341 -0
  116. package/dist/esm/preview/vibrance.mjs +254 -0
  117. package/dist/esm/preview/vignette.mjs +458 -0
  118. package/dist/esm/preview/wave.mjs +384 -0
  119. package/dist/esm/preview/waves.mjs +599 -0
  120. package/dist/esm/preview/white-balance.mjs +280 -0
  121. package/dist/esm/preview/white-noise.mjs +244 -0
  122. package/dist/esm/preview/zigzag.mjs +8 -0
  123. package/dist/esm/preview/zoom-blur.mjs +389 -0
  124. package/dist/lightning/geometry.d.ts +10 -0
  125. package/dist/lightning/index.d.ts +4 -0
  126. package/dist/lightning/mask.d.ts +2 -0
  127. package/dist/lightning/params.d.ts +259 -0
  128. package/dist/lightning/shaders.d.ts +2 -0
  129. package/dist/lightning.d.ts +2 -0
  130. package/dist/magnify/shader.d.ts +1 -0
  131. package/dist/magnify/webgpu-shader.d.ts +1 -0
  132. package/dist/magnify.d.ts +28 -0
  133. package/package.json +30 -6
@@ -0,0 +1,603 @@
1
+ import {
2
+ setupSinglePass,
3
+ prepareSinglePassSource,
4
+ drawSinglePass,
5
+ cleanupSinglePass
6
+ } from "./index-8p04sssx.mjs";
7
+ import {
8
+ validateUnitInterval,
9
+ parseColorRgba
10
+ } from "./index-wxhvgv2s.mjs";
11
+ import {
12
+ WEBGPU_SINGLE_PASS_VERTEX,
13
+ setupWebGpuSinglePass,
14
+ cleanupWebGpuSinglePass,
15
+ applyWebGpuSinglePass
16
+ } from "./index-tvfexb7s.mjs";
17
+ import {
18
+ assertEffectParamsObject,
19
+ assertRequiredFiniteNumber,
20
+ assertOptionalColor,
21
+ assertOptionalBoolean
22
+ } from "./index-4fvp93ps.mjs";
23
+
24
+ // src/lightning/index.ts
25
+ import { Internals } from "remotion";
26
+
27
+ // src/lightning/geometry.ts
28
+ var lightningSegments = (p, width, height, alpha) => {
29
+ const seed = BigInt(Math.floor(p.conductivityState)) ^ BigInt(p.seed) << 32n;
30
+ let state = BigInt.asUintN(64, seed * 0x9e3779b97f4a7c15n) ^ 0xd1b54a32d192ed03n | 1n;
31
+ const random = () => {
32
+ state ^= state >> 12n;
33
+ state ^= BigInt.asUintN(64, state << 25n);
34
+ state ^= state >> 27n;
35
+ return Number(BigInt.asUintN(64, state * 0x2545f4914f6cdd1dn) >> 11n) / 2 ** 53;
36
+ };
37
+ const alphaAt = (x, y) => {
38
+ if (!alpha)
39
+ return 0;
40
+ const px = Math.max(0, Math.min(width - 1, x - 0.5));
41
+ const py = Math.max(0, Math.min(height - 1, y - 0.5));
42
+ const x0 = Math.floor(px);
43
+ const y0 = Math.floor(py);
44
+ const x1 = Math.min(width - 1, x0 + 1);
45
+ const y1 = Math.min(height - 1, y0 + 1);
46
+ const tx = px - x0;
47
+ const ty = py - y0;
48
+ const { data } = alpha;
49
+ return ((data[(y0 * width + x0) * 4 + 3] * (1 - tx) + data[(y0 * width + x1) * 4 + 3] * tx) * (1 - ty) + (data[(y1 * width + x0) * 4 + 3] * (1 - tx) + data[(y1 * width + x1) * 4 + 3] * tx) * ty) / 255;
50
+ };
51
+ const origin = [p.origin[0] * width, p.origin[1] * height];
52
+ const direction = [p.direction[0] * width, p.direction[1] * height];
53
+ const dx = direction[0] - origin[0];
54
+ const dy = direction[1] - origin[1];
55
+ const distance = Math.hypot(dx, dy);
56
+ const depth = p.complexity + Number(p.fractalType === "spline");
57
+ const shape = { linear: 1, "semi-linear": 0.7, spline: 0.45 }[p.fractalType];
58
+ const turbulence = p.turbulence * (p.lightningType === "bouncy" ? 1.6 : 1);
59
+ const forking = p.lightningType === "breaking" ? Math.min(1, p.forking * (0.5 + distance / Math.max(width, height, 1))) : p.forking;
60
+ const segments = [];
61
+ const grow = (segment, remaining) => {
62
+ const { start, end, intensity, main } = segment;
63
+ if (segments.length > 20000)
64
+ return;
65
+ const vx = end[0] - start[0];
66
+ const vy = end[1] - start[1];
67
+ const length = Math.hypot(vx, vy);
68
+ if (remaining === 0 || length < 1) {
69
+ segments.push(segment);
70
+ return;
71
+ }
72
+ const nx = -vy / length;
73
+ const ny = vx / length;
74
+ let offset = (random() * 2 - 1) * length * 0.22 * turbulence * shape;
75
+ const mx = (start[0] + end[0]) / 2;
76
+ const my = (start[1] + end[1]) / 2;
77
+ if (alpha && (main || !p.mainCoreCollisionOnly)) {
78
+ const delta = alphaAt(mx + nx * offset, my + ny * offset) - alphaAt(mx - nx * offset, my - ny * offset);
79
+ if (delta * p.alphaObstacle > 0 && random() < Math.abs(p.alphaObstacle) / 10)
80
+ offset = -offset;
81
+ }
82
+ const mid = [mx + nx * offset, my + ny * offset];
83
+ if (!main && p.alphaObstacle > 0 && alphaAt(...mid) > 0.5 && random() < p.alphaObstacle / 10)
84
+ return;
85
+ grow({ start, end: mid, intensity, main }, remaining - 1);
86
+ grow({ start: mid, end, intensity, main }, remaining - 1);
87
+ if (random() < forking && intensity > p.terminationThreshold && length >= p.minForkDistance) {
88
+ const angle = (random() * 2 - 1) * 0.7;
89
+ const fx = mid[0] - start[0];
90
+ const fy = mid[1] - start[1];
91
+ const forkEnd = [
92
+ mid[0] + 1.2 * (fx * Math.cos(angle) - fy * Math.sin(angle)),
93
+ mid[1] + 1.2 * (fx * Math.sin(angle) + fy * Math.cos(angle))
94
+ ];
95
+ const variation = p.forkVariation > 0 ? 1 - p.forkVariation * random() : 1;
96
+ grow({
97
+ start: mid,
98
+ end: forkEnd,
99
+ intensity: Math.min(1, intensity * (1 - p.decay) * p.forkStrength * 2 * variation),
100
+ main: false
101
+ }, remaining - 1);
102
+ }
103
+ };
104
+ const growMain = (start, end, subdivisions) => grow({ start, end, intensity: 1, main: true }, subdivisions);
105
+ switch (p.lightningType) {
106
+ case "direction":
107
+ growMain(origin, [origin[0] + dx * 3, origin[1] + dy * 3], depth);
108
+ break;
109
+ case "vertical":
110
+ growMain(origin, [origin[0], height], depth);
111
+ break;
112
+ case "two-way-strike": {
113
+ const mid = [origin[0] + dx / 2, origin[1] + dy / 2];
114
+ const halfDepth = Math.max(1, depth - 1);
115
+ growMain(origin, mid, halfDepth);
116
+ growMain(direction, mid, halfDepth);
117
+ break;
118
+ }
119
+ case "omni":
120
+ case "anywhere": {
121
+ const radius = Math.max(distance, Math.min(width, height) * 0.25);
122
+ for (let i = 0;i < 4; i++) {
123
+ const angle = random() * 2 * Math.PI;
124
+ const length = p.lightningType === "anywhere" ? radius * (0.3 + 0.7 * random()) : radius;
125
+ growMain(origin, [
126
+ origin[0] + Math.cos(angle) * length,
127
+ origin[1] + Math.sin(angle) * length
128
+ ], depth);
129
+ }
130
+ break;
131
+ }
132
+ default:
133
+ growMain(origin, direction, depth);
134
+ }
135
+ if (p.decayMainCore || p.coreDrain > 0) {
136
+ const distanceFromOrigin = (point) => Math.hypot(point[0] - origin[0], point[1] - origin[1]);
137
+ const farthest = segments.reduce((max, segment) => Math.max(max, distanceFromOrigin(segment.end)), 0.000000001);
138
+ for (const segment of segments) {
139
+ const fraction = distanceFromOrigin(segment.start) / farthest;
140
+ if (p.decayMainCore)
141
+ segment.intensity *= Math.max(0, 1 - p.decay * fraction);
142
+ if (segment.main)
143
+ segment.intensity *= Math.max(0, 1 - p.coreDrain * fraction);
144
+ }
145
+ }
146
+ return segments;
147
+ };
148
+
149
+ // src/lightning/mask.ts
150
+ var blurRows = (input, output, width, radius) => {
151
+ const height = input.length / width;
152
+ const weight = 1 / (2 * radius + 1);
153
+ for (let y = 0;y < height; y++) {
154
+ const row = y * width;
155
+ let sum = input[row] * (radius + 1);
156
+ for (let x = 1;x <= radius; x++)
157
+ sum += input[row + Math.min(width - 1, x)];
158
+ for (let x = 0;x < width; x++) {
159
+ output[row + x] = sum * weight;
160
+ sum += input[row + Math.min(width - 1, x + radius + 1)] - input[row + Math.max(0, x - radius)];
161
+ }
162
+ }
163
+ };
164
+ var transpose = (input, output, width, height) => {
165
+ for (let x = 0;x < width; x++) {
166
+ for (let y = 0;y < height; y++)
167
+ output[x * height + y] = input[y * width + x];
168
+ }
169
+ };
170
+ var makeLightningMask = (p, width, height, alpha) => {
171
+ const segments = lightningSegments(p, width, height, alpha);
172
+ const data = new Uint8Array(width * height * 4);
173
+ const coreRadius = Math.max(0.3, p.coreRadius);
174
+ const sigma = p.glowRadius / 3;
175
+ const idealWidth = Math.sqrt(4 * sigma * sigma + 1);
176
+ const lowerWidth = 2 * Math.floor((idealWidth - 1) / 2) + 1;
177
+ const lowerPasses = Math.round((12 * sigma * sigma - 3 * lowerWidth ** 2 - 12 * lowerWidth - 9) / (-4 * lowerWidth - 4));
178
+ const radii = p.glowRadius > 0.5 ? [0, 1, 2].map((pass) => (lowerWidth - 1) / 2 + Number(pass >= lowerPasses)) : [];
179
+ const margin = coreRadius + 1 + radii.reduce((total, r) => total + r, 0);
180
+ let left = width;
181
+ let top = height;
182
+ let right = 0;
183
+ let bottom = 0;
184
+ for (const { start, end } of segments) {
185
+ left = Math.min(left, Math.floor(Math.min(start[0], end[0]) - margin));
186
+ right = Math.max(right, Math.ceil(Math.max(start[0], end[0]) + margin));
187
+ top = Math.min(top, Math.floor(Math.min(start[1], end[1]) - margin));
188
+ bottom = Math.max(bottom, Math.ceil(Math.max(start[1], end[1]) + margin));
189
+ }
190
+ left = Math.max(0, left);
191
+ top = Math.max(0, top);
192
+ right = Math.min(width, right);
193
+ bottom = Math.min(height, bottom);
194
+ const w = right - left;
195
+ const h = bottom - top;
196
+ if (w <= 0 || h <= 0)
197
+ return data;
198
+ let core = new Float32Array(w * h);
199
+ for (const { start, end, intensity } of segments) {
200
+ const dx = end[0] - start[0];
201
+ const dy = end[1] - start[1];
202
+ const lengthSq = Math.max(0.000000000001, dx * dx + dy * dy);
203
+ const x0 = Math.max(left, Math.floor(Math.min(start[0], end[0]) - coreRadius - 1));
204
+ const y0 = Math.max(top, Math.floor(Math.min(start[1], end[1]) - coreRadius - 1));
205
+ const x1 = Math.min(right, Math.ceil(Math.max(start[0], end[0]) + coreRadius + 1));
206
+ const y1 = Math.min(bottom, Math.ceil(Math.max(start[1], end[1]) + coreRadius + 1));
207
+ for (let y = y0;y < y1; y++) {
208
+ const py = y + 0.5 - start[1];
209
+ for (let x = x0;x < x1; x++) {
210
+ const px = x + 0.5 - start[0];
211
+ const t = Math.max(0, Math.min(1, (px * dx + py * dy) / lengthSq));
212
+ const distance = Math.sqrt((px - dx * t) ** 2 + (py - dy * t) ** 2);
213
+ const coverage = Math.min(1, coreRadius + 0.5 - distance) * intensity;
214
+ const index = (y - top) * w + x - left;
215
+ if (coverage > core[index])
216
+ core[index] = coverage;
217
+ }
218
+ }
219
+ }
220
+ for (let y = 0;y < h; y++) {
221
+ for (let x = 0;x < w; x++)
222
+ data[((y + top) * width + x + left) * 4] = Math.round(core[y * w + x] * 255);
223
+ }
224
+ if (radii.length === 0)
225
+ return data;
226
+ let scratch = new Float32Array(w * h);
227
+ for (const radius of radii) {
228
+ if (radius === 0)
229
+ continue;
230
+ blurRows(core, scratch, w, radius);
231
+ [core, scratch] = [scratch, core];
232
+ }
233
+ transpose(core, scratch, w, h);
234
+ [core, scratch] = [scratch, core];
235
+ for (const radius of radii) {
236
+ if (radius === 0)
237
+ continue;
238
+ blurRows(core, scratch, h, radius);
239
+ [core, scratch] = [scratch, core];
240
+ }
241
+ for (let x = 0;x < w; x++) {
242
+ for (let y = 0;y < h; y++)
243
+ data[((y + top) * width + x + left) * 4 + 1] = Math.round(Math.min(1, core[x * h + y] * 3) * 255);
244
+ }
245
+ return data;
246
+ };
247
+
248
+ // src/lightning/params.ts
249
+ var numberField = (description, defaultValue, [min, max], step) => ({
250
+ type: "number",
251
+ description,
252
+ default: defaultValue,
253
+ min,
254
+ max,
255
+ step,
256
+ hiddenFromList: false
257
+ });
258
+ var uvCoordinateField = (description, defaultValue) => ({
259
+ type: "uv-coordinate",
260
+ description,
261
+ default: defaultValue,
262
+ min: 0,
263
+ max: 1,
264
+ step: 0.01
265
+ });
266
+ var lightningSchema = {
267
+ lightningType: {
268
+ type: "enum",
269
+ description: "Lightning type",
270
+ variants: {
271
+ direction: {},
272
+ strike: {},
273
+ breaking: {},
274
+ bouncy: {},
275
+ omni: {},
276
+ anywhere: {},
277
+ vertical: {},
278
+ "two-way-strike": {}
279
+ },
280
+ default: "strike"
281
+ },
282
+ origin: {
283
+ ...uvCoordinateField("Origin", [0.5, 0]),
284
+ visual: { type: "line", to: "direction" }
285
+ },
286
+ direction: uvCoordinateField("Direction", [0.5, 1]),
287
+ conductivityState: numberField("Conductivity state", 10, [0, 1e5], 1),
288
+ coreRadius: numberField("Core radius", 3, [0, 100], 0.1),
289
+ coreOpacity: numberField("Core opacity", 0.75, [0, 1], 0.01),
290
+ coreColor: { type: "color", description: "Core color", default: "#ffffff" },
291
+ glowRadius: numberField("Glow radius", 50, [0, 1000], 0.1),
292
+ glowOpacity: numberField("Glow opacity", 0.5, [0, 1], 0.01),
293
+ glowColor: { type: "color", description: "Glow color", default: "#4059ff" },
294
+ turbulence: numberField("Turbulence", 1, [0, 10], 0.01),
295
+ forking: numberField("Forking", 0.25, [0, 1], 0.01),
296
+ decay: numberField("Decay", 0.3, [0, 1], 0.01),
297
+ decayMainCore: {
298
+ type: "boolean",
299
+ description: "Decay main core",
300
+ default: false
301
+ },
302
+ alphaObstacle: numberField("Alpha obstacle", 0, [-10, 10], 0.1),
303
+ compositeOnOriginal: {
304
+ type: "boolean",
305
+ description: "Composite on original",
306
+ default: true
307
+ },
308
+ complexity: { ...numberField("Complexity", 6, [1, 12], 1), integer: true },
309
+ minForkDistance: numberField("Min fork distance", 0, [0, 1000], 1),
310
+ terminationThreshold: numberField("Termination threshold", 0.05, [0, 1], 0.01),
311
+ mainCoreCollisionOnly: {
312
+ type: "boolean",
313
+ description: "Main core collision only",
314
+ default: false
315
+ },
316
+ fractalType: {
317
+ type: "enum",
318
+ description: "Fractal type",
319
+ variants: { linear: {}, "semi-linear": {}, spline: {} },
320
+ default: "linear"
321
+ },
322
+ coreDrain: numberField("Core drain", 0, [0, 1], 0.01),
323
+ forkStrength: numberField("Fork strength", 0.5, [0, 1], 0.01),
324
+ forkVariation: numberField("Fork variation", 0, [0, 1], 0.01),
325
+ seed: { ...numberField("Seed", 0, [0, 4294967295], 1), integer: true }
326
+ };
327
+ var resolve = (params) => ({
328
+ lightningType: params.lightningType ?? lightningSchema.lightningType.default,
329
+ origin: params.origin ?? lightningSchema.origin.default,
330
+ direction: params.direction ?? lightningSchema.direction.default,
331
+ conductivityState: params.conductivityState ?? lightningSchema.conductivityState.default,
332
+ coreRadius: params.coreRadius ?? lightningSchema.coreRadius.default,
333
+ coreOpacity: params.coreOpacity ?? lightningSchema.coreOpacity.default,
334
+ coreColor: params.coreColor ?? lightningSchema.coreColor.default,
335
+ glowRadius: params.glowRadius ?? lightningSchema.glowRadius.default,
336
+ glowOpacity: params.glowOpacity ?? lightningSchema.glowOpacity.default,
337
+ glowColor: params.glowColor ?? lightningSchema.glowColor.default,
338
+ turbulence: params.turbulence ?? lightningSchema.turbulence.default,
339
+ forking: params.forking ?? lightningSchema.forking.default,
340
+ decay: params.decay ?? lightningSchema.decay.default,
341
+ decayMainCore: params.decayMainCore ?? lightningSchema.decayMainCore.default,
342
+ alphaObstacle: params.alphaObstacle ?? lightningSchema.alphaObstacle.default,
343
+ compositeOnOriginal: params.compositeOnOriginal ?? lightningSchema.compositeOnOriginal.default,
344
+ complexity: params.complexity ?? lightningSchema.complexity.default,
345
+ minForkDistance: params.minForkDistance ?? lightningSchema.minForkDistance.default,
346
+ terminationThreshold: params.terminationThreshold ?? lightningSchema.terminationThreshold.default,
347
+ mainCoreCollisionOnly: params.mainCoreCollisionOnly ?? lightningSchema.mainCoreCollisionOnly.default,
348
+ fractalType: params.fractalType ?? lightningSchema.fractalType.default,
349
+ coreDrain: params.coreDrain ?? lightningSchema.coreDrain.default,
350
+ forkStrength: params.forkStrength ?? lightningSchema.forkStrength.default,
351
+ forkVariation: params.forkVariation ?? lightningSchema.forkVariation.default,
352
+ seed: params.seed ?? lightningSchema.seed.default
353
+ });
354
+ var validateLightningParams = (params) => {
355
+ assertEffectParamsObject(params, "Lightning");
356
+ for (const [name, field] of Object.entries(lightningSchema)) {
357
+ const value = params[name];
358
+ if (value === undefined)
359
+ continue;
360
+ switch (field.type) {
361
+ case "number":
362
+ assertRequiredFiniteNumber(value, name);
363
+ if (typeof value !== "number" || value < field.min || value > field.max) {
364
+ throw new TypeError(`"${name}" must be between ${field.min} and ${field.max}`);
365
+ }
366
+ if ("integer" in field && !Number.isInteger(value)) {
367
+ throw new TypeError(`"${name}" must be an integer`);
368
+ }
369
+ break;
370
+ case "uv-coordinate":
371
+ if (!Array.isArray(value) || value.length !== 2)
372
+ throw new TypeError(`"${name}" must be a [number, number] tuple`);
373
+ for (const coordinate of value) {
374
+ assertRequiredFiniteNumber(coordinate, name);
375
+ validateUnitInterval(coordinate, name);
376
+ }
377
+ break;
378
+ case "boolean":
379
+ assertOptionalBoolean(value, name);
380
+ break;
381
+ case "color":
382
+ assertOptionalColor(value, name);
383
+ break;
384
+ case "enum":
385
+ if (typeof value !== "string" || !Object.hasOwn(field.variants, value))
386
+ throw new TypeError(`Invalid "${name}": ${JSON.stringify(value)}`);
387
+ break;
388
+ default:
389
+ throw new TypeError(`Unknown lightning field "${name}"`);
390
+ }
391
+ }
392
+ };
393
+
394
+ // src/lightning/shaders.ts
395
+ var LIGHTNING_FRAGMENT_SHADER = `#version 300 es
396
+ precision highp float;
397
+ uniform sampler2D uSource;
398
+ uniform sampler2D uMask;
399
+ uniform vec4 uCore;
400
+ uniform vec4 uGlow;
401
+ uniform float uComposite;
402
+ in vec2 vUv;
403
+ out vec4 fragColor;
404
+
405
+ void main() {
406
+ vec4 source = texture(uSource, vUv) * uComposite;
407
+ vec2 mask = texture(uMask, vec2(vUv.x, 1.0 - vUv.y)).rg;
408
+ float core = mask.r * uCore.a;
409
+ float glow = mask.g * uGlow.a;
410
+ float alpha = source.a + max(core, glow) * (1.0 - source.a);
411
+ vec3 color = source.rgb + uCore.rgb * core + uGlow.rgb * glow;
412
+ fragColor = vec4(min(color, vec3(alpha)), alpha);
413
+ }
414
+ `;
415
+ var LIGHTNING_WEBGPU_SHADER = `
416
+ ${WEBGPU_SINGLE_PASS_VERTEX}
417
+ struct Params { core: vec4f, glow: vec4f, composite: f32 }
418
+ @group(0) @binding(0) var source: texture_2d<f32>;
419
+ @group(0) @binding(1) var sourceSampler: sampler;
420
+ @group(0) @binding(2) var<uniform> params: Params;
421
+ @group(0) @binding(3) var mask: texture_2d<f32>;
422
+
423
+ @fragment fn fragment(input: VertexOutput) -> @location(0) vec4f {
424
+ let src = textureSampleLevel(source, sourceSampler, input.uv, 0) * params.composite;
425
+ let coverage = textureLoad(mask, vec2i(input.position.xy), 0).rg;
426
+ let core = coverage.r * params.core.a;
427
+ let glow = coverage.g * params.glow.a;
428
+ let alpha = src.a + max(core, glow) * (1.0 - src.a);
429
+ let color = src.rgb + params.core.rgb * core + params.glow.rgb * glow;
430
+ return vec4f(min(color, vec3f(alpha)), alpha);
431
+ }
432
+ `;
433
+
434
+ // src/lightning/index.ts
435
+ var setupLightning = () => {
436
+ const canvas = document.createElement("canvas");
437
+ canvas.width = 1;
438
+ canvas.height = 1;
439
+ const ctx = canvas.getContext("2d", { willReadFrequently: true });
440
+ if (!ctx)
441
+ throw new Error("Could not acquire a 2D context for lightning");
442
+ return { ctx, mask: null };
443
+ };
444
+ var prepareLightning = ({
445
+ state,
446
+ params,
447
+ source,
448
+ width,
449
+ height,
450
+ sourceIsFlipped
451
+ }) => {
452
+ const p = resolve(params);
453
+ const {
454
+ coreColor,
455
+ coreOpacity,
456
+ glowColor,
457
+ glowOpacity,
458
+ compositeOnOriginal,
459
+ ...shape
460
+ } = p;
461
+ const key = JSON.stringify([width, height, shape]);
462
+ const { ctx } = state;
463
+ if (state.mask?.key !== key || p.alphaObstacle !== 0) {
464
+ let alpha = null;
465
+ if (p.alphaObstacle !== 0) {
466
+ if (ctx.canvas.width !== width)
467
+ ctx.canvas.width = width;
468
+ if (ctx.canvas.height !== height)
469
+ ctx.canvas.height = height;
470
+ ctx.clearRect(0, 0, width, height);
471
+ ctx.save();
472
+ try {
473
+ if (sourceIsFlipped) {
474
+ ctx.translate(0, height);
475
+ ctx.scale(1, -1);
476
+ }
477
+ ctx.drawImage(source, 0, 0, width, height);
478
+ } finally {
479
+ ctx.restore();
480
+ }
481
+ alpha = ctx.getImageData(0, 0, width, height);
482
+ }
483
+ state.mask = { key, data: makeLightningMask(p, width, height, alpha) };
484
+ }
485
+ const core = parseColorRgba(ctx, coreColor);
486
+ const glow = parseColorRgba(ctx, glowColor);
487
+ return {
488
+ data: state.mask.data,
489
+ uniforms: new Float32Array([
490
+ core[0] / 255,
491
+ core[1] / 255,
492
+ core[2] / 255,
493
+ core[3] / 255 * coreOpacity,
494
+ glow[0] / 255,
495
+ glow[1] / 255,
496
+ glow[2] / 255,
497
+ glow[3] / 255 * glowOpacity,
498
+ Number(compositeOnOriginal),
499
+ 0,
500
+ 0,
501
+ 0
502
+ ])
503
+ };
504
+ };
505
+ var lightning = Internals.createEffect({
506
+ type: "remotion/lightning",
507
+ label: "lightning()",
508
+ documentationLink: "https://www.remotion.dev/docs/effects/lightning",
509
+ calculateKey: (params) => `lightning-${JSON.stringify(resolve(params))}`,
510
+ schema: lightningSchema,
511
+ validateParams: validateLightningParams,
512
+ implementations: {
513
+ webgl2: Internals.createEffectImplementation({
514
+ setup: (target) => {
515
+ const shared = setupLightning();
516
+ const pass = setupSinglePass(target, LIGHTNING_FRAGMENT_SHADER, "lightning", ["uMask", "uCore", "uGlow", "uComposite"]);
517
+ const { gl } = pass;
518
+ const maskTexture = gl.createTexture();
519
+ if (!maskTexture) {
520
+ cleanupSinglePass(pass);
521
+ throw new Error("Could not allocate lightning mask texture");
522
+ }
523
+ gl.bindTexture(gl.TEXTURE_2D, maskTexture);
524
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
525
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
526
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
527
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
528
+ return { ...shared, ...pass, maskTexture };
529
+ },
530
+ apply: ({ source, width, height, params, state, flipSourceY }) => {
531
+ const previous = state.mask?.data;
532
+ const { data, uniforms } = prepareLightning({
533
+ state,
534
+ params,
535
+ source,
536
+ width,
537
+ height,
538
+ sourceIsFlipped: !flipSourceY
539
+ });
540
+ const { gl } = state;
541
+ prepareSinglePassSource({
542
+ state,
543
+ source,
544
+ width,
545
+ height,
546
+ flipSourceY
547
+ });
548
+ gl.activeTexture(gl.TEXTURE1);
549
+ gl.bindTexture(gl.TEXTURE_2D, state.maskTexture);
550
+ if (previous !== data) {
551
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
552
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
553
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);
554
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
555
+ }
556
+ gl.uniform1i(state.uniforms.uMask, 1);
557
+ gl.uniform4fv(state.uniforms.uCore, uniforms, 0, 4);
558
+ gl.uniform4fv(state.uniforms.uGlow, uniforms, 4, 4);
559
+ gl.uniform1f(state.uniforms.uComposite, uniforms[8]);
560
+ drawSinglePass(state);
561
+ gl.activeTexture(gl.TEXTURE0);
562
+ },
563
+ cleanup: (state) => {
564
+ state.gl.deleteTexture(state.maskTexture);
565
+ cleanupSinglePass(state);
566
+ }
567
+ }),
568
+ webgpu: Internals.createEffectImplementation({
569
+ setup: (target) => ({
570
+ ...setupLightning(),
571
+ ...setupWebGpuSinglePass(target, "lightning")
572
+ }),
573
+ apply: ({ source, width, height, params, state, gpuDevice }) => {
574
+ if (!gpuDevice)
575
+ throw new Error("A WebGPU device is required for lightning");
576
+ const { data, uniforms } = prepareLightning({
577
+ state,
578
+ params,
579
+ source,
580
+ width,
581
+ height,
582
+ sourceIsFlipped: false
583
+ });
584
+ applyWebGpuSinglePass({
585
+ state,
586
+ source,
587
+ width,
588
+ height,
589
+ device: gpuDevice,
590
+ shader: LIGHTNING_WEBGPU_SHADER,
591
+ uniformData: uniforms
592
+ }, {
593
+ sourceFilter: null,
594
+ auxiliaryTexture: { data, width, height, format: "rgba8unorm" }
595
+ });
596
+ },
597
+ cleanup: cleanupWebGpuSinglePass
598
+ })
599
+ }
600
+ });
601
+ export {
602
+ lightning
603
+ };
@@ -0,0 +1,6 @@
1
+ import {
2
+ linearGradientTint2
3
+ } from "./index-6agxdrvr.mjs";
4
+ export {
5
+ linearGradientTint2 as linearGradientTint
6
+ };
@@ -0,0 +1,6 @@
1
+ import {
2
+ linearGradient2
3
+ } from "./index-0w4eqht8.mjs";
4
+ export {
5
+ linearGradient2 as linearGradient
6
+ };