Three.js Saturn Ring System (120k Keplerian Particles)

Saturn's rings in Three.js as 120,000 GPU-animated particles following Kepler's third law, with the C, B and A rings, the Cassini division, the Encke gap, shepherd moons and the planet's shadow across the rings.

Key topics: three.js saturn, planetary rings, particle system, kepler, cassini division, astronomy, shader points

What this code does

- Keplerian Motion: each particle's angular speed is computed in the vertex shader as ω ∝ r^(−3/2), so inner rings visibly overtake outer ones.
- Ring Structure: radii are sampled per region (D, C, B, A, F) weighted by area × optical density, leaving the Cassini division and Encke gap empty.
- Planet Shadow: the shader darkens particles on the night side inside the planet's cylinder along the sun direction.
- Shepherd Moons: Pan sits in the Encke gap and Mimas orbits at the 2:1 resonance that clears the Cassini division.
- Procedural Bands: the planet uses a `CanvasTexture` of sine-based latitude bands and a 10% oblate scale.
- Controls: particle count, time scale, axial tilt, ring thickness, particle size, gaps and moons.

Continue Learning

JavaScript Implementation

ES6+
const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera(40, width / height, 0.1, 1000)
camera.position.set(0, 9, 34)
camera.lookAt(0, 0, 0)
const renderer = new THREE.WebGLRenderer({ antialias: true })
renderer.setSize(width, height)
document.querySelector('#app').appendChild(renderer.domElement)

const sun = new THREE.DirectionalLight(0xfff4e0, 3)
sun.position.set(100, 25, 40)
scene.add(sun)

const system = new THREE.Group()
system.rotation.z = THREE.MathUtils.degToRad(26.7)
scene.add(system)
system.add(new THREE.Mesh(new THREE.SphereGeometry(6, 64, 48), new THREE.MeshStandardMaterial({ color: 0xe8d3a0 })))

// Ring particles orbit with Kepler's law: ω ∝ r^(-3/2)
const n = 60000
const positions = new Float32Array(n * 3)
const radii = new Float32Array(n)
const angles = new Float32Array(n)
for (let i = 0; i < n; i++) {
  radii[i] = 6 * (1.24 + Math.random() * 1.03)
  angles[i] = Math.random() * Math.PI * 2
}
const geometry = new THREE.BufferGeometry()
geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3))
const rings = new THREE.Points(geometry, new THREE.PointsMaterial({ color: 0xd8c8a8, size: 0.05 }))
system.add(rings)

function animate (t) {
  requestAnimationFrame(animate)
  const time = t / 1000
  for (let i = 0; i < n; i++) {
    const a = angles[i] + time * 0.6 * Math.pow(radii[i] / 6, -1.5)
    positions[i * 3] = Math.cos(a) * radii[i]
    positions[i * 3 + 2] = Math.sin(a) * radii[i]
  }
  geometry.attributes.position.needsUpdate = true
  renderer.render(scene, camera)
}
animate(0)