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

    This article presents a practical workflow for using natural-language-driven AI coding tools to build a realistic 3D rainy night city scene. It covers translating vague mood requirements into structured engineering specs, a layered Three.js architecture, prompt patterns that keep multi-turn iteration converging, scale and composition rules, rain and reflection rendering, performance optimization with adaptive degradation, and detail polishing. Developers will learn how to turn an idea into a runnable, interactive WebGL scene while keeping frame rate and asset budgets under control.

    1. Introduction: Why a Rainy Night City Is a Good Test of AI Coding Ability

    At the intersection of 3D graphics and front-end engineering, a rainy night street scene that looks purely atmospheric actually tests rendering pipelines, resource management, physics simulation, and interaction design all at once. The original practice described here used an AI coding tool to generate a rainy night convenience store scene. The process was not one-shot: scale, performance, and details all required repeated discussion and iteration, but the idea did eventually become a runnable, playable piece.

    This article strips away product specifics and frames the practice as a general technical question: how to use natural-language-driven AI coding ability to efficiently build a realistic 3D rainy night urban scene. Here, “AI coding tool” refers to a general capability that understands natural-language intent, generates runnable code, and supports multi-turn iteration, not any particular vendor’s product.

    A rainy night city is a good vehicle for three reasons:

    • Moderate scene complexity: it includes static elements such as buildings, streets, and lights, plus dynamic effects such as raindrops, puddle reflections, and fog;
    • High performance sensitivity: large numbers of semi-transparent particles and real-time lighting easily trigger frame rate bottlenecks, making it a natural testbed for optimization;
    • Strongly subjective aesthetics: mood, scale, and detail are hard to describe in one sentence, which shows exactly why an iterative collaboration model is necessary.

    2. Requirement Breakdown: Turning “Atmosphere” into Executable Engineering Metrics

    Natural-language descriptions usually stay at an emotional level, for example “the street should feel wet” or “the lights should be warmer.” Before an AI coding tool can produce usable code, the first step is to translate these vague statements into structured requirements. Break them down along four dimensions:

    1. Scene composition: ground, building blocks, storefront, streetlights, trash bins, air conditioner units, and so on;
    2. Atmosphere elements: rain density, ground reflection strength, fog density, light source color temperature;
    3. Interaction goals: whether free roaming is supported, whether rain intensity can be toggled, whether day and night can be switched;
    4. Engineering constraints: target frame rate, polygon budget, texture size limit, mobile compatibility.

    A practical approach is to write a “scene specification” first, then hand it to the AI coding tool to generate a first version. Example:

    1. Scene: rainy night city corner with a convenience store
    2. View: first person, free roaming
    3. Lighting: warm storefront light as key light, cool blue ambient
    4. Dynamic: continuous rain, reflective puddles on the ground
    5. Constraints: 60fps on desktop, total polygons < 200k

    The value of this specification is that it turns “feeling” into verifiable items, so every later iteration can be checked against it instead of being overturned based on impressions.

    3. Technology Choices and Architecture: Layered Design for a Three.js Scene

    In a general technical context, this kind of project is usually built on a mature WebGL wrapper library. For maintainability, layer by responsibility:

    • Scene layer: scene graph, camera, renderer initialization;
    • Resource layer: unified loading of geometry, materials, and textures, plus lifecycle management;
    • Environment layer: rain, fog, skybox, ground reflection;
    • Interaction layer: controls, collision, UI state;
    • Scheduling layer: main loop, frame rate monitoring, on-demand degradation.

    A minimal skeleton:

    1. // Scene initialization skeleton (illustrative)
    2. const scene = new THREE.Scene();
    3. scene.fog = new THREE.FogExp2(0x0a0f1a, 0.035);
    4. const camera = new THREE.PerspectiveCamera(60, innerWidth / innerHeight, 0.1, 200);
    5. const renderer = new THREE.WebGLRenderer({ antialias: true });
    6. renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
    7. renderer.setSize(innerWidth, innerHeight);
    8. // Main loop
    9. function animate(t) {
    10. requestAnimationFrame(animate);
    11. updateRain(t); // update raindrops
    12. updateReflection(); // update ground reflection
    13. renderer.render(scene, camera);
    14. }
    15. animate(0);

    The benefit of layering is that when generated code misbehaves, you can quickly locate whether the problem is resource loading, an environment effect, or interaction logic, instead of rewriting everything.

    4. Prompt Engineering: Making Multi-Turn Iteration Converge Instead of Diverge

    The original practice noted that results were not always right on the first try, which shows that prompt design matters more than any single generation. The experience boils down to four rules:

    1. Skeleton first, details later: the first round only asks for a runnable minimal scene, the second adds rain, the third adds reflections, avoiding an uncontrolled pile-up of code;
    2. Give verifiable criteria: instead of “make it look better,” say “the storefront should be clearly brighter than the surroundings, with a color temperature around 3000K”;
    3. Constrain technical boundaries: specify polygon count, texture size, and whether post-processing is allowed, to prevent solutions that exceed budget;
    4. Keep a context summary: restate the key parameters of the current version each round to reduce the model “forgetting” earlier settings.

    An example iteration prompt:

    1. Current version: ground, convenience store block, camera controls in place.
    2. This round's goal: add rain particles, count 8000, area 40x40,
    3. rendered with a single geometry in batch, avoiding per-particle objects.
    4. Acceptance: frame rate no lower than 55fps.

    This four-part structure of “state + goal + constraints + acceptance” significantly improves convergence speed in multi-turn collaboration.

    5. Scale and Composition: The First Threshold of Believability

    Scale problems are the most common rework point in this kind of project. Once the door height, street width, or streetlight height is off, even good lighting makes the scene look “like a model rather than a place.” A “reference anchoring” approach is recommended:

    • Use a door handle height of about 1 meter and a step height of about 0.15 meters as implicit rulers;
    • Keep street width between 8 and 12 meters for two-way traffic plus sidewalks;
    • Set the initial camera height to 1.6 meters to simulate a real viewpoint.

    For composition, rainy night scenes suit a “low viewpoint plus strong depth,” letting distant lights stretch into long reflections on wet ground as visual guide lines. These rules can be written into prompts so the AI coding tool follows them automatically during generation.

    6. Implementing the Rainy Night Atmosphere

    Atmosphere is built by stacking three layers:

    • Rain: implemented with batched particles or shaders, with emphasis on density decaying with distance to avoid a blurry mess up close;
    • Ground reflection: use a general planar reflection or screen-space reflection approach, combined with a roughness map to differentiate puddles from dry ground;
    • Fog and glow: exponential fog separates depth layers, and soft glow is added at light sources to simulate scattering in humid air.

    Illustrative parameter configuration:

    1. // Atmosphere parameters (illustrative)
    2. const mood = {
    3. rainCount: 8000,
    4. rainArea: 40,
    5. fogDensity: 0.035,
    6. groundRoughness: 0.25,
    7. lightColor: 0xffb066,
    8. ambientColor: 0x223355
    9. };

    The key is restraint: too much rain, too thick fog, or overly strong reflections all flatten the image and make it look cheap.

    7. Performance Optimization: Making the Piece Actually Playable

    Interactivity means holding a frame rate floor. General optimization techniques include:

    • Batched rendering: merge similar geometry to reduce draw calls;
    • On-demand updates: lower the update frequency of expensive effects such as reflections and shadows;
    • Resolution control: cap the pixel ratio and degrade automatically on mobile;
    • Tiered loading: use low-poly models for distant objects and load high-poly only up close;
    • Monitoring and adaptation: watch frame rate at runtime and automatically adjust rain volume and reflection quality.
    1. // Adaptive degradation (illustrative)
    2. let lowPerf = false;
    3. function monitor(fps) {
    4. if (fps < 45 && !lowPerf) {
    5. lowPerf = true;
    6. rain.setDensity(4000);
    7. reflection.enabled = false;
    8. }
    9. }

    This mechanism balances performance and visual quality instead of looking good on only one particular device.

    8. Detail Polishing: Realism Comes from Imperfection

    The believability of a rainy night city often hides in details: slight flicker in the storefront light tube, wear on ground textures, water stains near the trash bin, rain streaks on glass. List a “detail checklist” explicitly in the prompt and ask the AI coding tool to implement it item by item. Details do not need to be many, but they need to be right: one accurate wear mark beats ten exaggerated decorations.

    9. Human-AI Collaboration Workflow Summary

    Abstract the whole process into a five-step loop:

    1. Write the specification: structure emotional requirements;
    2. Generate the skeleton: get it running first, then beautify;
    3. Four-part iteration: state, goal, constraints, acceptance;
    4. Performance gatekeeping: measure frame rate and polygon count every round;
    5. Detail closure: verify item by item against the checklist.

    10. Conclusion

    Building a rainy night city looks like visual creation, but it is essentially a complete front-end graphics engineering practice. The value of AI coding tools is not generating a perfect result in one shot, but compressing the distance from “idea to runnable work” enough that developers can focus their energy on aesthetic judgment and architecture decisions. Master requirement structuring, layered architecture, prompt constraints, and performance gatekeeping, and anyone can reliably turn a scene in their mind into something that truly runs and can be played with.