Skip to content

πŸŽ₯ Make videos programmatically with React

hmm

JonnyBurger2cd45a22fbd7
diff --git a/packages/docs/components/transitions/zoom-blur-toc-preview.tsx b/packages/docs/components/transitions/zoom-blur-toc-preview.tsx
index c735d24a7b..3222da02a2 100644
--- a/packages/docs/components/transitions/zoom-blur-toc-preview.tsx
+++ b/packages/docs/components/transitions/zoom-blur-toc-preview.tsx
@@ -1,18 +1,11 @@
-import type {PlayerRef} from '@remotion/player';
-import {Player} from '@remotion/player';
-import React, {useEffect, useRef} from 'react';
+import React from 'react';
import {staticFile} from 'remotion';
-import {useHtmlInCanvasDocsDemoBranch} from '../demos/useHtmlInCanvasDocsDemoBranch';
import {
presentationCompositionHeight,
presentationCompositionWidth,
} from '../TableOfContents/transitions/presentations';
-import {ZoomBlurTransitionPreviewThumb} from './zoom-blur-preview';
export const ZoomBlurTocPreview: React.FC = () => {
- const branch = useHtmlInCanvasDocsDemoBranch();
- const ref = useRef<PlayerRef>(null);
-
const tileHeight = 60;
const tileWidth =
(tileHeight * presentationCompositionWidth) / presentationCompositionHeight;
@@ -25,65 +18,18 @@ export const ZoomBlurTocPreview: React.FC = () => {
objectFit: 'cover',
};
- useEffect(() => {
- const {current} = ref;
- if (!current) {
- return;
- }
-
- const callback = () => {
- current?.seekTo(0);
- current?.play();
- };
-
- current?.getContainerNode()?.addEventListener('pointerenter', callback);
-
- return () => {
- current
- ?.getContainerNode()
- ?.removeEventListener('pointerenter', callback);
- };
- }, [branch]);
-
- if (branch === 'pending') {
- return (
- <div
- style={{
- ...sharedStyle,
- backgroundColor: '#000',
- }}
- />
- );
- }
-
- if (branch === 'fallback') {
- return (
- <video
- muted
- playsInline
- preload="auto"
- src={staticFile('img/zoom-blur-transition-thumb.mp4')}
- style={sharedStyle}
- onPointerEnter={(event) => {
- const video = event.currentTarget;
- video.currentTime = 0;
- void video.play();
- }}
- />
- );
- }
-
return (
- <Player
- ref={ref}
- acknowledgeRemotionLicense
- component={ZoomBlurTransitionPreviewThumb}
- compositionHeight={presentationCompositionHeight}
- compositionWidth={presentationCompositionWidth}
- durationInFrames={60}
- fps={30}
- numberOfSharedAudioTags={0}
+ <video
+ muted
+ playsInline
+ preload="auto"
+ src={staticFile('img/zoom-blur-transition-thumb.mp4')}
style={sharedStyle}
+ onPointerEnter={(event) => {
+ const video = event.currentTarget;
+ video.currentTime = 0;
+ void video.play();
+ }}
/>
);
};
diff --git a/packages/docs/components/transitions/zoom-in-out-toc-preview.tsx b/packages/docs/components/transitions/zoom-in-out-toc-preview.tsx
index 70b8885581..1150f0f71c 100644
--- a/packages/docs/components/transitions/zoom-in-out-toc-preview.tsx
+++ b/packages/docs/components/transitions/zoom-in-out-toc-preview.tsx
@@ -1,18 +1,11 @@
-import type {PlayerRef} from '@remotion/player';
-import {Player} from '@remotion/player';
-import React, {useEffect, useRef} from 'react';
+import React from 'react';
import {staticFile} from 'remotion';
-import {useHtmlInCanvasDocsDemoBranch} from '../demos/useHtmlInCanvasDocsDemoBranch';
import {
presentationCompositionHeight,
presentationCompositionWidth,
} from '../TableOfContents/transitions/presentations';
-import {ZoomInOutTransitionPreviewThumb} from './zoom-in-out-preview';
export const ZoomInOutTocPreview: React.FC = () => {
- const branch = useHtmlInCanvasDocsDemoBranch();
- const ref = useRef<PlayerRef>(null);
-
const tileHeight = 60;
const tileWidth =
(tileHeight * presentationCompositionWidth) / presentationCompositionHeight;
@@ -25,65 +18,18 @@ export const ZoomInOutTocPreview: React.FC = () => {
objectFit: 'cover',
};
- useEffect(() => {
- const {current} = ref;
- if (!current) {
- return;
- }
-
- const callback = () => {
- current?.seekTo(0);
- current?.play();
- };
-
- current?.getContainerNode()?.addEventListener('pointerenter', callback);
-
- return () => {
- current
- ?.getContainerNode()
- ?.removeEventListener('pointerenter', callback);
- };
- }, [branch]);
-
- if (branch === 'pending') {
- return (
- <div
- style={{
- ...sharedStyle,
- backgroundColor: '#000',
- }}
- />
- );
- }
-
- if (branch === 'fallback') {
- return (
- <video
- muted
- playsInline
- preload="auto"
- src={staticFile('img/zoom-in-out-transition-thumb.mp4')}
- style={sharedStyle}
- onPointerEnter={(event) => {
- const video = event.currentTarget;
- video.currentTime = 0;
- void video.play();
- }}
- />
- );
- }
-
return (
- <Player
- ref={ref}
- acknowledgeRemotionLicense
- component={ZoomInOutTransitionPreviewThumb}
- compositionHeight={presentationCompositionHeight}
- compositionWidth={presentationCompositionWidth}
- durationInFrames={60}
- fps={30}
- numberOfSharedAudioTags={0}
+ <video
+ muted
+ playsInline
+ preload="auto"
+ src={staticFile('img/zoom-in-out-transition-thumb.mp4')}
style={sharedStyle}
+ onPointerEnter={(event) => {
+ const video = event.currentTarget;
+ video.currentTime = 0;
+ void video.play();
+ }}
/>
);
};
diff --git a/packages/docs/docs/contributing/presentation.mdx b/packages/docs/docs/contributing/presentation.mdx
index 2c13db904c..a904da6ba7 100644
--- a/packages/docs/docs/contributing/presentation.mdx
+++ b/packages/docs/docs/contributing/presentation.mdx
@@ -73,16 +73,17 @@ An pull request for reference containing all required steps and filechanges can
## HTML-in-canvas presentations
-Some effects need to blend the entering and exiting scenes pixel-by-pixel through a fragment shader (zoom blur, dissolves, displacement, page curl, etc.). For these, use the [HTML-in-canvas](/docs/client-side-rendering/html-in-canvas) path instead of a CSS-only [custom presentation](/docs/transitions/presentations/custom).
+Some effects need to blend the entering and exiting scenes pixel-by-pixel.
+See [Custom HTML-in-canvas presentations](/docs/transitions/presentations/custom-html-in-canvas) how to create a HTML-in-canvas presentation.
-The full API is documented at [Custom HTML-in-canvas presentations](/docs/transitions/presentations/custom-html-in-canvas). A few extra contributing-side notes:
+If you want to contribute the presentations back into the `@remotion/transitions` package:
-<Step>1</Step> Author the shader using <code>makeHtmlInCanvasPresentation()</code> and the <code>HtmlInCanvasShader&lt;Props&gt;</code> type. See <a href="https://github.com/remotion-dev/remotion/blob/main/packages/transitions/src/presentations/zoom-blur.tsx"><code>zoom-blur.tsx</code></a> as a reference.<br />
+<Step>1</Step> Author the shader using <a href="/docs/transitions/make-html-in-canvas-presentation"><code>makeHtmlInCanvasPresentation()</code></a> and the <code>HtmlInCanvasShader&lt;Props&gt;</code> type. See <a href="https://github.com/remotion-dev/remotion/blob/main/packages/transitions/src/presentations/zoom-blur.tsx"><code>zoom-blur.tsx</code></a> as a reference.<br />
<Step>2</Step> [gl-transitions.com](https://gl-transitions.com/) is a great source of MIT-licensed fragment shaders that can be ported. Always credit the original author and the MIT license in a comment above the shader source. <a href="https://github.com/remotion-dev/remotion/blob/main/packages/transitions/src/presentations/zoom-in-out.tsx"><code>zoom-in-out.tsx</code></a> is an example of a port.<br />
<Step>3</Step> Mind the time convention: in our shaders <code>u_time = 0</code> outputs the entering scene and <code>u_time = 1</code> outputs the exiting scene. When porting from gl-transitions, set <code>float progress = 1.0 - u_time;</code> at the top of <code>main()</code>.<br />
<Step>4</Step> Handle the boundary cases inside the JS <code>draw()</code> function: when <code>prevImage</code> is <code>null</code>, force <code>time = 0</code>; when <code>nextImage</code> is <code>null</code>, force <code>time = 1</code>.<br />
<Step>5</Step> Set <code>serverSideRendering</code>, <code>nodejs</code>, <code>bun</code> and <code>serverlessFunctions</code> to <code>true</code> in the <code>&lt;CompatibilityTable /&gt;</code> on your docs page β€” Remotion's bundled Chromium for Lambda already includes the required APIs. Set <code>firefox</code> and <code>safari</code> to <code>false</code>.<br />
-<Step>6</Step> Live <code>&lt;Demo&gt;</code> and table-of-contents previews would crash for readers who do not have HTML-in-canvas enabled. Branch on <code>HtmlInCanvas.isHtmlInCanvasSupported()</code> via the <code>useHtmlInCanvasDocsDemoBranch()</code> hook and fall back to a pre-rendered video. See <a href="https://github.com/remotion-dev/remotion/blob/main/packages/docs/components/demos/ZoomBlurDemo.tsx"><code>ZoomBlurDemo.tsx</code></a> and <a href="https://github.com/remotion-dev/remotion/blob/main/packages/docs/components/transitions/zoom-blur-toc-preview.tsx"><code>zoom-blur-toc-preview.tsx</code></a> for the pattern.<br />
+<Step>6</Step> The table-of-contents preview should always render the pre-rendered fallback video β€” the live <code>&lt;Player&gt;</code> would crash for readers without HTML-in-canvas enabled, and a tiny TOC tile gains nothing from running the real shader. See <a href="https://github.com/remotion-dev/remotion/blob/main/packages/docs/components/transitions/zoom-blur-toc-preview.tsx"><code>zoom-blur-toc-preview.tsx</code></a> for the pattern. For the in-page <code>&lt;Demo&gt;</code>, branch on <code>HtmlInCanvas.isHtmlInCanvasSupported()</code> via the <code>useHtmlInCanvasDocsDemoBranch()</code> hook so supporting browsers see the real shader and others fall back to the video β€” see <a href="https://github.com/remotion-dev/remotion/blob/main/packages/docs/components/demos/ZoomBlurDemo.tsx"><code>ZoomBlurDemo.tsx</code></a>.<br />
<Step>7</Step> Render the fallback videos from a composition under <code>packages/example/src/HtmlInCanvas/</code> using <code>npx remotion render &lt;id&gt; --browser-executable=&lt;path-to-Chrome-Canary&gt; --allow-html-in-canvas</code>. Drop a high-res 1920Γ—1080 file at <code>packages/docs/static/img/&lt;name&gt;.mp4</code> for the docs page and a low-res 540Γ—280 file at <code>&lt;name&gt;-thumb.mp4</code> for the TOC tile.<br />
<Step>8</Step> Add an <code>&lt;HtmlInCanvasLabel /&gt;</code> next to the presentation name in the table-of-contents tile to flag the requirement.
diff --git a/packages/docs/docs/transitions/make-html-in-canvas-presentation.mdx b/packages/docs/docs/transitions/make-html-in-canvas-presentation.mdx
new file mode 100644
index 0000000000..ebba67489b
--- /dev/null
+++ b/packages/docs/docs/transitions/make-html-in-canvas-presentation.mdx
@@ -0,0 +1,305 @@
+---
+image: /generated/articles-docs-transitions-make-html-in-canvas-presentation.png
+crumb: '@remotion/transitions'
+title: 'makeHtmlInCanvasPresentation()'
+---
+
+# makeHtmlInCanvasPresentation()<AvailableFrom v="4.0.456" />
+
+Allows you to pass a shader to create a HTML-in-canvas-based [`@remotion/transitions`](/docs/transitions) presentation.
+
+For a step-by-step walkthrough, see [Custom HTML-in-canvas presentations](/docs/transitions/presentations/custom-html-in-canvas).
+
+```ts twoslash title="Minimal crossfade example"
+// @noErrors
+import 'remotion';
+import {makeHtmlInCanvasPresentation, type HtmlInCanvasShader} from '@remotion/transitions';
+
+const VERTEX = `#version 300 es
+in vec2 a_pos;
+out vec2 v_uv;
+void main() {
+ v_uv = vec2(a_pos.x * 0.5 + 0.5, 0.5 - a_pos.y * 0.5);
+ gl_Position = vec4(a_pos, 0.0, 1.0);
+}`;
+
+const FRAGMENT = `#version 300 es
+precision highp float;
+uniform sampler2D u_prev;
+uniform sampler2D u_next;
+uniform float u_time;
+in vec2 v_uv;
+out vec4 outColor;
+void main() {
+ outColor = mix(texture(u_next, v_uv), texture(u_prev, v_uv), u_time);
+}`;
+
+const myShader: HtmlInCanvasShader<{}> = (canvas) => {
+ const gl = canvas.getContext('webgl2', {premultipliedAlpha: true})!;
+
+ const compile = (src: string, type: number) => {
+ const sh = gl.createShader(type)!;
+ gl.shaderSource(sh, src);
+ gl.compileShader(sh);
+ return sh;
+ };
+
+ const program = gl.createProgram()!;
+ gl.attachShader(program, compile(VERTEX, gl.VERTEX_SHADER));
+ gl.attachShader(program, compile(FRAGMENT, gl.FRAGMENT_SHADER));
+ gl.linkProgram(program);
+
+ const buffer = gl.createBuffer();
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
+ gl.bufferData(
+ gl.ARRAY_BUFFER,
+ new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]),
+ gl.STATIC_DRAW,
+ );
+ const aPos = gl.getAttribLocation(program, 'a_pos');
+ gl.enableVertexAttribArray(aPos);
+ gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 0, 0);
+
+ const prevTex = gl.createTexture();
+ const nextTex = gl.createTexture();
+
+ return {
+ clear: () => {
+ gl.clearColor(0, 0, 0, 0);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+ },
+ cleanup: () => {
+ gl.deleteProgram(program);
+ gl.deleteTexture(prevTex);
+ gl.deleteTexture(nextTex);
+ gl.deleteBuffer(buffer);
+ },
+ draw: ({prevImage, nextImage, width, height, time}) => {
+ gl.viewport(0, 0, width, height);
+ gl.useProgram(program);
+
+ gl.activeTexture(gl.TEXTURE0);
+ gl.bindTexture(gl.TEXTURE_2D, prevTex);
+ if (prevImage) {
+ gl.texElementImage2D(
+ gl.TEXTURE_2D,
+ 0,
+ gl.RGBA,
+ gl.RGBA,
+ gl.UNSIGNED_BYTE,
+ prevImage,
+ );
+ }
+
+ gl.uniform1i(gl.getUniformLocation(program, 'u_prev'), 0);
+
+ gl.activeTexture(gl.TEXTURE1);
+ gl.bindTexture(gl.TEXTURE_2D, nextTex);
+ if (nextImage) {
+ gl.texElementImage2D(
+ gl.TEXTURE_2D,
+ 0,
+ gl.RGBA,
+ gl.RGBA,
+ gl.UNSIGNED_BYTE,
+ nextImage,
+ );
+ }
+
+ gl.uniform1i(gl.getUniformLocation(program, 'u_next'), 1);
+
+ const t = !prevImage ? 0 : !nextImage ? 1 : time;
+ gl.uniform1f(gl.getUniformLocation(program, 'u_time'), t);
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
+ },
+ };
+};
+// ---cut---
+const myPresentation = makeHtmlInCanvasPresentation(myShader);
+```
+
+<details>
+ <summary>Show <code>myShader</code> implementation</summary>
+
+```ts twoslash title="Minimal crossfade shader"
+// @noErrors
+import 'remotion';
+import {makeHtmlInCanvasPresentation, type HtmlInCanvasShader} from '@remotion/transitions';
+
+const VERTEX = `#version 300 es
+in vec2 a_pos;
+out vec2 v_uv;
+void main() {
+ v_uv = vec2(a_pos.x * 0.5 + 0.5, 0.5 - a_pos.y * 0.5);
+ gl_Position = vec4(a_pos, 0.0, 1.0);
+}`;
+
+const FRAGMENT = `#version 300 es
+precision highp float;
+uniform sampler2D u_prev;
+uniform sampler2D u_next;
+uniform float u_time;
+in vec2 v_uv;
+out vec4 outColor;
+void main() {
+ outColor = mix(texture(u_next, v_uv), texture(u_prev, v_uv), u_time);
+}`;
+
+const myShader: HtmlInCanvasShader<{}> = (canvas) => {
+ const gl = canvas.getContext('webgl2', {premultipliedAlpha: true})!;
+
+ const compile = (src: string, type: number) => {
+ const sh = gl.createShader(type)!;
+ gl.shaderSource(sh, src);
+ gl.compileShader(sh);
+ return sh;
+ };
+
+ const program = gl.createProgram()!;
+ gl.attachShader(program, compile(VERTEX, gl.VERTEX_SHADER));
+ gl.attachShader(program, compile(FRAGMENT, gl.FRAGMENT_SHADER));
+ gl.linkProgram(program);
+
+ const buffer = gl.createBuffer();
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
+ gl.bufferData(
+ gl.ARRAY_BUFFER,
+ new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]),
+ gl.STATIC_DRAW,
+ );
+ const aPos = gl.getAttribLocation(program, 'a_pos');
+ gl.enableVertexAttribArray(aPos);
+ gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 0, 0);
+
+ const prevTex = gl.createTexture();
+ const nextTex = gl.createTexture();
+
+ return {
+ clear: () => {
+ gl.clearColor(0, 0, 0, 0);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+ },
+ cleanup: () => {
+ gl.deleteProgram(program);
+ gl.deleteTexture(prevTex);
+ gl.deleteTexture(nextTex);
+ gl.deleteBuffer(buffer);
+ },
+ draw: ({prevImage, nextImage, width, height, time}) => {
+ gl.viewport(0, 0, width, height);
+ gl.useProgram(program);
+
+ gl.activeTexture(gl.TEXTURE0);
+ gl.bindTexture(gl.TEXTURE_2D, prevTex);
+ if (prevImage) {
+ gl.texElementImage2D(
+ gl.TEXTURE_2D,
+ 0,
+ gl.RGBA,
+ gl.RGBA,
+ gl.UNSIGNED_BYTE,
+ prevImage,
+ );
+ }
+
+ gl.uniform1i(gl.getUniformLocation(program, 'u_prev'), 0);
+
+ gl.activeTexture(gl.TEXTURE1);
+ gl.bindTexture(gl.TEXTURE_2D, nextTex);
+ if (nextImage) {
+ gl.texElementImage2D(
+ gl.TEXTURE_2D,
+ 0,
+ gl.RGBA,
+ gl.RGBA,
+ gl.UNSIGNED_BYTE,
+ nextImage,
+ );
+ }
+
+ gl.uniform1i(gl.getUniformLocation(program, 'u_next'), 1);
+
+ const t = !prevImage ? 0 : !nextImage ? 1 : time;
+ gl.uniform1f(gl.getUniformLocation(program, 'u_time'), t);
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
+ },
+ };
+};
+
+const myPresentation = makeHtmlInCanvasPresentation(myShader);
+```
+
+</details>
+
+:::warning
+HTML-in-canvas requires [Chrome Canary](https://www.google.com/chrome/canary/) with `chrome://flags/#canvas-draw-element` enabled.
+:::
+
+## Arguments
+
+### `shader`
+
+A function of type `HtmlInCanvasShader<Props>`. Called once per transition mount with a shared `OffscreenCanvas`. Must return an object with three callbacks: `clear`, `cleanup` and `draw`.
+
+```ts twoslash
+import type {HtmlInCanvasShader} from '@remotion/transitions';
+// ^?
+```
+
+#### `clear()`
+
+Called when there is nothing to draw (both scenes are unmounted). Typically clears the WebGL color buffer.
+
+#### `cleanup()`
+
+Called once when the transition unmounts. Release any GL resources you allocated (programs, textures, buffers, VAOs).
+
+#### `draw()`
+
+Called every frame the transition is active. Has the type `HtmlInCanvasShaderDraw<Props>`:
+
+```ts twoslash
+import type {HtmlInCanvasShaderDraw} from '@remotion/transitions';
+// ^?
+```
+
+The argument has the type `HtmlInCanvasShaderDrawParams<Props>`:
+
+```ts twoslash
+import type {HtmlInCanvasShaderDrawParams} from '@remotion/transitions';
+// ^?
+```
+
+##### `prevImage`
+
+`ElementImage | null` β€” the captured exiting scene. `null` while it has not yet rendered (e.g. at the very start).
+
+##### `nextImage`
+
+`ElementImage | null` β€” the captured entering scene. `null` after the entering scene has unmounted.
+
+##### `width` / `height`
+
+The pixel size of the canvas to draw into.
+
+##### `time`
+
+A `number` between `0` and `1`.
+
+`time = 0` means the shader should output the entering scene fully (i.e. transition end), and `time = 1` means the shader should output the exiting scene fully (i.e. transition start).
+
+When one image is missing, treat it as the boundary case: if `!prevImage`, force `time = 0` so the shader falls back to `nextImage` only; if `!nextImage`, force `time = 1` so the shader falls back to `prevImage` only.
+
+##### `passedProps`
+
+Whatever you typed your `Props` as. Use this for runtime knobs like `rotation`, `intensity`, `direction`, etc.
+
+## Return value
+
+A function `(props: Props) => TransitionPresentation<Props>` that you call with your runtime props and pass to `presentation` on a `<TransitionSeries.Transition>`.
+
+## See also
+
+- [Custom HTML-in-canvas presentations](/docs/transitions/presentations/custom-html-in-canvas) β€” full walkthrough and example
+- [HTML-in-canvas](/docs/client-side-rendering/html-in-canvas)
+- [Custom presentations](/docs/transitions/presentations/custom) β€” the CSS-based path
diff --git a/packages/docs/docs/transitions/presentations/custom-html-in-canvas.mdx b/packages/docs/docs/transitions/presentations/custom-html-in-canvas.mdx
index 8618ee6ec8..5bc2785649 100644
--- a/packages/docs/docs/transitions/presentations/custom-html-in-canvas.mdx
+++ b/packages/docs/docs/transitions/presentations/custom-html-in-canvas.mdx
@@ -6,7 +6,7 @@ title: 'Custom HTML-in-canvas presentations'
# Custom HTML-in-canvas presentations<AvailableFrom v="4.0.456" />
-Build a presentation that runs the entering and exiting scenes through a WebGL2 fragment shader using the experimental [HTML-in-canvas](/docs/client-side-rendering/html-in-canvas) APIs. This is the path used by [`zoomBlur()`](/docs/transitions/presentations/zoom-blur) and [`zoomInOut()`](/docs/transitions/presentations/zoom-in-out).
+Build a presentation that runs the entering and exiting scenes through a WebGL2 fragment shader using the experimental [HTML-in-canvas](https://github.com/WICG/html-in-canvas) APIs.
:::warning
HTML-in-canvas requires [Chrome Canary](https://www.google.com/chrome/canary/) with `chrome://flags/#canvas-draw-element` enabled in the browser. For server-side renders, pass `--allow-html-in-canvas` (or [`Config.setAllowHtmlInCanvasEnabled(true)`](/docs/config#setallowhtmlincanvasenabled)). It does not work in Firefox or Safari.
@@ -25,7 +25,7 @@ If a CSS `clip-path`, `transform`, `filter` or `mask` can express the effect, pr
Remotion captures both scenes via `drawElementImage()` and passes them to your shader as two `ElementImage` textures (`prevImage` and `nextImage`) along with the transition `time` (`0` β†’ `1`). Your shader writes the blended result to an offscreen WebGL2 canvas, which Remotion then composites into the frame.
-You implement a single function β€” `HtmlInCanvasShader<Props>` β€” and pass it to `makeHtmlInCanvasPresentation()` to get back a `TransitionPresentation` constructor.
+You implement a single function β€” `HtmlInCanvasShader<Props>` β€” and pass it to [`makeHtmlInCanvasPresentation()`](/docs/transitions/make-html-in-canvas-presentation) to get back a `TransitionPresentation` constructor.
## Boilerplate
@@ -119,77 +119,30 @@ export const MyComp: React.FC = () => {
};
```
-## API
+## API reference
-### `makeHtmlInCanvasPresentation(shader)`
-
-Wraps a shader factory and returns a `(props) => TransitionPresentation<Props>` function.
-
-### `HtmlInCanvasShader<Props>`
-
-A factory called once per transition mount with a shared `OffscreenCanvas`. It must return three callbacks:
-
-#### `clear()`
-
-Called when there is nothing to draw (both scenes are unmounted). Typically clears the WebGL color buffer.
-
-#### `cleanup()`
-
-Called once when the transition unmounts. Release any GL resources you allocated (programs, textures, buffers, VAOs).
-
-#### `draw({prevImage, nextImage, width, height, time, passedProps})`
-
-Called every frame the transition is active.
-
-##### `prevImage`
-
-`ElementImage | null` β€” the captured exiting scene. `null` while it has not yet rendered (e.g. at the very start).
-
-##### `nextImage`
-
-`ElementImage | null` β€” the captured entering scene. `null` after the entering scene has unmounted.
-
-##### `width` / `height`
-
-The pixel size of the canvas to draw into.
-
-##### `time`
-
-A `number` between `0` and `1`. **Note the convention**: `time = 0` means the shader should output the entering scene fully (i.e. transition end), and `time = 1` means the shader should output the exiting scene fully (i.e. transition start). This matches `mix(prev, next, 1.0 - time)`.
-
-When one image is missing, treat it as the boundary case: if `!prevImage`, force `time = 0` so the shader falls back to `nextImage` only; if `!nextImage`, force `time = 1` so the shader falls back to `prevImage` only.
-
-##### `passedProps`
-
-Whatever you typed your `Props` as. Use this for runtime knobs like `rotation`, `intensity`, `direction`, etc.
+The signature of [`makeHtmlInCanvasPresentation()`](/docs/transitions/make-html-in-canvas-presentation) and the `HtmlInCanvasShader<Props>` callback contract β€” `clear`, `cleanup`, `draw({prevImage, nextImage, width, height, time, passedProps})` β€” are documented on its own page.
## Adapting GLSL transitions from gl-transitions.com
-[gl-transitions.com](https://gl-transitions.com/) is a curated catalog of community-contributed fragment shaders licensed (mostly) under MIT β€” a great starting point. Their shader signature is:
-
-```glsl
-uniform sampler2D from;
-uniform sampler2D to;
-uniform float progress;
-vec4 transition(vec2 uv);
-```
+[gl-transitions.com](https://gl-transitions.com/) is a curated catalog of community-contributed fragment shaders licensed under MIT β€” a great starting point.
To port one to a Remotion HTML-in-canvas presentation:
<Step>1</Step> Replace `getFromColor(uv)` with `texture(u_prev, uv)` and `getToColor(uv)` with `texture(u_next, uv)`.<br />
<Step>2</Step> Map `progress` to Remotion's reversed convention with `float progress = 1.0 - u_time;` at the top of `main()`.<br />
<Step>3</Step> Wrap the `transition()` body inside `void main() { outColor = transition(v_uv); }` (with `out vec4 outColor;` declared).<br />
-<Step>4</Step> Credit the original author and license in a comment above the shader source β€” see [`zoom-in-out.tsx`](https://github.com/remotion-dev/remotion/blob/main/packages/transitions/src/presentations/zoom-in-out.tsx) for the convention used in the built-in presentations.
-## Source references
+## Example implementations
-The two built-in HTML-in-canvas presentations are good copy-paste starting points:
+See the following example implementations:
-- [`zoom-blur.tsx`](https://github.com/remotion-dev/remotion/blob/main/packages/transitions/src/presentations/zoom-blur.tsx) β€” original, with a tunable `rotation` prop
+- [`zoom-blur.tsx`](https://github.com/remotion-dev/remotion/blob/main/packages/transitions/src/presentations/zoom-blur.tsx)
- [`zoom-in-out.tsx`](https://github.com/remotion-dev/remotion/blob/main/packages/transitions/src/presentations/zoom-in-out.tsx) β€” adapted from a gl-transitions shader
## See also
+- [`makeHtmlInCanvasPresentation()`](/docs/transitions/make-html-in-canvas-presentation) β€” API reference
- [HTML-in-canvas](/docs/client-side-rendering/html-in-canvas)
- [Custom presentations](/docs/transitions/presentations/custom) β€” the CSS-based path
- [Contributing a new presentation](/docs/contributing/presentation)
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index da4eed6857..8c8548c785 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -721,6 +721,7 @@ const sidebars: SidebarsConfig = {
items: [
'transitions/transitionseries',
'transitions/use-transition-progress',
+ 'transitions/make-html-in-canvas-presentation',
{
type: 'category',
label: 'Timings',
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index ca1ca33fb7..785b00c6ba 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -6321,6 +6321,15 @@ export const articles = [
noAi: false,
slug: 'transitions/index',
},
+ {
+ id: 'transitions/make-html-in-canvas-presentation',
+ title: 'makeHtmlInCanvasPresentation()',
+ relativePath: 'docs/transitions/make-html-in-canvas-presentation.mdx',
+ compId: 'articles-docs-transitions-make-html-in-canvas-presentation',
+ crumb: '@remotion/transitions',
+ noAi: false,
+ slug: 'transitions/make-html-in-canvas-presentation',
+ },
{
id: 'transitions/presentations/clock-wipe',
title: 'clockWipe()',
@@ -6339,6 +6348,15 @@ export const articles = [
noAi: false,
slug: 'transitions/presentations/cube',
},
+ {
+ id: 'transitions/presentations/custom-html-in-canvas',
+ title: 'Custom HTML-in-canvas presentations',
+ relativePath: 'docs/transitions/presentations/custom-html-in-canvas.mdx',
+ compId: 'articles-docs-transitions-presentations-custom-html-in-canvas',
+ crumb: '@remotion/transitions',
+ noAi: false,
+ slug: 'transitions/presentations/custom-html-in-canvas',
+ },
{
id: 'transitions/presentations/custom',
title: 'Custom presentations',
@@ -6420,6 +6438,15 @@ export const articles = [
noAi: false,
slug: 'transitions/presentations/zoom-blur',
},
+ {
+ id: 'transitions/presentations/zoom-in-out',
+ title: 'zoomInOut()',
+ relativePath: 'docs/transitions/presentations/zoom-in-out.mdx',
+ compId: 'articles-docs-transitions-presentations-zoom-in-out',
+ crumb: '@remotion/transitions - Presentations',
+ noAi: false,
+ slug: 'transitions/presentations/zoom-in-out',
+ },
{
id: 'transitions/timings/custom',
title: 'Custom timings',
diff --git a/packages/docs/static/generated/articles-docs-transitions-make-html-in-canvas-presentation.png b/packages/docs/static/generated/articles-docs-transitions-make-html-in-canvas-presentation.png
new file mode 100644
index 0000000000..8b47b9658e
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-transitions-make-html-in-canvas-presentation.png differ
diff --git a/packages/promo-pages/src/components/prompts/PromptsSubmit.tsx b/packages/promo-pages/src/components/prompts/PromptsSubmit.tsx
index 1b5e60db91..de3bfa41e7 100644
--- a/packages/promo-pages/src/components/prompts/PromptsSubmit.tsx
+++ b/packages/promo-pages/src/components/prompts/PromptsSubmit.tsx
@@ -376,11 +376,11 @@ export const PromptsSubmitPage: React.FC = () => {
<h2 className="font-brand mt-5 font-bold">Model used</h2>
<p className="text-muted-foreground text-sm mb-0 font-brand">
- Which AI model did you use? (e.g. Opus 4.5, GPT-5.2)
+ Which AI model did you use? (e.g. Opus 4.7, GPT-5.5)
</p>
<Input
name="modelUsed"
- placeholder="Opus 4.5"
+ placeholder="Opus 4.7"
className="font-brand mt-3"
value={modelUsed}
onChange={(e) => setModelUsed(e.target.value)}
diff --git a/packages/transitions/src/html-in-canvas-presentation.tsx b/packages/transitions/src/html-in-canvas-presentation.tsx
index 7452eb6506..e1fe36f3f6 100644
--- a/packages/transitions/src/html-in-canvas-presentation.tsx
+++ b/packages/transitions/src/html-in-canvas-presentation.tsx
@@ -201,17 +201,23 @@ export const HtmlInCanvasPresentation = <
);
};
+export type HtmlInCanvasShaderDrawParams<Props> = {
+ prevImage: ElementImage | null;
+ nextImage: ElementImage | null;
+ width: number;
+ height: number;
+ time: number;
+ passedProps: Props;
+};
+
+export type HtmlInCanvasShaderDraw<Props> = (
+ params: HtmlInCanvasShaderDrawParams<Props>,
+) => void;
+
export type HtmlInCanvasShader<Props> = (canvas: OffscreenCanvas) => {
clear: () => void;
cleanup: () => void;
- draw: (params: {
- prevImage: ElementImage | null;
- nextImage: ElementImage | null;
- width: number;
- height: number;
- time: number;
- passedProps: Props;
- }) => void;
+ draw: HtmlInCanvasShaderDraw<Props>;
};
export const makeHtmlInCanvasPresentation = <
diff --git a/packages/transitions/src/index.ts b/packages/transitions/src/index.ts
index 5b95f3a6e5..513bfc3f97 100644
--- a/packages/transitions/src/index.ts
+++ b/packages/transitions/src/index.ts
@@ -17,5 +17,7 @@ export {
// HTML-in-canvas
export {
HtmlInCanvasShader,
+ HtmlInCanvasShaderDraw,
+ HtmlInCanvasShaderDrawParams,
makeHtmlInCanvasPresentation,
} from './html-in-canvas-presentation.js';