Skip to content

🎥 Make videos programmatically with React

`@remotion/effects`: Add flannel effect (#9189)

Jonny Burger67b19deea583
diff --git a/packages/docs/components/effects-demos/registry.ts b/packages/docs/components/effects-demos/registry.ts
index e4ab2264f2..fea15e325e 100644
--- a/packages/docs/components/effects-demos/registry.ts
+++ b/packages/docs/components/effects-demos/registry.ts
@@ -14,6 +14,7 @@ import {duotone} from '@remotion/effects/duotone';
import {emboss} from '@remotion/effects/emboss';
import {evolve} from '@remotion/effects/evolve';
import {fisheye} from '@remotion/effects/fisheye';
+import {flannel} from '@remotion/effects/flannel';
import {glow} from '@remotion/effects/glow';
import {grayscale} from '@remotion/effects/grayscale';
import {gridlines} from '@remotion/effects/gridlines';
@@ -75,6 +76,7 @@ import {EffectsDuotonePreview} from '../effects/effects-duotone-preview';
import {EffectsEmbossPreview} from '../effects/effects-emboss-preview';
import {EffectsEvolvePreview} from '../effects/effects-evolve-preview';
import {EffectsFisheyePreview} from '../effects/effects-fisheye-preview';
+import {EffectsFlannelPreview} from '../effects/effects-flannel-preview';
import {EffectsGlowPreview} from '../effects/effects-glow-preview';
import {EffectsGrayscalePreview} from '../effects/effects-grayscale-preview';
import {EffectsGridlinesPreview} from '../effects/effects-gridlines-preview';
@@ -183,6 +185,14 @@ export const effectsDemos: EffectsDemoType[] = [
comp: EffectsBurlapPreview,
schema: burlap().definition.schema,
},
+ {
+ ...defaults,
+ id: 'effects-flannel',
+ effectName: 'flannel',
+ effectImportPath: '@remotion/effects/flannel',
+ comp: EffectsFlannelPreview,
+ schema: flannel().definition.schema,
+ },
{
...defaults,
id: 'effects-emboss',
diff --git a/packages/docs/components/effects/effects-flannel-preview.tsx b/packages/docs/components/effects/effects-flannel-preview.tsx
new file mode 100644
index 0000000000..abdf2b8675
--- /dev/null
+++ b/packages/docs/components/effects/effects-flannel-preview.tsx
@@ -0,0 +1,22 @@
+import {flannel} from '@remotion/effects/flannel';
+import React from 'react';
+import {Solid, useVideoConfig} from 'remotion';
+
+export const EffectsFlannelPreview: React.FC<{
+ readonly amount: number;
+ readonly size: number;
+ readonly softness: number;
+ readonly baseColor: string;
+ readonly stripeColor: string;
+}> = ({amount, size, softness, baseColor, stripeColor}) => {
+ const {width, height} = useVideoConfig();
+
+ return (
+ <Solid
+ width={width}
+ height={height}
+ color={baseColor}
+ effects={[flannel({amount, size, softness, baseColor, stripeColor})]}
+ />
+ );
+};
diff --git a/packages/docs/docs/effects/flannel.mdx b/packages/docs/docs/effects/flannel.mdx
new file mode 100644
index 0000000000..6b22319142
--- /dev/null
+++ b/packages/docs/docs/effects/flannel.mdx
@@ -0,0 +1,84 @@
+---
+image: /generated/articles-docs-effects-flannel.png
+slug: /effects/flannel
+title: flannel()
+sidebar_label: flannel()
+crumb: '@remotion/effects'
+---
+
+# flannel()<AvailableFrom v="4.0.491" />
+
+_Part of the [`@remotion/effects`](/docs/effects/api) package._
+
+Generates a plaid woven-fabric pattern on a [`<Solid>`](/docs/solid).
+
+The solid color supplies an opaque base for the fabric pattern.
+
+## Preview
+
+<EffectsDemo type="effects-flannel" />
+
+## Example
+
+```tsx twoslash title="MyComp.tsx"
+import {Solid} from 'remotion';
+import {flannel} from '@remotion/effects/flannel';
+
+export const MyComp: React.FC = () => {
+ return (
+ <Solid
+ width={1280}
+ height={720}
+ color="#c92f3d"
+ effects={[
+ flannel({
+ amount: 0.8,
+ size: 96,
+ softness: 0.18,
+ baseColor: '#c92f3d',
+ stripeColor: '#241015',
+ }),
+ ]}
+ />
+ );
+};
+```
+
+## API
+
+Pass an object with the following properties. You can also call `flannel()` without arguments.
+
+### `amount?`
+
+Strength from `0` to `1`. Defaults to `0.7`. Use `0` to leave the layer unchanged.
+
+### `size?`
+
+Width of one plaid repeat in pixels. Defaults to `96`. Must be greater than `0`.
+
+### `softness?`
+
+Softness of the woven stripe edges from `0` to `1`. Defaults to `0.18`.
+
+### `baseColor?`
+
+Main fabric color. Defaults to `#c92f3d`.
+
+### `stripeColor?`
+
+Color of the crossing stripes. Defaults to `#241015`. Alpha controls how strongly the stripes cover the base color.
+
+### `disabled?`
+
+When `true`, the effect is skipped. Defaults to `false`.
+
+## Requirements
+
+`flannel()` uses a WebGL2 backend. During renders, enable WebGL via [`Config.setChromiumOpenGlRenderer('angle')`](/docs/config#setchromiumopenglrenderer). See [Using WebGL during renders](/docs/remotion/html-in-canvas#using-webgl-during-renders).
+
+## See also
+
+- [`@remotion/effects`](/docs/effects/api)
+- [`burlap()`](/docs/effects/burlap)
+- [`pattern()`](/docs/effects/pattern)
+- [Source code for this effect](https://github.com/remotion-dev/remotion/blob/main/packages/effects/src/flannel.ts)
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index a0dcab4dae..8067a5da51 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -289,6 +289,7 @@ const sidebars: SidebarsConfig = {
'effects/emboss',
'effects/evolve',
'effects/fisheye',
+ 'effects/flannel',
'effects/glow',
'effects/grayscale',
'effects/gridlines',
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 4922d1f3bd..c8bb8a7f70 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -1916,6 +1916,15 @@ export const articles = [
noAi: false,
slug: 'effects/fisheye',
},
+ {
+ id: 'effects/flannel',
+ title: 'flannel()',
+ relativePath: 'docs/effects/flannel.mdx',
+ compId: 'articles-docs-effects-flannel',
+ crumb: '@remotion/effects',
+ noAi: false,
+ slug: 'effects/flannel',
+ },
{
id: 'effects/glow',
title: 'glow()',
diff --git a/packages/docs/src/remotion/Root.tsx b/packages/docs/src/remotion/Root.tsx
index c2e5568b02..952fb544d4 100644
--- a/packages/docs/src/remotion/Root.tsx
+++ b/packages/docs/src/remotion/Root.tsx
@@ -18,6 +18,7 @@ import {EffectsDuotonePreview} from '../../components/effects/effects-duotone-pr
import {EffectsEmbossPreview} from '../../components/effects/effects-emboss-preview';
import {EffectsEvolvePreview} from '../../components/effects/effects-evolve-preview';
import {EffectsFisheyePreview} from '../../components/effects/effects-fisheye-preview';
+import {EffectsFlannelPreview} from '../../components/effects/effects-flannel-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';
@@ -210,6 +211,19 @@ export const RemotionRoot: React.FC = () => {
color: '#3b2818',
}}
/>
+ <Still
+ id="effects-flannel-preview"
+ component={EffectsFlannelPreview}
+ width={1280}
+ height={720}
+ defaultProps={{
+ amount: 0.82,
+ size: 96,
+ softness: 0.18,
+ baseColor: '#c92f3d',
+ stripeColor: '#241015',
+ }}
+ />
<Still
id="effects-emboss-preview"
component={EffectsEmbossPreview}
diff --git a/packages/docs/static/generated/articles-docs-effects-flannel.png b/packages/docs/static/generated/articles-docs-effects-flannel.png
new file mode 100644
index 0000000000..d7f5057815
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-effects-flannel.png differ
diff --git a/packages/docs/static/img/effects-flannel-preview.png b/packages/docs/static/img/effects-flannel-preview.png
new file mode 100644
index 0000000000..e6f0caa524
Binary files /dev/null and b/packages/docs/static/img/effects-flannel-preview.png differ
diff --git a/packages/effects/bundle.ts b/packages/effects/bundle.ts
index fb78193f0f..766cac901b 100644
--- a/packages/effects/bundle.ts
+++ b/packages/effects/bundle.ts
@@ -21,6 +21,7 @@ const effectEntrypoints = [
'src/emboss.ts',
'src/evolve.ts',
'src/fisheye.ts',
+ 'src/flannel.ts',
'src/corner-pin.ts',
'src/glow.ts',
'src/grayscale.ts',
diff --git a/packages/effects/package.json b/packages/effects/package.json
index 03d8676f8d..7ec455033a 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"
},
+ "./flannel": {
+ "types": "./dist/flannel.d.ts",
+ "module": "./dist/esm/flannel.mjs",
+ "import": "./dist/esm/flannel.mjs"
+ },
"./checkerboard": {
"types": "./dist/checkerboard.d.ts",
"module": "./dist/esm/checkerboard.mjs",
@@ -342,6 +347,9 @@
"burlap": [
"dist/burlap.d.ts"
],
+ "flannel": [
+ "dist/flannel.d.ts"
+ ],
"checkerboard": [
"dist/checkerboard.d.ts"
],
diff --git a/packages/effects/src/flannel.ts b/packages/effects/src/flannel.ts
new file mode 100644
index 0000000000..5e7298af35
--- /dev/null
+++ b/packages/effects/src/flannel.ts
@@ -0,0 +1,376 @@
+import type {InteractivitySchema} from 'remotion';
+import {Internals} from 'remotion';
+import {
+ assertOptionalFiniteNumber,
+ parseColorRgba,
+ type ParsedColorRgba,
+ validateUnitInterval,
+} from './color-utils.js';
+import {
+ assertEffectParamsObject,
+ assertOptionalColor,
+} from './validate-effect-param.js';
+
+const {createEffect, createWebGL2ContextError} = Internals;
+
+const DEFAULT_AMOUNT = 0.7 as const;
+const DEFAULT_SIZE = 96 as const;
+const DEFAULT_SOFTNESS = 0.18 as const;
+const DEFAULT_BASE_COLOR = '#c92f3d' as const;
+const DEFAULT_STRIPE_COLOR = '#241015' as const;
+
+const flannelSchema = {
+ amount: {
+ type: 'number',
+ min: 0,
+ max: 1,
+ step: 0.01,
+ default: DEFAULT_AMOUNT,
+ description: 'Amount',
+ hiddenFromList: false,
+ },
+ size: {
+ type: 'number',
+ min: 1,
+ max: 500,
+ step: 1,
+ default: DEFAULT_SIZE,
+ description: 'Pattern size',
+ hiddenFromList: false,
+ },
+ softness: {
+ type: 'number',
+ min: 0,
+ max: 1,
+ step: 0.01,
+ default: DEFAULT_SOFTNESS,
+ description: 'Softness',
+ hiddenFromList: false,
+ },
+ baseColor: {
+ type: 'color',
+ default: DEFAULT_BASE_COLOR,
+ description: 'Base color',
+ },
+ stripeColor: {
+ type: 'color',
+ default: DEFAULT_STRIPE_COLOR,
+ description: 'Stripe color',
+ },
+} as const satisfies InteractivitySchema;
+
+export type FlannelParams = {
+ /** Strength of the flannel treatment from `0` to `1`. Defaults to `0.7`. */
+ readonly amount?: number;
+ /** Width of one plaid repeat in pixels. Defaults to `96`. */
+ readonly size?: number;
+ /** Edge softness of the woven stripes from `0` to `1`. Defaults to `0.18`. */
+ readonly softness?: number;
+ /** Main fabric color. Defaults to `#c92f3d`. */
+ readonly baseColor?: string;
+ /** Color of the crossing stripes. Defaults to `#241015`. */
+ readonly stripeColor?: string;
+};
+
+type FlannelResolved = Required<FlannelParams>;
+
+type FlannelState = {
+ readonly gl: WebGL2RenderingContext;
+ readonly program: WebGLProgram;
+ readonly vao: WebGLVertexArrayObject;
+ readonly vbo: WebGLBuffer;
+ readonly texture: WebGLTexture;
+ readonly uSource: WebGLUniformLocation | null;
+ readonly uResolution: WebGLUniformLocation | null;
+ readonly uAmount: WebGLUniformLocation | null;
+ readonly uSize: WebGLUniformLocation | null;
+ readonly uSoftness: WebGLUniformLocation | null;
+ readonly uBaseColor: WebGLUniformLocation | null;
+ readonly uStripeColor: WebGLUniformLocation | null;
+ readonly colorCtx: CanvasRenderingContext2D;
+ cachedBaseColor: string;
+ cachedBaseColorRgba: ParsedColorRgba;
+ cachedStripeColor: string;
+ cachedStripeColorRgba: ParsedColorRgba;
+};
+
+const resolve = (params: FlannelParams): FlannelResolved => ({
+ amount: params.amount ?? DEFAULT_AMOUNT,
+ size: params.size ?? DEFAULT_SIZE,
+ softness: params.softness ?? DEFAULT_SOFTNESS,
+ baseColor: params.baseColor ?? DEFAULT_BASE_COLOR,
+ stripeColor: params.stripeColor ?? DEFAULT_STRIPE_COLOR,
+});
+
+const validateFlannelParams = (params: FlannelParams): void => {
+ assertEffectParamsObject(params, 'Flannel');
+ assertOptionalFiniteNumber(params.amount, 'amount');
+ assertOptionalFiniteNumber(params.size, 'size');
+ assertOptionalFiniteNumber(params.softness, 'softness');
+ assertOptionalColor(params.baseColor, 'baseColor');
+ assertOptionalColor(params.stripeColor, 'stripeColor');
+
+ const resolved = resolve(params);
+ validateUnitInterval(resolved.amount, 'amount');
+ validateUnitInterval(resolved.softness, 'softness');
+ if (resolved.size <= 0) {
+ throw new TypeError(
+ `"size" must be greater than 0, but got ${JSON.stringify(resolved.size)}`,
+ );
+ }
+};
+
+const FLANNEL_VS = /* 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 FLANNEL_FS = /* glsl */ `#version 300 es
+precision highp float;
+
+in vec2 vUv;
+out vec4 fragColor;
+
+uniform sampler2D uSource;
+uniform vec2 uResolution;
+uniform float uAmount;
+uniform float uSize;
+uniform float uSoftness;
+uniform vec4 uBaseColor;
+uniform vec4 uStripeColor;
+
+float stripe(float coordinate, float center, float width, float softness) {
+ float distanceFromCenter = abs(fract(coordinate) - center);
+ float halfWidth = width * 0.5;
+ return 1.0 - smoothstep(halfWidth, halfWidth + softness, distanceFromCenter);
+}
+
+void main() {
+ vec4 source = texture(uSource, vUv);
+ if (source.a <= 0.001 || uAmount <= 0.0) {
+ fragColor = source;
+ return;
+ }
+
+ vec2 pixel = vUv * uResolution;
+ vec2 plaid = pixel / max(uSize, 0.001);
+ float edge = mix(0.002, 0.08, uSoftness);
+
+ float verticalWide = stripe(plaid.x, 0.5, 0.34, edge);
+ float horizontalWide = stripe(plaid.y, 0.5, 0.34, edge);
+ float verticalFine = stripe(plaid.x * 2.0, 0.5, 0.07, edge * 0.5);
+ float horizontalFine = stripe(plaid.y * 2.0, 0.5, 0.07, edge * 0.5);
+ float bands = max(max(verticalWide, horizontalWide), max(verticalFine, horizontalFine) * 0.72);
+ float crossing = max(verticalWide * horizontalWide, verticalFine * horizontalFine);
+
+ float threadX = 0.5 + 0.5 * sin(pixel.x * 3.14159265);
+ float threadY = 0.5 + 0.5 * sin(pixel.y * 3.14159265);
+ float weave = (threadX - 0.5) * (threadY - 0.5) * 0.12;
+
+ vec3 sourceRgb = source.rgb / source.a;
+ float luminance = dot(sourceRgb, vec3(0.2126, 0.7152, 0.0722));
+ vec3 plaidColor = mix(uBaseColor.rgb, uStripeColor.rgb, bands * uStripeColor.a);
+ plaidColor = mix(plaidColor, uStripeColor.rgb * 0.72, crossing * uStripeColor.a);
+ plaidColor *= mix(0.58, 1.18, luminance) + weave;
+ vec3 result = mix(sourceRgb, clamp(plaidColor, 0.0, 1.0), uAmount);
+
+ fragColor = vec4(result * source.a, source.a);
+}
+`;
+
+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(`Flannel shader compile failed: ${log ?? '(no log)'}`);
+ }
+
+ return shader;
+};
+
+const setupFlannel = (target: HTMLCanvasElement): FlannelState => {
+ const gl = target.getContext('webgl2', {
+ premultipliedAlpha: true,
+ alpha: true,
+ preserveDrawingBuffer: true,
+ });
+ if (!gl) {
+ throw createWebGL2ContextError('flannel effect');
+ }
+
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
+ const vertexShader = compileShader(gl, gl.VERTEX_SHADER, FLANNEL_VS);
+ const fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, FLANNEL_FS);
+ const program = gl.createProgram();
+ if (!program) {
+ throw new Error('Failed to create WebGL program');
+ }
+
+ gl.attachShader(program, vertexShader);
+ gl.attachShader(program, fragmentShader);
+ gl.linkProgram(program);
+ gl.deleteShader(vertexShader);
+ gl.deleteShader(fragmentShader);
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
+ const log = gl.getProgramInfoLog(program);
+ gl.deleteProgram(program);
+ throw new Error(`Flannel program link failed: ${log ?? '(no log)'}`);
+ }
+
+ const vao = gl.createVertexArray();
+ const vbo = gl.createBuffer();
+ if (!vao || !vbo) {
+ throw new Error('Failed to create WebGL geometry');
+ }
+
+ gl.bindVertexArray(vao);
+ gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
+ gl.bufferData(
+ gl.ARRAY_BUFFER,
+ new Float32Array([-1, -1, 0, 0, 1, -1, 1, 0, -1, 1, 0, 1, 1, 1, 1, 1]),
+ 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_WRAP_S, gl.CLAMP_TO_EDGE);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
+ gl.bindTexture(gl.TEXTURE_2D, null);
+
+ const colorCanvas = document.createElement('canvas');
+ colorCanvas.width = 1;
+ colorCanvas.height = 1;
+ const colorCtx = colorCanvas.getContext('2d', {willReadFrequently: true});
+ if (!colorCtx) {
+ throw new Error('Failed to acquire 2D context for color parsing');
+ }
+
+ return {
+ gl,
+ program,
+ vao,
+ vbo,
+ texture,
+ uSource: gl.getUniformLocation(program, 'uSource'),
+ uResolution: gl.getUniformLocation(program, 'uResolution'),
+ uAmount: gl.getUniformLocation(program, 'uAmount'),
+ uSize: gl.getUniformLocation(program, 'uSize'),
+ uSoftness: gl.getUniformLocation(program, 'uSoftness'),
+ uBaseColor: gl.getUniformLocation(program, 'uBaseColor'),
+ uStripeColor: gl.getUniformLocation(program, 'uStripeColor'),
+ colorCtx,
+ cachedBaseColor: '',
+ cachedBaseColorRgba: [0, 0, 0, 255],
+ cachedStripeColor: '',
+ cachedStripeColorRgba: [0, 0, 0, 255],
+ };
+};
+
+const normalizedRgba = (
+ color: ParsedColorRgba,
+): readonly [number, number, number, number] => [
+ color[0] / 255,
+ color[1] / 255,
+ color[2] / 255,
+ color[3] / 255,
+];
+
+export const flannel = createEffect<FlannelParams, FlannelState>({
+ type: 'dev.remotion.effects.flannel',
+ label: 'flannel()',
+ documentationLink: 'https://www.remotion.dev/docs/effects/flannel',
+ backend: 'webgl2',
+ calculateKey: (params) => {
+ const resolved = resolve(params);
+ return `flannel-${resolved.amount}-${resolved.size}-${resolved.softness}-${resolved.baseColor}-${resolved.stripeColor}`;
+ },
+ setup: setupFlannel,
+ apply: ({source, width, height, params, state, flipSourceY}) => {
+ const resolved = resolve(params);
+ if (state.cachedBaseColor !== resolved.baseColor) {
+ state.cachedBaseColor = resolved.baseColor;
+ state.cachedBaseColorRgba = parseColorRgba(
+ state.colorCtx,
+ resolved.baseColor,
+ );
+ }
+
+ if (state.cachedStripeColor !== resolved.stripeColor) {
+ state.cachedStripeColor = resolved.stripeColor;
+ state.cachedStripeColorRgba = parseColorRgba(
+ state.colorCtx,
+ resolved.stripeColor,
+ );
+ }
+
+ const base = normalizedRgba(state.cachedBaseColorRgba);
+ const stripe = normalizedRgba(state.cachedStripeColorRgba);
+ const {gl} = 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.useProgram(state.program);
+ gl.bindVertexArray(state.vao);
+ gl.activeTexture(gl.TEXTURE0);
+ gl.bindTexture(gl.TEXTURE_2D, state.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,
+ );
+ if (state.uSource) gl.uniform1i(state.uSource, 0);
+ if (state.uResolution) gl.uniform2f(state.uResolution, width, height);
+ if (state.uAmount) gl.uniform1f(state.uAmount, resolved.amount);
+ if (state.uSize) gl.uniform1f(state.uSize, resolved.size);
+ if (state.uSoftness) gl.uniform1f(state.uSoftness, resolved.softness);
+ if (state.uBaseColor) gl.uniform4f(state.uBaseColor, ...base);
+ if (state.uStripeColor) gl.uniform4f(state.uStripeColor, ...stripe);
+ 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: flannelSchema,
+ validateParams: validateFlannelParams,
+});
diff --git a/packages/effects/src/test/effect-params.test.ts b/packages/effects/src/test/effect-params.test.ts
index 4ddb01e105..96fb29e321 100644
--- a/packages/effects/src/test/effect-params.test.ts
+++ b/packages/effects/src/test/effect-params.test.ts
@@ -15,6 +15,7 @@ import {duotone} from '../duotone.js';
import {emboss} from '../emboss.js';
import {evolve} from '../evolve.js';
import {fisheye} from '../fisheye/index.js';
+import {flannel} from '../flannel.js';
import {glow} from '../glow/index.js';
import {grayscale} from '../grayscale.js';
import {gridlines} from '../gridlines.js';
@@ -127,6 +128,9 @@ test('@remotion/effects expose documentation links', () => {
expect(fisheye().definition.documentationLink).toBe(
'https://www.remotion.dev/docs/effects/fisheye',
);
+ expect(flannel().definition.documentationLink).toBe(
+ 'https://www.remotion.dev/docs/effects/flannel',
+ );
expect(cornerPin().definition.documentationLink).toBe(
'https://www.remotion.dev/docs/effects/corner-pin',
);
@@ -281,6 +285,7 @@ test('@remotion/effects expose API names as Studio labels', () => {
expect(dropShadow().definition.label).toBe('dropShadow()');
expect(emboss().definition.label).toBe('emboss()');
expect(fisheye().definition.label).toBe('fisheye()');
+ expect(flannel().definition.label).toBe('flannel()');
expect(cornerPin().definition.label).toBe('cornerPin()');
expect(glow().definition.label).toBe('glow()');
expect(grayscale().definition.label).toBe('grayscale()');
@@ -2240,6 +2245,53 @@ test('burlap() parameters produce distinct effect keys', () => {
).toBe(6);
});
+test('flannel() accepts default and valid params', () => {
+ expect(() => flannel()).not.toThrow();
+ expect(() =>
+ flannel({
+ amount: 0.8,
+ size: 72,
+ softness: 0.25,
+ baseColor: '#b51f2e',
+ stripeColor: '#16233f',
+ }),
+ ).not.toThrow();
+});
+
+test('flannel() uses a red palette by default', () => {
+ expect(flannel().definition.schema.baseColor).toMatchObject({
+ default: '#c92f3d',
+ });
+ expect(flannel().definition.schema.stripeColor).toMatchObject({
+ default: '#241015',
+ });
+});
+
+test('flannel() rejects invalid params', () => {
+ expect(() => flannel({amount: Number.NaN})).toThrow(
+ '"amount" must be a finite number',
+ );
+ expect(() => flannel({amount: 1.1})).toThrow('"amount" must be <= 1');
+ expect(() => flannel({size: 0})).toThrow('"size" must be greater than 0');
+ expect(() => flannel({softness: -0.1})).toThrow('"softness" must be >= 0');
+ expect(() => flannel({baseColor: ''})).toThrow(
+ '"baseColor" must be a non-empty string',
+ );
+});
+
+test('flannel() parameters produce distinct effect keys', () => {
+ const keys = [
+ flannel(),
+ flannel({amount: 0.8}),
+ flannel({size: 72}),
+ flannel({softness: 0.3}),
+ flannel({baseColor: '#224422'}),
+ flannel({stripeColor: '#eee8d5'}),
+ ].map((effect) => effect.effectKey);
+
+ expect(new Set(keys).size).toBe(keys.length);
+});
+
test('emboss() accepts default params', () => {
expect(() => emboss()).not.toThrow();
});
diff --git a/packages/studio-shared/src/effect-catalog.ts b/packages/studio-shared/src/effect-catalog.ts
index 82d2711ef2..8f629da039 100644
--- a/packages/studio-shared/src/effect-catalog.ts
+++ b/packages/studio-shared/src/effect-catalog.ts
@@ -685,6 +685,17 @@ export const EFFECT_CATALOG: readonly EffectCatalogItem[] = [
config: {},
},
},
+ {
+ id: 'effects-flannel',
+ category: 'Generate',
+ label: 'flannel()',
+ description: 'Plaid woven fabric pattern',
+ effect: {
+ name: 'flannel',
+ importPath: '@remotion/effects/flannel',
+ config: {},
+ },
+ },
{
id: 'effects-halftone-linear-gradient',
category: 'Generate',