Skip to content

Production-ready animations, transitions, backgrounds, and scenes for Remotion

feat: ascii render

kapishdima2c8f946ae5f5
diff --git a/components/docs/examples/ascii-render-example.tsx b/components/docs/examples/ascii-render-example.tsx
new file mode 100644
index 00000000..f4197034
--- /dev/null
+++ b/components/docs/examples/ascii-render-example.tsx
@@ -0,0 +1,55 @@
+"use client";
+
+import { CanvasSceneA } from "@/components/docs/examples/canvas-scenes";
+import { AsciiRender } from "@/registry/remocn/ascii-render";
+
+interface AsciiRenderExampleProps {
+ glyphSize?: number;
+ charset?: string;
+ colored?: boolean;
+ ink?: string;
+ intensity?: number;
+}
+
+export function AsciiRenderExampleScene({
+ glyphSize,
+ charset,
+ colored,
+ ink,
+ intensity,
+}: AsciiRenderExampleProps) {
+ return (
+ <AsciiRender
+ glyphSize={glyphSize}
+ charset={charset}
+ colored={colored}
+ ink={ink}
+ intensity={intensity}
+ >
+ <CanvasSceneA />
+ </AsciiRender>
+ );
+}
+
+export const asciiRenderExampleCode = (
+ values: Record<string, unknown>,
+): string => {
+ const glyphSize = (values.glyphSize as number) ?? 26;
+ const charset = (values.charset as string) ?? " .:-=+*#%@";
+ const colored = (values.colored as boolean) ?? false;
+ const ink = (values.ink as string) ?? "#9dff9d";
+ const intensity = (values.intensity as number) ?? 1;
+ return `import { AsciiRender } from "@/components/remocn/ascii-render";
+
+export const MyScene = () => (
+ <AsciiRender
+ glyphSize={${glyphSize}}
+ charset="${charset}"
+ colored={${colored}}
+ ink="${ink}"
+ intensity={${intensity}}
+ >
+ <Scene />
+ </AsciiRender>
+);`;
+};
diff --git a/components/docs/examples/ascii-render-recipes.tsx b/components/docs/examples/ascii-render-recipes.tsx
new file mode 100644
index 00000000..edd2babe
--- /dev/null
+++ b/components/docs/examples/ascii-render-recipes.tsx
@@ -0,0 +1,112 @@
+"use client";
+
+import { AbsoluteFill, interpolate, useCurrentFrame } from "remotion";
+import {
+ CanvasSceneA,
+ CanvasSceneB,
+} from "@/components/docs/examples/canvas-scenes";
+import { AsciiRender } from "@/registry/remocn/ascii-render";
+
+const SANS =
+ "var(--font-geist-sans), -apple-system, BlinkMacSystemFont, sans-serif";
+
+export function AsciiResolveExampleScene() {
+ const frame = useCurrentFrame();
+ const intensity = interpolate(frame, [0, 34, 76, 96], [1, 0, 0, 1]);
+ const glyphSize = interpolate(frame, [0, 34, 76, 96], [44, 20, 20, 44]);
+
+ return (
+ <AsciiRender intensity={intensity} glyphSize={glyphSize}>
+ <CanvasSceneA />
+ </AsciiRender>
+ );
+}
+
+export function AsciiBeatExampleScene() {
+ const frame = useCurrentFrame();
+ const intensity = interpolate(
+ frame,
+ [18, 20, 32, 56, 58, 70],
+ [0, 1, 0, 0, 1, 0],
+ { extrapolateLeft: "clamp", extrapolateRight: "clamp" },
+ );
+
+ return (
+ <AsciiRender intensity={intensity} glyphSize={24}>
+ <CanvasSceneB />
+ </AsciiRender>
+ );
+}
+
+const COLUMNS = 16;
+const ROWS = 9;
+const CELLS = Array.from({ length: ROWS }, (_, row) =>
+ Array.from({ length: COLUMNS }, (_, column) => ({
+ row,
+ column,
+ key: `${row}-${column}`,
+ })),
+).flat();
+
+function SignalField() {
+ const frame = useCurrentFrame();
+
+ return (
+ <AbsoluteFill
+ style={{ background: "#07100c", display: "flex", flexWrap: "wrap" }}
+ >
+ {CELLS.map((cell) => {
+ const wave =
+ Math.sin(
+ (cell.column + cell.row) * 0.62 - (frame / 90) * Math.PI * 4,
+ ) *
+ 0.5 +
+ 0.5;
+ return (
+ <div
+ key={cell.key}
+ style={{
+ width: `${100 / COLUMNS}%`,
+ height: `${100 / ROWS}%`,
+ background: `rgba(120, 255, 190, ${0.06 + wave * 0.5})`,
+ }}
+ />
+ );
+ })}
+ </AbsoluteFill>
+ );
+}
+
+export function AsciiBackdropExampleScene() {
+ return (
+ <AbsoluteFill>
+ <AsciiRender glyphSize={18} ink="#2f7a52">
+ <SignalField />
+ </AsciiRender>
+ <AbsoluteFill
+ style={{
+ padding: 96,
+ justifyContent: "center",
+ fontFamily: SANS,
+ }}
+ >
+ <span
+ style={{
+ fontSize: 96,
+ fontWeight: 600,
+ letterSpacing: "-0.03em",
+ lineHeight: 1.05,
+ color: "#f2f2f2",
+ }}
+ >
+ Every render,
+ <br />
+ byte for byte
+ </span>
+ <span style={{ marginTop: 28, fontSize: 34, color: "#8b9a90" }}>
+ Deterministic output across parallel workers
+ </span>
+ </AbsoluteFill>
+ </AbsoluteFill>
+ );
+}
diff --git a/components/docs/examples/index.tsx b/components/docs/examples/index.tsx
index a78751c9..4e9a38ba 100644
--- a/components/docs/examples/index.tsx
+++ b/components/docs/examples/index.tsx
@@ -9,6 +9,11 @@ import {
AlertDialogExampleScene,
alertDialogExampleCode,
} from "./alert-dialog-example";
+import {
+ AsciiBackdropExampleScene,
+ AsciiBeatExampleScene,
+ AsciiResolveExampleScene,
+} from "./ascii-render-recipes";
import { BlurInExampleScene, blurInExampleCode } from "./blur-in-example";
import { ButtonExampleScene, buttonExampleCode } from "./button-example";
import { CheckboxExampleScene, checkboxExampleCode } from "./checkbox-example";
@@ -431,4 +436,34 @@ export const examples: Record<string, ExampleEntry> = {
height: H,
previewBackdrop: { type: "color", value: "#ffffff" },
},
+ "ascii-resolve-example": {
+ Component: AsciiResolveExampleScene,
+ code: "<AsciiRender intensity={intensity} glyphSize={glyphSize} />",
+ // Resolves out of text by frame 34, holds clean, then returns so the loop closes.
+ durationInFrames: 96,
+ fps: FPS,
+ width: W,
+ height: H,
+ previewBackdrop: { type: "color", value: "#0a0a0a" },
+ },
+ "ascii-beat-example": {
+ Component: AsciiBeatExampleScene,
+ code: "<AsciiRender intensity={intensity} glyphSize={24} />",
+ // Two punches, at frames 18–32 and 56–70, clean everywhere else.
+ durationInFrames: 90,
+ fps: FPS,
+ width: W,
+ height: H,
+ previewBackdrop: { type: "color", value: "#0a0a0a" },
+ },
+ "ascii-backdrop-example": {
+ Component: AsciiBackdropExampleScene,
+ code: '<AsciiRender glyphSize={18} ink="#2f7a52" />',
+ // The wrapped field completes exactly two wave cycles over these 90 frames.
+ durationInFrames: 90,
+ fps: FPS,
+ width: W,
+ height: H,
+ previewBackdrop: { type: "color", value: "#0a0a0a" },
+ },
};
diff --git a/content/changelog/2026-08-02-filters.mdx b/content/changelog/2026-08-02-filters.mdx
index bf812f1d..3405f138 100644
--- a/content/changelog/2026-08-02-filters.mdx
+++ b/content/changelog/2026-08-02-filters.mdx
@@ -10,6 +10,7 @@ Canvas transitions gave the catalog effects that live at a cut. Filters are the
### New components
- [VHS Filter](/docs/filters/components/vhs-filter) — a scene held under analog tape. Colour bleeds sideways off every edge while brightness stays sharp, which is what separates tape from a blur; rows wander out of line on a slow drift with per-line jitter on top; the bottom of the frame tears where a real deck switches heads; luma noise and scanlines settle over all of it. Every knob is a plain number, so `intensity` can be interpolated to let a scene surface out of the wear.
+- [ASCII Render](/docs/filters/components/ascii-render) — the scene redrawn as text. The frame divides into glyph cells, each one measures the average brightness of the picture inside it and becomes the matching character from a density ramp, and because the measurement happens every frame the characters flow with whatever moves underneath. Monochrome on black for a terminal, or `colored` to let each glyph keep the colour of its own cell. `intensity` blends the text back toward the untouched scene and is read every frame, so a scene can resolve out of ASCII on entry, drop into it on a beat, or sit in it the whole time. It is the sustained sibling of `ascii-dissolve` — the same alphabet, held over a scene instead of covering a cut.
- [Pixelate Region](/docs/filters/components/pixelate-region) — the practical one. Hand it rectangles in composition coordinates and everything inside them becomes an opaque mosaic, each cell the average of the picture under it, while the rest of the frame stays perfectly sharp. It is built so that failing open is impossible: the mosaic is composited over black at full alpha every frame, the CSS fallback degrades to a plain opaque block rather than an approximation, and passing more regions than can be covered throws instead of quietly dropping one. Record the real dashboard, cover the real key.
- [Sustained Glitch](/docs/filters/components/sustained-glitch) — broadcast corruption held over a scene as scheduled bursts rather than a constant texture. Slices tear sideways on their own beats, channels pull apart, and blocks fill with picture dragged in from elsewhere in the frame; a few frames later it has decayed and the scene is untouched again until the next hit. `intensity` is read every frame, so the damage can be interpolated onto a beat. It is the sustained sibling of `glitch-cut` — the same look, living between the cuts instead of at one.
- [CRT Screen](/docs/filters/components/crt-screen) — the scene put behind curved glass. The picture bulges outward so straight lines bow, an RGB phosphor mask breaks the colour into stripes, scanlines follow the curve instead of lying flat, bright areas flood the mask around them, and past the edge of the tube the corners fall away into real darkness rather than a hole. The pair splits cleanly: `vhs-filter` degrades the signal, `crt-screen` is the display it arrives on, and they stack.
diff --git a/content/docs/filters/components/ascii-render.mdx b/content/docs/filters/components/ascii-render.mdx
new file mode 100644
index 00000000..8cfaa00a
--- /dev/null
+++ b/content/docs/filters/components/ascii-render.mdx
@@ -0,0 +1,213 @@
+---
+title: ASCII Render
+description: Redraw a live scene as ASCII, one character per cell, tracking the picture as it moves
+component: ascii-render
+vibe: tech
+length: sustained
+useWhen:
+ - "A scene should arrive out of text — interpolate intensity from 1 to 0 and the UI resolves out of ASCII instead of just fading in."
+ - "A scene should read as a terminal rendering of itself — developer-facing intros, hacker-flavoured beats, a dashboard reduced to text."
+ - "You want a moving backdrop made of characters, by wrapping a shader or gradient while the content on top stays sharp."
+ - "The scene is high contrast, since the glyph ramp is driven by brightness and flat mid-tones give flat text."
+avoidWhen:
+ - "The ASCII should only cover the cut between two scenes — use `ascii-dissolve`."
+ - "You want cascading code rain as a motif rather than the scene itself turned into characters — use `matrix-decode`."
+ - "The scene carries fine detail or small type that has to stay readable, since a glyph cell throws away everything inside it but its average brightness."
+---
+
+<ComponentPreview name="ascii-render" />
+
+<CanvasFilterNote />
+
+## Installation
+
+<InstallBlock name="ascii-render" />
+
+## Usage
+
+`AsciiRender` is a wrapper. Put a scene inside it and the frame is divided into
+glyph cells; each cell measures the average brightness of the picture inside it
+and draws the character from `charset` that matches. Because the measurement
+happens every frame, the characters flow with whatever moves underneath.
+
+```tsx
+import { AsciiRender } from "@/components/remocn/ascii-render";
+
+export const MyScene = () => (
+ <AsciiRender>
+ <Scene />
+ </AsciiRender>
+);
+```
+
+## What to reach for it for
+
+On its own, a scene converted to text is a look. What makes it useful in a video
+is `intensity`, which is read every frame: it blends the ASCII back toward the
+untouched scene, so the treatment can arrive, leave, or spike.
+
+### Resolve the scene out of text
+
+The strongest use. The scene enters as characters and sharpens into the real UI
+over the first second — a beginning with more intent than a fade, and one that
+says "this is software" before the viewer can read anything.
+
+<ComponentExample name="ascii-resolve" />
+
+```tsx
+import { interpolate, useCurrentFrame } from "remotion";
+import { AsciiRender } from "@/components/remocn/ascii-render";
+
+export const Opening = () => {
+ const frame = useCurrentFrame();
+ const intensity = interpolate(frame, [0, 30], [1, 0], {
+ extrapolateRight: "clamp",
+ });
+
+ return (
+ <AsciiRender intensity={intensity} glyphSize={22}>
+ <Dashboard />
+ </AsciiRender>
+ );
+};
+```
+
+Animating `glyphSize` alongside it — coarse to fine, as the preview does — makes
+the scene feel like it is being resolved rather than revealed. The preview runs
+the move in reverse at the end so that it loops; a real opening would stop at 0
+and stay there.
+
+### Punch it in on a beat
+
+Hold the scene clean and let it drop into text for a few frames, the way
+`sustained-glitch` is used for damage. Good on a hard cut in the music or the
+moment a command runs.
+
+<ComponentExample name="ascii-beat" />
+
+```tsx
+const intensity = interpolate(frame, [44, 46, 58], [0, 1, 0], {
+ extrapolateLeft: "clamp",
+ extrapolateRight: "clamp",
+});
+```
+
+Two frames of attack and a dozen of release is the shape that reads as a hit.
+Give it a slow ramp and it stops being punctuation.
+
+### Build a backdrop out of characters
+
+The filter wraps anything, not just your main scene. Wrap something that moves
+and you get a field of text to sit content on — and the content stays perfectly
+sharp, because it lives outside the wrapper rather than inside it.
+
+<ComponentExample name="ascii-backdrop" />
+
+```tsx
+import { AbsoluteFill } from "remotion";
+import { AsciiRender } from "@/components/remocn/ascii-render";
+
+export const Scene = () => (
+ <AbsoluteFill>
+ <AsciiRender glyphSize={18} ink="#2f7a52">
+ <YourMovingBackdrop />
+ </AsciiRender>
+ <AbsoluteFill>{/* headline and body stay sharp */}</AbsoluteFill>
+ </AbsoluteFill>
+);
+```
+
+A shader background works here too, but only on Chrome 152+, where a canvas
+nested inside the captured subtree is itself captured. A backdrop built from DOM
+has no such requirement, which is what the preview above uses.
+
+## The charset is a ramp
+
+`charset` is read as a density ramp, darkest first: the leftmost character is
+what a black cell becomes, the rightmost is what a white cell becomes. The
+default `" .:-=+*#%@"` runs from a space to a solid glyph, which is why it reads
+as shading rather than as noise.
+
+Order matters more than length. A ramp whose characters do not grow steadily
+denser left to right will produce texture instead of tone.
+
+```tsx
+<AsciiRender charset=" ░▒▓█" glyphSize={20}>
+ <Scene />
+</AsciiRender>
+```
+
+## Colour
+
+By default the glyphs are drawn in a single `ink` colour on black — a terminal.
+Set `colored` and each glyph takes the colour of the picture in its own cell
+instead, which keeps the scene recognisable while still reducing it to text.
+
+```tsx
+<AsciiRender colored>
+ <Scene />
+</AsciiRender>
+```
+
+## Props
+
+<PropsTable
+ rows={[
+ {
+ name: "glyphSize",
+ type: "number",
+ default: "26",
+ description:
+ "Height of one glyph cell in composition units. The cell width follows from the monospace aspect, so this alone sets how much of the scene survives.",
+ },
+ {
+ name: "charset",
+ type: "string",
+ default: '" .:-=+*#%@"',
+ description:
+ "Density ramp, darkest character first. Any printable characters work; an empty string falls back to the default ramp.",
+ },
+ {
+ name: "colored",
+ type: "boolean",
+ default: "false",
+ description:
+ "When set, each glyph takes the colour of its own cell. When unset, all glyphs use ink.",
+ },
+ {
+ name: "ink",
+ type: "string",
+ default: '"#9dff9d"',
+ description: "Glyph colour in the monochrome mode. Ignored when colored is set.",
+ },
+ {
+ name: "intensity",
+ type: "number",
+ default: "1",
+ description:
+ "How much of the ASCII survives, from 0 to 1. Read every frame, so interpolating it is how the scene resolves out of text or drops into it. At 0 the scene passes through exactly as it was.",
+ },
+ {
+ name: "children",
+ type: "React.ReactNode",
+ description: "The scene the filter wraps and re-reads every frame.",
+ },
+ ]}
+/>
+
+## Notes
+
+Between the glyphs the filter writes opaque black wherever the scene was opaque,
+so the result reads as a terminal rather than as characters floating over the
+original. Where the scene is transparent it stays transparent, so the filter can
+sit over a backdrop without boxing it in.
+
+The glyph atlas is drawn once per charset with the system monospace face and
+cached for the lifetime of the canvas, so it costs nothing per frame. It uses a
+system font rather than a loaded webfont specifically so that there is no frame
+where the atlas has been built from a fallback face.
+
+In browsers without html-in-canvas the scene renders untouched. There is no
+honest CSS approximation of resampling a live scene into glyphs, and a
+half-measure that only tinted the frame green would misrepresent what the
+component does.
diff --git a/content/docs/filters/components/meta.json b/content/docs/filters/components/meta.json
index e60d5fa2..32497fc5 100644
--- a/content/docs/filters/components/meta.json
+++ b/content/docs/filters/components/meta.json
@@ -1,5 +1,11 @@
{
"title": "Filters",
"collapsible": false,
- "pages": ["vhs-filter", "crt-screen", "sustained-glitch", "pixelate-region"]
+ "pages": [
+ "vhs-filter",
+ "crt-screen",
+ "sustained-glitch",
+ "pixelate-region",
+ "ascii-render"
+ ]
}
diff --git a/registry-artifacts/ascii-render.json b/registry-artifacts/ascii-render.json
new file mode 100644
index 00000000..e596d543
--- /dev/null
+++ b/registry-artifacts/ascii-render.json
@@ -0,0 +1,17 @@
+{
+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",
+ "name": "ascii-render",
+ "title": "ASCII Render",
+ "description": "Redraw a live scene as ASCII: the frame divides into glyph cells and each one becomes the character matching the brightness of the picture inside it.",
+ "dependencies": ["remotion"],
+ "registryDependencies": ["@remocn/canvas-presentation"],
+ "files": [
+ {
+ "path": "registry/remocn/ascii-render/index.tsx",
+ "content": "\"use client\";\n\nimport type React from \"react\";\nimport { AbsoluteFill, useVideoConfig } from \"remotion\";\nimport {\n type CanvasFilterProps,\n makeCanvasFilter,\n makeFilterShader,\n} from \"@/lib/remocn/canvas-presentation\";\n\nexport type AsciiRenderProps = {\n glyphSize?: number;\n charset?: string;\n colored?: boolean;\n ink?: string;\n intensity?: number;\n};\n\nconst DEFAULTS = {\n glyphSize: 26,\n charset: \" .:-=+*#%@\",\n colored: false,\n ink: \"#9dff9d\",\n intensity: 1,\n};\n\nconst GLYPH_ASPECT = 0.545;\nconst ATLAS_CELL_W = 24;\nconst ATLAS_CELL_H = 44;\nconst ATLAS_FONT =\n 'ui-monospace, SFMono-Regular, Menlo, Consolas, \"Liberation Mono\", monospace';\n\ntype NormalizedProps = {\n cellX: number;\n cellY: number;\n charset: string;\n colored: boolean;\n ink: string;\n intensity: number;\n};\n\nconst FRAGMENT_SHADER = `#version 300 es\nprecision highp float;\n\nuniform sampler2D u_scene;\nuniform sampler2D u_atlas;\nuniform vec2 u_cell;\nuniform float u_glyph_count;\nuniform float u_colored;\nuniform vec3 u_ink;\nuniform float u_intensity;\n\nin vec2 v_uv;\nout vec4 outColor;\n\nconst int TAPS = 3;\n\nvec4 cellAverage(vec2 center, vec2 cell) {\n vec4 sum = vec4(0.0);\n for (int y = 0; y < TAPS; y++) {\n for (int x = 0; x < TAPS; x++) {\n vec2 offset = (vec2(float(x), float(y)) + 0.5) / float(TAPS) - 0.5;\n sum += texture(u_scene, center + offset * cell);\n }\n }\n return sum / float(TAPS * TAPS);\n}\n\nvoid main() {\n vec2 cell = max(u_cell, vec2(0.001));\n vec2 origin = floor(v_uv / cell) * cell;\n vec4 sampled = cellAverage(origin + cell * 0.5, cell);\n\n float luma = dot(sampled.rgb, vec3(0.299, 0.587, 0.114));\n float index = min(floor(luma * u_glyph_count), u_glyph_count - 1.0);\n\n vec2 local = clamp((v_uv - origin) / cell, 0.008, 0.992);\n float mask =\n texture(u_atlas, vec2((index + local.x) / u_glyph_count, local.y)).r;\n\n vec3 glyph = mix(u_ink, sampled.rgb, u_colored) * mask;\n vec4 source = texture(u_scene, v_uv);\n float amount = clamp(u_intensity, 0.0, 1.0);\n\n outColor = vec4(\n mix(source.rgb, glyph, amount),\n mix(source.a, max(mask, sampled.a), amount)\n );\n}`;\n\ntype Atlas = { charset: string; texture: WebGLTexture };\n\nconst atlases = new WeakMap<WebGL2RenderingContext, Atlas>();\n\nfunction drawAtlas(charset: string): OffscreenCanvas {\n const canvas = new OffscreenCanvas(\n ATLAS_CELL_W * charset.length,\n ATLAS_CELL_H,\n );\n const context = canvas.getContext(\"2d\");\n if (!context) {\n throw new Error(\"ascii-render: failed to acquire a 2D context\");\n }\n context.fillStyle = \"#000000\";\n context.fillRect(0, 0, canvas.width, canvas.height);\n context.fillStyle = \"#ffffff\";\n context.font = `${Math.round(ATLAS_CELL_H * 0.74)}px ${ATLAS_FONT}`;\n context.textAlign = \"center\";\n context.textBaseline = \"middle\";\n for (let i = 0; i < charset.length; i++) {\n context.fillText(\n charset[i],\n i * ATLAS_CELL_W + ATLAS_CELL_W / 2,\n ATLAS_CELL_H / 2,\n );\n }\n return canvas;\n}\n\nfunction bindAtlas(gl: WebGL2RenderingContext, charset: string): void {\n gl.activeTexture(gl.TEXTURE1);\n\n let atlas = atlases.get(gl);\n if (!atlas) {\n const texture = gl.createTexture();\n if (!texture) {\n throw new Error(\"ascii-render: failed to create the glyph atlas\");\n }\n gl.bindTexture(gl.TEXTURE_2D, texture);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n atlas = { charset: \"\", texture };\n atlases.set(gl, atlas);\n } else {\n gl.bindTexture(gl.TEXTURE_2D, atlas.texture);\n }\n\n if (atlas.charset !== charset) {\n gl.texImage2D(\n gl.TEXTURE_2D,\n 0,\n gl.RGBA,\n gl.RGBA,\n gl.UNSIGNED_BYTE,\n drawAtlas(charset),\n );\n atlas.charset = charset;\n }\n}\n\nfunction toRgb(hex: string): [number, number, number] {\n const value = hex.replace(\"#\", \"\");\n const full =\n value.length === 3\n ? value\n .split(\"\")\n .map((c) => c + c)\n .join(\"\")\n : value;\n const int = Number.parseInt(full, 16);\n if (Number.isNaN(int)) return [1, 1, 1];\n return [\n ((int >> 16) & 255) / 255,\n ((int >> 8) & 255) / 255,\n (int & 255) / 255,\n ];\n}\n\nconst shader = makeFilterShader<NormalizedProps>(\n FRAGMENT_SHADER,\n ({ gl, uniform, passedProps }) => {\n const { cellX, cellY, charset, colored, ink, intensity } = passedProps;\n bindAtlas(gl, charset);\n gl.uniform1i(uniform(\"u_atlas\"), 1);\n gl.uniform1f(uniform(\"u_glyph_count\"), charset.length);\n gl.uniform2f(uniform(\"u_cell\"), cellX, cellY);\n gl.uniform1f(uniform(\"u_colored\"), colored ? 1 : 0);\n gl.uniform3fv(uniform(\"u_ink\"), toRgb(ink));\n gl.uniform1f(uniform(\"u_intensity\"), intensity);\n },\n);\n\nconst AsciiRenderFallback: React.FC<NormalizedProps & CanvasFilterProps> = ({\n children,\n}) => <AbsoluteFill>{children}</AbsoluteFill>;\n\nconst AsciiRenderCanvas = makeCanvasFilter<NormalizedProps>({\n shader,\n fallback: AsciiRenderFallback,\n});\n\nexport const AsciiRender: React.FC<AsciiRenderProps & CanvasFilterProps> = ({\n glyphSize = DEFAULTS.glyphSize,\n charset = DEFAULTS.charset,\n colored = DEFAULTS.colored,\n ink = DEFAULTS.ink,\n intensity = DEFAULTS.intensity,\n children,\n}) => {\n const { width, height } = useVideoConfig();\n const resolved = charset.length > 0 ? charset : DEFAULTS.charset;\n\n return (\n <AsciiRenderCanvas\n cellX={(glyphSize * GLYPH_ASPECT) / width}\n cellY={glyphSize / height}\n charset={resolved}\n colored={colored}\n ink={ink}\n intensity={intensity}\n >\n {children}\n </AsciiRenderCanvas>\n );\n};\n",
+ "type": "registry:component",
+ "target": "components/remocn/ascii-render.tsx"
+ }
+ ],
+ "type": "registry:component"
+}
diff --git a/registry-artifacts/registry.json b/registry-artifacts/registry.json
index 5909957d..78b77fa5 100644
--- a/registry-artifacts/registry.json
+++ b/registry-artifacts/registry.json
@@ -1674,6 +1674,21 @@
],
"type": "registry:component"
},
+ {
+ "name": "ascii-render",
+ "title": "ASCII Render",
+ "description": "Redraw a live scene as ASCII: the frame divides into glyph cells and each one becomes the character matching the brightness of the picture inside it.",
+ "dependencies": ["remotion"],
+ "registryDependencies": ["@remocn/canvas-presentation"],
+ "files": [
+ {
+ "path": "registry/remocn/ascii-render/index.tsx",
+ "type": "registry:component",
+ "target": "components/remocn/ascii-render.tsx"
+ }
+ ],
+ "type": "registry:component"
+ },
{
"name": "pixelate-region",
"title": "Pixelate Region",
diff --git a/registry/__index__.tsx b/registry/__index__.tsx
index b293afb0..09b8d3d5 100644
--- a/registry/__index__.tsx
+++ b/registry/__index__.tsx
@@ -4,6 +4,7 @@ import { type ComponentConfig, SHARED_CONTROLS } from "@/lib/customizer-config";
import { animatedBarChartConfig } from "@/registry/remocn/animated-bar-chart/config";
import { animatedLineChartConfig } from "@/registry/remocn/animated-line-chart/config";
import { asciiDissolveConfig } from "@/registry/remocn/ascii-dissolve/config";
+import { asciiRenderConfig } from "@/registry/remocn/ascii-render/config";
import { backdropConfig } from "@/registry/remocn/backdrop/config";
import { blurOutUpConfig } from "@/registry/remocn/blur-out-up/config";
import { bottomUpLettersConfig } from "@/registry/remocn/bottom-up-letters/config";
@@ -1489,6 +1490,13 @@ const registry: Record<string, RegistryEntry> = {
),
config: pixelateRegionConfig,
},
+ "ascii-render": {
+ load: () =>
+ import("@/components/docs/examples/ascii-render-example").then((m) => ({
+ default: m.AsciiRenderExampleScene,
+ })),
+ config: asciiRenderConfig,
+ },
"slide-swap": {
load: () =>
import("@/components/docs/examples/slide-swap-example").then((m) => ({
diff --git a/registry/remocn/ascii-render/config.ts b/registry/remocn/ascii-render/config.ts
new file mode 100644
index 00000000..c54e617b
--- /dev/null
+++ b/registry/remocn/ascii-render/config.ts
@@ -0,0 +1,46 @@
+import { asciiRenderExampleCode } from "@/components/docs/examples/ascii-render-example";
+import { type ComponentConfig, FPS, H, W } from "@/lib/customizer-config";
+
+export const asciiRenderConfig: ComponentConfig = {
+ componentName: "AsciiRender",
+ importPath: "@/components/remocn/ascii-render",
+ controls: {
+ glyphSize: {
+ type: "number",
+ default: 26,
+ min: 10,
+ max: 64,
+ step: 2,
+ label: "Glyph size",
+ },
+ charset: {
+ type: "text",
+ default: " .:-=+*#%@",
+ label: "Charset",
+ },
+ colored: {
+ type: "boolean",
+ default: false,
+ label: "Source colour",
+ },
+ ink: {
+ type: "color",
+ default: "#9dff9d",
+ label: "Ink",
+ },
+ intensity: {
+ type: "number",
+ default: 1,
+ min: 0,
+ max: 1,
+ step: 0.05,
+ label: "Intensity",
+ },
+ },
+ durationInFrames: 90,
+ fps: FPS,
+ compositionWidth: W,
+ compositionHeight: H,
+ previewBackdrop: { type: "color", value: "#0a0a0a" },
+ snippet: asciiRenderExampleCode,
+};
diff --git a/registry/remocn/ascii-render/index.tsx b/registry/remocn/ascii-render/index.tsx
new file mode 100644
index 00000000..bfd4da37
--- /dev/null
+++ b/registry/remocn/ascii-render/index.tsx
@@ -0,0 +1,217 @@
+"use client";
+
+import type React from "react";
+import { AbsoluteFill, useVideoConfig } from "remotion";
+import {
+ type CanvasFilterProps,
+ makeCanvasFilter,
+ makeFilterShader,
+} from "@/lib/remocn/canvas-presentation";
+
+export type AsciiRenderProps = {
+ glyphSize?: number;
+ charset?: string;
+ colored?: boolean;
+ ink?: string;
+ intensity?: number;
+};
+
+const DEFAULTS = {
+ glyphSize: 26,
+ charset: " .:-=+*#%@",
+ colored: false,
+ ink: "#9dff9d",
+ intensity: 1,
+};
+
+const GLYPH_ASPECT = 0.545;
+const ATLAS_CELL_W = 24;
+const ATLAS_CELL_H = 44;
+const ATLAS_FONT =
+ 'ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace';
+
+type NormalizedProps = {
+ cellX: number;
+ cellY: number;
+ charset: string;
+ colored: boolean;
+ ink: string;
+ intensity: number;
+};
+
+const FRAGMENT_SHADER = `#version 300 es
+precision highp float;
+
+uniform sampler2D u_scene;
+uniform sampler2D u_atlas;
+uniform vec2 u_cell;
+uniform float u_glyph_count;
+uniform float u_colored;
+uniform vec3 u_ink;
+uniform float u_intensity;
+
+in vec2 v_uv;
+out vec4 outColor;
+
+const int TAPS = 3;
+
+vec4 cellAverage(vec2 center, vec2 cell) {
+ vec4 sum = vec4(0.0);
+ for (int y = 0; y < TAPS; y++) {
+ for (int x = 0; x < TAPS; x++) {
+ vec2 offset = (vec2(float(x), float(y)) + 0.5) / float(TAPS) - 0.5;
+ sum += texture(u_scene, center + offset * cell);
+ }
+ }
+ return sum / float(TAPS * TAPS);
+}
+
+void main() {
+ vec2 cell = max(u_cell, vec2(0.001));
+ vec2 origin = floor(v_uv / cell) * cell;
+ vec4 sampled = cellAverage(origin + cell * 0.5, cell);
+
+ float luma = dot(sampled.rgb, vec3(0.299, 0.587, 0.114));
+ float index = min(floor(luma * u_glyph_count), u_glyph_count - 1.0);
+
+ vec2 local = clamp((v_uv - origin) / cell, 0.008, 0.992);
+ float mask =
+ texture(u_atlas, vec2((index + local.x) / u_glyph_count, local.y)).r;
+
+ vec3 glyph = mix(u_ink, sampled.rgb, u_colored) * mask;
+ vec4 source = texture(u_scene, v_uv);
+ float amount = clamp(u_intensity, 0.0, 1.0);
+
+ outColor = vec4(
+ mix(source.rgb, glyph, amount),
+ mix(source.a, max(mask, sampled.a), amount)
+ );
+}`;
+
+type Atlas = { charset: string; texture: WebGLTexture };
+
+const atlases = new WeakMap<WebGL2RenderingContext, Atlas>();
+
+function drawAtlas(charset: string): OffscreenCanvas {
+ const canvas = new OffscreenCanvas(
+ ATLAS_CELL_W * charset.length,
+ ATLAS_CELL_H,
+ );
+ const context = canvas.getContext("2d");
+ if (!context) {
+ throw new Error("ascii-render: failed to acquire a 2D context");
+ }
+ context.fillStyle = "#000000";
+ context.fillRect(0, 0, canvas.width, canvas.height);
+ context.fillStyle = "#ffffff";
+ context.font = `${Math.round(ATLAS_CELL_H * 0.74)}px ${ATLAS_FONT}`;
+ context.textAlign = "center";
+ context.textBaseline = "middle";
+ for (let i = 0; i < charset.length; i++) {
+ context.fillText(
+ charset[i],
+ i * ATLAS_CELL_W + ATLAS_CELL_W / 2,
+ ATLAS_CELL_H / 2,
+ );
+ }
+ return canvas;
+}
+
+function bindAtlas(gl: WebGL2RenderingContext, charset: string): void {
+ gl.activeTexture(gl.TEXTURE1);
+
+ let atlas = atlases.get(gl);
+ if (!atlas) {
+ const texture = gl.createTexture();
+ if (!texture) {
+ throw new Error("ascii-render: failed to create the glyph atlas");
+ }
+ 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);
+ atlas = { charset: "", texture };
+ atlases.set(gl, atlas);
+ } else {
+ gl.bindTexture(gl.TEXTURE_2D, atlas.texture);
+ }
+
+ if (atlas.charset !== charset) {
+ gl.texImage2D(
+ gl.TEXTURE_2D,
+ 0,
+ gl.RGBA,
+ gl.RGBA,
+ gl.UNSIGNED_BYTE,
+ drawAtlas(charset),
+ );
+ atlas.charset = charset;
+ }
+}
+
+function toRgb(hex: string): [number, number, number] {
+ const value = hex.replace("#", "");
+ const full =
+ value.length === 3
+ ? value
+ .split("")
+ .map((c) => c + c)
+ .join("")
+ : value;
+ const int = Number.parseInt(full, 16);
+ if (Number.isNaN(int)) return [1, 1, 1];
+ return [
+ ((int >> 16) & 255) / 255,
+ ((int >> 8) & 255) / 255,
+ (int & 255) / 255,
+ ];
+}
+
+const shader = makeFilterShader<NormalizedProps>(
+ FRAGMENT_SHADER,
+ ({ gl, uniform, passedProps }) => {
+ const { cellX, cellY, charset, colored, ink, intensity } = passedProps;
+ bindAtlas(gl, charset);
+ gl.uniform1i(uniform("u_atlas"), 1);
+ gl.uniform1f(uniform("u_glyph_count"), charset.length);
+ gl.uniform2f(uniform("u_cell"), cellX, cellY);
+ gl.uniform1f(uniform("u_colored"), colored ? 1 : 0);
+ gl.uniform3fv(uniform("u_ink"), toRgb(ink));
+ gl.uniform1f(uniform("u_intensity"), intensity);
+ },
+);
+
+const AsciiRenderFallback: React.FC<NormalizedProps & CanvasFilterProps> = ({
+ children,
+}) => <AbsoluteFill>{children}</AbsoluteFill>;
+
+const AsciiRenderCanvas = makeCanvasFilter<NormalizedProps>({
+ shader,
+ fallback: AsciiRenderFallback,
+});
+
+export const AsciiRender: React.FC<AsciiRenderProps & CanvasFilterProps> = ({
+ glyphSize = DEFAULTS.glyphSize,
+ charset = DEFAULTS.charset,
+ colored = DEFAULTS.colored,
+ ink = DEFAULTS.ink,
+ intensity = DEFAULTS.intensity,
+ children,
+}) => {
+ const { width, height } = useVideoConfig();
+ const resolved = charset.length > 0 ? charset : DEFAULTS.charset;
+
+ return (
+ <AsciiRenderCanvas
+ cellX={(glyphSize * GLYPH_ASPECT) / width}
+ cellY={glyphSize / height}
+ charset={resolved}
+ colored={colored}
+ ink={ink}
+ intensity={intensity}
+ >
+ {children}
+ </AsciiRenderCanvas>
+ );
+};
diff --git a/registry/remocn/registry.json b/registry/remocn/registry.json
index 4032af37..931b7efe 100644
--- a/registry/remocn/registry.json
+++ b/registry/remocn/registry.json
@@ -1674,6 +1674,21 @@
}
]
},
+ {
+ "name": "ascii-render",
+ "type": "registry:component",
+ "title": "ASCII Render",
+ "description": "Redraw a live scene as ASCII: the frame divides into glyph cells and each one becomes the character matching the brightness of the picture inside it.",
+ "dependencies": ["remotion"],
+ "registryDependencies": ["@remocn/canvas-presentation"],
+ "files": [
+ {
+ "path": "ascii-render/index.tsx",
+ "type": "registry:component",
+ "target": "components/remocn/ascii-render.tsx"
+ }
+ ]
+ },
{
"name": "pixelate-region",
"type": "registry:component",
diff --git a/src/remotion/canvas-spike-root.tsx b/src/remotion/canvas-spike-root.tsx
index b48e0fdc..55eaaa10 100644
--- a/src/remotion/canvas-spike-root.tsx
+++ b/src/remotion/canvas-spike-root.tsx
@@ -6,6 +6,7 @@ import {
isHtmlInCanvasSupported,
registerRoot,
} from "remotion";
+import { AsciiRenderExampleScene } from "@/components/docs/examples/ascii-render-example";
import { CrtScreenExampleScene } from "@/components/docs/examples/crt-screen-example";
import { DisplacementExampleScene } from "@/components/docs/examples/displacement-example";
import { EmberBurnExampleScene } from "@/components/docs/examples/ember-burn-example";
@@ -16,6 +17,7 @@ import { PixelateRegionExampleScene } from "@/components/docs/examples/pixelate-
import { SustainedGlitchExampleScene } from "@/components/docs/examples/sustained-glitch-example";
import { VhsFilterExampleScene } from "@/components/docs/examples/vhs-filter-example";
import type { ComponentConfig } from "@/lib/customizer-config";
+import { asciiRenderConfig } from "@/registry/remocn/ascii-render/config";
import { crtScreenConfig } from "@/registry/remocn/crt-screen/config";
import { displacementConfig } from "@/registry/remocn/displacement/config";
import { emberBurnConfig } from "@/registry/remocn/ember-burn/config";
@@ -60,6 +62,7 @@ const SCENES: Record<
Scene: PixelateRegionExampleScene,
config: pixelateRegionConfig,
},
+ "ascii-render": { Scene: AsciiRenderExampleScene, config: asciiRenderConfig },
};
function makeStage(Scene: ComponentType) {