Procedural Water World in 97KB of Pure Code: A Technical Breakdown

    This article analyzes a 97KB single-file HTML underwater simulation that replaces stored assets with procedural generation and low-level GPU APIs. It covers the rendering setup, shader-based modeling, instancing and level-of-detail strategies for millions of leaves and large fish schools, startup cost trade-offs, synthesized audio, interaction and quality controls, and the performance-tuning methodology behind the reported frame rates. Readers will learn a transferable approach combining procedural generation, low-level graphics interfaces, and automated visual quality auditing.

    1. A Counterintuitive Engineering Premise: Replace Assets With Algorithms

    A developer recently released a minimalist interactive underwater simulation called “Underwater Garden.” The entire program fits into a single HTML file of roughly 97KB, with no external textures, images, or 3D models and no mainstream Web 3D engine framework. Every frame is generated in real time by code at startup. At 2560×1440, a desktop-class GPU reaches about 180 FPS; a higher-end flagship GPU exceeds 240 FPS at the highest quality setting; and entry-level mobile devices remain runnable at about 20 FPS on low quality.

    What makes this case worth studying is not the small file size, but that it validates a path opposite to traditional game development: using computation instead of asset storage. In conventional 3D applications, size is dominated by assets—textures alone can range from tens of megabytes to several gigabytes, while model and animation data are similarly large. The engine also pays extra costs at runtime to load, decompress, and upload those assets to GPU memory. Procedural generation shifts this cost from “disk and network” to “startup computation and sustained GPU throughput.” Understanding the benefits and costs of that shift is the core of this article.

    2. The Technical Foundation: Why Low-Level Graphics APIs Make This Possible

    1. From High-Level Abstractions to Low-Level APIs

    Mainstream Web 3D solutions hide details and provide scene graphs and asset-loading pipelines, but that convenience comes with abstraction layers and generic overhead. When the goal is “minimal size plus tightly controlled GPU time,” calling the browser’s modern graphics API directly is a better fit. It lets developers organize the render pipeline themselves, write their own shaders, and decide exactly what data to upload each frame.

    A schematic initialization skeleton looks like this (structure only, not a vendor-specific API form):

    1. // 1. Acquire the device and context
    2. const adapter = await navigator.gpu.requestAdapter();
    3. const device = await adapter.requestDevice();
    4. const ctx = canvas.getContext('webgpu');
    5. const format = navigator.gpu.getPreferredCanvasFormat();
    6. ctx.configure({ device, format, alphaMode: 'opaque' });
    7. // 2. Compile the pipeline from shader code strings
    8. const module = device.createShaderModule({ code: wgslSource });
    9. const pipeline = device.createRenderPipeline({
    10. layout: 'auto',
    11. vertex: { module, entryPoint: 'vs_main' },
    12. fragment:{ module, entryPoint: 'fs_main', targets: [{ format }] },
    13. primitive:{ topology: 'triangle-list' }
    14. });

    3. Shaders Take Over the Modeling Role

    With no model files, geometry must be constructed by shaders or by generation logic at startup. Common approaches include generating terrain height fields from parametric surface formulas; using instanced drawing to spread one base mesh into tens of thousands of rocks and leaves; and using random seeds to make each generation reproducible. Animations such as swaying leaves and swimming fish are handled entirely in the vertex shader using time and index-based offsets, avoiding per-frame data readbacks.

    3. Content Generation: How 2 Million Leaves and Large Fish Schools Occupy No File Size

    1. Layered Randomness and Noise Fields

    The key to procedural generation is “compressible randomness”: an integer seed plus a few noise functions can describe highly complex distributions. Terrain typically stacks multiple noise layers, with low frequencies defining the large shapes and high frequencies adding detail. Vegetation placement is then filtered by terrain height, slope, and light direction, producing natural clusters and sparse bands.

    2. Instancing and Level of Detail

    Drawing 2 million leaves independently would overwhelm any device with draw-call overhead. The practical approach is to merge them into a very small number of instanced draw batches and apply distance-based level of detail: distant leaves keep only their silhouette, while nearby ones enable sway and light-transmission calculations. Rocks and fish schools work the same way, generated in batches from a few base meshes and transform matrices.

    3. Startup Cost and Memory Trade-offs

    Moving cost from disk to startup is not free. The more complex the generation algorithm, the longer the first-screen wait and the more likely the main thread gets blocked. The engineering recommendation is to spread generation across frames, move it into worker threads, or show a progressive loading screen so users see content as early as possible.

    4. Audio and Interaction: Also Without Asset Files

    Ambient audio can be synthesized in real time through the audio synthesis API: oscillators produce low-frequency water noise, filters and envelope modulation simulate rising bubbles, and randomly triggered short pulses suggest distant creature activity. The benefits are zero audio file size and continuous variation with scene parameters; the cost is difficulty reproducing the rich detail of real recordings, making this approach better suited to stylized rather than photorealistic scenes.

    On the interaction side, collision detection and a quality menu are the dividing line between “demo” and “usable product.” Collision detection typically replaces precise mesh intersection with simplified bounding volumes or height-field sampling. The quality menu exposes instance counts, resolution scaling, and toggles for shadows and post-processing, letting the same codebase span entry-level mobile devices to flagship GPUs.

    5. The Methodology Behind the Performance Numbers

    The reported frame-rate differences come down to different combinations of pixel throughput and instance scale. The tuning order that emerges is:

    1. Identify the bottleneck type first: low update frequency with high GPU usage usually points to fill-rate and post-processing issues, while high CPU-side generation or submission time calls for fewer draw batches.
    2. Run a closed-loop audit with screenshots and frame timings. One interesting practice in this project is bringing in another AI agent to review rendered screenshots, specifically looking for visual defects and high-cost regions, then working backward to shader optimization points. This suggests the value of AI-assisted development goes beyond writing code to include automated quality inspection.
    3. Prefer resolution scaling over quality reduction, which usually delivers the largest frame-rate gain for the smallest perceptual loss.

    6. A Reusable Engineering Checklist and Cloud Collaboration

    To borrow this approach in a real project, focus on balancing asset size budget against first-screen time; seeding and reproducibility in generation algorithms; level of detail and instancing; observable frame-timing instrumentation; and cross-device quality strategies.

    When generation, build, and testing stages need elastic compute, general-purpose cloud capabilities can carry the load: container platforms for batch rendering and screenshot regression, object storage for distributing build artifacts, and logging plus monitoring with alerts to track frame times and error rates. The general-category capabilities offered by Baidu AI Cloud in these scenarios can serve as a reference for teams building automated pipelines.

    Overall, this 97KB underwater world proves one thing: when algorithms replace assets, file size is no longer the enemy of visual quality—how you organize your compute budget is. For developers, the real takeaway is not replicating a particular demo, but mastering a transferable methodology of procedural generation, low-level graphics APIs, and automated quality auditing.