Using Large Language Models to Build a Rainy-Night Three.js Scene
This practical guide explores how large language models can help turn a visual concept into an interactive Three.js prototype. It covers scene decomposition, iterative prompt-driven development, particle-based rain, camera composition, lighting, performance optimization, wet-surface reflections, and the engineering judgment required to validate AI-generated code.
From Concept to Code: Building a 3D Scene with Large Language Models
In software development, we often come up with atmospheric scene concepts such as “a convenience store on a rainy night.” Traditionally, turning that idea into a working prototype involves building the scene, writing shaders, tuning physically based materials, and debugging lighting effects. The process can take hours or even days.
With the growing capabilities of large language models (LLMs), developers can use multi-turn conversations to transform a visual concept into runnable, interactive code much more quickly.
1. Technology Selection and Scene Decomposition
The main goal of this experiment was to evaluate the feasibility of conversational programming for graphics development. Three.js was selected as the rendering foundation because it provides a mature scene graph, material system, and post-processing pipeline, making it suitable for rapidly building lightweight 3D applications.
Before starting a conversation with an LLM, the abstract idea of a “rainy-night convenience store” needs to be broken down into concrete technical requirements:
- Environment: A skybox or background color, ground materials, and fog to simulate reduced visibility during rain.
- Main structure: The exterior geometry of the convenience store, constructed from box-shaped components, along with doors, windows, and signage.
- Lighting system: Warm interior lighting to create a welcoming atmosphere, cool exterior lighting to represent the rainy night, and additional sources such as streetlights or headlights.
- Dynamic effects: A particle system for falling rain, wet-surface reflections, and subtle light flickering or pulsing.
- Interaction and camera control: Basic orbiting around the scene or first-person movement.
This requirements list can then be provided to an LLM with instructions to generate a basic Three.js code structure.
2. A Collaborative Development Workflow with an LLM
Some developers assume that AI-assisted programming means generating an entire application with a single prompt. In more complex graphics applications, however, step-by-step communication and modular generation are much more reliable.
Step 1: Generate the Basic Scene Structure
The first prompt can request an HTML file containing a scene, camera, renderer, and orbit controls. The model will typically produce standard initialization code.
At this stage, it is important to check whether the coordinate system and renderer configuration are appropriate for the current Three.js version. For example, verify whether the renderer uses the correct outputColorSpace configuration.
Step 2: Iterate on the Prototype and Refine the Problem
Once the basic scene is running, dynamic elements can be added. Rain is a good example.
If the model is simply asked to “add rain,” it may generate a performance-heavy solution based on many mesh objects, such as cylinders representing individual drops. An experienced developer should instead guide it toward a particle system based on BufferGeometry.
A more precise instruction might be:
Use a
Pointsmaterial. Generate random vertex positions in a loop, assign each particle a falling speed, and reset its position when it reaches the end of its lifecycle.
This approach has considerably lower overhead than using individual geometric rain-drop objects.
Step 3: Tune the Visual Details
The longest part of the experiment involved tuning three areas: proportions, performance, and visual detail. These are also areas where AI-generated code can be logically correct while still producing an unsatisfactory visual result.
3. Key Debugging Areas: Proportions, Performance, and Detail
After generating the first version, the convenience store appeared disproportionately large compared with the surrounding street. It lacked the perspective of a small location on a street corner.
This was not a calculation error. Rather, the generated scene lacked practical knowledge of photographic composition. Adding a more specific instruction helped:
Set the building height to approximately one-quarter of the camera height, move the camera farther away, and simulate a 35mm focal length.
The resulting perspective became more balanced.
Performance optimization was another major challenge in AI-assisted development. The model tended to combine high-quality materials with a large number of light sources. Several adjustments were used to reduce the workload:
- Lighting strategy: Replace real-time shadows with baked shadow maps or approximate the effect with volumetric lighting, reducing the frequency of shadow-map updates.
- Particle count: Reduce the number of rain particles from 15,000 to 4,000, then use transparent texture overlays to preserve the impression of rainfall density.
- Inline external resources: Ask the model to inline texture images as Base64 data or generate gradient textures dynamically with Canvas, avoiding additional network requests.
For visual detail, the model performed particularly well with wet-surface reflections. A reflection plane using Reflector, combined with a low reflection strength, successfully simulated the wet appearance of the road.
Later, adjusting the normal-map intensity helped resolve distortion caused by the road surface appearing too smooth.
4. Engineering Considerations and Conclusion
Although this experiment was partly exploratory, it demonstrates the practical value of LLMs in visualization development. Generated code does not always work on the first attempt, but it can significantly reduce the time between an abstract idea and a playable prototype.
For developers, this workflow creates a new requirement: the ability to ask precise questions may be as important as coding ability. Instead of simply asking for “rain,” it is more effective to describe the lifecycle of a particle system. Similarly, understanding concepts such as tone mapping makes it easier to guide the model toward a more cinematic visual result.
The scene was eventually run successfully in a local environment. With appropriate guidance, decomposition, and verification, an LLM can serve as a useful pair-programming partner for creative coding. This workflow is valuable both for individual developers exploring ideas and for small teams validating interaction concepts quickly.
As models improve their understanding of 3D space, developers may be able to adjust dynamic events through natural-language instructions, such as changing a traffic light to green or increasing the intensity of the rain. This experiment offers an early view of how intelligent development workflows may support interactive 3D creation.
