Skip to content

🎥 Make videos programmatically with React

`@remotion/effects`: Add emboss effect (#8530)

Jonny Burger8c4d19b4c461
diff --git a/packages/docs/components/effects-demos/registry.ts b/packages/docs/components/effects-demos/registry.ts
index 20e620d1f1..cfbb2ca412 100644
--- a/packages/docs/components/effects-demos/registry.ts
+++ b/packages/docs/components/effects-demos/registry.ts
@@ -9,6 +9,7 @@ import {contrast} from '@remotion/effects/contrast';
import {dotGrid} from '@remotion/effects/dot-grid';
import {dropShadow} from '@remotion/effects/drop-shadow';
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 {glow} from '@remotion/effects/glow';
@@ -54,6 +55,7 @@ import {EffectsContrastPreview} from '../effects/effects-contrast-preview';
import {EffectsDotGridPreview} from '../effects/effects-dot-grid-preview';
import {EffectsDropShadowPreview} from '../effects/effects-drop-shadow-preview';
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 {EffectsGlowPreview} from '../effects/effects-glow-preview';
@@ -139,6 +141,14 @@ export const effectsDemos: EffectsDemoType[] = [
comp: EffectsBurlapPreview,
schema: burlap().definition.schema,
},
+ {
+ ...defaults,
+ id: 'effects-emboss',
+ effectName: 'emboss',
+ effectImportPath: '@remotion/effects/emboss',
+ comp: EffectsEmbossPreview,
+ schema: emboss().definition.schema,
+ },
{
...defaults,
id: 'effects-contrast',
diff --git a/packages/docs/components/effects/effects-emboss-preview.tsx b/packages/docs/components/effects/effects-emboss-preview.tsx
new file mode 100644
index 0000000000..6ec267f0f3
--- /dev/null
+++ b/packages/docs/components/effects/effects-emboss-preview.tsx
@@ -0,0 +1,34 @@
+import {emboss} from '@remotion/effects/emboss';
+import React from 'react';
+import {CanvasImage} from 'remotion';
+import {EFFECTS_PREVIEW_IMAGE_SRC} from './effects-preview-image';
+
+export const EffectsEmbossPreview: React.FC<{
+ readonly amount: number;
+ readonly size: number;
+ readonly lineWidth: number;
+ readonly depth: number;
+ readonly angle: number;
+ readonly lightAngle: number;
+ readonly offset: number;
+}> = ({amount, size, lineWidth, depth, angle, lightAngle, offset}) => {
+ return (
+ <CanvasImage
+ src={EFFECTS_PREVIEW_IMAGE_SRC}
+ width={1280}
+ height={720}
+ fit="cover"
+ effects={[
+ emboss({
+ amount,
+ size,
+ lineWidth,
+ depth,
+ angle,
+ lightAngle,
+ offset,
+ }),
+ ]}
+ />
+ );
+};
diff --git a/packages/docs/docs/effects/emboss.mdx b/packages/docs/docs/effects/emboss.mdx
new file mode 100644
index 0000000000..cede1c87e0
--- /dev/null
+++ b/packages/docs/docs/effects/emboss.mdx
@@ -0,0 +1,110 @@
+---
+image: /generated/articles-docs-effects-emboss.png
+slug: /effects/emboss
+title: emboss()
+sidebar_label: emboss()
+crumb: '@remotion/effects'
+---
+
+# emboss()<AvailableFrom v="4.0.479" />
+
+_Part of the [`@remotion/effects`](/docs/effects/api) package._
+
+Adds a procedural raised-line relief to canvas-based components such as [`<Video>`](/docs/media/video), [`<HtmlInCanvas>`](/docs/remotion/html-in-canvas) and [`<Solid>`](/docs/solid).
+
+The effect preserves the source colors and alpha mask. Transparent regions stay transparent.
+
+## Preview
+
+<EffectsDemo type="effects-emboss" />
+
+## Example
+
+```tsx twoslash title="MyComp.tsx"
+import {emboss} from '@remotion/effects/emboss';
+import {Video} from '@remotion/media';
+import {AbsoluteFill, useCurrentFrame} from 'remotion';
+
+export const MyComp: React.FC = () => {
+ const frame = useCurrentFrame();
+
+ return (
+ <AbsoluteFill>
+ <Video
+ src="https://remotion.media/video.mp4"
+ effects={[
+ emboss({
+ amount: 0.85,
+ size: 24,
+ lineWidth: 6,
+ depth: 0.85,
+ angle: 0,
+ lightAngle: 135,
+ offset: frame * 0.6,
+ }),
+ ]}
+ />
+ </AbsoluteFill>
+ );
+};
+```
+
+## API
+
+Pass an object with the following properties. You can also call `emboss()` without arguments.
+
+### `amount?`
+
+Strength from `0` to `1`. Defaults to `0.7`.
+
+Use `0` to leave the layer unchanged.
+
+### `size?`
+
+Size of the repeated relief cells in pixels. Defaults to `26`.
+
+Must be greater than `0`. Smaller values create a tighter relief pattern.
+
+### `lineWidth?`
+
+Width of each raised dash in pixels. Defaults to `7`.
+
+Must be greater than `0`. Values larger than the cell size are clamped by the shader.
+
+### `depth?`
+
+Height of the virtual relief from `0` to `1`. Defaults to `0.75`.
+
+Use lower values for flatter shading.
+
+### `angle?`
+
+Rotates the repeated relief pattern in degrees. Defaults to `0`.
+
+### `lightAngle?`
+
+Direction of the virtual light in degrees. Defaults to `135`.
+
+Change this value to move the highlight and shadow edges of the raised pattern.
+
+### `offset?`
+
+Offset in pixels. Defaults to `0`.
+
+Animate this value with [`useCurrentFrame()`](/docs/use-current-frame) to scroll the relief pattern.
+
+### `disabled?`
+
+When `true`, the effect is skipped. Defaults to `false`.
+
+## Requirements
+
+`emboss()` 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)
+- [`lines()`](/docs/effects/lines)
+- [`scanlines()`](/docs/effects/scanlines)
+- [Source code for this effect](https://github.com/remotion-dev/remotion/blob/main/packages/effects/src/emboss.ts)
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index 1ee124c6b5..cf18e6a62c 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -284,6 +284,7 @@ const sidebars: SidebarsConfig = {
'effects/dot-grid',
'effects/drop-shadow',
'effects/duotone',
+ 'effects/emboss',
'effects/evolve',
'effects/fisheye',
'effects/glow',
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 996518b2c2..84a0ce5883 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -1835,6 +1835,15 @@ export const articles = [
noAi: false,
slug: 'effects/duotone',
},
+ {
+ id: 'effects/emboss',
+ title: 'emboss()',
+ relativePath: 'docs/effects/emboss.mdx',
+ compId: 'articles-docs-effects-emboss',
+ crumb: '@remotion/effects',
+ noAi: false,
+ slug: 'effects/emboss',
+ },
{
id: 'effects/evolve',
title: 'evolve()',
diff --git a/packages/docs/src/remotion/Root.tsx b/packages/docs/src/remotion/Root.tsx
index 22ee831610..56af3e0d0f 100644
--- a/packages/docs/src/remotion/Root.tsx
+++ b/packages/docs/src/remotion/Root.tsx
@@ -13,6 +13,7 @@ import {EffectsContrastPreview} from '../../components/effects/effects-contrast-
import {EffectsDotGridPreview} from '../../components/effects/effects-dot-grid-preview';
import {EffectsDropShadowPreview} from '../../components/effects/effects-drop-shadow-preview';
import {EffectsDuotonePreview} from '../../components/effects/effects-duotone-preview';
+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 {EffectsGlowPreview} from '../../components/effects/effects-glow-preview';
@@ -147,6 +148,21 @@ export const RemotionRoot: React.FC = () => {
color: '#3b2818',
}}
/>
+ <Still
+ id="effects-emboss-preview"
+ component={EffectsEmbossPreview}
+ width={1280}
+ height={720}
+ defaultProps={{
+ amount: 0.85,
+ size: 38,
+ lineWidth: 11,
+ depth: 0.85,
+ angle: 0,
+ lightAngle: 135,
+ offset: 0,
+ }}
+ />
<Still
id="effects-contrast-preview"
component={EffectsContrastPreview}
diff --git a/packages/docs/static/generated/articles-docs-effects-emboss.png b/packages/docs/static/generated/articles-docs-effects-emboss.png
new file mode 100644
index 0000000000..e74b2dd9c0
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-effects-emboss.png differ
diff --git a/packages/docs/static/img/effects-emboss-preview.png b/packages/docs/static/img/effects-emboss-preview.png
new file mode 100644
index 0000000000..f57f0712ac
Binary files /dev/null and b/packages/docs/static/img/effects-emboss-preview.png differ
diff --git a/packages/effects/bundle.ts b/packages/effects/bundle.ts
index 7cd4f1b4ca..433547ed7f 100644
--- a/packages/effects/bundle.ts
+++ b/packages/effects/bundle.ts
@@ -17,6 +17,7 @@ const effectEntrypoints = [
'src/contour-lines.ts',
'src/drop-shadow.ts',
'src/duotone.ts',
+ 'src/emboss.ts',
'src/evolve.ts',
'src/fisheye.ts',
'src/glow.ts',
diff --git a/packages/effects/package.json b/packages/effects/package.json
index 72972294f5..9a35f7bb02 100644
--- a/packages/effects/package.json
+++ b/packages/effects/package.json
@@ -84,6 +84,11 @@
"module": "./dist/esm/duotone.mjs",
"import": "./dist/esm/duotone.mjs"
},
+ "./emboss": {
+ "types": "./dist/emboss.d.ts",
+ "module": "./dist/esm/emboss.mjs",
+ "import": "./dist/esm/emboss.mjs"
+ },
"./evolve": {
"types": "./dist/evolve.d.ts",
"module": "./dist/esm/evolve.mjs",
@@ -283,6 +288,9 @@
"duotone": [
"dist/duotone.d.ts"
],
+ "emboss": [
+ "dist/emboss.d.ts"
+ ],
"evolve": [
"dist/evolve.d.ts"
],
diff --git a/packages/effects/src/emboss.ts b/packages/effects/src/emboss.ts
new file mode 100644
index 0000000000..20c1543b3d
--- /dev/null
+++ b/packages/effects/src/emboss.ts
@@ -0,0 +1,449 @@
+import type {InteractivitySchema} from 'remotion';
+import {Internals} from 'remotion';
+import {
+ assertOptionalFiniteNumber,
+ validateUnitInterval,
+} from './color-utils.js';
+import {assertEffectParamsObject} from './validate-effect-param.js';
+
+const {createEffect, createWebGL2ContextError} = Internals;
+
+const DEFAULT_AMOUNT = 0.7 as const;
+const DEFAULT_SIZE = 26 as const;
+const DEFAULT_LINE_WIDTH = 7 as const;
+const DEFAULT_DEPTH = 0.75 as const;
+const DEFAULT_ANGLE = 0 as const;
+const DEFAULT_LIGHT_ANGLE = 135 as const;
+const DEFAULT_OFFSET = 0 as const;
+
+export const embossSchema = {
+ amount: {
+ type: 'number',
+ min: 0,
+ max: 1,
+ step: 0.01,
+ default: DEFAULT_AMOUNT,
+ description: 'Amount',
+ hiddenFromList: false,
+ },
+ size: {
+ type: 'number',
+ min: 1,
+ max: 200,
+ step: 1,
+ default: DEFAULT_SIZE,
+ description: 'Size',
+ hiddenFromList: false,
+ },
+ lineWidth: {
+ type: 'number',
+ min: 0.1,
+ max: 100,
+ step: 0.1,
+ default: DEFAULT_LINE_WIDTH,
+ description: 'Line width',
+ hiddenFromList: false,
+ },
+ depth: {
+ type: 'number',
+ min: 0,
+ max: 1,
+ step: 0.01,
+ default: DEFAULT_DEPTH,
+ description: 'Depth',
+ hiddenFromList: false,
+ },
+ angle: {
+ type: 'rotation-degrees',
+ step: 1,
+ default: DEFAULT_ANGLE,
+ description: 'Angle',
+ },
+ lightAngle: {
+ type: 'rotation-degrees',
+ step: 1,
+ default: DEFAULT_LIGHT_ANGLE,
+ description: 'Light angle',
+ },
+ offset: {
+ type: 'number',
+ step: 0.1,
+ default: DEFAULT_OFFSET,
+ description: 'Offset',
+ hiddenFromList: false,
+ },
+} as const satisfies InteractivitySchema;
+
+export type EmbossParams = {
+ /** Strength of the relief shading from `0` to `1`. Defaults to `0.7`. */
+ readonly amount?: number;
+ /** Size of the repeated relief cells in pixels. Defaults to `26`. */
+ readonly size?: number;
+ /** Width of each raised dash in pixels. Defaults to `7`. */
+ readonly lineWidth?: number;
+ /** Height of the virtual relief from `0` to `1`. Defaults to `0.75`. */
+ readonly depth?: number;
+ /** Rotates the repeated relief pattern in degrees. Defaults to `0`. */
+ readonly angle?: number;
+ /** Direction of the virtual light in degrees. Defaults to `135`. */
+ readonly lightAngle?: number;
+ /** Offset in pixels. Animate this value to scroll the relief pattern. Defaults to `0`. */
+ readonly offset?: number;
+};
+
+type EmbossResolved = {
+ amount: number;
+ size: number;
+ lineWidth: number;
+ depth: number;
+ angle: number;
+ lightAngle: number;
+ offset: number;
+};
+
+type EmbossState = {
+ readonly gl: WebGL2RenderingContext;
+ readonly program: WebGLProgram;
+ readonly vao: WebGLVertexArrayObject;
+ readonly vbo: WebGLBuffer;
+ readonly texture: WebGLTexture;
+ readonly uniforms: {
+ readonly uSource: WebGLUniformLocation | null;
+ readonly uResolution: WebGLUniformLocation | null;
+ readonly uAmount: WebGLUniformLocation | null;
+ readonly uSize: WebGLUniformLocation | null;
+ readonly uLineWidth: WebGLUniformLocation | null;
+ readonly uDepth: WebGLUniformLocation | null;
+ readonly uAngle: WebGLUniformLocation | null;
+ readonly uLightAngle: WebGLUniformLocation | null;
+ readonly uOffset: WebGLUniformLocation | null;
+ };
+};
+
+const resolve = (p: EmbossParams): EmbossResolved => ({
+ amount: p.amount ?? DEFAULT_AMOUNT,
+ size: p.size ?? DEFAULT_SIZE,
+ lineWidth: p.lineWidth ?? DEFAULT_LINE_WIDTH,
+ depth: p.depth ?? DEFAULT_DEPTH,
+ angle: p.angle ?? DEFAULT_ANGLE,
+ lightAngle: p.lightAngle ?? DEFAULT_LIGHT_ANGLE,
+ offset: p.offset ?? DEFAULT_OFFSET,
+});
+
+const validatePositive = (value: number, name: string): void => {
+ if (value <= 0) {
+ throw new TypeError(
+ `"${name}" must be greater than 0, but got ${JSON.stringify(value)}`,
+ );
+ }
+};
+
+const validateEmbossParams = (params: EmbossParams): void => {
+ assertEffectParamsObject(params, 'Emboss');
+ assertOptionalFiniteNumber(params.amount, 'amount');
+ assertOptionalFiniteNumber(params.size, 'size');
+ assertOptionalFiniteNumber(params.lineWidth, 'lineWidth');
+ assertOptionalFiniteNumber(params.depth, 'depth');
+ assertOptionalFiniteNumber(params.angle, 'angle');
+ assertOptionalFiniteNumber(params.lightAngle, 'lightAngle');
+ assertOptionalFiniteNumber(params.offset, 'offset');
+
+ const r = resolve(params);
+ validateUnitInterval(r.amount, 'amount');
+ validatePositive(r.size, 'size');
+ validatePositive(r.lineWidth, 'lineWidth');
+ validateUnitInterval(r.depth, 'depth');
+};
+
+const EMBOSS_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 EMBOSS_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 uLineWidth;
+uniform float uDepth;
+uniform float uAngle;
+uniform float uLightAngle;
+uniform float uOffset;
+
+mat2 rotation(float angle) {
+ float c = cos(angle);
+ float s = sin(angle);
+ return mat2(c, -s, s, c);
+}
+
+float roundedBoxSdf(vec2 p, vec2 halfSize, float radius) {
+ vec2 q = abs(p) - halfSize + vec2(radius);
+ return length(max(q, vec2(0.0))) + min(max(q.x, q.y), 0.0) - radius;
+}
+
+float reliefHeight(vec2 fragPos) {
+ float size = max(uSize, 0.001);
+ float lineWidth = clamp(uLineWidth, 0.001, size * 0.85);
+ vec2 pos = rotation(uAngle) * (fragPos - uResolution * 0.5);
+ pos.x += uOffset;
+
+ vec2 cell = floor(pos / size);
+ vec2 local = (fract(pos / size) - 0.5) * size;
+ float alternate = mod(cell.x + cell.y, 2.0);
+ float dashAngle = mix(0.78539816339, -0.78539816339, step(0.5, alternate));
+ vec2 dash = rotation(dashAngle) * local;
+
+ float sdf = roundedBoxSdf(
+ dash,
+ vec2(size * 0.36, lineWidth * 0.5),
+ lineWidth * 0.5
+ );
+
+ return 1.0 - smoothstep(-1.0, 1.0, sdf);
+}
+
+void main() {
+ vec4 texColor = texture(uSource, vUv);
+ float alpha = texColor.a;
+
+ if (alpha <= 0.001) {
+ fragColor = vec4(0.0);
+ return;
+ }
+
+ if (uAmount <= 0.0 || uDepth <= 0.0) {
+ fragColor = texColor;
+ return;
+ }
+
+ vec2 fragPos = vUv * uResolution;
+ float h = reliefHeight(fragPos);
+ float hLeft = reliefHeight(fragPos - vec2(1.0, 0.0));
+ float hRight = reliefHeight(fragPos + vec2(1.0, 0.0));
+ float hDown = reliefHeight(fragPos - vec2(0.0, 1.0));
+ float hUp = reliefHeight(fragPos + vec2(0.0, 1.0));
+
+ vec3 normal = normalize(vec3(
+ (hLeft - hRight) * uDepth * 3.8,
+ (hDown - hUp) * uDepth * 3.8,
+ 1.0
+ ));
+ vec3 light = normalize(vec3(cos(uLightAngle), sin(uLightAngle), 0.7));
+ float lit = dot(normal, light);
+
+ float bevel = (lit - 0.64) * 0.72 * uDepth;
+ float plateau = (h - 0.5) * 0.08 * uDepth;
+ float edge = min(
+ abs(hRight - hLeft) + abs(hUp - hDown),
+ 1.0
+ );
+
+ vec3 rgb = texColor.rgb / alpha;
+ vec3 shaded = clamp(rgb + bevel + plateau - edge * 0.035 * uDepth, 0.0, 1.0);
+ rgb = mix(rgb, shaded, uAmount);
+
+ fragColor = vec4(rgb * alpha, alpha);
+}
+`;
+
+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(`Emboss 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(`Emboss program link failed: ${log ?? '(no log)'}`);
+ }
+
+ return program;
+};
+
+const setupEmboss = (target: HTMLCanvasElement): EmbossState => {
+ const gl = target.getContext('webgl2', {
+ premultipliedAlpha: true,
+ alpha: true,
+ preserveDrawingBuffer: true,
+ });
+ if (!gl) {
+ throw createWebGL2ContextError('emboss effect');
+ }
+
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
+
+ const vs = compileShader(gl, gl.VERTEX_SHADER, EMBOSS_VS);
+ const fs = compileShader(gl, gl.FRAGMENT_SHADER, EMBOSS_FS);
+ 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_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);
+
+ return {
+ gl,
+ program,
+ vao,
+ vbo,
+ texture,
+ uniforms: {
+ uSource: gl.getUniformLocation(program, 'uSource'),
+ uResolution: gl.getUniformLocation(program, 'uResolution'),
+ uAmount: gl.getUniformLocation(program, 'uAmount'),
+ uSize: gl.getUniformLocation(program, 'uSize'),
+ uLineWidth: gl.getUniformLocation(program, 'uLineWidth'),
+ uDepth: gl.getUniformLocation(program, 'uDepth'),
+ uAngle: gl.getUniformLocation(program, 'uAngle'),
+ uLightAngle: gl.getUniformLocation(program, 'uLightAngle'),
+ uOffset: gl.getUniformLocation(program, 'uOffset'),
+ },
+ };
+};
+
+const degreesToRadians = (degrees: number): number => {
+ return (degrees * Math.PI) / 180;
+};
+
+export const emboss = createEffect<EmbossParams, EmbossState>({
+ type: 'dev.remotion.effects.emboss',
+ label: 'emboss()',
+ documentationLink: 'https://www.remotion.dev/docs/effects/emboss',
+ backend: 'webgl2',
+ calculateKey: (params) => {
+ const r = resolve(params);
+ return `emboss-${r.amount}-${r.size}-${r.lineWidth}-${r.depth}-${r.angle}-${r.lightAngle}-${r.offset}`;
+ },
+ setup: (target) => setupEmboss(target),
+ apply: ({source, width, height, params, state, flipSourceY}) => {
+ const r = resolve(params);
+ const {gl, program, vao, texture, uniforms} = 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(program);
+ gl.bindVertexArray(vao);
+
+ 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,
+ );
+
+ if (uniforms.uSource) gl.uniform1i(uniforms.uSource, 0);
+ if (uniforms.uResolution) gl.uniform2f(uniforms.uResolution, width, height);
+ if (uniforms.uAmount) gl.uniform1f(uniforms.uAmount, r.amount);
+ if (uniforms.uSize) gl.uniform1f(uniforms.uSize, r.size);
+ if (uniforms.uLineWidth) gl.uniform1f(uniforms.uLineWidth, r.lineWidth);
+ if (uniforms.uDepth) gl.uniform1f(uniforms.uDepth, r.depth);
+ if (uniforms.uAngle) {
+ gl.uniform1f(uniforms.uAngle, degreesToRadians(r.angle));
+ }
+
+ if (uniforms.uLightAngle) {
+ gl.uniform1f(uniforms.uLightAngle, degreesToRadians(r.lightAngle));
+ }
+
+ if (uniforms.uOffset) gl.uniform1f(uniforms.uOffset, r.offset);
+
+ 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: embossSchema,
+ validateParams: validateEmbossParams,
+});
diff --git a/packages/effects/src/test/effect-params.test.ts b/packages/effects/src/test/effect-params.test.ts
index a6434fec1e..10373a13d5 100644
--- a/packages/effects/src/test/effect-params.test.ts
+++ b/packages/effects/src/test/effect-params.test.ts
@@ -10,6 +10,7 @@ import {contrast} from '../contrast.js';
import {dotGrid} from '../dot-grid.js';
import {dropShadow} from '../drop-shadow/index.js';
import {duotone} from '../duotone.js';
+import {emboss} from '../emboss.js';
import {evolve} from '../evolve.js';
import {fisheye} from '../fisheye/index.js';
import {glow} from '../glow/index.js';
@@ -96,6 +97,9 @@ test('@remotion/effects expose documentation links', () => {
expect(duotone().definition.documentationLink).toBe(
'https://www.remotion.dev/docs/effects/duotone',
);
+ expect(emboss().definition.documentationLink).toBe(
+ 'https://www.remotion.dev/docs/effects/emboss',
+ );
expect(evolve().definition.documentationLink).toBe(
'https://www.remotion.dev/docs/effects/evolve',
);
@@ -213,6 +217,7 @@ test('@remotion/effects expose API names as Studio labels', () => {
expect(duotone().definition.label).toBe('duotone()');
expect(evolve().definition.label).toBe('evolve()');
expect(dropShadow().definition.label).toBe('dropShadow()');
+ expect(emboss().definition.label).toBe('emboss()');
expect(fisheye().definition.label).toBe('fisheye()');
expect(glow().definition.label).toBe('glow()');
expect(grayscale().definition.label).toBe('grayscale()');
@@ -1735,6 +1740,72 @@ test('burlap() parameters produce distinct effect keys', () => {
).toBe(6);
});
+test('emboss() accepts default params', () => {
+ expect(() => emboss()).not.toThrow();
+});
+
+test('emboss() rejects non-finite params', () => {
+ expect(() => emboss({amount: Number.NaN})).toThrow(
+ '"amount" must be a finite number',
+ );
+ expect(() => emboss({size: Number.NaN})).toThrow(
+ '"size" must be a finite number',
+ );
+ expect(() => emboss({lineWidth: Number.NaN})).toThrow(
+ '"lineWidth" must be a finite number',
+ );
+ expect(() => emboss({depth: Number.NaN})).toThrow(
+ '"depth" must be a finite number',
+ );
+ expect(() => emboss({angle: Number.NaN})).toThrow(
+ '"angle" must be a finite number',
+ );
+ expect(() => emboss({lightAngle: Number.NaN})).toThrow(
+ '"lightAngle" must be a finite number',
+ );
+ expect(() => emboss({offset: Number.NaN})).toThrow(
+ '"offset" must be a finite number',
+ );
+});
+
+test('emboss() rejects amount and depth outside range', () => {
+ expect(() => emboss({amount: -0.1})).toThrow('"amount" must be >= 0');
+ expect(() => emboss({amount: 1.1})).toThrow('"amount" must be <= 1');
+ expect(() => emboss({depth: -0.1})).toThrow('"depth" must be >= 0');
+ expect(() => emboss({depth: 1.1})).toThrow('"depth" must be <= 1');
+});
+
+test('emboss() rejects non-positive size and lineWidth', () => {
+ expect(() => emboss({size: 0})).toThrow('"size" must be greater than 0');
+ expect(() => emboss({lineWidth: 0})).toThrow(
+ '"lineWidth" must be greater than 0',
+ );
+});
+
+test('emboss() parameters produce distinct effect keys', () => {
+ const defaults = emboss();
+ const subtle = emboss({amount: 0.3});
+ const larger = emboss({size: 40});
+ const wider = emboss({lineWidth: 12});
+ const deeper = emboss({depth: 1});
+ const angled = emboss({angle: 30});
+ const relit = emboss({lightAngle: 45});
+ const shifted = emboss({offset: 16});
+
+ expect(
+ new Set([
+ defaults.effectKey,
+ subtle.effectKey,
+ larger.effectKey,
+ wider.effectKey,
+ deeper.effectKey,
+ angled.effectKey,
+ relit.effectKey,
+ shifted.effectKey,
+ ]).size,
+ ).toBe(8);
+});
+
test('noiseDisplacement() accepts required params', () => {
expect(() =>
noiseDisplacement({
diff --git a/packages/skills/skills/remotion/SKILL.md b/packages/skills/skills/remotion/SKILL.md
index 5f0bfaeb39..ce35bb28c0 100644
--- a/packages/skills/skills/remotion/SKILL.md
+++ b/packages/skills/skills/remotion/SKILL.md
@@ -260,7 +260,7 @@ When creating a visual effect, prefer: 1. normal Remotion/HTML/CSS/SVG/filter/bl
For light leak overlays, see [rules/light-leaks.md](rules/light-leaks.md). Docs: https://www.remotion.dev/docs/effects
-Available effects: `brightness()`, `contrast()`, `colorKey()`, `duotone()`, `grayscale()`, `hue()`, `invert()`, `saturation()`, `tint()`, `thermalVision()`, `blur()`, `linearProgressiveBlur()`, `dropShadow()`, `glow()`, `evolve()`, `mirror()`, `scale()`, `uvTranslate()`, `xyTranslate()`, `barrelDistortion()`, `chromaticAberration()`, `fisheye()`, `wave()`, `burlap()`, `dotGrid()`, `halftone()`, `noise()`, `noiseDisplacement()`, `pattern()`, `pixelate()`, `pixelDissolve()`, `scanlines()`, `speckle()`, `shine()`, `shrinkwrap()`, `vignette()`, `contourLines()`, `halftoneLinearGradient()`, `whiteNoise()`, `tvSignalOff()`, `lines()`, `rings()`, `waves()`, `zigzag()`, `lightLeak()`, `starburst()`.
+Available effects: `brightness()`, `contrast()`, `colorKey()`, `duotone()`, `grayscale()`, `hue()`, `invert()`, `saturation()`, `tint()`, `thermalVision()`, `blur()`, `linearProgressiveBlur()`, `dropShadow()`, `glow()`, `evolve()`, `mirror()`, `scale()`, `uvTranslate()`, `xyTranslate()`, `barrelDistortion()`, `chromaticAberration()`, `fisheye()`, `wave()`, `burlap()`, `emboss()`, `dotGrid()`, `halftone()`, `noise()`, `noiseDisplacement()`, `pattern()`, `pixelate()`, `pixelDissolve()`, `scanlines()`, `speckle()`, `shine()`, `shrinkwrap()`, `vignette()`, `contourLines()`, `halftoneLinearGradient()`, `whiteNoise()`, `tvSignalOff()`, `lines()`, `rings()`, `waves()`, `zigzag()`, `lightLeak()`, `starburst()`.
## 3D content
diff --git a/packages/studio-shared/src/effect-catalog.ts b/packages/studio-shared/src/effect-catalog.ts
index 5fc423ac44..771bc3c996 100644
--- a/packages/studio-shared/src/effect-catalog.ts
+++ b/packages/studio-shared/src/effect-catalog.ts
@@ -351,6 +351,17 @@ export const EFFECT_CATALOG: readonly EffectCatalogItem[] = [
config: {},
},
},
+ {
+ id: 'effects-emboss',
+ category: 'Stylize',
+ label: 'emboss()',
+ description: 'Procedural raised-line relief',
+ effect: {
+ name: 'emboss',
+ importPath: '@remotion/effects/emboss',
+ config: {},
+ },
+ },
{
id: 'effects-dot-grid',
category: 'Stylize',