🎥 Make videos programmatically with React
`@remotion/effects`: Add glow effect (#7687)
Jonny Burgereabcc30e4a07
diff --git a/packages/docs/components/demos/index.tsx b/packages/docs/components/demos/index.tsxindex b25e0c7f50..51333a4b4d 100644--- a/packages/docs/components/demos/index.tsx+++ b/packages/docs/components/demos/index.tsx@@ -23,6 +23,7 @@ import {effectsChromaticAberrationDemo,effectsContrastDemo,effectsDuotoneDemo,+ effectsGlowDemo,effectsGrayscaleDemo,effectsHalftoneDemo,effectsHueDemo,@@ -91,6 +92,7 @@ const demos: DemoType[] = [effectsBrightnessDemo,effectsContrastDemo,effectsDuotoneDemo,+ effectsGlowDemo,effectsGrayscaleDemo,effectsHueDemo,effectsInvertDemo,diff --git a/packages/docs/components/demos/types.ts b/packages/docs/components/demos/types.tsindex db739dd5bd..f3c5e322e9 100644--- a/packages/docs/components/demos/types.ts+++ b/packages/docs/components/demos/types.ts@@ -5,6 +5,7 @@ import {EffectsBrightnessPreview} from '../effects/effects-brightness-preview';import {EffectsChromaticAberrationPreview} from '../effects/effects-chromatic-aberration-preview';import {EffectsContrastPreview} from '../effects/effects-contrast-preview';import {EffectsDuotonePreview} from '../effects/effects-duotone-preview';+import {EffectsGlowPreview} from '../effects/effects-glow-preview';import {EffectsGrayscalePreview} from '../effects/effects-grayscale-preview';import {EffectsHalftonePreview} from '../effects/effects-halftone-preview';import {EffectsHuePreview} from '../effects/effects-hue-preview';@@ -1535,6 +1536,53 @@ export const effectsDuotoneDemo: DemoType = {],};+export const effectsGlowDemo: DemoType = {+ comp: EffectsGlowPreview,+ compHeight: 720,+ compWidth: 1280,+ durationInFrames: 1,+ fps: 30,+ id: 'effects-glow',+ autoPlay: false,+ controls: false,+ logLevel: 'info',+ options: [+ {+ name: 'radius',+ type: 'numeric',+ min: 0,+ max: 100,+ step: 1,+ default: 28,+ optional: 'no',+ },+ {+ name: 'intensity',+ type: 'numeric',+ min: 0,+ max: 5,+ step: 0.1,+ default: 1.8,+ optional: 'no',+ },+ {+ name: 'threshold',+ type: 'numeric',+ min: 0,+ max: 1,+ step: 0.01,+ default: 0.25,+ optional: 'no',+ },+ {+ name: 'color',+ type: 'color',+ default: '#00d8ff',+ optional: 'no',+ },+ ],+};+export const effectsHueDemo: DemoType = {comp: EffectsHuePreview,compHeight: 720,diff --git a/packages/docs/components/effects/effects-duotone-preview.tsx b/packages/docs/components/effects/effects-duotone-preview.tsxindex e83f1355bc..30bcad5e90 100644--- a/packages/docs/components/effects/effects-duotone-preview.tsx+++ b/packages/docs/components/effects/effects-duotone-preview.tsx@@ -13,6 +13,7 @@ export const EffectsDuotonePreview: React.FC<{src={EFFECTS_PREVIEW_IMAGE_SRC}width={1280}height={720}+ fit="cover"effects={[duotone({darkColor, lightColor, threshold})]}/>);diff --git a/packages/docs/components/effects/effects-glow-preview.tsx b/packages/docs/components/effects/effects-glow-preview.tsxnew file mode 100644index 0000000000..0048311efe--- /dev/null+++ b/packages/docs/components/effects/effects-glow-preview.tsx@@ -0,0 +1,28 @@+import {glow} from '@remotion/effects/glow';+import React from 'react';+import {CanvasImage} from 'remotion';+import {EFFECTS_PREVIEW_IMAGE_SRC} from './effects-preview-image';++export const EffectsGlowPreview: React.FC<{+ readonly radius: number;+ readonly intensity: number;+ readonly threshold: number;+ readonly color: string;+}> = ({radius, intensity, threshold, color}) => {+ return (+ <CanvasImage+ src={EFFECTS_PREVIEW_IMAGE_SRC}+ width={1280}+ height={720}+ fit="cover"+ effects={[+ glow({+ radius,+ intensity,+ threshold,+ color,+ }),+ ]}+ />+ );+};diff --git a/packages/docs/docs/effects/glow.mdx b/packages/docs/docs/effects/glow.mdxnew file mode 100644index 0000000000..1f00637922--- /dev/null+++ b/packages/docs/docs/effects/glow.mdx@@ -0,0 +1,82 @@+---+image: /generated/articles-docs-effects-glow.png+slug: /effects/glow+title: glow()+sidebar_label: glow()+crumb: '@remotion/effects'+---++# glow()<AvailableFrom v="4.0.468" />++_Part of the [`@remotion/effects`](/docs/effects/api) package._++Adds a soft halo around bright parts of canvas-based components such as [`<Video>`](/docs/media/video), [`<HtmlInCanvas>`](/docs/remotion/html-in-canvas) and [`<Solid>`](/docs/solid).++Use it when an element should appear to emit light.++## Preview++<Demo type="effects-glow" />++## Example++```tsx twoslash title="MyComp.tsx"+import {AbsoluteFill} from 'remotion';+import {Video} from '@remotion/media';+import {glow} from '@remotion/effects/glow';++export const MyComp: React.FC = () => {+ return (+ <AbsoluteFill>+ <Video+ src="https://remotion.media/video.mp4"+ effects={[+ glow({+ radius: 24,+ intensity: 1.5,+ threshold: 0.35,+ color: '#00d8ff',+ }),+ ]}+ />+ </AbsoluteFill>+ );+};+```++## API++Pass an object with the following properties. You can also call `glow()` without arguments.++### `radius?`++Blur radius of the glow in pixels. Defaults to `20`. Must be at least `0`.++### `intensity?`++Brightness multiplier for the glow. Defaults to `1`. Must be at least `0`.++### `threshold?`++Luminance threshold from `0` to `1`. Defaults to `0`.++Pixels brighter than this value contribute to the glow. Increase it to glow only the brightest parts.++### `color?`++Color of the glow. Defaults to white.++### `disabled?`++When `true`, the effect is skipped. Defaults to `false`.++## Requirements++`glow()` uses a WebGL2 backend. During renders, enable WebGL via [`Config.setChromiumOpenGlRenderer()`](/docs/config#setchromiumopenglrenderer) (for example `'angle'`). See [Using WebGL during renders](/docs/remotion/html-in-canvas#using-webgl-during-renders).++## See also++- [`@remotion/effects`](/docs/effects/api)+- [`blur()`](/docs/effects/blur)+- [HTML-in-canvas guide](/docs/html-in-canvas)+- [Source code for this effect](https://github.com/remotion-dev/remotion/blob/main/packages/effects/src/glow/index.ts)diff --git a/packages/docs/docs/effects/table-of-contents.tsx b/packages/docs/docs/effects/table-of-contents.tsxindex e542ec8197..0bb0bb556a 100644--- a/packages/docs/docs/effects/table-of-contents.tsx+++ b/packages/docs/docs/effects/table-of-contents.tsx@@ -38,6 +38,13 @@ const categories: {name: 'duotone()',description: 'Two-color threshold effect',},+ {+ link: '/docs/effects/glow',+ preview: '/img/effects-glow-preview.jpg',+ alt: 'glow effect preview',+ name: 'glow()',+ description: 'Soft halo effect',+ },{link: '/docs/effects/grayscale',preview: '/img/effects-grayscale-preview.jpg',diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.tsindex 4d8307f08b..e551378683 100644--- a/packages/docs/sidebars.ts+++ b/packages/docs/sidebars.ts@@ -274,6 +274,7 @@ const sidebars: SidebarsConfig = {'effects/chromatic-aberration','effects/contrast','effects/duotone',+ 'effects/glow','effects/grayscale','effects/halftone','effects/hue',diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex f584e1ad70..c7dcf85abe 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -1772,6 +1772,15 @@ export const articles = [noAi: false,slug: 'effects/duotone',},+ {+ id: 'effects/glow',+ title: 'glow()',+ relativePath: 'docs/effects/glow.mdx',+ compId: 'articles-docs-effects-glow',+ crumb: '@remotion/effects',+ noAi: false,+ slug: 'effects/glow',+ },{id: 'effects/grayscale',title: 'grayscale()',diff --git a/packages/docs/static/generated/articles-docs-effects-glow.png b/packages/docs/static/generated/articles-docs-effects-glow.pngnew file mode 100644index 0000000000..03015a9aa0Binary files /dev/null and b/packages/docs/static/generated/articles-docs-effects-glow.png differdiff --git a/packages/docs/static/img/effects-duotone-preview.jpg b/packages/docs/static/img/effects-duotone-preview.jpgindex 4fa45213fd..c42c5b6aa0 100644Binary files a/packages/docs/static/img/effects-duotone-preview.jpg and b/packages/docs/static/img/effects-duotone-preview.jpg differdiff --git a/packages/docs/static/img/effects-glow-preview.jpg b/packages/docs/static/img/effects-glow-preview.jpgnew file mode 100644index 0000000000..edc6062644Binary files /dev/null and b/packages/docs/static/img/effects-glow-preview.jpg differdiff --git a/packages/effects/bundle.ts b/packages/effects/bundle.tsindex f0d84f006c..dd9ceea171 100644--- a/packages/effects/bundle.ts+++ b/packages/effects/bundle.ts@@ -13,6 +13,7 @@ const effectEntrypoints = ['src/brightness.ts','src/contrast.ts','src/duotone.ts',+ 'src/glow.ts','src/grayscale.ts','src/halftone.ts','src/hue.ts',diff --git a/packages/effects/package.json b/packages/effects/package.jsonindex f26d5c9360..7404ecaff6 100644--- a/packages/effects/package.json+++ b/packages/effects/package.json@@ -62,6 +62,11 @@"module": "./dist/esm/duotone.mjs","import": "./dist/esm/duotone.mjs"},+ "./glow": {+ "types": "./dist/glow.d.ts",+ "module": "./dist/esm/glow.mjs",+ "import": "./dist/esm/glow.mjs"+ },"./halftone": {"types": "./dist/halftone.d.ts","module": "./dist/esm/halftone.mjs",@@ -134,6 +139,9 @@"duotone": ["dist/duotone.d.ts"],+ "glow": [+ "dist/glow.d.ts"+ ],"halftone": ["dist/halftone.d.ts"],diff --git a/packages/effects/src/glow.ts b/packages/effects/src/glow.tsnew file mode 100644index 0000000000..84a144ce34--- /dev/null+++ b/packages/effects/src/glow.ts@@ -0,0 +1 @@+export {glow, type GlowParams} from './glow/index.js';diff --git a/packages/effects/src/glow/glow-runtime.ts b/packages/effects/src/glow/glow-runtime.tsnew file mode 100644index 0000000000..921eefcf87--- /dev/null+++ b/packages/effects/src/glow/glow-runtime.ts@@ -0,0 +1,424 @@+import {Internals} from 'remotion';+import type {ParsedColorRgba} from '../color-utils.js';+import {+ GLOW_BLUR_FS_HORIZONTAL,+ GLOW_BLUR_FS_VERTICAL,+ GLOW_COMPOSITE_FS,+ GLOW_EXTRACT_FS,+ GLOW_VS,+} from './glow-shaders.js';++const {createWebGL2ContextError} = Internals;++export type GlowState = {+ readonly gl: WebGL2RenderingContext;+ readonly programExtract: WebGLProgram;+ readonly programHorizontal: WebGLProgram;+ readonly programVertical: WebGLProgram;+ readonly programComposite: WebGLProgram;+ readonly vao: WebGLVertexArrayObject;+ readonly vbo: WebGLBuffer;+ readonly textureSource: WebGLTexture;+ readonly textureGlowA: WebGLTexture;+ readonly textureGlowB: WebGLTexture;+ readonly framebuffer: WebGLFramebuffer;+ readonly extract: {+ readonly uSource: WebGLUniformLocation | null;+ readonly uColor: WebGLUniformLocation | null;+ readonly uThreshold: WebGLUniformLocation | null;+ };+ readonly horizontal: {+ readonly uRadius: WebGLUniformLocation | null;+ readonly uTexelSize: WebGLUniformLocation | null;+ readonly uSource: WebGLUniformLocation | null;+ };+ readonly vertical: {+ readonly uRadius: WebGLUniformLocation | null;+ readonly uTexelSize: WebGLUniformLocation | null;+ readonly uSource: WebGLUniformLocation | null;+ };+ readonly composite: {+ readonly uSource: WebGLUniformLocation | null;+ readonly uGlow: WebGLUniformLocation | null;+ readonly uIntensity: WebGLUniformLocation | null;+ };+ readonly colorCtx: CanvasRenderingContext2D;+ cachedColorStr: string;+ cachedColorRgba: ParsedColorRgba;+};++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(`Glow 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(`Glow program link failed: ${log ?? '(no log)'}`);+ }++ return program;+};++const createProgram = (+ gl: WebGL2RenderingContext,+ vertexSource: string,+ fragmentSource: string,+): WebGLProgram => {+ const vs = compileShader(gl, gl.VERTEX_SHADER, vertexSource);+ const fs = compileShader(gl, gl.FRAGMENT_SHADER, fragmentSource);+ const program = linkProgram(gl, vs, fs);+ gl.deleteShader(vs);+ gl.deleteShader(fs);+ return program;+};++const createRgbaTexture = (gl: WebGL2RenderingContext): WebGLTexture => {+ 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 texture;+};++const getBlurUniforms = (+ gl: WebGL2RenderingContext,+ program: WebGLProgram,+): GlowState['horizontal'] => ({+ uRadius: gl.getUniformLocation(program, 'uRadius'),+ uTexelSize: gl.getUniformLocation(program, 'uTexelSize'),+ uSource: gl.getUniformLocation(program, 'uSource'),+});++export const setupGlow = (target: HTMLCanvasElement): GlowState => {+ const gl = target.getContext('webgl2', {+ premultipliedAlpha: true,+ alpha: true,+ preserveDrawingBuffer: true,+ });+ if (!gl) {+ throw createWebGL2ContextError('glow effect');+ }++ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);++ const programExtract = createProgram(gl, GLOW_VS, GLOW_EXTRACT_FS);+ const programHorizontal = createProgram(gl, GLOW_VS, GLOW_BLUR_FS_HORIZONTAL);+ const programVertical = createProgram(gl, GLOW_VS, GLOW_BLUR_FS_VERTICAL);+ const programComposite = createProgram(gl, GLOW_VS, GLOW_COMPOSITE_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);++ gl.enableVertexAttribArray(0);+ gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 16, 0);+ gl.enableVertexAttribArray(1);+ gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 16, 8);++ gl.bindVertexArray(null);++ const textureSource = createRgbaTexture(gl);+ const textureGlowA = createRgbaTexture(gl);+ const textureGlowB = createRgbaTexture(gl);++ const framebuffer = gl.createFramebuffer();+ if (!framebuffer) {+ throw new Error('Failed to create WebGL framebuffer');+ }++ 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,+ programExtract,+ programHorizontal,+ programVertical,+ programComposite,+ vao,+ vbo,+ textureSource,+ textureGlowA,+ textureGlowB,+ framebuffer,+ extract: {+ uSource: gl.getUniformLocation(programExtract, 'uSource'),+ uColor: gl.getUniformLocation(programExtract, 'uColor'),+ uThreshold: gl.getUniformLocation(programExtract, 'uThreshold'),+ },+ horizontal: getBlurUniforms(gl, programHorizontal),+ vertical: getBlurUniforms(gl, programVertical),+ composite: {+ uSource: gl.getUniformLocation(programComposite, 'uSource'),+ uGlow: gl.getUniformLocation(programComposite, 'uGlow'),+ uIntensity: gl.getUniformLocation(programComposite, 'uIntensity'),+ },+ colorCtx,+ cachedColorStr: '',+ cachedColorRgba: [255, 255, 255, 255],+ };+};++export const cleanupGlow = ({+ gl,+ programExtract,+ programHorizontal,+ programVertical,+ programComposite,+ vao,+ vbo,+ textureSource,+ textureGlowA,+ textureGlowB,+ framebuffer,+}: GlowState): void => {+ gl.deleteFramebuffer(framebuffer);+ gl.deleteTexture(textureSource);+ gl.deleteTexture(textureGlowA);+ gl.deleteTexture(textureGlowB);+ gl.deleteBuffer(vbo);+ gl.deleteProgram(programExtract);+ gl.deleteProgram(programHorizontal);+ gl.deleteProgram(programVertical);+ gl.deleteProgram(programComposite);+ gl.deleteVertexArray(vao);+};++const drawFullscreenQuad = (state: GlowState): void => {+ const {gl, vao} = state;+ gl.bindVertexArray(vao);+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);+ gl.bindVertexArray(null);+};++const setTextureSize = (+ gl: WebGL2RenderingContext,+ texture: WebGLTexture,+ width: number,+ height: number,+): void => {+ gl.bindTexture(gl.TEXTURE_2D, texture);+ gl.texImage2D(+ gl.TEXTURE_2D,+ 0,+ gl.RGBA,+ width,+ height,+ 0,+ gl.RGBA,+ gl.UNSIGNED_BYTE,+ null,+ );+};++const setFramebufferTexture = (+ gl: WebGL2RenderingContext,+ framebuffer: WebGLFramebuffer,+ texture: WebGLTexture,+): void => {+ gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);+ gl.framebufferTexture2D(+ gl.FRAMEBUFFER,+ gl.COLOR_ATTACHMENT0,+ gl.TEXTURE_2D,+ texture,+ 0,+ );+ const status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);+ if (status !== gl.FRAMEBUFFER_COMPLETE) {+ throw new Error(`Glow framebuffer incomplete: 0x${status.toString(16)}`);+ }+};++const setBlurUniforms = ({+ gl,+ uniforms,+ radius,+ width,+ height,+}: {+ readonly gl: WebGL2RenderingContext;+ readonly uniforms: GlowState['horizontal'];+ readonly radius: number;+ readonly width: number;+ readonly height: number;+}): void => {+ if (uniforms.uSource) gl.uniform1i(uniforms.uSource, 0);+ if (uniforms.uRadius) gl.uniform1f(uniforms.uRadius, radius);+ if (uniforms.uTexelSize)+ gl.uniform2f(uniforms.uTexelSize, 1 / width, 1 / height);+};++const normalizedColor = (+ color: ParsedColorRgba,+): readonly [number, number, number, number] => {+ return [color[0] / 255, color[1] / 255, color[2] / 255, color[3] / 255];+};++type ApplyGlowParams = {+ readonly state: GlowState;+ readonly source: CanvasImageSource;+ readonly width: number;+ readonly height: number;+ readonly radius: number;+ readonly intensity: number;+ readonly threshold: number;+ readonly color: ParsedColorRgba;+ readonly flipSourceY: boolean;+};++export const applyGlow = ({+ state,+ source,+ width,+ height,+ radius,+ intensity,+ threshold,+ color,+ flipSourceY,+}: ApplyGlowParams): void => {+ const {+ gl,+ textureSource,+ textureGlowA,+ textureGlowB,+ framebuffer,+ programExtract,+ programHorizontal,+ programVertical,+ programComposite,+ } = state;++ gl.viewport(0, 0, width, height);+ gl.clearColor(0, 0, 0, 0);++ 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,+ );+ setTextureSize(gl, textureGlowA, width, height);+ setTextureSize(gl, textureGlowB, width, height);++ const [r, g, b, a] = normalizedColor(color);++ setFramebufferTexture(gl, framebuffer, textureGlowA);+ gl.clear(gl.COLOR_BUFFER_BIT);+ gl.useProgram(programExtract);+ gl.activeTexture(gl.TEXTURE0);+ gl.bindTexture(gl.TEXTURE_2D, textureSource);+ if (state.extract.uSource) gl.uniform1i(state.extract.uSource, 0);+ if (state.extract.uColor) gl.uniform4f(state.extract.uColor, r, g, b, a);+ if (state.extract.uThreshold)+ gl.uniform1f(state.extract.uThreshold, threshold);+ drawFullscreenQuad(state);++ setFramebufferTexture(gl, framebuffer, textureGlowB);+ gl.clear(gl.COLOR_BUFFER_BIT);+ gl.useProgram(programHorizontal);+ gl.activeTexture(gl.TEXTURE0);+ gl.bindTexture(gl.TEXTURE_2D, textureGlowA);+ setBlurUniforms({+ gl,+ uniforms: state.horizontal,+ radius,+ width,+ height,+ });+ drawFullscreenQuad(state);++ setFramebufferTexture(gl, framebuffer, textureGlowA);+ gl.clear(gl.COLOR_BUFFER_BIT);+ gl.useProgram(programVertical);+ gl.activeTexture(gl.TEXTURE0);+ gl.bindTexture(gl.TEXTURE_2D, textureGlowB);+ setBlurUniforms({+ gl,+ uniforms: state.vertical,+ radius,+ width,+ height,+ });+ drawFullscreenQuad(state);++ gl.bindFramebuffer(gl.FRAMEBUFFER, null);+ gl.clear(gl.COLOR_BUFFER_BIT);+ gl.useProgram(programComposite);+ gl.activeTexture(gl.TEXTURE0);+ gl.bindTexture(gl.TEXTURE_2D, textureSource);+ gl.activeTexture(gl.TEXTURE1);+ gl.bindTexture(gl.TEXTURE_2D, textureGlowA);+ if (state.composite.uSource) gl.uniform1i(state.composite.uSource, 0);+ if (state.composite.uGlow) gl.uniform1i(state.composite.uGlow, 1);+ if (state.composite.uIntensity)+ gl.uniform1f(state.composite.uIntensity, intensity);+ drawFullscreenQuad(state);++ gl.bindTexture(gl.TEXTURE_2D, null);+ gl.useProgram(null);+};diff --git a/packages/effects/src/glow/glow-shaders.ts b/packages/effects/src/glow/glow-shaders.tsnew file mode 100644index 0000000000..fc8fe6640f--- /dev/null+++ b/packages/effects/src/glow/glow-shaders.ts@@ -0,0 +1,106 @@+export const GLOW_VS = /* glsl */ `#version 300 es+layout(location = 0) in vec2 aPos;+layout(location = 1) in vec2 aUv;+out vec2 vUv;++void main() {+ vUv = aUv;+ gl_Position = vec4(aPos, 0.0, 1.0);+}+`;++export const GLOW_EXTRACT_FS = /* glsl */ `#version 300 es+precision highp float;++in vec2 vUv;+out vec4 fragColor;++uniform sampler2D uSource;+uniform vec4 uColor;+uniform float uThreshold;++void main() {+ vec4 source = texture(uSource, vUv);+ float alpha = source.a;++ if (alpha <= 0.001) {+ fragColor = vec4(0.0);+ return;+ }++ vec3 rgb = source.rgb / alpha;+ float luminance = dot(rgb, vec3(0.299, 0.587, 0.114));+ float threshold = clamp(uThreshold, 0.0, 1.0);+ float contribution = threshold >= 1.0+ ? step(1.0, luminance)+ : clamp((luminance - threshold) / max(1.0 - threshold, 0.0001), 0.0, 1.0);+ float glowAlpha = alpha * contribution * uColor.a;++ fragColor = vec4(uColor.rgb * glowAlpha, glowAlpha);+}+`;++const buildBlurFs = (direction: 'horizontal' | 'vertical') => {+ const dirVec =+ direction === 'horizontal' ? 'vec2(1.0, 0.0)' : 'vec2(0.0, 1.0)';++ return /* glsl */ `#version 300 es+precision highp float;++in vec2 vUv;+out vec4 fragColor;++uniform sampler2D uSource;+uniform float uRadius;+uniform vec2 uTexelSize;++const int KERNEL_HALF = 4;+const vec2 DIRECTION = ${dirVec};++void main() {+ if (uRadius <= 0.0) {+ fragColor = texture(uSource, vUv);+ return;+ }++ float pixelStride = uRadius / float(KERNEL_HALF);+ float sigma = uRadius / 3.0;+ float twoSigmaSq = 2.0 * sigma * sigma;++ vec4 sum = vec4(0.0);+ float weightSum = 0.0;++ for (int i = -KERNEL_HALF; i <= KERNEL_HALF; ++i) {+ float offsetPx = float(i) * pixelStride;+ float w = exp(-(offsetPx * offsetPx) / twoSigmaSq);+ vec2 uv = vUv + DIRECTION * uTexelSize * offsetPx;+ sum += texture(uSource, uv) * w;+ weightSum += w;+ }++ fragColor = sum / weightSum;+}+`;+};++export const GLOW_BLUR_FS_HORIZONTAL = buildBlurFs('horizontal');+export const GLOW_BLUR_FS_VERTICAL = buildBlurFs('vertical');++export const GLOW_COMPOSITE_FS = /* glsl */ `#version 300 es+precision highp float;++in vec2 vUv;+out vec4 fragColor;++uniform sampler2D uSource;+uniform sampler2D uGlow;+uniform float uIntensity;++void main() {+ vec4 source = texture(uSource, vUv);+ vec4 glow = texture(uGlow, vUv) * max(uIntensity, 0.0);+ vec4 outColor = source + glow;++ fragColor = vec4(min(outColor.rgb, vec3(1.0)), min(outColor.a, 1.0));+}+`;diff --git a/packages/effects/src/glow/index.ts b/packages/effects/src/glow/index.tsnew file mode 100644index 0000000000..ca1ff0748c--- /dev/null+++ b/packages/effects/src/glow/index.ts@@ -0,0 +1,130 @@+import type {SequenceSchema} from 'remotion';+import {Internals} from 'remotion';+import {+ assertOptionalFiniteNumber,+ parseColorRgba,+ validateNonNegative,+ validateUnitInterval,+} from '../color-utils.js';+import {+ assertEffectParamsObject,+ assertOptionalColor,+} from '../validate-effect-param.js';+import {+ applyGlow,+ cleanupGlow,+ setupGlow,+ type GlowState,+} from './glow-runtime.js';++const {createEffect} = Internals;++const DEFAULT_RADIUS = 20 as const;+const DEFAULT_INTENSITY = 1 as const;+const DEFAULT_THRESHOLD = 0 as const;+const DEFAULT_COLOR = '#ffffff' as const;++const glowSchema = {+ radius: {+ type: 'number',+ min: 0,+ max: 100,+ step: 1,+ default: DEFAULT_RADIUS,+ description: 'Radius',+ },+ intensity: {+ type: 'number',+ min: 0,+ max: 5,+ step: 0.1,+ default: DEFAULT_INTENSITY,+ description: 'Intensity',+ },+ threshold: {+ type: 'number',+ min: 0,+ max: 1,+ step: 0.01,+ default: DEFAULT_THRESHOLD,+ description: 'Threshold',+ },+ color: {+ type: 'color',+ default: DEFAULT_COLOR,+ description: 'Color',+ },+} as const satisfies SequenceSchema;++export type GlowParams = {+ /** Blur radius of the glow in pixels. Defaults to `20`. */+ readonly radius?: number;+ /** Brightness multiplier for the glow. Defaults to `1`. */+ readonly intensity?: number;+ /** Luminance threshold from `0` to `1`. Defaults to `0`. */+ readonly threshold?: number;+ /** Color of the glow. Defaults to white. */+ readonly color?: string;+};++type GlowResolved = {+ readonly radius: number;+ readonly intensity: number;+ readonly threshold: number;+ readonly color: string;+};++const resolve = (p: GlowParams): GlowResolved => ({+ radius: p.radius ?? DEFAULT_RADIUS,+ intensity: p.intensity ?? DEFAULT_INTENSITY,+ threshold: p.threshold ?? DEFAULT_THRESHOLD,+ color: p.color ?? DEFAULT_COLOR,+});++const validateGlowParams = (params: GlowParams): void => {+ assertEffectParamsObject(params, 'Glow');+ assertOptionalFiniteNumber(params.radius, 'radius');+ assertOptionalFiniteNumber(params.intensity, 'intensity');+ assertOptionalFiniteNumber(params.threshold, 'threshold');+ assertOptionalColor(params.color, 'color');++ const r = resolve(params);+ validateNonNegative(r.radius, 'radius');+ validateNonNegative(r.intensity, 'intensity');+ validateUnitInterval(r.threshold, 'threshold');+};++export const glow = createEffect<GlowParams, GlowState>({+ type: 'remotion/glow',+ label: 'Glow',+ documentationLink: 'https://www.remotion.dev/docs/effects/glow',+ backend: 'webgl2',+ calculateKey: (params) => {+ const r = resolve(params);+ return `glow-${r.radius}-${r.intensity}-${r.threshold}-${r.color}`;+ },+ setup: (target) => setupGlow(target),+ apply: ({source, width, height, params, state, flipSourceY}) => {+ const r = resolve(params);++ if (state.cachedColorStr !== r.color) {+ state.cachedColorStr = r.color;+ state.cachedColorRgba = parseColorRgba(state.colorCtx, r.color);+ }++ applyGlow({+ state,+ source,+ width,+ height,+ radius: r.radius,+ intensity: r.intensity,+ threshold: r.threshold,+ color: state.cachedColorRgba,+ flipSourceY,+ });+ },+ cleanup: (state) => cleanupGlow(state),+ schema: glowSchema,+ validateParams: validateGlowParams,+});diff --git a/packages/effects/src/test/effect-params.test.ts b/packages/effects/src/test/effect-params.test.tsindex 903d322012..ca4e5dd53b 100644--- a/packages/effects/src/test/effect-params.test.ts+++ b/packages/effects/src/test/effect-params.test.ts@@ -5,6 +5,7 @@ import {brightness} from '../brightness.js';import {chromaticAberration} from '../chromatic-aberration/index.js';import {contrast} from '../contrast.js';import {duotone} from '../duotone.js';+import {glow} from '../glow/index.js';import {grayscale} from '../grayscale.js';import {halftone} from '../halftone.js';import {hue} from '../hue.js';@@ -35,6 +36,9 @@ test('@remotion/effects expose documentation links', () => {expect(duotone().definition.documentationLink).toBe('https://www.remotion.dev/docs/effects/duotone',);+ expect(glow().definition.documentationLink).toBe(+ 'https://www.remotion.dev/docs/effects/glow',+ );expect(grayscale().definition.documentationLink).toBe('https://www.remotion.dev/docs/effects/grayscale',);@@ -380,6 +384,73 @@ test('duotone() parameters produce distinct effect keys', () => {).toBe(3);});+test('glow() accepts default params', () => {+ expect(() => glow()).not.toThrow();+});++test('glow() accepts valid params', () => {+ expect(() =>+ glow({+ radius: 30,+ intensity: 1.5,+ threshold: 0.4,+ color: '#00ffff',+ }),+ ).not.toThrow();+});++test('glow() rejects non-finite radius', () => {+ expect(() => glow({radius: Number.NaN})).toThrow(+ '"radius" must be a finite number',+ );+});++test('glow() rejects negative radius', () => {+ expect(() => glow({radius: -1})).toThrow('"radius" must be >= 0');+});++test('glow() rejects non-finite intensity', () => {+ expect(() => glow({intensity: Number.NaN})).toThrow(+ '"intensity" must be a finite number',+ );+});++test('glow() rejects negative intensity', () => {+ expect(() => glow({intensity: -0.1})).toThrow('"intensity" must be >= 0');+});++test('glow() rejects threshold below range', () => {+ expect(() => glow({threshold: -0.1})).toThrow('"threshold" must be >= 0');+});++test('glow() rejects threshold above range', () => {+ expect(() => glow({threshold: 1.1})).toThrow('"threshold" must be <= 1');+});++test('glow() rejects empty color strings', () => {+ expect(() => glow({color: ''})).toThrow(+ '"color" must be a non-empty string, but got ""',+ );+});++test('glow() parameters produce distinct effect keys', () => {+ const defaultGlow = glow();+ const widerGlow = glow({radius: 40});+ const strongerGlow = glow({intensity: 2});+ const thresholdGlow = glow({threshold: 0.5});+ const coloredGlow = glow({color: '#00ffff'});++ expect(+ new Set([+ defaultGlow.effectKey,+ widerGlow.effectKey,+ strongerGlow.effectKey,+ thresholdGlow.effectKey,+ coloredGlow.effectKey,+ ]).size,+ ).toBe(5);+});+test('halftone() accepts default params', () => {expect(() => halftone()).not.toThrow();});