Branchwell

Become a Pro / portrait-video · becomeapro.ai / src / transitions / GlitchTransition.tsx

1import React from 'react';
2import { AbsoluteFill, interpolate } from 'remotion';
3import type { TransitionPresentation, TransitionPresentationComponentProps } from '@remotion/transitions';
4
5const GlitchPresenter: React.FC<TransitionPresentationComponentProps<Record<string, never>>> = ({
6 children,
7 presentationDirection,
8 presentationProgress,
9}) => {
10 const isExiting = presentationDirection === 'exiting';
11
12 // Subtle intensity — quick spike in the middle
13 const intensity = interpolate(presentationProgress, [0, 0.35, 0.5, 0.65, 1], [0, 0, 1, 0, 0], {
14 extrapolateLeft: 'clamp',
15 extrapolateRight: 'clamp',
16 });
17
18 // Very subtle RGB shift (max 5px)
19 const rgbShift = intensity * 5;
20
21 // Gentle slice displacement (max 8px, only 3 slices)
22 const sliceOffset = intensity * 8;
23
24 // Crossfade opacity
25 const opacity = isExiting
26 ? interpolate(presentationProgress, [0, 1], [1, 0], { extrapolateRight: 'clamp' })
27 : interpolate(presentationProgress, [0, 1], [0, 1], { extrapolateRight: 'clamp' });
28
29 // Only 3 slices for a subtle effect
30 const slices = Array.from({ length: 3 }, (_, i) => {
31 const yStart = (i / 3) * 100;
32 const yEnd = ((i + 1) / 3) * 100;
33 const xShift = (i === 1 ? 1 : -1) * sliceOffset * intensity;
34 return { yStart, yEnd, xShift };
35 });
36
37 // No glitch visible — just crossfade
38 if (intensity < 0.05) {
39 return (
40 <AbsoluteFill style={{ opacity }}>
41 {children}
42 </AbsoluteFill>
43 );
44 }
45
46 return (
47 <AbsoluteFill>
48 {/* Sliced content — subtle horizontal shift on middle third only */}
49 {slices.map((slice, i) => (
50 <div
51 key={i}
52 style={{
53 position: 'absolute',
54 left: 0,
55 width: '100%',
56 top: `${slice.yStart}%`,
57 height: `${slice.yEnd - slice.yStart}%`,
58 overflow: 'hidden',
59 transform: `translateX(${slice.xShift}px)`,
60 opacity,
61 }}
62 >
63 <div style={{
64 position: 'absolute',
65 top: `-${slice.yStart}%`,
66 left: 0,
67 width: '100%',
68 height: `${100 / ((slice.yEnd - slice.yStart) / 100)}%`,
69 }}>
70 {children}
71 </div>
72 </div>
73 ))}
74
75 {/* Very subtle RGB fringe — barely visible */}
76 <AbsoluteFill style={{
77 opacity: intensity * 0.12,
78 transform: `translateX(-${rgbShift}px)`,
79 mixBlendMode: 'screen',
80 }}>
81 <div style={{
82 position: 'absolute',
83 top: 0, left: 0, width: '100%', height: '100%',
84 background: `rgba(255, 50, 50, ${intensity * 0.08})`,
85 }} />
86 </AbsoluteFill>
87
88 <AbsoluteFill style={{
89 opacity: intensity * 0.12,
90 transform: `translateX(${rgbShift}px)`,
91 mixBlendMode: 'screen',
92 }}>
93 <div style={{
94 position: 'absolute',
95 top: 0, left: 0, width: '100%', height: '100%',
96 background: `rgba(50, 100, 255, ${intensity * 0.08})`,
97 }} />
98 </AbsoluteFill>
99 </AbsoluteFill>
100 );
101};
102
103export const glitch = (): TransitionPresentation<Record<string, never>> => {
104 return {
105 component: GlitchPresenter,
106 props: {},
107 };
108};