Skip to content

🎥 Make videos programmatically with React

Add turbulentDisplace effect and interactive text demo

Jonny Burger7a58c217a92c
diff --git a/packages/docs/components/demos/index.tsx b/packages/docs/components/demos/index.tsx
index a0bdf63616..7da0e6a645 100644
--- a/packages/docs/components/demos/index.tsx
+++ b/packages/docs/components/demos/index.tsx
@@ -24,6 +24,7 @@ import {
sphereGlobeDemo,
pageTurnDemo,
fractalNoiseDemo,
+ turbulentDisplaceDemo,
customPresentationDemo,
customTimingDemo,
dissolvePresentationDemo,
@@ -161,6 +162,7 @@ const demos: DemoType[] = [
sphereGlobeDemo,
pageTurnDemo,
fractalNoiseDemo,
+ turbulentDisplaceDemo,
animationMathDemo,
roundedTextBoxDemo,
springDemo,
diff --git a/packages/docs/components/demos/types.ts b/packages/docs/components/demos/types.ts
index f8d40f8ffe..817b606c48 100644
--- a/packages/docs/components/demos/types.ts
+++ b/packages/docs/components/demos/types.ts
@@ -2,6 +2,7 @@ import type {LogLevel} from 'remotion';
import {FractalNoiseDemo} from '../effects/effects-fractal-noise-preview';
import {PageTurnDemo} from '../effects/effects-page-turn-preview';
import {SpinningGlobeDemo} from '../effects/effects-sphere-preview';
+import {TurbulentDisplaceDemo} from '../effects/effects-turbulent-displace-preview';
import {
ClockWipeDemo,
CubeDemo,
@@ -1799,3 +1800,16 @@ export const fractalNoiseDemo: DemoType = {
logLevel: 'info',
options: [],
};
+
+export const turbulentDisplaceDemo: DemoType = {
+ comp: TurbulentDisplaceDemo,
+ compWidth: 1280,
+ compHeight: 720,
+ fps: 30,
+ durationInFrames: 120,
+ id: 'turbulent-displace',
+ 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 d6e4cf8f4b..74f83bf77e 100644
--- a/packages/docs/components/effects-demos/registry.ts
+++ b/packages/docs/components/effects-demos/registry.ts
@@ -65,6 +65,7 @@ import {thermalVision} from '@remotion/effects/thermal-vision';
import {tile} from '@remotion/effects/tile';
import {tint} from '@remotion/effects/tint';
import {uvTranslate, xyTranslate} from '@remotion/effects/translate';
+import {turbulentDisplace} from '@remotion/effects/turbulent-displace';
import {tvSignalOff} from '@remotion/effects/tv-signal-off';
import {venetianBlinds} from '@remotion/effects/venetian-blinds';
import {vibrance} from '@remotion/effects/vibrance';
@@ -170,6 +171,7 @@ import {
EffectsUvTranslatePreview,
EffectsXyTranslatePreview,
} from '../effects/effects-translate-preview';
+import {EffectsTurbulentDisplacePreview} from '../effects/effects-turbulent-displace-preview';
import {EffectsTvSignalOffPreview} from '../effects/effects-tv-signal-off-preview';
import {EffectsVenetianBlindsPreview} from '../effects/effects-venetian-blinds-preview';
import {EffectsVibrancePreview} from '../effects/effects-vibrance-preview';
@@ -204,6 +206,14 @@ const shrinkwrapDemoSchema = {
const cylinderDemoSchema = cylinder().definition.schema;
export const effectsDemos: EffectsDemoType[] = [
+ {
+ ...defaults,
+ id: 'effects-turbulent-displace',
+ effectName: 'turbulentDisplace',
+ effectImportPath: '@remotion/effects/turbulent-displace',
+ comp: EffectsTurbulentDisplacePreview,
+ schema: turbulentDisplace().definition.schema,
+ },
{
...defaults,
id: 'effects-fractal-noise',
diff --git a/packages/docs/components/effects/effects-turbulent-displace-preview.tsx b/packages/docs/components/effects/effects-turbulent-displace-preview.tsx
new file mode 100644
index 0000000000..1ee68961f0
--- /dev/null
+++ b/packages/docs/components/effects/effects-turbulent-displace-preview.tsx
@@ -0,0 +1,105 @@
+import {
+ turbulentDisplace,
+ type TurbulentDisplaceParams,
+} from '@remotion/effects/turbulent-displace';
+import React from 'react';
+import {
+ AbsoluteFill,
+ CanvasImage,
+ Easing,
+ HtmlInCanvas,
+ Interactive,
+ interpolate,
+ staticFile,
+ useCurrentFrame,
+} from 'remotion';
+
+export const TurbulentDisplaceTextSource: React.FC = () => {
+ return (
+ <Interactive.Div
+ name="Fluid text"
+ style={{
+ width: '100%',
+ height: '100%',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ fontFamily: 'Arial, Helvetica, sans-serif',
+ fontSize: 170,
+ fontWeight: 900,
+ lineHeight: 1,
+ color: 'white',
+ }}
+ >
+ STAY FLUID
+ </Interactive.Div>
+ );
+};
+
+export const EffectsTurbulentDisplacePreview: React.FC<
+ Required<TurbulentDisplaceParams>
+> = ({
+ displacement,
+ amount,
+ size,
+ offset,
+ complexity,
+ evolution,
+ cycleEvolution,
+ cycle,
+ seed,
+ pinning,
+}) => {
+ return (
+ <AbsoluteFill style={{backgroundColor: 'black'}}>
+ <CanvasImage
+ name="Distorted text"
+ src={staticFile('img/effects-turbulent-displace-text.png')}
+ width={1280}
+ height={720}
+ fit="cover"
+ effects={[
+ turbulentDisplace({
+ displacement,
+ amount,
+ size,
+ offset,
+ complexity,
+ evolution,
+ cycleEvolution,
+ cycle,
+ seed,
+ pinning,
+ }),
+ ]}
+ />
+ </AbsoluteFill>
+ );
+};
+
+export const TurbulentDisplaceDemo: React.FC = () => {
+ const frame = useCurrentFrame();
+ return (
+ <AbsoluteFill style={{backgroundColor: 'black'}}>
+ <HtmlInCanvas
+ name="Melting text"
+ width={1280}
+ height={720}
+ effects={[
+ turbulentDisplace({
+ amount: interpolate(frame, [0, 30, 90, 120], [0, 120, 120, 0], {
+ easing: Easing.bezier(0.42, 0, 0.58, 1),
+ }),
+ size: 150,
+ complexity: 2,
+ cycleEvolution: true,
+ evolution: interpolate(frame, [0, 120], [0, 360]),
+ pinning: 'all',
+ }),
+ ]}
+ >
+ <TurbulentDisplaceTextSource />
+ </HtmlInCanvas>
+ </AbsoluteFill>
+ );
+};
diff --git a/packages/docs/docs/effects/turbulent-displace.mdx b/packages/docs/docs/effects/turbulent-displace.mdx
new file mode 100644
index 0000000000..eeaa716ea7
--- /dev/null
+++ b/packages/docs/docs/effects/turbulent-displace.mdx
@@ -0,0 +1,151 @@
+---
+image: /generated/articles-docs-effects-turbulent-displace.png
+slug: /effects/turbulent-displace
+title: turbulentDisplace()
+sidebar_label: turbulentDisplace()
+crumb: '@remotion/effects'
+---
+
+# turbulentDisplace()<AvailableFrom v="4.0.537" />
+
+_Part of the [`@remotion/effects`](/docs/effects/api) package._
+
+Warps a layer using evolving fractal noise. Use it for liquid text, heat haze and organic distortion. The effect moves color and alpha together, so it can deform the outlines of text and shapes.
+
+## Preview
+
+<Demo type="turbulent-displace" />
+
+## Controls
+
+<EffectsDemo type="effects-turbulent-displace" />
+
+## Example
+
+```tsx twoslash title="MyComp.tsx"
+import {turbulentDisplace} from '@remotion/effects/turbulent-displace';
+import {AbsoluteFill, HtmlInCanvas, Interactive, interpolate, useCurrentFrame} from 'remotion';
+
+export const MyComp: React.FC = () => {
+ const frame = useCurrentFrame();
+
+ return (
+ <AbsoluteFill style={{backgroundColor: 'black'}}>
+ <HtmlInCanvas
+ width={1280}
+ height={720}
+ effects={[
+ turbulentDisplace({
+ amount: 120,
+ size: 150,
+ complexity: 2,
+ cycleEvolution: true,
+ evolution: interpolate(frame, [0, 120], [0, 360]),
+ pinning: 'all',
+ }),
+ ]}
+ >
+ <Interactive.Div
+ name="Fluid text"
+ style={{
+ width: '100%',
+ height: '100%',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ fontFamily: 'Arial, Helvetica, sans-serif',
+ fontSize: 170,
+ fontWeight: 900,
+ color: 'white',
+ }}
+ >
+ STAY FLUID
+ </Interactive.Div>
+ </HtmlInCanvas>
+ </AbsoluteFill>
+ );
+};
+```
+
+## API
+
+Pass an object with the following properties. You can also call `turbulentDisplace()` without arguments.
+
+### `displacement?`
+
+Distortion mode. Defaults to `"turbulent"`.
+
+- `"turbulent"`: Displace horizontally and vertically using independent noise fields.
+- `"bulge"`: Push pixels along the slope of the noise field.
+- `"twist"`: Push pixels perpendicular to that slope.
+- `"turbulent-smoother"`, `"bulge-smoother"`, `"twist-smoother"`: Reduce the strength of finer noise layers for smoother distortion.
+- `"vertical"`: Move pixels vertically.
+- `"horizontal"`: Move pixels horizontally.
+- `"cross"`: Apply the same displacement to both axes, producing diagonal movement.
+
+### `amount?`
+
+Distortion strength in pixels. Defaults to `50`. Set to `0` to leave the source unchanged. Negative values reverse the displacement.
+
+### `size?`
+
+Size of the largest noise features in pixels. Must be at least `1`. Defaults to `100`. Larger values create broader bends.
+
+### `offset?`
+
+Origin of the noise field as an `[x, y]` tuple in normalized coordinates, where `[0, 0]` is the top-left and `[1, 1]` is the bottom-right. Defaults to `[0.5, 0.5]`. Values outside the canvas are allowed. Animate this value to move the distortion across the layer.
+
+### `complexity?`
+
+Number of noise layers, from `1` to `10`. Defaults to `1`. Fractional values smoothly introduce the next layer. Higher values add finer detail and take longer to render.
+
+The smoother displacement modes reduce the influence of these finer layers. At a complexity of `1`, they match their regular counterparts.
+
+### `evolution?`
+
+Evolution of the noise in degrees. Defaults to `0`. Animate it to morph the distortion without translating the noise field.
+
+By default, `360` continues to a new pattern. Enable `cycleEvolution` to repeat after `cycle * 360` degrees.
+
+### `cycleEvolution?`
+
+Whether to loop the distortion. Defaults to `false`. When enabled, evolution repeats smoothly after `cycle` revolutions.
+
+### `cycle?`
+
+Length of the evolution loop in revolutions, where one revolution is `360` degrees. Must be an integer from `1` to `65535`. Defaults to `1`. Used when `cycleEvolution` is `true`.
+
+### `seed?`
+
+Integer from `0` to `4294967295` selecting a repeatable noise pattern. Defaults to `0`. Animate `evolution` instead of `seed` for smooth changes.
+
+### `pinning?`
+
+Edges that stay in place. Defaults to `"all"`. The distortion fades out near pinned edges.
+
+- `"none"`: Do not pin edges.
+- `"all"`: Pin all four edges.
+- `"horizontal"`: Pin the top and bottom edges.
+- `"vertical"`: Pin the left and right edges.
+- `"left"`, `"top"`, `"right"`, `"bottom"`: Pin one edge.
+
+The variants `"all-locked"`, `"horizontal-locked"`, `"vertical-locked"`, `"left-locked"`, `"top-locked"`, `"right-locked"` and `"bottom-locked"` also clamp source sampling to the canvas bounds. This prevents transparent gaps caused by sampling outside the source, with a wider fade near pinned edges.
+
+The canvas size stays unchanged. Pixels moved outside it are cropped.
+
+### `disabled?`
+
+When `true`, the effect is skipped. Defaults to `false`.
+
+## Requirements
+
+`turbulentDisplace()` uses WebGL2. See [Using WebGL and WebGPU during renders](/docs/webgl).
+
+The animated text example also uses [`<HtmlInCanvas>`](/docs/remotion/html-in-canvas).
+
+## See also
+
+- [`fractalNoise()`](/docs/effects/fractal-noise)
+- [`noiseDisplacement()`](/docs/effects/noise-displacement)
+- [`wave()`](/docs/effects/wave)
+- [Source code for this effect](https://github.com/remotion-dev/remotion/tree/main/packages/effects/src/turbulent-displace)
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index 444afec5d1..7543678d4f 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -348,6 +348,7 @@ const sidebars: SidebarsConfig = {
'effects/thermal-vision',
'effects/tile',
'effects/tint',
+ 'effects/turbulent-displace',
'effects/tv-signal-off',
'effects/uv-translate',
'effects/venetian-blinds',
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index f4dee7d9f9..0d33307b2b 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -3987,6 +3987,15 @@ export const articles = [
noAi: false,
slug: 'effects/tint',
},
+ {
+ id: 'effects/turbulent-displace',
+ title: 'turbulentDisplace()',
+ relativePath: 'docs/effects/turbulent-displace.mdx',
+ compId: 'articles-docs-effects-turbulent-displace',
+ crumb: '@remotion/effects',
+ noAi: false,
+ slug: 'effects/turbulent-displace',
+ },
{
id: 'effects/tv-signal-off',
title: 'tvSignalOff()',
diff --git a/packages/docs/src/remotion/Root.tsx b/packages/docs/src/remotion/Root.tsx
index 8210d83867..71ab3863a9 100644
--- a/packages/docs/src/remotion/Root.tsx
+++ b/packages/docs/src/remotion/Root.tsx
@@ -119,6 +119,11 @@ import {
EffectsUvTranslatePreview,
EffectsXyTranslatePreview,
} from '../../components/effects/effects-translate-preview';
+import {
+ EffectsTurbulentDisplacePreview,
+ TurbulentDisplaceDemo,
+ TurbulentDisplaceTextSource,
+} from '../../components/effects/effects-turbulent-displace-preview';
import {EffectsTvSignalOffPreview} from '../../components/effects/effects-tv-signal-off-preview';
import {EffectsVenetianBlindsPreview} from '../../components/effects/effects-venetian-blinds-preview';
import {EffectsVibrancePreview} from '../../components/effects/effects-vibrance-preview';
@@ -438,6 +443,39 @@ export const RemotionRoot: React.FC = () => {
feather: 0.18,
}}
/>
+ <Still
+ id="effects-turbulent-displace-text-source"
+ component={TurbulentDisplaceTextSource}
+ width={1280}
+ height={720}
+ />
+ <Still
+ id="effects-turbulent-displace-preview"
+ component={EffectsTurbulentDisplacePreview}
+ width={1280}
+ height={720}
+ defaultProps={{
+ displacement: 'turbulent',
+ amount: 120,
+ size: 150,
+ offset: [0.5, 0.5],
+ complexity: 2,
+ evolution: 90,
+ cycleEvolution: false,
+ cycle: 1,
+ seed: 0,
+ pinning: 'all',
+ }}
+ />
+ <Composition
+ id="turbulent-displace-demo"
+ component={TurbulentDisplaceDemo}
+ width={1280}
+ height={720}
+ fps={30}
+ durationInFrames={120}
+ />
+
<Still
id="effects-fractal-noise-preview"
component={EffectsFractalNoisePreview}
diff --git a/packages/docs/static/generated/articles-docs-effects-turbulent-displace.png b/packages/docs/static/generated/articles-docs-effects-turbulent-displace.png
new file mode 100644
index 0000000000..c0162749ec
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-effects-turbulent-displace.png differ
diff --git a/packages/docs/static/img/effects-turbulent-displace-preview.png b/packages/docs/static/img/effects-turbulent-displace-preview.png
new file mode 100644
index 0000000000..5667d94e8a
Binary files /dev/null and b/packages/docs/static/img/effects-turbulent-displace-preview.png differ
diff --git a/packages/docs/static/img/effects-turbulent-displace-text.png b/packages/docs/static/img/effects-turbulent-displace-text.png
new file mode 100644
index 0000000000..83235f694c
Binary files /dev/null and b/packages/docs/static/img/effects-turbulent-displace-text.png differ
diff --git a/packages/effects/THIRD_PARTY_LICENSES.md b/packages/effects/THIRD_PARTY_LICENSES.md
index 0aa26b18bd..8f2e486b7e 100644
--- a/packages/effects/THIRD_PARTY_LICENSES.md
+++ b/packages/effects/THIRD_PARTY_LICENSES.md
@@ -2,7 +2,8 @@
## EffectCraft
-The Fractal Noise shader is adapted from the value-noise engine in
+The Fractal Noise and Turbulent Displace shaders are adapted from the noise
+and distortion engines in
[EffectCraft](https://github.com/storytold/effectcraft), revision
`8f02f52a44a4b1ea807d8824b92301b96f896a06`. It is used under the MIT license.
diff --git a/packages/effects/bundle.ts b/packages/effects/bundle.ts
index 18bb772d64..fd038e4cdc 100644
--- a/packages/effects/bundle.ts
+++ b/packages/effects/bundle.ts
@@ -74,6 +74,7 @@ const effectEntrypoints = [
'src/tile.ts',
'src/tint.ts',
'src/translate.ts',
+ 'src/turbulent-displace.ts',
'src/tv-signal-off.ts',
'src/venetian-blinds.ts',
'src/vibrance.ts',
diff --git a/packages/effects/package.json b/packages/effects/package.json
index 1d732632ac..9e3be7109e 100644
--- a/packages/effects/package.json
+++ b/packages/effects/package.json
@@ -369,6 +369,11 @@
"module": "./dist/esm/translate.mjs",
"import": "./dist/esm/translate.mjs"
},
+ "./turbulent-displace": {
+ "types": "./dist/turbulent-displace.d.ts",
+ "module": "./dist/esm/turbulent-displace.mjs",
+ "import": "./dist/esm/turbulent-displace.mjs"
+ },
"./tv-signal-off": {
"types": "./dist/tv-signal-off.d.ts",
"module": "./dist/esm/tv-signal-off.mjs",
@@ -624,6 +629,9 @@
"translate": [
"dist/translate.d.ts"
],
+ "turbulent-displace": [
+ "dist/turbulent-displace.d.ts"
+ ],
"tv-signal-off": [
"dist/tv-signal-off.d.ts"
],
diff --git a/packages/effects/src/fractal-noise/shader.ts b/packages/effects/src/fractal-noise/shader.ts
index e946608743..42ab8b6b9a 100644
--- a/packages/effects/src/fractal-noise/shader.ts
+++ b/packages/effects/src/fractal-noise/shader.ts
@@ -1,3 +1,5 @@
+import {VALUE_NOISE_SHADER} from '../value-noise-shader.js';
+
// Adapted to WebGL2; see ../../THIRD_PARTY_LICENSES.md.
// Multi-octave value noise and texture modes based on Effectcraft's noise3.rs:
// https://github.com/storytold/effectcraft/blob/8f02f52a44a4b1ea807d8824b92301b96f896a06/crates/effects/src/noise3.rs
@@ -25,66 +27,7 @@ uniform int uNoiseType;
uniform bool uInvert;
uniform bool uCycleEvolution;
-float lattice(ivec3 point, uint seed) {
- // Wrap lattice indices as well as coordinates so interpolation stays continuous
- // across the period boundary, including negative coordinates.
- uvec3 p = uvec3(point) & uvec3(65535u);
- uint h = p.x * 0x27d4eb2du ^ p.y * 0x165667b1u ^ p.z * 0x9e3779b9u ^ seed * 0x85ebca6bu;
- h ^= h >> 15;
- h *= 0x2c1b3c6du;
- h ^= h >> 12;
- h *= 0x297a2d39u;
- h ^= h >> 15;
- return float(h & 65535u) / 65535.0;
-}
-
-float catmull(vec4 p, float t) {
- return 0.5 * (2.0 * p.y + (p.z - p.x) * t
- + (2.0 * p.x - 5.0 * p.y + 4.0 * p.z - p.w) * t * t
- + (3.0 * p.y - p.x - 3.0 * p.z + p.w) * t * t * t);
-}
-
-vec3 bspline(float t) {
- return vec3(0.5 * (1.0-t) * (1.0-t), 0.5 + t * (1.0-t), 0.5 * t * t);
-}
-
-float sliceNoise(ivec3 p, vec2 t, uint seed) {
- if (uNoiseType == 0) return lattice(p, seed);
- if (uNoiseType == 1) {
- return mix(mix(lattice(p, seed), lattice(p + ivec3(1,0,0), seed), t.x),
- mix(lattice(p + ivec3(0,1,0), seed), lattice(p + ivec3(1,1,0), seed), t.x), t.y);
- }
- if (uNoiseType == 2) {
- vec3 wx = bspline(t.x);
- vec3 wy = bspline(t.y);
- float result = 0.0;
- for (int y = 0; y < 3; y++) {
- for (int x = 0; x < 3; x++) {
- result += wx[x] * wy[y] * lattice(p + ivec3(x-1, y-1, 0), seed);
- }
- }
- return result;
- }
- vec4 rows;
- for (int y = 0; y < 4; y++) {
- vec4 row;
- for (int x = 0; x < 4; x++) {
- row[x] = lattice(p + ivec3(x-1, y-1, 0), seed);
- }
- rows[y] = catmull(row, t.x);
- }
- return catmull(rows, t.y);
-}
-
-float valueNoise(vec3 point, uint seed) {
- // A large period keeps conversion to integer coordinates defined at extreme scales.
- vec3 p = mod(point + vec3(uNoiseType == 2 ? 0.5 : 0.0, uNoiseType == 2 ? 0.5 : 0.0, 0.0), 65536.0);
- ivec3 cell = ivec3(floor(p));
- vec3 t = fract(p);
- float fz = t.z * t.z * t.z * (t.z * (t.z * 6.0 - 15.0) + 10.0);
- float n = mix(sliceNoise(cell, t.xy, seed), sliceNoise(cell + ivec3(0,0,1), t.xy, seed), fz);
- return uNoiseType == 2 ? 0.5 + (n - 0.5) * (181.0 / 231.0) / 0.55 : n;
-}
+${VALUE_NOISE_SHADER}
float layer(vec2 p, float z, uint seed) {
if (!uCycleEvolution) return valueNoise(vec3(p, uEvolution + z), seed);
diff --git a/packages/effects/src/turbulent-displace.ts b/packages/effects/src/turbulent-displace.ts
new file mode 100644
index 0000000000..4d8066064c
--- /dev/null
+++ b/packages/effects/src/turbulent-displace.ts
@@ -0,0 +1,4 @@
+export {
+ turbulentDisplace,
+ type TurbulentDisplaceParams,
+} from './turbulent-displace/index.js';
diff --git a/packages/effects/src/turbulent-displace/index.ts b/packages/effects/src/turbulent-displace/index.ts
new file mode 100644
index 0000000000..ea899d11c1
--- /dev/null
+++ b/packages/effects/src/turbulent-displace/index.ts
@@ -0,0 +1,469 @@
+import type {InteractivitySchema} from 'remotion';
+import {Internals} from 'remotion';
+import {assertOptionalFiniteNumber} from '../color-utils.js';
+import {
+ assertEffectParamsObject,
+ assertOptionalBoolean,
+ assertRequiredFiniteNumber,
+} from '../validate-effect-param.js';
+import {TURBULENT_DISPLACE_FRAGMENT_SHADER} from './shader.js';
+
+const {createEffect, createWebGL2ContextError} = Internals;
+
+const DEFAULT_DISPLACEMENT = 'turbulent' as const;
+const DEFAULT_AMOUNT = 50 as const;
+const DEFAULT_SIZE = 100 as const;
+const DEFAULT_OFFSET = [0.5, 0.5] as const;
+const DEFAULT_COMPLEXITY = 1 as const;
+const DEFAULT_EVOLUTION = 0 as const;
+const DEFAULT_CYCLE_EVOLUTION = false as const;
+const DEFAULT_CYCLE = 1 as const;
+const DEFAULT_SEED = 0 as const;
+const DEFAULT_PINNING = 'all' as const;
+const DISPLACEMENT_MODES = [
+ 'turbulent',
+ 'bulge',
+ 'twist',
+ 'turbulent-smoother',
+ 'bulge-smoother',
+ 'twist-smoother',
+ 'vertical',
+ 'horizontal',
+ 'cross',
+] as const;
+const PINNING_MODES = [
+ 'none',
+ 'all',
+ 'horizontal',
+ 'vertical',
+ 'left',
+ 'top',
+ 'right',
+ 'bottom',
+ 'all-locked',
+ 'horizontal-locked',
+ 'vertical-locked',
+ 'left-locked',
+ 'top-locked',
+ 'right-locked',
+ 'bottom-locked',
+] as const;
+
+const turbulentDisplaceSchema = {
+ displacement: {
+ type: 'enum',
+ variants: {
+ turbulent: {},
+ bulge: {},
+ twist: {},
+ 'turbulent-smoother': {},
+ 'bulge-smoother': {},
+ 'twist-smoother': {},
+ vertical: {},
+ horizontal: {},
+ cross: {},
+ },
+ default: DEFAULT_DISPLACEMENT,
+ description: 'Displacement',
+ },
+ amount: {
+ type: 'number',
+ min: -200,
+ max: 200,
+ step: 1,
+ default: DEFAULT_AMOUNT,
+ description: 'Amount',
+ hiddenFromList: false,
+ },
+ size: {
+ type: 'number',
+ min: 1,
+ max: 1000,
+ step: 1,
+ default: DEFAULT_SIZE,
+ description: 'Size',
+ hiddenFromList: false,
+ },
+ offset: {
+ type: 'uv-coordinate',
+ step: 0.01,
+ default: DEFAULT_OFFSET,
+ description: 'Offset',
+ },
+ complexity: {
+ type: 'number',
+ min: 1,
+ max: 10,
+ step: 0.1,
+ default: DEFAULT_COMPLEXITY,
+ description: 'Complexity',
+ hiddenFromList: false,
+ },
+ evolution: {
+ type: 'rotation-degrees',
+ step: 1,
+ default: DEFAULT_EVOLUTION,
+ description: 'Evolution',
+ },
+ cycleEvolution: {
+ type: 'boolean',
+ default: DEFAULT_CYCLE_EVOLUTION,
+ description: 'Cycle evolution',
+ },
+ cycle: {
+ type: 'number',
+ min: 1,
+ max: 100,
+ step: 1,
+ integer: true,
+ default: DEFAULT_CYCLE,
+ description: 'Cycle length',
+ hiddenFromList: false,
+ },
+ seed: {
+ type: 'number',
+ min: 0,
+ max: 4294967295,
+ step: 1,
+ integer: true,
+ default: DEFAULT_SEED,
+ description: 'Seed',
+ hiddenFromList: false,
+ },
+ pinning: {
+ type: 'enum',
+ variants: {
+ none: {},
+ all: {},
+ horizontal: {},
+ vertical: {},
+ left: {},
+ top: {},
+ right: {},
+ bottom: {},
+ 'all-locked': {},
+ 'horizontal-locked': {},
+ 'vertical-locked': {},
+ 'left-locked': {},
+ 'top-locked': {},
+ 'right-locked': {},
+ 'bottom-locked': {},
+ },
+ default: DEFAULT_PINNING,
+ description: 'Pinning',
+ },
+} as const satisfies InteractivitySchema;
+
+export type TurbulentDisplaceParams = {
+ /** Distortion mode. Defaults to `turbulent`. */
+ readonly displacement?: (typeof DISPLACEMENT_MODES)[number];
+ /** Displacement strength in pixels. May be negative. Defaults to `50`. */
+ readonly amount?: number;
+ /** Size of the noise features in pixels. Must be at least `1`. Defaults to `100`. */
+ readonly size?: number;
+ /** Noise origin in UV coordinates. Defaults to `[0.5, 0.5]`. */
+ readonly offset?: readonly [number, number];
+ /** Number of noise layers, including fractional layers, from `1` to `10`. Defaults to `1`. */
+ readonly complexity?: number;
+ /** Noise evolution in degrees. Animate to morph the distortion. Defaults to `0`. */
+ readonly evolution?: number;
+ /** Loop the evolution after `cycle` revolutions. Defaults to `false`. */
+ readonly cycleEvolution?: boolean;
+ /** Loop length in whole revolutions. Defaults to `1`. */
+ readonly cycle?: number;
+ /** Unsigned 32-bit integer seed for repeatable distortion. Defaults to `0`. */
+ readonly seed?: number;
+ /** Edges kept in place. Locked modes also keep samples inside the source. Defaults to `all`. */
+ readonly pinning?: (typeof PINNING_MODES)[number];
+};
+
+type TurbulentDisplaceResolved = Required<TurbulentDisplaceParams>;
+
+const resolve = (
+ params: TurbulentDisplaceParams,
+): TurbulentDisplaceResolved => ({
+ displacement: params.displacement ?? DEFAULT_DISPLACEMENT,
+ amount: params.amount ?? DEFAULT_AMOUNT,
+ size: params.size ?? DEFAULT_SIZE,
+ offset: params.offset ?? DEFAULT_OFFSET,
+ complexity: params.complexity ?? DEFAULT_COMPLEXITY,
+ evolution: params.evolution ?? DEFAULT_EVOLUTION,
+ cycleEvolution: params.cycleEvolution ?? DEFAULT_CYCLE_EVOLUTION,
+ cycle: params.cycle ?? DEFAULT_CYCLE,
+ seed: params.seed ?? DEFAULT_SEED,
+ pinning: params.pinning ?? DEFAULT_PINNING,
+});
+
+const validateTurbulentDisplaceParams = (
+ params: TurbulentDisplaceParams,
+): void => {
+ assertEffectParamsObject(params, 'Turbulent displace');
+ assertOptionalFiniteNumber(params.amount, 'amount');
+ assertOptionalFiniteNumber(params.size, 'size');
+ assertOptionalFiniteNumber(params.complexity, 'complexity');
+ assertOptionalFiniteNumber(params.evolution, 'evolution');
+ assertOptionalBoolean(params.cycleEvolution, 'cycleEvolution');
+ assertOptionalFiniteNumber(params.cycle, 'cycle');
+ assertOptionalFiniteNumber(params.seed, 'seed');
+ if (
+ params.displacement !== undefined &&
+ !DISPLACEMENT_MODES.includes(params.displacement)
+ ) {
+ throw new TypeError(
+ 'Invalid displacement: ' + JSON.stringify(params.displacement),
+ );
+ }
+
+ if (params.pinning !== undefined && !PINNING_MODES.includes(params.pinning)) {
+ throw new TypeError('Invalid pinning: ' + JSON.stringify(params.pinning));
+ }
+
+ if (params.offset !== undefined) {
+ if (!Array.isArray(params.offset) || params.offset.length !== 2)
+ throw new TypeError('"offset" must be a two-number tuple');
+ assertRequiredFiniteNumber(params.offset[0], 'offset[0]');
+ assertRequiredFiniteNumber(params.offset[1], 'offset[1]');
+ }
+
+ const r = resolve(params);
+ if (r.size < 1) throw new TypeError('"size" must be at least 1');
+ if (r.complexity < 1 || r.complexity > 10)
+ throw new TypeError('"complexity" must be between 1 and 10');
+ if (!Number.isInteger(r.cycle) || r.cycle < 1 || r.cycle > 65535)
+ throw new TypeError('"cycle" must be an integer between 1 and 65535');
+ if (!Number.isInteger(r.seed) || r.seed < 0 || r.seed > 4294967295)
+ throw new TypeError('"seed" must be an unsigned 32-bit integer');
+};
+
+type TurbulentDisplaceState = {
+ readonly gl: WebGL2RenderingContext;
+ readonly program: WebGLProgram;
+ readonly vao: WebGLVertexArrayObject;
+ readonly vbo: WebGLBuffer;
+ readonly texture: WebGLTexture;
+ readonly uSource: WebGLUniformLocation | null;
+ readonly uResolution: WebGLUniformLocation | null;
+ readonly uDisplacement: WebGLUniformLocation | null;
+ readonly uAmount: WebGLUniformLocation | null;
+ readonly uSize: WebGLUniformLocation | null;
+ readonly uOffset: WebGLUniformLocation | null;
+ readonly uComplexity: WebGLUniformLocation | null;
+ readonly uEvolution: WebGLUniformLocation | null;
+ readonly uCycleEvolution: WebGLUniformLocation | null;
+ readonly uCycle: WebGLUniformLocation | null;
+ readonly uSeed: WebGLUniformLocation | null;
+ readonly uPinning: 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 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(
+ `TurbulentDisplace 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(
+ `TurbulentDisplace program link failed: ${log ?? '(no log)'}`,
+ );
+ }
+
+ return program;
+};
+
+const setupTurbulentDisplace = (
+ target: HTMLCanvasElement,
+): TurbulentDisplaceState => {
+ const gl = target.getContext('webgl2', {
+ premultipliedAlpha: true,
+ alpha: true,
+ preserveDrawingBuffer: true,
+ });
+ if (!gl) {
+ throw createWebGL2ContextError('turbulent displace 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,
+ TURBULENT_DISPLACE_FRAGMENT_SHADER,
+ );
+ const program = linkProgram(gl, vs, fs);
+ gl.deleteShader(vs);
+ gl.deleteShader(fs);
+
+ const vao = gl.createVertexArray();
+ if (!vao) {
+ throw new Error('Failed to create WebGL vertex array');
+ }
+
+ gl.bindVertexArray(vao);
+
+ const data = new Float32Array([
+ -1, -1, 0, 0, 1, -1, 1, 0, -1, 1, 0, 1, 1, 1, 1, 1,
+ ]);
+
+ const vbo = gl.createBuffer();
+ if (!vbo) {
+ throw new Error('Failed to create WebGL buffer');
+ }
+
+ gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
+ gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
+
+ const aPos = gl.getAttribLocation(program, 'aPos');
+ const aUv = gl.getAttribLocation(program, 'aUv');
+ gl.enableVertexAttribArray(aPos);
+ gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 16, 0);
+ gl.enableVertexAttribArray(aUv);
+ gl.vertexAttribPointer(aUv, 2, gl.FLOAT, false, 16, 8);
+
+ gl.bindVertexArray(null);
+
+ const texture = gl.createTexture();
+ if (!texture) {
+ throw new Error('Failed to create WebGL texture');
+ }
+
+ gl.bindTexture(gl.TEXTURE_2D, texture);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
+ gl.bindTexture(gl.TEXTURE_2D, null);
+
+ return {
+ gl,
+ program,
+ vao,
+ vbo,
+ texture,
+ uSource: gl.getUniformLocation(program, 'uSource'),
+ uResolution: gl.getUniformLocation(program, 'uResolution'),
+ uDisplacement: gl.getUniformLocation(program, 'uDisplacement'),
+ uAmount: gl.getUniformLocation(program, 'uAmount'),
+ uSize: gl.getUniformLocation(program, 'uSize'),
+ uOffset: gl.getUniformLocation(program, 'uOffset'),
+ uComplexity: gl.getUniformLocation(program, 'uComplexity'),
+ uEvolution: gl.getUniformLocation(program, 'uEvolution'),
+ uCycleEvolution: gl.getUniformLocation(program, 'uCycleEvolution'),
+ uCycle: gl.getUniformLocation(program, 'uCycle'),
+ uSeed: gl.getUniformLocation(program, 'uSeed'),
+ uPinning: gl.getUniformLocation(program, 'uPinning'),
+ };
+};
+
+export const turbulentDisplace = createEffect<
+ TurbulentDisplaceParams,
+ TurbulentDisplaceState
+>({
+ type: 'remotion/turbulent-displace',
+ label: 'turbulentDisplace()',
+ documentationLink: 'https://www.remotion.dev/docs/effects/turbulent-displace',
+ backend: 'webgl2',
+ calculateKey: (params) => {
+ const r = resolve(params);
+ return `turbulent-displace-${JSON.stringify(r)}`;
+ },
+ setup: (target) => setupTurbulentDisplace(target),
+ apply: ({source, width, height, params, state, flipSourceY}) => {
+ const r = resolve(params);
+ const {gl, program, texture, vao} = state;
+
+ gl.viewport(0, 0, width, height);
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
+ gl.clearColor(0, 0, 0, 0);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+
+ gl.activeTexture(gl.TEXTURE0);
+ gl.bindTexture(gl.TEXTURE_2D, texture);
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipSourceY);
+ gl.texImage2D(
+ gl.TEXTURE_2D,
+ 0,
+ gl.RGBA,
+ gl.RGBA,
+ gl.UNSIGNED_BYTE,
+ source as TexImageSource,
+ );
+
+ gl.useProgram(program);
+ if (state.uSource) gl.uniform1i(state.uSource, 0);
+ if (state.uResolution) gl.uniform2f(state.uResolution, width, height);
+ if (state.uDisplacement)
+ gl.uniform1i(
+ state.uDisplacement,
+ DISPLACEMENT_MODES.indexOf(r.displacement),
+ );
+ if (state.uAmount) gl.uniform1f(state.uAmount, r.amount);
+ if (state.uSize) gl.uniform1f(state.uSize, r.size);
+ if (state.uOffset) gl.uniform2f(state.uOffset, r.offset[0], r.offset[1]);
+ if (state.uComplexity) gl.uniform1f(state.uComplexity, r.complexity);
+ if (state.uEvolution) gl.uniform1f(state.uEvolution, r.evolution / 360);
+ if (state.uCycleEvolution)
+ gl.uniform1i(state.uCycleEvolution, r.cycleEvolution ? 1 : 0);
+ if (state.uCycle) gl.uniform1f(state.uCycle, r.cycle);
+ if (state.uSeed) gl.uniform1ui(state.uSeed, r.seed);
+ if (state.uPinning)
+ gl.uniform1i(state.uPinning, PINNING_MODES.indexOf(r.pinning));
+
+ gl.bindVertexArray(vao);
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
+ gl.bindVertexArray(null);
+ gl.bindTexture(gl.TEXTURE_2D, null);
+ gl.useProgram(null);
+ },
+ cleanup: ({gl, program, vao, vbo, texture}) => {
+ gl.deleteTexture(texture);
+ gl.deleteBuffer(vbo);
+ gl.deleteProgram(program);
+ gl.deleteVertexArray(vao);
+ },
+ schema: turbulentDisplaceSchema,
+ validateParams: validateTurbulentDisplaceParams,
+});
diff --git a/packages/effects/src/turbulent-displace/shader.ts b/packages/effects/src/turbulent-displace/shader.ts
new file mode 100644
index 0000000000..b452233aa8
--- /dev/null
+++ b/packages/effects/src/turbulent-displace/shader.ts
@@ -0,0 +1,111 @@
+import {VALUE_NOISE_SHADER} from '../value-noise-shader.js';
+
+// Adapted from EffectCraft's distort2.rs; see ../../THIRD_PARTY_LICENSES.md.
+// https://github.com/storytold/effectcraft/blob/8f02f52a44a4b1ea807d8824b92301b96f896a06/crates/effects/src/distort2.rs#L38
+export const TURBULENT_DISPLACE_FRAGMENT_SHADER = /* glsl */ `#version 300 es
+precision highp float;
+precision highp int;
+
+in vec2 vUv;
+out vec4 fragColor;
+uniform sampler2D uSource;
+uniform vec2 uResolution;
+uniform float uAmount;
+uniform float uSize;
+uniform vec2 uOffset;
+uniform float uComplexity;
+uniform float uEvolution;
+uniform bool uCycleEvolution;
+uniform float uCycle;
+uniform uint uSeed;
+uniform int uDisplacement;
+uniform int uPinning;
+const int uNoiseType = 2;
+
+${VALUE_NOISE_SHADER}
+
+float noiseLayer(vec2 p, float z, uint seed) {
+ if (!uCycleEvolution) return valueNoise(vec3(p, uEvolution + z), seed);
+ float t = mod(uEvolution, uCycle);
+ // Zero blend derivatives at the seam keep the looping motion smooth.
+ float weight = smoothstep(0.0, 1.0, t / uCycle);
+ return mix(valueNoise(vec3(p, t + z), seed), valueNoise(vec3(p, t - uCycle + z), seed), weight);
+}
+
+float turbulence(vec2 p, uint channel) {
+ float sum = 0.0;
+ float norm = 0.0;
+ float amplitude = 1.0;
+ float frequency = 1.0;
+ float falloff = uDisplacement >= 3 && uDisplacement <= 5 ? 0.3 : 0.5;
+ for (int octave = 0; octave < 10; octave++) {
+ float weight = clamp(uComplexity - float(octave), 0.0, 1.0);
+ if (weight == 0.0) break;
+ uint seed = (uSeed ^ 0x7d15u) + channel + uint(octave) * 101u;
+ sum += noiseLayer(p * frequency, float(octave) * 5.17, seed) * amplitude * weight;
+ norm += amplitude * weight;
+ amplitude *= falloff;
+ frequency *= 2.0;
+ }
+ return sum / norm - 0.5;
+}
+
+vec4 readPixel(ivec2 p) {
+ if (any(lessThan(p, ivec2(0))) || any(greaterThanEqual(p, ivec2(uResolution)))) return vec4(0.0);
+ return texelFetch(uSource, ivec2(p.x, int(uResolution.y) - 1 - p.y), 0);
+}
+
+vec4 sampleSource(vec2 p) {
+ // Bilinear interpolation with transparent samples outside the source, so
+ // warped alpha edges do not smear the outermost pixel across the canvas.
+ ivec2 base = ivec2(floor(p - 0.5));
+ vec2 t = fract(p - 0.5);
+ return mix(mix(readPixel(base), readPixel(base + ivec2(1,0)), t.x),
+ mix(readPixel(base + ivec2(0,1)), readPixel(base + ivec2(1,1)), t.x), t.y);
+}
+
+void main() {
+ if (uAmount == 0.0) {
+ fragColor = texture(uSource, vUv);
+ return;
+ }
+ vec2 pixel = vec2(vUv.x, 1.0 - vUv.y) * uResolution;
+ vec2 p = (pixel - uOffset * uResolution) / uSize;
+ vec2 displacement;
+ if (uDisplacement == 1 || uDisplacement == 2 || uDisplacement == 4 || uDisplacement == 5) {
+ float epsilon = 0.05;
+ vec2 gradient = vec2(
+ turbulence(p + vec2(epsilon,0), 0u) - turbulence(p - vec2(epsilon,0), 0u),
+ turbulence(p + vec2(0,epsilon), 0u) - turbulence(p - vec2(0,epsilon), 0u)
+ ) / (2.0 * epsilon);
+ displacement = (uDisplacement == 1 || uDisplacement == 4) ? gradient : vec2(-gradient.y, gradient.x);
+ displacement *= uAmount * 0.25;
+ } else if (uDisplacement == 6) {
+ displacement = vec2(0.0, turbulence(p, 17u) * uAmount);
+ } else if (uDisplacement == 7) {
+ displacement = vec2(turbulence(p, 0u) * uAmount, 0.0);
+ } else if (uDisplacement == 8) {
+ displacement = vec2(turbulence(p, 0u) * uAmount);
+ } else {
+ displacement = vec2(turbulence(p, 0u), turbulence(p, 17u)) * uAmount;
+ }
+ bool locked = uPinning >= 8;
+ int pin = locked ? uPinning - 7 : uPinning;
+ float edge = max(1.0, min(uResolution.x, uResolution.y) * (locked ? 0.25 : 0.1));
+ vec2 nearEdge = clamp((pixel - 0.5) / edge, 0.0, 1.0);
+ vec2 farEdge = clamp((uResolution - 0.5 - pixel) / edge, 0.0, 1.0);
+ float horizontal = min(nearEdge.x, farEdge.x);
+ float vertical = min(nearEdge.y, farEdge.y);
+ float weight = 1.0;
+ if (pin == 1) weight = min(horizontal, vertical);
+ if (pin == 2) weight = vertical;
+ if (pin == 3) weight = horizontal;
+ if (pin == 4) weight = nearEdge.x;
+ if (pin == 5) weight = nearEdge.y;
+ if (pin == 6) weight = farEdge.x;
+ if (pin == 7) weight = farEdge.y;
+ vec2 sourcePixel = pixel + displacement * weight;
+ if (locked) sourcePixel = clamp(sourcePixel, vec2(0.5), uResolution - 0.5);
+ fragColor = sampleSource(sourcePixel);
+}
+`;
diff --git a/packages/effects/src/value-noise-shader.ts b/packages/effects/src/value-noise-shader.ts
new file mode 100644
index 0000000000..339cb6b59b
--- /dev/null
+++ b/packages/effects/src/value-noise-shader.ts
@@ -0,0 +1,64 @@
+// Adapted from EffectCraft's noise3.rs; see ../THIRD_PARTY_LICENSES.md.
+// Callers declare uNoiseType: 0 = block, 1 = linear, 2 = soft linear, 3 = spline.
+export const VALUE_NOISE_SHADER = /* glsl */ `
+float lattice(ivec3 point, uint seed) {
+ // Wrap lattice indices as well as coordinates so interpolation stays continuous
+ // across the period boundary, including negative coordinates.
+ uvec3 p = uvec3(point) & uvec3(65535u);
+ uint h = p.x * 0x27d4eb2du ^ p.y * 0x165667b1u ^ p.z * 0x9e3779b9u ^ seed * 0x85ebca6bu;
+ h ^= h >> 15;
+ h *= 0x2c1b3c6du;
+ h ^= h >> 12;
+ h *= 0x297a2d39u;
+ h ^= h >> 15;
+ return float(h & 65535u) / 65535.0;
+}
+
+float catmull(vec4 p, float t) {
+ return 0.5 * (2.0 * p.y + (p.z - p.x) * t
+ + (2.0 * p.x - 5.0 * p.y + 4.0 * p.z - p.w) * t * t
+ + (3.0 * p.y - p.x - 3.0 * p.z + p.w) * t * t * t);
+}
+
+vec3 bspline(float t) {
+ return vec3(0.5 * (1.0-t) * (1.0-t), 0.5 + t * (1.0-t), 0.5 * t * t);
+}
+
+float sliceNoise(ivec3 p, vec2 t, uint seed) {
+ if (uNoiseType == 0) return lattice(p, seed);
+ if (uNoiseType == 1) {
+ return mix(mix(lattice(p, seed), lattice(p + ivec3(1,0,0), seed), t.x),
+ mix(lattice(p + ivec3(0,1,0), seed), lattice(p + ivec3(1,1,0), seed), t.x), t.y);
+ }
+ if (uNoiseType == 2) {
+ vec3 wx = bspline(t.x);
+ vec3 wy = bspline(t.y);
+ float result = 0.0;
+ for (int y = 0; y < 3; y++) {
+ for (int x = 0; x < 3; x++) {
+ result += wx[x] * wy[y] * lattice(p + ivec3(x-1, y-1, 0), seed);
+ }
+ }
+ return result;
+ }
+ vec4 rows;
+ for (int y = 0; y < 4; y++) {
+ vec4 row;
+ for (int x = 0; x < 4; x++) {
+ row[x] = lattice(p + ivec3(x-1, y-1, 0), seed);
+ }
+ rows[y] = catmull(row, t.x);
+ }
+ return catmull(rows, t.y);
+}
+
+float valueNoise(vec3 point, uint seed) {
+ // A large period keeps conversion to integer coordinates defined at extreme scales.
+ vec3 p = mod(point + vec3(uNoiseType == 2 ? 0.5 : 0.0, uNoiseType == 2 ? 0.5 : 0.0, 0.0), 65536.0);
+ ivec3 cell = ivec3(floor(p));
+ vec3 t = fract(p);
+ float fz = t.z * t.z * t.z * (t.z * (t.z * 6.0 - 15.0) + 10.0);
+ float n = mix(sliceNoise(cell, t.xy, seed), sliceNoise(cell + ivec3(0,0,1), t.xy, seed), fz);
+ return uNoiseType == 2 ? 0.5 + (n - 0.5) * (181.0 / 231.0) / 0.55 : n;
+}
+`;
diff --git a/packages/studio-shared/src/effect-catalog.ts b/packages/studio-shared/src/effect-catalog.ts
index 7e9882cd6d..6ec0ea9e23 100644
--- a/packages/studio-shared/src/effect-catalog.ts
+++ b/packages/studio-shared/src/effect-catalog.ts
@@ -640,6 +640,17 @@ export const EFFECT_CATALOG: readonly EffectCatalogItem[] = [
config: {},
},
},
+ {
+ id: 'effects-turbulent-displace',
+ category: 'Distort',
+ label: 'turbulentDisplace()',
+ description: 'Evolving turbulent, bulge and twist distortion',
+ effect: {
+ name: 'turbulentDisplace',
+ importPath: '@remotion/effects/turbulent-displace',
+ config: {},
+ },
+ },
{
id: 'effects-noise-displacement',
category: 'Stylize',