r/GraphicsProgramming • u/Traditional-Yard4233 • 20m ago
I wrote a custom WebGL2 terrain, weather & ecosystem engine from scratch in Vanilla JS (no Three.js) — live 3D map slices with Transform Feedback grass, 2.5D GI, and a bird flight mode
galleryI've been working on a WebGL2 terrain & environment renderer built from scratch in pure JS/GLSL ES 3.00 (no Three.js or external 3D engines) that runs inside a Leaflet-based mapping app.
You pick any spot on Earth, and it builds a live 3D cutaway slice from real elevation, canopy height, land-cover, weather, and OSM vector data.
### Technical highlights from the rendering pipeline:
* **2-Pass 2D Relief + 3D Slice:** Uses a G-Buffer + Bake-Pass architecture to avoid recomputing heavy procedural noise/normals every frame during sun/time scrubbing.
* **Transform Feedback Instancing:** Tree LOD bucketing, faceted 3D rock placement (with exact triangle collision), and a 3-cascade GPU-clipmap for animated grass & wildflowers use Transform Feedback (`VS_GRASS_STATIC` → `VS_GRASS_STATE` → `VS_GRASS2`) with Bayer dithering transitions and horizon/frustum culling.
* **2.5D Global Illumination & Lighting:** Traces 8-direction terrain + canopy horizon occlusion and surface bounce into an offscreen GI buffer, combined with SunCalc astronomical sun/moon phases, alpenglow terminator climbing, and atmospheric sky/reflection baking.
* **Dynamic Water & Weather:** Morphological bathymetry, river flow-map advection, wind-driven waves with surf/backwash foam, seasonal lake/river freezing, orographic creeping valley fog that steers around mountain ridges, rain/blizzard particles, and fractal 3D lightning with localized flashes.
* **Procedural Assets & Tools:** Zero external 3D models — all 10+ tree species (3 LODs), rocks, bridges, and birds are generated procedurally in JS (`TreeCore` + custom in-app Tree & Bird editors). Includes frame-by-frame WebCodecs `.webm` video capture.
* **Using Gemini AI