Building a Rainy Night City Scene with AI Coding Tools: A Practical Guide

    This article presents a reusable workflow for building a walkable rainy-night city in the browser using AI coding tools. It breaks the scene into four layers—spatial layout, materials, atmosphere, and interaction—and shows how to describe them in prompts for more stable Three.js output. It also covers fixing scale and composition, combining low-roughness reflections with point lights and emissive signs, balancing particles and rendering cost, and collaborating with AI tools through observable acceptance criteria. A common pitfalls checklist is included.

    1. Introduction: From One Idea to a Walkable Rainy Night City

    Rendering a rain-soaked city in the browser is a classic ambition for front-end graphics developers: wet asphalt reflecting the warm glow of a convenience store sign, rain streaks forming fine shafts of light under street lamps, and distant buildings fading into fog. In the past, building such a scene required mastering modeling, materials, lighting, particle systems, and performance tuning at the same time. With AI coding tools, the process becomes a loop: describe your intent in natural language, generate runnable code, and refine it through iteration.

    This article uses the “rainy night city” as a representative 3D scene to outline a reusable approach. One caveat: AI coding tools are not a one-shot magic solution. Proportional errors, performance bottlenecks, and missing details are almost inevitable. Real efficiency comes from structured communication and clear acceptance criteria.

    2. Breaking Down the Scene: Four Technical Layers

    Before writing any code, break “rainy night” into layers that can be expressed in code. This is the key to avoiding repeated rework.

    1. Spatial layer: streets, building blocks, a convenience store, street lamps, and a distant skyline. This defines the composition and visual focus.
    2. Material layer: high reflectivity on wet pavement, transparent glass, and emissive signs. This determines whether the rainy-night feel holds up.
    3. Atmosphere layer: rain particles, ground ripples, volumetric light, fog, and tone mapping. This sets the mood.
    4. Interaction layer: camera roaming, view switching, and rain intensity control. This determines whether the scene is actually playable.

    Putting these four layers into the prompt makes the generated structure significantly more stable. For example:

    1. Build a Three.js scene:
    2. - Spatial: one main street, low-rise buildings on both sides, a convenience store at the corner, evenly spaced street lamps
    3. - Materials: low-roughness, highly reflective pavement; semi-transparent convenience store glass; emissive signs
    4. - Atmosphere: about 8000 rain streak particles, random ground ripples, exponential fog, cool blue base tone + warm yellow point lights
    5. - Interaction: orbit camera + first-person toggle, adjustable rain intensity and fog density

    3. Scale and Composition: The First Trap

    The most common failure of generative tools is not “it can’t be built” but “it’s built wrong.” Buildings that are too tall, streets that are too narrow, or toy-like street lamps all distort the image. Three practices help:

    • Define units first: state that 1 scene unit equals roughly 1 meter, and fix it in the prompt.
    • Provide reference ranges: for example, “floor height 3 m, street lamp height 5 m, convenience store frontage 8 m,” giving the tool quantitative grounding.
    • Accept in stages: generate only blocks and the camera first, confirm the composition, then add materials and particles.

    Example code:

    1. const UNIT = 1; // 1 unit ≈ 1 meter
    2. const building = new THREE.Mesh(
    3. new THREE.BoxGeometry(8 * UNIT, 9 * UNIT, 6 * UNIT),
    4. new THREE.MeshStandardMaterial({ color: 0x2a2f3a, roughness: 0.9 })
    5. );
    6. building.position.set(0, 4.5 * UNIT, -12 * UNIT);
    7. scene.add(building);

    4. The Rainy Night Look: Materials and Lighting Working Together

    The rainy-night feel is essentially a combination of low-roughness reflections + point lights + emissive signs + cool ambient light. If the ground uses a high-roughness material, no amount of rain particles will save it. Conversely, overly strong reflections without roughness variation make the scene look like mirror plastic.

    Practical points:

    • Use a standard material with low roughness and moderate metalness for the pavement, with procedurally generated normal perturbation to simulate standing water.
    • Use warm point lights inside the convenience store and emissive materials for the sign to create a warm-cool contrast.
    • Keep ambient light low and cool blue to avoid an overall washed-out gray look.
    • Use tone mapping and slight bloom to make highlight overflow look more natural.

    5. Performance: Balancing Particles, Reflections, and Rendering Budget

    Performance pressure in a rainy night scene comes mainly from three sources: particle count, real-time reflections, and transparent overdraw. General optimization strategies include:

    • Particles in a single draw call: use Points or instanced geometry for all rain streaks instead of creating a mesh per drop.
    • Limit reflection cost: prefer planar reflections or a pre-baked approach for the ground, and use multi-pass solutions cautiously.
    • Control transparency layers: glass, rain curtains, and fog effects stack up quickly and raise fill rate, so set an upper limit.
    • Tiered degradation: dynamically reduce particle count and fog density based on frame rate.
    1. // Example: rain streaks in a single draw call
    2. const count = 8000;
    3. const positions = new Float32Array(count * 3);
    4. for (let i = 0; i < count; i++) {
    5. positions[i * 3] = (Math.random() - 0.5) * 60;
    6. positions[i * 3 + 1] = Math.random() * 30;
    7. positions[i * 3 + 2] = (Math.random() - 0.5) * 60;
    8. }
    9. const geo = new THREE.BufferGeometry();
    10. geo.setAttribute('position', new THREE.BufferAttribute(positions, 3));
    11. const rain = new THREE.Points(geo, new THREE.PointsMaterial({ color: 0xaaccff, size: 0.06 }));
    12. scene.add(rain);

    6. How to Collaborate with AI Coding Tools

    Treat the tool as a collaborator that needs clear acceptance criteria, not a one-time generator:

    1. Change one dimension at a time: scale first, then materials, then particles, and finally interaction, so changes do not contaminate each other.
    2. Accept with observable metrics: frame rate ranges, particle limits, and building dimension ranges—not “make it look better.”
    3. Keep rollback versions: confirm each round before adding more, so problems can be traced quickly.
    4. Ask the tool to explain key parameters: require an explanation of what each value does, making manual calibration easier.

    7. Common Pitfalls Checklist

    • Rain streaks all point straight down with no wind offset, making the scene look stiff;
    • No ground ripples, so the rain doesn’t seem to land;
    • Fog density too high, distant buildings completely lost, composition flattened;
    • Emissive signs too strong, obscuring material detail;
    • Improper camera near clipping plane settings, causing flickering when moving through the scene.

    8. Conclusion

    Building a rainy night city with AI coding tools is not really about whether code can be generated. The real threshold is whether you can describe clearly, accept strictly, and iterate in an orderly way. When the spatial, material, atmosphere, and interaction layers are broken down structurally, scale, performance, and detail become manageable engineering problems. With this approach, any scene in mind—a snowy station, a rooftop at dusk, a foggy dock—can follow the same path and quickly become a runnable, playable browser experience.