Material Spotlight
- group .........
- 3D and WebGL scenes
- source ........
- https://ui.aryank.space/components/material-spotlight
- markdown ......
- /lab/material-spotlight.md
- human .........
- /lab/material-spotlight
── WHAT_IT_IS ────────────────────────────────────────────────────────────────────────────────
A cursor-driven material reveal on a 3D model. A near-matte standard material lit by a room-environment IBL gets a shader patch that carves a soft sphere of low-roughness, darker diffuse around the pointer's world-space hit — a wet, polished spotlight that follows the cursor and eases away. Three.js + WebGL.
── BEHAVIOUR ────────────────────────────────────────────────────────────────────────────────
* A patch, not a new shader
onBeforeCompile splices four small chunks into MeshStandardMaterial — it keeps all of the standard PBR lighting and only overrides roughness and diffuse inside the sphere of influence.
* World-space, ray-picked
The cursor is ray-cast onto a plane to get a world point; the fragment shader measures distance to it, so the spotlight sticks to the surface in 3D rather than sliding across the screen.
* Eased, never snapped
Both the hit point and the activation amount lerp every frame, so the spot glides to the cursor and fades out smoothly when the pointer leaves.