@remotion/effects 4.0.481 → 4.0.482

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.
@@ -0,0 +1,27 @@
1
+ export type CornerPinState = {
2
+ gl: WebGL2RenderingContext;
3
+ program: WebGLProgram;
4
+ vao: WebGLVertexArrayObject;
5
+ vbo: WebGLBuffer;
6
+ textureSource: WebGLTexture;
7
+ uniforms: {
8
+ uSource: WebGLUniformLocation | null;
9
+ uTopLeft: WebGLUniformLocation | null;
10
+ uTopRight: WebGLUniformLocation | null;
11
+ uBottomRight: WebGLUniformLocation | null;
12
+ uBottomLeft: WebGLUniformLocation | null;
13
+ };
14
+ };
15
+ export declare const setupCornerPin: (target: HTMLCanvasElement) => CornerPinState;
16
+ export declare const cleanupCornerPin: (state: CornerPinState) => void;
17
+ export declare const applyCornerPin: ({ state, source, width, height, topLeft, topRight, bottomRight, bottomLeft, flipSourceY, }: {
18
+ readonly state: CornerPinState;
19
+ readonly source: CanvasImageSource;
20
+ readonly width: number;
21
+ readonly height: number;
22
+ readonly topLeft: readonly [number, number];
23
+ readonly topRight: readonly [number, number];
24
+ readonly bottomRight: readonly [number, number];
25
+ readonly bottomLeft: readonly [number, number];
26
+ readonly flipSourceY: boolean;
27
+ }) => void;
@@ -0,0 +1,2 @@
1
+ export declare const CORNER_PIN_VS = "#version 300 es\nlayout(location = 0) in vec2 aPos;\nlayout(location = 1) in vec2 aUv;\nout vec2 vUv;\n\nvoid main() {\n\tvUv = aUv;\n\tgl_Position = vec4(aPos, 0.0, 1.0);\n}\n";
2
+ export declare const CORNER_PIN_FS = "#version 300 es\nprecision highp float;\n\nin vec2 vUv;\nout vec4 fragColor;\n\nuniform sampler2D uSource;\nuniform vec2 uTopLeft;\nuniform vec2 uTopRight;\nuniform vec2 uBottomRight;\nuniform vec2 uBottomLeft;\n\nfloat cross2(vec2 a, vec2 b) {\n\treturn a.x * b.y - a.y * b.x;\n}\n\nbool solveBilinearInverse(vec2 p, out vec2 uv) {\n\tvec2 a = uBottomLeft;\n\tvec2 b = uBottomRight - uBottomLeft;\n\tvec2 c = uTopLeft - uBottomLeft;\n\tvec2 d = uBottomLeft - uBottomRight + uTopRight - uTopLeft;\n\tvec2 q = p - a;\n\n\tfloat linearDenominator = cross2(b, c);\n\tif (abs(cross2(b, d)) < 0.000001) {\n\t\tif (abs(linearDenominator) < 0.000001) {\n\t\t\treturn false;\n\t\t}\n\n\t\tuv.x = cross2(q, c) / linearDenominator;\n\t\tuv.y = cross2(q, b) / cross2(c, b);\n\t\treturn true;\n\t}\n\n\tfloat qa = -cross2(b, d);\n\tfloat qb = cross2(q, d) - cross2(b, c);\n\tfloat qc = cross2(q, c);\n\tfloat discriminant = qb * qb - 4.0 * qa * qc;\n\n\tif (discriminant < 0.0) {\n\t\treturn false;\n\t}\n\n\tfloat sqrtDiscriminant = sqrt(discriminant);\n\tfloat u1 = (-qb + sqrtDiscriminant) / (2.0 * qa);\n\tfloat u2 = (-qb - sqrtDiscriminant) / (2.0 * qa);\n\tfloat u = u1;\n\tif (u1 < -0.001 || u1 > 1.001) {\n\t\tu = u2;\n\t}\n\n\tvec2 denominator = c + d * u;\n\tfloat v = abs(denominator.x) > abs(denominator.y)\n\t\t? (q.x - b.x * u) / denominator.x\n\t\t: (q.y - b.y * u) / denominator.y;\n\n\tuv = vec2(u, v);\n\treturn true;\n}\n\nvoid main() {\n\tvec2 sourceUv;\n\tif (!solveBilinearInverse(vUv, sourceUv)) {\n\t\tfragColor = vec4(0.0);\n\t\treturn;\n\t}\n\n\tif (\n\t\tsourceUv.x < 0.0 ||\n\t\tsourceUv.x > 1.0 ||\n\t\tsourceUv.y < 0.0 ||\n\t\tsourceUv.y > 1.0\n\t) {\n\t\tfragColor = vec4(0.0);\n\t\treturn;\n\t}\n\n\tfragColor = texture(uSource, sourceUv);\n}\n";
@@ -0,0 +1,14 @@
1
+ export type CornerPinUvCoordinate = readonly [number, number];
2
+ export type CornerPinParams = {
3
+ /** Top-left output corner in UV coordinates. Defaults to `[0, 0]`. */
4
+ readonly topLeft?: CornerPinUvCoordinate;
5
+ /** Top-right output corner in UV coordinates. Defaults to `[1, 0]`. */
6
+ readonly topRight?: CornerPinUvCoordinate;
7
+ /** Bottom-right output corner in UV coordinates. Defaults to `[1, 1]`. */
8
+ readonly bottomRight?: CornerPinUvCoordinate;
9
+ /** Bottom-left output corner in UV coordinates. Defaults to `[0, 1]`. */
10
+ readonly bottomLeft?: CornerPinUvCoordinate;
11
+ };
12
+ export declare const cornerPin: (params?: (CornerPinParams & {
13
+ readonly disabled?: boolean | undefined;
14
+ }) | undefined) => import("remotion").EffectDescriptor<unknown>;
@@ -0,0 +1 @@
1
+ export { cornerPin, type CornerPinParams, type CornerPinUvCoordinate, } from './corner-pin/index.js';
@@ -0,0 +1,389 @@
1
+ // src/corner-pin/index.ts
2
+ import { Internals as Internals2 } 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/corner-pin/corner-pin-runtime.ts
36
+ import { Internals } from "remotion";
37
+
38
+ // src/uv-coordinate.ts
39
+ var publicUvToShaderUv = (uv) => {
40
+ return [uv[0], 1 - uv[1]];
41
+ };
42
+
43
+ // src/corner-pin/corner-pin-shaders.ts
44
+ var CORNER_PIN_VS = `#version 300 es
45
+ layout(location = 0) in vec2 aPos;
46
+ layout(location = 1) in vec2 aUv;
47
+ out vec2 vUv;
48
+
49
+ void main() {
50
+ vUv = aUv;
51
+ gl_Position = vec4(aPos, 0.0, 1.0);
52
+ }
53
+ `;
54
+ var CORNER_PIN_FS = `#version 300 es
55
+ precision highp float;
56
+
57
+ in vec2 vUv;
58
+ out vec4 fragColor;
59
+
60
+ uniform sampler2D uSource;
61
+ uniform vec2 uTopLeft;
62
+ uniform vec2 uTopRight;
63
+ uniform vec2 uBottomRight;
64
+ uniform vec2 uBottomLeft;
65
+
66
+ float cross2(vec2 a, vec2 b) {
67
+ return a.x * b.y - a.y * b.x;
68
+ }
69
+
70
+ bool solveBilinearInverse(vec2 p, out vec2 uv) {
71
+ vec2 a = uBottomLeft;
72
+ vec2 b = uBottomRight - uBottomLeft;
73
+ vec2 c = uTopLeft - uBottomLeft;
74
+ vec2 d = uBottomLeft - uBottomRight + uTopRight - uTopLeft;
75
+ vec2 q = p - a;
76
+
77
+ float linearDenominator = cross2(b, c);
78
+ if (abs(cross2(b, d)) < 0.000001) {
79
+ if (abs(linearDenominator) < 0.000001) {
80
+ return false;
81
+ }
82
+
83
+ uv.x = cross2(q, c) / linearDenominator;
84
+ uv.y = cross2(q, b) / cross2(c, b);
85
+ return true;
86
+ }
87
+
88
+ float qa = -cross2(b, d);
89
+ float qb = cross2(q, d) - cross2(b, c);
90
+ float qc = cross2(q, c);
91
+ float discriminant = qb * qb - 4.0 * qa * qc;
92
+
93
+ if (discriminant < 0.0) {
94
+ return false;
95
+ }
96
+
97
+ float sqrtDiscriminant = sqrt(discriminant);
98
+ float u1 = (-qb + sqrtDiscriminant) / (2.0 * qa);
99
+ float u2 = (-qb - sqrtDiscriminant) / (2.0 * qa);
100
+ float u = u1;
101
+ if (u1 < -0.001 || u1 > 1.001) {
102
+ u = u2;
103
+ }
104
+
105
+ vec2 denominator = c + d * u;
106
+ float v = abs(denominator.x) > abs(denominator.y)
107
+ ? (q.x - b.x * u) / denominator.x
108
+ : (q.y - b.y * u) / denominator.y;
109
+
110
+ uv = vec2(u, v);
111
+ return true;
112
+ }
113
+
114
+ void main() {
115
+ vec2 sourceUv;
116
+ if (!solveBilinearInverse(vUv, sourceUv)) {
117
+ fragColor = vec4(0.0);
118
+ return;
119
+ }
120
+
121
+ if (
122
+ sourceUv.x < 0.0 ||
123
+ sourceUv.x > 1.0 ||
124
+ sourceUv.y < 0.0 ||
125
+ sourceUv.y > 1.0
126
+ ) {
127
+ fragColor = vec4(0.0);
128
+ return;
129
+ }
130
+
131
+ fragColor = texture(uSource, sourceUv);
132
+ }
133
+ `;
134
+
135
+ // src/corner-pin/corner-pin-runtime.ts
136
+ var { createWebGL2ContextError } = Internals;
137
+ var compileShader = (gl, type, source) => {
138
+ const shader = gl.createShader(type);
139
+ if (!shader) {
140
+ throw new Error("Failed to create WebGL shader");
141
+ }
142
+ gl.shaderSource(shader, source);
143
+ gl.compileShader(shader);
144
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
145
+ const log = gl.getShaderInfoLog(shader);
146
+ gl.deleteShader(shader);
147
+ throw new Error(`Shader compile failed: ${log ?? "(no log)"}`);
148
+ }
149
+ return shader;
150
+ };
151
+ var linkProgram = (gl, vs, fs) => {
152
+ const program = gl.createProgram();
153
+ if (!program) {
154
+ throw new Error("Failed to create WebGL program");
155
+ }
156
+ gl.attachShader(program, vs);
157
+ gl.attachShader(program, fs);
158
+ gl.linkProgram(program);
159
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
160
+ const log = gl.getProgramInfoLog(program);
161
+ gl.deleteProgram(program);
162
+ throw new Error(`Program link failed: ${log ?? "(no log)"}`);
163
+ }
164
+ return program;
165
+ };
166
+ var createProgram = (gl, vertexSource, fragmentSource) => {
167
+ const vs = compileShader(gl, gl.VERTEX_SHADER, vertexSource);
168
+ const fs = compileShader(gl, gl.FRAGMENT_SHADER, fragmentSource);
169
+ const program = linkProgram(gl, vs, fs);
170
+ gl.deleteShader(vs);
171
+ gl.deleteShader(fs);
172
+ return program;
173
+ };
174
+ var createRgbaTexture = (gl) => {
175
+ const texture = gl.createTexture();
176
+ if (!texture) {
177
+ throw new Error("Failed to create WebGL texture");
178
+ }
179
+ gl.bindTexture(gl.TEXTURE_2D, texture);
180
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
181
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
182
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
183
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
184
+ gl.bindTexture(gl.TEXTURE_2D, null);
185
+ return texture;
186
+ };
187
+ var setupCornerPin = (target) => {
188
+ const gl = target.getContext("webgl2", {
189
+ premultipliedAlpha: true,
190
+ alpha: true,
191
+ preserveDrawingBuffer: true
192
+ });
193
+ if (!gl) {
194
+ throw createWebGL2ContextError("corner pin effect");
195
+ }
196
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
197
+ const program = createProgram(gl, CORNER_PIN_VS, CORNER_PIN_FS);
198
+ const vao = gl.createVertexArray();
199
+ if (!vao) {
200
+ throw new Error("Failed to create WebGL vertex array");
201
+ }
202
+ gl.bindVertexArray(vao);
203
+ const data = new Float32Array([
204
+ -1,
205
+ -1,
206
+ 0,
207
+ 0,
208
+ 1,
209
+ -1,
210
+ 1,
211
+ 0,
212
+ -1,
213
+ 1,
214
+ 0,
215
+ 1,
216
+ 1,
217
+ 1,
218
+ 1,
219
+ 1
220
+ ]);
221
+ const vbo = gl.createBuffer();
222
+ if (!vbo) {
223
+ throw new Error("Failed to create WebGL buffer");
224
+ }
225
+ gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
226
+ gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
227
+ gl.enableVertexAttribArray(0);
228
+ gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 16, 0);
229
+ gl.enableVertexAttribArray(1);
230
+ gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 16, 8);
231
+ gl.bindVertexArray(null);
232
+ const textureSource = createRgbaTexture(gl);
233
+ return {
234
+ gl,
235
+ program,
236
+ vao,
237
+ vbo,
238
+ textureSource,
239
+ uniforms: {
240
+ uSource: gl.getUniformLocation(program, "uSource"),
241
+ uTopLeft: gl.getUniformLocation(program, "uTopLeft"),
242
+ uTopRight: gl.getUniformLocation(program, "uTopRight"),
243
+ uBottomRight: gl.getUniformLocation(program, "uBottomRight"),
244
+ uBottomLeft: gl.getUniformLocation(program, "uBottomLeft")
245
+ }
246
+ };
247
+ };
248
+ var cleanupCornerPin = (state) => {
249
+ const { gl, program, vao, vbo, textureSource } = state;
250
+ gl.deleteTexture(textureSource);
251
+ gl.deleteBuffer(vbo);
252
+ gl.deleteProgram(program);
253
+ gl.deleteVertexArray(vao);
254
+ };
255
+ var drawFullscreenQuad = (state) => {
256
+ const { gl, vao } = state;
257
+ gl.bindVertexArray(vao);
258
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
259
+ gl.bindVertexArray(null);
260
+ };
261
+ var setUvUniform = (gl, location, uv) => {
262
+ if (!location) {
263
+ return;
264
+ }
265
+ const shaderUv = publicUvToShaderUv(uv);
266
+ gl.uniform2f(location, shaderUv[0], shaderUv[1]);
267
+ };
268
+ var applyCornerPin = ({
269
+ state,
270
+ source,
271
+ width,
272
+ height,
273
+ topLeft,
274
+ topRight,
275
+ bottomRight,
276
+ bottomLeft,
277
+ flipSourceY
278
+ }) => {
279
+ const { gl, program, textureSource, uniforms } = state;
280
+ gl.viewport(0, 0, width, height);
281
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipSourceY);
282
+ gl.bindTexture(gl.TEXTURE_2D, textureSource);
283
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
284
+ gl.bindTexture(gl.TEXTURE_2D, null);
285
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
286
+ gl.clearColor(0, 0, 0, 0);
287
+ gl.clear(gl.COLOR_BUFFER_BIT);
288
+ gl.useProgram(program);
289
+ if (uniforms.uSource)
290
+ gl.uniform1i(uniforms.uSource, 0);
291
+ setUvUniform(gl, uniforms.uTopLeft, topLeft);
292
+ setUvUniform(gl, uniforms.uTopRight, topRight);
293
+ setUvUniform(gl, uniforms.uBottomRight, bottomRight);
294
+ setUvUniform(gl, uniforms.uBottomLeft, bottomLeft);
295
+ gl.activeTexture(gl.TEXTURE0);
296
+ gl.bindTexture(gl.TEXTURE_2D, textureSource);
297
+ drawFullscreenQuad(state);
298
+ gl.bindTexture(gl.TEXTURE_2D, null);
299
+ gl.useProgram(null);
300
+ };
301
+
302
+ // src/corner-pin/index.ts
303
+ var { createEffect } = Internals2;
304
+ var DEFAULT_TOP_LEFT = [0, 0];
305
+ var DEFAULT_TOP_RIGHT = [1, 0];
306
+ var DEFAULT_BOTTOM_RIGHT = [1, 1];
307
+ var DEFAULT_BOTTOM_LEFT = [0, 1];
308
+ var cornerSchema = (defaultValue) => ({
309
+ type: "uv-coordinate",
310
+ min: -1,
311
+ max: 2,
312
+ step: 0.01,
313
+ default: defaultValue,
314
+ description: "Corner"
315
+ });
316
+ var cornerPinSchema = {
317
+ topLeft: {
318
+ ...cornerSchema(DEFAULT_TOP_LEFT),
319
+ description: "Top left"
320
+ },
321
+ topRight: {
322
+ ...cornerSchema(DEFAULT_TOP_RIGHT),
323
+ description: "Top right"
324
+ },
325
+ bottomRight: {
326
+ ...cornerSchema(DEFAULT_BOTTOM_RIGHT),
327
+ description: "Bottom right"
328
+ },
329
+ bottomLeft: {
330
+ ...cornerSchema(DEFAULT_BOTTOM_LEFT),
331
+ description: "Bottom left"
332
+ }
333
+ };
334
+ var resolve = (p) => ({
335
+ topLeft: [...p.topLeft ?? DEFAULT_TOP_LEFT],
336
+ topRight: [...p.topRight ?? DEFAULT_TOP_RIGHT],
337
+ bottomRight: [
338
+ ...p.bottomRight ?? DEFAULT_BOTTOM_RIGHT
339
+ ],
340
+ bottomLeft: [
341
+ ...p.bottomLeft ?? DEFAULT_BOTTOM_LEFT
342
+ ]
343
+ });
344
+ var assertOptionalUvCoordinate = (value, name) => {
345
+ if (value === undefined) {
346
+ return;
347
+ }
348
+ if (!Array.isArray(value) || value.length !== 2 || value.some((item) => typeof item !== "number" || !Number.isFinite(item))) {
349
+ throw new TypeError(`"${name}" must be a [number, number] tuple`);
350
+ }
351
+ };
352
+ var validateCornerPinParams = (params) => {
353
+ assertEffectParamsObject(params, "Corner pin");
354
+ assertOptionalUvCoordinate(params.topLeft, "topLeft");
355
+ assertOptionalUvCoordinate(params.topRight, "topRight");
356
+ assertOptionalUvCoordinate(params.bottomRight, "bottomRight");
357
+ assertOptionalUvCoordinate(params.bottomLeft, "bottomLeft");
358
+ };
359
+ var cornerPin = createEffect({
360
+ type: "dev.remotion.effects.cornerPin",
361
+ label: "cornerPin()",
362
+ documentationLink: "https://www.remotion.dev/docs/effects/corner-pin",
363
+ backend: "webgl2",
364
+ calculateKey: (params) => {
365
+ const r = resolve(params);
366
+ return `corner-pin-${r.topLeft.join(":")}-${r.topRight.join(":")}-${r.bottomRight.join(":")}-${r.bottomLeft.join(":")}`;
367
+ },
368
+ setup: (target) => setupCornerPin(target),
369
+ apply: ({ source, width, height, params, state, flipSourceY }) => {
370
+ const r = resolve(params);
371
+ applyCornerPin({
372
+ state,
373
+ source,
374
+ width,
375
+ height,
376
+ topLeft: r.topLeft,
377
+ topRight: r.topRight,
378
+ bottomRight: r.bottomRight,
379
+ bottomLeft: r.bottomLeft,
380
+ flipSourceY
381
+ });
382
+ },
383
+ cleanup: (state) => cleanupCornerPin(state),
384
+ schema: cornerPinSchema,
385
+ validateParams: validateCornerPinParams
386
+ });
387
+ export {
388
+ cornerPin
389
+ };
@@ -160,7 +160,7 @@ var gridlinesSchema = {
160
160
  type: "rotation-degrees",
161
161
  min: -180,
162
162
  max: 180,
163
- step: 1,
163
+ step: 0.1,
164
164
  default: DEFAULT_ROTATION_X,
165
165
  description: "Rotation X"
166
166
  },
@@ -168,7 +168,7 @@ var gridlinesSchema = {
168
168
  type: "rotation-degrees",
169
169
  min: -180,
170
170
  max: 180,
171
- step: 1,
171
+ step: 0.1,
172
172
  default: DEFAULT_ROTATION_Y,
173
173
  description: "Rotation Y"
174
174
  },