🎥 Make videos programmatically with React
Text subpixel rendering
Jonny Burger09f80c046daa
diff --git a/packages/docs/docs/troubleshooting/subpixel-rendering.mdx b/packages/docs/docs/troubleshooting/subpixel-rendering.mdxnew file mode 100644index 0000000000..38c9c8c413--- /dev/null+++ b/packages/docs/docs/troubleshooting/subpixel-rendering.mdx@@ -0,0 +1,56 @@+---+image: /generated/articles-docs-troubleshooting-subpixel-rendering.png+sidebar_label: Subpixel rendering+title: Text subpixel rendering+crumb: 'Troubleshooting'+---++Chrome will by default always render text to align it with the closest pixel.+That means that a text with `margin-top: 10px` and `margin-top: 10.4px` will be rendered identically.++This can make your animations less smooth more jarring.++To counter this effect, you can render your text with:++- A `transform` property+- An additional `perspective()` transform+- A `willChange: "transform"` CSS property++Notice the difference in this 200x100 video:++<video+ src="https://remotion-assets.s3.eu-central-1.amazonaws.com/smooth-text.mp4"+ playsInline+ muted+ autoPlay+ loop+ style={{+ width: '100%',+ border: '2px solid var(--text-color)',+ borderRadius: 4,+ }}+/>+<br />++```tsx title="Left side of the video"+<div+ style={{+ transform: 'translateY(' + interpolate(frame, [0, 200], [0, 50]) + 'px)',+ }}+>+ hi there+</div>+```++```tsx title="Right side of the video"+<div+ style={{+ transform: 'perspective(100px) translateY(' + interpolate(frame, [0, 200], [0, 50]) + 'px)',+ willChange: 'transform',+ }}+>+ hi there+</div>+```++Consider using this optimization [only during rendering](/docs/get-remotion-environment) as excessive `will-change`: `transform` will use more resources.diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex 8d6e44bfcf..ad48996b5b 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -1001,6 +1001,7 @@ module.exports = {'troubleshooting/bundling-bundle','troubleshooting/browser-launch','troubleshooting/sigkill',+ 'troubleshooting/subpixel-rendering','troubleshooting/could-not-find-executable-to-run','troubleshooting/stuck-render',],diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex 1e70c09b08..4110475924 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -4994,6 +4994,15 @@ export const articles = [noAi: false,slug: 'troubleshooting/sigkill',},+ {+ id: 'troubleshooting/subpixel-rendering',+ title: 'Text subpixel rendering',+ relativePath: 'docs/troubleshooting/subpixel-rendering.mdx',+ compId: 'articles-docs-troubleshooting-subpixel-rendering',+ crumb: 'Troubleshooting',+ noAi: false,+ slug: 'troubleshooting/subpixel-rendering',+ },{id: 'troubleshooting/timed-out-page-function',title: 'Timed out evaluating page function',diff --git a/packages/docs/static/generated/articles-docs-troubleshooting-subpixel-rendering.png b/packages/docs/static/generated/articles-docs-troubleshooting-subpixel-rendering.pngnew file mode 100644index 0000000000..cf57d1fd3dBinary files /dev/null and b/packages/docs/static/generated/articles-docs-troubleshooting-subpixel-rendering.png differdiff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsxindex e67b460d7b..f775f90c8d 100644--- a/packages/example/src/Root.tsx+++ b/packages/example/src/Root.tsx@@ -115,6 +115,7 @@ const INCLUDE_COMP_BREAKING_GET_COMPOSITIONS = false;import {ThreeDEngine} from './3DEngine';import {AnimatedImages} from './AnimatedImage/Avif';+import {SmoothTextTransition} from './SmoothTextTransition';class Vector2 {readonly x: number;@@ -1490,6 +1491,7 @@ export const Index: React.FC = () => {height={1000}width={1000}/>+ <SmoothTextTransition /></>);};diff --git a/packages/example/src/SmoothTextTransition.tsx b/packages/example/src/SmoothTextTransition.tsxnew file mode 100644index 0000000000..16665fcb7a--- /dev/null+++ b/packages/example/src/SmoothTextTransition.tsx@@ -0,0 +1,53 @@+import {StudioInternals} from '@remotion/studio';+import {AbsoluteFill, interpolate, useCurrentFrame} from 'remotion';++const Comp: React.FC = () => {+ const frame = useCurrentFrame();++ return (+ <AbsoluteFill+ style={{+ fontSize: 20,+ display: 'flex',+ lineHeight: 1,+ fontFamily: 'sans-serif',+ backgroundColor: 'white',+ textAlign: 'center',+ flexDirection: 'row',+ }}+ >+ <div style={{width: 100}}>+ <div+ style={{+ transform:+ 'translateY(' + interpolate(frame, [0, 200], [0, 50]) + 'px)',+ }}+ >+ hi there+ </div>+ </div>+ <div style={{width: 100}}>+ <div+ style={{+ transform:+ 'translateY(' ++ interpolate(frame, [0, 200], [0, 50]) ++ 'px) perspective(100px)',+ willChange: 'transform',+ }}+ >+ hi there+ </div>+ </div>+ </AbsoluteFill>+ );+};++export const SmoothTextTransition = StudioInternals.createComposition({+ component: Comp,+ height: 100,+ width: 200,+ id: 'smooth-text',+ durationInFrames: 200,+ fps: 3,+});