@remotion/effects 4.0.469 → 4.0.471
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/esm/evolve.mjs +398 -0
- package/dist/esm/fisheye.mjs +430 -0
- package/dist/esm/index.mjs +893 -0
- package/dist/esm/lines.mjs +487 -0
- package/dist/esm/pixel-dissolve.mjs +369 -0
- package/dist/esm/rings.mjs +461 -0
- package/dist/esm/scanlines.mjs +381 -0
- package/dist/esm/waves.mjs +540 -0
- package/dist/esm/white-noise.mjs +279 -0
- package/dist/esm/zigzag.mjs +531 -0
- package/dist/evolve.d.ts +43 -0
- package/dist/fisheye/fisheye-runtime.d.ts +28 -0
- package/dist/fisheye/fisheye-shaders.d.ts +2 -0
- package/dist/fisheye/index.d.ts +26 -0
- package/dist/fisheye.d.ts +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/lines.d.ts +61 -0
- package/dist/pixel-dissolve.d.ts +10 -0
- package/dist/rings.d.ts +48 -0
- package/dist/scanlines.d.ts +15 -0
- package/dist/visual-test/effects-visual.test.d.ts +1 -0
- package/dist/visual-test/visual-utils.d.ts +13 -0
- package/dist/waves.d.ts +91 -0
- package/dist/white-noise.d.ts +9 -0
- package/dist/zigzag.d.ts +81 -0
- package/package.json +79 -3
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
// src/lines.ts
|
|
2
|
+
import { Internals } from "remotion";
|
|
3
|
+
|
|
4
|
+
// src/validate-effect-param.ts
|
|
5
|
+
var assertEffectParamsObject = (params, effectLabel) => {
|
|
6
|
+
if (params === null || typeof params !== "object") {
|
|
7
|
+
throw new TypeError(`${effectLabel} effect requires a parameters object, but got ${JSON.stringify(params)}`);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var assertRequiredFiniteNumber = (value, name) => {
|
|
11
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
12
|
+
throw new TypeError(`"${name}" must be a finite number, but got ${JSON.stringify(value)}`);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var assertRequiredColor = (value, name) => {
|
|
16
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
17
|
+
throw new TypeError(`"${name}" must be a non-empty string, but got ${JSON.stringify(value)}`);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var assertOptionalColor = (value, name) => {
|
|
21
|
+
if (value === undefined) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
assertRequiredColor(value, name);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// src/color-utils.ts
|
|
28
|
+
var DEFAULT_AMOUNT = 1;
|
|
29
|
+
var DEFAULT_BRIGHTNESS_AMOUNT = 0;
|
|
30
|
+
var DEFAULT_HUE_DEGREES = 0;
|
|
31
|
+
var colorAmountSchema = {
|
|
32
|
+
type: "number",
|
|
33
|
+
min: 0,
|
|
34
|
+
max: 1,
|
|
35
|
+
step: 0.01,
|
|
36
|
+
default: DEFAULT_AMOUNT,
|
|
37
|
+
description: "Amount"
|
|
38
|
+
};
|
|
39
|
+
var colorMultiplierSchema = {
|
|
40
|
+
type: "number",
|
|
41
|
+
min: 0,
|
|
42
|
+
step: 0.01,
|
|
43
|
+
default: DEFAULT_AMOUNT,
|
|
44
|
+
description: "Amount"
|
|
45
|
+
};
|
|
46
|
+
var brightnessAmountSchema = {
|
|
47
|
+
type: "number",
|
|
48
|
+
min: -1,
|
|
49
|
+
max: 1,
|
|
50
|
+
step: 0.01,
|
|
51
|
+
default: DEFAULT_BRIGHTNESS_AMOUNT,
|
|
52
|
+
description: "Amount"
|
|
53
|
+
};
|
|
54
|
+
var hueDegreesSchema = {
|
|
55
|
+
type: "number",
|
|
56
|
+
step: 1,
|
|
57
|
+
default: DEFAULT_HUE_DEGREES,
|
|
58
|
+
description: "Degrees"
|
|
59
|
+
};
|
|
60
|
+
var assertOptionalFiniteNumber = (value, name) => {
|
|
61
|
+
if (value === undefined) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
assertRequiredFiniteNumber(value, name);
|
|
65
|
+
};
|
|
66
|
+
var validateUnitInterval = (value, name) => {
|
|
67
|
+
if (value < 0) {
|
|
68
|
+
throw new TypeError(`"${name}" must be >= 0, but got ${JSON.stringify(value)}`);
|
|
69
|
+
}
|
|
70
|
+
if (value > 1) {
|
|
71
|
+
throw new TypeError(`"${name}" must be <= 1, but got ${JSON.stringify(value)}`);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var validateNonNegative = (value, name) => {
|
|
75
|
+
if (value < 0) {
|
|
76
|
+
throw new TypeError(`"${name}" must be >= 0, but got ${JSON.stringify(value)}`);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
var validateSignedUnitInterval = (value, name) => {
|
|
80
|
+
if (value < -1) {
|
|
81
|
+
throw new TypeError(`"${name}" must be >= -1, but got ${JSON.stringify(value)}`);
|
|
82
|
+
}
|
|
83
|
+
if (value > 1) {
|
|
84
|
+
throw new TypeError(`"${name}" must be <= 1, but got ${JSON.stringify(value)}`);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
var clampColorChannel = (value) => {
|
|
88
|
+
return Math.max(0, Math.min(255, value));
|
|
89
|
+
};
|
|
90
|
+
var parseColorRgba = (ctx, color) => {
|
|
91
|
+
ctx.clearRect(0, 0, 1, 1);
|
|
92
|
+
ctx.fillStyle = color;
|
|
93
|
+
ctx.fillRect(0, 0, 1, 1);
|
|
94
|
+
const { data } = ctx.getImageData(0, 0, 1, 1);
|
|
95
|
+
return [data[0], data[1], data[2], data[3]];
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// src/lines.ts
|
|
99
|
+
var { createEffect, createWebGL2ContextError } = Internals;
|
|
100
|
+
var LINE_DIRECTIONS = ["horizontal", "vertical"];
|
|
101
|
+
var DEFAULT_COLORS = ["#dff4ff", "#7cc6ff"];
|
|
102
|
+
var DEFAULT_DIRECTION = "horizontal";
|
|
103
|
+
var DEFAULT_THICKNESS = 40;
|
|
104
|
+
var DEFAULT_GAP = 0;
|
|
105
|
+
var DEFAULT_ANGLE = 0;
|
|
106
|
+
var DEFAULT_OFFSET = 0;
|
|
107
|
+
var linesSchema = {
|
|
108
|
+
direction: {
|
|
109
|
+
type: "enum",
|
|
110
|
+
variants: {
|
|
111
|
+
horizontal: {},
|
|
112
|
+
vertical: {}
|
|
113
|
+
},
|
|
114
|
+
default: DEFAULT_DIRECTION,
|
|
115
|
+
description: "Direction"
|
|
116
|
+
},
|
|
117
|
+
thickness: {
|
|
118
|
+
type: "number",
|
|
119
|
+
min: 0.1,
|
|
120
|
+
max: 400,
|
|
121
|
+
step: 0.1,
|
|
122
|
+
default: DEFAULT_THICKNESS,
|
|
123
|
+
description: "Thickness"
|
|
124
|
+
},
|
|
125
|
+
gap: {
|
|
126
|
+
type: "number",
|
|
127
|
+
min: 0,
|
|
128
|
+
max: 400,
|
|
129
|
+
step: 0.1,
|
|
130
|
+
default: DEFAULT_GAP,
|
|
131
|
+
description: "Gap"
|
|
132
|
+
},
|
|
133
|
+
angle: {
|
|
134
|
+
type: "number",
|
|
135
|
+
min: -180,
|
|
136
|
+
max: 180,
|
|
137
|
+
step: 1,
|
|
138
|
+
default: DEFAULT_ANGLE,
|
|
139
|
+
description: "Angle"
|
|
140
|
+
},
|
|
141
|
+
offset: {
|
|
142
|
+
type: "number",
|
|
143
|
+
step: 0.1,
|
|
144
|
+
default: DEFAULT_OFFSET,
|
|
145
|
+
description: "Offset"
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
var resolve = (p) => {
|
|
149
|
+
const thickness = p.thickness ?? DEFAULT_THICKNESS;
|
|
150
|
+
const gap = p.gap ?? DEFAULT_GAP;
|
|
151
|
+
return {
|
|
152
|
+
colors: p.colors ?? DEFAULT_COLORS,
|
|
153
|
+
direction: p.direction ?? DEFAULT_DIRECTION,
|
|
154
|
+
thickness,
|
|
155
|
+
spacing: thickness + gap,
|
|
156
|
+
angle: p.angle ?? DEFAULT_ANGLE,
|
|
157
|
+
offset: p.offset ?? DEFAULT_OFFSET
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
var formatEnum = (variants) => {
|
|
161
|
+
if (variants.length === 2) {
|
|
162
|
+
return `"${variants[0]}" or "${variants[1]}"`;
|
|
163
|
+
}
|
|
164
|
+
return `${variants.slice(0, -1).map((variant) => `"${variant}"`).join(", ")} or "${variants[variants.length - 1]}"`;
|
|
165
|
+
};
|
|
166
|
+
var validatePositive = (value, name) => {
|
|
167
|
+
if (value <= 0) {
|
|
168
|
+
throw new TypeError(`"${name}" must be greater than 0, but got ${JSON.stringify(value)}`);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
var validateNonNegative2 = (value, name) => {
|
|
172
|
+
if (value < 0) {
|
|
173
|
+
throw new TypeError(`"${name}" must be greater than or equal to 0, but got ${JSON.stringify(value)}`);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
var validateColors = (colors) => {
|
|
177
|
+
if (colors === undefined) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (!Array.isArray(colors) || colors.length < 2) {
|
|
181
|
+
throw new TypeError(`"colors" must be an array with at least 2 colors, but got ${JSON.stringify(colors)}`);
|
|
182
|
+
}
|
|
183
|
+
for (let i = 0;i < colors.length; i++) {
|
|
184
|
+
assertRequiredColor(colors[i], `colors[${i}]`);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
var validateDirection = (direction) => {
|
|
188
|
+
if (direction === undefined) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
if (typeof direction !== "string" || !LINE_DIRECTIONS.includes(direction)) {
|
|
192
|
+
throw new TypeError(`"direction" must be ${formatEnum(LINE_DIRECTIONS)}, but got ${JSON.stringify(direction)}`);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
var validateLinesParams = (params) => {
|
|
196
|
+
assertEffectParamsObject(params, "Lines");
|
|
197
|
+
validateColors(params.colors);
|
|
198
|
+
validateDirection(params.direction);
|
|
199
|
+
assertOptionalFiniteNumber(params.thickness, "thickness");
|
|
200
|
+
assertOptionalFiniteNumber(params.gap, "gap");
|
|
201
|
+
assertOptionalFiniteNumber(params.angle, "angle");
|
|
202
|
+
assertOptionalFiniteNumber(params.offset, "offset");
|
|
203
|
+
const thickness = params.thickness ?? DEFAULT_THICKNESS;
|
|
204
|
+
const gap = params.gap ?? DEFAULT_GAP;
|
|
205
|
+
validatePositive(thickness, "thickness");
|
|
206
|
+
validateNonNegative2(gap, "gap");
|
|
207
|
+
};
|
|
208
|
+
var LINES_VS = `#version 300 es
|
|
209
|
+
in vec2 aPos;
|
|
210
|
+
in vec2 aUv;
|
|
211
|
+
out vec2 vUv;
|
|
212
|
+
|
|
213
|
+
void main() {
|
|
214
|
+
vUv = aUv;
|
|
215
|
+
gl_Position = vec4(aPos, 0.0, 1.0);
|
|
216
|
+
}
|
|
217
|
+
`;
|
|
218
|
+
var LINES_FS = `#version 300 es
|
|
219
|
+
precision highp float;
|
|
220
|
+
|
|
221
|
+
in vec2 vUv;
|
|
222
|
+
out vec4 fragColor;
|
|
223
|
+
|
|
224
|
+
uniform sampler2D uSource;
|
|
225
|
+
uniform sampler2D uPalette;
|
|
226
|
+
uniform vec2 uResolution;
|
|
227
|
+
uniform float uNumColors;
|
|
228
|
+
uniform int uDirection;
|
|
229
|
+
uniform float uThickness;
|
|
230
|
+
uniform float uSpacing;
|
|
231
|
+
uniform float uAngle;
|
|
232
|
+
uniform float uOffset;
|
|
233
|
+
|
|
234
|
+
void main() {
|
|
235
|
+
vec4 texColor = texture(uSource, vUv);
|
|
236
|
+
float thickness = max(uThickness, 0.001);
|
|
237
|
+
float spacing = max(uSpacing, 0.001);
|
|
238
|
+
float cycle = spacing * uNumColors;
|
|
239
|
+
vec2 centered = vUv * uResolution - uResolution * 0.5;
|
|
240
|
+
float s = sin(uAngle);
|
|
241
|
+
float c = cos(uAngle);
|
|
242
|
+
vec2 rotated = vec2(
|
|
243
|
+
centered.x * c - centered.y * s,
|
|
244
|
+
centered.x * s + centered.y * c
|
|
245
|
+
);
|
|
246
|
+
float axis = uDirection == 0 ? rotated.y : rotated.x;
|
|
247
|
+
float position = mod(axis + uOffset, cycle);
|
|
248
|
+
if (position < 0.0) {
|
|
249
|
+
position += cycle;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
float colorIndex = floor(position / spacing);
|
|
253
|
+
float inStripe = mod(position, spacing);
|
|
254
|
+
if (inStripe > thickness) {
|
|
255
|
+
fragColor = texColor;
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
float texCoord = (colorIndex + 0.5) / uNumColors;
|
|
260
|
+
vec4 lineColor = texture(uPalette, vec2(texCoord, 0.5));
|
|
261
|
+
float lineAlpha = lineColor.a;
|
|
262
|
+
vec3 premultipliedLine = lineColor.rgb * lineAlpha;
|
|
263
|
+
|
|
264
|
+
fragColor = vec4(
|
|
265
|
+
premultipliedLine + texColor.rgb * (1.0 - lineAlpha),
|
|
266
|
+
lineAlpha + texColor.a * (1.0 - lineAlpha)
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
`;
|
|
270
|
+
var compileShader = (gl, type, source) => {
|
|
271
|
+
const shader = gl.createShader(type);
|
|
272
|
+
if (!shader) {
|
|
273
|
+
throw new Error("Failed to create WebGL shader");
|
|
274
|
+
}
|
|
275
|
+
gl.shaderSource(shader, source);
|
|
276
|
+
gl.compileShader(shader);
|
|
277
|
+
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
278
|
+
const log = gl.getShaderInfoLog(shader);
|
|
279
|
+
gl.deleteShader(shader);
|
|
280
|
+
throw new Error(`Lines shader compile failed: ${log ?? "(no log)"}`);
|
|
281
|
+
}
|
|
282
|
+
return shader;
|
|
283
|
+
};
|
|
284
|
+
var linkProgram = (gl, vs, fs) => {
|
|
285
|
+
const program = gl.createProgram();
|
|
286
|
+
if (!program) {
|
|
287
|
+
throw new Error("Failed to create WebGL program");
|
|
288
|
+
}
|
|
289
|
+
gl.attachShader(program, vs);
|
|
290
|
+
gl.attachShader(program, fs);
|
|
291
|
+
gl.linkProgram(program);
|
|
292
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
293
|
+
const log = gl.getProgramInfoLog(program);
|
|
294
|
+
gl.deleteProgram(program);
|
|
295
|
+
throw new Error(`Lines program link failed: ${log ?? "(no log)"}`);
|
|
296
|
+
}
|
|
297
|
+
return program;
|
|
298
|
+
};
|
|
299
|
+
var createProgram = (gl, vertexSource, fragmentSource) => {
|
|
300
|
+
const vs = compileShader(gl, gl.VERTEX_SHADER, vertexSource);
|
|
301
|
+
const fs = compileShader(gl, gl.FRAGMENT_SHADER, fragmentSource);
|
|
302
|
+
const program = linkProgram(gl, vs, fs);
|
|
303
|
+
gl.deleteShader(vs);
|
|
304
|
+
gl.deleteShader(fs);
|
|
305
|
+
return program;
|
|
306
|
+
};
|
|
307
|
+
var createTexture = (gl, filter) => {
|
|
308
|
+
const texture = gl.createTexture();
|
|
309
|
+
if (!texture) {
|
|
310
|
+
throw new Error("Failed to create WebGL texture");
|
|
311
|
+
}
|
|
312
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
313
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filter);
|
|
314
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filter);
|
|
315
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
316
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
317
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
318
|
+
return texture;
|
|
319
|
+
};
|
|
320
|
+
var setupLines = (target) => {
|
|
321
|
+
const gl = target.getContext("webgl2", {
|
|
322
|
+
premultipliedAlpha: true,
|
|
323
|
+
alpha: true,
|
|
324
|
+
preserveDrawingBuffer: true
|
|
325
|
+
});
|
|
326
|
+
if (!gl) {
|
|
327
|
+
throw createWebGL2ContextError("lines effect");
|
|
328
|
+
}
|
|
329
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
|
|
330
|
+
const program = createProgram(gl, LINES_VS, LINES_FS);
|
|
331
|
+
const vao = gl.createVertexArray();
|
|
332
|
+
if (!vao) {
|
|
333
|
+
throw new Error("Failed to create WebGL vertex array");
|
|
334
|
+
}
|
|
335
|
+
gl.bindVertexArray(vao);
|
|
336
|
+
const data = new Float32Array([
|
|
337
|
+
-1,
|
|
338
|
+
-1,
|
|
339
|
+
0,
|
|
340
|
+
0,
|
|
341
|
+
1,
|
|
342
|
+
-1,
|
|
343
|
+
1,
|
|
344
|
+
0,
|
|
345
|
+
-1,
|
|
346
|
+
1,
|
|
347
|
+
0,
|
|
348
|
+
1,
|
|
349
|
+
1,
|
|
350
|
+
1,
|
|
351
|
+
1,
|
|
352
|
+
1
|
|
353
|
+
]);
|
|
354
|
+
const vbo = gl.createBuffer();
|
|
355
|
+
if (!vbo) {
|
|
356
|
+
throw new Error("Failed to create WebGL buffer");
|
|
357
|
+
}
|
|
358
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
|
|
359
|
+
gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
|
|
360
|
+
const aPos = gl.getAttribLocation(program, "aPos");
|
|
361
|
+
const aUv = gl.getAttribLocation(program, "aUv");
|
|
362
|
+
gl.enableVertexAttribArray(aPos);
|
|
363
|
+
gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 16, 0);
|
|
364
|
+
gl.enableVertexAttribArray(aUv);
|
|
365
|
+
gl.vertexAttribPointer(aUv, 2, gl.FLOAT, false, 16, 8);
|
|
366
|
+
gl.bindVertexArray(null);
|
|
367
|
+
const colorCanvas = document.createElement("canvas");
|
|
368
|
+
colorCanvas.width = 1;
|
|
369
|
+
colorCanvas.height = 1;
|
|
370
|
+
const colorCtx = colorCanvas.getContext("2d", { willReadFrequently: true });
|
|
371
|
+
if (!colorCtx) {
|
|
372
|
+
throw new Error("Failed to acquire 2D context for color parsing");
|
|
373
|
+
}
|
|
374
|
+
return {
|
|
375
|
+
gl,
|
|
376
|
+
program,
|
|
377
|
+
vao,
|
|
378
|
+
vbo,
|
|
379
|
+
sourceTexture: createTexture(gl, gl.LINEAR),
|
|
380
|
+
paletteTexture: createTexture(gl, gl.NEAREST),
|
|
381
|
+
colorCtx,
|
|
382
|
+
uniforms: {
|
|
383
|
+
uSource: gl.getUniformLocation(program, "uSource"),
|
|
384
|
+
uPalette: gl.getUniformLocation(program, "uPalette"),
|
|
385
|
+
uResolution: gl.getUniformLocation(program, "uResolution"),
|
|
386
|
+
uNumColors: gl.getUniformLocation(program, "uNumColors"),
|
|
387
|
+
uDirection: gl.getUniformLocation(program, "uDirection"),
|
|
388
|
+
uThickness: gl.getUniformLocation(program, "uThickness"),
|
|
389
|
+
uSpacing: gl.getUniformLocation(program, "uSpacing"),
|
|
390
|
+
uAngle: gl.getUniformLocation(program, "uAngle"),
|
|
391
|
+
uOffset: gl.getUniformLocation(program, "uOffset")
|
|
392
|
+
},
|
|
393
|
+
cachedPaletteKey: "",
|
|
394
|
+
palettePixelData: new Uint8Array(0)
|
|
395
|
+
};
|
|
396
|
+
};
|
|
397
|
+
var updatePalette = (state, colors) => {
|
|
398
|
+
const paletteKey = colors.join("|");
|
|
399
|
+
const paletteDirty = state.cachedPaletteKey !== paletteKey;
|
|
400
|
+
if (!paletteDirty) {
|
|
401
|
+
return false;
|
|
402
|
+
}
|
|
403
|
+
state.cachedPaletteKey = paletteKey;
|
|
404
|
+
const len = colors.length * 4;
|
|
405
|
+
if (state.palettePixelData.length !== len) {
|
|
406
|
+
state.palettePixelData = new Uint8Array(len);
|
|
407
|
+
}
|
|
408
|
+
const { palettePixelData } = state;
|
|
409
|
+
for (let i = 0;i < colors.length; i++) {
|
|
410
|
+
const color = parseColorRgba(state.colorCtx, colors[i]);
|
|
411
|
+
palettePixelData[i * 4] = color[0];
|
|
412
|
+
palettePixelData[i * 4 + 1] = color[1];
|
|
413
|
+
palettePixelData[i * 4 + 2] = color[2];
|
|
414
|
+
palettePixelData[i * 4 + 3] = color[3];
|
|
415
|
+
}
|
|
416
|
+
return true;
|
|
417
|
+
};
|
|
418
|
+
var lines = createEffect({
|
|
419
|
+
type: "remotion/lines",
|
|
420
|
+
label: "lines()",
|
|
421
|
+
documentationLink: "https://www.remotion.dev/docs/effects/lines",
|
|
422
|
+
backend: "webgl2",
|
|
423
|
+
calculateKey: (params) => {
|
|
424
|
+
const r = resolve(params);
|
|
425
|
+
return `lines-${r.colors.join("|")}-${r.direction}-${r.thickness}-${r.spacing}-${r.angle}-${r.offset}`;
|
|
426
|
+
},
|
|
427
|
+
setup: (target) => setupLines(target),
|
|
428
|
+
apply: ({ source, width, height, params, state, flipSourceY }) => {
|
|
429
|
+
const r = resolve(params);
|
|
430
|
+
const paletteDirty = updatePalette(state, r.colors);
|
|
431
|
+
const { gl, program, sourceTexture, paletteTexture, uniforms, vao } = state;
|
|
432
|
+
gl.viewport(0, 0, width, height);
|
|
433
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
434
|
+
gl.clearColor(0, 0, 0, 0);
|
|
435
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
436
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
437
|
+
gl.bindTexture(gl.TEXTURE_2D, sourceTexture);
|
|
438
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
|
|
439
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipSourceY);
|
|
440
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
|
|
441
|
+
gl.activeTexture(gl.TEXTURE1);
|
|
442
|
+
gl.bindTexture(gl.TEXTURE_2D, paletteTexture);
|
|
443
|
+
if (paletteDirty) {
|
|
444
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
445
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
|
|
446
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, r.colors.length, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, state.palettePixelData);
|
|
447
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
|
|
448
|
+
}
|
|
449
|
+
gl.useProgram(program);
|
|
450
|
+
if (uniforms.uSource)
|
|
451
|
+
gl.uniform1i(uniforms.uSource, 0);
|
|
452
|
+
if (uniforms.uPalette)
|
|
453
|
+
gl.uniform1i(uniforms.uPalette, 1);
|
|
454
|
+
if (uniforms.uResolution)
|
|
455
|
+
gl.uniform2f(uniforms.uResolution, width, height);
|
|
456
|
+
if (uniforms.uNumColors)
|
|
457
|
+
gl.uniform1f(uniforms.uNumColors, r.colors.length);
|
|
458
|
+
if (uniforms.uDirection)
|
|
459
|
+
gl.uniform1i(uniforms.uDirection, r.direction === "horizontal" ? 0 : 1);
|
|
460
|
+
if (uniforms.uThickness)
|
|
461
|
+
gl.uniform1f(uniforms.uThickness, r.thickness);
|
|
462
|
+
if (uniforms.uSpacing)
|
|
463
|
+
gl.uniform1f(uniforms.uSpacing, r.spacing);
|
|
464
|
+
if (uniforms.uAngle)
|
|
465
|
+
gl.uniform1f(uniforms.uAngle, r.angle * Math.PI / 180);
|
|
466
|
+
if (uniforms.uOffset)
|
|
467
|
+
gl.uniform1f(uniforms.uOffset, r.offset);
|
|
468
|
+
gl.bindVertexArray(vao);
|
|
469
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
470
|
+
gl.bindVertexArray(null);
|
|
471
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
472
|
+
gl.useProgram(null);
|
|
473
|
+
},
|
|
474
|
+
cleanup: ({ gl, program, vao, vbo, sourceTexture, paletteTexture }) => {
|
|
475
|
+
gl.deleteTexture(sourceTexture);
|
|
476
|
+
gl.deleteTexture(paletteTexture);
|
|
477
|
+
gl.deleteBuffer(vbo);
|
|
478
|
+
gl.deleteProgram(program);
|
|
479
|
+
gl.deleteVertexArray(vao);
|
|
480
|
+
},
|
|
481
|
+
schema: linesSchema,
|
|
482
|
+
validateParams: validateLinesParams
|
|
483
|
+
});
|
|
484
|
+
export {
|
|
485
|
+
linesSchema,
|
|
486
|
+
lines
|
|
487
|
+
};
|