When LLMs Write Renderers From Scratch: A Technical Breakdown of Pure Code-Generated Images
This article examines what happens when a large language model is asked to generate images using only code, with no image generation models, no ready-made 3D software, and no built-in denoising. It explains why pure code rendering is difficult, the four capability layers required from geometry to photons, why a mathematically correct render is not automatically attractive, and how the challenge grows when moving from still frames to video. It closes with a reusable practice checklist and the main takeaway:底层 rendering and generation capability can cover long-tail needs when paired with elastic compute and observability.
1. Background: Taking Every Ready-Made Tool Away
Most generative image workflows stand on top of a mature toolchain: they call existing image generation services, reuse material and lighting presets from 3D software, and rely on one-click denoising. These conveniences also hide a question: how much geometry and optics does the model actually understand, and how much is it simply stitching together existing assets?
That question led to an almost deliberately punishing experiment. No image generation model, no ready-made 3D software, code output only. The code had to build the scene, compute the lighting, and denoise the result on its own. The goal was not to produce a “good-looking” image, but to see how far a model can push an image under the strictest possible constraints.
The engineering value of this kind of experiment is not in rejecting toolchains. It is in reverse validation: when the abstraction level is pushed down to the lowest layer, does the model’s reasoning chain still hold together? The relevance to real projects is direct: any long-tail requirement that existing tools do not cover will ultimately have to be handled by low-level capability.
2. Why Pure Code Rendering Is Hard
Pure code rendering is difficult because it removes three kinds of feedback at once.
- No visual feedback: without a viewport preview, object proportions, orientation, and placement can only be reasoned about in a 3D coordinate system, then verified through a long render.
- No material presets: without ready-made material spheres, diffuse, specular, and subsurface scattering all have to be written as functions, and the meaning of every parameter has to be defined explicitly.
- No post-processing shortcuts: without one-click denoising, final image quality depends entirely on the filtering logic you implement yourself.
Render cost makes it worse. Take path tracing: a single frame requires a large number of light paths sampled per pixel, and path length and sample count directly determine convergence speed. A render on the order of three hours is not unusual, which makes trial and error extremely expensive: one wrong coordinate may cost hours of waiting before you find out.
3. Capability Breakdown: From Geometry to Photons
To make an image work, the model has to chain at least four layers of capability. Miss one and the whole frame falls apart.
- Scene and camera model: define the coordinate system, camera position and orientation, and field of view, then project 3D points to pixels. A mistake here invalidates everything downstream.
- Ray-material interaction: implement ray intersections with spheres, planes, and triangle meshes, sample reflection and refraction directions by material type, and use probability density functions for importance sampling.
- Global illumination: approximate the rendering equation with Monte Carlo integration and accumulate multiple bounces; only then does indirect light appear and the image gain a sense of volume.
- Denoising and tone mapping: suppress noise with filtering when sample counts are low, then apply exposure and gamma correction to produce a viewable image.
A schematic code skeleton looks roughly like this; the point is the structure, not the specific values:
def trace(ray, scene, depth):if depth <= 0:return background(ray)hit = intersect(scene, ray)if not hit:return background(ray)p, n, mat = hit.point, hit.normal, hit.materialif mat.kind == "diffuse":d = cosine_sample_hemisphere(n)return mat.albedo * trace(Ray(p + eps * n, d), scene, depth - 1)if mat.kind == "mirror":r = reflect(ray.dir, n)return mat.albedo * trace(Ray(p + eps * n, r), scene, depth - 1)if mat.kind == "glass":return refract_and_reflect(p, n, ray, mat, scene, depth)
What usually decides success is not these functions but the sampling strategy: the ratio among light source area, sample count, and bounce depth directly determines the noise structure and the render time.
4. The Dividing Line: Computable Is Not the Same as Attractive
Code has no notion of beauty. Among a nearly infinite set of parameter combinations, a roughness value off by a few decimals or a slightly excessive metallic value can immediately turn an image into a plastic-looking failure. The model has to build its own bridge between cold mathematical rules and human visual habits. A few relatively stable heuristics emerge:
- Composition before detail: subject proportion, horizon placement, and line of sight determine whether the first impression works.
- Lighting must follow logic: the intensity ratios and color temperature differences among key, fill, and rim lights determine volume and atmosphere, and every light source needs a plausible origin.
- Materials rely on contrast: rough against smooth, warm against cool, sparse against dense; contrast is what gives an image layers.
- Restraint is taste: fewer elements put more pressure on selection, and excessive accumulation usually signals loss of control.
After a week of observation, the most direct impression is that the model displays not only computation and reasoning ability but a stable aesthetic tendency: it knows when to stop.
5. From Still Frames to Motion: The Difficulty Steps Up
Once a static image works, video is the natural next step. Dynamic scenes raise the difficulty across the board: as the camera moves along a path, every frame has to reconverge, and inconsistent noise between frames produces flicker. Media such as water add absorption, scattering, and caustics, which are classic hard problems in computer graphics.
Engineering typically requires additional handling:
- Temporal consistency: use a fixed random seed strategy or temporal filtering to suppress inter-frame jitter.
- Sampling budget allocation: concentrate compute on the subject and caustic regions, and relax the background moderately.
- Resolution and frame rate trade-offs: verify motion and composition at low resolution first, then scale up for the final output.
- Distributed rendering: split frames across multiple compute instances running in parallel, aggregate outputs in object storage, schedule tasks with a message queue, and track failures and retries with monitoring and alerting.
This combination of offline rendering plus elastic compute can be hosted on Baidu AI Cloud using a container platform for render workers, object storage for intermediate frames and final output, and log and monitoring services with alerting to locate long-tail failures. This is a common industry practice.
6. A Reusable Practice Checklist
- Validate the minimum closed loop first: one sphere, one light, one camera; get intersection and sampling working before discussing style.
- Turn parameters into readable semantics: build parameter tables with explicit names for materials and lighting, and avoid magic numbers.
- Separate rendering from tuning: use low samples for fast composition previews and high samples only for final output.
- Preserve determinism: fix seeds and version scene descriptions so problems are reproducible.
- Make cost observable: record per-frame time and failure reasons to form a data loop that can be optimized.
7. Conclusion
Once every tool is taken away, only two things are left to compete on: whether you can get the physics right, and whether you know what counts as beautiful. The first relies on reasoning and implementation; the second on selection and judgment. For developers, the real payoff of this kind of experiment is not an image or a video, but confirmation that low-level generation and rendering capability can carry long-tail requirements. Putting that pipeline into an elastic, observable engineering system is where scaling actually begins.
