Building a WebGL Rainy-Night City with AI Coding Tools: From Idea to a Runnable 3D Scene

    Learn how to turn a one-sentence creative idea into a working WebGL 3D scene using AI coding tools. This article covers scene decomposition, scale control, rain rendering, wet-surface reflections, lighting strategy, performance optimization, and practical techniques for iterating with AI assistants.

    Building a WebGL Rainy-Night City with AI Coding Tools: From Idea to a Runnable 3D Scene

    From a One-Sentence Idea to a 3D Scene: A New Paradigm for AI-Assisted Development

    “I want to build a small city on a rainy night, with a convenience store glowing warmly at the street corner, puddles reflecting the lights, and raindrops clearly visible under the streetlamps.” — In the past, turning a description like this into reality required solid 3D graphics fundamentals, familiarity with rendering pipelines, and shader programming skills. Today, with the code generation capabilities of AI coding tools, developers can describe requirements in natural language and quickly get a runnable WebGL 3D scene prototype.

    However, it’s important to be clear: AI assistance does not mean “one sentence, finished product.” In practice, issues like disproportionate scale, performance bottlenecks, and missing details are still common, requiring multiple rounds of communication and iteration between developer and tool. This article uses the “rainy-night city” scene as an example to walk through the complete engineering workflow from creative description to deliverable work.

    Scene Decomposition: Turning Vague Ideas into a Clear Technical Checklist

    AI coding tools fail most often when the requirement is too vague. A prompt like “build a rainy-night city” usually produces disappointing results. The right approach is to break the idea down into a structured technical checklist first:

    1. Environment layer

    • Sky: dark gradient background, optionally with volumetric fog to simulate rainy-night humidity
    • Ground: wet asphalt road with reflective properties
    • Atmosphere: global fog to control visibility and set the mood

    2. Architecture layer

    • Main building: the convenience store (glowing sign, transparent glass windows)
    • Background buildings: low-rise silhouettes along the street, no need for high detail
    • Street elements: streetlamps, utility poles, trash bins, vending machines

    3. Dynamic layer

    • Rain system: particles or line rendering
    • Lighting: cone-shaped streetlamp glows, warm point lights from the convenience store
    • Interaction: camera roaming controls

    Once the idea is broken into these three layers, submitting requirements to the AI tool layer by layer significantly improves generation quality.

    Key Implementation Details

    3.1 Scene Setup and Scale Control

    The first common pitfall is scale. In AI-generated code, the convenience store might be only two meters tall while the streetlamps look like skyscrapers. The solution is to establish explicit size baselines in your prompts:

    1. Build the scene in "meters" with the following baseline dimensions:
    2. - Convenience store: 8m wide, 6m deep, 3.5m tall
    3. - Streetlamp: 4m tall, lamp head at 3.8m
    4. - Street: 10m wide, sidewalks 2m wide on each side
    5. - Initial camera position: (0, 1.7, 15), simulating human eye level

    Using an eye height of 1.7 meters as the camera baseline is the key trick to making a scene “look right.” Once the relative proportions of people, buildings, and streets match everyday experience, viewers immediately feel immersed.

    3.2 Two Approaches to Rendering Rain

    Rain is the soul of a rainy-night atmosphere. There are two common implementation strategies:

    Option 1: Particle system. Create thousands of tiny particles with a downward initial velocity and slight horizontal drift, paired with semi-transparent short-line textures. Pros: simple to implement. Cons: the particle effect is obvious up close.

    Option 2: Instanced line segments. Use instanced rendering to draw large numbers of short line segments, with each segment’s length and tilt angle computed dynamically from wind speed parameters. Raindrops fall fast, so what the human eye actually perceives are “lines” rather than “points.” The line-segment approach therefore looks more realistic, and instanced rendering is performance-friendly.

    Practical advice: use sparse, large rain streaks in the distance to build the outline, and dense, small rain streaks around the camera for a sense of presence. Layer the rain to control the total count and avoid particle explosions.

    3.3 Wet Ground and Lighting Atmosphere

    The core visual feature that distinguishes a rainy night from a clear night is reflection. On wet ground, streetlamp and sign lights create stretched reflections on the pavement. In a general-purpose WebGL rendering framework, you can simulate this with:

    • Increasing the ground material’s glossiness and lowering its roughness;
    • Using planar reflection or environment maps to approximate the reflections;
    • For performance-sensitive scenes, a fallback: draw blurred, vertically stretched light-patch textures on the ground, trading accuracy for a much cheaper approximation.

    For lighting, adopt a “cool ambient + warm focal” contrast strategy: use cool tones for ambient light and streetlamps, and warm point lights for the convenience store windows. The warm-cool contrast naturally draws the viewer’s eye toward the scene’s focal point.

    3.4 Three Performance Red Lines

    AI-generated scenes often “run but stutter.” During iteration, hold three red lines:

    1. Draw call control: merge geometry for similar static objects, use low-poly models for distant buildings, and keep per-frame draw calls within a reasonable range;
    2. Light count control: dynamic lights are performance killers. Replace distant lights with emissive materials plus texture-based glows, and keep only a small number of key lights in real-time lighting calculations;
    3. Pixel fill rate control: volumetric fog, transparent rain, and reflections all involve massive overlapping semi-transparent pixels. Limit the screen coverage of these effects, and degrade quality by device capability when necessary.

    A useful iteration prompt: “Please merge rendering for same-type buildings and limit dynamic point lights to no more than 5, while preserving the visual effect.” — Giving the AI explicit quantitative constraints is far more effective than “help me optimize performance.”

    Iteration and Communication: Treat the AI Like a Junior Engineer

    The biggest takeaway from this practice: AI coding tools are excellent at quickly turning ideas in your head into something that actually runs and can be played with — but only if you change how you communicate. Treat the AI like a highly capable junior engineer with no contextual memory.

    Specific recommendations:

    • Small steps, fast iterations: raise one clear change at a time, e.g., “make the rain streaks thinner and reduce density by 30%,” rather than dumping ten requirements at once;
    • Describe phenomena, not emotions: “the sign’s glow clips through to the other side of the street” gets a correct fix far more easily than “it looks wrong”;
    • Keep rollback-friendly versions: save a working version after each iteration so a single change can’t destroy the whole structure;
    • Take over key parameters yourself: camera settings, color grading, and performance budgets are aesthetic and architectural decisions that should stay with the developer, while the AI fills in implementation details.

    Summary and Next Steps

    From a vague idea of a “rainy-night city” to a complete 3D work you can roam through, with rain sounds and light reflections, AI coding tools compress what used to be a development cycle measured in days down to hours. But the real value goes beyond speed: this rapid “describe — generate — run — feedback” loop lets creators validate ideas at extremely low cost and devote more energy to polishing atmosphere and narrative expression.

    You can extend this foundation further: add a sound system syncing rain and thunder, implement a day-night cycle, or deploy the scene to static hosting and share it with others. As tools keep lowering the barrier to 3D development, the idea itself once again becomes the scarcest resource.