Ghost In The Raster A bare-metal software rasterizer built from the ground up, exploring the intersection of human intuition and artificial intelligence in low-level graphics programming. Ghost In The Raster is not just a rendering engine; it is an experiment in "Context Engineering." It challenges the notion that AI can replace deep technical understanding. By building a 3D pipeline purely on the CPU using C++, this project demonstrates that while AI can generate the syntax of linear algebra, it takes a human architect to enforce the physics of light. The Philosophy In an era where AI can scaffold a React app in seconds, we asked a fundamental question: Can AI truly understand the math behind the pixels? Most AI-generated graphics code relies on high-level libraries (OpenGL, Unity, Three.js). This project strips away the GPU and the drivers, forcing the AI to write raw C++ code for vertex transformation, clipping, and rasterization. The Core Conflict: AI acts as a brilliant mathematician that is blind to the physical world. It can multiply matrices perfectly but often fails to grasp the concept of "perspective" (the w w -divide) until explicitly guided by a human who understands the visual result. Tech Stack Language: C++17 (Modern, strict typing) Windowing: EasyX / SDL2 (Used strictly for framebuffer output) Architecture: Pure CPU Software Rasterization Key Algorithms: 4x4 Matrix Transformations (Model, View, Projection) Perspective-Correct Interpolation Barycentric Coordinate Rasterization Phong Lighting Model Project Structure The project is organized to mirror the graphics pipeline, separating the "math" from the "rasterization." text
编辑
GhostInTheRaster/ ├── src/ │ ├── main.cpp # Entry point & Game Loop │ ├── core/ │ │ ├── Window.h # OS Window management │ │ └── Framebuffer.h # Raw pixel memory manipulation │ ├── math/ │ │ ├── Vec3.h # 3D Vector operations │ │ └── Mat4.h # 4x4 Matrix & Projection logic │ └── render/ │ ├── Rasterizer.h # Triangle setup & Edge functions │ └── Shader.h # Vertex & Fragment processing ├── assets/ │ └── texture.bmp # Test texture for UV mapping └── CMakeLists.txt Key Features
- The "Perspective" Fix A major focus of this project was debugging AI hallucinations regarding Perspective Division. Standard AI responses often conflate Orthographic and Perspective projections. This codebase explicitly implements the 1 / w 1/w interpolation to ensure textures do not warp on 3D surfaces.
- Barycentric Rasterization Instead of simple scanline rendering, we utilize Barycentric coordinates to determine pixel coverage. This allows for smooth attribute interpolation across the triangle surface.
- Zero GPU Dependency This engine does not ask the graphics card for help. Every pixel color is calculated by the CPU, demonstrating the raw computational power of modern processors when guided by efficient algorithms. How to Build Prerequisites A C++17 compatible compiler (GCC, Clang, or MSVC) CMake 3.10+ (Optional) EasyX library if running on Windows, or SDL2 for cross-platform. Compilation bash
编辑
git clone https://github.com/YourUsername/GhostInTheRaster.git cd GhostInTheRaster
mkdir build && cd build
cmake .. cmake --build .
./GhostInTheRaster The Roadmap v0.1: Wireframe Cube (The "Hello World" of 3D) v0.2: Z-Buffering & Depth Testing (Fixing the "painter's algorithm") v0.3: Texture Mapping with Perspective Correction (The "Ghost" is caught) v1.0: Phong Lighting & Normals (Injecting soul into the machine) Acknowledgments This project was written in collaboration with a Large Language Model, but architected, debugged, and refined by a human who knows that math is not the same as reality.