Skip to content

πŸŽ₯ Make videos programmatically with React

`@remotion/effects`: Graduate wave() with WebGL2 warp

Jonny Burger1436a5a79f7c
diff --git a/packages/docs/docs/effects/table-of-contents.tsx b/packages/docs/docs/effects/table-of-contents.tsx
index 571fcd14fd..901cb0b983 100644
--- a/packages/docs/docs/effects/table-of-contents.tsx
+++ b/packages/docs/docs/effects/table-of-contents.tsx
@@ -35,6 +35,16 @@ export const TableOfContents: React.FC = () => {
</div>
</div>
</TOCItem>
+ <TOCItem link="/docs/effects/wave">
+ <div style={row}>
+ <div style={{flex: 1}}>
+ <strong>
+ <code>{'wave()'}</code>
+ </strong>
+ <div>Sine wave warp for canvas components</div>
+ </div>
+ </div>
+ </TOCItem>
</Grid>
</div>
);
diff --git a/packages/docs/docs/effects/wave.mdx b/packages/docs/docs/effects/wave.mdx
new file mode 100644
index 0000000000..fe45f7b0bb
--- /dev/null
+++ b/packages/docs/docs/effects/wave.mdx
@@ -0,0 +1,79 @@
+---
+image: /generated/articles-docs-effects-wave.png
+slug: /effects/wave
+title: wave()
+sidebar_label: wave()
+crumb: '@remotion/effects'
+---
+
+_Part of the [`@remotion/effects`](/docs/effects/api) package._
+
+# `wave()`<AvailableFrom v="4.0.464" />
+
+Applies a sine wave warp to a canvas-backed component using WebGL2. The image is displaced smoothly along the wave axis (no slice gaps).
+
+## Example
+
+```tsx twoslash title="MyComp.tsx"
+import {AbsoluteFill, useCurrentFrame} from 'remotion';
+import {Video} from '@remotion/media';
+import {wave} from '@remotion/effects/wave';
+
+export const MyComp: React.FC = () => {
+ const frame = useCurrentFrame();
+
+ return (
+ <AbsoluteFill>
+ <Video
+ src="https://remotion.media/video.mp4"
+ effects={[
+ wave({
+ phase: frame * 0.2,
+ amplitude: 22,
+ wavelength: 180,
+ }),
+ ]}
+ />
+ </AbsoluteFill>
+ );
+};
+```
+
+## API
+
+Pass an object with the following properties.
+
+### `phase?`
+
+Phase offset in **radians**, passed to the sine function. Animate this value over frames to move the wave. Defaults to `0`.
+
+### `direction?`
+
+Wave propagation axis. Defaults to `'horizontal'`.
+
+- `'horizontal'` β€” phase varies along X; pixels are displaced vertically.
+- `'vertical'` β€” phase varies along Y; pixels are displaced horizontally.
+
+To combine both axes, chain two `wave()` calls with different `direction` values in the `effects` array.
+
+### `amplitude?`
+
+Displacement strength in pixels. Defaults to `60`.
+
+### `wavelength?`
+
+Distance in pixels between wave peaks. Defaults to `240`. Must be greater than `0`.
+
+### `disabled?`
+
+When `true`, the effect is skipped. Defaults to `false`.
+
+## Requirements
+
+`wave()` 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)
+- [`blur()`](/docs/effects/blur)
+- [Source code for this effect](https://github.com/remotion-dev/remotion/blob/main/packages/effects/src/wave/index.ts)
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index 3c3bd464e2..ded81689c3 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -266,7 +266,7 @@ const sidebars: SidebarsConfig = {
type: 'doc',
id: 'effects/effects-api',
},
- items: ['effects/blur'],
+ items: ['effects/blur', 'effects/wave'],
},
{
type: 'category',
diff --git a/packages/effects/README.md b/packages/effects/README.md
index 794e9df4f8..b176b9acc5 100644
--- a/packages/effects/README.md
+++ b/packages/effects/README.md
@@ -7,8 +7,12 @@ Effects that can be applied to Remotion-based canvas components.
```tsx
import {Video} from '@remotion/media';
import {blur} from '@remotion/effects/blur';
+import {wave} from '@remotion/effects/wave';
-<Video src="https://remotion.media/video.mp4" effects={[blur({radius: 8})]} />;
+<Video
+ src="https://remotion.media/video.mp4"
+ effects={[blur({radius: 8}), wave({phase: 0, amplitude: 22, wavelength: 180})]}
+/>;
```
See the [documentation](https://www.remotion.dev/docs/effects/api).
diff --git a/packages/effects/bundle.ts b/packages/effects/bundle.ts
index f5f395d6f8..ba5d43f7d2 100644
--- a/packages/effects/bundle.ts
+++ b/packages/effects/bundle.ts
@@ -5,7 +5,7 @@ if (process.env.NODE_ENV !== 'production') {
throw new Error('This script must be run using NODE_ENV=production');
}
-const effectEntrypoints = ['src/index.ts', 'src/blur.ts'];
+const effectEntrypoints = ['src/index.ts', 'src/blur.ts', 'src/wave.ts'];
console.time('Generated.');
const output = await build({
diff --git a/packages/effects/package.json b/packages/effects/package.json
index 3e266340c8..fb6ae23967 100644
--- a/packages/effects/package.json
+++ b/packages/effects/package.json
@@ -37,12 +37,20 @@
"module": "./dist/esm/blur.mjs",
"import": "./dist/esm/blur.mjs"
},
+ "./wave": {
+ "types": "./dist/wave.d.ts",
+ "module": "./dist/esm/wave.mjs",
+ "import": "./dist/esm/wave.mjs"
+ },
"./package.json": "./package.json"
},
"typesVersions": {
">=1.0": {
"blur": [
"dist/blur.d.ts"
+ ],
+ "wave": [
+ "dist/wave.d.ts"
]
}
},
diff --git a/packages/effects/src/effect-internals.ts b/packages/effects/src/effect-internals.ts
index b214c5c514..450c2fa4f2 100644
--- a/packages/effects/src/effect-internals.ts
+++ b/packages/effects/src/effect-internals.ts
@@ -1,9 +1,7 @@
import {halftone} from './halftone.js';
import {tint} from './tint.js';
-import {wave} from './wave.js';
export const EffectInternals = {
halftone,
tint,
- wave,
} as const;
diff --git a/packages/effects/src/index.ts b/packages/effects/src/index.ts
index 57abd00fc7..2aa897e592 100644
--- a/packages/effects/src/index.ts
+++ b/packages/effects/src/index.ts
@@ -1,4 +1,3 @@
export {EffectInternals} from './effect-internals.js';
export {halftoneSchema, type HalftoneParams} from './halftone.js';
export {tintSchema, type TintParams} from './tint.js';
-export {waveSchema, type WaveParams} from './wave.js';
diff --git a/packages/effects/src/test/effect-params.test.ts b/packages/effects/src/test/effect-params.test.ts
index 00d8065682..c622696a28 100644
--- a/packages/effects/src/test/effect-params.test.ts
+++ b/packages/effects/src/test/effect-params.test.ts
@@ -1,6 +1,7 @@
import {expect, test} from 'bun:test';
import {blur} from '../blur/index.js';
import {tint} from '../tint.js';
+import {wave} from '../wave/index.js';
test('tint() throws when color is not passed', () => {
expect(() => tint({} as Parameters<typeof tint>[0])).toThrow(
@@ -54,3 +55,27 @@ test('blur() axis flags produce distinct effect keys', () => {
];
expect(new Set(keys).size).toBe(keys.length);
});
+
+test('wave() accepts default params', () => {
+ expect(() => wave()).not.toThrow();
+});
+
+test('wave() rejects invalid direction', () => {
+ expect(() => wave({direction: 'diagonal' as 'horizontal'})).toThrow(
+ '"direction" must be "horizontal" or "vertical"',
+ );
+});
+
+test('wave() rejects non-positive wavelength', () => {
+ expect(() => wave({wavelength: 0})).toThrow('"wavelength" must be > 0');
+});
+
+test('wave() rejects negative amplitude', () => {
+ expect(() => wave({amplitude: -1})).toThrow('"amplitude" must be >= 0');
+});
+
+test('wave() direction produces distinct effect keys', () => {
+ const horizontal = wave({direction: 'horizontal'});
+ const vertical = wave({direction: 'vertical'});
+ expect(horizontal.effectKey).not.toBe(vertical.effectKey);
+});
diff --git a/packages/effects/src/wave.ts b/packages/effects/src/wave.ts
index 8884cb73ae..d66ff6436d 100644
--- a/packages/effects/src/wave.ts
+++ b/packages/effects/src/wave.ts
@@ -1,114 +1,6 @@
-import type {SequenceSchema} from 'remotion';
-import {Internals} from 'remotion';
-
-const {createEffect} = Internals;
-
-export const waveSchema = {
- amplitude: {
- type: 'number',
- min: 0,
- max: 500,
- step: 1,
- default: 60,
- description: 'Amplitude',
- },
- wavelength: {
- type: 'number',
- min: 1,
- max: 2000,
- step: 1,
- default: 240,
- description: 'Wavelength',
- },
- evolution: {
- type: 'number',
- default: 0,
- description: 'Evolution',
- },
- sliceWidth: {
- type: 'number',
- min: 1,
- max: 100,
- step: 1,
- default: 4,
- description: 'Slice width',
- },
- background: {
- type: 'color',
- default: 'transparent',
- description: 'Background',
- },
-} as const satisfies SequenceSchema;
-
-export type WaveParams = {
- readonly amplitude?: number;
- readonly wavelength?: number;
- readonly evolution?: number;
- readonly sliceWidth?: number;
- readonly background?: string;
-};
-
-type WaveResolved = {
- amplitude: number;
- wavelength: number;
- evolution: number;
- sliceWidth: number;
- background: string;
-};
-
-const resolve = (p: WaveParams): WaveResolved => ({
- amplitude: p.amplitude ?? 60,
- wavelength: p.wavelength ?? 240,
- evolution: p.evolution ?? 0,
- sliceWidth: p.sliceWidth ?? 4,
- background: p.background ?? 'transparent',
-});
-
-// Vertical-displacement wave effect: shifts vertical slices of the source
-// up/down with a sine wave phase driven by `evolution`. Operates on the 2D
-// backend.
-export const wave = createEffect<WaveParams, null>({
- type: 'remotion/wave',
- label: 'Wave',
- backend: '2d',
- calculateKey: (params) => {
- const r = resolve(params);
- return `wave-${r.amplitude}-${r.wavelength}-${r.evolution}-${r.sliceWidth}-${r.background}`;
- },
- setup: () => null,
- apply: ({source, target, width, height, params}) => {
- const ctx = target.getContext('2d');
- if (!ctx) {
- throw new Error(
- 'Failed to acquire 2D context for wave effect. The canvas may have been assigned a different context type.',
- );
- }
-
- 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 + r.evolution) * r.amplitude;
- ctx.drawImage(
- source,
- x,
- 0,
- r.sliceWidth,
- height,
- x,
- offset,
- r.sliceWidth,
- height,
- );
- }
- },
- cleanup: () => undefined,
- schema: waveSchema,
- validateParams: () => {},
-});
+export {
+ wave,
+ waveSchema,
+ type WaveDirection,
+ type WaveParams,
+} from './wave/index.js';
diff --git a/packages/effects/src/wave/index.ts b/packages/effects/src/wave/index.ts
new file mode 100644
index 0000000000..c0d49b884e
--- /dev/null
+++ b/packages/effects/src/wave/index.ts
@@ -0,0 +1,138 @@
+import type {SequenceSchema} from 'remotion';
+import {Internals} from 'remotion';
+import {
+ assertEffectParamsObject,
+ assertRequiredFiniteNumber,
+} from '../validate-effect-param.js';
+import {
+ applyWave,
+ cleanupWave,
+ setupWave,
+ type WaveState,
+} from './wave-runtime.js';
+
+const {createEffect} = Internals;
+
+export type WaveDirection = 'horizontal' | 'vertical';
+
+export const waveSchema = {
+ phase: {
+ type: 'number',
+ default: 0,
+ description: 'Phase',
+ },
+ direction: {
+ type: 'enum',
+ variants: {
+ horizontal: {},
+ vertical: {},
+ },
+ default: 'horizontal' as const,
+ description: 'Direction',
+ },
+ amplitude: {
+ type: 'number',
+ min: 0,
+ max: 500,
+ step: 1,
+ default: 60,
+ description: 'Amplitude',
+ },
+ wavelength: {
+ type: 'number',
+ min: 1,
+ max: 2000,
+ step: 1,
+ default: 240,
+ description: 'Wavelength',
+ },
+} as const satisfies SequenceSchema;
+
+export type WaveParams = {
+ /** Phase offset in radians. */
+ readonly phase?: number;
+ /** Wave propagation axis. Defaults to `horizontal`. */
+ readonly direction?: WaveDirection;
+ readonly amplitude?: number;
+ readonly wavelength?: number;
+};
+
+type WaveResolved = {
+ phase: number;
+ direction: WaveDirection;
+ amplitude: number;
+ wavelength: number;
+};
+
+const resolve = (p: WaveParams): WaveResolved => ({
+ phase: p.phase ?? 0,
+ direction: p.direction ?? 'horizontal',
+ amplitude: p.amplitude ?? 60,
+ wavelength: p.wavelength ?? 240,
+});
+
+const assertOptionalFiniteNumber = (value: unknown, name: string): void => {
+ if (value === undefined) {
+ return;
+ }
+
+ assertRequiredFiniteNumber(value, name);
+};
+
+const validateWaveParams = (params: WaveParams): void => {
+ assertEffectParamsObject(params, 'Wave');
+ assertOptionalFiniteNumber(params.phase, 'phase');
+ assertOptionalFiniteNumber(params.amplitude, 'amplitude');
+ assertOptionalFiniteNumber(params.wavelength, 'wavelength');
+
+ if (
+ params.direction !== undefined &&
+ params.direction !== 'horizontal' &&
+ params.direction !== 'vertical'
+ ) {
+ throw new TypeError(
+ `"direction" must be "horizontal" or "vertical", but got ${JSON.stringify(params.direction)}`,
+ );
+ }
+
+ const resolved = resolve(params);
+ if (resolved.amplitude < 0) {
+ throw new TypeError(
+ `"amplitude" must be >= 0, but got ${JSON.stringify(resolved.amplitude)}`,
+ );
+ }
+
+ if (resolved.wavelength <= 0) {
+ throw new TypeError(
+ `"wavelength" must be > 0, but got ${JSON.stringify(resolved.wavelength)}`,
+ );
+ }
+};
+
+// Sine wave warp: displaces source UVs along the propagation axis. WebGL2 only.
+export const wave = createEffect<WaveParams, WaveState>({
+ type: 'remotion/wave',
+ label: 'Wave',
+ backend: 'webgl2',
+ calculateKey: (params) => {
+ const r = resolve(params);
+ return `wave-${r.phase}-${r.direction}-${r.amplitude}-${r.wavelength}`;
+ },
+ setup: (target) => setupWave(target),
+ apply: ({source, width, height, params, state}) => {
+ const r = resolve(params);
+ applyWave({
+ state,
+ source,
+ width,
+ height,
+ amplitude: r.amplitude,
+ wavelength: r.wavelength,
+ phase: r.phase,
+ direction: r.direction,
+ });
+ },
+ cleanup: (state) => cleanupWave(state),
+ schema: waveSchema,
+ validateParams: validateWaveParams,
+});
diff --git a/packages/effects/src/wave/wave-runtime.ts b/packages/effects/src/wave/wave-runtime.ts
new file mode 100644
index 0000000000..ed73e42978
--- /dev/null
+++ b/packages/effects/src/wave/wave-runtime.ts
@@ -0,0 +1,226 @@
+import {Internals} from 'remotion';
+import {WAVE_FS, WAVE_VS} from './wave-shaders.js';
+
+const {createWebGL2ContextError} = Internals;
+
+export type WaveState = {
+ gl: WebGL2RenderingContext;
+ program: WebGLProgram;
+ vao: WebGLVertexArrayObject;
+ vbo: WebGLBuffer;
+ textureSource: WebGLTexture;
+ uniforms: {
+ uSource: WebGLUniformLocation | null;
+ uResolution: WebGLUniformLocation | null;
+ uAmplitude: WebGLUniformLocation | null;
+ uWavelength: WebGLUniformLocation | null;
+ uPhase: WebGLUniformLocation | null;
+ uDirection: 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;
+};
+
+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 getWaveUniforms = (
+ gl: WebGL2RenderingContext,
+ program: WebGLProgram,
+): WaveState['uniforms'] => ({
+ uSource: gl.getUniformLocation(program, 'uSource'),
+ uResolution: gl.getUniformLocation(program, 'uResolution'),
+ uAmplitude: gl.getUniformLocation(program, 'uAmplitude'),
+ uWavelength: gl.getUniformLocation(program, 'uWavelength'),
+ uPhase: gl.getUniformLocation(program, 'uPhase'),
+ uDirection: gl.getUniformLocation(program, 'uDirection'),
+});
+
+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 setupWave = (target: HTMLCanvasElement): WaveState => {
+ const gl = target.getContext('webgl2', {
+ premultipliedAlpha: true,
+ alpha: true,
+ preserveDrawingBuffer: true,
+ });
+ if (!gl) {
+ throw createWebGL2ContextError('wave effect');
+ }
+
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
+
+ const program = createProgram(gl, WAVE_VS, WAVE_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 textureSource = createRgbaTexture(gl);
+
+ return {
+ gl,
+ program,
+ vao,
+ vbo,
+ textureSource,
+ uniforms: getWaveUniforms(gl, program),
+ };
+};
+
+export const cleanupWave = (state: WaveState): void => {
+ const {gl, program, vao, vbo, textureSource} = state;
+ gl.deleteTexture(textureSource);
+ gl.deleteBuffer(vbo);
+ gl.deleteProgram(program);
+ gl.deleteVertexArray(vao);
+};
+
+type ApplyWaveParams = {
+ readonly state: WaveState;
+ readonly source: CanvasImageSource;
+ readonly width: number;
+ readonly height: number;
+ readonly amplitude: number;
+ readonly wavelength: number;
+ readonly phase: number;
+ readonly direction: 'horizontal' | 'vertical';
+};
+
+const drawFullscreenQuad = (state: WaveState): void => {
+ const {gl, vao} = state;
+ gl.bindVertexArray(vao);
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
+ gl.bindVertexArray(null);
+};
+
+export const applyWave = ({
+ state,
+ source,
+ width,
+ height,
+ amplitude,
+ wavelength,
+ phase,
+ direction,
+}: ApplyWaveParams): void => {
+ const {gl, program, textureSource, uniforms} = state;
+
+ gl.viewport(0, 0, width, height);
+ 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.uResolution) gl.uniform2f(uniforms.uResolution, width, height);
+ if (uniforms.uAmplitude) gl.uniform1f(uniforms.uAmplitude, amplitude);
+ if (uniforms.uWavelength) gl.uniform1f(uniforms.uWavelength, wavelength);
+ if (uniforms.uPhase) gl.uniform1f(uniforms.uPhase, phase);
+ if (uniforms.uDirection)
+ gl.uniform1i(uniforms.uDirection, direction === 'horizontal' ? 0 : 1);
+
+ 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/wave/wave-shaders.ts b/packages/effects/src/wave/wave-shaders.ts
new file mode 100644
index 0000000000..7b0d7eb727
--- /dev/null
+++ b/packages/effects/src/wave/wave-shaders.ts
@@ -0,0 +1,47 @@
+// GLSL for the WebGL2 wave warp: samples the source with a sine displacement.
+// `horizontal` β€” phase along X, displacement in Y. `vertical` β€” phase along Y,
+// displacement in X.
+
+export const WAVE_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 WAVE_FS = /* glsl */ `#version 300 es
+precision highp float;
+in vec2 vUv;
+out vec4 fragColor;
+
+uniform sampler2D uSource;
+uniform vec2 uResolution;
+uniform float uAmplitude;
+uniform float uWavelength;
+uniform float uPhase;
+uniform int uDirection;
+
+const float TWO_PI = 6.28318530718;
+
+void main() {
+ float wavelength = max(uWavelength, 0.001);
+ vec2 srcUv = vUv;
+
+ if (uDirection == 0) {
+ float coordPx = vUv.x * uResolution.x;
+ float offsetPx =
+ sin((coordPx / wavelength) * TWO_PI + uPhase) * uAmplitude;
+ srcUv.y -= offsetPx / uResolution.y;
+ } else {
+ float coordPx = vUv.y * uResolution.y;
+ float offsetPx =
+ sin((coordPx / wavelength) * TWO_PI + uPhase) * uAmplitude;
+ srcUv.x -= offsetPx / uResolution.x;
+ }
+
+ fragColor = texture(uSource, srcUv);
+}
+`;
diff --git a/packages/example/src/EffectsTestbed/EffectsTestbed.tsx b/packages/example/src/EffectsTestbed/EffectsTestbed.tsx
index fcf77450c2..4ad9e4961a 100644
--- a/packages/example/src/EffectsTestbed/EffectsTestbed.tsx
+++ b/packages/example/src/EffectsTestbed/EffectsTestbed.tsx
@@ -1,5 +1,6 @@
import {EffectInternals} from '@remotion/effects';
import {blur} from '@remotion/effects/blur';
+import {wave} from '@remotion/effects/wave';
import {LightLeakInternals} from '@remotion/light-leaks';
import {Video} from '@remotion/media';
import {StarburstInternals} from '@remotion/starburst';
@@ -83,7 +84,7 @@ const tileVideoStyle: React.CSSProperties = {
const AnimatedWaveVideo: React.FC = () => {
const frame = useCurrentFrame();
- const evolution = frame * 0.2;
+ const phase = frame * 0.2;
return (
<Video
@@ -93,12 +94,10 @@ const AnimatedWaveVideo: React.FC = () => {
loop
objectFit="cover"
effects={[
- EffectInternals.wave({
+ wave({
+ phase,
amplitude: 22,
wavelength: 180,
- evolution,
- sliceWidth: 4,
- background: '#020617',
}),
]}
/>
@@ -129,7 +128,7 @@ const AnimatedLightLeakSolid: React.FC = () => {
const AnimatedStackVideo: React.FC = () => {
const frame = useCurrentFrame();
- const evolution = frame * 0.2;
+ const phase = frame * 0.2;
return (
<Video
@@ -144,12 +143,10 @@ const AnimatedStackVideo: React.FC = () => {
rays: 12,
}),
blur({radius: 24}),
- EffectInternals.wave({
+ wave({
+ phase,
amplitude: 22,
wavelength: 180,
- evolution,
- sliceWidth: 4,
- background: '#020617',
}),
]}
/>
@@ -205,7 +202,7 @@ export const EffectsTestbed: React.FC = () => {
]}
/>
</Tile>
- <Tile title="wave" subtitle="amplitude 22, evolution from frame">
+ <Tile title="wave" subtitle="amplitude 22, phase from frame">
<AnimatedWaveVideo />
</Tile>
</div>
diff --git a/packages/example/src/Gif/GifEffects.tsx b/packages/example/src/Gif/GifEffects.tsx
index 166550ae83..b985238857 100644
--- a/packages/example/src/Gif/GifEffects.tsx
+++ b/packages/example/src/Gif/GifEffects.tsx
@@ -1,5 +1,6 @@
import {EffectInternals} from '@remotion/effects';
import {blur} from '@remotion/effects/blur';
+import {wave} from '@remotion/effects/wave';
import {Gif} from '@remotion/gif';
import {StudioInternals} from '@remotion/studio';
import React from 'react';
@@ -98,7 +99,7 @@ const AnimatedBlurGif: React.FC = () => {
const AnimatedWaveGif: React.FC = () => {
const frame = useCurrentFrame();
- const evolution = frame * 0.2;
+ const phase = frame * 0.2;
return (
<Gif
@@ -106,12 +107,10 @@ const AnimatedWaveGif: React.FC = () => {
fit="contain"
style={tileGifStyle}
effects={[
- EffectInternals.wave({
+ wave({
+ phase,
amplitude: 22,
wavelength: 180,
- evolution,
- sliceWidth: 4,
- background: '#020617',
}),
]}
/>
@@ -120,7 +119,7 @@ const AnimatedWaveGif: React.FC = () => {
const StackedGif: React.FC = () => {
const frame = useCurrentFrame();
- const evolution = frame * 0.2;
+ const phase = frame * 0.2;
return (
<Gif
@@ -129,12 +128,10 @@ const StackedGif: React.FC = () => {
style={tileGifStyle}
effects={[
EffectInternals.tint({color: '#ff5fa2', amount: 0.4}),
- EffectInternals.wave({
+ wave({
+ phase,
amplitude: 12,
wavelength: 160,
- evolution,
- sliceWidth: 4,
- background: '#020617',
}),
blur({radius: 6}),
]}
@@ -195,7 +192,7 @@ const Comp: React.FC = () => {
<Tile title="blur" subtitle="separable Gaussian, animated 0β†’18">
<AnimatedBlurGif />
</Tile>
- <Tile title="wave" subtitle="amplitude 22, evolution from frame">
+ <Tile title="wave" subtitle="amplitude 22, phase from frame">
<AnimatedWaveGif />
</Tile>
<Tile title="tint + wave + blur" subtitle="effect chain">
diff --git a/packages/example/src/Rive/RiveEffects.tsx b/packages/example/src/Rive/RiveEffects.tsx
index 1299ed6770..939e1ea2dc 100644
--- a/packages/example/src/Rive/RiveEffects.tsx
+++ b/packages/example/src/Rive/RiveEffects.tsx
@@ -1,5 +1,6 @@
import {EffectInternals} from '@remotion/effects';
import {blur} from '@remotion/effects/blur';
+import {wave} from '@remotion/effects/wave';
import {RemotionRiveCanvas} from '@remotion/rive';
import {StudioInternals} from '@remotion/studio';
import React from 'react';
@@ -94,19 +95,17 @@ const AnimatedBlurRive: React.FC = () => {
const AnimatedWaveRive: React.FC = () => {
const frame = useCurrentFrame();
- const evolution = frame * 0.2;
+ const phase = frame * 0.2;
return (
<RemotionRiveCanvas
src={RIVE_SRC}
style={tileRiveStyle}
effects={[
- EffectInternals.wave({
+ wave({
+ phase,
amplitude: 22,
wavelength: 180,
- evolution,
- sliceWidth: 4,
- background: '#020617',
}),
]}
/>
@@ -115,7 +114,7 @@ const AnimatedWaveRive: React.FC = () => {
const StackedRive: React.FC = () => {
const frame = useCurrentFrame();
- const evolution = frame * 0.2;
+ const phase = frame * 0.2;
return (
<RemotionRiveCanvas
@@ -123,12 +122,10 @@ const StackedRive: React.FC = () => {
style={tileRiveStyle}
effects={[
EffectInternals.tint({color: '#ff5fa2', amount: 0.4}),
- EffectInternals.wave({
+ wave({
+ phase,
amplitude: 12,
wavelength: 160,
- evolution,
- sliceWidth: 4,
- background: '#020617',
}),
blur({radius: 6}),
]}
@@ -187,7 +184,7 @@ const Comp: React.FC = () => {
<Tile title="blur" subtitle="separable Gaussian, animated 0β†’18">
<AnimatedBlurRive />
</Tile>
- <Tile title="wave" subtitle="amplitude 22, evolution from frame">
+ <Tile title="wave" subtitle="amplitude 22, phase from frame">
<AnimatedWaveRive />
</Tile>
<Tile title="tint + wave + blur" subtitle="effect chain">