AI Coding Practice: Building a Rainy Night City with Natural Language

    This article explains how to turn a natural-language prompt into a runnable 3D rainy-night city scene in the browser, and why that task is a strong test of AI coding tools. It covers translating creative descriptions into four types of constraints (scale, composition, performance, interaction), building a procedural scene skeleton with a fixed random seed, implementing rain in three depth layers with GPU-driven motion, controlling light ratios and wet-ground reflections for a convincing night look, adding low-cost interactions through a central config object, and running a performance and acceptance checklist with a defined degradation strategy. Readers will get a reusable prompt template, JavaScript examples, and a structured single-variable iteration loop for converging on a playable baseline.

    1. Why a Rainy Night City Is an Ideal Test for AI Coding

    Describing a rainy night city in natural language sounds poetic, but in engineering terms it is a fairly complete 3D graphics task. It touches scene scale and proportion, procedural geometry, particle systems, lighting and shadows, post-processing, materials and reflections, and browser-side performance budgets. That is exactly what makes it a touchstone for judging the output quality of AI coding tools: almost any tool can generate a static cube in one pass, but once a scene must contain rain, night, streets, and a convenience store all constraining one another, quality differences show up immediately.

    The difficulty is not whether any single feature can be written. It is the coupling between multiple systems. Rain density affects frame rate; a lower frame rate forces you to reduce shadow resolution; once shadows drop, the reflection quality of the wet ground degrades with them. The brightness of the convenience store sign determines whether it forms a readable visual anchor in the rain, yet an overly bright sign flattens the light and dark layers of the whole street. The original text notes that results are not always right on the first try, and that proportion, performance, and detail still require repeated discussion. That is precisely the iterative necessity created by multi-constraint coupling. So when handing this kind of task to an AI coding tool, the right expectation is not “one sentence produces a perfect work,” but “quickly get a runnable, playable baseline, then converge step by step through structured communication.”

    2. Translating an Idea into Machine-Executable Constraints

    The biggest problem with natural language is ambiguity. “Rainy night,” “small city,” and “convenience store” all form images in a person’s mind, but at the code level they must be translated into explicit values and structures. A practical approach is to break one creative sentence into four categories of constraints.

    The first is scale constraints. The most common failure in a 3D scene is not ugliness but distorted proportion: street width mismatched with building height, a convenience store door frame unreasonable relative to a pedestrian, or a camera height that makes the whole scene look like a sandbox model. It is worth fixing the base unit and key dimensions at the prompt stage, for example meters as the unit, an adult height of about 1.7, a floor height of about 3, a street width of 6 to 8, and an initial camera height of around 1.6. Writing these numbers into the requirements noticeably improves the usability of the generated result.

    The second is composition constraints. Be explicit about where the visual center is: the warm-lit window of the corner convenience store, or the reflection of a distant traffic light on the wet ground. Composition constraints determine the priority for every later detail decision.

    The third is performance constraints. A budget must be given up front: target frame rate, acceptable maximum draw calls, particle count limit, shadow map resolution limit, and whether post-processing is allowed. Without a budget, generated code tends to pile on high-precision effects and drop to single-digit frame rates on an ordinary laptop.

    The fourth is interaction constraints. For a work to be playable, you need to define how it is interacted with: drag the mouse to rotate the view, scroll to zoom, press a key to switch day/night or rain intensity, click the sign to trigger a lighting change. The more explicit the interaction constraints, the less likely the generated code is to bind event listeners repeatedly or fail to release resources.

    A reusable requirements template looks roughly like this:

    1. Scene: rainy night street in a small city, visual center is the warm-lit window of a corner convenience store
    2. Units and scale: 1 unit = 1 meter; floor height 3; street width 7; initial camera height 1.6
    3. Performance budget: target 60fps; particles <= 8000; shadows 1024; 1 post-processing pass allowed
    4. Interaction: drag to rotate, scroll to zoom, press R to cycle 3 rain levels, click sign to toggle lights
    5. Delivery: a single HTML file, no external resource dependencies, code organized with section comments

    3. Scene Skeleton: Structure First, Atmosphere Later

    Code that starts with rain and glow is usually hard to maintain. A safer order is to build the skeleton first: ground and road, building blocks, camera and controls, basic lighting. At the skeleton stage you only care about three things: whether the scale is correct, whether the camera can observe freely, and whether objects sit in reasonable positions.

    Procedural generation is preferable to hand-writing each building. Place blocks along both sides of the street with a loop, control height and depth with pseudo-random numbers, but keep a fixed random seed so the scene is identical on every refresh. This makes it easy to compare the effect of different prompts. The value here is high in real iteration: if the layout changes on every generation, you cannot tell whether a change actually took effect.

    1. // Procedural block skeleton: a fixed seed guarantees reproducibility
    2. function makeBlocks(side, count) {
    3. const group = new THREE.Group();
    4. let seed = 20260601;
    5. const rnd = () => (seed = (seed * 9301 + 49297) % 233280) / 233280;
    6. for (let i = 0; i < count; i++) {
    7. const h = 6 + rnd() * 12; // height 6-18 meters
    8. const d = 4 + rnd() * 3; // depth 4-7 meters
    9. const geo = new THREE.BoxGeometry(5, h, d);
    10. const mesh = new THREE.Mesh(geo, new THREE.MeshStandardMaterial({
    11. color: new THREE.Color().setHSL(0.6, 0.05, 0.12 + rnd() * 0.05),
    12. roughness: 0.85
    13. }));
    14. mesh.position.set(side * 6, h / 2, i * 6);
    15. mesh.castShadow = true;
    16. mesh.receiveShadow = true;
    17. group.add(mesh);
    18. }
    19. return group;
    20. }
    21. scene.add(makeBlocks(1, 20), makeBlocks(-1, 20));

    Once the skeleton passes, move on to the atmosphere layer. That way any layer that breaks can be located quickly, instead of guessing the cause inside one large mass of code.

    4. Implementing Rain: Balancing Particles, Depth Layers, and Performance

    Rain is the part most easily written badly in this kind of scene. A common mistake is treating rain as a single particle cloud, which ends up looking either like snow or like screen noise. The look of a real rainy night comes from stacking three layers.

    The far layer uses translucent patches or thin long strands to convey the overall tendency of the rain curtain; density is high but precise motion is unnecessary. The mid layer is the main rain streaks, drawn as line segments or thin elongated quads, falling tilted along the direction of gravity, with the tilt angle related to the camera view. The near layer is a small number of fast streaks sweeping past, creating depth and a sense of speed. Control the count of the three layers separately; when tuning performance, cut the far and near layers first and keep the mid-layer density, which loses the least visually.

    Raindrop motion should avoid iterating over every particle position each frame. The more common engineering approach is to compute displacement in the shader based on time, with the CPU updating only the time uniform. Even with tens of thousands of particles, the frame rate stays stable.

    1. // Sketch: GPU-driven rain fall, CPU updates time only
    2. const rainMat = new THREE.ShaderMaterial({
    3. transparent: true,
    4. depthWrite: false,
    5. uniforms: { uTime: { value: 0 }, uSpeed: { value: 18.0 } },
    6. vertexShader: `
    7. uniform float uTime; uniform float uSpeed;
    8. void main() {
    9. vec3 p = position;
    10. p.y = mod(p.y - uTime * uSpeed, 30.0); // looping fall
    11. p.x += p.y * 0.06; // wind slant
    12. gl_Position = projectionMatrix * modelViewMatrix * vec4(p, 1.0);
    13. }`,
    14. fragmentShader: `
    15. void main() { gl_FragColor = vec4(0.7, 0.8, 1.0, 0.35); }`
    16. });
    17. function tick(t) {
    18. rainMat.uniforms.uTime.value = t * 0.001;
    19. requestAnimationFrame(tick);
    20. }
    21. requestAnimationFrame(tick);

    Two often-overlooked details go with the rain. One is ground splashes: a small number of short-lived rings or point sprites triggered randomly at ground height noticeably improve the credibility of rain landing on the ground. The other is lens raindrops: a sparse layer of water streaks in front of the camera gives the feeling of watching the world through rain. Both are cheap and pay off well, so include them in the requirements from the baseline version.

    5. Night Lighting and Wet-Ground Reflections: Light Ratio Is What Matters

    Whether a night scene looks good depends about eighty percent on light ratio, not on the number of lights. Beginners tend to light the scene brightly, and the sense of night disappears. The right approach is to lower ambient light and let a few high-contrast sources carry the narrative: the cool white ceiling light of the convenience store, the warm yellow sign, the red and green of the traffic light, and the sweep of distant headlights.

    The core of the wet-ground effect is reflection. There are two common engineering routes. The lightweight option pairs a ground material with contrasting roughness, an environment map, and screen-space reflections; it is cheap but the reflected content is limited. The high-fidelity option uses planar reflection rendering, which looks real but requires an extra scene render pass at a clear frame rate cost. State in the requirements whether frame rate or quality takes priority, so the generated code makes a consistent tradeoff rather than mixing both and ending up slow and unattractive.

    Glow around the sign and window openings can be done with emissive materials plus light bloom post-processing. Budget awareness matters here: every added post-processing pass stacks full-screen cost, and usually a single bloom pass is enough for the rainy-night mood, with the rest handled by emissive materials and fog. Fog is the invisible helper of a night scene; it makes distant buildings fade naturally and avoids exposing weak spots from insufficient far-field detail.

    6. Interaction and Playability: Making the Work Come Alive

    A scene you can only look at rarely holds interest for long. Three kinds of interaction give low cost and high return: view control (an orbit controller, with the pitch angle limited to avoid going below the ground), parameter switching (three rain levels, day/night toggle, managed by a single state machine so multiple switches do not fight each other), and local response (clicking the sign toggles the lights, the convenience store door opens automatically on approach and spills warm light).

    In implementation, put all tunable parameters into one config object and let interaction only modify the config, with the render loop reading it. This avoids scattered logic:

    1. const CONFIG = { rainLevel: 1, openSign: true, fogDensity: 0.035 };
    2. window.addEventListener('keydown', (e) => {
    3. if (e.key === 'r' || e.key === 'R') CONFIG.rainLevel = (CONFIG.rainLevel + 1) % 3;
    4. });

    This structure needs almost no changes to existing code when adding features later, and it makes it easy to map vague feedback like “the rain feels too light” quickly into a concrete numeric adjustment.

    7. Performance Budget and Acceptance Checklist

    The biggest risk of generative coding is “it looks like it runs, but it is actually unusable.” Fix a checklist at the acceptance stage and confirm item by item: whether the frame rate hits the target; whether memory and draw calls stay within budget; whether the scene and UI still render correctly after window resizing; whether long runs leak handles or listeners; whether switching rain level or day/night leaves stale state behind; and whether mobile or low-end devices can run in a degraded mode.

    Design the degradation strategy in advance, for example automatically reducing particle count and disabling post-processing when the frame rate stays below a threshold, and exposing a “performance mode” toggle in the UI. Only when degradation is written into the requirements will the generated code include it.

    8. Iteration Method: Turning “Repeated Discussion” into a Controlled Process

    The repeated discussion mentioned in the original text can be engineered into a fixed loop: get the baseline running first, then make single-point changes, one variable at a time, comparing immediately after each change. Give quantifiable feedback, using “reduce sign brightness by about thirty percent” or “halve the rain streaks but keep the near layer” instead of “it feels weird.” Also keep reproducible random seeds and config snapshots so you can roll back.

    When such works need engineering support, front-end static assets can be distributed through object storage, build artifacts deployed through a container platform, and runtime logs and front-end exceptions routed into a logging service, with monitoring and alerting to track real experience metrics. These general cloud capabilities are standard offerings from providers such as Baidu AI Cloud and can be combined as needed without binding to a specific implementation.

    9. Conclusion

    Building a rainy night city with natural language is valuable not for a one-shot generation but for turning an idea into constraints and constraints into verifiable iteration. Once scale, budget, and interaction are written clearly, AI coding tools can reliably output a runnable, playable baseline; the remaining proportion, performance, and detail are approached through structured single-point iteration. With this method, the distance from an idea in your head to that rainy little city in the browser shrinks to one conversation and a few rounds of polishing.