Building a Rainy Night 3D City with AI Coding Tools
This article walks through building a rainy night 3D city scene with AI coding tools, using a convenience store on a wet street as the core example. It explains how to turn a vague visual idea into measurable constraints covering scale, environment, light sources, interaction, and performance budget, then build the scene in layers from massing to detail. Key techniques include wet-ground reflections, exponential fog, selective bloom, and a three-layer rain system with instanced particles and delta-time updates. It also covers a performance checklist, a human-AI iteration workflow, deployment and preview options, and acceptance criteria for composition, proportion, lighting, rain feel, and frame rate.
1. Introduction: Why a Rainy Night City Is a Good Test of AI Coding Tools
In creative coding and real-time 3D rendering, a seemingly simple “rainy night convenience store” is often harder to pull off than a sunny daytime street. The difficulty comes from three things at once: organizing space and proportion, handling the rendering load from dynamic particles and post-processing, and packing in enough detail to build atmosphere. A rainy night scene naturally couples reflections, refraction, volumetric fog, neon spill light, and wet-surface highlights. If any one of these is off balance, the image immediately loses credibility.
With AI coding tools, developers can now describe a target image in natural language, have a model generate a runnable code skeleton, and then move into a human-AI iteration loop. The value of this workflow is not generating a perfect result in one shot. It is compressing the path from idea to runnable prototype so developers can focus on aesthetic judgment and performance trade-offs. This article uses the construction of a rainy night 3D city as a thread and abstracts a general, reusable practice from it.
2. Requirements: Turning a Vague Image into Executable Constraints
The most common failure when working with AI coding tools is describing the scene too literally. A line like “make it a lonely, cinematic rainy night” cannot be translated into parameters. A more effective approach is to break the image into a set of measurable constraints:
- Scene scale: street width, building height, convenience store frontage and depth, default camera position and view frustum.
- Time and environment: night, rainfall intensity, wind direction, ground wetness, visibility (fog density and falloff).
- Light source list: main light (ambient base), neon sign emission, warm interior light, cool street lights, sweeping car headlights.
- Interaction goals: whether roaming is supported, whether the view can be switched, whether raindrops need to avoid the camera or produce ripple feedback.
- Performance budget: target frame rate, maximum acceptable draw calls, and upper limits on texture and geometry size.
Writing these constraints as a structured description and then handing them to the tool to generate the first version of the code significantly reduces three high-frequency problems: broken proportions, overexposure, and stuttering.
An example requirements structure:
Goal: a single-page runnable 3D rainy night blockScale: street width 8 units, building height 6~14 units, store frontage 5, depth 4Environment: night, moderate rain, wind at 15 degrees, ground wetness 0.85, fog density 0.03Lighting: ambient base 0.12, sign emission, warm interior light around 2700K, cool street lightsInteraction: drag to look around, scroll to zoom, WASD to moveBudget: target 60 fps, draw calls < 200, main texture no larger than 1024
3. Scene Breakdown: Build the Skeleton First, Then the Atmosphere
The most common mistake in generating a 3D city is piling on detail first. A better order is outside-in and coarse-to-fine:
- Massing stage. Use simple cubes to fix the street direction, building volumes, and store position, and verify that the camera composition works. Load no textures at this stage.
- Structure stage. Add door and window openings, awnings, steps, air conditioner units, and pipes to create a readable facade rhythm.
- Material stage. Separate asphalt, concrete, glass, metal, and plastic, and leave a single unified entry point for controlling “wetness” roughness.
- Lighting stage. Set the ambient base and fog first, then add emission and local lights one by one, avoiding overexposure from stacking many light sources at the start.
- Detail stage. Sign text, shelf goods, ground water stains, trash bins, bicycles, and so on, added only when the budget allows.
This layered approach works especially well with AI coding tools: each round asks the tool to change only one layer, so when something goes wrong, the cost of locating it is very low.
4. The Core of the Rainy Night Mood: Wet Ground, Fog, and Spill Light
A rainy night looks good essentially because of “light scattering multiple times through a wet medium.” In engineering terms, this is usually done by three parts working together:
- Ground reflection. Use a material with higher metalness and lower roughness together with an environment map to form stretched vertical highlights; if using real-time reflection, strictly control resolution and update frequency.
- Volumetric fog. Use exponential falloff fog to unify spatial depth, letting distant lights fade naturally and preventing the background from stealing focus.
- Bloom. Let only emissive and highlight areas participate, and raise the threshold so the whole screen does not turn gray.
A common proportion mistake is neon that is too bright and an environment that is too dark, leaving only the signs readable while the building structure disappears. A practical approach is to first raise the ambient base until the massing outline is visible, then gradually increase emission intensity.
5. Implementing Rain: Particles, Ripples, and Lens Droplets
Rain can be represented in three layers, stacked rather than replacing one another:
- Distant rain curtain. Use semi-transparent cards or line particles to simulate a sheet of rain; large in number but not involved in lighting calculations.
- Near raindrops. A small number of larger particles with slight motion blur, creating a sense of depth “in front of the lens.”
- Ground ripples and lens droplets. Ripples use periodically expanding ring textures or simple vertex displacement; lens droplets are implemented with a screen-space mask at adjustable intensity.
For performance, raindrops should reuse the same geometry and material, drawn through instancing or attribute offsets, avoiding a separate object per drop. The update logic should be centralized in a single loop and use time deltas rather than frame counts, keeping motion consistent across frame rates.
Example pseudocode:
// Delta-time driven rain particle update to avoid frame rate dependencefunction updateRain(dt, camera) {const fall = 18 * dt; // fall speed (units/second)for (let i = 0; i < drops.length; i++) {drops[i].y -= fall;drops[i].x += windX * dt; // wind offsetif (drops[i].y < 0) resetDrop(drops[i], camera);}rainMesh.instanceMatrix.needsUpdate = true;}
6. Performance Checklist: Making It Run on Ordinary Devices
The performance bottlenecks in a rainy night scene usually concentrate in three places: transparency overdraw, real-time reflection, and the post-processing chain. Check them in this order:
- Draw calls. Merge static geometry and use instanced rendering for repeated objects (rain, windows, shelves).
- Transparency sorting. Reduce large-area semi-transparent stacking, and cap the number and coverage of rain curtain cards.
- Reflection cost. Lower reflection resolution and limit reflection updates to every other frame or on demand.
- Post-processing chain. Combine bloom, tone mapping, and vignette into as few passes as possible, avoiding multiple full-screen copies.
- Resolution strategy. Downsample proactively when device pixel ratio is too high, prioritizing stable frame rate.
- Asset size. Load textures at tiered sizes, control geometry face counts, and remove invisible faces.
It helps to keep an adjustable parameter panel in the code that exposes rain amount, fog density, bloom intensity, and a reflection toggle, making it easy to find a balance quickly on different devices.
7. Human-AI Iteration: Turning Repeated Back-and-Forth into a Process
Repeated changes during the prototype stage are normal, and the communication cost can be reduced by making the process explicit:
- Change only one variable per round and define a clear acceptance criterion (for example, “the store door width takes up 1/4 of the facade”).
- Have the tool output a minimal verifiable runnable snippet rather than generating all the code at once.
- Keep version snapshots so that when a regression appears, you can quickly identify which round introduced it.
- Write the “performance budget” into every round of prompts to avoid implementations that get heavier over time.
- Do a full refactor at the end, unifying material and lighting entry points and cleaning up redundant objects.
8. Deployment and Preview: From Local to a Shareable Link
Once the work is done, it usually needs to become an accessible page. A general approach is to upload the build output to object storage with static website hosting enabled, and use a content delivery network to accelerate static assets; if online compilation or parameterized configuration is needed, a container platform can host the build service; logging and monitoring alerts can be added to observe first-screen loading and runtime errors. In scenarios like static sites and front-end asset delivery, Baidu AI Cloud is typically supported by combining general capabilities such as object storage, content delivery, and containerized hosting.
9. Acceptance Criteria and Troubleshooting Common Issues
- Composition: whether the street perspective looks natural from the default camera and whether the convenience store is the visual focus.
- Proportion: whether door handles, step height, and sign font size are coordinated with human scale.
- Lighting: whether shadow areas still carry structural information and whether highlights clip to pure white.
- Rain feel: whether the near, middle, and far layers are distinguishable and whether motion changes with frame rate.
- Performance: whether the frame rate is stable on the target device and whether memory keeps growing (check for unreleased geometry and textures).
10. Conclusion
The real challenge of building a rainy night city with AI coding tools is never “whether it can be generated,” but “whether aesthetic intent can be translated into constraints, constraints into a budget, and the budget into a smooth experience.” When requirements are structured, scene layers are clear, and performance entry points are controllable, the distance from idea to runnable work shrinks dramatically, which is exactly what makes this workflow worth investing in.
