Add noise
Using the @remotion/noise API, you can add noise for your videos.
Noise Dot Grid Demo
This example shows how to create a floating dot grid "surface" using createNoise3D function.
- 1st and 2nd dimensions used for space domain.
- 3rd dimension used for time domain.
tsx
importReact , {useMemo ,useState } from "react";import {AbsoluteFill ,Easing ,interpolate ,useCurrentFrame ,useVideoConfig } from "remotion";import {Player } from "@remotion/player";import {createNoise3D } from "@remotion/noise";constxNoise3d =createNoise3D ("x");constyNoise3d =createNoise3D ("y");constopacityNoise3d =createNoise3D ("opacity");constcolorNoise3d =createNoise3D ("color");interfaceProps {scale : numberspeed : numbercircleRadius : number}constBackground :React .FC <Props > = ({scale ,speed ,circleRadius ,}) => {constconfig =useVideoConfig ();constframe =useCurrentFrame ();constoverscanMargin = 100;constwidth =config .width +overscanMargin ;constheight =config .height +overscanMargin ;constrows =Math .round (height /scale );constcols =Math .round (width /scale );return (<>{newArray (cols ).fill (0).map ((_i ,i ) =>newArray (rows ).fill (0).map ((_j ,j ) => {constkey = `${i }-${j }`;constx =i *scale ;consty =j *scale ;constpx =i /cols ;constpy =j /rows ;constdx =xNoise3d (px ,py ,frame *speed ) *scale ;constdy =yNoise3d (px ,py ,frame *speed ) *scale ;constopacity =interpolate (opacityNoise3d (i ,j ,frame *speed ),[-1, 1],[0, 1],{easing :Easing .bezier (0.85, 0, 0.15, 1) });constcolor =Math .round (interpolate (colorNoise3d (px ,py ,frame *speed ),[-1, 1],[0, 1])) === 0 ? "0,87,184" : "254,221,0";return (<circle key ={key }cx ={x +dx }cy ={y +dy }r ={circleRadius }fill ={`rgba(${color }, ${opacity })`}/>);}))}</>);};constMyComposition :React .FC <Props > = (props ) => {const {width ,height } =useVideoConfig ();return (<AbsoluteFill ><svg width ={width }height ={height }><rect width ={width }height ={height }fill ="black" /><Background {...props } /><defs ><filter id ="blur"x ="0"y ="0"width ={width }height ={height }filterUnits ="userSpaceOnUse"colorInterpolationFilters ="sRGB"><feFlood floodOpacity ="0"result ="BackgroundImageFix" /><feBlend mode ="normal"in ="SourceGraphic"in2 ="BackgroundImageFix"result ="shape"/><feGaussianBlur stdDeviation ="50"result ="effect1_foregroundBlur" /></filter ></defs ></svg ></AbsoluteFill >);}export constNoiseDemo = () => {constfps = 30;const [scale ,setScale ] =useState (75);const [speed ,setSpeed ] =useState (0.01);const [circleRadius ,setCircleRadius ] =useState (5);constinputStyle =useMemo <React .CSSProperties >(() => ({width : 90,marginRight : 8}), []);constlabelStyle =useMemo <React .CSSProperties >(() => ({display : 'flex',flexDirection : 'row',alignItems : 'center',margin : 8,}), []);return (<><Player component ={MyComposition }compositionWidth ={1280}compositionHeight ={720}durationInFrames ={fps * 5}fps ={fps }style ={{width : "100%",border : "1px solid var(--ifm-color-emphasis-300)",borderRadius : "var(--ifm-pre-border-radius)",}}inputProps ={{scale ,speed ,circleRadius ,}}autoPlay loop /><div ><label style ={labelStyle }><input type ="range"min ={50} // don't set too low values, otherwise you're going to kill the DOM thread spawning lots of dotsmax ={200}step ={1}value ={scale }style ={inputStyle }onChange ={(e ) =>setScale (Number (e .target .value ))}/><code >{`scale={${scale }}`}</code ></label ><label style ={labelStyle }><input type ="range"min ={0.001}max ={0.025}step ={0.001}value ={speed }style ={inputStyle }onChange ={(e ) =>setSpeed (Number (e .target .value ))}/><code >{`speed={${speed }}`}</code ></label ><label style ={labelStyle }><input type ="range"min ={2}max ={20}step ={1}value ={circleRadius }style ={inputStyle }onChange ={(e ) =>setCircleRadius (Number (e .target .value ))}/><code >{`circleRadius={${circleRadius }}`}</code ></label ></div ></>);};
tsx
importReact , {useMemo ,useState } from "react";import {AbsoluteFill ,Easing ,interpolate ,useCurrentFrame ,useVideoConfig } from "remotion";import {Player } from "@remotion/player";import {createNoise3D } from "@remotion/noise";constxNoise3d =createNoise3D ("x");constyNoise3d =createNoise3D ("y");constopacityNoise3d =createNoise3D ("opacity");constcolorNoise3d =createNoise3D ("color");interfaceProps {scale : numberspeed : numbercircleRadius : number}constBackground :React .FC <Props > = ({scale ,speed ,circleRadius ,}) => {constconfig =useVideoConfig ();constframe =useCurrentFrame ();constoverscanMargin = 100;constwidth =config .width +overscanMargin ;constheight =config .height +overscanMargin ;constrows =Math .round (height /scale );constcols =Math .round (width /scale );return (<>{newArray (cols ).fill (0).map ((_i ,i ) =>newArray (rows ).fill (0).map ((_j ,j ) => {constkey = `${i }-${j }`;constx =i *scale ;consty =j *scale ;constpx =i /cols ;constpy =j /rows ;constdx =xNoise3d (px ,py ,frame *speed ) *scale ;constdy =yNoise3d (px ,py ,frame *speed ) *scale ;constopacity =interpolate (opacityNoise3d (i ,j ,frame *speed ),[-1, 1],[0, 1],{easing :Easing .bezier (0.85, 0, 0.15, 1) });constcolor =Math .round (interpolate (colorNoise3d (px ,py ,frame *speed ),[-1, 1],[0, 1])) === 0 ? "0,87,184" : "254,221,0";return (<circle key ={key }cx ={x +dx }cy ={y +dy }r ={circleRadius }fill ={`rgba(${color }, ${opacity })`}/>);}))}</>);};constMyComposition :React .FC <Props > = (props ) => {const {width ,height } =useVideoConfig ();return (<AbsoluteFill ><svg width ={width }height ={height }><rect width ={width }height ={height }fill ="black" /><Background {...props } /><defs ><filter id ="blur"x ="0"y ="0"width ={width }height ={height }filterUnits ="userSpaceOnUse"colorInterpolationFilters ="sRGB"><feFlood floodOpacity ="0"result ="BackgroundImageFix" /><feBlend mode ="normal"in ="SourceGraphic"in2 ="BackgroundImageFix"result ="shape"/><feGaussianBlur stdDeviation ="50"result ="effect1_foregroundBlur" /></filter ></defs ></svg ></AbsoluteFill >);}export constNoiseDemo = () => {constfps = 30;const [scale ,setScale ] =useState (75);const [speed ,setSpeed ] =useState (0.01);const [circleRadius ,setCircleRadius ] =useState (5);constinputStyle =useMemo <React .CSSProperties >(() => ({width : 90,marginRight : 8}), []);constlabelStyle =useMemo <React .CSSProperties >(() => ({display : 'flex',flexDirection : 'row',alignItems : 'center',margin : 8,}), []);return (<><Player component ={MyComposition }compositionWidth ={1280}compositionHeight ={720}durationInFrames ={fps * 5}fps ={fps }style ={{width : "100%",border : "1px solid var(--ifm-color-emphasis-300)",borderRadius : "var(--ifm-pre-border-radius)",}}inputProps ={{scale ,speed ,circleRadius ,}}autoPlay loop /><div ><label style ={labelStyle }><input type ="range"min ={50} // don't set too low values, otherwise you're going to kill the DOM thread spawning lots of dotsmax ={200}step ={1}value ={scale }style ={inputStyle }onChange ={(e ) =>setScale (Number (e .target .value ))}/><code >{`scale={${scale }}`}</code ></label ><label style ={labelStyle }><input type ="range"min ={0.001}max ={0.025}step ={0.001}value ={speed }style ={inputStyle }onChange ={(e ) =>setSpeed (Number (e .target .value ))}/><code >{`speed={${speed }}`}</code ></label ><label style ={labelStyle }><input type ="range"min ={2}max ={20}step ={1}value ={circleRadius }style ={inputStyle }onChange ={(e ) =>setCircleRadius (Number (e .target .value ))}/><code >{`circleRadius={${circleRadius }}`}</code ></label ></div ></>);};