Three.js Fur Shader (Shell Texturing)

Real-time fur in Three.js using shell texturing, where one instanced draw renders dozens of offset shells and each strand tapers, droops with gravity, sways in the wind and can be brushed with the pointer.

Key topics: three.js fur, shell texturing, hair shader, instancedmesh, gl_instanceid, fur rendering

What this code does

- Shells: the mesh is redrawn N times as an `InstancedMesh`, and each instance reads its height from gl_InstanceID.
- Strands: UV space is split into cells, each with a random length; a shell keeps pixels inside a tapering disc while below that length.
- Bending: gravity and wind displace shells by height², so roots stay put and tips swing.
- Brushing: a raycast hit point pushes nearby fur outward in the vertex shader.
- Shading: root-to-tip gradient, height-based self-occlusion and a Kajiya–Kay-style sheen.
- Controls: shape, shell count, length, density, thickness, gravity, wind, root and tip colors and spin.

Continue Learning

JavaScript Implementation

ES6+
// Shell fur: draw the same mesh N times, offset along normals, discarding pixels without a strand
const shells = 32
const material = new THREE.ShaderMaterial({
  vertexShader: `
    varying vec2 vUv; varying float vH;
    void main () {
      vH = float(gl_InstanceID) / 32.0;
      vUv = uv;
      vec3 p = position + normal * vH * 0.25 - vec3(0.0, vH * vH * 0.1, 0.0);
      gl_Position = projectionMatrix * modelViewMatrix * vec4(p, 1.0);
    }`,
  fragmentShader: `
    varying vec2 vUv; varying float vH;
    float hash (vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
    void main () {
      vec2 st = vUv * vec2(240.0, 120.0);
      float len = hash(floor(st));
      if (vH > 0.0 && (len < vH || length(fract(st) * 2.0 - 1.0) > 1.0 - vH / len)) discard;
      gl_FragColor = vec4(mix(vec3(0.23, 0.14, 0.09), vec3(0.91, 0.7, 0.48), vH) * mix(0.3, 1.0, vH), 1.0);
    }`
})
const fur = new THREE.InstancedMesh(new THREE.SphereGeometry(1, 96, 64), material, shells)
scene.add(fur)