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

    This article presents a practical engineering workflow for building an interactive rainy night city scene with AI coding tools. It covers a five-layer architecture, how to translate atmosphere into quantifiable parameters, iterative collaboration with code generation tools, performance and quality governance, deployment and observability, and common pitfalls with workarounds. The goal is to turn a creative idea into stable, runnable code through structured descriptions, parameterized constraints, small-step iteration, and performance budgeting.

    1. Background and Problem Definition

    In 3D graphics and creative coding, a “rainy night city” is a typical high-information-density scene: wet road reflections, volumetric fog, neon halos, rain particles, convenience store warm light, and cool street lighting all interweave. It needs both atmosphere and real-time interactivity. In the past, the barrier to such work was that developers had to master scene modeling, materials and lighting, particle systems, performance tuning, and engineering deployment at the same time. As intelligent coding tools (AI coding assistants that understand natural language and generate runnable code) matured, the workflow was compressed into a closed loop of “describe, generate, run, get feedback, and fix.”

    However, it must be emphasized that these tools are not magic that produces a finished result in one shot. In practice, common deviations fall into three categories: scale distortion (inconsistent building and street proportions), performance loss of control (frame rate drops sharply when particles and post-processing stack up), and missing details (material roughness, reflection intensity, and light color temperature not matching expectations). This article provides a rigorous engineering method from a general technical perspective.

    2. Overall Technical Architecture

    A runnable rainy night city can be split into five layers:

    1. Scene description layer: Use structured natural language (or JSON configuration) to describe city layout, building proportions, lighting scheme, and weather parameters.
    2. Code generation layer: Intelligent coding tools produce the code skeleton for scene initialization, geometry construction, materials and lighting, particles, and post-processing.
    3. Runtime layer: Render in real time in the browser based on a general web graphics rendering approach (such as a WebGL-based rendering pipeline).
    4. Performance governance layer: Control overhead through instancing, culling, resolution scaling, and particle count limits.
    5. Deployment and observability layer: Use general cloud capabilities (object storage for hosting static resources, container platforms for running services, logging services, and monitoring alerts) to complete launch and quality tracking.

    Illustrative configuration (pseudocode):

    1. {
    2. "city": { "blocks": 6, "streetWidth": 8, "buildingHeightRange": [12, 40] },
    3. "weather": { "rainCount": 4000, "fogDensity": 0.035, "wind": [0.2, 0.0] },
    4. "lighting": { "ambient": 0.12, "neonHue": [190, 320], "warmShop": 2700 },
    5. "quality": { "pixelRatioCap": 1.5, "shadowMapSize": 1024 }
    6. }

    3. Requirement Breakdown: Translating “Atmosphere” into Executable Parameters

    A “rainy night” is not a single effect but a superposition of multiple physical and visual phenomena. It needs to be broken down into quantifiable items:

    • Scale and proportion: Street width, floor height, and sign size must match real urban intuition. It is recommended to first fix “1 unit = 1 meter” and then have the generated result output around that baseline.
    • Wet reflections: Ground materials need low roughness and relatively high reflection intensity, combined with the general idea of environment lighting maps or screen-space reflections.
    • Volumetric fog and halos: Fog density determines visibility, and neon halos rely on bloom-type post-processing, but excessive stacking will “blur into one mass.”
    • Rain particles: Count, length, speed, and wind direction together determine realism; particles are the number one performance killer and must have an upper limit.
    • Color temperature contrast: Convenience store warm light (about 2700K) and cool street light (above about 6000K) create narrative tension.

    Writing the above items into structured prompts so that intelligent coding tools “generate by parameters” rather than “generate by feeling” can significantly reduce rework.

    4. Generation and Iteration: The Right Way to Collaborate with Tools

    1. Skeleton first, details later: In the first round, only ask for the layout and camera path generation, confirm the proportions are correct, and then add materials and particles.
    2. Small-step commits: Change only one dimension at a time (such as adjusting only fog density) to make it easier to locate problems.
    3. Constrain output: Explicitly require “no additional dependencies” and “keep it runnable as a single file” to reduce environment conflicts.
    4. Feedback must be verifiable: Replace “make it more realistic” with measurable conditions such as “automatically downgrade particle count when frame rate is below 30.”
    5. Keep rollback points: Save a snapshot after each round of generation to avoid detail iteration breaking the overall proportions.

    Illustrative pseudocode (performance adaptation):

    1. // Dynamically adjust particles and pixel ratio based on frame rate
    2. function adaptQuality(fps, rain, renderer) {
    3. if (fps < 30) {
    4. rain.count = Math.max(800, rain.count * 0.8);
    5. renderer.setPixelRatio(Math.min(1.0, renderer.getPixelRatio()));
    6. }
    7. }

    5. Performance and Quality Governance

    • Instanced rendering: Use instancing for buildings, street lights, and signs to reduce draw calls.
    • Culling strategy: Combine frustum culling and distance culling; reduce the model detail of distant buildings or replace them with billboards.
    • Post-processing restraint: Enable bloom, tone mapping, and anti-aliasing on a “necessary first” basis, avoiding stacking.
    • Resolution and frame rate balance: Limit the upper bound of pixel ratio and lower it further on mobile devices.
    • Resource size control: Compress textures, load on demand, and serve static resources through general object storage and a content delivery network.

    6. Deployment and Observability

    For a work to be “playable,” it must be stably accessible. General practices:

    • Host static resources on object storage, combined with a content delivery network to reduce latency.
    • If the server needs APIs, deploy using a container platform, keeping it stateless and horizontally scalable.
    • Integrate logging services to collect frontend errors and performance metrics, and configure monitoring alerts (such as error rate and loading time).
    • Gray release: Validate with a small traffic flow first, then roll out fully.

    7. Common Pitfalls and Workarounds

    • Scale drift: Fix the baseline unit first, then generate.
    • Particle explosion: Hard upper limit plus adaptive downgrade.
    • Material overexposure: Control light source intensity and tone mapping curves.
    • Dependency bloat: Constrain to a single file or minimal dependencies.
    • Detail and performance conflict: Prioritize details, with the performance budget coming first.

    8. Conclusion

    Building a rainy night city with intelligent coding tools is essentially engineering creativity: structured description, parameterized constraints, small-step iteration, performance budgeting, and observable deployment. The tool is responsible for quickly turning ideas into runnable code, and the developer is responsible for defining standards and maintaining quality. With the general cloud capabilities of Baidu AI Cloud for hosting and observability, a work can move from “runnable” to “stably playable.”