🎥 Make videos programmatically with React
`@remotion/effects`: Add scanlines effect (#7758)
Igor Samokhovets89800709de09
diff --git a/packages/docs/components/demos/index.tsx b/packages/docs/components/demos/index.tsxindex c765f556aa..0c8724ad91 100644--- a/packages/docs/components/demos/index.tsx+++ b/packages/docs/components/demos/index.tsx@@ -35,6 +35,7 @@ import {effectsMirrorDemo,effectsNoiseDemo,effectsSaturationDemo,+ effectsScanlinesDemo,effectsScaleDemo,effectsShineDemo,effectsSpeckleDemo,@@ -112,6 +113,7 @@ const demos: DemoType[] = [effectsSpeckleDemo,effectsMirrorDemo,effectsNoiseDemo,+ effectsScanlinesDemo,effectsScaleDemo,effectsXyTranslateDemo,effectsUvTranslateDemo,diff --git a/packages/docs/components/demos/types.ts b/packages/docs/components/demos/types.tsindex 141e75aef1..9097d7f770 100644--- a/packages/docs/components/demos/types.ts+++ b/packages/docs/components/demos/types.ts@@ -18,6 +18,7 @@ import {EffectsMirrorPreview} from '../effects/effects-mirror-preview';import {EffectsNoisePreview} from '../effects/effects-noise-preview';import {EffectsSaturationPreview} from '../effects/effects-saturation-preview';import {EffectsScalePreview} from '../effects/effects-scale-preview';+import {EffectsScanlinesPreview} from '../effects/effects-scanlines-preview';import {EffectsShinePreview} from '../effects/effects-shine-preview';import {EffectsSpecklePreview} from '../effects/effects-speckle-preview';import {EffectsStarburstPreview} from '../effects/effects-starburst-preview';@@ -2058,6 +2059,62 @@ export const effectsNoiseDemo: DemoType = {],};+export const effectsScanlinesDemo: DemoType = {+ comp: EffectsScanlinesPreview,+ compHeight: 720,+ compWidth: 1280,+ durationInFrames: 1,+ fps: 30,+ id: 'effects-scanlines',+ autoPlay: false,+ controls: false,+ logLevel: 'info',+ options: [+ {+ name: 'amount',+ type: 'numeric',+ min: 0,+ max: 1,+ step: 0.01,+ default: 0.6,+ optional: 'no',+ },+ {+ name: 'spacing',+ type: 'numeric',+ min: 0.1,+ max: 40,+ step: 0.1,+ default: 8,+ optional: 'no',+ },+ {+ name: 'thickness',+ type: 'numeric',+ min: 0,+ max: 20,+ step: 0.1,+ default: 2,+ optional: 'no',+ },+ {+ name: 'offset',+ type: 'numeric',+ min: -40,+ max: 40,+ step: 0.1,+ default: 0,+ optional: 'no',+ },+ {+ name: 'premultiply',+ type: 'boolean',+ default: false,+ optional: 'no',+ },+ ],+};+export const effectsVignetteDemo: DemoType = {comp: EffectsVignettePreview,compHeight: 720,diff --git a/packages/docs/components/effects/effects-scanlines-preview.tsx b/packages/docs/components/effects/effects-scanlines-preview.tsxnew file mode 100644index 0000000000..544ae7f59c--- /dev/null+++ b/packages/docs/components/effects/effects-scanlines-preview.tsx@@ -0,0 +1,22 @@+import {scanlines} from '@remotion/effects/scanlines';+import React from 'react';+import {CanvasImage} from 'remotion';+import {EFFECTS_PREVIEW_IMAGE_SRC} from './effects-preview-image';++export const EffectsScanlinesPreview: React.FC<{+ readonly amount: number;+ readonly spacing: number;+ readonly thickness: number;+ readonly offset: number;+ readonly premultiply: boolean;+}> = ({amount, spacing, thickness, offset, premultiply}) => {+ return (+ <CanvasImage+ src={EFFECTS_PREVIEW_IMAGE_SRC}+ width={1280}+ height={720}+ fit="cover"+ effects={[scanlines({amount, spacing, thickness, offset, premultiply})]}+ />+ );+};diff --git a/packages/docs/docs/effects/scanlines.mdx b/packages/docs/docs/effects/scanlines.mdxnew file mode 100644index 0000000000..90cf2d7c90--- /dev/null+++ b/packages/docs/docs/effects/scanlines.mdx@@ -0,0 +1,96 @@+---+image: /generated/articles-docs-effects-scanlines.png+slug: /effects/scanlines+title: scanlines()+sidebar_label: scanlines()+crumb: '@remotion/effects'+---++# scanlines()<AvailableFrom v="4.0.469" />++_Part of the [`@remotion/effects`](/docs/effects/api) package._++Adds horizontal scanlines to canvas-based components such as [`<Video>`](/docs/media/video), [`<HtmlInCanvas>`](/docs/remotion/html-in-canvas) and [`<Solid>`](/docs/solid).++The effect is additive and preserves the source alpha mask. Transparent regions stay transparent.++## Preview++<Demo type="effects-scanlines" />++## Example++```tsx twoslash title="MyComp.tsx"+import {scanlines} from '@remotion/effects/scanlines';+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={[+ scanlines({+ amount: 0.25,+ spacing: 4,+ thickness: 1,+ offset: frame * 0.5,+ }),+ ]}+ />+ </AbsoluteFill>+ );+};+```++## API++Pass an object with the following properties. You can also call `scanlines()` without arguments.++### `amount?`++Strength from `0` to `1`. Defaults to `0.15`.++Use `0` to leave the layer unchanged.++### `spacing?`++Distance between scanlines in pixels. Defaults to `4`.++A lower value creates denser scanlines. A higher value creates wider gaps.++### `thickness?`++Height of each scanline in pixels. Defaults to `1`.++A value greater than `spacing` is clamped to the spacing.++### `offset?`++Vertical offset in pixels. Defaults to `0`.++Animate this value with [`useCurrentFrame()`](/docs/use-current-frame) to scroll the scanlines.++### `premultiply?`++Whether the scanline contribution is multiplied with the input colors before being added. Defaults to `false`.++Set to `true` for a subtler effect that follows the source brightness more closely.++### `disabled?`++When `true`, the effect is skipped. Defaults to `false`.++## Requirements++`scanlines()` 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)+- [`noise()`](/docs/effects/noise)+- [`speckle()`](/docs/effects/speckle)+- [Source code for this effect](https://github.com/remotion-dev/remotion/blob/main/packages/effects/src/scanlines.ts)diff --git a/packages/docs/docs/effects/table-of-contents.tsx b/packages/docs/docs/effects/table-of-contents.tsxindex d121e71aff..3bcdf5e269 100644--- a/packages/docs/docs/effects/table-of-contents.tsx+++ b/packages/docs/docs/effects/table-of-contents.tsx@@ -31,13 +31,6 @@ const categories: {name: 'contrast()',description: 'Contrast adjustment effect',},- {- link: '/docs/effects/duotone',- preview: '/img/effects-duotone-preview.png',- alt: 'duotone effect preview',- name: 'duotone()',- description: 'Two-color threshold effect',- },{link: '/docs/effects/drop-shadow',preview: '/img/effects-drop-shadow-preview.png',@@ -45,6 +38,13 @@ const categories: {name: 'dropShadow()',description: 'Blurred alpha shadow effect',},+ {+ link: '/docs/effects/duotone',+ preview: '/img/effects-duotone-preview.png',+ alt: 'duotone effect preview',+ name: 'duotone()',+ description: 'Two-color threshold effect',+ },{link: '/docs/effects/glow',preview: '/img/effects-glow-preview.png',@@ -113,13 +113,6 @@ const categories: {name: 'scale()',description: 'Scale transform effect',},- {- link: '/docs/effects/xy-translate',- preview: '/img/effects-xy-translate-preview.png',- alt: 'XY translate effect preview',- name: 'xyTranslate()',- description: 'Pixel-based translate effect',- },{link: '/docs/effects/uv-translate',preview: '/img/effects-uv-translate-preview.png',@@ -127,6 +120,13 @@ const categories: {name: 'uvTranslate()',description: 'UV-based translate effect',},+ {+ link: '/docs/effects/xy-translate',+ preview: '/img/effects-xy-translate-preview.png',+ alt: 'XY translate effect preview',+ name: 'xyTranslate()',+ description: 'Pixel-based translate effect',+ },],},{@@ -139,13 +139,6 @@ const categories: {name: 'barrelDistortion()',description: 'Barrel distortion effect',},- {- link: '/docs/effects/chromatic-aberration',- preview: '/img/effects-chromatic-aberration-preview.png',- alt: 'chromatic aberration effect preview',- name: 'chromaticAberration()',- description: 'RGB channel split effect',- },{link: '/docs/effects/blur',preview: '/img/effects-blur-preview.png',@@ -153,6 +146,13 @@ const categories: {name: 'blur()',description: 'Gaussian blur effect',},+ {+ link: '/docs/effects/chromatic-aberration',+ preview: '/img/effects-chromatic-aberration-preview.png',+ alt: 'chromatic aberration effect preview',+ name: 'chromaticAberration()',+ description: 'RGB channel split effect',+ },{link: '/docs/effects/wave',preview: '/img/effects-wave-preview.png',@@ -165,6 +165,13 @@ const categories: {{title: 'Generative',effects: [+ {+ link: '/docs/effects/dot-grid',+ preview: '/img/effects-dot-grid-preview.png',+ alt: 'dot grid effect preview',+ name: 'dotGrid()',+ description: 'Source-color dot mask effect',+ },{link: '/docs/effects/halftone',preview: '/img/effects-halftone-preview.png',@@ -180,11 +187,11 @@ const categories: {description: 'Linear dot size gradient',},{- link: '/docs/effects/dot-grid',- preview: '/img/effects-dot-grid-preview.png',- alt: 'dot grid effect preview',- name: 'dotGrid()',- description: 'Source-color dot mask effect',+ link: '/docs/light-leaks/light-leak-effect',+ preview: '/img/effects-light-leak-preview.png',+ alt: 'light leak effect preview',+ name: 'lightLeak()',+ description: 'Light leak overlay effect',},{link: '/docs/effects/noise',@@ -194,18 +201,11 @@ const categories: {description: 'Procedural grain effect',},{- link: '/docs/starburst/starburst-effect',- preview: '/img/effects-starburst-preview.png',- alt: 'starburst effect preview',- name: 'starburst()',- description: 'Starburst ray effect',- },- {- link: '/docs/light-leaks/light-leak-effect',- preview: '/img/effects-light-leak-preview.png',- alt: 'light leak effect preview',- name: 'lightLeak()',- description: 'Light leak overlay effect',+ link: '/docs/effects/scanlines',+ preview: '/img/effects-scanlines-preview.png',+ alt: 'scanlines effect preview',+ name: 'scanlines()',+ description: 'Additive horizontal scanlines',},{link: '/docs/effects/shine',@@ -221,6 +221,13 @@ const categories: {name: 'speckle()',description: 'Random alpha-hole effect',},+ {+ link: '/docs/starburst/starburst-effect',+ preview: '/img/effects-starburst-preview.png',+ alt: 'starburst effect preview',+ name: 'starburst()',+ description: 'Starburst ray effect',+ },],},];diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.tsindex bea92df4cc..6c160aefda 100644--- a/packages/docs/sidebars.ts+++ b/packages/docs/sidebars.ts@@ -286,6 +286,7 @@ const sidebars: SidebarsConfig = {'effects/noise','effects/saturation','effects/scale',+ 'effects/scanlines','effects/shine','effects/speckle','effects/tint',diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex 53ece262f2..98d688d2fc 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -1889,6 +1889,15 @@ export const articles = [noAi: false,slug: 'effects/scale',},+ {+ id: 'effects/scanlines',+ title: 'scanlines()',+ relativePath: 'docs/effects/scanlines.mdx',+ compId: 'articles-docs-effects-scanlines',+ crumb: '@remotion/effects',+ noAi: false,+ slug: 'effects/scanlines',+ },{id: 'effects/shine',title: 'shine()',diff --git a/packages/docs/src/remotion/Root.tsx b/packages/docs/src/remotion/Root.tsxindex 1f226c79c9..660b0d9576 100644--- a/packages/docs/src/remotion/Root.tsx+++ b/packages/docs/src/remotion/Root.tsx@@ -21,6 +21,7 @@ import {EffectsMirrorPreview} from '../../components/effects/effects-mirror-previmport {EffectsNoisePreview} from '../../components/effects/effects-noise-preview';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 {EffectsShinePreview} from '../../components/effects/effects-shine-preview';import {EffectsSpecklePreview} from '../../components/effects/effects-speckle-preview';import {EffectsStarburstPreview} from '../../components/effects/effects-starburst-preview';@@ -301,6 +302,19 @@ export const RemotionRoot: React.FC = () => {premultiply: false,}}/>+ <Still+ id="effects-scanlines-preview"+ component={EffectsScanlinesPreview}+ width={1280}+ height={720}+ defaultProps={{+ amount: 0.6,+ spacing: 8,+ thickness: 2,+ offset: 0,+ premultiply: false,+ }}+ /><Stillid="effects-shine-preview"component={EffectsShinePreview}diff --git a/packages/docs/static/generated/articles-docs-effects-scanlines.png b/packages/docs/static/generated/articles-docs-effects-scanlines.pngnew file mode 100644index 0000000000..c063b3631fBinary files /dev/null and b/packages/docs/static/generated/articles-docs-effects-scanlines.png differdiff --git a/packages/docs/static/img/effects-scanlines-preview.png b/packages/docs/static/img/effects-scanlines-preview.pngnew file mode 100644index 0000000000..e3ba747ccaBinary files /dev/null and b/packages/docs/static/img/effects-scanlines-preview.png differdiff --git a/packages/effects/bundle.ts b/packages/effects/bundle.tsindex fadc3068cb..efe8e82429 100644--- a/packages/effects/bundle.ts+++ b/packages/effects/bundle.ts@@ -24,6 +24,7 @@ const effectEntrypoints = ['src/mirror.ts','src/noise.ts','src/saturation.ts',+ 'src/scanlines.ts','src/scale.ts','src/shine.ts','src/speckle.ts',diff --git a/packages/effects/package.json b/packages/effects/package.jsonindex 85485ea5e2..673b708e45 100644--- a/packages/effects/package.json+++ b/packages/effects/package.json@@ -117,6 +117,11 @@"module": "./dist/esm/saturation.mjs","import": "./dist/esm/saturation.mjs"},+ "./scanlines": {+ "types": "./dist/scanlines.d.ts",+ "module": "./dist/esm/scanlines.mjs",+ "import": "./dist/esm/scanlines.mjs"+ },"./scale": {"types": "./dist/scale.d.ts","module": "./dist/esm/scale.mjs",@@ -207,6 +212,9 @@"saturation": ["dist/saturation.d.ts"],+ "scanlines": [+ "dist/scanlines.d.ts"+ ],"scale": ["dist/scale.d.ts"],diff --git a/packages/effects/src/scanlines.ts b/packages/effects/src/scanlines.tsnew file mode 100644index 0000000000..7745bee341--- /dev/null+++ b/packages/effects/src/scanlines.ts@@ -0,0 +1,357 @@+import type {SequenceSchema} from 'remotion';+import {Internals} from 'remotion';+import {+ assertOptionalFiniteNumber,+ validateNonNegative,+ validateUnitInterval,+} from './color-utils.js';+import {assertEffectParamsObject} from './validate-effect-param.js';++const {createEffect, createWebGL2ContextError} = Internals;++const DEFAULT_AMOUNT = 0.15 as const;+const DEFAULT_SPACING = 4 as const;+const DEFAULT_THICKNESS = 1 as const;+const DEFAULT_OFFSET = 0 as const;+const DEFAULT_PREMULTIPLY = false as const;++const scanlinesSchema = {+ amount: {+ type: 'number',+ min: 0,+ max: 1,+ step: 0.01,+ default: DEFAULT_AMOUNT,+ description: 'Amount',+ },+ spacing: {+ type: 'number',+ min: 0.1,+ max: 100,+ step: 0.1,+ default: DEFAULT_SPACING,+ description: 'Spacing',+ },+ thickness: {+ type: 'number',+ min: 0,+ max: 100,+ step: 0.1,+ default: DEFAULT_THICKNESS,+ description: 'Thickness',+ },+ offset: {+ type: 'number',+ step: 0.1,+ default: DEFAULT_OFFSET,+ description: 'Offset',+ },+ premultiply: {+ type: 'boolean',+ default: DEFAULT_PREMULTIPLY,+ description: 'Premultiply',+ },+} as const satisfies SequenceSchema;++export type ScanlinesParams = {+ /** Strength of the scanline modulation from `0` to `1`. Defaults to `0.15`. */+ readonly amount?: number;+ /** Distance between scanlines in pixels. Defaults to `4`. */+ readonly spacing?: number;+ /** Thickness of each scanline in pixels. Defaults to `1`. */+ readonly thickness?: number;+ /** Vertical offset in pixels. Animate this value to scroll the scanlines. Defaults to `0`. */+ readonly offset?: number;+ /** Multiply the scanline contribution with the input colors before blending. Defaults to `false`. */+ readonly premultiply?: boolean;+};++type ScanlinesResolved = {+ amount: number;+ spacing: number;+ thickness: number;+ offset: number;+ premultiply: boolean;+};++type ScanlinesState = {+ readonly gl: WebGL2RenderingContext;+ readonly program: WebGLProgram;+ readonly vao: WebGLVertexArrayObject;+ readonly vbo: WebGLBuffer;+ readonly texture: WebGLTexture;+ readonly uSource: WebGLUniformLocation | null;+ readonly uAmount: WebGLUniformLocation | null;+ readonly uSpacing: WebGLUniformLocation | null;+ readonly uThickness: WebGLUniformLocation | null;+ readonly uOffset: WebGLUniformLocation | null;+ readonly uPremultiply: WebGLUniformLocation | null;+};++const resolve = (p: ScanlinesParams): ScanlinesResolved => ({+ amount: p.amount ?? DEFAULT_AMOUNT,+ spacing: p.spacing ?? DEFAULT_SPACING,+ thickness: p.thickness ?? DEFAULT_THICKNESS,+ offset: p.offset ?? DEFAULT_OFFSET,+ premultiply: p.premultiply ?? DEFAULT_PREMULTIPLY,+});++const assertOptionalBoolean = (value: unknown, name: string): void => {+ if (value === undefined) {+ return;+ }++ if (typeof value !== 'boolean') {+ throw new TypeError(+ `"${name}" must be a boolean, but got ${JSON.stringify(value)}`,+ );+ }+};++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 validateScanlinesParams = (params: ScanlinesParams): void => {+ assertEffectParamsObject(params, 'Scanlines');+ assertOptionalFiniteNumber(params.amount, 'amount');+ assertOptionalFiniteNumber(params.spacing, 'spacing');+ assertOptionalFiniteNumber(params.thickness, 'thickness');+ assertOptionalFiniteNumber(params.offset, 'offset');+ assertOptionalBoolean(params.premultiply, 'premultiply');++ const r = resolve(params);+ validateUnitInterval(r.amount, 'amount');+ validatePositive(r.spacing, 'spacing');+ validateNonNegative(r.thickness, 'thickness');+};++const SCANLINES_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 SCANLINES_FS = /* glsl */ `#version 300 es+precision highp float;++in vec2 vUv;+out vec4 fragColor;++uniform sampler2D uSource;+uniform float uAmount;+uniform float uSpacing;+uniform float uThickness;+uniform float uOffset;+uniform bool uPremultiply;++void main() {+ vec4 texColor = texture(uSource, vUv);+ float alpha = texColor.a;++ if (alpha <= 0.001) {+ fragColor = vec4(0.0);+ return;+ }++ if (uAmount <= 0.0 || uThickness <= 0.0) {+ fragColor = texColor;+ return;+ }++ float spacing = max(uSpacing, 0.001);+ float thickness = min(uThickness, spacing);+ float halfThickness = thickness * 0.5;+ float position = mod(gl_FragCoord.y + uOffset, spacing);+ float distanceToLine = min(position, spacing - position);+ float line = 1.0 - smoothstep(halfThickness, halfThickness + 1.0, distanceToLine);+ float dutyCycle = thickness / spacing;+ float signal = line - dutyCycle;++ vec3 rgb = texColor.rgb / alpha;+ vec3 scanlineLayer = uPremultiply ? rgb * signal : vec3(signal);+ rgb = clamp(rgb + scanlineLayer * uAmount, 0.0, 1.0);+ 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(`Scanlines 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(`Scanlines program link failed: ${log ?? '(no log)'}`);+ }++ return program;+};++const setupScanlines = (target: HTMLCanvasElement): ScanlinesState => {+ const gl = target.getContext('webgl2', {+ premultipliedAlpha: true,+ alpha: true,+ preserveDrawingBuffer: true,+ });+ if (!gl) {+ throw createWebGL2ContextError('scanlines effect');+ }++ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);++ const vs = compileShader(gl, gl.VERTEX_SHADER, SCANLINES_VS);+ const fs = compileShader(gl, gl.FRAGMENT_SHADER, SCANLINES_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_MIN_FILTER, gl.LINEAR);+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);+ gl.bindTexture(gl.TEXTURE_2D, null);++ return {+ gl,+ program,+ vao,+ vbo,+ texture,+ uSource: gl.getUniformLocation(program, 'uSource'),+ uAmount: gl.getUniformLocation(program, 'uAmount'),+ uSpacing: gl.getUniformLocation(program, 'uSpacing'),+ uThickness: gl.getUniformLocation(program, 'uThickness'),+ uOffset: gl.getUniformLocation(program, 'uOffset'),+ uPremultiply: gl.getUniformLocation(program, 'uPremultiply'),+ };+};++export const scanlines = createEffect<ScanlinesParams, ScanlinesState>({+ type: 'remotion/scanlines',+ label: 'scanlines()',+ documentationLink: 'https://www.remotion.dev/docs/effects/scanlines',+ backend: 'webgl2',+ calculateKey: (params) => {+ const r = resolve(params);+ return `scanlines-${r.amount}-${r.spacing}-${r.thickness}-${r.offset}-${r.premultiply ? 1 : 0}`;+ },+ setup: (target) => setupScanlines(target),+ apply: ({source, width, height, params, state, flipSourceY}) => {+ const r = resolve(params);+ const {gl, program, texture, vao} = state;++ gl.viewport(0, 0, width, height);+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);+ gl.clearColor(0, 0, 0, 0);+ gl.clear(gl.COLOR_BUFFER_BIT);++ gl.activeTexture(gl.TEXTURE0);+ gl.bindTexture(gl.TEXTURE_2D, texture);+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipSourceY);+ gl.texImage2D(+ gl.TEXTURE_2D,+ 0,+ gl.RGBA,+ gl.RGBA,+ gl.UNSIGNED_BYTE,+ source as TexImageSource,+ );++ gl.useProgram(program);+ if (state.uSource) gl.uniform1i(state.uSource, 0);+ if (state.uAmount) gl.uniform1f(state.uAmount, r.amount);+ if (state.uSpacing) gl.uniform1f(state.uSpacing, r.spacing);+ if (state.uThickness) gl.uniform1f(state.uThickness, r.thickness);+ if (state.uOffset) gl.uniform1f(state.uOffset, r.offset);+ if (state.uPremultiply)+ gl.uniform1i(state.uPremultiply, r.premultiply ? 1 : 0);++ gl.bindVertexArray(vao);+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);+ gl.bindVertexArray(null);+ gl.bindTexture(gl.TEXTURE_2D, null);+ gl.useProgram(null);+ },+ cleanup: ({gl, program, vao, vbo, texture}) => {+ gl.deleteTexture(texture);+ gl.deleteBuffer(vbo);+ gl.deleteProgram(program);+ gl.deleteVertexArray(vao);+ },+ schema: scanlinesSchema,+ validateParams: validateScanlinesParams,+});diff --git a/packages/effects/src/test/effect-params.test.ts b/packages/effects/src/test/effect-params.test.tsindex d63b6a7141..b85c47b36a 100644--- a/packages/effects/src/test/effect-params.test.ts+++ b/packages/effects/src/test/effect-params.test.ts@@ -17,6 +17,7 @@ import {mirror} from '../mirror.js';import {noise} from '../noise.js';import {saturation} from '../saturation.js';import {scale} from '../scale.js';+import {scanlines} from '../scanlines.js';import {shine} from '../shine.js';import {speckle} from '../speckle.js';import {tint} from '../tint.js';@@ -76,6 +77,9 @@ test('@remotion/effects expose documentation links', () => {expect(saturation().definition.documentationLink).toBe('https://www.remotion.dev/docs/effects/saturation',);+ expect(scanlines().definition.documentationLink).toBe(+ 'https://www.remotion.dev/docs/effects/scanlines',+ );expect(scale({scale: 1}).definition.documentationLink).toBe('https://www.remotion.dev/docs/effects/scale',);@@ -121,6 +125,7 @@ test('@remotion/effects expose API names as Studio labels', () => {expect(mirror().definition.label).toBe('mirror()');expect(noise().definition.label).toBe('noise()');expect(saturation().definition.label).toBe('saturation()');+ expect(scanlines().definition.label).toBe('scanlines()');expect(scale({scale: 1}).definition.label).toBe('scale()');expect(shine().definition.label).toBe('shine()');expect(speckle().definition.label).toBe('speckle()');@@ -985,6 +990,72 @@ test('saturation() amount produces distinct effect keys', () => {).toBe(3);});+test('scanlines() accepts default params', () => {+ expect(() => scanlines()).not.toThrow();+});++test('scanlines() rejects non-finite amount', () => {+ expect(() => scanlines({amount: Number.NaN})).toThrow(+ '"amount" must be a finite number',+ );+});++test('scanlines() rejects amount below range', () => {+ expect(() => scanlines({amount: -0.1})).toThrow('"amount" must be >= 0');+});++test('scanlines() rejects amount above range', () => {+ expect(() => scanlines({amount: 1.1})).toThrow('"amount" must be <= 1');+});++test('scanlines() rejects non-finite spacing', () => {+ expect(() => scanlines({spacing: Number.NaN})).toThrow(+ '"spacing" must be a finite number',+ );+});++test('scanlines() rejects non-positive spacing', () => {+ expect(() => scanlines({spacing: 0})).toThrow(+ '"spacing" must be greater than 0',+ );+});++test('scanlines() rejects negative thickness', () => {+ expect(() => scanlines({thickness: -1})).toThrow('"thickness" must be >= 0');+});++test('scanlines() rejects non-finite offset', () => {+ expect(() => scanlines({offset: Number.NaN})).toThrow(+ '"offset" must be a finite number',+ );+});++test('scanlines() rejects non-boolean premultiply', () => {+ expect(() => scanlines({premultiply: 'yes' as unknown as boolean})).toThrow(+ '"premultiply" must be a boolean',+ );+});++test('scanlines() parameters produce distinct effect keys', () => {+ const subtle = scanlines({amount: 0.1});+ const strong = scanlines({amount: 0.3});+ const dense = scanlines({spacing: 2});+ const thick = scanlines({thickness: 2});+ const shifted = scanlines({offset: 1});+ const premultiplied = scanlines({premultiply: true});++ expect(+ new Set([+ subtle.effectKey,+ strong.effectKey,+ dense.effectKey,+ thick.effectKey,+ shifted.effectKey,+ premultiplied.effectKey,+ ]).size,+ ).toBe(6);+});+test('hue() accepts default params', () => {expect(() => hue()).not.toThrow();});