Loading…
← All components

Cursors · Cursor

Chrome Blob Cursor

A liquid-chrome blob that follows the pointer and swells, turning translucent, over links and buttons.

Hover this linkdata-cursor-hover
<CursorBlob3D />Live

Customize

Color#e4e4e7

Installation

Use it in your project

Or skip the copy-paste

One command: writes the file and installs the dependencies.

$ npx deepui-cli add cursor-blob
01

Install

The 3D packages this component is built on.

$ npm install three @react-three/fiber @react-three/drei && npm install -D @types/three
02

Add the component

One self-contained file: create components/CursorBlob3D.tsx and paste it in.

components/CursorBlob3D.tsx
1"use client";
2
3import {
4 memo,
5 useEffect,
6 useLayoutEffect,
7 useMemo,
8 useRef,
9 useState,
10 type CSSProperties,
11 type ReactNode,
12} from "react";
13import * as THREE from "three";
14import { Canvas, useFrame, useThree, type CanvasProps } from "@react-three/fiber";
15import { Environment, Lightformer } from "@react-three/drei";
16
17/**
18 * Shared GLSL noise functions, injected into the background shaders as strings.
19 *
20 * Both are the classic webgl-noise implementations by Ian McEwan and Stefan
21 * Gustavson (Ashima Arts), MIT License — https://github.com/ashima/webgl-noise
22 */
23
24/** 3D simplex noise: `float snoise(vec3 v)`, returns roughly -1..1. */
25const SIMPLEX_3D = /* glsl */ `
26vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
27vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
28vec4 permute(vec4 x) { return mod289(((x * 34.0) + 10.0) * x); }
29vec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; }
30
31float snoise(vec3 v) {
32 const vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);
33 const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);
34
35 vec3 i = floor(v + dot(v, C.yyy));
36 vec3 x0 = v - i + dot(i, C.xxx);
37
38 vec3 g = step(x0.yzx, x0.xyz);
39 vec3 l = 1.0 - g;
40 vec3 i1 = min(g.xyz, l.zxy);
41 vec3 i2 = max(g.xyz, l.zxy);
42
43 vec3 x1 = x0 - i1 + C.xxx;
44 vec3 x2 = x0 - i2 + C.yyy;
45 vec3 x3 = x0 - D.yyy;
46
47 i = mod289(i);
48 vec4 p = permute(permute(permute(
49 i.z + vec4(0.0, i1.z, i2.z, 1.0))
50 + i.y + vec4(0.0, i1.y, i2.y, 1.0))
51 + i.x + vec4(0.0, i1.x, i2.x, 1.0));
52
53 float n_ = 0.142857142857;
54 vec3 ns = n_ * D.wyz - D.xzx;
55
56 vec4 j = p - 49.0 * floor(p * ns.z * ns.z);
57 vec4 x_ = floor(j * ns.z);
58 vec4 y_ = floor(j - 7.0 * x_);
59
60 vec4 x = x_ * ns.x + ns.yyyy;
61 vec4 y = y_ * ns.x + ns.yyyy;
62 vec4 h = 1.0 - abs(x) - abs(y);
63
64 vec4 b0 = vec4(x.xy, y.xy);
65 vec4 b1 = vec4(x.zw, y.zw);
66 vec4 s0 = floor(b0) * 2.0 + 1.0;
67 vec4 s1 = floor(b1) * 2.0 + 1.0;
68 vec4 sh = -step(h, vec4(0.0));
69
70 vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;
71 vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;
72
73 vec3 p0 = vec3(a0.xy, h.x);
74 vec3 p1 = vec3(a0.zw, h.y);
75 vec3 p2 = vec3(a1.xy, h.z);
76 vec3 p3 = vec3(a1.zw, h.w);
77
78 vec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));
79 p0 *= norm.x;
80 p1 *= norm.y;
81 p2 *= norm.z;
82 p3 *= norm.w;
83
84 vec4 m = max(0.5 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);
85 m = m * m;
86 return 105.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));
87}
88`;
89
90/**
91 * The shared props API of DeepUI's individual 3D components (not the full-page templates, which keep
92 * their own tailored scenes).
93 *
94 * The props are grouped by concern. A component extends ONLY the groups it really applies, so its
95 * type never advertises a knob that does nothing (a card has no particles, a background has no tilt):
96 *
97 * interface MyCardProps extends CursorProps, TiltProps, MaterialProps, PerformanceProps { … }
98 *
99 * `Base3DComponentProps` is every group at once, for tooling that handles any component. Same name,
100 * same unit and same meaning everywhere; the default values live in DEFAULT_3D_PROPS. These files are
101 * inlined into each component's single-file bundle (lib/bundle-source.mjs), only what it uses.
102 */
103
104/** Which rotation axes follow the pointer. "x-only": the object nods (up / down); "y-only": it turns (left / right). */
105export type TiltAxis = "both" | "x-only" | "y-only" | "none";
106
107/** 1. Cursor: how the pointer pulls, pushes and drags the object. */
108interface CursorProps {
109 /** 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). */
110 cursorRadius?: number;
111 /** Positive pulls things towards the pointer, negative pushes them away (repulsion, shockwave). Default 1. */
112 cursorForce?: number;
113 /** How far the object slides towards the pointer, 0 (stays put) to 1 (follows closely). Default 0. */
114 magneticStrength?: number;
115 /** Share of the remaining distance the motion closes each frame (at 60 fps), 0.01 (heavy, slow) to 1 (instant). Default 0.1. */
116 cursorDamping?: number;
117}
118
119/** 2. Tilt and parallax: the object leans towards the pointer, its layers slide against each other. */
120interface TiltProps {
121 /** Largest lean towards the pointer, in degrees. Default 15. */
122 maxTiltAngle?: number;
123 /** Axes that follow the pointer. Default "both". */
124 tiltAxis?: TiltAxis;
125 /** Lean away from the pointer instead of towards it. Default false. */
126 invertTilt?: boolean;
127 /** How far apart the depth layers slide when the object tilts, 0 (flat) to 2. Default 1. */
128 parallaxOffset?: number;
129}
130
131/** 3. Text and 3D typography, for components that draw a label. */
132interface Text3DProps {
133 /** The label drawn by the component. */
134 text?: string;
135 /** Scale of the lettering. Default 1. */
136 fontSize?: number;
137 /** Extrusion depth of 3D letters. Default 0.2. */
138 textDepth?: number;
139 /** Bevelled, light-catching edges on 3D letters. Default true. */
140 bevelEnabled?: boolean;
141 /** Custom font: a .woff / .ttf (flat text) or a typeface .json (extruded text). */
142 fontUrl?: string;
143}
144
145/** 4. Rendering, materials and glow. */
146interface MaterialProps {
147 /** Main color of the object. Default "#6366f1". */
148 primaryColor?: string;
149 /** Color of the glow. Default "#00f0ff". */
150 emissiveColor?: string;
151 /** Strength of the glow, 0 (none) to 3. Default 1. */
152 emissiveIntensity?: number;
153 /** 0 (mirror, glass) to 1 (matte). Default 0.3. */
154 roughness?: number;
155 /** 0 (plastic, organic) to 1 (metal). Default 0.5. */
156 metalness?: number;
157 /** 0 (opaque) to 1 (clear glass): see-through, refracting surfaces. Default 0. */
158 transmission?: number;
159 /** Technical wireframe rendering. Default false. */
160 wireframe?: boolean;
161}
162
163/** 5. Particles, idle motion and shader animation. */
164interface MotionProps {
165 /** Number of instanced elements. Default depends on the component. */
166 particleCount?: number;
167 /** Spin on its own, in radians per second (negative: the other way; 0.5 ≈ one turn in 12 s). Default 0. */
168 autoRotateSpeed?: number;
169 /** Pulses or ripples per second. Default 1. */
170 pulseRate?: number;
171 /** Amplitude of the noise deformation, 0 (none) to 2. Default 1. */
172 displacementScale?: number;
173}
174
175/** 6. Environment and camera. */
176interface EnvironmentProps {
177 /** Camera field of view, in degrees. Default depends on the component. */
178 cameraFov?: number;
179 /** Color of the depth fog. Default "#0a0a0a". */
180 fogColor?: string;
181 /** Thickness of the fog, 0 (none) to 0.2. Default 0. */
182 fogDensity?: number;
183}
184
185/** 7. Performance and accessibility. */
186interface PerformanceProps {
187 /** Lighter rendering for weak devices: pixel ratio 1, fewer instances, smaller environment maps. Default false. */
188 lowPowerMode?: boolean;
189 /** Under the OS "reduce motion" setting, stop idle spin, pulses and deformation (pointer feedback stays). Default true. */
190 respectReducedMotion?: boolean;
191 /** Stop the render loop while the component is scrolled out of view. Default true. */
192 pauseWhenOffscreen?: boolean;
193}
194
195/** Every group at once. Components extend only the groups they apply (see the top of this file). */
196interface Base3DComponentProps
197 extends CursorProps,
198 TiltProps,
199 Text3DProps,
200 MaterialProps,
201 MotionProps,
202 EnvironmentProps,
203 PerformanceProps {}
204
205type Defaults = Required<Omit<Base3DComponentProps, "text" | "fontUrl" | "particleCount" | "cameraFov">>;
206
207/** The values a prop takes when it is left out. A component may override one, and then documents it. */
208const DEFAULT_3D_PROPS: Defaults = {
209 cursorRadius: 220,
210 cursorForce: 1,
211 magneticStrength: 0,
212 cursorDamping: 0.1,
213 maxTiltAngle: 15,
214 tiltAxis: "both",
215 invertTilt: false,
216 parallaxOffset: 1,
217 fontSize: 1,
218 textDepth: 0.2,
219 bevelEnabled: true,
220 primaryColor: "#6366f1",
221 emissiveColor: "#00f0ff",
222 emissiveIntensity: 1,
223 roughness: 0.3,
224 metalness: 0.5,
225 transmission: 0,
226 wireframe: false,
227 autoRotateSpeed: 0,
228 pulseRate: 1,
229 displacementScale: 1,
230 fogColor: "#0a0a0a",
231 fogDensity: 0,
232 lowPowerMode: false,
233 respectReducedMotion: true,
234 pauseWhenOffscreen: true,
235};
236
237/** Inline widget: fills its positioned parent and receives pointer events. */
238const FILL_STYLE: CSSProperties = { position: "absolute", top: 0, left: 0, width: "100%", height: "100%" };
239
240/** Cursor overlay: covers the viewport, above everything, never intercepts the page's events. */
241const OVERLAY_STYLE: CSSProperties = {
242 position: "fixed",
243 top: 0,
244 left: 0,
245 width: "100%",
246 height: "100%",
247 pointerEvents: "none",
248 zIndex: 9999,
249};
250
251interface UICanvasProps extends Omit<CanvasProps, "children" | "style" | "gl">, Pick<PerformanceProps, "pauseWhenOffscreen" | "lowPowerMode"> {
252 children: ReactNode;
253 /** Full-viewport, click-through overlay (cursors) instead of an inline widget. */
254 overlay?: boolean;
255}
256
257/**
258 * Ready-to-use <Canvas>: pauses its render loop while scrolled out of view (pauseWhenOffscreen), pixel
259 * ratio 1 in lowPowerMode; R3F disposes the renderer and its WebGL context on unmount.
260 */
261function UICanvas({ children, overlay = false, dpr = [1, 2], pauseWhenOffscreen = DEFAULT_3D_PROPS.pauseWhenOffscreen, lowPowerMode = DEFAULT_3D_PROPS.lowPowerMode, ...canvasProps }: UICanvasProps) {
262 const containerRef = useRef<HTMLDivElement>(null);
263 // In view at first: the first frame is always drawn before the loop can be paused
264 const [inView, setInView] = useState(true);
265 useEffect(() => {
266 const el = containerRef.current;
267 if (!el || !pauseWhenOffscreen) return undefined;
268 const observer = new IntersectionObserver(([entry]) => setInView(entry.isIntersecting));
269 observer.observe(el);
270 return () => observer.disconnect();
271 }, [pauseWhenOffscreen]);
272 return (
273 <div ref={containerRef} style={overlay ? OVERLAY_STYLE : FILL_STYLE} aria-hidden="true">
274 <Canvas
275 dpr={lowPowerMode ? 1 : dpr}
276 frameloop={inView || !pauseWhenOffscreen ? "always" : "never"}
277 gl={{ antialias: true, alpha: true, powerPreference: "high-performance" }}
278 style={overlay ? { pointerEvents: "none" } : undefined}
279 {...canvasProps}
280 >
281 {children}
282 </Canvas>
283 </div>
284 );
285}
286
287/**
288 * Perspective camera placed so that 1 world unit = 1 CSS pixel on the z = 0 plane: widgets are laid
289 * out in pixels like the rest of the page, and still get real depth (presses, tilts, shadows).
290 */
291function PixelPerspective({ fov = 30 }: { fov?: number }) {
292 const camera = useThree((state) => state.camera) as THREE.PerspectiveCamera;
293 const size = useThree((state) => state.size);
294 useLayoutEffect(() => {
295 camera.fov = fov;
296 camera.near = 1;
297 camera.far = 20000;
298 camera.position.set(0, 0, size.height / 2 / Math.tan(THREE.MathUtils.degToRad(fov / 2)));
299 camera.lookAt(0, 0, 0);
300 camera.updateProjectionMatrix();
301 }, [camera, size, fov]);
302 return null;
303}
304
305/** True on devices with a precise pointer (mouse, trackpad): cursors make no sense on touch screens. */
306function useFinePointer() {
307 const [fine, setFine] = useState(false);
308 useEffect(() => {
309 const query = window.matchMedia("(pointer: fine)");
310 const sync = () => setFine(query.matches);
311 sync();
312 query.addEventListener("change", sync);
313 return () => query.removeEventListener("change", sync);
314 }, []);
315 return fine;
316}
317
318/**
319 * `cursorDamping` (share of the gap closed per 60 fps frame) as a rate for THREE.MathUtils.damp, so the
320 * motion feels the same at 30, 60 or 120 fps.
321 */
322function dampingToLambda(damping: number): number {
323 const share = THREE.MathUtils.clamp(damping, 0.001, 0.999);
324 return -Math.log(1 - share) * 60;
325}
326
327export interface CursorBlobProps extends Pick<MaterialProps, "primaryColor" | "roughness">, Pick<CursorProps, "cursorDamping">, Pick<MotionProps, "displacementScale">, Pick<PerformanceProps, "pauseWhenOffscreen" | "lowPowerMode"> {
328 primaryColor?: string;
329 /** @deprecated Use `primaryColor`. */
330 color?: string;
331 /** 0 = mirror chrome, 1 = brushed. Default 0.12. */
332 roughness?: number;
333 /** Strength of the organic wobble and of the stretch when moving. Default 1. */
334 displacementScale?: number;
335 /** @deprecated Use `displacementScale`. */
336 distortionScale?: number;
337 cursorDamping?: number;
338 /** @deprecated Use `cursorDamping` (shared unit). */
339 followSpeed?: number;
340 /** Size multiplier over links, buttons and other interactive elements. Default 2.4. */
341 hoverScale?: number;
342 /** Radius of the blob, in CSS pixels. Default 14. */
343 size?: number;
344 /** Hide the system cursor while the blob is shown. Default true. */
345 hideNativeCursor?: boolean;
346 /** What counts as interactive (the blob grows and turns translucent over it). */
347 interactiveSelector?: string;
348}
349
350const DEFAULT_SELECTOR = "a, button, [role='button'], input, select, textarea, label, summary, [data-cursor-hover]";
351
352// Injected into MeshPhysicalMaterial: the sphere is deformed on the GPU (teardrop stretch along the
353// motion + simplex wobble) and its normal is rebuilt from the deformed surface, so reflections follow
354const BLOB_PARS = /* glsl */ `
355uniform float uTime;
356uniform float uDistortion;
357uniform float uHover;
358uniform vec3 uVelocity; // smoothed motion, in blob radii per second, scaled
359
360${SIMPLEX_3D}
361
362vec3 blobDisplace(vec3 p) {
363 float speed = length(uVelocity);
364 vec3 dir = speed > 0.0001 ? uVelocity / speed : vec3(0.0);
365 float along = dot(p, dir);
366 // Stretch along the motion, slight squash across it, and a tail on the trailing side
367 vec3 q = p + dir * along * speed * 0.45 - (p - dir * along) * speed * 0.16;
368 q -= dir * max(-along, 0.0) * speed * 0.55;
369 float n = snoise(p * 1.7 + vec3(0.0, uTime * 0.9, uTime * 0.6));
370 q += p * n * uDistortion * (0.07 + speed * 0.22 + uHover * 0.05);
371 return q;
372}
373`;
374
375const BLOB_NORMAL = /* glsl */ `
376vec3 blobP = normalize(position);
377vec3 blobT1 = normalize(cross(blobP, abs(blobP.y) < 0.99 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0)));
378vec3 blobT2 = cross(blobP, blobT1);
379vec3 blobPos = blobDisplace(blobP);
380vec3 blobA = blobDisplace(normalize(blobP + blobT1 * 0.01));
381vec3 blobB = blobDisplace(normalize(blobP + blobT2 * 0.01));
382vec3 objectNormal = normalize(cross(blobA - blobPos, blobB - blobPos));
383`;
384
385interface PointerState {
386 x: number;
387 y: number;
388 inside: boolean;
389 hovering: boolean;
390 pressed: boolean;
391 seen: boolean;
392}
393
394export type CursorBlobSceneProps = Omit<CursorBlobProps, "hideNativeCursor">;
395
396/** The blob itself, for an existing R3F scene. It reads the pointer from the window, not from R3F events. */
397export const CursorBlobScene = memo(function CursorBlobScene({
398 primaryColor,
399 color = primaryColor ?? "#e4e4e7",
400 roughness = 0.12,
401 displacementScale,
402 distortionScale = displacementScale ?? 1,
403 cursorDamping,
404 followSpeed = cursorDamping !== undefined ? dampingToLambda(cursorDamping) : 9,
405 hoverScale = 2.4,
406 size = 14,
407 interactiveSelector = DEFAULT_SELECTOR,
408}: CursorBlobSceneProps) {
409 const meshRef = useRef<THREE.Mesh>(null);
410 const gl = useThree((state) => state.gl);
411 const pointer = useRef<PointerState>({ x: 0, y: 0, inside: false, hovering: false, pressed: false, seen: false });
412 const motion = useMemo(
413 () => ({
414 target: new THREE.Vector3(),
415 previous: new THREE.Vector3(),
416 velocity: new THREE.Vector3(),
417 raw: new THREE.Vector3(),
418 ndc: new THREE.Vector3(),
419 direction: new THREE.Vector3(),
420 scale: 0,
421 hover: 0,
422 baseColor: new THREE.Color(),
423 white: new THREE.Color(1, 1, 1),
424 }),
425 []
426 );
427
428 const geometry = useMemo(() => new THREE.SphereGeometry(1, 96, 64), []);
429 const uniforms = useMemo(
430 () => ({ uTime: { value: 0 }, uDistortion: { value: 1 }, uHover: { value: 0 }, uVelocity: { value: new THREE.Vector3() } }),
431 []
432 );
433 const material = useMemo(() => {
434 const m = new THREE.MeshPhysicalMaterial({ metalness: 1, clearcoat: 1, clearcoatRoughness: 0.05, envMapIntensity: 1.6, transparent: true });
435 m.onBeforeCompile = (shader) => {
436 Object.assign(shader.uniforms, uniforms);
437 shader.vertexShader = shader.vertexShader
438 .replace("#include <common>", `#include <common>\n${BLOB_PARS}`)
439 .replace("#include <beginnormal_vertex>", BLOB_NORMAL)
440 .replace("#include <begin_vertex>", "vec3 transformed = blobPos;");
441 };
442 return m;
443 }, [uniforms]);
444
445 useEffect(() => {
446 motion.baseColor.set(color);
447 uniforms.uDistortion.value = distortionScale;
448 }, [motion, uniforms, color, distortionScale]);
449 useEffect(() => () => geometry.dispose(), [geometry]);
450 useEffect(() => () => material.dispose(), [material]);
451
452 // Pointer from the window (the overlay canvas is click-through), plus "is it over something clickable"
453 useEffect(() => {
454 const el = gl.domElement;
455 const move = (event: PointerEvent) => {
456 if (event.pointerType === "touch") return;
457 const rect = el.getBoundingClientRect();
458 const p = pointer.current;
459 p.x = event.clientX - rect.left;
460 p.y = event.clientY - rect.top;
461 p.inside = p.x >= 0 && p.y >= 0 && p.x <= rect.width && p.y <= rect.height;
462 p.seen = true;
463 const target = event.target instanceof Element ? event.target : null;
464 p.hovering = !!target?.closest(interactiveSelector);
465 };
466 const down = () => {
467 pointer.current.pressed = true;
468 };
469 const up = () => {
470 pointer.current.pressed = false;
471 };
472 const leave = () => {
473 pointer.current.inside = false;
474 };
475 window.addEventListener("pointermove", move, { passive: true });
476 window.addEventListener("pointerdown", down, { passive: true });
477 window.addEventListener("pointerup", up, { passive: true });
478 document.documentElement.addEventListener("pointerleave", leave);
479 return () => {
480 window.removeEventListener("pointermove", move);
481 window.removeEventListener("pointerdown", down);
482 window.removeEventListener("pointerup", up);
483 document.documentElement.removeEventListener("pointerleave", leave);
484 };
485 }, [gl, interactiveSelector]);
486
487 useFrame((state, delta) => {
488 const mesh = meshRef.current;
489 if (!mesh) return;
490 const dt = Math.min(delta, 1 / 30);
491 const p = pointer.current;
492 uniforms.uTime.value = state.clock.elapsedTime;
493
494 // Screen → world: on the z = 0 plane, through the camera
495 const { camera, size: canvasSize } = state;
496 motion.ndc.set((p.x / canvasSize.width) * 2 - 1, -(p.y / canvasSize.height) * 2 + 1, 0.5).unproject(camera);
497 motion.direction.copy(motion.ndc).sub(camera.position).normalize();
498 motion.raw.copy(camera.position).addScaledVector(motion.direction, -camera.position.z / motion.direction.z);
499 const worldPerPixel = state.viewport.getCurrentViewport(camera, [0, 0, 0]).width / canvasSize.width;
500
501 // First sighting: appear in place instead of flying in from the center
502 if (p.seen && motion.scale < 0.01) mesh.position.copy(motion.raw);
503 motion.previous.copy(mesh.position);
504 mesh.position.lerp(motion.raw, 1 - Math.exp(-followSpeed * dt));
505
506 // Velocity, in blob radii per second → the stretch (smoothed and clamped)
507 const radius = size * worldPerPixel;
508 motion.target.subVectors(mesh.position, motion.previous).divideScalar(Math.max(dt, 1e-4) * radius);
509 motion.velocity.lerp(motion.target, 1 - Math.exp(-10 * dt));
510 uniforms.uVelocity.value.copy(motion.velocity).multiplyScalar(0.018).clampLength(0, 1.1);
511
512 // Size: hidden off-screen, bigger over interactive elements, a little smaller while pressed
513 motion.hover = THREE.MathUtils.damp(motion.hover, p.hovering ? 1 : 0, 10, dt);
514 uniforms.uHover.value = motion.hover;
515 const targetScale = p.inside ? (1 + (hoverScale - 1) * motion.hover) * (p.pressed ? 0.82 : 1) : 0;
516 motion.scale = THREE.MathUtils.damp(motion.scale, targetScale, 12, dt);
517 mesh.scale.setScalar(radius * motion.scale);
518 mesh.visible = motion.scale > 0.01;
519
520 // Material: polished metal at rest, a lighter translucent lens over interactive elements
521 material.color.copy(motion.baseColor).lerp(motion.white, motion.hover * 0.6);
522 material.roughness = THREE.MathUtils.lerp(roughness, 0.02, motion.hover);
523 material.metalness = 1 - motion.hover * 0.7;
524 material.opacity = 1 - motion.hover * 0.45;
525 });
526
527 return <mesh ref={meshRef} geometry={geometry} material={material} frustumCulled={false} renderOrder={10} />;
528});
529
530/** Self-contained cursor: a full-viewport overlay canvas above the page. Render it once, e.g. in the layout. */
531function CursorBlob3D({ hideNativeCursor = true, pauseWhenOffscreen, lowPowerMode, ...props }: CursorBlobProps) {
532 const finePointer = useFinePointer();
533
534 useEffect(() => {
535 if (!finePointer || !hideNativeCursor) return undefined;
536 const style = document.createElement("style");
537 style.textContent = "*, *::before, *::after { cursor: none !important; }";
538 document.head.appendChild(style);
539 return () => style.remove();
540 }, [finePointer, hideNativeCursor]);
541
542 if (!finePointer) return null;
543 return (
544 <UICanvas pauseWhenOffscreen={pauseWhenOffscreen} lowPowerMode={lowPowerMode} overlay>
545 <PixelPerspective />
546 {/* Studio reflections for the chrome: light panels, no HDR file to download */}
547 <Environment resolution={128} frames={1}>
548 <Lightformer form="rect" intensity={3} position={[0, 5, 2]} rotation-x={Math.PI / 2} scale={[10, 3, 1]} />
549 <Lightformer form="rect" intensity={2} position={[-5, 0, 3]} rotation-y={Math.PI / 2} scale={[2, 8, 1]} />
550 <Lightformer form="ring" intensity={4} position={[4, -1, 5]} scale={2} />
551 </Environment>
552 <CursorBlobScene {...props} />
553 </UICanvas>
554 );
555}
556
557export default memo(CursorBlob3D);
03

Drop it in a page

Updated live with the settings above.

app/page.tsx
1import CursorBlob3D from "@/components/CursorBlob3D";
2
3export default function Section() {
4 return (
5 // The component fills this box: give it a position and a height
6 <div style={{ position: "relative", width: "100%", height: "100vh" }}>
7 <CursorBlob3D
8 size={14}
9 hoverScale={2.4}
10 cursorDamping={0.14}
11 displacementScale={1}
12 roughness={0.12}
13 primaryColor="#e4e4e7"
14 />
15 </div>
16 );
17}
Next componentRibbon Cursor→