Building a Three.js Rainy-Night City Scene with an AI Coding Assistant

    A Three.js "convenience store on a rainy night" scene is a compact project that covers modeling, lighting, materials, particle systems, and post-processing. This article walks through the key implementation details—fog, warm/cool lighting contrast, wet-ground reflections, and a GPU-friendly rain particle system—while sharing a practical AI-assisted workflow and a proven performance optimization checklist for real-time 3D scenes.

    Building a Three.js Rainy-Night City Scene with an AI Coding Assistant

    1. Why a “Rainy-Night Convenience Store” Is a Great Practice Project

    In 3D visualization and creative coding, a convenience store on a rainy night is an excellent all-around exercise. It looks like a small scene, but it touches nearly every core concept in the real-time rendering pipeline:

    • Geometry and scene organization: building blocks, streets, streetlights, signage, and their hierarchy management;
    • Lighting systems: ambient light at night, warm point light leaking from the storefront, and the glow of streetlights;
    • Materials and textures: reflections on wet asphalt, the semi-transparency of glass windows, and self-illuminating neon signs;
    • Particle systems: continuously falling raindrops, splashes, mist, and light halos;
    • Post-processing: bloom, tone mapping, vignetting, and other atmosphere-enhancing techniques.

    In other words, completing this project means practicing most of Three.js’s commonly used capabilities in one go. And this kind of project—clear in vision but dense in detail—is exactly where an AI coding assistant delivers the most value.

    2. The Real Experience of AI-Assisted Development: Not One-Shot Generation, but Efficient Collaboration

    One common misconception needs to be cleared up first: using an AI coding assistant for a 3D project rarely gets everything right in a single pass. In this practice, issues such as distorted proportions, performance bottlenecks, and missing details still required multiple rounds of back-and-forth to resolve. But the overall efficiency gain is obvious—steps that used to require digging through documentation and repeated trial and error can now move forward quickly through natural language descriptions.

    A typical workflow looks like this:

    1. Describe the idea: tell the assistant the effect you want in one paragraph, e.g., “a corner convenience store on a rainy night, warm light coming through the windows, puddle reflections on the ground, rain falling continuously”;
    2. Get initial code: the assistant generates the scene skeleton, including the renderer, camera, lights, and basic geometry;
    3. Report problems: point out concrete issues such as “the sign is too big,” “the rain density is too low,” or “the frame rate dropped noticeably”;
    4. Iterate and refine: adjust parameters step by step, swap implementation approaches, until the result is satisfactory.

    Throughout this process, the developer acts more like a “director”: responsible for aesthetic judgment and acceptance criteria, while delegating most of the implementation-level coding to the assistant.

    3. Key Implementation Details of the Scene

    3.1 Basic Scene and Fog

    The first ingredient of a rainy-night atmosphere is “limited visibility.” Three.js fog lets distant objects gradually melt into the night, and combined with a deep blue-black background color, it immediately establishes the sense of a nighttime space:

    1. const scene = new THREE.Scene();
    2. scene.background = new THREE.Color(0x0a0e1a);
    3. scene.fog = new THREE.FogExp2(0x0a0e1a, 0.035);

    Exponential fog looks more natural than linear fog because it mimics the attenuation of real atmospheric scattering.

    3.2 Lighting Design: Warm/Cool Contrast Is the Soul

    The worst thing for a rainy-night scene is a “flat, dead black.” The right approach is to build a warm/cool contrast:

    • Cool ambient light: low-intensity blue-purple ambient or hemisphere light to outline object silhouettes;
    • Warm point light: a warm orange point light inside the storefront to form the visual focal point;
    • Neon self-illumination: signs use emissive materials, and combined with bloom post-processing, produce a halo effect.
    1. const warmLight = new THREE.PointLight(0xffa95e, 2.5, 30);
    2. warmLight.position.set(0, 3, 5);
    3. scene.add(warmLight);

    3.3 Wet-Ground Reflections: Balancing Performance and Effect

    True planar reflections (such as Reflector) are expensive. In practice, a compromise works well: use a standard material with blended roughness to simulate a “half-wet” state, optionally overlaid with a low-opacity mirrored layer; or simply use an environment map with low roughness so the ground merely looks wet. When collaborating with AI, explicitly stating “prioritize frame rate; the reflection effect can be simplified” usually leads to a more sensible solution.

    3.4 Rain Particle System

    For raindrops, use Points or InstancedMesh instead of individual Meshes, and keep the count in the low thousands:

    1. const rainGeo = new THREE.BufferGeometry();
    2. const positions = new Float32Array(count * 3);
    3. // Distribute raindrops randomly; each frame they fall based on velocity
    4. // and reset to the top after hitting the ground

    Driving the falling animation in a vertex shader keeps CPU overhead to a minimum—one of the key points for maintaining frame rate.

    4. Performance Optimization Checklist

    Through repeated iteration, the following measures proved to be the most effective:

    • Merge static geometry: use InstancedMesh or merged BufferGeometry for repeated objects like streetlights and railings to reduce draw calls;
    • Limit the number of lights: keep real-time point lights to 3–4 at most, and fake the rest with emissive materials;
    • Render on demand: lower the frame rate or pause the render loop when there is no interaction;
    • Texture compression and reuse: share a single texture for noise, rain streaks, and similar effects;
    • Trim post-processing: keep bloom and tone mapping, but decide on expensive effects like anti-aliasing based on the target device.

    5. Three Lessons from Working with AI

    1. Report one category of problem at a time. Separating feedback on “proportions, performance, and details” into individual rounds yields more usable fixes than dumping everything at once.
    2. Describe effects in measurable terms. “Increase raindrop density by 30%” or “set the sign height to one-fifth of the storefront width” is far more effective than “tweak it a bit.”
    3. Ask the AI to explain the implementation. Follow up with questions like “why use exponential fog” or “why write the reflection this way”—this both ensures code quality and continuously deepens your own technical understanding.

    6. Conclusion

    From a single sentence—“I want to build a rainy-night convenience store”—to a real, runnable, explorable rainy-night city, an AI coding assistant is already capable of handling most of the engineering work between idea and implementation. It won’t replace a developer’s judgment on aesthetics, structure, or performance, but it turns those judgments into reality at a remarkably low cost. For developers looking to enter the 3D visualization field, now is a great time to get hands-on: pick a scene from your imagination and build it.