Skip to content

🎥 Make videos programmatically with React

`@remotion/effects`: Add pixel dissolve effect (#7953)

Jonny Burger2b1d04fad1ca
diff --git a/packages/docs/components/effects-demos/registry.ts b/packages/docs/components/effects-demos/registry.ts
index 71ff88d097..f4936826c7 100644
--- a/packages/docs/components/effects-demos/registry.ts
+++ b/packages/docs/components/effects-demos/registry.ts
@@ -17,6 +17,7 @@ import {invert} from '@remotion/effects/invert';
import {lines} from '@remotion/effects/lines';
import {mirror} from '@remotion/effects/mirror';
import {noise} from '@remotion/effects/noise';
+import {pixelDissolve} from '@remotion/effects/pixel-dissolve';
import {saturation} from '@remotion/effects/saturation';
import {scale} from '@remotion/effects/scale';
import {scanlines} from '@remotion/effects/scanlines';
@@ -51,6 +52,7 @@ import {EffectsLightLeakPreview} from '../effects/effects-light-leak-preview';
import {EffectsLinesPreview} from '../effects/effects-lines-preview';
import {EffectsMirrorPreview} from '../effects/effects-mirror-preview';
import {EffectsNoisePreview} from '../effects/effects-noise-preview';
+import {EffectsPixelDissolvePreview} from '../effects/effects-pixel-dissolve-preview';
import {EffectsSaturationPreview} from '../effects/effects-saturation-preview';
import {EffectsScalePreview} from '../effects/effects-scale-preview';
import {EffectsScanlinesPreview} from '../effects/effects-scanlines-preview';
@@ -326,6 +328,14 @@ export const effectsDemos: EffectsDemoType[] = [
comp: EffectsHalftonePreview,
schema: halftone().definition.schema,
},
+ {
+ ...defaults,
+ id: 'effects-pixel-dissolve',
+ effectName: 'pixelDissolve',
+ effectImportPath: '@remotion/effects/pixel-dissolve',
+ comp: EffectsPixelDissolvePreview,
+ schema: pixelDissolve().definition.schema,
+ },
{
...defaults,
id: 'effects-halftone-linear-gradient',
diff --git a/packages/docs/components/effects/effects-pixel-dissolve-preview.tsx b/packages/docs/components/effects/effects-pixel-dissolve-preview.tsx
new file mode 100644
index 0000000000..fc20ae955e
--- /dev/null
+++ b/packages/docs/components/effects/effects-pixel-dissolve-preview.tsx
@@ -0,0 +1,30 @@
+import {pixelDissolve} from '@remotion/effects/pixel-dissolve';
+import React from 'react';
+import {CanvasImage} from 'remotion';
+import {EFFECTS_PREVIEW_IMAGE_SRC} from './effects-preview-image';
+
+export const EffectsPixelDissolvePreview: React.FC<{
+ readonly progress: number;
+ readonly columns: number;
+ readonly rows: number;
+ readonly seed: number;
+ readonly feather: number;
+}> = ({progress, columns, rows, seed, feather}) => {
+ return (
+ <CanvasImage
+ src={EFFECTS_PREVIEW_IMAGE_SRC}
+ width={1280}
+ height={720}
+ fit="cover"
+ effects={[
+ pixelDissolve({
+ progress,
+ columns,
+ rows,
+ seed,
+ feather,
+ }),
+ ]}
+ />
+ );
+};
diff --git a/packages/docs/docs/effects/pixel-dissolve.mdx b/packages/docs/docs/effects/pixel-dissolve.mdx
new file mode 100644
index 0000000000..8cc6495cf8
--- /dev/null
+++ b/packages/docs/docs/effects/pixel-dissolve.mdx
@@ -0,0 +1,83 @@
+---
+image: /generated/articles-docs-effects-pixel-dissolve.png
+slug: /effects/pixel-dissolve
+title: pixelDissolve()
+sidebar_label: pixelDissolve()
+crumb: '@remotion/effects'
+---
+
+# pixelDissolve()<AvailableFrom v="4.0.471" />
+
+_Part of the [`@remotion/effects`](/docs/effects/api) package._
+
+A pixel dissolve effect that divides the frame into a grid and fades the cells out in a pseudo-random order while preserving the source image color.
+
+## Preview
+
+<EffectsDemo type="effects-pixel-dissolve" />
+
+## Example
+
+```tsx twoslash title="MyComp.tsx"
+import {AbsoluteFill} from 'remotion';
+import {Video} from '@remotion/media';
+import {pixelDissolve} from '@remotion/effects/pixel-dissolve';
+
+export const MyComp: React.FC = () => {
+ return (
+ <AbsoluteFill>
+ <Video
+ src="https://remotion.media/video.mp4"
+ effects={[
+ pixelDissolve({
+ progress: 0.45,
+ columns: 10,
+ rows: 10,
+ seed: 0,
+ feather: 0.15,
+ }),
+ ]}
+ />
+ </AbsoluteFill>
+ );
+};
+```
+
+## API
+
+Pass an object with the following properties. You can also call `pixelDissolve()` without arguments.
+
+### `progress?`
+
+How far the dissolve has progressed, from `0` to `1`. Defaults to `0.5`.
+
+### `columns?`
+
+Horizontal divisions across the frame. Defaults to `10`. Must be an integer of at least `1`.
+
+### `rows?`
+
+Vertical divisions across the frame. Defaults to `10`. Must be an integer of at least `1`.
+
+### `seed?`
+
+Changes the random order of the blocks. Defaults to `0`.
+
+### `feather?`
+
+Softness of the dissolve edge from `0` (sharp) to `1` (fully feathered). Defaults to `0.15`.
+
+### `disabled?`
+
+When `true`, the effect is skipped. Defaults to `false`.
+
+## Requirements
+
+`pixelDissolve()` uses a WebGL2 backend. During renders, enable WebGL via [`Config.setChromiumOpenGlRenderer()`](/docs/config#setchromiumopenglrenderer) (for example `'angle'`). See [Using WebGL during renders](/docs/remotion/html-in-canvas#using-webgl-during-renders).
+
+## See also
+
+- [`@remotion/effects`](/docs/effects/api)
+- [`speckle()`](/docs/effects/speckle)
+- [`evolve()`](/docs/effects/evolve)
+- [Source code for this effect](https://github.com/remotion-dev/remotion/blob/main/packages/effects/src/pixel-dissolve.ts)
diff --git a/packages/docs/docs/effects/table-of-contents.tsx b/packages/docs/docs/effects/table-of-contents.tsx
index 485d6a303b..2e1955e137 100644
--- a/packages/docs/docs/effects/table-of-contents.tsx
+++ b/packages/docs/docs/effects/table-of-contents.tsx
@@ -202,6 +202,13 @@ const categories: {
name: 'halftone()',
description: 'Source-image halftone effect',
},
+ {
+ link: '/docs/effects/pixel-dissolve',
+ preview: '/img/effects-pixel-dissolve-preview.png',
+ alt: 'pixel dissolve effect preview',
+ name: 'pixelDissolve()',
+ description: 'Pixelated dissolve effect',
+ },
{
link: '/docs/effects/scanlines',
preview: '/img/effects-scanlines-preview.png',
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index 297d8559bc..33d13fc1c7 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -281,6 +281,7 @@ const sidebars: SidebarsConfig = {
'effects/grayscale',
'effects/halftone',
'effects/halftone-linear-gradient',
+ 'effects/pixel-dissolve',
'effects/hue',
'effects/dot-grid',
'effects/invert',
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 14b15cceab..8f6e15db39 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -1898,6 +1898,15 @@ export const articles = [
noAi: false,
slug: 'effects/noise',
},
+ {
+ id: 'effects/pixel-dissolve',
+ title: 'pixelDissolve()',
+ relativePath: 'docs/effects/pixel-dissolve.mdx',
+ compId: 'articles-docs-effects-pixel-dissolve',
+ crumb: '@remotion/effects',
+ noAi: false,
+ slug: 'effects/pixel-dissolve',
+ },
{
id: 'effects/saturation',
title: 'saturation()',
diff --git a/packages/docs/src/remotion/Root.tsx b/packages/docs/src/remotion/Root.tsx
index 2a0925c7b8..c304af2db3 100644
--- a/packages/docs/src/remotion/Root.tsx
+++ b/packages/docs/src/remotion/Root.tsx
@@ -22,6 +22,7 @@ import {EffectsLightLeakPreview} from '../../components/effects/effects-light-le
import {EffectsLinesPreview} from '../../components/effects/effects-lines-preview';
import {EffectsMirrorPreview} from '../../components/effects/effects-mirror-preview';
import {EffectsNoisePreview} from '../../components/effects/effects-noise-preview';
+import {EffectsPixelDissolvePreview} from '../../components/effects/effects-pixel-dissolve-preview';
import {EffectsSaturationPreview} from '../../components/effects/effects-saturation-preview';
import {EffectsScalePreview} from '../../components/effects/effects-scale-preview';
import {EffectsScanlinesPreview} from '../../components/effects/effects-scanlines-preview';
@@ -294,6 +295,19 @@ export const RemotionRoot: React.FC = () => {
invert: false,
}}
/>
+ <Still
+ id="effects-pixel-dissolve-preview"
+ component={EffectsPixelDissolvePreview}
+ width={1280}
+ height={720}
+ defaultProps={{
+ progress: 0.4,
+ columns: 12,
+ rows: 12,
+ seed: 0,
+ feather: 0.15,
+ }}
+ />
<Still
id="effects-halftone-linear-gradient-preview"
component={EffectsHalftoneLinearGradientPreview}
diff --git a/packages/docs/static/generated/articles-docs-effects-pixel-dissolve.png b/packages/docs/static/generated/articles-docs-effects-pixel-dissolve.png
new file mode 100644
index 0000000000..2b5c01c387
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-effects-pixel-dissolve.png differ
diff --git a/packages/docs/static/img/effects-pixel-dissolve-preview.png b/packages/docs/static/img/effects-pixel-dissolve-preview.png
new file mode 100644
index 0000000000..b13bf068e5
Binary files /dev/null and b/packages/docs/static/img/effects-pixel-dissolve-preview.png differ
diff --git a/packages/effects/bundle.ts b/packages/effects/bundle.ts
index dada80bdfa..2d086d0a65 100644
--- a/packages/effects/bundle.ts
+++ b/packages/effects/bundle.ts
@@ -22,6 +22,7 @@ const effectEntrypoints = [
'src/halftone.ts',
'src/hue.ts',
'src/dot-grid.ts',
+ 'src/pixel-dissolve.ts',
'src/invert.ts',
'src/lines.ts',
'src/mirror.ts',
diff --git a/packages/effects/package.json b/packages/effects/package.json
index abfc287705..1b2a9ff58b 100644
--- a/packages/effects/package.json
+++ b/packages/effects/package.json
@@ -94,6 +94,11 @@
"module": "./dist/esm/halftone-linear-gradient.mjs",
"import": "./dist/esm/halftone-linear-gradient.mjs"
},
+ "./pixel-dissolve": {
+ "types": "./dist/pixel-dissolve.d.ts",
+ "module": "./dist/esm/pixel-dissolve.mjs",
+ "import": "./dist/esm/pixel-dissolve.mjs"
+ },
"./grayscale": {
"types": "./dist/grayscale.d.ts",
"module": "./dist/esm/grayscale.mjs",
@@ -229,6 +234,9 @@
"halftone-linear-gradient": [
"dist/halftone-linear-gradient.d.ts"
],
+ "pixel-dissolve": [
+ "dist/pixel-dissolve.d.ts"
+ ],
"grayscale": [
"dist/grayscale.d.ts"
],
diff --git a/packages/effects/src/pixel-dissolve.ts b/packages/effects/src/pixel-dissolve.ts
new file mode 100644
index 0000000000..90d2e09011
--- /dev/null
+++ b/packages/effects/src/pixel-dissolve.ts
@@ -0,0 +1,370 @@
+import type {SequenceSchema} from 'remotion';
+import {Internals} from 'remotion';
+import {
+ assertOptionalFiniteNumber,
+ validateUnitInterval,
+} from './color-utils.js';
+import {assertEffectParamsObject} from './validate-effect-param.js';
+
+const {createEffect, createWebGL2ContextError} = Internals;
+
+const DEFAULT_PROGRESS = 0.5 as const;
+const DEFAULT_COLUMNS = 10 as const;
+const DEFAULT_ROWS = 10 as const;
+const DEFAULT_SEED = 0 as const;
+const DEFAULT_FEATHER = 0.15 as const;
+
+const pixelDissolveSchema = {
+ progress: {
+ type: 'number',
+ min: 0,
+ max: 1,
+ step: 0.01,
+ default: DEFAULT_PROGRESS,
+ description: 'Progress',
+ },
+ columns: {
+ type: 'number',
+ min: 1,
+ max: 400,
+ step: 1,
+ default: DEFAULT_COLUMNS,
+ description: 'Columns',
+ },
+ rows: {
+ type: 'number',
+ min: 1,
+ max: 400,
+ step: 1,
+ default: DEFAULT_ROWS,
+ description: 'Rows',
+ },
+ seed: {
+ type: 'number',
+ step: 1,
+ default: DEFAULT_SEED,
+ description: 'Seed',
+ },
+ feather: {
+ type: 'number',
+ min: 0,
+ max: 1,
+ step: 0.01,
+ default: DEFAULT_FEATHER,
+ description: 'Feather',
+ },
+} as const satisfies SequenceSchema;
+
+export type PixelDissolveParams = {
+ readonly progress?: number;
+ readonly columns?: number;
+ readonly rows?: number;
+ readonly seed?: number;
+ readonly feather?: number;
+};
+
+type PixelDissolveResolved = {
+ readonly progress: number;
+ readonly columns: number;
+ readonly rows: number;
+ readonly seed: number;
+ readonly feather: number;
+};
+
+const resolve = (params: PixelDissolveParams): PixelDissolveResolved => ({
+ progress: params.progress ?? DEFAULT_PROGRESS,
+ columns: params.columns ?? DEFAULT_COLUMNS,
+ rows: params.rows ?? DEFAULT_ROWS,
+ seed: params.seed ?? DEFAULT_SEED,
+ feather: params.feather ?? DEFAULT_FEATHER,
+});
+
+const assertOptionalIntegerNumber = (value: unknown, name: string): void => {
+ if (value === undefined) {
+ return;
+ }
+
+ if (!Number.isInteger(value)) {
+ throw new TypeError(
+ `"${name}" must be an integer, but got ${JSON.stringify(value)}`,
+ );
+ }
+};
+
+const validatePixelDissolveParams = (params: PixelDissolveParams): void => {
+ assertEffectParamsObject(params, 'Pixel Dissolve');
+ assertOptionalFiniteNumber(params.progress, 'progress');
+ assertOptionalFiniteNumber(params.columns, 'columns');
+ assertOptionalFiniteNumber(params.rows, 'rows');
+ assertOptionalFiniteNumber(params.seed, 'seed');
+ assertOptionalFiniteNumber(params.feather, 'feather');
+ assertOptionalIntegerNumber(params.columns, 'columns');
+ assertOptionalIntegerNumber(params.rows, 'rows');
+
+ const r = resolve(params);
+ validateUnitInterval(r.progress, 'progress');
+ validateUnitInterval(r.feather, 'feather');
+
+ if (r.columns < 1) {
+ throw new TypeError(
+ `"columns" must be >= 1, but got ${JSON.stringify(r.columns)}`,
+ );
+ }
+
+ if (r.rows < 1) {
+ throw new TypeError(
+ `"rows" must be >= 1, but got ${JSON.stringify(r.rows)}`,
+ );
+ }
+};
+
+type PixelDissolveState = {
+ readonly gl: WebGL2RenderingContext;
+ readonly program: WebGLProgram;
+ readonly vao: WebGLVertexArrayObject;
+ readonly vbo: WebGLBuffer;
+ readonly texture: WebGLTexture;
+ readonly uSource: WebGLUniformLocation | null;
+ readonly uProgress: WebGLUniformLocation | null;
+ readonly uColumns: WebGLUniformLocation | null;
+ readonly uRows: WebGLUniformLocation | null;
+ readonly uSeed: WebGLUniformLocation | null;
+ readonly uFeather: WebGLUniformLocation | null;
+};
+
+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 float uProgress;
+uniform float uColumns;
+uniform float uRows;
+uniform float uSeed;
+uniform float uFeather;
+
+float hash21(vec2 p) {
+ vec3 p3 = fract(vec3(p.xyx) * vec3(443.8975, 397.2973, 491.1871));
+ p3 += dot(p3, p3.yzx + 19.19);
+ return fract((p3.x + p3.y) * p3.z);
+}
+
+float dissolveMask(float noise, float threshold, float feather) {
+ float edge = max(feather, 0.0);
+ if (edge <= 0.0001) {
+ return step(noise, threshold);
+ }
+
+ return 1.0 - smoothstep(threshold, min(threshold + edge, 1.0), noise);
+}
+
+void main() {
+ vec2 divisions = max(vec2(uColumns, uRows), vec2(1.0));
+ vec2 gridUv = min(vUv, vec2(1.0) - vec2(0.000001));
+ vec2 cell = floor(gridUv * divisions);
+ vec4 color = texture(uSource, vUv);
+
+ float threshold = 1.0 - clamp(uProgress, 0.0, 1.0);
+ float noise = hash21(cell + vec2(uSeed, uSeed * 1.618));
+ float mask = dissolveMask(noise, threshold, uFeather);
+
+ fragColor = vec4(color.rgb * mask, color.a * mask);
+}
+`;
+
+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(
+ `Pixel Dissolve 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(`Pixel Dissolve program link failed: ${log ?? '(no log)'}`);
+ }
+
+ return program;
+};
+
+const createFullscreenQuad = (
+ gl: WebGL2RenderingContext,
+): {
+ readonly vao: WebGLVertexArrayObject;
+ readonly vbo: WebGLBuffer;
+} => {
+ const vao = gl.createVertexArray();
+ if (!vao) {
+ throw new Error('Failed to create WebGL vertex array');
+ }
+
+ gl.bindVertexArray(vao);
+
+ 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,
+ new Float32Array([-1, -1, 0, 0, 1, -1, 1, 0, -1, 1, 0, 1, 1, 1, 1, 1]),
+ gl.STATIC_DRAW,
+ );
+
+ return {vao, vbo};
+};
+
+export const pixelDissolve = createEffect<
+ PixelDissolveParams,
+ PixelDissolveState
+>({
+ type: 'remotion/pixel-dissolve',
+ label: 'pixelDissolve()',
+ documentationLink: 'https://www.remotion.dev/docs/effects/pixel-dissolve',
+ backend: 'webgl2',
+ calculateKey: (params) => {
+ const r = resolve(params);
+ return `pixel-dissolve-${r.progress}-${r.columns}-${r.rows}-${r.seed}-${r.feather}`;
+ },
+ setup: (target) => {
+ const gl = target.getContext('webgl2', {
+ premultipliedAlpha: true,
+ alpha: true,
+ preserveDrawingBuffer: true,
+ });
+ if (!gl) {
+ throw createWebGL2ContextError('pixel dissolve effect');
+ }
+
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
+
+ const vs = compileShader(gl, gl.VERTEX_SHADER, VERTEX_SHADER);
+ const fs = compileShader(gl, gl.FRAGMENT_SHADER, FRAGMENT_SHADER);
+ const program = linkProgram(gl, vs, fs);
+ gl.deleteShader(vs);
+ gl.deleteShader(fs);
+
+ const {vao, vbo} = createFullscreenQuad(gl);
+ 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_WRAP_S, gl.CLAMP_TO_EDGE);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
+ gl.bindTexture(gl.TEXTURE_2D, null);
+
+ return {
+ gl,
+ program,
+ vao,
+ vbo,
+ texture,
+ uSource: gl.getUniformLocation(program, 'uSource'),
+ uProgress: gl.getUniformLocation(program, 'uProgress'),
+ uColumns: gl.getUniformLocation(program, 'uColumns'),
+ uRows: gl.getUniformLocation(program, 'uRows'),
+ uSeed: gl.getUniformLocation(program, 'uSeed'),
+ uFeather: gl.getUniformLocation(program, 'uFeather'),
+ };
+ },
+ apply: ({source, width, height, params, state, flipSourceY}) => {
+ const r = resolve(params);
+
+ state.gl.viewport(0, 0, width, height);
+ state.gl.bindFramebuffer(state.gl.FRAMEBUFFER, null);
+ state.gl.clearColor(0, 0, 0, 0);
+ state.gl.clear(state.gl.COLOR_BUFFER_BIT);
+
+ state.gl.useProgram(state.program);
+ state.gl.bindVertexArray(state.vao);
+
+ state.gl.activeTexture(state.gl.TEXTURE0);
+ state.gl.bindTexture(state.gl.TEXTURE_2D, state.texture);
+ state.gl.pixelStorei(state.gl.UNPACK_FLIP_Y_WEBGL, flipSourceY);
+ state.gl.texImage2D(
+ state.gl.TEXTURE_2D,
+ 0,
+ state.gl.RGBA,
+ state.gl.RGBA,
+ state.gl.UNSIGNED_BYTE,
+ source as TexImageSource,
+ );
+
+ if (state.uSource) state.gl.uniform1i(state.uSource, 0);
+ if (state.uProgress) state.gl.uniform1f(state.uProgress, r.progress);
+ if (state.uColumns) state.gl.uniform1f(state.uColumns, r.columns);
+ if (state.uRows) state.gl.uniform1f(state.uRows, r.rows);
+ if (state.uSeed) state.gl.uniform1f(state.uSeed, r.seed);
+ if (state.uFeather) state.gl.uniform1f(state.uFeather, r.feather);
+
+ state.gl.drawArrays(state.gl.TRIANGLE_STRIP, 0, 4);
+
+ state.gl.bindVertexArray(null);
+ state.gl.bindTexture(state.gl.TEXTURE_2D, null);
+ state.gl.useProgram(null);
+ },
+ cleanup: ({gl, program, vao, vbo, texture}) => {
+ gl.deleteTexture(texture);
+ gl.deleteBuffer(vbo);
+ gl.deleteProgram(program);
+ gl.deleteVertexArray(vao);
+ },
+ schema: pixelDissolveSchema,
+ validateParams: validatePixelDissolveParams,
+});
diff --git a/packages/effects/src/test/effect-params.test.ts b/packages/effects/src/test/effect-params.test.ts
index 880698edad..580cfa132d 100644
--- a/packages/effects/src/test/effect-params.test.ts
+++ b/packages/effects/src/test/effect-params.test.ts
@@ -18,6 +18,7 @@ import {invert} from '../invert.js';
import {lines} from '../lines.js';
import {mirror} from '../mirror.js';
import {noise} from '../noise.js';
+import {pixelDissolve} from '../pixel-dissolve.js';
import {saturation} from '../saturation.js';
import {scale} from '../scale.js';
import {scanlines} from '../scanlines.js';
@@ -71,6 +72,9 @@ test('@remotion/effects expose documentation links', () => {
expect(halftoneLinearGradient().definition.documentationLink).toBe(
'https://www.remotion.dev/docs/effects/halftone-linear-gradient',
);
+ expect(pixelDissolve().definition.documentationLink).toBe(
+ 'https://www.remotion.dev/docs/effects/pixel-dissolve',
+ );
expect(hue().definition.documentationLink).toBe(
'https://www.remotion.dev/docs/effects/hue',
);
@@ -145,6 +149,7 @@ test('@remotion/effects expose API names as Studio labels', () => {
expect(halftoneLinearGradient().definition.label).toBe(
'halftoneLinearGradient()',
);
+ expect(pixelDissolve().definition.label).toBe('pixelDissolve()');
expect(hue().definition.label).toBe('hue()');
expect(invert().definition.label).toBe('invert()');
expect(lines().definition.label).toBe('lines()');
@@ -1613,6 +1618,66 @@ test('speckle() parameters produce distinct effect keys', () => {
).toBe(4);
});
+test('pixelDissolve() accepts default params', () => {
+ expect(() => pixelDissolve()).not.toThrow();
+});
+
+test('pixelDissolve() rejects non-finite progress', () => {
+ expect(() => pixelDissolve({progress: Number.NaN})).toThrow(
+ '"progress" must be a finite number',
+ );
+});
+
+test('pixelDissolve() rejects progress below range', () => {
+ expect(() => pixelDissolve({progress: -0.1})).toThrow(
+ '"progress" must be >= 0',
+ );
+});
+
+test('pixelDissolve() rejects columns below range', () => {
+ expect(() => pixelDissolve({columns: 0})).toThrow('"columns" must be >= 1');
+});
+
+test('pixelDissolve() rejects rows below range', () => {
+ expect(() => pixelDissolve({rows: 0})).toThrow('"rows" must be >= 1');
+});
+
+test('pixelDissolve() rejects non-integer divisions', () => {
+ expect(() => pixelDissolve({columns: 10.5})).toThrow(
+ '"columns" must be an integer',
+ );
+});
+
+test('pixelDissolve() rejects non-finite seed', () => {
+ expect(() => pixelDissolve({seed: Number.NaN})).toThrow(
+ '"seed" must be a finite number',
+ );
+});
+
+test('pixelDissolve() rejects feather above range', () => {
+ expect(() => pixelDissolve({feather: 1.1})).toThrow('"feather" must be <= 1');
+});
+
+test('pixelDissolve() parameters produce distinct effect keys', () => {
+ const defaultDissolve = pixelDissolve();
+ const progressed = pixelDissolve({progress: 0.7});
+ const widerGrid = pixelDissolve({columns: 12});
+ const tallerGrid = pixelDissolve({rows: 12});
+ const reseeded = pixelDissolve({seed: 3});
+ const sharper = pixelDissolve({feather: 0.05});
+
+ expect(
+ new Set([
+ defaultDissolve.effectKey,
+ progressed.effectKey,
+ widerGrid.effectKey,
+ tallerGrid.effectKey,
+ reseeded.effectKey,
+ sharper.effectKey,
+ ]).size,
+ ).toBe(6);
+});
+
test('xyTranslate() accepts default params', () => {
expect(() => xyTranslate()).not.toThrow();
});