Building a Rainy Night 3D Scene with an AI Coding Assistant: A Practical Guide

    Learn how to turn a vivid scene description into a runnable 3D rainy night street scene using an AI coding assistant. This guide walks through the full workflow — breaking a creative idea into engineering tasks, designing effective prompts, iterating on proportions, lighting, and rain effects, keeping performance within budget, and delivering a browser-based experience that opens and runs from a single webpage. Aimed at developers validating visual ideas, front-end engineers without WebGL experience, and creators who want to present atmosphere through code.

    1. Introduction: When the Image in Your Mind Can Be Written as a Sentence

    Late at night, the sign on a corner convenience store is still lit. Cold white light spills out through the glass doors and lands on the rain-soaked asphalt. In the distance, an orange street lamp blooms into a halo through the curtain of rain; fine streaks of rain slant across the light, and every so often a car’s headlights sweep across the far end of the street, lighting up a cloud of splashing mist. This is a scene many people carry in memory. It is vivid and specific, yet hard to build quickly with traditional methods: modeling, texturing, writing shaders, tuning lighting, and wiring up interaction — each of these can mean days or even weeks of work.

    In recent years, AI coding assistants that can understand natural-language requirements and directly generate and modify code have begun to change this workflow. A creator only needs to describe the picture clearly to get a runnable first version in a relatively short time, then refine proportions, optimize performance, and add details through rounds of dialogue — much like repeatedly discussing a design with a product manager and an artist.

    Using the goal of “generating a rainy night street-corner 3D scene” as an example, this article walks through the entire pipeline:

    • How to break a creative idea down into engineering tasks;
    • How to design prompts;
    • How to iterate and debug;
    • How to hold the performance baseline;
    • How to deliver a work that “opens in a browser and is ready to play.”

    The intended readers fall into three groups: developers who want to quickly validate a visual idea, front-end engineers who lack WebGL experience, and creators who want to express atmosphere through code.

    2. Technical Foundation: What a Browser-Based 3D Scene Is Actually Doing

    A browser-based 3D scene is built on WebGL, the graphics interface provided natively by the browser. The GPU uses it to perform vertex transformation, rasterization, and per-pixel shading, with no plug-in installation required.

    On top of this, the common practice in the industry is to organize code through a rendering framework or engine, which typically consists of a few core parts:

    • Render loop: requestAnimationFrame runs “update logic, then draw the frame” on every frame, and the time delta between frames keeps motion speed independent of frame rate.
    • Scene graph: objects and their parent-child relationships are organized in a tree. The camera’s view is governed by frustum culling, so objects outside the frame can be skipped entirely during drawing.
    • Materials and lighting: a physically based rendering model describes how a surface reflects light, and ambient, directional, point, and spot lights are used to approximate real illumination.
    • Render pipeline: a scene is often not drawn only once. Shadows, water reflections, bloom, and similar effects each require additional render passes, which are then composited layer by layer.
    • Geometry data and buffers: an object’s vertices, normals, and UV coordinates are stored in GPU buffers, and every draw call introduces CPU-to-GPU communication overhead.

    Understanding these layers also explains why an AI-generated first version often “looks about right but feels off”: a rendering framework’s default color space, tone mapping, and light intensity all lean “neutral,” missing the night mood and atmosphere the creator wants. These problems are not because the model “can’t code” — they arise because the default parameters are not tuned for the specific image.

    3. Translating Creativity into Engineering Language

    3.1 Why the First Version Rarely Lands on Target

    Natural language is inherently ambiguous, while 3D rendering is highly sensitive to parameters. The same sentence — “a convenience store on a rainy night” — will evoke completely different rain intensity, color temperature, and composition in different people. And when “make the rain heavier” reaches the code, it could mean doubling the particle count, or it could mean longer, faster-falling streaks — which produce very different results in both performance and appearance.

    So “it does not always land in one shot” is not a defect of the tool; it is an inherent property of creative projects. What truly separates efficient workflows from slow ones is whether the creator can consistently translate vague adjectives into quantifiable, verifiable engineering constraints.

    3.2 Breaking Down the Scene: An Actionable Task List

    Before opening an AI coding assistant, break the picture into six layers:

    1. Spatial structure: street orientation, building scale, and camera height, which determine the compositional skeleton of the frame;
    2. Light distribution: which objects emit light themselves, and which lights fall on the ground and on pedestrians;
    3. Atmospheric particles: rain streaks, rain mist, and splashes, which give the scene its sense of motion;
    4. Material appearance: whether the asphalt is slick, whether the glass is transparent, whether the metal edges of the sign are worn;
    5. Camera and interaction: whether the player free-roams, advances along the street, or stays fixed at one vantage point;
    6. Performance constraints: target frame rate, resolution range, and device type.

    The value of this breakdown is that it turns the subjective goal of “looking good” into a set of engineering tasks that can be checked and corrected one by one.

    3.3 Replacing Adjectives with Parameters

    The more concrete the vague words, the fewer iterations you need:

    Vague description Engineering specification
    Heavy rain About 20,000 rain-streak particles, 0.3–0.6 m long, falling at 12–18 m/s, tilted slightly at around 8° overall
    A very bright sign Self-emission intensity 2.0, bloom threshold 0.8, halo intensity 0.9
    A wet road surface Roughness 0.08–0.2, overlaid with noise to form puddles; low areas get an extra reflection pass from a reflection camera for the mirrored image
    A cold night Ambient light leaning blue (color temperature around 8000K), convenience store lights warm white (around 4000K), roughly a 1:2 color-temperature contrast

    Note that the “falling speed of 12–18 m/s” is a deliberately slowed artistic choice — real rain typically falls at a few meters per second up to around nine. Visual work need not be bound by physical accuracy; what matters is whether it “looks like rain” on screen.

    4. Prompt Design: Getting the AI to Think from an Engineering Perspective

    4.1 The Five-Element Structure

    A high-quality initial prompt usually contains five elements:

    • Goal: what you are building and how it is interacted with;
    • Scene: scale, layout, and composition;
    • Lighting and color: light types, colors, and warm/cool contrast;
    • Effects: rain, fog, reflections, bloom, and so on;
    • Constraints and acceptance criteria: performance targets, tech stack, delivery format, and how success is verified.

    4.2 Example of an Initial Prompt

    Please implement a browser-runnable rainy night street scene using HTML + JavaScript:

    1. Scene: a street about 60 m long, lined on both sides with low-rise shops, with a convenience store at the corner — storefront 8 m wide, 10 m deep, 3.5 m tall. The camera faces the convenience store as the initial view, at a height of 1.7 m, close to a real human eye point;
    2. Lighting: a deep-blue night sky, warm white light from the convenience store’s glass windows, an orange street lamp at the far end of the street, with all light sources forming reflections on the wet ground;
    3. Effects: fine rain-streak particles, low ground mist, and bloom on the sign and street lamp;
    4. Interaction: drag with the mouse to rotate the view, use the scroll wheel to move forward and back;
    5. Constraints: desktop target frame rate of 60 fps, a fixed 16:9 aspect ratio, all assets generated procedurally in code with no external images referenced;
    6. Acceptance: clean code structure, key parameters defined in one place, with run instructions included.

    The key to this prompt lies in two points: using scale numbers to anchor proportions, and using acceptance criteria to anchor delivery quality.

    4.3 Staged Generation and Context Management

    Asking the model to generate everything at once tends to produce bloated, interfering code. A more reliable approach is to generate in stages:

    1. Skeleton: scene, camera, basic lighting, and render loop;
    2. Main body: the structure of the street and convenience store;
    3. Atmosphere: rain, fog, bloom, and ground reflections;
    4. Interaction and performance: camera controls, detail animation, and performance optimization.

    Context accumulated over a long conversation keeps growing, and the tool may overlook earlier constraints or forget a bug that was already fixed. After each milestone, write the key parameters, conventions, and known issues into a short “project brief,” and at the start of a new session have the tool read it before continuing. This is effectively giving the AI a continuously updated project document.

    5. Iteration in Practice: Proportions, Performance, and Detail

    5.1 Proportions: Locking Scale with Numbers and Reference Objects

    Proportion imbalance is the most common source of the “off” feeling in a first version, usually showing up as streets that are too wide, buildings that are too short, or signs that are too large. There are three effective ways to correct it:

    • Use real dimensions as a baseline: a street 8–10 m wide, a convenience store door about 2.1 m tall, steps about 0.15 m per riser;
    • Use the camera to verify: set the field of view between 45° and 60°, slightly above adult eye level, so the sign and the ground reflections stay clearly visible. Also keep the near clipping plane from being too large, or objects will clip through the camera when you get close;
    • Place a “scale reference”: temporarily drop a 1.8 m capsule as a stand-in person, eyeball the building and street proportions against it, then remove it once confirmed.

    If the AI-generated scene always seems “a bit off” in some dimension, give it the comparison numbers directly: “The current street width looks about 20 m; please change it to 8 m and scale the sidewalk width down accordingly.”

    5.2 Lighting and Materials: The Core of the Rainy Night Mood

    The texture of a rainy night image depends mainly on three things:

    • Warm/cool contrast: keep the ambient light dim and blue, and let the convenience store and street lamp act as warm light sources that create focal points;
    • Wet reflections: rough asphalt approaches a mirror when wet, and reflection strength rises as roughness drops. A high-quality approach is to render the main light sources into a texture with a reflection camera and overlay it on the ground material, rather than simply duplicating an inverted copy of the buildings;
    • Bloom and tone mapping: bloom affects only the areas brighter than a threshold, such as signs and lamp shades; tone mapping compresses the high-dynamic-range render result into the range the screen can display. Together they determine how the light “bleeds.”

    This part is best handled by letting the AI produce runnable code directly, then fine-tuning the values live in the browser.

    5.3 Rain Effects and Dynamic Detail

    Rain is usually made up of three parts:

    • Rain streaks: use GPU instancing or a custom particle shader to render tens of thousands of short lines, which saves a large number of draw calls compared with creating a mesh per drop;
    • Rain mist: semi-transparent particles or a screen-space fog effect, more visible near light sources;
    • Splashes: short-lived small rings generated at random ground positions to enrich close-up detail.

    The rain region needs to follow the camera; otherwise the player will “walk out of the rain” after moving some distance.

    1. // Illustrative pseudocode: batch-render rain streaks with InstancedMesh instead of a mesh per drop
    2. const RAIN_COUNT = 20000
    3. const rainMesh = new InstancedMesh(dropGeometry, rainMaterial, RAIN_COUNT)
    4. rainMesh.frustumCulled = false // the particle cluster follows the camera; skip frustum culling to avoid flicker
    5. const drops = Array.from({ length: RAIN_COUNT }, () => ({
    6. x: (Math.random() - 0.5) * 40, // covers roughly a 40 m square around the camera
    7. y: Math.random() * 20, // initial height 0~20 m
    8. z: (Math.random() - 0.5) * 40,
    9. speed: 12 + Math.random() * 6, // fall speed 12~18 m/s
    10. length: 0.3 + Math.random() * 0.3
    11. }))
    12. function updateRain(dt, cameraPos) {
    13. rainMesh.position.set(cameraPos.x, 0, cameraPos.z) // rain region follows the camera
    14. drops.forEach((drop, i) => {
    15. drop.y -= drop.speed * dt
    16. if (drop.y < 0) drop.y += 20 // recycle to high altitude after hitting the bottom
    17. dummy.position.set(drop.x, drop.y, drop.z)
    18. dummy.scale.set(1, drop.length, 1)
    19. dummy.rotation.z = 0.14 // ~8° tilt to simulate wind-driven slanted rain
    20. dummy.updateMatrix()
    21. rainMesh.setMatrixAt(i, dummy.matrix)
    22. })
    23. rainMesh.instanceMatrix.needsUpdate = true // upload transform data each frame
    24. }

    Because each instance carries its own scale and rotation, the final visual result is largely independent of which rendering framework you use.

    5.4 Post-Processing: The “Last Mile” of Atmosphere

    The same scene and lighting can look completely different depending on the order and parameters of the post-processing chain. A typical chain looks like this:

    Scene render → Bloom → Tone mapping and color-space conversion → Vignette and grain

    A few easily overlooked details:

    • Bloom should come before tone mapping, acting on genuine high-dynamic-range data so the highlights look natural;
    • When the image looks washed-out gray, check the tone mapping method first, along with whether the render target is using the correct color space;
    • Don’t push all parameters to their maximum at once — stacking too much rain, fog, bloom, and vignette will gray out the image and lose the clarity a night scene should have.

    5.5 Interaction: From “Viewable” to “Playable”

    Staring at a static image gets tiring quickly, and interaction is what makes a work “playable”:

    • Camera controls: free roaming is good for showcasing, but height should be limited and wall clipping prevented;
    • Dynamic elements: a swaying awning, flickering fluorescent tubes, a wind-blown sign, and headlights passing occasionally all add significant liveliness;
    • Decoupling animation from frame rate: drive all animation by time delta, so switching to the background and back won’t cause a sudden “jump”;
    • Detail sound: rain audio synthesized in code (approximated with filtered white noise) can further enhance immersion, but it should default to muted and be turned on manually by the user.

    6. Performance: Keeping “Good Looks” Within Budget

    Rainy night scenes are especially demanding on performance, for three reasons: a large number of transparent particles bring repeated fill and blending costs; the wet-ground reflection effectively renders the scene a second time; and post-processing such as bloom needs extra full-screen texture reads and writes. Drop an AI’s first-version parameters straight onto a mid-range laptop, and the frame rate will often come in well below expectations.

    6.1 Common Optimization Techniques

    • Cap the pixel ratio: on high-resolution screens, capping the pixel ratio between 1.5 and 2 is often more effective than reducing model detail;
    • Merge draw calls: render static buildings with InstancedMesh; merge many BoxGeometry objects into a single BufferGeometry;
    • Reuse textures: keep all procedural textures at 512 or 1024 pixels and reuse them through object pools, avoiding frequent creation and destruction;
    • Adaptive quality: monitor the frame rate and automatically reduce particle count, reflection resolution, or disable post-processing when it drops below a threshold;
    • Pause background rendering: pause the render loop when the page is not visible.

    6.2 Render Loop Skeleton

    1. // Illustrative pseudocode: delta-time driven + adaptive quality scaling + frame-rate self-check
    2. const state = { quality: 1.0, frameCount: 0, elapsed: 0 }
    3. let lastTime = performance.now()
    4. function animate(now) {
    5. requestAnimationFrame(animate)
    6. const dt = Math.min((now - lastTime) / 1000, 0.05) // clamp per-frame step to prevent jumps
    7. lastTime = now
    8. updateControls(dt)
    9. updateRain(dt, camera.position)
    10. updateRipples(dt)
    11. composer.render()
    12. // evaluate frame rate every 2 seconds and adjust the quality tier automatically
    13. state.frameCount++; state.elapsed += dt
    14. if (state.elapsed >= 2) {
    15. const fps = state.frameCount / state.elapsed
    16. if (fps < 40 && state.quality > 0.4) state.quality = Math.max(0.4, state.quality - 0.2)
    17. if (fps > 57 && state.quality < 1.0) state.quality = Math.min(1.0, state.quality + 0.1)
    18. applyQuality(state.quality) // adjust rain count, reflection resolution, and post-processing toggles accordingly
    19. console.log('fps:', fps.toFixed(1), 'quality:', state.quality.toFixed(1))
    20. state.frameCount = 0; state.elapsed = 0
    21. }
    22. }

    You can also collect metrics such as frame time, render time, and draw-call count, aggregate and analyze them through a cloud platform’s log service, and use monitoring and alerting to catch anomalies.

    7. Troubleshooting Checklist

    Symptom Possible cause Fix
    Overall gray and washed out, lacking night mood Improper tone mapping or color-space configuration Use tone mapping that supports high dynamic range and adjust exposure
    Jagged blocks at light edges Insufficient shadow map resolution Increase the shadow map size and narrow the light’s shadow range
    Distant rain streaks flicker and vanish while moving Frustum culling applied to the particle cluster Disable culling on the particle cluster or enlarge its bounding range
    Ground reflection points the opposite way from the real object Incorrect mirror transform for the reflection camera Fix the reflection matrix, or verify it with a reflection matrix as an aid
    Mobile device overheats and frame rate plummets Pixel ratio too high, particles and reflection too costly Scale quality down by device performance tier
    Existing features break after an AI edit Forgotten context or a regression introduced by the edit Update the project brief and roll back to verify before committing

    8. Delivery and Launch: From Demo to an Accessible Page

    A deliverable 3D web work should include the following:

    • A clear project structure: separate entry page, scene code, parameter configuration, and assets;
    • Loading feedback: even though a procedural scene needs no large model downloads, first-frame shader compilation still takes time, so show a loading progress indicator;
    • A fallback strategy: when a WebGL context cannot be created, show a static cover and a short message rather than a blank screen;
    • Shareability: control the initial view, time, and rain intensity through URL parameters, making it easy to show others different views;
    • Hosting and distribution: static files can be hosted on a cloud platform’s storage service, accelerated with a content delivery network, and the pay-by-traffic model helps control costs for small projects.

    If you want to call large-model capabilities in the page (for example, to dynamically generate scene descriptions from user input), you can use a cloud platform’s API gateway for unified authentication and rate limiting. Keys should be kept on the server or proxied through serverless functions, and must never be written into front-end code.

    9. Key Takeaways

    Looking back over the whole process, creating a rainy night street scene with an AI coding assistant comes down to three things:

    1. Think clearly before you speak: the more precise the scale numbers, light distribution, and effects list, the closer the first version lands to expectations;
    2. Move in small, fast steps: solve one class of problem per round, and keep the project brief up to date;
    3. Verify with your eyes: the AI can guarantee the code logic is correct, but whether the image “looks like a rainy night” still takes the creator’s own judgment and adjustment.

    The greatest value of an AI coding assistant is not that it produces a perfect work for you, but that it shrinks the distance from “idea to runnable version” to a single conversation. Proportions, performance, and detail are still three small hills the developer has to climb step by step. But when the rain streaks first fall in the browser, and the convenience store light first reflects on the wet ground, you’ll find that the little city in your mind has truly come into being.