← All components Next componentHyperspace Starfield→
Background · Energy
Volumetric Aura
A turbulent energy sphere that follows the cursor and stretches like a comet as it moves.
<VolumetricAuraBackground />Live
It follows your cursor
Customize
Core#fdf4ff
Glow#a855f7
Installation
Use it in your project
Or skip the copy-paste
One command: writes the file and installs the dependencies.
$ npx deepui-cli add volumetric-aura
01
Install
The 3D packages this component is built on.
$ npm install three @react-three/fiber @react-three/postprocessing postprocessing && npm install -D @types/three
02
Add the component
One self-contained file: create components/VolumetricAuraBackground.tsx and paste it in.
components/VolumetricAuraBackground.tsx
1"use client";23import {4 memo,5 useEffect,6 useMemo,7 useRef,8 useState,9 type CSSProperties,10 type ReactNode,11 type RefObject,12} from "react";13import * as THREE from "three";14import { Canvas, useFrame, useThree, type CanvasProps } from "@react-three/fiber";15import { Bloom, EffectComposer, Vignette } from "@react-three/postprocessing";1617/**18 * The shared props API of DeepUI's individual 3D components (not the full-page templates, which keep19 * their own tailored scenes).20 *21 * The props are grouped by concern. A component extends ONLY the groups it really applies, so its22 * type never advertises a knob that does nothing (a card has no particles, a background has no tilt):23 *24 * interface MyCardProps extends CursorProps, TiltProps, MaterialProps, PerformanceProps { … }25 *26 * `Base3DComponentProps` is every group at once, for tooling that handles any component. Same name,27 * same unit and same meaning everywhere; the default values live in DEFAULT_3D_PROPS. These files are28 * inlined into each component's single-file bundle (lib/bundle-source.mjs), only what it uses.29 */3031/** Which rotation axes follow the pointer. "x-only": the object nods (up / down); "y-only": it turns (left / right). */32export type TiltAxis = "both" | "x-only" | "y-only" | "none";3334/** 1. Cursor: how the pointer pulls, pushes and drags the object. */35interface CursorProps {36 /** Reach of the pointer's influence, in the component's own space: CSS pixels for pixel-laid-out widgets, world units for 3D scenes (each component says which). Default 220 (px). */37 cursorRadius?: number;38 /** Positive pulls things towards the pointer, negative pushes them away (repulsion, shockwave). Default 1. */39 cursorForce?: number;40 /** How far the object slides towards the pointer, 0 (stays put) to 1 (follows closely). Default 0. */41 magneticStrength?: number;42 /** Share of the remaining distance the motion closes each frame (at 60 fps), 0.01 (heavy, slow) to 1 (instant). Default 0.1. */43 cursorDamping?: number;44}4546/** 2. Tilt and parallax: the object leans towards the pointer, its layers slide against each other. */47interface TiltProps {48 /** Largest lean towards the pointer, in degrees. Default 15. */49 maxTiltAngle?: number;50 /** Axes that follow the pointer. Default "both". */51 tiltAxis?: TiltAxis;52 /** Lean away from the pointer instead of towards it. Default false. */53 invertTilt?: boolean;54 /** How far apart the depth layers slide when the object tilts, 0 (flat) to 2. Default 1. */55 parallaxOffset?: number;56}5758/** 3. Text and 3D typography, for components that draw a label. */59interface Text3DProps {60 /** The label drawn by the component. */61 text?: string;62 /** Scale of the lettering. Default 1. */63 fontSize?: number;64 /** Extrusion depth of 3D letters. Default 0.2. */65 textDepth?: number;66 /** Bevelled, light-catching edges on 3D letters. Default true. */67 bevelEnabled?: boolean;68 /** Custom font: a .woff / .ttf (flat text) or a typeface .json (extruded text). */69 fontUrl?: string;70}7172/** 4. Rendering, materials and glow. */73interface MaterialProps {74 /** Main color of the object. Default "#6366f1". */75 primaryColor?: string;76 /** Color of the glow. Default "#00f0ff". */77 emissiveColor?: string;78 /** Strength of the glow, 0 (none) to 3. Default 1. */79 emissiveIntensity?: number;80 /** 0 (mirror, glass) to 1 (matte). Default 0.3. */81 roughness?: number;82 /** 0 (plastic, organic) to 1 (metal). Default 0.5. */83 metalness?: number;84 /** 0 (opaque) to 1 (clear glass): see-through, refracting surfaces. Default 0. */85 transmission?: number;86 /** Technical wireframe rendering. Default false. */87 wireframe?: boolean;88}8990/** 5. Particles, idle motion and shader animation. */91interface MotionProps {92 /** Number of instanced elements. Default depends on the component. */93 particleCount?: number;94 /** Spin on its own, in radians per second (negative: the other way; 0.5 ≈ one turn in 12 s). Default 0. */95 autoRotateSpeed?: number;96 /** Pulses or ripples per second. Default 1. */97 pulseRate?: number;98 /** Amplitude of the noise deformation, 0 (none) to 2. Default 1. */99 displacementScale?: number;100}101102/** 6. Environment and camera. */103interface EnvironmentProps {104 /** Camera field of view, in degrees. Default depends on the component. */105 cameraFov?: number;106 /** Color of the depth fog. Default "#0a0a0a". */107 fogColor?: string;108 /** Thickness of the fog, 0 (none) to 0.2. Default 0. */109 fogDensity?: number;110}111112/** 7. Performance and accessibility. */113interface PerformanceProps {114 /** Lighter rendering for weak devices: pixel ratio 1, fewer instances, smaller environment maps. Default false. */115 lowPowerMode?: boolean;116 /** Under the OS "reduce motion" setting, stop idle spin, pulses and deformation (pointer feedback stays). Default true. */117 respectReducedMotion?: boolean;118 /** Stop the render loop while the component is scrolled out of view. Default true. */119 pauseWhenOffscreen?: boolean;120}121122/** Every group at once. Components extend only the groups they apply (see the top of this file). */123interface Base3DComponentProps124 extends CursorProps,125 TiltProps,126 Text3DProps,127 MaterialProps,128 MotionProps,129 EnvironmentProps,130 PerformanceProps {}131132type Defaults = Required<Omit<Base3DComponentProps, "text" | "fontUrl" | "particleCount" | "cameraFov">>;133134/** The values a prop takes when it is left out. A component may override one, and then documents it. */135const DEFAULT_3D_PROPS: Defaults = {136 cursorRadius: 220,137 cursorForce: 1,138 magneticStrength: 0,139 cursorDamping: 0.1,140 maxTiltAngle: 15,141 tiltAxis: "both",142 invertTilt: false,143 parallaxOffset: 1,144 fontSize: 1,145 textDepth: 0.2,146 bevelEnabled: true,147 primaryColor: "#6366f1",148 emissiveColor: "#00f0ff",149 emissiveIntensity: 1,150 roughness: 0.3,151 metalness: 0.5,152 transmission: 0,153 wireframe: false,154 autoRotateSpeed: 0,155 pulseRate: 1,156 displacementScale: 1,157 fogColor: "#0a0a0a",158 fogDensity: 0,159 lowPowerMode: false,160 respectReducedMotion: true,161 pauseWhenOffscreen: true,162};163164/** Fills the positioned parent; never intercepts clicks meant for the page content above it. */165const FILL_STYLE: CSSProperties = {166 position: "absolute",167 top: 0,168 left: 0,169 width: "100%",170 height: "100%",171 pointerEvents: "none",172};173174interface BackgroundCanvasProps extends Omit<CanvasProps, "children" | "style" | "frameloop" | "gl">, Pick<PerformanceProps, "pauseWhenOffscreen" | "lowPowerMode"> {175 children: ReactNode;176}177178/**179 * Ready-to-use <Canvas> shared by every background.180 * - Pauses the render loop while the canvas is scrolled out of view.181 * - Renders a single still frame when the user prefers reduced motion.182 * - Caps the pixel ratio; R3F disposes the renderer and releases the WebGL183 * context (forceContextLoss) when the Canvas unmounts.184 */185function BackgroundCanvas({ children, dpr = [1, 1.75], pauseWhenOffscreen = DEFAULT_3D_PROPS.pauseWhenOffscreen, lowPowerMode = DEFAULT_3D_PROPS.lowPowerMode, ...canvasProps }: BackgroundCanvasProps) {186 const containerRef = useRef<HTMLDivElement>(null);187 // Starts "in view" so the first frame is always drawn before the loop can be paused188 const [inView, setInView] = useState(true);189 const [reducedMotion, setReducedMotion] = useState(false);190191 useEffect(() => {192 const el = containerRef.current;193 if (!el) return undefined;194 const observer = new IntersectionObserver(([entry]) => setInView(entry.isIntersecting));195 observer.observe(el);196197 const query = window.matchMedia("(prefers-reduced-motion: reduce)");198 const sync = () => setReducedMotion(query.matches);199 sync();200 query.addEventListener("change", sync);201202 return () => {203 observer.disconnect();204 query.removeEventListener("change", sync);205 };206 }, []);207208 return (209 <div ref={containerRef} style={FILL_STYLE} aria-hidden="true">210 <Canvas211 dpr={lowPowerMode ? 1 : dpr}212 frameloop={!inView && pauseWhenOffscreen ? "never" : reducedMotion ? "demand" : "always"}213 gl={{ antialias: true, alpha: true, powerPreference: "high-performance" }}214 style={{ pointerEvents: "none" }}215 {...canvasProps}216 >217 {children}218 </Canvas>219 </div>220 );221}222223interface CanvasPointer {224 /** Pointer position in normalized device coordinates of the canvas (-1..1). */225 ndc: THREE.Vector2;226 /** True while the pointer is over the canvas area. */227 inside: boolean;228 /** True while a button is held down. */229 pressed: boolean;230}231232/**233 * Tracks the pointer relative to the canvas through window listeners: the234 * canvas itself has `pointer-events: none`, so R3F's own events never fire.235 * Returns a ref read inside useFrame — pointer moves never re-render React.236 */237function useCanvasPointer(onDown?: (ndc: THREE.Vector2) => void): RefObject<CanvasPointer> {238 const gl = useThree((state) => state.gl);239 const pointer = useRef<CanvasPointer>({ ndc: new THREE.Vector2(), inside: false, pressed: false });240 const onDownRef = useRef(onDown);241242 useEffect(() => {243 onDownRef.current = onDown;244 }, [onDown]);245246 useEffect(() => {247 const el = gl.domElement;248 const update = (event: PointerEvent) => {249 const rect = el.getBoundingClientRect();250 const p = pointer.current;251 p.ndc.set(((event.clientX - rect.left) / rect.width) * 2 - 1, -((event.clientY - rect.top) / rect.height) * 2 + 1);252 p.inside = Math.abs(p.ndc.x) <= 1 && Math.abs(p.ndc.y) <= 1;253 };254 const down = (event: PointerEvent) => {255 update(event);256 pointer.current.pressed = true;257 if (pointer.current.inside) onDownRef.current?.(pointer.current.ndc);258 };259 const up = () => {260 pointer.current.pressed = false;261 };262 const leave = () => {263 pointer.current.inside = false;264 pointer.current.pressed = false;265 };266267 window.addEventListener("pointermove", update, { passive: true });268 window.addEventListener("pointerdown", down, { passive: true });269 window.addEventListener("pointerup", up, { passive: true });270 document.documentElement.addEventListener("pointerleave", leave);271 window.addEventListener("blur", leave);272 return () => {273 window.removeEventListener("pointermove", update);274 window.removeEventListener("pointerdown", down);275 window.removeEventListener("pointerup", up);276 document.documentElement.removeEventListener("pointerleave", leave);277 window.removeEventListener("blur", leave);278 };279 }, [gl]);280281 return pointer;282}283284const unprojected = new THREE.Vector3();285286const rayDirection = new THREE.Vector3();287288/** Screen (NDC) → world space: intersects the camera ray with the plane z = planeZ. */289function ndcToWorldOnPlane(ndc: THREE.Vector2, camera: THREE.Camera, planeZ: number, target: THREE.Vector3) {290 unprojected.set(ndc.x, ndc.y, 0.5).unproject(camera);291 rayDirection.copy(unprojected).sub(camera.position).normalize();292 const distance = (planeZ - camera.position.z) / rayDirection.z;293 return target.copy(camera.position).addScaledVector(rayDirection, distance);294}295296/**297 * Shared GLSL noise functions, injected into the background shaders as strings.298 *299 * Both are the classic webgl-noise implementations by Ian McEwan and Stefan300 * Gustavson (Ashima Arts), MIT License — https://github.com/ashima/webgl-noise301 */302303/** 3D simplex noise: `float snoise(vec3 v)`, returns roughly -1..1. */304const SIMPLEX_3D = /* glsl */ `305vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }306vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }307vec4 permute(vec4 x) { return mod289(((x * 34.0) + 10.0) * x); }308vec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; }309310float snoise(vec3 v) {311 const vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);312 const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);313314 vec3 i = floor(v + dot(v, C.yyy));315 vec3 x0 = v - i + dot(i, C.xxx);316317 vec3 g = step(x0.yzx, x0.xyz);318 vec3 l = 1.0 - g;319 vec3 i1 = min(g.xyz, l.zxy);320 vec3 i2 = max(g.xyz, l.zxy);321322 vec3 x1 = x0 - i1 + C.xxx;323 vec3 x2 = x0 - i2 + C.yyy;324 vec3 x3 = x0 - D.yyy;325326 i = mod289(i);327 vec4 p = permute(permute(permute(328 i.z + vec4(0.0, i1.z, i2.z, 1.0))329 + i.y + vec4(0.0, i1.y, i2.y, 1.0))330 + i.x + vec4(0.0, i1.x, i2.x, 1.0));331332 float n_ = 0.142857142857;333 vec3 ns = n_ * D.wyz - D.xzx;334335 vec4 j = p - 49.0 * floor(p * ns.z * ns.z);336 vec4 x_ = floor(j * ns.z);337 vec4 y_ = floor(j - 7.0 * x_);338339 vec4 x = x_ * ns.x + ns.yyyy;340 vec4 y = y_ * ns.x + ns.yyyy;341 vec4 h = 1.0 - abs(x) - abs(y);342343 vec4 b0 = vec4(x.xy, y.xy);344 vec4 b1 = vec4(x.zw, y.zw);345 vec4 s0 = floor(b0) * 2.0 + 1.0;346 vec4 s1 = floor(b1) * 2.0 + 1.0;347 vec4 sh = -step(h, vec4(0.0));348349 vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;350 vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;351352 vec3 p0 = vec3(a0.xy, h.x);353 vec3 p1 = vec3(a0.zw, h.y);354 vec3 p2 = vec3(a1.xy, h.z);355 vec3 p3 = vec3(a1.zw, h.w);356357 vec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));358 p0 *= norm.x;359 p1 *= norm.y;360 p2 *= norm.z;361 p3 *= norm.w;362363 vec4 m = max(0.5 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);364 m = m * m;365 return 105.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));366}367`;368369export interface VolumetricAuraProps extends Pick<MaterialProps, "primaryColor" | "emissiveColor">, Pick<PerformanceProps, "pauseWhenOffscreen" | "lowPowerMode"> {370 /** Color of the bright heart of the sphere. */371 primaryColor?: string;372 /** @deprecated Use `primaryColor`. */373 coreColor?: string;374 /** Color of the rim, filaments, halo and sparks. */375 emissiveColor?: string;376 /** @deprecated Use `emissiveColor`. */377 glowColor?: string;378 /** Frequency of the turbulence. Default 1.5. */379 noiseDensity?: number;380 turbulenceSpeed?: number;381 /** Radius of the sphere, in world units. Default 1.8. */382 auraRadius?: number;383 /** The aura follows the cursor and stretches like a comet when it moves. Default true. */384 interactive?: boolean;385}386387const SPARK_COUNT = 900;388const Y_AXIS = new THREE.Vector3(0, 1, 0);389390// Shared by every layer: noise, FBM, the swirl of the noise domain, and the comet stretch391const AURA_COMMON = /* glsl */ `392uniform float uTime;393uniform float uDensity;394uniform vec3 uStretch; // smoothed velocity of the aura, object space395396${SIMPLEX_3D}397398float fbm(vec3 p) {399 float sum = 0.0;400 float amplitude = 0.5;401 for (int i = 0; i < 3; i++) {402 sum += snoise(p) * amplitude;403 p = p * 2.03 + 11.7;404 amplitude *= 0.5;405 }406 return sum;407}408409// The noise domain turns around Y over time: the turbulence swirls instead of just scrolling410vec3 swirl(vec3 p) {411 float a = uTime * 0.35 + p.y * 0.6;412 float c = cos(a);413 float s = sin(a);414 return vec3(c * p.x - s * p.z, p.y, s * p.x + c * p.z);415}416417// Comet: the side facing away from the motion is pulled into a tail418vec3 stretchPosition(vec3 p, vec3 n) {419 float strength = length(uStretch);420 if (strength < 0.0001) return p;421 vec3 dir = uStretch / strength;422 float back = max(dot(n, -dir), 0.0);423 return p - dir * back * back * strength * 1.4;424}425`;426427const coreVertexShader = /* glsl */ `428${AURA_COMMON}429varying vec3 vObject;430varying vec3 vNormalW;431varying vec3 vWorld;432433void main() {434 float n = fbm(swirl(normal * uDensity) + uTime * 0.2);435 vec3 p = position * (1.0 + n * 0.14);436 p = stretchPosition(p, normal);437 vObject = position;438 vNormalW = normalize(mat3(modelMatrix) * normal);439 vec4 world = modelMatrix * vec4(p, 1.0);440 vWorld = world.xyz;441 gl_Position = projectionMatrix * viewMatrix * world;442}443`;444445const coreFragmentShader = /* glsl */ `446${AURA_COMMON}447uniform vec3 uCore;448uniform vec3 uGlow;449uniform float uRadius;450varying vec3 vObject;451varying vec3 vNormalW;452varying vec3 vWorld;453454void main() {455 vec3 viewDir = normalize(cameraPosition - vWorld);456 float facing = max(dot(normalize(vNormalW), viewDir), 0.0);457 float fresnel = pow(1.0 - facing, 2.2);458459 vec3 q = swirl(vObject / uRadius * uDensity);460 float cloud = fbm(q + uTime * 0.15) * 0.5 + 0.5;461 // Ridged noise: bright energy filaments462 float filaments = pow(1.0 - abs(snoise(q * 1.7 - uTime * 0.25)), 8.0);463464 // HDR values (> 1): the bloom turns them into light465 vec3 color = uCore * pow(facing, 4.0) * smoothstep(0.35, 0.9, cloud) * 1.1;466 color += uGlow * (0.12 + cloud * 0.25) * facing;467 color += uGlow * fresnel * 1.8;468 color += mix(uGlow, uCore, 0.5) * filaments * (0.35 + fresnel) * 1.5;469 gl_FragColor = vec4(color, 1.0);470 #include <colorspace_fragment>471}472`;473474const haloVertexShader = /* glsl */ `475${AURA_COMMON}476varying vec3 vNormalW;477varying vec3 vWorld;478varying vec3 vObject;479480void main() {481 vec3 p = stretchPosition(position, normal);482 vObject = position;483 vNormalW = normalize(mat3(modelMatrix) * normal);484 vec4 world = modelMatrix * vec4(p, 1.0);485 vWorld = world.xyz;486 gl_Position = projectionMatrix * viewMatrix * world;487}488`;489490const haloFragmentShader = /* glsl */ `491${AURA_COMMON}492uniform vec3 uGlow;493varying vec3 vNormalW;494varying vec3 vWorld;495varying vec3 vObject;496497void main() {498 // Back faces of a larger sphere: brightest just outside the core's edge, fading outwards499 vec3 viewDir = normalize(cameraPosition - vWorld);500 float facing = max(dot(-normalize(vNormalW), viewDir), 0.0);501 float glow = pow(facing, 3.5);502 // Wispy rays: noise on the direction, slowly turning503 float rays = fbm(swirl(normalize(vObject) * 3.0) + uTime * 0.1) * 0.5 + 0.5;504 gl_FragColor = vec4(uGlow * glow * (0.25 + rays * 0.8) * 0.9, 1.0);505 #include <colorspace_fragment>506}507`;508509const sparksVertexShader = /* glsl */ `510${AURA_COMMON}511uniform float uRadius;512uniform float uPixelRatio;513attribute vec3 aOrbit; // angle, inclination, distance factor514attribute float aSeed;515varying float vAlpha;516517void main() {518 // Each spark orbits on its own tilted ring, faster close to the surface519 float speed = (0.25 + aSeed * 0.5) / aOrbit.z;520 float angle = aOrbit.x + uTime * speed;521 float r = uRadius * aOrbit.z;522 vec3 p = vec3(cos(angle) * r, sin(aOrbit.y) * sin(angle) * r * 0.6, cos(aOrbit.y) * sin(angle) * r);523 p += snoise(p * 0.8 + uTime * 0.3) * 0.15 * uRadius;524 p = stretchPosition(p, normalize(p));525526 vec4 mv = modelViewMatrix * vec4(p, 1.0);527 gl_Position = projectionMatrix * mv;528 gl_PointSize = (1.5 + aSeed * 3.0) * uPixelRatio * (8.0 / -mv.z);529 vAlpha = 0.65 + 0.35 * sin(uTime * (1.0 + aSeed * 3.0) + aSeed * 40.0); // twinkle530}531`;532533const sparksFragmentShader = /* glsl */ `534uniform vec3 uGlow;535varying float vAlpha;536537void main() {538 float d = length(gl_PointCoord - 0.5);539 float a = 1.0 - smoothstep(0.0, 0.5, d);540 gl_FragColor = vec4(mix(uGlow, vec3(1.0), 0.5) * 2.0, a * vAlpha);541 #include <colorspace_fragment>542}543`;544545const Aura = memo(function Aura({ coreColor, glowColor, noiseDensity, turbulenceSpeed, auraRadius, interactive }: Required<Omit<VolumetricAuraProps, "primaryColor" | "emissiveColor" | "pauseWhenOffscreen" | "lowPowerMode">>) {546 const groupRef = useRef<THREE.Group>(null);547 const pointer = useCanvasPointer();548 const time = useRef(0);549 const motion = useMemo(550 () => ({ target: new THREE.Vector3(), previous: new THREE.Vector3(), velocity: new THREE.Vector3(), hit: new THREE.Vector3() }),551 []552 );553554 const coreGeometry = useMemo(() => new THREE.SphereGeometry(1, 128, 128), []);555 const haloGeometry = useMemo(() => new THREE.SphereGeometry(1, 64, 64), []);556 const sparksGeometry = useMemo(() => {557 const orbit = new Float32Array(SPARK_COUNT * 3);558 const seeds = new Float32Array(SPARK_COUNT);559 for (let i = 0; i < SPARK_COUNT; i++) {560 orbit[i * 3] = Math.random() * Math.PI * 2;561 orbit[i * 3 + 1] = Math.random() * Math.PI * 2;562 orbit[i * 3 + 2] = 1.15 + Math.pow(Math.random(), 1.8) * 1.3;563 seeds[i] = Math.random();564 }565 const g = new THREE.BufferGeometry();566 // Positions are computed in the shader; the attribute only sets the vertex count567 g.setAttribute("position", new THREE.BufferAttribute(new Float32Array(SPARK_COUNT * 3), 3));568 g.setAttribute("aOrbit", new THREE.BufferAttribute(orbit, 3));569 g.setAttribute("aSeed", new THREE.BufferAttribute(seeds, 1));570 return g;571 }, []);572573 const materials = useMemo(() => {574 // One set of uniforms shared by all three layers575 const shared = {576 uTime: { value: 0 },577 uDensity: { value: 1.5 },578 uStretch: { value: new THREE.Vector3() },579 uRadius: { value: 1.8 },580 uGlow: { value: new THREE.Color() },581 uCore: { value: new THREE.Color() },582 uPixelRatio: { value: 1 },583 };584 const additive = { transparent: true, depthWrite: false, blending: THREE.AdditiveBlending } as const;585 return {586 shared,587 core: new THREE.ShaderMaterial({ uniforms: shared, vertexShader: coreVertexShader, fragmentShader: coreFragmentShader, ...additive }),588 halo: new THREE.ShaderMaterial({589 uniforms: shared,590 vertexShader: haloVertexShader,591 fragmentShader: haloFragmentShader,592 side: THREE.BackSide,593 ...additive,594 }),595 sparks: new THREE.ShaderMaterial({ uniforms: shared, vertexShader: sparksVertexShader, fragmentShader: sparksFragmentShader, ...additive }),596 };597 }, []);598599 useEffect(() => {600 const s = materials.shared;601 s.uDensity.value = noiseDensity;602 s.uRadius.value = auraRadius;603 s.uCore.value.set(coreColor);604 s.uGlow.value.set(glowColor);605 }, [materials, noiseDensity, auraRadius, coreColor, glowColor]);606607 useEffect(608 () => () => {609 coreGeometry.dispose();610 haloGeometry.dispose();611 sparksGeometry.dispose();612 },613 [coreGeometry, haloGeometry, sparksGeometry]614 );615 useEffect(616 () => () => {617 materials.core.dispose();618 materials.halo.dispose();619 materials.sparks.dispose();620 },621 [materials]622 );623624 useFrame((state, delta) => {625 const group = groupRef.current;626 if (!group) return;627 const dt = Math.min(delta, 1 / 30);628 time.current += dt * turbulenceSpeed;629 const s = materials.shared;630 s.uTime.value = time.current;631 s.uPixelRatio.value = state.viewport.dpr;632633 // Target: a third of the way to the cursor, or a slow figure-eight drift on its own634 const p = pointer.current;635 const t = state.clock.elapsedTime;636 if (interactive && p.inside) {637 ndcToWorldOnPlane(p.ndc, state.camera, 0, motion.hit);638 motion.target.copy(motion.hit).multiplyScalar(0.35);639 } else {640 motion.target.set(Math.sin(t * 0.4) * 0.6, Math.sin(t * 0.8) * 0.3, 0);641 }642 motion.previous.copy(group.position);643 group.position.lerp(motion.target, 1 - Math.exp(-3 * dt));644645 // Velocity → comet stretch, smoothed and clamped646 const velocity = motion.hit.subVectors(group.position, motion.previous).divideScalar(Math.max(dt, 1e-4));647 motion.velocity.lerp(velocity, 1 - Math.exp(-6 * dt));648 s.uStretch.value.copy(motion.velocity).multiplyScalar(0.12).clampLength(0, 1.2);649650 group.rotation.y += dt * 0.15 * turbulenceSpeed;651 // The stretch is in object space: undo the group's spin so the tail stays behind the motion652 s.uStretch.value.applyAxisAngle(Y_AXIS, -group.rotation.y);653 });654655 return (656 <group ref={groupRef}>657 <mesh geometry={haloGeometry} material={materials.halo} scale={auraRadius * 1.7} />658 <mesh geometry={coreGeometry} material={materials.core} scale={auraRadius} />659 <points geometry={sparksGeometry} material={materials.sparks} frustumCulled={false} />660 </group>661 );662});663664function VolumetricAuraBackground({665 primaryColor,666 coreColor = primaryColor ?? "#fdf4ff",667 emissiveColor,668 glowColor = emissiveColor ?? "#a855f7",669 noiseDensity = 1.5,670 turbulenceSpeed = 1,671 auraRadius = 1.8,672 interactive = true,673 pauseWhenOffscreen,674 lowPowerMode,675}: VolumetricAuraProps) {676 return (677 <BackgroundCanvas pauseWhenOffscreen={pauseWhenOffscreen} lowPowerMode={lowPowerMode} camera={{ position: [0, 0, 9], fov: 45 }}>678 <Aura679 coreColor={coreColor}680 glowColor={glowColor}681 noiseDensity={noiseDensity}682 turbulenceSpeed={turbulenceSpeed}683 auraRadius={auraRadius}684 interactive={interactive}685 />686 <EffectComposer multisampling={0}>687 <Bloom mipmapBlur intensity={1.0} luminanceThreshold={0.65} luminanceSmoothing={0.3} />688 <Vignette offset={0.25} darkness={0.7} />689 </EffectComposer>690 </BackgroundCanvas>691 );692}693694export default memo(VolumetricAuraBackground);
03
Drop it in a page
Updated live with the settings above.
app/page.tsx
1import VolumetricAuraBackground from "@/components/VolumetricAuraBackground";23export default function Section() {4 return (5 // The component fills this box: give it a position and a height6 <div style={{ position: "relative", width: "100%", height: "100vh" }}>7 <VolumetricAuraBackground8 auraRadius={1.8}9 noiseDensity={1.5}10 turbulenceSpeed={1}11 primaryColor="#fdf4ff"12 emissiveColor="#a855f7"13 />14 </div>15 );16}