A small CPU renderer that draws an antialiased triangle using ray-plane intersections and barycentric area tests.
A computer-graphics learning exercise implemented in C++. For each pixel, the program casts jittered orthographic rays at a triangle, checks whether the intersection is inside it, and averages the samples to soften its edges. The result is written as a binary PPM image.
- Three-dimensional vector operations and triangle-normal calculation.
- Ray-plane intersection followed by an area-based inside-triangle test.
- Forty jittered samples per pixel.
- A 1024 × 1024 grayscale result stored as RGB pixels.
- A minimal Makefile and no third-party runtime dependencies.
- C++11
- Standard C/C++ math and file I/O
- Make
Install a C++ compiler and Make, then run:
git clone https://github.com/ericksonnoah5/Triangle-Renderer-CPP.git
cd Triangle-Renderer-CPP
make renderThis builds triangle and generates triangle.ppm in the current directory. Open it with a viewer that supports PPM. On macOS, open triangle.ppm opens it in the default viewer. The PNG above is a preview generated from the program's output.
Other commands:
make # Build only
./triangle # Render again
make clean # Remove executable and generated PPMEdit WIDTH, HEIGHT, and SSLEVEL in src/triangle.cpp to change the image size or sample count. The triangle's three vertices are assigned in main(). Coordinates are in the same units as the image grid; adjust them if you change the dimensions.
src/triangle.cpp Vector math, intersection tests, sampling, and PPM output
docs/triangle.png Preview generated by the renderer
Makefile Build, render, and clean targets
The scene contains one fixed white triangle on a black background with an orthographic camera. There is no lighting, texture mapping, scene loader, or interactive view. The random generator is not explicitly seeded. The intersection code assumes a nondegenerate triangle whose plane is not parallel to the rays.
Published by Noah Erickson as a computer-graphics learning exercise.
Available under the MIT License.
