AI Coding for a 3D Rainy Night City Scene: A Practical Guide

    This article walks through building a 3D rainy night convenience store scene with AI coding tools. It explains how to translate atmosphere into measurable engineering parameters such as scale, lighting, materials, particles, and performance budgets, then assemble the scene with a scale-first order. It also covers the four technical pillars of rainy night realism, common performance pitfalls and fixes, a single-variable iteration workflow, and how to turn a one-off prototype into a stable, deployable project.

    1. Why a Rainy Night City Scene Is a Good Test of AI Coding

    Generating a 3D rainy night convenience store scene with an AI coding tool may look like simply “drawing a house,” but it actually tests five dimensions at once: spatial proportions, lighting layers, particle systems, post-processing, and runtime performance. The core takeaway from this practice is straightforward: generation rarely gets everything right on the first try, and proportions, performance, and details all require back-and-forth refinement. Even so, the overall experience shows that mainstream AI coding workflows are already capable of turning an idea into a real, runnable, playable project quickly.

    The value of this kind of task is not about having the model write all the code for you. It is about handing creative descriptions, engineering constraints, and acceptance criteria to the tool at the same time, so it can iterate continuously inside a runnable project skeleton. In other words, AI takes on the role of “rapidly producing a runnable prototype,” while the developer takes on the role of “defining constraints and acceptance criteria.”

    2. Requirement Breakdown: Translating “Atmosphere” into Engineering Language

    “Rainy night” is an atmosphere word, not an engineering word. To keep the generated result controllable, the first step is to break it down into measurable elements:

    • Spatial scale: the convenience store’s width, depth, and ceiling height, the street width, and the camera height and field of view. Without scale constraints, the most common failure is “shelves that look like toys and door frames that look like giants.”
    • Lighting structure: the key light (cool white ceiling lights inside the store), the fill light (warm sign light), ambient light (low-intensity blue-gray skylight), and dynamic light (lightning or headlights).
    • Material differentiation: wet asphalt with high reflectivity and low roughness, glass with transmission and reflection, metal shutters with directional highlights, and concrete with rough diffuse reflection.
    • Particles and post-processing: rain streak density, fall speed, wind offset, ground ripples, lens water marks, and subtle bloom and tone mapping.
    • Performance budget: target frame rate, draw call limit, number of transparent objects, total particle count, and pixel ratio cap.

    Writing these items into the prompt noticeably improves the stability of the generated result. A reusable prompt skeleton looks like this:

    1. Build a single-file runnable 3D rainy night street corner convenience store scene with:
    2. 1) Real-world scale: store width 6m, depth 4m, ceiling height 3m, street width 8m, camera height 1.6m;
    3. 2) Lighting: cool white ceiling lights inside as the key light, warm sign light as fill, low-intensity blue-gray ambient, occasional lightning allowed;
    4. 3) Materials: wet asphalt with low roughness and high reflectivity, glass with transmission and reflection, metal shutters with directional highlights;
    5. 4) Rain: about 6000 rain streaks with wind offset, ground ripples and reflection trails;
    6. 5) Performance: target 60fps, pixel ratio cap 1.5, transparent objects sorted in layers;
    7. 6) Output: a single HTML file with a render loop, window resizing, and basic interaction.

    3. Scene Skeleton: Render Loop and Scale-First Strategy

    Regardless of which WebGL wrapper you use, the project skeleton follows the same pattern: scene, camera, renderer, lights, geometry, materials, and render loop. What really determines success is the order: establish scale first, then lighting, then details.

    1. // Pseudocode: scale-first build order
    2. const scene = new Scene();
    3. const camera = new PerspectiveCamera(55, aspect, 0.1, 200);
    4. camera.position.set(0, 1.6, 9); // eye level, avoids a "model-like" look
    5. const renderer = new WebGLRenderer({ antialias: true });
    6. renderer.setPixelRatio(Math.min(devicePixelRatio, 1.5));
    7. renderer.shadowMap.enabled = true;
    8. // 1. First build measurable boxes: street, store body, door frames, shelves
    9. // 2. Then add key and fill lights, and confirm light and dark layers
    10. // 3. Finally layer on rain, ripples, water marks, and bloom

    The benefit of scale-first is that all later details attach to the correct coordinate system, reducing the communication cost of repeated rebuilds. A practical lesson is that defining key dimensions as centrally managed constants works far better than repeatedly describing “keep the proportions harmonious” in the prompt.

    4. Four Technical Pillars of Rainy Night Realism

    1. Wet ground reflections. Realism comes mainly from the ground, not the rain streaks. A common approach is to approximate with planar or screen-space reflections, then overlay a roughness map to create broken highlights. If performance is tight, this can degrade to “low-roughness material + environment map + vertical trail decals.”
    2. Rain streak rendering. Use many thin quads or line segments with a shader to handle falling and wind offset, and avoid rebuilding geometry every frame. Using time as the only input and computing displacement inside the shader is key to controlling overhead.
    3. Glass and signage. Glass needs to distinguish transmission from reflection, and the sign uses an emissive material with subtle bloom. Bloom intensity must stay restrained, or the image will “blur into a mess.”
    4. Lens water marks and tone. Screen-space water marks and vignetting significantly improve the “watching rain through a window” feel, and tone mapping helps pull cool blue and warm yellow apart in contrast.

    5. Performance and Stability: From “It Runs” to “It Runs Smoothly”

    Common performance traps in generative output include: pixel ratio set too high, too many transparent objects causing overdraw, oversized shadow maps, and per-frame object creation triggering garbage collection stutter. General strategies that work:

    • Cap the pixel ratio, and lower it further on mobile;
    • Make total particle count and rain density tunable parameters, with conservative defaults;
    • Merge static geometry to reduce draw calls;
    • Have only the key light cast shadows, and limit the shadow camera range;
    • Drive animation with time to avoid per-frame memory allocation;
    • Add simple frame rate monitoring to locate regressions during iteration.
    1. // Example: tunable parameters + frame rate sampling
    2. const params = { rainCount: 6000, windX: 0.35, pixelRatioCap: 1.5 };
    3. let frames = 0, last = performance.now();
    4. function tick(now) {
    5. frames++;
    6. if (now - last >= 1000) {
    7. console.log('fps:', frames);
    8. frames = 0; last = now;
    9. }
    10. requestAnimationFrame(tick);
    11. }

    6. Iteration Method: Turning “Back-and-Forth” into a Convergent Process

    The original experience mentions that proportions, performance, and details require repeated discussion. This is exactly controllable iteration, not a defect. A good approach is to limit each round of conversation to a single variable:

    1. The first round only confirms scale and camera position, with no discussion of materials;
    2. The second round only confirms lighting layers and light-dark contrast;
    3. The third round adds rain effects and ground reflections, while recording frame rate;
    4. The fourth round subtracts, removing details that do not affect the atmosphere to reclaim performance;
    5. Finally, run a unified acceptance check: whether window resizing works, whether it runs on low-end devices, and whether interaction feels responsive.

    Asking the tool to output a “runnable single-file version + change notes” each round can significantly reduce regression cost.

    7. Transferable Engineering Conclusions

    This method is not limited to rainy night scenes. Any real-time 3D subject that is “atmosphere-driven, detail-dense, and performance-sensitive” can use the same framework: first translate the atmosphere into five categories of parameters (scale, lighting, materials, particles, and budget), then build the skeleton in a scale-first order, and finally converge with single-variable iteration. If you take it further to the cloud, you can host the build artifacts in object storage and accelerate access through a content delivery network, use logging and monitoring alerts to track load time and error rate, and turn a one-off creative prototype into a stable, continuously operated project.