---
id: "rayleigh-mie-single-scattering"
title: "Ray-marched Rayleigh/Mie Single Scattering"
aliases: [Nishita sky, analytic sky ray march]
domain: "volumes"
stage: "volume"
realtime: "realtime"
platforms: [webgl2, webgpu, desktop-gpu, mobile-gpu]
year_introduced: 1993
inputs: [material-params]
outputs: [radiance, hdr-image]
style: "photoreal"
dynamic: "dynamic"
cost: "medium"
authority: "Nishita et al., 1993"
url: "https://texelatlas.vercel.app/t/rayleigh-mie-single-scattering/"
sources_verified_at: "2026-11-29"
---
# Ray-marched Rayleigh/Mie Single Scattering (Nishita et al., 1993)

> Integrate sunlight scattered once toward the eye along the view ray through an exponential-density atmosphere, with an inner loop for sun transmittance; the textbook way to get blue skies and red sunsets in a shader.

## Reach for it when

- need a blue sky and red sunset in a shader
- cheap atmosphere without precomputed tables
- haze and sun glow around the sun in a scene
- procedural sky that responds to sun position

## How it works

Intersect the view ray with the atmosphere shell, split it into N samples and at each sample accumulate the local Rayleigh and Mie densities, which decay exponentially with altitude using separate scale heights. A second short march from the sample toward the sun gives the optical depth to the light; transmittance is exp of minus the sum of beta times optical depth over both legs. Contribution at each sample is that transmittance times density, and the final color is multiplied by the sun power and by the Rayleigh and Henyey-Greenstein phase functions evaluated at the angle to the sun. Rayleigh coefficients scale roughly with inverse wavelength to the fourth power, which makes the blue sky and red dusk. Higher scattering orders are ignored, so a constant ambient floor is often added.

## When to use it

Choose it for a compact sky shader with no tables, when you need sunset colors, and when you can afford roughly a hundred texture-less samples per pixel (or render to a small sky-dome texture once per frame).

