🎥 Make videos programmatically with React
`@remotion/effects`: Add light trail effect (#8593)
Jonny Burger115d6fe755ca
diff --git a/packages/docs/components/effects-demos/registry.ts b/packages/docs/components/effects-demos/registry.tsindex ee9781c5bf..5d008964a9 100644--- a/packages/docs/components/effects-demos/registry.ts+++ b/packages/docs/components/effects-demos/registry.ts@@ -20,6 +20,7 @@ import {halftone} from '@remotion/effects/halftone';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 {linearProgressiveBlur} from '@remotion/effects/linear-progressive-blur';import {lines} from '@remotion/effects/lines';import {mirror} from '@remotion/effects/mirror';@@ -70,6 +71,10 @@ import {EffectsHalftonePreview} from '../effects/effects-halftone-preview';import {EffectsHuePreview} from '../effects/effects-hue-preview';import {EffectsInvertPreview} from '../effects/effects-invert-preview';import {EffectsLightLeakPreview} from '../effects/effects-light-leak-preview';+import {+ EffectsLightTrailPreview,+ LIGHT_TRAIL_PREVIEW_PARAMS,+} from '../effects/effects-light-trail-preview';import {EffectsLinearProgressiveBlurPreview} from '../effects/effects-linear-progressive-blur-preview';import {EffectsLinesPreview} from '../effects/effects-lines-preview';import {EffectsMirrorPreview} from '../effects/effects-mirror-preview';@@ -433,6 +438,15 @@ export const effectsDemos: EffectsDemoType[] = [comp: EffectsLinearProgressiveBlurPreview,schema: linearProgressiveBlur().definition.schema,},+ {+ ...defaults,+ id: 'effects-light-trail',+ effectName: 'lightTrail',+ effectImportPath: '@remotion/effects/light-trail',+ comp: EffectsLightTrailPreview,+ schema: lightTrail().definition.schema,+ initialValues: LIGHT_TRAIL_PREVIEW_PARAMS,+ },{...defaults,id: 'effects-zoom-blur',diff --git a/packages/docs/components/effects/effects-light-trail-preview.tsx b/packages/docs/components/effects/effects-light-trail-preview.tsxnew file mode 100644index 0000000000..542ce55089--- /dev/null+++ b/packages/docs/components/effects/effects-light-trail-preview.tsx@@ -0,0 +1,73 @@+import {lightTrail} from '@remotion/effects/light-trail';+import React from 'react';+import {AbsoluteFill, CanvasImage, staticFile} from 'remotion';++export const LIGHT_TRAIL_TEXT_IMAGE_SRC = 'img/effects-light-trail-text.png';++export const LIGHT_TRAIL_PREVIEW_PARAMS = {+ direction: 180,+ distance: 240,+ intensity: 4.5,+ decay: 0.96,+ threshold: 0,+ samples: 64,+ color: '#ffc400',+} as const;++const container: React.CSSProperties = {+ backgroundColor: 'black',+};++const textContainer: React.CSSProperties = {+ alignItems: 'center',+ justifyContent: 'center',+};++const textStyle: React.CSSProperties = {+ color: 'white',+ fontFamily: 'Inter, Arial, Helvetica, system-ui, -apple-system, sans-serif',+ fontSize: 280,+ fontWeight: 900,+ lineHeight: 0.9,+ textAlign: 'center',+};++export const LightTrailTextSource: React.FC = () => {+ return (+ <AbsoluteFill style={textContainer}>+ <div style={textStyle}>TRAIL</div>+ </AbsoluteFill>+ );+};++export const EffectsLightTrailPreview: React.FC<{+ readonly direction: number;+ readonly distance: number;+ readonly intensity: number;+ readonly decay: number;+ readonly threshold: number;+ readonly samples: number;+ readonly color: string;+}> = ({direction, distance, intensity, decay, threshold, samples, color}) => {+ return (+ <AbsoluteFill style={container}>+ <CanvasImage+ src={staticFile(LIGHT_TRAIL_TEXT_IMAGE_SRC)}+ width={1280}+ height={720}+ fit="cover"+ effects={[+ lightTrail({+ direction,+ distance,+ intensity,+ decay,+ threshold,+ samples,+ color,+ }),+ ]}+ />+ </AbsoluteFill>+ );+};diff --git a/packages/docs/docs/effects/light-trail.mdx b/packages/docs/docs/effects/light-trail.mdxnew file mode 100644index 0000000000..a249d8cbe8--- /dev/null+++ b/packages/docs/docs/effects/light-trail.mdx@@ -0,0 +1,107 @@+---+image: /generated/articles-docs-effects-light-trail.png+slug: /effects/light-trail+title: lightTrail()+sidebar_label: lightTrail()+crumb: '@remotion/effects'+---++# lightTrail()<AvailableFrom v="4.0.476" />++_Part of the [`@remotion/effects`](/docs/effects/api) package._++Creates a directional light trail from bright or opaque parts of canvas-based components such as [`<Video>`](/docs/media/video), [`<HtmlInCanvas>`](/docs/remotion/html-in-canvas) and [`<Solid>`](/docs/solid).++Use it for speed streaks, luminous text trails and fast-moving logo smears.++## Preview++<EffectsDemo type="effects-light-trail" />++## Example++```tsx twoslash title="MyComp.tsx"+import {lightTrail} from '@remotion/effects/light-trail';+import {AbsoluteFill, CanvasImage, staticFile} from 'remotion';++export const MyComp: React.FC = () => {+ return (+ <AbsoluteFill>+ <CanvasImage+ src={staticFile('logo.png')}+ width={1280}+ height={720}+ fit="contain"+ effects={[+ lightTrail({+ direction: 180,+ distance: 120,+ intensity: 1.6,+ decay: 0.9,+ threshold: 0.2,+ color: '#ffb000',+ }),+ ]}+ />+ </AbsoluteFill>+ );+};+```++## API++Pass an object with the following properties. You can also call `lightTrail()` without arguments.++### `direction?`++Direction in which the trail extends, in degrees. Defaults to `180`.++### `distance?`++Length of the trail in pixels. Defaults to `80`. Must be at least `0`.++### `intensity?`++Brightness multiplier for the trail. Defaults to `1`. Must be at least `0`.++### `decay?`++Falloff from one trail sample to the next. Defaults to `0.9`.++Use values closer to `1` for a longer visible trail. Use smaller values for a shorter falloff.++### `threshold?`++Luminance or alpha threshold from `0` to `1`. Defaults to `0`.++Pixels brighter or more opaque than this value contribute to the trail. Increase it to affect only the strongest parts of the source.++### `samples?`++Number of samples used for the trail. Defaults to `32`. Must be an integer from `1` to `64`.++Higher values make the trail smoother and cost more GPU work.++### `color?`++Color of the trail. Defaults to white.++### `disabled?`++When `true`, the effect is skipped. Defaults to `false`.++## Combining effects++`lightTrail()` only creates the directional trail. For a glowing speed-logo look, combine it with [`glow()`](/docs/effects/glow) and [`chromaticAberration()`](/docs/effects/chromatic-aberration).++## Requirements++`lightTrail()` 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++- [`@remotion/effects`](/docs/effects/api)+- [`glow()`](/docs/effects/glow)+- [`chromaticAberration()`](/docs/effects/chromatic-aberration)+- [HTML-in-canvas guide](/docs/html-in-canvas)+- [Source code for this effect](https://github.com/remotion-dev/remotion/blob/main/packages/effects/src/light-trail/index.ts)diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.tsindex 7a4a716380..fcc8351710 100644--- a/packages/docs/sidebars.ts+++ b/packages/docs/sidebars.ts@@ -296,6 +296,7 @@ const sidebars: SidebarsConfig = {'effects/hue','effects/invert','effects/linear-progressive-blur',+ 'effects/light-trail','effects/lines','effects/mirror','effects/noise',diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex 2ef6710640..a0b1b503f9 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -1943,6 +1943,15 @@ export const articles = [noAi: false,slug: 'effects/invert',},+ {+ id: 'effects/light-trail',+ title: 'lightTrail()',+ relativePath: 'docs/effects/light-trail.mdx',+ compId: 'articles-docs-effects-light-trail',+ crumb: '@remotion/effects',+ noAi: false,+ slug: 'effects/light-trail',+ },{id: 'effects/linear-progressive-blur',title: 'linearProgressiveBlur()',diff --git a/packages/docs/src/remotion/Root.tsx b/packages/docs/src/remotion/Root.tsxindex afe25782a9..ba3acffdbd 100644--- a/packages/docs/src/remotion/Root.tsx+++ b/packages/docs/src/remotion/Root.tsx@@ -25,6 +25,11 @@ import {EffectsHalftonePreview} from '../../components/effects/effects-halftone-import {EffectsHuePreview} from '../../components/effects/effects-hue-preview';import {EffectsInvertPreview} from '../../components/effects/effects-invert-preview';import {EffectsLightLeakPreview} from '../../components/effects/effects-light-leak-preview';+import {+ EffectsLightTrailPreview,+ LIGHT_TRAIL_PREVIEW_PARAMS,+ LightTrailTextSource,+} from '../../components/effects/effects-light-trail-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';@@ -365,6 +370,19 @@ export const RemotionRoot: React.FC = () => {endBlur: 50,}}/>+ <Still+ id="effects-light-trail-text-source"+ component={LightTrailTextSource}+ width={1920}+ height={1080}+ />+ <Still+ id="effects-light-trail-preview"+ component={EffectsLightTrailPreview}+ width={1280}+ height={720}+ defaultProps={LIGHT_TRAIL_PREVIEW_PARAMS}+ /><Stillid="effects-zoom-blur-preview"component={EffectsZoomBlurPreview}diff --git a/packages/docs/static/generated/articles-docs-effects-light-trail.png b/packages/docs/static/generated/articles-docs-effects-light-trail.pngnew file mode 100644index 0000000000..ce132d908bBinary files /dev/null and b/packages/docs/static/generated/articles-docs-effects-light-trail.png differdiff --git a/packages/docs/static/img/effects-light-trail-preview.png b/packages/docs/static/img/effects-light-trail-preview.pngnew file mode 100644index 0000000000..690294fb3fBinary files /dev/null and b/packages/docs/static/img/effects-light-trail-preview.png differdiff --git a/packages/docs/static/img/effects-light-trail-text.png b/packages/docs/static/img/effects-light-trail-text.pngnew file mode 100644index 0000000000..ff72e1bc0aBinary files /dev/null and b/packages/docs/static/img/effects-light-trail-text.png differdiff --git a/packages/effects/bundle.ts b/packages/effects/bundle.tsindex 41a843ca15..625d788016 100644--- a/packages/effects/bundle.ts+++ b/packages/effects/bundle.ts@@ -33,6 +33,7 @@ const effectEntrypoints = ['src/invert.ts','src/lines.ts','src/linear-progressive-blur.ts',+ 'src/light-trail.ts','src/mirror.ts','src/noise.ts','src/noise-displacement.ts',diff --git a/packages/effects/package.json b/packages/effects/package.jsonindex b9f09ef02c..d1ca4d4162 100644--- a/packages/effects/package.json+++ b/packages/effects/package.json@@ -159,6 +159,11 @@"module": "./dist/esm/linear-progressive-blur.mjs","import": "./dist/esm/linear-progressive-blur.mjs"},+ "./light-trail": {+ "types": "./dist/light-trail.d.ts",+ "module": "./dist/esm/light-trail.mjs",+ "import": "./dist/esm/light-trail.mjs"+ },"./dot-grid": {"types": "./dist/dot-grid.d.ts","module": "./dist/esm/dot-grid.mjs",@@ -348,6 +353,9 @@"linear-progressive-blur": ["dist/linear-progressive-blur.d.ts"],+ "light-trail": [+ "dist/light-trail.d.ts"+ ],"dot-grid": ["dist/dot-grid.d.ts"],diff --git a/packages/effects/src/light-trail.ts b/packages/effects/src/light-trail.tsnew file mode 100644index 0000000000..51d6de2b0d--- /dev/null+++ b/packages/effects/src/light-trail.ts@@ -0,0 +1 @@+export {lightTrail, type LightTrailParams} from './light-trail/index.js';diff --git a/packages/effects/src/light-trail/index.ts b/packages/effects/src/light-trail/index.tsnew file mode 100644index 0000000000..c3e098f509--- /dev/null+++ b/packages/effects/src/light-trail/index.ts@@ -0,0 +1,197 @@+import type {InteractivitySchema} from 'remotion';+import {Internals} from 'remotion';+import {+ assertOptionalFiniteNumber,+ parseColorRgba,+ validateNonNegative,+ validateUnitInterval,+} from '../color-utils.js';+import {+ assertEffectParamsObject,+ assertOptionalColor,+} from '../validate-effect-param.js';+import {+ applyLightTrail,+ cleanupLightTrail,+ setupLightTrail,+ type LightTrailState,+} from './light-trail-runtime.js';++const {createEffect} = Internals;++const DEFAULT_DIRECTION = 180 as const;+const DEFAULT_DISTANCE = 80 as const;+const DEFAULT_INTENSITY = 1 as const;+const DEFAULT_DECAY = 0.9 as const;+const DEFAULT_THRESHOLD = 0 as const;+const DEFAULT_SAMPLES = 32 as const;+const DEFAULT_COLOR = '#ffffff' as const;+const MAX_SAMPLES = 64 as const;++const lightTrailSchema = {+ direction: {+ type: 'rotation-degrees',+ step: 1,+ default: DEFAULT_DIRECTION,+ description: 'Direction',+ },+ distance: {+ type: 'number',+ min: 0,+ max: 300,+ step: 1,+ default: DEFAULT_DISTANCE,+ description: 'Distance',+ hiddenFromList: false,+ },+ intensity: {+ type: 'number',+ min: 0,+ max: 5,+ step: 0.1,+ default: DEFAULT_INTENSITY,+ description: 'Intensity',+ hiddenFromList: false,+ },+ decay: {+ type: 'number',+ min: 0,+ max: 1,+ step: 0.01,+ default: DEFAULT_DECAY,+ description: 'Decay',+ hiddenFromList: false,+ },+ threshold: {+ type: 'number',+ min: 0,+ max: 1,+ step: 0.01,+ default: DEFAULT_THRESHOLD,+ description: 'Threshold',+ hiddenFromList: false,+ },+ samples: {+ type: 'number',+ min: 1,+ max: MAX_SAMPLES,+ step: 1,+ default: DEFAULT_SAMPLES,+ description: 'Samples',+ hiddenFromList: false,+ },+ color: {+ type: 'color',+ default: DEFAULT_COLOR,+ description: 'Color',+ },+} as const satisfies InteractivitySchema;++export type LightTrailParams = {+ /** Direction in which the trail extends, in degrees. Defaults to `180`. */+ readonly direction?: number;+ /** Length of the trail in pixels. Defaults to `80`. */+ readonly distance?: number;+ /** Brightness multiplier for the trail. Defaults to `1`. */+ readonly intensity?: number;+ /** Falloff from one sample to the next. Defaults to `0.9`. */+ readonly decay?: number;+ /** Luminance or alpha threshold from `0` to `1`. Defaults to `0`. */+ readonly threshold?: number;+ /** Number of samples used for the trail. Defaults to `32`. */+ readonly samples?: number;+ /** Color of the trail. Defaults to white. */+ readonly color?: string;+};++type LightTrailResolved = {+ readonly direction: number;+ readonly distance: number;+ readonly intensity: number;+ readonly decay: number;+ readonly threshold: number;+ readonly samples: number;+ readonly color: string;+};++const resolve = (p: LightTrailParams): LightTrailResolved => ({+ direction: p.direction ?? DEFAULT_DIRECTION,+ distance: p.distance ?? DEFAULT_DISTANCE,+ intensity: p.intensity ?? DEFAULT_INTENSITY,+ decay: p.decay ?? DEFAULT_DECAY,+ threshold: p.threshold ?? DEFAULT_THRESHOLD,+ samples: p.samples ?? DEFAULT_SAMPLES,+ color: p.color ?? DEFAULT_COLOR,+});++const validateSamples = (samples: number): void => {+ if (!Number.isInteger(samples)) {+ throw new TypeError(`"samples" must be an integer, but got ${samples}`);+ }++ if (samples < 1) {+ throw new TypeError(`"samples" must be >= 1, but got ${samples}`);+ }++ if (samples > MAX_SAMPLES) {+ throw new TypeError(+ `"samples" must be <= ${MAX_SAMPLES}, but got ${samples}`,+ );+ }+};++const validateLightTrailParams = (params: LightTrailParams): void => {+ assertEffectParamsObject(params, 'Light trail');+ assertOptionalFiniteNumber(params.direction, 'direction');+ assertOptionalFiniteNumber(params.distance, 'distance');+ assertOptionalFiniteNumber(params.intensity, 'intensity');+ assertOptionalFiniteNumber(params.decay, 'decay');+ assertOptionalFiniteNumber(params.threshold, 'threshold');+ assertOptionalFiniteNumber(params.samples, 'samples');+ assertOptionalColor(params.color, 'color');++ const r = resolve(params);+ validateNonNegative(r.distance, 'distance');+ validateNonNegative(r.intensity, 'intensity');+ validateUnitInterval(r.decay, 'decay');+ validateUnitInterval(r.threshold, 'threshold');+ validateSamples(r.samples);+};++export const lightTrail = createEffect<LightTrailParams, LightTrailState>({+ type: 'remotion/light-trail',+ label: 'lightTrail()',+ documentationLink: 'https://www.remotion.dev/docs/effects/light-trail',+ backend: 'webgl2',+ calculateKey: (params) => {+ const r = resolve(params);+ return `light-trail-${r.direction}-${r.distance}-${r.intensity}-${r.decay}-${r.threshold}-${r.samples}-${r.color}`;+ },+ setup: (target) => setupLightTrail(target),+ apply: ({source, width, height, params, state, flipSourceY}) => {+ const r = resolve(params);++ if (state.cachedColorStr !== r.color) {+ state.cachedColorStr = r.color;+ state.cachedColorRgba = parseColorRgba(state.colorCtx, r.color);+ }++ applyLightTrail({+ state,+ source,+ width,+ height,+ direction: r.direction,+ distance: r.distance,+ intensity: r.intensity,+ decay: r.decay,+ threshold: r.threshold,+ samples: r.samples,+ color: state.cachedColorRgba,+ flipSourceY,+ });+ },+ cleanup: (state) => cleanupLightTrail(state),+ schema: lightTrailSchema,+ validateParams: validateLightTrailParams,+});diff --git a/packages/effects/src/light-trail/light-trail-runtime.ts b/packages/effects/src/light-trail/light-trail-runtime.tsnew file mode 100644index 0000000000..192d3d18ab--- /dev/null+++ b/packages/effects/src/light-trail/light-trail-runtime.ts@@ -0,0 +1,263 @@+import {Internals} from 'remotion';+import type {ParsedColorRgba} from '../color-utils.js';+import {LIGHT_TRAIL_FS, LIGHT_TRAIL_VS} from './light-trail-shaders.js';++const {createWebGL2ContextError} = Internals;++export type LightTrailState = {+ readonly gl: WebGL2RenderingContext;+ readonly program: WebGLProgram;+ readonly vao: WebGLVertexArrayObject;+ readonly vbo: WebGLBuffer;+ readonly textureSource: WebGLTexture;+ readonly uniforms: {+ readonly uSource: WebGLUniformLocation | null;+ readonly uDirection: WebGLUniformLocation | null;+ readonly uTexelSize: WebGLUniformLocation | null;+ readonly uColor: WebGLUniformLocation | null;+ readonly uDistance: WebGLUniformLocation | null;+ readonly uIntensity: WebGLUniformLocation | null;+ readonly uDecay: WebGLUniformLocation | null;+ readonly uThreshold: WebGLUniformLocation | null;+ readonly uSamples: WebGLUniformLocation | null;+ };+ readonly colorCtx: CanvasRenderingContext2D;+ cachedColorStr: string;+ cachedColorRgba: ParsedColorRgba;+};++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(`Light trail shader compile failed: ${log ?? '(no log)'}`);+ }++ return shader;+};++const linkProgram = (+ gl: WebGL2RenderingContext,+ vs: WebGLShader,+ fs: WebGLShader,+): WebGLProgram => {+ 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);+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {+ const log = gl.getProgramInfoLog(program);+ gl.deleteProgram(program);+ throw new Error(`Light trail program link failed: ${log ?? '(no log)'}`);+ }++ return program;+};++const createProgram = (+ gl: WebGL2RenderingContext,+ vertexSource: string,+ fragmentSource: string,+): WebGLProgram => {+ const vs = compileShader(gl, gl.VERTEX_SHADER, vertexSource);+ const fs = compileShader(gl, gl.FRAGMENT_SHADER, fragmentSource);+ const program = linkProgram(gl, vs, fs);+ gl.deleteShader(vs);+ gl.deleteShader(fs);+ 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;+};++export const setupLightTrail = (target: HTMLCanvasElement): LightTrailState => {+ const gl = target.getContext('webgl2', {+ premultipliedAlpha: true,+ alpha: true,+ preserveDrawingBuffer: true,+ });+ if (!gl) {+ throw createWebGL2ContextError('light trail effect');+ }++ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);++ const program = createProgram(gl, LIGHT_TRAIL_VS, LIGHT_TRAIL_FS);++ 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);++ gl.enableVertexAttribArray(0);+ gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 16, 0);+ gl.enableVertexAttribArray(1);+ gl.vertexAttribPointer(1, 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,+ textureSource: createRgbaTexture(gl),+ uniforms: {+ uSource: gl.getUniformLocation(program, 'uSource'),+ uDirection: gl.getUniformLocation(program, 'uDirection'),+ uTexelSize: gl.getUniformLocation(program, 'uTexelSize'),+ uColor: gl.getUniformLocation(program, 'uColor'),+ uDistance: gl.getUniformLocation(program, 'uDistance'),+ uIntensity: gl.getUniformLocation(program, 'uIntensity'),+ uDecay: gl.getUniformLocation(program, 'uDecay'),+ uThreshold: gl.getUniformLocation(program, 'uThreshold'),+ uSamples: gl.getUniformLocation(program, 'uSamples'),+ },+ colorCtx,+ cachedColorStr: '',+ cachedColorRgba: [255, 255, 255, 255],+ };+};++export const cleanupLightTrail = (state: LightTrailState): void => {+ const {gl, program, vao, vbo, textureSource} = state;+ gl.deleteTexture(textureSource);+ gl.deleteBuffer(vbo);+ gl.deleteProgram(program);+ gl.deleteVertexArray(vao);+};++const drawFullscreenQuad = (state: LightTrailState): void => {+ const {gl, vao} = state;+ gl.bindVertexArray(vao);+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);+ gl.bindVertexArray(null);+};++export const applyLightTrail = ({+ state,+ source,+ width,+ height,+ direction,+ distance,+ intensity,+ decay,+ threshold,+ samples,+ color,+ flipSourceY,+}: {+ readonly state: LightTrailState;+ readonly source: CanvasImageSource;+ readonly width: number;+ readonly height: number;+ readonly direction: number;+ readonly distance: number;+ readonly intensity: number;+ readonly decay: number;+ readonly threshold: number;+ readonly samples: number;+ readonly color: ParsedColorRgba;+ readonly flipSourceY: boolean;+}): void => {+ const {gl, program, textureSource, uniforms} = state;+ const radians = (direction * Math.PI) / 180;+ const x = Math.cos(radians);+ const y = Math.sin(radians);++ gl.viewport(0, 0, width, height);+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipSourceY);+ gl.bindTexture(gl.TEXTURE_2D, textureSource);+ gl.texImage2D(+ gl.TEXTURE_2D,+ 0,+ gl.RGBA,+ gl.RGBA,+ gl.UNSIGNED_BYTE,+ source as TexImageSource,+ );+ gl.bindTexture(gl.TEXTURE_2D, null);++ gl.bindFramebuffer(gl.FRAMEBUFFER, null);+ gl.clearColor(0, 0, 0, 0);+ gl.clear(gl.COLOR_BUFFER_BIT);++ gl.useProgram(program);+ if (uniforms.uSource) gl.uniform1i(uniforms.uSource, 0);+ if (uniforms.uDirection) gl.uniform2f(uniforms.uDirection, x, y);+ if (uniforms.uTexelSize) {+ gl.uniform2f(uniforms.uTexelSize, 1 / width, 1 / height);+ }++ if (uniforms.uColor) {+ gl.uniform4f(+ uniforms.uColor,+ color[0] / 255,+ color[1] / 255,+ color[2] / 255,+ color[3] / 255,+ );+ }++ if (uniforms.uDistance) gl.uniform1f(uniforms.uDistance, distance);+ if (uniforms.uIntensity) gl.uniform1f(uniforms.uIntensity, intensity);+ if (uniforms.uDecay) gl.uniform1f(uniforms.uDecay, decay);+ if (uniforms.uThreshold) gl.uniform1f(uniforms.uThreshold, threshold);+ if (uniforms.uSamples) gl.uniform1i(uniforms.uSamples, samples);++ gl.activeTexture(gl.TEXTURE0);+ gl.bindTexture(gl.TEXTURE_2D, textureSource);+ drawFullscreenQuad(state);+ gl.bindTexture(gl.TEXTURE_2D, null);+ gl.useProgram(null);+};diff --git a/packages/effects/src/light-trail/light-trail-shaders.ts b/packages/effects/src/light-trail/light-trail-shaders.tsnew file mode 100644index 0000000000..54045be8ec--- /dev/null+++ b/packages/effects/src/light-trail/light-trail-shaders.ts@@ -0,0 +1,72 @@+export const LIGHT_TRAIL_VS = /* glsl */ `#version 300 es+layout(location = 0) in vec2 aPos;+layout(location = 1) in vec2 aUv;+out vec2 vUv;++void main() {+ vUv = aUv;+ gl_Position = vec4(aPos, 0.0, 1.0);+}+`;++export const LIGHT_TRAIL_FS = /* glsl */ `#version 300 es+precision highp float;++in vec2 vUv;+out vec4 fragColor;++uniform sampler2D uSource;+uniform vec2 uDirection;+uniform vec2 uTexelSize;+uniform vec4 uColor;+uniform float uDistance;+uniform float uIntensity;+uniform float uDecay;+uniform float uThreshold;+uniform int uSamples;++const int MAX_SAMPLES = 64;++float getContribution(vec4 color) {+ if (color.a <= 0.001) {+ return 0.0;+ }++ vec3 rgb = color.rgb / color.a;+ float luminance = dot(rgb, vec3(0.299, 0.587, 0.114));+ float source = max(color.a, luminance);+ float threshold = clamp(uThreshold, 0.0, 1.0);++ if (threshold >= 1.0) {+ return step(1.0, source);+ }++ return clamp((source - threshold) / max(1.0 - threshold, 0.0001), 0.0, 1.0);+}++void main() {+ vec4 source = texture(uSource, vUv);+ vec4 trail = vec4(0.0);+ float sampleCount = float(max(uSamples, 1));++ for (int i = 1; i <= MAX_SAMPLES; i++) {+ if (i > uSamples) {+ break;+ }++ float progress = float(i) / sampleCount;+ vec2 offset = uDirection * uTexelSize * uDistance * progress;+ vec4 sampleColor = texture(uSource, vUv - offset);+ float contribution = getContribution(sampleColor);+ float weight = pow(clamp(uDecay, 0.0, 1.0), float(i - 1)) * contribution;+ float alpha = sampleColor.a * uColor.a * weight;++ trail += vec4(uColor.rgb * alpha, alpha);+ }++ trail *= max(uIntensity, 0.0) / sampleCount;++ vec4 outColor = source + trail;+ fragColor = vec4(min(outColor.rgb, vec3(1.0)), min(outColor.a, 1.0));+}+`;diff --git a/packages/effects/src/test/effect-params.test.ts b/packages/effects/src/test/effect-params.test.tsindex 598bf80d98..08e9cd4f6a 100644--- a/packages/effects/src/test/effect-params.test.ts+++ b/packages/effects/src/test/effect-params.test.ts@@ -21,6 +21,7 @@ import {halftoneLinearGradient} from '../halftone-linear-gradient.js';import {halftone} from '../halftone.js';import {hue} from '../hue.js';import {invert} from '../invert.js';+import {lightTrail} from '../light-trail/index.js';import {linearProgressiveBlur} from '../linear-progressive-blur/index.js';import {lines} from '../lines.js';import {mirror} from '../mirror.js';@@ -145,6 +146,9 @@ test('@remotion/effects expose documentation links', () => {expect(linearProgressiveBlur().definition.documentationLink).toBe('https://www.remotion.dev/docs/effects/linear-progressive-blur',);+ expect(lightTrail().definition.documentationLink).toBe(+ 'https://www.remotion.dev/docs/effects/light-trail',+ );expect(dotGrid().definition.documentationLink).toBe('https://www.remotion.dev/docs/effects/dot-grid',);@@ -246,6 +250,7 @@ test('@remotion/effects expose API names as Studio labels', () => {expect(linearProgressiveBlur().definition.label).toBe('linearProgressiveBlur()',);+ expect(lightTrail().definition.label).toBe('lightTrail()');expect(dotGrid().definition.label).toBe('dotGrid()');expect(mirror().definition.label).toBe('mirror()');expect(noise().definition.label).toBe('noise()');@@ -1158,6 +1163,88 @@ test('glow() parameters produce distinct effect keys', () => {).toBe(5);});+test('lightTrail() accepts default params', () => {+ expect(() => lightTrail()).not.toThrow();+});++test('lightTrail() accepts valid params', () => {+ expect(() =>+ lightTrail({+ direction: 180,+ distance: 120,+ intensity: 1.6,+ decay: 0.86,+ threshold: 0.25,+ samples: 48,+ color: '#ffb000',+ }),+ ).not.toThrow();+});++test('lightTrail() rejects non-finite direction', () => {+ expect(() => lightTrail({direction: Number.NaN})).toThrow(+ '"direction" must be a finite number',+ );+});++test('lightTrail() rejects negative distance', () => {+ expect(() => lightTrail({distance: -1})).toThrow('"distance" must be >= 0');+});++test('lightTrail() rejects negative intensity', () => {+ expect(() => lightTrail({intensity: -0.1})).toThrow(+ '"intensity" must be >= 0',+ );+});++test('lightTrail() rejects decay outside range', () => {+ expect(() => lightTrail({decay: 1.1})).toThrow('"decay" must be <= 1');+});++test('lightTrail() rejects threshold outside range', () => {+ expect(() => lightTrail({threshold: -0.1})).toThrow(+ '"threshold" must be >= 0',+ );+});++test('lightTrail() rejects non-integer samples', () => {+ expect(() => lightTrail({samples: 1.5})).toThrow(+ '"samples" must be an integer',+ );+});++test('lightTrail() rejects samples above maximum', () => {+ expect(() => lightTrail({samples: 65})).toThrow('"samples" must be <= 64');+});++test('lightTrail() rejects empty color strings', () => {+ expect(() => lightTrail({color: ''})).toThrow(+ '"color" must be a non-empty string, but got ""',+ );+});++test('lightTrail() parameters produce distinct effect keys', () => {+ const defaultTrail = lightTrail();+ const longerTrail = lightTrail({distance: 120});+ const strongerTrail = lightTrail({intensity: 2});+ const softerTrail = lightTrail({decay: 0.75});+ const thresholdTrail = lightTrail({threshold: 0.5});+ const detailedTrail = lightTrail({samples: 48});+ const coloredTrail = lightTrail({color: '#ffb000'});++ expect(+ new Set([+ defaultTrail.effectKey,+ longerTrail.effectKey,+ strongerTrail.effectKey,+ softerTrail.effectKey,+ thresholdTrail.effectKey,+ detailedTrail.effectKey,+ coloredTrail.effectKey,+ ]).size,+ ).toBe(7);+});+test('vignette() accepts default params', () => {expect(() => vignette()).not.toThrow();});diff --git a/packages/skills/skills/remotion/SKILL.md b/packages/skills/skills/remotion/SKILL.mdindex 98c44d26ae..5679dbf601 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/blFor 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()`, `zoomBlur()`, `dropShadow()`, `glow()`, `evolve()`, `mirror()`, `scale()`, `uvTranslate()`, `xyTranslate()`, `barrelDistortion()`, `chromaticAberration()`, `fisheye()`, `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()`, `thermalVision()`, `blur()`, `linearProgressiveBlur()`, `zoomBlur()`, `dropShadow()`, `glow()`, `lightTrail()`, `evolve()`, `mirror()`, `scale()`, `uvTranslate()`, `xyTranslate()`, `barrelDistortion()`, `chromaticAberration()`, `fisheye()`, `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 contentdiff --git a/packages/studio-shared/src/effect-catalog.ts b/packages/studio-shared/src/effect-catalog.tsindex 87cdc2b7cf..5bddff5b71 100644--- a/packages/studio-shared/src/effect-catalog.ts+++ b/packages/studio-shared/src/effect-catalog.ts@@ -250,6 +250,17 @@ export const EFFECT_CATALOG: readonly EffectCatalogItem[] = [config: {},},},+ {+ id: 'effects-light-trail',+ category: 'Blur & Shadow',+ label: 'lightTrail()',+ description: 'Directional light trail effect',+ effect: {+ name: 'lightTrail',+ importPath: '@remotion/effects/light-trail',+ config: {},+ },+ },{id: 'effects-evolve',category: 'Reveal',