[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-116095":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":14,"subscribersCount":14,"size":14,"stars1d":15,"stars7d":16,"stars30d":16,"stars90d":14,"forks30d":14,"starsTrendScore":17,"compositeScore":18,"rankGlobal":9,"rankLanguage":9,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":22,"hasPages":20,"topics":23,"createdAt":9,"pushedAt":30,"updatedAt":31,"readmeContent":32,"aiSummary":33,"trendingCount":14,"starSnapshotCount":14,"syncStatus":13,"lastSyncTime":34,"discoverSource":35},116095,"SmartImposter","SamG-Coder\u002FSmartImposter","SamG-Coder","Hardware ray-traced forest renderer (Rust + Vulkan) with parallax octahedral impostors evaluated by the RTX cores",null,"Rust",167,19,2,0,4,58,20,77.7,"MIT License",false,"main",true,[24,25,26,27,28,29],"foliage","impostors","ray-tracing","rendering","rust","vulkan","2026-11-20 06:34:33","2026-11-23 20:45:17","# SmartImposter\n\n**A hardware ray-traced renderer of forests and of the whole Earth, written from scratch in Rust +\nVulkan. Every plant beyond its mesh distance is a parallax octahedral impostor evaluated by the RTX\ncores, and NVIDIA DLSS Ray Reconstruction turns one noisy sample per pixel into the final image.**\n\n![Meadow at the forest edge, 1440p, DLSS-RR DLAA](docs\u002Fimages\u002Fhero.jpg)\n\nIt runs in three modes, all through the same renderer:\n\n- **A generated forest** (the default): a 144 km landscape from a tectonic uplift and river\n  erosion simulation, with a forest grown on it by seed dispersal and succession, in any of eight\n  biomes (`--biome temperate|boreal|rainforest|savanna|desert|tundra|mediterranean|alpine`).\n- **A real place** (`--site lat,lon`): the same forest scene on real terrain and land cover.\n- **The whole Earth at 1:1** (`--globe`): terrain, land cover, forests, clouds and the sea streamed\n  in from orbit down to standing height.\n\nThe default temperate forest holds **about 6.2 million plants** in an 8 km radius:\n\n| Layer | Count | Species |\n|---|---|---|\n| Canopy trees | 5,872,027 | European beech, black alder, black poplar, European aspen, common hazel |\n| Shrubs | 101,189 | heather, huckleberry oak |\n| Ferns | 140,250 | bracken |\n| Grass patches | 116,223 | wild grass, grass clumps, tall grass, tufted grass, dry grass, cotton grass |\n| Boulders and deadwood | 2,032 | mossy boulders, fallen logs, snags |\n\nTrees, shrubs and ferns are **Quixel Megaplants**, with every leaf as real geometry: up to\n**519 million triangles per tree** once all twig instances are expanded. The grass, palms, cacti\nand props are **Quixel Megascans**. Near the camera everything is drawn as the real asset. Beyond\nthat, each plant collapses to a single AABB in the acceleration structure, and an intersection\nshader ray-marches a baked, BC-compressed hemi-octahedral atlas of it. The atlases are baked on the\nsame GPU, with the same ray tracing pipeline, once, and cached.\n\n**At 1440p on an RTX 5080: about 10 ms per frame with DLSS-RR Quality, 15–20 ms with DLAA.**\n\n| ![Forest interior](docs\u002Fimages\u002Fcanopy.jpg) | ![Flyover](docs\u002Fimages\u002Foverview.jpg) |\n|---|---|\n| Beech, aspen and alder over leaf litter, with bracken and huckleberry in the understory | From 55 m up. Every tree past ~50 m is an impostor |\n| ![Cotton grass](docs\u002Fimages\u002Fmeadow.jpg) | ![Grass close up](docs\u002Fimages\u002Fgrass_close.jpg) |\n| Cotton grass on wet ground, dry grass and heather | Real Megascans grass cards at eye level |\n| ![Forest edge](docs\u002Fimages\u002Fforest_edge.jpg) | ![From above](docs\u002Fimages\u002Ffrom_above.jpg) |\n| Forest edge: poplar, hazel and huckleberry | Looking down on a meadow: real grass near, grass impostors far |\n\n## Contents\n\n- [Highlights](#highlights)\n- [Performance](#performance)\n- [How it works](#how-it-works)\n  1. [Assets](#1-assets-keeping-half-a-billion-triangles-cheap)\n  2. [Baking and compressing the impostor](#2-baking-and-compressing-the-impostor)\n  3. [The intersection shader](#3-the-intersection-shader-shadersimpostorrint)\n  4. [Lighting impostors like the real plant](#4-lighting-impostors-like-the-real-plant)\n  5. [Grass](#5-grass)\n  6. [LOD and draw distance](#6-lod-and-draw-distance)\n  7. [Terrain, rivers, forest growth, ground and biomes](#7-terrain-rivers-forest-growth-and-ground)\n  8. [Materials](#8-materials)\n  9. [Frame: DLSS Ray Reconstruction](#9-frame-dlss-ray-reconstruction-or-taa)\n  10. [Performance work](#10-performance-work)\n- [The Earth: a 1:1 globe and real places](#the-earth-a-11-globe-and-real-places)\n- [Getting started](#getting-started)\n- [Tools](#tools) · [Code layout](#code-layout) · [Limitations](#limitations) · [License](#license)\n\n## Highlights\n\n- **Hardware ray tracing end to end.** Primary rays, sun shadows, AO and the impostor bake all go\n  through `VK_KHR_ray_tracing_pipeline`. There's no rasterizer.\n- **Impostors as procedural geometry.** One AABB per far plant. The RT cores do traversal and\n  culling, and a custom intersection shader marches the baked depth (parallax occlusion mapping in\n  each view's orthographic space).\n- **DLSS Ray Reconstruction.** NVIDIA's AI denoiser and upscaler replaces TAA + supersampling,\n  through a small C++ shim over the NGX SDK. Without the SDK the engine builds and runs with its\n  own TAA.\n- **Shader Execution Reordering.** On RTX 40\u002F50 the primary rays are regrouped by what they hit\n  before shading.\n- **Forests that grow.** The canopy comes out of a seed-dispersal and succession simulation on\n  eroded terrain: beech stands, alder on wet ground, poplar and hazel at forest edges, aspen groves,\n  heather on dry open ground, bracken under the canopy, cotton grass in wet meadows. Eight biome\n  presets put other species, understory, ground and climate on the same landscape.\n- **The Earth at 1:1.** A cube-sphere quadtree of terrain tiles from orbit to 5 m cells, from\n  Copernicus 30 m elevation, ESA 10 m land cover and the RESOLVE ecoregions, with trees to the\n  horizon, a physically based atmosphere, volumetric clouds placed by climate, an FFT ocean, and the\n  real sun and moon.\n- **Megascans grass.** Clumps are grouped into 3 m patches. Real alpha-tested cards near the\n  camera, compressed impostors beyond, the ground texture past the draw distance.\n- **Compressed, cached, streamed atlases.** Each variant's atlas is sized and cropped to the\n  plant, BC-compressed on the GPU (3.25 bytes per texel instead of 16) and cached on disk. The\n  forest scene loads only what grows in it; on the globe every variant keeps a small base atlas and\n  only the variants growing near the camera stream in their full one.\n- **Impostors that light like the real plant.** Traced, layered self-shadowing, plus the *normal\n  spread* of the leaves or blades baked per texel. Impostor brightness is within a few percent of\n  the real meshes, front-lit, back-lit and from above, for trees and grass alike.\n- **Natural ground.** Four scanned surfaces with hex-tile stochastic texturing (no visible\n  repetition), blended by a mask built from the actual tree crowns, moisture and dryness.\n- **LOD with no popping.** Every boundary is a stochastic per-pixel dissolve. The mesh any-hit and\n  the impostor intersection shader share one random number, so exactly one copy of a plant answers\n  each ray.\n\n## Performance\n\nRTX 5080, 2560x1440, median frame time over 300 frames. DLAA is the quality reference.\n\n**The generated forest** (the default temperate biome, ~6.2M plants, 4.2 GB of GPU memory):\n\n| View | DLAA | DLSS-RR Quality | DLSS-RR Balanced |\n|---|---|---|---|\n| Clearing at eye level (`0,1.7,0,0,2`) | 18.6 ms | 9.9 ms | 7.9 ms |\n| Forest interior (`-150,1.7,-150,40,4`) | 20.5 ms | 10.5 ms | 8.4 ms |\n| From 45 m (`0,45,0,30,-10`) | 15.5 ms | 8.6 ms | 6.3 ms |\n\n```\nsmart_imposter --size 2560x1440 --dlss quality --views \"0,1.7,0,0,2;-150,1.7,-150,40,4;0,45,0,30,-10\" --frames 300 --shot shots\u002Fperf.png\n```\n\nQuality renders at 1708x960 and is about 2x faster than DLAA. It's a little softer on grass blades:\n\n![DLAA vs DLSS-RR Quality](docs\u002Fimages\u002Fdlss_modes.jpg)\n\nWhere the time goes in the clearing at DLAA (GPU timestamps, printed by every screenshot run):\nray tracing (primary, sun shadow and AO rays) 13.1 ms, DLSS Ray Reconstruction 5.2 ms, tonemap,\nsharpen and blit 0.08 ms; the CPU's LOD pass and instance list (~0.1 ms) overlap the previous\nframe's GPU work. `SI_PROF_SKIP` takes out the shadow and AO rays to see their share.\n\n**The globe** (DLSS-RR Quality, clouds on; GPU time once the view has streamed in):\n\n| View (`--at`) | GPU | GPU memory |\n|---|---|---|\n| Lake Como from 300 m (`46.05,9.25,300,200,-8`) | 15.7 ms | 8.0 GB |\n| In the treetops above Lake Como (`45.99,9.262,12,250,-4`) | 12.9 ms | 10.6 GB |\n| Aokigahara and Mount Fuji from 70 m (`35.47,138.62,70,140,-8`) | 18.1 ms | 10.8 GB |\n| The Earth from 12,000 km (`30,5,12000000,0,-90`) | 5.2 ms | 7.1 GB |\n\nFlying at 240 m\u002Fs, 300 m over Lake Como, with everything streaming in (`--bench-move 4`, 900\nframes): average 17.2 ms, 99th percentile 21–23 ms, worst 24–37 ms over repeated runs.\n\nStartup: the forest scene is ready in ~8 s: the world in ~3 s (the grown forest comes from\n`assets\u002Fcache\u002Fforest`; the first run of a biome grows its ~6M trees in ~23 s, the succession\nsimulation), then the renderer in ~5 s (texture decode, BLAS builds, impostor atlases from the\ncache in ~1 s). The globe is ready in ~3 s. The first run of a scene bakes and caches the impostor\natlases it shows (~5 s for a biome's 60–90 variants, ~16 s for all 207 on the globe) and\ncompresses the textures.\n\nGPU memory: 4.2 GB for the default temperate forest (1.8 GB desert, 4.7 GB boreal, 5.1 GB\nrainforest), 7–11 GB on the globe depending on the view. The forest scene loads only what grows\nin it: 62 of the 207 variants, 172 of the 517 meshes, 17 of the 52 species' textures and 12 of\nthe 26 ground scans in the temperate biome.\n\n## How it works\n\n```mermaid\nflowchart LR\n    UE[\"Unreal project\u003Cbr\u002F>(Fab Megaplants)\"] -->|tools\u002Fue_export_megaplants.py| USD[\"per-species USD meshes,\u003Cbr\u002F>assembly.json, textures\"]\n    USD -->|tools\u002Fmegaplant_to_mtree.py| MTREE[\"assets\u002Fspecies\u002F*.mtree + .json\"]\n    FAB[\"Fab Megascans grass\u003Cbr\u002F>(glTF)\"] -->|tools\u002Fgrass_to_mtree.py| MTREE\n    MTREE --> CAT[\"catalog.rs\u003Cbr\u002F>species, variants, LOD scale\"]\n    CAT --> WORLD[\"world.rs\u003Cbr\u002F>biome scatter, ground mask\"]\n    CAT --> BLAS[\"BLAS per unique mesh\u003Cbr\u002F>AABB BLAS per variant\"]\n    BLAS --> BAKE[\"Impostor bake\u003Cbr\u002F>(bake.rgen, alpha-tested)\"]\n    BAKE --> ENC[\"mip.comp + bcenc.comp\u003Cbr\u002F>BC3 \u002F BC5 atlases\"]\n    WORLD --> FRAME[\"Per frame (CPU, overlapped):\u003Cbr\u002F>LOD per plant, instance list\"]\n    ENC --> FRAME\n    FRAME --> TRACE[\"main.rgen (SER)\u003Cbr\u002F>primary + shadow + AO rays,\u003Cbr\u002F>G-buffer\"]\n    TRACE --> DLSS[\"DLSS Ray Reconstruction\u003Cbr\u002F>(or taa.comp)\"] --> RES[\"resolve.comp\u003Cbr\u002F>tonemap\"] --> CAS[\"sharpen.comp\"] --> OUT[\"swapchain\"]\n```\n\n### 1. Assets: keeping half a billion triangles cheap\n\nIn UE 5.x a Megaplant is a Nanite assembly: a hierarchy of parts (trunk, branches, twigs, leaf\nclusters) placed by transforms, with the same few meshes reused hundreds to thousands of times.\n`ue_export_megaplants.py` reads that assembly data inside Unreal and exports each unique mesh, the\npart hierarchy, the textures and the material parameters. `megaplant_to_mtree.py` flattens the\nhierarchy: small subtrees are merged into one mesh, large ones stay instanced. The result is unique\nmeshes plus a list of (mesh, transform) parts per variant.\n\nThe engine builds one BLAS per unique mesh: 517 meshes, 31.4M triangles, for 207 variants of 52\nspecies. A near tree costs one TLAS instance per part, not a copy of its geometry:\n\n| Species | Expanded triangles per variant | Parts per variant |\n|---|---|---|\n| Black alder | 71M – 519M | 281 – 2,029 |\n| Black poplar | 59M – 119M | 1,251 – 2,459 |\n| European beech | 1.2M – 27M | 105 – 388 |\n| European aspen | 2.1M – 12M | 131 – 795 |\n| Heather | 3.0M – 15M | 113 – 668 |\n| Grass patch | 0.1M – 1.4M | 10 – 194 clumps |\n\n### 2. Baking and compressing the impostor\n\n`bake.rgen` builds a TLAS containing just one full-detail plant and shoots orthographic rays from\n12x12 directions on a hemi-octahedral grid, with 3x3 sub-samples per texel. It's the same ray\ntracing pipeline and the same closest-hit and any-hit shaders used at runtime, so the bake sees\nexactly the materials, and the alpha-tested cut-outs, the meshes have.\n\n![Impostor atlas](docs\u002Fimages\u002Fatlas.jpg)\n\nEach variant's frame resolution follows its size: 5.5 cm texels for a full-size tree (scaled by\nthe variant's LOD scale, since small plants switch to impostors closer; grass gets 1.6x coarser\ntexels), rounded to a multiple of 32 and capped at 448 px for the square that shows the plant's\nwhole bounding sphere.\n\n**Frames cropped to the plant.** A tree is tall and narrow: in that square 65–90% of the texels\nare empty. So the frame that is baked and kept is the square cropped, about its centre, to what\nthe plant can cover in any view (`frame_res` in `src\u002Frenderer.rs`): as wide as the plant reaches\nsideways from its axis, as tall as it reaches at all, both measured on the real vertices, plus a\nmargin of one texel of the coarsest mip. The rays and their random numbers are those of the square\nbake, and the crop moves in whole BC blocks of the coarsest level, so the texels and blocks that\nremain are bit for bit the square's; only the empty margins go. A poplar's 448 px square becomes\n192x448, an aspen's 352 px square 160x352. Compact plants (grass patches, shrubs, boulders) keep\ntheir squares.\n\nThe bake writes an uncompressed scratch atlas shared by all variants. `mip.comp` builds\ncoverage-weighted mips, so empty texels don't drag depth or colour towards zero. Then `bcenc.comp`\n(one thread per 4x4 block) compresses every level, and the blocks are copied into the sampled\natlases:\n\n| Atlas | Format | Contents |\n|---|---|---|\n| albedo | BC3 | sqrt(albedo), ray-traced ambient occlusion |\n| normal | BC5 | octahedral normal |\n| depth | BC5 | depth along the view, coverage (fraction of sub-samples that hit) |\n| visibility | BC3, half resolution | sky visibility `a + b·up`, **normal spread** (length of the averaged normal) |\n\nTexels with zero coverage are left out of the block endpoint fit, so silhouette blocks keep their\nprecision. That's 3.25 bytes per texel instead of 16: with the cropped frames all 207 variants\ntake 5.5 GB at full resolution (0.6–125 MB each; 7.4 GB as squares, 27 GB uncompressed).\n\n**Baked once, loaded by need** (`src\u002Fatlas.rs`). The compressed blocks of a variant go to\n`assets\u002Fcache\u002Fimpostors`, keyed on the asset, the settings and the bake shaders, so later starts\nread them instead of baking (`SI_REBAKE=1` forces a bake). A variant is baked the first time a\nscene shows it.\n\n- **The forest scene** only ever shows the variants that grow in it (62 of the 207 in the\n  temperate biome): their full atlases are loaded at startup (1.8 GB), and nothing for the rest.\n- **The globe** can bring any species into view. Every variant keeps a base atlas on the GPU, its\n  levels from 1\u002F4 resolution down, which is all a far impostor samples anyway. A variant gets its\n  full atlas while one of its plants is close enough for the base atlas's texels to be bigger than\n  a pixel, nearest first within `SI_IMPOSTOR_MB` (default 25% of VRAM): a loader thread reads it\n  straight into a mapped upload buffer, and the copies are recorded into the frame like any other\n  upload, so it never stalls a frame.\n\n### 3. The intersection shader (`shaders\u002Fimpostor.rint`)\n\nFor each far plant a ray touches, the RT cores invoke the intersection shader with the ray in\nplant space:\n\n1. **LOD decision.** The shader looks up the instance (per-instance buffer indexed by\n   `gl_InstanceID`). It dissolves against the mesh copy if the plant is in the mesh band, and\n   dissolves the plant out near its draw distance.\n2. **View selection.** It finds the 3 baked views around the ray direction and picks **one**,\n   with probability equal to its (sharpened) barycentric weight. Blending three slightly\n   misaligned views per sample causes ghosting and a smeared look. The temporal accumulation\n   (DLSS-RR or TAA) averages the stochastic choice instead.\n3. **Parallax march.** In that view's orthographic space the ray is linear, `S(t) = A + B·t`\n   (uv, height), and is marched against the baked depth:\n   - **Front crossings only:** a hit requires an empty → solid transition, so rays entering the\n     box from the side don't hit extruded heightfield walls.\n   - **Foliage shell:** a thin shell behind the surface (0.12 of the radius), not an infinitely\n     deep solid, so views from below don't smear on clump undersides.\n   - **Coverage decided once per crossing:** a ray is blocked with probability equal to the\n     texel's coverage. Testing at every step biases towards the maximum along the path, which\n     made crowns too dense and shadows solid.\n   - **Adaptive step count, binary refinement, single-mip march fetches.**\n4. **Attributes.** It reports the hit with albedo, normal and visibility packed into hit\n   attributes.\n\n### 4. Lighting impostors like the real plant\n\n**Shadows.** Shadow rays through an impostor are marched like a camera ray **from the sun**:\nstochastic view choice around the light direction, shell crossing, then a fresh coverage test\nevery 0.12 of the radius of crown depth (layered, Beer–Lambert-like). The light that reaches a\nleaf or the ground under a crown is dappled, like the real one.\n\n**Normal spread.** An impostor texel stands for many leaves or blades facing different ways. The\nbake averages their normals; the *length* of that average says how coherent they are (1 = a flat\nsurface, ~0.5 = leaves in all directions), and that's stored per texel and per mip. Using the\nrenormalised average as if it were one surface lit every texel as if all its leaves faced the sun:\ngrass seen from above came out 1.6–2x too bright, and trees needed a fudge factor.\n\n- **Trees** return their normal shortened to the spread, so Lambert gives the leaves' mean\n  diffuse. Leaf transmission keeps full strength: some leaves always face away from the sun.\n- **Grass and ferns** have normals bent upwards, so seen from above hardly any blade is back-lit:\n  the spread scales all their sunlight.\n\n**Crown-level transmission and sheen.** With the crown normal, `max(-n·l)` put a whole crown's\ntransmission on the side facing away from the sun at full strength, and the tonemapper bleached\nthose hot spots. Impostors use a broad lobe with the same total energy. Glossy leaves get a Fresnel\nsheen of the view\u002Fsun geometry: in a crown some leaf always faces the half vector.\n\nMeasured on plant pixels only, impostor \u002F real mesh brightness:\n\n| Plant | Front-lit | Back-lit | From above |\n|---|---|---|---|\n| Alder | 1.02 | 0.98 | 0.87* |\n| Aspen | 1.05 | 1.00 | 0.87* |\n| Beech | 1.02 | 0.98 | 0.95* |\n| Poplar | 1.20 | 0.98 | 0.82* |\n| Wild grass | 0.98 (low angle) | | 0.99 |\n| Dry grass | 0.99 (low angle) | | 1.14 |\n\n\\* From above, the impostor's albedo itself reads 0.86–0.90 (crown edges), so the lighting is\nwithin a few percent.\n\n![Tree impostors vs real meshes](docs\u002Fimages\u002Ftree_impostor_vs_mesh.jpg)\n\n### 5. Grass\n\nA Megascans grass asset is a few small clumps (0.3–1.3 m), far too small to instance one by one\nacross a landscape. `tools\u002Fgrass_to_mtree.py` reads the Fab glTF download and builds **patch**\nvariants: about 3 m of randomly placed, rotated and scaled clumps (instanced parts of the LOD0\nmeshes) inside a disc with a ragged edge, so overlapping patches merge into one sward. It also\ncomposes the engine's foliage texture pair (colour+opacity, normal+translucency) and reads the\nmaterial's translucency tint.\n\n- **Alpha testing:** meshes of grass species are flagged; their instances are non-opaque, and\n  `tri.rahit` discards hits where the texture's opacity is below the cutoff. The cutoff drops with\n  distance, since box-filtered mips thin the blades' coverage. This runs for camera, shadow and AO\n  rays, and in the impostor bake, so impostors and shadows have the shape of the blades.\n- **Placement:** a scatter layer (2.3 m spacing, 600 m radius) on open ground and forest edges:\n  wild grass and grass clumps as the base, dry grass on dry ground, cotton grass on wet ground,\n  tall and tufted grass in drifts (the temperate mix; each biome preset has its own). Each patch\n  tilts to the slope.\n- **LOD:** real cards to ~20 m, compressed impostors beyond, then a dissolve into the ground\n  texture at 140–200 m.\n\n![Grass impostors vs real cards](docs\u002Fimages\u002Fgrass_impostor_vs_mesh.jpg)\n\n#### Lawn: short grass with no geometry (`--lawn on`, experimental)\n\nShort grass is the worst case for the patches above: it is everywhere, a few centimetres high, and\nevery ray that grazes the ground stops at one patch box after another. The lawn is the impostor\ntechnique turned on its side, with nothing in the acceleration structures beyond the first metres\naround the camera:\n\n- **One tile of real blades** (`src\u002Flawn.rs`: 0.42 m, ~5,300 curved, tapering blades up to 4.5 cm,\n  in clumps; `--lawn-height` sets the height) is baked once like a plant, between copies of itself\n  so the result wraps around.\n- **Views laid out for a ground cover.** A view from direction f stores, for the line along f\n  through every point of the plane of the blade tips, the height of the first blade on that line,\n  plus its colour, normal, coverage and sky visibility: a height map sheared along f. The plants'\n  hemisphere grid has only a handful of views below 20°, where a lawn is nearly always seen, and\n  smears it into streaks. So the lawn has 16 azimuths x 12 slopes, spaced geometrically in\n  cot(elevation) from 79° down to 2.4° (a standing eye sees the lawn through its own views out to\n  ~40 m): 192 views of 320 texels, one 5120x3840 atlas (85 MB).\n- **Marched in the terrain's hit shader** (`shaders\u002Flawn.glsl`). A ray that hits lawn-covered\n  ground is backed up to the top of the blade slab and marched down through the nearest view with\n  wrap-around lookups, the same coverage-per-crossing march as `impostor.rint`. A hit moves the\n  surface up to the blade and takes its colour, normal and visibility; a miss shades the soil\n  between the blades, darkened by them.\n- **Self-shadowing** uses the view nearest the sun as a shadow map of the tile; trees still shadow\n  the lawn through the ordinary shadow ray.\n- **No rows of repeats.** One square repeated shows as lines: every clump lines up with its\n  copies along every direction of the grid. So each copy of the tile is shifted by its own random\n  amount (the tile wraps, so a shifted copy is whole), with ragged borders between copies. Blade\n  height also varies over a few metres and in tufts a foot across, the tile coordinates are bent\n  by a slow noise, and the colour follows the ground layers underneath.\n- **Thin in flat views.** A point counts as blade if it is just behind the first blade on its\n  line; in a flat view that depth is kept to one blade height along the ground, or blades seen a\n  few degrees off their view smear sideways.\n- **LOD is the mip chain.** Far lawn is a coarser level of the same atlas, fading into the ground\n  texture by 220 m.\n- **Real blades around the camera.** A layer inside the ground has parallax but no silhouette,\n  and its blades stand in front of nothing: fine for a lawn seen from standing height, flat for\n  anything taller or closer. So within a few metres of the camera the tile itself is drawn as\n  geometry: one instance of its mesh per square of the grid, sheared onto the terrain and turned\n  one of four ways. They are the same blades the layer was baked from, tinted the same way. 4 m\n  of a lawn, up to 30 m of tall grass (`--lawn-near`); a few hundred to a few thousand instances\n  of one BLAS.\n- **The hand-over is blade by blade.** Towards the edge of that circle whole blades drop out one\n  at a time, by the distance of their own root from the camera (`tri.rahit`), while the layer\n  fades in under them: there is no edge of tiles to see and nothing shrinks.\n- **One height field for both.** How much of its height the grass stands at is one continuous\n  function of the place (`shaders\u002Flawnh.glsl`): the layer squashes its blades by it, and each\n  real blade is trimmed to its value at the blade's own root, so neighbouring tiles grade into\n  each other instead of stepping.\n- **Automatic length (`--lawn auto`).** The grass is long where it would be left to grow and\n  short elsewhere, from a map built with the scene (`World::build_grass_map`): long under and\n  around trees, in hollows and in patches of rough with ragged edges, short on the open ground\n  between, blended over a few metres. One tile baked at the long height (32 cm) serves both;\n  the short grass is 4.5 cm.\n- **Quality (`--grass low|medium|high|ultra`, key B)** scales how far the real blades and the\n  layer are drawn: 0.35x, 0.65x, 1x and 2x (ultra: real blades to 58 m of tall grass, the layer\n  to 440 m). In the park all four trace in 1.6 to 1.9 ms at 1080p; ultra adds about 3,000\n  instances.\n- **Any height.** `--lawn meadow` (22 cm) and `--lawn tall` (45 cm), or `--lawn-height` in cm, are\n  the same layer: the tile is four blade heights across, the blades grow wider and fewer, and\n  unmown grass has blades of every length, arching, with seed stalks. In the forest scene a\n  meadow also stands in for the tall and dry grass patches.\n\nWith the lawn on, the biome's short grass patches are thinned to a fifth (`--lawn 0.3` keeps 30%;\n116,223 patches become 73,071 in the default scene) and the taller, dry and wet grasses stay as\nits tufts. Ray tracing time at 1440p, DLSS Quality, median of three alternating runs (measured\nwith the first version of the lawn: 8.5 cm blades, 96 views, a 42 MB atlas):\n\n| View | Lawn | Patches only |\n|---|---|---|\n| Clearing, eye height | 5.79 ms | 6.54 ms |\n| Forest interior | 6.69 ms | 7.00 ms |\n| From 45 m up | 4.69 ms | 4.83 ms |\n| Standing, looking across | 7.63 ms | 7.97 ms |\n| Looking down at the ground | 4.26 ms | 4.77 ms |\n| Eye 0.5 m above the ground | 7.40 ms | 7.29 ms |\n\nGPU memory was 4.24 GB against 4.20 GB (the atlas is 43 MB larger now). The march itself is nearly free (laid over the full grass\nits cost was within run-to-run noise, except 0.3–0.5 ms looking straight down); the time saved is the patch boxes that\nare no longer there.\n\n![Lawn](docs\u002Fimages\u002Flawn.jpg)\n\n*Top: the default clearing with grass patches only, and with `--lawn meadow`. Bottom: the park's\nmown lawn and its tall grass (`--lawn tall`), both from 0.75 m.* It is off by default: see\n[Limitations](#limitations).\n\n**The park (`--park`)** is a scene made for it: rolling hills of lawn and nothing else on the\nground, with the biome's trees in groves and a few standing alone (about 8,800 within 1.4 km), and\nhigher hills behind. There are no grass patches, shrubs or rocks, the lawn runs up to the trunks,\nand its blades are kept nearly even, as mown. It starts on foot (see [Controls](#controls)) and\nruns at about 4 ms a frame at 2560x1080 with DLSS Quality on an RTX 5080.\n\n```\ncargo run --release -- --park\n```\n\n![The park](docs\u002Fimages\u002Fpark.jpg)\n\n*The park as a lawn, and with `--lawn tall`.*\n\n### 6. LOD and draw distance\n\n| Distance (x the variant's LOD scale) | Representation | In the TLAS |\n|---|---|---|\n| \u003C 44 m | real mesh | one instance per part, `FORCE_OPAQUE` (non-opaque for alpha-tested cards) |\n| 44–56 m | both | parts non-opaque with a dissolve any-hit (`tri.rahit`), plus the impostor |\n| > 56 m | impostor | one AABB |\n| 0.8–1x draw distance | impostor dissolving out | small plants only |\n\nThe LOD scale is the plant's height \u002F 16 m, clamped to 0.25–1.2 (grass at least 0.4). A 32 m\npoplar switches at 60 m, a fern at 12.5 m. Plants under 2 m are drawn to 120 + 60 m per metre of\nheight, plants under 6 m to 450 m. The CPU keeps a per-plant state machine with hysteresis and\nrebuilds the instance list only when a plant changes state; the shaders compute the fade from the\nexact distance every frame, so the transition is continuous. An 8M-instance budget keeps very\nlong mesh distances from exhausting GPU memory.\n\n**Impostor boxes in cells.** The forest scene's plants are grouped into 192 m cells, one AABB\nBLAS per cell with one box per plant, and a record per plant (its transform, variant and seed).\n2.6M of the 6.2M plants have a draw distance (hazel,\nshrubs, ferns, grass): the intersection shader drops them beyond it, so their boxes are only\nworth having near the camera. A cell's permanent BLAS holds just the plants that are never\nculled; while the camera is within the draw distance of a cell, the TLAS shows a complete BLAS of\nit instead, built inside the frame when the cell comes into reach and freed when it is left\nbehind. The picture is the same, and the far cells' boxes take no memory.\n\n### 7. Terrain, rivers, forest growth and ground\n\n**Terrain from erosion.** `erosion.rs` lifts a 144 km landscape by a tectonic uplift field and cuts\nit down with rivers, using the stream-power law solved implicitly (Braun & Willett 2013; Cordonnier\net al. 2016). Every iteration a priority-flood pass (Barnes et al. 2014) routes all water to the sea,\nand the drainage area is accumulated. Branching valleys, ridges and basins come out of the\nsimulation; the result is cached in `assets\u002Fcache`. Rivers are the cells draining more than 12 km²,\ntraced into smoothed, meandering polylines with widths from their catchment and a water level that\nonly falls downstream. Floodplains, banks and a riverbed are cut along them. The mesh is 3 m near\nthe start, grows to 200 m cells out to ±60 km, and carries the Earth's curvature.\n\n**Forest growth as succession.** Trees are grown, not scattered:\n\n- founder pairs on a 60 m lattice where the site allows forest, then 10 generations (~150 years)\n  of seed dispersal;\n- pioneers (aspen in root-sucker groves, poplar and alder in thickets) colonise open ground and\n  gaps; shade-tolerant beech establishes under them and overtops them;\n- every species has a lifespan and an age of first seeding; windthrow gaps of all sizes reset\n  patches early on;\n- a seedling fails under a crown two generations older within 5.5 m (light competition).\n\nThe result is a mosaic of stand ages and species, with alder and poplar along the rivers and\nmeadows on the valley floors (~6M trees in an 8 km radius). Shrubs, ferns and grass are scattered\non jittered grids from the simulated canopy cover.\n\nGrowing the forest takes ~23 s, and it is a pure function of the terrain, the biome, the radius\nand the code, so the result is cached in `assets\u002Fcache\u002Fforest` under a name made of all of them\n(the code as a hash of `world.rs`, `biome.rs` and `erosion.rs`, taken at build time). The next\nstart reads it in a fraction of a second; a changed input or changed code grows a new one, and\n`SI_REGROW=1` forces it.\n\nThe ground blends twelve scanned surfaces found in the Fab library cache: forest floor, mossy\ngrass, uncut grass, dried grass, two rock cliffs, snow, gravel, lichen rock, riverbed, pebbles and\nwet grass:\n\n- **Biome mask:** a 1024² mask is built at startup from the actual tree crowns (canopy cover),\n  moisture, dryness and understory density. Leaf litter goes under closed canopy, moss on wet\n  ground and under scattered trees, grass and dry grass in the open.\n- **No visible repetition:** hex-tile stochastic texturing (Mikkelsen 2022). The plane is split\n  into hexagons and every lookup blends three samples, each with its own random rotation and\n  offset, with contrast-preserving weights.\n- **Natural edges and large-scale variation:** layer boundaries are perturbed by noise at ~3, 16\n  and 80 m, and open ground varies in brightness and hue over tens of metres.\n- **Height-based blending** (grass blades over litter), and a per-layer gain: the scans' mean\n  albedos differ about 10x.\n- **Landform-driven layers:** leaf litter only under the simulated crowns; dry grass on convex,\n  sun-facing ground and lush grass in hollows; rock where it is too steep for soil (triplanar, with\n  strata), scree and snow by altitude zone; pebble bars, mud and wet grass along the water.\n- **Water:** rivers and lakes have a bed below the water surface. The ray-gen shades the surface\n  over the bed: absorption with depth (Beer-Lambert) and in-scattering, sunlight attenuated down to\n  the bed, flowing ripples, foam where it is shallow, a ray-traced reflection by Fresnel, the sun\n  glint, and wet banks.\n\n![Ground: plain tiling vs hex-tile stochastic texturing](docs\u002Fimages\u002Fground_tiling.jpg)\n\n**Biomes (`--biome`).** The eroded terrain can carry any of eight biomes (`src\u002Fbiome.rs`):\n`temperate` (the default), `boreal`, `rainforest`, `savanna`, `desert`, `tundra`, `mediterranean`\nand `alpine`. The terrain stays the erosion simulation's; a preset decides what grows on it and how\nthe ground looks:\n\n- **Canopy:** the succession works with six ecological roles (shade-tolerant climax trees, trees\n  of wet ground, edge pioneers, clonal groves, an understory tree, others). A preset fills them with\n  its species: spruce over birch pioneers and aspen groves in the taiga, Aleppo pine and oak in the\n  Mediterranean, broad crowns, bamboo and palms in the rainforest. It also sets how much of the\n  land is forest, how wide the strips along the rivers are (a ribbon of willows and palms at the\n  water in the desert), how far apart the trees stand (open savanna) and how tall they grow (dwarf\n  birch and willow in the tundra).\n- **Understory:** shrubs, forest plants and grasses, each with the habitat it grows in (open\n  ground, forest edges, under the canopy; moist, dry or wet grass), plus boulder fields (clustered,\n  and under steep ground) and deadwood.\n- **Ground:** the 12 ground slots of `tri.rchit` (forest floor, moss, grass, dry grass, rock,\n  snow, scree, mud, pebbles, wet grass) map to any of the 26 scans: sand and arid soil in the\n  desert, red clay in the rainforest, tundra and lichen ground, boreal moss.\n- **Climate:** plants' dryness tint, how dry and wet the ground is, the treeline and snow line\n  (higher in the tropics and deserts, lower in the tundra), and a default sun, haze and exposure.\n\n| | |\n|---|---|\n| ![temperate](docs\u002Fimages\u002Fbiomes\u002Ftemperate.jpg) `temperate` | ![boreal](docs\u002Fimages\u002Fbiomes\u002Fboreal.jpg) `boreal` |\n| ![rainforest](docs\u002Fimages\u002Fbiomes\u002Frainforest.jpg) `rainforest` | ![savanna](docs\u002Fimages\u002Fbiomes\u002Fsavanna.jpg) `savanna` |\n| ![desert](docs\u002Fimages\u002Fbiomes\u002Fdesert.jpg) `desert` | ![tundra](docs\u002Fimages\u002Fbiomes\u002Ftundra.jpg) `tundra` |\n| ![mediterranean](docs\u002Fimages\u002Fbiomes\u002Fmediterranean.jpg) `mediterranean` | ![alpine](docs\u002Fimages\u002Fbiomes\u002Falpine.jpg) `alpine` |\n\n### 8. Materials\n\n![Leaves front-lit and back-lit](docs\u002Fimages\u002Fleaves.jpg)\n\n`tri.rchit` shades leaves and bark with each species' textures (4 per species, selected by the\nmesh's texture set):\n- **Leaves:** colour, normal map, and a translucency map. Transmitted light is leaf albedo x the\n  Unreal material's translucency tint x the translucency mask, like Unreal's two-sided foliage.\n- **Per-species normalisation:** Megaplant colour maps are authored very differently (Unreal's\n  material darkens the pale ones), so the foliage brightness and the translucency mask are\n  normalised per species from texture statistics at load time. Grass is matched to the ground it\n  stands on.\n- **Bark:** colour, normal, and AO.\n- **Normal mapping:** a tangent frame built per triangle from the UV gradients.\n- **Mip selection:** a ray cone (hit distance x pixel spread vs texel size on the triangle), using\n  the output-resolution footprint when DLSS upscales.\n- **Leaf variation:** a subtle per-leaf colour change from the converter's leaf ids, and paler\n  undersides.\n\n### 9. Frame: DLSS Ray Reconstruction (or TAA)\n\n`main.rgen` traces one primary ray per pixel and computes direct sun light (one traced shadow\nray), leaf transmission, specular, sky ambient with one traced AO ray, and a procedural sky with\nclouds. That's noisy by design: the dissolve bands, the stochastic impostor view and coverage, the\nsingle shadow and AO rays all rely on temporal accumulation.\n\n**With DLSS Ray Reconstruction** (`native\u002Fdlss_shim.cpp`, `src\u002Fdlss.rs`), `main.rgen` also writes\nthe G-buffer NGX needs: linear view depth, per-pixel motion (each hit point reprojected into the\nprevious camera), world normal + roughness, diffuse albedo, and pre-integrated specular albedo.\nDLSS-RR denoises and upscales from the render resolution to the display, then `resolve.comp`\ntonemaps (ACES) and `sharpen.comp` applies contrast-adaptive sharpening.\n\nDetails that mattered:\n- **Jitter:** the samples use a Halton(2,3) sequence (32 frames). NGX wants the offset of the\n  *projection*, the opposite sign of where the samples sit. Measured: all four sign combinations,\n  both-flipped clearly sharpest.\n- **Texture mips:** with upscaling, textures are sampled for the output pixel footprint.\n- **Required Vulkan extensions** are queried from NGX and enabled when the driver offers them.\n\n**Without DLSS** (or `--dlss off`), the frame goes through `taa.comp`: reprojection, 4x4\nCatmull-Rom history, depth-based disocclusion rejection, YCoCg variance clipping, Karis weighting,\nand an exact running average when the camera is still. `resolve.comp` then downsamples from the\nsupersampled resolution, tonemapping each sample before averaging.\n\n### 10. Performance work\n\nThe goal was speed without any visible change at DLAA. Every candidate was measured with GPU\ntimestamps and compared with the previous build's image (old and new builds run alternately,\ntwice). These were measured on the first, smaller forest (440k plants in a 1.4 km radius):\n\n| Change | Result |\n|---|---|\n| **Shader Execution Reordering** (`hitObjectTraceRayNV` + `reorderThreadNV` for primary rays) | ray tracing 5–9% faster, same image |\n| **CPU\u002FGPU overlap:** the LOD update for 440k plants and the instance list are built before waiting for the previous frame; only the upload waits | fly-through median 13.5 → 11.0 ms |\n| Overall at DLAA | 4–7% faster in still views, 15–18% in the fly-through; image differences at the run-to-run noise floor |\n\nTried and dropped:\n\n| Idea | Why not |\n|---|---|\n| Opacity micromaps for the grass cards | Megascans cards already hug the blades: 60–100% of the card area would still be \"unknown\" and need the any-hit |\n| Ground AO rays skipping grass | 17% faster from above, but the ground between blades got visibly brighter |\n| Cheaper impostor march for AO rays | no measurable gain |\n| Separate R8 opacity textures for the alpha test | no measurable gain |\n\nA later pass on the 6.2M-plant forest was about GPU memory (8.3 GB -> 4.2 GB, same image, same\nframe time): loading only what the scene shows, cropped impostor frames, cells that keep\ndraw-distance plants out of the far field, no terrain index buffer. Profiling it showed where the\nray tracing time goes: a fixed cost for every plant box a ray stops at (halving the impostor march\nsteps, or the ground shading, changes nothing; shrinking the boxes by 30% saves 15%). What that\nruled out:\n\n| Idea | Why not |\n|---|---|\n| Up to 3 stacked hull boxes per plant (thin at the trunk, wide at the crown) | these trees branch almost to the ground: no gain, +105 MB of BLAS |\n| A cylinder bound around each plant's axis instead of its turned box | crowns are not round enough: within noise |\n| A 32-byte plant record (position + scaled quaternion) instead of the 3x4 matrix | 125 MB less, but ~5% slower: the unpacking runs for every box |\n\nThe remaining cost is primary rays through dense grass (any-hit invocations) and the fixed DLSS-RR\ncost at DLAA; DLSS-RR Quality halves the frame time for a slightly softer image.\n\n## The Earth: a 1:1 globe and real places\n\nThe plan for the whole planet at true scale is in [docs\u002FEARTH_PLAN.md](docs\u002FEARTH_PLAN.md). Built\nso far:\n\n- **`--globe`: the planet at 1:1, in the same renderer.** A cube-sphere quadtree of terrain tiles\n  from orbit down to ~5 m cells, streamed in as you fly. Positions are float64 on the CPU and\n  camera-relative float32 on the GPU, so it holds still from orbit to standing height. The globe is\n  a mode of the main renderer, so it keeps the same path tracing, DLSS Ray Reconstruction \u002F TAA,\n  AO, mesh LOD band and see-through water. A single-scattering atmosphere (Rayleigh + Mie) gives\n  the sky, sunlight, sky light and aerial perspective from the ground to space.\n  - Trees to the horizon: tree tiles out to the visible horizon (`sqrt(2Rh)` from the camera\n    height, plus a ridge allowance). Every tree is placed within 6 km; coarser tiles further out\n    keep 1\u002F4^k of the trees at their true size, and the terrain shader adds the canopy colour of\n    the ones left out. Near the camera the trees switch to meshes through the usual LOD band,\n    and grass, ferns and shrubs grow from the 20 m land cover within 700 m.\n    - Tree thinning, smooth or stepped (`--tree-thinning smooth|stepped`, key N; smooth by\n      default). Smooth: trees also thin out continuously with distance inside each tile\n      (impostor.rint rejects a tree once its distance asks for less than its tile's density;\n      `thinLevels` in rt.glsl), so the density meets the next tile level's at every tile edge and\n      the canopy colour follows the same curve: no density squares from the air. Rays pass\n      through the trees that are thinned out, so it can cost a little in dense forest.\n      Stepped: one density per tile, the canopy colour by whole levels; tiles of\n      different levels meet with a visible density step from high up. (Measured at Lake Como,\n      2560x1392 DLSS Quality: smooth 11.28 ms, stepped 11.32 ms average, within run-to-run\n      noise.)\n  - Clouds (`shaders\u002Fclouds.glsl`, noise from `src\u002Fcloudnoise.rs`), after Schneider's Nubis\n    (Horizon), Hillaire's Frostbite sky and Wrenninge's multiple scattering:\n    - Three layers fixed to the Earth: low clouds from 600 m (stratus and stratocumulus ~1 km\n      thick, cumulus to ~3 km, cumulonimbus towers with anvils to 11 km), altocumulus at\n      3.5-5 km, cirrus streaks at 8-9.5 km drawn out along the wind.\n    - Where they form: the equatorial band of towering convection, clear subtropics and\n      deserts, marine stratocumulus decks off subtropical west coasts (ocean with land to the\n      east), the cloudy mid-latitude storm tracks, polar stratus; weather systems of ~800 km and\n      cells of ~12 km that grow and decay over tens of minutes; `--cloud-cover` scales it all.\n    - Shapes from tiling 3D noise textures built once and cached: Perlin-Worley billows eroded by\n      Worley fBm, a height profile per cloud type (flat bases, rounded tops), wispy below.\n    - Light: sunlight marched towards the sun and summed over three scattering octaves\n      (multiple scattering: bright, soft interiors), the droplet phase function of Jendersie &\n      d'Eon 2023 (Henyey-Greenstein + Draine fitted to Mie: silver linings, fogbow and glory\n      lobes), darker thin edges seen away from the sun (powder), light diffused down through the\n      cloud above (1 \u002F (1 + 0.75 tau (1 - g)): thick parts darker on the base), sky light from the\n      atmosphere and the sunlit ground's bounce. Clouds shadow the ground through all three\n      layers, dim the sky light under them and show in water reflections.\n    - About 3.2 ms at 2560x1392 (Lake Como, 15.0 vs 11.8 ms); `--clouds off` or key U.\n    - **The forest scenes have the same clouds** (the generated forest, a site, the park), in\n      place of the cumulus painted on their sky. A planet is put under the scene, whose terrain\n      already carries the Earth's curvature, so the same march runs unchanged; the weather is a\n      fair day's (fields of cumulus with a base ~850 m over the start, a little altocumulus and\n      cirrus, `--cloud-cover` scales it). They are lit by the scene's own sun and sky fill, in\n      its sky's brightness, and fade into that sky with distance. Their shadows drift over the\n      land, with the shadow density eroded as the visible clouds are (the coarse density alone\n      shades far beyond the cloud one sees), and in a shadow the fill light turns grey and\n      brighter. About 0.3 to 0.6 ms at 1080p; `--clouds off` (key U) brings the painted sky back.\n\n      ![Clouds over the park and the forest](docs\u002Fimages\u002Fforest_clouds.jpg)\n  - Atmosphere: ozone absorption, and samples packed towards the eye with each one dimmed only to\n    its own middle, so the horizon is pale and hazy rather than a brown band.\n  - The sea (`src\u002Fglobe\u002Focean.rs`, `shaders\u002Fmain.rgen`), built the way film and game oceans are\n    (Tessendorf, \"Simulating Ocean Water\"):\n    - Waves from a measured spectrum: JONSWAP wind sea plus a narrower swell, directional\n      spreading, deep-water dispersion. Four FFT cascades (1024, 256, 64, 16 m patches, 128^2)\n      on a background thread (~5 ms a step, overlapped), with choppy displacement (sharp crests,\n      round troughs), slopes and the Jacobian, uploaded each frame as RGBA16F textures with mips.\n    - Wind by region: trade winds, calm doldrums, westerlies (strongest in the Southern Ocean),\n      polar easterlies, varied by weather patterns; the spectrum follows the camera's place.\n    - Real wave geometry within 1.5 km: every view ray is marched through the slab the waves\n      fill and stops on the height field (bisection-refined), so crests hide the troughs behind\n      them and the skyline is made of waves; further out the cascades are normal detail.\n    - Roughness from physics: what the mips average away plus the Cox-Munk slope variance below\n      the finest cascade (0.003 + 0.00512 U) drives the reflection blur and a Beckmann sun\n      glitter, so the glitter path widens with the wind as over the real sea.\n    - Whitecaps where the crests fold (lowest Jacobian), steered so their area matches the\n      measured coverage for the wind (Monahan: 3.84e-6 U^3.41, ~1% at 10 m\u002Fs), fading over a few\n      seconds, drawn as dense fresh foam with streaks trailing downwind.\n    - Water colour by floor depth: clear deep blue over the open ocean (pure water absorbs red,\n      barely blue), greener over the shelf; light glows through thin crests when the sun is\n      behind them (after the Atlas GDC 2019 water BSDF); waves die out as the bottom shoals.\n    - No repeating patches (stochastic tiling): each cascade is laid out on hex cells ~1.5\n      patches across, every cell at a random offset and turned up to +-25 degrees about the\n      wind, three cells blended per point (variance-preserving, slopes and displacements turned\n      back); amplitudes rise and fall in wave groups, and the whitecaps cluster with them.\n    - Cost at sea level (2560x1392, DLSS Quality): ~10.4 ms a frame with clouds.\n    Lakes keep their own calmer wind ripples.\n  - Streaming without hitches: one pool of worker threads builds terrain tiles (first) and grows\n    tree tiles. Their vertex copies and BLAS builds are recorded into the frame's own command\n    buffer, with no GPU waits. Storage is pooled and device-local: fixed slots for terrain\n    vertices and BLASes, one plant record \u002F AABB buffer, and size-class slabs for tree BLASes.\n    Tile selection, instance lists and mesh LOD run while the previous frame is still on the GPU.\n    A tree tile that is being replaced by a finer or coarser one stays until its replacement is\n    in, so the forest never shows bare patches. The coarse terrain tiles above the drawn ones\n    (and their siblings) are never evicted, so very fast flight lowers the detail gradually\n    instead of dropping whole regions to a coarse tile. Moving fast, tiles are requested by their\n    distance from where the camera will be ~30 frames later, so the ground ahead fills first.\n  - Elevation: NOAA ETOPO 2022 (60″, global, land and seafloor), Copernicus GLO-30 (30 m) where its\n    tiles are present, blended at the edges. The whole ETOPO grid also lives on the GPU for\n    per-pixel coastlines and relief far away.\n  - Land cover: ESA WorldCover 2021 (10 m) where present, as fractions per terrain vertex. They pick\n    the Quixel ground scans (forest floor, grass, rock on cliffs, glaciers, gravel, wetland) and mark\n    lakes and rivers.\n- **Time, sun and moon.** A UTC clock drives the sun and the moon (Astronomical Almanac \u002F\n  Meeus formulas: sun to ~0.01 degrees, moon to ~0.3), so the Earth turns under them: day and\n  night, the seasons, and from orbit the terminator sweeping across the planet. The moon has its\n  real phase and brightness (~2.4 millionths of sunlight at full); at night it is the light, and the\n  eye adapts (pre-exposure in main.rgen, so moonlit radiance survives the 16-bit targets). `,` `.`\n  step an hour (Shift: a day), `\u002F` cycles the speed (real time, a minute, an hour or a day per\n  second, stopped); `--time 2026-06-21T19:30` starts at a UTC time.\n- **Water and shores.** Every terrain tile carries a 64 x 64 signed distance to the shore (from the\n  10 m land cover, ETOPO where there is none), filtered per pixel: coastlines and lake shores are\n  smooth curves at any distance. The same field gives the depth (lakes shelve to ~18 m, the sea to\n  ~12 m and then ETOPO's seafloor), so the water is see-through over its bed: shallows show the\n  pebbles or sand, foam at the waterline, a wet strip and a pebble or beach-sand strip on the shore,\n  deep blue sea and dark lakes further out.\n- **Biomes.** RESOLVE Ecoregions 2017 (846 ecoregions in 14 biomes, `tools\u002Fbake_biomes.py` ->\n  a 3.7 km grid) chooses per place:\n  - which trees grow (globe\u002Fforest.rs `BIOME_TREES`: e.g. spruce, pine, birch in the taiga; beech,\n    oak, maple, hornbeam in temperate forest; Aleppo pine and oak in Mediterranean scrub; palms in\n    oases and the tropics), with conifers taking over with altitude in temperate mountains and\n    alders \u002F willows \u002F poplars on wet ground;\n  - which understory plants belong there (bilberry and anemone in temperate and boreal forest,\n    greasewood in deserts and steppe, ...);\n  - which ground scans cover the land (globe.rchit: mossy forest floor in the taiga, red soil in\n    the tropics, dry grass and red soil in savanna, sand and arid soil in deserts, tundra stones\n    and lichen in the Arctic, mud in wetlands and mangroves, glacier ice, ploughed fields, beach\n    sand on sea coasts).\n\n  Species and scans are found by name: a Quixel asset that is not downloaded is skipped (the\n  biome's other species, or a stand-in, take its place) and grows where it belongs once it is.\n- **`--site lat,lon`: a real place in the forest renderer.** The local tangent plane at that point\n  (with the Earth's curvature), heights from GLO-30 \u002F ETOPO, lakes and rivers from WorldCover,\n  streams from a priority-flood drainage of the real 30 m heights, and the forest grown only where\n  WorldCover has tree cover. Altitude zones shift with latitude.\n- **M** in site mode returns to the globe above the same spot.\n\n**Data (free, not included).** `tools\u002Ffetch_earth.py` downloads it into `assets\u002Fearth\u002F`\n(resumable: stop and restart any time; `--bbox south,west,north,east` limits it to a region):\n\n| Command | Folder | Dataset | Download | On disk |\n|---|---|---|---|---|\n| (by hand) | `etopo\u002F` | [NOAA ETOPO 2022](https:\u002F\u002Fwww.ncei.noaa.gov\u002Fproducts\u002Fetopo-global-relief-model) 60″ ice surface, `ETOPO_2022_v1_60s_N90W180_surface.tif` | 466 MB | 0.9 GB |\n| `fetch_earth.py dem` | `glo30\u002F` | [Copernicus DEM GLO-30](https:\u002F\u002Fregistry.opendata.aws\u002Fcopernicus-dem\u002F), 26,450 1° tiles | ~543 GB | ~120 GB |\n| `fetch_earth.py cover` | `worldcover\u002F` | [ESA WorldCover 2021 v200](https:\u002F\u002Fregistry.opendata.aws\u002Fesa-worldcover-vito\u002F), 2,651 3° tiles | 124 GB | 124 GB |\n| `fetch_earth.py vectors` | `ecoregions\u002F`, `hydrorivers\u002F`, `hydrolakes\u002F` | [RESOLVE Ecoregions 2017](https:\u002F\u002Fecoregions.appspot.com\u002F), [HydroRIVERS \u002F HydroLAKES](https:\u002F\u002Fwww.hydrosheds.org\u002F) | 1.5 GB | 5.3 GB |\n\nElevation tiles are converted to a compact `.dem` file as they arrive (half-metre int16,\ngradient-predicted, deflate: ~4.5x smaller than the GeoTIFF; `smart_imposter --convert-dem`).\nNothing is loaded up front: the workers decode elevation tiles and 1024 x 1024 land-cover blocks\nthe first time they need them and keep the recent ones in memory. Far terrain reads the land\ncover's overviews (20 m ... 600 m pixels) instead of single 10 m pixels. The globe runs with\nETOPO alone; the 30 m elevation and land cover exist wherever their tiles are present.\n\nStreaming on an RTX 5080 at 1920x1080, DLSS-RR Quality, `--bench-move` over 900 frames:\n\n| Run | avg | p99 | max | frames > 33 ms |\n|---|---|---|---|---|\n| Flight at 300 m over Lake Como, 4 m\u002Fframe | 7.3 ms | 9.5 ms | 12.3 ms | 0 |\n| Walk on an alpine slope, 0.3 m\u002Fframe | 6.3 ms | 10.2 ms | 11.2 ms | 0 |\n| Flight at 1500 m, 15 m\u002Fframe | 7.1 ms | 11.0 ms | 15.5 ms | 0 |\n\nEarlier, with synchronous per-tile uploads, the same runs had p99 64–68 ms and maxima of 76–110 ms.\nA cold view streams in fully in ~1.8 s after the first frame (was 4.3 s).\n\nThe Quixel species (52 packs, 207 variants; docs\u002FQUIXEL_DOWNLOADS.md): 16 trees (European beech,\nblack alder, black poplar, European aspen, common hazel, Norway spruce, Baltic pine, silver birch,\nEnglish oak, goat willow, Norway maple, Aleppo pine, dead pine, rowan, elder, giant bamboo), shrubs\nand forest plants (heather, huckleberry oak, greasewood, European spindle, bilberry, wood anemone,\nbracken, leather fern, Xanadu, Zamia, five palms, yuccas, dead shrubs), scanned props (cacti,\nboulders, logs, snags), 13 grasses and 26 ground scans. Megaplants\nare exported from Unreal with `tools\u002Fue_export_megaplants.py` (the USD plugins must be enabled) and\nconverted with `tools\u002Fmegaplant_to_mtree.py` (needs Pixar's `usd-core`); the Megascans glTF\ndownloads go through `tools\u002Ffab_to_mtree.py` and `tools\u002Fgrass_to_mtree.py`.\n\nGPU memory is kept in check without losing detail: textures are block-compressed on first use and\ncached (`assets\u002Fcache\u002Ftex`): colour as BC7, normal x \u002F y as BC5, single data channels as BC4,\n>= 35 dB for almost all of them, a quarter of RGBA8 or less; static and streamed BLASes are\ncompacted (the tree meshes 1.9 -> 0.7 GB); tree AABBs are build input only; plant records carry\nno padding; the terrain grid's triangles are worked out in the shader (no index buffer); the\nforest scene loads only the species that grow in it; impostor frames are cropped to the plant and\natlases stream by need (see [Baking and compressing the\nimpostor](#2-baking-and-compressing-the-impostor)). Terrain tiles nothing has drawn for 4 s are\nevicted, and empty vertex pool and BLAS heap chunks are given back, so memory stays flat when the\ncamera jumps across the planet. `SI_MEM=1` prints the GPU memory by allocation with the benchmark\noutput (and after each tour shot).\n\n**Scripted tours and video** (`--tour`, `src\u002Ftour.rs`). A tour file is a list of shots: spline keys\n(latitude, longitude, height above the ground, heading, pitch) with a local solar time, cloud cover,\ndate and exposure compensation per shot. Each shot waits in black until its terrain, trees, ocean\nand full atlases have streamed in, then fades in, flies its keys with eased, constant-speed motion\nand fades out. Animation steps a fixed 1\u002F60 s per frame, so with `--tour-pace 40` (each frame on\nscreen for 40 ms) a 60 fps recorder captures every frame however heavy the scene;\n`tools\u002Frecord_tour.ps1` records it with OBS Studio and `tools\u002Ftour_post.py` drops the repeated\nframes, cuts the loading gaps and adds titles, giving smooth 60 fps video.\n[`tours\u002Fshowcase.txt`](tours\u002Fshowcase.txt) is a five-minute flight over ten forests.\n\n**Test flight** (`--test-flight`, `src\u002Fflight.rs`, `src\u002Fpilot.rs`, `src\u002Faircraft.rs`). An F-16C\nflown over the globe, from a chase camera, the cockpit or a camera it flies past.\n\n```\ncargo run --release -- --test-flight                          # over Lake Como, heading for the Alps\ncargo run --release -- --test-flight --at 32,-122,1000,90,0   # lat, lon, height above ground, heading\n```\n\n![An F-16C over Lake Como: afterburner lit, a vapour cone round it](docs\u002Fimages\u002Ftest_flight.jpg)\n\n![Shock waves bending the view above Mach 1, a hard pull with its wing-tip vortices, a condensation trail high up, the cockpit](docs\u002Fimages\u002Ftest_flight_views.jpg)\n\nThe model as Blender renders it (`tools\u002Fmake_f16.py --renders`):\n\n![The F-16C model](docs\u002Fimages\u002Ff16_model.jpg)\n\n- **The aircraft** is built by `tools\u002Fmake_f16.py` in Blender from published dimensions and a\n  digitised three-view (the script's header says what is data and what is estimated), painted\n  by `tools\u002Ff16_paint.py` and written as `assets\u002Faircraft\u002Ff16c.acm` with its three skin maps.\n  It is not in the repository: run the script once (`blender -b --python tools\u002Fmake_f16.py --\n  assets\u002Faircraft`). It is ray traced like everything else, by its own hit shaders\n  (`aircraft.rchit`, `aircraft.rahit`): the painted skin, flat materials, a mirror-gold canopy\n  one looks out through from inside. The leading-edge flaps, flaperons, tailplanes and rudder\n  move.\n- **The flight model** (`flight.rs`) integrates lift, drag, side force, thrust and gravity in\n  the 1976 standard atmosphere. The coefficients (by angle of attack and Mach number) and the\n  engine (an F110-GE-129's 76 \u002F 132 kN, falling with air density, rising with ram pressure,\n  losing inlet recovery above Mach 1) are fitted to the aircraft's published performance, not\n  taken from wind-tunnel tables: it tops out at Mach 2.10 at 12 km and Mach 1.29 at sea\n  level (the real aircraft: about 2.05 and 1.2), with the transonic drag rise between. It is flown through the real aircraft's control\n  laws: the stick commands load factor (+9 to -3 g, 1 g hands off) limited to 25.2 degrees\n  angle of attack, and roll rate about the flight path (to 324 deg\u002Fs, less when slow or at\n  high angle of attack); sideslip is held at zero unless the pedals ask for some. The moments\n  themselves are not modelled (the computer's commands are followed with the airframe's lags),\n  nor fuel, stores, landing gear or wind. Four unit tests hold it to 1 g hands off, the 9 g and\n  angle-of-attack limits and the top speed.\n- **As flown, it is tuned for play** (`Sim::arcade`, on in `--test-flight`), away from the real\n  aircraft in two ways: 30% more afterburner and no inlet loss, so it reaches Mach 3.08 at\n  12 km and Mach 1.62 at sea level; and A \u002F D turn it (a 40 degree bank flown for you, plus up\n  to 1.4 g of flat turn), where a real rudder only slips the nose a few degrees.\n- **The air bends the light** (`aircraft.glsl` `craftBend`): supersonic, the bow shock and the\n  tail shock are cones of denser air (half angle asin(1 \u002F Mach)), and a ray is refracted going\n  in and coming out, most where it meets the cone edge on. What is behind is looked for again\n  along the bent ray, so the land and sky show two shifted lines trailing back from the\n  aircraft; the exhaust makes what is seen through it shimmer. The bending is many times the\n  real air's, which only a schlieren camera shows.\n- **What speed does to the air** (`shaders\u002Faircraft.glsl`), all thin volumes integrated along\n  the view ray: the afterburner's flame with its shock diamonds; the veil of condensation\n  round the aircraft between about Mach 0.9 and 1.09 low down (a ragged cone ending at the\n  shock, its sunward side warm, the far side sky blue, pastel fringes where it is thinnest); vapour over the wings and in the tip\n  and strake vortices above 4 g; a condensation trail where the air is colder than about\n  -40 C (above roughly 8.5 km). Humidity is assumed by height, not simulated. There is no sound.\n- **Clouds** (`clouds.glsl`): with an aircraft flying, the cloud samples crowd towards the\n  camera (metres apart, not a kilometre), so one flies through cloud and not past a backdrop.\n  The aircraft's wake, 32 points kept for 95 s and drifting with the wind, clears a tube\n  through the cloud that widens from 9 m to ~140 m and turns the cloud's shapes about the\n  path. Inside a thick deck that tube is what keeps the aircraft in sight of the chase camera;\n  the lane it leaves in thin or broken cloud is subtle.\n\n**Still to do** (see the plan): rivers from HydroRIVERS (the 10 m land cover has the wide ones),\nstars, seasons in the vegetation, and wind.\n\n## Getting started\n\n### Requirements\n- A GPU with Vulkan hardware ray tracing (`VK_KHR_ray_tracing_pipeline`, `VK_KHR_acceleration_structure`). Developed on an RTX 5080 (16 GB).\n- About 4–5 GB of VRAM for the forest scene and 11 GB for the globe at the defaults (16 GB\n  recommended for the globe). Lower it with `SI_IMPOSTOR_MB=2000`, `--imp-res 320`, `SI_TEX_MAX=1024` or\n  `--species Beech,Alder` (forest scene).\n- Rust (stable) and the [Vulkan SDK](https:\u002F\u002Fvulkan.lunarg.com\u002F), for `glslangValidator`.\n- Python 3.12 with `usd-core`, `numpy` and `pillow`, for the asset converters.\n- Optional, for DLSS Ray Reconstruction: an NVIDIA RTX GPU, the\n  [NVIDIA DLSS SDK](https:\u002F\u002Fgithub.com\u002FNVIDIA\u002FDLSS) and the MSVC C++ build tools.\n\n### Plant assets (not included)\n\nThe plants are **Quixel Megaplants** and **Megascans** from [Fab](https:\u002F\u002Fwww.fab.com). Their\nlicense doesn't allow redistribution, so this repository contains no assets. Get them yourself:\n\n1. On Fab, add the Megaplants you want (for example Black Alder, Black Poplar, European Beech,\n   European Aspen, Common Hazel, Common Heather, Huckleberry Oak, Bracken Fern) and add the\n   **Unreal Engine** format to a UE 5.x project. Enable the Procedural Vegetation Editor plugin and\n   Nanite Foliage. They land in `\u002FGame\u002FMegaplant_Library`.\n2. Export meshes, assembly data, textures and material parameters headlessly:\n   ```\n   UnrealEditor-Cmd.exe \u003CProject>.uproject -run=pythonscript -script=\u003Crepo>\u002Ftools\u002Fue_export_megaplants.py ^\n       -EnablePlugins=PythonScriptPlugin,EditorScriptingUtilities,USDImporter -unattended -nop4 -nosplash -NullRHI\n   ```\n   This writes `assets\u002Fmegaplants\u002F\u003CSpecies>\u002F`. `SI_ONLY=Beech` limits it to matching species.\n3. Convert each species:\n   ```\n   python -m venv tools\u002F.venv\n   tools\u002F.venv\u002FScripts\u002Fpip install usd-core numpy pillow\n   tools\u002F.venv\u002FScripts\u002Fpython tools\u002Fmegaplant_to_mtree.py assets\u002Fmegaplants\u002FTree_European_Beech assets\u002Fspecies\u002FTree_European_Beech\n   ```\n   This writes `assets\u002Fspecies\u002F\u003CSpecies>.mtree` and `.json` (kind, textures, Unreal tints,\n   variants, heights). The engine loads every pack in `assets\u002Fspecies`. Species are found by\n   name: the forest scene grows the ones its biome preset names (`src\u002Fbiome.rs`; any species with\n   `--species`), the globe the ones its biome tables name (`globe\u002Fforest.rs`); a missing one is\n   skipped.\n4. Grass (optional): add Megascans 3D grass to your Fab library (Grass Clumps, Wild Grass, Tall\n   Grass, Tufted Grass, Dry Grass, Cotton Grass), download the glTF format, and convert each:\n   ```\n   tools\u002F.venv\u002FScripts\u002Fpython tools\u002Fgrass_to_mtree.py \u003CFabLibrary>\u002FGrass_Clumps-\u003Cid> assets\u002Fspecies\u002FGrass_Clumps\n   ```\n   Options: `--patch 2.6` (patch diameter, m), `--patches 3` (variants), `--density 1.0`.\n5. Other Megascans plants and props (optional): palms, ferns and yuccas (alpha-tested cards) and\n   scanned solids (cacti, boulders, logs, snags), from their Fab glTF downloads:\n   ```\n   tools\u002F.venv\u002FScripts\u002Fpython tools\u002Ffab_to_mtree.py plant \u003CFabLibrary>\u002F\u003CPlant>-\u003Cid> assets\u002Fspecies\u002FShrub_\u003CName> --kind shrub\n   tools\u002F.venv\u002FScripts\u002Fpython tools\u002Ffab_to_mtree.py solid assets\u002Fspecies\u002FProp_\u003CName> \u003CFabLibrary>\u002F\u003CScan>-\u003Cid> [...]\n   ```\n   A `solid` group (all the cacti, say) becomes one species with a shared texture atlas; see the\n   script's header for the options.\n6. Ground (optional): add the Fab surfaces listed in `catalog.rs` `GROUND_LAYERS` (Forest Floor,\n   Mossy Grass, Uncut Grass, Grass Dried, rock cliffs, snow, gravel, riverbed, pebbles, wet grass;\n   glTF, 2K). The engine finds them in your Fab library cache: set `SI_GROUND_DIR` to it, at run\n   time or at build time in `.cargo\u002Fconfig.toml` (`[env]`). Missing surfaces fall back to\n   procedural stand-ins.\n\nThe older single-species route (USD download → `tools\u002Fusd_to_mtree.py`, textures via\n`tools\u002Fue_export.py`) still works: with no `assets\u002Fspecies` packs the engine loads\n`assets\u002Fblack_alder.mtree` and `assets\u002Ftextures`.\n\n### DLSS Ray Reconstruction (optional)\n\nThe DLSS SDK and runtime are NVIDIA's and are not part of this repository.\n\n1. Get the [DLSS SDK](https:\u002F\u002Fgithub.com\u002FNVIDIA\u002FDLSS) (it needs `include\u002F` and\n   `lib\u002FWindows_x86_64\u002Fx64\u002Fnvsdk_ngx_d.lib`).\n2. Point the build at it, for example in a local, git-ignored `.cargo\u002Fconfig.toml`:\n   ```toml\n   [env]\n   DLSS_SDK = \"C:\u002Fpath\u002Fto\u002FDLSS\"\n   ```\n3. Put the Ray Reconstruction runtime `nvngx_dlssd.dll` in `assets\u002Fdlss\u002F` (or set `SI_DLSS_DIR`).\n\nThe log says `DLSS Ray Reconstruction available` when it works; otherwise the engine explains why\nand falls back to TAA.\n\n### Build and run\n\n```\ncargo run --release\n```\n\n| Flag | Meaning |\n|---|---|\n| `--size 2560x1440`, `--fullscreen` | window size \u002F borderless fullscreen |\n| `--vsync`, `--validation` | present with vsync; Vulkan validation layers (also `SI_VALIDATION`) |\n| `--dlss dlaa\\|quality\\|balanced\\|performance\\|ultra\\|off` | DLSS Ray Reconstruction mode (default quality) |\n| `--fly [--fly-speed 13 --fly-start 0]` | forest scene: automatic showcase fly-through (1.8 km loop): speed (m\u002Fs), start (m along the path) |\n| `--ss 2` | supersampling factor for the TAA path (default 1.5) |\n| `--lod 50`, `--lod-band 12` | mesh distance for a 16 m plant and dissolve band width |\n| `--lod2 100`, `--lod2-band 24` | forest scene: high-detail to low-detail impostor distance and its band |\n| `--ao 1` | AO rays per pixel (0-2; key O) |\n| `--sun 35,38`, `--haze 1` | sun azimuth \u002F elevation (degrees) and aerial perspective strength (forest scene; defaults from the biome) |\n| `--species Beech,Fern` | load only matching species packs |\n| `--asset path.mtree` | a single plant asset (the older single-species route, when `assets\u002Fspecies` is empty) |\n| `--imp-texel 0.055 --imp-res 448 --imp-grid 12` | impostor texel size (m), maximum frame resolution, views per side |\n| `--spacing 7 --radius 8000` | forest scene: canopy tree spacing and forest radius (m, the defaults) |\n| `--sharpen 0.5`, `--no-taa` | post-processing |\n| `--clouds on\\|off`, `--cloud-cover 0.45` | volumetric clouds, in every scene, and how much of the sky they cover (0-1; on the globe before the weather systems and latitude belts); key U toggles them (off in the forest scenes: the pa","SmartImposter 是一个基于硬件光线追踪的超大规模植被实时渲染器，专为森林与地球尺度场景设计。它采用 Rust + Vulkan 实现，核心创新在于对远距离植物使用视差八面体代理（parallax octahedral impostors），由 NVIDIA RTX 核心在着色器中实时 ray-march 渲染；近处物体则直接绘制 Quixel Megaplants\u002FMegascans 高精度几何；结合 DLSS Ray Reconstruction 提升信噪比。支持三种模式：程序生成森林（含8种生物群系）、真实地理坐标加载、全地球1:1流式渲染。适用于高保真地理可视化、数字孪生、影视预演及科研级生态模拟等需亿级植物实例与实时光线追踪的场景。","2026-11-24 04:52:47","CREATED_QUERY"]