Building a Web3D Rainy Night Scene: A Practice in LLM-Assisted Development
This article explores how to leverage Large Language Models (LLMs) to efficiently build a Web3D "rainy night city" scene from scratch. It covers structured prompt engineering for 3D scene planning, iterative debugging for spatial proportions and visual details, and key performance optimization strategies such as managing draw calls and shadow calculations.
1. Introduction: The Efficiency Revolution in Web3D Creative Implementation
In traditional Web3D development, developers often need to master complex computer graphics theory, specific rendering engine APIs, and tedious model import/export processes. Transforming an abstract visual concept (like a “rainy night city”) into an interactive 3D experience in the browser usually requires a long cycle of coding and debugging. However, with the maturity of LLM-assisted development tools, this process is undergoing a profound transformation. Leveraging the powerful code generation and logic understanding capabilities of LLMs, developers can rapidly build scene prototypes and focus more on creative expression and experience optimization. Using a “rainy night convenience store” Web3D scene as an example, this article details the practice of rapid end-to-end implementation using AI coding tools.
2. Scene Planning and Initial Prompt Construction
To ensure the LLM accurately understands and generates the expected Web3D scene, designing high-quality prompts is the first step. Rather than giving vague instructions like “draw a rainy night convenience store,” the request should be broken down into structured development requirements.
- Specify Tech Stack and Environment: First, specify the frontend 3D technology solution, such as WebGL technology based on HTML5 Canvas, along with a suitable 3D rendering library. Additionally, instruct the LLM to output the code in a single file or modular format to ensure it runs directly in the browser.
- Describe Core Visual Elements: Break down the “rainy night city” into specific 3D objects. For example: a convenience store building model with a glowing sign, wet and reflective street surfaces, dim streetlights, and a rain particle system to set the mood.
- Define Lighting and Material Style: Emphasize the nighttime visual effect, requesting spotlights to simulate streetlights and point lights for the glowing store sign. Materials should reflect the roughness and wet reflectivity of the ground, as well as the diffuse reflection of the building’s exterior walls.
With such structured prompt inputs, AI coding tools can quickly generate initial code that includes scene initialization, camera controls, basic geometry setup, and light configuration. This step significantly shortens project preparation time, achieving “second-level visualization” of creative ideas.
3. Iterative Debugging: Refining Proportions, Details, and Lighting
Although LLMs can generate basic code quickly, building a realistic 3D scene is rarely a one-shot process. The initial output often has deviations in spatial proportions, visual details, and atmosphere, requiring developers to conduct meticulous iterative debugging through multiple rounds of dialogue.
- Reshaping Spatial Proportions: When generating buildings and streets, the LLM might create a convenience store that is too large for a narrow street, or streetlights at heights that defy visual intuition. Developers need to precisely specify the adjustment direction. For example, prompt: “Please reduce the width of the convenience store by 30%, increase the height of the streetlights by 1.5 times, and adjust the camera’s initial position to present a better depth perspective of the street.”
- Optimizing Particle System Details: The soul of a rainy night scene lies in the “rain.” Initially generated raindrops might just be simple straight white lines, lacking realism. Developers can ask the LLM to introduce physical gravity, adjust the falling speed, density, and tilt angle (to simulate wind) of the raindrops, and even request the raindrops to be rendered as semi-transparent, elongated geometries.
- Enhancing Lighting Atmosphere: Nighttime scenes require strong lighting contrast. If the overall scene is too bright, developers can prompt the LLM to reduce ambient light intensity while enhancing the spotlight falloff effect of the streetlights, creating clear light circles on the ground. Additionally, request the addition of emissive materials for the convenience store sign and use post-processing techniques (like bloom effects) to create a soft glow for the neon lights.
This iterative communication process is essentially the developer translating their own aesthetics and visual experience into parameter instructions that the LLM can understand, gradually approaching the desired artistic effect.
4. Performance Optimization: Key Strategies for Smooth Scene Execution
In Web3D development, visual effects and runtime performance are always at odds. When generating code, LLMs often prioritize functionality and may ignore rendering pressure on the browser side. Therefore, performance optimization is an indispensable part of the practice.
- Controlling Draw Calls: If the scene contains a large number of independent small objects (like dense raindrops or distant building fragments), it will cause a spike in Draw Calls. Developers need to guide the LLM to use merged geometries or InstancedMesh technology. For example, prompt: “The current number of rain particles is too high, causing frame rate drops. Please rewrite the raindrop system using InstancedMesh to ensure that tens of thousands of raindrops consume very few Draw Calls.”
- Optimizing Shadow Calculations: Dynamic shadows are a performance killer. If both the convenience store and streetlights have real-time shadow calculations enabled, it will be difficult for low-end devices to run smoothly. Through instructions, the LLM can be directed to introduce baked shadows or lower the resolution of shadow maps, or only enable shadows for important nearby objects while using fake dark textures for distant objects.
- Balancing Materials and Textures: High-resolution PBR (Physically Based Rendering) materials consume significant VRAM. Developers can ask the LLM to use simple Lambert materials for objects with low reflection requirements (like distant buildings) when generating code, and only retain high-resolution reflective materials on wet ground, thereby achieving a balance between performance and visual quality.
Through this series of performance tuning dialogues, AI coding tools can not only provide optimized code but also output corresponding optimization logic explanations, helping developers better understand the causes of Web3D performance bottlenecks.
5. Conclusion: A New Development Paradigm of Human-AI Collaboration
Through this practice of building a “rainy night city” scene, we can clearly see the immense potential of LLM-assisted development tools in the frontend 3D domain. It is highly suitable for quickly turning fleeting ideas in your mind into actually running, playable prototype works.
However, this does not mean the developer’s role is replaced. On the contrary, the core capabilities of developers are shifting upward: from tedious API calls and basic code writing to requirement breakdown, aesthetic control, problem diagnosis, and performance optimization strategy formulation. The LLM acts as a tireless junior engineer, responsible for translating high-dimensional requirements into underlying code implementations. In future technological evolution, mastering how to communicate efficiently with AI and guiding it to produce high-quality, high-performance code will become a core competency for every modern developer.
