A complete, self-contained 3D Vertex Processor built without any external libraries (no GLM, no Eigen, no OpenGL/DirectX/Vulkan, no stb_image).
The system faithfully models modern and classic hardware GPU vertex processing pipelines:
[ Vertex Stream (VBO / Indexed Buffers) ]
│
▼
[ Vertex Fetch / Puller ]
│
▼
[ Post-Transform Vertex Cache ] ◄── FIFO Reuse (Up to 65%+ shader skip)
│
▼
[ Vertex Shader Engine ]
├── C++ Programmable Kernel
└── Microcode Vector ISA (DP4, DP3, MAD, RSQ, LIT, MOV)
│
▼
[ Homogeneous 4D Frustum Clipper ] ◄── Sutherland-Hodgman (6 planes)
│
▼
[ Perspective Division ] ◄── (x/w, y/w, z/w) -> NDC [-1, 1]^3
│
▼
[ Viewport Transformation ] ◄── NDC to Screen Pixels & Depth [0, 1]
│
▼
[ Primitive Assembly & Culling ] ◄── Backface Culling & Winding
│
▼
[ Software Rasterizer & Z-Buffer ] ◄── Barycentric Perspective-Correct
│
├──> Terminal ASCII Live View
└──> 24-bit Raw BMP Output
-
include/math3d.hpp:-
Vec2,Vec3,Vec4vector math with arithmetic operators, dot products, cross products, normalization, and lerp. -
Mat44x4 matrix engine: translation, scaling, axis-angle rotation, Euler rotation, analytical cofactor 4x4 matrix inversion (inverse()), transpose, view matrix (lookAt), and perspective projection (perspective).
-
-
include/microcode_shader.hpp:- Virtual GPU vector instruction set simulator:
-
DP4(4-component dot product for MVP matrix multiplication) -
DP3(3-component dot product for normal & lighting) -
RSQ(reciprocal square root for fast normalization) -
MAD(multiply-add) -
LIT(hardware Phong lighting instruction) - Full register file (
$v0..v15$ attributes,$c0..c63$ uniforms,$r0..r15$ temps,$oPos, oCol, oNormal, oTex$ outputs).
-
- Virtual GPU vector instruction set simulator:
-
include/vertex_processor.hpp:- Post-Transform Vertex Cache (PTVC): Emulates GPU hardware FIFO cache to skip re-transforming shared vertices across triangle meshes.
-
Frustum Clipper: 4D Homogeneous Sutherland-Hodgman polygon clipping against all 6 frustum planes (
$w \pm x \ge 0$ ,$w \pm y \ge 0$ ,$w \pm z \ge 0$ ). Interpolates all vertex attributes (color, normal, UV) along clipped edges before perspective division. - Perspective Division & Viewport Mapping: Transforms clip coordinates to NDC and pixel coordinates.
- Backface Culling: Fast 2D signed area winding test.
-
include/rasterizer.hpp&include/framebuffer.hpp:- Perspective-correct barycentric software rasterizer.
- 24-bit color buffer + 32-bit floating point depth buffer (Z-buffer).
- C++ BMP file writer (generates valid uncompressed Windows Bitmap files byte-by-byte).
- High-contrast ASCII terminal renderer with luminance mapping.
g++ -std=c++14 -O3 -Wall -Wextra -Iinclude src/main.cpp -o vertex_processor.exe
./vertex_processor.exemake
make runmkdir build && cd build
cmake ..
cmake --build . --config Release
./vertex_processor.exeWhen rendering a dense 3D Torus mesh (3,840 vertices fetched, 1,280 triangles):
- Cache Hit Ratio:
65.0%(2,496 shader invocations avoided!) - Shader Invocations: Reduced from 3,840 to 1,344
- Processing Time: ~
2.2 msin software - Frustum Clipping: 100% stable, zero artifacts on geometry crossing the near/far/screen boundaries.