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

    This article walks through building a rainy night convenience store scene in Three.js with the help of AI coding tools. It explains how to turn vague atmosphere words into a concrete constraint list, how to write structured prompts, how to keep scale and coordinates consistent across iterations, and how to set a performance budget for particles and overdraw. A reusable workflow and three rounds of detail refinement are included.

    1. Why a Rainy Night Scene Tests AI Coding Tools

    In real-time rendering, a seemingly simple “rainy night convenience store” actually exercises four capabilities at once: scene modeling, material and lighting, particle systems, and performance control. Night means low illumination and strong contrast. Rain means a large number of semi-transparent particles and stacked overdraw. A convenience store means regular geometry, glowing signage, and an indoor-outdoor lighting transition. Combining the three produces a practice sample of moderate complexity but full dimensional coverage, which makes it a good way to test how an AI coding tool performs under real engineering constraints.

    From a practical standpoint, the value of this task is not a perfect result on the first generation. It is validating a workflow: describe the scene intent in natural language, let the tool produce runnable code, refine scale, performance, and details with the developer over several rounds, and end up with a stable, playable result. The core tension in this workflow is the gap between the vagueness of expressing intent and the precision of the rendered output. Every method below is about narrowing that gap.

    2. Requirement Breakdown: Turning Atmosphere into Engineering Constraints

    Words like “rainy night,” “convenience store,” and “small town” are atmosphere words in natural language and cannot drive code directly. The first step is to break them into quantifiable engineering items:

    • Scene scale: fix street width, storefront span, floor height, and sign height in meters to avoid proportion drift later.
    • Lighting structure: separate ambient light, moonlight or skylight, in-store main light, sign emission, and street lamp point lights, with defined intensity and falloff range for each.
    • Weather system: model rain density, fall speed, wind offset, ground splashes, and glass water streaks separately instead of lumping them together.
    • Material layers: wet road surface, concrete wall, metal roller shutter, and glass window each need a different roughness and reflection strategy.
    • Performance budget: target frame rate, draw call limit, and particle cap come first, before any implementation.

    The output of this step is not code but a constraint list. When you later talk to an AI coding tool, converting the list into prompts item by item significantly reduces back-and-forth rework.

    3. Prompt Design: Structured Description Instead of Casual Wishing

    The most common failure in practice is driving generation with a single sentence like “make a convenience store in the rain.” A more reliable approach is a structured prompt that states constraints, structure, and acceptance criteria. Example:

    1. Task: Generate a Three.js scene of a rainy night corner convenience store.
    2. Scale: street width 8 m, storefront span 6 m, floor height 3.2 m, sign bottom edge 2.6 m above ground.
    3. Lighting: ambient 0.15, directional light simulating cool skylight 0.4, warm in-store main light 1.2, emissive sign.
    4. Weather: 6000 rain streaks, fall speed 18 m/s, wind offset 0.15, 800 ground splash particles.
    5. Materials: road roughness 0.25 with reflection, wall 0.8, glass with transmission and water streak normals.
    6. Performance: target 60fps, draw calls < 120, particle cap 8000.
    7. Acceptance: runs on first load, no console errors, proportions match the constraint list.

    The key to a structured prompt is replacing adjectives with numbers and structure. When the result deviates, you can locate the specific item to fix instead of rewriting everything.

    The original text notes that scale needs repeated discussion. This is not a tool capability issue but a missing shared coordinate baseline. Establish a set of scene measurement conventions first:

    1. Unified origin: use the store door center as the origin, with the street extending along the X axis and Y pointing up.
    2. Unified unit: use meters throughout, and never mix centimeters and meters in the same scene.
    3. Layered organization: split buildings, street, weather, and lighting into separate groups so each can be scaled independently without breaking the whole.
    4. Whitebox before polish: block out volume and openings with boxes first, confirm proportions, then replace materials and details.

    Sample code showing this layered approach:

    1. const city = new THREE.Group();
    2. const building = new THREE.Group();
    3. const street = new THREE.Group();
    4. const weather = new THREE.Group();
    5. city.add(building, street, weather);
    6. scene.add(city);
    7. // Whitebox stage: confirm volume only
    8. const box = new THREE.Mesh(
    9. new THREE.BoxGeometry(6, 3.2, 4),
    10. new THREE.MeshStandardMaterial({ color: 0x888888 })
    11. );
    12. box.position.set(0, 1.6, 0);
    13. building.add(box);

    When proportions drift, check the unit and the origin first instead of asking the tool to “generate another random version.”

    5. Performance Budget: Overdraw and Particles Are the Main Cost

    The frame rate killers in a rainy night scene are usually not polygon counts but semi-transparent overdraw and large particle counts. Set the budget first in engineering terms, then make the implementation fit it:

    • Cap the total particle count, and simulate the excess with textures and scrolling offsets instead of unlimited growth.
    • Render rain streaks with a single-draw-call instanced or Points approach, avoiding one object per streak.
    • Fake glass water streaks and ground reflections with textures and normals first to reduce real reflection cost.
    • Keep the light count under control, and pair point lights with distance falloff culling.
    • Add frame rate and draw call monitoring so “meeting the target” becomes an observable metric.

    Sample budget guard logic:

    1. const MAX_DROPS = 8000;
    2. function guardRain(count) {
    3. return Math.min(count, MAX_DROPS);
    4. }
    5. // Throttle dynamically each frame based on frame rate instead of filling up at once

    Treating performance as a constraint rather than a later optimization is the dividing line for whether this kind of scene stays playable.

    6. Detail Iteration: Three Rounds from Runnable to Watchable

    The first round solves “it runs”: no errors, correct proportions, distinguishable lighting. The second round solves “it looks like a rainy night”: add wind offset to rain streaks, ground splashes, sign glow, and cool ambient contrast. The third round solves “it holds up to viewing”: add glass water streaks, worn metal on the roller shutter, local puddle reflections on the road, and distant block silhouettes. Each round changes only one class of problem and is accepted against the same constraint list, so changes do not contaminate each other.

    7. A Reusable Engineering Workflow

    Turning the above into a fixed process greatly reduces reliance on getting everything right in one pass:

    1. Write the constraint list (scale, lighting, weather, materials, performance).
    2. Generate a whitebox version with a structured prompt.
    3. Verify scale and coordinates, and fix units and origin.
    4. Inject the performance budget and guard logic.
    5. Run three rounds of detail iteration, with single-goal acceptance each round.
    6. Wire up logging and monitoring to check whether frame rate and draw calls meet the target.

    8. Conclusion

    The real difficulty of “building a rainy night town” is not generating impressive-looking code. It is translating vague atmosphere into precise constraints and holding two bottom lines, scale and performance, across multiple rounds of discussion. AI coding tools are well suited to the accelerator role of going from idea to runnable code, while developers still need the methodology of decomposition, measurement, and acceptance. When the constraint list, coordinate baseline, and performance budget are all in place, an idea in your head can reliably become a real, runnable, playable result.