Pure-Code Video Generation: A Technical Practice for Stunning Short Videos
This article explains how to generate visually striking 30–60 second short videos entirely from code, without external image, video, or audio assets and without generative APIs. It covers turning creative concepts into executable design language, choosing between a browser shader pipeline and a scripted offline rendering pipeline, building core visual modules such as procedural materials, lighting, particles, audio-driven visuals and post-processing, and defining performance budgets with fallback strategies. It also outlines a reproducible project structure, run and render commands, self-assessment criteria, and common pitfalls to avoid.
1. Why Pure-Code Video Generation Is Worth Doing
As generative content tools spread quickly, another approach is being re-examined: synthesizing both visuals and sound entirely from code, without relying on any external image, video, or audio assets and without calling generative APIs. Its value is not about “replacing” generative solutions, but about three engineering properties:
- Reproducibility: the same source code, the same parameters, and the same environment should produce consistent output;
- Controllability: camera work, color, pacing, and material parameters can all be described precisely and iterated on;
- Auditability: with no black-box asset sources, the copyright and compliance chain is clearer.
The constraints in the original practice are typical: 30–60 seconds in duration, 1920×1080, 30fps, no external assets or generative APIs, a complete project with rendering commands must be provided, and a frame sequence or video file must actually be exported. These constraints essentially test a combination of “creative technical direction + graphics programming.”
2. Breaking “Stunning” into Executable Design Language
“Stunning” is not about piling up techniques; it is the result of layering visual concept + narrative pacing + camera design. It is recommended to lock down three things before starting:
- One-sentence concept: for example, “a microscopic nebula collapses and is reborn inside a gravitational well”;
- Three-act pacing: setup (0–10s to establish space and materials), development (10–25s to introduce disturbance and particle streams), and turn/resolution (25–45s for collapse, burst, and afterglow ending);
- Color and composition curve: low-saturation cool tones in the opening, high-contrast warm highlights added in the middle, and a return to cool tones with reduced brightness at the end, forming a closed loop.
An illustrative pacing table (usable directly as engineering configuration):
timeline:act1: 0.0-10.0s camera: slow_orbit palette: cold_low_satact2: 10.0-25.0s turbulence: ramp_up palette: add_warm_highlightact3: 25.0-45.0s collapse->burst->afterglow
3. Technology Choices: Browser Shader vs. Offline Rendering
There are two common routes. Choose one based on your team’s capabilities, and ensure “offline reproducibility.”
Route A: Browser + shaders (single-page entry)
Suitable for visually dense scenes centered on a full-screen fragment shader. Key engineering points:
- A single-page entry running offline via a local static server, with no external resources;
- A unified clock driving all animation to guarantee deterministic frame-by-frame output;
- Automated scripts capturing screenshots per frame, producing sequences like
frame_000001.png.
Route B: Scripted offline rendering (environment + commands)
Suitable for scenes requiring more controllable sampling, motion blur, and cumulative denoising. Key engineering points:
- Fixed random seed and sample count;
- Layered rendering (background, volume, particles, post) followed by compositing;
- Encoding and packaging done through the command line.
Whichever route you take, make “determinism” the first principle:
requirements:fixed_seed: truetime_source: frame_index / fpsno_external_assets: true
4. Core Visual Modules: Procedural Materials, Lighting, and Post-Processing
1. Procedural Materials
Use noise and domain warping to construct surface detail and avoid texture dependencies. A common combination is multi-layer noise stacking plus curvature/Fresnel modulation:
material = base_color+ fbm(p * scale + warp) * detail+ fresnel(view, normal) * rim
2. Lighting and Shadows
You can achieve good results without complex global illumination: key light + rim light + approximated volumetric fog. Shadows can use ray marching or screen-space approximation; the key is to let “light” participate in the narrative (for example, the key light gradually tightens during collapse).
3. Particles and Fluid Approximation
The particle system handles “density and direction,” while the fluid approximation handles “continuity.” Engineering recommendations:
- Make particle count and lifetime configurable, with support for degradation;
- Drive motion with a velocity field (curl noise) to create turbulence;
- Use a low-resolution grid with time stepping for the fluid, then upsample and composite.
4. Audio-Driven Visuals
Audio is fully synthesized in code (sine stacking, noise envelopes, simple filtering), then an envelope or spectral centroid drives brightness, particle velocity, and camera shake to achieve “audio-visual sync.”
5. Post-Processing
Glow, chromatic aberration, grain, vignette, and tone mapping are “texture amplifiers.” It is recommended to make post-processing a toggleable pipeline for easier performance degradation.
5. Performance Budget and Fallback Plan (Must Be in Deliverables)
Using 1080p/30fps as the baseline, provide a clear budget and degradation order:
- Budget: target per-frame rendering ≤ 33ms; set upper limits on peak particle count, volume step count, and post-processing sample count;
- Degradation order: disable screen-space shadows → reduce volume steps → halve particle count → downsample post-processing → lock 30fps without pursuing higher frame rates;
- Stability: automatically skip non-critical effects when a frame times out, ensuring the export task is not interrupted.
6. Reproducible Project Structure and Run/Render Commands
A recommended delivery structure (illustrative):
project/src/ # scene, materials, particles, audio, postassets_gen/ # runtime-generated textures/audio (not external assets)out/frames/ # frame sequence frame_%06d.pngout/video/ # composited video filerun.sh # one-click run/render
Run and export (neutral illustration):
# Start a local static server (browser approach)python -m http.server 8000# Render frame by frame and output to out/frames./run.sh --frames --fps 30 --width 1920 --height 1080# Composite the frame sequence into a videoffmpeg -framerate 30 -i out/frames/frame_%06d.png -c:v libx264 -pix_fmt yuv420p out/video/output.mp4
7. Self-Assessment: How to Judge Whether the Work Truly Meets the Bar
Use five dimensions for a hard self-assessment to avoid “looks flashy but not deliverable”:
- Visual impact: is there a clear concept and camera design, rather than asset collage;
- Technical difficulty: does it include at least one complex technique (procedural materials, volume, particles/fluid, audio-driven);
- Code quality: modular, centralized parameters, no hard-coded paths;
- Reproducibility: fixed seed, unified clock, offline operation, complete commands;
- Performance and stability: has a budget, has fallback, has timeout protection.
8. Common Pitfalls and Fixes
- Only pseudocode: runnable source code and real export commands must be provided;
- Random drift: failing to fix the seed or unify the clock causes different results each time;
- External dependencies: secretly referencing external assets or online resources breaks the “pure code” premise;
- No fallback: freezing under high load, lacking a switchable low-spec pipeline;
- Incomplete delivery: missing frame naming rules, compositing commands, and output path descriptions.
Following this approach, pure-code short videos are no longer an “inspiration demo,” but a reviewable, reproducible, and deliverable graphics engineering practice.
