Skip to content

🎥 Make videos programmatically with React

Add fractalNoise effect and documentation

Jonny Burgerad91ac0ef488
diff --git a/packages/docs/components/demos/index.tsx b/packages/docs/components/demos/index.tsx
index 406fcfc459..a0bdf63616 100644
--- a/packages/docs/components/demos/index.tsx
+++ b/packages/docs/components/demos/index.tsx
@@ -23,6 +23,7 @@ import {
cylinderTextDemo,
sphereGlobeDemo,
pageTurnDemo,
+ fractalNoiseDemo,
customPresentationDemo,
customTimingDemo,
dissolvePresentationDemo,
@@ -159,6 +160,7 @@ const demos: DemoType[] = [
cylinderTextDemo,
sphereGlobeDemo,
pageTurnDemo,
+ fractalNoiseDemo,
animationMathDemo,
roundedTextBoxDemo,
springDemo,
diff --git a/packages/docs/components/demos/types.ts b/packages/docs/components/demos/types.ts
index 7e149c2d9a..f8d40f8ffe 100644
--- a/packages/docs/components/demos/types.ts
+++ b/packages/docs/components/demos/types.ts
@@ -1,4 +1,5 @@
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 {
@@ -1785,3 +1786,16 @@ export const pageTurnDemo: DemoType = {
logLevel: 'info',
options: [],
};
+
+export const fractalNoiseDemo: DemoType = {
+ comp: FractalNoiseDemo,
+ compWidth: 1280,
+ compHeight: 720,
+ fps: 30,
+ durationInFrames: 180,
+ id: 'fractal-noise',
+ 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 b13b607c2c..d6e4cf8f4b 100644
--- a/packages/docs/components/effects-demos/registry.ts
+++ b/packages/docs/components/effects-demos/registry.ts
@@ -18,6 +18,7 @@ import {evolve} from '@remotion/effects/evolve';
import {exposure} from '@remotion/effects/exposure';
import {fisheye} from '@remotion/effects/fisheye';
import {flannel} from '@remotion/effects/flannel';
+import {fractalNoise} from '@remotion/effects/fractal-noise';
import {glow} from '@remotion/effects/glow';
import {grayscale} from '@remotion/effects/grayscale';
import {gridlines} from '@remotion/effects/gridlines';
@@ -94,6 +95,7 @@ import {EffectsEvolvePreview} from '../effects/effects-evolve-preview';
import {EffectsExposurePreview} from '../effects/effects-exposure-preview';
import {EffectsFisheyePreview} from '../effects/effects-fisheye-preview';
import {EffectsFlannelPreview} from '../effects/effects-flannel-preview';
+import {EffectsFractalNoisePreview} from '../effects/effects-fractal-noise-preview';
import {EffectsGlowPreview} from '../effects/effects-glow-preview';
import {EffectsGrayscalePreview} from '../effects/effects-grayscale-preview';
import {EffectsGridlinesPreview} from '../effects/effects-gridlines-preview';
@@ -202,6 +204,14 @@ const shrinkwrapDemoSchema = {
const cylinderDemoSchema = cylinder().definition.schema;
export const effectsDemos: EffectsDemoType[] = [
+ {
+ ...defaults,
+ id: 'effects-fractal-noise',
+ effectName: 'fractalNoise',
+ effectImportPath: '@remotion/effects/fractal-noise',
+ comp: EffectsFractalNoisePreview,
+ schema: fractalNoise().definition.schema,
+ },
{
...defaults,
id: 'effects-page-turn',
diff --git a/packages/docs/components/effects/effects-fractal-noise-preview.tsx b/packages/docs/components/effects/effects-fractal-noise-preview.tsx
new file mode 100644
index 0000000000..6a501d1c89
--- /dev/null
+++ b/packages/docs/components/effects/effects-fractal-noise-preview.tsx
@@ -0,0 +1,77 @@
+import {
+ fractalNoise,
+ type FractalNoiseParams,
+} from '@remotion/effects/fractal-noise';
+import React from 'react';
+import {interpolate, Solid, useCurrentFrame} from 'remotion';
+
+export const EffectsFractalNoisePreview: React.FC<
+ Required<FractalNoiseParams>
+> = ({
+ fractalType,
+ noiseType,
+ scale,
+ complexity,
+ evolution,
+ contrast,
+ brightness,
+ offsetX,
+ offsetY,
+ subInfluence,
+ subScaling,
+ cycleEvolution,
+ cycle,
+ seed,
+ invert,
+ amount,
+}) => {
+ return (
+ <Solid
+ name="Fractal noise"
+ color="black"
+ width={1280}
+ height={720}
+ effects={[
+ fractalNoise({
+ fractalType,
+ noiseType,
+ scale,
+ complexity,
+ evolution,
+ contrast,
+ brightness,
+ offsetX,
+ offsetY,
+ subInfluence,
+ subScaling,
+ cycleEvolution,
+ cycle,
+ seed,
+ invert,
+ amount,
+ }),
+ ]}
+ />
+ );
+};
+
+export const FractalNoiseDemo: React.FC = () => {
+ const frame = useCurrentFrame();
+ return (
+ <Solid
+ name="Evolving clouds"
+ color="black"
+ width={1280}
+ height={720}
+ effects={[
+ fractalNoise({
+ scale: 300,
+ complexity: 6,
+ contrast: 2,
+ cycleEvolution: true,
+ evolution: interpolate(frame, [0, 180], [0, 360]),
+ }),
+ ]}
+ />
+ );
+};
diff --git a/packages/docs/docs/effects/fractal-noise.mdx b/packages/docs/docs/effects/fractal-noise.mdx
new file mode 100644
index 0000000000..eeab8d179b
--- /dev/null
+++ b/packages/docs/docs/effects/fractal-noise.mdx
@@ -0,0 +1,160 @@
+---
+image: /generated/articles-docs-effects-fractal-noise.png
+slug: /effects/fractal-noise
+title: fractalNoise()
+sidebar_label: fractalNoise()
+crumb: '@remotion/effects'
+---
+
+# fractalNoise()<AvailableFrom v="4.0.537" />
+
+_Part of the [`@remotion/effects`](/docs/effects/api) package._
+
+Generates layered grayscale noise for clouds, smoke and organic textures. Animate `evolution` to morph the pattern smoothly, or animate the offsets to move it.
+
+The effect replaces the source colors and preserves its alpha mask. Apply it to a [`<Solid>`](/docs/solid) for a background, or to text and shapes to fill them with noise.
+
+## Preview
+
+<Demo type="fractal-noise" />
+
+## Controls
+
+<EffectsDemo type="effects-fractal-noise" />
+
+## Example
+
+```tsx twoslash title="MyComp.tsx"
+import {fractalNoise} from '@remotion/effects/fractal-noise';
+import {interpolate, Solid, useCurrentFrame} from 'remotion';
+
+export const MyComp: React.FC = () => {
+ const frame = useCurrentFrame();
+
+ return (
+ <Solid
+ name="Evolving clouds"
+ color="black"
+ width={1280}
+ height={720}
+ effects={[
+ fractalNoise({
+ scale: 300,
+ complexity: 6,
+ contrast: 2,
+ cycleEvolution: true,
+ evolution: interpolate(frame, [0, 180], [0, 360]),
+ }),
+ ]}
+ />
+ );
+};
+```
+
+This example loops every 180 frames. Combine the effect with [`tint()`](/docs/effects/tint) or [`duotone()`](/docs/effects/duotone) to color the texture.
+
+## API
+
+Pass an object with the following properties. You can also call `fractalNoise()` without arguments.
+
+### `fractalType?`
+
+Texture style. Defaults to `"basic"`.
+
+- `"basic"`: Layered clouds.
+- `"turbulent-smooth"`: Broad, smooth ridges.
+- `"turbulent-basic"`: Folded noise with sharper ridges.
+- `"turbulent-sharp"`: Narrow, high-contrast ridges.
+- `"dynamic"`: Noise warped by another noise field.
+- `"dynamic-twist"`: Twisted noise.
+- `"dynamic-progressive"`: Increasingly warped fine detail.
+- `"max"`: The strongest value from the layers.
+- `"strings"`: Thin strands around each layer's mid-gray values.
+
+### `noiseType?`
+
+Interpolation between noise cells. Defaults to `"soft-linear"`.
+
+- `"block"`: Hard-edged cells.
+- `"linear"`: Linear interpolation.
+- `"soft-linear"`: Smooth, filtered interpolation.
+- `"spline"`: Cubic interpolation.
+
+All modes evolve smoothly over time, including `"block"`.
+
+### `scale?`
+
+Size of the largest noise cells in pixels. Must be at least `1`. Defaults to `100`.
+
+Larger values produce broader shapes.
+
+### `complexity?`
+
+Number of noise layers, from `1` to `20`. Defaults to `6`. Fractional values fade in the next layer, allowing smooth animation of detail.
+
+Higher values add finer detail and take longer to render.
+
+### `evolution?`
+
+Evolution in degrees. Defaults to `0`. Animate this value to morph the texture without moving it.
+
+By default, `360` continues to a new pattern. Enable `cycleEvolution` to repeat the pattern after `cycle * 360` degrees.
+
+### `contrast?`
+
+Contrast multiplier around mid-gray. Must be non-negative. Defaults to `1`. Use `0` for flat gray before brightness is applied. Output values are clipped to black and white.
+
+### `brightness?`
+
+Brightness added after contrast. Defaults to `0`. A value of `1` adds the full black-to-white range; negative values darken the texture.
+
+### `offsetX?`
+
+Horizontal translation of the texture in pixels. Positive values move it right. Defaults to `0`.
+
+### `offsetY?`
+
+Vertical translation of the texture in pixels. Positive values move it down. Defaults to `0`.
+
+### `subInfluence?`
+
+Strength of each layer relative to the preceding layer, from `0` to `1`. Defaults to `0.7`. Use `0` to keep only the largest layer.
+
+### `subScaling?`
+
+Cell size of each layer relative to the preceding layer, from `0.1` to `1`. Defaults to `0.56`. Lower values add finer detail more quickly.
+
+### `cycleEvolution?`
+
+Whether to repeat the texture after `cycle` revolutions. Defaults to `false`.
+
+### `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.
+
+### `invert?`
+
+Whether to invert the generated grayscale values. Defaults to `false`.
+
+### `amount?`
+
+Mix with the source, from `0` (unchanged) to `1` (noise only). Defaults to `1`. Source transparency is preserved at every value.
+
+### `disabled?`
+
+When `true`, the effect is skipped. Defaults to `false`.
+
+## Requirements
+
+`fractalNoise()` uses WebGL2. See [Using WebGL and WebGPU during renders](/docs/webgl).
+
+## See also
+
+- [`noise()`](/docs/effects/noise)
+- [`liquidContours()`](/docs/effects/liquid-contours)
+- [`tint()`](/docs/effects/tint)
+- [Source code for this effect](https://github.com/remotion-dev/remotion/tree/main/packages/effects/src/fractal-noise)
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index de3847014f..444afec5d1 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -302,6 +302,7 @@ const sidebars: SidebarsConfig = {
'effects/exposure',
'effects/fisheye',
'effects/flannel',
+ 'effects/fractal-noise',
'effects/glow',
'effects/grayscale',
'effects/gridlines',
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 2a3968de42..f4dee7d9f9 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -3564,6 +3564,15 @@ export const articles = [
noAi: false,
slug: 'effects/flannel',
},
+ {
+ id: 'effects/fractal-noise',
+ title: 'fractalNoise()',
+ relativePath: 'docs/effects/fractal-noise.mdx',
+ compId: 'articles-docs-effects-fractal-noise',
+ crumb: '@remotion/effects',
+ noAi: false,
+ slug: 'effects/fractal-noise',
+ },
{
id: 'effects/glow',
title: 'glow()',
diff --git a/packages/docs/src/remotion/Root.tsx b/packages/docs/src/remotion/Root.tsx
index 198713e36d..8210d83867 100644
--- a/packages/docs/src/remotion/Root.tsx
+++ b/packages/docs/src/remotion/Root.tsx
@@ -27,6 +27,10 @@ import {EffectsEvolvePreview} from '../../components/effects/effects-evolve-prev
import {EffectsExposurePreview} from '../../components/effects/effects-exposure-preview';
import {EffectsFisheyePreview} from '../../components/effects/effects-fisheye-preview';
import {EffectsFlannelPreview} from '../../components/effects/effects-flannel-preview';
+import {
+ EffectsFractalNoisePreview,
+ FractalNoiseDemo,
+} from '../../components/effects/effects-fractal-noise-preview';
import {EffectsGlowPreview} from '../../components/effects/effects-glow-preview';
import {EffectsGrayscalePreview} from '../../components/effects/effects-grayscale-preview';
import {EffectsGridlinesPreview} from '../../components/effects/effects-gridlines-preview';
@@ -434,6 +438,38 @@ export const RemotionRoot: React.FC = () => {
feather: 0.18,
}}
/>
+ <Still
+ id="effects-fractal-noise-preview"
+ component={EffectsFractalNoisePreview}
+ width={1280}
+ height={720}
+ defaultProps={{
+ fractalType: 'basic',
+ noiseType: 'soft-linear',
+ scale: 300,
+ complexity: 6,
+ evolution: 0,
+ contrast: 2,
+ brightness: 0,
+ offsetX: 0,
+ offsetY: 0,
+ subInfluence: 0.7,
+ subScaling: 0.56,
+ cycleEvolution: false,
+ cycle: 1,
+ seed: 0,
+ invert: false,
+ amount: 1,
+ }}
+ />
+ <Composition
+ id="fractal-noise-demo"
+ component={FractalNoiseDemo}
+ width={1280}
+ height={720}
+ fps={30}
+ durationInFrames={180}
+ />
<Still
id="effects-exposure-preview"
component={EffectsExposurePreview}
diff --git a/packages/docs/static/generated/articles-docs-effects-fractal-noise.png b/packages/docs/static/generated/articles-docs-effects-fractal-noise.png
new file mode 100644
index 0000000000..526f84e868
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-effects-fractal-noise.png differ
diff --git a/packages/docs/static/img/effects-fractal-noise-preview.png b/packages/docs/static/img/effects-fractal-noise-preview.png
new file mode 100644
index 0000000000..44f584a619
Binary files /dev/null and b/packages/docs/static/img/effects-fractal-noise-preview.png differ
diff --git a/packages/effects/THIRD_PARTY_LICENSES.md b/packages/effects/THIRD_PARTY_LICENSES.md
new file mode 100644
index 0000000000..0aa26b18bd
--- /dev/null
+++ b/packages/effects/THIRD_PARTY_LICENSES.md
@@ -0,0 +1,29 @@
+# Third-party licenses
+
+## EffectCraft
+
+The Fractal Noise shader is adapted from the value-noise engine in
+[EffectCraft](https://github.com/storytold/effectcraft), revision
+`8f02f52a44a4b1ea807d8824b92301b96f896a06`. It is used under the MIT license.
+
+MIT License
+
+Copyright (c) 2026 ArtCraft Team and the EffectCraft contributors
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/packages/effects/bundle.ts b/packages/effects/bundle.ts
index 43e38a4711..18bb772d64 100644
--- a/packages/effects/bundle.ts
+++ b/packages/effects/bundle.ts
@@ -24,6 +24,7 @@ const effectEntrypoints = [
'src/exposure.ts',
'src/fisheye.ts',
'src/flannel.ts',
+ 'src/fractal-noise.ts',
'src/corner-pin.ts',
'src/cylinder.ts',
'src/glow.ts',
diff --git a/packages/effects/package.json b/packages/effects/package.json
index 09c75a593c..1d732632ac 100644
--- a/packages/effects/package.json
+++ b/packages/effects/package.json
@@ -49,6 +49,11 @@
"module": "./dist/esm/burlap.mjs",
"import": "./dist/esm/burlap.mjs"
},
+ "./fractal-noise": {
+ "types": "./dist/fractal-noise.d.ts",
+ "module": "./dist/esm/fractal-noise.mjs",
+ "import": "./dist/esm/fractal-noise.mjs"
+ },
"./flannel": {
"types": "./dist/flannel.d.ts",
"module": "./dist/esm/flannel.mjs",
@@ -427,6 +432,9 @@
"burlap": [
"dist/burlap.d.ts"
],
+ "fractal-noise": [
+ "dist/fractal-noise.d.ts"
+ ],
"flannel": [
"dist/flannel.d.ts"
],
diff --git a/packages/effects/src/fractal-noise.ts b/packages/effects/src/fractal-noise.ts
new file mode 100644
index 0000000000..1463ad1fde
--- /dev/null
+++ b/packages/effects/src/fractal-noise.ts
@@ -0,0 +1 @@
+export {fractalNoise, type FractalNoiseParams} from './fractal-noise/index.js';
diff --git a/packages/effects/src/fractal-noise/index.ts b/packages/effects/src/fractal-noise/index.ts
new file mode 100644
index 0000000000..df383a5180
--- /dev/null
+++ b/packages/effects/src/fractal-noise/index.ts
@@ -0,0 +1,531 @@
+import type {InteractivitySchema} from 'remotion';
+import {Internals} from 'remotion';
+import {
+ assertOptionalFiniteNumber,
+ validateUnitInterval,
+ validateNonNegative,
+} from '../color-utils.js';
+import {
+ assertEffectParamsObject,
+ assertOptionalBoolean,
+} from '../validate-effect-param.js';
+import {FRACTAL_NOISE_FRAGMENT_SHADER} from './shader.js';
+
+const {createEffect, createWebGL2ContextError} = Internals;
+
+const DEFAULT_FRACTAL_TYPE = 'basic' as const;
+const DEFAULT_NOISE_TYPE = 'soft-linear' as const;
+const DEFAULT_SCALE = 100 as const;
+const DEFAULT_COMPLEXITY = 6 as const;
+const DEFAULT_EVOLUTION = 0 as const;
+const DEFAULT_CONTRAST = 1 as const;
+const DEFAULT_BRIGHTNESS = 0 as const;
+const DEFAULT_OFFSET_X = 0 as const;
+const DEFAULT_OFFSET_Y = 0 as const;
+const DEFAULT_SUB_INFLUENCE = 0.7 as const;
+const DEFAULT_SUB_SCALING = 0.56 as const;
+const DEFAULT_CYCLE_EVOLUTION = false as const;
+const DEFAULT_CYCLE = 1 as const;
+const DEFAULT_SEED = 0 as const;
+const DEFAULT_INVERT = false as const;
+const DEFAULT_AMOUNT = 1 as const;
+
+const FRACTAL_TYPES = [
+ 'basic',
+ 'turbulent-smooth',
+ 'turbulent-basic',
+ 'turbulent-sharp',
+ 'dynamic',
+ 'dynamic-twist',
+ 'dynamic-progressive',
+ 'max',
+ 'strings',
+] as const;
+const NOISE_TYPES = ['block', 'linear', 'soft-linear', 'spline'] as const;
+
+const fractalNoiseSchema = {
+ fractalType: {
+ type: 'enum',
+ variants: {
+ basic: {},
+ 'turbulent-smooth': {},
+ 'turbulent-basic': {},
+ 'turbulent-sharp': {},
+ dynamic: {},
+ 'dynamic-twist': {},
+ 'dynamic-progressive': {},
+ max: {},
+ strings: {},
+ },
+ default: DEFAULT_FRACTAL_TYPE,
+ description: 'Fractal type',
+ },
+ noiseType: {
+ type: 'enum',
+ variants: {
+ block: {},
+ linear: {},
+ 'soft-linear': {},
+ spline: {},
+ },
+ default: DEFAULT_NOISE_TYPE,
+ description: 'Noise type',
+ },
+ scale: {
+ type: 'number',
+ min: 1,
+ max: 1000,
+ step: 1,
+ default: DEFAULT_SCALE,
+ description: 'Scale',
+ hiddenFromList: false,
+ },
+ complexity: {
+ type: 'number',
+ min: 1,
+ max: 20,
+ step: 0.1,
+ default: DEFAULT_COMPLEXITY,
+ description: 'Complexity',
+ hiddenFromList: false,
+ },
+ evolution: {
+ type: 'rotation-degrees',
+ step: 1,
+ default: DEFAULT_EVOLUTION,
+ description: 'Evolution',
+ },
+ contrast: {
+ type: 'number',
+ min: 0,
+ max: 10,
+ step: 0.01,
+ default: DEFAULT_CONTRAST,
+ description: 'Contrast',
+ hiddenFromList: false,
+ },
+ brightness: {
+ type: 'number',
+ min: -1,
+ max: 1,
+ step: 0.01,
+ default: DEFAULT_BRIGHTNESS,
+ description: 'Brightness',
+ hiddenFromList: false,
+ },
+ offsetX: {
+ type: 'number',
+ step: 1,
+ default: DEFAULT_OFFSET_X,
+ description: 'Offset X',
+ hiddenFromList: false,
+ },
+ offsetY: {
+ type: 'number',
+ step: 1,
+ default: DEFAULT_OFFSET_Y,
+ description: 'Offset Y',
+ hiddenFromList: false,
+ },
+ subInfluence: {
+ type: 'number',
+ min: 0,
+ max: 1,
+ step: 0.01,
+ default: DEFAULT_SUB_INFLUENCE,
+ description: 'Sub influence',
+ hiddenFromList: false,
+ },
+ subScaling: {
+ type: 'number',
+ min: 0.1,
+ max: 1,
+ step: 0.01,
+ default: DEFAULT_SUB_SCALING,
+ description: 'Sub scaling',
+ hiddenFromList: false,
+ },
+ 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,
+ },
+ invert: {
+ type: 'boolean',
+ default: DEFAULT_INVERT,
+ description: 'Invert',
+ },
+ amount: {
+ type: 'number',
+ min: 0,
+ max: 1,
+ step: 0.01,
+ default: DEFAULT_AMOUNT,
+ description: 'Amount',
+ hiddenFromList: false,
+ },
+} as const satisfies InteractivitySchema;
+
+export type FractalNoiseParams = {
+ /** Texture shape. Defaults to `basic`. */
+ readonly fractalType?: (typeof FRACTAL_TYPES)[number];
+ /** Lattice interpolation. Defaults to `soft-linear`. */
+ readonly noiseType?: (typeof NOISE_TYPES)[number];
+ /** Size of the largest noise cells in pixels. Defaults to `100`. */
+ readonly scale?: number;
+ /** Number of noise layers, including fractional layers, from `1` to `20`. Defaults to `6`. */
+ readonly complexity?: number;
+ /** Evolution in degrees. Animate to morph the texture. Defaults to `0`. */
+ readonly evolution?: number;
+ /** Contrast multiplier around mid-gray. Defaults to `1`. */
+ readonly contrast?: number;
+ /** Brightness added after contrast. Defaults to `0`. */
+ readonly brightness?: number;
+ /** Horizontal texture translation in pixels. Defaults to `0`. */
+ readonly offsetX?: number;
+ /** Vertical texture translation in pixels. Defaults to `0`. */
+ readonly offsetY?: number;
+ /** Relative strength of each successive layer, from `0` to `1`. Defaults to `0.7`. */
+ readonly subInfluence?: number;
+ /** Relative cell size of each successive layer, from `0.1` to `1`. Defaults to `0.56`. */
+ readonly subScaling?: number;
+ /** Loop 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 a repeatable texture. Defaults to `0`. */
+ readonly seed?: number;
+ /** Invert the generated grayscale values. Defaults to `false`. */
+ readonly invert?: boolean;
+ /** Mix with the source from `0` (unchanged) to `1` (noise only). Defaults to `1`. */
+ readonly amount?: number;
+};
+
+type FractalNoiseResolved = Required<FractalNoiseParams>;
+
+const resolve = (params: FractalNoiseParams): FractalNoiseResolved => ({
+ fractalType: params.fractalType ?? DEFAULT_FRACTAL_TYPE,
+ noiseType: params.noiseType ?? DEFAULT_NOISE_TYPE,
+ scale: params.scale ?? DEFAULT_SCALE,
+ complexity: params.complexity ?? DEFAULT_COMPLEXITY,
+ evolution: params.evolution ?? DEFAULT_EVOLUTION,
+ contrast: params.contrast ?? DEFAULT_CONTRAST,
+ brightness: params.brightness ?? DEFAULT_BRIGHTNESS,
+ offsetX: params.offsetX ?? DEFAULT_OFFSET_X,
+ offsetY: params.offsetY ?? DEFAULT_OFFSET_Y,
+ subInfluence: params.subInfluence ?? DEFAULT_SUB_INFLUENCE,
+ subScaling: params.subScaling ?? DEFAULT_SUB_SCALING,
+ cycleEvolution: params.cycleEvolution ?? DEFAULT_CYCLE_EVOLUTION,
+ cycle: params.cycle ?? DEFAULT_CYCLE,
+ seed: params.seed ?? DEFAULT_SEED,
+ invert: params.invert ?? DEFAULT_INVERT,
+ amount: params.amount ?? DEFAULT_AMOUNT,
+});
+
+const validateFractalNoiseParams = (params: FractalNoiseParams): void => {
+ assertEffectParamsObject(params, 'Fractal noise');
+ assertOptionalFiniteNumber(params.scale, 'scale');
+ assertOptionalFiniteNumber(params.complexity, 'complexity');
+ assertOptionalFiniteNumber(params.evolution, 'evolution');
+ assertOptionalFiniteNumber(params.contrast, 'contrast');
+ assertOptionalFiniteNumber(params.brightness, 'brightness');
+ assertOptionalFiniteNumber(params.offsetX, 'offsetX');
+ assertOptionalFiniteNumber(params.offsetY, 'offsetY');
+ assertOptionalFiniteNumber(params.subInfluence, 'subInfluence');
+ assertOptionalFiniteNumber(params.subScaling, 'subScaling');
+ assertOptionalBoolean(params.cycleEvolution, 'cycleEvolution');
+ assertOptionalFiniteNumber(params.cycle, 'cycle');
+ assertOptionalFiniteNumber(params.seed, 'seed');
+ assertOptionalBoolean(params.invert, 'invert');
+ assertOptionalFiniteNumber(params.amount, 'amount');
+ const r = resolve(params);
+ if (
+ params.fractalType !== undefined &&
+ !FRACTAL_TYPES.includes(params.fractalType)
+ ) {
+ throw new TypeError(
+ 'Invalid fractalType: ' + JSON.stringify(params.fractalType),
+ );
+ }
+
+ if (
+ params.noiseType !== undefined &&
+ !NOISE_TYPES.includes(params.noiseType)
+ ) {
+ throw new TypeError(
+ 'Invalid noiseType: ' + JSON.stringify(params.noiseType),
+ );
+ }
+
+ if (r.scale < 1) throw new TypeError('"scale" must be at least 1');
+ if (r.complexity < 1 || r.complexity > 20)
+ throw new TypeError('"complexity" must be between 1 and 20');
+ if (r.subScaling < 0.1 || r.subScaling > 1)
+ throw new TypeError('"subScaling" must be between 0.1 and 1');
+ 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');
+ validateNonNegative(r.contrast, 'contrast');
+ validateUnitInterval(r.subInfluence, 'subInfluence');
+ validateUnitInterval(r.amount, 'amount');
+};
+
+type FractalNoiseState = {
+ readonly gl: WebGL2RenderingContext;
+ readonly program: WebGLProgram;
+ readonly vao: WebGLVertexArrayObject;
+ readonly vbo: WebGLBuffer;
+ readonly texture: WebGLTexture;
+ readonly uSource: WebGLUniformLocation | null;
+ readonly uResolution: WebGLUniformLocation | null;
+ readonly uOffset: WebGLUniformLocation | null;
+ readonly uFractalType: WebGLUniformLocation | null;
+ readonly uNoiseType: WebGLUniformLocation | null;
+ readonly uScale: WebGLUniformLocation | null;
+ readonly uComplexity: WebGLUniformLocation | null;
+ readonly uEvolution: WebGLUniformLocation | null;
+ readonly uContrast: WebGLUniformLocation | null;
+ readonly uBrightness: WebGLUniformLocation | null;
+ readonly uSubInfluence: WebGLUniformLocation | null;
+ readonly uSubScaling: WebGLUniformLocation | null;
+ readonly uCycleEvolution: WebGLUniformLocation | null;
+ readonly uCycle: WebGLUniformLocation | null;
+ readonly uSeed: WebGLUniformLocation | null;
+ readonly uInvert: WebGLUniformLocation | null;
+ readonly uAmount: 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(`FractalNoise 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(`FractalNoise program link failed: ${log ?? '(no log)'}`);
+ }
+
+ return program;
+};
+
+const setupFractalNoise = (target: HTMLCanvasElement): FractalNoiseState => {
+ const gl = target.getContext('webgl2', {
+ premultipliedAlpha: true,
+ alpha: true,
+ preserveDrawingBuffer: true,
+ });
+ if (!gl) {
+ throw createWebGL2ContextError('fractal noise 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,
+ FRACTAL_NOISE_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'),
+ uOffset: gl.getUniformLocation(program, 'uOffset'),
+ uFractalType: gl.getUniformLocation(program, 'uFractalType'),
+ uNoiseType: gl.getUniformLocation(program, 'uNoiseType'),
+ uScale: gl.getUniformLocation(program, 'uScale'),
+ uComplexity: gl.getUniformLocation(program, 'uComplexity'),
+ uEvolution: gl.getUniformLocation(program, 'uEvolution'),
+ uContrast: gl.getUniformLocation(program, 'uContrast'),
+ uBrightness: gl.getUniformLocation(program, 'uBrightness'),
+ uSubInfluence: gl.getUniformLocation(program, 'uSubInfluence'),
+ uSubScaling: gl.getUniformLocation(program, 'uSubScaling'),
+ uCycleEvolution: gl.getUniformLocation(program, 'uCycleEvolution'),
+ uCycle: gl.getUniformLocation(program, 'uCycle'),
+ uSeed: gl.getUniformLocation(program, 'uSeed'),
+ uInvert: gl.getUniformLocation(program, 'uInvert'),
+ uAmount: gl.getUniformLocation(program, 'uAmount'),
+ };
+};
+
+export const fractalNoise = createEffect<FractalNoiseParams, FractalNoiseState>(
+ {
+ type: 'remotion/fractal-noise',
+ label: 'fractalNoise()',
+ documentationLink: 'https://www.remotion.dev/docs/effects/fractal-noise',
+ backend: 'webgl2',
+ calculateKey: (params) => {
+ const r = resolve(params);
+ return `fractal-noise-${JSON.stringify(r)}`;
+ },
+ setup: (target) => setupFractalNoise(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.uOffset) gl.uniform2f(state.uOffset, r.offsetX, r.offsetY);
+ if (state.uFractalType)
+ gl.uniform1i(state.uFractalType, FRACTAL_TYPES.indexOf(r.fractalType));
+ if (state.uNoiseType)
+ gl.uniform1i(state.uNoiseType, NOISE_TYPES.indexOf(r.noiseType));
+ if (state.uScale) gl.uniform1f(state.uScale, r.scale);
+ if (state.uComplexity) gl.uniform1f(state.uComplexity, r.complexity);
+ if (state.uEvolution) gl.uniform1f(state.uEvolution, r.evolution / 360);
+ if (state.uContrast) gl.uniform1f(state.uContrast, r.contrast);
+ if (state.uBrightness) gl.uniform1f(state.uBrightness, r.brightness);
+ if (state.uSubInfluence)
+ gl.uniform1f(state.uSubInfluence, r.subInfluence);
+ if (state.uSubScaling) gl.uniform1f(state.uSubScaling, r.subScaling);
+ 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.uInvert) gl.uniform1i(state.uInvert, r.invert ? 1 : 0);
+ if (state.uAmount) gl.uniform1f(state.uAmount, r.amount);
+
+ 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: fractalNoiseSchema,
+ validateParams: validateFractalNoiseParams,
+ },
+);
diff --git a/packages/effects/src/fractal-noise/shader.ts b/packages/effects/src/fractal-noise/shader.ts
new file mode 100644
index 0000000000..e946608743
--- /dev/null
+++ b/packages/effects/src/fractal-noise/shader.ts
@@ -0,0 +1,150 @@
+// 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
+export const FRACTAL_NOISE_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 vec2 uOffset;
+uniform float uScale;
+uniform float uComplexity;
+uniform float uEvolution;
+uniform float uSubInfluence;
+uniform float uSubScaling;
+uniform float uContrast;
+uniform float uBrightness;
+uniform float uAmount;
+uniform float uCycle;
+uniform uint uSeed;
+uniform int uFractalType;
+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;
+}
+
+float layer(vec2 p, float z, uint seed) {
+ if (!uCycleEvolution) return valueNoise(vec3(p, uEvolution + z), seed);
+ float t = mod(uEvolution, uCycle);
+ return mix(valueNoise(vec3(p, t + z), seed), valueNoise(vec3(p, t - uCycle + z), seed), t / uCycle);
+}
+
+float shape(float n) {
+ float s = 2.0 * n - 1.0;
+ if (uFractalType == 1) return 1.0 - s * s;
+ if (uFractalType == 2) return 1.0 - abs(s);
+ if (uFractalType == 3) return (1.0 - abs(s)) * (1.0 - abs(s));
+ if (uFractalType == 8) {
+ float distance = clamp(abs(s) / 0.12, 0.0, 1.0);
+ return 1.0 - distance * distance;
+ }
+ return n;
+}
+
+void main() {
+ vec4 source = texture(uSource, vUv);
+ if (source.a == 0.0 || uAmount == 0.0) {
+ fragColor = source;
+ return;
+ }
+ vec2 pixel = vec2(vUv.x, 1.0 - vUv.y) * uResolution;
+ vec2 base = (pixel - uResolution * 0.5 - uOffset) / uScale;
+ float sum = 0.0;
+ float norm = 0.0;
+ float amplitude = 1.0;
+ float frequency = 1.0;
+ float best = 0.0;
+ for (int octave = 0; octave < 20; octave++) {
+ float weight = clamp(uComplexity - float(octave), 0.0, 1.0);
+ if (weight == 0.0 || amplitude == 0.0) break;
+ vec2 p = base * frequency;
+ float z = float(octave) * 7.31;
+ uint seed = (uSeed ^ 0x51edu) + uint(octave);
+ if (uFractalType >= 4 && uFractalType <= 6) {
+ float a = layer(p * 0.5, z + 3.1, seed ^ 0x55u) - 0.5;
+ if (uFractalType == 5) {
+ float angle = a * 3.0;
+ p = mat2(cos(angle), sin(angle), -sin(angle), cos(angle)) * p;
+ } else {
+ float b = layer(p * 0.5, z + 5.7, seed ^ 0xaau) - 0.5;
+ float strength = uFractalType == 6 ? 0.5 + float(octave) * 0.35 : 1.0;
+ p += vec2(a, b) * 1.5 * strength;
+ }
+ }
+ float n = shape(layer(p, z, seed));
+ // Fade fractional octaves in for Max too, so animating complexity is continuous.
+ best = max(best, n * amplitude * weight);
+ sum += n * amplitude * weight;
+ norm += amplitude * weight;
+ amplitude *= uSubInfluence;
+ frequency /= uSubScaling;
+ }
+ float noise = uFractalType == 7 ? best : sum / norm;
+ noise = clamp((noise - 0.5) * uContrast + 0.5 + uBrightness, 0.0, 1.0);
+ if (uInvert) noise = 1.0 - noise;
+ fragColor = vec4(mix(source.rgb, vec3(noise) * source.a, uAmount), source.a);
+}
+`;
diff --git a/packages/studio-shared/src/effect-catalog.ts b/packages/studio-shared/src/effect-catalog.ts
index 1423aa4f2b..7e9882cd6d 100644
--- a/packages/studio-shared/src/effect-catalog.ts
+++ b/packages/studio-shared/src/effect-catalog.ts
@@ -804,6 +804,17 @@ export const EFFECT_CATALOG: readonly EffectCatalogItem[] = [
config: {},
},
},
+ {
+ id: 'effects-fractal-noise',
+ category: 'Generate',
+ label: 'fractalNoise()',
+ description: 'Evolving fractal noise textures',
+ effect: {
+ name: 'fractalNoise',
+ importPath: '@remotion/effects/fractal-noise',
+ config: {},
+ },
+ },
{
id: 'effects-contour-lines',
category: 'Generate',