AuroraRibbons
threecn/aurora-ribbonsFreeComponent
Silky aurora ribbons drifting in slow sine waves, shaded with a --primary → --accent gradient.
Install it
npx shadcn@latest add https://threecn.dev/r/aurora-ribbons.jsonSource
1"use client"23import * as React from "react"4import { useFrame } from "@react-three/fiber"5import * as THREE from "three"67import {8 SceneContainer,9 type SceneContainerProps,10} from "@/components/threecn/scene-container"11import {12 useShadcnTheme,13 type ThemeMode,14} from "@/components/hooks/use-shadcn-theme"1516const VERTEX_SHADER = /* glsl */ `17 varying vec2 vUv;18 void main() {19 vUv = uv;20 gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);21 }22`2324const FRAGMENT_SHADER = /* glsl */ `25 uniform vec3 uColorA;26 uniform vec3 uColorB;27 uniform float uOpacity;28 varying vec2 vUv;29 void main() {30 vec3 color = mix(uColorA, uColorB, vUv.x);31 float along = sin(vUv.x * 3.14159265);32 float edge = sin(vUv.y * 3.14159265);33 float alpha = along * pow(edge, 1.6) * uOpacity;34 gl_FragColor = vec4(color, alpha);35 }36`3738function Ribbon({39 index,40 total,41 speed,42 amplitude,43 colorA,44 colorB,45 isDark,46}: {47 index: number48 total: number49 speed: number50 amplitude: number51 colorA: THREE.Color52 colorB: THREE.Color53 isDark: boolean54}) {55 const meshRef = React.useRef<THREE.Mesh>(null)56 const materialRef = React.useRef<THREE.ShaderMaterial>(null)57 /** Pristine plane Y positions, captured on the first frame. */58 const baseYRef = React.useRef<Float32Array | null>(null)5960 const phase = (index / total) * Math.PI * 261 const zOffset = (index - (total - 1) / 2) * 0.762 const yOffset = (index - (total - 1) / 2) * 0.36364 const uniforms = React.useMemo(65 () => ({66 uColorA: { value: new THREE.Color() },67 uColorB: { value: new THREE.Color() },68 uOpacity: { value: 0.55 },69 }),70 []71 )7273 useFrame(({ clock }) => {74 const mesh = meshRef.current75 const material = materialRef.current76 if (!mesh || !material) return7778 const t = clock.getElapsedTime() * speed79 const pos = mesh.geometry.getAttribute("position") as THREE.BufferAttribute8081 if (!baseYRef.current || baseYRef.current.length !== pos.count) {82 const base = new Float32Array(pos.count)83 for (let i = 0; i < pos.count; i++) base[i] = pos.getY(i)84 baseYRef.current = base85 }86 const baseY = baseYRef.current8788 for (let i = 0; i < pos.count; i++) {89 const x = pos.getX(i)90 const wave =91 Math.sin(x * 0.5 + t * 0.8 + phase) * amplitude +92 Math.sin(x * 0.85 - t * 0.5 + phase * 1.7) * amplitude * 0.3593 pos.setY(i, baseY[i] + wave + yOffset)94// … truncated
What it pulls in
npm packages
Files it writes
More from threecn
All 28 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Boidsboids | threecn | Components | Free | 3 deps · 3 files | |
| Clothcloth | threecn | Components | Free | 3 deps · 3 files | |
| Crystalcrystal | threecn | Components | Free | 3 deps · 3 files | |
| CubeWavecube-wave | threecn | Components | Free | 3 deps · 3 files | |
| CurlFlowcurl-flow | threecn | Components | Free | 3 deps · 3 files | |
| DnaHelixdna-helix | threecn | Components | Free | 3 deps · 3 files | |
| FloatingCard3Dfloating-card-3d | threecn | Components | Free | 3 deps · 3 files | |
| Globeglobe | threecn | Components | Free | 3 deps · 3 files |
