Building a Rainy Night 3D City with AI Coding: A Practical Guide

    This article walks through building a real-time rainy night 3D city scene with AI coding tools. It covers breaking a vague idea into a technical checklist, locking down scale with reference objects and instanced rendering, managing reflections, emissive materials and fog for night atmosphere, treating frame rate as a hard performance budget, and running an iterative human-AI workflow. A common pitfalls and acceptance checklist is included to help turn one-off inspiration into a reusable scene template.

    1. Why a Rainy Night City Is an Ideal Test of AI Coding

    Rainy night scenes are a common benchmark in graphics programming because they stress three capabilities at once: geometry construction, physical approximation, and real-time performance control. Night means low light and high contrast, with emissive signs and street lamps as the main light sources. Rain means a large number of semi-transparent particles, ground reflections, and trails. A city means hundreds or thousands of repeated blocks and props. If any one of these is handled poorly, the flaws show up on screen immediately.

    Now that intelligent coding tools have entered everyday development workflows, the value of this kind of task is even greater. Developers no longer need to work out every matrix operation in advance. Instead, they describe intent in natural language, let the tool produce a runnable first prototype, and then have a human review proportions, pacing, and performance. It is worth stressing that the tool does not get it right in one shot. The real collaboration pattern is multi-turn conversational convergence, a point that recurs throughout this article.

    2. Requirement Breakdown: Turning One Idea into an Executable Technical Checklist

    A vague idea cannot be turned directly into code, so the first step is to structure it. A useful approach is to split “build a rainy night city” into four layers:

    • Scene layer: ground, building blocks, streets, distant skyline;
    • Lighting layer: ambient base light, street lamps, emissive signs, wet-ground reflections;
    • Effects layer: rain streaks, rain mist, splashes, water marks on glass;
    • Interaction layer: camera roaming, view switching, a parameter panel.

    An illustrative prompt structure could look like this:

    1. Goal: single-page real-time 3D scene, rainy night city street
    2. Constraints: low-poly style; instance repeated objects; pixel ratio capped at 2
    3. Lighting: cool ambient light + warm point lights, signs use emissive materials
    4. Effects: GPU particle rain, high-roughness ground reflection
    5. Interaction: orbit camera + one adjustable parameter panel (rain amount, wind speed, exposure)
    6. Deliverable: a directly runnable single page file with comments on key parameters

    The more precise the checklist, the lower the rework rate of the generated result. In practice, proportion errors and performance loss are the two most common sources of rework, so the prompt should specify up front “use a person or vehicle as a scale reference” and “a clear performance budget.”

    3. Scene and Scale: Build the Skeleton First, Then the Atmosphere

    The first generated version usually “looks the part but feels wrong,” and the problem is concentrated in scale. The solution is to introduce reference objects and unified units: first define 1 unit as 1 meter, then set floor height at about 3 meters, street width at 8 to 12 meters, and signs at least 2.5 meters above the ground. Putting these numbers into the prompt is far more effective than verbally saying “a bit taller” after the fact.

    Modular design is recommended for buildings: one base block plus several replaceable facade components, placed in batches via transformation matrices. Repeated objects should use instanced rendering rather than creating a separate mesh for each building, which significantly reduces draw calls.

    1. // Use instancing to batch-generate city blocks and control draw call count
    2. const blockGeo = new THREE.BoxGeometry(1, 1, 1);
    3. const blockMat = new THREE.MeshStandardMaterial({ color: 0x2a2f3a, roughness: 0.9 });
    4. const city = new THREE.InstancedMesh(blockGeo, blockMat, COUNT);
    5. const m = new THREE.Matrix4();
    6. for (let i = 0; i < COUNT; i++) {
    7. const h = 6 + Math.random() * 24; // 6~30 meters, forming an undulating skyline
    8. m.compose(
    9. new THREE.Vector3(x(i), h / 2, z(i)),
    10. new THREE.Quaternion(),
    11. new THREE.Vector3(6, h, 6)
    12. );
    13. city.setMatrixAt(i, m);
    14. }

    4. The Look of a Rainy Night: Reflections, Emissive Materials, and Fog

    The premium feel of a night scene does not come from model precision but from light management. Three general practices apply:

    1. Lay a base with low-intensity cool ambient light to avoid dead black areas;
    2. Keep the number of light sources under control, leaving most of the brightness to emissive materials and a few point lights;
    3. Use fog to compress the contrast of distant objects and create aerial perspective.

    The wet look of the ground is usually achieved by combining “high reflectivity + normal perturbation.” Planar reflection requires rendering the scene an extra time and is relatively costly. A more common engineering compromise is to give the ground low roughness and overlay a semi-transparent vertical gradient to simulate sign reflections, while reserving true reflections for the few most important light sources.

    Rain streaks are generally implemented with GPU particles or line segments. The key is to move the update logic into the shader and avoid iterating over particles on the CPU every frame:

    1. // Loop the fall by time in the vertex shader; the CPU does not update per particle
    2. float y = mod(position.y - uTime * uSpeed, uHeight);
    3. vec3 p = vec3(position.x + uWind * y * 0.02, y, position.z);

    Splashes where raindrops hit the ground can use a second particle system with a short lifetime, kept only near the camera and culled in the distance.

    5. Performance Budget: Treat Frame Rate as a Hard Constraint

    The failure of a real-time scene is often not that it cannot be rendered, but that it cannot run smoothly. Set the budget before writing effects: the target frame rate corresponds to the milliseconds available per frame, within which draw calls, triangle count, and semi-transparent overdraw each get an upper limit. The semi-transparent rain curtain is the main source of overdraw, so control particle size and layer count, and prefer additive blending to reduce sorting pressure.

    An adjustable parameter panel is very useful here because it turns “I feel it’s a bit laggy” into a quantifiable comparison experiment:

    1. const params = { rain: 20000, wind: 0.6, exposure: 1.1, reflect: true };
    2. function applyParams() {
    3. rainMesh.geometry.setDrawRange(0, params.rain);
    4. renderer.toneMappingExposure = params.exposure;
    5. ground.material.roughness = params.reflect ? 0.15 : 0.8;
    6. }

    Combined with general monitoring means (frame time statistics, draw call counts), continuous observation gives tuning a solid basis.

    6. Human-AI Workflow: Multi-Turn Convergence, Not One-Shot Drafts

    The most effective practice is to split generation into several verifiable small steps: first ask for a runnable empty scene with a camera, then gradually add the blocks, lighting, rain effects, and interaction. At each step, require the tool to output complete runnable code with comments on key parameters, making quick rollback easy.

    When the result deviates from expectations, feedback should be measurable. Rewrite “the atmosphere is wrong” as “lower ambient light by 30%, raise sign emissive intensity by 20%, increase fog density,” and rewrite “too laggy” as “halve the particle count and disable real-time ground reflection.” This constraint-based communication significantly reduces the number of back-and-forth rounds.

    7. Common Pitfalls and an Acceptance Checklist

    • Proportion imbalance: always keep a reference object;
    • Washed-out gray colors: check tone mapping and exposure rather than just adding lights;
    • Rain that does not look like rain: adjust the ratio between trail length and fall speed;
    • Frame rate jitter: prioritize checking semi-transparency and real-time reflections;
    • Unmaintainable code: require the generated result to be split into files or modules by scene, lighting, effects, and interaction.

    For acceptance, run through four criteria: runnable, interactive, measurable, and extensible. This basically turns one burst of inspiration into a reusable scene template, and switching themes later only requires replacing assets and lighting configuration.