Pure Code Video Generation: A Technical Practice for Stunning Short Videos
This article presents a practical technical approach to generating a narrative short video using only code, with no external assets and no generative API calls. It covers concept and visual language design, a layered rendering pipeline, key techniques such as SDF-based accretion disk geometry, gravitational lensing approximation, instanced particles with curl noise, anti-flicker bloom and tone mapping, and procedural audio that drives visual parameters. It also explains project structure, reproducibility, performance budgets with quality degradation tiers, and delivery with self-assessment. The core takeaway is that success depends on whether the work is truly pure code, reproducible, clearly engineered, and performance-controlled.
1. Background: Why Pure Code Video Generation Is Worth Doing
As intelligent coding tools and generative models evolve quickly, a common scenario is this: given a structured creative prompt, the system must produce a short video with a sense of narrative using only code, without any external assets and without calling any generative API. This is not a show-off demo but a complete graphics engineering practice that tests creative direction, graphics programming, engineering organization, and performance trade-offs at the same time.
The core constraints can be summarized in six points: no external assets, fully procedural generation, a complete and reproducible project, real export of a finished video or frame sequence, explicit run and render commands, and no pseudocode. Around these constraints, this article offers a general and actionable technical approach.
2. Concept and Visual Language Design
Strong technology without a visual concept ends up as a mere technical demo. Start by choosing a theme that can be expressed mathematically, for example “accretion disk evolution under gravitational lensing.” Its visual language can be reduced to three points:
- Composition: strong perspective with central symmetry, the subject occupying the central 60% of the frame, with dark surroundings to strengthen contrast.
- Color: a high-dynamic-range warm core and a cool periphery forming a complementary pair, finally converged into a cinematic palette through tone mapping.
- Rhythm: 0–8 seconds of silent build-up, 8–25 seconds of particle acceleration with gravitational distortion, 25–45 seconds reaching the visual climax, and 45–60 seconds of slow decay and closure.
This “setup, development, climax, resolution” structure can be driven uniformly by timeline variables that control the camera, particle emission rate, and color temperature, preventing modules from drifting apart.
3. Technical Approach and Key Challenges
The overall design uses a layered rendering pipeline: the geometry layer handles the accretion disk and particles, the effects layer handles bloom and tone mapping, and the audio layer generates procedural music that drives visual parameters in reverse.
Hybrid Fractals and Signed Distance Fields (SDF)
Fractal noise combined with an SDF describes the irregular edges of the accretion disk. The challenge is balancing iteration count against frame rate. In practice, the iteration limit is usually a tunable parameter and is reduced on lower-performance devices.Gravitational Lensing Approximation
In the shader, light bending approximates general relativistic effects. The core is a radial distortion of the background sampling coordinates. Example code:
// Approximate radial gravitational deflectionvec2 uv = fragCoord / resolution;vec2 dir = uv - center;float r = length(dir);float bend = strength / (r * r + 0.01);uv = center + dir * (1.0 + bend);vec3 col = texture(bgTexture, uv).rgb;
Large-Scale Instanced Particles and Curl Fields
Instanced rendering draws tens of thousands of particles, with the velocity field generated by curl noise to keep the motion divergence-free and visually closer to fluid. The challenge is the update frequency of instance attribute buffers: usually only a few parameters are updated per frame, while the rest are computed inside the shader.Anti-Flicker Bloom and Tone Mapping
The bloom stage uses a time-accumulation anti-flicker strategy to suppress highlight jitter. Finally, an industry-standard cinematic tone mapping curve compresses high dynamic range into a displayable range.Procedural Audio and Audio-Driven Visuals
Offline synthesis generates 48kHz samples, and the low-frequency energy envelope drives particle brightness and camera shake for audio-visual synchronization. Audio synthesis is decoupled from video rendering: the waveform file is produced first, then the renderer reads the envelope data.
4. Project Structure and Reproducibility
A reproducible project should contain at least an entry page or main program, shader files, an audio synthesis script, render and export scripts, dependency notes, and run commands. A sample directory layout:
project/index.htmlshaders/audio/gen_audio.pyrender/run.shREADME.md
The recommended workflow has three steps: first run the audio synthesis script to generate the waveform and envelope; then start a local static server for real-time preview; finally use a headless browser or offscreen rendering to output frames one by one, and combine them into an MP4 or GIF with a command-line tool. All commands should be written into the documentation so that others can reproduce the result with a single run.
5. Performance Budget and Degradation Plan
The performance budget should be set during design, for example a target of 1080p at 30fps with a per-frame budget of 33ms. Three degradation tiers can be defined: high quality enables all particles and multiple bloom iterations; medium quality reduces particle count and iteration count; low quality disables gravitational lensing and keeps only basic particles and tone mapping. The degradation logic switches automatically based on runtime frame time detection, ensuring stable export of the final video.
6. Delivery and Self-Assessment
Deliverables should include a concept description, technical approach, complete code, run and render commands, output naming rules, and a self-assessment. The self-assessment can cover five dimensions: visual impact, technical difficulty, code quality, reproducibility, and performance. What really determines success is not whether a single technique is impressive, but whether the work is truly pure code, reproducible, clearly engineered, and performance-controlled.
7. Conclusion
Generating a short video with pure code is a complete exercise in breaking creativity down into mathematics and engineering. As long as you insist on concept first, layered implementation, budget constraints, and reproducible delivery, you can reliably produce a finished video with both visual impact and engineering quality. If you use general capabilities such as the container platform, object storage, and log monitoring offered by Baidu AI Cloud to host rendering and distribution, this kind of creative workflow can further be turned into a reusable and observable production pipeline.
