← All components Next componentWave Field→
Isolated · Chrome
Liquid Chrome
A chrome blob whose surface flows like liquid metal, orbited by two satellites. Fully tunable.
<LiquidChrome />Live
Move your cursor over itLiquid chrome
Customize
Color#ffffff
Installation
Use it in your project
Or skip the copy-paste
One command: writes the file and installs the dependencies.
$ npx deepui-cli add liquid-chrome
01
Install
The 3D packages this component is built on.
$ npm install three02
Add the component
One self-contained file: create components/LiquidChrome.js and paste it in.
components/LiquidChrome.js
1"use client";23import { useEffect, useRef } from "react";4import * as THREE from "three";5import { RoomEnvironment } from "three/examples/jsm/environments/RoomEnvironment.js";67// Default props of LiquidChrome, kept apart from the component so pages (e.g. the playground UI)8// can read them without pulling three.js into their bundle.9const LIQUID_CHROME_DEFAULTS = {10 size: 0.60,11 distortion: 0.02,12 frequency: 1.4,13 speed: 0.10,14 cursor: 1,15 reflection: 0.75,16 roughness: 0.06,17 iridescence: 0,18 color: "#ffffff",19};2021/**22 * Liquid chrome: a sphere whose surface flows with 3D simplex noise (displacement + recomputed normals23 * in the vertex shader, so reflections follow the waves), orbited by two small chrome satellites.24 * Every prop can change at any time without rebuilding the scene: they are read each frame.25 *26 * Props (all optional):27 * - size 0.6–1.4 · distortion 0–0.6 · frequency 0.5–3 · speed 0–228 * - cursor 0–1 (how much the blob leans and drifts towards the pointer)29 * - reflection 0.2–3 (envMapIntensity) · roughness 0–0.6 · iridescence 0–1 · color (hex)30 * - className: sizing of the wrapper (the canvas fills it)31 */323334// Ashima Arts 3D simplex noise (MIT) — https://github.com/ashima/webgl-noise35const SIMPLEX = /* glsl */ `36vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }37vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }38vec4 permute(vec4 x) { return mod289(((x * 34.0) + 1.0) * x); }39vec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; }40float snoise(vec3 v) {41 const vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);42 const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);43 vec3 i = floor(v + dot(v, C.yyy));44 vec3 x0 = v - i + dot(i, C.xxx);45 vec3 g = step(x0.yzx, x0.xyz);46 vec3 l = 1.0 - g;47 vec3 i1 = min(g.xyz, l.zxy);48 vec3 i2 = max(g.xyz, l.zxy);49 vec3 x1 = x0 - i1 + C.xxx;50 vec3 x2 = x0 - i2 + C.yyy;51 vec3 x3 = x0 - D.yyy;52 i = mod289(i);53 vec4 p = permute(permute(permute(i.z + vec4(0.0, i1.z, i2.z, 1.0)) + i.y + vec4(0.0, i1.y, i2.y, 1.0)) + i.x + vec4(0.0, i1.x, i2.x, 1.0));54 float n_ = 0.142857142857;55 vec3 ns = n_ * D.wyz - D.xzx;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 vec4 x = x_ * ns.x + ns.yyyy;60 vec4 y = y_ * ns.x + ns.yyyy;61 vec4 h = 1.0 - abs(x) - abs(y);62 vec4 b0 = vec4(x.xy, y.xy);63 vec4 b1 = vec4(x.zw, y.zw);64 vec4 s0 = floor(b0) * 2.0 + 1.0;65 vec4 s1 = floor(b1) * 2.0 + 1.0;66 vec4 sh = -step(h, vec4(0.0));67 vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;68 vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;69 vec3 p0 = vec3(a0.xy, h.x);70 vec3 p1 = vec3(a0.zw, h.y);71 vec3 p2 = vec3(a1.xy, h.z);72 vec3 p3 = vec3(a1.zw, h.w);73 vec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));74 p0 *= norm.x; p1 *= norm.y; p2 *= norm.z; p3 *= norm.w;75 vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);76 m = m * m;77 return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));78}79`;8081export default function LiquidChrome({ className = "h-full w-full", ...props }) {82 const hostRef = useRef(null);83 // Latest props, read every frame by the render loop (no scene rebuild when a value changes)84 const paramsRef = useRef({ ...LIQUID_CHROME_DEFAULTS, ...props });85 paramsRef.current = { ...LIQUID_CHROME_DEFAULTS, ...props };8687 useEffect(() => {88 const host = hostRef.current;89 if (!host) return undefined;90 const reduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches;9192 // Fresh canvas per mount: its context is released on unmount (forceContextLoss)93 const canvas = document.createElement("canvas");94 canvas.className = "block h-full w-full";95 host.appendChild(canvas);9697 const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: true, powerPreference: "high-performance" });98 renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));99 renderer.setClearColor(0x000000, 0);100 renderer.outputColorSpace = THREE.SRGBColorSpace;101 renderer.toneMapping = THREE.ACESFilmicToneMapping;102 renderer.toneMappingExposure = 1.1;103104 const scene = new THREE.Scene();105 const pmrem = new THREE.PMREMGenerator(renderer);106 const room = new RoomEnvironment();107 const envTarget = pmrem.fromScene(room, 0.04);108 scene.environment = envTarget.texture;109 room.dispose();110 pmrem.dispose();111112 const camera = new THREE.PerspectiveCamera(32, 1, 0.1, 50);113 camera.position.set(0, 0, 7.5);114115 const key = new THREE.DirectionalLight(0xffffff, 2.4);116 key.position.set(6, 8, 10);117 const rim = new THREE.DirectionalLight(0xcfe0ff, 2);118 rim.position.set(-8, -3, -6);119 scene.add(key, rim);120121 // Blob: dense icosphere displaced along its normal by animated simplex noise122 const uniforms = { uTime: { value: 0 }, uAmp: { value: 0 }, uFreq: { value: 1 } };123 const blobMaterial = new THREE.MeshPhysicalMaterial({ color: 0xffffff, metalness: 1, roughness: 0.06, iridescenceIOR: 1.6, iridescenceThicknessRange: [180, 620] });124 blobMaterial.onBeforeCompile = (shader) => {125 Object.assign(shader.uniforms, uniforms);126 shader.vertexShader = shader.vertexShader127 .replace(128 "#include <common>",129 `#include <common>130uniform float uTime;131uniform float uAmp;132uniform float uFreq;133${SIMPLEX}134vec3 displaceP(vec3 p) {135 vec3 q = p * uFreq + vec3(uTime * 0.6, uTime * 0.45, uTime * 0.5);136 float n = snoise(q) * 0.75 + snoise(q * 2.1 + 7.3) * 0.25;137 return p + normalize(p) * n * uAmp;138}`139 )140 // Normal of the displaced surface, from two nearby displaced points (tangent + bitangent)141 .replace(142 "#include <beginnormal_vertex>",143 `vec3 dispPos = displaceP(position);144vec3 nrm = normalize(position);145vec3 tng = normalize(abs(nrm.y) < 0.99 ? cross(nrm, vec3(0.0, 1.0, 0.0)) : cross(nrm, vec3(1.0, 0.0, 0.0)));146vec3 btg = normalize(cross(nrm, tng));147vec3 objectNormal = normalize(cross(displaceP(position + tng * 0.01) - dispPos, displaceP(position + btg * 0.01) - dispPos));`148 )149 .replace("#include <begin_vertex>", "vec3 transformed = dispPos;");150 };151 const blob = new THREE.Mesh(new THREE.IcosahedronGeometry(1.15, 64), blobMaterial);152 const pivot = new THREE.Group();153 pivot.add(blob);154 scene.add(pivot);155156 // Two chrome satellites on tilted orbits157 const satMaterial = new THREE.MeshPhysicalMaterial({ color: 0xffffff, metalness: 1, roughness: 0.05, envMapIntensity: 1.4 });158 const satGeometry = new THREE.SphereGeometry(1, 32, 24);159 const satellites = [160 { radius: 2.15, speed: 0.55, tilt: new THREE.Euler(0.5, 0, 0.35), scale: 0.13, phase: 0 },161 { radius: 2.6, speed: -0.38, tilt: new THREE.Euler(-0.35, 0, -0.6), scale: 0.085, phase: 2.2 },162 ].map((s) => {163 const orbit = new THREE.Group();164 orbit.rotation.copy(s.tilt);165 const mesh = new THREE.Mesh(satGeometry, satMaterial);166 mesh.scale.setScalar(s.scale);167 orbit.add(mesh);168 scene.add(orbit);169 return { ...s, mesh };170 });171172 const color = new THREE.Color();173 const pointer = { x: 0, y: 0, sx: 0, sy: 0 };174 let size = paramsRef.current.size;175176 const resize = () => {177 const w = host.clientWidth;178 const h = host.clientHeight;179 if (!w || !h) return;180 renderer.setSize(w, h, false);181 camera.aspect = w / h;182 // Keep the whole orbit in frame on narrow (portrait) tiles183 camera.position.z = 7.5 / Math.min(1, camera.aspect);184 camera.updateProjectionMatrix();185 };186 const onPointer = (event) => {187 const r = host.getBoundingClientRect();188 pointer.x = ((event.clientX - r.left) / r.width) * 2 - 1;189 pointer.y = ((event.clientY - r.top) / r.height) * 2 - 1;190 };191 const onLeave = () => {192 pointer.x = 0;193 pointer.y = 0;194 };195196 const resizeObserver = new ResizeObserver(resize);197 resizeObserver.observe(host);198 resize();199 let visible = true;200 const visibility = new IntersectionObserver(([entry]) => {201 visible = entry.isIntersecting;202 });203 visibility.observe(host);204 host.addEventListener("pointermove", onPointer);205 host.addEventListener("pointerleave", onLeave);206207 let raf = 0;208 let time = 0;209 const timer = new THREE.Timer();210 timer.connect(document);211212 const frame = () => {213 raf = requestAnimationFrame(frame);214 if (document.hidden || !visible) return;215 timer.update();216 const dt = Math.min(timer.getDelta(), 0.1);217 const p = paramsRef.current;218 const motion = reduced ? 0 : 1;219220 // Material and noise follow the current props (smoothly for size, directly for the rest)221 time += dt * p.speed * motion;222 uniforms.uTime.value = time;223 uniforms.uAmp.value = p.distortion;224 uniforms.uFreq.value = p.frequency;225 blobMaterial.roughness = p.roughness;226 blobMaterial.envMapIntensity = p.reflection;227 // Never exactly 0: crossing 0 toggles a shader define and recompiles mid-drag (visible hitch)228 blobMaterial.iridescence = Math.max(0.001, p.iridescence);229 blobMaterial.color.copy(color.set(p.color));230 satMaterial.color.copy(blobMaterial.color);231 satMaterial.envMapIntensity = p.reflection;232 size += (p.size - size) * Math.min(1, dt * 8);233 blob.scale.setScalar(size);234235 // Cursor: the blob leans and drifts towards the pointer, proportionally to `cursor`236 pointer.sx += (pointer.x * p.cursor - pointer.sx) * Math.min(1, dt * 4);237 pointer.sy += (pointer.y * p.cursor - pointer.sy) * Math.min(1, dt * 4);238 pivot.rotation.set(pointer.sy * 0.6, pointer.sx * 0.8, 0);239 pivot.position.set(pointer.sx * 0.35, -pointer.sy * 0.25, 0);240 blob.rotation.y += dt * 0.15 * motion;241242 const t = timer.getElapsed() * motion;243 satellites.forEach((s) => {244 const a = s.phase + t * s.speed;245 s.mesh.position.set(Math.cos(a) * s.radius * size, 0, Math.sin(a) * s.radius * size);246 });247248 renderer.render(scene, camera);249 };250 frame();251252 return () => {253 cancelAnimationFrame(raf);254 timer.dispose();255 resizeObserver.disconnect();256 visibility.disconnect();257 host.removeEventListener("pointermove", onPointer);258 host.removeEventListener("pointerleave", onLeave);259 blob.geometry.dispose();260 blobMaterial.dispose();261 satGeometry.dispose();262 satMaterial.dispose();263 envTarget.dispose();264 renderer.dispose();265 renderer.forceContextLoss();266 canvas.remove();267 };268 }, []);269270 return <div ref={hostRef} className={className} />;271}
03
Drop it in a page
Updated live with the settings above.
app/page.jsx
1import LiquidChrome from "@/components/LiquidChrome";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 <LiquidChrome8 size={0.6}9 distortion={0.02}10 frequency={1.4}11 speed={0.1}12 cursor={1}13 reflection={0.75}14 roughness={0.06}15 iridescence={0}16 color="#ffffff"17 />18 </div>19 );20}