Building a Rainy Night 3D City with AI Coding Tools
This article explains how to build a rainy night 3D city scene with the help of AI coding tools, using real-time rendering as the core technical challenge. It covers translating atmosphere descriptions into engineering constraints, organizing scene complexity into structure, enclosure, and decoration layers, handling wet materials and lighting, designing believable rain particles with dynamic degradation, setting measurable performance budgets, and running effective multi-round human-AI iteration. It also includes interaction design, an acceptance checklist, and common defects, showing how clear constraints, quantified metrics, and small iterations lead to stable, high-quality real-time scenes.
1. Introduction: Why a Rainy Night City Tests Real-Time Rendering
In real-time graphics and creative coding, rainy night scenes are widely regarded as a stress test. They involve large amounts of transparent overdraw, dynamic lighting, reflection and refraction, particle systems, post-processing chains, and continuous resource scheduling. Even a seemingly simple scene—rain falling outside a convenience store—touches most parts of the rendering pipeline. Building a rainy night 3D city with the help of AI coding tools can validate the tool’s stability across long contexts and multiple iterations, while also producing a reusable engineering workflow.
AI coding tools are not magic that turns a single sentence into a finished product. They work more like a fast, knowledgeable collaborator that lacks awareness of on-site constraints: the clearer your constraints, the closer the output is to runnable; the vaguer you are, the more the tool oscillates between scale, performance, and detail. This article stays tool-agnostic and focuses on general capabilities and the human-AI collaboration process.
2. Requirement Breakdown: Turning Atmosphere into Engineering Constraints
Phrases like “rainy night, warm light, wet ground, distant neon” describe feelings, but a rendering engine only understands numbers and structures. The first step is translation:
- Scene scale: Define street width, floor height, and the convenience store’s frontage and depth in meters to avoid scale drift.
- Camera and frustum: Specify the initial position, field of view, and near/far clipping planes, which determine all later composition.
- Time budget: The target frame rate determines the milliseconds available per frame, which in turn constrains draw batches, particle counts, and post-processing levels.
- Interaction scope: Whether you need roaming, door opening, rain hitting an umbrella, or light sensing determines state machine complexity.
Write these into a “constraint list” and use it as a fixed prefix for every conversation round. This significantly reduces the chance of the model “forgetting” key settings during iteration.
Example constraint description (a prompt fragment for AI coding tools):
Goal: single-page real-time 3D scene, rainy night city corner with a convenience store.Scale: street width 8m; store frontage 6m, depth 4m, floor height 3.2m.Camera: starts across the street, 50-degree field of view, drag to rotate and scroll to zoom.Performance: prioritize smooth performance on integrated GPUs in mid-range laptops; particles and post-processing must support tiered degradation.Style: low-poly with high-contrast warm/cool lighting; wet ground shows visible reflections.
3. Scene Layering: Controlling Complexity with Structure, Enclosure, and Decoration
Complex scenes usually get out of control when all elements are placed on the same level. A more stable approach is layering:
- Structure layer: ground, walls, columns and beams, canopy frames. Use simple geometry and consistent units to keep proportions correct.
- Enclosure layer: glass, roller shutters, window frames, door openings. Transparency and occlusion relationships appear here, so rendering order strategy should be decided early.
- Decoration layer: signs, light boxes, shelves, drink coolers, puddles, trash bins, utility poles. Most detail lives here, and this is where performance fluctuates the most.
The direct benefit of layering is that when performance falls short, you can quickly identify whether the decoration layer is overloaded or the enclosure layer has transparency sorting issues, instead of rewriting everything.
4. Materials and Lighting: The Technical Essence of a Rainy Night Mood
A rainy night looks good not because of filters, but because of energy distribution and surface response.
- Wet ground: Lower roughness and increase specular reflection strength, with normal perturbation for fine highlights. If real-time reflection is too costly, approximate it with a baked environment map plus screen-space reflection.
- Glass and puddles: For transparent materials, control the ratio of refraction to reflection to avoid a “plastic” look. With multiple transparent layers, disable unnecessary depth writes to reduce sorting errors.
- Lighting structure: Use one main light (warm light inside the store) as a visual anchor, cool ambient light for contrast, and a few point lights to simulate signs and street lamps. Keep the light count controlled; too many dynamic lights quickly consume the performance budget.
- Fog and volume: Use exponential fog to separate near and far layers, and use a few billboards to simulate halos when needed, rather than scene-wide volumetric fog.
A common mistake is handing the entire mood to post-processing. Post-processing can enhance contrast and halos, but if the base lighting and materials are wrong, more layers only make it look dirtier.
5. Particles and Animation: Making Rain Believable, Not Just Dense
Rain’s believability depends on motion patterns and spatial distribution, not particle count.
- Layered rainfall: Near raindrops are large and sparse and fall fast; distant rain curtains are small and dense and slightly slower, creating parallax.
- Wind and disturbance: Add slight horizontal offset and gust noise so raindrops do not all fall perfectly parallel.
- Ground feedback: Place a few looping ripple decals or short-lived particles on the ground and canopy, far cheaper than full-scene physics simulation.
- Degradation strategy: Dynamically adjust particle emission rate based on frame time, sacrificing distant density first while preserving the near view.
Example pseudocode:
// Dynamically adjust rain density based on frame timeconst dt = clock.getDelta();if (dt > 0.028) rainFar.emitRate *= 0.9;else if (dt < 0.018) rainFar.emitRate = Math.min(maxRate, rainFar.emitRate * 1.05);
6. Performance Budget: Turning “Smooth” into Measurable Metrics
“Smooth” must be quantified; otherwise, iterations turn into subjective arguments. Build a three-layer budget:
- Frame budget: milliseconds per frame for the target frame rate, with separate CPU and GPU limits.
- Batch budget: an upper limit on draw calls, which the decoration layer most easily exceeds.
- VRAM budget: an upper limit on total texture and render target usage, with the post-processing chain as the main consumer.
Engineering techniques include merging static geometry, instancing repeated objects (shelf goods, canopy supports), tiering texture sizes, disabling updates for invisible faces, and splitting post-processing into toggleable levels. The key principle is “measure first, then optimize”; cutting by feel often removes the wrong things.
7. Human-AI Collaboration: How to Iterate Across Multiple Rounds
In practice, it rarely works on the first try. A more efficient collaboration approach is:
- First round: only a “minimum runnable loop”—ground, walls, camera, one light, basic rain.
- Second round: add enclosure and main light, then confirm scale and composition.
- Third round: add decoration and reflections, and run a performance measurement immediately.
- Fourth round: add interaction and animation, then tune post-processing levels together.
- At the end of each round, ask the tool to output a “current implementation summary + known defect list” to avoid context drift.
When scale is wrong, do not just say “that’s wrong”; point out the specific measurement relationship. When performance drops, provide frame time data instead of saying “it’s laggy.” The more specific the constraints, the less rework.
8. Interaction and Playability: From “Viewable” to “Playable”
Playability is not complicated; the key is clear states:
- Camera: orbit rotation, zoom, and limits to prevent wall clipping and flipping.
- Environmental response: signs brighten gradually on approach, and warm light from inside the door spills out more strongly.
- Detail feedback: clicking a puddle triggers ripples, and mouse movement adds slight parallax.
- Accessibility: provide quality tiers and a reduced-motion toggle for different devices and user sensitivities.
9. Acceptance Checklist and Common Defects
- Scale: whether door height matches a human reference and whether shelves clip through objects.
- Transparency sorting: whether glass and rain curtains flicker or occlude incorrectly.
- Performance: whether frame time is stable and degradation is smooth without jumps.
- Visuals: whether shadows are crushed to black, highlights are blown out, or fog washes out detail.
- Engineering: whether resources are configurable and code is modular enough for further extension.
10. Conclusion
Building a rainy night city with AI coding tools is essentially training in “turning vague creativity into engineering.” Tools can greatly shorten the distance from idea to runnable work, but scale definition, performance budgets, and acceptance criteria must remain in the developer’s hands. Writing constraints clearly, quantifying metrics, and keeping iterations small are the keys to stably producing high-quality real-time scenes. To take it further into an online service, you can combine object storage for static assets, a content delivery network for faster loading, and logging and monitoring services to observe runtime quality, forming a complete engineering loop.
