Skip to content

🎥 Make videos programmatically with React

`@remotion/canvas-effects`: Add wave, tint, and blur effects

JonnyBurgerfe561c3a534d
diff --git a/bun.lock b/bun.lock
index cc5a4ffaf3..9bcb7bb862 100644
--- a/bun.lock
+++ b/bun.lock
@@ -153,6 +153,20 @@
"react-dom": ">=16.8.0",
},
},
+ "packages/canvas-effects": {
+ "name": "@remotion/canvas-effects",
+ "version": "4.0.451",
+ "devDependencies": {
+ "@remotion/eslint-config-internal": "workspace:*",
+ "@typescript/native-preview": "catalog:",
+ "eslint": "catalog:",
+ "react": "catalog:",
+ },
+ "peerDependencies": {
+ "react": ">=16.8.0",
+ "remotion": "workspace:*",
+ },
+ },
"packages/captions": {
"name": "@remotion/captions",
"version": "4.0.451",
@@ -661,6 +675,7 @@
"@remotion/animation-utils": "workspace:*",
"@remotion/babel-loader": "workspace:*",
"@remotion/bundler": "workspace:*",
+ "@remotion/canvas-effects": "workspace:*",
"@remotion/captions": "workspace:*",
"@remotion/cli": "workspace:*",
"@remotion/cloudrun": "workspace:*",
@@ -3760,6 +3775,8 @@
"@remotion/bundler": ["@remotion/bundler@workspace:packages/bundler"],
+ "@remotion/canvas-effects": ["@remotion/canvas-effects@workspace:packages/canvas-effects"],
+
"@remotion/captions": ["@remotion/captions@workspace:packages/captions"],
"@remotion/cli": ["@remotion/cli@workspace:packages/cli"],
diff --git a/packages/canvas-effects/.npmignore b/packages/canvas-effects/.npmignore
new file mode 100644
index 0000000000..498c1db822
--- /dev/null
+++ b/packages/canvas-effects/.npmignore
@@ -0,0 +1,9 @@
+dist/test/**
+src
+tsconfig.tsbuildinfo
+*.tgz
+.turbo
+.prettierrc.js
+tsconfig.json
+bundle.ts
+eslint.config.mjs
diff --git a/packages/canvas-effects/LICENSE.md b/packages/canvas-effects/LICENSE.md
new file mode 100644
index 0000000000..a233a88cdb
--- /dev/null
+++ b/packages/canvas-effects/LICENSE.md
@@ -0,0 +1,7 @@
+Copyright (c) 2026 JonnyBurger
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/packages/canvas-effects/README.md b/packages/canvas-effects/README.md
new file mode 100644
index 0000000000..173f660265
--- /dev/null
+++ b/packages/canvas-effects/README.md
@@ -0,0 +1,18 @@
+# @remotion/canvas-effects
+
+Sample effects for the Remotion canvas-effect chain.
+
+[![NPM Downloads](https://img.shields.io/npm/dm/@remotion/canvas-effects.svg?style=flat&color=black&label=Downloads)](https://npmcharts.com/compare/@remotion/canvas-effects?minimal=true)
+
+## Installation
+
+```bash
+npm install @remotion/canvas-effects --save-exact
+```
+
+When installing a Remotion package, make sure to align the version of all `remotion` and `@remotion/*` packages to the same version.
+Remove the `^` character from the version number to use the exact version.
+
+## Usage
+
+See the [documentation](https://www.remotion.dev/docs/canvas-effects) for more information.
diff --git a/packages/canvas-effects/bundle.ts b/packages/canvas-effects/bundle.ts
new file mode 100644
index 0000000000..dbcb9970e2
--- /dev/null
+++ b/packages/canvas-effects/bundle.ts
@@ -0,0 +1,18 @@
+import {build} from 'bun';
+
+if (process.env.NODE_ENV !== 'production') {
+ throw new Error('This script must be run using NODE_ENV=production');
+}
+
+const output = await build({
+ entrypoints: ['src/index.ts'],
+ naming: '[name].mjs',
+ external: ['react/jsx-runtime', 'react', 'react-dom', 'remotion'],
+});
+
+const [file] = output.outputs;
+const text = await file.text();
+
+await Bun.write('dist/esm/index.mjs', text);
+
+export {};
diff --git a/packages/canvas-effects/eslint.config.mjs b/packages/canvas-effects/eslint.config.mjs
new file mode 100644
index 0000000000..ab29acaba0
--- /dev/null
+++ b/packages/canvas-effects/eslint.config.mjs
@@ -0,0 +1,7 @@
+import {remotionFlatConfig} from '@remotion/eslint-config-internal';
+
+const config = remotionFlatConfig({react: true});
+
+export default {
+ ...config,
+};
diff --git a/packages/canvas-effects/package.json b/packages/canvas-effects/package.json
new file mode 100644
index 0000000000..8237b48eea
--- /dev/null
+++ b/packages/canvas-effects/package.json
@@ -0,0 +1,53 @@
+{
+ "repository": {
+ "url": "https://github.com/remotion-dev/remotion/tree/main/packages/canvas-effects"
+ },
+ "name": "@remotion/canvas-effects",
+ "version": "4.0.451",
+ "description": "Sample effects for the Remotion canvas-effect chain",
+ "main": "dist/index.js",
+ "sideEffects": false,
+ "scripts": {
+ "formatting": "oxfmt src --check",
+ "format": "oxfmt src",
+ "lint": "eslint src",
+ "make": "tsgo -d && bun --env-file=../.env.bundle bundle.ts"
+ },
+ "types": "dist/index.d.ts",
+ "module": "dist/esm/index.mjs",
+ "author": "Jonny Burger <[email protected]>",
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/remotion-dev/remotion/issues"
+ },
+ "exports": {
+ "./package.json": "./package.json",
+ ".": {
+ "types": "./dist/index.d.ts",
+ "module": "./dist/esm/index.mjs",
+ "import": "./dist/esm/index.mjs",
+ "require": "./dist/index.js"
+ }
+ },
+ "devDependencies": {
+ "react": "catalog:",
+ "@remotion/eslint-config-internal": "workspace:*",
+ "eslint": "catalog:",
+ "@typescript/native-preview": "catalog:"
+ },
+ "keywords": [
+ "canvas",
+ "effects",
+ "webgl",
+ "remotion"
+ ],
+ "publishConfig": {
+ "access": "public"
+ },
+ "peerDependencies": {
+ "react": ">=16.8.0",
+ "remotion": "workspace:*"
+ },
+ "dependencies": {},
+ "homepage": "https://www.remotion.dev/docs/canvas-effects"
+}
diff --git a/packages/canvas-effects/src/blur/blur-horizontal.ts b/packages/canvas-effects/src/blur/blur-horizontal.ts
new file mode 100644
index 0000000000..3fed85d513
--- /dev/null
+++ b/packages/canvas-effects/src/blur/blur-horizontal.ts
@@ -0,0 +1,27 @@
+import {createDescriptor, defineEffect} from 'remotion';
+import {
+ applyBlur,
+ cleanupBlur,
+ setupBlur,
+ type BlurState,
+} from './blur-runtime.js';
+import {BLUR_FS_HORIZONTAL} from './blur-shaders.js';
+
+export type BlurHorizontalParams = {
+ readonly radius: number;
+};
+
+const blurHorizontalDef = defineEffect<BlurHorizontalParams, BlurState>({
+ type: 'remotion/blur-horizontal',
+ backend: 'webgl2',
+ setup: (target) => setupBlur(target, BLUR_FS_HORIZONTAL),
+ apply: ({source, width, height, params, state}) => {
+ applyBlur(state, source, width, height, params.radius);
+ },
+ cleanup: (state) => cleanupBlur(state),
+});
+
+// Single horizontal pass of the separable Gaussian blur. Most callers should
+// use [`blur`](./index.ts) which composes both horizontal and vertical passes.
+export const blurHorizontal = (params: BlurHorizontalParams) =>
+ createDescriptor(blurHorizontalDef, params);
diff --git a/packages/canvas-effects/src/blur/blur-runtime.ts b/packages/canvas-effects/src/blur/blur-runtime.ts
new file mode 100644
index 0000000000..a39b422fe5
--- /dev/null
+++ b/packages/canvas-effects/src/blur/blur-runtime.ts
@@ -0,0 +1,174 @@
+import {BLUR_VS} from './blur-shaders.js';
+
+// Shared WebGL2 plumbing for the separable Gaussian blur passes.
+// `setupBlur` compiles a fullscreen-quad VS + the supplied FS, allocates
+// the quad VBO/VAO, and creates a sampling texture. `applyBlur` uploads
+// the source into the sampling texture, sets uniforms, and draws.
+
+export type BlurState = {
+ gl: WebGL2RenderingContext;
+ program: WebGLProgram;
+ vao: WebGLVertexArrayObject;
+ texture: WebGLTexture;
+ uRadius: WebGLUniformLocation | null;
+ uTexelSize: WebGLUniformLocation | null;
+ uSource: WebGLUniformLocation | null;
+};
+
+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(`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(`Program link failed: ${log ?? '(no log)'}`);
+ }
+
+ return program;
+};
+
+export const setupBlur = (
+ target: HTMLCanvasElement,
+ fragmentSource: string,
+): BlurState => {
+ const gl = target.getContext('webgl2', {
+ premultipliedAlpha: true,
+ alpha: true,
+ preserveDrawingBuffer: true,
+ });
+ if (!gl) {
+ throw new Error('Failed to acquire WebGL2 context for blur effect');
+ }
+
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
+
+ const vs = compileShader(gl, gl.VERTEX_SHADER, BLUR_VS);
+ const fs = compileShader(gl, gl.FRAGMENT_SHADER, fragmentSource);
+ const program = linkProgram(gl, vs, fs);
+ gl.deleteShader(vs);
+ gl.deleteShader(fs);
+
+ const vao = gl.createVertexArray();
+ if (!vao) {
+ throw new Error('Failed to create WebGL vertex array');
+ }
+
+ gl.bindVertexArray(vao);
+
+ // Fullscreen-quad: positions in clip space + matching uv coords.
+ // Using a triangle strip (4 verts) avoids an index buffer.
+ 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 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);
+
+ const uRadius = gl.getUniformLocation(program, 'uRadius');
+ const uTexelSize = gl.getUniformLocation(program, 'uTexelSize');
+ const uSource = gl.getUniformLocation(program, 'uSource');
+
+ return {gl, program, vao, texture, uRadius, uTexelSize, uSource};
+};
+
+export const cleanupBlur = (state: BlurState): void => {
+ const {gl, program, vao, texture} = state;
+ gl.deleteProgram(program);
+ gl.deleteVertexArray(vao);
+ gl.deleteTexture(texture);
+};
+
+export const applyBlur = (
+ state: BlurState,
+ source: CanvasImageSource,
+ width: number,
+ height: number,
+ radius: number,
+): void => {
+ const {gl, program, vao, texture, uRadius, uTexelSize, uSource} = state;
+
+ gl.viewport(0, 0, width, height);
+ gl.clearColor(0, 0, 0, 0);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+
+ gl.useProgram(program);
+ gl.bindVertexArray(vao);
+
+ gl.activeTexture(gl.TEXTURE0);
+ gl.bindTexture(gl.TEXTURE_2D, texture);
+ gl.texImage2D(
+ gl.TEXTURE_2D,
+ 0,
+ gl.RGBA,
+ gl.RGBA,
+ gl.UNSIGNED_BYTE,
+ source as TexImageSource,
+ );
+
+ if (uSource) gl.uniform1i(uSource, 0);
+ if (uRadius) gl.uniform1f(uRadius, radius);
+ if (uTexelSize) gl.uniform2f(uTexelSize, 1 / width, 1 / height);
+
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
+
+ gl.bindVertexArray(null);
+ gl.bindTexture(gl.TEXTURE_2D, null);
+ gl.useProgram(null);
+};
diff --git a/packages/canvas-effects/src/blur/blur-shaders.ts b/packages/canvas-effects/src/blur/blur-shaders.ts
new file mode 100644
index 0000000000..4c9ca35aaf
--- /dev/null
+++ b/packages/canvas-effects/src/blur/blur-shaders.ts
@@ -0,0 +1,63 @@
+// Shared GLSL sources for the separable Gaussian blur passes.
+//
+// The blur is implemented as a 9-tap kernel (KERNEL_HALF = 4) with the sample
+// stride scaled by `uRadius` so the kernel always spans approximately
+// ±uRadius pixels. Sigma is set to uRadius / 3 (the standard 3-sigma rule)
+// so weights at the kernel edges are small but non-zero.
+//
+// The sampling direction is baked into the fragment shader as a vec2 constant
+// to keep the inner loop branch-free.
+
+export const BLUR_VS = /* 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 buildFs = (direction: 'horizontal' | 'vertical') => {
+ const dirVec =
+ direction === 'horizontal' ? 'vec2(1.0, 0.0)' : 'vec2(0.0, 1.0)';
+ return /* glsl */ `#version 300 es
+precision highp float;
+in vec2 vUv;
+out vec4 fragColor;
+
+uniform sampler2D uSource;
+uniform float uRadius;
+uniform vec2 uTexelSize;
+
+const int KERNEL_HALF = 4;
+const vec2 DIRECTION = ${dirVec};
+
+void main() {
+ if (uRadius <= 0.0) {
+ fragColor = texture(uSource, vUv);
+ return;
+ }
+
+ float pixelStride = uRadius / float(KERNEL_HALF);
+ float sigma = uRadius / 3.0;
+ float twoSigmaSq = 2.0 * sigma * sigma;
+
+ vec4 sum = vec4(0.0);
+ float weightSum = 0.0;
+
+ for (int i = -KERNEL_HALF; i <= KERNEL_HALF; ++i) {
+ float offsetPx = float(i) * pixelStride;
+ float w = exp(-(offsetPx * offsetPx) / twoSigmaSq);
+ vec2 uv = vUv + DIRECTION * uTexelSize * offsetPx;
+ sum += texture(uSource, uv) * w;
+ weightSum += w;
+ }
+
+ fragColor = sum / weightSum;
+}
+`;
+};
+
+export const BLUR_FS_HORIZONTAL = buildFs('horizontal');
+export const BLUR_FS_VERTICAL = buildFs('vertical');
diff --git a/packages/canvas-effects/src/blur/blur-vertical.ts b/packages/canvas-effects/src/blur/blur-vertical.ts
new file mode 100644
index 0000000000..5a8ba994d5
--- /dev/null
+++ b/packages/canvas-effects/src/blur/blur-vertical.ts
@@ -0,0 +1,27 @@
+import {createDescriptor, defineEffect} from 'remotion';
+import {
+ applyBlur,
+ cleanupBlur,
+ setupBlur,
+ type BlurState,
+} from './blur-runtime.js';
+import {BLUR_FS_VERTICAL} from './blur-shaders.js';
+
+export type BlurVerticalParams = {
+ readonly radius: number;
+};
+
+const blurVerticalDef = defineEffect<BlurVerticalParams, BlurState>({
+ type: 'remotion/blur-vertical',
+ backend: 'webgl2',
+ setup: (target) => setupBlur(target, BLUR_FS_VERTICAL),
+ apply: ({source, width, height, params, state}) => {
+ applyBlur(state, source, width, height, params.radius);
+ },
+ cleanup: (state) => cleanupBlur(state),
+});
+
+// Single vertical pass of the separable Gaussian blur. Most callers should
+// use [`blur`](./index.ts) which composes both horizontal and vertical passes.
+export const blurVertical = (params: BlurVerticalParams) =>
+ createDescriptor(blurVerticalDef, params);
diff --git a/packages/canvas-effects/src/blur/index.ts b/packages/canvas-effects/src/blur/index.ts
new file mode 100644
index 0000000000..4d942c7ffa
--- /dev/null
+++ b/packages/canvas-effects/src/blur/index.ts
@@ -0,0 +1,22 @@
+import {blurHorizontal} from './blur-horizontal.js';
+import {blurVertical} from './blur-vertical.js';
+
+export type BlurParams = {
+ readonly radius: number;
+};
+
+// Separable Gaussian blur. Returns a tuple of horizontal + vertical passes.
+// Both passes share the same WebGL2 program structure but bake the sampling
+// direction into the fragment shader at compile time. Callers spread the
+// result into the `effects` prop or pass the whole tuple thanks to the
+// runtime's automatic flattening.
+export const blur = (params: BlurParams) =>
+ [
+ blurHorizontal({radius: params.radius}),
+ blurVertical({radius: params.radius}),
+ ] as const;
+
+export {blurHorizontal} from './blur-horizontal.js';
+export type {BlurHorizontalParams} from './blur-horizontal.js';
+export {blurVertical} from './blur-vertical.js';
+export type {BlurVerticalParams} from './blur-vertical.js';
diff --git a/packages/canvas-effects/src/index.ts b/packages/canvas-effects/src/index.ts
new file mode 100644
index 0000000000..c6dafe7660
--- /dev/null
+++ b/packages/canvas-effects/src/index.ts
@@ -0,0 +1,10 @@
+export {blur, blurHorizontal, blurVertical} from './blur/index.js';
+export type {
+ BlurHorizontalParams,
+ BlurParams,
+ BlurVerticalParams,
+} from './blur/index.js';
+export {tint} from './tint.js';
+export type {TintParams} from './tint.js';
+export {wave} from './wave.js';
+export type {WaveParams} from './wave.js';
diff --git a/packages/canvas-effects/src/tint.ts b/packages/canvas-effects/src/tint.ts
new file mode 100644
index 0000000000..b64e9728f3
--- /dev/null
+++ b/packages/canvas-effects/src/tint.ts
@@ -0,0 +1,40 @@
+import {createDescriptor, defineEffect} from 'remotion';
+
+export type TintParams = {
+ readonly color: string;
+ readonly amount?: number;
+};
+
+const tintDef = defineEffect<TintParams, null>({
+ type: 'remotion/tint',
+ backend: '2d',
+ setup: () => null,
+ apply: ({source, target, width, height, params}) => {
+ const ctx = target.getContext('2d');
+ if (!ctx) {
+ return;
+ }
+
+ const amount = Math.max(0, Math.min(1, params.amount ?? 0.5));
+
+ ctx.clearRect(0, 0, width, height);
+ ctx.globalAlpha = 1;
+ ctx.globalCompositeOperation = 'source-over';
+ ctx.drawImage(source, 0, 0, width, height);
+
+ // `source-atop` only paints inside non-transparent regions of the source,
+ // so the tint respects the source's alpha mask.
+ ctx.globalAlpha = amount;
+ ctx.globalCompositeOperation = 'source-atop';
+ ctx.fillStyle = params.color;
+ ctx.fillRect(0, 0, width, height);
+
+ ctx.globalAlpha = 1;
+ ctx.globalCompositeOperation = 'source-over';
+ },
+});
+
+// Tints the source with a flat color. `amount` controls the blend strength
+// (0 = no tint, 1 = full color over opaque pixels). Operates on the 2D
+// backend; tinting respects the source's alpha mask.
+export const tint = (params: TintParams) => createDescriptor(tintDef, params);
diff --git a/packages/canvas-effects/src/wave.ts b/packages/canvas-effects/src/wave.ts
new file mode 100644
index 0000000000..1d47640634
--- /dev/null
+++ b/packages/canvas-effects/src/wave.ts
@@ -0,0 +1,67 @@
+import {createDescriptor, defineEffect} from 'remotion';
+
+export type WaveParams = {
+ readonly amplitude?: number;
+ readonly wavelength?: number;
+ readonly speed?: number;
+ readonly sliceWidth?: number;
+ readonly background?: string;
+};
+
+type WaveResolved = {
+ amplitude: number;
+ wavelength: number;
+ speed: number;
+ sliceWidth: number;
+ background: string;
+};
+
+const resolve = (p: WaveParams): WaveResolved => ({
+ amplitude: p.amplitude ?? 60,
+ wavelength: p.wavelength ?? 240,
+ speed: p.speed ?? 1 / 6,
+ sliceWidth: p.sliceWidth ?? 4,
+ background: p.background ?? 'transparent',
+});
+
+const waveDef = defineEffect<WaveParams, null>({
+ type: 'remotion/wave',
+ backend: '2d',
+ setup: () => null,
+ apply: ({source, target, frame, width, height, params}) => {
+ const ctx = target.getContext('2d');
+ if (!ctx) {
+ return;
+ }
+
+ const r = resolve(params);
+
+ ctx.clearRect(0, 0, width, height);
+ if (r.background !== 'transparent') {
+ ctx.fillStyle = r.background;
+ ctx.fillRect(0, 0, width, height);
+ }
+
+ for (let x = 0; x < width; x += r.sliceWidth) {
+ const offset =
+ Math.sin((x / r.wavelength) * Math.PI * 2 + frame * r.speed) *
+ r.amplitude;
+ ctx.drawImage(
+ source,
+ x,
+ 0,
+ r.sliceWidth,
+ height,
+ x,
+ offset,
+ r.sliceWidth,
+ height,
+ );
+ }
+ },
+});
+
+// Vertical-displacement wave effect: shifts vertical slices of the source
+// up/down with a sine wave that animates over time. Operates on the 2D backend.
+export const wave = (params: WaveParams = {}) =>
+ createDescriptor(waveDef, params);
diff --git a/packages/canvas-effects/tsconfig.json b/packages/canvas-effects/tsconfig.json
new file mode 100644
index 0000000000..949f1fdbf5
--- /dev/null
+++ b/packages/canvas-effects/tsconfig.json
@@ -0,0 +1,13 @@
+{
+ "extends": "../tsconfig.settings.json",
+ "compilerOptions": {
+ "rootDir": "./src",
+ "outDir": "./dist"
+ },
+ "include": ["src"],
+ "references": [
+ {
+ "path": "../core"
+ }
+ ]
+}
diff --git a/packages/docs/docs/canvas-effects/blur.mdx b/packages/docs/docs/canvas-effects/blur.mdx
new file mode 100644
index 0000000000..31396b0a35
--- /dev/null
+++ b/packages/docs/docs/canvas-effects/blur.mdx
@@ -0,0 +1,39 @@
+---
+image: /generated/articles-docs-canvas-effects-blur.png
+title: blur()
+crumb: '@remotion/canvas-effects'
+---
+
+# blur()<AvailableFrom v="4.0.452" />
+
+A WebGL2 [canvas effect](/docs/canvas-effects) that applies a separable Gaussian blur to the source. Returns a tuple of `[horizontal, vertical]` passes; the chain runtime flattens the array automatically.
+
+```tsx twoslash title="src/BlurDemo.tsx"
+import {blur} from '@remotion/canvas-effects';
+import {Solid} from 'remotion';
+
+export const BlurDemo = () => (
+ <Solid color="hotpink" width={1920} height={1080} effects={[blur({radius: 24})]} />
+);
+```
+
+The blur uses a 9-tap Gaussian kernel. Sample stride scales with `radius` so the kernel always spans approximately ±`radius` pixels; sigma is set to `radius / 3`.
+
+## Parameters
+
+### radius
+
+Blur radius in pixels. Higher values produce a softer image. The same radius is used for both passes.
+
+## Single-axis variants
+
+If you only need a one-dimensional blur, the individual passes are exported separately:
+
+- `blurHorizontal({radius})`
+- `blurVertical({radius})`
+
+## See also
+
+- [Canvas effects overview](/docs/canvas-effects)
+- [`wave()`](/docs/canvas-effects/wave)
+- [`tint()`](/docs/canvas-effects/tint)
diff --git a/packages/docs/docs/canvas-effects/define-effect.mdx b/packages/docs/docs/canvas-effects/define-effect.mdx
new file mode 100644
index 0000000000..e16ef6070d
--- /dev/null
+++ b/packages/docs/docs/canvas-effects/define-effect.mdx
@@ -0,0 +1,127 @@
+---
+image: /generated/articles-docs-canvas-effects-define-effect.png
+title: defineEffect()
+crumb: 'Canvas effects'
+---
+
+# defineEffect()<AvailableFrom v="4.0.452" />
+
+Helper for declaring a [canvas effect](/docs/canvas-effects). Wrapping a definition in `defineEffect()` does not change its runtime behavior — it only enables type inference for the parameter and state generics.
+
+```tsx twoslash title="src/effects/identity.ts"
+import {defineEffect, createDescriptor} from 'remotion';
+
+const identityDef = defineEffect<{}, null>({
+ type: 'remotion-docs/identity',
+ backend: '2d',
+ setup: () => null,
+ apply: ({source, target, width, height}) => {
+ const ctx = target.getContext('2d');
+ if (!ctx) {
+ return;
+ }
+
+ ctx.clearRect(0, 0, width, height);
+ ctx.drawImage(source, 0, 0, width, height);
+ },
+});
+
+export const identity = () => createDescriptor(identityDef, {});
+```
+
+## Definition fields
+
+### type
+
+A unique string identifier. Used in error messages and dev-tools; not used for caching.
+
+### backend
+
+One of `'2d' | 'webgl2' | 'webgpu'`. Determines which kind of context the runtime hands you in `target.getContext(...)`.
+
+### setup
+
+`(target: HTMLCanvasElement) => S | Promise<S>`
+
+Called once per effect identity, per chain. Use it to compile shaders, allocate textures, or upload static buffers. The returned value is passed back to `apply()` as `state`.
+
+The runtime caches the returned state in a `WeakMap<EffectDefinition, ...>`, so re-rendering does not re-run setup. The cache is invalidated only when the chain unmounts or the canvas dimensions change.
+
+### apply
+
+`(params: EffectApplyParams<P, S>) => void | Promise<void>`
+
+Called every frame. Receives:
+
+#### source
+
+A `CanvasImageSource` containing the input image (the output of the previous effect, or the source component's image for the first effect in the chain).
+
+#### target
+
+The `HTMLCanvasElement` to draw the output into. The runtime owns this canvas; the effect must not hold a reference to it across frames.
+
+#### state
+
+The value returned from `setup()`.
+
+#### params
+
+The parameters passed in the [`createDescriptor()`](#createdescriptor) call.
+
+#### frame
+
+The current frame number, equivalent to [`useCurrentFrame()`](/docs/use-current-frame).
+
+#### width / height / pixelRatio
+
+The chain's dimensions and the host's pixel ratio.
+
+#### gpuDevice
+
+A `GPUDevice` if any effect in the chain uses the `'webgpu'` backend, otherwise `null`. The type is `unknown` to avoid pulling `@webgpu/types` into core; cast it at the use site.
+
+### cleanup?
+
+`(state: S) => void`
+
+Called when the chain unmounts. Use it to free GPU resources allocated in `setup()`. Optional.
+
+## createDescriptor()
+
+Pairs a definition with a set of parameters to produce an `EffectDescriptor` that can be passed to a source component's `effects` prop.
+
+```ts twoslash
+import {defineEffect, createDescriptor} from 'remotion';
+
+const identityDef = defineEffect<{}, null>({
+ type: 'remotion-docs/identity',
+ backend: '2d',
+ setup: () => null,
+ apply: () => undefined,
+});
+// ---cut---
+const descriptor = createDescriptor(identityDef, {});
+```
+
+Effect authors typically expose a thin wrapper:
+
+```ts twoslash
+import {defineEffect, createDescriptor} from 'remotion';
+
+type WaveParams = {amplitude: number};
+const waveDef = defineEffect<WaveParams, null>({
+ type: 'remotion-docs/wave',
+ backend: '2d',
+ setup: () => null,
+ apply: () => undefined,
+});
+// ---cut---
+export const wave = (params: WaveParams) => createDescriptor(waveDef, params);
+```
+
+## See also
+
+- [`<Solid>`](/docs/solid)
+- [`<Experimental.HtmlInCanvas>`](/docs/canvas-effects/html-in-canvas)
+- [Canvas effects overview](/docs/canvas-effects)
diff --git a/packages/docs/docs/canvas-effects/html-in-canvas.mdx b/packages/docs/docs/canvas-effects/html-in-canvas.mdx
new file mode 100644
index 0000000000..09d2209ed9
--- /dev/null
+++ b/packages/docs/docs/canvas-effects/html-in-canvas.mdx
@@ -0,0 +1,88 @@
+---
+image: /generated/articles-docs-canvas-effects-html-in-canvas.png
+title: <Experimental.HtmlInCanvas>
+crumb: 'Canvas effects'
+---
+
+# &lt;Experimental.HtmlInCanvas&gt;<AvailableFrom v="4.0.452" />
+
+<ExperimentalBadge>
+<p>
+This component depends on the experimental{' '}
+<a href="https://github.com/WICG/html-in-canvas">WICG html-in-canvas</a> proposal,
+which currently requires Chrome Canary with{' '}
+<code>chrome://flags/#canvas-draw-element</code> enabled. Composition rendering
+will fail with a clear error in any other environment.
+</p>
+</ExperimentalBadge>
+
+A [canvas-effect source](/docs/canvas-effects) that rasterizes its DOM children into a canvas using the WICG `html-in-canvas` proposal. The captured DOM image then flows through an [effect chain](/docs/canvas-effects).
+
+```tsx twoslash title="src/HtmlInCanvasDemo.tsx"
+import {wave} from '@remotion/canvas-effects';
+import {AbsoluteFill, Experimental, useVideoConfig} from 'remotion';
+
+export const HtmlInCanvasDemo = () => {
+ const {width, height} = useVideoConfig();
+
+ return (
+ <AbsoluteFill style={{backgroundColor: 'black'}}>
+ <Experimental.HtmlInCanvas
+ width={width}
+ height={height}
+ effects={[wave({amplitude: 60, wavelength: 240})]}
+ >
+ <div
+ style={{
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ width: '100%',
+ height: '100%',
+ color: 'white',
+ fontSize: 96,
+ }}
+ >
+ Hello!
+ </div>
+ </Experimental.HtmlInCanvas>
+ </AbsoluteFill>
+ );
+};
+```
+
+## Props
+
+### width
+
+Width of the output canvas, in pixels.
+
+### height
+
+Height of the output canvas, in pixels.
+
+### children
+
+The DOM subtree to rasterize. Rendered inside a wrapper `<div>` sized to `width`/`height` so children can use `width: 100%`/`height: 100%`. The wrapper is itself a child of the source `<canvas>`, whose `layoutSubtree` flag is set so children participate in layout and paint.
+
+### effects?
+
+An array of [`EffectDescriptor`](/docs/canvas-effects/define-effect) values. See [`<Solid>`](/docs/solid) for details on the `effects` prop.
+
+### className?
+
+Forwarded to the visible output `<canvas>`.
+
+### style?
+
+Forwarded to the visible output `<canvas>`.
+
+### pixelRatio?
+
+Forwarded to effects as `pixelRatio` in `EffectApplyParams`. Default `1`.
+
+## See also
+
+- [Canvas effects overview](/docs/canvas-effects)
+- [`<Solid>`](/docs/solid)
+- [`defineEffect()`](/docs/canvas-effects/define-effect)
diff --git a/packages/docs/docs/canvas-effects/index.mdx b/packages/docs/docs/canvas-effects/index.mdx
new file mode 100644
index 0000000000..d10ad2039e
--- /dev/null
+++ b/packages/docs/docs/canvas-effects/index.mdx
@@ -0,0 +1,107 @@
+---
+image: /generated/articles-docs-canvas-effects-index.png
+title: 'Canvas effects'
+crumb: 'Canvas effects'
+---
+
+# Canvas effects<AvailableFrom v="4.0.452" />
+
+Canvas effects let you build After Effects–style per-pixel transformations directly on a `<canvas>`, composing 2D, WebGL2, and (in the future) WebGPU passes inside a single chain.
+
+The system has two layers:
+
+- The runtime, source components ([`<Solid>`](/docs/solid), [`<Experimental.HtmlInCanvas>`](/docs/canvas-effects/html-in-canvas)), and the [`defineEffect()`](/docs/canvas-effects/define-effect) helper ship inside `remotion`.
+- Sample effects ([`wave`](/docs/canvas-effects/wave), [`tint`](/docs/canvas-effects/tint), [`blur`](/docs/canvas-effects/blur)) ship inside [`@remotion/canvas-effects`](/docs/canvas-effects).
+
+## Installation
+
+The runtime is part of `remotion` itself — there is nothing extra to install if all you need is the source components and `defineEffect()`.
+
+To use the bundled sample effects, install [`@remotion/canvas-effects`](https://www.npmjs.com/package/@remotion/canvas-effects):
+
+import Tabs from '@theme/Tabs';
+import TabItem from '@theme/TabItem';
+
+<Tabs
+defaultValue="npm"
+values={[
+{ label: 'npm', value: 'npm' },
+{ label: 'pnpm', value: 'pnpm' },
+{ label: 'yarn', value: 'yarn' },
+]}>
+<TabItem value="npm">
+
+```bash
+npm i @remotion/canvas-effects
+```
+
+ </TabItem>
+ <TabItem value="pnpm">
+
+```bash
+pnpm i @remotion/canvas-effects
+```
+
+ </TabItem>
+ <TabItem value="yarn">
+
+```bash
+yarn add @remotion/canvas-effects
+```
+
+ </TabItem>
+</Tabs>
+
+Align the version with `remotion` and any other `@remotion/*` packages.
+
+## Concepts
+
+### Source components
+
+A source component owns a chain. It produces a `CanvasImageSource` (the input image) for every frame and renders the chain output into a visible `<canvas>`. The first source components are:
+
+- [`<Solid>`](/docs/solid) — a flat-color source.
+- [`<Experimental.HtmlInCanvas>`](/docs/canvas-effects/html-in-canvas) — rasterizes DOM children into a canvas via the [WICG `html-in-canvas` proposal](https://github.com/WICG/html-in-canvas).
+
+### Effects
+
+An effect is a description of how to transform an input image into an output image. Each effect targets a single backend (`'2d'`, `'webgl2'`, or `'webgpu'`) and defines `setup`, `apply`, and (optionally) `cleanup` lifecycle hooks. Authors declare effects with [`defineEffect()`](/docs/canvas-effects/define-effect).
+
+Effects are passed into a source component as an array via the `effects` prop:
+
+```tsx twoslash title="src/Demo.tsx"
+import {blur, tint} from '@remotion/canvas-effects';
+import {Solid} from 'remotion';
+
+export const Demo = () => (
+ <Solid
+ color="hotpink"
+ width={1920}
+ height={1080}
+ effects={[blur({radius: 24}), tint({color: 'cyan', amount: 0.4})]}
+ />
+);
+```
+
+### Chain semantics
+
+The chain runtime processes effects sequentially. Adjacent effects sharing the same backend are grouped into a single "run" and ping-ponged between two scratch canvases. Between runs, the runtime transfers the intermediate image via `createImageBitmap()` so the next backend can sample it.
+
+The runtime owns one `delayRender()`/`continueRender()` pair per frame and per chain.
+
+### Alpha and color space
+
+All scratch canvases use **premultiplied alpha** and **sRGB** storage. Effects that perform color math in linear space must convert to/from sRGB themselves. Source components write their input image in this format; the runtime preserves it through every transition.
+
+## API
+
+- [`<Solid>`](/docs/solid)
+- [`<Experimental.HtmlInCanvas>`](/docs/canvas-effects/html-in-canvas)
+- [`defineEffect()`](/docs/canvas-effects/define-effect)
+- [`wave()`](/docs/canvas-effects/wave)
+- [`tint()`](/docs/canvas-effects/tint)
+- [`blur()`](/docs/canvas-effects/blur)
+
+## License
+
+MIT
diff --git a/packages/docs/docs/canvas-effects/tint.mdx b/packages/docs/docs/canvas-effects/tint.mdx
new file mode 100644
index 0000000000..484bbaa0d9
--- /dev/null
+++ b/packages/docs/docs/canvas-effects/tint.mdx
@@ -0,0 +1,39 @@
+---
+image: /generated/articles-docs-canvas-effects-tint.png
+title: tint()
+crumb: '@remotion/canvas-effects'
+---
+
+# tint()<AvailableFrom v="4.0.452" />
+
+A 2D [canvas effect](/docs/canvas-effects) that overlays a flat color onto the source. The tint respects the source's alpha mask via `globalCompositeOperation: 'source-atop'`.
+
+```tsx twoslash title="src/TintDemo.tsx"
+import {tint} from '@remotion/canvas-effects';
+import {Solid} from 'remotion';
+
+export const TintDemo = () => (
+ <Solid
+ color="hotpink"
+ width={1920}
+ height={1080}
+ effects={[tint({color: 'cyan', amount: 0.5})]}
+ />
+);
+```
+
+## Parameters
+
+### color
+
+The CSS color to overlay onto the source.
+
+### amount?
+
+Blend strength between `0` (no tint) and `1` (full color over opaque pixels). Values are clamped. Default `0.5`.
+
+## See also
+
+- [Canvas effects overview](/docs/canvas-effects)
+- [`wave()`](/docs/canvas-effects/wave)
+- [`blur()`](/docs/canvas-effects/blur)
diff --git a/packages/docs/docs/canvas-effects/wave.mdx b/packages/docs/docs/canvas-effects/wave.mdx
new file mode 100644
index 0000000000..fd36135222
--- /dev/null
+++ b/packages/docs/docs/canvas-effects/wave.mdx
@@ -0,0 +1,51 @@
+---
+image: /generated/articles-docs-canvas-effects-wave.png
+title: wave()
+crumb: '@remotion/canvas-effects'
+---
+
+# wave()<AvailableFrom v="4.0.452" />
+
+A 2D [canvas effect](/docs/canvas-effects) that shifts vertical slices of the source up and down with an animated sine wave.
+
+```tsx twoslash title="src/WaveDemo.tsx"
+import {wave} from '@remotion/canvas-effects';
+import {Solid} from 'remotion';
+
+export const WaveDemo = () => (
+ <Solid
+ color="white"
+ width={1920}
+ height={1080}
+ effects={[wave({amplitude: 60, wavelength: 240})]}
+ />
+);
+```
+
+## Parameters
+
+### amplitude?
+
+Maximum vertical displacement in pixels. Default `60`.
+
+### wavelength?
+
+Horizontal period of the wave, in pixels. Default `240`.
+
+### speed?
+
+Per-frame phase increment, in radians. Default `1 / 6` (≈9.5° per frame).
+
+### sliceWidth?
+
+Width of each vertical slice, in pixels. Smaller values produce smoother curves at the cost of more draw calls. Default `4`.
+
+### background?
+
+CSS color for the background fill drawn before the slices. Default `'transparent'` (no fill).
+
+## See also
+
+- [Canvas effects overview](/docs/canvas-effects)
+- [`tint()`](/docs/canvas-effects/tint)
+- [`blur()`](/docs/canvas-effects/blur)
diff --git a/packages/docs/docs/solid.mdx b/packages/docs/docs/solid.mdx
new file mode 100644
index 0000000000..6393d2e86f
--- /dev/null
+++ b/packages/docs/docs/solid.mdx
@@ -0,0 +1,56 @@
+---
+image: /generated/articles-docs-solid.png
+title: <Solid>
+crumb: 'Canvas effects'
+---
+
+# &lt;Solid&gt;<AvailableFrom v="4.0.452" />
+
+A flat-color [canvas-effect source](/docs/canvas-effects). Useful as a procedural input to a chain of [effects](/docs/canvas-effects/define-effect).
+
+```tsx twoslash title="src/SolidDemo.tsx"
+import {blur} from '@remotion/canvas-effects';
+import {Solid} from 'remotion';
+
+export const SolidDemo = () => (
+ <Solid color="hotpink" width={1920} height={1080} effects={[blur({radius: 24})]} />
+);
+```
+
+## Props
+
+### color
+
+A CSS color string used to fill the source canvas. Any value the 2D context accepts is allowed.
+
+### width
+
+Width of the visible output canvas, in pixels.
+
+### height
+
+Height of the visible output canvas, in pixels.
+
+### effects?
+
+An array of [`EffectDescriptor`](/docs/canvas-effects/define-effect) values. Adjacent same-backend effects are grouped and ping-ponged between scratch canvases. Defaults to `[]`, in which case the source color is drawn directly into the output.
+
+You may also pass nested arrays — e.g. `[blur({radius: 12})]` returns a `[horizontal, vertical]` pair. The runtime calls `.flat()` once before processing.
+
+### className?
+
+Forwarded to the underlying `<canvas>`.
+
+### style?
+
+Forwarded to the underlying `<canvas>`.
+
+### pixelRatio?
+
+Forwarded to effects as `pixelRatio` in `EffectApplyParams`. Default `1`.
+
+## See also
+
+- [Canvas effects overview](/docs/canvas-effects)
+- [`defineEffect()`](/docs/canvas-effects/define-effect)
+- [`<Experimental.HtmlInCanvas>`](/docs/canvas-effects/html-in-canvas)
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index fe844d5996..fcf3ae3a8e 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -229,6 +229,22 @@ const sidebars: SidebarsConfig = {
'captions/create-tiktok-style-captions',
],
},
+ {
+ type: 'category',
+ label: 'Canvas effects',
+ link: {
+ type: 'doc',
+ id: 'canvas-effects/index',
+ },
+ items: [
+ 'solid',
+ 'canvas-effects/html-in-canvas',
+ 'canvas-effects/define-effect',
+ 'canvas-effects/wave',
+ 'canvas-effects/tint',
+ 'canvas-effects/blur',
+ ],
+ },
{
type: 'category',
label: '@remotion/cloudrun',
diff --git a/packages/example/package.json b/packages/example/package.json
index 3ac8eff956..39ecdabac6 100644
--- a/packages/example/package.json
+++ b/packages/example/package.json
@@ -39,6 +39,7 @@
"@remotion/animation-utils": "workspace:*",
"@remotion/babel-loader": "workspace:*",
"@remotion/bundler": "workspace:*",
+ "@remotion/canvas-effects": "workspace:*",
"@remotion/captions": "workspace:*",
"@remotion/cli": "workspace:*",
"@remotion/cloudrun": "workspace:*",
diff --git a/packages/example/src/CanvasEffects/SolidDemo.tsx b/packages/example/src/CanvasEffects/SolidDemo.tsx
new file mode 100644
index 0000000000..783b3034a0
--- /dev/null
+++ b/packages/example/src/CanvasEffects/SolidDemo.tsx
@@ -0,0 +1,39 @@
+import {blur, tint} from '@remotion/canvas-effects';
+import React from 'react';
+import {
+ AbsoluteFill,
+ interpolate,
+ Solid,
+ useCurrentFrame,
+ useVideoConfig,
+} from 'remotion';
+
+// Demonstrates the canvas-effect chain with `<Solid>` as the source. The chain
+// runs a separable Gaussian blur (WebGL2) followed by a tint pass (2D),
+// exercising the runtime's cross-backend transfer (createImageBitmap) inside
+// a single chain.
+export const SolidEffectsDemo: React.FC = () => {
+ const frame = useCurrentFrame();
+ const {width, height, durationInFrames} = useVideoConfig();
+
+ const radius = interpolate(frame, [0, durationInFrames - 1], [8, 64], {
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ });
+
+ const tintAmount = interpolate(frame, [0, durationInFrames - 1], [0.1, 0.6], {
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ });
+
+ return (
+ <AbsoluteFill style={{backgroundColor: 'black'}}>
+ <Solid
+ color="hotpink"
+ width={width}
+ height={height}
+ effects={[blur({radius}), tint({color: 'cyan', amount: tintAmount})]}
+ />
+ </AbsoluteFill>
+ );
+};
diff --git a/packages/example/src/HtmlInCanvas/apply-wave-effect.ts b/packages/example/src/HtmlInCanvas/apply-wave-effect.ts
deleted file mode 100644
index ee2554f865..0000000000
--- a/packages/example/src/HtmlInCanvas/apply-wave-effect.ts
+++ /dev/null
@@ -1,39 +0,0 @@
-import type {ApplyCanvasEffect} from './html-in-canvas';
-
-// Apply a vertical wave effect: shift columns of the captured image up and
-// down with a sine wave that moves over time.
-export const applyWaveEffect: ApplyCanvasEffect = ({
- source,
- target,
- frame,
- width,
- height,
-}) => {
- const ctx = target.getContext('2d');
- if (!ctx) {
- return;
- }
-
- ctx.fillStyle = 'black';
- ctx.fillRect(0, 0, width, height);
-
- const sliceWidth = 4;
- const amplitude = 60;
- const wavelength = 240;
-
- for (let x = 0; x < width; x += sliceWidth) {
- const offset =
- Math.sin((x / wavelength) * Math.PI * 2 + frame / 6) * amplitude;
- ctx.drawImage(
- source,
- x,
- 0,
- sliceWidth,
- height,
- x,
- offset,
- sliceWidth,
- height,
- );
- }
-};
diff --git a/packages/example/src/HtmlInCanvas/html-in-canvas.tsx b/packages/example/src/HtmlInCanvas/html-in-canvas.tsx
deleted file mode 100644
index efc8ed3037..0000000000
--- a/packages/example/src/HtmlInCanvas/html-in-canvas.tsx
+++ /dev/null
@@ -1,187 +0,0 @@
-import React, {useEffect, useRef} from 'react';
-import {
- cancelRender,
- continueRender,
- delayRender,
- useCurrentFrame,
-} from 'remotion';
-
-// Type augmentation for the WICG html-in-canvas proposal:
-// https://github.com/WICG/html-in-canvas
-//
-// Requires Chrome Canary with chrome://flags/#canvas-draw-element enabled, so
-// that both drawElementImage() and canvas.requestPaint() are available.
-//
-// The current Chromium implementation requires the element passed to
-// drawElementImage() to be an immediate child of the canvas, and the canvas
-// must have its `layoutSubtree` property set to true so the children are
-// actually laid out (instead of being treated as fallback content).
-type Canvas2DWithDrawElement = CanvasRenderingContext2D & {
- drawElementImage: (
- element: Element,
- dx: number,
- dy: number,
- dwidth: number,
- dheight: number,
- ) => DOMMatrix;
-};
-
-type HTMLCanvasWithLayoutSubtree = HTMLCanvasElement & {
- layoutSubtree?: boolean;
- requestPaint: () => void;
-};
-
-const isHtmlInCanvasSupported = () => {
- if (typeof document === 'undefined') {
- return false;
- }
-
- const canvas = document.createElement(
- 'canvas',
- ) as HTMLCanvasWithLayoutSubtree;
- const ctx = canvas.getContext('2d') as Canvas2DWithDrawElement | null;
- return (
- typeof ctx?.drawElementImage === 'function' &&
- typeof canvas.requestPaint === 'function'
- );
-};
-
-export type ApplyCanvasEffect = (params: {
- source: HTMLCanvasElement;
- target: HTMLCanvasElement;
- frame: number;
- width: number;
- height: number;
-}) => void;
-
-export const HtmlInCanvas: React.FC<{
- readonly width: number;
- readonly height: number;
- readonly applyEffect: ApplyCanvasEffect;
- readonly children: React.ReactNode;
-}> = ({width, height, applyEffect, children}) => {
- const frame = useCurrentFrame();
-
- const sourceCanvasRef = useRef<HTMLCanvasElement | null>(null);
- const sceneRef = useRef<HTMLDivElement | null>(null);
- const outputCanvasRef = useRef<HTMLCanvasElement | null>(null);
-
- // Mark the source canvas as a layoutSubtree root once on mount so its
- // child <div ref={sceneRef}> participates in layout/paint and can be
- // captured via drawElementImage().
- useEffect(() => {
- if (!isHtmlInCanvasSupported()) {
- cancelRender(
- new Error(
- 'HTML in Canvas is not supported. Open this page in Chrome Canary with chrome://flags/#canvas-draw-element enabled.',
- ),
- );
- return;
- }
-
- const sourceCanvas =
- sourceCanvasRef.current as HTMLCanvasWithLayoutSubtree | null;
- if (!sourceCanvas) {
- return;
- }
-
- sourceCanvas.layoutSubtree = true;
- }, []);
-
- useEffect(() => {
- const sourceCanvas =
- sourceCanvasRef.current as HTMLCanvasWithLayoutSubtree | null;
- const sceneEl = sceneRef.current;
- const outputCanvas = outputCanvasRef.current;
- if (!sourceCanvas || !sceneEl || !outputCanvas) {
- return;
- }
-
- const ctx = sourceCanvas.getContext('2d') as Canvas2DWithDrawElement | null;
- if (!ctx) {
- return;
- }
-
- const handle = delayRender(`Painting HTML in canvas (frame ${frame})`);
- let resolved = false;
- let cancelled = false;
-
- const capture = () => {
- if (cancelled) {
- return;
- }
-
- try {
- ctx.reset();
- ctx.drawElementImage(sceneEl, 0, 0, width, height);
-
- applyEffect({
- source: sourceCanvas,
- target: outputCanvas,
- frame,
- width,
- height,
- });
-
- resolved = true;
- continueRender(handle);
- } catch (err) {
- resolved = true;
- cancelRender(err as Error);
- }
- };
-
- const onPaint = () => {
- sourceCanvas.removeEventListener('paint', onPaint);
- capture();
- };
-
- sourceCanvas.addEventListener('paint', onPaint);
- sourceCanvas.requestPaint();
-
- return () => {
- cancelled = true;
- sourceCanvas.removeEventListener('paint', onPaint);
- if (!resolved) {
- continueRender(handle);
- }
- };
- }, [frame, width, height, applyEffect]);
-
- return (
- <>
- <canvas
- ref={sourceCanvasRef}
- width={width}
- height={height}
- style={{
- position: 'absolute',
- inset: 0,
- width,
- height,
- }}
- >
- <div
- ref={sceneRef}
- style={{
- width,
- height,
- }}
- >
- {children}
- </div>
- </canvas>
- <canvas
- ref={outputCanvasRef}
- width={width}
- height={height}
- style={{
- position: 'absolute',
- inset: 0,
- width,
- height,
- }}
- />
- </>
- );
-};
diff --git a/packages/example/src/HtmlInCanvas/index.tsx b/packages/example/src/HtmlInCanvas/index.tsx
index 14aa93c076..f9f0748fde 100644
--- a/packages/example/src/HtmlInCanvas/index.tsx
+++ b/packages/example/src/HtmlInCanvas/index.tsx
@@ -1,7 +1,11 @@
+import {wave} from '@remotion/canvas-effects';
import React from 'react';
-import {AbsoluteFill, useCurrentFrame, useVideoConfig} from 'remotion';
-import {applyWaveEffect} from './apply-wave-effect';
-import {HtmlInCanvas} from './html-in-canvas';
+import {
+ AbsoluteFill,
+ Experimental,
+ useCurrentFrame,
+ useVideoConfig,
+} from 'remotion';
const Scene: React.FC = () => {
const frame = useCurrentFrame();
@@ -40,9 +44,13 @@ export const HtmlInCanvasDemo: React.FC = () => {
return (
<AbsoluteFill style={{backgroundColor: 'black'}}>
- <HtmlInCanvas width={width} height={height} applyEffect={applyWaveEffect}>
+ <Experimental.HtmlInCanvas
+ width={width}
+ height={height}
+ effects={[wave({amplitude: 60, wavelength: 240})]}
+ >
<Scene />
- </HtmlInCanvas>
+ </Experimental.HtmlInCanvas>
</AbsoluteFill>
);
};
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsx
index 0fc032637a..adf1956132 100644
--- a/packages/example/src/Root.tsx
+++ b/packages/example/src/Root.tsx
@@ -16,6 +16,7 @@ import {NativeBufferStateForImage} from './BufferState/Image';
import {NativeBufferState} from './BufferState/Simple';
import {NativeBufferStateForVideo} from './BufferState/Video';
import {CancelRender} from './CancelRender';
+import {SolidEffectsDemo} from './CanvasEffects/SolidDemo';
import {ClassSerialization} from './ClassSerialization';
import {ColorInterpolation} from './ColorInterpolation';
import {ComplexSounds} from './ComplexSounds';
@@ -842,6 +843,14 @@ export const Index: React.FC = () => {
width={1920}
durationInFrames={120}
/>
+ <Composition
+ id="solid-effects"
+ component={SolidEffectsDemo}
+ fps={30}
+ height={1080}
+ width={1920}
+ durationInFrames={120}
+ />
<Composition
id="video-testing-webm"
component={VideoTesting}