Building a WebGL 3D Rainy Night Scene with AI-Assisted Programming

    This article explores how to leverage AI-assisted programming tools to build a WebGL-based 3D "rainy night convenience store" scene. It covers the complete workflow from requirement decomposition, basic geometry and material construction, to dynamic effects and lighting. It also reviews practical experiences in iterative refinement for scale control, detail polishing, and deep performance optimization, demonstrating a paradigm shift from writing raw graphics code to directing scene design.

    In web frontend development, rapidly transforming an abstract concept into an interactive 3D scene often requires navigating complex low-level graphics code and tedious scene assembly. With the rapid advancement of AI programming tools, developers now have a completely new workflow. Using the construction of a “rainy night convenience store” 3D scene as an example, this article explores the practical development of WebGL applications using AI-assisted tools, and reviews iterative experiences in scale control, performance optimization, and detail polishing.

    1. Creative Concept and Requirement Decomposition

    The rainy night convenience store is a scene blending cyberpunk aesthetics with everyday life. Core visual elements include: a glowing convenience store signboard, neon reflections on wet roads, dynamic falling rain, and warm interior lighting. If manually writing rendering engine code based on WebGL, developers must handle massive amounts of vertex data, shader logic, and particle systems.

    When introducing AI-assisted programming tools, the first step is not to ask it to generate the complete code in one go, but to decompose the requirements. We divided the entire scene into three main modules:

    1. Basic Geometry and Materials: The convenience store’s building structure, doors, windows, and road surface.
    2. Lighting and Atmosphere: Point lights, ambient light, volumetric lighting effects, and neon materials.
    3. Dynamic Environmental Effects: Raindrop particle systems, water ripples, and reflection effects.

    Issuing instructions to the AI tool through structured prompts effectively prevents logical breaks caused by generating too much code in a single pass.

    2. Building Basic Scenes and Materials

    During the construction phase, we first guide the AI tool to generate the basic skeleton of the scene. Using mainstream web 3D rendering technologies, we need to establish box-like building structures. At this point, the AI tool can quickly generate basic scene initialization code, camera controls, and a foundational lighting environment.

    However, geometry alone is insufficient. To achieve the texture of a rainy night, the use of Physically Based Rendering (PBR) materials is crucial. Developers need to explicitly instruct the AI that the road surface requires roughness and metalness properties to generate strong reflections when wet. Meanwhile, the convenience store signboard needs an emissive material. In this phase, the AI-generated code typically provides the correct API calling framework, but specific texture parameters and material values often require developers to fine-tune based on actual rendering results. It may even require multiple interactions with the AI to correct the lighting calculation logic within the shaders.

    3. Implementing Dynamic Effects and Lighting Atmosphere

    The soul of the rainy night scene lies in its dynamic effects. Rain effects are usually achieved through particle systems. When describing requirements to the AI, it is necessary to specify parameters such as the falling speed, density, and wind-induced offset of the raindrops. The AI tool can quickly generate point cloud or line segment-based particle system code, complete with basic physical gravity simulation.

    Even more complex are the road surface reflections and water ripples. To achieve a realistic rainy night effect, developers can use AI to assist in writing post-processing code for Screen Space Reflections (SSR) or planar reflections. At this stage, the AI’s advantage lies in its ability to rapidly provide universal shader code templates. For instance, when a developer requests “a fragment shader that simulates puddle refraction and reflection,” the AI can provide base code based on the Fresnel equation. By modifying the perturbation textures on this basis, developers can achieve realistic water ripple effects.

    4. Iterative Refinement of Scale and Details

    As experienced in actual development, AI-assisted 3D scene generation is rarely “perfect in one shot.” After initially generating the scene, we often find issues like disproportionate building scales, harsh lighting contrasts, or raindrops penetrating buildings.

    Solving these problems requires precise iterative communication. First is the scale issue: by feeding back to the AI that “the convenience store door is too tall relative to the overall building,” the AI can adjust the scaling parameters when generating geometry. Second are collision and occlusion issues, where we need to instruct the AI to add collision detection to the raindrop particle system to prevent rain from falling through eaves into the interior. In this process, the developer acts as the “art director,” while the AI acts as the executor. Through continuous prompts with clear contextual constraints, the AI gradually converges to the expected visual effects, completing the polishing of details like neon light flicker frequency and raindrop size distribution.

    5. Deep Optimization of Rendering Performance

    Once the scene’s visual effects meet expectations, performance bottlenecks often emerge. Massive dynamic particles, real-time reflection calculations, and high-resolution post-processing can cause frame rates to plummet on low-end devices. At this point, developers need to utilize AI tools for performance tuning.

    We can ask the AI tool to refactor existing code and introduce common industry optimization strategies:

    1. Instanced Rendering: Change repeated geometries in the scene (like raindrops) to instanced drawing, drastically reducing GPU draw calls.
    2. Hybrid Rendering Strategy: Use baked lightmaps for static interior convenience store items instead of real-time lighting calculations; for road surface puddles, enable real-time reflections only near the camera’s view.
    3. Adaptive Downsampling: Guide the AI to write logic that monitors the frame rate, automatically reducing particle counts or the rendering resolution of post-processing effects when the FPS drops below a threshold.

    During the performance optimization phase, AI helps developers quickly generate tedious optimization code logic, allowing them to focus their energy on global architecture and performance bottleneck analysis.

    Conclusion

    Overall, using AI programming tools to build a WebGL 3D rainy night scene represents a paradigm shift from “writing code” to “doing design.” Although limited by the current models’ contextual understanding and spatial imagination, scale, performance, and details still require developers to invest effort in repeated communication and correction. However, AI tools have already demonstrated powerful rapid prototyping capabilities. They significantly lower the barrier to writing graphics code, enabling developers to transform ideas in their heads into fully interactive 3D works running in browsers with exceptionally high efficiency.