Building a Rainy Night City Scene with AI Coding Tools: A Practical Guide
This article explains how to use AI coding tools to build a runnable, interactive 3D rainy-night city scene in the browser. It covers translating vague atmosphere requirements into engineering constraints, a three-round convergence workflow for generation and iteration, scale and composition anchors, performance budgeting for rain, reflections, and post-processing, interaction design, and a practical acceptance checklist. Readers will learn how to turn natural-language prompts into structured, verifiable, and extensible Web 3D work.
1. Background: Why a “Rainy Night City” Tests Generative Coding
Building a 3D “rainy night convenience store” scene on the web may look like just a few blocks and a few lights, but it simultaneously tests the rendering pipeline, material expression, lighting strategy, performance budget, and interaction design. The rainy-night theme is demanding: in low-light conditions, contrast is high, light-source information density is large, and ground reflections and volumetric fog must work together. Any proportion error or performance issue gets amplified. This makes such scenes well suited for evaluating how mature AI coding tools are at the “natural language to runnable code” workflow.
From an engineering perspective, a playable, runnable rainy-night scene must clear at least four hurdles: credible geometry and proportions; acceptable lighting and post-processing; a balance between frame rate and resource usage; and coherent interaction and camera storytelling. The original text notes that it is “not always right on the first try,” which is normal for generative coding: models are good at producing a structurally complete first draft, but proportions, performance, and details need to converge over multiple rounds of dialogue.
2. Requirement Breakdown: Turning “Atmosphere” into Executable Engineering Constraints
Before starting, convert vague atmosphere descriptions into clear engineering metrics. This is key to reducing back-and-forth.
- Scene skeleton: one main street, low-rise buildings on both sides, a corner convenience store, several street lamps and signs.
- Proportion constraints: use “floor height about 3 meters, street width 8 to 12 meters, convenience store frontage 6 to 8 meters” as initial parameters to avoid distorted human-to-building scale.
- Lighting plan: cool ambient light as the base, warm point lights accenting the display window and signs, creating a cool-warm contrast.
- Weather expression: rain streaks via particles or instanced geometry; ground with low-roughness material plus reflections; distant fog or volume to soften boundaries.
- Performance budget: define target frame rate and pixel-ratio cap, limit the number of real-time lights and post-processing layers.
Writing these constraints into the prompt is like giving the model an “acceptance standard.” For example, structure the prompt like this:
Role: Senior Web 3D EngineerGoal: Build a rainy-night convenience store 3D scene that is runnable and interactiveConstraints:- Units: 1 unit = 1 meter; floor height 3m; street width 10m- Lighting: 1 directional light + no more than 6 real-time point lights; the rest use baked or emissive materials- Performance: pixel ratio capped at 1.5; post-processing limited to Bloom and lightweight tone mapping- Interaction: WASD movement, mouse look, prompt appears near the display windowOutput: a complete HTML file with inline styles and scripts, no external resource dependencies
This “role + goal + constraints + output format” structure significantly reduces proportion drift and performance bloat caused by the model improvising.
3. Generation and Iteration: The Three-Round Convergence Method
Actual generation is rarely right on the first try. A “three-round convergence” rhythm is recommended.
Round one: get the skeleton. Focus only on layout, proportions, and the initial camera position; do not pursue materials or effects. The code should be clearly structured and well named for easy later replacement.
Round two: add lighting and weather. Introduce rain particles, ground reflections, fog, and Bloom, and watch for “overexposure,” “mushy blur,” or “sudden frame-rate drops.” The focus is finding the balance between visual quality and cost.
Round three: polish details and interaction. Sign text, in-window shelves, puddle ripples, pedestrian silhouettes, slight handheld camera sway, and similar touches are “playability” bonuses. Also complete collision, movement boundaries, and interaction prompts.
A simplified rendering and post-processing skeleton is shown below to illustrate the “structure first, effects later” order:
// Pseudocode: structure illustration only, not a specific product APIconst scene = new THREE.Scene();scene.fog = new THREE.FogExp2(0x0b1020, 0.035);const renderer = new THREE.WebGLRenderer({ antialias: true });renderer.setPixelRatio(Math.min(devicePixelRatio, 1.5));renderer.shadowMap.enabled = true;// Camera and controls omitted// Rain particles, ground material, lights, and post-processing are added in order
4. Proportion and Composition: Three Anchors That Make the “City” Believable
The most common mistake of generative tools is scale drift. The solution is to give the model three fixed anchors:
- Human anchor: place a reference figure about 1.7 meters tall, and calibrate all door widths and step heights around it.
- Street anchor: define street width and building setbacks first, then arrange facades to avoid “houses squeezed into paper sheets.”
- Light-source anchor: keep street lamp heights uniform at 4 to 5 meters and sign centers at 2.5 to 3 meters, forming a predictable visual rhythm.
For composition, rainy-night scenes suit “low camera position + telephoto compression,” stretching light reflections on wet ground to create depth. Specify in the prompt “initial camera height 1.6 meters, facing the street vanishing point” to reduce random camera placement by the model.
5. Performance Strategy: A “Budget System” for Rainy-Night Effects
Rain, reflections, and Bloom are the three major cost sources and must be managed with budgets.
- Rain: use instancing or Points instead of many independent meshes; control particle count and update frequency.
- Reflections: prefer lightweight planar or screen-space reflections; if necessary, downgrade to “low-roughness material + environment map” fake reflections.
- Post-processing: keep only Bloom and tone mapping; avoid stacking multiple passes.
- Lights: cap the number of real-time point lights; fake the rest with emissive materials and textures.
- Resolution: cap the pixel ratio and lower it further on mobile.
A simple adaptive downgrade logic can be added to illustrate the “budget system” idea:
// Pseudocode: automatic downgrade when frame rate is too lowlet lowFrames = 0;function adapt(dt) {if (dt > 1 / 40) lowFrames++; else lowFrames = 0;if (lowFrames > 60) {renderer.setPixelRatio(1.0);rain.count = Math.floor(rain.count * 0.6);lowFrames = 0;}}
6. Interaction and Narrative: From “Viewable” to “Playable”
Playability comes from small feedback: signs that light up automatically on approach, a wind chime when the door opens, ripples from stepping in puddles, and slight camera rise and fall with breathing. These details need no complex logic but greatly improve immersion. List an “interaction checklist” in the prompt so the model implements items one by one and nothing is missed.
At the same time, interaction needs boundaries: limit movement to the street to avoid walking through walls; limit camera pitch to prevent motion sickness; present all interaction prompts with minimal UI so the rainy-night atmosphere is not broken.
7. Common Pitfalls and Acceptance Checklist
- Proportion drift: use the anchor method to recheck door widths, floor heights, and street widths.
- Overexposure and gray haze: control Bloom intensity and fog density while preserving shadow detail.
- Frame-rate collapse: check the number of real-time lights, particle count, and pixel ratio.
- Clipping and floating objects: give buildings and props a unified “grounded” check.
- Missing interaction: verify each item against the interaction checklist.
8. Conclusion: Turning Dialogue into Runnable Engineering Assets
Using AI coding tools to build a rainy-night city is essentially translating natural-language descriptions into a structured, verifiable, and iterable engineering process. The key is not “how impressive the first generation is” but “how stable the convergence is over multiple rounds.” When requirement breakdown, proportion anchors, performance budgets, and the interaction checklist are all defined upfront, the result can evolve from a “demo” into a “runnable, debuggable, and extensible” work. This method also applies to other atmospheric 3D scenes and has strong reuse value.
