Texel A field guide to 3D techniques

MacCormack Predictor-Corrector Clamped Fluid Advection × Nubis-style Ray-marched Volumetric Clouds

Billowing Nubis volumetric clouds driven by MacCormack clamped advection. Advecting cloud moisture and cumulus anvil density with second-order MacCormack clamped advection keeps curling thunderhead edges razor-crisp over minutes of live weather evolution, eliminating the syrupy blurring of standard semi-Lagrangian wind scroll.

Open in StudioReproduced6308× · 195.6 ms

MacCormack Predictor-Corrector Clamped Fluid AdvectionSimulation · Real-timein: voxels, volume-densityout: voxels, volume-densitycompositeNubis-style Ray-marched Volumetric CloudsVolume · Real-timein: texture, depth, material-paramsout: radiance, volume-density

Verified proof

reproduced · 2026-12-01texel-lablicense MIT
Specimen render of MacCormack advection + Nubis clouds (left: blurry semi-Lagrangian drift, right: clamped MacCormack + Beer-Powder Nubis)
Cross-proof specimen. MacCormack advection + Nubis clouds (left: blurry semi-Lagrangian drift, right: clamped MacCormack + Beer-Powder Nubis). Verified WebGL2 proof · 2026-12-01

Split-screen WebGL2 proof comparing diffusive first-order semi-Lagrangian cloud wind drift (left) against second-order clamped MacCormack thermal-updraft advection driving Nubis volumetric ray-marched clouds with crisp Worley cauliflower edges and Beer-Powder scattering (right).

Chromium Headless ANGLE/SwiftShader WebGL2 · 512x512 · preserves crisp billowing cumulus anvil curls via clamped MacCormack predictor-corrector advection inside Nubis volumetric cloud ray-marching

Show GLSL proof (151 lines)
const float P_ADVECT_SHARP = 0.85; // P MacCormack Sharpen [0.2, 1.4, 0.05]
const float P_CLOUD_DENS = 1.15; // P Cloud Density [0.5, 2.0, 0.05]
const float P_POWDER_STR = 0.78; // P Beer-Powder Edge [0.1, 1.4, 0.05]
const float P_WIND_SPEED = 0.65; // P Updraft Velocity [0.0, 1.5, 0.05]

float hash31(vec3 p) {
  p = fract(p * 0.1031);
  p += dot(p, p.yzx + 33.33);
  return fract((p.x + p.y) * p.z);
}

float vnoise3(vec3 p) {
  vec3 i = floor(p);
  vec3 f = fract(p);
  f = f * f * (3.0 - 2.0 * f);
  return mix(
    mix(mix(hash31(i), hash31(i + vec3(1.0, 0.0, 0.0)), f.x),
        mix(hash31(i + vec3(0.0, 1.0, 0.0)), hash31(i + vec3(1.0, 1.0, 0.0)), f.x), f.y),
    mix(mix(hash31(i + vec3(0.0, 0.0, 1.0)), hash31(i + vec3(1.0, 0.0, 1.0)), f.x),
        mix(hash31(i + vec3(0.0, 1.0, 1.0)), hash31(i + vec3(1.0, 1.0, 1.0)), f.x), f.y),
    f.z
  );
}

float fbm3(vec3 p) {
  float s = 0.0;
  float a = 0.5;
  for (int i = 0; i < 4; i++) {
    s += a * vnoise3(p);
    p = p * 2.03 + vec3(1.7, -1.2, 2.3);
    a *= 0.5;
  }
  return s;
}

// Divergence-free swirling cumulus thermal updraft velocity field
vec3 thermalVel(vec3 p, float t) {
  float swirl = sin(p.y * 1.4 - t * 0.8);
  return vec3(0.45 * cos(p.z * 0.9 + t * 0.5) - 0.25 * p.z * swirl, 0.68 + 0.24 * cos(p.x * 1.2), 0.35 * sin(p.x * 1.1 + t * 0.6)) * P_WIND_SPEED;
}

// Base macro moisture silhouette of a towering cumulus anvil
float macroMoisture(vec3 p) {
  vec3 q = p - vec3(0.0, 0.25, 0.0);
  float core = 1.0 - length(q * vec3(0.68, 0.85, 0.72));
  float anvil = 1.0 - length((q - vec3(0.35, 0.58, -0.15)) * vec3(0.55, 1.55, 0.62));
  float base = max(core, anvil * 0.88);
  float shape = base + (fbm3(p * 1.35 + vec3(0.0, -0.4, 0.0)) - 0.45) * 0.75;
  return clamp(shape, 0.0, 1.0);
}

