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