Skip to content

🎥 Make videos programmatically with React

`@remotion/effects`: Add shadows and highlights effect (#10299)

Jonny Burger4d7f32fbe1d7
diff --git a/packages/docs/components/effects-demos/registry.ts b/packages/docs/components/effects-demos/registry.ts
index 29605ed51e..2d130648f6 100644
--- a/packages/docs/components/effects-demos/registry.ts
+++ b/packages/docs/components/effects-demos/registry.ts
@@ -47,6 +47,7 @@ import {roughenEdges} from '@remotion/effects/roughen-edges';
import {saturation} from '@remotion/effects/saturation';
import {scale} from '@remotion/effects/scale';
import {scanlines} from '@remotion/effects/scanlines';
+import {shadowsHighlights} from '@remotion/effects/shadows-highlights';
import {shine} from '@remotion/effects/shine';
import {shrinkwrap} from '@remotion/effects/shrinkwrap';
import {skew} from '@remotion/effects/skew';
@@ -130,6 +131,7 @@ import {EffectsRoughenEdgesPreview} from '../effects/effects-roughen-edges-previ
import {EffectsSaturationPreview} from '../effects/effects-saturation-preview';
import {EffectsScalePreview} from '../effects/effects-scale-preview';
import {EffectsScanlinesPreview} from '../effects/effects-scanlines-preview';
+import {EffectsShadowsHighlightsPreview} from '../effects/effects-shadows-highlights-preview';
import {EffectsShinePreview} from '../effects/effects-shine-preview';
import {
EffectsShrinkwrapPreview,
@@ -336,6 +338,14 @@ export const effectsDemos: EffectsDemoType[] = [
comp: EffectsSaturationPreview,
schema: saturation().definition.schema,
},
+ {
+ ...defaults,
+ id: 'effects-shadows-highlights',
+ effectName: 'shadowsHighlights',
+ effectImportPath: '@remotion/effects/shadows-highlights',
+ comp: EffectsShadowsHighlightsPreview,
+ schema: shadowsHighlights().definition.schema,
+ },
{
...defaults,
id: 'effects-tint',
diff --git a/packages/docs/components/effects/effects-shadows-highlights-preview.tsx b/packages/docs/components/effects/effects-shadows-highlights-preview.tsx
new file mode 100644
index 0000000000..3693d6c5f2
--- /dev/null
+++ b/packages/docs/components/effects/effects-shadows-highlights-preview.tsx
@@ -0,0 +1,19 @@
+import {shadowsHighlights} from '@remotion/effects/shadows-highlights';
+import React from 'react';
+import {CanvasImage} from 'remotion';
+import {EFFECTS_PREVIEW_IMAGE_SRC} from './effects-preview-image';
+
+export const EffectsShadowsHighlightsPreview: React.FC<{
+ readonly shadows: number;
+ readonly highlights: number;
+}> = ({shadows, highlights}) => {
+ return (
+ <CanvasImage
+ src={EFFECTS_PREVIEW_IMAGE_SRC}
+ width={1280}
+ height={720}
+ fit="cover"
+ effects={[shadowsHighlights({shadows, highlights})]}
+ />
+ );
+};
diff --git a/packages/docs/docs/effects/shadows-highlights.mdx b/packages/docs/docs/effects/shadows-highlights.mdx
new file mode 100644
index 0000000000..ee0944c699
--- /dev/null
+++ b/packages/docs/docs/effects/shadows-highlights.mdx
@@ -0,0 +1,67 @@
+---
+image: /generated/articles-docs-effects-shadows-highlights.png
+slug: /effects/shadows-highlights
+title: shadowsHighlights()
+sidebar_label: shadowsHighlights()
+crumb: '@remotion/effects'
+---
+
+# shadowsHighlights()<AvailableFrom v="4.0.508" />
+
+_Part of the [`@remotion/effects`](/docs/effects/api) package._
+
+Adjusts dark and bright tonal regions independently while preserving hue.
+
+## Preview
+
+<EffectsDemo type="effects-shadows-highlights" />
+
+## Example
+
+```tsx twoslash title="MyComp.tsx"
+import {Video} from '@remotion/media';
+import {shadowsHighlights} from '@remotion/effects/shadows-highlights';
+
+export const MyComp: React.FC = () => {
+ return (
+ <Video
+ src="https://remotion.media/video.mp4"
+ effects={[
+ shadowsHighlights({
+ shadows: 0.2,
+ highlights: -0.15,
+ }),
+ ]}
+ />
+ );
+};
+```
+
+## API
+
+You can call `shadowsHighlights()` without arguments or pass an object with the following properties.
+
+### `shadows?`
+
+The shadow adjustment from `-1` to `1`. Positive values lift dark regions by up to one stop, and negative values suppress them. Defaults to `0`.
+
+### `highlights?`
+
+The highlight adjustment from `-1` to `1`. Positive values brighten light regions by up to one stop, and negative values recover them. Defaults to `0`.
+
+The effect uses overlapping smooth tonal weights derived from unpremultiplied sRGB luminance. It applies the resulting exposure gain in linear light, without a spatial filter that could create halos.
+
+### `disabled?`
+
+When `true`, the effect is skipped. Defaults to `false`.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox safari nodejs="" bun="" serverlessFunctions="" clientSideRendering serverSideRendering player studio hideServers />
+
+## See also
+
+- [`@remotion/effects`](/docs/effects/api)
+- [`exposure()`](/docs/effects/exposure)
+- [`levels()`](/docs/effects/levels)
+- [Source code for this effect](https://github.com/remotion-dev/remotion/blob/main/packages/effects/src/shadows-highlights.ts)
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index d1bded965b..c1346034c8 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -322,6 +322,7 @@ const sidebars: SidebarsConfig = {
'effects/saturation',
'effects/scale',
'effects/scanlines',
+ 'effects/shadows-highlights',
'effects/shine',
'effects/shrinkwrap',
'effects/skew',
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 10568e84b6..5e33c2745a 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -2258,6 +2258,15 @@ export const articles = [
noAi: false,
slug: 'effects/scanlines',
},
+ {
+ id: 'effects/shadows-highlights',
+ title: 'shadowsHighlights()',
+ relativePath: 'docs/effects/shadows-highlights.mdx',
+ compId: 'articles-docs-effects-shadows-highlights',
+ crumb: '@remotion/effects',
+ noAi: false,
+ slug: 'effects/shadows-highlights',
+ },
{
id: 'effects/shine',
title: 'shine()',
diff --git a/packages/docs/src/remotion/Root.tsx b/packages/docs/src/remotion/Root.tsx
index 9a6fdbfb7f..8c4e8d278b 100644
--- a/packages/docs/src/remotion/Root.tsx
+++ b/packages/docs/src/remotion/Root.tsx
@@ -75,6 +75,7 @@ import {
import {EffectsSaturationPreview} from '../../components/effects/effects-saturation-preview';
import {EffectsScalePreview} from '../../components/effects/effects-scale-preview';
import {EffectsScanlinesPreview} from '../../components/effects/effects-scanlines-preview';
+import {EffectsShadowsHighlightsPreview} from '../../components/effects/effects-shadows-highlights-preview';
import {EffectsShinePreview} from '../../components/effects/effects-shine-preview';
import {
EffectsShrinkwrapPreview,
@@ -299,6 +300,13 @@ export const RemotionRoot: React.FC = () => {
height={720}
defaultProps={{blackPoint: 0.1, whitePoint: 0.9, gamma: 1.4}}
/>
+ <Still
+ id="effects-shadows-highlights-preview"
+ component={EffectsShadowsHighlightsPreview}
+ width={1280}
+ height={720}
+ defaultProps={{shadows: 0.8, highlights: -0.5}}
+ />
<Still
id="effects-white-balance-preview"
component={EffectsWhiteBalancePreview}
diff --git a/packages/docs/static/generated/articles-docs-effects-shadows-highlights.png b/packages/docs/static/generated/articles-docs-effects-shadows-highlights.png
new file mode 100644
index 0000000000..2aa807756e
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-effects-shadows-highlights.png differ
diff --git a/packages/docs/static/img/effects-shadows-highlights-preview.png b/packages/docs/static/img/effects-shadows-highlights-preview.png
new file mode 100644
index 0000000000..d336b09787
Binary files /dev/null and b/packages/docs/static/img/effects-shadows-highlights-preview.png differ
diff --git a/packages/effects/bundle.ts b/packages/effects/bundle.ts
index 93c5b2c57a..ce9c55cabc 100644
--- a/packages/effects/bundle.ts
+++ b/packages/effects/bundle.ts
@@ -56,6 +56,7 @@ const effectEntrypoints = [
'src/saturation.ts',
'src/scanlines.ts',
'src/scale.ts',
+ 'src/shadows-highlights.ts',
'src/shine.ts',
'src/shrinkwrap.ts',
'src/skew.ts',
diff --git a/packages/effects/package.json b/packages/effects/package.json
index fee90c9bca..90f997c53a 100644
--- a/packages/effects/package.json
+++ b/packages/effects/package.json
@@ -279,6 +279,11 @@
"module": "./dist/esm/scale.mjs",
"import": "./dist/esm/scale.mjs"
},
+ "./shadows-highlights": {
+ "types": "./dist/shadows-highlights.d.ts",
+ "module": "./dist/esm/shadows-highlights.mjs",
+ "import": "./dist/esm/shadows-highlights.mjs"
+ },
"./shine": {
"types": "./dist/shine.d.ts",
"module": "./dist/esm/shine.mjs",
@@ -520,6 +525,9 @@
"scale": [
"dist/scale.d.ts"
],
+ "shadows-highlights": [
+ "dist/shadows-highlights.d.ts"
+ ],
"shine": [
"dist/shine.d.ts"
],
diff --git a/packages/effects/src/shadows-highlights.ts b/packages/effects/src/shadows-highlights.ts
new file mode 100644
index 0000000000..4ee49f165d
--- /dev/null
+++ b/packages/effects/src/shadows-highlights.ts
@@ -0,0 +1,315 @@
+import type {InteractivitySchema} from 'remotion';
+import {Internals} from 'remotion';
+import {
+ assertOptionalFiniteNumber,
+ validateSignedUnitInterval,
+} from './color-utils.js';
+import {assertEffectParamsObject} from './validate-effect-param.js';
+
+const {createEffect, createWebGL2ContextError} = Internals;
+
+const DEFAULT_SHADOWS = 0 as const;
+const DEFAULT_HIGHLIGHTS = 0 as const;
+
+const shadowsHighlightsSchema = {
+ shadows: {
+ type: 'number',
+ min: -1,
+ max: 1,
+ step: 0.01,
+ default: DEFAULT_SHADOWS,
+ description: 'Shadows',
+ hiddenFromList: false,
+ },
+ highlights: {
+ type: 'number',
+ min: -1,
+ max: 1,
+ step: 0.01,
+ default: DEFAULT_HIGHLIGHTS,
+ description: 'Highlights',
+ hiddenFromList: false,
+ },
+} as const satisfies InteractivitySchema;
+
+export type ShadowsHighlightsParams = {
+ /** Shadow adjustment from `-1` to `1`. Defaults to `0`. */
+ readonly shadows?: number;
+ /** Highlight adjustment from `-1` to `1`. Defaults to `0`. */
+ readonly highlights?: number;
+};
+
+type ShadowsHighlightsResolved = {
+ shadows: number;
+ highlights: number;
+};
+
+type ShadowsHighlightsState = {
+ readonly gl: WebGL2RenderingContext;
+ readonly program: WebGLProgram;
+ readonly vao: WebGLVertexArrayObject;
+ readonly vbo: WebGLBuffer;
+ readonly textureSource: WebGLTexture;
+ readonly uniforms: {
+ readonly uSource: WebGLUniformLocation | null;
+ readonly uShadows: WebGLUniformLocation | null;
+ readonly uHighlights: WebGLUniformLocation | null;
+ };
+};
+
+const resolve = (
+ params: ShadowsHighlightsParams,
+): ShadowsHighlightsResolved => ({
+ shadows: params.shadows ?? DEFAULT_SHADOWS,
+ highlights: params.highlights ?? DEFAULT_HIGHLIGHTS,
+});
+
+const validateShadowsHighlightsParams = (
+ params: ShadowsHighlightsParams,
+): void => {
+ assertEffectParamsObject(params, 'Shadows and highlights');
+ assertOptionalFiniteNumber(params.shadows, 'shadows');
+ assertOptionalFiniteNumber(params.highlights, 'highlights');
+
+ const {shadows, highlights} = resolve(params);
+ validateSignedUnitInterval(shadows, 'shadows');
+ validateSignedUnitInterval(highlights, 'highlights');
+};
+
+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 FRAGMENT_SHADER = /* glsl */ `#version 300 es
+precision highp float;
+
+in vec2 vUv;
+out vec4 fragColor;
+
+uniform sampler2D uSource;
+uniform float uShadows;
+uniform float uHighlights;
+
+vec3 srgbToLinear(vec3 color) {
+ vec3 lower = color / 12.92;
+ vec3 upper = pow((color + 0.055) / 1.055, vec3(2.4));
+ return mix(lower, upper, step(vec3(0.04045), color));
+}
+
+vec3 linearToSrgb(vec3 color) {
+ vec3 nonNegative = max(color, vec3(0.0));
+ vec3 lower = nonNegative * 12.92;
+ vec3 upper = 1.055 * pow(nonNegative, vec3(1.0 / 2.4)) - 0.055;
+ return mix(lower, upper, step(vec3(0.0031308), nonNegative));
+}
+
+void main() {
+ vec4 sourceColor = texture(uSource, vUv);
+ float alpha = sourceColor.a;
+
+ if (alpha <= 0.0) {
+ fragColor = vec4(0.0);
+ return;
+ }
+
+ vec3 color = sourceColor.rgb / alpha;
+ float luminance = dot(color, vec3(0.2126, 0.7152, 0.0722));
+ float shadowWeight = 1.0 - smoothstep(0.0, 0.6, luminance);
+ float highlightWeight = smoothstep(0.4, 1.0, luminance);
+ shadowWeight *= shadowWeight;
+ highlightWeight *= highlightWeight;
+
+ float stops = uShadows * shadowWeight + uHighlights * highlightWeight;
+ vec3 linear = srgbToLinear(color);
+ vec3 adjusted = linear * exp2(stops);
+ vec3 corrected = linearToSrgb(adjusted);
+
+ fragColor = vec4(corrected * alpha, alpha);
+}
+`;
+
+const compileShader = (
+ gl: WebGL2RenderingContext,
+ type: number,
+ source: string,
+): WebGLShader => {
+ const shader = gl.createShader(type);
+ if (!shader) {
+ throw new Error('Failed to create shadows and highlights 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(
+ `Shadows and highlights shader compile failed: ${log ?? '(no log)'}`,
+ );
+ }
+
+ return shader;
+};
+
+const createProgram = (gl: WebGL2RenderingContext): WebGLProgram => {
+ const vertexShader = compileShader(gl, gl.VERTEX_SHADER, VERTEX_SHADER);
+ const fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, FRAGMENT_SHADER);
+ const program = gl.createProgram();
+ if (!program) {
+ throw new Error('Failed to create shadows and highlights shader 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(
+ `Shadows and highlights shader link failed: ${log ?? '(no log)'}`,
+ );
+ }
+
+ return program;
+};
+
+const createTexture = (gl: WebGL2RenderingContext): WebGLTexture => {
+ const texture = gl.createTexture();
+ if (!texture) {
+ throw new Error('Failed to create shadows and highlights 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 texture;
+};
+
+const setupShadowsHighlights = (
+ target: HTMLCanvasElement,
+): ShadowsHighlightsState => {
+ const gl = target.getContext('webgl2', {
+ premultipliedAlpha: true,
+ alpha: true,
+ preserveDrawingBuffer: true,
+ });
+ if (!gl) {
+ throw createWebGL2ContextError('shadows and highlights effect');
+ }
+
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
+
+ const program = createProgram(gl);
+ const vao = gl.createVertexArray();
+ if (!vao) {
+ throw new Error('Failed to create shadows and highlights vertex array');
+ }
+
+ const vbo = gl.createBuffer();
+ if (!vbo) {
+ throw new Error('Failed to create shadows and highlights vertex buffer');
+ }
+
+ 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);
+
+ return {
+ gl,
+ program,
+ vao,
+ vbo,
+ textureSource: createTexture(gl),
+ uniforms: {
+ uSource: gl.getUniformLocation(program, 'uSource'),
+ uShadows: gl.getUniformLocation(program, 'uShadows'),
+ uHighlights: gl.getUniformLocation(program, 'uHighlights'),
+ },
+ };
+};
+
+export const shadowsHighlights = createEffect<
+ ShadowsHighlightsParams,
+ ShadowsHighlightsState
+>({
+ type: 'remotion/shadows-highlights',
+ label: 'shadowsHighlights()',
+ documentationLink: 'https://www.remotion.dev/docs/effects/shadows-highlights',
+ backend: 'webgl2',
+ calculateKey: (params) => {
+ const {shadows, highlights} = resolve(params);
+ return `shadows-highlights-${shadows}-${highlights}`;
+ },
+ setup: setupShadowsHighlights,
+ apply: ({source, width, height, params, state, flipSourceY}) => {
+ const {shadows, highlights} = resolve(params);
+ const {gl, program, textureSource, uniforms, 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, textureSource);
+ 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 (uniforms.uSource) gl.uniform1i(uniforms.uSource, 0);
+
+ if (uniforms.uShadows) {
+ gl.uniform1f(uniforms.uShadows, shadows);
+ }
+
+ if (uniforms.uHighlights) {
+ gl.uniform1f(uniforms.uHighlights, highlights);
+ }
+
+ 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, textureSource}) => {
+ gl.deleteTexture(textureSource);
+ gl.deleteBuffer(vbo);
+ gl.deleteProgram(program);
+ gl.deleteVertexArray(vao);
+ },
+ schema: shadowsHighlightsSchema,
+ validateParams: validateShadowsHighlightsParams,
+});
diff --git a/packages/effects/src/test/effect-params.test.ts b/packages/effects/src/test/effect-params.test.ts
index 91ebe600dc..867fc1e9a6 100644
--- a/packages/effects/src/test/effect-params.test.ts
+++ b/packages/effects/src/test/effect-params.test.ts
@@ -55,6 +55,7 @@ import {roughenEdges} from '../roughen-edges.js';
import {saturation} from '../saturation.js';
import {scale} from '../scale.js';
import {scanlines} from '../scanlines.js';
+import {shadowsHighlights} from '../shadows-highlights.js';
import {shine} from '../shine.js';
import {shrinkwrap} from '../shrinkwrap.js';
import {skew} from '../skew.js';
@@ -175,6 +176,9 @@ test('@remotion/effects expose documentation links', () => {
expect(levels().definition.documentationLink).toBe(
'https://www.remotion.dev/docs/effects/levels',
);
+ expect(shadowsHighlights().definition.documentationLink).toBe(
+ 'https://www.remotion.dev/docs/effects/shadows-highlights',
+ );
expect(lines().definition.documentationLink).toBe(
'https://www.remotion.dev/docs/effects/lines',
);
@@ -333,6 +337,7 @@ test('@remotion/effects expose API names as Studio labels', () => {
expect(hue().definition.label).toBe('hue()');
expect(invert().definition.label).toBe('invert()');
expect(levels().definition.label).toBe('levels()');
+ expect(shadowsHighlights().definition.label).toBe('shadowsHighlights()');
expect(lines().definition.label).toBe('lines()');
expect(linearGradient().definition.label).toBe('linearGradient()');
expect(linearGradientTint().definition.label).toBe('linearGradientTint()');
@@ -1090,6 +1095,47 @@ test('levels() parameters produce distinct effect keys', () => {
).toBe(3);
});
+test('shadowsHighlights() accepts default params', () => {
+ expect(() => shadowsHighlights()).not.toThrow();
+});
+
+test('shadowsHighlights() rejects non-finite parameters', () => {
+ expect(() => shadowsHighlights({shadows: Number.NaN})).toThrow(
+ '"shadows" must be a finite number',
+ );
+ expect(() =>
+ shadowsHighlights({highlights: Number.POSITIVE_INFINITY}),
+ ).toThrow('"highlights" must be a finite number');
+});
+
+test('shadowsHighlights() rejects parameters outside the signed unit interval', () => {
+ expect(() => shadowsHighlights({shadows: -1.1})).toThrow(
+ '"shadows" must be >= -1',
+ );
+ expect(() => shadowsHighlights({shadows: 1.1})).toThrow(
+ '"shadows" must be <= 1',
+ );
+ expect(() => shadowsHighlights({highlights: -1.1})).toThrow(
+ '"highlights" must be >= -1',
+ );
+ expect(() => shadowsHighlights({highlights: 1.1})).toThrow(
+ '"highlights" must be <= 1',
+ );
+});
+
+test('shadowsHighlights() parameters produce distinct effect keys', () => {
+ const neutral = shadowsHighlights();
+ const liftedShadows = shadowsHighlights({shadows: 0.5});
+ const recoveredHighlights = shadowsHighlights({highlights: -0.5});
+ expect(
+ new Set([
+ neutral.effectKey,
+ liftedShadows.effectKey,
+ recoveredHighlights.effectKey,
+ ]).size,
+ ).toBe(3);
+});
+
test('contrast() accepts default params', () => {
expect(() => contrast()).not.toThrow();
});
diff --git a/packages/effects/src/visual-test/effects-visual.test.ts b/packages/effects/src/visual-test/effects-visual.test.ts
index cedb0eb2d9..276798919f 100644
--- a/packages/effects/src/visual-test/effects-visual.test.ts
+++ b/packages/effects/src/visual-test/effects-visual.test.ts
@@ -5,6 +5,7 @@ import {exposure} from '../exposure.js';
import {levels} from '../levels.js';
import {noise} from '../noise.js';
import {pixelDissolve} from '../pixel-dissolve.js';
+import {shadowsHighlights} from '../shadows-highlights.js';
import {vibrance} from '../vibrance.js';
import {vignette} from '../vignette.js';
import {whiteBalance} from '../white-balance.js';
@@ -217,6 +218,50 @@ test('levels() remaps endpoints and gamma while preserving alpha', async () => {
expect(pixels[11]).toBe(128);
});
+test('shadowsHighlights() targets dark and bright tones smoothly', async () => {
+ const source = document.createElement('canvas');
+ source.width = 3;
+ source.height = 1;
+ const sourceContext = source.getContext('2d');
+ if (!sourceContext) {
+ throw new Error('Could not get source context');
+ }
+
+ sourceContext.putImageData(
+ new ImageData(
+ new Uint8ClampedArray([
+ 64, 64, 64, 128, 128, 128, 128, 128, 224, 224, 224, 128,
+ ]),
+ 3,
+ 1,
+ ),
+ 0,
+ 0,
+ );
+
+ const canvas = await renderEffectChainToCanvas({
+ source,
+ width: 3,
+ height: 1,
+ effects: descriptorsToMemoizedEffects([
+ shadowsHighlights({shadows: 1, highlights: -1}),
+ ]),
+ });
+ const context = canvas.getContext('2d');
+ if (!context) {
+ throw new Error('Could not get output context');
+ }
+
+ const pixels = context.getImageData(0, 0, 3, 1).data;
+ expect(pixels[0]).toBeGreaterThan(64);
+ expect(pixels[4]).toBeGreaterThanOrEqual(126);
+ expect(pixels[4]).toBeLessThanOrEqual(130);
+ expect(pixels[8]).toBeLessThan(224);
+ expect(pixels[3]).toBe(128);
+ expect(pixels[7]).toBe(128);
+ expect(pixels[11]).toBe(128);
+});
+
test('vignette() color mode works on transparent sources', async () => {
const width = 40;
const height = 40;
diff --git a/packages/studio-shared/src/effect-catalog.ts b/packages/studio-shared/src/effect-catalog.ts
index aaf3a9549e..bcf786d930 100644
--- a/packages/studio-shared/src/effect-catalog.ts
+++ b/packages/studio-shared/src/effect-catalog.ts
@@ -173,6 +173,17 @@ export const EFFECT_CATALOG: readonly EffectCatalogItem[] = [
config: {},
},
},
+ {
+ id: 'effects-shadows-highlights',
+ category: 'Color',
+ label: 'shadowsHighlights()',
+ description: 'Recover dark and bright tonal regions',
+ effect: {
+ name: 'shadowsHighlights',
+ importPath: '@remotion/effects/shadows-highlights',
+ config: {},
+ },
+ },
{
id: 'effects-tint',
category: 'Color',