// Compare semi-Lagrangian (blurred) vs clamped MacCormack predictor-corrector advection + Nubis Worley erosion
float cloudDensity(vec3 p, float t, bool useMacCormack) {
  float dt = 0.48;
  vec3 u = thermalVel(p, t);
  vec3 pBack = p - u * dt;
  if (!useMacCormack) {
    // Left baseline: first-order semi-Lagrangian diffuses gradients across neighboring cells
    float eps = 0.22;
    float phi0 = macroMoisture(pBack);
    float phiBlur = 0.2 * (phi0 + macroMoisture(pBack + vec3(eps, 0.0, 0.0)) + macroMoisture(pBack - vec3(eps, 0.0, 0.0)) + macroMoisture(pBack + vec3(0.0, eps, 0.0)) + macroMoisture(pBack - vec3(0.0, eps, 0.0)));
    return max(0.0, phiBlur - 0.26) * P_CLOUD_DENS * 1.35;
  } else {
    // Right: MacCormack forward-backward step clamped to local stencil bounds [minN, maxN]
    float phiHat = macroMoisture(pBack);
    vec3 pFwd = pBack + thermalVel(pBack, t) * dt;
    float phiBack = macroMoisture(pFwd);
    float phiOrig = macroMoisture(p);
    float eps = 0.14;
    float n1 = macroMoisture(pBack + vec3(eps, 0.0, 0.0));
    float n2 = macroMoisture(pBack - vec3(eps, 0.0, 0.0));
    float n3 = macroMoisture(pBack + vec3(0.0, eps, 0.0));
    float n4 = macroMoisture(pBack - vec3(0.0, eps, 0.0));
    float lo = min(phiHat, min(min(n1, n2), min(n3, n4)));
    float hi = max(phiHat, max(max(n1, n2), max(n3, n4)));
    float phiMC = clamp(phiHat + 0.5 * P_ADVECT_SHARP * (phiOrig - phiBack), lo, hi);

    // Nubis billowy cauliflower Worley-like detail erosion along outer shell
    vec3 flowP = pBack * 2.85 + vec3(0.0, -t * 0.35 * P_WIND_SPEED, 0.0);
    float billow = 1.0 - abs(vnoise3(flowP) * 2.0 - 1.0);
    float fine = 1.0 - abs(vnoise3(flowP * 2.15 + 3.7) * 2.0 - 1.0);
    float erode = (1.0 - (billow * 0.65 + fine * 0.35)) * 0.34;
    float d = smoothstep(0.18, 0.68, phiMC - erode * (1.0 - phiMC));
    return d * P_CLOUD_DENS * 1.65;
  }
}

float hgPhase(float cosTheta, float g) {
  float g2 = g * g;
  return (1.0 - g2) / (12.56637 * pow(max(1.0 + g2 - 2.0 * g * cosTheta, 1e-4), 1.5));
}

