Skip to content

πŸŽ₯ Make videos programmatically with React

`@remotion/effects`: Add `cylinder()` for WebGPU cylinder wrapping

Jonny Burger58e63987d7a2
diff --git a/bun.lock b/bun.lock
index de7b5c5e7a..2b22379732 100644
--- a/bun.lock
+++ b/bun.lock
@@ -708,6 +708,7 @@
"@remotion/eslint-config-internal": "workspace:*",
"@typescript/native-preview": "catalog:",
"@vitest/browser-playwright": "catalog:",
+ "@webgpu/types": "0.1.74",
"eslint": "catalog:",
"vitest": "catalog:",
},
@@ -5793,7 +5794,7 @@
"@webext-core/match-patterns": ["@webext-core/[email protected]", "", {}, "sha512-EsyMMKfQuSE4rWCjP/TifwvUWlhC/OhiGn5OK3p9F0d57UmtLib0nzguzPKyxM1/kZV7SkE+jYXkE8gsdPRLmw=="],
- "@webgpu/types": ["@webgpu/[email protected]", "", {}, "sha512-pUrWq3V5PiSGFLeLxoGqReTZmiiXwY3jRkIG5sLLKjyqNxrwm/04b4nw7LSmGWJcKk59XOM/YRTUwOzo4MMlow=="],
+ "@webgpu/types": ["@webgpu/[email protected]", "", {}, "sha512-lgiI4hbuLcI9unnm2cL/tvCaQU45dp0xcLWJh5uB/9MBGvIA4F8XIk7nSiBeg+K4xWGYwgZKn80LmERI5CxoTA=="],
"@wxt-dev/browser": ["@wxt-dev/[email protected]", "", { "dependencies": { "@types/filesystem": "*", "@types/har-format": "*" } }, "sha512-676RhVsOFNSZnisfeM9U40DdYjZmx5whJuBHJ7v4R2sR6e/SYfuIuzmJf3owr2n82d2vCDwGNbvt4nLU14sGZg=="],
@@ -11273,6 +11274,8 @@
"@types/styled-components/csstype": ["[email protected]", "", {}, "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw=="],
+ "@types/three/@webgpu/types": ["@webgpu/[email protected]", "", {}, "sha512-pUrWq3V5PiSGFLeLxoGqReTZmiiXwY3jRkIG5sLLKjyqNxrwm/04b4nw7LSmGWJcKk59XOM/YRTUwOzo4MMlow=="],
+
"@types/three/fflate": ["[email protected]", "", {}, "sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A=="],
"@typescript-eslint/eslint-plugin/@typescript-eslint/utils": ["@typescript-eslint/[email protected]", "", { "dependencies": { "@eslint-community/eslint-utils": "4.7.0", "@types/json-schema": "7.0.15", "@types/semver": "7.5.3", "@typescript-eslint/scope-manager": "6.21.0", "@typescript-eslint/types": "6.21.0", "@typescript-eslint/typescript-estree": "6.21.0", "semver": "7.6.3" }, "peerDependencies": { "eslint": "9.19.0" } }, "sha512-NfWVaC8HP9T8cbKQxHcsJBY5YE1O33+jpMwN45qzWWaPDZgLIbo12toGMWnmhvCpd3sIxkpDw3Wv1B3dYrbDQQ=="],
@@ -11473,6 +11476,8 @@
"caniuse-api/browserslist": ["[email protected]", "", { "dependencies": { "caniuse-lite": "1.0.30001724", "electron-to-chromium": "1.5.167", "node-releases": "2.0.19", "update-browserslist-db": "1.1.3" }, "bin": { "browserslist": "cli.js" } }, "sha512-PJ8gYKeS5e/whHBh8xrwYK+dAvEj7JXtz6uTucnMRB8OiGTsKccFekoRrjajPBHV8oOY+2tI4uxeceSimKwMFA=="],
+ "canvaskit-wasm/@webgpu/types": ["@webgpu/[email protected]", "", {}, "sha512-pUrWq3V5PiSGFLeLxoGqReTZmiiXwY3jRkIG5sLLKjyqNxrwm/04b4nw7LSmGWJcKk59XOM/YRTUwOzo4MMlow=="],
+
"cheerio/htmlparser2": ["[email protected]", "", { "dependencies": { "domelementtype": "2.3.0", "domhandler": "5.0.3", "domutils": "3.0.1", "entities": "4.5.0" } }, "sha512-4lVbmc1diZC7GUJQtRQ5yBAeUCL1exyMwmForWkRLnwyzWBFxN633SALPMGYaWZvKe9j1pRZJpauvmxENSp/EA=="],
"chrome-launcher/@types/node": ["@types/[email protected]", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-GYDxsZi3ChgmckRT9HPU0WEhKLP08ev/Yfcq2AstjrDASOYCSXeyjDsHg4v5t4jOj7cyDX3vmprafKlWIG9MXQ=="],
@@ -18557,6 +18562,8 @@
"template-prompt-to-motion-graphics/@react-three/fiber/scheduler": ["[email protected]", "", {}, "sha512-xFVuu11jh+xcO7JOAGJNOXld8/TcEHK/4CituBUeUb5hqxJLj9YuemAEuvm9gQ/+pgXYfbQuqAkiYu+u7YEsNA=="],
+ "template-prompt-to-motion-graphics/@types/three/@webgpu/types": ["@webgpu/[email protected]", "", {}, "sha512-pUrWq3V5PiSGFLeLxoGqReTZmiiXwY3jRkIG5sLLKjyqNxrwm/04b4nw7LSmGWJcKk59XOM/YRTUwOzo4MMlow=="],
+
"template-prompt-to-motion-graphics/@types/three/fflate": ["[email protected]", "", {}, "sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A=="],
"template-prompt-to-motion-graphics/@typescript-eslint/eslint-plugin/@eslint-community/regexpp": ["@eslint-community/[email protected]", "", {}, "sha512-EriSTlt5OC9/7SXkRSCAhfSxxoSUgBm33OH+IkwbdpgoqsSsUg7y3uh+IICI/Qg4BBWr3U2i39RpmycbxMq4ew=="],
diff --git a/packages/docs/components/demos/CylinderTextDemo.tsx b/packages/docs/components/demos/CylinderTextDemo.tsx
new file mode 100644
index 0000000000..16a07ff023
--- /dev/null
+++ b/packages/docs/components/demos/CylinderTextDemo.tsx
@@ -0,0 +1,35 @@
+import {cylinder} from '@remotion/effects/cylinder';
+import React from 'react';
+import {
+ AbsoluteFill,
+ CanvasImage,
+ useCurrentFrame,
+ useVideoConfig,
+} from 'remotion';
+
+// A transparent strip lets the back of the wheel show through the lettering.
+const textSource = `data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="1280" height="720" viewBox="0 0 1280 720"><text x="0" y="394" fill="#b6f34b" font-family="Arial, sans-serif" font-size="100" font-weight="900" textLength="1280" lengthAdjust="spacingAndGlyphs">REMOTION β€’ CREATE β€’ </text></svg>`)}`;
+
+export const CylinderTextDemo: React.FC = () => {
+ const frame = useCurrentFrame();
+ const {durationInFrames} = useVideoConfig();
+ return (
+ <AbsoluteFill style={{backgroundColor: '#10151c'}}>
+ <CanvasImage
+ src={textSource}
+ width={1280}
+ height={720}
+ fit="cover"
+ effects={[
+ cylinder({
+ radius: 340,
+ rotation: (frame / durationInFrames) * 360,
+ rotationX: 52,
+ rotationZ: -18,
+ shading: 0.65,
+ }),
+ ]}
+ />
+ </AbsoluteFill>
+ );
+};
diff --git a/packages/docs/components/demos/index.tsx b/packages/docs/components/demos/index.tsx
index af820a0247..97f4bdd8f5 100644
--- a/packages/docs/components/demos/index.tsx
+++ b/packages/docs/components/demos/index.tsx
@@ -20,6 +20,7 @@ import {
crosswarpPresentationDemo,
crossZoomPresentationDemo,
cubePresentationDemo,
+ cylinderTextDemo,
customPresentationDemo,
customTimingDemo,
dissolvePresentationDemo,
@@ -153,6 +154,7 @@ const demos: DemoType[] = [
clockWipePresentationDemo,
irisPresentationDemo,
cubePresentationDemo,
+ cylinderTextDemo,
animationMathDemo,
roundedTextBoxDemo,
springDemo,
diff --git a/packages/docs/components/demos/types.ts b/packages/docs/components/demos/types.ts
index 55eb98af9c..f143a80a54 100644
--- a/packages/docs/components/demos/types.ts
+++ b/packages/docs/components/demos/types.ts
@@ -19,6 +19,7 @@ import {CalloutDemo} from './Callout';
import {CircleDemo} from './Circle';
import {CrosswarpDocsDemo} from './CrosswarpDemo';
import {CrossZoomDocsDemo} from './CrossZoomDemo';
+import {CylinderTextDemo} from './CylinderTextDemo';
import {DissolveDocsDemo} from './DissolveDemo';
import {DreamyZoomDocsDemo} from './DreamyZoomDemo';
import {EllipseDemo} from './Ellipse';
@@ -1743,3 +1744,16 @@ export const motionBlurHtmlInCanvasDemo: DemoType = {
logLevel: 'info',
options: [],
};
+
+export const cylinderTextDemo: DemoType = {
+ comp: CylinderTextDemo,
+ compWidth: 1280,
+ compHeight: 720,
+ durationInFrames: 180,
+ fps: 30,
+ id: 'cylinder-text',
+ autoPlay: true,
+ controls: true,
+ logLevel: 'info',
+ options: [],
+};
diff --git a/packages/docs/components/effects-demos/registry.ts b/packages/docs/components/effects-demos/registry.ts
index cf08fbf9c5..e29180c072 100644
--- a/packages/docs/components/effects-demos/registry.ts
+++ b/packages/docs/components/effects-demos/registry.ts
@@ -9,6 +9,7 @@ import {colorKey} from '@remotion/effects/color-key';
import {contourLines} from '@remotion/effects/contour-lines';
import {contrast} from '@remotion/effects/contrast';
import {cornerPin} from '@remotion/effects/corner-pin';
+import {cylinder} from '@remotion/effects/cylinder';
import {dotGrid} from '@remotion/effects/dot-grid';
import {dropShadow} from '@remotion/effects/drop-shadow';
import {duotone} from '@remotion/effects/duotone';
@@ -82,6 +83,7 @@ import {EffectsColorKeyPreview} from '../effects/effects-color-key-preview';
import {EffectsContourLinesPreview} from '../effects/effects-contour-lines-preview';
import {EffectsContrastPreview} from '../effects/effects-contrast-preview';
import {EffectsCornerPinPreview} from '../effects/effects-corner-pin-preview';
+import {EffectsCylinderPreview} from '../effects/effects-cylinder-preview';
import {EffectsDotGridPreview} from '../effects/effects-dot-grid-preview';
import {EffectsDropShadowPreview} from '../effects/effects-drop-shadow-preview';
import {EffectsDuotonePreview} from '../effects/effects-duotone-preview';
@@ -194,6 +196,14 @@ const shrinkwrapDemoSchema = {
} as const;
export const effectsDemos: EffectsDemoType[] = [
+ {
+ ...defaults,
+ id: 'effects-cylinder',
+ effectName: 'cylinder',
+ effectImportPath: '@remotion/effects/cylinder',
+ comp: EffectsCylinderPreview,
+ schema: cylinder().definition.schema,
+ },
{
...defaults,
id: 'effects-brightness',
diff --git a/packages/docs/components/effects/effects-cylinder-preview.tsx b/packages/docs/components/effects/effects-cylinder-preview.tsx
new file mode 100644
index 0000000000..d8c463ba44
--- /dev/null
+++ b/packages/docs/components/effects/effects-cylinder-preview.tsx
@@ -0,0 +1,25 @@
+import {cylinder, type CylinderRender} from '@remotion/effects/cylinder';
+import React from 'react';
+import {CanvasImage} from 'remotion';
+import {EFFECTS_PREVIEW_IMAGE_SRC} from './effects-preview-image';
+
+export const EffectsCylinderPreview: React.FC<{
+ readonly radius: number;
+ readonly rotation: number;
+ readonly rotationX: number;
+ readonly rotationY: number;
+ readonly rotationZ: number;
+ readonly position: readonly [number, number];
+ readonly render: CylinderRender;
+ readonly shading: number;
+}> = (params) => {
+ return (
+ <CanvasImage
+ src={EFFECTS_PREVIEW_IMAGE_SRC}
+ width={1280}
+ height={720}
+ fit="cover"
+ effects={[cylinder(params)]}
+ />
+ );
+};
diff --git a/packages/docs/docs/effects/cylinder.mdx b/packages/docs/docs/effects/cylinder.mdx
new file mode 100644
index 0000000000..6272249ad2
--- /dev/null
+++ b/packages/docs/docs/effects/cylinder.mdx
@@ -0,0 +1,102 @@
+---
+image: /generated/articles-docs-effects-cylinder.png
+slug: /effects/cylinder
+title: cylinder()
+sidebar_label: cylinder()
+crumb: '@remotion/effects'
+---
+
+# cylinder()<AvailableFrom v="4.0.537" />
+
+_Part of the [`@remotion/effects`](/docs/effects/api) package._
+
+Wraps canvas content around an open cylinder. Animate the texture rotation to spin text or images around it, and tilt the cylinder in three dimensions.
+
+## Spinning text
+
+<Demo type="cylinder-text" />
+
+Transparent areas reveal the back of the cylinder when `render` is `'both'`.
+
+## Preview
+
+<EffectsDemo type="effects-cylinder" />
+
+## Example
+
+```tsx twoslash title="MyComp.tsx"
+import React from 'react';
+import {CanvasImage, useCurrentFrame} from 'remotion';
+import {cylinder} from '@remotion/effects/cylinder';
+
+export const MyComp: React.FC = () => {
+ const frame = useCurrentFrame();
+
+ return (
+ <CanvasImage
+ src="https://remotion.media/transition-bg-blue.jpg"
+ width={1280}
+ height={720}
+ fit="cover"
+ effects={[
+ cylinder({
+ radius: 300,
+ rotation: frame * 2,
+ rotationX: 30,
+ rotationZ: -15,
+ }),
+ ]}
+ />
+ );
+};
+```
+
+## API
+
+### `radius?`
+
+Cylinder radius in pixels. Must be greater than `0`. Defaults to `250`.
+The entire source width wraps once around the circumference. The source height is the cylinder height.
+
+### `rotation?`
+
+Texture rotation around the cylinder, in degrees. Defaults to `0`. Animate from `0` to `360` for one revolution.
+
+### `rotationX?`
+
+Cylinder rotation around the X axis, in degrees. Defaults to `0`.
+
+### `rotationY?`
+
+Cylinder rotation around the Y axis, in degrees. Defaults to `0`.
+
+### `rotationZ?`
+
+Cylinder rotation around the Z axis, in degrees. Defaults to `0`.
+Axis rotations are applied in X, Y, then Z order. The projection is orthographic, and the cylinder has no end caps.
+
+### `position?`
+
+Center as `[x, y]` fractions of the canvas dimensions. Defaults to `[0.5, 0.5]`. Values outside the `0`–`1` range move the center beyond the canvas.
+
+### `render?`
+
+Which faces to render: `'both'`, `'front'`, or `'back'`. Defaults to `'both'`. The front face is composited over the back face.
+
+### `shading?`
+
+Darkening toward the cylinder's silhouette, from `0` to `1`. Defaults to `0.35`. Set to `0` to preserve the source colors.
+
+### `disabled?`
+
+When `true`, skips the effect. Defaults to `false`.
+
+## Requirements
+
+`cylinder()` requires WebGPU. See [Using WebGL and WebGPU during renders](/docs/webgl) for rendering configuration.
+
+## See also
+
+- [`@remotion/effects`](/docs/effects/api)
+- [`<CanvasImage>`](/docs/canvasimage)
+- [Source code](https://github.com/remotion-dev/remotion/blob/main/packages/effects/src/cylinder/index.ts)
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index d1cfed9e0d..9d22ac40f6 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -293,6 +293,7 @@ const sidebars: SidebarsConfig = {
'effects/contrast',
'effects/contour-lines',
'effects/corner-pin',
+ 'effects/cylinder',
'effects/dot-grid',
'effects/drop-shadow',
'effects/duotone',
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 6e536850a1..6c25dd09c2 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -3483,6 +3483,15 @@ export const articles = [
noAi: false,
slug: 'effects/corner-pin',
},
+ {
+ id: 'effects/cylinder',
+ title: 'cylinder()',
+ relativePath: 'docs/effects/cylinder.mdx',
+ compId: 'articles-docs-effects-cylinder',
+ crumb: '@remotion/effects',
+ noAi: false,
+ slug: 'effects/cylinder',
+ },
{
id: 'effects/dot-grid',
title: 'dotGrid()',
diff --git a/packages/docs/src/remotion/Root.tsx b/packages/docs/src/remotion/Root.tsx
index 03b090112a..1c4e688c6e 100644
--- a/packages/docs/src/remotion/Root.tsx
+++ b/packages/docs/src/remotion/Root.tsx
@@ -2,6 +2,7 @@ import {experts} from '@remotion/promo-pages/dist/experts/experts-data.js';
import {CreateVideoInternals} from 'create-video';
import React from 'react';
import {Composition, Folder, Still} from 'remotion';
+import {CylinderTextDemo} from '../../components/demos/CylinderTextDemo';
import {MotionBlurHtmlInCanvasLiveDemo} from '../../components/demos/MotionBlurDemo';
import {EffectsBarrelDistortionPreview} from '../../components/effects/effects-barrel-distortion-preview';
import {EffectsBlurPreview} from '../../components/effects/effects-blur-preview';
@@ -14,6 +15,7 @@ import {EffectsColorKeyPreview} from '../../components/effects/effects-color-key
import {EffectsContourLinesPreview} from '../../components/effects/effects-contour-lines-preview';
import {EffectsContrastPreview} from '../../components/effects/effects-contrast-preview';
import {EffectsCornerPinPreview} from '../../components/effects/effects-corner-pin-preview';
+import {EffectsCylinderPreview} from '../../components/effects/effects-cylinder-preview';
import {EffectsDotGridPreview} from '../../components/effects/effects-dot-grid-preview';
import {EffectsDropShadowPreview} from '../../components/effects/effects-drop-shadow-preview';
import {EffectsDuotonePreview} from '../../components/effects/effects-duotone-preview';
@@ -223,6 +225,30 @@ export const RemotionRoot: React.FC = () => {
})}
</Folder>
<Folder name="effect-previews">
+ <Composition
+ id="cylinder-text"
+ component={CylinderTextDemo}
+ width={1280}
+ height={720}
+ fps={30}
+ durationInFrames={180}
+ />
+ <Still
+ id="effects-cylinder-preview"
+ component={EffectsCylinderPreview}
+ width={1280}
+ height={720}
+ defaultProps={{
+ radius: 370,
+ rotation: 30,
+ rotationX: 18,
+ rotationY: 0,
+ rotationZ: -15,
+ position: [0.5, 0.5],
+ render: 'both',
+ shading: 0.35,
+ }}
+ />
<Still
id="effects-brightness-preview"
component={EffectsBrightnessPreview}
diff --git a/packages/docs/static/generated/articles-docs-effects-cylinder.png b/packages/docs/static/generated/articles-docs-effects-cylinder.png
new file mode 100644
index 0000000000..0d2022c9dd
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-effects-cylinder.png differ
diff --git a/packages/docs/static/img/effects-cylinder-preview.png b/packages/docs/static/img/effects-cylinder-preview.png
new file mode 100644
index 0000000000..53f5199728
Binary files /dev/null and b/packages/docs/static/img/effects-cylinder-preview.png differ
diff --git a/packages/effects/bundle.ts b/packages/effects/bundle.ts
index 50450fe454..788d2821a8 100644
--- a/packages/effects/bundle.ts
+++ b/packages/effects/bundle.ts
@@ -25,6 +25,7 @@ const effectEntrypoints = [
'src/fisheye.ts',
'src/flannel.ts',
'src/corner-pin.ts',
+ 'src/cylinder.ts',
'src/glow.ts',
'src/grayscale.ts',
'src/gridlines.ts',
diff --git a/packages/effects/package.json b/packages/effects/package.json
index 1869383420..33330a105c 100644
--- a/packages/effects/package.json
+++ b/packages/effects/package.json
@@ -89,6 +89,11 @@
"module": "./dist/esm/contour-lines.mjs",
"import": "./dist/esm/contour-lines.mjs"
},
+ "./cylinder": {
+ "types": "./dist/cylinder.d.ts",
+ "module": "./dist/esm/cylinder.mjs",
+ "import": "./dist/esm/cylinder.mjs"
+ },
"./drop-shadow": {
"types": "./dist/drop-shadow.d.ts",
"module": "./dist/esm/drop-shadow.mjs",
@@ -436,6 +441,9 @@
"contour-lines": [
"dist/contour-lines.d.ts"
],
+ "cylinder": [
+ "dist/cylinder.d.ts"
+ ],
"drop-shadow": [
"dist/drop-shadow.d.ts"
],
@@ -627,10 +635,11 @@
"homepage": "https://www.remotion.dev/docs/effects/api",
"devDependencies": {
"@remotion/eslint-config-internal": "workspace:*",
+ "@typescript/native-preview": "catalog:",
"@vitest/browser-playwright": "catalog:",
+ "@webgpu/types": "0.1.74",
"eslint": "catalog:",
- "vitest": "catalog:",
- "@typescript/native-preview": "catalog:"
+ "vitest": "catalog:"
},
"keywords": [
"remotion",
diff --git a/packages/effects/src/cylinder.ts b/packages/effects/src/cylinder.ts
new file mode 100644
index 0000000000..5919000df9
--- /dev/null
+++ b/packages/effects/src/cylinder.ts
@@ -0,0 +1,5 @@
+export {
+ cylinder,
+ type CylinderParams,
+ type CylinderRender,
+} from './cylinder/index.js';
diff --git a/packages/effects/src/cylinder/index.ts b/packages/effects/src/cylinder/index.ts
new file mode 100644
index 0000000000..fb2a4f961c
--- /dev/null
+++ b/packages/effects/src/cylinder/index.ts
@@ -0,0 +1,169 @@
+import type {InteractivitySchema} from 'remotion';
+import {Internals} from 'remotion';
+import {
+ assertOptionalFiniteNumber,
+ validateUnitInterval,
+} from '../color-utils.js';
+import {assertEffectParamsObject} from '../validate-effect-param.js';
+import {applyCylinder, cleanupCylinder, type CylinderState} from './runtime.js';
+
+const DEFAULT_RADIUS = 250;
+const DEFAULT_ROTATION = 0;
+const DEFAULT_POSITION = [0.5, 0.5] as const;
+const DEFAULT_RENDER = 'both';
+const DEFAULT_SHADING = 0.35;
+
+const cylinderSchema = {
+ radius: {
+ type: 'number',
+ min: 1,
+ max: 1000,
+ step: 1,
+ default: DEFAULT_RADIUS,
+ description: 'Radius',
+ hiddenFromList: false,
+ },
+ rotation: {
+ type: 'rotation-degrees',
+ default: DEFAULT_ROTATION,
+ description: 'Texture rotation',
+ },
+ rotationX: {
+ type: 'rotation-degrees',
+ default: DEFAULT_ROTATION,
+ description: 'X rotation',
+ },
+ rotationY: {
+ type: 'rotation-degrees',
+ default: DEFAULT_ROTATION,
+ description: 'Y rotation',
+ },
+ rotationZ: {
+ type: 'rotation-degrees',
+ default: DEFAULT_ROTATION,
+ description: 'Z rotation',
+ },
+ position: {
+ type: 'uv-coordinate',
+ default: DEFAULT_POSITION,
+ description: 'Position',
+ },
+ render: {
+ type: 'enum',
+ variants: {both: {}, front: {}, back: {}},
+ default: DEFAULT_RENDER,
+ description: 'Faces',
+ },
+ shading: {
+ type: 'number',
+ min: 0,
+ max: 1,
+ step: 0.01,
+ default: DEFAULT_SHADING,
+ description: 'Shading',
+ hiddenFromList: false,
+ },
+} as const satisfies InteractivitySchema;
+
+export type CylinderRender = 'both' | 'front' | 'back';
+
+export type CylinderParams = {
+ /** Cylinder radius in pixels. Defaults to 250. */
+ readonly radius?: number;
+ /** Texture rotation around the cylinder, in degrees. Defaults to 0. */
+ readonly rotation?: number;
+ /** Cylinder orientation in degrees, applied in X, Y, Z order. */
+ readonly rotationX?: number;
+ readonly rotationY?: number;
+ readonly rotationZ?: number;
+ /** Center as fractions of the canvas width and height. Defaults to [0.5, 0.5]. */
+ readonly position?: readonly [number, number];
+ /** Which faces to show. Defaults to 'both'. */
+ readonly render?: CylinderRender;
+ /** Darkening at the silhouette, from 0 to 1. Defaults to 0.35. */
+ readonly shading?: number;
+};
+
+const resolve = (params: CylinderParams) => ({
+ radius: params.radius ?? DEFAULT_RADIUS,
+ rotation: params.rotation ?? DEFAULT_ROTATION,
+ rotationX: params.rotationX ?? DEFAULT_ROTATION,
+ rotationY: params.rotationY ?? DEFAULT_ROTATION,
+ rotationZ: params.rotationZ ?? DEFAULT_ROTATION,
+ position: params.position ?? DEFAULT_POSITION,
+ render: params.render ?? DEFAULT_RENDER,
+ shading: params.shading ?? DEFAULT_SHADING,
+});
+
+export const cylinder = Internals.createEffect<CylinderParams, CylinderState>({
+ type: 'remotion/cylinder',
+ label: 'cylinder()',
+ documentationLink: 'https://www.remotion.dev/docs/effects/cylinder',
+ backend: 'webgpu',
+ schema: cylinderSchema,
+ validateParams: (params) => {
+ assertEffectParamsObject(params, 'Cylinder');
+ for (const key of [
+ 'radius',
+ 'rotation',
+ 'rotationX',
+ 'rotationY',
+ 'rotationZ',
+ 'shading',
+ ] as const) {
+ assertOptionalFiniteNumber(params[key], key);
+ }
+
+ const r = resolve(params);
+ if (r.radius <= 0) {
+ throw new TypeError('"radius" must be greater than 0');
+ }
+
+ validateUnitInterval(r.shading, 'shading');
+ if (
+ params.position !== undefined &&
+ (!Array.isArray(params.position) ||
+ params.position.length !== 2 ||
+ !Number.isFinite(params.position[0]) ||
+ !Number.isFinite(params.position[1]))
+ ) {
+ throw new TypeError('"position" must contain two finite numbers');
+ }
+
+ if (
+ params.render !== undefined &&
+ params.render !== 'both' &&
+ params.render !== 'front' &&
+ params.render !== 'back'
+ ) {
+ throw new TypeError('"render" must be "both", "front", or "back"');
+ }
+ },
+ calculateKey: (params) => {
+ const r = resolve(params);
+ return `cylinder-${r.radius}-${r.rotation}-${r.rotationX}-${r.rotationY}-${r.rotationZ}-${r.position.join(',')}-${r.render}-${r.shading}`;
+ },
+ setup: (target) => {
+ const context = target.getContext('webgpu');
+ if (!context) {
+ throw new Error('WebGPU is not available for the cylinder effect');
+ }
+
+ return {context: context as GPUCanvasContext, resources: null};
+ },
+ apply: ({source, width, height, params, state, gpuDevice}) => {
+ if (!gpuDevice) {
+ throw new Error('A WebGPU device is required for the cylinder effect');
+ }
+
+ applyCylinder({
+ source,
+ width,
+ height,
+ state,
+ device: gpuDevice as GPUDevice,
+ ...resolve(params),
+ });
+ },
+ cleanup: cleanupCylinder,
+});
diff --git a/packages/effects/src/cylinder/runtime.ts b/packages/effects/src/cylinder/runtime.ts
new file mode 100644
index 0000000000..e27de7caee
--- /dev/null
+++ b/packages/effects/src/cylinder/runtime.ts
@@ -0,0 +1,151 @@
+import type {CylinderRender} from './index.js';
+import {CYLINDER_SHADER} from './shader.js';
+
+export type CylinderState = {
+ context: GPUCanvasContext;
+ resources: {
+ device: GPUDevice;
+ pipeline: GPURenderPipeline;
+ uniforms: GPUBuffer;
+ sampler: GPUSampler;
+ texture: GPUTexture;
+ bindGroup: GPUBindGroup;
+ width: number;
+ height: number;
+ } | null;
+};
+
+export const cleanupCylinder = (state: CylinderState): void => {
+ state.resources?.texture.destroy();
+ state.resources?.uniforms.destroy();
+ state.resources = null;
+ state.context.unconfigure();
+};
+
+export const applyCylinder = ({
+ state,
+ source,
+ width,
+ height,
+ device,
+ radius,
+ rotation,
+ rotationX,
+ rotationY,
+ rotationZ,
+ position,
+ render,
+ shading,
+}: {
+ state: CylinderState;
+ source: CanvasImageSource;
+ width: number;
+ height: number;
+ device: GPUDevice;
+ radius: number;
+ rotation: number;
+ rotationX: number;
+ rotationY: number;
+ rotationZ: number;
+ position: readonly [number, number];
+ render: CylinderRender;
+ shading: number;
+}): void => {
+ if (
+ state.resources &&
+ (state.resources.device !== device ||
+ state.resources.width !== width ||
+ state.resources.height !== height)
+ ) {
+ cleanupCylinder(state);
+ }
+
+ if (!state.resources) {
+ const format = navigator.gpu.getPreferredCanvasFormat();
+ state.context.configure({device, format, alphaMode: 'premultiplied'});
+ const module = device.createShaderModule({code: CYLINDER_SHADER});
+ const pipeline = device.createRenderPipeline({
+ layout: 'auto',
+ vertex: {module, entryPoint: 'vertex'},
+ fragment: {module, entryPoint: 'fragment', targets: [{format}]},
+ primitive: {topology: 'triangle-list'},
+ });
+ const uniforms = device.createBuffer({
+ size: 48,
+ usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
+ });
+ const sampler = device.createSampler({
+ addressModeU: 'repeat',
+ magFilter: 'linear',
+ minFilter: 'linear',
+ });
+ const texture = device.createTexture({
+ size: [width, height],
+ format: 'rgba8unorm',
+ usage:
+ GPUTextureUsage.TEXTURE_BINDING |
+ GPUTextureUsage.COPY_DST |
+ GPUTextureUsage.RENDER_ATTACHMENT,
+ });
+ const bindGroup = device.createBindGroup({
+ layout: pipeline.getBindGroupLayout(0),
+ entries: [
+ {binding: 0, resource: texture.createView()},
+ {binding: 1, resource: sampler},
+ {binding: 2, resource: {buffer: uniforms}},
+ ],
+ });
+ state.resources = {
+ device,
+ pipeline,
+ uniforms,
+ sampler,
+ texture,
+ bindGroup,
+ width,
+ height,
+ };
+ }
+
+ const {resources} = state;
+ device.queue.copyExternalImageToTexture(
+ {source: source as GPUCopyExternalImageSource},
+ {texture: resources.texture, premultipliedAlpha: true},
+ [width, height],
+ );
+ const radians = Math.PI / 180;
+ device.queue.writeBuffer(
+ resources.uniforms,
+ 0,
+ new Float32Array([
+ width,
+ height,
+ position[0] * width,
+ position[1] * height,
+ radius,
+ (rotation % 360) * radians,
+ shading,
+ render === 'front' ? 1 : render === 'back' ? 2 : 0,
+ (rotationX % 360) * radians,
+ (rotationY % 360) * radians,
+ (rotationZ % 360) * radians,
+ 0,
+ ]),
+ );
+ const encoder = device.createCommandEncoder();
+ const pass = encoder.beginRenderPass({
+ colorAttachments: [
+ {
+ view: state.context.getCurrentTexture().createView(),
+ clearValue: {r: 0, g: 0, b: 0, a: 0},
+ loadOp: 'clear',
+ storeOp: 'store',
+ },
+ ],
+ });
+ pass.setPipeline(resources.pipeline);
+ pass.setBindGroup(0, resources.bindGroup);
+ pass.draw(3);
+ pass.end();
+ device.queue.submit([encoder.finish()]);
+};
diff --git a/packages/effects/src/cylinder/shader.ts b/packages/effects/src/cylinder/shader.ts
new file mode 100644
index 0000000000..e1b99d27c3
--- /dev/null
+++ b/packages/effects/src/cylinder/shader.ts
@@ -0,0 +1,54 @@
+export const CYLINDER_SHADER = /* wgsl */ `
+struct Params {
+ resolution: vec2f,
+ center: vec2f,
+ radius: f32,
+ spin: f32,
+ shading: f32,
+ faces: f32,
+ rotation: vec4f,
+}
+@group(0) @binding(0) var source: texture_2d<f32>;
+@group(0) @binding(1) var sourceSampler: sampler;
+@group(0) @binding(2) var<uniform> params: Params;
+
+@vertex fn vertex(@builtin(vertex_index) index: u32) -> @builtin(position) vec4f {
+ let positions = array<vec2f, 3>(vec2f(-1, -1), vec2f(3, -1), vec2f(-1, 3));
+ return vec4f(positions[index], 0, 1);
+}
+
+fn sampleFace(point: vec3f, inverse: mat3x3f, rotation: mat3x3f) -> vec4f {
+ let local = inverse * point;
+ let uv = vec2f(fract((atan2(local.x, local.z) + params.spin) / 6.28318530718 + 0.5), local.y / params.resolution.y + 0.5);
+ let color = textureSampleLevel(source, sourceSampler, uv, 0);
+ if (uv.y < 0 || uv.y > 1) { return vec4f(0); }
+ let normal = rotation * vec3f(local.x / params.radius, 0, local.z / params.radius);
+ let shade = mix(1.0, abs(normal.z), params.shading);
+ return vec4f(color.rgb * shade, color.a);
+}
+
+@fragment fn fragment(@builtin(position) position: vec4f) -> @location(0) vec4f {
+ let s = sin(params.rotation.xyz);
+ let c = cos(params.rotation.xyz);
+ let rx = mat3x3f(vec3f(1, 0, 0), vec3f(0, c.x, s.x), vec3f(0, -s.x, c.x));
+ let ry = mat3x3f(vec3f(c.y, 0, -s.y), vec3f(0, 1, 0), vec3f(s.y, 0, c.y));
+ let rz = mat3x3f(vec3f(c.z, s.z, 0), vec3f(-s.z, c.z, 0), vec3f(0, 0, 1));
+ let rotation = rz * ry * rx;
+ let axis = rotation[1];
+ let p = position.xy - params.center;
+ // Orthographic viewing ray intersecting the rotated, open cylinder wall.
+ let a = 1.0 - axis.z * axis.z;
+ let da = dot(p, axis.xy);
+ let b = -da * axis.z;
+ let discriminant = b * b - a * (dot(p, p) - da * da - params.radius * params.radius);
+ if (a < 0.000001 || discriminant <= 0) { return vec4f(0); }
+ let root = sqrt(discriminant);
+ let inverse = transpose(rotation);
+ let front = sampleFace(vec3f(p, (-b + root) / a), inverse, rotation);
+ let back = sampleFace(vec3f(p, (-b - root) / a), inverse, rotation);
+ if (params.faces == 1) { return front; }
+ if (params.faces == 2) { return back; }
+ // Both the texture and output use premultiplied alpha.
+ return front + back * (1.0 - front.a);
+}
+`;
diff --git a/packages/effects/tsconfig.json b/packages/effects/tsconfig.json
index 143a0d2e89..896abfa762 100644
--- a/packages/effects/tsconfig.json
+++ b/packages/effects/tsconfig.json
@@ -2,6 +2,7 @@
"extends": "../tsconfig.settings.json",
"compilerOptions": {
"rootDir": "src",
+ "types": ["bun", "@webgpu/types"],
"outDir": "dist",
"skipLibCheck": true,
"target": "ES2022",
diff --git a/packages/skills/skills/remotion-markup/effects.md b/packages/skills/skills/remotion-markup/effects.md
index 5912d80f07..e478be84c4 100644
--- a/packages/skills/skills/remotion-markup/effects.md
+++ b/packages/skills/skills/remotion-markup/effects.md
@@ -52,7 +52,7 @@ import {blur} from '@remotion/effects/blur';
Use the effect docs for exact props and imports. Most `@remotion/effects` imports use `@remotion/effects/<effect-slug>`; `uvTranslate()` and `xyTranslate()` use `@remotion/effects/translate`.
-These effects use WebGL2. During renders, enable WebGL with:
+Most effects use WebGL2; `cylinder()` uses WebGPU. During renders, enable WebGL and WebGPU with:
```ts
import {Config} from '@remotion/cli/config';
diff --git a/packages/studio-shared/src/effect-catalog.ts b/packages/studio-shared/src/effect-catalog.ts
index 33f9db2201..888db713c6 100644
--- a/packages/studio-shared/src/effect-catalog.ts
+++ b/packages/studio-shared/src/effect-catalog.ts
@@ -530,6 +530,17 @@ export const EFFECT_CATALOG: readonly EffectCatalogItem[] = [
},
},
},
+ {
+ id: 'effects-cylinder',
+ category: 'Distort',
+ label: 'cylinder()',
+ description: 'Wrap content around a rotating cylinder',
+ effect: {
+ name: 'cylinder',
+ importPath: '@remotion/effects/cylinder',
+ config: {},
+ },
+ },
{
id: 'effects-wave',
category: 'Distort',