@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.
@@ -1431,7 +1431,7 @@ var gridlinesSchema = {
1431
1431
  type: "rotation-degrees",
1432
1432
  min: -180,
1433
1433
  max: 180,
1434
- step: 1,
1434
+ step: 0.1,
1435
1435
  default: DEFAULT_ROTATION_X,
1436
1436
  description: "Rotation X"
1437
1437
  },
@@ -1439,7 +1439,7 @@ var gridlinesSchema = {
1439
1439
  type: "rotation-degrees",
1440
1440
  min: -180,
1441
1441
  max: 180,
1442
- step: 1,
1442
+ step: 0.1,
1443
1443
  default: DEFAULT_ROTATION_Y,
1444
1444
  description: "Rotation Y"
1445
1445
  },
@@ -2309,10 +2309,361 @@ var zigzag = createEffect5({
2309
2309
  schema: zigzagSchema,
2310
2310
  validateParams: validateZigzagParams
2311
2311
  });
2312
+ // src/corner-pin/index.ts
2313
+ import { Internals as Internals7 } from "remotion";
2314
+
2315
+ // src/corner-pin/corner-pin-runtime.ts
2316
+ import { Internals as Internals6 } from "remotion";
2317
+
2318
+ // src/corner-pin/corner-pin-shaders.ts
2319
+ var CORNER_PIN_VS = `#version 300 es
2320
+ layout(location = 0) in vec2 aPos;
2321
+ layout(location = 1) in vec2 aUv;
2322
+ out vec2 vUv;
2323
+
2324
+ void main() {
2325
+ vUv = aUv;
2326
+ gl_Position = vec4(aPos, 0.0, 1.0);
2327
+ }
2328
+ `;
2329
+ var CORNER_PIN_FS = `#version 300 es
2330
+ precision highp float;
2331
+
2332
+ in vec2 vUv;
2333
+ out vec4 fragColor;
2334
+
2335
+ uniform sampler2D uSource;
2336
+ uniform vec2 uTopLeft;
2337
+ uniform vec2 uTopRight;
2338
+ uniform vec2 uBottomRight;
2339
+ uniform vec2 uBottomLeft;
2340
+
2341
+ float cross2(vec2 a, vec2 b) {
2342
+ return a.x * b.y - a.y * b.x;
2343
+ }
2344
+
2345
+ bool solveBilinearInverse(vec2 p, out vec2 uv) {
2346
+ vec2 a = uBottomLeft;
2347
+ vec2 b = uBottomRight - uBottomLeft;
2348
+ vec2 c = uTopLeft - uBottomLeft;
2349
+ vec2 d = uBottomLeft - uBottomRight + uTopRight - uTopLeft;
2350
+ vec2 q = p - a;
2351
+
2352
+ float linearDenominator = cross2(b, c);
2353
+ if (abs(cross2(b, d)) < 0.000001) {
2354
+ if (abs(linearDenominator) < 0.000001) {
2355
+ return false;
2356
+ }
2357
+
2358
+ uv.x = cross2(q, c) / linearDenominator;
2359
+ uv.y = cross2(q, b) / cross2(c, b);
2360
+ return true;
2361
+ }
2362
+
2363
+ float qa = -cross2(b, d);
2364
+ float qb = cross2(q, d) - cross2(b, c);
2365
+ float qc = cross2(q, c);
2366
+ float discriminant = qb * qb - 4.0 * qa * qc;
2367
+
2368
+ if (discriminant < 0.0) {
2369
+ return false;
2370
+ }
2371
+
2372
+ float sqrtDiscriminant = sqrt(discriminant);
2373
+ float u1 = (-qb + sqrtDiscriminant) / (2.0 * qa);
2374
+ float u2 = (-qb - sqrtDiscriminant) / (2.0 * qa);
2375
+ float u = u1;
2376
+ if (u1 < -0.001 || u1 > 1.001) {
2377
+ u = u2;
2378
+ }
2379
+
2380
+ vec2 denominator = c + d * u;
2381
+ float v = abs(denominator.x) > abs(denominator.y)
2382
+ ? (q.x - b.x * u) / denominator.x
2383
+ : (q.y - b.y * u) / denominator.y;
2384
+
2385
+ uv = vec2(u, v);
2386
+ return true;
2387
+ }
2388
+
2389
+ void main() {
2390
+ vec2 sourceUv;
2391
+ if (!solveBilinearInverse(vUv, sourceUv)) {
2392
+ fragColor = vec4(0.0);
2393
+ return;
2394
+ }
2395
+
2396
+ if (
2397
+ sourceUv.x < 0.0 ||
2398
+ sourceUv.x > 1.0 ||
2399
+ sourceUv.y < 0.0 ||
2400
+ sourceUv.y > 1.0
2401
+ ) {
2402
+ fragColor = vec4(0.0);
2403
+ return;
2404
+ }
2405
+
2406
+ fragColor = texture(uSource, sourceUv);
2407
+ }
2408
+ `;
2409
+
2410
+ // src/corner-pin/corner-pin-runtime.ts
2411
+ var { createWebGL2ContextError: createWebGL2ContextError6 } = Internals6;
2412
+ var compileShader6 = (gl, type, source) => {
2413
+ const shader = gl.createShader(type);
2414
+ if (!shader) {
2415
+ throw new Error("Failed to create WebGL shader");
2416
+ }
2417
+ gl.shaderSource(shader, source);
2418
+ gl.compileShader(shader);
2419
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
2420
+ const log = gl.getShaderInfoLog(shader);
2421
+ gl.deleteShader(shader);
2422
+ throw new Error(`Shader compile failed: ${log ?? "(no log)"}`);
2423
+ }
2424
+ return shader;
2425
+ };
2426
+ var linkProgram6 = (gl, vs, fs) => {
2427
+ const program = gl.createProgram();
2428
+ if (!program) {
2429
+ throw new Error("Failed to create WebGL program");
2430
+ }
2431
+ gl.attachShader(program, vs);
2432
+ gl.attachShader(program, fs);
2433
+ gl.linkProgram(program);
2434
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
2435
+ const log = gl.getProgramInfoLog(program);
2436
+ gl.deleteProgram(program);
2437
+ throw new Error(`Program link failed: ${log ?? "(no log)"}`);
2438
+ }
2439
+ return program;
2440
+ };
2441
+ var createProgram4 = (gl, vertexSource, fragmentSource) => {
2442
+ const vs = compileShader6(gl, gl.VERTEX_SHADER, vertexSource);
2443
+ const fs = compileShader6(gl, gl.FRAGMENT_SHADER, fragmentSource);
2444
+ const program = linkProgram6(gl, vs, fs);
2445
+ gl.deleteShader(vs);
2446
+ gl.deleteShader(fs);
2447
+ return program;
2448
+ };
2449
+ var createRgbaTexture = (gl) => {
2450
+ const texture = gl.createTexture();
2451
+ if (!texture) {
2452
+ throw new Error("Failed to create WebGL texture");
2453
+ }
2454
+ gl.bindTexture(gl.TEXTURE_2D, texture);
2455
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
2456
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
2457
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
2458
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
2459
+ gl.bindTexture(gl.TEXTURE_2D, null);
2460
+ return texture;
2461
+ };
2462
+ var setupCornerPin = (target) => {
2463
+ const gl = target.getContext("webgl2", {
2464
+ premultipliedAlpha: true,
2465
+ alpha: true,
2466
+ preserveDrawingBuffer: true
2467
+ });
2468
+ if (!gl) {
2469
+ throw createWebGL2ContextError6("corner pin effect");
2470
+ }
2471
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
2472
+ const program = createProgram4(gl, CORNER_PIN_VS, CORNER_PIN_FS);
2473
+ const vao = gl.createVertexArray();
2474
+ if (!vao) {
2475
+ throw new Error("Failed to create WebGL vertex array");
2476
+ }
2477
+ gl.bindVertexArray(vao);
2478
+ const data = new Float32Array([
2479
+ -1,
2480
+ -1,
2481
+ 0,
2482
+ 0,
2483
+ 1,
2484
+ -1,
2485
+ 1,
2486
+ 0,
2487
+ -1,
2488
+ 1,
2489
+ 0,
2490
+ 1,
2491
+ 1,
2492
+ 1,
2493
+ 1,
2494
+ 1
2495
+ ]);
2496
+ const vbo = gl.createBuffer();
2497
+ if (!vbo) {
2498
+ throw new Error("Failed to create WebGL buffer");
2499
+ }
2500
+ gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
2501
+ gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
2502
+ gl.enableVertexAttribArray(0);
2503
+ gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 16, 0);
2504
+ gl.enableVertexAttribArray(1);
2505
+ gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 16, 8);
2506
+ gl.bindVertexArray(null);
2507
+ const textureSource = createRgbaTexture(gl);
2508
+ return {
2509
+ gl,
2510
+ program,
2511
+ vao,
2512
+ vbo,
2513
+ textureSource,
2514
+ uniforms: {
2515
+ uSource: gl.getUniformLocation(program, "uSource"),
2516
+ uTopLeft: gl.getUniformLocation(program, "uTopLeft"),
2517
+ uTopRight: gl.getUniformLocation(program, "uTopRight"),
2518
+ uBottomRight: gl.getUniformLocation(program, "uBottomRight"),
2519
+ uBottomLeft: gl.getUniformLocation(program, "uBottomLeft")
2520
+ }
2521
+ };
2522
+ };
2523
+ var cleanupCornerPin = (state) => {
2524
+ const { gl, program, vao, vbo, textureSource } = state;
2525
+ gl.deleteTexture(textureSource);
2526
+ gl.deleteBuffer(vbo);
2527
+ gl.deleteProgram(program);
2528
+ gl.deleteVertexArray(vao);
2529
+ };
2530
+ var drawFullscreenQuad = (state) => {
2531
+ const { gl, vao } = state;
2532
+ gl.bindVertexArray(vao);
2533
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
2534
+ gl.bindVertexArray(null);
2535
+ };
2536
+ var setUvUniform = (gl, location, uv) => {
2537
+ if (!location) {
2538
+ return;
2539
+ }
2540
+ const shaderUv = publicUvToShaderUv(uv);
2541
+ gl.uniform2f(location, shaderUv[0], shaderUv[1]);
2542
+ };
2543
+ var applyCornerPin = ({
2544
+ state,
2545
+ source,
2546
+ width,
2547
+ height,
2548
+ topLeft,
2549
+ topRight,
2550
+ bottomRight,
2551
+ bottomLeft,
2552
+ flipSourceY
2553
+ }) => {
2554
+ const { gl, program, textureSource, uniforms } = state;
2555
+ gl.viewport(0, 0, width, height);
2556
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipSourceY);
2557
+ gl.bindTexture(gl.TEXTURE_2D, textureSource);
2558
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
2559
+ gl.bindTexture(gl.TEXTURE_2D, null);
2560
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
2561
+ gl.clearColor(0, 0, 0, 0);
2562
+ gl.clear(gl.COLOR_BUFFER_BIT);
2563
+ gl.useProgram(program);
2564
+ if (uniforms.uSource)
2565
+ gl.uniform1i(uniforms.uSource, 0);
2566
+ setUvUniform(gl, uniforms.uTopLeft, topLeft);
2567
+ setUvUniform(gl, uniforms.uTopRight, topRight);
2568
+ setUvUniform(gl, uniforms.uBottomRight, bottomRight);
2569
+ setUvUniform(gl, uniforms.uBottomLeft, bottomLeft);
2570
+ gl.activeTexture(gl.TEXTURE0);
2571
+ gl.bindTexture(gl.TEXTURE_2D, textureSource);
2572
+ drawFullscreenQuad(state);
2573
+ gl.bindTexture(gl.TEXTURE_2D, null);
2574
+ gl.useProgram(null);
2575
+ };
2576
+
2577
+ // src/corner-pin/index.ts
2578
+ var { createEffect: createEffect6 } = Internals7;
2579
+ var DEFAULT_TOP_LEFT = [0, 0];
2580
+ var DEFAULT_TOP_RIGHT = [1, 0];
2581
+ var DEFAULT_BOTTOM_RIGHT = [1, 1];
2582
+ var DEFAULT_BOTTOM_LEFT = [0, 1];
2583
+ var cornerSchema = (defaultValue) => ({
2584
+ type: "uv-coordinate",
2585
+ min: -1,
2586
+ max: 2,
2587
+ step: 0.01,
2588
+ default: defaultValue,
2589
+ description: "Corner"
2590
+ });
2591
+ var cornerPinSchema = {
2592
+ topLeft: {
2593
+ ...cornerSchema(DEFAULT_TOP_LEFT),
2594
+ description: "Top left"
2595
+ },
2596
+ topRight: {
2597
+ ...cornerSchema(DEFAULT_TOP_RIGHT),
2598
+ description: "Top right"
2599
+ },
2600
+ bottomRight: {
2601
+ ...cornerSchema(DEFAULT_BOTTOM_RIGHT),
2602
+ description: "Bottom right"
2603
+ },
2604
+ bottomLeft: {
2605
+ ...cornerSchema(DEFAULT_BOTTOM_LEFT),
2606
+ description: "Bottom left"
2607
+ }
2608
+ };
2609
+ var resolve6 = (p) => ({
2610
+ topLeft: [...p.topLeft ?? DEFAULT_TOP_LEFT],
2611
+ topRight: [...p.topRight ?? DEFAULT_TOP_RIGHT],
2612
+ bottomRight: [
2613
+ ...p.bottomRight ?? DEFAULT_BOTTOM_RIGHT
2614
+ ],
2615
+ bottomLeft: [
2616
+ ...p.bottomLeft ?? DEFAULT_BOTTOM_LEFT
2617
+ ]
2618
+ });
2619
+ var assertOptionalUvCoordinate2 = (value, name) => {
2620
+ if (value === undefined) {
2621
+ return;
2622
+ }
2623
+ if (!Array.isArray(value) || value.length !== 2 || value.some((item) => typeof item !== "number" || !Number.isFinite(item))) {
2624
+ throw new TypeError(`"${name}" must be a [number, number] tuple`);
2625
+ }
2626
+ };
2627
+ var validateCornerPinParams = (params) => {
2628
+ assertEffectParamsObject(params, "Corner pin");
2629
+ assertOptionalUvCoordinate2(params.topLeft, "topLeft");
2630
+ assertOptionalUvCoordinate2(params.topRight, "topRight");
2631
+ assertOptionalUvCoordinate2(params.bottomRight, "bottomRight");
2632
+ assertOptionalUvCoordinate2(params.bottomLeft, "bottomLeft");
2633
+ };
2634
+ var cornerPin = createEffect6({
2635
+ type: "dev.remotion.effects.cornerPin",
2636
+ label: "cornerPin()",
2637
+ documentationLink: "https://www.remotion.dev/docs/effects/corner-pin",
2638
+ backend: "webgl2",
2639
+ calculateKey: (params) => {
2640
+ const r = resolve6(params);
2641
+ return `corner-pin-${r.topLeft.join(":")}-${r.topRight.join(":")}-${r.bottomRight.join(":")}-${r.bottomLeft.join(":")}`;
2642
+ },
2643
+ setup: (target) => setupCornerPin(target),
2644
+ apply: ({ source, width, height, params, state, flipSourceY }) => {
2645
+ const r = resolve6(params);
2646
+ applyCornerPin({
2647
+ state,
2648
+ source,
2649
+ width,
2650
+ height,
2651
+ topLeft: r.topLeft,
2652
+ topRight: r.topRight,
2653
+ bottomRight: r.bottomRight,
2654
+ bottomLeft: r.bottomLeft,
2655
+ flipSourceY
2656
+ });
2657
+ },
2658
+ cleanup: (state) => cleanupCornerPin(state),
2659
+ schema: cornerPinSchema,
2660
+ validateParams: validateCornerPinParams
2661
+ });
2312
2662
  export {
2313
2663
  zigzag,
2314
2664
  rings,
2315
2665
  pattern,
2316
2666
  gridlines,
2667
+ cornerPin,
2317
2668
  checkerboard
2318
2669
  };