Building a Rainy Night City Scene with AI Coding Tools

    This article walks through building a rainy night city scene in Three.js with the help of AI coding tools. It breaks the scene into four layers (layout, materials and lighting, atmospheric particles, and post-processing with interaction), explains how to define scale and camera settings up front, and shows how to use instanced rain, controlled light sources, and a clear performance budget to keep the result running smoothly. It also outlines a four-step iteration loop for collaborating effectively with generative coding tools.

    1. From a One-Sentence Idea to a Runnable Scene: Defining the Problem

    The core of this practice is not any single tool, but a common development need: a developer already has a fairly complete picture in mind—a rainy night, streets, a convenience store, wet reflections, neon and rain streaks—yet building a 3D scene from scratch is expensive. It involves camera and scale, materials and lighting, particle systems, post-processing, and performance budgets across multiple layers. The value of AI coding tools is that they quickly translate a natural language description into a runnable scaffold, freeing the developer to focus on aesthetic judgment and engineering tradeoffs.

    It is important to note that these tools cannot guarantee a perfect result on the first try. The original practice mentions that scale, performance, and details require repeated communication, which shows that the output of generative coding is an “iterable draft,” not a “final deliverable.” Treating the tool as a pair developer rather than an automated pipeline is the right mindset.

    2. Technical Breakdown: Four Layers of the Rainy Night City

    To turn an idea into a finished scene, split it into four layers. This makes it easier to issue instructions to the tool for each layer and to locate problems.

    1. Scene skeleton layer: ground, roads, building blocks, the convenience store facade, and sign placement. The key is to define “units and scale” first, for example using meters as the unit with an adult height of about 1.7 units, to avoid repeated rescaling later.
    2. Materials and lighting layer: high reflectivity and low roughness for the wet road, transparency and grime for the glass, anisotropic highlights for the metal roller shutter; a cool ambient light as the base, with warm in-store light and colorful signs as focal points.
    3. Atmospheric particle layer: rain streaks are usually implemented with a large number of thin instanced geometries or Points combined with shaders, along with ground ripples, splashes, and a sense of volumetric fog.
    4. Post-processing and interaction layer: bloom, tone mapping, slight depth of field, slow camera movement and mouse look-around determine “whether it is playable.”

    An illustrative requirement description can be organized like this, so the tool understands the structure rather than just grabbing keywords:

    1. Build a Three.js rainy night street scene:
    2. - Units: 1 unit = 1 meter, camera height 1.6
    3. - Subject: a convenience store facade about 8 meters wide, glass door, warm interior, vertical sign
    4. - Ground: wet asphalt, low roughness, high reflectivity, with localized puddles
    5. - Weather: moderate rainfall + light fog, rain streaks slightly tilted by wind
    6. - Post-processing: moderate bloom, cool blue ambient contrasted with warm yellow in-store light
    7. - Performance target: stable 60 FPS on a mid-range laptop, controlled draw calls

    3. Scale and Composition: The First and Most Overlooked Hurdle

    When the generated result “looks wrong,” it is usually not a model capability issue but a lack of scale constraints. It is recommended to explicitly provide reference objects and camera parameters in the prompt, and to manage constants centrally in the code to avoid magic numbers scattered around:

    1. const SCALE = { unit: 1, humanHeight: 1.7, cameraHeight: 1.6 };
    2. const SHOP = { width: 8, height: 3.2, doorWidth: 1.1 };

    For composition, a “low camera position + long focal length compression” more easily achieves a cinematic feel; the convenience store as the only warm light source naturally forms a visual anchor. If the generated result has imbalanced proportions, fix the constants first rather than tweaking each spot individually—this is the most efficient strategy for communicating with the tool.

    4. Rainy Night Atmosphere: Coordinating Materials, Lighting, and Particles

    The texture of a rainy night comes from the triangle relationship of “reflection—light source—particles.” The ground needs low roughness and environment reflection to pull the sign colors onto the road surface; the number of light sources should be restrained, using a few high-contrast lights to shape layers; rain streaks should be rendered with instancing, avoiding creating an independent object for each raindrop.

    1. // Instanced rain streaks to control draw calls
    2. const rainCount = 12000;
    3. const rain = new THREE.InstancedMesh(rainGeo, rainMat, rainCount);
    4. scene.add(rain);

    Adding ground ripples and a slight breathing motion to the camera can significantly improve the sense of realism. These details belong to later polishing and do not need to be fully implemented by the tool in the first version.

    5. Performance Budget: Keeping “Good Looks” Within a Runnable Range

    Performance problems almost inevitably appear, because generated code tends to “pile on effects first.” It is recommended to provide a budget in advance and require the tool to follow it:

    • Set upper limits on draw calls and triangle counts, and instance all repeated objects;
    • Enable shadows only for key light sources and reduce shadow map resolution;
    • Enable post-processing on demand, with automatic fallback on mobile;
    • Cap the pixel ratio to avoid rendering resolution getting out of control on high-DPI screens.
    1. renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));

    If the frame rate falls short, troubleshoot item by item in the order “particle count → shadows → post-processing → material complexity” rather than making a large one-time change.

    6. Collaboration Methodology: Turning Repeated Communication into a Controllable Process

    The “repetition” in practice is not wasted effort but a necessary convergence process. It can be solidified into a four-step loop: first get the skeleton and a runnable version, then add materials and lighting, then add atmospheric particles, and finally do performance and interaction acceptance. In each round, raise only one set of verifiable requirements with acceptance criteria, such as “building height in the frame is about twice the human height” or “frame rate no lower than 55.” When the result deviates, point out the specific phenomenon rather than a vague evaluation, and the tool’s correction hit rate will improve noticeably.

    7. Conclusion

    Building a rainy night city with AI coding tools is essentially an engineering process of “idea—constraints—iteration.” What truly determines the quality of the final product is the developer’s clear definition and continuous judgment of scale, performance, and details. Treat the tool as a collaborator and put budgets and acceptance criteria up front, and the picture in your mind can reliably become a runnable, playable work.