Building a Three.js Rainy Night Scene with AI Coding Assistants: A Practical Guide

    This article walks through building a runnable Three.js rainy night convenience store scene using AI coding assistants. It explains why the rainy night theme stresses spatial consistency, rendering performance budgets, and atmosphere control, then covers translating aesthetic requirements into measurable parameters, running an iterative multi-stage workflow, fixing scale and composition with anchor objects, implementing layered rain particles, wet ground reflections, bloom, fog and depth of field, and applying performance budgets with device-tier fallback. A reusable delivery checklist and a troubleshooting order for common defects are included.

    1. Why a Rainy Night Town Is an Ideal Test for AI Coding

    Generating a runnable Three.js rainy night convenience store scene with an AI coding tool looks like a small visual exercise, but it actually stresses three capabilities at once: consistency of spatial proportions, the performance budget of real-time rendering, and controllability of atmospheric detail. The recurring “it doesn’t work in one shot” experience in hands-on practice shows that this kind of task cannot be converged with a single prompt. Instead, it requires multiple rounds of communication and gradual calibration between the developer and the tool.

    The rainy night theme is representative because it stacks several rendering challenges together: visibility under low light, reflections on wet pavement, rain particle density, glow spill from neon and signage, and the different specular behavior of glass, water, and metal. If any one of these gets out of control, the image immediately loses credibility. So this article does not revolve around any specific product. It abstracts the topic into a general engineering problem: how to use natural language collaboration to reliably produce a real-time rainy night scene with a controllable performance budget and believable visuals.

    2. Requirement Breakdown: Translating “Atmosphere” into Executable Parameters

    A translation layer is needed between natural language descriptions and the rendering engine. The first thing a developer must do is break vague aesthetic demands into quantifiable engineering constraints.

    • Spatial scale: street width, storefront bay width and depth, floor height, and sign height above ground. Define a unified unit first (for example, 1 unit = 1 meter) to prevent model proportions from conflicting later.
    • Camera and composition: initial camera height, field of view, and whether roaming is allowed. These determine the first impression.
    • Lighting budget: upper limits on ambient light, directional light, and the number of point lights. This directly binds to performance.
    • Particle scale: rain count, fall speed, wind offset, and whether to use layers (heavy rain near the camera, a rain curtain in the distance).
    • Material list: wet asphalt, concrete, glass, metal roller shutters, and plastic signage, each with the reflection and roughness ranges it needs.

    Writing these items into a structured list before handing them to an AI coding tool gives a much higher hit rate than a single sentence like “make a convenience store in the rain.”

    An illustrative requirement structure:

    1. Scene: night city street + corner convenience store
    2. Units: 1 unit = 1m; street width 8m; storefront bay 6m, depth 8m, floor height 3.2m
    3. Camera: initial height 1.6m, FOV 55, drag to look around
    4. Lighting: 1 ambient light + 1 directional light (moonlight) + no more than 6 point lights
    5. Rain: two particle layers, near 4000, far 6000, speed 18~24 m/s, wind offset 15°
    6. Materials: ground roughness 0.15~0.3; glass transmission enabled; emissive signage
    7. Performance target: 60fps on mainstream laptops, fallback to 30fps on mobile

    3. Iterative Collaboration: Turning One-Shot Generation into a Controllable Pipeline

    The problem with one-shot generation is that errors get “packaged” into the result and become hard to locate. A more reliable approach is to advance in stages, with verifiable output at each stage.

    1. Skeleton stage: generate only the ground, walls, door and window openings, and camera controls; confirm proportions and viewpoint.
    2. Lighting stage: add ambient and key light to establish the night baseline, then add point lights one by one.
    3. Material stage: distinguish wet and dry areas, add reflections and normal perturbation to the ground so that “wet” holds up.
    4. Rain and fog stage: add particles first, then fog and water streaks on the lens, controlling overexposure from stacked transparency.
    5. Detail stage: signage, shelves, refrigerators, puddles on the ground, and distant building silhouettes.
    6. Performance stage: merge geometry, clip view distance, and apply device-based fallback.

    At the end of each stage, ask the tool “verifiable questions” rather than “optimize it a bit more.” For example: “Does the current ground reflection use an extra render pass? If so, provide a comparison plan with it disabled” and “Do the near rain streaks and the far rain curtain share the same material instance?”

    4. Scale and Composition: The Most Common Source of Rework

    Scale problems almost inevitably appear, and the root cause is that model fragments each follow different scale assumptions. There are three engineering solutions:

    • Define “anchor objects” first. Use the 2.1m door frame height and the 0.35m shelf spacing as anchors, and derive the remaining objects from them.
    • Use unified unit constants and scaling functions; forbid hard-coded magic numbers in individual places.
    1. const UNIT = 1; // 1 unit = 1 meter
    2. const DOOR_H = 2.1 * UNIT; // anchor: door height
    3. const SHELF_GAP = 0.35 * UNIT;
    4. function scaleTo(anchorMeters, targetMeters) {
    5. return targetMeters / anchorMeters;
    6. }
    • Use the camera for a “human-eye check.” Fix the camera at 1.6m height and walk through the street; wherever looking up or down is required for the view to make sense, the scale is usually wrong.

    5. Core Techniques for the Rainy Night Atmosphere

    5.1 Rain Layering and Particle Strategy

    A single particle layer struggles to deliver both the streak shape of near rain and the density of a distant rain curtain. The common approach is layering: the near layer uses thin line segments or stretched sprites to convey speed, while the far layer uses large, low-opacity particles to convey volume. The particle ceiling should be derived backward from the frame time budget, not set by feel.

    5.2 Wet Ground and Reflections

    The look of “wet” comes from three things: higher reflection intensity, lower roughness, and irregular surface perturbation. In implementation, you can choose a screen-space reflection approach or a simplified mirror/environment map approach. The former looks better but costs more; the latter suits mobile. The key is to make reflection intensity and roughness adjustable parameters so they can be tuned per device tier.

    5.3 Emission and Glow Spill

    Emissive signage needs a bloom-style post-processing pass to be believable, but bloom significantly raises fill-rate cost. It is recommended to limit the layers that participate in bloom, letting only signage and light boxes enter the pass, and avoid full-screen emission that washes out the night scene into gray.

    5.4 Fog and Depth of Field

    Fog compresses distant contrast and creates depth; depth of field locks the viewer’s gaze onto the convenience store. Both are post-processing effects and should share the same fallback switch as bloom.

    6. Performance Budget and Tiered Fallback

    Stability in a real-time scene comes from a budget, not from after-the-fact fixes. Practical steps:

    • Set a frame time ceiling (for example, 16.7ms) and list the costs of rendering, scripts, and post-processing in a table for item-by-item review.
    • Geometry merging and instancing: use instanced drawing for repeated objects such as shelves, awnings, and streetlights.
    • View-distance clipping and occlusion culling: replace distant buildings with low-poly models or billboards.
    • Device tiering: read hardware concurrency and screen pixel ratio, then dynamically adjust the particle ceiling, reflection approach, and post-processing switches.
    1. const tier = detectTier(); // 'high' | 'mid' | 'low'
    2. const config = {
    3. high: { rainNear: 4000, rainFar: 6000, reflection: 'ssr', bloom: true },
    4. mid: { rainNear: 2000, rainFar: 3000, reflection: 'env', bloom: true },
    5. low: { rainNear: 800, rainFar: 1200, reflection: 'env', bloom: false },
    6. }[tier];

    7. Common Defects and Troubleshooting Order

    • The whole image looks gray: usually the bloom range is too wide or the fog density is too high; narrow the emissive layers first.
    • The ground “doesn’t look wet”: reflections exist but roughness was not lowered, or normal perturbation is missing.
    • Rain looks like snow: particles are not stretched along a direction, or the speed parameter is too low.
    • Frame rate drops sharply at a specific viewpoint: that view pulls in too many point lights and transparent objects at once; check light culling and transparency sorting.
    • Odd proportions: there is no unified unit constant; go back to the anchor system and rebuild.

    8. A Reusable Delivery Checklist

    Turning collaboration results into a checklist significantly reduces communication cost next time: unit and anchor definitions, lighting and particle parameter tables, material parameter ranges, tiered fallback configuration, a performance review table, and known defects with workarounds. With this checklist, the path from idea to a runnable, playable real-time scene becomes much shorter. Combined with AI coding tools and general cloud capabilities such as cloud compute, storage, logging, and monitoring, the cost of repeated debugging can be reduced further.