MarkovJunior (Rewrite-Rule Generation) × Lattice Boltzmann fluids × Froxel Volumetric Fog
Fog that flows through generated caves. Procedural caves and dungeons whose fog actually moves through them: drafts along corridors, eddies behind pillars. The generator's voxel grid is used directly as the fluid solver's solid boundary, so no remeshing sits between level and air.
Open in StudioReproduced131× · 4.07 ms
Verified proof

Split-screen WebGL2 proof comparing a MarkovJunior rewrite-rule dungeon chamber lit with static uniform distance fog (left, ignoring corridors and obstacles) against divergence-free LBM-inspired fluid drafts streaming through doorways and shedding vortices behind stone pillars, integrated into froxel-sliced volumetric light scattering from warm braziers and cool ceiling vents (right).
Chromium Headless ANGLE/SwiftShader WebGL2 · 512x512 · replaces flat homogeneous fog with obstacle-aware swirling dungeon drafts and shadowed froxel volumetric light beams around pillars
Show GLSL proof (166 lines)
const float P_DRAFT_SPEED = 1.00; // P LBM Draft Velocity [0.2, 2.2, 0.05]
const float P_FOG_DENSITY = 1.25; // P Froxel Fog Density [0.3, 2.5, 0.05]
const float P_VORTICITY = 1.05; // P Pillar Wake Vorticity [0.0, 2.0, 0.05]
const float P_TORCH_GAIN = 1.30; // P Brazier Scatter [0.3, 2.5, 0.05]
float sdBox2(vec2 p, vec2 b) {
vec2 q = abs(p) - b;
return length(max(q, 0.0)) + min(max(q.x, q.y), 0.0);
}
// MarkovJunior-style rewritten dungeon floorplan: rooms, doorways, and 3 obstacle pillars
float dungeonWalls(vec2 p) {
// Outer boundary walls with top-left cold vent opening and right exit archway
float outer = -sdBox2(p, vec2(0.45, 0.42));
// Internal partition wall with two carved doorways
float partTop = sdBox2(p - vec2(-0.08, 0.28), vec2(0.032, 0.14));
float partMid = sdBox2(p - vec2(-0.08, -0.02), vec2(0.032, 0.07));
float partBot = sdBox2(p - vec2(-0.08, -0.32), vec2(0.032, 0.10));
// Three monolithic stone pillars creating Karman vortex wakes in the main hall
float p1 = sdBox2(p - vec2(0.14, 0.16), vec2(0.048, 0.048));
float p2 = sdBox2(p - vec2(0.16, -0.14), vec2(0.052, 0.052));
float p3 = sdBox2(p - vec2(-0.27, -0.06), vec2(0.045, 0.055));
return min(min(outer, min(partTop, min(partMid, partBot))), min(p1, min(p2, p3)));
}
// Smooth obstacle-respecting LBM-inspired draft velocity + Karman vortex wake
vec2 draftVelocity(vec2 p, float t) {
// Base draft flowing left-to-right from cold vent through doorways
vec2 v = vec2(0.42, -0.06 * sin(p.x * 5.0));
// Speed up jet through the two partition doorways at x = -0.08
float jet1 = exp(-pow((p.x + 0.08) * 11.0, 2.0) - pow((p.y - 0.09) * 10.0, 2.0));
float jet2 = exp(-pow((p.x + 0.08) * 11.0, 2.0) - pow((p.y + 0.15) * 10.0, 2.0));
v.x += (jet1 + jet2) * 0.48;
// Deflect velocity tangentially around walls using SDF gradient
float e = 0.008;
float d = dungeonWalls(p);
vec2 g = normalize(vec2(
dungeonWalls(p + vec2(e, 0.0)) - dungeonWalls(p - vec2(e, 0.0)),
dungeonWalls(p + vec2(0.0, e)) - dungeonWalls(p - vec2(0.0, e))
) + vec2(1e-4));
float nearWall = smoothstep(0.08, 0.0, d);
v -= g * min(dot(v, g), 0.0) * nearWall;
// Shed alternating Karman vortices downstream (+x) of the hall pillars
vec2 dp1 = p - vec2(0.14, 0.16);
if (dp1.x > 0.0) {
float wake1 = exp(-dp1.x * 4.5 - dp1.y * dp1.y * 90.0);
v.y += sin(dp1.x * 38.0 - t * 4.2 * P_DRAFT_SPEED) * wake1 * 0.55 * P_VORTICITY;
}
vec2 dp2 = p - vec2(0.16, -0.14);
if (dp2.x > 0.0) {
float wake2 = exp(-dp2.x * 4.5 - dp2.y * dp2.y * 90.0);
v.y += cos(dp2.x * 36.0 - t * 4.0 * P_DRAFT_SPEED) * wake2 * 0.55 * P_VORTICITY;
}
return v * P_DRAFT_SPEED;
}
// Advected fog scalar density (injected at left vent & swirled through doorways and pillar wakes)
float fogDensityField(vec2 p, float zSlice, float t) {
if (dungeonWalls(p) < 0.0) return 0.0;
vec2 q = p;
// Semi-Lagrangian backtrace along obstacle-aware draft velocity
for (int i = 0; i < 6; i++) {
vec2 v = draftVelocity(q, t - float(i) * 0.12);
q -= v * 0.085;
}
float plume = exp(-pow((q.x + 0.38) * 2.2, 2.0)) * 0.95;
float wisps = 0.5 + 0.5 * sin(q.x * 16.0 - t * 1.9 * P_DRAFT_SPEED + sin(q.y * 19.0 + zSlice * 3.1));
float wisps2 = 0.5 + 0.5 * cos(q.y * 23.0 + sin(q.x * 18.0 - t * 1.4 * P_DRAFT_SPEED));
float ribbon = pow(wisps * 0.6 + wisps2 * 0.4, 1.8);
// Fog hugs lower floor height slices thicker than ceiling
float heightFalloff = exp(-zSlice * 1.35);
return (0.22 + plume * 0.95) * (0.35 + 1.15 * ribbon) * heightFalloff * P_FOG_DENSITY;
}
// 2D shadow ray against dungeon walls for froxel light shafts
float shadowTest(vec2 p, vec2 lightPos) {
vec2 dir = lightPos - p;
float dist = length(dir);
dir /= max(dist, 1e-4);
float t = 0.015;
for (int i = 0; i < 16; i++) {
if (t >= dist - 0.01) return 1.0;
float d = dungeonWalls(p + dir * t);
if (d < 0.002) return 0.0;
t += max(d * 0.88, 0.015);
}
return 1.0;
}
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 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
bool useCross = uv.x > 0.0;
vec2 p = vec2(useCross ? (uv.x - 0.25) : (uv.x + 0.25), uv.y);
p.x *= 1.85;
float dWall = dungeonWalls(p);
// Two dungeon light sources: cool cyan ceiling vent on left, flickering warm torch brazier in hall
vec2 lVent = vec2(-0.34, 0.26);
vec2 lTorch = vec2(0.05, 0.02 + 0.012 * sin(iTime * 6.0));
float flicker = 0.92 + 0.08 * sin(iTime * 11.0 + cos(iTime * 7.3));
vec3 cVent = vec3(0.28, 0.72, 1.15) * 1.35;
vec3 cTorch = vec3(1.55, 0.68, 0.18) * flicker * P_TORCH_GAIN;
vec3 col = vec3(0.0);
if (dWall < 0.0) {
// Top-down masonry wall blocks with MarkovJunior tile grid seams
vec2 brick = fract(p * 18.0);
float seam = smoothstep(0.05, 0.12, min(min(brick.x, 1.0 - brick.x), min(brick.y, 1.0 - brick.y)));
float bevel = smoothstep(-0.025, -0.002, dWall);
col = mix(vec3(0.055, 0.06, 0.072), vec3(0.11, 0.115, 0.135), seam) + vec3(0.08, 0.075, 0.065) * bevel;
} else {
// Flagstone dungeon floor
vec2 fl = fract(p * 14.0);
float grout = smoothstep(0.04, 0.10, min(min(fl.x, 1.0 - fl.x), min(fl.y, 1.0 - fl.y)));
vec3 floorAlb = mix(vec3(0.09, 0.095, 0.105), vec3(0.21, 0.215, 0.225), grout);
float ao = smoothstep(0.0, 0.055, dWall);
float visV = shadowTest(p, lVent);
float visT = shadowTest(p, lTorch);
float attV = 1.0 / (1.0 + 18.0 * dot(p - lVent, p - lVent));
float attT = 1.0 / (1.0 + 22.0 * dot(p - lTorch, p - lTorch));
vec3 direct = floorAlb * (vec3(0.05, 0.06, 0.08) + cVent * attV * visV * 1.4 + cTorch * attT * visT * 1.8) * (0.35 + 0.65 * ao);
if (!useCross) {
// Left: naive uniform static fog over dungeon floor (no obstacle flow or volumetric rays)
float flatFog = clamp(0.32 * P_FOG_DENSITY, 0.0, 0.72);
vec3 fogTint = mix(vec3(0.08, 0.12, 0.17), vec3(0.26, 0.17, 0.10), clamp(attT * 2.2, 0.0, 1.0));
col = mix(direct, fogTint, flatFog);
} else {
// Right: 8-slice Froxel volumetric integration through LBM-advected draft wisps
float T = 1.0;
vec3 inScat = vec3(0.0);
const int SLICES = 8;
float dz = 1.0 / float(SLICES);
for (int s = 0; s < SLICES; s++) {
float z = (float(s) + 0.5) * dz;
// Perspective parallax shift per height froxel slice
vec2 sp = p * (1.0 + (z - 0.5) * 0.06);
float rho = fogDensityField(sp, z, iTime);
if (rho > 0.005) {
float svV = shadowTest(sp, lVent);
float svT = shadowTest(sp, lTorch);
float aV = 1.0 / (1.0 + 14.0 * dot(sp - lVent, sp - lVent) + z * z * 1.8);
float aT = 1.0 / (1.0 + 16.0 * dot(sp - lTorch, sp - lTorch) + z * z * 1.8);
vec3 sliceLight = cVent * aV * svV * 2.1 + cTorch * aT * svT * 2.6 + vec3(0.04, 0.06, 0.09);
float ext = 1.0 - exp(-rho * dz * 1.55);
inScat += T * ext * sliceLight;
T *= (1.0 - ext * 0.65);
}
}
col = direct * T + inScat;
}
// Glowing brazier & vent emitter markers
col += cTorch * exp(-length(p - lTorch) * 44.0) * 1.8;
col += cVent * exp(-length(p - lVent) * 34.0) * 1.4;
}
col = acesTone(col);
if (abs(uv.x) < 0.003) 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
MarkovJunior (Rewrite-Rule Generation) outputs voxels: a labelled 3D grid of rock, floor and openings. Lattice Boltzmann fluids consumes voxels natively through bounce-back on solid cells, so the grid becomes its obstacle mask, with inflow at chosen openings. It outputs a volume-density field: a passive smoke or mist scalar carried by the simulated velocity. Froxel Volumetric Fog takes volume-density as an input, sampling the world-space density texture as it fills its frustum grid, then lights it with shadowed in-scattering and integrates per pixel, so shafts from torches and openings appear in moving fog.
How to build it
Generate a cave with a MarkovJunior 3D model and export the grid, which is already voxels. Upload it as a 3D texture at full or half resolution. Run D3Q19 LBM in compute shaders with two ping-pong buffers at a coarse cell size, inject density at vents, and advect a density scalar. In Unity HDRP, feed that density as the 3D mask of a local volumetric fog volume; in Unreal, sample it in the volumetric fog material. Step the simulation at a lower rate than the frame and interpolate between steps. Keep inflow speeds low for stability, and add a little vorticity so wisps survive.
Field marks
- LBM becomes unstable at higher flow speeds or low viscosity.
- Nineteen distributions per cell make large 3D domains memory-heavy.
- Froxel resolution blurs thin wisps into uniform haze.
- Blocky voxel walls create visible stair-step eddies.
Prior art
No prior art found on 2026-11-29.
Searches run (4)
- arXiv: all:"lattice Boltzmann" AND all:"volumetric fog" → 0 results
- GitHub repos: "lattice Boltzmann" "volumetric fog" → 0 results
- arXiv: all:"procedural level" AND all:"fluid simulation" AND all:"voxel" → 0 results
- GitHub repos: "procedural level" "fluid simulation" voxel → 0 results