Back to articles

Sculpting Real-Time Parametric Shaders in Three.js

How to build performant, hardware-accelerated 3D wireframe sculptures that react seamlessly to user scroll velocity and viewport constraints.

Modern web interfaces frequently err on two extremes: static, lifeless typography or heavy, GPU-choking 3D experiences that cause battery drain and frame drops.

Striking the balance between artistic kinetic expression and mathematical restraint requires treating WebGL not as a toy, but as a precision rendering pipeline.


1. Minimal Mathematical Geometries

Instead of loading massive 50MB `.gltf` models with heavy UV textures, procedural parametric geometries offer infinite resolution at virtually zero network cost.

By composing a geodesic **Icosahedron wireframe** alongside a **Torus Knot core**, we achieve rich geometric complexity through pure code:

const outerGeo = new THREE.IcosahedronGeometry(1.6, 2);
const outerMat = new THREE.MeshBasicMaterial({
  color: 0x9e9ea7,
  wireframe: true,
  transparent: true,
  opacity: 0.35,
});
const mesh = new THREE.Mesh(outerGeo, outerMat);
scene.add(mesh);

2. Smooth Scroll Coupling via Linear Interpolation (Lerp)

Directly coupling scroll position to 3D rotation produces jagged stuttering. Instead, we decouple the scroll listener from the animation loop using smooth linear interpolation:

// Update scroll target in passive event listener
window.addEventListener('scroll', () => {
  targetScrollProgress = window.scrollY / maxScroll;
}, { passive: true });

// Lerp inside requestAnimationFrame loop
scrollProgress += (targetScrollProgress - scrollProgress) * 0.08;
mesh.rotation.y = time * 0.2 + scrollProgress * Math.PI * 2;

The result is a tactile, organic responsiveness that feels grounded in real-world physics.