Creating Cinematic Volumetric God Rays & Light Shafts in CSS & Canvas: Conic Gradients & Radial Dispersion

The Quick Answer

Volumetric god rays (crepuscular rays) occur when light scatters through atmospheric dust and fog. In web design, you can achieve this effect either with pure CSS using rotating conic-gradient sweeps with mix-blend-mode: screen, or in HTML5 Canvas by casting ray march angles outward from an emitter coordinate and layering subtle floating dust motes.

Interactive Demo Live Preview
☀️ Radial Dispersion & Dust Motes · Hover to pivot light source

Step 1: Pure CSS Conic Gradient Light Ray Architecture

A lightweight, zero-JS volumetric beam is created using repeating conic gradients layered inside a pseudo-element, positioned at a focal light source (top corner or center).

god-rays.css
.god-rays-hero {
  position: relative;
  overflow: hidden;
  background: #06080e;
}
.god-rays-hero::before {
  content: "";
  position: absolute;
  top: -50%;
  left: 50%;
  width: 200%;
  height: 200%;
  transform: translate(-50%, 0);
  background: repeating-conic-gradient(
    from 0deg at 50% 0%,
    rgba(255, 255, 255, 0.08) 0deg,
    rgba(255, 255, 255, 0.08) 8deg,
    transparent 8deg,
    transparent 16deg,
    rgba(255, 255, 255, 0.04) 16deg,
    transparent 24deg
  );
  filter: blur(18px);
  mix-blend-mode: screen;
  animation: raySweep 24s linear infinite;
  pointer-events: none;
}
@keyframes raySweep {
  0% { transform: translate(-50%, 0) rotate(0deg); }
  100% { transform: translate(-50%, 0) rotate(360deg); }
}

Step 2: Canvas Radial Dispersion & Ray Marching

For interactive light shafts that follow the cursor, render polygonal beam wedges in HTML5 Canvas. Calculate angle spans radiating from the light source and fill with radial gradients.

canvas-rays.js
function drawGodRay(originX, originY, angle, spread, length, ctx) {
  const x1 = originX + Math.cos(angle - spread) * length;
  const y1 = originY + Math.sin(angle - spread) * length;
  const x2 = originX + Math.cos(angle + spread) * length;
  const y2 = originY + Math.sin(angle + spread) * length;

  const grad = ctx.createRadialGradient(originX, originY, 10, originX, originY, length);
  grad.addColorStop(0, 'rgba(255, 240, 200, 0.25)');
  grad.addColorStop(0.5, 'rgba(255, 220, 150, 0.08)');
  grad.addColorStop(1, 'transparent');

  ctx.fillStyle = grad;
  ctx.beginPath();
  ctx.moveTo(originX, originY);
  ctx.lineTo(x1, y1);
  ctx.lineTo(x2, y2);
  ctx.closePath();
  ctx.fill();
}

Step 3: Illuminated Atmospheric Dust Motes

The illusion of volumetric depth is enhanced by tiny floating dust particles whose brightness increases when crossing active light shafts.

dust-motes.js
class DustMote {
  constructor(w, h) {
    this.x = Math.random() * w;
    this.y = Math.random() * h;
    this.vx = (Math.random() - 0.5) * 0.3;
    this.vy = Math.random() * 0.4 + 0.1; // gentle drift downward
    this.size = Math.random() * 1.5 + 0.5;
  }
  update(w, h, ctx) {
    this.x += this.vx;
    this.y += this.vy;
    if (this.y > h) this.y = 0;
    if (this.x < 0) this.x = w;
    if (this.x > w) this.x = 0;

    ctx.fillStyle = 'rgba(255, 255, 255, 0.4)';
    ctx.beginPath();
    ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
    ctx.fill();
  }
}

Next-Level Addons: Elevating Your Implementation

Take this technique further by combining it with complementary design token studios and animation tools:

AQUATIC LIGHT SHAFTS

1. Golden Hour Sunset & Underwater Caustics

Explore in Aurora Glow Studio →

Shift light shaft color palettes from warm amber sunset rays to aquatic cyan and turquoise underwater caustics using SVG feTurbulence displacement maps.

DYNAMIC FLASHLIGHT EMITTER

2. Interactive Light Source Cursor Tracking

Explore in Glassmorphism Studio →

Dynamically update the focal coordinate of the light emitter as the visitor hovers over hero cards, creating a cinematic flashlight effect.

REFRACTED GLASS

3. GPU Compositing with Backdrop Blur Masks

Explore in Glassmorphism Generator →

Layer frosted glass cards over volumetric light shafts so the moving beams refract through backdrop-filter: blur(16px) containers.

Chaam
Chaam's Pro Tip

Here's my golden rule when implementing this in production: test across multiple devices and browsers early. Keep your DOM hierarchy shallow, optimize assets with modern formats (like WebP/AVIF), and verify keyboard navigation for accessibility.

Why I Built the Aurora Glow Studio

I got tired of guessing values and testing browser quirks in DevTools, so I built this tool to tweak and preview values in real time with 1-click code export.

Open in Aurora Glow Studio ↗

Frequently Asked Questions

Practical answers to common implementation questions, browser quirks, and performance tips.

What is the performance difference between CSS conic gradients and Canvas god rays?

CSS conic gradients with mix-blend-mode: screen run entirely on the GPU compositor thread with 0ms main thread blocking. Canvas gives more control over interactive cursor angles and dust motes, but requires a 60fps requestAnimationFrame loop.

Which mix-blend-mode produces the best volumetric light effect?

mix-blend-mode: screen or mix-blend-mode: color-dodge. Screen adds the color luminance of the ray layer without blowing out the dark background into white, preserving subtle contrast in text elements positioned in front.

How do you keep text readable over bright volumetric light shafts?

Clamp the maximum ray alpha to 0.15–0.25 and apply text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8) to foreground typography. You can also place an ambient dark radial vignette between the rays and the content.

How do you simulate volumetric god rays casting shadows around obstacles?

In 2D Canvas, use shadow volume ray casting: shoot rays outward and detect polygon line intersections with obstacle bounding boxes. Draw dark shadow polygons over occluded ray segments.

Are CSS conic gradients supported in all major browsers?

Yes. repeating-conic-gradient is supported in Chrome, Edge, Safari (12.1+), and Firefox (75+), with over 97% global browser support.

← Back to all blog guides Launch Generator Studio →