Prefer [Hosek-Wilkie Sky Model](https://texelatlas.vercel.app/t/hosek-wilkie-sky.md) or [Preetham Analytic Daylight Model](https://texelatlas.vercel.app/t/preetham-sky.md) for a per-pixel-free analytic sky, [Precomputed Atmospheric Scattering](https://texelatlas.vercel.app/t/precomputed-atmospheric-scattering.md) or [Scalable Production Sky and Atmosphere (Hillaire)](https://texelatlas.vercel.app/t/hillaire-sky-atmosphere.md) when you need multiple scattering and aerial perspective at lower cost per pixel.

## Cost

medium — Cost grows as view samples times light samples per pixel; render to a low-res dome or cubemap to bring it down.
Measured GPU Weight: 42.39× baseline (heavy) — 1.3947 ms median / 1.4573 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 40.06× baseline (heavy) — 0.637 ms median (2.19× faster on L4).
Ampere A100 scaling: 26.17× baseline (heavy) — 0.7537 ms median (1.85× faster on A100).

## Failure modes

- Single scattering only: the sky around the horizon after sunset goes unrealistically black or too saturated
- Banding or hard rings with too few view samples when the ray grazes the horizon
- Sun below the horizon without a planet-shadow test lights the ground incorrectly
- Mie asymmetry g near 0.99 creates aliasing at the sun disc without more samples
- Looking down onto ground needs a separate ground color; the integral just stops at the planet

## Engine support

- babylonjs: official — `@babylonjs/materials SkyMaterial (rayleigh, mieCoefficient, mieDirectionalG)` (evidence: https://github.com/BabylonJS/Babylon.js/blob/9.38.0/packages/dev/materials/src/sky/skyMaterial.ts, checked 2026-12-01)
- blender: builtin — `Sky Texture node > Sky Type = Single Scattering` (evidence: https://docs.blender.org/manual/en/5.2/render/shader_nodes/textures/sky.html, checked 2026-12-01) — Single Scattering is legacy; Multiple Scattering is the default.
- godot: builtin — `Sky.sky_material = PhysicalSkyMaterial (rayleigh_coefficient, mie_coefficient)` (evidence: https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/PhysicalSkyMaterial.xml, checked 2026-12-01) — Analytic sky shader with Rayleigh and Mie terms.
- unity: builtin — `HDRP Volume > Add Override > Sky > Physically Based Sky (PhysicallyBasedSkyCommon.hlsl evaluates Rayleigh air and Mie aerosol scattering)` (evidence: https://github.com/Unity-Technologies/Graphics/blob/557f6ac22b948284f57ffae6a789751fd1f63620/Packages/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSkyCommon.hlsl, checked 2026-12-01) — HDRP only.
- unreal: builtin — `Sky Atmosphere component > Rayleigh Scattering / Mie Scattering settings` (evidence: https://dev.epicgames.com/documentation/en-us/unreal-engine/sky-atmosphere-component-properties-in-unreal-engine, checked 2026-12-01)

## Dataflow

- Inputs: material-params
- Outputs: radiance, hdr-image
- Platforms: webgl2, webgpu, desktop-gpu, mobile-gpu

## Presets

### Rayleigh/Mie sky, low sun, 16x6 samples (glsl-fragment; rendered 2026-11-29)

```json
{
  "R_PLANET": 6371000,
  "R_ATMO": 6471000,
  "H_R": 8000,
  "H_M": 1200,
  "G": 0.76,
  "N_VIEW": 16,
  "N_LIGHT": 6
}
```

```glsl
// GLSL ES 3.0, Shadertoy-style. Single-scattering Rayleigh + Mie sky from the ground.
const float R_PLANET = 6371e3;
const float R_ATMO = 6471e3;
const vec3 BETA_R = vec3(5.8e-6, 13.5e-6, 33.1e-6);
const float BETA_M = 21e-6;
const float H_R = 8e3;
const float H_M = 1.2e3;
const float G = 0.76;
const float SUN_POWER = 22.0;
const int N_VIEW = 16;
const int N_LIGHT = 6;

vec2 raySphere(vec3 o, vec3 d, float r) {
  float b = dot(o, d);
  float h = b * b - (dot(o, o) - r * r);
  if (h < 0.0) return vec2(1e9, -1e9);
  h = sqrt(h);
  return vec2(-b - h, -b + h);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
  vec3 ro = vec3(0.0, R_PLANET + 2.0, 0.0);
  vec3 rd = normalize(vec3(uv.x, uv.y + 0.18, -1.0));
  float a = 0.10 + 0.06 * sin(iTime * 0.4);
  vec3 sun = normalize(vec3(0.25, sin(a), -cos(a)));

  float tmax = raySphere(ro, rd, R_ATMO).y;
  vec2 pl = raySphere(ro, rd, R_PLANET);
  if (pl.x > 0.0) tmax = min(tmax, pl.x);

  float mu = dot(rd, sun);
  float phaseR = 3.0 / (16.0 * 3.14159265) * (1.0 + mu * mu);
  float g2 = G * G;
  float phaseM = 3.0 / (8.0 * 3.14159265) * ((1.0 - g2) * (1.0 + mu * mu))
               / ((2.0 + g2) * pow(1.0 + g2 - 2.0 * G * mu, 1.5));

  float ds = tmax / float(N_VIEW);
  float odR = 0.0, odM = 0.0;
  vec3 sumR = vec3(0.0), sumM = vec3(0.0);
  for (int i = 0; i < N_VIEW; i++) {
    vec3 p = ro + rd * (ds * (float(i) + 0.5));
    float h = length(p) - R_PLANET;
    float dR = exp(-h / H_R) * ds;
    float dM = exp(-h / H_M) * ds;
    odR += dR; odM += dM;
    float tl = raySphere(p, sun, R_ATMO).y;
    float dl = tl / float(N_LIGHT);
    float lR = 0.0, lM = 0.0;
    for (int j = 0; j < N_LIGHT; j++) {
      vec3 q = p + sun * (dl * (float(j) + 0.5));
      float hq = length(q) - R_PLANET;
      lR += exp(-hq / H_R) * dl;
      lM += exp(-hq / H_M) * dl;
    }
    vec3 tau = BETA_R * (odR + lR) + vec3(BETA_M * 1.1) * (odM + lM);
    vec3 att = exp(-tau);
    sumR += att * dR;
    sumM += att * dM;
  }
  vec3 col = SUN_POWER * (sumR * BETA_R * phaseR + sumM * BETA_M * phaseM);
  if (pl.x > 0.0) col += vec3(0.02, 0.025, 0.02);
  col = 1.0 - exp(-col * 0.7);
  col = pow(col, vec3(1.0 / 2.2));
  fragColor = vec4(col, 1.0);
}

```

Attribution: written for this index; scattering coefficients are the commonly quoted Earth values used in Rayleigh/Mie tutorials

## Lineage

- extends [Henyey-Greenstein Phase Function](https://texelatlas.vercel.app/t/henyey-greenstein-phase-function.md)
- extends [Ray-marched Participating Media](https://texelatlas.vercel.app/t/volume-ray-marching.md)
- extended by [Precomputed Atmospheric Scattering](https://texelatlas.vercel.app/t/precomputed-atmospheric-scattering.md)

## Combines with

- [Henyey-Greenstein Phase Function](https://texelatlas.vercel.app/t/henyey-greenstein-phase-function.md): Supplies the anisotropic Mie phase term evaluated at the view-sun angle.
- [Screen-space Volumetric Light Scattering (God Rays)](https://texelatlas.vercel.app/t/volumetric-light-scattering-god-rays.md): Sky color gives the sun color and intensity used by the screen-space ray accumulation.

## Sources

1. [primary] Tomoyuki Nishita, Takao Sirai, Katsumi Tadamura, Eihachiro Nakamae (1993) Display of the earth taking into account atmospheric scattering. Proceedings of the 20th annual conference on Computer graphics and interactive techniques. https://doi.org/10.1145/166117.166140 (verified via crossref on 2026-11-29)
2. [implementation] wwwtyro (2016) wwwtyro/glsl-atmosphere. https://github.com/wwwtyro/glsl-atmosphere License: Unlicense. (verified via github on 2026-11-29)
3. [tutorial] Scratchapixel Simulating the Colors of the Sky. scratchapixel.com. https://www.scratchapixel.com/lessons/procedural-generation-virtual-worlds/simulating-sky/simulating-colors-of-the-sky.html (verified via http on 2026-11-29)

## Cite this entry

Texel. "Ray-marched Rayleigh/Mie Single Scattering." https://texelatlas.vercel.app/t/rayleigh-mie-single-scattering/ (accessed 2026-12-01).
