Building a Rainy Night City Scene with AI Coding Tools: A Three.js Engineering Guide
This article explains how to turn a vague scene description into a structured, performance-controlled Three.js night scene using AI coding tools. It covers translating atmosphere into engineering constraints, fixing scale and composition through parameterization, designing a layered rendering pipeline, optimizing rain and reflections, and running a disciplined iteration loop with acceptance checklists. The focus is on the workflow that determines output quality rather than any specific product.
1. From an Idea to a Runnable Scene: Reframing the Problem
The starting point here is not a review of any particular tool, but an engineering problem that has become common in the age of generative coding: a developer already has a clear scene in mind — “rainy night,” “small town,” “convenience store” — yet turning it into an interactive, runnable 3D piece still requires requirement breakdown, structural organization, parameter tuning, and repeated validation.
So this article sets aside product specifics and frames the topic as: how to use AI coding tools to turn a fuzzy scene description into a well-structured, performance-controlled Three.js night scene. The path applies to any developer working with AI-assisted coding.
1.1 Why a Rainy Night Town Is a Good Exercise
A rainy night scene naturally spans several technical dimensions:
- Complex lighting layers: neon, street lamps, warm indoor light, and cool ambient light all coexist;
- Many transparent and reflective materials: wet pavement, glass, and puddles each need a different material strategy;
- Dense dynamic elements: rain streaks, ripples, flickering signs, pedestrians or vehicles;
- Atmosphere that depends on post-processing: bloom, tone mapping, and depth of field all strongly affect the look.
This makes it less a “pile up models” exercise and more a combined test of the rendering pipeline, resource management, and iteration process.
1.2 The Real Role of AI Coding Tools
To be clear: AI coding tools are good at quickly generating a runnable skeleton, filling in boilerplate, and offering multiple implementation options, but they cannot guarantee a finished result in one pass. Off-scale proportions, performance bottlenecks, and missing details are normal. What actually determines quality is whether the developer can turn feedback into precise, structured instructions and converge over multiple rounds.
2. Requirement Breakdown: Translating Atmosphere into Engineering Constraints
High-quality output starts with translating “I want a rainy night town” into an executable set of constraints.
2.1 Build a Scene Inventory
Before writing code, list three inventories:
- Subject inventory: convenience store, street, buildings, signs, utility poles, vehicles;
- Atmosphere inventory: rain, fog, wet reflections, neon color temperature, distant halos;
- Interaction inventory: camera roaming, view switching, rain intensity control, light toggles.
The point of these lists is to turn abstract feelings into verifiable items, avoiding results that “look right but you can’t say what’s wrong.”
2.2 Define Technical Boundaries
Stating technical boundaries explicitly in the prompt significantly reduces wasted code:
- Limit the rendering framework to Three.js;
- Specify a target frame rate range and device tier;
- Require no external high-precision models, with geometry generated procedurally;
- Require all assets to be reproducible, avoiding uncontrolled external material.
2.3 Replace Casual Descriptions with Structured Prompts
A reusable prompt structure:
Role: Senior Three.js rendering engineerGoal: Build a rainy night city corner with a convenience store as the subjectConstraints:1. Procedural generation, no external model dependencies2. Target 60fps, keep draw calls within a reasonable range3. Use instanced rendering for rain streaks and repeated parts4. Output a complete, directly runnable file structureAcceptance: Provide notes on key parameters and a list of adjustable options
The value of this format is turning “feel” into “metrics,” and “metrics” into “verifiable deliverables.”
3. Scale and Composition: The Highest-Risk Stage for Iteration
The original experience noted that scale took repeated discussion — this is exactly the biggest pitfall in 3D scenes.
3.1 Fix Units and Scale First
Lock the world unit at the very first step, for example 1 unit = 1 meter, and define:
- Convenience store floor height around 3.2–3.6 meters;
- Street width 6–8 meters;
- Sign hanging height above 2.6 meters to avoid clipping;
- Camera at human eye height of 1.6–1.7 meters.
Once scale drifts, all subsequent lighting and rain density will be distorted.
3.2 Composition Serves Atmosphere
The look of a rainy night town comes from “guided sightlines.” You can use:
- A low, near-ground camera angle to emphasize wet reflections;
- The street as a perspective line pushing the eye toward the store’s warm light;
- Blurred rain streaks or railings in the foreground to create layered occlusion.
3.3 Converge on Scale Through Parameterization
Don’t make the model “guess” proportions; write them as a constant configuration:
const SCALE = {unit: 1, // 1 unit = 1 meterfloorHeight: 3.4,streetWidth: 7,signHeight: 2.8,cameraHeight: 1.65};
Every module then references the same configuration, so scale changes from “repeated discussion” to “change one place, take effect everywhere.”
4. Rendering Architecture: Good-Looking and Smooth at the Same Time
4.1 Layer the Rendering Pipeline
Split into four layers, each with a single responsibility and easy to tune:
- Base layer: ground, buildings, street, procedurally generated with low polygon counts;
- Lighting layer: ambient light + a few key point lights + emissive materials;
- Dynamic layer: rain streaks, ripples, sign flickering;
- Post-processing layer: bloom, tone mapping, slight depth of field.
4.2 Three Performance-First Techniques
- Instanced rendering: use instancing for repeated elements such as rain streaks, window panes, and bricks to avoid many separate meshes;
- Light budget control: strictly limit the number of real-time point lights and simulate the rest with emissive materials and textures;
- Half-resolution post-processing: compute effects like bloom on a lower-resolution buffer, then composite.
Sample code:
// Instanced rain streaks significantly reduce draw callsconst rainCount = 6000;const rainGeo = new THREE.BufferGeometry();const positions = new Float32Array(rainCount * 6);rainGeo.setAttribute('position',new THREE.BufferAttribute(positions, 3));const rainMat = new THREE.LineBasicMaterial({color: 0x9fb4c7, transparent: true, opacity: 0.35});const rain = new THREE.LineSegments(rainGeo, rainMat);
4.3 Build Observability
Performance problems can’t be judged by feel. Expose at least three metrics:
- Average frame time and jitter;
- Draw call count and triangle count;
- VRAM usage trend.
Showing these in a debug panel is what lets you tell whether an iteration made things better or worse.
5. Detail Polish: Atmosphere Comes from Perceptible Small Things
The credibility of a rainy night is usually decided by details, not by the precision of the main models.
5.1 Trade-offs for Wet Reflections
True reflections are expensive, so engineering practice uses compromises:
- Use low-roughness ground materials with an environment map;
- Place gradient light-spot decals under key lights to fake reflections;
- Use a few plane meshes with normal perturbation for puddles.
5.2 Layers of Rain, Not Quantity
Simply increasing rain streak count quickly kills performance. Layering works better:
- Foreground: sparse, thick, fast, with a slight tilt;
- Midground: medium density;
- Background: suggested with fog and noise textures, no solid geometry.
5.3 Signs and Color Temperature as Narrative
Warm-cool contrast is the core language of a rainy night: cool blue street, warm yellow interior, highly saturated signs. Put color temperature into the configuration too, so you can grade the whole scene without editing materials one by one.
6. Iteration Methodology: Turning “Repeated Discussion” into a Process
6.1 Change One Variable per Round
Changing scale, lighting, and rain density at the same time makes attribution impossible. The disciplined approach is to move one dimension per round and keep rollback-able configuration snapshots.
6.2 Keep an Acceptance Checklist
At the end of each round, check against the list: is the scale correct, is the frame rate on target, is the subject occluded, does rain clip through geometry, are the store signs readable.
6.3 Make the Tool Output a Maintainable Structure
Ask the AI coding tool for a modular structure — scene assembly, material factory, dynamic systems, and debug panel kept separate. Clear structure is what keeps later iteration costs under control.
7. Common Pitfalls and How to Avoid Them
- Pitfall 1: Expecting a one-pass result. Assume multiple rounds and write that expectation into the process.
- Pitfall 2: Details too early. Get the skeleton and scale working first, then add detail, or rework becomes severe.
- Pitfall 3: Light abuse. Too many real-time lights are the leading cause of night-scene stutter.
- Pitfall 4: Ignoring reproducibility. Fix the random seed so every generation is consistent.
- Pitfall 5: No fallback mode. Provide a low-spec mode: post-processing off, lower rain volume and resolution.
8. Conclusion: Turning Tool Capability into Engineering Capability
Building a rainy night town with AI coding tools doesn’t really validate how much code the tool can write, but whether the developer can translate aesthetic intent into engineering constraints and vague feedback into precise iteration. Once scale is parameterized, rendering is layered, performance is measured, and details are checklist-driven, an idea in your head can reliably become a runnable, playable piece. The same method applies to any 3D interactive project that needs atmospheric expression, and it marks a step toward mature human-AI collaboration in development.
