({
className,
dpr,
paused = false,
colors = ['#A6C8FF', '#5227FF', '#FF9FFC'],
backgroundColor = '#0A29FF',
speed = 0.5,
streakCount = 2,
streakWidth = 1,
streakLength = 1,
glow = 1,
density = 0.6,
twinkle = 1,
zoom = 3,
backgroundGlow = 0.5,
opacity = 1,
mouseInteraction = true,
mouseStrength = 0.5,
mouseRadius = 1,
mouseDampening = 0.15,
mixBlendMode
})
| 192 | `; |
| 193 | |
| 194 | const Lightfall: React.FC<LightfallProps> = ({ |
| 195 | className, |
| 196 | dpr, |
| 197 | paused = false, |
| 198 | colors = ['#A6C8FF', '#5227FF', '#FF9FFC'], |
| 199 | backgroundColor = '#0A29FF', |
| 200 | speed = 0.5, |
| 201 | streakCount = 2, |
| 202 | streakWidth = 1, |
| 203 | streakLength = 1, |
| 204 | glow = 1, |
| 205 | density = 0.6, |
| 206 | twinkle = 1, |
| 207 | zoom = 3, |
| 208 | backgroundGlow = 0.5, |
| 209 | opacity = 1, |
| 210 | mouseInteraction = true, |
| 211 | mouseStrength = 0.5, |
| 212 | mouseRadius = 1, |
| 213 | mouseDampening = 0.15, |
| 214 | mixBlendMode |
| 215 | }) => { |
| 216 | const containerRef = useRef<HTMLDivElement | null>(null); |
| 217 | const rafRef = useRef<number | null>(null); |
| 218 | const programRef = useRef<Program | null>(null); |
| 219 | const meshRef = useRef<Mesh | null>(null); |
| 220 | const geometryRef = useRef<Triangle | null>(null); |
| 221 | const rendererRef = useRef<Renderer | null>(null); |
| 222 | const mouseTargetRef = useRef<[number, number]>([0, 0]); |
| 223 | const lastTimeRef = useRef(0); |
| 224 | |
| 225 | useEffect(() => { |
| 226 | const container = containerRef.current; |
| 227 | if (!container) return; |
| 228 | |
| 229 | const renderer = new Renderer({ |
| 230 | dpr: dpr ?? (typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1), |
| 231 | alpha: true, |
| 232 | antialias: true |
| 233 | }); |
| 234 | rendererRef.current = renderer; |
| 235 | const gl = renderer.gl; |
| 236 | const canvas = gl.canvas as HTMLCanvasElement; |
| 237 | |
| 238 | canvas.style.width = '100%'; |
| 239 | canvas.style.height = '100%'; |
| 240 | canvas.style.display = 'block'; |
| 241 | container.appendChild(canvas); |
| 242 | |
| 243 | const { arr, count, avg } = prepColors(colors); |
| 244 | |
| 245 | const uniforms = { |
| 246 | iResolution: { value: [gl.drawingBufferWidth, gl.drawingBufferHeight, 1] }, |
| 247 | iMouse: { value: [0, 0] }, |
| 248 | iTime: { value: 0 }, |
| 249 | uColor0: { value: arr[0] }, |
| 250 | uColor1: { value: arr[1] }, |
| 251 | uColor2: { value: arr[2] }, |
nothing calls this directly
no test coverage detected