Build a Three.js Rainy Night City with AI Coding Tools

    This article shows how to build a rainy night city scene in Three.js with the help of AI-assisted coding. It covers a layered render pipeline, rain particle shaders, wet-ground reflections, night lighting and bloom, and procedural town generation. It also explains how to tune proportions, performance, and detail through iteration. Along the way, it explains what AI coding tools speed up (prototyping, shader starting points, debugging) and where human judgment still takes over. The goal is a convincing scene that also runs smoothly, so developers can spend more time on aesthetics and experience.

    Introduction: Why a “Rainy Night Town” Is a Hard Problem in Real-Time Graphics

    In real-time 3D, a rainy night scene is a comprehensive test of the rendering pipeline. It demands particle systems, reflections and refractions, lighting models, post-processing, and performance management all at once. Get any one of them wrong, and the image drops from “atmospheric” to “cheap-looking.” That is exactly why rebuilding an image like a rainy-night convenience store or a rainy-night street corner as an interactive Web scene has become a classic way to test whether a development workflow is mature.

    In the past, going from an idea to a runnable demo meant long cycles of hand-writing and debugging. Now that AI-assisted coding tools have matured, developers can use them to scaffold a scene, generate shader code, and suggest parameter tweaks, compressing iterations that used to take days into minutes. But keep this in mind: they are not magic that works perfectly on the first try. Whether proportions are right, performance is up to par, and details hold up to scrutiny still takes repeated back-and-forth between you and the tool. From a technical perspective, this article explains how to build such a rainy night town, and what coding tools can and cannot do along the way.

    1. Scene Architecture: Plan the Render Pipeline First

    For a convincing rainy night scene, plan a layered structure before stacking on effects:

    • Geometry layer: ground, buildings, streetlights, signs, and the convenience store itself;
    • Lighting layer: ambient light, a directional light (for a cold moon or city skylight), and point lights (for signs and streetlights);
    • Effects layer: rain particles, ground ripples, fog, and water-vapor glow;
    • Post-processing layer: bloom, tone mapping, vignette, and subtle noise.

    In Three.js, these four layers come together through the cooperation of scene, renderer, and EffectComposer. The basic skeleton looks roughly like this:

    1. const scene = new THREE.Scene();
    2. scene.fog = new THREE.FogExp2(0x0a0f1a, 0.03); // Fog hides the distance and adds depth to the rainy night
    3. const renderer = new THREE.WebGLRenderer({ antialias: true });
    4. renderer.toneMapping = THREE.ACESFilmicToneMapping;
    5. renderer.toneMappingExposure = 1.1;
    6. const camera = new THREE.PerspectiveCamera(50, innerWidth / innerHeight, 0.1, 200);
    7. // Post-processing: a bloom pass so signs and lights glow naturally
    8. const composer = new EffectComposer(renderer);
    9. composer.addPass(new RenderPass(scene, camera));
    10. composer.addPass(new UnrealBloomPass(new THREE.Vector2(innerWidth, innerHeight), 0.8, 0.6, 0.85));

    Building the skeleton before adding effects is key to controlling complexity and communicating with AI coding tools later on. Only when you can clearly describe what is missing right now and what effect you want will the code the tools produce match your expectations.

    2. Rain Effects: Particle Systems and Shaders Working Together

    Rain is essentially a large number of fast-moving particles. There are two common approaches:

    1. Geometry particles (Points / LineSegments): use many short segments to represent rain streaks, and control falling and drift in a vertex shader. This suits mid-to-low-performance scenarios. The logic is clear and the density is easy to adjust.
    2. Full-screen / volumetric rain: generate a curtain of rain in screen space or near the camera, with UV scrolling. It is performance-friendly and looks soft.

    A reusable vertex shader idea is to make each drop fall along the direction of gravity and reset its height in a loop:

    1. // Vertex shader snippet: use time to drive the falling motion
    2. uniform float uTime;
    3. uniform float uFallSpeed;
    4. attribute float aSpeed;
    5. void main() {
    6. vec3 pos = position;
    7. pos.y = mod(pos.y - uTime * aSpeed * uFallSpeed, uHeight);
    8. gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);
    9. }

    The key here is “controllable”: rain speed, density, tilt angle (for wind), and falling range should all be parameters. Rain speed, density, and drift angle should all be exposed as parameters. What gives a rainy night its character is the direction and depth of the rain streaks: sharp and clear up close, fading into the fog in the distance. This is also the detail you most need to communicate when going back and forth with AI coding tools. Simply saying “rain” is too vague; describing it as “slanted, dense up close and sparse in the distance, with a sense of wind” is what gets you the look you want.

    3. Wet Ground and Reflections: The Soul of the Rainy Night Mood

    If rain sets the pace, then reflections on wet ground are the soul of the rainy night mood. Puddles on asphalt mirror neon signs, streetlights, and distant halos. This high-contrast, mirror-like reflection is the core feature that sets a “rainy night” apart from an “ordinary night scene.”

    Approaches range from simple to complex:

    • Fake reflections: mirror-copy light sources or the scene beneath the ground and add a layer of semi-transparent blur. They are inexpensive and well suited to quick validation.
    • Reflective render target: treat the ground as a mirror, render reflections in real time, and add normal perturbation to simulate water ripples.
    • PBR material with low roughness: use MeshStandardMaterial with lower roughness and moderately higher metalness, combined with an environment map, to approximate a wet, slippery surface.

    Combine this with a procedurally generated normal map (small bumps driven by a noise texture), and the reflections will look “broken rather than flat,” much more like a rain-soaked road with puddles:

    1. const wetGroundMat = new THREE.MeshStandardMaterial({
    2. color: 0x11151c,
    3. roughness: 0.15,
    4. metalness: 0.6,
    5. normalMap: noiseNormalTex,
    6. normalScale: new THREE.Vector2(0.3, 0.3),
    7. });

    4. Night Lighting and Bloom: Controlling Contrast and Rhythm

    A night scene should not just be turned down darker. It needs contrast and rhythm. A recommended color scheme is “cool base + warm point lights”: against an overall cool blue night, use signs, streetlights, and warm light spilling from inside the store as focal points. This cool-warm contrast naturally draws the eye toward the subject.

    For lighting:

    • use a low-intensity ambient or hemisphere light to provide the base tone and avoid dead-black areas;
    • use point or spot lights to highlight the main signs and streetlights;
    • use bloom to spread highlights into a soft glow, creating the “breathing” quality of lights on a rainy night and the effect of light scattering through moisture in the air.

    Note that bloom parameters (threshold, strength, radius) are extremely sensitive. A slight misstep can wash out the entire screen. This is another good place to externalize parameters: let AI coding tools suggest values based on the look you describe, then fine-tune each one yourself.

    5. Procedural Generation: Bringing the Town to Life

    Hand-placing every building in a “town” is very costly. Procedural generation can greatly improve efficiency:

    • use noise and random numbers to control building height, width, and spacing, producing a natural skyline;
    • use regular layouts (for example, placing streetlights and signs symmetrically along both sides of a street) to keep the rhythm consistent;
    • combine simple geometric primitives into landmark elements such as the convenience store, awnings, and vending machines.

    Procedural generation is reproducible and easy to tune through parameters. When you want “a busier street” or “more uneven buildings,” you only need to adjust the parameters of the generation rules. This is exactly where AI coding tools can assist: they can quickly produce a prototype of parameterized generation logic.

    6. How AI Coding Tools Change the Workflow

    In this practice, AI-assisted coding mainly adds value in three areas:

    1. Faster prototyping: turn an abstract idea in your head (“rainy night, neon signs, reflective ground”) into a runnable code skeleton, skipping a lot of boilerplate.
    2. A lower technical barrier: for error-prone parts like shaders and post-processing passes, they provide a usable starting point, letting developers focus on tuning and experience.
    3. Help with debugging and refactoring: when performance drops or the code becomes messy, they can offer structural suggestions.

    But be clear about their limits: they cannot make aesthetic judgments for you, and they cannot guarantee a perfect result in one shot. Proportions, performance, and detail are all highly context-dependent. You need to hold several rounds of conversation with the tools while describing clear goals. Treat them as an “efficient coding partner,” not a “fully automatic art director and architect.” That is how you get the most out of them.

    7. Iteration and Tuning: A Three-Fold Test of Proportion, Performance, and Detail

    What really determines the quality of the final result is the process of repeated polishing:

    • Proportion: the scale relationships between buildings and streets, and between streetlights and pedestrians, must be realistic and believable. First drafts from tools often get proportions wrong, so you need to calibrate camera angles and object sizes by hand.
    • Performance: rain particle count, reflection resolution, and the bloom pass are all performance hotspots. Optimizations include limiting particle count, lowering the reflection RenderTarget resolution, degrading quality by viewport or device tier, and using InstancedMesh to merge repeated geometry.
    • Detail: flickering signs, small ripples where raindrops hit the ground, and water trails flowing down glass. These micro-interactions determine how convincing the work feels.

    A practical principle is this: first ensure the main visual and a smooth frame rate, then add details step by step. Use frame-rate monitoring tools to pinpoint bottlenecks, and tiered quality settings to make trade-offs across devices. That way, the result can look good and run well.

    Conclusion

    Building a rainy night town with Three.js is essentially a comprehensive drill across every stage of the rendering pipeline: rain effects, reflections, lighting, and procedural generation each test your understanding of graphics technology. The value of AI coding tools lies in drastically shortening the path from idea to runnable demo, so developers can focus more on aesthetics and experience.

    They are not a silver bullet: proportion, performance, and detail still need human judgment and polishing. This is exactly why the collaboration model of “humans set direction and aesthetics, tools provide speed and execution” is becoming a practical path for turning ideas into runnable, playable works quickly.