Skip to content

🎥 Make videos programmatically with React

`@remotion/effects`: Add speckle effect (#7721)

Jonny Burger9f2bde9325d6
diff --git a/packages/docs/components/demos/index.tsx b/packages/docs/components/demos/index.tsx
index 55dbc50d53..87b994ae74 100644
--- a/packages/docs/components/demos/index.tsx
+++ b/packages/docs/components/demos/index.tsx
@@ -35,6 +35,7 @@ import {
effectsSaturationDemo,
effectsScaleDemo,
effectsShineDemo,
+ effectsSpeckleDemo,
effectsStarburstDemo,
effectsTintDemo,
effectsUvTranslateDemo,
@@ -105,6 +106,7 @@ const demos: DemoType[] = [
effectsSaturationDemo,
effectsTintDemo,
effectsShineDemo,
+ effectsSpeckleDemo,
effectsMirrorDemo,
effectsNoiseDemo,
effectsScaleDemo,
diff --git a/packages/docs/components/demos/types.ts b/packages/docs/components/demos/types.ts
index be85b22f3f..23b8f7a735 100644
--- a/packages/docs/components/demos/types.ts
+++ b/packages/docs/components/demos/types.ts
@@ -17,6 +17,7 @@ import {EffectsNoisePreview} from '../effects/effects-noise-preview';
import {EffectsSaturationPreview} from '../effects/effects-saturation-preview';
import {EffectsScalePreview} from '../effects/effects-scale-preview';
import {EffectsShinePreview} from '../effects/effects-shine-preview';
+import {EffectsSpecklePreview} from '../effects/effects-speckle-preview';
import {EffectsStarburstPreview} from '../effects/effects-starburst-preview';
import {EffectsTintPreview} from '../effects/effects-tint-preview';
import {
@@ -1762,6 +1763,47 @@ export const effectsShineDemo: DemoType = {
],
};
+export const effectsSpeckleDemo: DemoType = {
+ comp: EffectsSpecklePreview,
+ compHeight: 720,
+ compWidth: 1280,
+ durationInFrames: 1,
+ fps: 30,
+ id: 'effects-speckle',
+ autoPlay: false,
+ controls: false,
+ logLevel: 'info',
+ options: [
+ {
+ name: 'density',
+ type: 'numeric',
+ min: 0,
+ max: 1,
+ step: 0.01,
+ default: 0.14,
+ optional: 'no',
+ },
+ {
+ name: 'size',
+ type: 'numeric',
+ min: 0,
+ max: 50,
+ step: 0.1,
+ default: 4,
+ optional: 'no',
+ },
+ {
+ name: 'randomness',
+ type: 'numeric',
+ min: 0,
+ max: 1,
+ step: 0.01,
+ default: 1,
+ optional: 'no',
+ },
+ ],
+};
+
export const effectsMirrorDemo: DemoType = {
comp: EffectsMirrorPreview,
compHeight: 720,
diff --git a/packages/docs/components/effects/effects-speckle-preview.tsx b/packages/docs/components/effects/effects-speckle-preview.tsx
new file mode 100644
index 0000000000..196ae048db
--- /dev/null
+++ b/packages/docs/components/effects/effects-speckle-preview.tsx
@@ -0,0 +1,26 @@
+import {speckle} from '@remotion/effects/speckle';
+import React from 'react';
+import {CanvasImage} from 'remotion';
+import {EFFECTS_PREVIEW_IMAGE_SRC} from './effects-preview-image';
+
+export const EffectsSpecklePreview: React.FC<{
+ readonly density: number;
+ readonly size: number;
+ readonly randomness: number;
+}> = ({density, size, randomness}) => {
+ return (
+ <CanvasImage
+ src={EFFECTS_PREVIEW_IMAGE_SRC}
+ width={1280}
+ height={720}
+ fit="cover"
+ effects={[
+ speckle({
+ density,
+ size,
+ randomness,
+ }),
+ ]}
+ />
+ );
+};
diff --git a/packages/docs/docs/effects/speckle.mdx b/packages/docs/docs/effects/speckle.mdx
new file mode 100644
index 0000000000..0bba9868bb
--- /dev/null
+++ b/packages/docs/docs/effects/speckle.mdx
@@ -0,0 +1,82 @@
+---
+image: /generated/articles-docs-effects-speckle.png
+slug: /effects/speckle
+title: speckle()
+sidebar_label: speckle()
+crumb: '@remotion/effects'
+---
+
+# speckle()<AvailableFrom v="4.0.469" />
+
+_Part of the [`@remotion/effects`](/docs/effects/api) package._
+
+Adds small random alpha holes to canvas-based components such as [`<Video>`](/docs/media/video), [`<HtmlInCanvas>`](/docs/remotion/html-in-canvas) and [`<Solid>`](/docs/solid).
+
+Use it for isolated pinpricks or dust-like missing spots without adding edge damage or a broader grunge texture.
+
+## Preview
+
+<Demo type="effects-speckle" />
+
+## Example
+
+```tsx twoslash title="MyComp.tsx"
+import {AbsoluteFill} from 'remotion';
+import {Video} from '@remotion/media';
+import {speckle} from '@remotion/effects/speckle';
+
+export const MyComp: React.FC = () => {
+ return (
+ <AbsoluteFill>
+ <Video
+ src="https://remotion.media/video.mp4"
+ effects={[
+ speckle({
+ density: 0.14,
+ size: 4,
+ randomness: 1,
+ }),
+ ]}
+ />
+ </AbsoluteFill>
+ );
+};
+```
+
+## API
+
+Pass an object with the following properties. You can also call `speckle()` without arguments.
+
+### `density?`
+
+Chance that each grid cell receives a hole. Defaults to `0.08`.
+
+Must be between `0` and `1`.
+
+### `size?`
+
+Maximum diameter of each alpha hole in pixels. Defaults to `4`.
+
+Must be at least `0`. Set it to `0` to preserve the source.
+
+### `randomness?`
+
+Controls how much each hole varies in position and size. Defaults to `1`.
+
+Set it closer to `0` for a more regular pattern. Must be between `0` and `1`.
+
+### `disabled?`
+
+When `true`, the effect is skipped. Defaults to `false`.
+
+## Requirements
+
+`speckle()` 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)
+- [`halftone()`](/docs/effects/halftone)
+- [`vignette()`](/docs/effects/vignette)
+- [HTML-in-canvas guide](/docs/html-in-canvas)
+- [Source code for this effect](https://github.com/remotion-dev/remotion/blob/main/packages/effects/src/speckle.ts)
diff --git a/packages/docs/docs/effects/table-of-contents.tsx b/packages/docs/docs/effects/table-of-contents.tsx
index 46591c1788..3d3fb21373 100644
--- a/packages/docs/docs/effects/table-of-contents.tsx
+++ b/packages/docs/docs/effects/table-of-contents.tsx
@@ -200,6 +200,13 @@ const categories: {
name: 'shine()',
description: 'Glossy light sweep effect',
},
+ {
+ link: '/docs/effects/speckle',
+ preview: '/img/effects-speckle-preview.jpg',
+ alt: 'speckle effect preview',
+ name: 'speckle()',
+ description: 'Random alpha-hole effect',
+ },
],
},
];
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index 72925c19d4..136cddab2a 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -285,6 +285,7 @@ const sidebars: SidebarsConfig = {
'effects/saturation',
'effects/scale',
'effects/shine',
+ 'effects/speckle',
'effects/tint',
'effects/uv-translate',
'effects/vignette',
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 8ab38043f2..7a784ceb3b 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -1880,6 +1880,15 @@ export const articles = [
noAi: false,
slug: 'effects/shine',
},
+ {
+ id: 'effects/speckle',
+ title: 'speckle()',
+ relativePath: 'docs/effects/speckle.mdx',
+ compId: 'articles-docs-effects-speckle',
+ crumb: '@remotion/effects',
+ noAi: false,
+ slug: 'effects/speckle',
+ },
{
id: 'effects/tint',
title: 'tint()',
diff --git a/packages/docs/static/generated/articles-docs-effects-speckle.png b/packages/docs/static/generated/articles-docs-effects-speckle.png
new file mode 100644
index 0000000000..376bebe6d8
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-effects-speckle.png differ
diff --git a/packages/docs/static/img/effects-speckle-preview.jpg b/packages/docs/static/img/effects-speckle-preview.jpg
new file mode 100644
index 0000000000..3eb115c7ad
Binary files /dev/null and b/packages/docs/static/img/effects-speckle-preview.jpg differ
diff --git a/packages/effects/bundle.ts b/packages/effects/bundle.ts
index 498333106b..bcb62d541f 100644
--- a/packages/effects/bundle.ts
+++ b/packages/effects/bundle.ts
@@ -24,6 +24,7 @@ const effectEntrypoints = [
'src/saturation.ts',
'src/scale.ts',
'src/shine.ts',
+ 'src/speckle.ts',
'src/tint.ts',
'src/translate.ts',
'src/vignette.ts',
diff --git a/packages/effects/package.json b/packages/effects/package.json
index e16cc4a5d9..0fe7587865 100644
--- a/packages/effects/package.json
+++ b/packages/effects/package.json
@@ -117,6 +117,11 @@
"module": "./dist/esm/shine.mjs",
"import": "./dist/esm/shine.mjs"
},
+ "./speckle": {
+ "types": "./dist/speckle.d.ts",
+ "module": "./dist/esm/speckle.mjs",
+ "import": "./dist/esm/speckle.mjs"
+ },
"./tint": {
"types": "./dist/tint.d.ts",
"module": "./dist/esm/tint.mjs",
@@ -192,6 +197,9 @@
"shine": [
"dist/shine.d.ts"
],
+ "speckle": [
+ "dist/speckle.d.ts"
+ ],
"tint": [
"dist/tint.d.ts"
],
diff --git a/packages/effects/src/speckle.ts b/packages/effects/src/speckle.ts
new file mode 100644
index 0000000000..2a941bf8fc
--- /dev/null
+++ b/packages/effects/src/speckle.ts
@@ -0,0 +1,323 @@
+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_DENSITY = 0.08 as const;
+const DEFAULT_SIZE = 4 as const;
+const DEFAULT_RANDOMNESS = 1 as const;
+
+const speckleSchema = {
+ density: {
+ type: 'number',
+ min: 0,
+ max: 1,
+ step: 0.01,
+ default: DEFAULT_DENSITY,
+ description: 'Density',
+ },
+ size: {
+ type: 'number',
+ min: 0,
+ max: 50,
+ step: 0.1,
+ default: DEFAULT_SIZE,
+ description: 'Size',
+ },
+ randomness: {
+ type: 'number',
+ min: 0,
+ max: 1,
+ step: 0.01,
+ default: DEFAULT_RANDOMNESS,
+ description: 'Randomness',
+ },
+} as const satisfies SequenceSchema;
+
+export type SpeckleParams = {
+ /** Chance that a grid cell receives an alpha hole. Defaults to `0.08`. */
+ readonly density?: number;
+ /** Maximum speckle diameter in pixels. Defaults to `4`. */
+ readonly size?: number;
+ /** Amount of random position and size variation between 0 and 1. Defaults to `1`. */
+ readonly randomness?: number;
+};
+
+type SpeckleResolved = {
+ density: number;
+ size: number;
+ randomness: number;
+};
+
+const resolve = (p: SpeckleParams): SpeckleResolved => ({
+ density: p.density ?? DEFAULT_DENSITY,
+ size: p.size ?? DEFAULT_SIZE,
+ randomness: p.randomness ?? DEFAULT_RANDOMNESS,
+});
+
+const validateSpeckleParams = (params: SpeckleParams): void => {
+ assertEffectParamsObject(params, 'Speckle');
+ assertOptionalFiniteNumber(params.density, 'density');
+ assertOptionalFiniteNumber(params.size, 'size');
+ assertOptionalFiniteNumber(params.randomness, 'randomness');
+
+ const r = resolve(params);
+ validateUnitInterval(r.density, 'density');
+ validateNonNegative(r.size, 'size');
+ validateUnitInterval(r.randomness, 'randomness');
+};
+
+const SPECKLE_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 SPECKLE_FS = /* glsl */ `#version 300 es
+precision highp float;
+
+in vec2 vUv;
+out vec4 fragColor;
+
+uniform sampler2D uSource;
+uniform vec2 uResolution;
+uniform float uDensity;
+uniform float uSize;
+uniform float uRandomness;
+
+float hash21(vec2 p) {
+ vec3 p3 = fract(vec3(p.xyx) * vec3(443.8975, 397.2973, 491.1871));
+ p3 += dot(p3, p3.yzx + 19.19);
+ return fract((p3.x + p3.y) * p3.z);
+}
+
+vec2 hash22(vec2 p) {
+ return vec2(hash21(p + 17.13), hash21(p + 83.71));
+}
+
+void main() {
+ vec4 color = texture(uSource, vUv);
+
+ if (uDensity <= 0.0 || uSize <= 0.0) {
+ fragColor = color;
+ return;
+ }
+
+ vec2 fragPos = vUv * uResolution;
+ float cellSize = max(uSize * 2.5, 1.0);
+ vec2 baseCell = floor(fragPos / cellSize);
+ float hole = 0.0;
+
+ for (int y = -1; y <= 1; y++) {
+ for (int x = -1; x <= 1; x++) {
+ vec2 cell = baseCell + vec2(float(x), float(y));
+ float chance = hash21(cell);
+
+ if (chance <= uDensity) {
+ vec2 randomOffset = (hash22(cell + 11.7) - 0.5) * uRandomness;
+ vec2 center = (cell + 0.5 + randomOffset) * cellSize;
+ float sizeVariation = mix(1.0, 0.35 + hash21(cell + 29.43) * 0.65, uRandomness);
+ float radius = uSize * 0.5 * sizeVariation;
+ float edge = min(1.0, max(radius * 0.5, 0.35));
+ float coverage = 1.0 - smoothstep(radius - edge, radius + edge, length(fragPos - center));
+ hole = max(hole, coverage);
+ }
+ }
+ }
+
+ fragColor = color * (1.0 - clamp(hole, 0.0, 1.0));
+}
+`;
+
+type SpeckleState = {
+ gl: WebGL2RenderingContext;
+ program: WebGLProgram;
+ vao: WebGLVertexArrayObject;
+ vbo: WebGLBuffer;
+ texture: WebGLTexture;
+ uSource: WebGLUniformLocation | null;
+ uResolution: WebGLUniformLocation | null;
+ uDensity: WebGLUniformLocation | null;
+ uSize: WebGLUniformLocation | null;
+ uRandomness: WebGLUniformLocation | null;
+};
+
+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(`Speckle 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(`Speckle program link failed: ${log ?? '(no log)'}`);
+ }
+
+ return program;
+};
+
+export const speckle = createEffect<SpeckleParams, SpeckleState>({
+ type: 'remotion/speckle',
+ label: 'speckle()',
+ documentationLink: 'https://www.remotion.dev/docs/effects/speckle',
+ backend: 'webgl2',
+ calculateKey: (params) => {
+ const r = resolve(params);
+ return `speckle-${r.density}-${r.size}-${r.randomness}`;
+ },
+ setup: (target) => {
+ const gl = target.getContext('webgl2', {
+ premultipliedAlpha: true,
+ alpha: true,
+ preserveDrawingBuffer: true,
+ });
+ if (!gl) {
+ throw createWebGL2ContextError('speckle effect');
+ }
+
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
+
+ const vs = compileShader(gl, gl.VERTEX_SHADER, SPECKLE_VS);
+ const fs = compileShader(gl, gl.FRAGMENT_SHADER, SPECKLE_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,
+ uSource: gl.getUniformLocation(program, 'uSource'),
+ uResolution: gl.getUniformLocation(program, 'uResolution'),
+ uDensity: gl.getUniformLocation(program, 'uDensity'),
+ uSize: gl.getUniformLocation(program, 'uSize'),
+ uRandomness: gl.getUniformLocation(program, 'uRandomness'),
+ };
+ },
+ apply: ({source, width, height, params, state, flipSourceY}) => {
+ const r = resolve(params);
+ const {gl, program, vao, texture} = 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 (state.uSource) gl.uniform1i(state.uSource, 0);
+ if (state.uResolution) gl.uniform2f(state.uResolution, width, height);
+ if (state.uDensity) gl.uniform1f(state.uDensity, r.density);
+ if (state.uSize) gl.uniform1f(state.uSize, r.size);
+ if (state.uRandomness) gl.uniform1f(state.uRandomness, r.randomness);
+
+ 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.deleteBuffer(vbo);
+ gl.deleteProgram(program);
+ gl.deleteVertexArray(vao);
+ gl.deleteTexture(texture);
+ },
+ schema: speckleSchema,
+ validateParams: validateSpeckleParams,
+});
diff --git a/packages/effects/src/test/effect-params.test.ts b/packages/effects/src/test/effect-params.test.ts
index 9aa07745e2..109914c62d 100644
--- a/packages/effects/src/test/effect-params.test.ts
+++ b/packages/effects/src/test/effect-params.test.ts
@@ -16,6 +16,7 @@ import {noise} from '../noise.js';
import {saturation} from '../saturation.js';
import {scale} from '../scale.js';
import {shine} from '../shine.js';
+import {speckle} from '../speckle.js';
import {tint} from '../tint.js';
import {uvTranslate, xyTranslate} from '../translate.js';
import {vignette} from '../vignette.js';
@@ -73,6 +74,9 @@ test('@remotion/effects expose documentation links', () => {
expect(shine().definition.documentationLink).toBe(
'https://www.remotion.dev/docs/effects/shine',
);
+ expect(speckle().definition.documentationLink).toBe(
+ 'https://www.remotion.dev/docs/effects/speckle',
+ );
expect(tint({color: '#fff'}).definition.documentationLink).toBe(
'https://www.remotion.dev/docs/effects/tint',
);
@@ -109,6 +113,7 @@ test('@remotion/effects expose API names as Studio labels', () => {
expect(saturation().definition.label).toBe('saturation()');
expect(scale({scale: 1}).definition.label).toBe('scale()');
expect(shine().definition.label).toBe('shine()');
+ expect(speckle().definition.label).toBe('speckle()');
expect(tint({color: '#fff'}).definition.label).toBe('tint()');
expect(uvTranslate().definition.label).toBe('uvTranslate()');
expect(vignette().definition.label).toBe('vignette()');
@@ -988,6 +993,56 @@ test('shine() parameters produce distinct effect keys', () => {
).toBe(6);
});
+test('speckle() accepts default params', () => {
+ expect(() => speckle()).not.toThrow();
+});
+
+test('speckle() accepts valid params', () => {
+ expect(() =>
+ speckle({
+ density: 0.2,
+ size: 6,
+ randomness: 0.5,
+ }),
+ ).not.toThrow();
+});
+
+test('speckle() rejects non-finite density', () => {
+ expect(() => speckle({density: Number.NaN})).toThrow(
+ '"density" must be a finite number',
+ );
+});
+
+test('speckle() rejects density above range', () => {
+ expect(() => speckle({density: 1.1})).toThrow('"density" must be <= 1');
+});
+
+test('speckle() rejects negative size', () => {
+ expect(() => speckle({size: -0.1})).toThrow('"size" must be >= 0');
+});
+
+test('speckle() rejects randomness below range', () => {
+ expect(() => speckle({randomness: -0.1})).toThrow(
+ '"randomness" must be >= 0',
+ );
+});
+
+test('speckle() parameters produce distinct effect keys', () => {
+ const defaultSpeckle = speckle();
+ const denser = speckle({density: 0.2});
+ const larger = speckle({size: 8});
+ const steadier = speckle({randomness: 0.25});
+
+ expect(
+ new Set([
+ defaultSpeckle.effectKey,
+ denser.effectKey,
+ larger.effectKey,
+ steadier.effectKey,
+ ]).size,
+ ).toBe(4);
+});
+
test('xyTranslate() accepts default params', () => {
expect(() => xyTranslate()).not.toThrow();
});