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

    This article walks through building a browser-based 3D rainy night city scene using AI coding tools. It covers defining the task as an atmosphere-driven real-time rendering problem, translating mood descriptions into measurable prompt constraints, progressing from blockout to detailed assets, implementing rain, fog, and reflections, setting performance budgets with quality tiers, and running multi-turn collaboration with a clear acceptance checklist. Readers will find prompt structures, scene setup code, and practical tuning criteria they can apply to similar real-time graphics work.

    1. From an Idea to a Runnable Scene: Defining the Problem

    The goal of this practice is not to have a model write an entire city in one shot. It is to turn a visual concept with a strong atmospheric requirement into a 3D scene that runs in the browser and can be iterated on continuously. A rainy night city is difficult in three main areas: spatial proportions are easy to distort; frame rate drops quickly once rain, fog, and reflections are layered together; and details such as signs, standing water, and light falloff usually take several rounds of discussion to converge. In engineering terms, it should be defined as an atmosphere-driven real-time rendering task, not simply a code generation task.

    A practical approach is to break the concept into four layers of verifiable goals:

    • Composition layer: street layout, convenience store placement, viewpoint height, and focal length;
    • Atmosphere layer: rain intensity, fog density, color temperature contrast, and ground reflection strength;
    • Performance layer: target frame rate, draw call ceiling, and texture and geometry budgets;
    • Interaction layer: free roaming, switchable viewpoints, and an adjustable parameter panel.

    2. Prompt Engineering: Turning “Feel” into Parameters

    When you describe an atmosphere in natural language, the model often returns results that look plausible but have unbalanced proportions. An effective approach is to provide constraints first, then details, and finally acceptance criteria. A sample prompt structure:

    1. Role: Senior real-time rendering engineer
    2. Task: Generate a single-file 3D scene that runs in a modern browser
    3. Constraints:
    4. 1) Street width 8 meters, convenience store frontage 6 meters, viewpoint height 1.6 meters;
    5. 2) Use only basic geometry and procedural materials; do not load external assets;
    6. 3) Render rain streaks with instancing; count is configurable, default 6000;
    7. 4) Ground reflections use a screen-space approximation; real-time multi-pass reflections are not allowed;
    8. Acceptance: Interactive within 3 seconds of first load; automatically reduce rain and shadows when frame rate falls below the threshold

    This turns the “rainy night feel” into measurable engineering constraints and reduces back-and-forth rework.

    3. Scene Breakdown: Skeleton First, Skin Later

    The recommended progression is white-box, gray-box, then final look. In the first step, generate only the block masses and camera path, and confirm perspective and proportions. In the second step, add materials, lighting, rain, and fog. In the third step, add details such as signs, ripples in standing water, and shelf silhouettes inside the store. Each step should produce a runnable version, which avoids generating an oversized code block in one pass that is hard to debug.

    Sample scene structure:

    1. const scene = new THREE.Scene();
    2. scene.fog = new THREE.FogExp2(0x0b1020, 0.035);
    3. const camera = new THREE.PerspectiveCamera(55, innerWidth / innerHeight, 0.1, 200);
    4. camera.position.set(0, 1.6, 12);
    5. const renderer = new THREE.WebGLRenderer({ antialias: true });
    6. renderer.setPixelRatio(Math.min(devicePixelRatio, 1.5));
    7. renderer.shadowMap.enabled = true;

    The practical rule for correcting proportions is to fix the viewpoint height and street width first, then derive building heights and sign sizes, and finally use reference objects such as trash bins, steps, and door frames for visual verification.

    4. Three Elements of the Rainy Night Atmosphere: Rain, Fog, and Reflections

    Rain does not need to be a realistic fluid simulation. Instanced line segments or quads work, and recycling them around the camera position creates an “endless curtain of rain.” Fog compresses the contrast of distant objects and gives the lights a sense of depth. Reflections are key to the atmosphere but the most expensive part. A good option is a ground material with low roughness combined with ambient light and a small number of point lights; when necessary, use a screen-space approximation instead of multiple planar reflections.

    1. const rainCount = 6000;
    2. const rainGeo = new THREE.BufferGeometry();
    3. const positions = new Float32Array(rainCount * 6);
    4. // After initializing both endpoints of each rain streak, write them into the attribute
    5. rainGeo.setAttribute('position', new THREE.BufferAttribute(positions, 3));
    6. const rain = new THREE.LineSegments(rainGeo, new THREE.LineBasicMaterial({
    7. color: 0xaaccff, transparent: true, opacity: 0.35
    8. }));

    For lighting, a “cool ambient light plus warm sign light” color temperature contrast works well. Use distance falloff to control the size of light pools and avoid washing out the whole screen.

    5. Performance Budget: Keeping the Atmosphere Sustainable

    The performance bottlenecks in a rainy night scene are usually transparency sorting, shadows, and post-processing. Actionable strategies include limiting the pixel ratio, making rain count and shadows degradable, merging static geometry, using instancing to reduce draw calls, and keeping post-processing to a single lightweight pass. It helps to set a budget table—for example, no more than 120 draw calls, no more than 3 layers of transparent objects per frame, and total texture memory in the tens of megabytes—and expose a “quality tier” option in the parameter panel.

    1. const quality = {
    2. high: { rain: 9000, shadow: 2048, pixelRatio: 1.5 },
    3. medium: { rain: 5000, shadow: 1024, pixelRatio: 1.2 },
    4. low: { rain: 2000, shadow: 0, pixelRatio: 1.0 }
    5. };

    6. Multi-Turn Collaboration and an Acceptance Checklist

    Treat the model as a pair developer, not a one-shot code machine. Solve one variable per round: proportions first, then materials, then rain volume, then interaction. A fixed acceptance checklist can cover: time to first interaction, whether the viewpoint height is correct, whether signs are overexposed, whether low-end devices automatically degrade, and whether the parameter panel takes effect in real time. If something is off, converge with an instruction such as “keep everything else and adjust only this one parameter” instead of rewriting the whole scene.

    7. Conclusion

    The value of this practice is that it validates a path: you do not need to have an idea fully worked out before you start. With AI coding tools and the general compute, storage, and monitoring and alerting capabilities provided by Baidu AI Cloud, developers can quickly turn an atmosphere description into a runnable prototype, then refine it step by step with engineering budgets and acceptance criteria. What ultimately determines the quality of the work is still clear constraints, sensible breakdown, and continuous quantitative tuning.