Skip to content

🎥 Make videos programmatically with React

`@remotion/effects`: Add thermalVision effect (#8518)

Jonny Burgerc722367fd54e
diff --git a/packages/docs/components/effects-demos/registry.ts b/packages/docs/components/effects-demos/registry.ts
index 67ebe4c2b2..20e620d1f1 100644
--- a/packages/docs/components/effects-demos/registry.ts
+++ b/packages/docs/components/effects-demos/registry.ts
@@ -32,6 +32,7 @@ import {scanlines} from '@remotion/effects/scanlines';
import {shine} from '@remotion/effects/shine';
import {shrinkwrap} from '@remotion/effects/shrinkwrap';
import {speckle} from '@remotion/effects/speckle';
+import {thermalVision} from '@remotion/effects/thermal-vision';
import {tint} from '@remotion/effects/tint';
import {uvTranslate, xyTranslate} from '@remotion/effects/translate';
import {tvSignalOff} from '@remotion/effects/tv-signal-off';
@@ -88,6 +89,7 @@ import {
} from '../effects/effects-shrinkwrap-preview';
import {EffectsSpecklePreview} from '../effects/effects-speckle-preview';
import {EffectsStarburstPreview} from '../effects/effects-starburst-preview';
+import {EffectsThermalVisionPreview} from '../effects/effects-thermal-vision-preview';
import {EffectsTintPreview} from '../effects/effects-tint-preview';
import {
EffectsUvTranslatePreview,
@@ -233,6 +235,14 @@ export const effectsDemos: EffectsDemoType[] = [
color: '#1ec8ff',
},
},
+ {
+ ...defaults,
+ id: 'effects-thermal-vision',
+ effectName: 'thermalVision',
+ effectImportPath: '@remotion/effects/thermal-vision',
+ comp: EffectsThermalVisionPreview,
+ schema: thermalVision().definition.schema,
+ },
{
...defaults,
id: 'effects-shine',
diff --git a/packages/docs/components/effects/effects-thermal-vision-preview.tsx b/packages/docs/components/effects/effects-thermal-vision-preview.tsx
new file mode 100644
index 0000000000..3b8d0e9ecb
--- /dev/null
+++ b/packages/docs/components/effects/effects-thermal-vision-preview.tsx
@@ -0,0 +1,19 @@
+import {thermalVision} from '@remotion/effects/thermal-vision';
+import React from 'react';
+import {CanvasImage} from 'remotion';
+import {EFFECTS_PREVIEW_IMAGE_SRC} from './effects-preview-image';
+
+export const EffectsThermalVisionPreview: React.FC<{
+ readonly amount: number;
+ readonly palette: readonly string[];
+}> = ({amount, palette}) => {
+ return (
+ <CanvasImage
+ src={EFFECTS_PREVIEW_IMAGE_SRC}
+ width={1280}
+ height={720}
+ fit="cover"
+ effects={[thermalVision({amount, palette})]}
+ />
+ );
+};
diff --git a/packages/docs/docs/effects/thermal-vision.mdx b/packages/docs/docs/effects/thermal-vision.mdx
new file mode 100644
index 0000000000..28144f02e1
--- /dev/null
+++ b/packages/docs/docs/effects/thermal-vision.mdx
@@ -0,0 +1,85 @@
+---
+image: /generated/articles-docs-effects-thermal-vision.png
+slug: /effects/thermal-vision
+title: thermalVision()
+sidebar_label: thermalVision()
+crumb: '@remotion/effects'
+---
+
+# thermalVision()<AvailableFrom v="4.0.479" />
+
+_Part of the [`@remotion/effects`](/docs/effects/api) package._
+
+Maps source luminance to a thermal heat-map color ramp. It can be applied to canvas-based components such as [`<Video>`](/docs/media/video), [`<HtmlInCanvas>`](/docs/remotion/html-in-canvas) and [`<Solid>`](/docs/solid).
+
+The source alpha channel is preserved, so transparent and semi-transparent regions keep their original transparency.
+
+## Preview
+
+<EffectsDemo type="effects-thermal-vision" />
+
+## Example
+
+```tsx twoslash title="MyComp.tsx"
+import {thermalVision} from '@remotion/effects/thermal-vision';
+import {AbsoluteFill, CanvasImage, staticFile} from 'remotion';
+
+export const MyComp: React.FC = () => {
+ return (
+ <AbsoluteFill>
+ <CanvasImage
+ src={staticFile('image.png')}
+ width={1280}
+ height={720}
+ fit="cover"
+ effects={[
+ thermalVision({
+ amount: 1,
+ palette: [
+ '#020617',
+ '#1238ff',
+ '#00a6ff',
+ '#00c853',
+ '#d6f542',
+ '#ffb000',
+ '#ff2f00',
+ '#ffffff',
+ ],
+ }),
+ ]}
+ />
+ </AbsoluteFill>
+ );
+};
+```
+
+## API
+
+Pass an object with the following properties. You can also call `thermalVision()` without arguments.
+
+### `amount?`
+
+Blend amount from `0` to `1`. Defaults to `1`.
+
+Use `0` to leave the layer unchanged. Use `1` to fully remap luminance to the thermal color ramp.
+
+### `palette?`
+
+Color ramp used from dark to bright pixels. Accepts an array of at least two CSS color strings.
+
+Defaults to a dark blue, blue, cyan, green, yellow, orange, red and white ramp.
+
+### `disabled?`
+
+When `true`, the effect is skipped. Defaults to `false`.
+
+## Requirements
+
+`thermalVision()` uses a WebGL2 backend. During renders, enable WebGL via [`Config.setChromiumOpenGlRenderer('angle')`](/docs/config#setchromiumopenglrenderer). See [Using WebGL during renders](/docs/remotion/html-in-canvas#using-webgl-during-renders).
+
+## See also
+
+- [`@remotion/effects`](/docs/effects/api)
+- [`duotone()`](/docs/effects/duotone)
+- [`grayscale()`](/docs/effects/grayscale)
+- [Source code for this effect](https://github.com/remotion-dev/remotion/blob/main/packages/effects/src/thermal-vision.ts)
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index db65dbc0be..1c5d55e82f 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -307,6 +307,7 @@ const sidebars: SidebarsConfig = {
'effects/shine',
'effects/shrinkwrap',
'effects/speckle',
+ 'effects/thermal-vision',
'effects/tint',
'effects/tv-signal-off',
'effects/uv-translate',
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 5be4679d87..2613e01112 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -2051,6 +2051,15 @@ export const articles = [
noAi: false,
slug: 'effects/speckle',
},
+ {
+ id: 'effects/thermal-vision',
+ title: 'thermalVision()',
+ relativePath: 'docs/effects/thermal-vision.mdx',
+ compId: 'articles-docs-effects-thermal-vision',
+ crumb: '@remotion/effects',
+ noAi: false,
+ slug: 'effects/thermal-vision',
+ },
{
id: 'effects/tint',
title: 'tint()',
diff --git a/packages/docs/src/remotion/Root.tsx b/packages/docs/src/remotion/Root.tsx
index 4b7c2b70ec..22ee831610 100644
--- a/packages/docs/src/remotion/Root.tsx
+++ b/packages/docs/src/remotion/Root.tsx
@@ -45,6 +45,7 @@ import {
} from '../../components/effects/effects-shrinkwrap-preview';
import {EffectsSpecklePreview} from '../../components/effects/effects-speckle-preview';
import {EffectsStarburstPreview} from '../../components/effects/effects-starburst-preview';
+import {EffectsThermalVisionPreview} from '../../components/effects/effects-thermal-vision-preview';
import {EffectsTintPreview} from '../../components/effects/effects-tint-preview';
import {
EffectsUvTranslatePreview,
@@ -63,6 +64,16 @@ import {Expert} from './Expert';
import {TemplateComp} from './Template';
const DEFAULT_EFFECT_COLORS = ['#dff4ff', '#7cc6ff'] as const;
+const DEFAULT_THERMAL_PALETTE = [
+ '#020617',
+ '#1238ff',
+ '#00a6ff',
+ '#00c853',
+ '#d6f542',
+ '#ffb000',
+ '#ff2f00',
+ '#ffffff',
+] as const;
export const RemotionRoot: React.FC = () => {
return (
@@ -237,6 +248,16 @@ export const RemotionRoot: React.FC = () => {
height={720}
defaultProps={{color: '#1ec8ff', amount: 0.7}}
/>
+ <Still
+ id="effects-thermal-vision-preview"
+ component={EffectsThermalVisionPreview}
+ width={1280}
+ height={720}
+ defaultProps={{
+ amount: 1,
+ palette: DEFAULT_THERMAL_PALETTE,
+ }}
+ />
<Still
id="effects-vignette-preview"
component={EffectsVignettePreview}
diff --git a/packages/docs/static/generated/articles-docs-effects-thermal-vision.png b/packages/docs/static/generated/articles-docs-effects-thermal-vision.png
new file mode 100644
index 0000000000..a78d5d5456
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-effects-thermal-vision.png differ
diff --git a/packages/docs/static/img/effects-thermal-vision-preview.png b/packages/docs/static/img/effects-thermal-vision-preview.png
new file mode 100644
index 0000000000..93a24af7e7
Binary files /dev/null and b/packages/docs/static/img/effects-thermal-vision-preview.png differ
diff --git a/packages/effects/bundle.ts b/packages/effects/bundle.ts
index 601d0ac98e..7cd4f1b4ca 100644
--- a/packages/effects/bundle.ts
+++ b/packages/effects/bundle.ts
@@ -41,6 +41,7 @@ const effectEntrypoints = [
'src/shine.ts',
'src/shrinkwrap.ts',
'src/speckle.ts',
+ 'src/thermal-vision.ts',
'src/tint.ts',
'src/translate.ts',
'src/tv-signal-off.ts',
diff --git a/packages/effects/package.json b/packages/effects/package.json
index 07f7561e0e..cc7ed5c6ee 100644
--- a/packages/effects/package.json
+++ b/packages/effects/package.json
@@ -204,6 +204,11 @@
"module": "./dist/esm/speckle.mjs",
"import": "./dist/esm/speckle.mjs"
},
+ "./thermal-vision": {
+ "types": "./dist/thermal-vision.d.ts",
+ "module": "./dist/esm/thermal-vision.mjs",
+ "import": "./dist/esm/thermal-vision.mjs"
+ },
"./tint": {
"types": "./dist/tint.d.ts",
"module": "./dist/esm/tint.mjs",
@@ -350,6 +355,9 @@
"speckle": [
"dist/speckle.d.ts"
],
+ "thermal-vision": [
+ "dist/thermal-vision.d.ts"
+ ],
"tint": [
"dist/tint.d.ts"
],
diff --git a/packages/effects/src/test/effect-params.test.ts b/packages/effects/src/test/effect-params.test.ts
index 4be20567e9..a6434fec1e 100644
--- a/packages/effects/src/test/effect-params.test.ts
+++ b/packages/effects/src/test/effect-params.test.ts
@@ -36,6 +36,7 @@ import {scanlines} from '../scanlines.js';
import {shine} from '../shine.js';
import {shrinkwrap} from '../shrinkwrap.js';
import {speckle} from '../speckle.js';
+import {thermalVision} from '../thermal-vision.js';
import {tint} from '../tint.js';
import {uvTranslate, xyTranslate} from '../translate.js';
import {tvSignalOff} from '../tv-signal-off.js';
@@ -168,6 +169,9 @@ test('@remotion/effects expose documentation links', () => {
expect(speckle().definition.documentationLink).toBe(
'https://www.remotion.dev/docs/effects/speckle',
);
+ expect(thermalVision().definition.documentationLink).toBe(
+ 'https://www.remotion.dev/docs/effects/thermal-vision',
+ );
expect(tint({color: '#fff'}).definition.documentationLink).toBe(
'https://www.remotion.dev/docs/effects/tint',
);
@@ -237,6 +241,7 @@ test('@remotion/effects expose API names as Studio labels', () => {
expect(shine().definition.label).toBe('shine()');
expect(shrinkwrap().definition.label).toBe('shrinkwrap()');
expect(speckle().definition.label).toBe('speckle()');
+ expect(thermalVision().definition.label).toBe('thermalVision()');
expect(tint({color: '#fff'}).definition.label).toBe('tint()');
expect(tvSignalOff().definition.label).toBe('tvSignalOff()');
expect(uvTranslate().definition.label).toBe('uvTranslate()');
@@ -874,6 +879,67 @@ test('duotone() parameters produce distinct effect keys', () => {
).toBe(3);
});
+test('thermalVision() accepts default params', () => {
+ expect(() => thermalVision()).not.toThrow();
+});
+
+test('thermalVision() exposes palette as an array control', () => {
+ expect(thermalVision().definition.schema.palette).toEqual({
+ type: 'array',
+ item: {
+ type: 'color',
+ },
+ default: [
+ '#020617',
+ '#1238ff',
+ '#00a6ff',
+ '#00c853',
+ '#d6f542',
+ '#ffb000',
+ '#ff2f00',
+ '#ffffff',
+ ],
+ minLength: 2,
+ newItemDefault: '#00c853',
+ description: 'Palette',
+ keyframable: false,
+ });
+});
+
+test('thermalVision() rejects non-finite amount', () => {
+ expect(() => thermalVision({amount: Number.NaN})).toThrow(
+ '"amount" must be a finite number',
+ );
+});
+
+test('thermalVision() rejects amount below range', () => {
+ expect(() => thermalVision({amount: -0.1})).toThrow('"amount" must be >= 0');
+});
+
+test('thermalVision() rejects amount above range', () => {
+ expect(() => thermalVision({amount: 1.1})).toThrow('"amount" must be <= 1');
+});
+
+test('thermalVision() rejects invalid palettes', () => {
+ expect(() => thermalVision({palette: ['#020617']})).toThrow(
+ '"palette" must be an array with at least 2 colors',
+ );
+ expect(() =>
+ thermalVision({palette: ['#020617', '' as unknown as string]}),
+ ).toThrow('"palette[1]" must be a non-empty string');
+});
+
+test('thermalVision() parameters produce distinct effect keys', () => {
+ const defaults = thermalVision();
+ const subtle = thermalVision({amount: 0.25});
+ const customPalette = thermalVision({palette: ['#000000', '#ffffff']});
+
+ expect(
+ new Set([defaults.effectKey, subtle.effectKey, customPalette.effectKey])
+ .size,
+ ).toBe(3);
+});
+
test('evolve() accepts default params', () => {
expect(() => evolve()).not.toThrow();
});
diff --git a/packages/effects/src/thermal-vision.ts b/packages/effects/src/thermal-vision.ts
new file mode 100644
index 0000000000..070da11328
--- /dev/null
+++ b/packages/effects/src/thermal-vision.ts
@@ -0,0 +1,399 @@
+import {Internals, type InteractivitySchema} from 'remotion';
+import {
+ assertOptionalFiniteNumber,
+ colorAmountSchema,
+ parseColorRgba,
+ type ParsedColorRgba,
+ validateUnitInterval,
+} from './color-utils.js';
+import {
+ assertEffectParamsObject,
+ assertRequiredColor,
+} from './validate-effect-param.js';
+
+const {createEffect, createWebGL2ContextError} = Internals;
+
+const DEFAULT_AMOUNT = 1 as const;
+const DEFAULT_PALETTE = [
+ '#020617',
+ '#1238ff',
+ '#00a6ff',
+ '#00c853',
+ '#d6f542',
+ '#ffb000',
+ '#ff2f00',
+ '#ffffff',
+] as const;
+
+export const thermalVisionSchema = {
+ amount: colorAmountSchema,
+ palette: {
+ type: 'array',
+ item: {
+ type: 'color',
+ },
+ default: DEFAULT_PALETTE,
+ minLength: 2,
+ newItemDefault: '#00c853',
+ description: 'Palette',
+ keyframable: false,
+ },
+} as const satisfies InteractivitySchema;
+
+export type ThermalVisionParams = {
+ /** Blend amount from `0` to `1`. Defaults to `1`. */
+ readonly amount?: number;
+ /** Color ramp used from dark to bright pixels. Defaults to a blue, green, yellow, red and white ramp. */
+ readonly palette?: readonly string[];
+};
+
+type ThermalVisionResolved = {
+ amount: number;
+ palette: readonly string[];
+};
+
+type ThermalVisionState = {
+ readonly gl: WebGL2RenderingContext;
+ readonly program: WebGLProgram;
+ readonly vao: WebGLVertexArrayObject;
+ readonly vbo: WebGLBuffer;
+ readonly sourceTexture: WebGLTexture;
+ readonly paletteTexture: WebGLTexture;
+ readonly colorCtx: CanvasRenderingContext2D;
+ readonly uniforms: {
+ readonly uSource: WebGLUniformLocation | null;
+ readonly uPalette: WebGLUniformLocation | null;
+ readonly uPaletteLength: WebGLUniformLocation | null;
+ readonly uAmount: WebGLUniformLocation | null;
+ };
+ cachedPaletteKey: string;
+ palettePixelData: Uint8Array;
+};
+
+const resolve = (p: ThermalVisionParams): ThermalVisionResolved => ({
+ amount: p.amount ?? DEFAULT_AMOUNT,
+ palette: p.palette ?? DEFAULT_PALETTE,
+});
+
+const validatePalette = (palette: unknown): void => {
+ if (palette === undefined) {
+ return;
+ }
+
+ if (!Array.isArray(palette) || palette.length < 2) {
+ throw new TypeError(
+ `"palette" must be an array with at least 2 colors, but got ${JSON.stringify(palette)}`,
+ );
+ }
+
+ for (let i = 0; i < palette.length; i++) {
+ assertRequiredColor(palette[i], `palette[${i}]`);
+ }
+};
+
+const validateThermalVisionParams = (params: ThermalVisionParams): void => {
+ assertEffectParamsObject(params, 'Thermal vision');
+ assertOptionalFiniteNumber(params.amount, 'amount');
+ validatePalette(params.palette);
+
+ const {amount} = resolve(params);
+ validateUnitInterval(amount, 'amount');
+};
+
+const THERMAL_VISION_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 THERMAL_VISION_FS = /* glsl */ `#version 300 es
+precision highp float;
+
+in vec2 vUv;
+out vec4 fragColor;
+
+uniform sampler2D uSource;
+uniform sampler2D uPalette;
+uniform float uPaletteLength;
+uniform float uAmount;
+
+vec3 paletteColor(float luminance) {
+ float length = max(uPaletteLength, 2.0);
+ float texCoord = (clamp(luminance, 0.0, 1.0) * (length - 1.0) + 0.5) / length;
+ return texture(uPalette, vec2(texCoord, 0.5)).rgb;
+}
+
+void main() {
+ vec4 texColor = texture(uSource, vUv);
+ float alpha = texColor.a;
+
+ if (alpha <= 0.001) {
+ fragColor = vec4(0.0);
+ return;
+ }
+
+ vec3 rgb = texColor.rgb / alpha;
+ float luminance = dot(rgb, vec3(0.299, 0.587, 0.114));
+ vec3 thermalRgb = paletteColor(luminance);
+ vec3 mixedRgb = mix(rgb, thermalRgb, clamp(uAmount, 0.0, 1.0));
+
+ fragColor = vec4(mixedRgb * 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(
+ `Thermal vision 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(`Thermal vision 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 createTexture = (
+ gl: WebGL2RenderingContext,
+ filter: number,
+): 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, filter);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filter);
+ 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 setupThermalVision = (target: HTMLCanvasElement): ThermalVisionState => {
+ const gl = target.getContext('webgl2', {
+ premultipliedAlpha: true,
+ alpha: true,
+ preserveDrawingBuffer: true,
+ });
+ if (!gl) {
+ throw createWebGL2ContextError('thermal vision effect');
+ }
+
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
+
+ const program = createProgram(gl, THERMAL_VISION_VS, THERMAL_VISION_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 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,
+ program,
+ vao,
+ vbo,
+ sourceTexture: createTexture(gl, gl.LINEAR),
+ paletteTexture: createTexture(gl, gl.LINEAR),
+ colorCtx,
+ uniforms: {
+ uSource: gl.getUniformLocation(program, 'uSource'),
+ uPalette: gl.getUniformLocation(program, 'uPalette'),
+ uPaletteLength: gl.getUniformLocation(program, 'uPaletteLength'),
+ uAmount: gl.getUniformLocation(program, 'uAmount'),
+ },
+ cachedPaletteKey: '',
+ palettePixelData: new Uint8Array(0),
+ };
+};
+
+const updatePalette = (
+ state: ThermalVisionState,
+ palette: readonly string[],
+): boolean => {
+ const paletteKey = palette.join('|');
+ const paletteDirty = state.cachedPaletteKey !== paletteKey;
+ if (!paletteDirty) {
+ return false;
+ }
+
+ state.cachedPaletteKey = paletteKey;
+ const len = palette.length * 4;
+ if (state.palettePixelData.length !== len) {
+ state.palettePixelData = new Uint8Array(len);
+ }
+
+ const {palettePixelData} = state;
+ for (let i = 0; i < palette.length; i++) {
+ const color: ParsedColorRgba = parseColorRgba(state.colorCtx, palette[i]);
+ palettePixelData[i * 4] = color[0];
+ palettePixelData[i * 4 + 1] = color[1];
+ palettePixelData[i * 4 + 2] = color[2];
+ palettePixelData[i * 4 + 3] = color[3];
+ }
+
+ return true;
+};
+
+export const thermalVision = createEffect<
+ ThermalVisionParams,
+ ThermalVisionState
+>({
+ type: 'remotion/thermal-vision',
+ label: 'thermalVision()',
+ documentationLink: 'https://www.remotion.dev/docs/effects/thermal-vision',
+ backend: 'webgl2',
+ calculateKey: (params) => {
+ const r = resolve(params);
+ return `thermal-vision-${r.amount}-${r.palette.join('|')}`;
+ },
+ setup: (target) => setupThermalVision(target),
+ apply: ({source, width, height, params, state, flipSourceY}) => {
+ const r = resolve(params);
+ const paletteDirty = updatePalette(state, r.palette);
+ const {gl, program, sourceTexture, paletteTexture, 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, sourceTexture);
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
+ 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.activeTexture(gl.TEXTURE1);
+ gl.bindTexture(gl.TEXTURE_2D, paletteTexture);
+ if (paletteDirty) {
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
+ gl.texImage2D(
+ gl.TEXTURE_2D,
+ 0,
+ gl.RGBA,
+ r.palette.length,
+ 1,
+ 0,
+ gl.RGBA,
+ gl.UNSIGNED_BYTE,
+ state.palettePixelData,
+ );
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
+ }
+
+ gl.useProgram(program);
+ if (uniforms.uSource) gl.uniform1i(uniforms.uSource, 0);
+ if (uniforms.uPalette) gl.uniform1i(uniforms.uPalette, 1);
+ if (uniforms.uPaletteLength)
+ gl.uniform1f(uniforms.uPaletteLength, r.palette.length);
+ if (uniforms.uAmount) gl.uniform1f(uniforms.uAmount, r.amount);
+
+ 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, sourceTexture, paletteTexture}) => {
+ gl.deleteTexture(sourceTexture);
+ gl.deleteTexture(paletteTexture);
+ gl.deleteBuffer(vbo);
+ gl.deleteProgram(program);
+ gl.deleteVertexArray(vao);
+ },
+ schema: thermalVisionSchema,
+ validateParams: validateThermalVisionParams,
+});
diff --git a/packages/skills/skills/remotion/SKILL.md b/packages/skills/skills/remotion/SKILL.md
index e96143d486..5f0bfaeb39 100644
--- a/packages/skills/skills/remotion/SKILL.md
+++ b/packages/skills/skills/remotion/SKILL.md
@@ -260,7 +260,7 @@ When creating a visual effect, prefer: 1. normal Remotion/HTML/CSS/SVG/filter/bl
For light leak overlays, see [rules/light-leaks.md](rules/light-leaks.md). Docs: https://www.remotion.dev/docs/effects
-Available effects: `brightness()`, `contrast()`, `colorKey()`, `duotone()`, `grayscale()`, `hue()`, `invert()`, `saturation()`, `tint()`, `blur()`, `linearProgressiveBlur()`, `dropShadow()`, `glow()`, `evolve()`, `mirror()`, `scale()`, `uvTranslate()`, `xyTranslate()`, `barrelDistortion()`, `chromaticAberration()`, `fisheye()`, `wave()`, `burlap()`, `dotGrid()`, `halftone()`, `noise()`, `noiseDisplacement()`, `pattern()`, `pixelate()`, `pixelDissolve()`, `scanlines()`, `speckle()`, `shine()`, `shrinkwrap()`, `vignette()`, `contourLines()`, `halftoneLinearGradient()`, `whiteNoise()`, `tvSignalOff()`, `lines()`, `rings()`, `waves()`, `zigzag()`, `lightLeak()`, `starburst()`.
+Available effects: `brightness()`, `contrast()`, `colorKey()`, `duotone()`, `grayscale()`, `hue()`, `invert()`, `saturation()`, `tint()`, `thermalVision()`, `blur()`, `linearProgressiveBlur()`, `dropShadow()`, `glow()`, `evolve()`, `mirror()`, `scale()`, `uvTranslate()`, `xyTranslate()`, `barrelDistortion()`, `chromaticAberration()`, `fisheye()`, `wave()`, `burlap()`, `dotGrid()`, `halftone()`, `noise()`, `noiseDisplacement()`, `pattern()`, `pixelate()`, `pixelDissolve()`, `scanlines()`, `speckle()`, `shine()`, `shrinkwrap()`, `vignette()`, `contourLines()`, `halftoneLinearGradient()`, `whiteNoise()`, `tvSignalOff()`, `lines()`, `rings()`, `waves()`, `zigzag()`, `lightLeak()`, `starburst()`.
## 3D content
diff --git a/packages/studio-shared/src/effect-catalog.ts b/packages/studio-shared/src/effect-catalog.ts
index e6c778700e..5fc423ac44 100644
--- a/packages/studio-shared/src/effect-catalog.ts
+++ b/packages/studio-shared/src/effect-catalog.ts
@@ -182,6 +182,17 @@ export const EFFECT_CATALOG: readonly EffectCatalogItem[] = [
},
},
},
+ {
+ id: 'effects-thermal-vision',
+ category: 'Color',
+ label: 'thermalVision()',
+ description: 'Thermal heat-map color effect',
+ effect: {
+ name: 'thermalVision',
+ importPath: '@remotion/effects/thermal-vision',
+ config: {},
+ },
+ },
{
id: 'effects-blur',
category: 'Blur & Shadow',