Building a Rainy Night City Scene with AI Coding Tools: A Practical Guide
This article presents a practical methodology for building a rainy night city scene in the browser using AI coding tools. It covers how to translate natural-language creative ideas into verifiable engineering constraints, choose between single-file and modular architectures, calibrate real-world scale, and apply physically based lighting and materials to achieve a convincing wet-night atmosphere. It also explains GPU-driven rain particles, interaction design, performance and compatibility strategies, and a five-step human-AI iteration workflow. Developers will learn how to turn an aesthetic concept into a runnable, explorable 3D scene through structured prompts, layered design, and incremental refinement.
1. Introduction: From an Idea to a Runnable World
As 3D graphics and browser rendering capabilities continue to evolve, describing a scene in natural language and having AI coding tools generate runnable code has moved from demos into everyday development workflows. The core goal of this practice is straightforward: build a rainy-night city street corner in the browser, centered on a convenience store, with wet reflective pavement, neon glow, continuous rainfall, and street clutter, forming a small world that users can rotate, zoom, explore, and play with.
Such a task may look lightweight, but it spans multiple engineering dimensions: scene composition and scale consistency, physical plausibility of materials and lighting, performance limits of particle systems, interaction and camera control, and cross-device compatibility. It is rarely right on the first attempt; proportions, performance, and details usually require several rounds of feedback and correction. This article abstracts that process into a general methodology, stripped of any specific product attributes, to help developers reliably deliver high-quality 3D work with the help of AI coding tools.
2. Requirement Breakdown: Translating “Rainy Night City” into Engineering Language
A natural-language creative idea must first be broken down into verifiable technical constraints; otherwise the generated result will waver between “looks right” and “runs smoothly.” It is recommended to establish a requirement baseline across four dimensions.
- Visual goals: set the time to late night, with the convenience store sign and cool white interior light as the key light, warm yellow street lamps and distant neon as fill light, and wet asphalt ground with high reflectivity and localized puddles.
- Composition goals: use the convenience store facade as the visual anchor, extend the street into the depth of the scene, and place recognizable clutter in the foreground (bench, trash can, bicycle, cardboard boxes) to create layers.
- Interaction goals: support orbit rotation, scroll-wheel zoom, optional first-person roaming, and trigger logic for “entering the store.”
- Engineering goals: maintain a stable frame rate on mainstream browsers and mid-range devices, keep resource loading controllable, and allow the scene to be extended incrementally.
Writing these goals into a structured prompt is key to improving the first-pass success rate. Example (illustrative description, not specific tool syntax):
Role: Senior graphics engineerTask: Generate a single-file Three.js sceneConstraints:1) Use WebGLRenderer with shadows and tone mapping enabled;2) Use a perspective camera, initial position (6, 4, 10), looking at (0, 1.5, 0);3) Scene unit is meters; convenience store width 6m, depth 8m, floor height 3.2m;4) Rain uses GPU particles, with a configurable upper limit, default 6000;5) Ground uses a physical material with roughness 0.15 and normal perturbation;6) Expose a window.__scene debug handle for external parameter tuning.
The value of such prompts lies in being “verifiable”: each item can be checked directly against the running result, preventing generated content from staying at the level of style description.
3. Architecture Design: Single File vs. Modularization
The rainy night city is not large in scale, but for future extension and team collaboration, it is still advisable to define clear layers. There are two common approaches.
Single-file mode suits rapid validation and online sharing, keeping the scene, materials, and interaction in one script. Its advantage is that it runs as soon as it is copied; its drawback is that late-stage iteration tends to cause naming conflicts and mixed responsibilities. Modular mode splits by responsibility, for example into five modules: scene assembly, material library, particle system, interaction control, and performance panel, assembled through a unified entry point. For teams that need long-term evolution, modularization is more conducive to review and reuse.
Regardless of the mode, a “parameter hub” should be retained to centralize adjustable items and avoid magic numbers scattered everywhere:
const CONFIG = {rain: { count: 6000, area: 40, speed: 18 },ground: { roughness: 0.15, metalness: 0.0 },lights: { keyIntensity: 2.4, fillIntensity: 0.8 },camera: { fov: 55, near: 0.1, far: 200 }};
4. Scale and Proportion: The Overlooked Foundation of Realism
The most common rework in practice comes from proportion imbalance: door frames too high, shelves too low, streets too wide, making the scene look “like a model rather than a space.” The solution is to first establish a scale reference, then calibrate level by level.
- Use the human body as a baseline: set adult height to 1.7m, door opening clear height to 2.1m, and step height to 0.15m.
- Use modules as a baseline: design the convenience store width at 6m, shelf unit width at 0.9m, and checkout counter height at 1.05m.
- Use the street as a baseline: sidewalk width 2.5m, lane width 3.5m, curb height 0.12m.
- Verify with the camera: place the camera at a 1.6m eye height for a “pedestrian view” check, then switch to a top-down view to confirm the overall layout.
It is recommended to explicitly annotate units and key dimensions in the code, so that AI tools maintain consistency during later modifications:
// Unit: metersconst SHOP = { width: 6, depth: 8, height: 3.2, doorHeight: 2.1 };const STREET = { sidewalk: 2.5, lane: 3.5, curb: 0.12 };
5. Lighting and Materials: The Physical Logic of a Rainy Night
The core of the rainy-night look is “low ambient light + high-contrast light sources + wet surface reflections.” Missing any one of the three undermines the scene’s credibility.
- Ambient light: use low-intensity hemisphere light to simulate the night sky and ground bounce, avoiding dead black areas.
- Key light: cool white light from inside the convenience store spills through the glass and doorway, creating bright patches on the ground.
- Fill light: warm yellow street lamps cast downward as spotlights, with shadow maps reinforcing directionality.
- Reflection: the ground uses a physical material with reduced roughness, combined with an environment map to produce blurred reflections; localized puddles can be overlaid with separate planes at higher reflection intensity.
- Volume: add semi-transparent cones or screen-space halos to light sources to simulate scattering in rain and mist.
At the material level, it is recommended to adopt a physically based rendering approach throughout to avoid a “plastic” look. Metal shelves, glass doors and windows, wet asphalt, and plastic signs should each be assigned metalness and roughness ranges, with normal maps added to supply micro-scale surface variation.
6. Rain and Particles: Balancing Visuals and Frame Rate
Rain is the atmospheric protagonist and also a performance risk. A GPU-driven particle approach is recommended, with position updates handled in the shader and the CPU only passing parameters. Key control items include particle count, distribution volume, fall speed, and wind offset.
// Example: time-driven rainfall to avoid per-frame CPU computationuniform float uTime;attribute float aOffset;void main() {vec3 p = position;p.y = mod(p.y - uTime * 18.0 + aOffset, 40.0);p.x += sin(uTime * 0.5 + aOffset) * 0.6; // slight wind offsetgl_Position = projectionMatrix * modelViewMatrix * vec4(p, 1.0);}
A fallback strategy should also be provided: when the frame rate drops below a threshold, automatically reduce particle count, disable shadows, or lower render resolution to keep interaction smooth. Raindrops hitting the ground can be paired with simple ripple textures or short particle bursts, but the count must be strictly limited.
7. Interaction and Playability: Making People Want to Stop and Look
“Playable” means the scene needs feedback. Basic interactions include orbit control with damping, zoom range limits on the scroll wheel, and double-click to focus on a detail. Advanced interactions can include lights turning on automatically as you approach, pushing the door to enter the store, flickering checkout screens, and the occasional distant car passing by and splashing water.
Interaction implementation should keep “states small and clear,” for example using a finite state machine to manage three states: “street — doorway — inside,” avoiding logic pile-up that becomes hard to debug:
const state = { mode: 'street' };function enterShop() { state.mode = 'shop'; /* trigger camera tween and lighting changes */ }function exitShop() { state.mode = 'street'; }
8. Performance and Compatibility: From “Runs” to “Runs Smoothly”
Performance governance should run throughout development, not be a last-minute fix. Three routine checks are recommended.
- Draw calls: merge static geometry and reuse materials to reduce draw calls.
- Textures and resolution: load by device capability tier, and reduce shadow map size on mobile.
- Frame rate monitoring: build in a simple panel showing frame rate and particle count to quickly locate bottlenecks.
For compatibility, handle high-DPI pixel ratio caps, pause rendering when the page is not visible, and synchronize camera and renderer updates on window resize. For low-end devices, offering a “quality preset” switch is the lowest-cost, most robust solution.
9. Human-AI Collaboration: Multiple Iterations, Not One-Shot Success
Treat AI coding tools as “efficient collaborators that need clear constraints.” The workflow can be fixed into five steps: structure requirements, generate the skeleton, calibrate proportions, polish the atmosphere, and converge on performance. Each round focuses on a single goal and includes the current problem and acceptance criteria in the prompt, for example “lower the door frame height to 2.1m and keep everything else unchanged.” This “small commits, immediate verification” approach significantly reduces rework costs.
Human checkpoints should also be established: whether proportions are distorted, whether lighting matches physical intuition, whether interactions are predictable, and whether performance meets targets. Tools provide productivity; developers provide judgment. Only their combination yields stable output.
10. Conclusion
Building a rainy night city with AI coding tools is essentially an exercise in “engineering an aesthetic intent.” The key to success is not how complete a single generation is, but whether you can break a creative idea into verifiable constraints, carry complexity with a layered architecture, support atmosphere with physical logic, safeguard experience with performance strategies, and approach the ideal result through multiple iterations. Once you master this method, any “scene in your mind” can be reliably transformed into a truly runnable, playable work.
