Skip to content

🎥 Make videos programmatically with React

`@remotion/effects`: Add linear gradient effects (#8660)

Jonny Burgerba67726b4cfe
diff --git a/packages/docs/components/effects-demos/registry.ts b/packages/docs/components/effects-demos/registry.ts
index 3bf50b082d..a9fa0174c9 100644
--- a/packages/docs/components/effects-demos/registry.ts
+++ b/packages/docs/components/effects-demos/registry.ts
@@ -22,6 +22,8 @@ import {halftoneLinearGradient} from '@remotion/effects/halftone-linear-gradient
import {hue} from '@remotion/effects/hue';
import {invert} from '@remotion/effects/invert';
import {lightTrail} from '@remotion/effects/light-trail';
+import {linearGradientTint} from '@remotion/effects/linear-gradient-tint';
+import {linearGradient} from '@remotion/effects/linear-gradient';
import {linearProgressiveBlur} from '@remotion/effects/linear-progressive-blur';
import {lines} from '@remotion/effects/lines';
import {mirror} from '@remotion/effects/mirror';
@@ -78,6 +80,8 @@ import {
EffectsLightTrailPreview,
LIGHT_TRAIL_PREVIEW_PARAMS,
} from '../effects/effects-light-trail-preview';
+import {EffectsLinearGradientTintPreview} from '../effects/effects-linear-gradient-tint-preview';
+import {EffectsLinearGradientPreview} from '../effects/effects-linear-gradient-preview';
import {EffectsLinearProgressiveBlurPreview} from '../effects/effects-linear-progressive-blur-preview';
import {EffectsLinesPreview} from '../effects/effects-lines-preview';
import {EffectsMirrorPreview} from '../effects/effects-mirror-preview';
@@ -263,6 +267,22 @@ export const effectsDemos: EffectsDemoType[] = [
color: '#1ec8ff',
},
},
+ {
+ ...defaults,
+ id: 'effects-linear-gradient',
+ effectName: 'linearGradient',
+ effectImportPath: '@remotion/effects/linear-gradient',
+ comp: EffectsLinearGradientPreview,
+ schema: linearGradient().definition.schema,
+ },
+ {
+ ...defaults,
+ id: 'effects-linear-gradient-tint',
+ effectName: 'linearGradientTint',
+ effectImportPath: '@remotion/effects/linear-gradient-tint',
+ comp: EffectsLinearGradientTintPreview,
+ schema: linearGradientTint().definition.schema,
+ },
{
...defaults,
id: 'effects-thermal-vision',
diff --git a/packages/docs/components/effects/effects-linear-gradient-preview.tsx b/packages/docs/components/effects/effects-linear-gradient-preview.tsx
new file mode 100644
index 0000000000..6f6683d674
--- /dev/null
+++ b/packages/docs/components/effects/effects-linear-gradient-preview.tsx
@@ -0,0 +1,28 @@
+import type {LinearGradientUvCoordinate} from '@remotion/effects/linear-gradient';
+import {linearGradient} from '@remotion/effects/linear-gradient';
+import React from 'react';
+import {Solid, useVideoConfig} from 'remotion';
+
+export const EffectsLinearGradientPreview: React.FC<{
+ readonly start: LinearGradientUvCoordinate;
+ readonly end: LinearGradientUvCoordinate;
+ readonly startColor: string;
+ readonly endColor: string;
+}> = ({start, end, startColor, endColor}) => {
+ const {width, height} = useVideoConfig();
+
+ return (
+ <Solid
+ width={width}
+ height={height}
+ effects={[
+ linearGradient({
+ start,
+ end,
+ startColor,
+ endColor,
+ }),
+ ]}
+ />
+ );
+};
diff --git a/packages/docs/components/effects/effects-linear-gradient-tint-preview.tsx b/packages/docs/components/effects/effects-linear-gradient-tint-preview.tsx
new file mode 100644
index 0000000000..a6eedee3e9
--- /dev/null
+++ b/packages/docs/components/effects/effects-linear-gradient-tint-preview.tsx
@@ -0,0 +1,31 @@
+import type {LinearGradientTintUvCoordinate} from '@remotion/effects/linear-gradient-tint';
+import {linearGradientTint} from '@remotion/effects/linear-gradient-tint';
+import React from 'react';
+import {CanvasImage} from 'remotion';
+import {EFFECTS_PREVIEW_IMAGE_SRC} from './effects-preview-image';
+
+export const EffectsLinearGradientTintPreview: React.FC<{
+ readonly start: LinearGradientTintUvCoordinate;
+ readonly end: LinearGradientTintUvCoordinate;
+ readonly startColor: string;
+ readonly endColor: string;
+ readonly amount: number;
+}> = ({start, end, startColor, endColor, amount}) => {
+ return (
+ <CanvasImage
+ src={EFFECTS_PREVIEW_IMAGE_SRC}
+ width={1280}
+ height={720}
+ fit="cover"
+ effects={[
+ linearGradientTint({
+ start,
+ end,
+ startColor,
+ endColor,
+ amount,
+ }),
+ ]}
+ />
+ );
+};
diff --git a/packages/docs/docs/effects/linear-gradient-tint.mdx b/packages/docs/docs/effects/linear-gradient-tint.mdx
new file mode 100644
index 0000000000..ca035e7c63
--- /dev/null
+++ b/packages/docs/docs/effects/linear-gradient-tint.mdx
@@ -0,0 +1,111 @@
+---
+image: /generated/articles-docs-effects-linear-gradient-tint.png
+slug: /effects/linear-gradient-tint
+title: linearGradientTint()
+sidebar_label: linearGradientTint()
+crumb: '@remotion/effects'
+---
+
+# linearGradientTint()<AvailableFrom v="4.0.483" />
+
+_Part of the [`@remotion/effects`](/docs/effects/api) package._
+
+A tint effect whose color changes across a two-stop linear gradient.
+
+Use it to colorize canvas-based components such as [`<Video>`](/docs/media/video), [`<HtmlInCanvas>`](/docs/remotion/html-in-canvas) and [`<Solid>`](/docs/solid). The tint respects the source's alpha mask, so transparent regions are left untouched.
+
+## Preview
+
+<EffectsDemo type="effects-linear-gradient-tint" />
+
+## Example
+
+```tsx twoslash title="MyComp.tsx"
+import {AbsoluteFill} from 'remotion';
+import {Video} from '@remotion/media';
+import {linearGradientTint} from '@remotion/effects/linear-gradient-tint';
+
+export const MyComp: React.FC = () => {
+ return (
+ <AbsoluteFill>
+ <Video
+ src="https://remotion.media/video.mp4"
+ effects={[
+ linearGradientTint({
+ start: [0, 0.5],
+ end: [1, 0.5],
+ startColor: '#0b84f3',
+ endColor: '#ff5c8a',
+ amount: 0.75,
+ }),
+ ]}
+ />
+ </AbsoluteFill>
+ );
+};
+```
+
+## API
+
+Pass an object with the following properties. You can also call `linearGradientTint()` without arguments.
+
+### `start?`
+
+UV coordinate where `startColor` is reached. Defaults to `[0, 0.5]`.
+
+Pass a `[number, number]` tuple where `[0, 0]` is top-left and `[1, 1]` is bottom-right.
+
+The accepted range in the visual editor is `[-1, 2]` for each coordinate. Values outside `[0, 1]` place the stop outside the visible area.
+
+### `end?`
+
+UV coordinate where `endColor` is reached. Defaults to `[1, 0.5]`.
+
+Pass a `[number, number]` tuple.
+
+### `startColor?`
+
+The tint color at `start`. Defaults to `'#000000'`.
+
+Accepts any CSS color string.
+
+### `endColor?`
+
+The tint color at `end`. Defaults to `'#ffffff'`.
+
+Accepts any CSS color string.
+
+### `amount?`
+
+Blend amount from `0` to `1`. Defaults to `0.5`.
+
+`0` leaves the source unchanged. `1` applies the gradient tint fully.
+
+### `disabled?`
+
+When `true`, the effect is skipped. Defaults to `false`.
+
+## Behavior
+
+The tint color is interpolated between `startColor` and `endColor` along the `start` to `end` line.
+
+Before `start`, the tint is clamped to `startColor`. After `end`, the tint is clamped to `endColor`.
+
+## Difference to `linearGradient()`
+
+`linearGradientTint()` keeps the source pixels and blends their RGB values toward the gradient color. It respects the source alpha mask, so transparent source areas remain transparent.
+
+[`linearGradient()`](/docs/effects/linear-gradient) draws a gradient layer. If the colors have lower opacity, layers behind the gradient become visible.
+
+Use `linearGradientTint()` to colorize existing pixels. Use `linearGradient()` to create a gradient fill.
+
+## Requirements
+
+`linearGradientTint()` uses a WebGL2 backend. During renders, enable WebGL via [`Config.setChromiumOpenGlRenderer('angle')`](/docs/config#setchromiumopenglrenderer). See [Using WebGL during renders](/docs/remotion/html-in-canvas#using-webgl-during-renders).
+
+## See also
+
+- [`linearGradient()`](/docs/effects/linear-gradient)
+- [`tint()`](/docs/effects/tint)
+- [`@remotion/effects`](/docs/effects/api)
+- [Source code for this effect](https://github.com/remotion-dev/remotion/blob/main/packages/effects/src/linear-gradient-tint.ts)
diff --git a/packages/docs/docs/effects/linear-gradient.mdx b/packages/docs/docs/effects/linear-gradient.mdx
new file mode 100644
index 0000000000..a385079f6b
--- /dev/null
+++ b/packages/docs/docs/effects/linear-gradient.mdx
@@ -0,0 +1,103 @@
+---
+image: /generated/articles-docs-effects-linear-gradient.png
+slug: /effects/linear-gradient
+title: linearGradient()
+sidebar_label: linearGradient()
+crumb: '@remotion/effects'
+---
+
+# linearGradient()<AvailableFrom v="4.0.483" />
+
+_Part of the [`@remotion/effects`](/docs/effects/api) package._
+
+A two-stop linear gradient for canvas-based components such as [`<Solid>`](/docs/solid), [`<Video>`](/docs/media/video) and [`<HtmlInCanvas>`](/docs/remotion/html-in-canvas).
+
+Use it to fill a layer with a gradient. The effect replaces the source pixels.
+
+## Preview
+
+<EffectsDemo type="effects-linear-gradient" />
+
+## Example
+
+```tsx twoslash title="MyComp.tsx"
+import {AbsoluteFill, Solid} from 'remotion';
+import {linearGradient} from '@remotion/effects/linear-gradient';
+
+export const MyComp: React.FC = () => {
+ return (
+ <AbsoluteFill>
+ <Solid
+ width={1280}
+ height={720}
+ effects={[
+ linearGradient({
+ start: [0, 0.5],
+ end: [1, 0.5],
+ startColor: '#0b84f3',
+ endColor: '#ff5c8a',
+ }),
+ ]}
+ />
+ </AbsoluteFill>
+ );
+};
+```
+
+## API
+
+Pass an object with the following properties. You can also call `linearGradient()` without arguments.
+
+### `start?`
+
+UV coordinate where `startColor` is reached. Defaults to `[0, 0.5]`.
+
+Pass a `[number, number]` tuple where `[0, 0]` is top-left and `[1, 1]` is bottom-right.
+
+The accepted range in the visual editor is `[-1, 2]` for each coordinate. Values outside `[0, 1]` place the stop outside the visible area.
+
+### `end?`
+
+UV coordinate where `endColor` is reached. Defaults to `[1, 0.5]`.
+
+Pass a `[number, number]` tuple.
+
+### `startColor?`
+
+The color at `start`. Defaults to `'#000000'`.
+
+Accepts any CSS color string.
+
+### `endColor?`
+
+The color at `end`. Defaults to `'#ffffff'`.
+
+Accepts any CSS color string.
+
+### `disabled?`
+
+When `true`, the effect is skipped. Defaults to `false`.
+
+## Behavior
+
+The color is interpolated between `startColor` and `endColor` along the `start` to `end` line.
+
+Before `start`, the color is clamped to `startColor`. After `end`, the color is clamped to `endColor`.
+
+## Difference to `linearGradientTint()`
+
+`linearGradient()` draws a gradient layer. If the colors have lower opacity, layers behind the gradient become visible.
+
+[`linearGradientTint()`](/docs/effects/linear-gradient-tint) keeps the source pixels and blends their RGB values toward the gradient color. It respects the source alpha mask, so transparent source areas remain transparent.
+
+Use `linearGradient()` to create a gradient fill. Use `linearGradientTint()` to colorize existing pixels.
+
+## Requirements
+
+`linearGradient()` uses a WebGL2 backend. During renders, enable WebGL via [`Config.setChromiumOpenGlRenderer('angle')`](/docs/config#setchromiumopenglrenderer). See [Using WebGL during renders](/docs/remotion/html-in-canvas#using-webgl-during-renders).
+
+## See also
+
+- [`linearGradientTint()`](/docs/effects/linear-gradient-tint)
+- [`@remotion/effects`](/docs/effects/api)
+- [Source code for this effect](https://github.com/remotion-dev/remotion/blob/main/packages/effects/src/linear-gradient.ts)
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index 79890efe9e..81b224baed 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -296,6 +296,8 @@ const sidebars: SidebarsConfig = {
'effects/halftone-linear-gradient',
'effects/hue',
'effects/invert',
+ 'effects/linear-gradient',
+ 'effects/linear-gradient-tint',
'effects/linear-progressive-blur',
'effects/light-trail',
'effects/lines',
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 050ad2a841..f7cabb47a5 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -1961,6 +1961,24 @@ export const articles = [
noAi: false,
slug: 'effects/light-trail',
},
+ {
+ id: 'effects/linear-gradient-tint',
+ title: 'linearGradientTint()',
+ relativePath: 'docs/effects/linear-gradient-tint.mdx',
+ compId: 'articles-docs-effects-linear-gradient-tint',
+ crumb: '@remotion/effects',
+ noAi: false,
+ slug: 'effects/linear-gradient-tint',
+ },
+ {
+ id: 'effects/linear-gradient',
+ title: 'linearGradient()',
+ relativePath: 'docs/effects/linear-gradient.mdx',
+ compId: 'articles-docs-effects-linear-gradient',
+ crumb: '@remotion/effects',
+ noAi: false,
+ slug: 'effects/linear-gradient',
+ },
{
id: 'effects/linear-progressive-blur',
title: 'linearProgressiveBlur()',
diff --git a/packages/docs/src/remotion/Root.tsx b/packages/docs/src/remotion/Root.tsx
index 6ef1382f95..51a2c78649 100644
--- a/packages/docs/src/remotion/Root.tsx
+++ b/packages/docs/src/remotion/Root.tsx
@@ -31,6 +31,8 @@ import {
LIGHT_TRAIL_PREVIEW_PARAMS,
LightTrailTextSource,
} from '../../components/effects/effects-light-trail-preview';
+import {EffectsLinearGradientPreview} from '../../components/effects/effects-linear-gradient-preview';
+import {EffectsLinearGradientTintPreview} from '../../components/effects/effects-linear-gradient-tint-preview';
import {EffectsLinearProgressiveBlurPreview} from '../../components/effects/effects-linear-progressive-blur-preview';
import {EffectsLinesPreview} from '../../components/effects/effects-lines-preview';
import {EffectsMirrorPreview} from '../../components/effects/effects-mirror-preview';
@@ -387,6 +389,31 @@ export const RemotionRoot: React.FC = () => {
endBlur: 50,
}}
/>
+ <Still
+ id="effects-linear-gradient-preview"
+ component={EffectsLinearGradientPreview}
+ width={1280}
+ height={720}
+ defaultProps={{
+ start: [0, 0.5],
+ end: [1, 0.5],
+ startColor: '#0b84f3',
+ endColor: '#ff5c8a',
+ }}
+ />
+ <Still
+ id="effects-linear-gradient-tint-preview"
+ component={EffectsLinearGradientTintPreview}
+ width={1280}
+ height={720}
+ defaultProps={{
+ start: [0, 0.5],
+ end: [1, 0.5],
+ startColor: '#0b84f3',
+ endColor: '#ff5c8a',
+ amount: 0.75,
+ }}
+ />
<Still
id="effects-radial-progressive-blur-preview"
component={EffectsRadialProgressiveBlurPreview}
diff --git a/packages/docs/static/generated/articles-docs-effects-linear-gradient-tint.png b/packages/docs/static/generated/articles-docs-effects-linear-gradient-tint.png
new file mode 100644
index 0000000000..af84670a12
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-effects-linear-gradient-tint.png differ
diff --git a/packages/docs/static/generated/articles-docs-effects-linear-gradient.png b/packages/docs/static/generated/articles-docs-effects-linear-gradient.png
new file mode 100644
index 0000000000..c053fbf10d
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-effects-linear-gradient.png differ
diff --git a/packages/docs/static/img/effects-linear-gradient-preview.png b/packages/docs/static/img/effects-linear-gradient-preview.png
new file mode 100644
index 0000000000..8398ce5fc1
Binary files /dev/null and b/packages/docs/static/img/effects-linear-gradient-preview.png differ
diff --git a/packages/docs/static/img/effects-linear-gradient-tint-preview.png b/packages/docs/static/img/effects-linear-gradient-tint-preview.png
new file mode 100644
index 0000000000..b4c7214a0e
Binary files /dev/null and b/packages/docs/static/img/effects-linear-gradient-tint-preview.png differ
diff --git a/packages/effects/bundle.ts b/packages/effects/bundle.ts
index 59cd74120f..1284381fd3 100644
--- a/packages/effects/bundle.ts
+++ b/packages/effects/bundle.ts
@@ -33,6 +33,8 @@ const effectEntrypoints = [
'src/pixelate.ts',
'src/invert.ts',
'src/lines.ts',
+ 'src/linear-gradient.ts',
+ 'src/linear-gradient-tint.ts',
'src/linear-progressive-blur.ts',
'src/light-trail.ts',
'src/mirror.ts',
diff --git a/packages/effects/package.json b/packages/effects/package.json
index 398912392d..c3822afada 100644
--- a/packages/effects/package.json
+++ b/packages/effects/package.json
@@ -159,6 +159,16 @@
"module": "./dist/esm/lines.mjs",
"import": "./dist/esm/lines.mjs"
},
+ "./linear-gradient": {
+ "types": "./dist/linear-gradient.d.ts",
+ "module": "./dist/esm/linear-gradient.mjs",
+ "import": "./dist/esm/linear-gradient.mjs"
+ },
+ "./linear-gradient-tint": {
+ "types": "./dist/linear-gradient-tint.d.ts",
+ "module": "./dist/esm/linear-gradient-tint.mjs",
+ "import": "./dist/esm/linear-gradient-tint.mjs"
+ },
"./linear-progressive-blur": {
"types": "./dist/linear-progressive-blur.d.ts",
"module": "./dist/esm/linear-progressive-blur.mjs",
@@ -363,6 +373,12 @@
"lines": [
"dist/lines.d.ts"
],
+ "linear-gradient": [
+ "dist/linear-gradient.d.ts"
+ ],
+ "linear-gradient-tint": [
+ "dist/linear-gradient-tint.d.ts"
+ ],
"linear-progressive-blur": [
"dist/linear-progressive-blur.d.ts"
],
diff --git a/packages/effects/src/index.ts b/packages/effects/src/index.ts
index 99285ac5a6..c41fb6179b 100644
--- a/packages/effects/src/index.ts
+++ b/packages/effects/src/index.ts
@@ -3,6 +3,16 @@ export {pattern, type PatternOrigin, type PatternParams} from './pattern.js';
export {rings, type RingsCenter, type RingsParams} from './rings.js';
export {gridlines, type GridlinesParams} from './gridlines.js';
export {zigzag, type ZigzagDirection, type ZigzagParams} from './zigzag.js';
+export {
+ linearGradient,
+ type LinearGradientParams,
+ type LinearGradientUvCoordinate,
+} from './linear-gradient.js';
+export {
+ linearGradientTint,
+ type LinearGradientTintParams,
+ type LinearGradientTintUvCoordinate,
+} from './linear-gradient-tint.js';
export {
cornerPin,
type CornerPinParams,
diff --git a/packages/effects/src/linear-gradient-tint.ts b/packages/effects/src/linear-gradient-tint.ts
new file mode 100644
index 0000000000..c1a60db97b
--- /dev/null
+++ b/packages/effects/src/linear-gradient-tint.ts
@@ -0,0 +1,444 @@
+import type {InteractivitySchema} from 'remotion';
+import {Internals} from 'remotion';
+import {
+ assertOptionalFiniteNumber,
+ parseColorRgba,
+ type ParsedColorRgba,
+ validateUnitInterval,
+} from './color-utils.js';
+import {
+ assertEffectParamsObject,
+ assertOptionalColor,
+} from './validate-effect-param.js';
+
+const {createEffect, createWebGL2ContextError} = Internals;
+
+const DEFAULT_START = [0, 0.5] as const;
+const DEFAULT_END = [1, 0.5] as const;
+const DEFAULT_START_COLOR = '#000000' as const;
+const DEFAULT_END_COLOR = '#ffffff' as const;
+const DEFAULT_AMOUNT = 0.5 as const;
+
+export type LinearGradientTintUvCoordinate = readonly [number, number];
+
+export type LinearGradientTintParams = {
+ /**
+ * UV coordinate where `startColor` is reached. Defaults to `[0, 0.5]`.
+ */
+ readonly start?: LinearGradientTintUvCoordinate;
+ /**
+ * UV coordinate where `endColor` is reached. Defaults to `[1, 0.5]`.
+ */
+ readonly end?: LinearGradientTintUvCoordinate;
+ /**
+ * Tint color at `start`. Defaults to black.
+ */
+ readonly startColor?: string;
+ /**
+ * Tint color at `end`. Defaults to white.
+ */
+ readonly endColor?: string;
+ /**
+ * Tint blend amount from `0` to `1`. Defaults to `0.5`.
+ */
+ readonly amount?: number;
+};
+
+type LinearGradientTintResolved = {
+ readonly start: LinearGradientTintUvCoordinate;
+ readonly end: LinearGradientTintUvCoordinate;
+ readonly startColor: string;
+ readonly endColor: string;
+ readonly amount: number;
+};
+
+type LinearGradientTintState = {
+ readonly gl: WebGL2RenderingContext;
+ readonly program: WebGLProgram;
+ readonly vao: WebGLVertexArrayObject;
+ readonly vbo: WebGLBuffer;
+ readonly textureSource: WebGLTexture;
+ readonly uniforms: {
+ readonly uSource: WebGLUniformLocation | null;
+ readonly uStart: WebGLUniformLocation | null;
+ readonly uEnd: WebGLUniformLocation | null;
+ readonly uStartColor: WebGLUniformLocation | null;
+ readonly uEndColor: WebGLUniformLocation | null;
+ readonly uAmount: WebGLUniformLocation | null;
+ };
+ readonly colorCtx: CanvasRenderingContext2D;
+ cachedStartColor: string;
+ cachedStartColorRgba: ParsedColorRgba;
+ cachedEndColor: string;
+ cachedEndColorRgba: ParsedColorRgba;
+};
+
+const linearGradientTintSchema = {
+ start: {
+ type: 'uv-coordinate',
+ min: -1,
+ max: 2,
+ step: 0.01,
+ default: DEFAULT_START,
+ description: 'Start',
+ visual: {
+ type: 'line',
+ to: 'end',
+ },
+ },
+ end: {
+ type: 'uv-coordinate',
+ min: -1,
+ max: 2,
+ step: 0.01,
+ default: DEFAULT_END,
+ description: 'End',
+ },
+ startColor: {
+ type: 'color',
+ default: DEFAULT_START_COLOR,
+ description: 'Start color',
+ },
+ endColor: {
+ type: 'color',
+ default: DEFAULT_END_COLOR,
+ description: 'End color',
+ },
+ amount: {
+ type: 'number',
+ min: 0,
+ max: 1,
+ step: 0.01,
+ default: DEFAULT_AMOUNT,
+ description: 'Amount',
+ hiddenFromList: false,
+ },
+} as const satisfies InteractivitySchema;
+
+const resolve = (p: LinearGradientTintParams): LinearGradientTintResolved => ({
+ start: [...(p.start ?? DEFAULT_START)] as LinearGradientTintUvCoordinate,
+ end: [...(p.end ?? DEFAULT_END)] as LinearGradientTintUvCoordinate,
+ startColor: p.startColor ?? DEFAULT_START_COLOR,
+ endColor: p.endColor ?? DEFAULT_END_COLOR,
+ amount: p.amount ?? DEFAULT_AMOUNT,
+});
+
+const assertOptionalUvCoordinate = (value: unknown, name: string): void => {
+ if (value === undefined) {
+ return;
+ }
+
+ if (
+ !Array.isArray(value) ||
+ value.length !== 2 ||
+ value.some((item) => typeof item !== 'number' || !Number.isFinite(item))
+ ) {
+ throw new TypeError(`"${name}" must be a [number, number] tuple`);
+ }
+};
+
+const validateLinearGradientTintParams = (
+ params: LinearGradientTintParams,
+): void => {
+ assertEffectParamsObject(params, 'Linear gradient tint');
+ assertOptionalUvCoordinate(params.start, 'start');
+ assertOptionalUvCoordinate(params.end, 'end');
+ assertOptionalColor(params.startColor, 'startColor');
+ assertOptionalColor(params.endColor, 'endColor');
+ assertOptionalFiniteNumber(params.amount, 'amount');
+ validateUnitInterval(resolve(params).amount, 'amount');
+};
+
+const VERTEX_SHADER = /* glsl */ `#version 300 es
+in vec2 aPos;
+in vec2 aUv;
+out vec2 vUv;
+
+void main() {
+ vUv = aUv;
+ gl_Position = vec4(aPos, 0.0, 1.0);
+}
+`;
+
+const FRAGMENT_SHADER = /* glsl */ `#version 300 es
+precision highp float;
+
+in vec2 vUv;
+out vec4 fragColor;
+
+uniform sampler2D uSource;
+uniform vec2 uStart;
+uniform vec2 uEnd;
+uniform vec4 uStartColor;
+uniform vec4 uEndColor;
+uniform float uAmount;
+
+float gradientProgress(vec2 uv) {
+ vec2 gradient = uEnd - uStart;
+ float gradientLengthSq = dot(gradient, gradient);
+ if (gradientLengthSq <= 0.0000001) {
+ return 0.0;
+ }
+
+ return clamp(dot(uv - uStart, gradient) / gradientLengthSq, 0.0, 1.0);
+}
+
+void main() {
+ vec4 texColor = texture(uSource, vUv);
+ float alpha = texColor.a;
+
+ if (alpha <= 0.001) {
+ fragColor = vec4(0.0);
+ return;
+ }
+
+ vec2 publicUv = vec2(vUv.x, 1.0 - vUv.y);
+ vec4 tintColor = mix(uStartColor, uEndColor, gradientProgress(publicUv));
+ vec3 sourceRgb = texColor.rgb / alpha;
+ vec3 blended = mix(sourceRgb, tintColor.rgb, uAmount * tintColor.a);
+
+ fragColor = vec4(blended * alpha, alpha);
+}
+`;
+
+const compileShader = (
+ gl: WebGL2RenderingContext,
+ type: number,
+ source: string,
+): WebGLShader => {
+ const shader = gl.createShader(type);
+ if (!shader) {
+ throw new Error('Failed to create WebGL shader');
+ }
+
+ gl.shaderSource(shader, source);
+ gl.compileShader(shader);
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
+ const log = gl.getShaderInfoLog(shader);
+ gl.deleteShader(shader);
+ throw new Error(
+ `Linear gradient tint shader compile failed: ${log ?? '(no log)'}`,
+ );
+ }
+
+ return shader;
+};
+
+const createProgram = (gl: WebGL2RenderingContext): WebGLProgram => {
+ const vs = compileShader(gl, gl.VERTEX_SHADER, VERTEX_SHADER);
+ const fs = compileShader(gl, gl.FRAGMENT_SHADER, FRAGMENT_SHADER);
+ const program = gl.createProgram();
+ if (!program) {
+ throw new Error('Failed to create WebGL program');
+ }
+
+ gl.attachShader(program, vs);
+ gl.attachShader(program, fs);
+ gl.linkProgram(program);
+ gl.deleteShader(vs);
+ gl.deleteShader(fs);
+
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
+ const log = gl.getProgramInfoLog(program);
+ gl.deleteProgram(program);
+ throw new Error(
+ `Linear gradient tint program link failed: ${log ?? '(no log)'}`,
+ );
+ }
+
+ return program;
+};
+
+const createRgbaTexture = (gl: WebGL2RenderingContext): WebGLTexture => {
+ const texture = gl.createTexture();
+ if (!texture) {
+ throw new Error('Failed to create WebGL texture');
+ }
+
+ gl.bindTexture(gl.TEXTURE_2D, texture);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
+ gl.bindTexture(gl.TEXTURE_2D, null);
+ return texture;
+};
+
+const setupLinearGradientTint = (
+ target: HTMLCanvasElement,
+): LinearGradientTintState => {
+ const gl = target.getContext('webgl2', {
+ premultipliedAlpha: true,
+ alpha: true,
+ preserveDrawingBuffer: true,
+ });
+ if (!gl) {
+ throw createWebGL2ContextError('linear gradient tint effect');
+ }
+
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
+
+ const program = createProgram(gl);
+
+ const vao = gl.createVertexArray();
+ if (!vao) {
+ throw new Error('Failed to create WebGL vertex array');
+ }
+
+ gl.bindVertexArray(vao);
+
+ const data = new Float32Array([
+ -1, -1, 0, 0, 1, -1, 1, 0, -1, 1, 0, 1, 1, 1, 1, 1,
+ ]);
+
+ const vbo = gl.createBuffer();
+ if (!vbo) {
+ throw new Error('Failed to create WebGL buffer');
+ }
+
+ gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
+ gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
+
+ const aPos = gl.getAttribLocation(program, 'aPos');
+ const aUv = gl.getAttribLocation(program, 'aUv');
+ gl.enableVertexAttribArray(aPos);
+ gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 16, 0);
+ gl.enableVertexAttribArray(aUv);
+ gl.vertexAttribPointer(aUv, 2, gl.FLOAT, false, 16, 8);
+
+ gl.bindVertexArray(null);
+
+ const textureSource = createRgbaTexture(gl);
+
+ const colorCanvas = document.createElement('canvas');
+ colorCanvas.width = 1;
+ colorCanvas.height = 1;
+ const colorCtx = colorCanvas.getContext('2d', {willReadFrequently: true});
+ if (!colorCtx) {
+ throw new Error('Failed to acquire 2D context for color parsing');
+ }
+
+ return {
+ gl,
+ program,
+ vao,
+ vbo,
+ textureSource,
+ uniforms: {
+ uSource: gl.getUniformLocation(program, 'uSource'),
+ uStart: gl.getUniformLocation(program, 'uStart'),
+ uEnd: gl.getUniformLocation(program, 'uEnd'),
+ uStartColor: gl.getUniformLocation(program, 'uStartColor'),
+ uEndColor: gl.getUniformLocation(program, 'uEndColor'),
+ uAmount: gl.getUniformLocation(program, 'uAmount'),
+ },
+ colorCtx,
+ cachedStartColor: '',
+ cachedStartColorRgba: [0, 0, 0, 255],
+ cachedEndColor: '',
+ cachedEndColorRgba: [255, 255, 255, 255],
+ };
+};
+
+const normalizedRgba = (
+ color: ParsedColorRgba,
+): readonly [number, number, number, number] => {
+ return [color[0] / 255, color[1] / 255, color[2] / 255, color[3] / 255];
+};
+
+const getParsedColors = (
+ state: LinearGradientTintState,
+ resolved: LinearGradientTintResolved,
+): {
+ start: ParsedColorRgba;
+ end: ParsedColorRgba;
+} => {
+ if (state.cachedStartColor !== resolved.startColor) {
+ state.cachedStartColor = resolved.startColor;
+ state.cachedStartColorRgba = parseColorRgba(
+ state.colorCtx,
+ resolved.startColor,
+ );
+ }
+
+ if (state.cachedEndColor !== resolved.endColor) {
+ state.cachedEndColor = resolved.endColor;
+ state.cachedEndColorRgba = parseColorRgba(
+ state.colorCtx,
+ resolved.endColor,
+ );
+ }
+
+ return {
+ start: state.cachedStartColorRgba,
+ end: state.cachedEndColorRgba,
+ };
+};
+
+export const linearGradientTint = createEffect<
+ LinearGradientTintParams,
+ LinearGradientTintState
+>({
+ type: 'dev.remotion.effects.linearGradientTint',
+ label: 'linearGradientTint()',
+ documentationLink:
+ 'https://www.remotion.dev/docs/effects/linear-gradient-tint',
+ backend: 'webgl2',
+ calculateKey: (params) => {
+ const r = resolve(params);
+ return `linear-gradient-tint-${r.start.join(':')}-${r.end.join(':')}-${r.startColor}-${r.endColor}-${r.amount}`;
+ },
+ setup: (target) => setupLinearGradientTint(target),
+ apply: ({source, width, height, params, state, flipSourceY}) => {
+ const r = resolve(params);
+ const {start, end} = getParsedColors(state, r);
+ const [sr, sg, sb, sa] = normalizedRgba(start);
+ const [er, eg, eb, ea] = normalizedRgba(end);
+ const {gl, program, textureSource, uniforms, vao} = state;
+
+ gl.viewport(0, 0, width, height);
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
+ gl.clearColor(0, 0, 0, 0);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+
+ gl.activeTexture(gl.TEXTURE0);
+ gl.bindTexture(gl.TEXTURE_2D, textureSource);
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipSourceY);
+ gl.texImage2D(
+ gl.TEXTURE_2D,
+ 0,
+ gl.RGBA,
+ gl.RGBA,
+ gl.UNSIGNED_BYTE,
+ source as TexImageSource,
+ );
+
+ gl.useProgram(program);
+ if (uniforms.uSource) gl.uniform1i(uniforms.uSource, 0);
+ if (uniforms.uStart) gl.uniform2f(uniforms.uStart, r.start[0], r.start[1]);
+ if (uniforms.uEnd) gl.uniform2f(uniforms.uEnd, r.end[0], r.end[1]);
+ if (uniforms.uStartColor) {
+ gl.uniform4f(uniforms.uStartColor, sr, sg, sb, sa);
+ }
+
+ if (uniforms.uEndColor) {
+ gl.uniform4f(uniforms.uEndColor, er, eg, eb, ea);
+ }
+
+ if (uniforms.uAmount) gl.uniform1f(uniforms.uAmount, r.amount);
+
+ gl.bindVertexArray(vao);
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
+ gl.bindVertexArray(null);
+ gl.bindTexture(gl.TEXTURE_2D, null);
+ gl.useProgram(null);
+ },
+ cleanup: ({gl, program, vao, vbo, textureSource}) => {
+ gl.deleteTexture(textureSource);
+ gl.deleteBuffer(vbo);
+ gl.deleteProgram(program);
+ gl.deleteVertexArray(vao);
+ },
+ schema: linearGradientTintSchema,
+ validateParams: validateLinearGradientTintParams,
+});
diff --git a/packages/effects/src/linear-gradient.ts b/packages/effects/src/linear-gradient.ts
new file mode 100644
index 0000000000..8d986c5ad3
--- /dev/null
+++ b/packages/effects/src/linear-gradient.ts
@@ -0,0 +1,363 @@
+import type {InteractivitySchema} from 'remotion';
+import {Internals} from 'remotion';
+import {parseColorRgba, type ParsedColorRgba} from './color-utils.js';
+import {
+ assertEffectParamsObject,
+ assertOptionalColor,
+} from './validate-effect-param.js';
+
+const {createEffect, createWebGL2ContextError} = Internals;
+
+const DEFAULT_START = [0, 0.5] as const;
+const DEFAULT_END = [1, 0.5] as const;
+const DEFAULT_START_COLOR = '#000000' as const;
+const DEFAULT_END_COLOR = '#ffffff' as const;
+
+export type LinearGradientUvCoordinate = readonly [number, number];
+
+export type LinearGradientParams = {
+ /**
+ * UV coordinate where `startColor` is reached. Defaults to `[0, 0.5]`.
+ */
+ readonly start?: LinearGradientUvCoordinate;
+ /**
+ * UV coordinate where `endColor` is reached. Defaults to `[1, 0.5]`.
+ */
+ readonly end?: LinearGradientUvCoordinate;
+ /**
+ * Color at `start`. Defaults to black.
+ */
+ readonly startColor?: string;
+ /**
+ * Color at `end`. Defaults to white.
+ */
+ readonly endColor?: string;
+};
+
+type LinearGradientResolved = {
+ readonly start: LinearGradientUvCoordinate;
+ readonly end: LinearGradientUvCoordinate;
+ readonly startColor: string;
+ readonly endColor: string;
+};
+
+type LinearGradientState = {
+ readonly gl: WebGL2RenderingContext;
+ readonly program: WebGLProgram;
+ readonly vao: WebGLVertexArrayObject;
+ readonly vbo: WebGLBuffer;
+ readonly uniforms: {
+ readonly uStart: WebGLUniformLocation | null;
+ readonly uEnd: WebGLUniformLocation | null;
+ readonly uStartColor: WebGLUniformLocation | null;
+ readonly uEndColor: WebGLUniformLocation | null;
+ };
+ readonly colorCtx: CanvasRenderingContext2D;
+ cachedStartColor: string;
+ cachedStartColorRgba: ParsedColorRgba;
+ cachedEndColor: string;
+ cachedEndColorRgba: ParsedColorRgba;
+};
+
+const linearGradientSchema = {
+ start: {
+ type: 'uv-coordinate',
+ min: -1,
+ max: 2,
+ step: 0.01,
+ default: DEFAULT_START,
+ description: 'Start',
+ visual: {
+ type: 'line',
+ to: 'end',
+ },
+ },
+ end: {
+ type: 'uv-coordinate',
+ min: -1,
+ max: 2,
+ step: 0.01,
+ default: DEFAULT_END,
+ description: 'End',
+ },
+ startColor: {
+ type: 'color',
+ default: DEFAULT_START_COLOR,
+ description: 'Start color',
+ },
+ endColor: {
+ type: 'color',
+ default: DEFAULT_END_COLOR,
+ description: 'End color',
+ },
+} as const satisfies InteractivitySchema;
+
+const resolve = (p: LinearGradientParams): LinearGradientResolved => ({
+ start: [...(p.start ?? DEFAULT_START)] as LinearGradientUvCoordinate,
+ end: [...(p.end ?? DEFAULT_END)] as LinearGradientUvCoordinate,
+ startColor: p.startColor ?? DEFAULT_START_COLOR,
+ endColor: p.endColor ?? DEFAULT_END_COLOR,
+});
+
+const assertOptionalUvCoordinate = (value: unknown, name: string): void => {
+ if (value === undefined) {
+ return;
+ }
+
+ if (
+ !Array.isArray(value) ||
+ value.length !== 2 ||
+ value.some((item) => typeof item !== 'number' || !Number.isFinite(item))
+ ) {
+ throw new TypeError(`"${name}" must be a [number, number] tuple`);
+ }
+};
+
+const validateLinearGradientParams = (params: LinearGradientParams): void => {
+ assertEffectParamsObject(params, 'Linear gradient');
+ assertOptionalUvCoordinate(params.start, 'start');
+ assertOptionalUvCoordinate(params.end, 'end');
+ assertOptionalColor(params.startColor, 'startColor');
+ assertOptionalColor(params.endColor, 'endColor');
+};
+
+const VERTEX_SHADER = /* glsl */ `#version 300 es
+in vec2 aPos;
+in vec2 aUv;
+out vec2 vUv;
+
+void main() {
+ vUv = aUv;
+ gl_Position = vec4(aPos, 0.0, 1.0);
+}
+`;
+
+const FRAGMENT_SHADER = /* glsl */ `#version 300 es
+precision highp float;
+
+in vec2 vUv;
+out vec4 fragColor;
+
+uniform vec2 uStart;
+uniform vec2 uEnd;
+uniform vec4 uStartColor;
+uniform vec4 uEndColor;
+
+float gradientProgress(vec2 uv) {
+ vec2 gradient = uEnd - uStart;
+ float gradientLengthSq = dot(gradient, gradient);
+ if (gradientLengthSq <= 0.0000001) {
+ return 0.0;
+ }
+
+ return clamp(dot(uv - uStart, gradient) / gradientLengthSq, 0.0, 1.0);
+}
+
+void main() {
+ vec2 publicUv = vec2(vUv.x, 1.0 - vUv.y);
+ vec4 color = mix(uStartColor, uEndColor, gradientProgress(publicUv));
+ fragColor = vec4(color.rgb * color.a, color.a);
+}
+`;
+
+const compileShader = (
+ gl: WebGL2RenderingContext,
+ type: number,
+ source: string,
+): WebGLShader => {
+ const shader = gl.createShader(type);
+ if (!shader) {
+ throw new Error('Failed to create WebGL shader');
+ }
+
+ gl.shaderSource(shader, source);
+ gl.compileShader(shader);
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
+ const log = gl.getShaderInfoLog(shader);
+ gl.deleteShader(shader);
+ throw new Error(
+ `Linear gradient shader compile failed: ${log ?? '(no log)'}`,
+ );
+ }
+
+ return shader;
+};
+
+const createProgram = (gl: WebGL2RenderingContext): WebGLProgram => {
+ const vs = compileShader(gl, gl.VERTEX_SHADER, VERTEX_SHADER);
+ const fs = compileShader(gl, gl.FRAGMENT_SHADER, FRAGMENT_SHADER);
+ const program = gl.createProgram();
+ if (!program) {
+ throw new Error('Failed to create WebGL program');
+ }
+
+ gl.attachShader(program, vs);
+ gl.attachShader(program, fs);
+ gl.linkProgram(program);
+ gl.deleteShader(vs);
+ gl.deleteShader(fs);
+
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
+ const log = gl.getProgramInfoLog(program);
+ gl.deleteProgram(program);
+ throw new Error(
+ `Linear gradient program link failed: ${log ?? '(no log)'}`,
+ );
+ }
+
+ return program;
+};
+
+const setupLinearGradient = (
+ target: HTMLCanvasElement,
+): LinearGradientState => {
+ const gl = target.getContext('webgl2', {
+ premultipliedAlpha: true,
+ alpha: true,
+ preserveDrawingBuffer: true,
+ });
+ if (!gl) {
+ throw createWebGL2ContextError('linear gradient effect');
+ }
+
+ const program = createProgram(gl);
+
+ const vao = gl.createVertexArray();
+ if (!vao) {
+ throw new Error('Failed to create WebGL vertex array');
+ }
+
+ gl.bindVertexArray(vao);
+
+ const data = new Float32Array([
+ -1, -1, 0, 0, 1, -1, 1, 0, -1, 1, 0, 1, 1, 1, 1, 1,
+ ]);
+
+ const vbo = gl.createBuffer();
+ if (!vbo) {
+ throw new Error('Failed to create WebGL buffer');
+ }
+
+ gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
+ gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
+
+ const aPos = gl.getAttribLocation(program, 'aPos');
+ const aUv = gl.getAttribLocation(program, 'aUv');
+ gl.enableVertexAttribArray(aPos);
+ gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 16, 0);
+ gl.enableVertexAttribArray(aUv);
+ gl.vertexAttribPointer(aUv, 2, gl.FLOAT, false, 16, 8);
+
+ gl.bindVertexArray(null);
+
+ const colorCanvas = document.createElement('canvas');
+ colorCanvas.width = 1;
+ colorCanvas.height = 1;
+ const colorCtx = colorCanvas.getContext('2d', {willReadFrequently: true});
+ if (!colorCtx) {
+ throw new Error('Failed to acquire 2D context for color parsing');
+ }
+
+ return {
+ gl,
+ program,
+ vao,
+ vbo,
+ uniforms: {
+ uStart: gl.getUniformLocation(program, 'uStart'),
+ uEnd: gl.getUniformLocation(program, 'uEnd'),
+ uStartColor: gl.getUniformLocation(program, 'uStartColor'),
+ uEndColor: gl.getUniformLocation(program, 'uEndColor'),
+ },
+ colorCtx,
+ cachedStartColor: '',
+ cachedStartColorRgba: [0, 0, 0, 255],
+ cachedEndColor: '',
+ cachedEndColorRgba: [255, 255, 255, 255],
+ };
+};
+
+const normalizedRgba = (
+ color: ParsedColorRgba,
+): readonly [number, number, number, number] => {
+ return [color[0] / 255, color[1] / 255, color[2] / 255, color[3] / 255];
+};
+
+const getParsedColors = (
+ state: LinearGradientState,
+ resolved: LinearGradientResolved,
+): {
+ start: ParsedColorRgba;
+ end: ParsedColorRgba;
+} => {
+ if (state.cachedStartColor !== resolved.startColor) {
+ state.cachedStartColor = resolved.startColor;
+ state.cachedStartColorRgba = parseColorRgba(
+ state.colorCtx,
+ resolved.startColor,
+ );
+ }
+
+ if (state.cachedEndColor !== resolved.endColor) {
+ state.cachedEndColor = resolved.endColor;
+ state.cachedEndColorRgba = parseColorRgba(
+ state.colorCtx,
+ resolved.endColor,
+ );
+ }
+
+ return {
+ start: state.cachedStartColorRgba,
+ end: state.cachedEndColorRgba,
+ };
+};
+
+export const linearGradient = createEffect<
+ LinearGradientParams,
+ LinearGradientState
+>({
+ type: 'dev.remotion.effects.linearGradient',
+ label: 'linearGradient()',
+ documentationLink: 'https://www.remotion.dev/docs/effects/linear-gradient',
+ backend: 'webgl2',
+ calculateKey: (params) => {
+ const r = resolve(params);
+ return `linear-gradient-${r.start.join(':')}-${r.end.join(':')}-${r.startColor}-${r.endColor}`;
+ },
+ setup: (target) => setupLinearGradient(target),
+ apply: ({width, height, params, state}) => {
+ const r = resolve(params);
+ const {start, end} = getParsedColors(state, r);
+ const [sr, sg, sb, sa] = normalizedRgba(start);
+ const [er, eg, eb, ea] = normalizedRgba(end);
+ const {gl, program, uniforms, vao} = state;
+
+ gl.viewport(0, 0, width, height);
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
+ gl.clearColor(0, 0, 0, 0);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+ gl.useProgram(program);
+
+ if (uniforms.uStart) gl.uniform2f(uniforms.uStart, r.start[0], r.start[1]);
+ if (uniforms.uEnd) gl.uniform2f(uniforms.uEnd, r.end[0], r.end[1]);
+ if (uniforms.uStartColor) {
+ gl.uniform4f(uniforms.uStartColor, sr, sg, sb, sa);
+ }
+
+ if (uniforms.uEndColor) {
+ gl.uniform4f(uniforms.uEndColor, er, eg, eb, ea);
+ }
+
+ gl.bindVertexArray(vao);
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
+ gl.bindVertexArray(null);
+ gl.useProgram(null);
+ },
+ cleanup: ({gl, program, vao, vbo}) => {
+ gl.deleteBuffer(vbo);
+ gl.deleteProgram(program);
+ gl.deleteVertexArray(vao);
+ },
+ schema: linearGradientSchema,
+ validateParams: validateLinearGradientParams,
+});
diff --git a/packages/effects/src/test/effect-params.test.ts b/packages/effects/src/test/effect-params.test.ts
index 02dad7226d..31dc43e3e3 100644
--- a/packages/effects/src/test/effect-params.test.ts
+++ b/packages/effects/src/test/effect-params.test.ts
@@ -23,6 +23,8 @@ import {halftone} from '../halftone.js';
import {hue} from '../hue.js';
import {invert} from '../invert.js';
import {lightTrail} from '../light-trail/index.js';
+import {linearGradientTint} from '../linear-gradient-tint.js';
+import {linearGradient} from '../linear-gradient.js';
import {linearProgressiveBlur} from '../linear-progressive-blur/index.js';
import {lines} from '../lines.js';
import {mirror} from '../mirror.js';
@@ -148,6 +150,12 @@ test('@remotion/effects expose documentation links', () => {
expect(lines().definition.documentationLink).toBe(
'https://www.remotion.dev/docs/effects/lines',
);
+ expect(linearGradient().definition.documentationLink).toBe(
+ 'https://www.remotion.dev/docs/effects/linear-gradient',
+ );
+ expect(linearGradientTint().definition.documentationLink).toBe(
+ 'https://www.remotion.dev/docs/effects/linear-gradient-tint',
+ );
expect(linearProgressiveBlur().definition.documentationLink).toBe(
'https://www.remotion.dev/docs/effects/linear-progressive-blur',
);
@@ -256,6 +264,8 @@ test('@remotion/effects expose API names as Studio labels', () => {
expect(hue().definition.label).toBe('hue()');
expect(invert().definition.label).toBe('invert()');
expect(lines().definition.label).toBe('lines()');
+ expect(linearGradient().definition.label).toBe('linearGradient()');
+ expect(linearGradientTint().definition.label).toBe('linearGradientTint()');
expect(linearProgressiveBlur().definition.label).toBe(
'linearProgressiveBlur()',
);
@@ -1565,6 +1575,131 @@ test('halftoneLinearGradient() parameters produce distinct effect keys', () => {
).toBe(6);
});
+test('linearGradient() accepts default params', () => {
+ expect(() => linearGradient()).not.toThrow();
+});
+
+test('linearGradient() connects its stop position controls', () => {
+ expect(linearGradient().definition.schema.start).toMatchObject({
+ type: 'uv-coordinate',
+ visual: {
+ type: 'line',
+ to: 'end',
+ },
+ });
+});
+
+test('linearGradient() rejects start outside the tuple shape', () => {
+ expect(() =>
+ linearGradient({
+ start: [0, 0.5, 1] as unknown as [number, number],
+ }),
+ ).toThrow('"start" must be a [number, number] tuple');
+});
+
+test('linearGradient() rejects end outside the tuple shape', () => {
+ expect(() =>
+ linearGradient({
+ end: [0, Number.NaN],
+ }),
+ ).toThrow('"end" must be a [number, number] tuple');
+});
+
+test('linearGradient() rejects empty colors', () => {
+ expect(() => linearGradient({startColor: ''})).toThrow(
+ '"startColor" must be a non-empty string',
+ );
+ expect(() => linearGradient({endColor: ''})).toThrow(
+ '"endColor" must be a non-empty string',
+ );
+});
+
+test('linearGradient() parameters produce distinct effect keys', () => {
+ const defaultGradient = linearGradient();
+ const shiftedStart = linearGradient({start: [0.2, 0.5]});
+ const shiftedEnd = linearGradient({end: [0.8, 0.5]});
+ const customStartColor = linearGradient({startColor: '#ff0000'});
+ const customEndColor = linearGradient({endColor: '#0000ff'});
+
+ expect(
+ new Set([
+ defaultGradient.effectKey,
+ shiftedStart.effectKey,
+ shiftedEnd.effectKey,
+ customStartColor.effectKey,
+ customEndColor.effectKey,
+ ]).size,
+ ).toBe(5);
+});
+
+test('linearGradientTint() accepts default params', () => {
+ expect(() => linearGradientTint()).not.toThrow();
+});
+
+test('linearGradientTint() connects its stop position controls', () => {
+ expect(linearGradientTint().definition.schema.start).toMatchObject({
+ type: 'uv-coordinate',
+ visual: {
+ type: 'line',
+ to: 'end',
+ },
+ });
+});
+
+test('linearGradientTint() rejects start outside the tuple shape', () => {
+ expect(() =>
+ linearGradientTint({
+ start: [0, 0.5, 1] as unknown as [number, number],
+ }),
+ ).toThrow('"start" must be a [number, number] tuple');
+});
+
+test('linearGradientTint() rejects end outside the tuple shape', () => {
+ expect(() =>
+ linearGradientTint({
+ end: [0, Number.NaN],
+ }),
+ ).toThrow('"end" must be a [number, number] tuple');
+});
+
+test('linearGradientTint() rejects empty colors', () => {
+ expect(() => linearGradientTint({startColor: ''})).toThrow(
+ '"startColor" must be a non-empty string',
+ );
+ expect(() => linearGradientTint({endColor: ''})).toThrow(
+ '"endColor" must be a non-empty string',
+ );
+});
+
+test('linearGradientTint() rejects amount outside unit interval', () => {
+ expect(() => linearGradientTint({amount: -0.1})).toThrow(
+ '"amount" must be >= 0',
+ );
+ expect(() => linearGradientTint({amount: 1.1})).toThrow(
+ '"amount" must be <= 1',
+ );
+});
+
+test('linearGradientTint() parameters produce distinct effect keys', () => {
+ const defaultGradient = linearGradientTint();
+ const shiftedStart = linearGradientTint({start: [0.2, 0.5]});
+ const shiftedEnd = linearGradientTint({end: [0.8, 0.5]});
+ const customStartColor = linearGradientTint({startColor: '#ff0000'});
+ const customEndColor = linearGradientTint({endColor: '#0000ff'});
+ const strongerAmount = linearGradientTint({amount: 1});
+
+ expect(
+ new Set([
+ defaultGradient.effectKey,
+ shiftedStart.effectKey,
+ shiftedEnd.effectKey,
+ customStartColor.effectKey,
+ customEndColor.effectKey,
+ strongerAmount.effectKey,
+ ]).size,
+ ).toBe(6);
+});
+
test('dotGrid() accepts default params', () => {
expect(() => dotGrid()).not.toThrow();
});
diff --git a/packages/skills/skills/remotion/SKILL.md b/packages/skills/skills/remotion/SKILL.md
index d190be737c..9bc99d18b1 100644
--- a/packages/skills/skills/remotion/SKILL.md
+++ b/packages/skills/skills/remotion/SKILL.md
@@ -260,7 +260,7 @@ When creating a visual effect, prefer: 1. normal Remotion/HTML/CSS/SVG/filter/bl
For light leak overlays, see [rules/light-leaks.md](rules/light-leaks.md). Docs: https://www.remotion.dev/docs/effects
-Available effects: `brightness()`, `contrast()`, `colorKey()`, `duotone()`, `grayscale()`, `hue()`, `invert()`, `saturation()`, `tint()`, `thermalVision()`, `blur()`, `linearProgressiveBlur()`, `radialProgressiveBlur()`, `zoomBlur()`, `dropShadow()`, `glow()`, `lightTrail()`, `evolve()`, `mirror()`, `scale()`, `uvTranslate()`, `xyTranslate()`, `barrelDistortion()`, `chromaticAberration()`, `fisheye()`, `cornerPin()`, `wave()`, `burlap()`, `emboss()`, `dotGrid()`, `halftone()`, `noise()`, `noiseDisplacement()`, `pattern()`, `pixelate()`, `pixelDissolve()`, `scanlines()`, `speckle()`, `shine()`, `shrinkwrap()`, `vignette()`, `contourLines()`, `checkerboard()`, `halftoneLinearGradient()`, `gridlines()`, `whiteNoise()`, `tvSignalOff()`, `lines()`, `rings()`, `waves()`, `zigzag()`, `lightLeak()`, `starburst()`.
+Available effects: `brightness()`, `contrast()`, `colorKey()`, `duotone()`, `grayscale()`, `hue()`, `invert()`, `saturation()`, `tint()`, `linearGradient()`, `linearGradientTint()`, `thermalVision()`, `blur()`, `linearProgressiveBlur()`, `radialProgressiveBlur()`, `zoomBlur()`, `dropShadow()`, `glow()`, `lightTrail()`, `evolve()`, `mirror()`, `scale()`, `uvTranslate()`, `xyTranslate()`, `barrelDistortion()`, `chromaticAberration()`, `fisheye()`, `cornerPin()`, `wave()`, `burlap()`, `emboss()`, `dotGrid()`, `halftone()`, `noise()`, `noiseDisplacement()`, `pattern()`, `pixelate()`, `pixelDissolve()`, `scanlines()`, `speckle()`, `shine()`, `shrinkwrap()`, `vignette()`, `contourLines()`, `checkerboard()`, `halftoneLinearGradient()`, `gridlines()`, `whiteNoise()`, `tvSignalOff()`, `lines()`, `rings()`, `waves()`, `zigzag()`, `lightLeak()`, `starburst()`.
## 3D content
diff --git a/packages/studio-shared/src/effect-catalog.ts b/packages/studio-shared/src/effect-catalog.ts
index 72efefe6af..d9119a6ff9 100644
--- a/packages/studio-shared/src/effect-catalog.ts
+++ b/packages/studio-shared/src/effect-catalog.ts
@@ -182,6 +182,28 @@ export const EFFECT_CATALOG: readonly EffectCatalogItem[] = [
},
},
},
+ {
+ id: 'effects-linear-gradient',
+ category: 'Color',
+ label: 'linearGradient()',
+ description: 'Two-stop gradient effect',
+ effect: {
+ name: 'linearGradient',
+ importPath: '@remotion/effects/linear-gradient',
+ config: {},
+ },
+ },
+ {
+ id: 'effects-linear-gradient-tint',
+ category: 'Color',
+ label: 'linearGradientTint()',
+ description: 'Gradient tint effect',
+ effect: {
+ name: 'linearGradientTint',
+ importPath: '@remotion/effects/linear-gradient-tint',
+ config: {},
+ },
+ },
{
id: 'effects-thermal-vision',
category: 'Color',