vec3 acesTone(vec3 x) {
  return clamp((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14), 0.0, 1.0);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 res = max(iResolution.xy, vec2(1.0));
  vec2 uvN = fragCoord / res;
  float splitX = iMouse.z > 0.0 ? clamp(iMouse.x / res.x, 0.05, 0.95) : 0.5;
  bool useMacCormack = uvN.x > splitX;

  vec2 p = (fragCoord - 0.5 * res) / res.y;
  float t = iTime;
  vec3 ro = vec3(0.0, 0.12, 3.25);
  vec3 rd = normalize(vec3(p.x * 1.15, p.y + 0.10, -1.55));
  vec3 sunDir = normalize(vec3(0.68, 0.42, -0.58));

  // Twilight golden-hour sky backdrop
  float elev = clamp(rd.y * 1.4 + 0.18, 0.0, 1.0);
  vec3 sky = mix(vec3(0.86, 0.48, 0.28), vec3(0.10, 0.22, 0.46), pow(elev, 0.68));
  float sunCos = dot(rd, sunDir);
  sky += vec3(1.6, 0.95, 0.45) * pow(max(sunCos, 0.0), 28.0) * 0.75;

  // Dual-lobe Henyey-Greenstein phase for silver lining + back scatter
  float phase = mix(hgPhase(sunCos, 0.72), hgPhase(sunCos, -0.25), 0.28) * 10.5;

  vec3 accumLight = vec3(0.0);
  float transmittance = 1.0;
  float tStart = 1.25;
  float dtStep = 0.10;

  for (int i = 0; i < 42; i++) {
    vec3 pos = ro + rd * (tStart + float(i) * dtStep);
    float dens = cloudDensity(pos, t, useMacCormack);
    if (dens > 0.004) {
      // Sun light optical depth march (4 steps toward sun)
      float sunOD = 0.0;
      for (int s = 1; s <= 4; s++) {
        sunOD += cloudDensity(pos + sunDir * (float(s) * 0.24), t, useMacCormack) * 0.24;
      }
      float beer = exp(-sunOD * 2.15);
      float powder = useMacCormack ? (1.0 - exp(-sunOD * 3.8 * P_POWDER_STR)) : 0.72;
      float energy = mix(beer, beer * powder * 2.1, useMacCormack ? 0.72 : 0.2);
      // Multi-scattering height gradient (warm sunlit top, cool blue-slate cloud base)
      float heightGrad = clamp((pos.y + 0.75) * 0.55, 0.0, 1.0);
      vec3 sunCol = vec3(1.45, 1.12, 0.84) * (0.45 + phase * 0.55);
      vec3 ambCol = mix(vec3(0.14, 0.22, 0.36), vec3(0.42, 0.50, 0.64), heightGrad);
      vec3 scat = (sunCol * energy + ambCol * 0.62) * dens;
      float stepT = exp(-dens * dtStep * 2.8);
      accumLight += transmittance * scat * (1.0 - stepT) / max(dens, 1e-4) * 0.85;
      transmittance *= stepT;
      if (transmittance < 0.02) break;
    }
  }

  vec3 col = sky * transmittance + accumLight;
  col = acesTone(col * 1.05);
  if (abs(fragCoord.x - splitX * res.x) < 1.0) col = vec3(0.95, 0.93, 0.89);
  fragColor = vec4(pow(clamp(col, 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}

Why they connect

MacCormack Predictor-Corrector Clamped Fluid Advection transports a 3D moisture/density grid (or 2D weather coverage + height-band anvil fields) through a divergence-free thermal updraft velocity field via forward-backward predictor-corrector steps clamped tightly to local stencil min/max bounds. The hop to Nubis-style Ray-marched Volumetric Clouds is composite: feed the sharpened advected coverage/density volume as the macro weather-and-shape field into the Nubis cloud ray-marcher, which carves fine-scale billowing edges using tiling 3D Perlin-Worley detail noise, evaluates dual-lobe Henyey-Greenstein scattering plus powder-sugar dark-edge attenuation, and outputs physically lit volumetric clouds.

How to build it

Maintain a 2D multi-channel weather texture (coverage, precipitation, cloud-top height) or compact 3D density volume advected by a curl-plus-buoyancy velocity field. Each step, compute phi_hat = Advect(phi, +u, dt), reverse-advect phi_back = Advect(phi_hat, -u, dt), form the second-order estimate phi_mc = phi_hat + 0.5 * (phi - phi_back), and clamp phi_mc strictly to [min_neighbors, max_neighbors] around the departure cell to prevent dispersive ringing. In the Nubis cloud fragment pass, ray-march the cloud layer, sample the MacCormack-advected macro density, erode its outer shell with animated 3D Worley fBM, and integrate Beer-Powder transmittance with multiple-scattering octaves toward the sun.

Field marks

  1. Clamping fallback near sharp velocity shear reverts locally to first-order semi-Lagrangian dissipation, softening small isolated wisps.
  2. High CFL wind speeds (u * dt > 1 cell) break the 2x2x2 neighbor clamping assumption and can introduce stair-stepped density streaks.
  3. Mixing dynamically advected macro density with static tiling Worley detail noise creates visible texture-swimming unless UV detail coordinates are also flow-advected and phase-blended.
  4. Full 3D advection + 64-step volumetric ray-marching with sun shadow marches saturates fragment ALU without temporal reprojection or quarter-res cloud rendering.

Prior art

No prior art found on 2026-12-01.

Searches run (2)
  • arXiv: all:"MacCormack" AND all:"volumetric clouds"
  • GitHub repos: "maccormack" volumetric clouds