-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into event-loop-break
- Loading branch information
Showing
7 changed files
with
125 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+45.2 KB
...ages/docs/static/generated/articles-docs-troubleshooting-subpixel-rendering.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}); |